@adecore/editor 0.62.0 → 0.63.0-untangle.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/dist/attribution.js +0 -1
- package/dist/bidi.js +0 -1
- package/dist/column-selection.d.ts +0 -1
- package/dist/column-selection.js +1 -1
- package/dist/controller.d.ts +4 -2
- package/dist/controller.js +0 -5
- package/dist/engine.js +0 -3
- package/dist/fake.d.ts +3 -0
- package/dist/fake.js +29 -24
- package/dist/find.d.ts +3 -2
- package/dist/find.js +0 -2
- package/dist/geometry-stops.d.ts +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/keymap-table.d.ts +8 -1
- package/dist/keymap-table.js +0 -1
- package/dist/keymap.d.ts +2 -1
- package/dist/layout-changes.d.ts +2 -1
- package/dist/layout.d.ts +3 -57
- package/dist/layout.js +1 -6
- package/dist/line-geometry.d.ts +55 -0
- package/dist/line-geometry.js +1 -0
- package/dist/metrics.d.ts +1 -1
- package/dist/modifier-gesture.d.ts +2 -1
- package/dist/modifier-gesture.js +0 -1
- package/dist/native-input.d.ts +2 -1
- package/dist/outline.d.ts +3 -3
- package/dist/outline.js +0 -1
- package/dist/overview.d.ts +3 -2
- package/dist/paint.d.ts +5 -5
- package/dist/paint.js +3 -4
- package/dist/php-html.d.ts +0 -6
- package/dist/php-html.js +2 -2
- package/dist/pointer.d.ts +2 -1
- package/dist/scroll-animation.d.ts +0 -1
- package/dist/scroll-animation.js +1 -1
- package/dist/scroll.js +0 -1
- package/dist/search-client.d.ts +2 -2
- package/dist/shiki-document.js +1 -1
- package/dist/shiki-grammar.d.ts +7 -0
- package/dist/shiki-grammar.js +168 -0
- package/dist/shiki-worker.js +1 -1
- package/dist/shiki.d.ts +1 -7
- package/dist/shiki.js +1 -168
- package/dist/smart-keys.js +0 -1
- package/dist/testing.js +0 -2
- package/dist/todos.d.ts +2 -1
- package/dist/tokens.d.ts +2 -1
- package/dist/tokens.js +0 -1
- package/dist/touch.d.ts +2 -1
- package/dist/types.d.ts +5 -13
- package/dist/uniform-geometry.d.ts +1 -1
- package/dist/view.d.ts +12 -10
- package/dist/view.js +61 -38
- package/dist/zoom.d.ts +0 -2
- package/dist/zoom.js +2 -2
- package/package.json +8 -3
- package/src/attribution.ts +0 -1
- package/src/bidi.ts +0 -1
- package/src/column-selection.ts +1 -1
- package/src/controller.ts +3 -9
- package/src/engine.ts +0 -3
- package/src/fake.ts +38 -24
- package/src/find.ts +2 -4
- package/src/geometry-stops.ts +1 -1
- package/src/index.ts +2 -2
- package/src/keymap-table.ts +10 -3
- package/src/keymap.ts +2 -1
- package/src/layout-changes.ts +1 -1
- package/src/layout.ts +4 -81
- package/src/line-geometry.ts +69 -0
- package/src/metrics.ts +1 -1
- package/src/modifier-gesture.ts +1 -2
- package/src/native-input.ts +1 -1
- package/src/outline.ts +3 -5
- package/src/overview.ts +2 -2
- package/src/paint.ts +5 -11
- package/src/php-html.ts +2 -2
- package/src/pointer.ts +1 -4
- package/src/scroll-animation.ts +1 -1
- package/src/scroll.ts +0 -2
- package/src/search-client.ts +2 -2
- package/src/shiki-document.ts +1 -1
- package/src/shiki-grammar.ts +223 -0
- package/src/shiki-worker.ts +1 -1
- package/src/shiki.ts +1 -224
- package/src/smart-keys.ts +0 -1
- package/src/testing.ts +0 -2
- package/src/todos.ts +1 -1
- package/src/tokens.ts +1 -2
- package/src/touch.ts +1 -1
- package/src/types.ts +9 -22
- package/src/uniform-geometry.ts +1 -1
- package/src/view.ts +89 -56
- package/src/zoom.ts +2 -2
package/dist/native-input.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DocumentModel, Selection, TextEdit } from '@adecore/editor-core';
|
|
2
|
-
|
|
2
|
+
interface NativeInputHost {
|
|
3
3
|
readOnly(): boolean;
|
|
4
4
|
replace(text: string): void;
|
|
5
5
|
type(character: string): void;
|
|
@@ -25,3 +25,4 @@ export declare class NativeInput {
|
|
|
25
25
|
private composedText;
|
|
26
26
|
private replacedText;
|
|
27
27
|
}
|
|
28
|
+
export {};
|
package/dist/outline.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DocumentChange, FoldingRange } from '@adecore/editor-core';
|
|
2
2
|
import type { EditorBlock } from './types.ts';
|
|
3
|
-
|
|
3
|
+
interface OutlineBlock {
|
|
4
4
|
startLine: number;
|
|
5
5
|
endLine: number;
|
|
6
6
|
name?: string;
|
|
@@ -12,7 +12,7 @@ interface OutlineEntry {
|
|
|
12
12
|
name?: string;
|
|
13
13
|
kind?: string;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
interface OutlineDocument {
|
|
16
16
|
getLine(line: number): {
|
|
17
17
|
start: number;
|
|
18
18
|
end: number;
|
|
@@ -40,7 +40,7 @@ export declare class Outline {
|
|
|
40
40
|
declarationStops(document: OutlineDocument): number[];
|
|
41
41
|
blocks(document: OutlineDocument): readonly OutlineBlock[];
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
interface StickyRows {
|
|
44
44
|
top(line: number): number;
|
|
45
45
|
bottom(line: number): number;
|
|
46
46
|
startsRow(line: number): boolean;
|
package/dist/outline.js
CHANGED
|
@@ -192,7 +192,6 @@ export function stickyPlacements(blocks, scrollTop, lineHeight, max, rows) {
|
|
|
192
192
|
}
|
|
193
193
|
return placements;
|
|
194
194
|
}
|
|
195
|
-
/* How far down from the top the pinned headers reach. */
|
|
196
195
|
export function stickyCover(placements, lineHeight) {
|
|
197
196
|
return Math.max(0, ...placements.map((placement) => (placement.depth + 1) * lineHeight + placement.offset));
|
|
198
197
|
}
|
package/dist/overview.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type OverviewKind = 'added' | 'modified' | 'deleted' | 'find' | 'find-current' | 'occurrence' | 'todo' | 'info' | 'warning' | 'error';
|
|
2
2
|
export interface OverviewSpan {
|
|
3
3
|
kind: OverviewKind;
|
|
4
4
|
top: number;
|
|
@@ -6,7 +6,7 @@ export interface OverviewSpan {
|
|
|
6
6
|
offset?: number;
|
|
7
7
|
title?: string;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
interface OverviewTick {
|
|
10
10
|
kind: OverviewKind;
|
|
11
11
|
y: number;
|
|
12
12
|
height: number;
|
|
@@ -15,3 +15,4 @@ export interface OverviewTick {
|
|
|
15
15
|
}
|
|
16
16
|
export declare function overviewTicks(spans: readonly OverviewSpan[], contentHeight: number, trackHeight: number): OverviewTick[];
|
|
17
17
|
export declare function paintOverview(container: HTMLElement, ticks: readonly OverviewTick[]): void;
|
|
18
|
+
export {};
|
package/dist/paint.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type AttributedLines } from './attribution.ts';
|
|
2
|
-
import { type EditorLayout, type LayoutRect, type LayoutRow, type
|
|
2
|
+
import { type EditorLayout, type LayoutRect, type LayoutRow, type VerticalWindow } from './layout.ts';
|
|
3
|
+
import { type LineGeometry } from './line-geometry.ts';
|
|
3
4
|
import type { EditorChangeKind, EditorGutterIcon, LineToken } from './types.ts';
|
|
4
5
|
export interface RowPaint {
|
|
5
6
|
layoutVersion: number;
|
|
@@ -12,7 +13,6 @@ export interface RowPaint {
|
|
|
12
13
|
onUnfold(line: number): void;
|
|
13
14
|
}
|
|
14
15
|
export declare function styleSpan(span: HTMLElement, token: LineToken): void;
|
|
15
|
-
export declare function lineElement(document: Document, geometry: LineGeometry, tokens: readonly LineToken[] | null, lineHeight: number, band: SubRowBand, whitespace?: boolean): HTMLElement;
|
|
16
16
|
export declare class RowPainter {
|
|
17
17
|
private readonly rows;
|
|
18
18
|
private readonly code;
|
|
@@ -30,7 +30,7 @@ export declare class RowPainter {
|
|
|
30
30
|
private fillBlock;
|
|
31
31
|
clear(): void;
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
interface GutterPaint {
|
|
34
34
|
lineNumber(line: number): string | null;
|
|
35
35
|
activeLines: ReadonlySet<number>;
|
|
36
36
|
changes: ReadonlyMap<number, EditorChangeKind>;
|
|
@@ -51,7 +51,7 @@ export interface GutterPaint {
|
|
|
51
51
|
}>;
|
|
52
52
|
}
|
|
53
53
|
export declare function paintGutter(container: HTMLElement, layout: EditorLayout, rows: readonly LayoutRow[], paint: GutterPaint): void;
|
|
54
|
-
|
|
54
|
+
interface OverlayPaint {
|
|
55
55
|
currentLine: LayoutRect | null;
|
|
56
56
|
selections: readonly LayoutRect[];
|
|
57
57
|
focused: boolean;
|
|
@@ -87,10 +87,10 @@ export interface StickyEntry {
|
|
|
87
87
|
tokens: readonly LineToken[] | null;
|
|
88
88
|
}
|
|
89
89
|
export declare function paintSticky(container: HTMLElement, entries: readonly StickyEntry[], lineHeight: number): void;
|
|
90
|
-
export declare function arrowSign(document: Document, width: number, lineHeight: number, className: string): SVGSVGElement;
|
|
91
90
|
export interface WrapSign {
|
|
92
91
|
x: number;
|
|
93
92
|
y: number;
|
|
94
93
|
width: number;
|
|
95
94
|
}
|
|
96
95
|
export declare function paintSigns(container: HTMLElement, signs: readonly WrapSign[], lineHeight: number): void;
|
|
96
|
+
export {};
|
package/dist/paint.js
CHANGED
|
@@ -2,6 +2,7 @@ import { colorValue, tintValue } from './attribution.js';
|
|
|
2
2
|
import { BIDI_CONTROLS, BIDI_PATTERN, visibleBidi } from './bidi.js';
|
|
3
3
|
import { offsetOfStop, rowOfStop, stopAtOffset, stopCount, xOfStop } from './geometry-stops.js';
|
|
4
4
|
import { scanLine, subRowBand } from './layout.js';
|
|
5
|
+
import {} from './line-geometry.js';
|
|
5
6
|
const ITALIC = 1;
|
|
6
7
|
const BOLD = 2;
|
|
7
8
|
const UNDERLINE = 4;
|
|
@@ -66,7 +67,7 @@ function fillRun(run, geometry, from, to, tokens, whitespace, tokensFrom = geome
|
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
+
function lineElement(document, geometry, tokens, lineHeight, band, whitespace = false) {
|
|
70
71
|
const element = document.createElement('div');
|
|
71
72
|
element.className = 'se-line';
|
|
72
73
|
element.style.width = `${geometry.width}px`;
|
|
@@ -365,7 +366,6 @@ function gutterButton(document, className, label) {
|
|
|
365
366
|
button.setAttribute('aria-label', label);
|
|
366
367
|
return button;
|
|
367
368
|
}
|
|
368
|
-
/* The line numbers of the visible rows, and the fold control of the lines that have one. */
|
|
369
369
|
export function paintGutter(container, layout, rows, paint) {
|
|
370
370
|
const document = container.ownerDocument;
|
|
371
371
|
const fragment = document.createDocumentFragment();
|
|
@@ -553,7 +553,7 @@ const SVG = 'http://www.w3.org/2000/svg';
|
|
|
553
553
|
* An arrow as the platform draws a tab or a soft wrap: a line across the middle of half a line's height,
|
|
554
554
|
* ending in a head that points right with a bar behind it, in as much room as it has.
|
|
555
555
|
*/
|
|
556
|
-
|
|
556
|
+
function arrowSign(document, width, lineHeight, className) {
|
|
557
557
|
const svg = document.createElementNS(SVG, 'svg');
|
|
558
558
|
svg.setAttribute('class', className);
|
|
559
559
|
svg.setAttribute('width', String(Math.max(1, Math.round(width))));
|
|
@@ -572,7 +572,6 @@ export function arrowSign(document, width, lineHeight, className) {
|
|
|
572
572
|
svg.append(path);
|
|
573
573
|
return svg;
|
|
574
574
|
}
|
|
575
|
-
/* An arrow over each tab of a line. */
|
|
576
575
|
function appendTabSigns(element, geometry, lineHeight, band) {
|
|
577
576
|
if (geometry.uniform !== undefined) {
|
|
578
577
|
return;
|
package/dist/php-html.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import type { Highlighter } from 'shiki';
|
|
2
|
-
type LanguageRegistration = Extract<Parameters<Highlighter['loadLanguage']>[0], {
|
|
3
|
-
readonly scopeName: string;
|
|
4
|
-
}>;
|
|
5
|
-
export declare const PHP_DOCUMENT_ID = "php-html";
|
|
6
|
-
export declare const PHP_DOCUMENT: LanguageRegistration;
|
|
7
2
|
export declare function documentLanguageOf(language: string): string;
|
|
8
3
|
export declare function loadDocumentLanguage(highlighter: Highlighter, language: string): Promise<void>;
|
|
9
|
-
export {};
|
package/dist/php-html.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* Shiki's `php` is only the code inside the tags, which makes a plain `<?php` an operator and a constant. */
|
|
2
|
-
|
|
2
|
+
const PHP_DOCUMENT_ID = 'php-html';
|
|
3
3
|
/*
|
|
4
4
|
* A PHP file as a document: HTML with PHP between its tags, the way `text.html.php` of the PHP
|
|
5
5
|
* grammar family does it. Shiki bundles no such grammar, so it is written here on top of `html` and
|
|
6
6
|
* `php`, which have to be loaded first. The tags carry the scope a theme draws a tag's brackets in.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
const PHP_DOCUMENT = {
|
|
9
9
|
name: PHP_DOCUMENT_ID,
|
|
10
10
|
scopeName: 'text.html.php',
|
|
11
11
|
embeddedLangs: ['html', 'php'],
|
package/dist/pointer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DocumentModel, Selection } from '@adecore/editor-core';
|
|
2
2
|
import type { ContentPoint } from './column-selection.ts';
|
|
3
|
-
|
|
3
|
+
interface VisualLine {
|
|
4
4
|
start: number;
|
|
5
5
|
end: number;
|
|
6
6
|
next: number;
|
|
@@ -47,3 +47,4 @@ export declare class PointerSelection {
|
|
|
47
47
|
private reach;
|
|
48
48
|
private autoScroll;
|
|
49
49
|
}
|
|
50
|
+
export {};
|
package/dist/scroll-animation.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* over a moment that grows with the distance up to a tenth of a second, starting fast and easing out.
|
|
4
4
|
*/
|
|
5
5
|
/* The longest the view takes to get anywhere. */
|
|
6
|
-
|
|
6
|
+
const SCROLL_DURATION_MS = 100;
|
|
7
7
|
/* How many lines away the view has to go before it takes any time, and how many before it takes all of it. */
|
|
8
8
|
const FREE_LINES = 1;
|
|
9
9
|
const FULL_LINES = 11;
|
package/dist/scroll.js
CHANGED
|
@@ -64,7 +64,6 @@ function horizontalPosition(request, kind) {
|
|
|
64
64
|
}
|
|
65
65
|
return clamp(position, content.width - width);
|
|
66
66
|
}
|
|
67
|
-
/* The scroll position that shows the target the way `kind` asks. */
|
|
68
67
|
export function scrollPosition(request, kind) {
|
|
69
68
|
const { target, view } = request;
|
|
70
69
|
const inView = target.x >= view.x && target.x < view.x + view.width && target.y >= view.y && target.y < view.y + view.height;
|
package/dist/search-client.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { FindMatch } from '@adecore/editor-core';
|
|
2
2
|
import { type EditorSearchRange, type EditorSearchNextOptions, type EditorSearchReplacementOptions, type EditorSearchReplacements, type EditorSearchOptions, type EditorSearchResult, type EditorSearchSnapshot } from './search-protocol.ts';
|
|
3
|
-
import type { EditorFindQuery } from './types.ts';
|
|
3
|
+
import type { EditorFindQuery, EditorSearchWorkerFactory } from './types.ts';
|
|
4
4
|
export type EditorSearchErrorKind = 'timeout' | 'superseded' | 'unavailable' | 'syntax' | 'range' | 'snapshot' | 'error' | 'disposed';
|
|
5
5
|
export declare class EditorSearchError extends Error {
|
|
6
6
|
readonly kind: EditorSearchErrorKind;
|
|
7
7
|
constructor(kind: EditorSearchErrorKind, message: string);
|
|
8
8
|
}
|
|
9
9
|
export interface EditorSearchClientOptions {
|
|
10
|
-
readonly workerFactory:
|
|
10
|
+
readonly workerFactory: EditorSearchWorkerFactory;
|
|
11
11
|
readonly deadline?: number;
|
|
12
12
|
readonly schedule?: (callback: () => void, delay: number) => () => void;
|
|
13
13
|
}
|
package/dist/shiki-document.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { documentLanguageOf, loadGrammar } from './shiki.js';
|
|
1
|
+
import { documentLanguageOf, loadGrammar } from './shiki-grammar.js';
|
|
2
2
|
export function shikiDocumentHighlighter(highlighter, blocks, language, theme, transformers = []) {
|
|
3
3
|
return documentHighlighter(highlighter, blocks, language, theme, (loaded, code, grammar, theme, state) => {
|
|
4
4
|
let root;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Highlighter } from 'shiki';
|
|
2
|
+
import { documentLanguageOf } from './php-html.ts';
|
|
3
|
+
import type { ScopeColorSource, TokenizerSource } from './types.ts';
|
|
4
|
+
export { documentLanguageOf };
|
|
5
|
+
export declare function loadGrammar(highlighter: Highlighter, grammar: string, text?: string): Promise<boolean>;
|
|
6
|
+
export declare function shikiTokenizers(highlighter: () => Promise<Highlighter>): TokenizerSource;
|
|
7
|
+
export declare function shikiScopeColors(highlighter: () => Promise<Highlighter>): ScopeColorSource;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { documentLanguageOf, loadDocumentLanguage } from './php-html.js';
|
|
2
|
+
import { scopeColorsOf } from './theme-scopes.js';
|
|
3
|
+
export { documentLanguageOf };
|
|
4
|
+
/* The standard token types of TextMate: 1 comment, 2 string, 3 regex. */
|
|
5
|
+
const KINDS = { 1: 'comment', 2: 'string', 3: 'regex' };
|
|
6
|
+
const PLAIN_TEXT = new Set(['', 'text', 'txt', 'plain', 'plaintext']);
|
|
7
|
+
/* Colors one line at a time and hands the grammar's state from one line to the next. A grammar Shiki rebuilt does not know the states of the old one. */
|
|
8
|
+
function lineTokenizer(highlighter, language, theme, embedded) {
|
|
9
|
+
let grammar = highlighter.getLanguage(language);
|
|
10
|
+
return {
|
|
11
|
+
prepare: embedded.matcher === null ? undefined : (text) => loadEmbedded(highlighter, embedded, text),
|
|
12
|
+
stale() {
|
|
13
|
+
const current = highlighter.getLanguage(language);
|
|
14
|
+
const changed = current !== grammar;
|
|
15
|
+
grammar = current;
|
|
16
|
+
return changed;
|
|
17
|
+
},
|
|
18
|
+
tokenizeLine(text, state) {
|
|
19
|
+
const options = {
|
|
20
|
+
lang: language,
|
|
21
|
+
theme,
|
|
22
|
+
grammarState: (state ?? undefined),
|
|
23
|
+
includeExplanation: 'tokenType'
|
|
24
|
+
};
|
|
25
|
+
const lines = highlighter.codeToTokensBase(text, options);
|
|
26
|
+
const tokens = (lines[0] ?? []).map((token) => ({
|
|
27
|
+
length: token.content.length,
|
|
28
|
+
color: token.color ?? '',
|
|
29
|
+
fontStyle: token.fontStyle ?? 0,
|
|
30
|
+
kind: KINDS[token.type ?? 0]
|
|
31
|
+
}));
|
|
32
|
+
return { tokens, state: highlighter.getLastGrammarState(lines) };
|
|
33
|
+
},
|
|
34
|
+
sameState(a, b) {
|
|
35
|
+
if (a === b) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
const left = a?.getInternalStack(theme);
|
|
39
|
+
const right = b?.getInternalStack(theme);
|
|
40
|
+
return left !== undefined && right !== undefined && left.equals(right);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const languageLoads = new WeakMap();
|
|
45
|
+
const embeddedIndexes = new Map();
|
|
46
|
+
/* Concurrent documents await one load, so each learns the grammar was rebuilt. */
|
|
47
|
+
function loadOnce(highlighter, id) {
|
|
48
|
+
if (highlighter.getLoadedLanguages().includes(id)) {
|
|
49
|
+
return Promise.resolve();
|
|
50
|
+
}
|
|
51
|
+
let loads = languageLoads.get(highlighter);
|
|
52
|
+
if (loads === undefined) {
|
|
53
|
+
loads = new Map();
|
|
54
|
+
languageLoads.set(highlighter, loads);
|
|
55
|
+
}
|
|
56
|
+
const pending = loads.get(id);
|
|
57
|
+
if (pending !== undefined) {
|
|
58
|
+
return pending;
|
|
59
|
+
}
|
|
60
|
+
const load = (async () => {
|
|
61
|
+
await loadDocumentLanguage(highlighter, id);
|
|
62
|
+
if (!highlighter.getLoadedLanguages().includes(id)) {
|
|
63
|
+
await highlighter.loadLanguage(id);
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
66
|
+
loads.set(id, load);
|
|
67
|
+
void load.catch(() => {
|
|
68
|
+
if (loads.get(id) === load) {
|
|
69
|
+
loads.delete(id);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return load;
|
|
73
|
+
}
|
|
74
|
+
function embedIndex(grammar) {
|
|
75
|
+
const cached = embeddedIndexes.get(grammar);
|
|
76
|
+
if (cached !== undefined) {
|
|
77
|
+
return cached;
|
|
78
|
+
}
|
|
79
|
+
const pending = (async () => {
|
|
80
|
+
const { bundledLanguages, bundledLanguagesInfo } = await import('shiki');
|
|
81
|
+
const bundled = bundledLanguages[grammar];
|
|
82
|
+
const registrations = bundled === undefined ? [] : (await bundled()).default;
|
|
83
|
+
const lazy = registrations.find((registration) => registration.name === grammar)?.embeddedLangsLazy ?? [];
|
|
84
|
+
const names = new Map();
|
|
85
|
+
for (const id of lazy) {
|
|
86
|
+
const aliases = bundledLanguagesInfo.find((info) => info.id === id)?.aliases ?? [];
|
|
87
|
+
for (const name of [id, ...aliases]) {
|
|
88
|
+
names.set(name.toLowerCase(), id);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (names.size === 0) {
|
|
92
|
+
return { names, matcher: null };
|
|
93
|
+
}
|
|
94
|
+
let matcher;
|
|
95
|
+
if (grammar === 'markdown' || grammar === 'mdx') {
|
|
96
|
+
matcher = /^\s*(?:`{3,}|~{3,})[ \t]*([\w#+.-]+)/gm;
|
|
97
|
+
}
|
|
98
|
+
else if (grammar === 'vue' || grammar === 'svelte' || grammar === 'astro') {
|
|
99
|
+
matcher = /\blang\s*=\s*["']([\w#+.-]+)["']/gi;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const alternatives = [...names.keys()].map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
|
|
103
|
+
matcher = new RegExp(`(?<![\\w-])(${alternatives})(?![\\w-])`, 'gi');
|
|
104
|
+
}
|
|
105
|
+
return { names, matcher };
|
|
106
|
+
})();
|
|
107
|
+
embeddedIndexes.set(grammar, pending);
|
|
108
|
+
void pending.catch(() => embeddedIndexes.delete(grammar));
|
|
109
|
+
return pending;
|
|
110
|
+
}
|
|
111
|
+
async function loadEmbedded(highlighter, embedded, text) {
|
|
112
|
+
if (embedded.matcher === null) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
const loaded = new Set(highlighter.getLoadedLanguages());
|
|
116
|
+
const named = new Set();
|
|
117
|
+
for (const match of text.matchAll(embedded.matcher)) {
|
|
118
|
+
const id = embedded.names.get(match[1].toLowerCase());
|
|
119
|
+
if (id !== undefined && !loaded.has(id)) {
|
|
120
|
+
named.add(id);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const results = await Promise.allSettled([...named].map((id) => loadOnce(highlighter, id)));
|
|
124
|
+
return results.some((result) => result.status === 'fulfilled');
|
|
125
|
+
}
|
|
126
|
+
/* Text names the optional embedded grammars that must load before the host hands out states. */
|
|
127
|
+
export async function loadGrammar(highlighter, grammar, text = '') {
|
|
128
|
+
await loadOnce(highlighter, grammar);
|
|
129
|
+
await loadEmbedded(highlighter, await embedIndex(grammar), text);
|
|
130
|
+
return highlighter.getLoadedLanguages().includes(grammar);
|
|
131
|
+
}
|
|
132
|
+
/*
|
|
133
|
+
* Colors with the viewer's highlighter, so a grammar loads once for both. A language Shiki has no
|
|
134
|
+
* grammar for, or a theme it cannot load, is plain text.
|
|
135
|
+
*/
|
|
136
|
+
export function shikiTokenizers(highlighter) {
|
|
137
|
+
return async (language, theme, text) => {
|
|
138
|
+
if (language === undefined || PLAIN_TEXT.has(language)) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
const grammar = documentLanguageOf(language);
|
|
142
|
+
const shiki = await highlighter();
|
|
143
|
+
try {
|
|
144
|
+
if (!shiki.getLoadedThemes().includes(theme)) {
|
|
145
|
+
await shiki.loadTheme(theme);
|
|
146
|
+
}
|
|
147
|
+
return (await loadGrammar(shiki, grammar, text)) ? lineTokenizer(shiki, grammar, theme, await embedIndex(grammar)) : null;
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/* The colors of a theme's own rules by scope, so what a language server classifies is drawn in the theme's colors. */
|
|
155
|
+
export function shikiScopeColors(highlighter) {
|
|
156
|
+
return async (theme) => {
|
|
157
|
+
const shiki = await highlighter();
|
|
158
|
+
try {
|
|
159
|
+
if (!shiki.getLoadedThemes().includes(theme)) {
|
|
160
|
+
await shiki.loadTheme(theme);
|
|
161
|
+
}
|
|
162
|
+
return scopeColorsOf(shiki.getTheme(theme).settings);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
package/dist/shiki-worker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { shikiDocumentTokens } from './shiki-document.js';
|
|
2
|
-
import { documentLanguageOf } from './shiki.js';
|
|
2
|
+
import { documentLanguageOf } from './shiki-grammar.js';
|
|
3
3
|
function yieldToHost() {
|
|
4
4
|
return new Promise((resolve) => {
|
|
5
5
|
const channel = new MessageChannel();
|
package/dist/shiki.d.ts
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { documentLanguageOf } from './php-html.ts';
|
|
3
|
-
import type { ScopeColorSource, TokenizerSource } from './types.ts';
|
|
4
|
-
export { documentLanguageOf };
|
|
5
|
-
export declare function loadGrammar(highlighter: Highlighter, grammar: string, text?: string): Promise<boolean>;
|
|
6
|
-
export declare function shikiTokenizers(highlighter: () => Promise<Highlighter>): TokenizerSource;
|
|
7
|
-
export declare function shikiScopeColors(highlighter: () => Promise<Highlighter>): ScopeColorSource;
|
|
1
|
+
export { documentLanguageOf, loadGrammar, shikiScopeColors, shikiTokenizers } from './shiki-grammar.ts';
|
|
8
2
|
export { shikiDocumentHighlighter, shikiDocumentTokens, type ShikiDocumentTokenOptions } from './shiki-document.ts';
|
package/dist/shiki.js
CHANGED
|
@@ -1,169 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { scopeColorsOf } from './theme-scopes.js';
|
|
3
|
-
export { documentLanguageOf };
|
|
4
|
-
/* The standard token types of TextMate: 1 comment, 2 string, 3 regex. */
|
|
5
|
-
const KINDS = { 1: 'comment', 2: 'string', 3: 'regex' };
|
|
6
|
-
const PLAIN_TEXT = new Set(['', 'text', 'txt', 'plain', 'plaintext']);
|
|
7
|
-
/* Colors one line at a time and hands the grammar's state from one line to the next. A grammar Shiki rebuilt does not know the states of the old one. */
|
|
8
|
-
function lineTokenizer(highlighter, language, theme, embedded) {
|
|
9
|
-
let grammar = highlighter.getLanguage(language);
|
|
10
|
-
return {
|
|
11
|
-
prepare: embedded.matcher === null ? undefined : (text) => loadEmbedded(highlighter, embedded, text),
|
|
12
|
-
stale() {
|
|
13
|
-
const current = highlighter.getLanguage(language);
|
|
14
|
-
const changed = current !== grammar;
|
|
15
|
-
grammar = current;
|
|
16
|
-
return changed;
|
|
17
|
-
},
|
|
18
|
-
tokenizeLine(text, state) {
|
|
19
|
-
const options = {
|
|
20
|
-
lang: language,
|
|
21
|
-
theme,
|
|
22
|
-
grammarState: (state ?? undefined),
|
|
23
|
-
includeExplanation: 'tokenType'
|
|
24
|
-
};
|
|
25
|
-
const lines = highlighter.codeToTokensBase(text, options);
|
|
26
|
-
const tokens = (lines[0] ?? []).map((token) => ({
|
|
27
|
-
length: token.content.length,
|
|
28
|
-
color: token.color ?? '',
|
|
29
|
-
fontStyle: token.fontStyle ?? 0,
|
|
30
|
-
kind: KINDS[token.type ?? 0]
|
|
31
|
-
}));
|
|
32
|
-
return { tokens, state: highlighter.getLastGrammarState(lines) };
|
|
33
|
-
},
|
|
34
|
-
sameState(a, b) {
|
|
35
|
-
if (a === b) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
const left = a?.getInternalStack(theme);
|
|
39
|
-
const right = b?.getInternalStack(theme);
|
|
40
|
-
return left !== undefined && right !== undefined && left.equals(right);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
const languageLoads = new WeakMap();
|
|
45
|
-
const embeddedIndexes = new Map();
|
|
46
|
-
/* Concurrent documents await one load, so each learns the grammar was rebuilt. */
|
|
47
|
-
function loadOnce(highlighter, id) {
|
|
48
|
-
if (highlighter.getLoadedLanguages().includes(id)) {
|
|
49
|
-
return Promise.resolve();
|
|
50
|
-
}
|
|
51
|
-
let loads = languageLoads.get(highlighter);
|
|
52
|
-
if (loads === undefined) {
|
|
53
|
-
loads = new Map();
|
|
54
|
-
languageLoads.set(highlighter, loads);
|
|
55
|
-
}
|
|
56
|
-
const pending = loads.get(id);
|
|
57
|
-
if (pending !== undefined) {
|
|
58
|
-
return pending;
|
|
59
|
-
}
|
|
60
|
-
const load = (async () => {
|
|
61
|
-
await loadDocumentLanguage(highlighter, id);
|
|
62
|
-
if (!highlighter.getLoadedLanguages().includes(id)) {
|
|
63
|
-
await highlighter.loadLanguage(id);
|
|
64
|
-
}
|
|
65
|
-
})();
|
|
66
|
-
loads.set(id, load);
|
|
67
|
-
void load.catch(() => {
|
|
68
|
-
if (loads.get(id) === load) {
|
|
69
|
-
loads.delete(id);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return load;
|
|
73
|
-
}
|
|
74
|
-
function embedIndex(grammar) {
|
|
75
|
-
const cached = embeddedIndexes.get(grammar);
|
|
76
|
-
if (cached !== undefined) {
|
|
77
|
-
return cached;
|
|
78
|
-
}
|
|
79
|
-
const pending = (async () => {
|
|
80
|
-
const { bundledLanguages, bundledLanguagesInfo } = await import('shiki');
|
|
81
|
-
const bundled = bundledLanguages[grammar];
|
|
82
|
-
const registrations = bundled === undefined ? [] : (await bundled()).default;
|
|
83
|
-
const lazy = registrations.find((registration) => registration.name === grammar)?.embeddedLangsLazy ?? [];
|
|
84
|
-
const names = new Map();
|
|
85
|
-
for (const id of lazy) {
|
|
86
|
-
const aliases = bundledLanguagesInfo.find((info) => info.id === id)?.aliases ?? [];
|
|
87
|
-
for (const name of [id, ...aliases]) {
|
|
88
|
-
names.set(name.toLowerCase(), id);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (names.size === 0) {
|
|
92
|
-
return { names, matcher: null };
|
|
93
|
-
}
|
|
94
|
-
let matcher;
|
|
95
|
-
if (grammar === 'markdown' || grammar === 'mdx') {
|
|
96
|
-
matcher = /^\s*(?:`{3,}|~{3,})[ \t]*([\w#+.-]+)/gm;
|
|
97
|
-
}
|
|
98
|
-
else if (grammar === 'vue' || grammar === 'svelte' || grammar === 'astro') {
|
|
99
|
-
matcher = /\blang\s*=\s*["']([\w#+.-]+)["']/gi;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
const alternatives = [...names.keys()].map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
|
|
103
|
-
matcher = new RegExp(`(?<![\\w-])(${alternatives})(?![\\w-])`, 'gi');
|
|
104
|
-
}
|
|
105
|
-
return { names, matcher };
|
|
106
|
-
})();
|
|
107
|
-
embeddedIndexes.set(grammar, pending);
|
|
108
|
-
void pending.catch(() => embeddedIndexes.delete(grammar));
|
|
109
|
-
return pending;
|
|
110
|
-
}
|
|
111
|
-
async function loadEmbedded(highlighter, embedded, text) {
|
|
112
|
-
if (embedded.matcher === null) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
const loaded = new Set(highlighter.getLoadedLanguages());
|
|
116
|
-
const named = new Set();
|
|
117
|
-
for (const match of text.matchAll(embedded.matcher)) {
|
|
118
|
-
const id = embedded.names.get(match[1].toLowerCase());
|
|
119
|
-
if (id !== undefined && !loaded.has(id)) {
|
|
120
|
-
named.add(id);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
const results = await Promise.allSettled([...named].map((id) => loadOnce(highlighter, id)));
|
|
124
|
-
return results.some((result) => result.status === 'fulfilled');
|
|
125
|
-
}
|
|
126
|
-
/* Text names the optional embedded grammars that must load before the host hands out states. */
|
|
127
|
-
export async function loadGrammar(highlighter, grammar, text = '') {
|
|
128
|
-
await loadOnce(highlighter, grammar);
|
|
129
|
-
await loadEmbedded(highlighter, await embedIndex(grammar), text);
|
|
130
|
-
return highlighter.getLoadedLanguages().includes(grammar);
|
|
131
|
-
}
|
|
132
|
-
/*
|
|
133
|
-
* Colors with the viewer's highlighter, so a grammar loads once for both. A language Shiki has no
|
|
134
|
-
* grammar for, or a theme it cannot load, is plain text.
|
|
135
|
-
*/
|
|
136
|
-
export function shikiTokenizers(highlighter) {
|
|
137
|
-
return async (language, theme, text) => {
|
|
138
|
-
if (language === undefined || PLAIN_TEXT.has(language)) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
const grammar = documentLanguageOf(language);
|
|
142
|
-
const shiki = await highlighter();
|
|
143
|
-
try {
|
|
144
|
-
if (!shiki.getLoadedThemes().includes(theme)) {
|
|
145
|
-
await shiki.loadTheme(theme);
|
|
146
|
-
}
|
|
147
|
-
return (await loadGrammar(shiki, grammar, text)) ? lineTokenizer(shiki, grammar, theme, await embedIndex(grammar)) : null;
|
|
148
|
-
}
|
|
149
|
-
catch {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
/* The colors of a theme's own rules by scope, so what a language server classifies is drawn in the theme's colors. */
|
|
155
|
-
export function shikiScopeColors(highlighter) {
|
|
156
|
-
return async (theme) => {
|
|
157
|
-
const shiki = await highlighter();
|
|
158
|
-
try {
|
|
159
|
-
if (!shiki.getLoadedThemes().includes(theme)) {
|
|
160
|
-
await shiki.loadTheme(theme);
|
|
161
|
-
}
|
|
162
|
-
return scopeColorsOf(shiki.getTheme(theme).settings);
|
|
163
|
-
}
|
|
164
|
-
catch {
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
1
|
+
export { documentLanguageOf, loadGrammar, shikiScopeColors, shikiTokenizers } from './shiki-grammar.js';
|
|
169
2
|
export { shikiDocumentHighlighter, shikiDocumentTokens } from './shiki-document.js';
|
package/dist/smart-keys.js
CHANGED
package/dist/testing.js
CHANGED
|
@@ -43,14 +43,12 @@ export function createPage() {
|
|
|
43
43
|
function createEvent(window, type) {
|
|
44
44
|
return new window.Event(type, { bubbles: true, cancelable: true });
|
|
45
45
|
}
|
|
46
|
-
/* Fires a keydown at the element and says whether the editor took the key. */
|
|
47
46
|
export function press(window, target, key, options = {}) {
|
|
48
47
|
const event = createEvent(window, 'keydown');
|
|
49
48
|
Object.assign(event, { key, ctrlKey: false, metaKey: false, altKey: false, shiftKey: false, isComposing: false, ...options });
|
|
50
49
|
target.dispatchEvent(event);
|
|
51
50
|
return event.defaultPrevented;
|
|
52
51
|
}
|
|
53
|
-
/* Fires a keyup at the element, the other half of `press`. */
|
|
54
52
|
export function release(window, target, key, options = {}) {
|
|
55
53
|
const event = createEvent(window, 'keyup');
|
|
56
54
|
Object.assign(event, { key, ctrlKey: false, metaKey: false, altKey: false, shiftKey: false, isComposing: false, ...options });
|
package/dist/todos.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type DocumentModel, type TodoMatch } from '@adecore/editor-core';
|
|
2
2
|
import type { LineToken } from './types.ts';
|
|
3
|
-
|
|
3
|
+
type TodoMark = TodoMatch & {
|
|
4
4
|
readonly text: string;
|
|
5
5
|
};
|
|
6
6
|
export declare class TodoMarks {
|
|
@@ -21,3 +21,4 @@ export declare class TodoMarks {
|
|
|
21
21
|
refresh(): void;
|
|
22
22
|
dispose(): void;
|
|
23
23
|
}
|
|
24
|
+
export {};
|
package/dist/tokens.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DocumentChange } from '@adecore/editor-core';
|
|
2
2
|
import type { LineToken, LineTokenizer } from './types.ts';
|
|
3
|
-
|
|
3
|
+
interface TokenSource {
|
|
4
4
|
getLineCount(): number;
|
|
5
5
|
getLineText(line: number): string;
|
|
6
6
|
}
|
|
@@ -29,3 +29,4 @@ export declare class TokenCache {
|
|
|
29
29
|
private forgetPivot;
|
|
30
30
|
covers(line: number): boolean;
|
|
31
31
|
}
|
|
32
|
+
export {};
|