agentlas 1.0.42 → 1.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/engine/agentlas-workforce.cjs +1 -1
- package/engine/hephaestus/runtime.cjs +1 -1
- package/engine/storm/storm.cjs +1 -1
- package/engine/storm/swarm.cjs +1 -1
- package/engine/ui/shell.cjs +9 -3
- package/engine/vendor/mermaid/LICENSE +205 -0
- package/engine/vendor/mermaid/ansi.js +23 -0
- package/engine/vendor/mermaid/canvas.js +366 -0
- package/engine/vendor/mermaid/graph.js +91 -0
- package/engine/vendor/mermaid/index.js +100 -0
- package/engine/vendor/mermaid/labels.js +324 -0
- package/engine/vendor/mermaid/layout-seq.js +194 -0
- package/engine/vendor/mermaid/layout.js +881 -0
- package/engine/vendor/mermaid/package.json +1 -0
- package/engine/vendor/mermaid/parse.js +1108 -0
- package/engine/vendor/mermaid/source-box.js +78 -0
- package/engine/vendor/mermaid/types.js +1 -0
- package/engine/vendor/mermaid/width-data.js +994 -0
- package/engine/vendor/mermaid/width.js +76 -0
- package/engine/vendor/tui/LICENSE +20 -0
- package/engine/vendor/tui/autocomplete.js +632 -0
- package/engine/vendor/tui/components/alt-screen-flash.js +37 -0
- package/engine/vendor/tui/components/box.js +104 -0
- package/engine/vendor/tui/components/cancellable-loader.js +35 -0
- package/engine/vendor/tui/components/editor.js +1961 -0
- package/engine/vendor/tui/components/h-stack.js +43 -0
- package/engine/vendor/tui/components/image.js +90 -0
- package/engine/vendor/tui/components/input.js +378 -0
- package/engine/vendor/tui/components/loader.js +69 -0
- package/engine/vendor/tui/components/markdown.js +806 -0
- package/engine/vendor/tui/components/scroll-view.js +173 -0
- package/engine/vendor/tui/components/select-list.js +159 -0
- package/engine/vendor/tui/components/settings-list.js +182 -0
- package/engine/vendor/tui/components/spacer.js +23 -0
- package/engine/vendor/tui/components/stack.js +111 -0
- package/engine/vendor/tui/components/text.js +89 -0
- package/engine/vendor/tui/components/truncated-text.js +51 -0
- package/engine/vendor/tui/components/v-stack.js +26 -0
- package/engine/vendor/tui/deps/east-asian-width/LICENSE +9 -0
- package/engine/vendor/tui/deps/east-asian-width/index.js +30 -0
- package/engine/vendor/tui/deps/east-asian-width/lookup-data.js +21 -0
- package/engine/vendor/tui/deps/east-asian-width/lookup.js +138 -0
- package/engine/vendor/tui/deps/east-asian-width/utilities.js +24 -0
- package/engine/vendor/tui/deps/marked/LICENSE +44 -0
- package/engine/vendor/tui/deps/marked/index.js +77 -0
- package/engine/vendor/tui/editor-component.js +2 -0
- package/engine/vendor/tui/fuzzy.js +110 -0
- package/engine/vendor/tui/index.js +42 -0
- package/engine/vendor/tui/keybindings.js +209 -0
- package/engine/vendor/tui/keys.js +1174 -0
- package/engine/vendor/tui/kill-ring.js +44 -0
- package/engine/vendor/tui/latex.js +1264 -0
- package/engine/vendor/tui/layout-node.js +6 -0
- package/engine/vendor/tui/layout.js +314 -0
- package/engine/vendor/tui/native-modifiers.js +60 -0
- package/engine/vendor/tui/package.json +1 -0
- package/engine/vendor/tui/stdin-buffer.js +361 -0
- package/engine/vendor/tui/terminal-colors.js +59 -0
- package/engine/vendor/tui/terminal-image.js +518 -0
- package/engine/vendor/tui/terminal.js +436 -0
- package/engine/vendor/tui/tui-alt-screen.js +902 -0
- package/engine/vendor/tui/tui-main-screen.js +533 -0
- package/engine/vendor/tui/tui.js +937 -0
- package/engine/vendor/tui/undo-stack.js +25 -0
- package/engine/vendor/tui/utils.js +1191 -0
- package/engine/vendor/tui/word-navigation.js +96 -0
- package/package.json +2 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.43 — 2026-08-11
|
|
4
|
+
|
|
5
|
+
Zero runtime dependencies. The renderer now lives in this repository.
|
|
6
|
+
|
|
7
|
+
- The terminal shell's renderer and diagram sources are vendored into
|
|
8
|
+
`engine/vendor/` and `package.json` declares no runtime dependencies at all.
|
|
9
|
+
An exact version pin already prevented drift and tampering, but a package
|
|
10
|
+
removed from the registry would still have broken installs; that last failure
|
|
11
|
+
mode is now gone, and the code is ours to fix.
|
|
12
|
+
- Upstream copyright notices are preserved beside each vendored tree, as the
|
|
13
|
+
MIT and Apache-2.0 terms require. The vendoring script refuses to run if a
|
|
14
|
+
notice is missing.
|
|
15
|
+
- New release gate `vendor-tui-sync` fails when the vendored tree and its
|
|
16
|
+
upstream differ, so the copy cannot rot silently.
|
|
17
|
+
|
|
3
18
|
## 1.0.42 — 2026-08-11
|
|
4
19
|
|
|
5
20
|
Projects, automations and firms reach the interactive shell; the shell is
|
|
@@ -1979,7 +1979,7 @@ function create(deps = {}) {
|
|
|
1979
1979
|
const D = deps;
|
|
1980
1980
|
|
|
1981
1981
|
/*
|
|
1982
|
-
*
|
|
1982
|
+
* 셸 이행 정지작업 (D3 Phase 1-2, 2026-08-11): ctx가 준 Ui가 있으면 그것을
|
|
1983
1983
|
* 쓴다. 자체 생성 Ui는 렌더러 교체 시 구 코드가 stdout에 직접 써 프레임을
|
|
1984
1984
|
* 찢는 병렬 경로였다. 생성은 주입이 없을 때의 폴백으로만 남긴다.
|
|
1985
1985
|
*/
|
|
@@ -195,7 +195,7 @@ function create(ctx, deps = {}) {
|
|
|
195
195
|
const lang = () => (ctx && ctx.lang) || "en";
|
|
196
196
|
|
|
197
197
|
/*
|
|
198
|
-
*
|
|
198
|
+
* 셸 이행 정지작업 (D3 Phase 1-2, 2026-08-11): ctx가 준 Ui가 있으면 그것을
|
|
199
199
|
* 쓴다. 자체 생성 Ui는 렌더러 교체 시 구 코드가 stdout에 직접 써 프레임을
|
|
200
200
|
* 찢는 병렬 경로였다. 생성은 주입이 없을 때의 폴백으로만 남긴다.
|
|
201
201
|
*/
|
package/engine/storm/storm.cjs
CHANGED
|
@@ -37,7 +37,7 @@ function create(deps) {
|
|
|
37
37
|
const { swarmRun } = require("./swarm.cjs").create(D);
|
|
38
38
|
|
|
39
39
|
/*
|
|
40
|
-
*
|
|
40
|
+
* 셸 이행 정지작업 (D3 Phase 1-2, 2026-08-11): ctx가 준 Ui가 있으면 그것을
|
|
41
41
|
* 쓴다. 자체 생성 Ui는 렌더러 교체 시 구 코드가 stdout에 직접 써 프레임을
|
|
42
42
|
* 찢는 병렬 경로였다. 생성은 주입이 없을 때의 폴백으로만 남긴다.
|
|
43
43
|
*/
|
package/engine/storm/swarm.cjs
CHANGED
|
@@ -128,7 +128,7 @@ function create(deps) {
|
|
|
128
128
|
const D = deps;
|
|
129
129
|
|
|
130
130
|
/*
|
|
131
|
-
*
|
|
131
|
+
* 셸 이행 정지작업 (D3 Phase 1-2, 2026-08-11): ctx가 준 Ui가 있으면 그것을
|
|
132
132
|
* 쓴다. 자체 생성 Ui는 렌더러 교체 시 구 코드가 stdout에 직접 써 프레임을
|
|
133
133
|
* 찢는 병렬 경로였다. 생성은 주입이 없을 때의 폴백으로만 남긴다.
|
|
134
134
|
*/
|
package/engine/ui/shell.cjs
CHANGED
|
@@ -29,8 +29,14 @@ const { resolveProjectController, withProjectControllerContext } = require("../p
|
|
|
29
29
|
|
|
30
30
|
function loadRenderer() {
|
|
31
31
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
/*
|
|
33
|
+
* 렌더러는 engine/vendor/tui 에 내재화돼 있다 — npm 의존성이 아니다.
|
|
34
|
+
* 이유: 정확 핀+무결성 해시는 버전 드리프트·변조를 막지만 레지스트리에서
|
|
35
|
+
* 그 버전이 삭제되면 설치가 실패한다. 소스가 저장소에 있으면 그 위험이 없고
|
|
36
|
+
* 우리가 직접 고칠 수 있다. 갱신은 scripts/vendor-tui.mjs.
|
|
37
|
+
* ESM 이므로 require(esm) 이 필요하다 — engines 가 Node >=20.19 를 선언한다.
|
|
38
|
+
*/
|
|
39
|
+
return require("../vendor/tui/index.js");
|
|
34
40
|
} catch (cause) {
|
|
35
41
|
throw Object.assign(
|
|
36
42
|
new Error("The Agentlas shell needs Node >=20.19. Run without AGENTLAS_TUI=1, or upgrade Node."),
|
|
@@ -272,7 +278,7 @@ async function startShell(ctx, opts = {}) {
|
|
|
272
278
|
const lbl = e.sourceHandle === "true" ? "|참|" : e.sourceHandle === "false" ? "|거짓|" : "";
|
|
273
279
|
lines.push(` ${e.source} -->${lbl} ${e.target}`);
|
|
274
280
|
}
|
|
275
|
-
const { render, toAnsi } = require("
|
|
281
|
+
const { render, toAnsi } = require("../vendor/mermaid/index.js");
|
|
276
282
|
const art = toAnsi(render(lines.join("\n")));
|
|
277
283
|
ui.ensureNl();
|
|
278
284
|
ui.line(ui.c.bold(row.name));
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Copyright 2023-2026 SpaceXAI
|
|
2
|
+
Copyright 2026 Alexey Zaytsev
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Apache License
|
|
6
|
+
Version 2.0, January 2004
|
|
7
|
+
http://www.apache.org/licenses/
|
|
8
|
+
|
|
9
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
10
|
+
|
|
11
|
+
1. Definitions.
|
|
12
|
+
|
|
13
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
14
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
15
|
+
|
|
16
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
17
|
+
the copyright owner that is granting the License.
|
|
18
|
+
|
|
19
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
20
|
+
other entities that control, are controlled by, or are under common
|
|
21
|
+
control with that entity. For the purposes of this definition,
|
|
22
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
23
|
+
direction or management of such entity, whether by contract or
|
|
24
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
25
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
26
|
+
|
|
27
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
28
|
+
exercising permissions granted by this License.
|
|
29
|
+
|
|
30
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
31
|
+
including but not limited to software source code, documentation
|
|
32
|
+
source, and configuration files.
|
|
33
|
+
|
|
34
|
+
"Object" form shall mean any form resulting from mechanical
|
|
35
|
+
transformation or translation of a Source form, including but
|
|
36
|
+
not limited to compiled object code, generated documentation,
|
|
37
|
+
and conversions to other media types.
|
|
38
|
+
|
|
39
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
40
|
+
Object form, made available under the License, as indicated by a
|
|
41
|
+
copyright notice that is included in or attached to the work
|
|
42
|
+
(an example is provided in the Appendix below).
|
|
43
|
+
|
|
44
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
45
|
+
form, that is based on (or derived from) the Work and for which the
|
|
46
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
47
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
48
|
+
of this License, Derivative Works shall not include works that remain
|
|
49
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
50
|
+
the Work and Derivative Works thereof.
|
|
51
|
+
|
|
52
|
+
"Contribution" shall mean any work of authorship, including
|
|
53
|
+
the original version of the Work and any modifications or additions
|
|
54
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
55
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
56
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
57
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
58
|
+
means any form of electronic, verbal, or written communication sent
|
|
59
|
+
to the Licensor or its representatives, including but not limited to
|
|
60
|
+
communication on electronic mailing lists, source code control systems,
|
|
61
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
62
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
63
|
+
excluding communication that is conspicuously marked or otherwise
|
|
64
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
65
|
+
|
|
66
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
67
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
68
|
+
subsequently incorporated within the Work.
|
|
69
|
+
|
|
70
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
74
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
75
|
+
Work and such Derivative Works in Source or Object form.
|
|
76
|
+
|
|
77
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
78
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
79
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
80
|
+
(except as stated in this section) patent license to make, have made,
|
|
81
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
82
|
+
where such license applies only to those patent claims licensable
|
|
83
|
+
by such Contributor that are necessarily infringed by their
|
|
84
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
85
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
86
|
+
institute patent litigation against any entity (including a
|
|
87
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
88
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
89
|
+
or contributory patent infringement, then any patent licenses
|
|
90
|
+
granted to You under this License for that Work shall terminate
|
|
91
|
+
as of the date such litigation is filed.
|
|
92
|
+
|
|
93
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
94
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
95
|
+
modifications, and in Source or Object form, provided that You
|
|
96
|
+
meet the following conditions:
|
|
97
|
+
|
|
98
|
+
(a) You must give any other recipients of the Work or
|
|
99
|
+
Derivative Works a copy of this License; and
|
|
100
|
+
|
|
101
|
+
(b) You must cause any modified files to carry prominent notices
|
|
102
|
+
stating that You changed the files; and
|
|
103
|
+
|
|
104
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
105
|
+
that You distribute, all copyright, patent, trademark, and
|
|
106
|
+
attribution notices from the Source form of the Work,
|
|
107
|
+
excluding those notices that do not pertain to any part of
|
|
108
|
+
the Derivative Works; and
|
|
109
|
+
|
|
110
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
111
|
+
distribution, then any Derivative Works that You distribute must
|
|
112
|
+
include a readable copy of the attribution notices contained
|
|
113
|
+
within such NOTICE file, excluding those notices that do not
|
|
114
|
+
pertain to any part of the Derivative Works, in at least one
|
|
115
|
+
of the following places: within a NOTICE text file distributed
|
|
116
|
+
as part of the Derivative Works; within the Source form or
|
|
117
|
+
documentation, if provided along with the Derivative Works; or,
|
|
118
|
+
within a display generated by the Derivative Works, if and
|
|
119
|
+
wherever such third-party notices normally appear. The contents
|
|
120
|
+
of the NOTICE file are for informational purposes only and
|
|
121
|
+
do not modify the License. You may add Your own attribution
|
|
122
|
+
notices within Derivative Works that You distribute, alongside
|
|
123
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
124
|
+
that such additional attribution notices cannot be construed
|
|
125
|
+
as modifying the License.
|
|
126
|
+
|
|
127
|
+
You may add Your own copyright statement to Your modifications and
|
|
128
|
+
may provide additional or different license terms and conditions
|
|
129
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
130
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
131
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
132
|
+
the conditions stated in this License.
|
|
133
|
+
|
|
134
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
135
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
136
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
137
|
+
this License, without any additional terms or conditions.
|
|
138
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
139
|
+
the terms of any separate license agreement you may have executed
|
|
140
|
+
with Licensor regarding such Contributions.
|
|
141
|
+
|
|
142
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
143
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
144
|
+
except as required for reasonable and customary use in describing the
|
|
145
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
146
|
+
|
|
147
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
148
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
149
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
150
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
151
|
+
implied, including, without limitation, any warranties or conditions
|
|
152
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
153
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
154
|
+
appropriateness of using or redistributing the Work and assume any
|
|
155
|
+
risks associated with Your exercise of permissions under this License.
|
|
156
|
+
|
|
157
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
158
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
159
|
+
unless required by applicable law (such as deliberate and grossly
|
|
160
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
161
|
+
liable to You for damages, including any direct, indirect, special,
|
|
162
|
+
incidental, or consequential damages of any character arising as a
|
|
163
|
+
result of this License or out of the use or inability to use the
|
|
164
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
165
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
166
|
+
other commercial damages or losses), even if such Contributor
|
|
167
|
+
has been advised of the possibility of such damages.
|
|
168
|
+
|
|
169
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
170
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
171
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
172
|
+
or other liability obligations and/or rights consistent with this
|
|
173
|
+
License. However, in accepting such obligations, You may act only
|
|
174
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
175
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
176
|
+
defend, and hold each Contributor harmless for any liability
|
|
177
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
178
|
+
of your accepting any such warranty or additional liability.
|
|
179
|
+
|
|
180
|
+
END OF TERMS AND CONDITIONS
|
|
181
|
+
|
|
182
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
183
|
+
|
|
184
|
+
To apply the Apache License to your work, attach the following
|
|
185
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
186
|
+
replaced with your own identifying information. (Don't include
|
|
187
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
188
|
+
comment syntax for the file format. We also recommend that a
|
|
189
|
+
file or class name and description of purpose be included on the
|
|
190
|
+
same "printed page" as the copyright notice for easier
|
|
191
|
+
identification within third-party archives.
|
|
192
|
+
|
|
193
|
+
Copyright [yyyy] [name of copyright owner]
|
|
194
|
+
|
|
195
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
196
|
+
you may not use this file except in compliance with the License.
|
|
197
|
+
You may obtain a copy of the License at
|
|
198
|
+
|
|
199
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
200
|
+
|
|
201
|
+
Unless required by applicable law or agreed to in writing, software
|
|
202
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
203
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
204
|
+
See the License for the specific language governing permissions and
|
|
205
|
+
limitations under the License.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const ESC = String.fromCharCode(27);
|
|
2
|
+
/** Dim frame, plain labels, cyan connectors. Readable on light and dark. */
|
|
3
|
+
export const DEFAULT_THEME = {
|
|
4
|
+
border: '2',
|
|
5
|
+
edge: '36',
|
|
6
|
+
edgeLabel: '2;36',
|
|
7
|
+
title: '1',
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Render art to ANSI-coloured lines.
|
|
11
|
+
*
|
|
12
|
+
* A convenience over mapping `art.styled` yourself — reach for that directly
|
|
13
|
+
* when your TUI has its own styling model.
|
|
14
|
+
*/
|
|
15
|
+
export function toAnsi(art, theme = DEFAULT_THEME) {
|
|
16
|
+
return art.styled.map((row) => row
|
|
17
|
+
.map((span) => {
|
|
18
|
+
const sgr = theme[span.cls];
|
|
19
|
+
return sgr === undefined ? span.text : `${ESC}[${sgr}m${span.text}${ESC}[0m`;
|
|
20
|
+
})
|
|
21
|
+
.join(''));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=ansi.js.map
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { measured } from './width.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sentinel occupying the trailing column of a wide glyph. Never emitted: the
|
|
4
|
+
* line builder skips it so a CJK character claims two cells of layout but
|
|
5
|
+
* contributes one character of output.
|
|
6
|
+
*/
|
|
7
|
+
export const CONT = String.fromCharCode(0);
|
|
8
|
+
/** Connection direction bits, combined into a box-drawing glyph by `maskChar`. */
|
|
9
|
+
export const U = 1;
|
|
10
|
+
export const D = 2;
|
|
11
|
+
export const L = 4;
|
|
12
|
+
export const R = 8;
|
|
13
|
+
/** Line styles, tracked per cell so crossing edges keep their own stroke. */
|
|
14
|
+
export const STY_DOT = 1;
|
|
15
|
+
export const STY_THICK = 2;
|
|
16
|
+
export const STY_SOLID = 4;
|
|
17
|
+
/**
|
|
18
|
+
* A grid of cells. Edges accumulate as direction bits rather than glyphs so
|
|
19
|
+
* that crossings and junctions resolve correctly whatever order they are drawn
|
|
20
|
+
* in; `finalizeMask` turns the accumulated bits into characters at the end.
|
|
21
|
+
*
|
|
22
|
+
* `occupied` marks cells claimed by a box, which edge bits must not overwrite.
|
|
23
|
+
*/
|
|
24
|
+
export class Canvas {
|
|
25
|
+
w;
|
|
26
|
+
h;
|
|
27
|
+
ch;
|
|
28
|
+
cls;
|
|
29
|
+
mask;
|
|
30
|
+
style;
|
|
31
|
+
occupied;
|
|
32
|
+
curStyle = STY_SOLID;
|
|
33
|
+
constructor(w, h) {
|
|
34
|
+
const n = w * h;
|
|
35
|
+
this.w = w;
|
|
36
|
+
this.h = h;
|
|
37
|
+
this.ch = new Array(n).fill(' ');
|
|
38
|
+
this.cls = new Array(n).fill('none');
|
|
39
|
+
this.mask = new Uint8Array(n);
|
|
40
|
+
this.style = new Uint8Array(n);
|
|
41
|
+
this.occupied = new Uint8Array(n);
|
|
42
|
+
}
|
|
43
|
+
idx(x, y) {
|
|
44
|
+
return y * this.w + x;
|
|
45
|
+
}
|
|
46
|
+
set(x, y, c, cls) {
|
|
47
|
+
if (x >= this.w || y >= this.h)
|
|
48
|
+
return;
|
|
49
|
+
const i = this.idx(x, y);
|
|
50
|
+
this.ch[i] = c;
|
|
51
|
+
this.cls[i] = cls;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Accumulate direction bits on a free cell.
|
|
55
|
+
*
|
|
56
|
+
* `cls` is the class to claim the cell for; `border` cells are never
|
|
57
|
+
* reclassified, so a connector meeting a box keeps the box's styling.
|
|
58
|
+
*/
|
|
59
|
+
addBits(x, y, bits, cls = 'edge') {
|
|
60
|
+
if (x >= this.w || y >= this.h)
|
|
61
|
+
return;
|
|
62
|
+
const i = this.idx(x, y);
|
|
63
|
+
if (this.occupied[i])
|
|
64
|
+
return;
|
|
65
|
+
this.mask[i] |= bits;
|
|
66
|
+
this.style[i] |= this.curStyle;
|
|
67
|
+
if (this.cls[i] !== 'border')
|
|
68
|
+
this.cls[i] = cls;
|
|
69
|
+
}
|
|
70
|
+
/** Stamp a finished sub-canvas (a subgraph frame's contents) at an offset. */
|
|
71
|
+
blit(sub, ox, oy) {
|
|
72
|
+
for (let sy = 0; sy < sub.h; sy++) {
|
|
73
|
+
for (let sx = 0; sx < sub.w; sx++) {
|
|
74
|
+
const x = ox + sx;
|
|
75
|
+
const y = oy + sy;
|
|
76
|
+
if (x >= this.w || y >= this.h)
|
|
77
|
+
continue;
|
|
78
|
+
const si = sub.idx(sx, sy);
|
|
79
|
+
const di = this.idx(x, y);
|
|
80
|
+
this.ch[di] = sub.ch[si];
|
|
81
|
+
this.cls[di] = sub.cls[si];
|
|
82
|
+
this.style[di] = sub.style[si];
|
|
83
|
+
this.occupied[di] = 1;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Add direction bits even to an occupied cell, so an edge can meet a border. */
|
|
88
|
+
junction(x, y, bits) {
|
|
89
|
+
if (x >= this.w || y >= this.h)
|
|
90
|
+
return;
|
|
91
|
+
const i = this.idx(x, y);
|
|
92
|
+
this.mask[i] |= bits;
|
|
93
|
+
if (this.cls[i] !== 'border')
|
|
94
|
+
this.cls[i] = 'edge';
|
|
95
|
+
}
|
|
96
|
+
segV(x, y0, y1) {
|
|
97
|
+
const a = Math.min(y0, y1);
|
|
98
|
+
const b = Math.max(y0, y1);
|
|
99
|
+
for (let y = a; y <= b; y++) {
|
|
100
|
+
let bits = 0;
|
|
101
|
+
if (y > a)
|
|
102
|
+
bits |= U;
|
|
103
|
+
if (y < b)
|
|
104
|
+
bits |= D;
|
|
105
|
+
this.addBits(x, y, bits);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
segH(y, x0, x1) {
|
|
109
|
+
const a = Math.min(x0, x1);
|
|
110
|
+
const b = Math.max(x0, x1);
|
|
111
|
+
for (let x = a; x <= b; x++) {
|
|
112
|
+
let bits = 0;
|
|
113
|
+
if (x > a)
|
|
114
|
+
bits |= L;
|
|
115
|
+
if (x < b)
|
|
116
|
+
bits |= R;
|
|
117
|
+
this.addBits(x, y, bits);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Resolve accumulated direction bits into glyphs, honouring line style. */
|
|
121
|
+
finalizeMask() {
|
|
122
|
+
for (let i = 0; i < this.ch.length; i++) {
|
|
123
|
+
if (this.mask[i] !== 0 && this.ch[i] === ' ') {
|
|
124
|
+
const c = maskChar(this.mask[i]);
|
|
125
|
+
this.ch[i] =
|
|
126
|
+
this.style[i] === STY_DOT ? dottedChar(c) : this.style[i] === STY_THICK ? thickChar(c) : c;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Mirror top-to-bottom for `BT`. Rows reorder but within-row text does not,
|
|
132
|
+
* so labels stay readable; box-drawing glyphs flip to match.
|
|
133
|
+
*/
|
|
134
|
+
flipVertical() {
|
|
135
|
+
for (let y = 0; y < Math.floor(this.h / 2); y++) {
|
|
136
|
+
const y2 = this.h - 1 - y;
|
|
137
|
+
for (let x = 0; x < this.w; x++) {
|
|
138
|
+
const i = this.idx(x, y);
|
|
139
|
+
const j = this.idx(x, y2);
|
|
140
|
+
[this.ch[i], this.ch[j]] = [this.ch[j], this.ch[i]];
|
|
141
|
+
[this.cls[i], this.cls[j]] = [this.cls[j], this.cls[i]];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (let i = 0; i < this.ch.length; i++)
|
|
145
|
+
this.ch[i] = flipGlyphV(this.ch[i]);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Mirror left-to-right for `RL`. Mirroring reverses each row, so after
|
|
149
|
+
* flipping glyphs each text/label run is reversed back to reading order.
|
|
150
|
+
*/
|
|
151
|
+
flipHorizontal() {
|
|
152
|
+
for (let y = 0; y < this.h; y++) {
|
|
153
|
+
for (let x = 0; x < Math.floor(this.w / 2); x++) {
|
|
154
|
+
const x2 = this.w - 1 - x;
|
|
155
|
+
const i = this.idx(x, y);
|
|
156
|
+
const j = this.idx(x2, y);
|
|
157
|
+
[this.ch[i], this.ch[j]] = [this.ch[j], this.ch[i]];
|
|
158
|
+
[this.cls[i], this.cls[j]] = [this.cls[j], this.cls[i]];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
for (let i = 0; i < this.ch.length; i++)
|
|
162
|
+
this.ch[i] = flipGlyphH(this.ch[i]);
|
|
163
|
+
for (let y = 0; y < this.h; y++) {
|
|
164
|
+
let x = 0;
|
|
165
|
+
while (x < this.w) {
|
|
166
|
+
const cls = this.cls[this.idx(x, y)];
|
|
167
|
+
if (cls === 'text' || cls === 'edgeLabel') {
|
|
168
|
+
const start = this.idx(x, y);
|
|
169
|
+
while (x < this.w && this.cls[this.idx(x, y)] === cls)
|
|
170
|
+
x++;
|
|
171
|
+
const end = this.idx(x, y);
|
|
172
|
+
reverseSlice(this.ch, start, end);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
x++;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** Group each row into runs of one class, dropping wide-glyph continuations. */
|
|
181
|
+
toLines() {
|
|
182
|
+
const plain = [];
|
|
183
|
+
const styled = [];
|
|
184
|
+
let width = 0;
|
|
185
|
+
for (let y = 0; y < this.h; y++) {
|
|
186
|
+
// A trailing CONT counts as painted: it is the second cell of a wide
|
|
187
|
+
// glyph, so the row really does reach that column.
|
|
188
|
+
let last = 0;
|
|
189
|
+
for (let x = this.w - 1; x >= 0; x--) {
|
|
190
|
+
if (this.ch[this.idx(x, y)] !== ' ') {
|
|
191
|
+
last = x + 1;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
width = Math.max(width, last);
|
|
196
|
+
const spans = [];
|
|
197
|
+
let plainRow = '';
|
|
198
|
+
let run = '';
|
|
199
|
+
let runCls = 'none';
|
|
200
|
+
for (let x = 0; x < last; x++) {
|
|
201
|
+
const i = this.idx(x, y);
|
|
202
|
+
const c = this.ch[i];
|
|
203
|
+
if (c === CONT)
|
|
204
|
+
continue;
|
|
205
|
+
const cls = this.cls[i];
|
|
206
|
+
plainRow += c;
|
|
207
|
+
if (cls !== runCls && run !== '') {
|
|
208
|
+
spans.push({ text: run, cls: runCls });
|
|
209
|
+
run = '';
|
|
210
|
+
}
|
|
211
|
+
runCls = cls;
|
|
212
|
+
run += c;
|
|
213
|
+
}
|
|
214
|
+
if (run !== '')
|
|
215
|
+
spans.push({ text: run, cls: runCls });
|
|
216
|
+
styled.push(spans);
|
|
217
|
+
// Only ASCII spaces, which is all a blank cell ever holds. Trimming `\s`
|
|
218
|
+
// would eat a trailing NBSP that `styled` keeps, desyncing the two.
|
|
219
|
+
plain.push(plainRow.replace(/ +$/, ''));
|
|
220
|
+
}
|
|
221
|
+
let first = 0;
|
|
222
|
+
while (first < plain.length && plain[first] === '')
|
|
223
|
+
first++;
|
|
224
|
+
let end = plain.length;
|
|
225
|
+
while (end > first && plain[end - 1] === '')
|
|
226
|
+
end--;
|
|
227
|
+
return { plain: plain.slice(first, end), styled: styled.slice(first, end), width };
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function reverseSlice(arr, start, end) {
|
|
231
|
+
for (let i = start, j = end - 1; i < j; i++, j--) {
|
|
232
|
+
;
|
|
233
|
+
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Paint `text` at `x, y`, one grapheme cluster per cell.
|
|
238
|
+
*
|
|
239
|
+
* A wide cluster claims a second cell, marked with `CONT` so the line builder
|
|
240
|
+
* emits one character for it rather than a stray space.
|
|
241
|
+
*/
|
|
242
|
+
export function drawText(canvas, text, x, y, cls) {
|
|
243
|
+
let cur = x;
|
|
244
|
+
for (const [cluster, cw] of measured(text)) {
|
|
245
|
+
if (cw === 0)
|
|
246
|
+
continue;
|
|
247
|
+
canvas.set(cur, y, cluster, cls);
|
|
248
|
+
for (let k = 1; k < cw; k++)
|
|
249
|
+
canvas.set(cur + k, y, CONT, cls);
|
|
250
|
+
cur += cw;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Paint `text` at `x, y`, clearing any edge bits underneath first.
|
|
255
|
+
*
|
|
256
|
+
* Used where text sits on top of a drawn line (sequence messages, dividers,
|
|
257
|
+
* compartment rows) and must win over it.
|
|
258
|
+
*/
|
|
259
|
+
export function drawTextOverEdges(canvas, text, x, y, cls) {
|
|
260
|
+
let cur = x;
|
|
261
|
+
for (const [cluster, cw] of measured(text)) {
|
|
262
|
+
if (cw === 0)
|
|
263
|
+
continue;
|
|
264
|
+
for (let k = 0; k < cw; k++) {
|
|
265
|
+
if (cur + k < canvas.w && y < canvas.h)
|
|
266
|
+
canvas.mask[canvas.idx(cur + k, y)] = 0;
|
|
267
|
+
canvas.set(cur + k, y, k === 0 ? cluster : CONT, cls);
|
|
268
|
+
}
|
|
269
|
+
cur += cw;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
export function maskChar(mask) {
|
|
273
|
+
switch (mask) {
|
|
274
|
+
case 0:
|
|
275
|
+
return ' ';
|
|
276
|
+
case U:
|
|
277
|
+
case D:
|
|
278
|
+
case U | D:
|
|
279
|
+
return '│';
|
|
280
|
+
case L:
|
|
281
|
+
case R:
|
|
282
|
+
case L | R:
|
|
283
|
+
return '─';
|
|
284
|
+
case D | R:
|
|
285
|
+
return '┌';
|
|
286
|
+
case D | L:
|
|
287
|
+
return '┐';
|
|
288
|
+
case U | R:
|
|
289
|
+
return '└';
|
|
290
|
+
case U | L:
|
|
291
|
+
return '┘';
|
|
292
|
+
case U | D | R:
|
|
293
|
+
return '├';
|
|
294
|
+
case U | D | L:
|
|
295
|
+
return '┤';
|
|
296
|
+
case D | L | R:
|
|
297
|
+
return '┬';
|
|
298
|
+
case U | L | R:
|
|
299
|
+
return '┴';
|
|
300
|
+
default:
|
|
301
|
+
return '┼';
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const DOTTED = { '─': '╌', '│': '╎' };
|
|
305
|
+
const THICK = {
|
|
306
|
+
'─': '━',
|
|
307
|
+
'│': '┃',
|
|
308
|
+
'┌': '┏',
|
|
309
|
+
'┐': '┓',
|
|
310
|
+
'└': '┗',
|
|
311
|
+
'┘': '┛',
|
|
312
|
+
'├': '┣',
|
|
313
|
+
'┤': '┫',
|
|
314
|
+
'┬': '┳',
|
|
315
|
+
'┴': '┻',
|
|
316
|
+
'┼': '╋',
|
|
317
|
+
};
|
|
318
|
+
const FLIP_V = {
|
|
319
|
+
'┌': '└',
|
|
320
|
+
'└': '┌',
|
|
321
|
+
'┐': '┘',
|
|
322
|
+
'┘': '┐',
|
|
323
|
+
'┏': '┗',
|
|
324
|
+
'┗': '┏',
|
|
325
|
+
'┓': '┛',
|
|
326
|
+
'┛': '┓',
|
|
327
|
+
'╭': '╰',
|
|
328
|
+
'╰': '╭',
|
|
329
|
+
'╮': '╯',
|
|
330
|
+
'╯': '╮',
|
|
331
|
+
'┬': '┴',
|
|
332
|
+
'┴': '┬',
|
|
333
|
+
'┳': '┻',
|
|
334
|
+
'┻': '┳',
|
|
335
|
+
'▼': '▲',
|
|
336
|
+
'▲': '▼',
|
|
337
|
+
'▽': '△',
|
|
338
|
+
'△': '▽',
|
|
339
|
+
};
|
|
340
|
+
const FLIP_H = {
|
|
341
|
+
'┌': '┐',
|
|
342
|
+
'┐': '┌',
|
|
343
|
+
'└': '┘',
|
|
344
|
+
'┘': '└',
|
|
345
|
+
'┏': '┓',
|
|
346
|
+
'┓': '┏',
|
|
347
|
+
'┗': '┛',
|
|
348
|
+
'┛': '┗',
|
|
349
|
+
'╭': '╮',
|
|
350
|
+
'╮': '╭',
|
|
351
|
+
'╰': '╯',
|
|
352
|
+
'╯': '╰',
|
|
353
|
+
'├': '┤',
|
|
354
|
+
'┤': '├',
|
|
355
|
+
'┣': '┫',
|
|
356
|
+
'┫': '┣',
|
|
357
|
+
'▶': '◄',
|
|
358
|
+
'◄': '▶',
|
|
359
|
+
'▷': '◁',
|
|
360
|
+
'◁': '▷',
|
|
361
|
+
};
|
|
362
|
+
export const dottedChar = (c) => DOTTED[c] ?? c;
|
|
363
|
+
export const thickChar = (c) => THICK[c] ?? c;
|
|
364
|
+
export const flipGlyphV = (c) => FLIP_V[c] ?? c;
|
|
365
|
+
export const flipGlyphH = (c) => FLIP_H[c] ?? c;
|
|
366
|
+
//# sourceMappingURL=canvas.js.map
|