zion 0.0.6 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/cli.js +633 -0
  2. package/package.json +45 -7
  3. package/bin/zion.js +0 -108
package/dist/cli.js ADDED
@@ -0,0 +1,633 @@
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 Box6, Text as Text8, 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
+ };
29
+
30
+ // src/components/HintBar.tsx
31
+ import { jsx } from "react/jsx-runtime";
32
+ function HintBar({ text }) {
33
+ return /* @__PURE__ */ jsx(Text, { color: COLORS.subtle, children: text });
34
+ }
35
+
36
+ // src/components/ui/Markdown.tsx
37
+ import Table from "cli-table3";
38
+ import { marked } from "marked";
39
+ import { Box, Text as Text2 } from "ink";
40
+ import Link from "ink-link";
41
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
42
+ function Markdown({ children, width }) {
43
+ const tokens = marked.lexer(children);
44
+ return /* @__PURE__ */ jsx2(Box, { flexDirection: "column", width, children: tokens.map((token, idx) => /* @__PURE__ */ jsx2(TokenRenderer, { token, width }, idx)) });
45
+ }
46
+ function TokenRenderer({ token, width }) {
47
+ switch (token.type) {
48
+ case "heading":
49
+ return /* @__PURE__ */ jsx2(Box, { marginTop: token.depth === 1 ? 0 : 1, children: /* @__PURE__ */ jsx2(Text2, { bold: true, underline: token.depth === 1, children: renderInline(token.tokens) }) });
50
+ case "paragraph": {
51
+ const hasLinks = token.tokens?.some(
52
+ (t) => t.type === "link" || t.type === "strong" && "tokens" in t && t.tokens?.some((st) => st.type === "link")
53
+ );
54
+ if (hasLinks) {
55
+ return /* @__PURE__ */ jsx2(Box, { flexDirection: "row", flexWrap: "wrap", children: renderInline(token.tokens) });
56
+ }
57
+ return /* @__PURE__ */ jsx2(Text2, { wrap: "wrap", children: renderInline(token.tokens) });
58
+ }
59
+ case "code": {
60
+ const innerWidth = width ? width - 4 : 76;
61
+ const horizontalBar = "\u2500".repeat(innerWidth + 2);
62
+ const lines = token.text.split("\n").map((line) => {
63
+ const truncated = line.length > innerWidth ? line.slice(0, innerWidth) : line;
64
+ return `\u2502 ${truncated.padEnd(innerWidth)} \u2502`;
65
+ });
66
+ const block = [`\u250C${horizontalBar}\u2510`, ...lines, `\u2514${horizontalBar}\u2518`].join("\n");
67
+ return /* @__PURE__ */ jsx2(Box, { marginY: 1, children: /* @__PURE__ */ jsx2(Text2, { dimColor: true, children: block }) });
68
+ }
69
+ case "blockquote":
70
+ return /* @__PURE__ */ jsxs(Box, { marginLeft: 2, children: [
71
+ /* @__PURE__ */ jsx2(Text2, { color: "gray", children: "\u2502 " }),
72
+ /* @__PURE__ */ jsx2(Box, { flexDirection: "column", children: token.tokens?.map((t, idx) => /* @__PURE__ */ jsx2(TokenRenderer, { token: t, width: width ? width - 4 : void 0 }, idx)) })
73
+ ] });
74
+ case "list":
75
+ return /* @__PURE__ */ jsx2(Box, { flexDirection: "column", marginY: 1, children: token.items.map((item, idx) => /* @__PURE__ */ jsxs(Box, { children: [
76
+ /* @__PURE__ */ jsx2(Text2, { children: token.ordered ? `${idx + 1}. ` : "\u2022 " }),
77
+ /* @__PURE__ */ jsx2(Box, { flexDirection: "column", children: item.tokens.map((t, i) => /* @__PURE__ */ jsx2(TokenRenderer, { token: t, width: width ? width - 2 : void 0 }, i)) })
78
+ ] }, idx)) });
79
+ case "table":
80
+ return /* @__PURE__ */ jsx2(TableRenderer, { token });
81
+ case "hr":
82
+ return /* @__PURE__ */ jsx2(Text2, { dimColor: true, children: "\u2500".repeat(40) });
83
+ case "space":
84
+ return null;
85
+ default:
86
+ if ("text" in token && typeof token.text === "string") {
87
+ return /* @__PURE__ */ jsx2(Text2, { children: token.text });
88
+ }
89
+ return null;
90
+ }
91
+ }
92
+ function TableRenderer({ token }) {
93
+ const table = new Table({
94
+ head: token.header.map((cell) => renderInlineToString(cell.tokens)),
95
+ style: { head: ["cyan"], border: ["gray"] }
96
+ });
97
+ for (const row of token.rows) {
98
+ table.push(row.map((cell) => renderInlineToString(cell.tokens)));
99
+ }
100
+ return /* @__PURE__ */ jsx2(Text2, { children: table.toString() });
101
+ }
102
+ function renderInline(tokens) {
103
+ if (!tokens) return null;
104
+ return tokens.map((token, idx) => {
105
+ switch (token.type) {
106
+ case "text":
107
+ return /* @__PURE__ */ jsx2(Text2, { children: token.text }, idx);
108
+ case "strong":
109
+ return /* @__PURE__ */ jsx2(Text2, { bold: true, children: renderInline(token.tokens) }, idx);
110
+ case "em":
111
+ return /* @__PURE__ */ jsx2(Text2, { italic: true, children: renderInline(token.tokens) }, idx);
112
+ case "codespan":
113
+ return /* @__PURE__ */ jsxs(Text2, { color: "yellow", children: [
114
+ "`",
115
+ token.text,
116
+ "`"
117
+ ] }, idx);
118
+ case "link":
119
+ return /* @__PURE__ */ jsx2(Link, { url: token.href, children: /* @__PURE__ */ jsx2(Text2, { color: "blue", children: renderInlineToString(token.tokens) }) }, idx);
120
+ case "image":
121
+ return /* @__PURE__ */ jsxs(Text2, { color: "blue", children: [
122
+ "[Image: ",
123
+ token.text || token.href,
124
+ "]"
125
+ ] }, idx);
126
+ case "br":
127
+ return /* @__PURE__ */ jsx2(Text2, { children: "\n" }, idx);
128
+ case "del":
129
+ return /* @__PURE__ */ jsx2(Text2, { strikethrough: true, children: renderInline(token.tokens) }, idx);
130
+ default:
131
+ if ("text" in token && typeof token.text === "string") {
132
+ return /* @__PURE__ */ jsx2(Text2, { children: token.text }, idx);
133
+ }
134
+ return null;
135
+ }
136
+ });
137
+ }
138
+ function renderInlineToString(tokens) {
139
+ if (!tokens) return "";
140
+ return tokens.map((token) => {
141
+ if ("text" in token && typeof token.text === "string") {
142
+ return token.text;
143
+ }
144
+ if ("tokens" in token && Array.isArray(token.tokens)) {
145
+ return renderInlineToString(token.tokens);
146
+ }
147
+ return "";
148
+ }).join("");
149
+ }
150
+
151
+ // src/components/BlogDetailView.tsx
152
+ import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
153
+ function BlogDetailView({ post, scrollRef, viewportHeight, contentWidth }) {
154
+ const { stdout } = useStdout();
155
+ useEffect(() => {
156
+ const handleResize = () => scrollRef.current?.remeasure();
157
+ stdout?.on("resize", handleResize);
158
+ return () => {
159
+ stdout?.off("resize", handleResize);
160
+ };
161
+ }, [stdout, scrollRef]);
162
+ useEffect(() => {
163
+ scrollRef.current?.scrollToTop();
164
+ }, [post.slug, scrollRef]);
165
+ return /* @__PURE__ */ jsxs2(Fragment, { children: [
166
+ /* @__PURE__ */ jsx3(Box2, { marginTop: 1, children: /* @__PURE__ */ jsx3(Text3, { bold: true, color: "white", children: post.title }) }),
167
+ /* @__PURE__ */ jsx3(Box2, { marginTop: 1, height: viewportHeight, flexDirection: "column", children: /* @__PURE__ */ jsx3(ScrollView, { ref: scrollRef, children: /* @__PURE__ */ jsx3(Markdown, { width: contentWidth, children: post.content }) }) }),
168
+ /* @__PURE__ */ jsx3(Box2, { marginTop: 1, children: /* @__PURE__ */ jsx3(HintBar, { text: "Hint: h/j/k: back, down, up | q: quit" }) })
169
+ ] });
170
+ }
171
+
172
+ // src/components/BlogListView.tsx
173
+ import { Box as Box3, Text as Text4 } from "ink";
174
+ import { ScrollView as ScrollView2 } from "ink-scroll-view";
175
+
176
+ // src/lib/content.ts
177
+ async function fetchJson(url) {
178
+ try {
179
+ const res = await fetch(url);
180
+ if (!res.ok) return { ok: false, error: `${res.status} ${res.statusText} (${url})` };
181
+ return { ok: true, data: await res.json() };
182
+ } catch (err) {
183
+ return { ok: false, error: err instanceof Error ? err.message : String(err) };
184
+ }
185
+ }
186
+ function loadAboutContent() {
187
+ return fetchJson(`${BASE_URL}/api/about`);
188
+ }
189
+ function loadBlogPostList() {
190
+ return fetchJson(`${BASE_URL}/api/posts`);
191
+ }
192
+ function loadBlogPost(slug) {
193
+ return fetchJson(`${BASE_URL}/api/posts/${slug}`);
194
+ }
195
+ function formatDate(dateStr) {
196
+ const date = /* @__PURE__ */ new Date(dateStr + "T00:00:00");
197
+ return date.toLocaleDateString("en-US", {
198
+ year: "numeric",
199
+ month: "long",
200
+ day: "numeric"
201
+ });
202
+ }
203
+
204
+ // src/components/BlogListView.tsx
205
+ import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
206
+ function BlogListView({ posts, highlightedIndex, scrollRef, viewportHeight }) {
207
+ return /* @__PURE__ */ jsxs3(Fragment2, { children: [
208
+ /* @__PURE__ */ jsx4(Box3, { marginTop: 1, height: viewportHeight, flexDirection: "column", children: /* @__PURE__ */ jsx4(ScrollView2, { ref: scrollRef, children: posts.map((post, idx) => {
209
+ const isSelected = idx === highlightedIndex;
210
+ const prefix = isSelected ? "\u203A " : " ";
211
+ const dateStr = formatDate(post.publishedAt);
212
+ return /* @__PURE__ */ jsxs3(Box3, { flexDirection: "row", children: [
213
+ /* @__PURE__ */ jsx4(Text4, { bold: isSelected, color: isSelected ? COLORS.selectedBlog : void 0, children: prefix }),
214
+ /* @__PURE__ */ jsx4(Box3, { width: 20, children: /* @__PURE__ */ jsx4(Text4, { color: COLORS.subtle, children: dateStr }) }),
215
+ /* @__PURE__ */ jsx4(Text4, { bold: isSelected, color: isSelected ? COLORS.selectedBlog : COLORS.text, children: post.title })
216
+ ] }, post.slug);
217
+ }) }) }),
218
+ /* @__PURE__ */ jsx4(Box3, { marginTop: 1, children: /* @__PURE__ */ jsx4(HintBar, { text: "Hint: h/j/k/l/enter: back, down, up, open | q: quit" }) })
219
+ ] });
220
+ }
221
+
222
+ // src/components/HomeView.tsx
223
+ import { Box as Box4, Text as Text5 } from "ink";
224
+ import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
225
+ function HomeView({ aboutTitle, aboutContent, contentWidth }) {
226
+ return /* @__PURE__ */ jsxs4(Fragment3, { children: [
227
+ /* @__PURE__ */ jsx5(Box4, { marginTop: 1, children: /* @__PURE__ */ jsx5(Text5, { bold: true, color: "white", children: aboutTitle }) }),
228
+ /* @__PURE__ */ jsx5(Box4, { marginTop: 1, children: /* @__PURE__ */ jsx5(Markdown, { width: contentWidth, children: aboutContent }) }),
229
+ /* @__PURE__ */ jsx5(Box4, { marginTop: 1, children: /* @__PURE__ */ jsx5(HintBar, { text: "Hint: b: blog | q, ctrl+c: quit" }) })
230
+ ] });
231
+ }
232
+
233
+ // src/components/NavBar.tsx
234
+ import { Box as Box5, Text as Text6 } from "ink";
235
+ import Link2 from "ink-link";
236
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
237
+ function NavBar() {
238
+ return /* @__PURE__ */ jsx6(Box5, { flexDirection: "row", children: NAV_LINKS.map((link, idx) => /* @__PURE__ */ jsxs5(Box5, { flexDirection: "row", children: [
239
+ idx > 0 && /* @__PURE__ */ jsx6(Text6, { color: COLORS.subtle, children: DOT_CHAR }),
240
+ /* @__PURE__ */ jsx6(Box5, { marginRight: 2, children: link.name === "home" || link.name === "blog" ? /* @__PURE__ */ jsx6(Text6, { color: link.color, children: link.name }) : /* @__PURE__ */ jsx6(Link2, { url: `${BASE_URL}${link.path}`, children: /* @__PURE__ */ jsx6(Text6, { color: link.color, children: link.name }) }) })
241
+ ] }, link.name)) });
242
+ }
243
+
244
+ // src/components/ui/AnimatedText.tsx
245
+ import chalk from "chalk";
246
+ import { useEffect as useEffect2, useState } from "react";
247
+ import { Text as Text7 } from "ink";
248
+ import { jsx as jsx7 } from "react/jsx-runtime";
249
+ function hexToRgb(hex) {
250
+ const h = hex.replace("#", "");
251
+ const n = h.length === 3 ? parseInt(h[0] + h[0] + h[1] + h[1] + h[2] + h[2], 16) : parseInt(h, 16);
252
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
253
+ }
254
+ var DELAYS = {
255
+ pulse: 16,
256
+ neon: 500,
257
+ radar: 50,
258
+ karaoke: 50,
259
+ rainbow: 15,
260
+ glitch: 55
261
+ };
262
+ var GLITCH_CHARS = "\u2593\u2592\u2591\u2588\u2580\u2584\u258C\u2590\u2500\u2502\u2524\u2510\u2514\u2518\u251C\u252C\u2534\u253C";
263
+ var TOTAL_PULSE_FRAMES = 120;
264
+ function lerp(a, b, t) {
265
+ return Math.round(a + (b - a) * t);
266
+ }
267
+ function applyPulse(text, frame, config) {
268
+ const [br, bg, bb] = hexToRgb(config?.baseColor ?? "#E6E6E6");
269
+ const [pr, pg, pb] = hexToRgb(config?.pulseColor ?? "#FF1010");
270
+ const t = (Math.sin(frame / TOTAL_PULSE_FRAMES * Math.PI * 2) + 1) / 2;
271
+ const r = lerp(br, pr, t);
272
+ const g = lerp(bg, pg, t);
273
+ const b = lerp(bb, pb, t);
274
+ return chalk.rgb(r, g, b)(text);
275
+ }
276
+ function applyNeon(text, frame, config) {
277
+ const on = frame % 2 === 0;
278
+ const onColor = config?.onColor ?? "#00FFFF";
279
+ const offColor = config?.offColor ?? "#325050";
280
+ return on ? chalk.hex(onColor)(text) : chalk.hex(offColor)(text);
281
+ }
282
+ function applyRadar(text, frame, config) {
283
+ const [br, bg, bb] = hexToRgb(config?.baseColor ?? "#3C3C3C");
284
+ const depth = Math.max(1, Math.floor(text.length * 0.2));
285
+ const globalPos = frame % (text.length + depth);
286
+ const chars = [];
287
+ for (let i = 0; i < text.length; i++) {
288
+ const pos = -(i - globalPos);
289
+ if (pos > 0 && pos <= depth - 1) {
290
+ const t = (depth - pos) / depth;
291
+ chars.push(chalk.rgb(lerp(br, 255, t), lerp(bg, 255, t), lerp(bb, 255, t))(text[i]));
292
+ } else {
293
+ chars.push(chalk.rgb(br, bg, bb)(text[i]));
294
+ }
295
+ }
296
+ return chars.join("");
297
+ }
298
+ function applyKaraoke(text, frame, config) {
299
+ const highlightColor = config?.highlightColor ?? "#FFBB00";
300
+ const baseColor = config?.baseColor ?? "#FFFFFF";
301
+ const pos = frame % (text.length + 20) - 10;
302
+ if (pos < 0) {
303
+ return chalk.hex(baseColor)(text);
304
+ }
305
+ return chalk.hex(highlightColor).bold(text.substring(0, pos)) + chalk.hex(baseColor)(text.substring(pos));
306
+ }
307
+ function hsvToRgb(h, s, v) {
308
+ const i = Math.floor(h / 60) % 6;
309
+ const f = h / 60 - Math.floor(h / 60);
310
+ const p = v * (1 - s);
311
+ const q = v * (1 - f * s);
312
+ const t = v * (1 - (1 - f) * s);
313
+ const map = [
314
+ [v, t, p],
315
+ [q, v, p],
316
+ [p, v, t],
317
+ [p, q, v],
318
+ [t, p, v],
319
+ [v, p, q]
320
+ ];
321
+ return map[i].map((c) => Math.round(c * 255));
322
+ }
323
+ function applyRainbow(text, frame, config) {
324
+ const sat = config?.saturation ?? 1;
325
+ const bri = config?.brightness ?? 1;
326
+ const hueStart = 5 * frame % 360;
327
+ const chars = [];
328
+ for (let i = 0; i < text.length; i++) {
329
+ const hue = (hueStart + i * 360 / Math.max(text.length, 1)) % 360;
330
+ const [r, g, b] = hsvToRgb(hue, sat, bri);
331
+ chars.push(chalk.rgb(r, g, b)(text[i]));
332
+ }
333
+ return chars.join("");
334
+ }
335
+ function applyGlitch(text, frame) {
336
+ if (frame % 2 + frame % 3 + frame % 11 + frame % 29 + frame % 37 > 52) {
337
+ return text.replace(/[^\r\n]/g, " ");
338
+ }
339
+ const chunkSize = Math.max(3, Math.round(text.length * 0.02));
340
+ const chars = [];
341
+ for (let i = 0; i < text.length; i++) {
342
+ const skip = Math.round(Math.max(0, (Math.random() - 0.8) * chunkSize));
343
+ chars.push(text.substring(i, i + skip).replace(/[^\r\n]/g, " "));
344
+ i += skip;
345
+ if (text[i]) {
346
+ if (text[i] !== "\n" && text[i] !== "\r" && Math.random() > 0.995) {
347
+ chars.push(GLITCH_CHARS[Math.floor(Math.random() * GLITCH_CHARS.length)]);
348
+ } else if (Math.random() > 5e-3) {
349
+ chars.push(text[i]);
350
+ }
351
+ }
352
+ }
353
+ return chars.join("");
354
+ }
355
+ function applyAnimation(text, name, frame, config) {
356
+ switch (name) {
357
+ case "pulse":
358
+ return applyPulse(text, frame, config);
359
+ case "neon":
360
+ return applyNeon(text, frame, config);
361
+ case "radar":
362
+ return applyRadar(text, frame, config);
363
+ case "karaoke":
364
+ return applyKaraoke(text, frame, config);
365
+ case "rainbow":
366
+ return applyRainbow(text, frame, config);
367
+ case "glitch":
368
+ return applyGlitch(text, frame);
369
+ }
370
+ }
371
+ function flattenChildren(children) {
372
+ if (typeof children === "string") return children;
373
+ if (typeof children === "number") return String(children);
374
+ if (children == null || typeof children === "boolean") return "";
375
+ if (Array.isArray(children)) return children.map(flattenChildren).join("");
376
+ return "";
377
+ }
378
+ function AnimatedText({
379
+ name = "pulse",
380
+ speed = 1,
381
+ bold,
382
+ italic,
383
+ underline,
384
+ strikethrough,
385
+ dimColor,
386
+ config,
387
+ children
388
+ }) {
389
+ const [frame, setFrame] = useState(0);
390
+ const text = flattenChildren(children);
391
+ useEffect2(() => {
392
+ const delay = DELAYS[name] / speed;
393
+ const interval = setInterval(() => {
394
+ setFrame((f) => f + 1);
395
+ }, delay);
396
+ return () => clearInterval(interval);
397
+ }, [name, speed]);
398
+ let animated = applyAnimation(text, name, frame, config);
399
+ if (bold) animated = chalk.bold(animated);
400
+ if (italic) animated = chalk.italic(animated);
401
+ if (underline) animated = chalk.underline(animated);
402
+ if (strikethrough) animated = chalk.strikethrough(animated);
403
+ if (dimColor) animated = chalk.dim(animated);
404
+ return /* @__PURE__ */ jsx7(Text7, { children: animated });
405
+ }
406
+
407
+ // src/hooks/useListNavigation.ts
408
+ import { useState as useState2 } from "react";
409
+ import { useInput } from "ink";
410
+
411
+ // src/hooks/useScrollToIndex.ts
412
+ import { useEffect as useEffect3, useRef } from "react";
413
+ function useScrollToIndex(index) {
414
+ const scrollRef = useRef(null);
415
+ useEffect3(() => {
416
+ const ref = scrollRef.current;
417
+ if (!ref) return;
418
+ const pos = ref.getItemPosition(index);
419
+ const viewportHeight = ref.getViewportHeight();
420
+ const scrollOffset = ref.getScrollOffset();
421
+ if (!pos) return;
422
+ if (pos.top < scrollOffset) {
423
+ ref.scrollTo(pos.top);
424
+ } else if (pos.top + pos.height > scrollOffset + viewportHeight) {
425
+ ref.scrollTo(pos.top + pos.height - viewportHeight);
426
+ }
427
+ }, [index]);
428
+ return scrollRef;
429
+ }
430
+
431
+ // src/hooks/useListNavigation.ts
432
+ function useListNavigation({ length, onSelect, isActive }) {
433
+ const [highlightedIndex, setHighlightedIndex] = useState2(0);
434
+ const scrollRef = useScrollToIndex(highlightedIndex);
435
+ useInput(
436
+ (input, key) => {
437
+ if (length === 0) return;
438
+ if (key.upArrow || input === "k") {
439
+ setHighlightedIndex((i) => Math.max(0, i - 1));
440
+ }
441
+ if (key.downArrow || input === "j") {
442
+ setHighlightedIndex((i) => Math.min(length - 1, i + 1));
443
+ }
444
+ if ((input === "l" || key.return) && onSelect) {
445
+ onSelect(highlightedIndex);
446
+ }
447
+ },
448
+ { isActive: isActive === true }
449
+ );
450
+ return {
451
+ highlightedIndex,
452
+ scrollRef,
453
+ reset: () => setHighlightedIndex(0)
454
+ };
455
+ }
456
+
457
+ // src/app.tsx
458
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
459
+ function App() {
460
+ const { exit } = useApp();
461
+ const { stdout } = useStdout2();
462
+ const columns = stdout?.columns ?? 80;
463
+ const rows = stdout?.rows ?? 24;
464
+ const [currentView, setCurrentView] = useState3("home");
465
+ const [errors, setErrors] = useState3({});
466
+ const [aboutTitle, setAboutTitle] = useState3("");
467
+ const [aboutContent, setAboutContent] = useState3("");
468
+ const [blogPosts, setBlogPosts] = useState3([]);
469
+ const [currentPost, setCurrentPost] = useState3(null);
470
+ const [loading, setLoading] = useState3("about");
471
+ const detailScrollRef = useRef2(null);
472
+ const addError = (key, message) => setErrors((prev) => ({ ...prev, [key]: message }));
473
+ const clearError = (key) => setErrors((prev) => {
474
+ const next = { ...prev };
475
+ delete next[key];
476
+ return next;
477
+ });
478
+ const blogList = useListNavigation({
479
+ length: blogPosts.length,
480
+ isActive: currentView === "blogList",
481
+ onSelect: (index) => {
482
+ const post = blogPosts[index];
483
+ if (!post) return;
484
+ setLoading("post");
485
+ loadBlogPost(post.slug).then((result) => {
486
+ setLoading(null);
487
+ if (result.ok) {
488
+ clearError("post");
489
+ setCurrentPost(result.data);
490
+ setCurrentView("blogDetail");
491
+ } else {
492
+ addError("post", result.error);
493
+ }
494
+ });
495
+ }
496
+ });
497
+ useEffect4(() => {
498
+ loadAboutContent().then((result) => {
499
+ setLoading(null);
500
+ if (result.ok) {
501
+ clearError("about");
502
+ setAboutTitle(result.data.title);
503
+ setAboutContent(result.data.content);
504
+ } else {
505
+ addError("about", result.error);
506
+ }
507
+ });
508
+ loadBlogPostList().then((result) => {
509
+ setLoading((prev) => prev === "posts" ? null : prev);
510
+ if (result.ok) {
511
+ clearError("posts");
512
+ setBlogPosts(result.data);
513
+ } else {
514
+ addError("posts", result.error);
515
+ }
516
+ });
517
+ }, []);
518
+ const contentWidth = Math.max(Math.min(Math.floor(columns * 2 / 3), 80), 40);
519
+ const blogListVPHeight = Math.min(blogPosts.length, Math.min(Math.floor(rows / 2), 20));
520
+ const blogDetailVPHeight = Math.min(Math.floor(rows / 2), 25);
521
+ const visibleErrors = [];
522
+ if (currentView === "home" && errors.about) visibleErrors.push(errors.about);
523
+ if (currentView === "blogList") {
524
+ if (errors.posts) visibleErrors.push(errors.posts);
525
+ if (errors.post) visibleErrors.push(errors.post);
526
+ }
527
+ if (currentView === "blogDetail" && errors.post) visibleErrors.push(errors.post);
528
+ useInput2((input, key) => {
529
+ if (input === "q" || key.ctrl && input === "c") {
530
+ exit();
531
+ return;
532
+ }
533
+ switch (currentView) {
534
+ case "home":
535
+ if (input === "b") {
536
+ setCurrentView("blogList");
537
+ blogList.reset();
538
+ }
539
+ break;
540
+ case "blogList":
541
+ if (input === "h") {
542
+ setCurrentView("home");
543
+ }
544
+ break;
545
+ case "blogDetail":
546
+ if (input === "h") {
547
+ setCurrentView("blogList");
548
+ setCurrentPost(null);
549
+ } else if (input === "j" || key.downArrow) {
550
+ detailScrollRef.current?.scrollBy(1);
551
+ } else if (input === "k" || key.upArrow) {
552
+ detailScrollRef.current?.scrollBy(-1);
553
+ }
554
+ break;
555
+ }
556
+ });
557
+ return /* @__PURE__ */ jsx8(Box6, { width: columns, height: rows, justifyContent: "center", alignItems: "center", children: /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", width: contentWidth, children: [
558
+ /* @__PURE__ */ jsx8(NavBar, {}),
559
+ visibleErrors.length > 0 && /* @__PURE__ */ jsx8(Box6, { marginTop: 1, flexDirection: "column", children: visibleErrors.map((err, i) => /* @__PURE__ */ jsx8(Text8, { color: "red", children: err }, i)) }),
560
+ loading && /* @__PURE__ */ jsx8(AnimatedText, { name: "radar", children: "Loading" }),
561
+ currentView === "home" && !loading && /* @__PURE__ */ jsx8(HomeView, { aboutTitle, aboutContent, contentWidth }),
562
+ currentView === "blogList" && !loading && /* @__PURE__ */ jsx8(
563
+ BlogListView,
564
+ {
565
+ posts: blogPosts,
566
+ highlightedIndex: blogList.highlightedIndex,
567
+ scrollRef: blogList.scrollRef,
568
+ viewportHeight: blogListVPHeight
569
+ }
570
+ ),
571
+ currentView === "blogDetail" && currentPost && /* @__PURE__ */ jsx8(
572
+ BlogDetailView,
573
+ {
574
+ post: currentPost,
575
+ scrollRef: detailScrollRef,
576
+ viewportHeight: blogDetailVPHeight,
577
+ contentWidth
578
+ }
579
+ )
580
+ ] }) });
581
+ }
582
+
583
+ // src/lib/render.tsx
584
+ import { render as inkRender } from "ink";
585
+
586
+ // src/lib/Screen.tsx
587
+ import { useCallback, useEffect as useEffect5, useState as useState4 } from "react";
588
+ import { Box as Box7, useStdout as useStdout3 } from "ink";
589
+ import { jsx as jsx9 } from "react/jsx-runtime";
590
+ function Screen({ children }) {
591
+ const { stdout } = useStdout3();
592
+ const getSize = useCallback(() => ({ height: stdout.rows, width: stdout.columns }), [stdout]);
593
+ const [size, setSize] = useState4(getSize);
594
+ useEffect5(() => {
595
+ const onResize = () => setSize(getSize());
596
+ stdout.on("resize", onResize);
597
+ return () => {
598
+ stdout.off("resize", onResize);
599
+ };
600
+ }, [stdout, getSize]);
601
+ return /* @__PURE__ */ jsx9(Box7, { height: size.height, width: size.width, children });
602
+ }
603
+
604
+ // src/lib/render.tsx
605
+ import { jsx as jsx10 } from "react/jsx-runtime";
606
+ var ENTER_ALT_BUFFER = "\x1B[?1049h";
607
+ var EXIT_ALT_BUFFER = "\x1B[?1049l";
608
+ var CLEAR_SCREEN = "\x1B[2J\x1B[H";
609
+ function render(node, options) {
610
+ process.stdout.write(ENTER_ALT_BUFFER + CLEAR_SCREEN);
611
+ const element = /* @__PURE__ */ jsx10(Screen, { children: node });
612
+ const instance = inkRender(element, options);
613
+ setImmediate(() => instance.rerender(element));
614
+ const cleanup = () => process.stdout.write(EXIT_ALT_BUFFER);
615
+ const originalWaitUntilExit = instance.waitUntilExit.bind(instance);
616
+ instance.waitUntilExit = async () => {
617
+ await originalWaitUntilExit();
618
+ cleanup();
619
+ };
620
+ process.on("exit", cleanup);
621
+ const handleSignal = () => {
622
+ cleanup();
623
+ instance.unmount();
624
+ process.exit(0);
625
+ };
626
+ process.on("SIGINT", handleSignal);
627
+ process.on("SIGTERM", handleSignal);
628
+ return instance;
629
+ }
630
+
631
+ // src/cli.tsx
632
+ import { jsx as jsx11 } from "react/jsx-runtime";
633
+ render(/* @__PURE__ */ jsx11(App, {}));
package/package.json CHANGED
@@ -1,8 +1,46 @@
1
- { "author": "Tomas Carnecky <tomas.carnecky@gmail.com>"
2
- , "bin": { "zion": "./bin/zion.js" }
3
- , "devDependencies": { "coffee-script": "*" }
4
- , "engines": { "node": "0.6.x" }
5
- , "name": "zion"
6
- , "repository": { "url": "git://github.com/wereHamster/zion.git" }
7
- , "version": "0.0.6"
1
+ {
2
+ "name": "zion",
3
+ "version": "2.0.1",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/zion-off/zzzzion.git"
8
+ },
9
+ "bin": "dist/cli.js",
10
+ "type": "module",
11
+ "engines": {
12
+ "node": ">=16"
13
+ },
14
+ "scripts": {
15
+ "build": "tsup",
16
+ "build:watch": "nodemon --watch src --ext ts,tsx --exec tsup",
17
+ "dev": "tsx --watch src/cli.tsx",
18
+ "start": "node dist/cli.js",
19
+ "lint": "prettier --write . && eslint . --fix"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "chalk": "^5.6.2",
26
+ "cli-table3": "^0.6.5",
27
+ "ink": "^6.6.0",
28
+ "ink-link": "^5.0.0",
29
+ "ink-scroll-view": "^0.3.5",
30
+ "marked": "^17.0.1",
31
+ "react": "^19.2.4"
32
+ },
33
+ "devDependencies": {
34
+ "@trivago/prettier-plugin-sort-imports": "^4.3.0",
35
+ "@types/node": "^22.0.0",
36
+ "@types/react": "^19.2.13",
37
+ "eslint": "^9.0.0",
38
+ "eslint-plugin-react": "^7.32.2",
39
+ "nodemon": "^3.1.11",
40
+ "prettier": "^2.8.7",
41
+ "tsup": "^8.5.1",
42
+ "tsx": "^4.21.0",
43
+ "typescript": "^5.0.3",
44
+ "typescript-eslint": "^8.0.0"
45
+ }
8
46
  }
package/bin/zion.js DELETED
@@ -1,108 +0,0 @@
1
- #!/usr/bin/env node
2
- (function() {
3
- var Worker, app, appVersions, basename, cluster, join, mtime, readdirSync, skipSelf, statSync, _ref, _ref2;
4
-
5
- cluster = require('cluster');
6
-
7
- app = process.env.APP || process.argv[2];
8
-
9
- process.title = "zion " + (cluster.isMaster && 'master' || 'worker') + " " + app;
10
-
11
- if (cluster.isMaster && process.argv.length === 2) {
12
- _ref = require('path'), basename = _ref.basename, join = _ref.join;
13
- _ref2 = require('fs'), statSync = _ref2.statSync, readdirSync = _ref2.readdirSync;
14
- skipSelf = function(x) {
15
- return x !== basename(__filename);
16
- };
17
- mtime = function(x) {
18
- return statSync(join(__dirname, x)).mtime.getTime();
19
- };
20
- appVersions = readdirSync(__dirname).filter(skipSelf).sort(function(lhs, rhs) {
21
- return mtime(rhs) - mtime(lhs);
22
- });
23
- if (appVersions.length === 0) throw new Error("No app version deployed");
24
- app = join(__dirname, appVersions[0]);
25
- }
26
-
27
- Worker = (function() {
28
- var getWorkerIndex, workers;
29
-
30
- workers = [];
31
-
32
- getWorkerIndex = function(proc) {
33
- var k, v, _len;
34
- for (k = 0, _len = workers.length; k < _len; k++) {
35
- v = workers[k];
36
- if (v.proc === proc) return k;
37
- }
38
- };
39
-
40
- cluster.on('death', function(proc) {
41
- var index, worker;
42
- index = getWorkerIndex(proc);
43
- worker = workers[index];
44
- if (proc.exitCode === 0) {
45
- return workers.splice(index, 1);
46
- } else {
47
- return worker.fork();
48
- }
49
- });
50
-
51
- cluster.isMaster && process.on('SIGTERM', function() {
52
- var worker, _i, _len;
53
- for (_i = 0, _len = workers.length; _i < _len; _i++) {
54
- worker = workers[_i];
55
- process.kill(worker.proc.pid);
56
- }
57
- return process.exit(0);
58
- });
59
-
60
- function Worker(msg) {
61
- this.msg = msg != null ? msg : {};
62
- workers.push(this);
63
- this.fork();
64
- }
65
-
66
- Worker.prototype.fork = function() {
67
- var proc,
68
- _this = this;
69
- process.env.APP = app;
70
- this.proc = proc = cluster.fork();
71
- return proc.on('message', function(msg) {
72
- var worker, _i, _len, _results;
73
- if (msg.cmd === 'zion:online') {
74
- return proc.send(_this.msg);
75
- } else if (msg.cmd === 'zion:switch') {
76
- return app = msg.app;
77
- } else if (msg.cmd === 'zion:fork') {
78
- return new Worker(msg);
79
- } else if (msg.cmd === 'zion:restart') {
80
- _results = [];
81
- for (_i = 0, _len = workers.length; _i < _len; _i++) {
82
- worker = workers[_i];
83
- _results.push(process.kill(worker.proc.pid));
84
- }
85
- return _results;
86
- }
87
- });
88
- };
89
-
90
- return Worker;
91
-
92
- })();
93
-
94
- if (cluster.isMaster) {
95
- new Worker({
96
- cmd: 'zion:bootstrap'
97
- });
98
- } else {
99
- process.chdir(app);
100
- process.send({
101
- cmd: 'zion:online'
102
- });
103
- process.on('message', function(msg) {
104
- return require(app)(msg);
105
- });
106
- }
107
-
108
- }).call(this);