@nibling/editor 0.0.0-stage → 0.0.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 +53 -2
- package/dist/commands/autoclose.d.ts +13 -0
- package/dist/commands/autoclose.js +78 -0
- package/dist/commands/commands.d.ts +104 -0
- package/dist/commands/commands.js +442 -0
- package/dist/commands/comments.d.ts +3 -0
- package/dist/commands/comments.js +9 -0
- package/dist/commands/fold.d.ts +18 -0
- package/dist/commands/fold.js +75 -0
- package/dist/commands/keymap.d.ts +40 -0
- package/dist/commands/keymap.js +118 -0
- package/dist/complete/autocomplete.d.ts +35 -0
- package/dist/complete/autocomplete.js +386 -0
- package/dist/complete/source.d.ts +72 -0
- package/dist/complete/source.js +52 -0
- package/dist/complete/words.d.ts +53 -0
- package/dist/complete/words.js +203 -0
- package/dist/element.d.ts +119 -0
- package/dist/element.js +1011 -0
- package/dist/expand/expansions.d.ts +68 -0
- package/dist/expand/expansions.js +143 -0
- package/dist/expand/projection.d.ts +73 -0
- package/dist/expand/projection.js +189 -0
- package/dist/expand/resolver.d.ts +42 -0
- package/dist/expand/resolver.js +585 -0
- package/dist/expand/slice-tokens.d.ts +25 -0
- package/dist/expand/slice-tokens.js +79 -0
- package/dist/extension.d.ts +58 -0
- package/dist/extension.js +1 -0
- package/dist/find/find.d.ts +12 -0
- package/dist/find/find.js +469 -0
- package/dist/find/search.d.ts +81 -0
- package/dist/find/search.js +308 -0
- package/dist/headless.d.ts +16 -0
- package/dist/headless.js +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/inline-expansion.d.ts +89 -0
- package/dist/inline-expansion.js +324 -0
- package/dist/input/edit-context.d.ts +23 -0
- package/dist/input/edit-context.js +102 -0
- package/dist/input/surface.d.ts +101 -0
- package/dist/input/surface.js +84 -0
- package/dist/input/textarea.d.ts +26 -0
- package/dist/input/textarea.js +125 -0
- package/dist/sheet.d.ts +6 -0
- package/dist/sheet.js +12 -0
- package/dist/state/core.d.ts +73 -0
- package/dist/state/core.js +86 -0
- package/dist/state/fold-ranges.d.ts +41 -0
- package/dist/state/fold-ranges.js +167 -0
- package/dist/state/folds.d.ts +45 -0
- package/dist/state/folds.js +240 -0
- package/dist/state/history.d.ts +25 -0
- package/dist/state/history.js +127 -0
- package/dist/state/indent.d.ts +33 -0
- package/dist/state/indent.js +121 -0
- package/dist/state/selection.d.ts +45 -0
- package/dist/state/selection.js +106 -0
- package/dist/state/whitespace.d.ts +16 -0
- package/dist/state/whitespace.js +54 -0
- package/dist/text/changeset.d.ts +56 -0
- package/dist/text/changeset.js +321 -0
- package/dist/text/text.d.ts +30 -0
- package/dist/text/text.js +321 -0
- package/dist/tokens/bridge.d.ts +107 -0
- package/dist/tokens/bridge.js +461 -0
- package/dist/tokens/engine.d.ts +39 -0
- package/dist/tokens/engine.js +360 -0
- package/dist/tokens/protocol.d.ts +113 -0
- package/dist/tokens/protocol.js +38 -0
- package/dist/tokens/textmate/ascii-regex.d.ts +5 -0
- package/dist/tokens/textmate/ascii-regex.js +156 -0
- package/dist/tokens/textmate/index.d.ts +7 -0
- package/dist/tokens/textmate/index.js +19 -0
- package/dist/tokens/textmate/linker.d.ts +67 -0
- package/dist/tokens/textmate/linker.js +238 -0
- package/dist/tokens/textmate/scopes.d.ts +14 -0
- package/dist/tokens/textmate/scopes.js +54 -0
- package/dist/tokens/textmate/theme.d.ts +54 -0
- package/dist/tokens/textmate/theme.js +138 -0
- package/dist/tokens/textmate/tokenizer.d.ts +29 -0
- package/dist/tokens/textmate/tokenizer.js +684 -0
- package/dist/tokens/textmate.d.ts +49 -0
- package/dist/tokens/textmate.js +4 -0
- package/dist/view/decorations.d.ts +183 -0
- package/dist/view/decorations.js +51 -0
- package/dist/view/guides.d.ts +58 -0
- package/dist/view/guides.js +174 -0
- package/dist/view/heightmap.d.ts +97 -0
- package/dist/view/heightmap.js +229 -0
- package/dist/view/line-dom.d.ts +54 -0
- package/dist/view/line-dom.js +168 -0
- package/dist/view/measure.d.ts +37 -0
- package/dist/view/measure.js +136 -0
- package/dist/view/overlays.d.ts +32 -0
- package/dist/view/overlays.js +135 -0
- package/dist/view/rail.d.ts +27 -0
- package/dist/view/rail.js +232 -0
- package/dist/view/remote.d.ts +24 -0
- package/dist/view/remote.js +143 -0
- package/dist/view/scope-focus.d.ts +27 -0
- package/dist/view/scope-focus.js +255 -0
- package/dist/view/view.d.ts +114 -0
- package/dist/view/view.js +1231 -0
- package/dist/vite.d.ts +12 -0
- package/dist/vite.js +64 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +64 -0
- package/grammars/astro.mjs +2 -0
- package/grammars/chunks/r-90cb351dba.mjs +1 -0
- package/grammars/chunks/r-b92a500aab.mjs +1 -0
- package/grammars/chunks/r-ced5311992.mjs +1 -0
- package/grammars/chunks/r-ebae91d4ec.mjs +1 -0
- package/grammars/chunks/s-1821e66170.mjs +1 -0
- package/grammars/css.mjs +1 -0
- package/grammars/diff.mjs +1 -0
- package/grammars/docker.mjs +1 -0
- package/grammars/dotenv.mjs +1 -0
- package/grammars/graphql.mjs +1 -0
- package/grammars/html.mjs +2 -0
- package/grammars/ini.mjs +1 -0
- package/grammars/javascript.mjs +5 -0
- package/grammars/json.mjs +1 -0
- package/grammars/json5.mjs +1 -0
- package/grammars/jsonc.mjs +1 -0
- package/grammars/less.mjs +1 -0
- package/grammars/manifest.json +58 -0
- package/grammars/markdown.mjs +1 -0
- package/grammars/mdx.mjs +1 -0
- package/grammars/pug.mjs +1 -0
- package/grammars/scss.mjs +1 -0
- package/grammars/shellscript.mjs +1 -0
- package/grammars/sql.mjs +1 -0
- package/grammars/stylus.mjs +1 -0
- package/grammars/svelte.mjs +1 -0
- package/grammars/toml.mjs +1 -0
- package/grammars/tsx.mjs +5 -0
- package/grammars/typescript.mjs +2 -0
- package/grammars/vue.mjs +1 -0
- package/grammars/yaml.mjs +1 -0
- package/package.json +71 -3
- package/themes/dark-plus.json +1 -0
- package/themes/light-plus.json +1 -0
- package/themes/monokai.json +1 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Immutable end-of-line tokenizer state. */
|
|
2
|
+
export interface Frame {
|
|
3
|
+
equals(other: Frame | null | undefined): boolean;
|
|
4
|
+
}
|
|
5
|
+
/** A compiled grammar module (build/modules/<lang>.mjs). Opaque here. */
|
|
6
|
+
export interface GrammarModule {
|
|
7
|
+
readonly scopeName: string;
|
|
8
|
+
}
|
|
9
|
+
export interface LinkedGrammar {
|
|
10
|
+
/** Relink with another module (vscode-textmate pruning recomputed). */
|
|
11
|
+
link(module: GrammarModule): void;
|
|
12
|
+
/** Bit for a scope, for `misses` masks. */
|
|
13
|
+
bit(scope: string): number;
|
|
14
|
+
/** Pre-scan: embedded scopes these lines can reach. */
|
|
15
|
+
scan(lines: readonly string[]): Set<string>;
|
|
16
|
+
}
|
|
17
|
+
export interface ScopeTable {
|
|
18
|
+
setTheme(theme: Theme): void;
|
|
19
|
+
styleOf(scopeId: number): number;
|
|
20
|
+
}
|
|
21
|
+
/** One theme, or a light/dark pair resolved together (style ids name a pair of styles). */
|
|
22
|
+
export interface Theme {
|
|
23
|
+
/** A style id as CSS: colors may be `light-dark(light, dark)` for a pair. */
|
|
24
|
+
css(style: number): {
|
|
25
|
+
readonly fg: string | null;
|
|
26
|
+
readonly bg: string | null;
|
|
27
|
+
readonly fontStyle: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface LineResult {
|
|
31
|
+
/** [start, scopeId, ...] */
|
|
32
|
+
readonly tokens: readonly number[];
|
|
33
|
+
readonly state: Frame;
|
|
34
|
+
/** Bitmask of missing grammars this line consulted. */
|
|
35
|
+
readonly misses: number;
|
|
36
|
+
}
|
|
37
|
+
export interface Tokenizer {
|
|
38
|
+
tokenizeLine(line: string, prev: Frame | null): LineResult;
|
|
39
|
+
invalidate(): void;
|
|
40
|
+
}
|
|
41
|
+
export interface TextMateRuntime {
|
|
42
|
+
linkedGrammar(root: GrammarModule, opts: {
|
|
43
|
+
available?: (scope: string) => boolean;
|
|
44
|
+
}): LinkedGrammar;
|
|
45
|
+
tokenizer(grammar: LinkedGrammar, scopes: ScopeTable): Tokenizer;
|
|
46
|
+
scopeTable(): ScopeTable;
|
|
47
|
+
/** One compiled theme, or with `dark`, `compiled` is the light theme of a pair. */
|
|
48
|
+
theme(compiled: unknown, dark?: unknown): Theme;
|
|
49
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Types for the S3 runtime (research/textmate/runtime/*.mjs), which is ported to TypeScript
|
|
2
|
+
// under tokens/textmate/ unchanged in behavior. Only the engine imports it; it never reaches the
|
|
3
|
+
// main thread. The declarations below are the surface the engine uses.
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { Snapshot } from '../state/core.ts';
|
|
2
|
+
import type { HiddenSpan } from '../state/folds.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Decorations are split by *renderer*, because the renderers have opposite cost models (D1):
|
|
5
|
+
* spans are cheap per token and dense; highlights cost ~3.3 µs per registered range on every
|
|
6
|
+
* changed frame. One unified range set would invite dense data into the expensive path. So there
|
|
7
|
+
* are four kinds, each with exactly one renderer, and no type can reach the wrong one:
|
|
8
|
+
*
|
|
9
|
+
* kind density renderer source
|
|
10
|
+
* LineTokens dense <span class="sN"> per run TokenBridge only (TextMate now,
|
|
11
|
+
* semantic tokens merged in the worker)
|
|
12
|
+
* Overlay sparse CSS.highlights StaticRange OverlaySource (selection, find matches,
|
|
13
|
+
* diagnostics, remote selections)
|
|
14
|
+
* LineClass per line class on the line element LineClassSource (active line)
|
|
15
|
+
* Widget rare inline element inside the line later (inlay hints)
|
|
16
|
+
* BlockWidget rare element between lines, measured ViewBlocks (inline expansions)
|
|
17
|
+
*
|
|
18
|
+
* Carets and the past-end-of-line selection box are not decorations; the view positions them.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Overlay kinds are a closed, namespaced list. Each kind is one Highlight registered as
|
|
22
|
+
* `nib-<instance>-<kind>`, with one `::highlight()` rule in the instance's adopted sheet.
|
|
23
|
+
* `priority` is the Highlight priority; selection paints over everything.
|
|
24
|
+
*/
|
|
25
|
+
export declare const overlayKinds: {
|
|
26
|
+
readonly 'match-current': {
|
|
27
|
+
readonly priority: 110;
|
|
28
|
+
};
|
|
29
|
+
readonly selection: {
|
|
30
|
+
readonly priority: 100;
|
|
31
|
+
};
|
|
32
|
+
readonly composition: {
|
|
33
|
+
readonly priority: 90;
|
|
34
|
+
};
|
|
35
|
+
readonly match: {
|
|
36
|
+
readonly priority: 50;
|
|
37
|
+
};
|
|
38
|
+
/** Other occurrences of the primary selection (CodeMirror's highlightSelectionMatches). Below
|
|
39
|
+
* `match` so an active find match still stands out from the ambient highlight. */
|
|
40
|
+
readonly 'selection-match': {
|
|
41
|
+
readonly priority: 49;
|
|
42
|
+
};
|
|
43
|
+
readonly 'diagnostic-error': {
|
|
44
|
+
readonly priority: 40;
|
|
45
|
+
};
|
|
46
|
+
readonly 'diagnostic-warning': {
|
|
47
|
+
readonly priority: 39;
|
|
48
|
+
};
|
|
49
|
+
readonly 'diagnostic-info': {
|
|
50
|
+
readonly priority: 38;
|
|
51
|
+
};
|
|
52
|
+
readonly bracket: {
|
|
53
|
+
readonly priority: 30;
|
|
54
|
+
};
|
|
55
|
+
readonly 'remote-1': {
|
|
56
|
+
readonly priority: 20;
|
|
57
|
+
};
|
|
58
|
+
readonly 'remote-2': {
|
|
59
|
+
readonly priority: 20;
|
|
60
|
+
};
|
|
61
|
+
readonly 'remote-3': {
|
|
62
|
+
readonly priority: 20;
|
|
63
|
+
};
|
|
64
|
+
readonly 'remote-4': {
|
|
65
|
+
readonly priority: 20;
|
|
66
|
+
};
|
|
67
|
+
readonly 'remote-5': {
|
|
68
|
+
readonly priority: 20;
|
|
69
|
+
};
|
|
70
|
+
readonly 'remote-6': {
|
|
71
|
+
readonly priority: 20;
|
|
72
|
+
};
|
|
73
|
+
readonly 'remote-7': {
|
|
74
|
+
readonly priority: 20;
|
|
75
|
+
};
|
|
76
|
+
readonly 'remote-8': {
|
|
77
|
+
readonly priority: 20;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
export type OverlayKind = keyof typeof overlayKinds;
|
|
81
|
+
/** A sparse range. Document offsets in the snapshot the source was queried with. */
|
|
82
|
+
export interface Overlay {
|
|
83
|
+
readonly kind: OverlayKind;
|
|
84
|
+
readonly from: number;
|
|
85
|
+
readonly to: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A pull-based producer of overlays. The view queries it for the mounted range only, once per
|
|
89
|
+
* frame in which the source said it changed or the mounted range moved. The source keeps its own
|
|
90
|
+
* positions current (it is a follower of EditorCore and maps them through Updates); the view
|
|
91
|
+
* never maps on its behalf.
|
|
92
|
+
*/
|
|
93
|
+
export interface OverlaySource {
|
|
94
|
+
query(state: Snapshot, from: number, to: number): Iterable<Overlay>;
|
|
95
|
+
/** Registers the view's invalidation callback. The source calls it when its output changed. */
|
|
96
|
+
subscribe(invalidate: () => void): () => void;
|
|
97
|
+
}
|
|
98
|
+
export interface LineClassSource {
|
|
99
|
+
/** Classes for a 1-based line. Called only for mounted lines being (re)rendered. */
|
|
100
|
+
classesFor(state: Snapshot, line: number): string | undefined;
|
|
101
|
+
subscribe(invalidate: () => void): () => void;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Folding's hooks into the view (src/view/rail.ts implements them). The view owns geometry and
|
|
105
|
+
* the gutter and line elements; folding says which lines are hidden and decorates elements the
|
|
106
|
+
* view hands it. Both hooks run inside the frame, after the view's own writes to the element.
|
|
107
|
+
*/
|
|
108
|
+
export interface ViewFolding {
|
|
109
|
+
/** Merged hidden spans, read when the view builds its HeightMap. */
|
|
110
|
+
hidden(): readonly HiddenSpan[];
|
|
111
|
+
/** After the gutter element for `line` is placed (the number is written first). */
|
|
112
|
+
gutter(el: HTMLElement, line: number): void;
|
|
113
|
+
/** After the line element for `line` is rendered. Anything appended goes after the text, so
|
|
114
|
+
* it is outside `LineBox.starts`. */
|
|
115
|
+
line(el: HTMLElement, line: number): void;
|
|
116
|
+
/** Re-placing every line follows, with a HeightMap built from `hidden()` again. */
|
|
117
|
+
subscribe(invalidate: () => void): () => void;
|
|
118
|
+
/** Its classes on line elements (the folded header); registered by the view. */
|
|
119
|
+
readonly lineClasses: LineClassSource;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A block widget: DOM directly below its anchor line that takes part in vertical layout, pushing
|
|
123
|
+
* the following lines down (not an overlay). The view owns its geometry: it mounts the widget with
|
|
124
|
+
* its anchor line, measures it, and keeps its last height while it is unmounted, so scrolling past
|
|
125
|
+
* one never changes the document's height.
|
|
126
|
+
*/
|
|
127
|
+
export interface BlockWidget {
|
|
128
|
+
/** Stable for the widget's life; geometry and measurements are keyed by it. */
|
|
129
|
+
readonly key: string;
|
|
130
|
+
/** Current 1-based anchor line. The source maps it through edits before the view updates. */
|
|
131
|
+
readonly line: number;
|
|
132
|
+
/** Height until the widget has been measured, given the view's line height. */
|
|
133
|
+
estimate(lineHeight: number): number;
|
|
134
|
+
/** Build its DOM in `host` when the anchor line mounts. `signal` aborts when it unmounts. */
|
|
135
|
+
mount(host: HTMLElement, signal: AbortSignal): void;
|
|
136
|
+
}
|
|
137
|
+
/** A collaborator's color: `--nib-editor-presence-<slot>`, and the `remote-<slot>` overlay. */
|
|
138
|
+
export type PresenceSlot = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
139
|
+
/** One collaborator's cursors, in document offsets of the snapshot the source was queried with. */
|
|
140
|
+
export interface RemoteCursor {
|
|
141
|
+
/** Stable for the collaborator's session; the view keys its label by it. */
|
|
142
|
+
readonly id: string;
|
|
143
|
+
readonly name: string;
|
|
144
|
+
readonly slot: PresenceSlot;
|
|
145
|
+
/** Several for a remote multicursor. The first carries the name label. */
|
|
146
|
+
readonly ranges: readonly {
|
|
147
|
+
readonly anchor: number;
|
|
148
|
+
readonly head: number;
|
|
149
|
+
}[];
|
|
150
|
+
/**
|
|
151
|
+
* `Date.now()` of the collaborator's last own move or edit; the label shows for a while after
|
|
152
|
+
* it. Absent: the view treats any change in `ranges` as activity, so a cursor that only shifted
|
|
153
|
+
* because text above it changed shows its label too.
|
|
154
|
+
*/
|
|
155
|
+
readonly activeAt?: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Remote carets, name labels, and selections (as `remote-<slot>` overlays). Like OverlaySource,
|
|
159
|
+
* the source keeps its positions current through Updates; the view never maps on its behalf.
|
|
160
|
+
*/
|
|
161
|
+
export interface RemoteCursorSource {
|
|
162
|
+
cursors(state: Snapshot): Iterable<RemoteCursor>;
|
|
163
|
+
subscribe(invalidate: () => void): () => void;
|
|
164
|
+
}
|
|
165
|
+
/** Block widgets' hook into the view, like ViewFolding. */
|
|
166
|
+
export interface ViewBlocks {
|
|
167
|
+
/** Sorted by line; read when the view builds its HeightMap and when it places widgets. */
|
|
168
|
+
widgets(): readonly BlockWidget[];
|
|
169
|
+
/** Widgets were added, removed, or re-anchored. */
|
|
170
|
+
subscribe(invalidate: () => void): () => void;
|
|
171
|
+
}
|
|
172
|
+
/** Placeholder so inline widget support has a named home. Not rendered in the first slice. */
|
|
173
|
+
export interface Widget {
|
|
174
|
+
readonly pos: number;
|
|
175
|
+
readonly side: -1 | 1;
|
|
176
|
+
readonly key: string;
|
|
177
|
+
toDOM(): HTMLElement;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The one hard cap on registered overlay ranges across all kinds (D1: "low hundreds").
|
|
181
|
+
* When exceeded, lower-priority kinds are dropped first and the drop is counted, not thrown.
|
|
182
|
+
*/
|
|
183
|
+
export declare const OVERLAY_BUDGET = 400;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decorations are split by *renderer*, because the renderers have opposite cost models (D1):
|
|
3
|
+
* spans are cheap per token and dense; highlights cost ~3.3 µs per registered range on every
|
|
4
|
+
* changed frame. One unified range set would invite dense data into the expensive path. So there
|
|
5
|
+
* are four kinds, each with exactly one renderer, and no type can reach the wrong one:
|
|
6
|
+
*
|
|
7
|
+
* kind density renderer source
|
|
8
|
+
* LineTokens dense <span class="sN"> per run TokenBridge only (TextMate now,
|
|
9
|
+
* semantic tokens merged in the worker)
|
|
10
|
+
* Overlay sparse CSS.highlights StaticRange OverlaySource (selection, find matches,
|
|
11
|
+
* diagnostics, remote selections)
|
|
12
|
+
* LineClass per line class on the line element LineClassSource (active line)
|
|
13
|
+
* Widget rare inline element inside the line later (inlay hints)
|
|
14
|
+
* BlockWidget rare element between lines, measured ViewBlocks (inline expansions)
|
|
15
|
+
*
|
|
16
|
+
* Carets and the past-end-of-line selection box are not decorations; the view positions them.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Overlay kinds are a closed, namespaced list. Each kind is one Highlight registered as
|
|
20
|
+
* `nib-<instance>-<kind>`, with one `::highlight()` rule in the instance's adopted sheet.
|
|
21
|
+
* `priority` is the Highlight priority; selection paints over everything.
|
|
22
|
+
*/
|
|
23
|
+
export const overlayKinds = {
|
|
24
|
+
// Find's current match paints over the selection that covers it, as VS Code's does.
|
|
25
|
+
'match-current': { priority: 110 },
|
|
26
|
+
selection: { priority: 100 },
|
|
27
|
+
composition: { priority: 90 },
|
|
28
|
+
match: { priority: 50 },
|
|
29
|
+
/** Other occurrences of the primary selection (CodeMirror's highlightSelectionMatches). Below
|
|
30
|
+
* `match` so an active find match still stands out from the ambient highlight. */
|
|
31
|
+
'selection-match': { priority: 49 },
|
|
32
|
+
'diagnostic-error': { priority: 40 },
|
|
33
|
+
'diagnostic-warning': { priority: 39 },
|
|
34
|
+
'diagnostic-info': { priority: 38 },
|
|
35
|
+
bracket: { priority: 30 },
|
|
36
|
+
// One kind per presence slot, so each peer's selection keeps its color. Equal priority: where peers
|
|
37
|
+
// overlap, their translucent fills stack.
|
|
38
|
+
'remote-1': { priority: 20 },
|
|
39
|
+
'remote-2': { priority: 20 },
|
|
40
|
+
'remote-3': { priority: 20 },
|
|
41
|
+
'remote-4': { priority: 20 },
|
|
42
|
+
'remote-5': { priority: 20 },
|
|
43
|
+
'remote-6': { priority: 20 },
|
|
44
|
+
'remote-7': { priority: 20 },
|
|
45
|
+
'remote-8': { priority: 20 },
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The one hard cap on registered overlay ranges across all kinds (D1: "low hundreds").
|
|
49
|
+
* When exceeded, lower-priority kinds are dropped first and the drop is counted, not thrown.
|
|
50
|
+
*/
|
|
51
|
+
export const OVERLAY_BUDGET = 400;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Snapshot } from '../state/core.ts';
|
|
2
|
+
import { type IndentUnit } from '../state/indent.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Indent guides and whitespace marks. Both stay quiet: guides a step off the background,
|
|
5
|
+
* whitespace dots and arrows only where asked for. The cursor's block is the scope rail's job
|
|
6
|
+
* (scope-focus.ts), so guides have no active state.
|
|
7
|
+
*
|
|
8
|
+
* Guides add no DOM. Each line's own background draws them: a 1px line every indent unit
|
|
9
|
+
* (`--nib-guide-w`, in `ch`, so tabs at `tab-size` line up), sized to `--nib-guides` units and not
|
|
10
|
+
* repeated past them. A blank line has no width of its own, so `min-width` gives it room for
|
|
11
|
+
* its guides.
|
|
12
|
+
*
|
|
13
|
+
* Whitespace marks are `::after` boxes on the spans `renderLine` makes for marked runs. They are
|
|
14
|
+
* positioned so they paint above selection highlights, and they carry no text. A dot per space
|
|
15
|
+
* repeats every `1ch`. A tab's advance varies, so its arrow sits at the left, centred.
|
|
16
|
+
*
|
|
17
|
+
* Every color is a `--nib-editor-*` knob (docs/design/theming.md): a platform token, then the
|
|
18
|
+
* TextMate theme's color (`--nib-theme-*`, written by the element), then a mix of foreground and
|
|
19
|
+
* background. The whitespace fallback mixes the foreground with transparent instead, so marks stay
|
|
20
|
+
* legible over a selection, which is where the default mode shows them.
|
|
21
|
+
*/
|
|
22
|
+
export declare const guidesCss = "\n:host{\n --nib-editor-indent-guide:var(--nib-color-border,var(--nib-theme-indent-guide,color-mix(in srgb,var(--nib-fg,#d4d4d4) 14%,var(--nib-bg,#1e1e1e))));\n --nib-editor-whitespace:var(--nib-theme-whitespace,color-mix(in srgb,var(--nib-fg,#d4d4d4) 30%,transparent));\n}\n.nib-scroller{--nib-guide-w:calc(var(--nib-indent-unit,4) * 1ch);\n --nib-ws-arrow:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M1.5 5h6.5M5.5 2.5 8 5 5.5 7.5' fill='none' stroke='%23000' stroke-width='1.1' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E\")}\n.nib-line{min-width:calc(var(--nib-guides,0) * var(--nib-guide-w));\n background:repeating-linear-gradient(to right,var(--nib-editor-indent-guide) 0 1px,transparent 1px var(--nib-guide-w)) 0 0/calc(var(--nib-guides,0) * var(--nib-guide-w)) 100% no-repeat}\n.nib-ws,.nib-ws-tab{position:relative}\n.nib-ws::after,.nib-ws-tab::after{content:'';position:absolute;inset:0;pointer-events:none}\n.nib-ws::after{background:radial-gradient(circle,var(--nib-editor-whitespace) 0 .9px,transparent 1.3px) 0 50%/1ch 100% repeat-x}\n.nib-ws-tab::after{background:var(--nib-editor-whitespace);\n -webkit-mask:var(--nib-ws-arrow) .2ch 50%/1ch 1ch no-repeat;mask:var(--nib-ws-arrow) .2ch 50%/1ch 1ch no-repeat}\n.nib-awaiting :is(.nib-ws,.nib-ws-tab)::after{visibility:hidden}\n@media (prefers-reduced-motion:no-preference){\n .nib-ws-enter::after{animation:nib-ws-in var(--nib-editor-motion-duration-fast) var(--nib-editor-motion-ease-out)}\n}\n@keyframes nib-ws-in{from{opacity:0}}\n";
|
|
23
|
+
/** The parts of a mounted line the guides write, so a frame writes only what changed. */
|
|
24
|
+
export interface GuideBox {
|
|
25
|
+
readonly el: HTMLDivElement;
|
|
26
|
+
/** Guide levels the element currently shows (`--nib-guides`). */
|
|
27
|
+
guides: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The view's side of indent guides: which unit to draw, and each mounted line's depth. Cached
|
|
31
|
+
* indents follow edits (`edited`): a keystroke drops only the lines it touched and shifts the
|
|
32
|
+
* rest, so the window never re-reads text that did not change. Cursor moves cost nothing.
|
|
33
|
+
*/
|
|
34
|
+
export declare class IndentGuides {
|
|
35
|
+
#private;
|
|
36
|
+
constructor(scroller: HTMLElement, enabled: boolean);
|
|
37
|
+
get enabled(): boolean;
|
|
38
|
+
set enabled(on: boolean);
|
|
39
|
+
/** The indent unit the guides draw, or null before the first paint. */
|
|
40
|
+
get unit(): IndentUnit | null;
|
|
41
|
+
/**
|
|
42
|
+
* Carry cached indents across an edit: drop every line an edit touched and shift the lines after
|
|
43
|
+
* it by its line delta. `edits` are in document order, in the old document's line numbers.
|
|
44
|
+
*/
|
|
45
|
+
edited(edits: readonly {
|
|
46
|
+
oldLo: number;
|
|
47
|
+
oldHi: number;
|
|
48
|
+
newLo: number;
|
|
49
|
+
newHi: number;
|
|
50
|
+
}[], version: number): void;
|
|
51
|
+
/** A new document: detect its unit again on the next paint. */
|
|
52
|
+
resetUnit(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Write each mounted line's guides. `remounted` says the set of mounted lines changed, so lines
|
|
55
|
+
* may show a different line than last frame. Only style writes, no layout reads.
|
|
56
|
+
*/
|
|
57
|
+
paint(state: Snapshot, tabSize: number, boxes: ReadonlyMap<number, GuideBox>, remounted: boolean): void;
|
|
58
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { detectIndentUnit, guideDepth, lineIndent } from "../state/indent.js";
|
|
2
|
+
/**
|
|
3
|
+
* Indent guides and whitespace marks. Both stay quiet: guides a step off the background,
|
|
4
|
+
* whitespace dots and arrows only where asked for. The cursor's block is the scope rail's job
|
|
5
|
+
* (scope-focus.ts), so guides have no active state.
|
|
6
|
+
*
|
|
7
|
+
* Guides add no DOM. Each line's own background draws them: a 1px line every indent unit
|
|
8
|
+
* (`--nib-guide-w`, in `ch`, so tabs at `tab-size` line up), sized to `--nib-guides` units and not
|
|
9
|
+
* repeated past them. A blank line has no width of its own, so `min-width` gives it room for
|
|
10
|
+
* its guides.
|
|
11
|
+
*
|
|
12
|
+
* Whitespace marks are `::after` boxes on the spans `renderLine` makes for marked runs. They are
|
|
13
|
+
* positioned so they paint above selection highlights, and they carry no text. A dot per space
|
|
14
|
+
* repeats every `1ch`. A tab's advance varies, so its arrow sits at the left, centred.
|
|
15
|
+
*
|
|
16
|
+
* Every color is a `--nib-editor-*` knob (docs/design/theming.md): a platform token, then the
|
|
17
|
+
* TextMate theme's color (`--nib-theme-*`, written by the element), then a mix of foreground and
|
|
18
|
+
* background. The whitespace fallback mixes the foreground with transparent instead, so marks stay
|
|
19
|
+
* legible over a selection, which is where the default mode shows them.
|
|
20
|
+
*/
|
|
21
|
+
export const guidesCss = `
|
|
22
|
+
:host{
|
|
23
|
+
--nib-editor-indent-guide:var(--nib-color-border,var(--nib-theme-indent-guide,color-mix(in srgb,var(--nib-fg,#d4d4d4) 14%,var(--nib-bg,#1e1e1e))));
|
|
24
|
+
--nib-editor-whitespace:var(--nib-theme-whitespace,color-mix(in srgb,var(--nib-fg,#d4d4d4) 30%,transparent));
|
|
25
|
+
}
|
|
26
|
+
.nib-scroller{--nib-guide-w:calc(var(--nib-indent-unit,4) * 1ch);
|
|
27
|
+
--nib-ws-arrow:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M1.5 5h6.5M5.5 2.5 8 5 5.5 7.5' fill='none' stroke='%23000' stroke-width='1.1' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}
|
|
28
|
+
.nib-line{min-width:calc(var(--nib-guides,0) * var(--nib-guide-w));
|
|
29
|
+
background:repeating-linear-gradient(to right,var(--nib-editor-indent-guide) 0 1px,transparent 1px var(--nib-guide-w)) 0 0/calc(var(--nib-guides,0) * var(--nib-guide-w)) 100% no-repeat}
|
|
30
|
+
.nib-ws,.nib-ws-tab{position:relative}
|
|
31
|
+
.nib-ws::after,.nib-ws-tab::after{content:'';position:absolute;inset:0;pointer-events:none}
|
|
32
|
+
.nib-ws::after{background:radial-gradient(circle,var(--nib-editor-whitespace) 0 .9px,transparent 1.3px) 0 50%/1ch 100% repeat-x}
|
|
33
|
+
.nib-ws-tab::after{background:var(--nib-editor-whitespace);
|
|
34
|
+
-webkit-mask:var(--nib-ws-arrow) .2ch 50%/1ch 1ch no-repeat;mask:var(--nib-ws-arrow) .2ch 50%/1ch 1ch no-repeat}
|
|
35
|
+
.nib-awaiting :is(.nib-ws,.nib-ws-tab)::after{visibility:hidden}
|
|
36
|
+
@media (prefers-reduced-motion:no-preference){
|
|
37
|
+
.nib-ws-enter::after{animation:nib-ws-in var(--nib-editor-motion-duration-fast) var(--nib-editor-motion-ease-out)}
|
|
38
|
+
}
|
|
39
|
+
@keyframes nib-ws-in{from{opacity:0}}
|
|
40
|
+
`;
|
|
41
|
+
/** Cached indents kept at most; cleared past this. */
|
|
42
|
+
const CACHE_LIMIT = 4096;
|
|
43
|
+
/** Past this many edits in one update (a remote burst), mapping the cache costs more than refilling it. */
|
|
44
|
+
const MAP_LIMIT = 16;
|
|
45
|
+
/**
|
|
46
|
+
* The view's side of indent guides: which unit to draw, and each mounted line's depth. Cached
|
|
47
|
+
* indents follow edits (`edited`): a keystroke drops only the lines it touched and shifts the
|
|
48
|
+
* rest, so the window never re-reads text that did not change. Cursor moves cost nothing.
|
|
49
|
+
*/
|
|
50
|
+
export class IndentGuides {
|
|
51
|
+
#scroller;
|
|
52
|
+
#enabled;
|
|
53
|
+
#unit = null;
|
|
54
|
+
#tabSize = 4;
|
|
55
|
+
#version = -1;
|
|
56
|
+
#indents = new Map();
|
|
57
|
+
/** An edit was mapped since the last paint: depths need a fresh look. */
|
|
58
|
+
#edited = false;
|
|
59
|
+
/** Set when the next paint must visit every mounted line. */
|
|
60
|
+
#stale = true;
|
|
61
|
+
constructor(scroller, enabled) {
|
|
62
|
+
this.#scroller = scroller;
|
|
63
|
+
this.#enabled = enabled;
|
|
64
|
+
}
|
|
65
|
+
get enabled() {
|
|
66
|
+
return this.#enabled;
|
|
67
|
+
}
|
|
68
|
+
set enabled(on) {
|
|
69
|
+
if (on === this.#enabled)
|
|
70
|
+
return;
|
|
71
|
+
this.#enabled = on;
|
|
72
|
+
this.#stale = true;
|
|
73
|
+
}
|
|
74
|
+
/** The indent unit the guides draw, or null before the first paint. */
|
|
75
|
+
get unit() {
|
|
76
|
+
return this.#unit;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Carry cached indents across an edit: drop every line an edit touched and shift the lines after
|
|
80
|
+
* it by its line delta. `edits` are in document order, in the old document's line numbers.
|
|
81
|
+
*/
|
|
82
|
+
edited(edits, version) {
|
|
83
|
+
this.#version = version;
|
|
84
|
+
this.#edited = true;
|
|
85
|
+
const old = this.#indents;
|
|
86
|
+
if (old.size === 0)
|
|
87
|
+
return;
|
|
88
|
+
if (edits.length > MAP_LIMIT) {
|
|
89
|
+
old.clear();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const next = new Map();
|
|
93
|
+
for (const [n, v] of old) {
|
|
94
|
+
let shift = 0;
|
|
95
|
+
let touched = false;
|
|
96
|
+
for (const e of edits) {
|
|
97
|
+
if (n < e.oldLo)
|
|
98
|
+
break;
|
|
99
|
+
if (n <= e.oldHi) {
|
|
100
|
+
touched = true;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
shift += e.newHi - e.newLo - (e.oldHi - e.oldLo);
|
|
104
|
+
}
|
|
105
|
+
if (!touched)
|
|
106
|
+
next.set(n + shift, v);
|
|
107
|
+
}
|
|
108
|
+
this.#indents = next;
|
|
109
|
+
}
|
|
110
|
+
/** A new document: detect its unit again on the next paint. */
|
|
111
|
+
resetUnit() {
|
|
112
|
+
this.#unit = null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Write each mounted line's guides. `remounted` says the set of mounted lines changed, so lines
|
|
116
|
+
* may show a different line than last frame. Only style writes, no layout reads.
|
|
117
|
+
*/
|
|
118
|
+
paint(state, tabSize, boxes, remounted) {
|
|
119
|
+
const text = state.text;
|
|
120
|
+
const version = state.version;
|
|
121
|
+
let block = this.#stale;
|
|
122
|
+
if (tabSize !== this.#tabSize) {
|
|
123
|
+
this.#tabSize = tabSize;
|
|
124
|
+
this.#unit = null;
|
|
125
|
+
}
|
|
126
|
+
if (version !== this.#version) {
|
|
127
|
+
// A version `edited` did not see (a document reset): nothing cached can be trusted.
|
|
128
|
+
this.#version = version;
|
|
129
|
+
this.#indents.clear();
|
|
130
|
+
block = true;
|
|
131
|
+
}
|
|
132
|
+
else if (this.#edited) {
|
|
133
|
+
this.#edited = false;
|
|
134
|
+
block = true;
|
|
135
|
+
}
|
|
136
|
+
if (this.#enabled && this.#unit === null) {
|
|
137
|
+
this.#unit = detectIndentUnit(text, tabSize);
|
|
138
|
+
this.#indents.clear();
|
|
139
|
+
this.#scroller.style.setProperty('--nib-indent-unit', String(this.#unit.width));
|
|
140
|
+
block = true;
|
|
141
|
+
}
|
|
142
|
+
if (!block && !remounted)
|
|
143
|
+
return;
|
|
144
|
+
this.#stale = false;
|
|
145
|
+
const unit = this.#unit;
|
|
146
|
+
if (!this.#enabled || !unit) {
|
|
147
|
+
for (const b of boxes.values())
|
|
148
|
+
write(b, 0);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const indents = this.#indents;
|
|
152
|
+
const read = (n) => {
|
|
153
|
+
let v = indents.get(n);
|
|
154
|
+
if (v === undefined) {
|
|
155
|
+
if (indents.size >= CACHE_LIMIT)
|
|
156
|
+
indents.clear();
|
|
157
|
+
v = lineIndent(text, n, tabSize);
|
|
158
|
+
indents.set(n, v);
|
|
159
|
+
}
|
|
160
|
+
return v;
|
|
161
|
+
};
|
|
162
|
+
for (const [n, b] of boxes)
|
|
163
|
+
write(b, guideDepth(text, n, unit, tabSize, read));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function write(b, depth) {
|
|
167
|
+
if (b.guides === depth)
|
|
168
|
+
return;
|
|
169
|
+
if (depth > 0)
|
|
170
|
+
b.el.style.setProperty('--nib-guides', String(depth));
|
|
171
|
+
else
|
|
172
|
+
b.el.style.removeProperty('--nib-guides');
|
|
173
|
+
b.guides = depth;
|
|
174
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { ChangeSet } from '../text/changeset.ts';
|
|
2
|
+
import type { Text } from '../text/text.ts';
|
|
3
|
+
import { type HiddenSpan } from '../state/folds.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Vertical geometry of the whole document, in px from the top of the content. The view asks it
|
|
6
|
+
* two questions and never computes heights itself, so wrapping and folding replace this module
|
|
7
|
+
* (a CM6-style HeightMap tree with measured heights) without touching the view's frame logic.
|
|
8
|
+
*/
|
|
9
|
+
export interface HeightMap {
|
|
10
|
+
/** Lines in the document it describes. */
|
|
11
|
+
readonly lines: number;
|
|
12
|
+
readonly totalHeight: number;
|
|
13
|
+
/** 1-based line whose box contains y (clamped). */
|
|
14
|
+
lineAt(y: number): number;
|
|
15
|
+
/** Top of a 1-based line. */
|
|
16
|
+
topOf(line: number): number;
|
|
17
|
+
heightOf(line: number): number;
|
|
18
|
+
/** The nearest line in `dir` with height, skipping folded ones: 0 or lines + 1 past the ends. */
|
|
19
|
+
next(line: number, dir: -1 | 1): number;
|
|
20
|
+
/** Height of the block widgets anchored after `line` (0 when it has none or is hidden). */
|
|
21
|
+
blockSpace(line: number): number;
|
|
22
|
+
/** Persistent update; the result describes `after`. */
|
|
23
|
+
update(changes: ChangeSet, before: Text, after: Text): HeightMap;
|
|
24
|
+
/** Feed back measured heights of mounted lines (no-op for fixed heights). */
|
|
25
|
+
measured(heights: ReadonlyMap<number, number>): HeightMap;
|
|
26
|
+
}
|
|
27
|
+
/** First slice: every line is `lineHeight` tall. All queries are arithmetic. */
|
|
28
|
+
export declare class FixedHeightMap implements HeightMap {
|
|
29
|
+
readonly lines: number;
|
|
30
|
+
readonly lineHeight: number;
|
|
31
|
+
constructor(lines: number, lineHeight: number);
|
|
32
|
+
get totalHeight(): number;
|
|
33
|
+
lineAt(y: number): number;
|
|
34
|
+
topOf(line: number): number;
|
|
35
|
+
heightOf(): number;
|
|
36
|
+
next(line: number, dir: -1 | 1): number;
|
|
37
|
+
blockSpace(): number;
|
|
38
|
+
update(_changes: ChangeSet, _before: Text, after: Text): HeightMap;
|
|
39
|
+
measured(): HeightMap;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Fixed-height lines with folded ones at zero height. Built from merged hidden spans; every query
|
|
43
|
+
* is a binary search over them, so cost grows with log(folds), never with lines. It reads the spans
|
|
44
|
+
* again from `hidden` on each update, so it never maps folds itself: FoldState, which listens to
|
|
45
|
+
* the core before the view, already has.
|
|
46
|
+
*/
|
|
47
|
+
export declare class FoldedHeightMap implements HeightMap {
|
|
48
|
+
#private;
|
|
49
|
+
readonly lines: number;
|
|
50
|
+
readonly lineHeight: number;
|
|
51
|
+
/** A FixedHeightMap when nothing is hidden, so an unfolded document pays nothing. */
|
|
52
|
+
static create(lines: number, lineHeight: number, hidden: () => readonly HiddenSpan[]): HeightMap;
|
|
53
|
+
private constructor();
|
|
54
|
+
get totalHeight(): number;
|
|
55
|
+
lineAt(y: number): number;
|
|
56
|
+
topOf(line: number): number;
|
|
57
|
+
heightOf(line: number): number;
|
|
58
|
+
next(line: number, dir: -1 | 1): number;
|
|
59
|
+
blockSpace(): number;
|
|
60
|
+
update(_changes: ChangeSet, _before: Text, after: Text): HeightMap;
|
|
61
|
+
measured(): HeightMap;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* One block widget's slot: `height` px of space directly below line `line`, in the order slots are
|
|
65
|
+
* listed. Slots on the same line stack in list order.
|
|
66
|
+
*/
|
|
67
|
+
export interface BlockSlot {
|
|
68
|
+
readonly line: number;
|
|
69
|
+
readonly height: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Block widgets layered over any base map (fixed, folded, and later wrapped): FoldedHeightMap
|
|
73
|
+
* removes spans, this inserts them. A slot whose anchor line the base hides takes no space, so a
|
|
74
|
+
* fold over a call site hides its expansion too.
|
|
75
|
+
*
|
|
76
|
+
* Built from slots sorted by line. `#start[i]` is where slot i begins in the combined geometry and
|
|
77
|
+
* `#cum[i]` the space of the slots before it, so every query is a binary search over slots plus one
|
|
78
|
+
* base query: O(log blocks + log folds), never O(lines) or O(blocks). Building it is O(blocks)
|
|
79
|
+
* base queries, once per Update or per measured resize, as FoldedHeightMap is O(folds) per Update.
|
|
80
|
+
* Like FoldedHeightMap it never maps anchors itself: it reads `slots()` again on update, from the
|
|
81
|
+
* follower that already has.
|
|
82
|
+
*/
|
|
83
|
+
export declare class BlockHeightMap implements HeightMap {
|
|
84
|
+
#private;
|
|
85
|
+
/** The base itself when there are no slots, so a document without widgets pays nothing. */
|
|
86
|
+
static create(base: HeightMap, slots: () => readonly BlockSlot[]): HeightMap;
|
|
87
|
+
private constructor();
|
|
88
|
+
get totalHeight(): number;
|
|
89
|
+
lineAt(y: number): number;
|
|
90
|
+
topOf(line: number): number;
|
|
91
|
+
heightOf(line: number): number;
|
|
92
|
+
next(line: number, dir: -1 | 1): number;
|
|
93
|
+
get lines(): number;
|
|
94
|
+
blockSpace(line: number): number;
|
|
95
|
+
update(changes: ChangeSet, before: Text, after: Text): HeightMap;
|
|
96
|
+
measured(heights: ReadonlyMap<number, number>): HeightMap;
|
|
97
|
+
}
|