@mnmal-ai/surface-kit 0.0.0 → 0.14.6
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/LICENSE +202 -0
- package/README.md +5 -1
- package/dist/bar.d.ts +5 -0
- package/dist/bar.d.ts.map +1 -0
- package/dist/cells.d.ts +9 -0
- package/dist/cells.d.ts.map +1 -0
- package/dist/cells.js +37 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/markdown.d.ts +19 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/panel.d.ts +19 -0
- package/dist/panel.d.ts.map +1 -0
- package/dist/sparkline.d.ts +3 -0
- package/dist/sparkline.d.ts.map +1 -0
- package/dist/spinner-DIFSSHah.js +133 -0
- package/dist/spinner.d.ts +7 -0
- package/dist/spinner.d.ts.map +1 -0
- package/dist/text.d.ts +5 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +3 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
# @mnmal-ai/surface-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Stateless view primitives (Ink 7 + React 19): `Panel`, cell-width helpers, markdown spans, spinners and sparklines. Colours come from `@mnmal-ai/surface-theme` tones.
|
|
4
|
+
|
|
5
|
+
Part of [surface](https://github.com/mnmal-ai/surface). Pre-1.0: the module contract may break between minor versions.
|
|
6
|
+
|
|
7
|
+
Apache-2.0.
|
package/dist/bar.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Intensity per cell, 0 (track) to 3 (head): a head fading over two cells either side. */
|
|
2
|
+
export declare function barFrame(frame: number, width?: number): number[];
|
|
3
|
+
/** The glyph every cell uses — thin, so the bar sits low in the line. */
|
|
4
|
+
export declare const BAR_GLYPH = "\u2501";
|
|
5
|
+
//# sourceMappingURL=bar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bar.d.ts","sourceRoot":"","sources":["../src/bar.ts"],"names":[],"mappings":"AAWA,2FAA2F;AAC3F,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,MAAM,EAAE,CAQ3D;AAED,yEAAyE;AACzE,eAAO,MAAM,SAAS,WAAM,CAAC"}
|
package/dist/cells.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Terminal columns `s` occupies. */
|
|
2
|
+
export declare const cellWidth: (s: string) => number;
|
|
3
|
+
/** The longest prefix of `s` that fits in `max` columns, never splitting a character. */
|
|
4
|
+
export declare function cutToWidth(s: string, max: number): string;
|
|
5
|
+
/** `s` in at most `max` columns, ending in `…` when anything was cut. */
|
|
6
|
+
export declare function truncateCells(s: string, max: number): string;
|
|
7
|
+
/** `s` cut and padded to exactly `width` columns, right-aligned when asked. */
|
|
8
|
+
export declare function padCells(s: string, width: number, right?: boolean): string;
|
|
9
|
+
//# sourceMappingURL=cells.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cells.d.ts","sourceRoot":"","sources":["../src/cells.ts"],"names":[],"mappings":"AAOA,qCAAqC;AACrC,eAAO,MAAM,SAAS,MAAO,MAAM,KAAG,MAAwB,CAAC;AAI/D,yFAAyF;AACzF,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAUzD;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAG5D;AAED,+EAA+E;AAC/E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,MAAM,CAIxE"}
|
package/dist/cells.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import stringWidth from "string-width";
|
|
2
|
+
|
|
3
|
+
//#region src/cells.ts
|
|
4
|
+
/**
|
|
5
|
+
* Columns are cells, not code units: `.length` counts a CJK character as one column where
|
|
6
|
+
* a terminal draws two. `string-width` is the measure Ink lays out with, so the two cannot
|
|
7
|
+
* disagree, and cuts fall on grapheme boundaries, never inside a character.
|
|
8
|
+
*/
|
|
9
|
+
/** Terminal columns `s` occupies. */
|
|
10
|
+
const cellWidth = (s) => stringWidth(s);
|
|
11
|
+
const graphemes = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
12
|
+
/** The longest prefix of `s` that fits in `max` columns, never splitting a character. */
|
|
13
|
+
function cutToWidth(s, max) {
|
|
14
|
+
let out = "";
|
|
15
|
+
let used = 0;
|
|
16
|
+
for (const { segment } of graphemes.segment(s)) {
|
|
17
|
+
const w = cellWidth(segment);
|
|
18
|
+
if (used + w > max) break;
|
|
19
|
+
out += segment;
|
|
20
|
+
used += w;
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
/** `s` in at most `max` columns, ending in `…` when anything was cut. */
|
|
25
|
+
function truncateCells(s, max) {
|
|
26
|
+
if (max <= 1) return cutToWidth(s, Math.max(0, max));
|
|
27
|
+
return cellWidth(s) <= max ? s : `${cutToWidth(s, max - 1)}…`;
|
|
28
|
+
}
|
|
29
|
+
/** `s` cut and padded to exactly `width` columns, right-aligned when asked. */
|
|
30
|
+
function padCells(s, width, right = false) {
|
|
31
|
+
const clipped = truncateCells(s, width);
|
|
32
|
+
const pad = " ".repeat(Math.max(0, width - cellWidth(clipped)));
|
|
33
|
+
return right ? pad + clipped : clipped + pad;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { cellWidth, cutToWidth, padCells, truncateCells };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { BAR_GLYPH, barFrame } from './bar.js';
|
|
2
|
+
export { cellWidth, cutToWidth, padCells, truncateCells } from './cells.js';
|
|
3
|
+
export { type MarkdownSpan, type MarkdownStyle, markdownSpans } from './markdown.js';
|
|
4
|
+
export { Panel, type PanelProps } from './panel.js';
|
|
5
|
+
export { sparkline } from './sparkline.js';
|
|
6
|
+
export { BOX_CHASE, BRAILLE_RING, SPINNER, spinnerFrame } from './spinner.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { a as sparkline, c as barFrame, i as spinnerFrame, n as BRAILLE_RING, o as markdownSpans, r as SPINNER, s as BAR_GLYPH, t as BOX_CHASE } from "./spinner-DIFSSHah.js";
|
|
2
|
+
import { cellWidth, cutToWidth, padCells, truncateCells } from "./cells.js";
|
|
3
|
+
import { Box, Text } from "ink";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/panel.tsx
|
|
7
|
+
/** The panel anatomy: a single-line border in the panel's tone and an upper-case title line led by `theme.glyph.title`. */
|
|
8
|
+
function Panel({ title, theme, tone = "accent", width, ground, children }) {
|
|
9
|
+
const label = `${theme.glyph.title} ${title.toUpperCase()}`;
|
|
10
|
+
const shown = width === void 0 ? label : truncateCells(label, Math.max(1, width - 4));
|
|
11
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
12
|
+
borderStyle: "single",
|
|
13
|
+
borderColor: theme.color[tone],
|
|
14
|
+
borderBackgroundColor: ground ?? theme.color.raised,
|
|
15
|
+
paddingX: 1,
|
|
16
|
+
flexDirection: "column",
|
|
17
|
+
...width === void 0 ? {} : { width },
|
|
18
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
19
|
+
bold: true,
|
|
20
|
+
color: theme.color[tone],
|
|
21
|
+
children: shown
|
|
22
|
+
}), children]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { BAR_GLYPH, BOX_CHASE, BRAILLE_RING, Panel, SPINNER, barFrame, cellWidth, cutToWidth, markdownSpans, padCells, sparkline, spinnerFrame, truncateCells };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An answer's inline Markdown as styled spans: `**bold**`, `*italic*` / `_italic_`,
|
|
3
|
+
* `` `code` ``. Inline only: block markup is all but absent from answers, and Ink
|
|
4
|
+
* already breaks a `<Text>` on `\n`.
|
|
5
|
+
*
|
|
6
|
+
* A marker is styled only when it can only be markup, and otherwise left exactly as written: an
|
|
7
|
+
* answer is prose about arbitrary things (`5 * 3 = 15`, `alpha_prime_v3`, `Ænima*`). The rules are
|
|
8
|
+
* CommonMark's flanking rules, cut down: an opening delimiter is followed by a non-space, a
|
|
9
|
+
* closing one preceded by one, and an underscore is never inside a word. A marker that finds no
|
|
10
|
+
* partner stays literal.
|
|
11
|
+
*/
|
|
12
|
+
export type MarkdownStyle = 'bold' | 'italic' | 'code';
|
|
13
|
+
export interface MarkdownSpan {
|
|
14
|
+
readonly text: string;
|
|
15
|
+
readonly style?: MarkdownStyle;
|
|
16
|
+
}
|
|
17
|
+
/** The answer cut into plain and styled spans. Markers that are not markup stay in the text. */
|
|
18
|
+
export declare function markdownSpans(text: string): MarkdownSpan[];
|
|
19
|
+
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEvD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;CAChC;AAwBD,gGAAgG;AAChG,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CAqB1D"}
|
package/dist/panel.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Theme, Tone } from '@mnmal-ai/surface-theme';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
export interface PanelProps {
|
|
4
|
+
readonly title: string;
|
|
5
|
+
readonly theme: Theme;
|
|
6
|
+
readonly tone?: Tone;
|
|
7
|
+
/** Outer width in columns, border included. */
|
|
8
|
+
readonly width?: number;
|
|
9
|
+
/**
|
|
10
|
+
* The background its border is drawn on. Ink paints borders on no background unless told, so a
|
|
11
|
+
* Panel inside an overlay showed a stripe of the terminal's own ground on every border row and
|
|
12
|
+
* down each side. Defaults to `theme.color.raised`, the overlay ground every Panel sits on today.
|
|
13
|
+
*/
|
|
14
|
+
readonly ground?: string;
|
|
15
|
+
readonly children?: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
/** The panel anatomy: a single-line border in the panel's tone and an upper-case title line led by `theme.glyph.title`. */
|
|
18
|
+
export declare function Panel({ title, theme, tone, width, ground, children }: PanelProps): import("react").JSX.Element;
|
|
19
|
+
//# sourceMappingURL=panel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../src/panel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;IACrB,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAC/B;AAED,2HAA2H;AAC3H,wBAAgB,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAe,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,UAAU,+BAmB3F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sparkline.d.ts","sourceRoot":"","sources":["../src/sparkline.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAQtF"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
//#region src/bar.ts
|
|
2
|
+
/** Intensity per cell, 0 (track) to 3 (head): a head fading over two cells either side. */
|
|
3
|
+
function barFrame(frame, width = 8) {
|
|
4
|
+
if (width <= 0) return [];
|
|
5
|
+
if (width === 1) return [3];
|
|
6
|
+
const period = 2 * (width - 1);
|
|
7
|
+
const p = (frame % period + period) % period;
|
|
8
|
+
const head = p < width ? p : period - p;
|
|
9
|
+
return Array.from({ length: width }, (_, i) => Math.max(0, 3 - Math.abs(i - head)));
|
|
10
|
+
}
|
|
11
|
+
/** The glyph every cell uses — thin, so the bar sits low in the line. */
|
|
12
|
+
const BAR_GLYPH = "━";
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/markdown.ts
|
|
16
|
+
const WORD = /[\p{L}\p{N}]/u;
|
|
17
|
+
const isWord = (ch) => ch !== void 0 && WORD.test(ch);
|
|
18
|
+
const isSpace = (ch) => ch === void 0 || /\s/.test(ch);
|
|
19
|
+
/**
|
|
20
|
+
* Where `delim` closes an emphasis run opened at `open` (the index just after the opening
|
|
21
|
+
* delimiter), or -1. Never across a line break: a stray marker must not style the rest of an
|
|
22
|
+
* answer.
|
|
23
|
+
*/
|
|
24
|
+
function closing(text, open, delim) {
|
|
25
|
+
for (let i = open + 1; i <= text.length - delim.length; i++) {
|
|
26
|
+
if (text[i] === "\n") return -1;
|
|
27
|
+
if (!text.startsWith(delim, i)) continue;
|
|
28
|
+
if (isSpace(text[i - 1])) continue;
|
|
29
|
+
if (delim === "*" && (text[i + 1] === "*" || text[i - 1] === "*")) continue;
|
|
30
|
+
if (delim.startsWith("_") && isWord(text[i + delim.length])) continue;
|
|
31
|
+
return i;
|
|
32
|
+
}
|
|
33
|
+
return -1;
|
|
34
|
+
}
|
|
35
|
+
/** The answer cut into plain and styled spans. Markers that are not markup stay in the text. */
|
|
36
|
+
function markdownSpans(text) {
|
|
37
|
+
const spans = [];
|
|
38
|
+
let plain = "";
|
|
39
|
+
const emit = (span) => {
|
|
40
|
+
if (plain !== "") spans.push({ text: plain });
|
|
41
|
+
plain = "";
|
|
42
|
+
spans.push(span);
|
|
43
|
+
};
|
|
44
|
+
let i = 0;
|
|
45
|
+
while (i < text.length) {
|
|
46
|
+
const next = styledAt(text, i);
|
|
47
|
+
if (next === null) {
|
|
48
|
+
plain += text[i];
|
|
49
|
+
i++;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
emit(next.span);
|
|
53
|
+
i = next.end;
|
|
54
|
+
}
|
|
55
|
+
if (plain !== "") spans.push({ text: plain });
|
|
56
|
+
return spans;
|
|
57
|
+
}
|
|
58
|
+
/** The styled span that starts at `i`, and the index just past it; null when `i` is plain. */
|
|
59
|
+
function styledAt(text, i) {
|
|
60
|
+
if (text[i] === "`") {
|
|
61
|
+
const end = text.indexOf("`", i + 1);
|
|
62
|
+
if (end > i + 1 && !text.slice(i + 1, end).includes("\n")) return {
|
|
63
|
+
span: {
|
|
64
|
+
text: text.slice(i + 1, end),
|
|
65
|
+
style: "code"
|
|
66
|
+
},
|
|
67
|
+
end: end + 1
|
|
68
|
+
};
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
for (const [delim, style] of [
|
|
72
|
+
["**", "bold"],
|
|
73
|
+
["__", "bold"],
|
|
74
|
+
["*", "italic"],
|
|
75
|
+
["_", "italic"]
|
|
76
|
+
]) {
|
|
77
|
+
if (!text.startsWith(delim, i)) continue;
|
|
78
|
+
const after = i + delim.length;
|
|
79
|
+
if (isSpace(text[after])) return null;
|
|
80
|
+
if (delim.startsWith("_") && isWord(text[i - 1])) return null;
|
|
81
|
+
if (delim === "*" && text[after] === "*") return null;
|
|
82
|
+
const end = closing(text, after - 1, delim);
|
|
83
|
+
if (end < 0 || end === after) return null;
|
|
84
|
+
return {
|
|
85
|
+
span: {
|
|
86
|
+
text: text.slice(after, end),
|
|
87
|
+
style
|
|
88
|
+
},
|
|
89
|
+
end: end + delim.length
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/sparkline.ts
|
|
97
|
+
/** Values scaled onto `glyphs` (lowest first). Equal values draw flat at the lowest glyph. */
|
|
98
|
+
function sparkline(values, glyphs) {
|
|
99
|
+
if (values.length === 0 || glyphs.length === 0) return "";
|
|
100
|
+
const min = Math.min(...values);
|
|
101
|
+
const span = Math.max(...values) - min;
|
|
102
|
+
const top = glyphs.length - 1;
|
|
103
|
+
return values.map((v) => glyphs[span === 0 ? 0 : Math.round((v - min) / span * top)] ?? "").join("");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/spinner.ts
|
|
108
|
+
/** Clockwise: ▘ top-left → ▝ top-right → ▗ bottom-right → ▖ bottom-left. */
|
|
109
|
+
const BOX_CHASE = [
|
|
110
|
+
"▘",
|
|
111
|
+
"▝",
|
|
112
|
+
"▗",
|
|
113
|
+
"▖"
|
|
114
|
+
];
|
|
115
|
+
/** A gap running round a ring of eight braille dots. The default — see the header. */
|
|
116
|
+
const BRAILLE_RING = [
|
|
117
|
+
"⣾",
|
|
118
|
+
"⣽",
|
|
119
|
+
"⣻",
|
|
120
|
+
"⢿",
|
|
121
|
+
"⡿",
|
|
122
|
+
"⣟",
|
|
123
|
+
"⣯",
|
|
124
|
+
"⣷"
|
|
125
|
+
];
|
|
126
|
+
const SPINNER = BRAILLE_RING;
|
|
127
|
+
function spinnerFrame(frame, frames = SPINNER) {
|
|
128
|
+
if (frames.length === 0) return "";
|
|
129
|
+
return frames[(Math.floor(frame) % frames.length + frames.length) % frames.length];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
export { sparkline as a, barFrame as c, spinnerFrame as i, BRAILLE_RING as n, markdownSpans as o, SPINNER as r, BAR_GLYPH as s, BOX_CHASE as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Clockwise: ▘ top-left → ▝ top-right → ▗ bottom-right → ▖ bottom-left. */
|
|
2
|
+
export declare const BOX_CHASE: readonly ['▘', '▝', '▗', '▖'];
|
|
3
|
+
/** A gap running round a ring of eight braille dots. The default — see the header. */
|
|
4
|
+
export declare const BRAILLE_RING: readonly ['⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷'];
|
|
5
|
+
export declare const SPINNER: readonly string[];
|
|
6
|
+
export declare function spinnerFrame(frame: number, frames?: readonly string[]): string;
|
|
7
|
+
//# sourceMappingURL=spinner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spinner.d.ts","sourceRoot":"","sources":["../src/spinner.ts"],"names":[],"mappings":"AAOA,4EAA4E;AAC5E,eAAO,MAAM,SAAS,YAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAEvD,sFAAsF;AACtF,eAAO,MAAM,YAAY,YAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAE9E,eAAO,MAAM,OAAO,EAAE,SAAS,MAAM,EAAiB,CAAC;AAEvD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,SAAS,MAAM,EAAY,GAAG,MAAM,CAIvF"}
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { BAR_GLYPH, barFrame } from './bar.js';
|
|
2
|
+
export { type MarkdownSpan, type MarkdownStyle, markdownSpans } from './markdown.js';
|
|
3
|
+
export { sparkline } from './sparkline.js';
|
|
4
|
+
export { BOX_CHASE, BRAILLE_RING, SPINNER, spinnerFrame } from './spinner.js';
|
|
5
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/text.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as sparkline, c as barFrame, i as spinnerFrame, n as BRAILLE_RING, o as markdownSpans, r as SPINNER, s as BAR_GLYPH, t as BOX_CHASE } from "./spinner-DIFSSHah.js";
|
|
2
|
+
|
|
3
|
+
export { BAR_GLYPH, BOX_CHASE, BRAILLE_RING, SPINNER, barFrame, markdownSpans, sparkline, spinnerFrame };
|
package/package.json
CHANGED
|
@@ -1,7 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mnmal-ai/surface-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.14.6",
|
|
4
|
+
"description": "Stateless Ink view primitives for surface terminal UIs: panels, cells, markdown spans, spinners, sparklines.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"
|
|
7
|
-
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/mnmal-ai/surface.git",
|
|
9
|
+
"directory": "packages/surface-kit"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./cells": {
|
|
18
|
+
"types": "./dist/cells.d.ts",
|
|
19
|
+
"import": "./dist/cells.js"
|
|
20
|
+
},
|
|
21
|
+
"./text": {
|
|
22
|
+
"types": "./dist/text.d.ts",
|
|
23
|
+
"import": "./dist/text.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@mnmal-ai/surface-theme": "0.14.6",
|
|
31
|
+
"string-width": "^8.1.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"ink": "^7.1.1",
|
|
35
|
+
"react": "^19.3.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@mnmal-ai/substrate-config": "1.0.0-alpha.0",
|
|
39
|
+
"@types/node": "^26.6.4",
|
|
40
|
+
"@types/react": "^19.2.0",
|
|
41
|
+
"ink": "^7.1.1",
|
|
42
|
+
"ink-testing-library": "^4.0.0",
|
|
43
|
+
"react": "^19.3.0",
|
|
44
|
+
"tsdown": "^0.23.0",
|
|
45
|
+
"typescript": "^7.0.2",
|
|
46
|
+
"vitest": "^5.0.3"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=26.2.0"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"registry": "https://registry.npmjs.org/",
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsdown && tsc -p tsconfig.dts.json",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"check-types": "tsc -p tsconfig.json --noEmit",
|
|
59
|
+
"lint": "biome check ."
|
|
60
|
+
}
|
|
61
|
+
}
|