@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,119 @@
1
+ import type { CodeCommand } from '../core/commands';
2
+ import type { CodeText } from '../core/text';
3
+ import { type CodeExtension } from '../extension';
4
+ /** A position as the protocol counts it: line and character (UTF-16 code units), both from 0. */
5
+ export interface LspPosition {
6
+ line: number;
7
+ character: number;
8
+ }
9
+ export interface LspRange {
10
+ start: LspPosition;
11
+ end: LspPosition;
12
+ }
13
+ /** A place in some document, e.g. where a name is defined. */
14
+ export interface LspLocation {
15
+ uri: string;
16
+ range: LspRange;
17
+ }
18
+ /** A JSON-RPC message: a request, its response, or a notification. */
19
+ export interface LspMessage {
20
+ jsonrpc: '2.0';
21
+ id?: number | string | null;
22
+ method?: string;
23
+ params?: unknown;
24
+ result?: unknown;
25
+ error?: {
26
+ code: number;
27
+ message: string;
28
+ data?: unknown;
29
+ };
30
+ }
31
+ /**
32
+ * How messages reach the server and come back: one JSON-RPC message
33
+ * (an object, not a string) at a time.
34
+ */
35
+ export interface LspTransport {
36
+ send: (message: LspMessage) => void;
37
+ /** Listens for the server's messages; returns a function that stops listening. */
38
+ onMessage: (listener: (message: LspMessage) => void) => () => void;
39
+ /** Ends the connection, e.g. terminates the worker. */
40
+ close?: () => void;
41
+ /**
42
+ * Listens for the connection breaking by itself, e.g. the worker failing
43
+ * or the socket closing; returns a function that stops listening.
44
+ */
45
+ onClose?: (listener: () => void) => () => void;
46
+ }
47
+ export interface LanguageClientOptions {
48
+ /**
49
+ * The connection to the server. A function is called when the first
50
+ * editor using the client mounts, and the connection is shut down and
51
+ * closed when the last one unmounts; a later editor starts a new one.
52
+ * A transport given as it is stays open until `close()`.
53
+ *
54
+ * Editors still mounted when the connection ends (`close()`, or the
55
+ * server stopping by itself) stay without the server until they mount
56
+ * again.
57
+ */
58
+ transport: LspTransport | (() => LspTransport);
59
+ /** The workspace folder, sent as `rootUri`. */
60
+ rootUri?: string | null;
61
+ /** Sent as `initializationOptions`, for what the server reads there. */
62
+ initializationOptions?: unknown;
63
+ }
64
+ export interface LanguageDocumentOptions {
65
+ /** The document's URI, e.g. `file:///src/report.ts`. */
66
+ uri: string;
67
+ /** The language's identifier as the server knows it, e.g. `typescript`. */
68
+ languageId: string;
69
+ /**
70
+ * Opens a definition in another document (`F12` on a name defined
71
+ * elsewhere). Definitions in this document are selected in place.
72
+ */
73
+ openLocation?: (location: LspLocation) => void;
74
+ }
75
+ /** A document's extension, with its commands. */
76
+ export interface LanguageDocument extends CodeExtension {
77
+ /**
78
+ * Goes to the definition of the name at the cursor: a command for
79
+ * `editor.run()`, a key of `DouCodeKeys` or your own button. Also on
80
+ * `F12`, and in the touch toolbar when the cursor is on a name.
81
+ */
82
+ goToDefinition: CodeCommand;
83
+ }
84
+ export interface LanguageClient {
85
+ /** An extension that opens a document on the server and shows what it says about it. One per editor. */
86
+ document: (options: LanguageDocumentOptions) => LanguageDocument;
87
+ /** Sends a request once the server is ready; `signal` cancels it (`$/cancelRequest`). */
88
+ request: <T = unknown>(method: string, params?: unknown, signal?: AbortSignal) => Promise<T>;
89
+ /** Sends a notification once the server is ready. */
90
+ notify: (method: string, params?: unknown) => void;
91
+ /** Listens for one of the server's notifications, e.g. `window/logMessage`; returns a function that stops listening. */
92
+ onNotification: (method: string, listener: (params: any) => void) => () => void;
93
+ /** What the server said it can do in its `initialize` answer; `null` until it answered. */
94
+ readonly capabilities: Readonly<Record<string, any>> | null;
95
+ /** Shuts the server down and closes the connection. */
96
+ close: () => void;
97
+ }
98
+ /**
99
+ * A transport over a Web Worker that runs the server, posting message
100
+ * objects both ways. An error before the worker's first message (it failed
101
+ * to load) counts as the connection closing; an error after it, thrown
102
+ * while handling one request, leaves the worker running.
103
+ */
104
+ export declare function workerTransport(worker: Worker): LspTransport;
105
+ /**
106
+ * A transport over a WebSocket, one JSON message per frame. Messages sent
107
+ * before it opens wait for it.
108
+ */
109
+ export declare function socketTransport(socket: WebSocket): LspTransport;
110
+ /** Offset `pos` as the protocol's line and character. */
111
+ export declare function toLspPosition(doc: CodeText, pos: number): LspPosition;
112
+ /** The offset of a protocol position; past the end of a line or the text, the nearest end. */
113
+ export declare function fromLspPosition(doc: CodeText, position: LspPosition): number;
114
+ /**
115
+ * Talks to a language server: its completions, hover texts, parameter
116
+ * hints, problems and definitions show in the editors that use
117
+ * `client.document(...)`.
118
+ */
119
+ export declare function createLanguageClient(options: LanguageClientOptions): LanguageClient;
@@ -0,0 +1,14 @@
1
+ import { type VNodeChild } from 'vue';
2
+ /** Documentation as a language server sends it: Markdown or plain text, or a code block (`MarkedString`). */
3
+ export type Markup = string | {
4
+ kind?: string;
5
+ language?: string;
6
+ value: string;
7
+ };
8
+ /**
9
+ * Documentation for the hover box, completion info and parameter hints:
10
+ * Markdown's code blocks, lists, rules, headings, links, bold, italic and
11
+ * code are drawn; plain text stays as it is. Nothing is read as HTML.
12
+ * Returns plain text when there is nothing to draw.
13
+ */
14
+ export declare function lspMarkup(markup: Markup | Markup[]): string | (() => VNodeChild);
@@ -0,0 +1,14 @@
1
+ import { type PropType, type VNodeChild } from 'vue';
2
+ /** Draws what a render function returns: panels and widgets given by extensions. */
3
+ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
+ render: {
5
+ type: PropType<() => VNodeChild>;
6
+ required: true;
7
+ };
8
+ }>, () => VNodeChild, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
9
+ render: {
10
+ type: PropType<() => VNodeChild>;
11
+ required: true;
12
+ };
13
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
14
+ export default _default;
@@ -0,0 +1,63 @@
1
+ import { type CodeLanguage, type CodeTokenType } from '../language/language';
2
+ /** The part of a TextMate rule stack the editor uses: Shiki's `StateStack`. */
3
+ export interface ShikiStateStack {
4
+ equals(other: ShikiStateStack): boolean;
5
+ }
6
+ /** What the editor needs of a Shiki highlighter (`createHighlighter()` from `shiki`). */
7
+ export interface ShikiHighlighterLike {
8
+ getLanguage(name: string): {
9
+ tokenizeLine(line: string, state: ShikiStateStack | null, timeLimit?: number): {
10
+ tokens: Array<{
11
+ startIndex: number;
12
+ endIndex: number;
13
+ scopes: string[];
14
+ }>;
15
+ ruleStack: ShikiStateStack;
16
+ /** The time limit ran out before the end of the line. */
17
+ stoppedEarly?: boolean;
18
+ };
19
+ };
20
+ }
21
+ export interface ShikiLanguageOptions {
22
+ /** The name the editor and code blocks know it by; defaults to the Shiki language's. */
23
+ name?: string;
24
+ aliases?: string[];
25
+ /** How the language writes comments, for toggling them; Shiki doesn't say. */
26
+ comment?: {
27
+ line?: string;
28
+ block?: [open: string, close: string];
29
+ };
30
+ brackets?: string;
31
+ autoClose?: string;
32
+ indentAfter?: RegExp;
33
+ /**
34
+ * The token kind (syntax color) for a token's scopes, outermost first;
35
+ * return `undefined` to use the built-in mapping (`tokenTypeOfScopes`).
36
+ */
37
+ tokenType?: (scopes: readonly string[]) => CodeTokenType | null | undefined;
38
+ }
39
+ export interface ShikiState {
40
+ /** The grammar's state at the start of the line being read, or after the last line. */
41
+ stack: ShikiStateStack | null;
42
+ /** The tokens of the line being read; positions from `base`. */
43
+ line: {
44
+ text: string;
45
+ base: number;
46
+ ends: number[];
47
+ types: Array<CodeTokenType | null>;
48
+ } | null;
49
+ }
50
+ /** The kind a token with these scopes (outermost first, as Shiki gives them) is drawn as. */
51
+ export declare function tokenTypeOfScopes(scopes: readonly string[]): CodeTokenType | null;
52
+ /**
53
+ * Turns a language loaded into a Shiki highlighter into one the editor
54
+ * reads. Shiki's grammar does the reading; its scopes are drawn with the
55
+ * editor's own syntax colors, so the theme and dark mode apply as they do
56
+ * to the built-in languages.
57
+ *
58
+ * ```ts
59
+ * const highlighter = await createHighlighter({ langs: ['rust'], themes: [] })
60
+ * const rust = shikiLanguage(highlighter, 'rust', { comment: { line: '//' } })
61
+ * ```
62
+ */
63
+ export declare function shikiLanguage(highlighter: ShikiHighlighterLike, language: string, options?: ShikiLanguageOptions): CodeLanguage<ShikiState>;
@@ -0,0 +1,267 @@
1
+ import type { Component } from 'vue';
2
+ import type { CodeDiagnostic, CodeExtension } from './extension';
3
+ import type { CodeCommand } from './core/commands';
4
+ import type { CodeKeymap } from './core/keymap';
5
+ import type { CodeSearchQuery } from './core/search';
6
+ import type { CodeSelection } from './core/selection';
7
+ import type { CodeMessages } from './locale';
8
+ import type { CodeLanguage } from './language/language';
9
+ import type { CodeText } from './core/text';
10
+ import type { CodeState, CodeTransaction, CodeTransactionMeta, CodeTransactionResult } from './core/transaction';
11
+ export interface CodeEditorProps {
12
+ /** The code. `\r\n` and `\r` read as `\n`; the value handed back always uses `\n`. */
13
+ modelValue?: string;
14
+ /** `v-model.lazy`: hand the code back only when the editor loses focus. */
15
+ modelModifiers?: {
16
+ lazy?: boolean;
17
+ };
18
+ /**
19
+ * The text as a `CodeText` (`v-model:doc`). For large files: nothing is
20
+ * joined into one string on every key press.
21
+ */
22
+ doc?: CodeText;
23
+ selection?: CodeSelection;
24
+ /** Can be selected and copied, not changed. */
25
+ readonly?: boolean;
26
+ disabled?: boolean;
27
+ /** Shows line numbers. */
28
+ lineNumbers?: boolean;
29
+ /**
30
+ * The column left of the text: line numbers, fold toggles, and the
31
+ * problems' and extensions' markers. Off, problems are only underlined.
32
+ * On by default.
33
+ */
34
+ gutter?: boolean;
35
+ /** Tints the line with the cursor. */
36
+ activeLine?: boolean;
37
+ /** Columns per tab stop, also the width of one indent. */
38
+ tabSize?: number;
39
+ /** Indents with tabs instead of spaces. */
40
+ indentWithTabs?: boolean;
41
+ placeholder?: string;
42
+ /** The language: colors its tokens, and tells how to indent, comment and pair brackets. */
43
+ language?: CodeLanguage | null;
44
+ /**
45
+ * Reads the code for its colors in a worker, so a long file opened far
46
+ * down is colored without the page doing the reading. `true` uses the
47
+ * editor's own worker, which knows the built-in languages; a function
48
+ * makes your own (`serveCodeHighlighting` from `@dou-ui/code/worker`),
49
+ * called in the browser once the editor is mounted. The editor ends the
50
+ * worker when it unmounts or no longer uses it.
51
+ */
52
+ worker?: boolean | (() => Worker);
53
+ /** Typing an opening bracket or quote also types its partner. On by default. */
54
+ closeBrackets?: boolean;
55
+ /** Outlines the bracket next to the cursor and its partner. On by default. */
56
+ matchBrackets?: boolean;
57
+ /** The built-in search panel (Mod+F). On by default. */
58
+ searchable?: boolean;
59
+ /** Wraps long lines at the editor's width instead of scrolling sideways. */
60
+ wrap?: boolean;
61
+ /**
62
+ * Shows the whole text in small at the right, with the part in view
63
+ * marked: press it to go there, drag the mark to scroll. Left out when
64
+ * the editor is narrower than 480px.
65
+ */
66
+ minimap?: boolean;
67
+ /** Shows fold toggles beside the line numbers, and lets blocks be folded. On by default. */
68
+ foldable?: boolean;
69
+ /** Replaces any of the editor's texts, which otherwise follow DouUI's locale. */
70
+ messages?: Partial<CodeMessages>;
71
+ /**
72
+ * The bar of symbol keys below the editor, moved by its grip, shown on touch screens
73
+ * while the editor can be typed in. An array sets the keys that scroll;
74
+ * a string is a key that types itself. `false` leaves the bar out. On by default.
75
+ */
76
+ keys?: boolean | ReadonlyArray<CodeKey | string>;
77
+ /** Extra keys, tried before the built-in ones. */
78
+ keymap?: CodeKeymap;
79
+ /** `Tab` indents. Off, `Tab` moves the focus on as in a form, unless a completion or snippet is in use. On by default. */
80
+ tabIndents?: boolean;
81
+ /** Extensions: decorations, gutter columns, panels, linters and more. */
82
+ extensions?: CodeExtension[];
83
+ /**
84
+ * Problems to show in the text (underlined, marked in the gutter, with
85
+ * their fixes), for the text as it is when they are given; they move
86
+ * with later edits until new ones come.
87
+ */
88
+ diagnostics?: CodeDiagnostic[];
89
+ /**
90
+ * Where the completion list, hover text, parameter hints and touch
91
+ * handles render: above the page, in this element or selector (by
92
+ * default the global config's, else `body`), so a short editor never cuts
93
+ * them off. `false` keeps them inside the editor's frame.
94
+ */
95
+ teleport?: string | HTMLElement | false;
96
+ autofocus?: boolean;
97
+ ariaLabel?: string;
98
+ }
99
+ /** A key on the bar of symbols (`DouCodeKeys`). */
100
+ export interface CodeKey {
101
+ /** What the key shows, or its name when it shows an icon. */
102
+ label: string;
103
+ /** Typed when pressed, as from the keyboard: a bracket closes itself. Defaults to `label`. */
104
+ text?: string;
105
+ /** Run when pressed, instead of typing. */
106
+ command?: CodeCommand;
107
+ /** Drawn instead of the label. */
108
+ icon?: Component;
109
+ /** Held down, the key goes on. */
110
+ repeat?: boolean;
111
+ /** What screen readers read, when the label doesn't say it. */
112
+ ariaLabel?: string;
113
+ }
114
+ export interface CodeKeysProps {
115
+ /** The editor the keys type into. */
116
+ editor?: (Pick<CodeEditorExpose, 'run'> & Partial<Pick<CodeEditorExpose, 'focus'>>) | null;
117
+ /** The keys that scroll; a string is a key that types itself. The arrow keys at the end always stay. */
118
+ keys?: ReadonlyArray<CodeKey | string>;
119
+ messages?: Partial<CodeMessages>;
120
+ }
121
+ export interface CodeEditorEmits {
122
+ 'update:modelValue': [value: string];
123
+ 'update:doc': [value: CodeText];
124
+ 'update:selection': [value: CodeSelection];
125
+ /** Every change, after it is applied: typing, undo and new `v-model` values alike. `meta.action` says what made it. */
126
+ transaction: [result: CodeTransactionResult];
127
+ focus: [event: FocusEvent];
128
+ blur: [event: FocusEvent];
129
+ /** The folds changed: the lines that start one now, from 1. Edits that move a fold to another line count too. */
130
+ foldChange: [lines: number[]];
131
+ }
132
+ export interface CodeEditorExpose {
133
+ /** The text and selection now. */
134
+ readonly state: CodeState;
135
+ readonly doc: CodeText;
136
+ readonly selection: CodeSelection;
137
+ /**
138
+ * Makes a change: `run` adds changes to the transaction, which is applied
139
+ * and recorded for undo as one. Positions are in the text as it was when
140
+ * the transaction started. Returns what happened, also when nothing
141
+ * changed: `changed` is then `false` and nothing was applied.
142
+ */
143
+ transact: (run: (tr: CodeTransaction) => void, meta?: CodeTransactionMeta) => CodeTransactionResult;
144
+ /** Runs a command, e.g. `selectAll`, as if its key were pressed. */
145
+ run: (command: CodeCommand) => boolean;
146
+ undo: () => boolean;
147
+ redo: () => boolean;
148
+ readonly canUndo: boolean;
149
+ readonly canRedo: boolean;
150
+ /** Selects `anchor`–`head` (a cursor without `head`), or a whole selection, and scrolls it into view. */
151
+ select: (anchor: number | CodeSelection, head?: number) => void;
152
+ /** Scrolls a position (the main cursor by default) into view. */
153
+ scrollIntoView: (pos?: number) => void;
154
+ /** Where a position is drawn, relative to the viewport; `null` when its line isn't drawn. */
155
+ coordsAtPos: (pos: number) => {
156
+ left: number;
157
+ top: number;
158
+ bottom: number;
159
+ } | null;
160
+ /** The position nearest to a point relative to the viewport. */
161
+ posAtCoords: (point: {
162
+ x: number;
163
+ y: number;
164
+ }) => number;
165
+ focus: () => void;
166
+ blur: () => void;
167
+ /** Opens the search panel, filled with `query` or else the selected text; `false` when `searchable` is off. */
168
+ openSearch: (query?: Partial<CodeSearchQuery>) => boolean;
169
+ /** Closes the search panel; `false` when it wasn't open. */
170
+ closeSearch: () => boolean;
171
+ /** Folds the block starting at a line (from 1), or the one around the cursor; `false` when there is none. */
172
+ fold: (line?: number) => boolean;
173
+ /** Unfolds the folds that start at or hide a line, or the cursor's line. */
174
+ unfold: (line?: number) => boolean;
175
+ /** Folds every outermost block. */
176
+ foldAll: () => boolean;
177
+ /** Unfolds everything. */
178
+ unfoldAll: () => boolean;
179
+ /** The lines that start a fold now, from 1. */
180
+ readonly folds: number[];
181
+ /** The problems found now, by all linters and the `diagnostics` prop, in text order. */
182
+ readonly diagnostics: readonly CodeDiagnostic[];
183
+ }
184
+ export interface CodeInputProps {
185
+ /** The code; with one line, line breaks typed or pasted become spaces. */
186
+ modelValue?: string;
187
+ placeholder?: string;
188
+ /** Several lines: Enter breaks the line, and the box grows with the content. */
189
+ multiline?: boolean;
190
+ /**
191
+ * With `multiline`, the least and the most lines shown, written as for
192
+ * DouTextarea's `autosize`. Defaults to `{ minRows: 1, maxRows: 6 }`.
193
+ */
194
+ autosize?: {
195
+ minRows?: number;
196
+ maxRows?: number;
197
+ };
198
+ size?: 'sm' | 'md' | 'lg';
199
+ invalid?: boolean;
200
+ disabled?: boolean;
201
+ readonly?: boolean;
202
+ language?: CodeLanguage | null;
203
+ extensions?: CodeExtension[];
204
+ diagnostics?: CodeDiagnostic[];
205
+ closeBrackets?: boolean;
206
+ tabSize?: number;
207
+ keymap?: CodeKeymap;
208
+ /**
209
+ * Where the completion list, hover text and parameter hints render; above
210
+ * the page by default. `false` keeps them inside the box.
211
+ */
212
+ teleport?: string | HTMLElement | false;
213
+ /** The bar of symbol keys below the box, moved by its grip; off by default. */
214
+ keys?: boolean | ReadonlyArray<CodeKey | string>;
215
+ messages?: Partial<CodeMessages>;
216
+ autofocus?: boolean;
217
+ ariaLabel?: string;
218
+ }
219
+ export interface CodeInputEmits {
220
+ 'update:modelValue': [value: string];
221
+ /** Enter on one line, or Mod + Enter on several, when no completion is open. */
222
+ enter: [];
223
+ transaction: [result: CodeTransactionResult];
224
+ focus: [event: FocusEvent];
225
+ blur: [event: FocusEvent];
226
+ }
227
+ export interface CodeDiffProps {
228
+ /** The text before. */
229
+ original?: string;
230
+ /** The text after, bound with `v-model`; editable beside the original with `editable`. */
231
+ modelValue?: string;
232
+ language?: CodeLanguage | null;
233
+ /**
234
+ * `split` puts the two texts side by side, `inline` puts the changes in
235
+ * one column. `auto` (the default) is `split` when there is room (560px)
236
+ * and `inline` otherwise, as on a phone. Bound with `v-model:mode` when
237
+ * the toolbar's toggle should be kept.
238
+ */
239
+ mode?: 'split' | 'inline' | 'auto';
240
+ /** Lets the modified text be edited, side by side; the inline view is always read-only. */
241
+ editable?: boolean;
242
+ /**
243
+ * Hides runs of unchanged lines behind a bar that shows them, keeping
244
+ * `context` lines (3 by default, at least 1) next to each change, when
245
+ * at least `minLines` (4 by default) would be hidden. On by default.
246
+ */
247
+ collapseUnchanged?: boolean | {
248
+ context?: number;
249
+ minLines?: number;
250
+ };
251
+ /** Treats lines that differ only in spaces as unchanged. */
252
+ ignoreWhitespace?: boolean;
253
+ /** Marks the words that changed inside changed lines. On by default. */
254
+ words?: boolean;
255
+ /** Wraps long lines in the inline view; side by side, lines never wrap, to stay aligned. */
256
+ wrap?: boolean;
257
+ /** Extensions of the modified side, side by side only. */
258
+ extensions?: CodeExtension[];
259
+ tabSize?: number;
260
+ /** The toolbar above: change count, previous and next, expand, and the view toggle. On by default. */
261
+ toolbar?: boolean;
262
+ messages?: Partial<CodeMessages>;
263
+ }
264
+ export interface CodeDiffEmits {
265
+ 'update:modelValue': [value: string];
266
+ 'update:mode': [mode: 'split' | 'inline'];
267
+ }
@@ -0,0 +1,12 @@
1
+ /** A replacement within a string: `from`–`to` of the old string became `insert`. */
2
+ export interface TextDiff {
3
+ from: number;
4
+ to: number;
5
+ insert: string;
6
+ }
7
+ /**
8
+ * The one replacement that turns `old` into `next`. When text repeats (an
9
+ * `a` typed next to an `a`), the change is placed at `at`, the old caret,
10
+ * which is where typing happens. Surrogate pairs are never split.
11
+ */
12
+ export declare function diffText(old: string, next: string, at?: number): TextDiff | null;
@@ -0,0 +1,55 @@
1
+ import type { ChangeSet } from '../core/changes';
2
+ import { type CodeText } from '../core/text';
3
+ import type { Measure } from './measure';
4
+ /** How a line is cut into rows: where each row after the first starts, and how far those rows are indented. */
5
+ export interface WrappedLine {
6
+ readonly breaks: readonly number[];
7
+ readonly indent: number;
8
+ }
9
+ export declare const UNWRAPPED: WrappedLine;
10
+ /**
11
+ * Cuts a line into rows no wider than `width`. Rows break after spaces and
12
+ * opening brackets, commas and semicolons, before a `.`, or between
13
+ * characters of scripts written without spaces; a word longer than
14
+ * a row is cut where it overflows. Rows after the first line up with the
15
+ * line's indentation, unless that leaves too little room.
16
+ */
17
+ export declare function wrapLine(text: string, width: number, measure: Measure): WrappedLine;
18
+ /** The row of a line that column `col` is drawn on. A column right at a break starts the next row. */
19
+ export declare function rowOfCol(wrapped: WrappedLine, col: number): number;
20
+ /**
21
+ * Where each line sits, counted in rows: a wrapped line takes several and a
22
+ * folded line none. When every line is one row, nothing is stored and the
23
+ * answers are plain arithmetic.
24
+ */
25
+ export declare class LineLayout {
26
+ readonly lines: number;
27
+ /** Rows before each line, as a Fenwick tree over the rows of each line. */
28
+ private tree;
29
+ private rows;
30
+ readonly total: number;
31
+ constructor(lines: number,
32
+ /** Rows of each line (index `n - 1`), or `null` when none wraps. */
33
+ wrapRows: ArrayLike<number> | null,
34
+ /** Hidden lines, as sorted inclusive ranges. */
35
+ hidden: ReadonlyArray<readonly [number, number]>);
36
+ /** Whether every line is one row. */
37
+ get uniform(): boolean;
38
+ /** How many rows line `n` takes; `0` when it is hidden. */
39
+ rowsOf(n: number): number;
40
+ /** The row line `n` starts on, from 0. */
41
+ rowOf(n: number): number;
42
+ /** The line drawn on row `row`, and which of its rows that is; clamped to the text. */
43
+ lineAtRow(row: number): {
44
+ n: number;
45
+ sub: number;
46
+ };
47
+ /** Whether line `n` is drawn. */
48
+ shown(n: number): boolean;
49
+ }
50
+ /**
51
+ * Moves per-line values (rows of each line) along with an edit, working
52
+ * out `valueOf` again only for the lines it touched. Returns `false` when
53
+ * starting over is cheaper or the values no longer fit the text.
54
+ */
55
+ export declare function updateRows(rows: number[], before: CodeText, after: CodeText, changes: ChangeSet, valueOf: (text: string) => number): boolean;
@@ -0,0 +1,22 @@
1
+ export declare class Measure {
2
+ private readonly probe;
3
+ /** Width of one monospace cell. */
4
+ cell: number;
5
+ lineHeight: number;
6
+ /** Space above the first line and below the last (`--dou-code-editor-padding-y`). */
7
+ padY: number;
8
+ /** Space before and after each line (`--dou-code-editor-padding-x`). */
9
+ padX: number;
10
+ tabSize: number;
11
+ private widths;
12
+ constructor(probe: () => HTMLElement | null | undefined);
13
+ /** Reads the cell width and line height again, e.g. after the font changed. */
14
+ refresh(tabSize: number): void;
15
+ /** Width of one character as drawn. */
16
+ width(cluster: string): number;
17
+ private tab;
18
+ /** The x of column `col` in `text`, from the line's start. */
19
+ x(text: string, col: number): number;
20
+ /** The column nearest to `x` in `text`, on a character boundary. */
21
+ col(text: string, x: number): number;
22
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The part of the window in view, above a phone's keyboard and inside a
3
+ * pinch zoom, in the coordinates `getBoundingClientRect` gives.
4
+ *
5
+ * Browsers disagree on what those coordinates are relative to: the layout
6
+ * viewport (so the visual viewport sits `offsetTop` into them), or the
7
+ * visual viewport itself (iOS Safari, where adding `offsetTop` counts the
8
+ * scroll twice). The page's own box tells which: the visual viewport's place
9
+ * in the page, plus where the page starts in those coordinates.
10
+ */
11
+ export declare function visibleViewport(): {
12
+ left: number;
13
+ top: number;
14
+ width: number;
15
+ height: number;
16
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import type { CodeLanguage } from '../language/language';
2
+ export type { CodeLanguage };
3
+ export { defineCodeLanguage, copyPlain, samePlain } from '../language/language';
4
+ export type { CodeLanguageSpec, CodeTokenType } from '../language/language';
5
+ export type { CodeStream } from '../language/stream';
6
+ export { createJavaScript, javascript, jsx, tsx, typescript } from '../languages/javascript';
7
+ export { createCss, css, scss } from '../languages/css';
8
+ export { json } from '../languages/json';
9
+ export { createHtml, html, vue } from '../languages/html';
10
+ export { createMarkdown, markdown } from '../languages/markdown';
11
+ export { python } from '../languages/python';
12
+ export { shell } from '../languages/shell';
13
+ export { sql } from '../languages/sql';
14
+ export { yaml } from '../languages/yaml';
15
+ /**
16
+ * Reads code in a worker for `DouCodeEditor`'s `worker`, so a long file is
17
+ * colored without the page doing the reading. Call it in the worker's own
18
+ * module with the languages the editors use:
19
+ *
20
+ * ```ts
21
+ * // code-worker.ts
22
+ * import { css, serveCodeHighlighting, typescript } from '@dou-ui/code/worker'
23
+ *
24
+ * serveCodeHighlighting([typescript, css])
25
+ * ```
26
+ *
27
+ * One worker serves every editor that is given it. A language works here
28
+ * when its states are plain data (the built-in ones are); those read by
29
+ * the Shiki adapter stay on the page.
30
+ */
31
+ export declare function serveCodeHighlighting(languages: readonly CodeLanguage[], scope?: {
32
+ postMessage(message: unknown): void;
33
+ addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
34
+ }): void;
@@ -0,0 +1,27 @@
1
+ // src/view/input.ts
2
+ var isHigh = (code) => code >= 55296 && code < 56320;
3
+ var isLow = (code) => code >= 56320 && code < 57344;
4
+ /**
5
+ * The one replacement that turns `old` into `next`. When text repeats (an
6
+ * `a` typed next to an `a`), the change is placed at `at`, the old caret,
7
+ * which is where typing happens. Surrogate pairs are never split.
8
+ */
9
+ function diffText(old, next, at = old.length) {
10
+ if (old === next) return null;
11
+ const max = Math.min(old.length, next.length);
12
+ let start = 0;
13
+ while (start < max && old.charCodeAt(start) === next.charCodeAt(start)) start++;
14
+ start = Math.min(start, at);
15
+ if (start > 0 && isHigh(old.charCodeAt(start - 1))) start--;
16
+ let end = 0;
17
+ while (end < old.length - start && end < next.length - start && old.charCodeAt(old.length - 1 - end) === next.charCodeAt(next.length - 1 - end)) end++;
18
+ if (end > 0 && isLow(old.charCodeAt(old.length - end))) end--;
19
+ return {
20
+ from: start,
21
+ to: old.length - end,
22
+ insert: next.slice(start, next.length - end)
23
+ };
24
+ }
25
+ export { diffText };
26
+
27
+ //# sourceMappingURL=input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.js","names":[],"sources":["../../src/view/input.ts"],"sourcesContent":["/** A replacement within a string: `from`–`to` of the old string became `insert`. */\nexport interface TextDiff {\n from: number\n to: number\n insert: string\n}\n\nconst isHigh = (code: number) => code >= 0xd800 && code < 0xdc00\nconst isLow = (code: number) => code >= 0xdc00 && code < 0xe000\n\n/**\n * The one replacement that turns `old` into `next`. When text repeats (an\n * `a` typed next to an `a`), the change is placed at `at`, the old caret,\n * which is where typing happens. Surrogate pairs are never split.\n */\nexport function diffText(old: string, next: string, at = old.length): TextDiff | null {\n if (old === next) return null\n const max = Math.min(old.length, next.length)\n let start = 0\n while (start < max && old.charCodeAt(start) === next.charCodeAt(start)) start++\n start = Math.min(start, at)\n if (start > 0 && isHigh(old.charCodeAt(start - 1))) start--\n let end = 0\n while (\n end < old.length - start &&\n end < next.length - start &&\n old.charCodeAt(old.length - 1 - end) === next.charCodeAt(next.length - 1 - end)\n )\n end++\n if (end > 0 && isLow(old.charCodeAt(old.length - end))) end--\n return { from: start, to: old.length - end, insert: next.slice(start, next.length - end) }\n}\n"],"mappings":";AAOA,IAAM,UAAU,SAAiB,QAAQ,SAAU,OAAO;AAC1D,IAAM,SAAS,SAAiB,QAAQ,SAAU,OAAO;;;;;;AAOzD,SAAgB,SAAS,KAAa,MAAc,KAAK,IAAI,QAAyB;CACpF,IAAI,QAAQ,MAAM,OAAO;CACzB,MAAM,MAAM,KAAK,IAAI,IAAI,QAAQ,KAAK,MAAM;CAC5C,IAAI,QAAQ;CACZ,OAAO,QAAQ,OAAO,IAAI,WAAW,KAAK,MAAM,KAAK,WAAW,KAAK,GAAG;CACxE,QAAQ,KAAK,IAAI,OAAO,EAAE;CAC1B,IAAI,QAAQ,KAAK,OAAO,IAAI,WAAW,QAAQ,CAAC,CAAC,GAAG;CACpD,IAAI,MAAM;CACV,OACE,MAAM,IAAI,SAAS,SACnB,MAAM,KAAK,SAAS,SACpB,IAAI,WAAW,IAAI,SAAS,IAAI,GAAG,MAAM,KAAK,WAAW,KAAK,SAAS,IAAI,GAAG,GAE9E;CACF,IAAI,MAAM,KAAK,MAAM,IAAI,WAAW,IAAI,SAAS,GAAG,CAAC,GAAG;CACxD,OAAO;EAAE,MAAM;EAAO,IAAI,IAAI,SAAS;EAAK,QAAQ,KAAK,MAAM,OAAO,KAAK,SAAS,GAAG;CAAE;AAC3F"}