@bearcove/monaco-lang-styx 0.1.0
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/index.cjs +507 -0
- package/dist/index.d.cts +103 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +476 -0
- package/package.json +51 -0
- package/src/index.ts +106 -0
- package/src/theme.ts +115 -0
- package/src/tokenizer.ts +496 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type * as monaco from 'monaco-editor';
|
|
2
|
+
import { StyxTokensProvider } from './tokenizer';
|
|
3
|
+
import { catppuccinMocha, mocha } from './theme';
|
|
4
|
+
|
|
5
|
+
export { StyxTokensProvider } from './tokenizer';
|
|
6
|
+
export { catppuccinMocha, mocha } from './theme';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Styx language configuration for Monaco editor.
|
|
10
|
+
* Defines brackets, comments, and auto-closing pairs.
|
|
11
|
+
*/
|
|
12
|
+
export const styxLanguageConfig: monaco.languages.LanguageConfiguration = {
|
|
13
|
+
comments: { lineComment: '//' },
|
|
14
|
+
brackets: [
|
|
15
|
+
['{', '}'],
|
|
16
|
+
['(', ')'],
|
|
17
|
+
],
|
|
18
|
+
autoClosingPairs: [
|
|
19
|
+
{ open: '{', close: '}' },
|
|
20
|
+
{ open: '(', close: ')' },
|
|
21
|
+
{ open: '"', close: '"' },
|
|
22
|
+
],
|
|
23
|
+
surroundingPairs: [
|
|
24
|
+
{ open: '{', close: '}' },
|
|
25
|
+
{ open: '(', close: ')' },
|
|
26
|
+
{ open: '"', close: '"' },
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Options for registering the Styx language.
|
|
32
|
+
*/
|
|
33
|
+
export interface RegisterStyxOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Whether to define the Catppuccin Mocha theme.
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
38
|
+
defineTheme?: boolean;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Whether to register embedded languages for heredoc injection (SQL, JavaScript, etc.)
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
registerEmbeddedLanguages?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Language definitions for embedded language support in heredocs.
|
|
49
|
+
*/
|
|
50
|
+
interface EmbeddedLanguage {
|
|
51
|
+
id: string;
|
|
52
|
+
def: {
|
|
53
|
+
conf: monaco.languages.LanguageConfiguration;
|
|
54
|
+
language: monaco.languages.IMonarchLanguage;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Register the Styx language with Monaco editor.
|
|
60
|
+
*
|
|
61
|
+
* @param monacoInstance - The monaco module
|
|
62
|
+
* @param embeddedLanguages - Optional array of embedded languages for heredoc injection.
|
|
63
|
+
* These are the monaco basic language definitions (sql, javascript, etc.)
|
|
64
|
+
* @param options - Registration options
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import * as monaco from 'monaco-editor';
|
|
69
|
+
* import * as sqlLang from 'monaco-editor/esm/vs/basic-languages/sql/sql';
|
|
70
|
+
* import { registerStyxLanguage } from '@bearcove/monaco-lang-styx';
|
|
71
|
+
*
|
|
72
|
+
* registerStyxLanguage(monaco, [
|
|
73
|
+
* { id: 'sql', def: sqlLang },
|
|
74
|
+
* ]);
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function registerStyxLanguage(
|
|
78
|
+
monacoInstance: typeof monaco,
|
|
79
|
+
embeddedLanguages?: EmbeddedLanguage[],
|
|
80
|
+
options: RegisterStyxOptions = {}
|
|
81
|
+
): void {
|
|
82
|
+
const { defineTheme = true, registerEmbeddedLanguages = true } = options;
|
|
83
|
+
|
|
84
|
+
// Register embedded languages first (for heredoc injection)
|
|
85
|
+
if (registerEmbeddedLanguages && embeddedLanguages) {
|
|
86
|
+
for (const { id, def } of embeddedLanguages) {
|
|
87
|
+
// Check if language is already registered
|
|
88
|
+
const existing = monacoInstance.languages.getLanguages().find((l) => l.id === id);
|
|
89
|
+
if (!existing) {
|
|
90
|
+
monacoInstance.languages.register({ id });
|
|
91
|
+
}
|
|
92
|
+
monacoInstance.languages.setMonarchTokensProvider(id, def.language);
|
|
93
|
+
monacoInstance.languages.setLanguageConfiguration(id, def.conf);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Register Styx language
|
|
98
|
+
monacoInstance.languages.register({ id: 'styx' });
|
|
99
|
+
monacoInstance.languages.setTokensProvider('styx', new StyxTokensProvider(monacoInstance.editor));
|
|
100
|
+
monacoInstance.languages.setLanguageConfiguration('styx', styxLanguageConfig);
|
|
101
|
+
|
|
102
|
+
// Define theme
|
|
103
|
+
if (defineTheme) {
|
|
104
|
+
monacoInstance.editor.defineTheme('catppuccin-mocha', catppuccinMocha);
|
|
105
|
+
}
|
|
106
|
+
}
|
package/src/theme.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type * as monaco from 'monaco-editor';
|
|
2
|
+
|
|
3
|
+
// Catppuccin Mocha theme - https://github.com/catppuccin/catppuccin
|
|
4
|
+
// Base colors
|
|
5
|
+
export const mocha = {
|
|
6
|
+
rosewater: 'f5e0dc',
|
|
7
|
+
flamingo: 'f2cdcd',
|
|
8
|
+
pink: 'f5c2e7',
|
|
9
|
+
mauve: 'cba6f7',
|
|
10
|
+
red: 'f38ba8',
|
|
11
|
+
maroon: 'eba0ac',
|
|
12
|
+
peach: 'fab387',
|
|
13
|
+
yellow: 'f9e2af',
|
|
14
|
+
green: 'a6e3a1',
|
|
15
|
+
teal: '94e2d5',
|
|
16
|
+
sky: '89dceb',
|
|
17
|
+
sapphire: '74c7ec',
|
|
18
|
+
blue: '89b4fa',
|
|
19
|
+
lavender: 'b4befe',
|
|
20
|
+
text: 'cdd6f4',
|
|
21
|
+
subtext1: 'bac2de',
|
|
22
|
+
subtext0: 'a6adc8',
|
|
23
|
+
overlay2: '9399b2',
|
|
24
|
+
overlay1: '7f849c',
|
|
25
|
+
overlay0: '6c7086',
|
|
26
|
+
surface2: '585b70',
|
|
27
|
+
surface1: '45475a',
|
|
28
|
+
surface0: '313244',
|
|
29
|
+
base: '1e1e2e',
|
|
30
|
+
mantle: '181825',
|
|
31
|
+
crust: '11111b',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Catppuccin Mocha theme for Monaco editor.
|
|
36
|
+
* A dark theme with warm, readable colors optimized for Styx syntax highlighting.
|
|
37
|
+
*/
|
|
38
|
+
export const catppuccinMocha: monaco.editor.IStandaloneThemeData = {
|
|
39
|
+
base: 'vs-dark',
|
|
40
|
+
inherit: true,
|
|
41
|
+
rules: [
|
|
42
|
+
// Comments
|
|
43
|
+
{ token: 'comment', foreground: mocha.overlay1, fontStyle: 'italic' },
|
|
44
|
+
{ token: 'comment.doc', foreground: mocha.overlay2, fontStyle: 'italic' },
|
|
45
|
+
|
|
46
|
+
// Keys - pink/flamingo for that warm feel
|
|
47
|
+
{ token: 'key', foreground: mocha.flamingo },
|
|
48
|
+
{ token: 'string.key', foreground: mocha.flamingo },
|
|
49
|
+
{ token: 'tag.key', foreground: mocha.mauve },
|
|
50
|
+
|
|
51
|
+
// Values - sapphire/blue
|
|
52
|
+
{ token: 'value', foreground: mocha.sapphire },
|
|
53
|
+
|
|
54
|
+
// Tags - mauve (purple)
|
|
55
|
+
{ token: 'tag', foreground: mocha.mauve },
|
|
56
|
+
|
|
57
|
+
// Strings - green
|
|
58
|
+
{ token: 'string', foreground: mocha.green },
|
|
59
|
+
{ token: 'string.heredoc', foreground: mocha.green },
|
|
60
|
+
{ token: 'string.escape', foreground: mocha.peach },
|
|
61
|
+
|
|
62
|
+
// Delimiters
|
|
63
|
+
{ token: 'delimiter.curly', foreground: mocha.yellow },
|
|
64
|
+
{ token: 'delimiter.parenthesis', foreground: mocha.pink },
|
|
65
|
+
{ token: 'delimiter.comma', foreground: mocha.overlay2 },
|
|
66
|
+
|
|
67
|
+
// Invalid
|
|
68
|
+
{ token: 'invalid', foreground: mocha.red },
|
|
69
|
+
|
|
70
|
+
// Additional token types for embedded languages
|
|
71
|
+
{ token: 'keyword', foreground: mocha.mauve },
|
|
72
|
+
{ token: 'keyword.sql', foreground: mocha.mauve },
|
|
73
|
+
{ token: 'operator', foreground: mocha.sky },
|
|
74
|
+
{ token: 'operator.sql', foreground: mocha.sky },
|
|
75
|
+
{ token: 'number', foreground: mocha.peach },
|
|
76
|
+
{ token: 'number.json', foreground: mocha.peach },
|
|
77
|
+
{ token: 'identifier', foreground: mocha.text },
|
|
78
|
+
{ token: 'type', foreground: mocha.yellow },
|
|
79
|
+
{ token: 'type.identifier.json', foreground: mocha.blue },
|
|
80
|
+
{ token: 'predefined', foreground: mocha.blue },
|
|
81
|
+
{ token: 'predefined.sql', foreground: mocha.blue },
|
|
82
|
+
|
|
83
|
+
// JSON specific
|
|
84
|
+
{ token: 'string.key.json', foreground: mocha.flamingo },
|
|
85
|
+
{ token: 'string.value.json', foreground: mocha.green },
|
|
86
|
+
{ token: 'keyword.json', foreground: mocha.mauve },
|
|
87
|
+
{ token: 'delimiter.bracket.json', foreground: mocha.overlay2 },
|
|
88
|
+
{ token: 'delimiter.array.json', foreground: mocha.pink },
|
|
89
|
+
{ token: 'delimiter.colon.json', foreground: mocha.overlay2 },
|
|
90
|
+
{ token: 'delimiter.comma.json', foreground: mocha.overlay2 },
|
|
91
|
+
],
|
|
92
|
+
colors: {
|
|
93
|
+
'editor.background': '#' + mocha.base,
|
|
94
|
+
'editor.foreground': '#' + mocha.text,
|
|
95
|
+
'editor.lineHighlightBackground': '#' + mocha.surface0,
|
|
96
|
+
'editorCursor.foreground': '#' + mocha.rosewater,
|
|
97
|
+
'editor.selectionBackground': '#' + mocha.surface2 + '80',
|
|
98
|
+
'editorLineNumber.foreground': '#' + mocha.surface2,
|
|
99
|
+
'editorLineNumber.activeForeground': '#' + mocha.lavender,
|
|
100
|
+
'editorIndentGuide.background': '#' + mocha.surface1,
|
|
101
|
+
'editorIndentGuide.activeBackground': '#' + mocha.surface2,
|
|
102
|
+
'editorBracketMatch.background': '#' + mocha.surface2 + '80',
|
|
103
|
+
'editorBracketMatch.border': '#' + mocha.mauve,
|
|
104
|
+
'editor.findMatchBackground': '#' + mocha.peach + '40',
|
|
105
|
+
'editor.findMatchHighlightBackground': '#' + mocha.yellow + '30',
|
|
106
|
+
'editorWidget.background': '#' + mocha.mantle,
|
|
107
|
+
'editorWidget.border': '#' + mocha.surface1,
|
|
108
|
+
'input.background': '#' + mocha.surface0,
|
|
109
|
+
'input.border': '#' + mocha.surface1,
|
|
110
|
+
'input.foreground': '#' + mocha.text,
|
|
111
|
+
'scrollbarSlider.background': '#' + mocha.surface1 + '80',
|
|
112
|
+
'scrollbarSlider.hoverBackground': '#' + mocha.surface2 + '80',
|
|
113
|
+
'scrollbarSlider.activeBackground': '#' + mocha.surface2,
|
|
114
|
+
},
|
|
115
|
+
};
|