typerighter 0.2.2 → 0.3.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.
Files changed (45) hide show
  1. package/bin/typerighter.js +1 -1
  2. package/dist/cli-CoyGXgR1.js +579 -0
  3. package/dist/cli.js +1 -1
  4. package/dist/{vite-BNDqb1zM.js → constants-B7b8AsH0.js} +126 -315
  5. package/dist/index.js +4 -4
  6. package/dist/init-CUo89E7j.js +2358 -0
  7. package/dist/node/build/index.d.ts +2 -3
  8. package/dist/node/build/index.d.ts.map +1 -1
  9. package/dist/node/build/{render.d.ts → prerender.d.ts} +6 -3
  10. package/dist/node/build/prerender.d.ts.map +1 -0
  11. package/dist/node/cli/index.d.ts +1 -1
  12. package/dist/node/cli/index.d.ts.map +1 -1
  13. package/dist/node/cli/init.d.ts +1 -1
  14. package/dist/node/cli/init.d.ts.map +1 -1
  15. package/dist/node/context.d.ts +14 -0
  16. package/dist/node/context.d.ts.map +1 -0
  17. package/dist/node/lib/logger.d.ts +10 -3
  18. package/dist/node/lib/logger.d.ts.map +1 -1
  19. package/dist/node/lib/progress.d.ts +10 -0
  20. package/dist/node/lib/progress.d.ts.map +1 -0
  21. package/dist/node/lib/typedown-context.d.ts +1 -3
  22. package/dist/node/lib/typedown-context.d.ts.map +1 -1
  23. package/dist/node/plugin/vite/index.d.ts +5 -1
  24. package/dist/node/plugin/vite/index.d.ts.map +1 -1
  25. package/dist/plugin-D2xuSVM4.js +1 -0
  26. package/dist/rolldown-runtime-Dqa2HsxW.js +20 -0
  27. package/dist/shared/utils/format.d.ts +2 -0
  28. package/dist/shared/utils/format.d.ts.map +1 -0
  29. package/dist/shared/utils/html.d.ts +2 -0
  30. package/dist/shared/utils/html.d.ts.map +1 -0
  31. package/dist/shared/utils/html.test.d.ts.map +1 -0
  32. package/dist/shared/utils/index.d.ts +2 -0
  33. package/dist/shared/utils/index.d.ts.map +1 -1
  34. package/dist/vite-BxXQPieu.js +228 -0
  35. package/dist/vite.js +2 -2
  36. package/package.json +6 -3
  37. package/dist/cli-CfMrevh1.js +0 -160
  38. package/dist/constants-BN1OmC7K.js +0 -46
  39. package/dist/init-0BIO3hYI.js +0 -647
  40. package/dist/node/build/html.d.ts +0 -21
  41. package/dist/node/build/html.d.ts.map +0 -1
  42. package/dist/node/build/html.test.d.ts.map +0 -1
  43. package/dist/node/build/render.d.ts.map +0 -1
  44. package/dist/plugin-B-At85hl.js +0 -1
  45. /package/dist/{node/build → shared/utils}/html.test.d.ts +0 -0
@@ -1,46 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = (e, n) => {
3
- let r = {};
4
- for (var i in e) t(r, i, {
5
- get: e[i],
6
- enumerable: !0
7
- });
8
- return n || t(r, Symbol.toStringTag, { value: "Module" }), r;
9
- }, c = (e, i, o, s) => {
10
- if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
11
- get: ((e) => i[e]).bind(null, d),
12
- enumerable: !(s = n(i, d)) || s.enumerable
13
- });
14
- return e;
15
- }, l = (n, r, a) => (a = n == null ? {} : e(i(n)), c(r || !n || !n.__esModule ? t(a, "default", {
16
- value: n,
17
- enumerable: !0
18
- }) : a, n));
19
- //#endregion
20
- //#region src/node/build/html.ts
21
- function u(e) {
22
- let t = e.cssFiles.map((t) => ` <link rel="stylesheet" href="${e.base}${t}">`).join("\n"), n = e.jsFiles.map((t) => ` <link rel="modulepreload" href="${e.base}${t}">`).join("\n");
23
- return `<!DOCTYPE html>
24
- <html lang="${e.lang ?? "en"}">
25
- <head>
26
- <meta charset="UTF-8">
27
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
28
- <title>${d(e.title)}</title>
29
- <meta name="description" content="${d(e.description)}">
30
- ${t}
31
- ${n}
32
- </head>
33
- <body>
34
- <div id="app">${e.content}</div>
35
- <script type="module" src="${e.base}${e.clientEntry}"><\/script>
36
- </body>
37
- </html>`;
38
- }
39
- function d(e) {
40
- return e.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
41
- }
42
- //#endregion
43
- //#region src/node/plugin/vite/constants.ts
44
- var f = "@typedown/app", p = "\0@typedown/app", m = "__typedown_index__.td";
45
- //#endregion
46
- export { u as a, l as c, d as i, f as n, o, m as r, s, p as t };
@@ -1,647 +0,0 @@
1
- import { i as e, n as t, o as n } from "./constants-BN1OmC7K.js";
2
- import { r } from "./brand-CeSqpEQ2.js";
3
- import i from "node:path";
4
- import "node:fs";
5
- import a from "node:fs/promises";
6
- import { styleText as o } from "node:util";
7
- import s, { stdin as c, stdout as l } from "node:process";
8
- import u from "node:readline";
9
- import "node:tty";
10
- //#region ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
11
- var d = (() => {
12
- let e = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
13
- return (t) => {
14
- let n = 0;
15
- for (e.lastIndex = 0; e.test(t);) n += 1;
16
- return t.length - n;
17
- };
18
- })(), f = (e) => e === 12288 || e >= 65281 && e <= 65376 || e >= 65504 && e <= 65510, ee = (e) => e === 8987 || e === 9001 || e >= 12272 && e <= 12287 || e >= 12289 && e <= 12350 || e >= 12441 && e <= 12543 || e >= 12549 && e <= 12591 || e >= 12593 && e <= 12686 || e >= 12688 && e <= 12771 || e >= 12783 && e <= 12830 || e >= 12832 && e <= 12871 || e >= 12880 && e <= 19903 || e >= 65040 && e <= 65049 || e >= 65072 && e <= 65106 || e >= 65108 && e <= 65126 || e >= 65128 && e <= 65131 || e >= 127488 && e <= 127490 || e >= 127504 && e <= 127547 || e >= 127552 && e <= 127560 || e >= 131072 && e <= 196605 || e >= 196608 && e <= 262141, te = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y, ne = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y, p = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy, re = /\t{1,1000}/y, m = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy, ie = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y, ae = /\p{M}+/gu, h = {
19
- limit: Infinity,
20
- ellipsis: ""
21
- }, g = (e, t = {}, n = {}) => {
22
- let r = t.limit ?? Infinity, i = t.ellipsis ?? "", a = t?.ellipsisWidth ?? (i ? g(i, h, n).width : 0), o = n.controlWidth ?? 0, s = n.tabWidth ?? 8, c = n.emojiWidth ?? 2, l = n.regularWidth ?? 1, u = n.wideWidth ?? 2, _ = [
23
- [ie, l],
24
- [te, 0],
25
- [ne, o],
26
- [re, s],
27
- [m, c],
28
- [p, u]
29
- ], v = 0, y = 0, b = e.length, x = 0, S = !1, C = b, w = Math.max(0, r - a), T = 0, E = 0, D = 0, O = 0;
30
- outer: for (;;) {
31
- if (E > T || y >= b && y > v) {
32
- let t = e.slice(T, E) || e.slice(v, y);
33
- x = 0;
34
- for (let e of t.replaceAll(ae, "")) {
35
- let t = e.codePointAt(0) || 0;
36
- if (O = f(t) ? 2 : ee(t) ? u : l, D + O > w && (C = Math.min(C, Math.max(T, v) + x)), D + O > r) {
37
- S = !0;
38
- break outer;
39
- }
40
- x += e.length, D += O;
41
- }
42
- T = E = 0;
43
- }
44
- if (y >= b) break outer;
45
- for (let t = 0, n = _.length; t < n; t++) {
46
- let [n, i] = _[t];
47
- if (n.lastIndex = y, n.test(e)) {
48
- if (x = n === p ? d(e.slice(y, n.lastIndex)) : n === m ? 1 : n.lastIndex - y, O = x * i, D + O > w && (C = Math.min(C, y + Math.floor((w - D) / i))), D + O > r) {
49
- S = !0;
50
- break outer;
51
- }
52
- D += O, T = v, E = y, y = v = n.lastIndex;
53
- continue outer;
54
- }
55
- }
56
- y += 1;
57
- }
58
- return {
59
- width: S ? w : D,
60
- index: S ? C : b,
61
- truncated: S,
62
- ellipsed: S && r >= a
63
- };
64
- }, _ = {
65
- limit: Infinity,
66
- ellipsis: "",
67
- ellipsisWidth: 0
68
- }, v = (e, t = {}) => g(e, _, t).width, y = "\x1B", b = "›", x = 39, S = "\x07", C = "[", w = "]", T = "m", E = `${w}8;;`, D = RegExp(`(?:\\${C}(?<code>\\d+)m|\\${E}(?<uri>.*)${S})`, "y"), O = (e) => {
69
- if (e >= 30 && e <= 37 || e >= 90 && e <= 97) return 39;
70
- if (e >= 40 && e <= 47 || e >= 100 && e <= 107) return 49;
71
- if (e === 1 || e === 2) return 22;
72
- if (e === 3) return 23;
73
- if (e === 4) return 24;
74
- if (e === 7) return 27;
75
- if (e === 8) return 28;
76
- if (e === 9) return 29;
77
- if (e === 0) return 0;
78
- }, k = (e) => `${y}${C}${e}${T}`, A = (e) => `${y}${E}${e}${S}`, j = (e, t, n) => {
79
- let r = t[Symbol.iterator](), i = !1, a = !1, o = e.at(-1), s = o === void 0 ? 0 : v(o), c = r.next(), l = r.next(), u = 0;
80
- for (; !c.done;) {
81
- let o = c.value, d = v(o);
82
- s + d <= n ? e[e.length - 1] += o : (e.push(o), s = 0), (o === y || o === b) && (i = !0, a = t.startsWith(E, u + 1)), i ? a ? o === S && (i = !1, a = !1) : o === T && (i = !1) : (s += d, s === n && !l.done && (e.push(""), s = 0)), c = l, l = r.next(), u += o.length;
83
- }
84
- o = e.at(-1), !s && o !== void 0 && o.length && e.length > 1 && (e[e.length - 2] += e.pop());
85
- }, oe = (e) => {
86
- let t = e.split(" "), n = t.length;
87
- for (; n && !v(t[n - 1]);) n--;
88
- return n === t.length ? e : t.slice(0, n).join(" ") + t.slice(n).join("");
89
- }, se = (e, t, n = {}) => {
90
- if (n.trim !== !1 && e.trim() === "") return "";
91
- let r = "", i, a, o = e.split(" "), s = [""], c = 0;
92
- for (let e = 0; e < o.length; e++) {
93
- let r = o[e];
94
- if (n.trim !== !1) {
95
- let e = s.at(-1) ?? "", t = e.trimStart();
96
- e.length !== t.length && (s[s.length - 1] = t, c = v(t));
97
- }
98
- e !== 0 && (c >= t && (n.wordWrap === !1 || n.trim === !1) && (s.push(""), c = 0), (c || n.trim === !1) && (s[s.length - 1] += " ", c++));
99
- let i = v(r);
100
- if (n.hard && i > t) {
101
- let e = t - c, n = 1 + Math.floor((i - e - 1) / t);
102
- Math.floor((i - 1) / t) < n && s.push(""), j(s, r, t), c = v(s.at(-1) ?? "");
103
- continue;
104
- }
105
- if (c + i > t && c && i) {
106
- if (n.wordWrap === !1 && c < t) {
107
- j(s, r, t), c = v(s.at(-1) ?? "");
108
- continue;
109
- }
110
- s.push(""), c = 0;
111
- }
112
- if (c + i > t && n.wordWrap === !1) {
113
- j(s, r, t), c = v(s.at(-1) ?? "");
114
- continue;
115
- }
116
- s[s.length - 1] += r, c += i;
117
- }
118
- n.trim !== !1 && (s = s.map((e) => oe(e)));
119
- let l = s.join("\n"), u = !1;
120
- for (let e = 0; e < l.length; e++) {
121
- let t = l[e];
122
- if (r += t, u) u = !1;
123
- else if (u = t >= "\ud800" && t <= "\udbff", u) continue;
124
- if (t === y || t === b) {
125
- D.lastIndex = e + 1;
126
- let t = D.exec(l)?.groups;
127
- if (t?.code !== void 0) {
128
- let e = Number.parseFloat(t.code);
129
- i = e === x ? void 0 : e;
130
- } else t?.uri !== void 0 && (a = t.uri.length === 0 ? void 0 : t.uri);
131
- }
132
- if (l[e + 1] === "\n") {
133
- a && (r += A(""));
134
- let e = i ? O(i) : void 0;
135
- i && e && (r += k(e));
136
- } else t === "\n" && (i && O(i) && (r += k(i)), a && (r += A(a)));
137
- }
138
- return r;
139
- }, ce = /\r?\n/;
140
- function M(e, t, n) {
141
- return String(e).normalize().split(ce).map((e) => se(e, t, n)).join("\n");
142
- }
143
- //#endregion
144
- //#region ../../node_modules/.pnpm/@clack+core@1.4.3/node_modules/@clack/core/dist/index.mjs
145
- var N = (/* @__PURE__ */ n(((e, t) => {
146
- var n = "\x1B", r = `${n}[`, i = "\x07", a = {
147
- to(e, t) {
148
- return t ? `${r}${t + 1};${e + 1}H` : `${r}${e + 1}G`;
149
- },
150
- move(e, t) {
151
- let n = "";
152
- return e < 0 ? n += `${r}${-e}D` : e > 0 && (n += `${r}${e}C`), t < 0 ? n += `${r}${-t}A` : t > 0 && (n += `${r}${t}B`), n;
153
- },
154
- up: (e = 1) => `${r}${e}A`,
155
- down: (e = 1) => `${r}${e}B`,
156
- forward: (e = 1) => `${r}${e}C`,
157
- backward: (e = 1) => `${r}${e}D`,
158
- nextLine: (e = 1) => `${r}E`.repeat(e),
159
- prevLine: (e = 1) => `${r}F`.repeat(e),
160
- left: `${r}G`,
161
- hide: `${r}?25l`,
162
- show: `${r}?25h`,
163
- save: `${n}7`,
164
- restore: `${n}8`
165
- };
166
- t.exports = {
167
- cursor: a,
168
- scroll: {
169
- up: (e = 1) => `${r}S`.repeat(e),
170
- down: (e = 1) => `${r}T`.repeat(e)
171
- },
172
- erase: {
173
- screen: `${r}2J`,
174
- up: (e = 1) => `${r}1J`.repeat(e),
175
- down: (e = 1) => `${r}J`.repeat(e),
176
- line: `${r}2K`,
177
- lineEnd: `${r}K`,
178
- lineStart: `${r}1K`,
179
- lines(e) {
180
- let t = "";
181
- for (let n = 0; n < e; n++) t += this.line + (n < e - 1 ? a.up() : "");
182
- return e && (t += a.left), t;
183
- }
184
- },
185
- beep: i
186
- };
187
- })))(), P = {
188
- actions: /* @__PURE__ */ new Set([
189
- "up",
190
- "down",
191
- "left",
192
- "right",
193
- "space",
194
- "enter",
195
- "cancel"
196
- ]),
197
- aliases: /* @__PURE__ */ new Map([
198
- ["k", "up"],
199
- ["j", "down"],
200
- ["h", "left"],
201
- ["l", "right"],
202
- ["", "cancel"],
203
- ["escape", "cancel"]
204
- ]),
205
- messages: {
206
- cancel: "Canceled",
207
- error: "Something went wrong"
208
- },
209
- withGuide: !0,
210
- date: {
211
- monthNames: [
212
- "January",
213
- "February",
214
- "March",
215
- "April",
216
- "May",
217
- "June",
218
- "July",
219
- "August",
220
- "September",
221
- "October",
222
- "November",
223
- "December"
224
- ],
225
- messages: {
226
- required: "Please enter a valid date",
227
- invalidMonth: "There are only 12 months in a year",
228
- invalidDay: (e, t) => `There are only ${e} days in ${t}`,
229
- afterMin: (e) => `Date must be on or after ${e.toISOString().slice(0, 10)}`,
230
- beforeMax: (e) => `Date must be on or before ${e.toISOString().slice(0, 10)}`
231
- }
232
- }
233
- };
234
- function F(e, t) {
235
- if (typeof e == "string") return P.aliases.get(e) === t;
236
- for (let n of e) if (n !== void 0 && F(n, t)) return !0;
237
- return !1;
238
- }
239
- function le(e, t) {
240
- if (e === t) return;
241
- let n = e.split("\n"), r = t.split("\n"), i = Math.max(n.length, r.length), a = [];
242
- for (let e = 0; e < i; e++) n[e] !== r[e] && a.push(e);
243
- return {
244
- lines: a,
245
- numLinesBefore: n.length,
246
- numLinesAfter: r.length,
247
- numLines: i
248
- };
249
- }
250
- globalThis.process.platform.startsWith("win");
251
- var I = Symbol("clack:cancel");
252
- function L(e) {
253
- return e === I;
254
- }
255
- function R(e, t) {
256
- let n = e;
257
- n.isTTY && n.setRawMode(t);
258
- }
259
- var z = (e) => "rows" in e && typeof e.rows == "number" ? e.rows : 20;
260
- function B(e, t) {
261
- if ("~standard" in e) {
262
- let n = e["~standard"].validate(t);
263
- if (n instanceof Promise) throw TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
264
- return n.issues?.at(0)?.message;
265
- }
266
- return e(t);
267
- }
268
- var V = class {
269
- input;
270
- output;
271
- _abortSignal;
272
- rl;
273
- opts;
274
- _render;
275
- _track = !1;
276
- _prevFrame = "";
277
- _subscribers = /* @__PURE__ */ new Map();
278
- _cursor = 0;
279
- state = "initial";
280
- error = "";
281
- value;
282
- userInput = "";
283
- constructor(e, t = !0) {
284
- let { input: n = c, output: r = l, render: i, signal: a, ...o } = e;
285
- this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = i.bind(this), this._track = t, this._abortSignal = a, this.input = n, this.output = r;
286
- }
287
- unsubscribe() {
288
- this._subscribers.clear();
289
- }
290
- setSubscriber(e, t) {
291
- let n = this._subscribers.get(e) ?? [];
292
- n.push(t), this._subscribers.set(e, n);
293
- }
294
- on(e, t) {
295
- this.setSubscriber(e, { cb: t });
296
- }
297
- once(e, t) {
298
- this.setSubscriber(e, {
299
- cb: t,
300
- once: !0
301
- });
302
- }
303
- emit(e, ...t) {
304
- let n = this._subscribers.get(e) ?? [], r = [];
305
- for (let e of n) e.cb(...t), e.once && r.push(() => n.splice(n.indexOf(e), 1));
306
- for (let e of r) e();
307
- }
308
- prompt() {
309
- return new Promise((e) => {
310
- if (this._abortSignal) {
311
- if (this._abortSignal.aborted) return this.state = "cancel", this.close(), e(I);
312
- this._abortSignal.addEventListener("abort", () => {
313
- this.state = "cancel", this.close();
314
- }, { once: !0 });
315
- }
316
- this.rl = u.createInterface({
317
- input: this.input,
318
- tabSize: 2,
319
- prompt: "",
320
- escapeCodeTimeout: 50,
321
- terminal: !0
322
- }), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, !0), this.input.on("keypress", this.onKeypress), R(this.input, !0), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
323
- this.output.write(N.cursor.show), this.output.off("resize", this.render), R(this.input, !1), e(this.value);
324
- }), this.once("cancel", () => {
325
- this.output.write(N.cursor.show), this.output.off("resize", this.render), R(this.input, !1), e(I);
326
- });
327
- });
328
- }
329
- _isActionKey(e, t) {
330
- return e === " ";
331
- }
332
- _shouldSubmit(e, t) {
333
- return !0;
334
- }
335
- _setValue(e) {
336
- this.value = e, this.emit("value", this.value);
337
- }
338
- _setUserInput(e, t) {
339
- this.userInput = e ?? "", this.emit("userInput", this.userInput), t && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
340
- }
341
- _clearUserInput() {
342
- this.rl?.write(null, {
343
- ctrl: !0,
344
- name: "u"
345
- }), this._setUserInput("");
346
- }
347
- onKeypress(e, t) {
348
- if (this._track && t.name !== "return" && (t.name && this._isActionKey(e, t) && this.rl?.write(null, {
349
- ctrl: !0,
350
- name: "h"
351
- }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), t?.name && (!this._track && P.aliases.has(t.name) && this.emit("cursor", P.aliases.get(t.name)), P.actions.has(t.name) && this.emit("cursor", t.name)), e && (e.toLowerCase() === "y" || e.toLowerCase() === "n") && this.emit("confirm", e.toLowerCase() === "y"), this.emit("key", e, t), t?.name === "return" && this._shouldSubmit(e, t)) {
352
- if (this.opts.validate) {
353
- let e = B(this.opts.validate, this.value);
354
- e && (this.error = e instanceof Error ? e.message : e, this.state = "error", this.rl?.write(this.userInput));
355
- }
356
- this.state !== "error" && (this.state = "submit");
357
- }
358
- F([
359
- e,
360
- t?.name,
361
- t?.sequence
362
- ], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
363
- }
364
- close() {
365
- this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write("\n"), R(this.input, !1), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
366
- }
367
- restoreCursor() {
368
- let e = M(this._prevFrame, process.stdout.columns, {
369
- hard: !0,
370
- trim: !1
371
- }).split("\n").length - 1;
372
- this.output.write(N.cursor.move(-999, e * -1));
373
- }
374
- render() {
375
- let e = M(this._render(this) ?? "", process.stdout.columns, {
376
- hard: !0,
377
- trim: !1
378
- });
379
- if (e !== this._prevFrame) {
380
- if (this.state === "initial") this.output.write(N.cursor.hide);
381
- else {
382
- let t = le(this._prevFrame, e), n = z(this.output);
383
- if (this.restoreCursor(), t) {
384
- let r = Math.max(0, t.numLinesAfter - n), i = Math.max(0, t.numLinesBefore - n), a = t.lines.find((e) => e >= r);
385
- if (a === void 0) {
386
- this._prevFrame = e;
387
- return;
388
- }
389
- if (t.lines.length === 1) {
390
- this.output.write(N.cursor.move(0, a - i)), this.output.write(N.erase.lines(1));
391
- let t = e.split("\n");
392
- this.output.write(t[a]), this._prevFrame = e, this.output.write(N.cursor.move(0, t.length - a - 1));
393
- return;
394
- } else if (t.lines.length > 1) {
395
- if (r < i) a = r;
396
- else {
397
- let e = a - i;
398
- e > 0 && this.output.write(N.cursor.move(0, e));
399
- }
400
- this.output.write(N.erase.down());
401
- let t = e.split("\n").slice(a);
402
- this.output.write(t.join("\n")), this._prevFrame = e;
403
- return;
404
- }
405
- }
406
- this.output.write(N.erase.down());
407
- }
408
- this.output.write(e), this.state === "initial" && (this.state = "active"), this._prevFrame = e;
409
- }
410
- }
411
- }, H = class extends V {
412
- get userInputWithCursor() {
413
- if (this.state === "submit") return this.userInput;
414
- let e = this.userInput;
415
- if (this.cursor >= e.length) return `${this.userInput}\u2588`;
416
- let t = e.slice(0, this.cursor), n = e.slice(this.cursor, this.cursor + 1), r = e.slice(this.cursor + 1);
417
- return `${t}${o("inverse", n)}${r}`;
418
- }
419
- get cursor() {
420
- return this._cursor;
421
- }
422
- constructor(e) {
423
- super({
424
- ...e,
425
- initialUserInput: e.initialUserInput ?? e.initialValue
426
- }), this.on("userInput", (e) => {
427
- this._setValue(e);
428
- }), this.on("finalize", () => {
429
- this.value ||= e.defaultValue, this.value === void 0 && (this.value = "");
430
- });
431
- }
432
- };
433
- //#endregion
434
- //#region ../../node_modules/.pnpm/@clack+prompts@1.7.0/node_modules/@clack/prompts/dist/index.mjs
435
- function U() {
436
- return s.platform === "win32" ? !!s.env.CI || !!s.env.WT_SESSION || !!s.env.TERMINUS_SUBLIME || s.env.ConEmuTask === "{cmd::Cmder}" || s.env.TERM_PROGRAM === "Terminus-Sublime" || s.env.TERM_PROGRAM === "vscode" || s.env.TERM === "xterm-256color" || s.env.TERM === "alacritty" || s.env.TERMINAL_EMULATOR === "JetBrains-JediTerm" : s.env.TERM !== "linux";
437
- }
438
- var W = U(), G = (e, t) => W ? e : t, ue = G("◆", "*"), de = G("■", "x"), fe = G("▲", "x"), K = G("◇", "o"), pe = G("┌", "T"), q = G("│", "|"), J = G("└", "—"), me = G("●", "•"), he = G("◆", "*"), ge = G("▲", "!"), _e = G("■", "x"), ve = (e) => {
439
- switch (e) {
440
- case "initial":
441
- case "active": return o("cyan", ue);
442
- case "cancel": return o("red", de);
443
- case "error": return o("yellow", fe);
444
- case "submit": return o("green", K);
445
- }
446
- };
447
- `${o("dim", "↑/↓")}`, `${o("dim", "Space:")}`, `${o("dim", "Enter:")}`;
448
- var Y = {
449
- message: (e = [], { symbol: t = o("gray", q), secondarySymbol: n = o("gray", q), output: r = process.stdout, spacing: i = 1, withGuide: a } = {}) => {
450
- let s = [], c = a ?? P.withGuide, l = c ? n : "", u = c ? `${t} ` : "", d = c ? `${n} ` : "";
451
- for (let e = 0; e < i; e++) s.push(l);
452
- let f = Array.isArray(e) ? e : e.split("\n");
453
- if (f.length > 0) {
454
- let [e, ...r] = f;
455
- e.length > 0 ? s.push(`${u}${e}`) : s.push(c ? t : "");
456
- for (let e of r) e.length > 0 ? s.push(`${d}${e}`) : s.push(c ? n : "");
457
- }
458
- r.write(`${s.join("\n")}
459
- `);
460
- },
461
- info: (e, t) => {
462
- Y.message(e, {
463
- ...t,
464
- symbol: o("blue", me)
465
- });
466
- },
467
- success: (e, t) => {
468
- Y.message(e, {
469
- ...t,
470
- symbol: o("green", he)
471
- });
472
- },
473
- step: (e, t) => {
474
- Y.message(e, {
475
- ...t,
476
- symbol: o("green", K)
477
- });
478
- },
479
- warn: (e, t) => {
480
- Y.message(e, {
481
- ...t,
482
- symbol: o("yellow", ge)
483
- });
484
- },
485
- warning: (e, t) => {
486
- Y.warn(e, t);
487
- },
488
- error: (e, t) => {
489
- Y.message(e, {
490
- ...t,
491
- symbol: o("red", _e)
492
- });
493
- }
494
- }, X = (e = "", t) => {
495
- let n = t?.output ?? process.stdout, r = t?.withGuide ?? P.withGuide ? `${o("gray", J)} ` : "";
496
- n.write(`${r}${o("red", e)}
497
-
498
- `);
499
- }, ye = (e = "", t) => {
500
- let n = t?.output ?? process.stdout, r = t?.withGuide ?? P.withGuide ? `${o("gray", pe)} ` : "";
501
- n.write(`${r}${e}
502
- `);
503
- }, be = (e = "", t) => {
504
- let n = t?.output ?? process.stdout, r = t?.withGuide ?? P.withGuide ? `${o("gray", q)}
505
- ${o("gray", J)} ` : "";
506
- n.write(`${r}${e}
507
-
508
- `);
509
- };
510
- `${o("dim", "↑/↓")}`, `${o("dim", "Enter:")}`, `${o("gray", q)}`;
511
- var Z = (e) => new H({
512
- validate: e.validate,
513
- placeholder: e.placeholder,
514
- defaultValue: e.defaultValue,
515
- initialValue: e.initialValue,
516
- output: e.output,
517
- signal: e.signal,
518
- input: e.input,
519
- render() {
520
- let t = e?.withGuide ?? P.withGuide, n = `${`${t ? `${o("gray", q)}
521
- ` : ""}${ve(this.state)} `}${e.message}
522
- `, r = e.placeholder && e.placeholder.length > 0 ? o("inverse", e.placeholder[0]) + o("dim", e.placeholder.slice(1)) : o(["inverse", "hidden"], "_"), i = this.userInput ? this.userInputWithCursor : r, a = this.value ?? "";
523
- switch (this.state) {
524
- case "error": {
525
- let e = this.error ? ` ${o("yellow", this.error)}` : "", r = t ? `${o("yellow", q)} ` : "", a = t ? o("yellow", J) : "";
526
- return `${n.trim()}
527
- ${r}${i}
528
- ${a}${e}
529
- `;
530
- }
531
- case "submit": {
532
- let e = a ? ` ${o("dim", a)}` : "";
533
- return `${n}${t ? o("gray", q) : ""}${e}`;
534
- }
535
- case "cancel": {
536
- let e = a ? ` ${o(["strikethrough", "dim"], a)}` : "", r = t ? o("gray", q) : "";
537
- return `${n}${r}${e}${a.trim() ? `
538
- ${r}` : ""}`;
539
- }
540
- default: return `${n}${t ? `${o("cyan", q)} ` : ""}${i}
541
- ${t ? o("cyan", J) : ""}
542
- `;
543
- }
544
- }
545
- }).prompt();
546
- //#endregion
547
- //#region src/node/cli/init.ts
548
- async function xe(e) {
549
- ye("typedown");
550
- let t = i.basename(i.resolve(e)), n = await Z({
551
- message: "Project name",
552
- placeholder: t,
553
- defaultValue: t
554
- });
555
- L(n) && (X("Cancelled."), process.exit(0));
556
- let r = await Z({
557
- message: "Site title",
558
- placeholder: n,
559
- defaultValue: n
560
- });
561
- L(r) && (X("Cancelled."), process.exit(0));
562
- let a = await Z({
563
- message: "Site description",
564
- placeholder: "A typedown site",
565
- defaultValue: "A typedown site"
566
- });
567
- L(a) && (X("Cancelled."), process.exit(0)), await Te(e, {
568
- projectName: n,
569
- siteTitle: r,
570
- siteDescription: a
571
- });
572
- let o = ["Done scaffolding."];
573
- e !== "." && o.push(`cd ${e}`), o.push("pnpm install", "pnpm dev"), be(o.join("\n"));
574
- }
575
- function Q(n) {
576
- return `<!doctype html>
577
- <html lang="en">
578
- <head>
579
- <meta charset="UTF-8" />
580
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
581
- <title>${e(n.siteTitle)}</title>
582
- <link
583
- rel="icon"
584
- type="image/svg+xml"
585
- href="${r}"
586
- >
587
- </head>
588
- <body>
589
- <div id="app"></div>
590
- <script
591
- type="module"
592
- src="/${t}"
593
- ><\/script>
594
- </body>
595
- </html>
596
- `;
597
- }
598
- function Se(e) {
599
- return JSON.stringify({
600
- name: e.projectName,
601
- version: "0.0.0",
602
- private: !0,
603
- type: "module",
604
- scripts: {
605
- dev: "typerighter dev",
606
- build: "typerighter build",
607
- preview: "typerighter preview"
608
- },
609
- devDependencies: { typerighter: "^0.1.6" }
610
- }, void 0, 2) + "\n";
611
- }
612
- function Ce() {
613
- return "---\n_type: Article\ntitle: \"Hello, world\"\n---\n\nWelcome to your new typedown site.\n";
614
- }
615
- function we() {
616
- return "---\n_type: schema\nproperties:\n title:\n type: string\n tags:\n type: list[string]\n optional: true\n---\n";
617
- }
618
- async function Te(e, t) {
619
- let n = i.resolve(e), r = i.join(n, "vault", "content"), o = i.join(n, "vault", "schemas");
620
- await a.mkdir(r, { recursive: !0 }), await a.mkdir(o, { recursive: !0 }), await Promise.all([
621
- $(n, "package.json", Se(t)),
622
- $(n, "typedown.yaml", Ee(t)),
623
- $(n, "index.html", Q(t)),
624
- $(o, "Article.td", we(), { shouldLog: !1 }),
625
- $(r, "hello.td", Ce(), { shouldLog: !1 })
626
- ]);
627
- }
628
- function Ee(e) {
629
- return `version: "1.0.0"
630
- vault:
631
- content_dir: vault/content
632
- schema_dir: vault/schemas
633
- site:
634
- title: "${e.siteTitle}"
635
- description: "${e.siteDescription}"
636
- `;
637
- }
638
- async function $(e, t, n, { shouldLog: r = !0 } = {}) {
639
- let o = i.join(e, t);
640
- if (await a.access(o).then(() => !0).catch(() => !1) && r) {
641
- Y.warn(`skip ${t} (already exists)`);
642
- return;
643
- }
644
- await a.writeFile(o, n), r && Y.success(`created ${t}`);
645
- }
646
- //#endregion
647
- export { xe as initialize };