@synapsync/synk 1.0.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.
@@ -0,0 +1,196 @@
1
+ import { r as __toESM } from "../../rolldown-runtime.mjs";
2
+ import { a as SD, c as fD, d as require_picocolors, i as RD, l as pD, n as LD, o as _D, r as MD, s as dD, t as ID, u as require_src } from "./core.mjs";
3
+ import y from "node:process";
4
+ import { stripVTControlCharacters } from "node:util";
5
+ var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
6
+ require_src();
7
+ function ce() {
8
+ return y.platform !== "win32" ? y.env.TERM !== "linux" : !!y.env.CI || !!y.env.WT_SESSION || !!y.env.TERMINUS_SUBLIME || y.env.ConEmuTask === "{cmd::Cmder}" || y.env.TERM_PROGRAM === "Terminus-Sublime" || y.env.TERM_PROGRAM === "vscode" || y.env.TERM === "xterm-256color" || y.env.TERM === "alacritty" || y.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
9
+ }
10
+ const V = ce(), u = (t, n) => V ? t : n, le = u("◆", "*"), L = u("■", "x"), W = u("▲", "x"), C = u("◇", "o");
11
+ u("┌", "T");
12
+ const o = u("│", "|"), d = u("└", "—"), k = u("●", ">"), P = u("○", " "), A = u("◻", "[•]"), T = u("◼", "[+]"), F = u("◻", "[ ]");
13
+ u("▪", "•");
14
+ u("─", "-");
15
+ u("╮", "+");
16
+ u("├", "+");
17
+ u("╯", "+");
18
+ const q = u("●", "•"), D = u("◆", "*"), U = u("▲", "!"), K = u("■", "x"), b = (t) => {
19
+ switch (t) {
20
+ case "initial":
21
+ case "active": return import_picocolors.default.cyan(le);
22
+ case "cancel": return import_picocolors.default.red(L);
23
+ case "error": return import_picocolors.default.yellow(W);
24
+ case "submit": return import_picocolors.default.green(C);
25
+ }
26
+ }, G = (t) => {
27
+ const { cursor: n, options: r, style: i } = t, s = t.maxItems ?? Number.POSITIVE_INFINITY, c = Math.max(process.stdout.rows - 4, 0), a = Math.min(c, Math.max(s, 5));
28
+ let l = 0;
29
+ n >= l + a - 3 ? l = Math.max(Math.min(n - a + 3, r.length - a), 0) : n < l + 2 && (l = Math.max(n - 2, 0));
30
+ const $ = a < r.length && l > 0, g = a < r.length && l + a < r.length;
31
+ return r.slice(l, l + a).map((p, v, f) => {
32
+ const j = v === 0 && $, E = v === f.length - 1 && g;
33
+ return j || E ? import_picocolors.default.dim("...") : i(p, v + l === n);
34
+ });
35
+ }, ye = (t) => {
36
+ const n = t.active ?? "Yes", r = t.inactive ?? "No";
37
+ return new dD({
38
+ active: n,
39
+ inactive: r,
40
+ initialValue: t.initialValue ?? !0,
41
+ render() {
42
+ const i = `${import_picocolors.default.gray(o)}
43
+ ${b(this.state)} ${t.message}
44
+ `, s = this.value ? n : r;
45
+ switch (this.state) {
46
+ case "submit": return `${i}${import_picocolors.default.gray(o)} ${import_picocolors.default.dim(s)}`;
47
+ case "cancel": return `${i}${import_picocolors.default.gray(o)} ${import_picocolors.default.strikethrough(import_picocolors.default.dim(s))}
48
+ ${import_picocolors.default.gray(o)}`;
49
+ default: return `${i}${import_picocolors.default.cyan(o)} ${this.value ? `${import_picocolors.default.green(k)} ${n}` : `${import_picocolors.default.dim(P)} ${import_picocolors.default.dim(n)}`} ${import_picocolors.default.dim("/")} ${this.value ? `${import_picocolors.default.dim(P)} ${import_picocolors.default.dim(r)}` : `${import_picocolors.default.green(k)} ${r}`}
50
+ ${import_picocolors.default.cyan(d)}
51
+ `;
52
+ }
53
+ }
54
+ }).prompt();
55
+ }, ve = (t) => {
56
+ const n = (r, i) => {
57
+ const s = r.label ?? String(r.value);
58
+ switch (i) {
59
+ case "selected": return `${import_picocolors.default.dim(s)}`;
60
+ case "active": return `${import_picocolors.default.green(k)} ${s} ${r.hint ? import_picocolors.default.dim(`(${r.hint})`) : ""}`;
61
+ case "cancelled": return `${import_picocolors.default.strikethrough(import_picocolors.default.dim(s))}`;
62
+ default: return `${import_picocolors.default.dim(P)} ${import_picocolors.default.dim(s)}`;
63
+ }
64
+ };
65
+ return new LD({
66
+ options: t.options,
67
+ initialValue: t.initialValue,
68
+ render() {
69
+ const r = `${import_picocolors.default.gray(o)}
70
+ ${b(this.state)} ${t.message}
71
+ `;
72
+ switch (this.state) {
73
+ case "submit": return `${r}${import_picocolors.default.gray(o)} ${n(this.options[this.cursor], "selected")}`;
74
+ case "cancel": return `${r}${import_picocolors.default.gray(o)} ${n(this.options[this.cursor], "cancelled")}
75
+ ${import_picocolors.default.gray(o)}`;
76
+ default: return `${r}${import_picocolors.default.cyan(o)} ${G({
77
+ cursor: this.cursor,
78
+ options: this.options,
79
+ maxItems: t.maxItems,
80
+ style: (i, s) => n(i, s ? "active" : "inactive")
81
+ }).join(`
82
+ ${import_picocolors.default.cyan(o)} `)}
83
+ ${import_picocolors.default.cyan(d)}
84
+ `;
85
+ }
86
+ }
87
+ }).prompt();
88
+ }, fe = (t) => {
89
+ const n = (r, i) => {
90
+ const s = r.label ?? String(r.value);
91
+ return i === "active" ? `${import_picocolors.default.cyan(A)} ${s} ${r.hint ? import_picocolors.default.dim(`(${r.hint})`) : ""}` : i === "selected" ? `${import_picocolors.default.green(T)} ${import_picocolors.default.dim(s)} ${r.hint ? import_picocolors.default.dim(`(${r.hint})`) : ""}` : i === "cancelled" ? `${import_picocolors.default.strikethrough(import_picocolors.default.dim(s))}` : i === "active-selected" ? `${import_picocolors.default.green(T)} ${s} ${r.hint ? import_picocolors.default.dim(`(${r.hint})`) : ""}` : i === "submitted" ? `${import_picocolors.default.dim(s)}` : `${import_picocolors.default.dim(F)} ${import_picocolors.default.dim(s)}`;
92
+ };
93
+ return new SD({
94
+ options: t.options,
95
+ initialValues: t.initialValues,
96
+ required: t.required ?? !0,
97
+ cursorAt: t.cursorAt,
98
+ validate(r) {
99
+ if (this.required && r.length === 0) return `Please select at least one option.
100
+ ${import_picocolors.default.reset(import_picocolors.default.dim(`Press ${import_picocolors.default.gray(import_picocolors.default.bgWhite(import_picocolors.default.inverse(" space ")))} to select, ${import_picocolors.default.gray(import_picocolors.default.bgWhite(import_picocolors.default.inverse(" enter ")))} to submit`))}`;
101
+ },
102
+ render() {
103
+ const r = `${import_picocolors.default.gray(o)}
104
+ ${b(this.state)} ${t.message}
105
+ `, i = (s, c) => {
106
+ const a = this.value.includes(s.value);
107
+ return c && a ? n(s, "active-selected") : a ? n(s, "selected") : n(s, c ? "active" : "inactive");
108
+ };
109
+ switch (this.state) {
110
+ case "submit": return `${r}${import_picocolors.default.gray(o)} ${this.options.filter(({ value: s }) => this.value.includes(s)).map((s) => n(s, "submitted")).join(import_picocolors.default.dim(", ")) || import_picocolors.default.dim("none")}`;
111
+ case "cancel": {
112
+ const s = this.options.filter(({ value: c }) => this.value.includes(c)).map((c) => n(c, "cancelled")).join(import_picocolors.default.dim(", "));
113
+ return `${r}${import_picocolors.default.gray(o)} ${s.trim() ? `${s}
114
+ ${import_picocolors.default.gray(o)}` : ""}`;
115
+ }
116
+ case "error": {
117
+ const s = this.error.split(`
118
+ `).map((c, a) => a === 0 ? `${import_picocolors.default.yellow(d)} ${import_picocolors.default.yellow(c)}` : ` ${c}`).join(`
119
+ `);
120
+ return `${r + import_picocolors.default.yellow(o)} ${G({
121
+ options: this.options,
122
+ cursor: this.cursor,
123
+ maxItems: t.maxItems,
124
+ style: i
125
+ }).join(`
126
+ ${import_picocolors.default.yellow(o)} `)}
127
+ ${s}
128
+ `;
129
+ }
130
+ default: return `${r}${import_picocolors.default.cyan(o)} ${G({
131
+ options: this.options,
132
+ cursor: this.cursor,
133
+ maxItems: t.maxItems,
134
+ style: i
135
+ }).join(`
136
+ ${import_picocolors.default.cyan(o)} `)}
137
+ ${import_picocolors.default.cyan(d)}
138
+ `;
139
+ }
140
+ }
141
+ }).prompt();
142
+ }, M = {
143
+ message: (t = "", { symbol: n = import_picocolors.default.gray(o) } = {}) => {
144
+ const r = [`${import_picocolors.default.gray(o)}`];
145
+ if (t) {
146
+ const [i, ...s] = t.split(`
147
+ `);
148
+ r.push(`${n} ${i}`, ...s.map((c) => `${import_picocolors.default.gray(o)} ${c}`));
149
+ }
150
+ process.stdout.write(`${r.join(`
151
+ `)}
152
+ `);
153
+ },
154
+ info: (t) => {
155
+ M.message(t, { symbol: import_picocolors.default.blue(q) });
156
+ },
157
+ success: (t) => {
158
+ M.message(t, { symbol: import_picocolors.default.green(D) });
159
+ },
160
+ step: (t) => {
161
+ M.message(t, { symbol: import_picocolors.default.green(C) });
162
+ },
163
+ warn: (t) => {
164
+ M.message(t, { symbol: import_picocolors.default.yellow(U) });
165
+ },
166
+ warning: (t) => {
167
+ M.warn(t);
168
+ },
169
+ error: (t) => {
170
+ M.message(t, { symbol: import_picocolors.default.red(K) });
171
+ }
172
+ }, J = `${import_picocolors.default.gray(o)} `, x = {
173
+ message: async (t, { symbol: n = import_picocolors.default.gray(o) } = {}) => {
174
+ process.stdout.write(`${import_picocolors.default.gray(o)}
175
+ ${n} `);
176
+ let r = 3;
177
+ for await (let i of t) {
178
+ i = i.replace(/\n/g, `
179
+ ${J}`), i.includes(`
180
+ `) && (r = 3 + stripVTControlCharacters(i.slice(i.lastIndexOf(`
181
+ `))).length);
182
+ const s = stripVTControlCharacters(i).length;
183
+ r + s < process.stdout.columns ? (r += s, process.stdout.write(i)) : (process.stdout.write(`
184
+ ${J}${i.trimStart()}`), r = 3 + stripVTControlCharacters(i.trimStart()).length);
185
+ }
186
+ process.stdout.write(`
187
+ `);
188
+ },
189
+ info: (t) => x.message(t, { symbol: import_picocolors.default.blue(q) }),
190
+ success: (t) => x.message(t, { symbol: import_picocolors.default.green(D) }),
191
+ step: (t) => x.message(t, { symbol: import_picocolors.default.green(C) }),
192
+ warn: (t) => x.message(t, { symbol: import_picocolors.default.yellow(U) }),
193
+ warning: (t) => x.warn(t),
194
+ error: (t) => x.message(t, { symbol: import_picocolors.default.red(K) })
195
+ };
196
+ export { ve as n, ye as r, fe as t };