@op-ted/efx-syntax-highlighter 0.5.0 → 0.6.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/README.md CHANGED
@@ -34,13 +34,16 @@ const view = new EditorView({
34
34
  });
35
35
  ```
36
36
 
37
- The package offers five things:
37
+ The package offers these things:
38
38
 
39
39
  - **`efx(kind)`** gives an editor what it needs to read one kind of EFX-2 text: its parser, the EFX colours and the completions. The kind is `'template'` for a template file, `'rules'` for a rules file, `'expression'` for a single expression with its context, such as `WITH ND-Root COMPUTE BT-01-notice is present`, or `'bare-expression'` for an expression with no context in the text, such as `BT-01-notice is present`, read as the expression of `WITH … COMPUTE`. Any other kind is refused with a `RangeError`. `efx(kind).language` is the CodeMirror language, for an application that needs it on its own.
40
40
  - **`efx(kind, { version: 1 })`** does the same for EFX-1 text, without completions. The kinds are `'template'`, `'expression'`, such as `{ND-Root} ${BT-01-notice is present}`, and `'bare-expression'`; EFX-1 has no rules files. Any other kind or version is refused with a `RangeError`.
41
41
  - **`efxSymbols`** gives the editor the field and node ids it offers: `efxSymbols.of({ fields, nodes })`, each a list of ids, for example those of the SDK's `fields.json`. An entry can also be an id with its type, such as `{ id: 'BT-01-notice', type: 'code' }`; the editor shows the type beside the id, and "field" or "node" beside an id without one. The ids of several such extensions add up.
42
42
  - **`efxHighlightStyle`** is the EFX colours. `efx(kind)` already uses them as the editor's default colours; an application that gives its editor its own colours with `syntaxHighlighting(...)` replaces them.
43
43
  - **`efxTheme`** is a light look for the editor itself (white background, black cursor). Add it if you want it.
44
+ - **`efxDarkTheme`** is a dark look for the editor, with the EFX colours for a dark background. Add it instead of `efxTheme` on a dark screen. **`efxDarkHighlightStyle`** is those colours on their own, for an application that gives its editor its own dark look: `syntaxHighlighting(efxDarkHighlightStyle)`.
45
+
46
+ Both sets of colours mark the same kind of word with the same hue: purple for keywords and the words of expressions, green for fields and nodes, orange for variables and declared functions, pink for literals and the names of assets, and grey for operators and punctuation. Every colour reaches 4.5:1 against its background, the contrast that WCAG 2.1 AA and EN 301 549 require for text: the light colours against white, the dark ones against `#1e1f22`.
44
47
 
45
48
  The package ships its TypeScript types, so that an application written in TypeScript has its calls checked.
46
49
 
@@ -64,12 +67,12 @@ Known limits: after a `/` the `@` of an attribute is not offered; after a syntax
64
67
  ```bash
65
68
  npm run sync # writes the lexer tables, the words and the completion list (committed), and the SDK's EFX files and ANTLR grammars that the tests and the demo read (not committed)
66
69
  npm run build # generates the parsers from grammar/efx2.grammar and grammar/efx1.grammar and writes the package to dist/
67
- npm test # the package, lexer, conformance, style, EFX-2 tree and completion, EFX-1 entry and incremental tests, on the build
70
+ npm test # the package, lexer, conformance, style, EFX-2 tree and completion, EFX-1 entry, incremental, types and colour tests, on the build
68
71
  npm run demo # serves a demo page at http://localhost:8080/demo/ (after npm run sync and npm run build)
69
72
  npm run site # gathers the demo page and what it loads into site/ (after npm run sync and npm run build)
70
73
  ```
71
74
 
72
- Each version of EFX has its own places: its grammar in `grammar/efx2.grammar` or `grammar/efx1.grammar`, the modules its parser loads in `src/efx2/` or `src/efx1/` (its lexer table and the lexer's options in `lexer.js`, its highlight tags, and for EFX-2 its completions), and its tests, its copy of the SDK's ANTLR grammar (`oracle/`) and of the SDK's EFX files (`corpus/`) in `test/efx2/` or `test/efx1/`. What both share is at the top of `src/` and `test/`: the entry point and the language (`src/efxLanguage.js`), the lexer engine (`src/lexer/`), the ids (`src/efxSymbols.js`), the colours (`src/efxTheme.js`), and the package, lexer, conformance, style and incremental tests. The build writes each parser beside its modules, in `dist/efx2/` and `dist/efx1/`.
75
+ Each version of EFX has its own places: its grammar in `grammar/efx2.grammar` or `grammar/efx1.grammar`, the modules its parser loads in `src/efx2/` or `src/efx1/` (its lexer table and the lexer's options in `lexer.js`, its highlight tags, and for EFX-2 its completions), and its tests, its copy of the SDK's ANTLR grammar (`oracle/`) and of the SDK's EFX files (`corpus/`) in `test/efx2/` or `test/efx1/`. What both share is at the top of `src/` and `test/`: the entry point and the language (`src/efxLanguage.js`), the lexer engine (`src/lexer/`), the ids (`src/efxSymbols.js`), the colours (`src/efxTheme.js`), and the package, lexer, conformance, style, incremental and colour tests. The build writes each parser beside its modules, in `dist/efx2/` and `dist/efx1/`.
73
76
 
74
77
  The lexer reads the text on its own, as ANTLR's does, whatever the parser makes of the tokens, so the editor shows the tokens ANTLR's lexer reads, errors included. As a token depends on all the text before it, through the lexer's modes, the editor reuses its earlier tree only before the first change to the text, and the lexer reads the parts of the document a parse reads as one text, as ANTLR would (`src/lexer/EditorParser.js`). A comment that a token holds (the `;` that ends a template line, the path of an include) is shown as a comment.
75
78
 
package/dist/efxTheme.js CHANGED
@@ -1,35 +1,75 @@
1
- // The look of EFX in an editor: the colour of each highlight tag (efxHighlightStyle), which efx()
2
- // gives the editor as its default colours, and a look for the editor itself (efxTheme), which an
3
- // application adds if it wants it.
1
+ // The look of EFX in an editor: the colour of each highlight tag, and a look for the editor itself.
2
+ // - efxHighlightStyle, the EFX colours for a light background, which efx() gives the editor as its
3
+ // default colours; and efxTheme, a light look for the editor, which an application adds if it wants it.
4
+ // - efxDarkHighlightStyle, the same colours for a dark background; and efxDarkTheme, a dark look for the
5
+ // editor together with those colours, which an application adds instead of efxTheme on a dark screen.
6
+ // Every colour reaches 4.5:1 against its background, the contrast WCAG 2.1 AA and EN 301 549 require
7
+ // for text of this size, bold or not (test/colours.js checks it). Both sets keep the same hue for the
8
+ // same kind of word: purple for keywords, green for fields and nodes, orange for variables and
9
+ // declared functions, pink for literals and names of assets, and grey for operators and punctuation.
4
10
  import { tags as t } from "@lezer/highlight";
5
- import { HighlightStyle } from "@codemirror/language";
11
+ import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
6
12
  import { EditorView } from "@codemirror/view";
7
13
 
8
- export const efxHighlightStyle = HighlightStyle.define([
9
- { tag: t.keyword, color: "#7058be", fontWeight: "bold" },
10
- { tag: t.typeName, color: "#7058be" },
11
- { tag: t.literal, color: "#e14775" },
12
- { tag: t.propertyName, color: "#269d69", fontWeight: "bold" },
13
- { tag: t.variableName, color: "#cc7a0a", fontWeight: "bold" },
14
- { tag: t.function(t.name), color: "#cc7a0a", fontWeight: "bold" },
15
- { tag: t.function(t.keyword), color: "#7058be", fontWeight: "bold" },
16
- { tag: t.name, color: "#24292e" },
17
- { tag: t.className, color: "#7058be" },
18
- { tag: t.operator, color: "#6d6d6d", fontWeight: "bold" },
19
- { tag: t.punctuation, color: "#cc7a0a" },
20
- { tag: t.bracket, color: "#cc7a0a" },
21
- { tag: t.lineComment, color: "#999999", fontStyle: "italic" },
22
- { tag: t.special(t.name), color: "#e14775" },
23
- { tag: t.special(t.string), color: "black" },
24
- ]);
14
+ // The background each set of colours is made for.
15
+ export const LIGHT_BACKGROUND = "#ffffff";
16
+ export const DARK_BACKGROUND = "#1e1f22";
17
+
18
+ /** The highlight style of a palette: the colour, and the weight or slant, of each highlight tag. */
19
+ function styleOf(colours) {
20
+ return HighlightStyle.define([
21
+ { tag: t.keyword, color: colours.keyword, fontWeight: "bold" },
22
+ { tag: t.typeName, color: colours.keyword },
23
+ { tag: t.literal, color: colours.literal },
24
+ { tag: t.propertyName, color: colours.data, fontWeight: "bold" },
25
+ { tag: t.variableName, color: colours.variable, fontWeight: "bold" },
26
+ { tag: t.function(t.name), color: colours.variable, fontWeight: "bold" },
27
+ { tag: t.function(t.keyword), color: colours.keyword, fontWeight: "bold" },
28
+ { tag: t.name, color: colours.name },
29
+ { tag: t.className, color: colours.keyword },
30
+ { tag: t.operator, color: colours.operator, fontWeight: "bold" },
31
+ { tag: t.punctuation, color: colours.operator },
32
+ { tag: t.bracket, color: colours.operator, fontWeight: "bold" },
33
+ { tag: t.lineComment, color: colours.comment, fontStyle: "italic" },
34
+ { tag: t.special(t.name), color: colours.literal },
35
+ { tag: t.special(t.string), color: colours.text },
36
+ ]);
37
+ }
38
+
39
+ // The colours of each palette, by the kind of word they mark.
40
+ export const LIGHT_COLOURS = {
41
+ keyword: "#7058be",
42
+ data: "#208559",
43
+ variable: "#a96508",
44
+ literal: "#dc2b60",
45
+ operator: "#6d6d6d",
46
+ comment: "#757575",
47
+ name: "#24292e",
48
+ text: "#000000",
49
+ };
50
+
51
+ export const DARK_COLOURS = {
52
+ keyword: "#afa1db",
53
+ data: "#2ec081",
54
+ variable: "#f3920c",
55
+ literal: "#f08cab",
56
+ operator: "#b4b4b4",
57
+ comment: "#8c8c8c",
58
+ name: "#c9d1d9",
59
+ text: "#e6e6e6",
60
+ };
61
+
62
+ export const efxHighlightStyle = styleOf(LIGHT_COLOURS);
63
+
64
+ export const efxDarkHighlightStyle = styleOf(DARK_COLOURS);
25
65
 
26
66
  export const efxTheme = EditorView.theme({
27
67
  "&": {
28
- backgroundColor: "#ffffff",
68
+ backgroundColor: LIGHT_BACKGROUND,
29
69
  color: "#000000"
30
70
  },
31
71
  ".cm-content": {
32
- backgroundColor: "#ffffff",
72
+ backgroundColor: LIGHT_BACKGROUND,
33
73
  caretColor: "#000000"
34
74
  },
35
75
  ".cm-cursor, .cm-dropCursor": {
@@ -44,3 +84,31 @@ export const efxTheme = EditorView.theme({
44
84
  borderLeftColor: "#000000 !important"
45
85
  }
46
86
  });
87
+
88
+ export const efxDarkTheme = [
89
+ EditorView.theme({
90
+ "&": {
91
+ backgroundColor: DARK_BACKGROUND,
92
+ color: DARK_COLOURS.text
93
+ },
94
+ ".cm-content": {
95
+ backgroundColor: DARK_BACKGROUND,
96
+ caretColor: "#ffffff"
97
+ },
98
+ ".cm-cursor, .cm-dropCursor": {
99
+ borderLeftColor: "#ffffff !important",
100
+ borderLeftWidth: "2px !important",
101
+ borderLeftStyle: "solid !important"
102
+ },
103
+ "&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection": {
104
+ backgroundColor: "#264f78 !important"
105
+ },
106
+ ".cm-selectionMatch": {
107
+ backgroundColor: "#3a3d41 !important"
108
+ },
109
+ "&.cm-focused .cm-cursor": {
110
+ borderLeftColor: "#ffffff !important"
111
+ }
112
+ }, { dark: true }),
113
+ syntaxHighlighting(efxDarkHighlightStyle),
114
+ ];
package/dist/index.d.ts CHANGED
@@ -34,8 +34,17 @@ export interface EfxSymbols {
34
34
  */
35
35
  export const efxSymbols: Facet<EfxSymbols, { fields: (string | EfxSymbol)[]; nodes: (string | EfxSymbol)[] }>;
36
36
 
37
- /** The EFX colours, which efx() gives the editor as its default colours. */
37
+ /** The EFX colours for a light background, which efx() gives the editor as its default colours. */
38
38
  export const efxHighlightStyle: HighlightStyle;
39
39
 
40
40
  /** A light look for the editor itself, which an application adds if it wants it. */
41
41
  export const efxTheme: Extension;
42
+
43
+ /** The EFX colours for a dark background. efxDarkTheme already includes them. */
44
+ export const efxDarkHighlightStyle: HighlightStyle;
45
+
46
+ /**
47
+ * A dark look for the editor itself, with the EFX colours for a dark background, which an application
48
+ * adds instead of efxTheme on a dark screen.
49
+ */
50
+ export const efxDarkTheme: Extension;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // The package's public surface: EFX support for a CodeMirror 6 editor (efx), the field and node ids
2
- // it offers (efxSymbols), the EFX colours (efxHighlightStyle) and a look for the editor (efxTheme).
2
+ // it offers (efxSymbols), the EFX colours (efxHighlightStyle) and a light look for the editor
3
+ // (efxTheme), and the same for a dark background (efxDarkHighlightStyle, efxDarkTheme).
3
4
  export { efx } from './efxLanguage.js';
4
5
  export { efxSymbols } from './efxSymbols.js';
5
- export { efxHighlightStyle, efxTheme } from './efxTheme.js';
6
+ export { efxDarkHighlightStyle, efxDarkTheme, efxHighlightStyle, efxTheme } from './efxTheme.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-ted/efx-syntax-highlighter",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Lezer-based parser and CodeMirror 6 language support for EFX: syntax highlighting and completions.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "scripts": {
18
18
  "build": "node scripts/build.js",
19
- "test": "node test/synced.js && node test/package.js && node test/sync.js && node test/lexer.js && node test/conformance.js && node test/styles.js && node test/efx2/trees.js && node test/efx2/completions.js && node test/efx1/entries.js && node test/incremental.js && node test/types.js",
19
+ "test": "node test/synced.js && node test/package.js && node test/sync.js && node test/lexer.js && node test/conformance.js && node test/styles.js && node test/efx2/trees.js && node test/efx2/completions.js && node test/efx1/entries.js && node test/incremental.js && node test/types.js && node test/colours.js",
20
20
  "sync": "node scripts/sync.js",
21
21
  "demo": "node scripts/demo.js",
22
22
  "site": "node scripts/site.js"