@noldova/code.editor.angular 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.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/api/index.d.ts +30 -0
  4. package/api/index.js +27 -0
  5. package/app/components/code-editor/code-editor.component.d.ts +332 -0
  6. package/app/components/code-editor/code-editor.component.js +648 -0
  7. package/app/components/code-text/code-text.component.d.ts +70 -0
  8. package/app/components/code-text/code-text.component.js +40 -0
  9. package/app/components/find-bar/find-bar.component.d.ts +40 -0
  10. package/app/components/find-bar/find-bar.component.js +95 -0
  11. package/app/enums/code-row-kind.d.ts +14 -0
  12. package/app/enums/code-row-kind.js +15 -0
  13. package/app/enums/fold-shortcut.d.ts +11 -0
  14. package/app/enums/fold-shortcut.js +12 -0
  15. package/app/exceptions/background-job-failed.exception.d.ts +33 -0
  16. package/app/exceptions/background-job-failed.exception.js +15 -0
  17. package/app/interfaces/i-code-decorations.d.ts +103 -0
  18. package/app/interfaces/i-code-decorations.js +7 -0
  19. package/app/interfaces/i-code-editor-view.d.ts +13 -0
  20. package/app/interfaces/i-code-editor-view.js +7 -0
  21. package/app/interfaces/i-code-numbering.d.ts +38 -0
  22. package/app/interfaces/i-code-numbering.js +7 -0
  23. package/app/models/code-editor-view.d.ts +18 -0
  24. package/app/models/code-editor-view.js +26 -0
  25. package/app/models/code-search.d.ts +18 -0
  26. package/app/models/code-search.js +52 -0
  27. package/app/models/code-text-line.d.ts +17 -0
  28. package/app/models/code-text-line.js +42 -0
  29. package/app/models/code-text-span.d.ts +15 -0
  30. package/app/models/code-text-span.js +19 -0
  31. package/app/models/decorations/code-bar-action-event.d.ts +39 -0
  32. package/app/models/decorations/code-bar-action-event.js +15 -0
  33. package/app/models/decorations/code-bar-action.d.ts +40 -0
  34. package/app/models/decorations/code-bar-action.js +17 -0
  35. package/app/models/decorations/code-bar.d.ts +78 -0
  36. package/app/models/decorations/code-bar.js +34 -0
  37. package/app/models/decorations/code-decorations.d.ts +121 -0
  38. package/app/models/decorations/code-decorations.js +42 -0
  39. package/app/models/decorations/code-gutter-marker.d.ts +46 -0
  40. package/app/models/decorations/code-gutter-marker.js +20 -0
  41. package/app/models/decorations/code-line-decoration.d.ts +48 -0
  42. package/app/models/decorations/code-line-decoration.js +21 -0
  43. package/app/models/decorations/code-range-decoration.d.ts +44 -0
  44. package/app/models/decorations/code-range-decoration.js +15 -0
  45. package/app/models/folding/code-block.d.ts +17 -0
  46. package/app/models/folding/code-block.js +21 -0
  47. package/app/models/folding/code-blocks.d.ts +17 -0
  48. package/app/models/folding/code-blocks.js +32 -0
  49. package/app/models/folding/code-fold.d.ts +53 -0
  50. package/app/models/folding/code-fold.js +23 -0
  51. package/app/models/folding/fold-shortcuts.d.ts +14 -0
  52. package/app/models/folding/fold-shortcuts.js +17 -0
  53. package/app/models/language-tokenizer.d.ts +39 -0
  54. package/app/models/language-tokenizer.js +22 -0
  55. package/app/models/rows/code-embedded-lines.d.ts +76 -0
  56. package/app/models/rows/code-embedded-lines.js +43 -0
  57. package/app/models/rows/code-inserted-rows.d.ts +19 -0
  58. package/app/models/rows/code-inserted-rows.js +7 -0
  59. package/app/models/rows/code-row.d.ts +27 -0
  60. package/app/models/rows/code-row.js +31 -0
  61. package/app/models/rows/code-spacer.d.ts +61 -0
  62. package/app/models/rows/code-spacer.js +30 -0
  63. package/app/models/rows/inserted-rows.d.ts +12 -0
  64. package/app/models/rows/inserted-rows.js +18 -0
  65. package/app/models/rows/layer-lines.d.ts +18 -0
  66. package/app/models/rows/layer-lines.js +17 -0
  67. package/app/models/rows/layout-row.d.ts +14 -0
  68. package/app/models/rows/layout-row.js +17 -0
  69. package/app/models/rows/line-index.d.ts +58 -0
  70. package/app/models/rows/line-index.js +50 -0
  71. package/app/models/rows/row-builder.d.ts +35 -0
  72. package/app/models/rows/row-builder.js +87 -0
  73. package/app/models/rows/row-layout.d.ts +22 -0
  74. package/app/models/rows/row-layout.js +58 -0
  75. package/app/models/rows/row-span.d.ts +13 -0
  76. package/app/models/rows/row-span.js +17 -0
  77. package/app/models/shapes/bar-shape.d.ts +13 -0
  78. package/app/models/shapes/bar-shape.js +15 -0
  79. package/app/models/shapes/change-shape.d.ts +14 -0
  80. package/app/models/shapes/change-shape.js +19 -0
  81. package/app/models/shapes/code-shape.d.ts +14 -0
  82. package/app/models/shapes/code-shape.js +19 -0
  83. package/app/models/shapes/match-shape.d.ts +14 -0
  84. package/app/models/shapes/match-shape.js +19 -0
  85. package/app/models/text-measure.d.ts +18 -0
  86. package/app/models/text-measure.js +50 -0
  87. package/app/models/view-command.d.ts +16 -0
  88. package/app/models/view-command.js +24 -0
  89. package/app/services/background-ticker.d.ts +47 -0
  90. package/app/services/background-ticker.js +34 -0
  91. package/app/services/code-editor-classes.d.ts +102 -0
  92. package/app/services/code-editor-classes.js +30 -0
  93. package/app/services/code-editor-contribution.d.ts +20 -0
  94. package/app/services/code-editor-contribution.js +41 -0
  95. package/app/services/code-editor-features.d.ts +13 -0
  96. package/app/services/code-editor-features.js +13 -0
  97. package/app/services/code-editor-registries.d.ts +43 -0
  98. package/app/services/code-editor-registries.js +23 -0
  99. package/app/services/key-scope.d.ts +79 -0
  100. package/app/services/key-scope.js +53 -0
  101. package/app/services/token-style-sheet.d.ts +11 -0
  102. package/app/services/token-style-sheet.js +44 -0
  103. package/app/services/worker-runner.d.ts +87 -0
  104. package/app/services/worker-runner.js +84 -0
  105. package/package.json +38 -4
  106. package/resources.d.ts +124 -0
  107. package/resources.js +137 -0
@@ -0,0 +1,47 @@
1
+ /// <reference lib="esnext.disposable" />
2
+ /**
3
+ * @license
4
+ * Copyright (c) Noldova.
5
+ *
6
+ * This source code is licensed under the license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ import "@noldova/context.core";
10
+ import type { TextDocument } from "@noldova/code.editor";
11
+ /**
12
+ * Runs a step of background work after each edit to a document, in setTimeout
13
+ * slices, until the step says it is done; for work such as tokenizing that
14
+ * follows a document a view doesn't show.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { TextDocument, TokenCache } from "@noldova/code.editor";
19
+ * import { BackgroundTicker } from "@noldova/code.editor.angular";
20
+ *
21
+ * declare const cache: TokenCache;
22
+ * using ticker = new BackgroundTicker(TextDocument.fromText("a"), hasTime => cache.advance(hasTime));
23
+ * ```
24
+ */
25
+ export declare class BackgroundTicker implements Disposable {
26
+ private readonly step;
27
+ private readonly stop;
28
+ private timer;
29
+ /**
30
+ * Starts the ticks: one now and one after each edit.
31
+ *
32
+ * @param document The document whose edits start the step again.
33
+ * @param step The work of one slice; it works while `hasTime` is true and
34
+ * returns whether work is left.
35
+ * @example
36
+ * ```ts
37
+ * import { TextDocument } from "@noldova/code.editor";
38
+ * import { BackgroundTicker } from "@noldova/code.editor.angular";
39
+ *
40
+ * using ticker = new BackgroundTicker(TextDocument.fromText("a"), () => false);
41
+ * ```
42
+ */
43
+ constructor(document: TextDocument, step: (hasTime: () => boolean) => boolean);
44
+ [Symbol.dispose](): void;
45
+ private schedule;
46
+ private tick;
47
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import "@noldova/context.core";
9
+ import { Resources } from "../../resources.js";
10
+ export class BackgroundTicker {
11
+ step;
12
+ stop;
13
+ timer = null;
14
+ constructor(document, step) {
15
+ this.step = step;
16
+ this.stop = document.onChange(() => this.schedule());
17
+ this.schedule();
18
+ }
19
+ [Symbol.dispose]() {
20
+ this.stop();
21
+ if (!Object.isNull(this.timer))
22
+ clearTimeout(this.timer);
23
+ }
24
+ schedule() {
25
+ if (Object.isNull(this.timer))
26
+ this.timer = setTimeout(() => this.tick());
27
+ }
28
+ tick() {
29
+ this.timer = null;
30
+ const deadline = performance.now() + Resources.backgroundSliceMilliseconds;
31
+ if (this.step(() => performance.now() < deadline))
32
+ this.schedule();
33
+ }
34
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * The code view's CSS classes, each the bare class, which a host or a test
10
+ * builds its selectors from.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { CodeEditorClasses } from "@noldova/code.editor.angular";
15
+ *
16
+ * document.querySelectorAll(`.${CodeEditorClasses.line}`);
17
+ * CodeEditorClasses.token("keyword"); // "nol-code-editor-token-keyword"
18
+ * ```
19
+ */
20
+ export declare class CodeEditorClasses {
21
+ /**
22
+ * `nol-code-editor-line`: a line's text.
23
+ */
24
+ static readonly line: string;
25
+ /**
26
+ * `nol-code-editor-change`: a range decoration's mark, such as a changed range's.
27
+ */
28
+ static readonly change: string;
29
+ /**
30
+ * `nol-code-editor-line-number`: a line's gutter cell.
31
+ */
32
+ static readonly lineNumber: string;
33
+ /**
34
+ * `nol-code-editor-paint`: a line decoration's paint, on a row behind the text or in the gutter.
35
+ */
36
+ static readonly paint: string;
37
+ /**
38
+ * `nol-code-editor-row`: a row behind a line's text, which holds its paints.
39
+ */
40
+ static readonly row: string;
41
+ /**
42
+ * `nol-code-editor-row-spacer`: added to a row and a gutter cell that face an inserted filler row.
43
+ */
44
+ static readonly rowSpacer: string;
45
+ /**
46
+ * `nol-code-editor-row-fold`: added to a row and a gutter cell that face a folded region.
47
+ */
48
+ static readonly rowFold: string;
49
+ /**
50
+ * `nol-code-editor-line-fold`: added to the line that stands for a folded region.
51
+ */
52
+ static readonly lineFold: string;
53
+ /**
54
+ * `nol-code-editor-fold-toggle`: a fold's toggle.
55
+ */
56
+ static readonly foldToggle: string;
57
+ /**
58
+ * `nol-code-editor-fold-icon`: a fold toggle's icon.
59
+ */
60
+ static readonly foldIcon: string;
61
+ /**
62
+ * `nol-code-editor-scroller`: the scrolled area.
63
+ */
64
+ static readonly scroller: string;
65
+ /**
66
+ * `nol-code-editor-input`: the text input that takes keys.
67
+ */
68
+ static readonly input: string;
69
+ /**
70
+ * `nol-code-editor-caret`: a caret.
71
+ */
72
+ static readonly caret: string;
73
+ /**
74
+ * `nol-code-editor-match`: a search match's mark.
75
+ */
76
+ static readonly match: string;
77
+ /**
78
+ * `nol-code-editor-sign`: a gutter cell's change sign.
79
+ */
80
+ static readonly sign: string;
81
+ /**
82
+ * `nol-code-editor-number`: a gutter cell's line number.
83
+ */
84
+ static readonly number: string;
85
+ /**
86
+ * `nol-find-bar-field`: a field of the find bar, the find field first.
87
+ */
88
+ static readonly findField: string;
89
+ /**
90
+ * The class of a token of the type given.
91
+ *
92
+ * @param type The token type's id, such as `keyword`.
93
+ * @returns `nol-code-editor-token-` and the type.
94
+ * @example
95
+ * ```ts
96
+ * import { CodeEditorClasses } from "@noldova/code.editor.angular";
97
+ *
98
+ * CodeEditorClasses.token("comment"); // "nol-code-editor-token-comment"
99
+ * ```
100
+ */
101
+ static token(type: string): string;
102
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { Resources } from "../../resources.js";
9
+ export class CodeEditorClasses {
10
+ static line = Resources.lineClass;
11
+ static change = Resources.changeClass;
12
+ static lineNumber = Resources.lineNumberClass;
13
+ static paint = Resources.paintClass;
14
+ static row = Resources.codeRowClass;
15
+ static rowSpacer = Resources.rowSpacerClass;
16
+ static rowFold = Resources.rowFoldClass;
17
+ static lineFold = Resources.lineFoldClass;
18
+ static foldToggle = Resources.foldToggleClass;
19
+ static foldIcon = Resources.foldIconClass;
20
+ static scroller = Resources.scrollerClass;
21
+ static input = Resources.inputClass;
22
+ static caret = Resources.caretClass;
23
+ static match = Resources.matchClass;
24
+ static sign = Resources.signClass;
25
+ static number = Resources.numberClass;
26
+ static findField = Resources.findFieldClass;
27
+ static token(type) {
28
+ return `${Resources.tokenClassPrefix}${type}`;
29
+ }
30
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { type EditorRegistries, type ICommand, type IEditorContribution, type IKeyBindingRule } from "@noldova/code.editor";
9
+ import { type IReadOnlyList } from "@noldova/context.collections";
10
+ export declare class CodeEditorContribution implements IEditorContribution {
11
+ static readonly find: ICommand;
12
+ static readonly replace: ICommand;
13
+ static readonly closeFind: ICommand;
14
+ static readonly fold: ICommand;
15
+ static readonly unfold: ICommand;
16
+ static readonly commands: readonly ICommand[];
17
+ static readonly keyBindings: IReadOnlyList<IKeyBindingRule>;
18
+ readonly id: string;
19
+ contribute(registries: EditorRegistries): void;
20
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { Condition, CoreConditions, KeyBindingRule } from "@noldova/code.editor";
9
+ import { List } from "@noldova/context.collections";
10
+ import { Resources } from "../../resources.js";
11
+ import { FoldShortcut } from "../enums/fold-shortcut.js";
12
+ import { ViewCommand } from "../models/view-command.js";
13
+ import { CodeEditorFeatures } from "./code-editor-features.js";
14
+ export class CodeEditorContribution {
15
+ static find = new ViewCommand(Resources.findCommand, t => t.openSearch(false));
16
+ static replace = new ViewCommand(Resources.replaceCommand, t => t.openSearch(true));
17
+ static closeFind = new ViewCommand(Resources.closeFindCommand, t => t.closeSearch());
18
+ static fold = new ViewCommand(Resources.foldCommand, t => t.toggleFold(FoldShortcut.Fold));
19
+ static unfold = new ViewCommand(Resources.unfoldCommand, t => t.toggleFold(FoldShortcut.Unfold));
20
+ static commands = [
21
+ CodeEditorContribution.find, CodeEditorContribution.replace, CodeEditorContribution.closeFind, CodeEditorContribution.fold, CodeEditorContribution.unfold
22
+ ];
23
+ static keyBindings = new List([
24
+ new KeyBindingRule(CodeEditorContribution.find.id, Resources.findKeys),
25
+ new KeyBindingRule(CodeEditorContribution.find.id, Resources.findAlternateKeys),
26
+ new KeyBindingRule(CodeEditorContribution.replace.id, Resources.replaceMacKeys, CoreConditions.onMac),
27
+ new KeyBindingRule(CodeEditorContribution.replace.id, Resources.replaceKeys, CoreConditions.offMac),
28
+ new KeyBindingRule(CodeEditorContribution.closeFind.id, Resources.closeFindKeys, Condition.has(CodeEditorFeatures.findVisible)),
29
+ new KeyBindingRule(CodeEditorContribution.fold.id, Resources.foldKeys, CoreConditions.offMac),
30
+ new KeyBindingRule(CodeEditorContribution.fold.id, Resources.foldMacKeys, CoreConditions.onMac),
31
+ new KeyBindingRule(CodeEditorContribution.unfold.id, Resources.unfoldKeys, CoreConditions.offMac),
32
+ new KeyBindingRule(CodeEditorContribution.unfold.id, Resources.unfoldMacKeys, CoreConditions.onMac)
33
+ ]);
34
+ id = Resources.viewContribution;
35
+ contribute(registries) {
36
+ for (const command of CodeEditorContribution.commands)
37
+ registries.commands.register(command);
38
+ registries.conditions.register(CodeEditorFeatures.findVisible);
39
+ registries.keyBindings.addDefaults(this.id, CodeEditorContribution.keyBindings);
40
+ }
41
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { ConditionKey, EditorFeature } from "@noldova/code.editor";
9
+ import type { ICodeEditorView } from "../interfaces/i-code-editor-view.js";
10
+ export declare class CodeEditorFeatures {
11
+ static readonly view: EditorFeature<ICodeEditorView>;
12
+ static readonly findVisible: ConditionKey<boolean>;
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { ConditionKey, EditorFeature } from "@noldova/code.editor";
9
+ import { Resources } from "../../resources.js";
10
+ export class CodeEditorFeatures {
11
+ static view = new EditorFeature(Resources.viewFeature);
12
+ static findVisible = new ConditionKey(Resources.findVisibleKey, false, Resources.findVisibleDescription);
13
+ }
@@ -0,0 +1,43 @@
1
+ import { EditorRegistries } from "@noldova/code.editor";
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * The app's one set of editor registries, which every
5
+ * {@link CodeEditorComponent} adds its own on top of.
6
+ *
7
+ * @remarks
8
+ * It holds the core's contribution, with its built-in token types, and this
9
+ * package's: the find, replace, close-find, fold and unfold commands and their
10
+ * keys, and the `findVisible` condition. A host injects it to add user key
11
+ * bindings, settings, token types or its own contributions; every view styles
12
+ * its tokens by the token types here, whose rules it puts in the page.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { inject } from "@angular/core";
17
+ * import { KeyBindingRule } from "@noldova/code.editor";
18
+ * import { List } from "@noldova/context.collections";
19
+ * import { CodeEditorRegistries } from "@noldova/code.editor.angular";
20
+ *
21
+ * inject(CodeEditorRegistries).registries.keyBindings.setUserRules(new List([new KeyBindingRule("editor.deleteRight", "ctrl+d")]));
22
+ * ```
23
+ */
24
+ export declare class CodeEditorRegistries {
25
+ /**
26
+ * The registries.
27
+ */
28
+ readonly registries: EditorRegistries;
29
+ /**
30
+ * Creates the set with the core's and this package's contributions; Angular
31
+ * creates it once per app.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { CodeEditorRegistries } from "@noldova/code.editor.angular";
36
+ *
37
+ * const registries = new CodeEditorRegistries().registries;
38
+ * ```
39
+ */
40
+ constructor();
41
+ static ɵfac: i0.ɵɵFactoryDeclaration<CodeEditorRegistries, never>;
42
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
43
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { Injectable } from "@angular/core";
9
+ import { CoreContribution, EditorRegistries } from "@noldova/code.editor";
10
+ import { CodeEditorContribution } from "./code-editor-contribution.js";
11
+ import * as i0 from "@angular/core";
12
+ export class CodeEditorRegistries {
13
+ registries = new EditorRegistries();
14
+ constructor() {
15
+ this.registries.add(new CoreContribution(), new CodeEditorContribution());
16
+ }
17
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: CodeEditorRegistries, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
18
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: CodeEditorRegistries, providedIn: "root" });
19
+ }
20
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: CodeEditorRegistries, decorators: [{
21
+ type: Injectable,
22
+ args: [{ providedIn: "root" }]
23
+ }], ctorParameters: () => [] });
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import "@noldova/context.core";
9
+ import { type CommandContext, type KeyDispatchResult, type KeyPress } from "@noldova/code.editor";
10
+ import * as i0 from "@angular/core";
11
+ /**
12
+ * A view's key dispatch, which a view provides for itself and the views
13
+ * inside it, so a code view in a diff or merge view shares one
14
+ * {@link KeyDispatcher} with its host and dispatches each press through its
15
+ * own context and then its hosts'.
16
+ *
17
+ * @remarks
18
+ * A host view provides it, attaches its command context and listens; a code
19
+ * view inside finds it as its parent, so a key sequence may begin in the
20
+ * pane and a host's binding may complete it, and every view in the chain
21
+ * hears the pending chord.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { Component, inject } from "@angular/core";
26
+ * import type { CommandContext } from "@noldova/code.editor";
27
+ * import { CodeEditorComponent, KeyScope } from "@noldova/code.editor.angular";
28
+ *
29
+ * @Component({ selector: "app-pair", imports: [CodeEditorComponent], providers: [KeyScope], template: "" })
30
+ * export class PairComponent {
31
+ * public constructor() {
32
+ * const keys: KeyScope = inject(KeyScope);
33
+ * keys.attach(time => this.contextAt(time));
34
+ * keys.listen(label => console.log(label));
35
+ * }
36
+ *
37
+ * private contextAt(_: number): CommandContext {
38
+ * throw new Error("The app's own context.");
39
+ * }
40
+ * }
41
+ * ```
42
+ */
43
+ export declare class KeyScope {
44
+ private readonly parent;
45
+ private readonly dispatcher;
46
+ private readonly listeners;
47
+ private contextOf;
48
+ /**
49
+ * Gives the scope the command context its view's bindings run in, for the
50
+ * presses of the views inside it.
51
+ *
52
+ * @param contextOf Makes the context for a press's time.
53
+ */
54
+ attach(contextOf: (time: number) => CommandContext): void;
55
+ /**
56
+ * Hears the pending chord's label, and null once no sequence is pending,
57
+ * for this scope and the views inside it.
58
+ *
59
+ * @param listener Called with each change.
60
+ */
61
+ listen(listener: (label: string | null) => void): void;
62
+ /**
63
+ * Dispatches a press of this scope's view through its context and then
64
+ * its hosts'.
65
+ *
66
+ * @param press The press.
67
+ * @param context The view's command context.
68
+ * @returns What the shared dispatcher did with the press.
69
+ */
70
+ dispatch(press: KeyPress, context: CommandContext): KeyDispatchResult;
71
+ /**
72
+ * Drops the pending sequence, telling the listeners when one was pending.
73
+ */
74
+ cancel(): void;
75
+ private collect;
76
+ private report;
77
+ static ɵfac: i0.ɵɵFactoryDeclaration<KeyScope, never>;
78
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
79
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import "@noldova/context.core";
9
+ import { inject, Injectable } from "@angular/core";
10
+ import { KeyDispatcher } from "@noldova/code.editor";
11
+ import { List } from "@noldova/context.collections";
12
+ import * as i0 from "@angular/core";
13
+ export class KeyScope {
14
+ parent = inject(KeyScope, { optional: true, skipSelf: true });
15
+ dispatcher = this.parent?.dispatcher ?? new KeyDispatcher();
16
+ listeners = new List();
17
+ contextOf = null;
18
+ attach(contextOf) {
19
+ this.contextOf = contextOf;
20
+ }
21
+ listen(listener) {
22
+ this.listeners.add(listener);
23
+ }
24
+ dispatch(press, context) {
25
+ const contexts = new List([context]);
26
+ this.parent?.collect(contexts, context.time);
27
+ const pending = this.dispatcher.pendingLabel(context.conditions);
28
+ const result = this.dispatcher.dispatch(press, contexts);
29
+ const label = this.dispatcher.pendingLabel(context.conditions);
30
+ if (label !== pending)
31
+ this.report(label);
32
+ return result;
33
+ }
34
+ cancel() {
35
+ if (this.dispatcher.cancel())
36
+ this.report(null);
37
+ }
38
+ collect(contexts, time) {
39
+ if (!Object.isNull(this.contextOf))
40
+ contexts.add(this.contextOf(time));
41
+ this.parent?.collect(contexts, time);
42
+ }
43
+ report(label) {
44
+ for (const listener of this.listeners)
45
+ listener(label);
46
+ this.parent?.report(label);
47
+ }
48
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: KeyScope, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
49
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: KeyScope });
50
+ }
51
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: KeyScope, decorators: [{
52
+ type: Injectable
53
+ }] });
@@ -0,0 +1,11 @@
1
+ import "@noldova/context.core";
2
+ import { type TokenTypeRegistry } from "@noldova/code.editor";
3
+ import * as i0 from "@angular/core";
4
+ export declare class TokenStyleSheet {
5
+ private readonly document;
6
+ private readonly sheets;
7
+ constructor();
8
+ apply(registry: TokenTypeRegistry, prefix: string): void;
9
+ static ɵfac: i0.ɵɵFactoryDeclaration<TokenStyleSheet, never>;
10
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
11
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { DestroyRef, DOCUMENT, inject, Injectable } from "@angular/core";
9
+ import "@noldova/context.core";
10
+ import { TokenStyles } from "@noldova/code.editor";
11
+ import { Resources } from "../../resources.js";
12
+ import * as i0 from "@angular/core";
13
+ export class TokenStyleSheet {
14
+ document = inject(DOCUMENT);
15
+ sheets = new Map();
16
+ constructor() {
17
+ inject(DestroyRef).onDestroy(() => {
18
+ for (const sheet of this.sheets.values())
19
+ for (const style of sheet.values())
20
+ style.remove();
21
+ this.sheets.clear();
22
+ });
23
+ }
24
+ apply(registry, prefix) {
25
+ const sheets = this.sheets.get(prefix) ?? new Map();
26
+ this.sheets.set(prefix, sheets);
27
+ let style = sheets.get(registry);
28
+ if (Object.isUndefined(style)) {
29
+ style = this.document.createElement(Resources.styleElement);
30
+ style.setAttribute(Resources.tokenStyleAttribute, prefix);
31
+ this.document.head.append(style);
32
+ sheets.set(registry, style);
33
+ }
34
+ const rules = TokenStyles.styleSheet(registry, prefix);
35
+ if (style.textContent !== rules)
36
+ style.textContent = rules;
37
+ }
38
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: TokenStyleSheet, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
39
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: TokenStyleSheet, providedIn: "root" });
40
+ }
41
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: TokenStyleSheet, decorators: [{
42
+ type: Injectable,
43
+ args: [{ providedIn: "root" }]
44
+ }], ctorParameters: () => [] });
@@ -0,0 +1,87 @@
1
+ /// <reference lib="esnext.disposable" />
2
+ /**
3
+ * @license
4
+ * Copyright (c) Noldova.
5
+ *
6
+ * This source code is licensed under the license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ import { type IBackgroundJob, type IBackgroundRunner } from "@noldova/code.editor";
10
+ import { CancellationToken } from "@noldova/context.threading";
11
+ /**
12
+ * Runs background jobs in a web worker, so a view keeps taking input while
13
+ * they run; any package's jobs, by name.
14
+ *
15
+ * @remarks
16
+ * The worker runs the core's `WorkerJobHost` over its script's own
17
+ * `BackgroundJobRegistry`, since a worker can't receive the page's
18
+ * registries. A job that registry doesn't hold runs on the fallback runner,
19
+ * in slices on the page, as does every run once the worker fails or
20
+ * doesn't load; the fallback is the core's `SlicedRunner` when none is
21
+ * given. A job that throws in the worker rejects its run with a
22
+ * {@link BackgroundJobFailedException}. The app's build bundles the worker
23
+ * script through `webWorkerTsConfig`; the script imports only framework-free
24
+ * packages, such as the core, never Angular, which can't run in a worker.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { WorkerRunner } from "@noldova/code.editor.angular";
29
+ *
30
+ * using runner = new WorkerRunner(new Worker(new URL("./jobs.worker.ts", import.meta.url), { type: "module" }));
31
+ * ```
32
+ */
33
+ export declare class WorkerRunner implements IBackgroundRunner, Disposable {
34
+ /**
35
+ * The runner for the jobs the worker can't run.
36
+ */
37
+ readonly fallback: IBackgroundRunner;
38
+ private readonly worker;
39
+ private readonly breaks;
40
+ private nextId;
41
+ private broken;
42
+ private disposed;
43
+ /**
44
+ * Creates a runner that posts each job to a worker.
45
+ *
46
+ * @param worker A worker whose script runs the core's `WorkerJobHost`.
47
+ * @param fallback The runner for jobs the worker can't run; a new
48
+ * `SlicedRunner` when not given.
49
+ * @example
50
+ * ```ts
51
+ * import { SlicedRunner } from "@noldova/code.editor";
52
+ * import { WorkerRunner } from "@noldova/code.editor.angular";
53
+ *
54
+ * using runner = new WorkerRunner(new Worker(new URL("./jobs.worker.ts", import.meta.url), { type: "module" }), new SlicedRunner(10));
55
+ * ```
56
+ */
57
+ constructor(worker: Worker, fallback?: IBackgroundRunner);
58
+ /**
59
+ * Whether runs still go to the worker: false once it failed, didn't load
60
+ * or the runner was disposed.
61
+ */
62
+ get usesWorker(): boolean;
63
+ /**
64
+ * Runs a job in the worker, or on the fallback when the worker can't.
65
+ *
66
+ * @param job The job; the worker finds its own copy by the job's name.
67
+ * @param input Its input, which the worker receives as a structured clone.
68
+ * @param cancellationToken Stops waiting for the run: the promise rejects
69
+ * with an `OperationCanceledException`, and the worker's answer is dropped.
70
+ * Defaults to `CancellationToken.none`.
71
+ * @returns The job's output; it rejects with a
72
+ * {@link BackgroundJobFailedException} when the job throws in the worker or
73
+ * the runner is disposed first.
74
+ * @example
75
+ * ```ts
76
+ * import type { IBackgroundJob } from "@noldova/code.editor";
77
+ * import type { WorkerRunner } from "@noldova/code.editor.angular";
78
+ *
79
+ * declare const runner: WorkerRunner;
80
+ * declare const job: IBackgroundJob<readonly number[], number>;
81
+ * await runner.runAsync(job, [1, 2, 3]);
82
+ * ```
83
+ */
84
+ runAsync<TInput, TOutput>(job: IBackgroundJob<TInput, TOutput>, input: TInput, cancellationToken?: CancellationToken): Promise<TOutput>;
85
+ [Symbol.dispose](): void;
86
+ private stopAll;
87
+ }