take4-console 0.15.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.
Files changed (131) hide show
  1. package/CHANGELOG.md +287 -0
  2. package/LICENSE +21 -0
  3. package/README.md +986 -0
  4. package/dist/Screen/InterfaceBuilder.d.mts +43 -0
  5. package/dist/Screen/InterfaceBuilder.d.mts.map +1 -0
  6. package/dist/Screen/InterfaceBuilder.mjs +355 -0
  7. package/dist/Screen/InterfaceBuilder.mjs.map +1 -0
  8. package/dist/Screen/Pos.d.mts +52 -0
  9. package/dist/Screen/Pos.d.mts.map +1 -0
  10. package/dist/Screen/Pos.mjs +105 -0
  11. package/dist/Screen/Pos.mjs.map +1 -0
  12. package/dist/Screen/Region.d.mts +31 -0
  13. package/dist/Screen/Region.d.mts.map +1 -0
  14. package/dist/Screen/Region.mjs +73 -0
  15. package/dist/Screen/Region.mjs.map +1 -0
  16. package/dist/Screen/RegistryHolder.d.mts +6 -0
  17. package/dist/Screen/RegistryHolder.d.mts.map +1 -0
  18. package/dist/Screen/RegistryHolder.mjs +14 -0
  19. package/dist/Screen/RegistryHolder.mjs.map +1 -0
  20. package/dist/Screen/Screen.d.mts +25 -0
  21. package/dist/Screen/Screen.d.mts.map +1 -0
  22. package/dist/Screen/Screen.mjs +100 -0
  23. package/dist/Screen/Screen.mjs.map +1 -0
  24. package/dist/Screen/Size.d.mts +23 -0
  25. package/dist/Screen/Size.d.mts.map +1 -0
  26. package/dist/Screen/Size.mjs +48 -0
  27. package/dist/Screen/Size.mjs.map +1 -0
  28. package/dist/Screen/StyleRegistry.d.mts +32 -0
  29. package/dist/Screen/StyleRegistry.d.mts.map +1 -0
  30. package/dist/Screen/StyleRegistry.mjs +80 -0
  31. package/dist/Screen/StyleRegistry.mjs.map +1 -0
  32. package/dist/Screen/Window.d.mts +121 -0
  33. package/dist/Screen/Window.d.mts.map +1 -0
  34. package/dist/Screen/Window.mjs +407 -0
  35. package/dist/Screen/Window.mjs.map +1 -0
  36. package/dist/Screen/WindowManager.d.mts +86 -0
  37. package/dist/Screen/WindowManager.d.mts.map +1 -0
  38. package/dist/Screen/WindowManager.mjs +399 -0
  39. package/dist/Screen/WindowManager.mjs.map +1 -0
  40. package/dist/Screen/controls/BarChart.d.mts +29 -0
  41. package/dist/Screen/controls/BarChart.d.mts.map +1 -0
  42. package/dist/Screen/controls/BarChart.mjs +90 -0
  43. package/dist/Screen/controls/BarChart.mjs.map +1 -0
  44. package/dist/Screen/controls/Button.d.mts +16 -0
  45. package/dist/Screen/controls/Button.d.mts.map +1 -0
  46. package/dist/Screen/controls/Button.mjs +34 -0
  47. package/dist/Screen/controls/Button.mjs.map +1 -0
  48. package/dist/Screen/controls/Checkbox.d.mts +23 -0
  49. package/dist/Screen/controls/Checkbox.d.mts.map +1 -0
  50. package/dist/Screen/controls/Checkbox.mjs +55 -0
  51. package/dist/Screen/controls/Checkbox.mjs.map +1 -0
  52. package/dist/Screen/controls/LineChart.d.mts +29 -0
  53. package/dist/Screen/controls/LineChart.d.mts.map +1 -0
  54. package/dist/Screen/controls/LineChart.mjs +172 -0
  55. package/dist/Screen/controls/LineChart.mjs.map +1 -0
  56. package/dist/Screen/controls/ListBox.d.mts +34 -0
  57. package/dist/Screen/controls/ListBox.d.mts.map +1 -0
  58. package/dist/Screen/controls/ListBox.mjs +138 -0
  59. package/dist/Screen/controls/ListBox.mjs.map +1 -0
  60. package/dist/Screen/controls/ProgressBar.d.mts +26 -0
  61. package/dist/Screen/controls/ProgressBar.d.mts.map +1 -0
  62. package/dist/Screen/controls/ProgressBar.mjs +70 -0
  63. package/dist/Screen/controls/ProgressBar.mjs.map +1 -0
  64. package/dist/Screen/controls/ProgressBarV.d.mts +22 -0
  65. package/dist/Screen/controls/ProgressBarV.d.mts.map +1 -0
  66. package/dist/Screen/controls/ProgressBarV.mjs +61 -0
  67. package/dist/Screen/controls/ProgressBarV.mjs.map +1 -0
  68. package/dist/Screen/controls/Radio.d.mts +23 -0
  69. package/dist/Screen/controls/Radio.d.mts.map +1 -0
  70. package/dist/Screen/controls/Radio.mjs +55 -0
  71. package/dist/Screen/controls/Radio.mjs.map +1 -0
  72. package/dist/Screen/controls/Sparkline.d.mts +29 -0
  73. package/dist/Screen/controls/Sparkline.d.mts.map +1 -0
  74. package/dist/Screen/controls/Sparkline.mjs +82 -0
  75. package/dist/Screen/controls/Sparkline.mjs.map +1 -0
  76. package/dist/Screen/controls/Spinner.d.mts +37 -0
  77. package/dist/Screen/controls/Spinner.d.mts.map +1 -0
  78. package/dist/Screen/controls/Spinner.mjs +87 -0
  79. package/dist/Screen/controls/Spinner.mjs.map +1 -0
  80. package/dist/Screen/controls/StatusLED.d.mts +22 -0
  81. package/dist/Screen/controls/StatusLED.d.mts.map +1 -0
  82. package/dist/Screen/controls/StatusLED.mjs +51 -0
  83. package/dist/Screen/controls/StatusLED.mjs.map +1 -0
  84. package/dist/Screen/controls/Tabs.d.mts +42 -0
  85. package/dist/Screen/controls/Tabs.d.mts.map +1 -0
  86. package/dist/Screen/controls/Tabs.mjs +126 -0
  87. package/dist/Screen/controls/Tabs.mjs.map +1 -0
  88. package/dist/Screen/controls/TextArea.d.mts +41 -0
  89. package/dist/Screen/controls/TextArea.d.mts.map +1 -0
  90. package/dist/Screen/controls/TextArea.mjs +197 -0
  91. package/dist/Screen/controls/TextArea.mjs.map +1 -0
  92. package/dist/Screen/controls/TextBox.d.mts +35 -0
  93. package/dist/Screen/controls/TextBox.d.mts.map +1 -0
  94. package/dist/Screen/controls/TextBox.mjs +135 -0
  95. package/dist/Screen/controls/TextBox.mjs.map +1 -0
  96. package/dist/Screen/types.d.mts +399 -0
  97. package/dist/Screen/types.d.mts.map +1 -0
  98. package/dist/Screen/types.mjs +22 -0
  99. package/dist/Screen/types.mjs.map +1 -0
  100. package/dist/index.d.mts +26 -0
  101. package/dist/index.d.mts.map +1 -0
  102. package/dist/index.mjs +41 -0
  103. package/dist/index.mjs.map +1 -0
  104. package/package.json +72 -0
  105. package/src/Screen/InterfaceBuilder.mts +403 -0
  106. package/src/Screen/Pos.mts +119 -0
  107. package/src/Screen/Region.mts +88 -0
  108. package/src/Screen/RegistryHolder.mts +16 -0
  109. package/src/Screen/Screen.mts +103 -0
  110. package/src/Screen/Size.mts +55 -0
  111. package/src/Screen/StyleRegistry.mts +95 -0
  112. package/src/Screen/Window.mts +439 -0
  113. package/src/Screen/WindowManager.mts +472 -0
  114. package/src/Screen/controls/BarChart.mts +109 -0
  115. package/src/Screen/controls/Button.mts +40 -0
  116. package/src/Screen/controls/Checkbox.mts +66 -0
  117. package/src/Screen/controls/LineChart.mts +202 -0
  118. package/src/Screen/controls/ListBox.mts +154 -0
  119. package/src/Screen/controls/ProgressBar.mts +88 -0
  120. package/src/Screen/controls/ProgressBarV.mts +77 -0
  121. package/src/Screen/controls/Radio.mts +66 -0
  122. package/src/Screen/controls/Sparkline.mts +101 -0
  123. package/src/Screen/controls/Spinner.mts +102 -0
  124. package/src/Screen/controls/StatusLED.mts +65 -0
  125. package/src/Screen/controls/Tabs.mts +140 -0
  126. package/src/Screen/controls/TextArea.mts +194 -0
  127. package/src/Screen/controls/TextBox.mts +139 -0
  128. package/src/Screen/types.mts +416 -0
  129. package/src/demo.mts +171 -0
  130. package/src/index.mts +105 -0
  131. package/src/layout.yaml +236 -0
@@ -0,0 +1,73 @@
1
+ export class Region {
2
+ chars;
3
+ styleIds;
4
+ size;
5
+ /** Allocates a cell buffer for the given dimensions. All cells start with style ID 0 (empty). */
6
+ constructor(width, height) {
7
+ this.size = { width, height };
8
+ const len = width * height;
9
+ this.chars = Array(len).fill(' ');
10
+ this.styleIds = new Array(len).fill(0);
11
+ }
12
+ /** Returns the region dimensions (columns × rows). */
13
+ getSize() {
14
+ return { ...this.size };
15
+ }
16
+ /** Returns the style ID stored at (x, y). Throws RangeError if out of bounds. */
17
+ getStyleId(x, y) {
18
+ this.assertBounds(x, y);
19
+ return this.styleIds[this.index(x, y)];
20
+ }
21
+ /** Sets only the character at (x, y) without modifying the style ID. Throws RangeError if out of bounds. */
22
+ setChar(x, y, char) {
23
+ this.assertBounds(x, y);
24
+ this.chars[this.index(x, y)] = char;
25
+ }
26
+ /** Sets the character and style ID at (x, y). Throws RangeError if out of bounds. */
27
+ setCell(x, y, char, styleId = 0) {
28
+ this.assertBounds(x, y);
29
+ const i = this.index(x, y);
30
+ this.chars[i] = char;
31
+ this.styleIds[i] = styleId;
32
+ }
33
+ /** Replaces only the style ID at (x, y) without changing the character. Throws RangeError if out of bounds. */
34
+ setStyleId(x, y, styleId) {
35
+ this.assertBounds(x, y);
36
+ this.styleIds[this.index(x, y)] = styleId;
37
+ }
38
+ /** Resets every cell to a blank space with style ID 0. */
39
+ clear() {
40
+ const len = this.chars.length;
41
+ for (let i = 0; i < len; i++) {
42
+ this.chars[i] = ' ';
43
+ this.styleIds[i] = 0;
44
+ }
45
+ }
46
+ /** Fills every cell with the given character and style ID. */
47
+ fill(char, styleId = 0) {
48
+ const len = this.chars.length;
49
+ for (let i = 0; i < len; i++) {
50
+ this.chars[i] = char;
51
+ this.styleIds[i] = styleId;
52
+ }
53
+ }
54
+ /** Returns a readonly view of the character buffer for rendering. */
55
+ getChars() {
56
+ return this.chars;
57
+ }
58
+ /** Returns a readonly view of the style-ID buffer for rendering. */
59
+ getStyleIds() {
60
+ return this.styleIds;
61
+ }
62
+ /** Returns the flat buffer index for the given (x, y) coordinates. */
63
+ index(x, y) {
64
+ return y * this.size.width + x;
65
+ }
66
+ /** Throws RangeError if the coordinates (x, y) are outside the region boundaries. */
67
+ assertBounds(x, y) {
68
+ if (x < 0 || x >= this.size.width || y < 0 || y >= this.size.height) {
69
+ throw new RangeError(`Cell (${x}, ${y}) is out of bounds for region ${this.size.width}×${this.size.height}`);
70
+ }
71
+ }
72
+ }
73
+ //# sourceMappingURL=Region.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Region.mjs","sourceRoot":"","sources":["../../src/Screen/Region.mts"],"names":[],"mappings":"AAEA,MAAM,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CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,qFAAqF;IAC7E,YAAY,CAAC,CAAS,EAAE,CAAS;QACxC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACrE,MAAM,IAAI,UAAU,CACnB,SAAS,CAAC,KAAK,CAAC,iCAAiC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CACtF,CAAC;QACH,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,6 @@
1
+ import { StyleRegistry } from './StyleRegistry.mjs';
2
+ /** Returns the currently active StyleRegistry. */
3
+ export declare function getRegistry(): StyleRegistry;
4
+ /** Sets the active StyleRegistry. Called by the Screen constructor. */
5
+ export declare function setRegistry(registry: StyleRegistry): void;
6
+ //# sourceMappingURL=RegistryHolder.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegistryHolder.d.mts","sourceRoot":"","sources":["../../src/Screen/RegistryHolder.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAOpD,kDAAkD;AAClD,wBAAgB,WAAW,IAAI,aAAa,CAE3C;AAED,uEAAuE;AACvE,wBAAgB,WAAW,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAEzD"}
@@ -0,0 +1,14 @@
1
+ import { StyleRegistry } from './StyleRegistry.mjs';
2
+ /** Module-level singleton holding the active StyleRegistry.
3
+ * Initialized with an empty registry so Window and controls work
4
+ * in isolation (e.g. in tests) before any Screen is constructed. */
5
+ let activeRegistry = new StyleRegistry();
6
+ /** Returns the currently active StyleRegistry. */
7
+ export function getRegistry() {
8
+ return activeRegistry;
9
+ }
10
+ /** Sets the active StyleRegistry. Called by the Screen constructor. */
11
+ export function setRegistry(registry) {
12
+ activeRegistry = registry;
13
+ }
14
+ //# sourceMappingURL=RegistryHolder.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegistryHolder.mjs","sourceRoot":"","sources":["../../src/Screen/RegistryHolder.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;qEAEqE;AACrE,IAAI,cAAc,GAAkB,IAAI,aAAa,EAAE,CAAC;AAExD,kDAAkD;AAClD,MAAM,UAAU,WAAW;IAC1B,OAAO,cAAc,CAAC;AACvB,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,WAAW,CAAC,QAAuB;IAClD,cAAc,GAAG,QAAQ,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { CellAttributes, StyleId } from './types.mjs';
2
+ import { StyleRegistry } from './StyleRegistry.mjs';
3
+ import { Window } from './Window.mjs';
4
+ export declare class Screen extends Window {
5
+ /** Initializes the root window sized to the current terminal dimensions.
6
+ * Creates a fresh StyleRegistry (with built-in styles pre-registered)
7
+ * and installs it as the global singleton. */
8
+ constructor();
9
+ /** Registers a CellAttributes object in the global style registry and returns its stable ID. */
10
+ registerStyle(attrs: CellAttributes): StyleId;
11
+ /** Returns the global StyleRegistry. */
12
+ getStyleRegistry(): StyleRegistry;
13
+ /** Overrides a built-in named style (or registers any named style) and returns its new ID.
14
+ * Controls will use the updated style on their next render() call. */
15
+ setBuiltinStyle(name: string, attrs: CellAttributes): StyleId;
16
+ /**
17
+ * Composites the full window tree, then writes the result to stdout as a single ANSI string.
18
+ */
19
+ render(): void;
20
+ /** Converts cell attributes into an ANSI escape sequence (always resets first). */
21
+ private buildAnsiSequence;
22
+ /** Parses a hex color string (#rrggbb or #rgb) into [r, g, b] components. */
23
+ private hexToRgb;
24
+ }
25
+ //# sourceMappingURL=Screen.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Screen.d.mts","sourceRoot":"","sources":["../../src/Screen/Screen.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,qBAAa,MAAO,SAAQ,MAAM;IACjC;;mDAE+C;;IAS/C,gGAAgG;IACzF,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO;IAIpD,wCAAwC;IACjC,gBAAgB,IAAI,aAAa;IAIxC;2EACuE;IAChE,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO;IAIpE;;OAEG;IACa,MAAM,IAAI,IAAI;IAe9B,mFAAmF;IACnF,OAAO,CAAC,iBAAiB;IAgCzB,6EAA6E;IAC7E,OAAO,CAAC,QAAQ;CAehB"}
@@ -0,0 +1,100 @@
1
+ import { StyleRegistry } from './StyleRegistry.mjs';
2
+ import { getRegistry, setRegistry } from './RegistryHolder.mjs';
3
+ import { Window } from './Window.mjs';
4
+ import { Pos } from './Pos.mjs';
5
+ import { Size } from './Size.mjs';
6
+ export class Screen extends Window {
7
+ /** Initializes the root window sized to the current terminal dimensions.
8
+ * Creates a fresh StyleRegistry (with built-in styles pre-registered)
9
+ * and installs it as the global singleton. */
10
+ constructor() {
11
+ const width = process.stdout.columns ?? 80;
12
+ const height = process.stdout.rows ?? 24;
13
+ const registry = new StyleRegistry();
14
+ setRegistry(registry);
15
+ super({ pos: Pos.topLeft(), size: new Size(width, height), background: 0 });
16
+ }
17
+ /** Registers a CellAttributes object in the global style registry and returns its stable ID. */
18
+ registerStyle(attrs) {
19
+ return getRegistry().register(attrs);
20
+ }
21
+ /** Returns the global StyleRegistry. */
22
+ getStyleRegistry() {
23
+ return getRegistry();
24
+ }
25
+ /** Overrides a built-in named style (or registers any named style) and returns its new ID.
26
+ * Controls will use the updated style on their next render() call. */
27
+ setBuiltinStyle(name, attrs) {
28
+ return getRegistry().registerNamed(name, attrs);
29
+ }
30
+ /**
31
+ * Composites the full window tree, then writes the result to stdout as a single ANSI string.
32
+ */
33
+ render() {
34
+ super.render();
35
+ const reg = getRegistry();
36
+ const chars = this.region.getChars();
37
+ const styleIds = this.region.getStyleIds();
38
+ let output = '\x1b[H';
39
+ for (let i = 0; i < chars.length; i++) {
40
+ output += this.buildAnsiSequence(reg.get(styleIds[i]));
41
+ output += chars[i];
42
+ }
43
+ output += '\x1b[0m';
44
+ process.stdout.write(output);
45
+ }
46
+ /** Converts cell attributes into an ANSI escape sequence (always resets first). */
47
+ buildAnsiSequence(attrs) {
48
+ const codes = [0];
49
+ if (attrs.bold)
50
+ codes.push(1);
51
+ if (attrs.dim)
52
+ codes.push(2);
53
+ if (attrs.italic)
54
+ codes.push(3);
55
+ if (attrs.underline)
56
+ codes.push(4);
57
+ if (attrs.blink)
58
+ codes.push(5);
59
+ if (attrs.inverse)
60
+ codes.push(7);
61
+ if (attrs.strikethrough)
62
+ codes.push(9);
63
+ if (attrs.foreground !== undefined) {
64
+ if (typeof attrs.foreground === 'number') {
65
+ codes.push(38, 5, attrs.foreground);
66
+ }
67
+ else {
68
+ const [r, g, b] = this.hexToRgb(attrs.foreground);
69
+ codes.push(38, 2, r, g, b);
70
+ }
71
+ }
72
+ if (attrs.background !== undefined) {
73
+ if (typeof attrs.background === 'number') {
74
+ codes.push(48, 5, attrs.background);
75
+ }
76
+ else {
77
+ const [r, g, b] = this.hexToRgb(attrs.background);
78
+ codes.push(48, 2, r, g, b);
79
+ }
80
+ }
81
+ return `\x1b[${codes.join(';')}m`;
82
+ }
83
+ /** Parses a hex color string (#rrggbb or #rgb) into [r, g, b] components. */
84
+ hexToRgb(hex) {
85
+ const clean = hex.replace('#', '');
86
+ if (clean.length === 3) {
87
+ return [
88
+ parseInt(clean[0] + clean[0], 16),
89
+ parseInt(clean[1] + clean[1], 16),
90
+ parseInt(clean[2] + clean[2], 16),
91
+ ];
92
+ }
93
+ return [
94
+ parseInt(clean.slice(0, 2), 16),
95
+ parseInt(clean.slice(2, 4), 16),
96
+ parseInt(clean.slice(4, 6), 16),
97
+ ];
98
+ }
99
+ }
100
+ //# sourceMappingURL=Screen.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Screen.mjs","sourceRoot":"","sources":["../../src/Screen/Screen.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,MAAM,OAAO,MAAO,SAAQ,MAAM;IACjC;;mDAE+C;IAC/C;QACC,MAAM,KAAK,GAAM,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAK,OAAO,CAAC,MAAM,CAAC,IAAI,IAAO,EAAE,CAAC;QAC9C,MAAM,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QACrC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtB,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,gGAAgG;IACzF,aAAa,CAAC,KAAqB;QACzC,OAAO,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,wCAAwC;IACjC,gBAAgB;QACtB,OAAO,WAAW,EAAE,CAAC;IACtB,CAAC;IAED;2EACuE;IAChE,eAAe,CAAC,IAAY,EAAE,KAAqB;QACzD,OA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,GAAG,EAAE,EAAE,CAAC,CAAC;QACnC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO;gBACN,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;gBACjC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;gBACjC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;aACjC,CAAC;QACH,CAAC;QACD,OAAO;YACN,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;YAC/B,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;YAC/B,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;SAC/B,CAAC;IACH,CAAC;CACD"}
@@ -0,0 +1,23 @@
1
+ import { Pct } from './Pos.mjs';
2
+ /** Encodes window dimensions. Supports absolute pixel values and percentage of parent size. */
3
+ export declare class Size {
4
+ private wSpec;
5
+ private hSpec;
6
+ /** Creates a size from width and height values.
7
+ * Pass a plain number for absolute pixels, or a Pct instance for a percentage of the parent. */
8
+ constructor(w: number | Pct, h: number | Pct);
9
+ /** Creates a size that fills 100% of the parent in both dimensions. */
10
+ static fill(): Size;
11
+ /** Creates a size that fills 100% of the parent's width; height is absolute or percentage. */
12
+ static fillWidth(h: number | Pct): Size;
13
+ /** Creates a size that fills 100% of the parent's height; width is absolute or percentage. */
14
+ static fillHeight(w: number | Pct): Size;
15
+ /** Returns true when both dimensions are absolute pixel values (no parent size needed). */
16
+ isAbsolute(): boolean;
17
+ /** Resolves this size to pixel dimensions given the parent's dimensions. */
18
+ resolve(parentW: number, parentH: number): {
19
+ w: number;
20
+ h: number;
21
+ };
22
+ }
23
+ //# sourceMappingURL=Size.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Size.d.mts","sourceRoot":"","sources":["../../src/Screen/Size.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAchC,+FAA+F;AAC/F,qBAAa,IAAI;IAChB,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,KAAK,CAAU;IAEvB;qGACiG;gBAC9E,CAAC,EAAE,MAAM,GAAG,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,GAAG;IAKnD,uEAAuE;WACzD,IAAI,IAAI,IAAI;IAI1B,8FAA8F;WAChF,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI;IAI9C,8FAA8F;WAChF,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI;IAI/C,2FAA2F;IACpF,UAAU,IAAI,OAAO;IAI5B,4EAA4E;IACrE,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;CAM1E"}
@@ -0,0 +1,48 @@
1
+ import { Pct } from './Pos.mjs';
2
+ /** Converts a user-supplied dimension value to an internal DimSpec. */
3
+ function toDimSpec(v) {
4
+ if (v instanceof Pct)
5
+ return { mode: 'pct', value: v.value };
6
+ return { mode: 'abs', value: v };
7
+ }
8
+ /** Resolves a single dimension spec to a pixel value. */
9
+ function resolveDim(spec, parentSize) {
10
+ if (spec.mode === 'pct')
11
+ return Math.floor(parentSize * spec.value / 100);
12
+ return spec.value;
13
+ }
14
+ /** Encodes window dimensions. Supports absolute pixel values and percentage of parent size. */
15
+ export class Size {
16
+ wSpec;
17
+ hSpec;
18
+ /** Creates a size from width and height values.
19
+ * Pass a plain number for absolute pixels, or a Pct instance for a percentage of the parent. */
20
+ constructor(w, h) {
21
+ this.wSpec = toDimSpec(w);
22
+ this.hSpec = toDimSpec(h);
23
+ }
24
+ /** Creates a size that fills 100% of the parent in both dimensions. */
25
+ static fill() {
26
+ return new Size(new Pct(100), new Pct(100));
27
+ }
28
+ /** Creates a size that fills 100% of the parent's width; height is absolute or percentage. */
29
+ static fillWidth(h) {
30
+ return new Size(new Pct(100), h);
31
+ }
32
+ /** Creates a size that fills 100% of the parent's height; width is absolute or percentage. */
33
+ static fillHeight(w) {
34
+ return new Size(w, new Pct(100));
35
+ }
36
+ /** Returns true when both dimensions are absolute pixel values (no parent size needed). */
37
+ isAbsolute() {
38
+ return this.wSpec.mode === 'abs' && this.hSpec.mode === 'abs';
39
+ }
40
+ /** Resolves this size to pixel dimensions given the parent's dimensions. */
41
+ resolve(parentW, parentH) {
42
+ return {
43
+ w: resolveDim(this.wSpec, parentW),
44
+ h: resolveDim(this.hSpec, parentH),
45
+ };
46
+ }
47
+ }
48
+ //# sourceMappingURL=Size.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Size.mjs","sourceRoot":"","sources":["../../src/Screen/Size.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,uEAAuE;AACvE,SAAS,SAAS,CAAC,CAAe;IACjC,IAAI,CAAC,YAAY,GAAG;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IAC7D,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAClC,CAAC;AAED,yDAAyD;AACzD,SAAS,UAAU,CAAC,IAAa,EAAE,UAAkB;IACpD,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,KAAK,CAAC;AACnB,CAAC;AAED,+FAA+F;AAC/F,MAAM,OAAO,IAAI;IACR,KAAK,CAAU;IACf,KAAK,CAAU;IAEvB;qGACiG;IACjG,YAAmB,CAAe,EAAE,CAAe;QAClD,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,uEAAuE;IAChE,MAAM,CAAC,IAAI;QACjB,OAAO,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED,8FAA8F;IACvF,MAAM,CAAC,SAAS,CAAC,CAAe;QACtC,OAAO,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAClC,CAAC;IAED,8FAA8F;IACvF,MAAM,CAAC,UAAU,CAAC,CAAe;QACvC,OAAO,IAAI,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAClC,CAAC;IAED,2FAA2F;IACpF,UAAU;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC;IAC/D,CAAC;IAED,4EAA4E;IACrE,OAAO,CAAC,OAAe,EAAE,OAAe;QAC9C,OAAO;YACN,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC;YAClC,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC;SAClC,CAAC;IACH,CAAC;CACD"}
@@ -0,0 +1,32 @@
1
+ import type { CellAttributes, StyleId, Color } from './types.mjs';
2
+ /** Central registry that maps integer style IDs to CellAttributes objects.
3
+ * Identical attribute sets always map to the same ID (deduplication). */
4
+ export declare class StyleRegistry {
5
+ /** Styles indexed by ID. Index 0 is always the empty style {}. */
6
+ private styles;
7
+ /** Serialized key → ID, for deduplication. */
8
+ private index;
9
+ /** Name → ID map for built-in and user-defined named styles. */
10
+ private named;
11
+ /** Creates a new StyleRegistry with built-in named styles pre-registered. */
12
+ constructor();
13
+ /** Registers a CellAttributes object and returns its stable ID.
14
+ * If an identical style was registered before, returns the existing ID. */
15
+ register(attrs: CellAttributes): StyleId;
16
+ /** Registers a CellAttributes object under a given name and returns its stable ID.
17
+ * Calling with the same name again replaces the previous association. */
18
+ registerNamed(name: string, attrs: CellAttributes): StyleId;
19
+ /** Returns the StyleId associated with the given name, or undefined if not registered. */
20
+ getNamed(name: string): StyleId | undefined;
21
+ /** Returns the foreground Color of a named style, or the fallback value if the name is
22
+ * not registered or the style has no foreground attribute. */
23
+ getNamedForeground(name: string, fallback: Color): Color;
24
+ /** Returns the CellAttributes for the given style ID. Returns {} for unknown IDs. */
25
+ get(id: StyleId): CellAttributes;
26
+ /** Merges two styles and returns the ID of the result.
27
+ * The `over` style takes precedence over `base` for conflicting keys. */
28
+ merge(baseId: StyleId, overId: StyleId): StyleId;
29
+ /** Produces a deterministic JSON key for deduplication. */
30
+ private makeKey;
31
+ }
32
+ //# sourceMappingURL=StyleRegistry.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StyleRegistry.d.mts","sourceRoot":"","sources":["../../src/Screen/StyleRegistry.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAclE;0EAC0E;AAC1E,qBAAa,aAAa;IACzB,kEAAkE;IAClE,OAAO,CAAC,MAAM,CAA0B;IACxC,8CAA8C;IAC9C,OAAO,CAAC,KAAK,CAA8C;IAC3D,gEAAgE;IAChE,OAAO,CAAC,KAAK,CAAmC;IAEhD,6EAA6E;;IAc7E;gFAC4E;IACrE,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO;IAU/C;8EAC0E;IACnE,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO;IAMlE,0FAA0F;IACnF,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAIlD;mEAC+D;IACxD,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,KAAK;IAM/D,qFAAqF;IAC9E,GAAG,CAAC,EAAE,EAAE,OAAO,GAAG,cAAc;IAIvC;8EAC0E;IACnE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO;IAMvD,2DAA2D;IAC3D,OAAO,CAAC,OAAO;CASf"}
@@ -0,0 +1,80 @@
1
+ import { BUILTIN_WINDOW_BG, BUILTIN_BORDER, BUILTIN_BORDER_FOCUSED, BUILTIN_BORDER_DISABLED, BUILTIN_TEXT, BUILTIN_TEXT_FOCUSED, BUILTIN_TEXT_DISABLED, BUILTIN_TEXT_PLACEHOLDER, BUILTIN_TEXT_CHECKED, BUILTIN_CURSOR, } from './types.mjs';
2
+ /** Central registry that maps integer style IDs to CellAttributes objects.
3
+ * Identical attribute sets always map to the same ID (deduplication). */
4
+ export class StyleRegistry {
5
+ /** Styles indexed by ID. Index 0 is always the empty style {}. */
6
+ styles = [{}];
7
+ /** Serialized key → ID, for deduplication. */
8
+ index = new Map([['{}', 0]]);
9
+ /** Name → ID map for built-in and user-defined named styles. */
10
+ named = new Map();
11
+ /** Creates a new StyleRegistry with built-in named styles pre-registered. */
12
+ constructor() {
13
+ this.registerNamed(BUILTIN_WINDOW_BG, { background: 237 });
14
+ this.registerNamed(BUILTIN_BORDER, { foreground: 240 });
15
+ this.registerNamed(BUILTIN_BORDER_FOCUSED, { foreground: 75 });
16
+ this.registerNamed(BUILTIN_BORDER_DISABLED, { foreground: 238 });
17
+ this.registerNamed(BUILTIN_TEXT, { foreground: 252 });
18
+ this.registerNamed(BUILTIN_TEXT_FOCUSED, { foreground: 255, bold: true });
19
+ this.registerNamed(BUILTIN_TEXT_DISABLED, { foreground: 245, dim: true });
20
+ this.registerNamed(BUILTIN_TEXT_PLACEHOLDER, { foreground: 242, italic: true });
21
+ this.registerNamed(BUILTIN_TEXT_CHECKED, { foreground: 76, bold: true });
22
+ this.registerNamed(BUILTIN_CURSOR, { inverse: true });
23
+ }
24
+ /** Registers a CellAttributes object and returns its stable ID.
25
+ * If an identical style was registered before, returns the existing ID. */
26
+ register(attrs) {
27
+ const key = this.makeKey(attrs);
28
+ const existing = this.index.get(key);
29
+ if (existing !== undefined)
30
+ return existing;
31
+ const id = this.styles.length;
32
+ this.styles.push({ ...attrs });
33
+ this.index.set(key, id);
34
+ return id;
35
+ }
36
+ /** Registers a CellAttributes object under a given name and returns its stable ID.
37
+ * Calling with the same name again replaces the previous association. */
38
+ registerNamed(name, attrs) {
39
+ const id = this.register(attrs);
40
+ this.named.set(name, id);
41
+ return id;
42
+ }
43
+ /** Returns the StyleId associated with the given name, or undefined if not registered. */
44
+ getNamed(name) {
45
+ return this.named.get(name);
46
+ }
47
+ /** Returns the foreground Color of a named style, or the fallback value if the name is
48
+ * not registered or the style has no foreground attribute. */
49
+ getNamedForeground(name, fallback) {
50
+ const id = this.named.get(name);
51
+ if (id === undefined)
52
+ return fallback;
53
+ return this.styles[id]?.foreground ?? fallback;
54
+ }
55
+ /** Returns the CellAttributes for the given style ID. Returns {} for unknown IDs. */
56
+ get(id) {
57
+ return this.styles[id] ?? {};
58
+ }
59
+ /** Merges two styles and returns the ID of the result.
60
+ * The `over` style takes precedence over `base` for conflicting keys. */
61
+ merge(baseId, overId) {
62
+ if (overId === 0)
63
+ return baseId;
64
+ if (baseId === 0)
65
+ return overId;
66
+ return this.register({ ...this.get(baseId), ...this.get(overId) });
67
+ }
68
+ /** Produces a deterministic JSON key for deduplication. */
69
+ makeKey(attrs) {
70
+ const keys = Object.keys(attrs).sort();
71
+ if (keys.length === 0)
72
+ return '{}';
73
+ const sorted = {};
74
+ for (const k of keys) {
75
+ sorted[k] = attrs[k];
76
+ }
77
+ return JSON.stringify(sorted);
78
+ }
79
+ }
80
+ //# sourceMappingURL=StyleRegistry.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StyleRegistry.mjs","sourceRoot":"","sources":["../../src/Screen/StyleRegistry.mts"],"names":[],"mappings":"AACA,OAAO,EACN,iBAAiB,EACjB,cAAc,EACd,sBAAsB,EACtB,uBAAuB,EACvB,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,GACd,MAAM,aAAa,CAAC;AAErB;0EAC0E;AAC1E,MAAM,OAAO,aAAa;IACzB,kEAAkE;IAC1D,MAAM,GAAqB,CAAC,EAAE,CAAC,CAAC;IACxC,8CAA8C;IACtC,KAAK,GAAyB,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3D,gEAAgE;IACxD,KAAK,GAAyB,IAAI,GAAG,EAAE,CAAC;IAEhD,6EAA6E;IAC7E;QACC,IAAI,CAAC,aAAa,CAAC,iBAAiB,EAAS,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,aAAa,CAAC,cAAc,EAAY,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,aAAa,CAAC,sBAAsB,EAAI,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,aAAa,CAAC,uBAAuB,EAAG,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,aAAa,CAAC,YAAY,EAAc,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,aAAa,CAAC,oBAAoB,EAAM,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAA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indowProperties, WriteTextOptions, TerminalSize } from './types.mjs';
2
+ import { Region } from './Region.mjs';
3
+ import { StyleRegistry } from './StyleRegistry.mjs';
4
+ export declare class Window {
5
+ x: number;
6
+ y: number;
7
+ /** Composited display buffer – rebuilt by render(); read by blitChild and Screen. */
8
+ protected region: Region;
9
+ /** Global style registry shared by all windows and controls. */
10
+ protected registry: StyleRegistry;
11
+ protected children: Window[];
12
+ /** Whether this window currently has keyboard focus. */
13
+ protected focused: boolean;
14
+ /** Whether this window is disabled (inactive and visually dimmed). */
15
+ protected disabled: boolean;
16
+ /** Optional text label displayed by the control. */
17
+ protected label: string;
18
+ /** Style ID used for normal (default) text rendering. Initialized from BUILTIN_TEXT. */
19
+ protected normalStyleId: StyleId;
20
+ /** Style ID used when the control is focused. Initialized from BUILTIN_TEXT_FOCUSED. */
21
+ protected focusedStyleId: StyleId;
22
+ /** Style ID used when the control is disabled. Initialized from BUILTIN_TEXT_DISABLED. */
23
+ protected disabledStyleId: StyleId;
24
+ /** User-written content – survives render() cycles. */
25
+ private content;
26
+ private background;
27
+ private border;
28
+ /** True when the original border config included an explicit color; prevents auto-sync. */
29
+ private borderColorExplicit;
30
+ private active;
31
+ private posSpec;
32
+ private sizeSpec;
33
+ /** Creates a window from the given properties.
34
+ * For percentage-based sizes, call addChild() before writing content to the window.
35
+ * Uses the global StyleRegistry set by the Screen constructor. */
36
+ constructor(wp: WindowProperties);
37
+ /** Returns the window dimensions (columns × rows). */
38
+ getSize(): TerminalSize;
39
+ /** Returns the number of cells consumed by decorations on each edge. */
40
+ private borderInset;
41
+ /** Returns the top-left offset of the content area, accounting for decorations such as borders. */
42
+ getInnerOffset(): {
43
+ x: number;
44
+ y: number;
45
+ };
46
+ /** Returns the dimensions of the content area, accounting for decorations such as borders. */
47
+ getInnerSize(): TerminalSize;
48
+ /** Sets the active state. Affects border and background appearance on next render(). */
49
+ setActive(active: boolean): void;
50
+ /** Sets the focused state. Controls use this to change visual appearance on focus. */
51
+ setFocused(focused: boolean): void;
52
+ /** Returns whether this window currently has keyboard focus. */
53
+ isFocused(): boolean;
54
+ /** Sets the disabled state and deactivates the window when disabled. */
55
+ setDisabled(disabled: boolean): void;
56
+ /** Returns whether this window is currently disabled. */
57
+ isDisabled(): boolean;
58
+ /** Sets the label text displayed by the control. */
59
+ setLabel(label: string): void;
60
+ /** Returns the current label text. */
61
+ getLabel(): string;
62
+ /** Updates the border configuration. Effective on the next render() call.
63
+ * Intended for use by subclasses that need dynamic decoration (e.g. focus-state colour). */
64
+ protected updateBorder(border: WindowBorder | boolean | undefined): void;
65
+ /** Recomputes the border color from the current focused/disabled state.
66
+ * Called automatically at the start of render() so subclasses never need to do it manually.
67
+ * Only updates the color when no explicit color was provided in the original border config. */
68
+ private syncBorderColor;
69
+ /** Adds a child window. If the child uses percentage-based sizes they are resolved immediately
70
+ * against this window's inner dimensions (excluding decorations such as borders).
71
+ * Position is resolved relative to the inner area and stored on child.x/y. */
72
+ addChild(child: Window): void;
73
+ /** Returns a resolved Cell (char + CellAttributes) at (x, y) from the display buffer.
74
+ * Throws RangeError if out of bounds. */
75
+ getCell(x: number, y: number): Cell;
76
+ /** Sets only the character at (x, y) without modifying the style ID. Throws RangeError if out of bounds. */
77
+ setChar(x: number, y: number, char: string): void;
78
+ /** Sets the character and style ID at (x, y). Throws RangeError if out of bounds. */
79
+ setCell(x: number, y: number, char: string, styleId?: StyleId): void;
80
+ /** Merges the given style ID onto the existing style at (x, y) without changing the character.
81
+ * Throws RangeError if out of bounds. */
82
+ mergeStyle(x: number, y: number, styleId: StyleId): void;
83
+ /** Resets every cell to a blank space with style ID 0. */
84
+ clear(): void;
85
+ /** Fills every cell with the given character and style ID. */
86
+ fill(char: string, styleId?: StyleId): void;
87
+ /** Writes text into the window's content area starting at (x, y) (default 0, 0).
88
+ * Coordinates are relative to the inner content area (i.e. decorations such as borders are excluded).
89
+ * Newline characters move to the next row, resetting x to startX.
90
+ * Characters outside the inner bounds are silently clipped.
91
+ * When no style is provided, automatically picks disabledStyleId, focusedStyleId, or normalStyleId
92
+ * based on the current disabled/focused state. */
93
+ writeText(text: string, options?: WriteTextOptions): void;
94
+ /**
95
+ * Builds the display buffer: background → user content → border → children.
96
+ * The result is stored in region and used by blitChild / Screen.render().
97
+ */
98
+ render(): void;
99
+ /** Fills the display buffer with the background style. When inactive, adds dim to every cell.
100
+ * No-op when background is 0 (transparent). */
101
+ private paintBackground;
102
+ /** Overlays user-written content onto the display buffer, merging with any background already set. */
103
+ private blitContent;
104
+ /** Draws border characters on the display buffer edges. When inactive, adds dim to border cells. */
105
+ private paintBorder;
106
+ /** Copies a child's display buffer onto this window's display buffer, clipping to this window's bounds.
107
+ * Styles are transferred from the child's registry into this window's registry.
108
+ * Position is re-resolved from the child's Pos spec relative to the inner content area on every render. */
109
+ private blitChild;
110
+ /** Removes a previously added child window. No-op if the child is not found. */
111
+ removeChild(child: Window): void;
112
+ /** Replaces both internal regions with new ones of the given dimensions,
113
+ * then re-resolves sizes and positions of all direct children against the updated inner area. */
114
+ private resizeRegions;
115
+ /** Re-resolves sizes and absolute positions for every direct child against the current inner area.
116
+ * Called after this window is resized so that percentage-based children get correct dimensions. */
117
+ private reflowChildren;
118
+ /** Returns the flat index for (x, y) in the region buffer (used by getCell). */
119
+ private flatIndex;
120
+ }
121
+ //# sourceMappingURL=Window.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Window.d.mts","sourceRoot":"","sources":["../../src/Screen/Window.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAe,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE9H,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAmBpD,qBAAa,MAAM;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACjB,qFAAqF;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