From 90122a4c8452da6b1be6aecebaa926899e528af8 Mon Sep 17 00:00:00 2001 From: Samin Yeasar Sohag Date: Tue, 17 Nov 2026 20:48:53 +0600 Subject: [PATCH] =?UTF-8?q?feat!:=20val=5Fhighlight=201.0.0=20=E2=80=94=20?= =?UTF-8?q?stable=20API,=20linear-time=20grammars,=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Freeze the core API for 1.0 and fix the engine problems an audit found. Breaking (see docs/upgrading.mdx): - HighlightResult.fromBuffers, rawEnds and rawStacks, and ScopeTable's constructor, nameId and push are no longer public. - IncrementalHighlighter.lastRescannedLines is read-only. - BlockRule is an abstract base class. - Operators takes its characters as required and scope by name; Annotation and Preprocessor take sigil and scope by name. - LanguageRegistry takes fallback by name. - Detection.reason is a DetectionReason enum. - languages/c.dart no longer exports the shared C lists. - ValTheme.lookup merges a dotted scope's prefixes, matching the CSS classes (no change for the built-in themes). - matchingBracket defaults to the language's brackets. Fixed: - Quadratic time on long runs of one pattern in 20 languages (80,000 `#` took 49 s in Swift). test/hostile_input_test.dart now checks every language on every punctuation character and the patterns that were slow. - GrammarException on very long delimiters; delimiters over 1,024 characters are plain text. - Unbounded memory from caching one state per distinct heredoc tag or fence; at most 64 are kept per grammar. - LanguageRegistry.add listed a language twice. Docs: upgrade guide, streaming text, platforms and versions, troubleshooting; capture-group and linear-time guidance for grammar authors; US spelling; benchmark numbers from one fresh run. Every new sample is covered by the snippet tests. --- README.md | 12 +- docs/api/_code-field.mdx | 14 +- docs/api/_grammar.mdx | 61 +++------ docs/api/_highlighting.mdx | 41 +++--- docs/api/_incremental.mdx | 2 +- docs/api/_lookup.mdx | 26 +++- docs/api/_rendering.mdx | 2 +- docs/api/_text-field.mdx | 8 +- docs/api/_theme-list.mdx | 4 +- docs/api/_themes.mdx | 7 +- docs/components/code-field.mdx | 8 +- docs/components/code-view.mdx | 2 +- docs/components/rendering.mdx | 4 +- docs/components/text-field.mdx | 8 +- docs/customize/writing-a-grammar.mdx | 31 ++++- docs/engine/highlighting.mdx | 7 +- docs/engine/html.mdx | 2 +- docs/engine/incremental.mdx | 3 + docs/engine/lookup.mdx | 8 +- docs/engine/streaming.mdx | 87 +++++++++++++ docs/getting-started.mdx | 5 +- docs/reference/performance.mdx | 36 +++--- docs/reference/platforms.mdx | 62 +++++++++ docs/reference/scopes.mdx | 14 +- docs/reference/troubleshooting.mdx | 92 ++++++++++++++ docs/site.json | 6 +- docs/themes.mdx | 15 ++- docs/upgrading.mdx | 120 ++++++++++++++++++ val_highlight/CHANGELOG.md | 59 +++++++++ val_highlight/README.md | 32 ++--- val_highlight/example/main.dart | 8 +- val_highlight/lib/languages/all.dart | 2 +- val_highlight/lib/languages/c.dart | 36 +----- val_highlight/lib/languages/cpp.dart | 6 +- val_highlight/lib/languages/csharp.dart | 2 +- val_highlight/lib/languages/generic.dart | 7 +- val_highlight/lib/languages/go.dart | 10 +- val_highlight/lib/languages/graphql.dart | 2 +- val_highlight/lib/languages/kotlin.dart | 2 +- val_highlight/lib/languages/markdown.dart | 4 +- val_highlight/lib/languages/nasm.dart | 2 +- val_highlight/lib/languages/objectivec.dart | 2 +- val_highlight/lib/languages/perl.dart | 2 +- val_highlight/lib/languages/php.dart | 4 +- val_highlight/lib/languages/powershell.dart | 2 +- val_highlight/lib/languages/ruby.dart | 4 +- val_highlight/lib/languages/scala.dart | 4 +- val_highlight/lib/languages/swift.dart | 4 +- val_highlight/lib/languages/yaml.dart | 8 +- val_highlight/lib/src/detect.dart | 36 +++++- val_highlight/lib/src/engine/compiler.dart | 28 ++++ val_highlight/lib/src/engine/scanner.dart | 17 ++- val_highlight/lib/src/engine/scope_table.dart | 21 ++- val_highlight/lib/src/grammar/blocks.dart | 19 ++- val_highlight/lib/src/grammar/grammar.dart | 7 +- val_highlight/lib/src/highlighter.dart | 4 +- val_highlight/lib/src/incremental.dart | 13 +- val_highlight/lib/src/languages/c_family.dart | 38 ++++++ .../lib/src/languages/ecmascript.dart | 5 +- val_highlight/lib/src/registry.dart | 7 +- val_highlight/lib/src/result.dart | 64 +++++++--- val_highlight/lib/src/theme/theme.dart | 21 +-- val_highlight/lib/src/theme/vscode.dart | 2 +- .../lib/themes/high_contrast_dark.dart | 2 +- .../lib/themes/high_contrast_light.dart | 2 +- val_highlight/lib/val_highlight.dart | 2 +- val_highlight/pubspec.yaml | 2 +- val_highlight/test/docs/snippets_test.dart | 107 +++++++++++++++- val_highlight/test/editing_test.dart | 11 ++ val_highlight/test/engine_test.dart | 14 ++ val_highlight/test/hostile_input_test.dart | 93 ++++++++++++++ val_highlight/test/isolate_test.dart | 23 ++++ val_highlight/test/lines_and_detect_test.dart | 2 +- val_highlight/test/themes_test.dart | 30 +++++ val_highlight/tool/corpus_sweep.dart | 3 +- val_highlight_flutter/CHANGELOG.md | 4 + val_highlight_flutter/README.md | 8 +- val_highlight_flutter/example/pubspec.yaml | 2 +- .../lib/src/code_editing.dart | 10 +- val_highlight_flutter/lib/src/code_field.dart | 10 +- .../lib/src/editor_decorations.dart | 2 +- .../lib/src/highlight_text_controller.dart | 4 +- val_highlight_flutter/lib/src/spans.dart | 2 +- val_highlight_flutter/pubspec.yaml | 2 +- .../test/docs/api_completeness_test.dart | 1 - .../test/docs/snippets_test.dart | 71 +++++++++++ .../tool/docs/api_reference.dart | 35 ++++- 87 files changed, 1271 insertions(+), 342 deletions(-) create mode 100644 docs/engine/streaming.mdx create mode 100644 docs/reference/platforms.mdx create mode 100644 docs/reference/troubleshooting.mdx create mode 100644 docs/upgrading.mdx create mode 100644 val_highlight/lib/src/languages/c_family.dart create mode 100644 val_highlight/test/hostile_input_test.dart create mode 100644 val_highlight/test/isolate_test.dart diff --git a/README.md b/README.md index 84572f5..65cec03 100644 --- a/README.md +++ b/README.md @@ -43,14 +43,14 @@ to HTML (best of 5 runs, on a MacBook): | Lines | Highlight + HTML | |---|---| -| 600 | 1.5 ms | -| 2,400 | 4.3 ms | -| 9,600 | 13.9 ms | +| 600 | 1.6 ms | +| 2,400 | 4.4 ms | +| 9,600 | 14.4 ms | `just bench-languages` measures about 256 KB of realistic source per language on native code. It averages about 43 MB/s, from 30 MB/s (HTML) to -64 MB/s (Markdown). `just bench-js` runs the same test compiled to -JavaScript, where it averages about 62 MB/s. +62 MB/s (Markdown). `just bench-js` runs the same test compiled to +JavaScript, where it averages about 55 MB/s. With incremental highlighting, one keystroke in the 9,600-line file takes about 0.4 ms. Frame timings for scrolling and typing in Flutter are in the @@ -61,7 +61,7 @@ about 0.4 ms. Frame timings for scrolling and typing in Flutter are in the - **One pass, no copying.** The scanner walks the source by offset, never copies it, and time grows in step with input size. -- **First-character dispatch.** Each rule's pattern is analysed once to find +- **First-character dispatch.** Each rule's pattern is analyzed once to find the characters it can start with. The scanner skips positions where no rule can start, and tries only the rules that can. Rules anchored with `^` are tried only at line starts. States with a rule that can start almost diff --git a/docs/api/_code-field.mdx b/docs/api/_code-field.mdx index 32f8cf0..4fef5b7 100644 --- a/docs/api/_code-field.mdx +++ b/docs/api/_code-field.mdx @@ -22,7 +22,7 @@ the text's own layout, so wrapped lines line up. Laying out a text field is proportional to its styled runs, so for documents longer than `styleAllBelow` lines only the visible lines, plus -`margin` lines on each side, are coloured. The window follows scrolling +`margin` lines on each side, are colored. The window follows scrolling (of the field itself or of an enclosing scroll view) and is computed from the laid-out text, so wrapped lines are handled exactly. @@ -75,12 +75,12 @@ Creates a code editor. | `onChanged` | `ValueChanged?` | | Called when the user edits the text. | | `scrollController` | `ScrollController?` | | Scroll controller for the field's own scrolling. | | `textAlignVertical` | `TextAlignVertical?` | | Vertical alignment of the text. | -| `styleAllBelow` | `int` | `300` | Documents with at most this many lines are coloured in full. | -| `margin` | `int` | `150` | Lines coloured beyond each edge of the visible area. | +| `styleAllBelow` | `int` | `300` | Documents with at most this many lines are colored in full. | +| `margin` | `int` | `150` | Lines colored beyond each edge of the visible area. | | `indent` | `String` | `' '` | Text inserted by Tab and removed by Shift+Tab, such as two spaces or `'\t'`. Enter keeps the current line's indentation, adding one level after an opening `{`, `[`, `(` or `:`. | | `editing` | `CodeEditing` | `const CodeEditing()` | What typing, Enter and Backspace do beyond inserting text. Use `CodeEditing.none` for a plain text field. | | `shortcuts` | `Map?` | | Keys and the intents they send. Defaults to `defaultShortcuts`; pass `const {}` for none, so Tab moves focus as in other fields. | -| `inputFormatters` | `List?` | | Formatters applied after the editing behaviour, such as a length limit. | +| `inputFormatters` | `List?` | | Formatters applied after the editing behavior, such as a length limit. | | `undoController` | `UndoHistoryController?` | | Controls the field's undo history, as in `TextField.undoController`. Every edit the field makes itself — an auto-closed pair, a toggled comment, an indent — is a single undo step. | | `lineNumbers` | `bool` | `false` | Whether to show line numbers in a gutter. | | `firstLineNumber` | `int` | `1` | Number shown for the first line. | @@ -97,7 +97,7 @@ Creates a code editor. ### `CodeEditing` -Editing behaviour for `CodeField`: what typing, Enter and Backspace do +Editing behavior for `CodeField`: what typing, Enter and Backspace do beyond inserting text. Brackets, quotes and comment markers come from the language's @@ -110,7 +110,7 @@ CodeField( ) ``` -Use `CodeEditing.none` to turn every behaviour off. +Use `CodeEditing.none` to turn every behavior off. ```dart const CodeEditing({ @@ -122,7 +122,7 @@ const CodeEditing({ }) ``` -Creates editing behaviour. Everything is on by default. +Creates editing behavior. Everything is on by default. | Field | Type | Default | Description | |---|---|---|---| diff --git a/docs/api/_grammar.mdx b/docs/api/_grammar.mdx index 46f63d8..f1753ff 100644 --- a/docs/api/_grammar.mdx +++ b/docs/api/_grammar.mdx @@ -120,7 +120,12 @@ Base constructor for rules. Matches `pattern` and marks the match with `scope`. `captures` maps capture group numbers inside `pattern` to scopes. Captured -groups must appear in order and must not overlap. +groups must appear in order and must not overlap. Each captured text is +located by searching the match after the previous capture, so it must +not also occur earlier in that stretch: in `\w+\.(\w+)` on `ab.a`, the +capture `a` would mark the first `a`. Where that can happen, match only +the part to scope and put the context in a lookaround, as in +`(?<=\w\.)\w+`. ```dart const TokenRule( @@ -244,7 +249,8 @@ compiled. The built-in blocks cover what most languages repeat: comments, strings, numbers, operators and annotations, so most grammars need no regular -expressions. Extend this class to make your own blocks. +expressions. Extend this class to make your own blocks; subclasses must +be `final`, `base` or `sealed`. ```dart const BlockRule() @@ -409,17 +415,18 @@ Creates a number block. Runs of operator characters, such as `+`, `==` or `>>=`. ```dart -const Operators([ - String chars = '+-*/%=<>!&|^~?:', +const Operators( + String chars, { String scope = Scopes.operator, -]) +}) ``` -Creates an operator block matching runs of `chars`. +Creates an operator block matching runs of `chars`, such as +`'+-*/%=<>!&|^~?:'`. | Field | Type | Default | Description | |---|---|---|---| -| `chars` | `String` | `'+-*/%=<>!&\|^~?:'` | Characters that make up operators. | +| `chars` | `String` | *required* | Characters that make up operators. | | `scope` | `String` | `Scopes.operator` | Scope of operators. | ### `Annotation` @@ -428,10 +435,10 @@ Annotations, attributes and decorators, such as `@override` or `@app.route`. ```dart -const Annotation([ +const Annotation({ String sigil = '@', String scope = Scopes.meta, -]) +}) ``` Creates an annotation block starting with `sigil`. @@ -447,10 +454,10 @@ Preprocessor lines such as `#include ` or `#define X 1`, including lines continued with a trailing backslash. ```dart -const Preprocessor([ +const Preprocessor({ String sigil = '#', String scope = Scopes.meta, -]) +}) ``` Creates a preprocessor block starting with `sigil`. @@ -472,38 +479,6 @@ Common heuristics for identifiers that are not keywords, for use in | `static memberCall` | `TokenRule` | After a `.`, a called name is a function (`list.add(`). | | `static member` | `TokenRule` | After a `.`, any other name is a plain member, never a keyword. | -### `cKeywords` - -C keywords (C23 included). - -```dart -const List cKeywords -``` - -### `cTypes` - -C built-in and standard types. - -```dart -const List cTypes -``` - -### `cLiterals` - -C literals. - -```dart -const List cLiterals -``` - -### `cCommonRules` - -Rules shared by C, C++ and Objective-C. - -```dart -const List cCommonRules -``` - ### `EditingSyntax` How code in a language is edited: its comment markers, brackets and diff --git a/docs/api/_highlighting.mdx b/docs/api/_highlighting.mdx index 7dda2db..3350b75 100644 --- a/docs/api/_highlighting.mdx +++ b/docs/api/_highlighting.mdx @@ -50,6 +50,9 @@ tree of objects. Token `i` covers `code[tokenStart(i), tokenEnd(i))` and carries a scope stack id from `scopes`. Tokens always cover all of `code` with no gaps, and neighbouring tokens never share a stack. +A result never changes once made, though its `scopes` table may gain +stacks (see there). It can be sent to another isolate as it is. + | Field | Type | Description | |---|---|---| | `code` | `String` | The highlighted source. | @@ -57,14 +60,20 @@ with no gaps, and neighbouring tokens never share a stack. | `scopes` | `ScopeTable` | Scope names and stacks referenced by the tokens. | | `tokenCount` | `int` | Number of tokens. | +
+scopes: more + +Results from one `IncrementalHighlighter` share a table that grows as +the document is edited. A stack id never changes meaning, so styles +cached per stack id stay valid; later results may only add stacks. + +
+ | Member | Type | Description | |---|---|---| -| `HighlightResult.fromBuffers({…})` | `HighlightResult` | Creates a result from raw token buffers. | | `tokenStart(int index)` | `int` | Start offset of token `index`. | | `tokenEnd(int index)` | `int` | End offset (exclusive) of token `index`. | | `tokenStack(int index)` | `int` | Scope stack id of token `index`. See `scopes`. | -| `rawEnds` | `Int32List` | The raw token end offsets, for engines that copy tokens in bulk. Only the first `tokenCount` entries are valid. | -| `rawStacks` | `Int32List` | The raw token stack ids, alongside `rawEnds`. | | `tokens` | `Iterable` | All tokens, in order. | | `tokenAt(int offset)` | `int` | Index of the token covering `offset`, or `tokenCount` if `offset` is at or past the end. | | `lineCount` | `int` | Number of lines. Empty code has one empty line, and a trailing `\n` starts a final empty line. | @@ -74,18 +83,9 @@ with no gaps, and neighbouring tokens never share a stack. | `isStringOrCommentAt(int offset)` | `bool` | Whether the character at `offset` is inside a string, comment or regular expression. Interpolations inside strings count as code. | | `isCommentAt(int offset)` | `bool` | Whether the character at `offset` is inside a comment. | | `isInsideStringOrComment(int offset, [EditingSyntax? syntax])` | `bool` | Whether text typed at caret position `offset`, between `code[offset - 1]` and `code[offset]`, would land inside a string or comment. | -| `matchingBracket(…)` | `int` | Offset of the bracket matching the one at `offset`, or `-1` if the character at `offset` is not a bracket in code, or has no match within `limit` characters. | +| `matchingBracket(int offset, {String? brackets, int limit = 1 << 20})` | `int` | Offset of the bracket matching the one at `offset`, or `-1` if the character at `offset` is not a bracket in code, or has no match within `limit` characters. | | `toHtml([HtmlRenderer renderer = const HtmlRenderer()])` | `String` | Renders the result as HTML. See `HtmlRenderer` for options. | -
-HighlightResult.fromBuffers: more - -Engines use this, and so can code that moves results between isolates. -`ends` and `stacks` must have at least `tokenCount` entries. Pass -`lineStarts` if they are already known. - -
-
isInsideStringOrComment: more @@ -101,9 +101,10 @@ the end of a line comment or of an unterminated string is inside. matchingBracket: more `brackets` lists pairs as consecutive opening and closing characters, -as in `EditingSyntax.brackets`. Brackets inside strings and comments -are skipped, so `f(")")` matches correctly. The search walks tokens, -jumping over a whole string or comment at once. +and defaults to the `language`'s `EditingSyntax.brackets`. Brackets +inside strings and comments are skipped, so `f(")")` matches +correctly. The search walks tokens, jumping over a whole string or +comment at once.
@@ -133,18 +134,10 @@ the outside in, such as `string > interpolation > keyword`. Stack `0` is the root and has no scope. A parent always has a smaller id than its children, so renderers can resolve styles in a single forward pass. -```dart -ScopeTable() -``` - -Creates an empty table containing only the root stack. - | Member | Type | Description | |---|---|---| | `static root` | `int` | Id of the root stack, which has no scope. | | `stackCount` | `int` | Number of stacks, including the root. | -| `nameId(String name)` | `int` | Returns the id of scope `name`, adding it if needed. | -| `push(int stack, String name)` | `int` | Returns the stack made of `stack` with scope `name` pushed on top. | | `parentOf(int stack)` | `int` | Parent of `stack`, or `-1` for the root. | | `scopeOf(int stack)` | `String?` | Innermost scope of `stack`, or `null` for the root. | | `scopesOf(int stack)` | `List` | Scopes of `stack` from the outermost to the innermost. | diff --git a/docs/api/_incremental.mdx b/docs/api/_incremental.mdx index dc6e5da..ee98798 100644 --- a/docs/api/_incremental.mdx +++ b/docs/api/_incremental.mdx @@ -30,10 +30,10 @@ languages named inside the code, such as Markdown code fences. | Field | Type | Description | |---|---|---| | `registry` | `LanguageRegistry?` | Languages for embedded regions named in the code. | -| `lastRescannedLines` | `int` | Lines re-scanned by the last `update`, for diagnostics. | | Member | Type | Description | |---|---|---| +| `lastRescannedLines` | `int` | Lines re-scanned by the last `update`, for diagnostics. | | `result` | `HighlightResult` | The current result. | | `language` | `Grammar` | The current language. Setting it re-highlights everything. *Settable.* | | `update(String text)` | `HighlightResult` | Updates the document to `text` and returns the new result. | diff --git a/docs/api/_lookup.mdx b/docs/api/_lookup.mdx index 0c7a36f..e4cb64d 100644 --- a/docs/api/_lookup.mdx +++ b/docs/api/_lookup.mdx @@ -5,10 +5,10 @@ Languages addressable by name, alias, file name or file extension. ```dart -LanguageRegistry([ - Iterable languages = const [], +LanguageRegistry( + Iterable languages, { Grammar? fallback, -]) +}) ``` Creates a registry containing `languages`. @@ -24,7 +24,7 @@ the registry does not have. | Member | Type | Description | |---|---|---| | `languages` | `List` | Registered languages, in registration order. | -| `add(Grammar language, {List aliases = const []})` | `void` | Registers `language` under its name, its aliases and any extra `aliases`. Later registrations replace earlier ones for the same key. | +| `add(Grammar language, {List aliases = const []})` | `void` | Registers `language` under its name, its aliases and any extra `aliases`. Later registrations replace earlier ones for the same key. Adding a language again only adds the new `aliases`. | | `lookup(String nameOrAlias)` | `Grammar?` | Language registered as `nameOrAlias`, or `null`. | | `resolve(String nameOrAlias)` | `Grammar?` | Language registered as `nameOrAlias`, else `fallback`. | | `resolveFileName(String fileName)` | `Grammar?` | Language for `fileName`, matched as `forFileName` does, else `fallback`. | @@ -93,7 +93,7 @@ A detected language and how confident the detector is. const Detection( Grammar language, double score, { - String reason = 'content', + DetectionReason reason = DetectionReason.content, }) ``` @@ -103,7 +103,21 @@ Creates a detection result. |---|---|---|---| | `language` | `Grammar` | *required* | The detected language. | | `score` | `double` | *required* | Detection score. Higher is more confident; only useful for comparing candidates for the same input. | -| `reason` | `String` | `'content'` | Why this language won: `file name`, `shebang` or `content`. | +| `reason` | `DetectionReason` | `DetectionReason.content` | Which check picked this language. | + +### `DetectionReason` + +Which check picked a `Detection`'s language. + +```dart +enum DetectionReason { fileName, shebang, content } +``` + +| Value | Description | +|---|---| +| `fileName` | The file name or extension. | +| `shebang` | The `#!` first line. | +| `content` | The content score. | ### `allLanguages` diff --git a/docs/api/_rendering.mdx b/docs/api/_rendering.mdx index b91b596..64e3536 100644 --- a/docs/api/_rendering.mdx +++ b/docs/api/_rendering.mdx @@ -56,7 +56,7 @@ List documentSpans(HighlightResult result, CodeStyles styles) Spans covering every character of `result` exactly, as a text field needs. When `composing` is a valid range, that range is underlined. -Only code within `styled` (all of it by default) is coloured; the rest +Only code within `styled` (all of it by default) is colored; the rest is plain text, which keeps huge documents cheap to lay out. Adjacent pieces with the same style share one span. diff --git a/docs/api/_text-field.mdx b/docs/api/_text-field.mdx index 890bece..c94aac1 100644 --- a/docs/api/_text-field.mdx +++ b/docs/api/_text-field.mdx @@ -29,7 +29,7 @@ as Markdown code fences. | Member | Type | Description | |---|---|---| -| `window` | `({int first, int last})?` | Zero-based lines to colour, or `null` for all of them. *Settable.* | +| `window` | `({int first, int last})?` | Zero-based lines to color, or `null` for all of them. *Settable.* | | `language` | `Grammar` | The language of the text. Setting it re-highlights everything. *Settable.* | | `theme` | `ValTheme?` | The theme, or `null` to follow the app. *Settable.* | | `result` | `HighlightResult` | The highlight result for the current text. | @@ -39,7 +39,7 @@ as Markdown code fences. Laying out a text field with many thousands of styled runs is slow, so for large documents only the visible lines, plus a margin, need -colours. `CodeField` sets this automatically as you scroll. +colors. `CodeField` sets this automatically as you scroll. @@ -49,7 +49,7 @@ Applies `CodeEditing` to text typed into a field driven by a `HighlightTextController`. `CodeField` installs one automatically. Add one to a plain `TextField`'s -`inputFormatters` to get the same behaviour there: +`inputFormatters` to get the same behavior there: ```dart TextField( @@ -77,5 +77,5 @@ Creates a formatter for `controller`. | Field | Type | Default | Description | |---|---|---|---| | `controller` | `HighlightTextController` | *required* | The controller whose highlighting tells strings and comments apart. | -| `editing` | `CodeEditing` | `const CodeEditing()` | The behaviour to apply. | +| `editing` | `CodeEditing` | `const CodeEditing()` | The behavior to apply. | | `indent` | `String` | `' '` | One level of indentation, for Enter. | diff --git a/docs/api/_theme-list.mdx b/docs/api/_theme-list.mdx index 837c51f..3ed77c7 100644 --- a/docs/api/_theme-list.mdx +++ b/docs/api/_theme-list.mdx @@ -8,5 +8,5 @@ | `dimTheme` | `themes/dim.dart` | `dim` | yes | `#c4c8ce` on `#22262c` | A soft, low-glare dark theme. | | `midnightTheme` | `themes/midnight.dart` | `midnight` | yes | `#d8e0f0` on `#0e1628` | A deep blue dark theme. | | `forestTheme` | `themes/forest.dart` | `forest` | yes | `#d6e2d0` on `#15201a` | A green-tinted dark theme. | -| `highContrastLightTheme` | `themes/high_contrast_light.dart` | `high-contrast-light` | no | `#000000` on `#ffffff` | A high-contrast light theme: every colour has at least 7:1 contrast. | -| `highContrastDarkTheme` | `themes/high_contrast_dark.dart` | `high-contrast-dark` | yes | `#ffffff` on `#000000` | A high-contrast dark theme: every colour has at least 7:1 contrast. | +| `highContrastLightTheme` | `themes/high_contrast_light.dart` | `high-contrast-light` | no | `#000000` on `#ffffff` | A high-contrast light theme: every color has at least 7:1 contrast. | +| `highContrastDarkTheme` | `themes/high_contrast_dark.dart` | `high-contrast-dark` | yes | `#ffffff` on `#000000` | A high-contrast dark theme: every color has at least 7:1 contrast. | diff --git a/docs/api/_themes.mdx b/docs/api/_themes.mdx index c2d8eb2..877b31a 100644 --- a/docs/api/_themes.mdx +++ b/docs/api/_themes.mdx @@ -4,8 +4,9 @@ A color theme: a `root` style plus a style per scope. -Scope lookup cascades: `title.function.call` tries `title.function.call`, -then `title.function`, then `title`. +A scope's style builds on those of its dotted prefixes: `title.function` +takes the fields set for `title`, then those set for `title.function`. +This is how CSS classes from `toCss` combine too. ```dart const ValTheme({ @@ -29,7 +30,7 @@ Creates a theme. |---|---|---| | `ValTheme.fromVsCode(Map json, {String? name})` | `ValTheme` | Builds a theme from a decoded VS Code color theme (the JSON object of a `*-color-theme.json` file). | | `ValTheme.fromVsCodeJson(String source, {String? name})` | `ValTheme` | Like `ValTheme.fromVsCode`, from the text of a theme file. Comments and trailing commas (JSONC) are allowed. | -| `lookup(String scope)` | `Style?` | Style for `scope` alone, using the cascade, without inheritance. | +| `lookup(String scope)` | `Style?` | Style for `scope` alone, without inheriting from enclosing scopes: the styles of `a`, `a.b` and `a.b.c` merged in that order for `a.b.c`, or `null` if none is set. | | `resolve(ScopeTable table)` | `List