zion 2.3.0 → 2.5.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.
- package/README.md +11 -0
- package/dist/app-YZDBB2BN.js +671 -0
- package/dist/cli.js +2264 -661
- package/dist/render-3OJW5JZI.js +52 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,3 +3,14 @@
|
|
|
3
3
|
mirror of zzzzion.com in your terminal
|
|
4
4
|
|
|
5
5
|
run `npx zion`
|
|
6
|
+
|
|
7
|
+
#### commands
|
|
8
|
+
|
|
9
|
+
| command | what it does |
|
|
10
|
+
| ------------------- | -------------------------------------------------------------- |
|
|
11
|
+
| `npx zion` | open the terminal version of zzzzion.com |
|
|
12
|
+
| `npx zion dotfiles` | set up [zion's dotfiles](https://github.com/zion-off/dotfiles) |
|
|
13
|
+
| `npx zion skills` | install zion's agent skills |
|
|
14
|
+
| `npx zion help` | list commands; `npx zion help <command>` for more |
|
|
15
|
+
|
|
16
|
+
Global flags: `--no-color` (or `NO_COLOR`), `--no-input` (never prompt), `-h/--help`, `-v/--version`.
|
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/app.tsx
|
|
4
|
+
import { useEffect as useEffect4, useRef as useRef2, useState as useState3 } from "react";
|
|
5
|
+
import { Box as Box7, Text as Text11, useApp, useInput as useInput2, useStdout as useStdout2 } from "ink";
|
|
6
|
+
|
|
7
|
+
// src/components/BlogDetailView.tsx
|
|
8
|
+
import { useEffect } from "react";
|
|
9
|
+
import { Box as Box2, Text as Text3, useStdout } from "ink";
|
|
10
|
+
import { ScrollView } from "ink-scroll-view";
|
|
11
|
+
|
|
12
|
+
// src/components/HintBar.tsx
|
|
13
|
+
import { Text } from "ink";
|
|
14
|
+
|
|
15
|
+
// src/lib/config.ts
|
|
16
|
+
var DOT_CHAR = " \u2022 ";
|
|
17
|
+
var BASE_URL = process.env.BASE_URL || "https://zzzzion.com";
|
|
18
|
+
var NAV_LINKS = [
|
|
19
|
+
{ name: "home", path: "/", color: "#264b96" },
|
|
20
|
+
{ name: "blog", path: "/blog", color: "#006f3c" },
|
|
21
|
+
{ name: "portfolio", path: "/portfolio", color: "#f9a73e" },
|
|
22
|
+
{ name: "art", path: "/art", color: "#bf212f" }
|
|
23
|
+
];
|
|
24
|
+
var COLORS = {
|
|
25
|
+
subtle: "gray",
|
|
26
|
+
text: "white",
|
|
27
|
+
selectedBlog: "#006f3c",
|
|
28
|
+
link: "#5c9fd4"
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/components/HintBar.tsx
|
|
32
|
+
import { jsx } from "react/jsx-runtime";
|
|
33
|
+
function HintBar({ text }) {
|
|
34
|
+
return /* @__PURE__ */ jsx(Text, { color: COLORS.subtle, children: text });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/components/ui/Markdown.tsx
|
|
38
|
+
import Table from "cli-table3";
|
|
39
|
+
import { marked } from "marked";
|
|
40
|
+
import { Box, Text as Text2 } from "ink";
|
|
41
|
+
import terminalLink from "terminal-link";
|
|
42
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
43
|
+
function Markdown({ children, width }) {
|
|
44
|
+
const tokens = marked.lexer(children);
|
|
45
|
+
return /* @__PURE__ */ jsx2(Box, { flexDirection: "column", width, children: tokens.map((token, idx) => /* @__PURE__ */ jsx2(TokenRenderer, { token, width }, idx)) });
|
|
46
|
+
}
|
|
47
|
+
function TokenRenderer({ token, width }) {
|
|
48
|
+
switch (token.type) {
|
|
49
|
+
case "heading":
|
|
50
|
+
return /* @__PURE__ */ jsx2(Box, { marginTop: token.depth === 1 ? 0 : 1, children: /* @__PURE__ */ jsx2(Text2, { bold: true, underline: token.depth === 1, children: renderInline(token.tokens) }) });
|
|
51
|
+
case "paragraph":
|
|
52
|
+
return /* @__PURE__ */ jsx2(Text2, { wrap: "wrap", children: renderInline(token.tokens) });
|
|
53
|
+
case "code": {
|
|
54
|
+
const innerWidth = width ? width - 4 : 76;
|
|
55
|
+
const horizontalBar = "\u2500".repeat(innerWidth + 2);
|
|
56
|
+
const lines = token.text.split("\n").map((line) => {
|
|
57
|
+
const truncated = line.length > innerWidth ? line.slice(0, innerWidth) : line;
|
|
58
|
+
return `\u2502 ${truncated.padEnd(innerWidth)} \u2502`;
|
|
59
|
+
});
|
|
60
|
+
const block = [`\u250C${horizontalBar}\u2510`, ...lines, `\u2514${horizontalBar}\u2518`].join("\n");
|
|
61
|
+
return /* @__PURE__ */ jsx2(Box, { marginY: 1, children: /* @__PURE__ */ jsx2(Text2, { dimColor: true, children: block }) });
|
|
62
|
+
}
|
|
63
|
+
case "blockquote":
|
|
64
|
+
return /* @__PURE__ */ jsxs(Box, { marginLeft: 2, children: [
|
|
65
|
+
/* @__PURE__ */ jsx2(Text2, { color: "gray", children: "\u2502 " }),
|
|
66
|
+
/* @__PURE__ */ jsx2(Box, { flexDirection: "column", children: token.tokens?.map((t, idx) => /* @__PURE__ */ jsx2(TokenRenderer, { token: t, width: width ? width - 4 : void 0 }, idx)) })
|
|
67
|
+
] });
|
|
68
|
+
case "list":
|
|
69
|
+
return /* @__PURE__ */ jsx2(Box, { flexDirection: "column", marginY: 1, children: token.items.map((item, idx) => /* @__PURE__ */ jsxs(Box, { children: [
|
|
70
|
+
/* @__PURE__ */ jsx2(Text2, { children: token.ordered ? `${idx + 1}. ` : "\u2022 " }),
|
|
71
|
+
/* @__PURE__ */ jsx2(Box, { flexDirection: "column", children: item.tokens.map((t, i) => /* @__PURE__ */ jsx2(TokenRenderer, { token: t, width: width ? width - 2 : void 0 }, i)) })
|
|
72
|
+
] }, idx)) });
|
|
73
|
+
case "table":
|
|
74
|
+
return /* @__PURE__ */ jsx2(TableRenderer, { token });
|
|
75
|
+
case "hr":
|
|
76
|
+
return /* @__PURE__ */ jsx2(Text2, { dimColor: true, children: "\u2500".repeat(40) });
|
|
77
|
+
case "space":
|
|
78
|
+
return null;
|
|
79
|
+
default:
|
|
80
|
+
if ("text" in token && typeof token.text === "string") {
|
|
81
|
+
return /* @__PURE__ */ jsx2(Text2, { children: token.text });
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function TableRenderer({ token }) {
|
|
87
|
+
const table = new Table({
|
|
88
|
+
head: token.header.map((cell) => renderInlineToString(cell.tokens)),
|
|
89
|
+
style: { head: ["cyan"], border: ["gray"] }
|
|
90
|
+
});
|
|
91
|
+
for (const row of token.rows) {
|
|
92
|
+
table.push(row.map((cell) => renderInlineToString(cell.tokens)));
|
|
93
|
+
}
|
|
94
|
+
return /* @__PURE__ */ jsx2(Text2, { children: table.toString() });
|
|
95
|
+
}
|
|
96
|
+
function renderInline(tokens) {
|
|
97
|
+
if (!tokens) return null;
|
|
98
|
+
return tokens.map((token, idx) => {
|
|
99
|
+
switch (token.type) {
|
|
100
|
+
case "text":
|
|
101
|
+
return /* @__PURE__ */ jsx2(Text2, { children: token.text }, idx);
|
|
102
|
+
case "strong":
|
|
103
|
+
return /* @__PURE__ */ jsx2(Text2, { bold: true, children: renderInline(token.tokens) }, idx);
|
|
104
|
+
case "em":
|
|
105
|
+
return /* @__PURE__ */ jsx2(Text2, { italic: true, children: renderInline(token.tokens) }, idx);
|
|
106
|
+
case "codespan":
|
|
107
|
+
return /* @__PURE__ */ jsxs(Text2, { color: "yellow", children: [
|
|
108
|
+
"`",
|
|
109
|
+
token.text,
|
|
110
|
+
"`"
|
|
111
|
+
] }, idx);
|
|
112
|
+
case "link": {
|
|
113
|
+
const text = renderInlineToString(token.tokens);
|
|
114
|
+
return /* @__PURE__ */ jsx2(Text2, { color: "blue", children: terminalLink(text, token.href) }, idx);
|
|
115
|
+
}
|
|
116
|
+
case "image":
|
|
117
|
+
return /* @__PURE__ */ jsxs(Text2, { color: "blue", children: [
|
|
118
|
+
"[Image: ",
|
|
119
|
+
token.text || token.href,
|
|
120
|
+
"]"
|
|
121
|
+
] }, idx);
|
|
122
|
+
case "br":
|
|
123
|
+
return /* @__PURE__ */ jsx2(Text2, { children: "\n" }, idx);
|
|
124
|
+
case "del":
|
|
125
|
+
return /* @__PURE__ */ jsx2(Text2, { strikethrough: true, children: renderInline(token.tokens) }, idx);
|
|
126
|
+
default:
|
|
127
|
+
if ("text" in token && typeof token.text === "string") {
|
|
128
|
+
return /* @__PURE__ */ jsx2(Text2, { children: token.text }, idx);
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function renderInlineToString(tokens) {
|
|
135
|
+
if (!tokens) return "";
|
|
136
|
+
return tokens.map((token) => {
|
|
137
|
+
if ("text" in token && typeof token.text === "string") {
|
|
138
|
+
return token.text;
|
|
139
|
+
}
|
|
140
|
+
if ("tokens" in token && Array.isArray(token.tokens)) {
|
|
141
|
+
return renderInlineToString(token.tokens);
|
|
142
|
+
}
|
|
143
|
+
return "";
|
|
144
|
+
}).join("");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/components/BlogDetailView.tsx
|
|
148
|
+
import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
149
|
+
function BlogDetailView({ post, scrollRef, viewportHeight, contentWidth }) {
|
|
150
|
+
const { stdout } = useStdout();
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
const handleResize = () => scrollRef.current?.remeasure();
|
|
153
|
+
stdout?.on("resize", handleResize);
|
|
154
|
+
return () => {
|
|
155
|
+
stdout?.off("resize", handleResize);
|
|
156
|
+
};
|
|
157
|
+
}, [stdout, scrollRef]);
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
scrollRef.current?.scrollToTop();
|
|
160
|
+
}, [post.slug, scrollRef]);
|
|
161
|
+
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
162
|
+
/* @__PURE__ */ jsx3(Box2, { marginTop: 1, children: /* @__PURE__ */ jsx3(Text3, { bold: true, color: "white", children: post.title }) }),
|
|
163
|
+
/* @__PURE__ */ jsx3(Box2, { marginTop: 1, height: viewportHeight, flexDirection: "column", children: /* @__PURE__ */ jsx3(ScrollView, { ref: scrollRef, children: /* @__PURE__ */ jsx3(Markdown, { width: contentWidth, children: post.content }) }) }),
|
|
164
|
+
/* @__PURE__ */ jsx3(Box2, { marginTop: 1, children: /* @__PURE__ */ jsx3(HintBar, { text: "Hint: h: back | j/k: down, up | q: quit" }) })
|
|
165
|
+
] });
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/components/BlogListView.tsx
|
|
169
|
+
import { Box as Box3, Text as Text4 } from "ink";
|
|
170
|
+
import { ScrollView as ScrollView2 } from "ink-scroll-view";
|
|
171
|
+
|
|
172
|
+
// src/lib/content.ts
|
|
173
|
+
async function fetchJson(url) {
|
|
174
|
+
try {
|
|
175
|
+
const res = await fetch(url);
|
|
176
|
+
if (!res.ok) return { ok: false, error: `${res.status} ${res.statusText} (${url})` };
|
|
177
|
+
return { ok: true, data: await res.json() };
|
|
178
|
+
} catch (err) {
|
|
179
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function loadAboutContent() {
|
|
183
|
+
return fetchJson(`${BASE_URL}/api/about`);
|
|
184
|
+
}
|
|
185
|
+
function loadBlogPostList() {
|
|
186
|
+
return fetchJson(`${BASE_URL}/api/posts`);
|
|
187
|
+
}
|
|
188
|
+
function loadBlogPost(slug) {
|
|
189
|
+
return fetchJson(`${BASE_URL}/api/posts/${slug}`);
|
|
190
|
+
}
|
|
191
|
+
function loadPortfolioList() {
|
|
192
|
+
return fetchJson(`${BASE_URL}/api/portfolio`);
|
|
193
|
+
}
|
|
194
|
+
function formatDate(dateStr) {
|
|
195
|
+
const date = /* @__PURE__ */ new Date(dateStr + "T00:00:00");
|
|
196
|
+
return date.toLocaleDateString("en-US", {
|
|
197
|
+
year: "numeric",
|
|
198
|
+
month: "long",
|
|
199
|
+
day: "numeric"
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/components/BlogListView.tsx
|
|
204
|
+
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
205
|
+
function BlogListView({ posts, highlightedIndex, scrollRef, viewportHeight }) {
|
|
206
|
+
return /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
207
|
+
/* @__PURE__ */ jsx4(Box3, { marginTop: 1, height: viewportHeight, flexDirection: "column", children: /* @__PURE__ */ jsx4(ScrollView2, { ref: scrollRef, children: posts.map((post, idx) => {
|
|
208
|
+
const isSelected = idx === highlightedIndex;
|
|
209
|
+
const prefix = isSelected ? "\u203A " : " ";
|
|
210
|
+
const dateStr = formatDate(post.publishedAt);
|
|
211
|
+
return /* @__PURE__ */ jsxs3(Box3, { flexDirection: "row", children: [
|
|
212
|
+
/* @__PURE__ */ jsx4(Text4, { bold: isSelected, color: isSelected ? COLORS.selectedBlog : void 0, children: prefix }),
|
|
213
|
+
/* @__PURE__ */ jsx4(Box3, { width: 20, children: /* @__PURE__ */ jsx4(Text4, { color: COLORS.subtle, children: dateStr }) }),
|
|
214
|
+
/* @__PURE__ */ jsx4(Text4, { bold: isSelected, color: isSelected ? COLORS.selectedBlog : COLORS.text, children: post.title })
|
|
215
|
+
] }, post.slug);
|
|
216
|
+
}) }) }),
|
|
217
|
+
/* @__PURE__ */ jsx4(Box3, { marginTop: 1, children: /* @__PURE__ */ jsx4(HintBar, { text: "Hint: h/l: home, portfolio | j/k: down, up | enter: open | q: quit" }) })
|
|
218
|
+
] });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/components/HomeView.tsx
|
|
222
|
+
import { Box as Box4, Text as Text5 } from "ink";
|
|
223
|
+
import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
224
|
+
function HomeView({ aboutTitle, aboutContent, contentWidth }) {
|
|
225
|
+
return /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
226
|
+
/* @__PURE__ */ jsx5(Box4, { marginTop: 1, children: /* @__PURE__ */ jsx5(Text5, { bold: true, color: "white", children: aboutTitle }) }),
|
|
227
|
+
/* @__PURE__ */ jsx5(Box4, { marginTop: 1, children: /* @__PURE__ */ jsx5(Markdown, { width: contentWidth, children: aboutContent }) }),
|
|
228
|
+
/* @__PURE__ */ jsx5(Box4, { marginTop: 1, children: /* @__PURE__ */ jsx5(HintBar, { text: "Hint: l: blog | q, ctrl+c: quit" }) })
|
|
229
|
+
] });
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/components/NavBar.tsx
|
|
233
|
+
import { Box as Box5, Text as Text6 } from "ink";
|
|
234
|
+
import terminalLink2 from "terminal-link";
|
|
235
|
+
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
236
|
+
function NavBar() {
|
|
237
|
+
return /* @__PURE__ */ jsx6(Box5, { flexDirection: "row", children: NAV_LINKS.map((link, idx) => /* @__PURE__ */ jsxs5(Box5, { flexDirection: "row", children: [
|
|
238
|
+
idx > 0 && /* @__PURE__ */ jsx6(Text6, { color: COLORS.subtle, children: DOT_CHAR }),
|
|
239
|
+
/* @__PURE__ */ jsx6(Box5, { marginRight: 2, children: link.name === "home" || link.name === "blog" ? /* @__PURE__ */ jsx6(Text6, { color: link.color, children: link.name }) : /* @__PURE__ */ jsx6(Text6, { color: link.color, children: terminalLink2(link.name, `${BASE_URL}${link.path}`, { fallback: () => link.name }) }) })
|
|
240
|
+
] }, link.name)) });
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/components/PortfolioListView.tsx
|
|
244
|
+
import { Box as Box6, Text as Text9 } from "ink";
|
|
245
|
+
import { ScrollView as ScrollView3 } from "ink-scroll-view";
|
|
246
|
+
|
|
247
|
+
// src/components/ui/Badge.tsx
|
|
248
|
+
import { Text as Text7 } from "ink";
|
|
249
|
+
import { Fragment as Fragment4, jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
250
|
+
function Badge({ color, background, children }) {
|
|
251
|
+
return /* @__PURE__ */ jsxs6(Fragment4, { children: [
|
|
252
|
+
/* @__PURE__ */ jsx7(Text7, { color: background, children: "\uE0B6" }),
|
|
253
|
+
/* @__PURE__ */ jsx7(Text7, { color, backgroundColor: background, bold: true, children }),
|
|
254
|
+
/* @__PURE__ */ jsx7(Text7, { color: background, children: "\uE0B4" })
|
|
255
|
+
] });
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// src/components/ui/Stars.tsx
|
|
259
|
+
import { Text as Text8 } from "ink";
|
|
260
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
261
|
+
var formatter = new Intl.NumberFormat("en", { notation: "compact", maximumFractionDigits: 1 });
|
|
262
|
+
function Stars({ count }) {
|
|
263
|
+
return /* @__PURE__ */ jsx8(Text8, { color: COLORS.subtle, children: `\u2605 ${formatter.format(count).toLowerCase()}` });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// src/components/PortfolioListView.tsx
|
|
267
|
+
import { Fragment as Fragment5, jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
268
|
+
function PortfolioListView({ projects, highlightedIndex, scrollRef, viewportHeight }) {
|
|
269
|
+
return /* @__PURE__ */ jsxs7(Fragment5, { children: [
|
|
270
|
+
/* @__PURE__ */ jsx9(Box6, { marginTop: 1, height: viewportHeight, flexDirection: "column", children: /* @__PURE__ */ jsx9(ScrollView3, { ref: scrollRef, children: projects.map((project, idx) => {
|
|
271
|
+
const isSelected = idx === highlightedIndex;
|
|
272
|
+
const prefix = isSelected ? "\u203A " : " ";
|
|
273
|
+
return /* @__PURE__ */ jsxs7(Box6, { flexDirection: "column", marginBottom: 2, children: [
|
|
274
|
+
/* @__PURE__ */ jsxs7(Box6, { flexDirection: "row", children: [
|
|
275
|
+
/* @__PURE__ */ jsx9(Text9, { bold: isSelected, color: isSelected ? COLORS.selectedBlog : void 0, children: prefix }),
|
|
276
|
+
/* @__PURE__ */ jsx9(Text9, { bold: isSelected, color: isSelected ? COLORS.selectedBlog : COLORS.text, children: project.title }),
|
|
277
|
+
project.stars !== void 0 && /* @__PURE__ */ jsx9(Box6, { marginLeft: 2, children: /* @__PURE__ */ jsx9(Stars, { count: project.stars }) })
|
|
278
|
+
] }),
|
|
279
|
+
/* @__PURE__ */ jsx9(Box6, { marginLeft: 3, paddingBottom: 1, children: /* @__PURE__ */ jsxs7(Text9, { color: COLORS.subtle, children: [
|
|
280
|
+
project.description,
|
|
281
|
+
" "
|
|
282
|
+
] }) }),
|
|
283
|
+
project.links && project.links.length > 0 && /* @__PURE__ */ jsx9(Box6, { marginLeft: 3, flexDirection: "column", paddingBottom: 1, children: project.links.map((link, linkIdx) => /* @__PURE__ */ jsx9(Text9, { color: COLORS.link, children: link.url }, linkIdx)) }),
|
|
284
|
+
project.tools && project.tools.length > 0 && /* @__PURE__ */ jsx9(Box6, { marginLeft: 3, flexDirection: "row", gap: 1, paddingBottom: 1, children: project.tools.map((tool, toolIdx) => /* @__PURE__ */ jsx9(Box6, { children: /* @__PURE__ */ jsx9(Badge, { color: "white", background: "gray", children: tool }) }, toolIdx)) })
|
|
285
|
+
] }, idx);
|
|
286
|
+
}) }) }),
|
|
287
|
+
/* @__PURE__ */ jsx9(Box6, { marginTop: 1, children: /* @__PURE__ */ jsx9(HintBar, { text: "Hint: h: blog | j/k: down, up | q: quit" }) })
|
|
288
|
+
] });
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// src/components/ui/AnimatedText.tsx
|
|
292
|
+
import chalk from "chalk";
|
|
293
|
+
import { useEffect as useEffect2, useState } from "react";
|
|
294
|
+
import { Text as Text10 } from "ink";
|
|
295
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
296
|
+
function hexToRgb(hex) {
|
|
297
|
+
const h = hex.replace("#", "");
|
|
298
|
+
const n = h.length === 3 ? parseInt(h[0] + h[0] + h[1] + h[1] + h[2] + h[2], 16) : parseInt(h, 16);
|
|
299
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255];
|
|
300
|
+
}
|
|
301
|
+
var DELAYS = {
|
|
302
|
+
pulse: 16,
|
|
303
|
+
neon: 500,
|
|
304
|
+
radar: 50,
|
|
305
|
+
karaoke: 50,
|
|
306
|
+
rainbow: 15,
|
|
307
|
+
glitch: 55
|
|
308
|
+
};
|
|
309
|
+
var GLITCH_CHARS = "\u2593\u2592\u2591\u2588\u2580\u2584\u258C\u2590\u2500\u2502\u2524\u2510\u2514\u2518\u251C\u252C\u2534\u253C";
|
|
310
|
+
var TOTAL_PULSE_FRAMES = 120;
|
|
311
|
+
function lerp(a, b, t) {
|
|
312
|
+
return Math.round(a + (b - a) * t);
|
|
313
|
+
}
|
|
314
|
+
function applyPulse(text, frame, config) {
|
|
315
|
+
const [br, bg, bb] = hexToRgb(config?.baseColor ?? "#E6E6E6");
|
|
316
|
+
const [pr, pg, pb] = hexToRgb(config?.pulseColor ?? "#FF1010");
|
|
317
|
+
const t = (Math.sin(frame / TOTAL_PULSE_FRAMES * Math.PI * 2) + 1) / 2;
|
|
318
|
+
const r = lerp(br, pr, t);
|
|
319
|
+
const g = lerp(bg, pg, t);
|
|
320
|
+
const b = lerp(bb, pb, t);
|
|
321
|
+
return chalk.rgb(r, g, b)(text);
|
|
322
|
+
}
|
|
323
|
+
function applyNeon(text, frame, config) {
|
|
324
|
+
const on = frame % 2 === 0;
|
|
325
|
+
const onColor = config?.onColor ?? "#00FFFF";
|
|
326
|
+
const offColor = config?.offColor ?? "#325050";
|
|
327
|
+
return on ? chalk.hex(onColor)(text) : chalk.hex(offColor)(text);
|
|
328
|
+
}
|
|
329
|
+
function applyRadar(text, frame, config) {
|
|
330
|
+
const [br, bg, bb] = hexToRgb(config?.baseColor ?? "#3C3C3C");
|
|
331
|
+
const depth = Math.max(1, Math.floor(text.length * 0.2));
|
|
332
|
+
const globalPos = frame % (text.length + depth);
|
|
333
|
+
const chars = [];
|
|
334
|
+
for (let i = 0; i < text.length; i++) {
|
|
335
|
+
const pos = -(i - globalPos);
|
|
336
|
+
if (pos >= 0 && pos < depth) {
|
|
337
|
+
const t = (depth - pos) / depth;
|
|
338
|
+
chars.push(chalk.rgb(lerp(br, 255, t), lerp(bg, 255, t), lerp(bb, 255, t))(text[i]));
|
|
339
|
+
} else {
|
|
340
|
+
chars.push(chalk.rgb(br, bg, bb)(text[i]));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return chars.join("");
|
|
344
|
+
}
|
|
345
|
+
function applyKaraoke(text, frame, config) {
|
|
346
|
+
const highlightColor = config?.highlightColor ?? "#FFBB00";
|
|
347
|
+
const baseColor = config?.baseColor ?? "#FFFFFF";
|
|
348
|
+
const pos = frame % (text.length + 20) - 10;
|
|
349
|
+
if (pos < 0) {
|
|
350
|
+
return chalk.hex(baseColor)(text);
|
|
351
|
+
}
|
|
352
|
+
return chalk.hex(highlightColor).bold(text.substring(0, pos)) + chalk.hex(baseColor)(text.substring(pos));
|
|
353
|
+
}
|
|
354
|
+
function hsvToRgb(h, s, v) {
|
|
355
|
+
const i = Math.floor(h / 60) % 6;
|
|
356
|
+
const f = h / 60 - Math.floor(h / 60);
|
|
357
|
+
const p = v * (1 - s);
|
|
358
|
+
const q = v * (1 - f * s);
|
|
359
|
+
const t = v * (1 - (1 - f) * s);
|
|
360
|
+
const map = [
|
|
361
|
+
[v, t, p],
|
|
362
|
+
[q, v, p],
|
|
363
|
+
[p, v, t],
|
|
364
|
+
[p, q, v],
|
|
365
|
+
[t, p, v],
|
|
366
|
+
[v, p, q]
|
|
367
|
+
];
|
|
368
|
+
return map[i].map((c) => Math.round(c * 255));
|
|
369
|
+
}
|
|
370
|
+
function applyRainbow(text, frame, config) {
|
|
371
|
+
const sat = config?.saturation ?? 1;
|
|
372
|
+
const bri = config?.brightness ?? 1;
|
|
373
|
+
const hueStart = 5 * frame % 360;
|
|
374
|
+
const chars = [];
|
|
375
|
+
for (let i = 0; i < text.length; i++) {
|
|
376
|
+
const hue = (hueStart + i * 360 / Math.max(text.length, 1)) % 360;
|
|
377
|
+
const [r, g, b] = hsvToRgb(hue, sat, bri);
|
|
378
|
+
chars.push(chalk.rgb(r, g, b)(text[i]));
|
|
379
|
+
}
|
|
380
|
+
return chars.join("");
|
|
381
|
+
}
|
|
382
|
+
function applyGlitch(text, frame) {
|
|
383
|
+
if (frame % 2 + frame % 3 + frame % 11 + frame % 29 + frame % 37 > 52) {
|
|
384
|
+
return text.replace(/[^\r\n]/g, " ");
|
|
385
|
+
}
|
|
386
|
+
const chunkSize = Math.max(3, Math.round(text.length * 0.02));
|
|
387
|
+
const chars = [];
|
|
388
|
+
for (let i = 0; i < text.length; i++) {
|
|
389
|
+
const skip = Math.round(Math.max(0, (Math.random() - 0.8) * chunkSize));
|
|
390
|
+
chars.push(text.substring(i, i + skip).replace(/[^\r\n]/g, " "));
|
|
391
|
+
i += skip;
|
|
392
|
+
if (text[i]) {
|
|
393
|
+
if (text[i] !== "\n" && text[i] !== "\r" && Math.random() > 0.995) {
|
|
394
|
+
chars.push(GLITCH_CHARS[Math.floor(Math.random() * GLITCH_CHARS.length)]);
|
|
395
|
+
} else if (Math.random() > 5e-3) {
|
|
396
|
+
chars.push(text[i]);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return chars.join("");
|
|
401
|
+
}
|
|
402
|
+
function applyAnimation(text, name, frame, config) {
|
|
403
|
+
switch (name) {
|
|
404
|
+
case "pulse":
|
|
405
|
+
return applyPulse(text, frame, config);
|
|
406
|
+
case "neon":
|
|
407
|
+
return applyNeon(text, frame, config);
|
|
408
|
+
case "radar":
|
|
409
|
+
return applyRadar(text, frame, config);
|
|
410
|
+
case "karaoke":
|
|
411
|
+
return applyKaraoke(text, frame, config);
|
|
412
|
+
case "rainbow":
|
|
413
|
+
return applyRainbow(text, frame, config);
|
|
414
|
+
case "glitch":
|
|
415
|
+
return applyGlitch(text, frame);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function flattenChildren(children) {
|
|
419
|
+
if (typeof children === "string") return children;
|
|
420
|
+
if (typeof children === "number") return String(children);
|
|
421
|
+
if (children == null || typeof children === "boolean") return "";
|
|
422
|
+
if (Array.isArray(children)) return children.map(flattenChildren).join("");
|
|
423
|
+
return "";
|
|
424
|
+
}
|
|
425
|
+
function AnimatedText({
|
|
426
|
+
name = "pulse",
|
|
427
|
+
speed = 1,
|
|
428
|
+
bold,
|
|
429
|
+
italic,
|
|
430
|
+
underline,
|
|
431
|
+
strikethrough,
|
|
432
|
+
dimColor,
|
|
433
|
+
config,
|
|
434
|
+
children
|
|
435
|
+
}) {
|
|
436
|
+
const [frame, setFrame] = useState(0);
|
|
437
|
+
const text = flattenChildren(children);
|
|
438
|
+
useEffect2(() => {
|
|
439
|
+
const delay = DELAYS[name] / speed;
|
|
440
|
+
const interval = setInterval(() => {
|
|
441
|
+
setFrame((f) => f + 1);
|
|
442
|
+
}, delay);
|
|
443
|
+
return () => clearInterval(interval);
|
|
444
|
+
}, [name, speed]);
|
|
445
|
+
let animated = applyAnimation(text, name, frame, config);
|
|
446
|
+
if (bold) animated = chalk.bold(animated);
|
|
447
|
+
if (italic) animated = chalk.italic(animated);
|
|
448
|
+
if (underline) animated = chalk.underline(animated);
|
|
449
|
+
if (strikethrough) animated = chalk.strikethrough(animated);
|
|
450
|
+
if (dimColor) animated = chalk.dim(animated);
|
|
451
|
+
return /* @__PURE__ */ jsx10(Text10, { children: animated });
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// src/hooks/useListNavigation.ts
|
|
455
|
+
import { useState as useState2 } from "react";
|
|
456
|
+
import { useInput } from "ink";
|
|
457
|
+
|
|
458
|
+
// src/hooks/useScrollToIndex.ts
|
|
459
|
+
import { useEffect as useEffect3, useRef } from "react";
|
|
460
|
+
function useScrollToIndex(index) {
|
|
461
|
+
const scrollRef = useRef(null);
|
|
462
|
+
useEffect3(() => {
|
|
463
|
+
const ref = scrollRef.current;
|
|
464
|
+
if (!ref) return;
|
|
465
|
+
const pos = ref.getItemPosition(index);
|
|
466
|
+
const viewportHeight = ref.getViewportHeight();
|
|
467
|
+
const scrollOffset = ref.getScrollOffset();
|
|
468
|
+
if (!pos) return;
|
|
469
|
+
if (pos.top < scrollOffset) {
|
|
470
|
+
ref.scrollTo(pos.top);
|
|
471
|
+
} else if (pos.top + pos.height > scrollOffset + viewportHeight) {
|
|
472
|
+
ref.scrollTo(pos.top + pos.height - viewportHeight);
|
|
473
|
+
}
|
|
474
|
+
}, [index]);
|
|
475
|
+
return scrollRef;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// src/hooks/useListNavigation.ts
|
|
479
|
+
function useListNavigation({ length, onSelect, isActive }) {
|
|
480
|
+
const [highlightedIndex, setHighlightedIndex] = useState2(0);
|
|
481
|
+
const scrollRef = useScrollToIndex(highlightedIndex);
|
|
482
|
+
useInput(
|
|
483
|
+
(input, key) => {
|
|
484
|
+
if (length === 0) return;
|
|
485
|
+
if (key.upArrow || input === "k") {
|
|
486
|
+
setHighlightedIndex((i) => Math.max(0, i - 1));
|
|
487
|
+
}
|
|
488
|
+
if (key.downArrow || input === "j") {
|
|
489
|
+
setHighlightedIndex((i) => Math.min(length - 1, i + 1));
|
|
490
|
+
}
|
|
491
|
+
if (key.return && onSelect) {
|
|
492
|
+
onSelect(highlightedIndex);
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
{ isActive: isActive === true }
|
|
496
|
+
);
|
|
497
|
+
return {
|
|
498
|
+
highlightedIndex,
|
|
499
|
+
scrollRef,
|
|
500
|
+
reset: () => setHighlightedIndex(0)
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// src/app.tsx
|
|
505
|
+
import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
506
|
+
function App() {
|
|
507
|
+
const { exit } = useApp();
|
|
508
|
+
const { stdout } = useStdout2();
|
|
509
|
+
const columns = stdout?.columns ?? 80;
|
|
510
|
+
const rows = stdout?.rows ?? 24;
|
|
511
|
+
const [currentView, setCurrentView] = useState3("home");
|
|
512
|
+
const [errors, setErrors] = useState3({});
|
|
513
|
+
const [aboutTitle, setAboutTitle] = useState3("");
|
|
514
|
+
const [aboutContent, setAboutContent] = useState3("");
|
|
515
|
+
const [blogPosts, setBlogPosts] = useState3([]);
|
|
516
|
+
const [currentPost, setCurrentPost] = useState3(null);
|
|
517
|
+
const [portfolioProjects, setPortfolioProjects] = useState3([]);
|
|
518
|
+
const [loading, setLoading] = useState3("about");
|
|
519
|
+
const detailScrollRef = useRef2(null);
|
|
520
|
+
const addError = (key, message) => setErrors((prev) => ({ ...prev, [key]: message }));
|
|
521
|
+
const clearError = (key) => setErrors((prev) => {
|
|
522
|
+
const next = { ...prev };
|
|
523
|
+
delete next[key];
|
|
524
|
+
return next;
|
|
525
|
+
});
|
|
526
|
+
const blogList = useListNavigation({
|
|
527
|
+
length: blogPosts.length,
|
|
528
|
+
isActive: currentView === "blogList",
|
|
529
|
+
onSelect: (index) => {
|
|
530
|
+
const post = blogPosts[index];
|
|
531
|
+
if (!post) return;
|
|
532
|
+
setLoading("post");
|
|
533
|
+
loadBlogPost(post.slug).then((result) => {
|
|
534
|
+
setLoading(null);
|
|
535
|
+
if (result.ok) {
|
|
536
|
+
clearError("post");
|
|
537
|
+
setCurrentPost(result.data);
|
|
538
|
+
setCurrentView("blogDetail");
|
|
539
|
+
} else {
|
|
540
|
+
addError("post", result.error);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
const portfolioList = useListNavigation({
|
|
546
|
+
length: portfolioProjects.length,
|
|
547
|
+
isActive: currentView === "portfolioList"
|
|
548
|
+
});
|
|
549
|
+
useEffect4(() => {
|
|
550
|
+
loadAboutContent().then((result) => {
|
|
551
|
+
setLoading(null);
|
|
552
|
+
if (result.ok) {
|
|
553
|
+
clearError("about");
|
|
554
|
+
setAboutTitle(result.data.title);
|
|
555
|
+
setAboutContent(result.data.content);
|
|
556
|
+
} else {
|
|
557
|
+
addError("about", result.error);
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
}, []);
|
|
561
|
+
const contentWidth = Math.max(Math.min(Math.floor(columns * 2 / 3), 80), 40);
|
|
562
|
+
const blogListVPHeight = Math.min(blogPosts.length, Math.min(Math.floor(rows / 2), 20));
|
|
563
|
+
const blogDetailVPHeight = Math.min(Math.floor(rows / 2), 25);
|
|
564
|
+
const portfolioListVPHeight = Math.min(Math.floor(rows / 2), 20);
|
|
565
|
+
const visibleErrors = [];
|
|
566
|
+
if (currentView === "home" && errors.about) visibleErrors.push(errors.about);
|
|
567
|
+
if (currentView === "blogList") {
|
|
568
|
+
if (errors.posts) visibleErrors.push(errors.posts);
|
|
569
|
+
if (errors.post) visibleErrors.push(errors.post);
|
|
570
|
+
}
|
|
571
|
+
if (currentView === "blogDetail" && errors.post) visibleErrors.push(errors.post);
|
|
572
|
+
if (currentView === "portfolioList" && errors.portfolio) visibleErrors.push(errors.portfolio);
|
|
573
|
+
const openBlogList = () => {
|
|
574
|
+
setCurrentView("blogList");
|
|
575
|
+
blogList.reset();
|
|
576
|
+
if (blogPosts.length === 0) {
|
|
577
|
+
setLoading("posts");
|
|
578
|
+
loadBlogPostList().then((result) => {
|
|
579
|
+
setLoading(null);
|
|
580
|
+
if (result.ok) {
|
|
581
|
+
clearError("posts");
|
|
582
|
+
setBlogPosts(result.data);
|
|
583
|
+
} else {
|
|
584
|
+
addError("posts", result.error);
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
const openPortfolioList = () => {
|
|
590
|
+
setCurrentView("portfolioList");
|
|
591
|
+
portfolioList.reset();
|
|
592
|
+
if (portfolioProjects.length === 0) {
|
|
593
|
+
setLoading("portfolio");
|
|
594
|
+
loadPortfolioList().then((result) => {
|
|
595
|
+
setLoading(null);
|
|
596
|
+
if (result.ok) {
|
|
597
|
+
clearError("portfolio");
|
|
598
|
+
setPortfolioProjects(result.data);
|
|
599
|
+
} else {
|
|
600
|
+
addError("portfolio", result.error);
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
useInput2((input, key) => {
|
|
606
|
+
if (input === "q" || key.ctrl && input === "c") {
|
|
607
|
+
exit();
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
const left = input === "h" || key.leftArrow;
|
|
611
|
+
const right = input === "l" || key.rightArrow;
|
|
612
|
+
switch (currentView) {
|
|
613
|
+
case "home":
|
|
614
|
+
if (right) openBlogList();
|
|
615
|
+
break;
|
|
616
|
+
case "blogList":
|
|
617
|
+
if (left) setCurrentView("home");
|
|
618
|
+
else if (right) openPortfolioList();
|
|
619
|
+
break;
|
|
620
|
+
case "portfolioList":
|
|
621
|
+
if (left) openBlogList();
|
|
622
|
+
break;
|
|
623
|
+
case "blogDetail":
|
|
624
|
+
if (left) {
|
|
625
|
+
setCurrentView("blogList");
|
|
626
|
+
setCurrentPost(null);
|
|
627
|
+
} else if (input === "j" || key.downArrow) {
|
|
628
|
+
detailScrollRef.current?.scrollBy(1);
|
|
629
|
+
} else if (input === "k" || key.upArrow) {
|
|
630
|
+
detailScrollRef.current?.scrollBy(-1);
|
|
631
|
+
}
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
return /* @__PURE__ */ jsx11(Box7, { width: columns, height: rows, justifyContent: "center", alignItems: "center", children: /* @__PURE__ */ jsxs8(Box7, { flexDirection: "column", width: contentWidth, children: [
|
|
636
|
+
/* @__PURE__ */ jsx11(NavBar, {}),
|
|
637
|
+
visibleErrors.length > 0 && /* @__PURE__ */ jsx11(Box7, { marginTop: 1, flexDirection: "column", children: visibleErrors.map((err, i) => /* @__PURE__ */ jsx11(Text11, { color: "red", children: err }, i)) }),
|
|
638
|
+
loading && /* @__PURE__ */ jsx11(Box7, { paddingY: 2, children: /* @__PURE__ */ jsx11(AnimatedText, { name: "radar", speed: 0.6, children: "Loading" }) }),
|
|
639
|
+
currentView === "home" && !loading && /* @__PURE__ */ jsx11(HomeView, { aboutTitle, aboutContent, contentWidth }),
|
|
640
|
+
currentView === "blogList" && !loading && /* @__PURE__ */ jsx11(
|
|
641
|
+
BlogListView,
|
|
642
|
+
{
|
|
643
|
+
posts: blogPosts,
|
|
644
|
+
highlightedIndex: blogList.highlightedIndex,
|
|
645
|
+
scrollRef: blogList.scrollRef,
|
|
646
|
+
viewportHeight: blogListVPHeight
|
|
647
|
+
}
|
|
648
|
+
),
|
|
649
|
+
currentView === "blogDetail" && currentPost && /* @__PURE__ */ jsx11(
|
|
650
|
+
BlogDetailView,
|
|
651
|
+
{
|
|
652
|
+
post: currentPost,
|
|
653
|
+
scrollRef: detailScrollRef,
|
|
654
|
+
viewportHeight: blogDetailVPHeight,
|
|
655
|
+
contentWidth
|
|
656
|
+
}
|
|
657
|
+
),
|
|
658
|
+
currentView === "portfolioList" && !loading && /* @__PURE__ */ jsx11(
|
|
659
|
+
PortfolioListView,
|
|
660
|
+
{
|
|
661
|
+
projects: portfolioProjects,
|
|
662
|
+
highlightedIndex: portfolioList.highlightedIndex,
|
|
663
|
+
scrollRef: portfolioList.scrollRef,
|
|
664
|
+
viewportHeight: portfolioListVPHeight
|
|
665
|
+
}
|
|
666
|
+
)
|
|
667
|
+
] }) });
|
|
668
|
+
}
|
|
669
|
+
export {
|
|
670
|
+
App as default
|
|
671
|
+
};
|