@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.
- package/LICENSE +21 -0
- package/README.md +10 -2
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/assets/default-BZBMZKf_.js.map +1 -0
- package/dist/code-diff.js +6 -0
- package/dist/code-diff.js.map +1 -0
- package/dist/code-diff.vue_vue_type_script_setup_true_lang.js +792 -0
- package/dist/code-diff.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/code-editor.js +6 -0
- package/dist/code-editor.js.map +1 -0
- package/dist/code-editor.vue_vue_type_script_setup_true_lang.js +5078 -0
- package/dist/code-editor.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/code-input.js +6 -0
- package/dist/code-input.js.map +1 -0
- package/dist/code-input.vue_vue_type_script_setup_true_lang.js +237 -0
- package/dist/code-input.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/code-keys.js +42 -0
- package/dist/code-keys.js.map +1 -0
- package/dist/code-keys.vue_vue_type_script_setup_true_lang.js +244 -0
- package/dist/code-keys.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/code-keys2.js +6 -0
- package/dist/code-keys2.js.map +1 -0
- package/dist/collaboration/index.js +255 -0
- package/dist/collaboration/index.js.map +1 -0
- package/dist/completion/match.js +55 -0
- package/dist/completion/match.js.map +1 -0
- package/dist/completion/snippet.js +71 -0
- package/dist/completion/snippet.js.map +1 -0
- package/dist/core/brackets.js +55 -0
- package/dist/core/brackets.js.map +1 -0
- package/dist/core/changes.js +185 -0
- package/dist/core/changes.js.map +1 -0
- package/dist/core/chars.js +130 -0
- package/dist/core/chars.js.map +1 -0
- package/dist/core/commands.js +910 -0
- package/dist/core/commands.js.map +1 -0
- package/dist/core/diff.js +215 -0
- package/dist/core/diff.js.map +1 -0
- package/dist/core/folding.js +87 -0
- package/dist/core/folding.js.map +1 -0
- package/dist/core/history.js +74 -0
- package/dist/core/history.js.map +1 -0
- package/dist/core/keymap.js +326 -0
- package/dist/core/keymap.js.map +1 -0
- package/dist/core/search.js +91 -0
- package/dist/core/search.js.map +1 -0
- package/dist/core/selection.js +88 -0
- package/dist/core/selection.js.map +1 -0
- package/dist/core/text.js +320 -0
- package/dist/core/text.js.map +1 -0
- package/dist/core/transaction.js +98 -0
- package/dist/core/transaction.js.map +1 -0
- package/dist/extension.js +16 -0
- package/dist/extension.js.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/language/highlighter.js +336 -0
- package/dist/language/highlighter.js.map +1 -0
- package/dist/language/language.js +138 -0
- package/dist/language/language.js.map +1 -0
- package/dist/language/stream.js +112 -0
- package/dist/language/stream.js.map +1 -0
- package/dist/language/to-html.js +36 -0
- package/dist/language/to-html.js.map +1 -0
- package/dist/language/worker-client.js +198 -0
- package/dist/language/worker-client.js.map +1 -0
- package/dist/language/worker-protocol.js +48 -0
- package/dist/language/worker-protocol.js.map +1 -0
- package/dist/languages/css.js +128 -0
- package/dist/languages/css.js.map +1 -0
- package/dist/languages/html.js +175 -0
- package/dist/languages/html.js.map +1 -0
- package/dist/languages/javascript.js +300 -0
- package/dist/languages/javascript.js.map +1 -0
- package/dist/languages/json.js +45 -0
- package/dist/languages/json.js.map +1 -0
- package/dist/languages/markdown.js +82 -0
- package/dist/languages/markdown.js.map +1 -0
- package/dist/languages/python.js +88 -0
- package/dist/languages/python.js.map +1 -0
- package/dist/languages/shell.js +153 -0
- package/dist/languages/shell.js.map +1 -0
- package/dist/languages/sql.js +91 -0
- package/dist/languages/sql.js.map +1 -0
- package/dist/languages/yaml.js +85 -0
- package/dist/languages/yaml.js.map +1 -0
- package/dist/locale.js +158 -0
- package/dist/locale.js.map +1 -0
- package/dist/lsp/index.js +715 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp/markup.js +139 -0
- package/dist/lsp/markup.js.map +1 -0
- package/dist/render-part.js +14 -0
- package/dist/render-part.js.map +1 -0
- package/dist/shiki/index.js +140 -0
- package/dist/shiki/index.js.map +1 -0
- package/dist/style.css +1 -0
- package/dist/style.d.ts +1 -0
- package/dist/style.js +4 -0
- package/dist/types/code-diff.vue.d.ts +45 -0
- package/dist/types/code-editor.vue.d.ts +43 -0
- package/dist/types/code-input.vue.d.ts +32 -0
- package/dist/types/code-keys.d.ts +9 -0
- package/dist/types/code-keys.vue.d.ts +8 -0
- package/dist/types/collaboration/index.d.ts +36 -0
- package/dist/types/completion/match.d.ts +13 -0
- package/dist/types/completion/snippet.d.ts +17 -0
- package/dist/types/core/brackets.d.ts +15 -0
- package/dist/types/core/changes.d.ts +52 -0
- package/dist/types/core/chars.d.ts +24 -0
- package/dist/types/core/commands.d.ts +199 -0
- package/dist/types/core/diff.d.ts +52 -0
- package/dist/types/core/folding.d.ts +23 -0
- package/dist/types/core/history.d.ts +24 -0
- package/dist/types/core/keymap.d.ts +29 -0
- package/dist/types/core/search.d.ts +37 -0
- package/dist/types/core/selection.d.ts +28 -0
- package/dist/types/core/text.d.ts +79 -0
- package/dist/types/core/transaction.d.ts +65 -0
- package/dist/types/extension.d.ts +321 -0
- package/dist/types/index.d.ts +159 -0
- package/dist/types/language/highlighter.d.ts +99 -0
- package/dist/types/language/language.d.ts +100 -0
- package/dist/types/language/stream.d.ts +56 -0
- package/dist/types/language/to-html.d.ts +17 -0
- package/dist/types/language/worker-client.d.ts +52 -0
- package/dist/types/language/worker-protocol.d.ts +50 -0
- package/dist/types/languages/css.d.ts +17 -0
- package/dist/types/languages/html.d.ts +34 -0
- package/dist/types/languages/javascript.d.ts +29 -0
- package/dist/types/languages/json.d.ts +7 -0
- package/dist/types/languages/markdown.d.ts +17 -0
- package/dist/types/languages/python.d.ts +9 -0
- package/dist/types/languages/shell.d.ts +11 -0
- package/dist/types/languages/sql.d.ts +9 -0
- package/dist/types/languages/yaml.d.ts +14 -0
- package/dist/types/locale.d.ts +79 -0
- package/dist/types/lsp/index.d.ts +119 -0
- package/dist/types/lsp/markup.d.ts +14 -0
- package/dist/types/render-part.d.ts +14 -0
- package/dist/types/shiki/index.d.ts +63 -0
- package/dist/types/types.d.ts +267 -0
- package/dist/types/view/input.d.ts +12 -0
- package/dist/types/view/layout.d.ts +55 -0
- package/dist/types/view/measure.d.ts +22 -0
- package/dist/types/view/viewport.d.ts +16 -0
- package/dist/types/view/viewport.test.d.ts +1 -0
- package/dist/types/worker/default.d.ts +1 -0
- package/dist/types/worker/index.d.ts +34 -0
- package/dist/view/input.js +27 -0
- package/dist/view/input.js.map +1 -0
- package/dist/view/layout.js +194 -0
- package/dist/view/layout.js.map +1 -0
- package/dist/view/measure.js +104 -0
- package/dist/view/measure.js.map +1 -0
- package/dist/view/viewport.js +31 -0
- package/dist/view/viewport.js.map +1 -0
- package/dist/worker/default.js +20 -0
- package/dist/worker/default.js.map +1 -0
- package/dist/worker/index.js +139 -0
- package/dist/worker/index.js.map +1 -0
- package/package.json +88 -4
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ChangeSet } from '../core/changes';
|
|
2
|
+
import type { CodeText } from '../core/text';
|
|
3
|
+
import { type CodeLanguage, type CodeLineTokens } from './language';
|
|
4
|
+
export interface CodeHighlighterOptions {
|
|
5
|
+
tabSize?: number;
|
|
6
|
+
/** Lines between kept start states. */
|
|
7
|
+
interval?: number;
|
|
8
|
+
/** Lines whose tokens are kept. */
|
|
9
|
+
cache?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Keeps the tokens of a text up to date as it changes.
|
|
13
|
+
*
|
|
14
|
+
* Reading goes down from the top. It keeps the state at the start of
|
|
15
|
+
* every 32nd line read, and the tokens of the lines drawn lately; a line
|
|
16
|
+
* whose tokens are gone is read again from the kept state above it. So a
|
|
17
|
+
* text of a million lines, all read, holds some thirty thousand states
|
|
18
|
+
* and a few thousand lines' tokens.
|
|
19
|
+
*
|
|
20
|
+
* After an edit, lines before it keep everything; reading resumes at the
|
|
21
|
+
* edited line and stops as soon as a line after the edit starts in the
|
|
22
|
+
* same state as before, because from there on nothing can differ. Typing
|
|
23
|
+
* inside a function rereads one line; opening a comment rereads up to
|
|
24
|
+
* where it closes.
|
|
25
|
+
*
|
|
26
|
+
* Lines are read only when asked for (the ones in view and those before
|
|
27
|
+
* them); the rest wait for idle time, or come from a worker through
|
|
28
|
+
* `adopt`, so opening a long file costs nothing up front.
|
|
29
|
+
*/
|
|
30
|
+
export declare class CodeHighlighter<S = unknown> {
|
|
31
|
+
readonly language: CodeLanguage<S>;
|
|
32
|
+
private doc;
|
|
33
|
+
readonly tabSize: number;
|
|
34
|
+
private readonly interval;
|
|
35
|
+
private readonly cacheSize;
|
|
36
|
+
/** Kept start states: `lines[k]` starts in `states[k]`; the first is line 0. */
|
|
37
|
+
private lines;
|
|
38
|
+
private states;
|
|
39
|
+
/** Lines above this index are read; `tip` is the state line `read` starts in. */
|
|
40
|
+
private read;
|
|
41
|
+
private tip;
|
|
42
|
+
/**
|
|
43
|
+
* What was read past an edit, moved to where those lines are now. Once
|
|
44
|
+
* reading reaches one of these lines in the same state, everything up to
|
|
45
|
+
* `oldEnd` (which starts in `oldTip`) is read again for free.
|
|
46
|
+
*/
|
|
47
|
+
private oldLines;
|
|
48
|
+
private oldStates;
|
|
49
|
+
private oldAt;
|
|
50
|
+
private oldEnd;
|
|
51
|
+
private oldTip;
|
|
52
|
+
/** Where reading again from a kept state last got to, so going down line by line doesn't start over each time. */
|
|
53
|
+
private walk;
|
|
54
|
+
/** Tokens by line index, oldest first. */
|
|
55
|
+
private cache;
|
|
56
|
+
constructor(language: CodeLanguage<S>, doc: CodeText, options?: number | CodeHighlighterOptions);
|
|
57
|
+
/** How many lines from the top are read. */
|
|
58
|
+
get frontier(): number;
|
|
59
|
+
/** The text being read. */
|
|
60
|
+
get text(): CodeText;
|
|
61
|
+
/** Takes in a new text, made from the old one by `changes`. Without them, starts over. */
|
|
62
|
+
update(doc: CodeText, changes?: ChangeSet): void;
|
|
63
|
+
private reset;
|
|
64
|
+
private dropOld;
|
|
65
|
+
/** The index of the last kept state at or above line `i`. */
|
|
66
|
+
private keptAt;
|
|
67
|
+
/** Where to start reading line `i` again from: a kept state, or where the last such reading got to. */
|
|
68
|
+
private from;
|
|
69
|
+
/** The state line `i` starts in, read from the kept state above it in `doc`. */
|
|
70
|
+
private stateIn;
|
|
71
|
+
private remember;
|
|
72
|
+
/** Reads the next unread line, keeping its tokens with `keep`. */
|
|
73
|
+
private step;
|
|
74
|
+
/**
|
|
75
|
+
* The tokens of line `n` (from 1), reading up to it if it takes no more
|
|
76
|
+
* than `limit` lines; `null` when it would take more, so the caller
|
|
77
|
+
* draws plain text and lets idle time catch up.
|
|
78
|
+
*/
|
|
79
|
+
line(n: number, limit?: number): CodeLineTokens | null;
|
|
80
|
+
/** The state at the start of line `n`, reading up to it. */
|
|
81
|
+
stateAt(n: number): S;
|
|
82
|
+
/** The language active at the start of line `n`: an inner one inside a nesting language. */
|
|
83
|
+
languageAt(n: number): CodeLanguage;
|
|
84
|
+
/** Reads ahead until `deadline` (a `performance.now()` time) or line `until`; returns whether it read any. */
|
|
85
|
+
work(deadline: number, until?: number): boolean;
|
|
86
|
+
/** Whether every line up to `n` is read. */
|
|
87
|
+
ready(n: number): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* The kept start states from line `from` (an index) on, as
|
|
90
|
+
* `[line, state]` pairs, ending with the line reading is at.
|
|
91
|
+
*/
|
|
92
|
+
checkpoints(from?: number): Array<[line: number, state: S]>;
|
|
93
|
+
/**
|
|
94
|
+
* Takes in start states read elsewhere (a worker reading the same text):
|
|
95
|
+
* `[line, state]` pairs in order, the last one where that reading is.
|
|
96
|
+
* Those past what is read here are kept as read.
|
|
97
|
+
*/
|
|
98
|
+
adopt(points: ReadonlyArray<readonly [line: number, state: S]>): void;
|
|
99
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { CodeStream } from './stream';
|
|
2
|
+
/**
|
|
3
|
+
* What a token is. The editor draws each kind with its
|
|
4
|
+
* `--dou-color-syntax-*` color, so a theme recolors code without
|
|
5
|
+
* highlighting it again.
|
|
6
|
+
*/
|
|
7
|
+
export type CodeTokenType = 'keyword' | 'string' | 'number' | 'comment' | 'function' | 'type' | 'variable' | 'property' | 'operator' | 'punctuation' | 'tag' | 'attribute' | 'meta' | 'invalid' | 'heading' | 'strong' | 'emphasis' | 'link';
|
|
8
|
+
/** Every token kind, in a fixed order; tokens are stored by their index here. */
|
|
9
|
+
export declare const tokenTypes: readonly CodeTokenType[];
|
|
10
|
+
export interface CodeLanguageSpec<S> {
|
|
11
|
+
/** The name, also matched by `languageFor('…')` and code block `lang`. */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Other names, such as file extensions: `['js', 'mjs']`. */
|
|
14
|
+
aliases?: string[];
|
|
15
|
+
/** The state at the start of the text. Plain data: objects, arrays, strings, numbers. */
|
|
16
|
+
startState?: () => S;
|
|
17
|
+
/**
|
|
18
|
+
* Reads one token from the stream (at least one character) and returns
|
|
19
|
+
* its kind, or `null` for plain text. May change `state`, which carries
|
|
20
|
+
* over to the next token and the next line.
|
|
21
|
+
*/
|
|
22
|
+
token: (stream: CodeStream, state: S) => CodeTokenType | null;
|
|
23
|
+
/** Called for an empty line, for states that end at a line's end. */
|
|
24
|
+
blankLine?: (state: S) => void;
|
|
25
|
+
/** Copies a state. By default a deep copy of its plain objects and arrays. */
|
|
26
|
+
copyState?: (state: S) => S;
|
|
27
|
+
/** Whether two states are the same. By default compares their plain data. */
|
|
28
|
+
sameState?: (a: S, b: S) => boolean;
|
|
29
|
+
/** How the language writes comments, for toggling them. */
|
|
30
|
+
comment?: {
|
|
31
|
+
line?: string;
|
|
32
|
+
block?: [open: string, close: string];
|
|
33
|
+
};
|
|
34
|
+
/** Bracket pairs, for matching and indenting. Default `'()[]{}'`. */
|
|
35
|
+
brackets?: string;
|
|
36
|
+
/** Characters, as one string, that get their closing partner typed with them. Default the brackets' openers and `'"`. */
|
|
37
|
+
autoClose?: string;
|
|
38
|
+
/** A line before the cursor that matches this gets one more indent on Enter, besides an open bracket. */
|
|
39
|
+
indentAfter?: RegExp;
|
|
40
|
+
/** The language that is active in a state, for languages that hold others (a `<script>` in HTML). */
|
|
41
|
+
languageAt?: (state: S) => CodeLanguage | null;
|
|
42
|
+
/**
|
|
43
|
+
* The languages this one may hold, for languages with `languageAt`. A
|
|
44
|
+
* worker sends states with the languages in them by name; these are the
|
|
45
|
+
* ones the names are looked up in.
|
|
46
|
+
*/
|
|
47
|
+
nested?: readonly CodeLanguage[];
|
|
48
|
+
}
|
|
49
|
+
/** A language: how to read its tokens, and a few facts for editing it. */
|
|
50
|
+
export interface CodeLanguage<S = any> {
|
|
51
|
+
readonly name: string;
|
|
52
|
+
readonly aliases: readonly string[];
|
|
53
|
+
startState(): S;
|
|
54
|
+
token(stream: CodeStream, state: S): CodeTokenType | null;
|
|
55
|
+
blankLine?(state: S): void;
|
|
56
|
+
copyState(state: S): S;
|
|
57
|
+
sameState(a: S, b: S): boolean;
|
|
58
|
+
readonly comment: {
|
|
59
|
+
line?: string;
|
|
60
|
+
block?: [string, string];
|
|
61
|
+
};
|
|
62
|
+
readonly brackets: string;
|
|
63
|
+
readonly autoClose: string;
|
|
64
|
+
readonly indentAfter?: RegExp;
|
|
65
|
+
languageAt(state: S): CodeLanguage | null;
|
|
66
|
+
readonly nested: readonly CodeLanguage[];
|
|
67
|
+
}
|
|
68
|
+
/** Copies arrays and plain objects; everything else (languages among them) is shared. */
|
|
69
|
+
export declare function copyPlain<T>(value: T): T;
|
|
70
|
+
/** Compares arrays and plain objects by their content; everything else by identity. */
|
|
71
|
+
export declare function samePlain(a: unknown, b: unknown): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Defines a language from a tokenizer that reads one line at a time.
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* const ini = defineCodeLanguage({
|
|
77
|
+
* name: 'ini',
|
|
78
|
+
* token(stream) {
|
|
79
|
+
* if (stream.sol() && stream.match(/^\s*[;#].*$/)) return 'comment'
|
|
80
|
+
* if (stream.sol() && stream.match(/^\s*\[[^\]]*\]/)) return 'keyword'
|
|
81
|
+
* if (stream.match(/^[\w.-]+(?=\s*=)/)) return 'property'
|
|
82
|
+
* stream.next()
|
|
83
|
+
* return null
|
|
84
|
+
* },
|
|
85
|
+
* })
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function defineCodeLanguage<S = Record<string, never>>(spec: CodeLanguageSpec<S>): CodeLanguage<S>;
|
|
89
|
+
/** The language among `languages` named `name` or one of its aliases, ignoring case. */
|
|
90
|
+
export declare function languageFor(languages: readonly CodeLanguage[], name: string | undefined): CodeLanguage | null;
|
|
91
|
+
/**
|
|
92
|
+
* One line's tokens, as pairs of numbers: where each token ends and its
|
|
93
|
+
* kind's index in `tokenTypes` (`-1` for plain text). Each token starts
|
|
94
|
+
* where the one before ended.
|
|
95
|
+
*/
|
|
96
|
+
export type CodeLineTokens = readonly number[];
|
|
97
|
+
/** Reads one line from `state` (which it changes into the state after the line). */
|
|
98
|
+
export declare function tokenizeLine<S>(language: CodeLanguage<S>, text: string, state: S, tabSize?: number): CodeLineTokens;
|
|
99
|
+
/** A line's tokens as `[text, kind]` pairs, kind `null` for plain text. */
|
|
100
|
+
export declare function lineParts(text: string, tokens: CodeLineTokens | null | undefined): Array<[text: string, type: CodeTokenType | null]>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cursor over one line, handed to a language's `token` function. The
|
|
3
|
+
* function reads one token from `pos` onward (at least one character) and
|
|
4
|
+
* returns its kind; whatever it read becomes that token.
|
|
5
|
+
*/
|
|
6
|
+
export declare class CodeStream {
|
|
7
|
+
/** The whole line. */
|
|
8
|
+
readonly string: string;
|
|
9
|
+
/** Columns per tab stop, for `indentation()`. */
|
|
10
|
+
readonly tabSize: number;
|
|
11
|
+
/** Where the current token starts. */
|
|
12
|
+
start: number;
|
|
13
|
+
/** Where reading continues. */
|
|
14
|
+
pos: number;
|
|
15
|
+
/** Where this stream ends; a nesting language ends it early, e.g. at `</script>`. */
|
|
16
|
+
end: number;
|
|
17
|
+
constructor(
|
|
18
|
+
/** The whole line. */
|
|
19
|
+
string: string,
|
|
20
|
+
/** Columns per tab stop, for `indentation()`. */
|
|
21
|
+
tabSize?: number);
|
|
22
|
+
/** Whether the line is read to its end. */
|
|
23
|
+
eol(): boolean;
|
|
24
|
+
/** Whether the stream is at the line's first character that isn't whitespace. */
|
|
25
|
+
sol(): boolean;
|
|
26
|
+
/** The next character, without reading it. */
|
|
27
|
+
peek(): string | undefined;
|
|
28
|
+
/** Reads and returns the next character. */
|
|
29
|
+
next(): string | undefined;
|
|
30
|
+
/** Reads the next character if it is `match` (a character, a set as a regex, or a test). */
|
|
31
|
+
eat(match: string | RegExp | ((ch: string) => boolean)): string | undefined;
|
|
32
|
+
/** Reads characters while they match; returns whether it read any. */
|
|
33
|
+
eatWhile(match: string | RegExp | ((ch: string) => boolean)): boolean;
|
|
34
|
+
/** Reads whitespace. */
|
|
35
|
+
eatSpace(): boolean;
|
|
36
|
+
/** Reads to the end of the stream. */
|
|
37
|
+
skipToEnd(): void;
|
|
38
|
+
/** Reads up to (not including) the next `text`; returns whether it was found. */
|
|
39
|
+
skipTo(text: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Reads `pattern` if the line continues with it. A string matches as is
|
|
42
|
+
* (`caseInsensitive` ignores case); a regex must start with `^` and
|
|
43
|
+
* returns its match. `consume: false` only looks.
|
|
44
|
+
*/
|
|
45
|
+
match(pattern: string, consume?: boolean, caseInsensitive?: boolean): boolean;
|
|
46
|
+
match(pattern: RegExp, consume?: boolean): RegExpMatchArray | null;
|
|
47
|
+
/** Steps back `n` characters. */
|
|
48
|
+
backUp(n: number): void;
|
|
49
|
+
/** The text of the current token so far. */
|
|
50
|
+
current(): string;
|
|
51
|
+
/** The line's indentation in columns. */
|
|
52
|
+
indentation(): number;
|
|
53
|
+
/** The text after the stream, to the line's end (also past `end`). */
|
|
54
|
+
rest(): string;
|
|
55
|
+
}
|
|
56
|
+
export declare const isSpace: (ch: string) => ch is " " | "\t";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type CodeLanguage } from './language';
|
|
2
|
+
/**
|
|
3
|
+
* Highlights a whole text as HTML: one `<span class="line">` per line,
|
|
4
|
+
* tokens as `<span class="dou-syntax-…">`, the same classes and colors as
|
|
5
|
+
* the code editor.
|
|
6
|
+
*/
|
|
7
|
+
export declare function highlightToHtml(code: string, language: CodeLanguage, tabSize?: number): string;
|
|
8
|
+
/**
|
|
9
|
+
* A highlighter for `DouCodeBlock` (its `highlight` prop, or once for the
|
|
10
|
+
* whole app in the ConfigProvider's `defaults`) that knows `languages`.
|
|
11
|
+
* A block in another language shows as plain text.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const highlight = createCodeHighlighter([javascript, typescript, css])
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function createCodeHighlighter(languages: readonly CodeLanguage[]): (code: string, lang: string) => string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ChangeSet } from '../core/changes';
|
|
2
|
+
import type { CodeText } from '../core/text';
|
|
3
|
+
import type { CodeLanguage } from './language';
|
|
4
|
+
/**
|
|
5
|
+
* The editor's side of a highlighting worker (`serveCodeHighlighting`).
|
|
6
|
+
* The text goes over the first time states far ahead are wanted (most
|
|
7
|
+
* texts never need it), in pieces between other work; every change
|
|
8
|
+
* follows it.
|
|
9
|
+
*/
|
|
10
|
+
export declare class SyntaxWorkerClient {
|
|
11
|
+
private readonly worker;
|
|
12
|
+
private readonly language;
|
|
13
|
+
/** The text as it is now. */
|
|
14
|
+
private readonly text;
|
|
15
|
+
private readonly tabSize;
|
|
16
|
+
private readonly handlers;
|
|
17
|
+
private readonly id;
|
|
18
|
+
/** Changes sent so far; the worker's answers name how many it had taken in. */
|
|
19
|
+
private version;
|
|
20
|
+
private asking;
|
|
21
|
+
private closed;
|
|
22
|
+
/** Sending the text: messages wait until it is all there. */
|
|
23
|
+
private sending;
|
|
24
|
+
private opened;
|
|
25
|
+
private queue;
|
|
26
|
+
private timer;
|
|
27
|
+
private readonly languages;
|
|
28
|
+
constructor(worker: Worker, language: CodeLanguage,
|
|
29
|
+
/** The text as it is now. */
|
|
30
|
+
text: () => CodeText, tabSize: number, handlers: {
|
|
31
|
+
states: (points: Array<[line: number, state: unknown]>) => void;
|
|
32
|
+
/** The worker hasn't the language named `missing`, or can't send its states (no `missing`). */
|
|
33
|
+
unsupported: (missing?: string) => void;
|
|
34
|
+
/** The worker could not run (it failed to load, or threw). */
|
|
35
|
+
failed: (error: unknown) => void;
|
|
36
|
+
});
|
|
37
|
+
private fail;
|
|
38
|
+
private post;
|
|
39
|
+
private open;
|
|
40
|
+
private listen;
|
|
41
|
+
/** Passes on a change made to the text, once the worker has it. */
|
|
42
|
+
change(changes: ChangeSet): void;
|
|
43
|
+
/** Asks for the states from line index `from` on, once the worker has read up to `until`. */
|
|
44
|
+
want(from: number, until: number): void;
|
|
45
|
+
dispose(): void;
|
|
46
|
+
}
|
|
47
|
+
export declare function ownWorker(): Promise<{
|
|
48
|
+
worker: Worker;
|
|
49
|
+
release: () => void;
|
|
50
|
+
}>;
|
|
51
|
+
/** Counts an editor using `worker`; the returned function lets go, ending the worker after the last. */
|
|
52
|
+
export declare function holdWorker(worker: Worker): () => void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CodeLanguage } from './language';
|
|
2
|
+
/** A change as sent: `[from, to, insert]`. */
|
|
3
|
+
export type WireChange = [from: number, to: number, insert: string];
|
|
4
|
+
export type ToWorker =
|
|
5
|
+
/** `nested`: the names of the languages it may hold, which the worker's language must hold too. */
|
|
6
|
+
{
|
|
7
|
+
t: 'open';
|
|
8
|
+
id: number;
|
|
9
|
+
language: string;
|
|
10
|
+
nested: string[];
|
|
11
|
+
tabSize: number;
|
|
12
|
+
}
|
|
13
|
+
/** The text, in pieces of whole lines; `done` on the last. */
|
|
14
|
+
| {
|
|
15
|
+
t: 'text';
|
|
16
|
+
id: number;
|
|
17
|
+
lines: string[];
|
|
18
|
+
done: boolean;
|
|
19
|
+
} | {
|
|
20
|
+
t: 'change';
|
|
21
|
+
id: number;
|
|
22
|
+
changes: WireChange[];
|
|
23
|
+
length: number;
|
|
24
|
+
} | {
|
|
25
|
+
t: 'read';
|
|
26
|
+
id: number;
|
|
27
|
+
from: number;
|
|
28
|
+
until: number;
|
|
29
|
+
} | {
|
|
30
|
+
t: 'close';
|
|
31
|
+
id: number;
|
|
32
|
+
};
|
|
33
|
+
export type FromWorker = {
|
|
34
|
+
t: 'states';
|
|
35
|
+
id: number;
|
|
36
|
+
version: number;
|
|
37
|
+
points: Array<[line: number, state: unknown]>;
|
|
38
|
+
}
|
|
39
|
+
/** The worker hasn't the language named `missing`, or (without it) can't send its states. */
|
|
40
|
+
| {
|
|
41
|
+
t: 'unsupported';
|
|
42
|
+
id: number;
|
|
43
|
+
missing?: string;
|
|
44
|
+
};
|
|
45
|
+
/** A state as plain data, its languages replaced by their names. */
|
|
46
|
+
export declare function encodeState(value: unknown): unknown;
|
|
47
|
+
/** A state back from plain data; `undefined` when it names a language `find` doesn't know. */
|
|
48
|
+
export declare function decodeState(value: unknown, find: (name: string) => CodeLanguage | undefined): unknown;
|
|
49
|
+
/** A language and every language it may hold, by name. */
|
|
50
|
+
export declare function languagesIn(language: CodeLanguage): Map<string, CodeLanguage>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type CodeLanguage } from '../language/language';
|
|
2
|
+
export interface CssState {
|
|
3
|
+
/** Inside a `/* … *\/` comment. */
|
|
4
|
+
comment: boolean;
|
|
5
|
+
/** Open braces. */
|
|
6
|
+
depth: number;
|
|
7
|
+
/** After a property's `:`, before its `;`: reading a value. */
|
|
8
|
+
value: boolean;
|
|
9
|
+
/** Open parentheses in a value or selector, e.g. `rgb(…)` or `:is(…)`. */
|
|
10
|
+
parens: number;
|
|
11
|
+
/** Inside an at-rule's prelude, e.g. `@media (…)`. */
|
|
12
|
+
at: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Makes CSS or a nesting dialect such as SCSS (`//` comments, `$` variables). */
|
|
15
|
+
export declare function createCss(name: string, aliases: string[], scss?: boolean): CodeLanguage<CssState>;
|
|
16
|
+
export declare const css: CodeLanguage<CssState>;
|
|
17
|
+
export declare const scss: CodeLanguage<CssState>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type CodeLanguage } from '../language/language';
|
|
2
|
+
/** A language running inside HTML: a `<script>`, a `<style>`, or a Vue expression. */
|
|
3
|
+
interface Inner {
|
|
4
|
+
language: CodeLanguage;
|
|
5
|
+
state: unknown;
|
|
6
|
+
/** What ends it: `</script`, `}}` or the attribute's quote. */
|
|
7
|
+
end: string;
|
|
8
|
+
/** A whole block (script or style), as opposed to an expression inside the markup. */
|
|
9
|
+
block: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface HtmlState {
|
|
12
|
+
/** `text` between tags, `tag` among a tag's attributes. */
|
|
13
|
+
in: 'text' | 'tag';
|
|
14
|
+
/** The tag being read, lowercased. */
|
|
15
|
+
tag: string;
|
|
16
|
+
/** The attribute just named, lowercased. */
|
|
17
|
+
attr: string;
|
|
18
|
+
/** The `lang` or `type` the tag asked for. */
|
|
19
|
+
lang: string;
|
|
20
|
+
/** Inside `<!-- … -->`. */
|
|
21
|
+
comment: boolean;
|
|
22
|
+
/** An attribute value whose quote is still open at the line's end. */
|
|
23
|
+
quote: string;
|
|
24
|
+
inner: Inner | null;
|
|
25
|
+
}
|
|
26
|
+
interface HtmlOptions {
|
|
27
|
+
/** Vue templates: `{{ … }}` and directive values are expressions. */
|
|
28
|
+
vue?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** Makes HTML, or a Vue single-file component. */
|
|
31
|
+
export declare function createHtml(name: string, aliases: string[], options?: HtmlOptions): CodeLanguage<HtmlState>;
|
|
32
|
+
export declare const html: CodeLanguage<HtmlState>;
|
|
33
|
+
export declare const vue: CodeLanguage<HtmlState>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type CodeLanguage } from '../language/language';
|
|
2
|
+
/**
|
|
3
|
+
* Where the tokenizer is, as a string of one character per open context
|
|
4
|
+
* (a string compares fastest):
|
|
5
|
+
*
|
|
6
|
+
* - `{` a brace block, `$` a `${…}` in a template string, `` ` `` inside a template string
|
|
7
|
+
* - `<` inside a JSX tag (its attributes), `>` among a JSX element's children, `J` a `{…}` in JSX
|
|
8
|
+
*/
|
|
9
|
+
export interface JavaScriptState {
|
|
10
|
+
stack: string;
|
|
11
|
+
/** Inside a `/* … *\/` comment. */
|
|
12
|
+
comment: boolean;
|
|
13
|
+
/** An expression may start here: a `/` is a regular expression, a `<` a JSX tag. */
|
|
14
|
+
expr: boolean;
|
|
15
|
+
/** The token before was a `.`, so a name is a property. */
|
|
16
|
+
dot: boolean;
|
|
17
|
+
/** The token before opened a brace or was a comma inside one, so `name:` is a property. */
|
|
18
|
+
key: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface JavaScriptOptions {
|
|
21
|
+
typescript?: boolean;
|
|
22
|
+
jsx?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** Makes a JavaScript-family language: plain, TypeScript, JSX or TSX. */
|
|
25
|
+
export declare function createJavaScript(name: string, aliases: string[], options?: JavaScriptOptions): CodeLanguage<JavaScriptState>;
|
|
26
|
+
export declare const javascript: CodeLanguage<JavaScriptState>;
|
|
27
|
+
export declare const typescript: CodeLanguage<JavaScriptState>;
|
|
28
|
+
export declare const jsx: CodeLanguage<JavaScriptState>;
|
|
29
|
+
export declare const tsx: CodeLanguage<JavaScriptState>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type CodeLanguage } from '../language/language';
|
|
2
|
+
export interface JsonState {
|
|
3
|
+
/** Inside a `/* … *\/` comment (JSON with comments). */
|
|
4
|
+
comment: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** JSON, also with comments and trailing commas as in `tsconfig.json`. */
|
|
7
|
+
export declare const json: CodeLanguage<JsonState>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type CodeLanguage } from '../language/language';
|
|
2
|
+
export interface MarkdownState {
|
|
3
|
+
/** The open code fence (`` ``` `` or `~~~`, with its length), or `''`. */
|
|
4
|
+
fence: string;
|
|
5
|
+
/** The language of the fenced code, when it is one of `code`. */
|
|
6
|
+
inner: {
|
|
7
|
+
language: CodeLanguage;
|
|
8
|
+
state: unknown;
|
|
9
|
+
} | null;
|
|
10
|
+
}
|
|
11
|
+
export interface MarkdownOptions {
|
|
12
|
+
/** Languages for fenced code, picked by the fence's info string (`` ```ts ``). */
|
|
13
|
+
languages?: readonly CodeLanguage[];
|
|
14
|
+
}
|
|
15
|
+
/** Makes Markdown; `languages` lists the languages its fenced code is highlighted with. */
|
|
16
|
+
export declare function createMarkdown(options?: MarkdownOptions): CodeLanguage<MarkdownState>;
|
|
17
|
+
export declare const markdown: CodeLanguage<MarkdownState>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CodeLanguage } from '../language/language';
|
|
2
|
+
export interface PythonState {
|
|
3
|
+
/** The quotes of a triple-quoted string still open at the line's end, e.g. `"""`. */
|
|
4
|
+
string: string | null;
|
|
5
|
+
/** What the last name was a definition of: the next name is its name. */
|
|
6
|
+
define: 'def' | 'class' | null;
|
|
7
|
+
}
|
|
8
|
+
/** Python 3, with type hints, decorators and f-strings. */
|
|
9
|
+
export declare const python: CodeLanguage<PythonState>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CodeLanguage } from '../language/language';
|
|
2
|
+
export interface ShellState {
|
|
3
|
+
/** The quote of a string still open at the line's end. */
|
|
4
|
+
quote: '"' | "'" | null;
|
|
5
|
+
/** The next word is a command (at the line's start, or after `|`, `;`, `&&`, `then`…). */
|
|
6
|
+
command: boolean;
|
|
7
|
+
/** The word that ends a here-document being read, e.g. `EOF`. */
|
|
8
|
+
heredoc: string | null;
|
|
9
|
+
}
|
|
10
|
+
/** Shell scripts: Bash, sh and Zsh. */
|
|
11
|
+
export declare const shell: CodeLanguage<ShellState>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CodeLanguage } from '../language/language';
|
|
2
|
+
export interface SqlState {
|
|
3
|
+
/** Inside a `/* … *\/` comment. */
|
|
4
|
+
comment: boolean;
|
|
5
|
+
/** The quote of a string or quoted name still open at the line's end. */
|
|
6
|
+
quote: string | null;
|
|
7
|
+
}
|
|
8
|
+
/** SQL, the parts most dialects share (PostgreSQL, MySQL, SQLite). Keywords in any case. */
|
|
9
|
+
export declare const sql: CodeLanguage<SqlState>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type CodeLanguage } from '../language/language';
|
|
2
|
+
export interface YamlState {
|
|
3
|
+
/**
|
|
4
|
+
* Reading a block scalar (`|` or `>`): the indentation of the line that
|
|
5
|
+
* started it; lines indented further are its text. `-1` outside one.
|
|
6
|
+
*/
|
|
7
|
+
block: number;
|
|
8
|
+
/** The quote of a string still open at the line's end. */
|
|
9
|
+
quote: '"' | "'" | null;
|
|
10
|
+
/** Open `[` and `{` of flow collections. */
|
|
11
|
+
flow: number;
|
|
12
|
+
}
|
|
13
|
+
/** YAML, as in configuration files and front matter. */
|
|
14
|
+
export declare const yaml: CodeLanguage<YamlState>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type MaybeRefOrGetter } from 'vue';
|
|
2
|
+
export interface CodeMessages {
|
|
3
|
+
/** The marker of a folded block, as a tooltip. */
|
|
4
|
+
unfold: string;
|
|
5
|
+
/** Read out after folding: `{from}`, `{to}` are the hidden lines. */
|
|
6
|
+
folded: string;
|
|
7
|
+
unfolded: string;
|
|
8
|
+
foldedAll: string;
|
|
9
|
+
unfoldedAll: string;
|
|
10
|
+
/** The toolbar over a selection on touch screens. */
|
|
11
|
+
editMenu: string;
|
|
12
|
+
cut: string;
|
|
13
|
+
copy: string;
|
|
14
|
+
paste: string;
|
|
15
|
+
selectAll: string;
|
|
16
|
+
/** Toolbar button of a language server (`@dou-ui/code/lsp`): go to where the name is defined. */
|
|
17
|
+
goToDefinition: string;
|
|
18
|
+
/** The bar of symbol keys on a touch screen. */
|
|
19
|
+
keys: string;
|
|
20
|
+
/** The grip that moves the bar of symbol keys. */
|
|
21
|
+
moveKeys: string;
|
|
22
|
+
/** The Tab key on that bar. */
|
|
23
|
+
indent: string;
|
|
24
|
+
/** The stick at the end of the bar of keys, which moves the cursor. */
|
|
25
|
+
moveCursor: string;
|
|
26
|
+
undo: string;
|
|
27
|
+
redo: string;
|
|
28
|
+
error: string;
|
|
29
|
+
warning: string;
|
|
30
|
+
info: string;
|
|
31
|
+
hint: string;
|
|
32
|
+
/** The box with the problems at a place in the text. */
|
|
33
|
+
problems: string;
|
|
34
|
+
/** Read out when the cursor moves to a problem: `{line}`, `{severity}`, `{message}`. */
|
|
35
|
+
problemAt: string;
|
|
36
|
+
/** Read out when a fix or a completion is picked: `{label}`, `{index}`, `{count}`. */
|
|
37
|
+
itemAt: string;
|
|
38
|
+
/** The box with the text about a place, and its problems. */
|
|
39
|
+
details: string;
|
|
40
|
+
/** The completion list. */
|
|
41
|
+
completions: string;
|
|
42
|
+
/** The box with the parameters of a call. */
|
|
43
|
+
signature: string;
|
|
44
|
+
/** The diff view's name. */
|
|
45
|
+
diff: string;
|
|
46
|
+
/** The original side's label. */
|
|
47
|
+
diffOriginal: string;
|
|
48
|
+
/** The modified side's label. */
|
|
49
|
+
diffModified: string;
|
|
50
|
+
diffPrevious: string;
|
|
51
|
+
diffNext: string;
|
|
52
|
+
/** Shows the two sides next to each other. */
|
|
53
|
+
diffSplit: string;
|
|
54
|
+
/** Shows the changes in one column. */
|
|
55
|
+
diffInline: string;
|
|
56
|
+
/** Shows all the unchanged lines. */
|
|
57
|
+
diffExpandAll: string;
|
|
58
|
+
/** Hides the unchanged lines again. */
|
|
59
|
+
diffCollapse: string;
|
|
60
|
+
/** The bar over hidden unchanged lines: `{count}`. */
|
|
61
|
+
diffUnchanged: string;
|
|
62
|
+
/** How many lines were added and removed: `{added}`, `{removed}`. */
|
|
63
|
+
diffStats: string;
|
|
64
|
+
diffNoChanges: string;
|
|
65
|
+
/** A removed line, in the gutter. */
|
|
66
|
+
diffRemoved: string;
|
|
67
|
+
/** An added line, in the gutter. */
|
|
68
|
+
diffAdded: string;
|
|
69
|
+
/** Read out when moving to a change: `{index}`, `{count}`, `{line}`, `{removed}`, `{added}`. */
|
|
70
|
+
diffChangeAt: string;
|
|
71
|
+
}
|
|
72
|
+
export declare const zhCN: CodeMessages;
|
|
73
|
+
export declare const zhTW: CodeMessages;
|
|
74
|
+
export declare const en: CodeMessages;
|
|
75
|
+
export declare const codeLocales: Record<string, CodeMessages>;
|
|
76
|
+
/** The code editor's texts, picked by the name of DouUI's current locale. Pass `messages` to override any of them. */
|
|
77
|
+
export declare function useCodeMessages(override?: MaybeRefOrGetter<Partial<CodeMessages> | undefined>): import("vue").ComputedRef<CodeMessages>;
|
|
78
|
+
/** Fills `{name}` placeholders. */
|
|
79
|
+
export declare const format: (text: string, params: Record<string, string | number>) => string;
|