toiljs 0.0.16 → 0.0.20

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 (100) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/README.md +313 -128
  3. package/as-pect.config.js +1 -1
  4. package/build/backend/.tsbuildinfo +1 -1
  5. package/build/backend/index.d.ts +1 -0
  6. package/build/backend/index.js +20 -1
  7. package/build/cli/.tsbuildinfo +1 -1
  8. package/build/cli/index.js +1320 -697
  9. package/build/client/.tsbuildinfo +1 -1
  10. package/build/client/dev/devtools.js +42 -5
  11. package/build/client/errors.d.ts +1 -0
  12. package/build/client/errors.js +3 -0
  13. package/build/client/index.d.ts +2 -0
  14. package/build/client/index.js +2 -0
  15. package/build/client/rpc.d.ts +1 -0
  16. package/build/client/rpc.js +37 -0
  17. package/build/compiler/.tsbuildinfo +1 -1
  18. package/build/compiler/config.js +3 -1
  19. package/build/compiler/docs.js +69 -7
  20. package/build/compiler/generate.js +5 -4
  21. package/build/compiler/index.d.ts +1 -0
  22. package/build/compiler/index.js +30 -1
  23. package/build/compiler/plugin.js +80 -8
  24. package/build/compiler/seo.js +15 -1
  25. package/build/compiler/ssg.js +7 -1
  26. package/build/compiler/vite.js +25 -0
  27. package/build/io/.tsbuildinfo +1 -1
  28. package/build/io/codec.d.ts +54 -0
  29. package/build/io/codec.js +143 -0
  30. package/build/io/index.d.ts +1 -2
  31. package/build/io/index.js +1 -2
  32. package/eslint.config.js +1 -1
  33. package/examples/basic/client/routes/features/index.tsx +1 -1
  34. package/examples/basic/client/routes/io.tsx +6 -7
  35. package/examples/basic/client/routes/rest.tsx +84 -0
  36. package/examples/basic/client/routes/rpc.tsx +43 -0
  37. package/package.json +19 -7
  38. package/presets/prettier-plugin.js +51 -0
  39. package/presets/prettier.json +1 -0
  40. package/server/runtime/README.md +97 -0
  41. package/server/runtime/abort/abort.ts +27 -0
  42. package/server/runtime/env/Server.ts +61 -0
  43. package/server/runtime/envelope.ts +191 -0
  44. package/server/runtime/exports/index.ts +52 -0
  45. package/server/runtime/handlers/ToilHandler.ts +34 -0
  46. package/server/runtime/index.ts +26 -0
  47. package/server/runtime/lang/Potential.ts +5 -0
  48. package/server/runtime/memory.ts +81 -0
  49. package/server/runtime/request.ts +55 -0
  50. package/server/runtime/response.ts +86 -0
  51. package/server/runtime/rest/Rest.ts +39 -0
  52. package/server/runtime/rest/RestHandler.ts +20 -0
  53. package/server/runtime/rest/RouteContext.ts +82 -0
  54. package/server/runtime/rest/match.ts +48 -0
  55. package/server/runtime/tsconfig.json +7 -0
  56. package/src/backend/index.ts +45 -3
  57. package/src/cli/create.ts +16 -6
  58. package/src/cli/diagnostics.ts +81 -0
  59. package/src/cli/doctor.ts +384 -7
  60. package/src/cli/index.ts +11 -2
  61. package/src/client/dev/devtools.tsx +49 -4
  62. package/src/client/errors.ts +11 -0
  63. package/src/client/index.ts +2 -0
  64. package/src/client/rpc.ts +64 -0
  65. package/src/compiler/config.ts +3 -1
  66. package/src/compiler/docs.ts +69 -7
  67. package/src/compiler/generate.ts +6 -5
  68. package/src/compiler/index.ts +50 -1
  69. package/src/compiler/plugin.ts +99 -11
  70. package/src/compiler/seo.ts +23 -3
  71. package/src/compiler/ssg.ts +10 -1
  72. package/src/compiler/vite.ts +34 -0
  73. package/src/io/FastMap.ts +24 -0
  74. package/src/io/FastSet.ts +15 -1
  75. package/src/io/codec.ts +217 -0
  76. package/src/io/index.ts +1 -2
  77. package/src/io/types.ts +2 -1
  78. package/test/assembly/example.spec.ts +14 -4
  79. package/test/doctor.test.ts +65 -0
  80. package/test/errors.test.ts +21 -0
  81. package/test/io.test.ts +65 -41
  82. package/test/prettier-plugin.test.ts +46 -0
  83. package/test/rpc.test.ts +50 -0
  84. package/tests/data-parity/generated-parity.ts +99 -0
  85. package/tests/data-parity/parity.ts +80 -0
  86. package/tests/data-parity/spec.ts +46 -0
  87. package/tsconfig.json +1 -1
  88. package/tsconfig.server.json +1 -1
  89. package/build/io/BinaryReader.d.ts +0 -44
  90. package/build/io/BinaryReader.js +0 -244
  91. package/build/io/BinaryWriter.d.ts +0 -44
  92. package/build/io/BinaryWriter.js +0 -297
  93. package/build/server/release.wasm +0 -0
  94. package/build/server/release.wat +0 -9
  95. package/src/io/BinaryReader.ts +0 -340
  96. package/src/io/BinaryWriter.ts +0 -385
  97. package/src/server/index.ts +0 -10
  98. package/src/server/main.ts +0 -13
  99. package/src/server/tsconfig.json +0 -4
  100. package/toilconfig.json +0 -30
@@ -32,15 +32,15 @@ var require_src = __commonJS({
32
32
  var ESC2 = "\x1B";
33
33
  var CSI2 = `${ESC2}[`;
34
34
  var beep = "\x07";
35
- var cursor = {
36
- to(x3, y) {
37
- if (!y) return `${CSI2}${x3 + 1}G`;
38
- return `${CSI2}${y + 1};${x3 + 1}H`;
35
+ var cursor3 = {
36
+ to(x, y) {
37
+ if (!y) return `${CSI2}${x + 1}G`;
38
+ return `${CSI2}${y + 1};${x + 1}H`;
39
39
  },
40
- move(x3, y) {
40
+ move(x, y) {
41
41
  let ret = "";
42
- if (x3 < 0) ret += `${CSI2}${-x3}D`;
43
- else if (x3 > 0) ret += `${CSI2}${x3}C`;
42
+ if (x < 0) ret += `${CSI2}${-x}D`;
43
+ else if (x > 0) ret += `${CSI2}${x}C`;
44
44
  if (y < 0) ret += `${CSI2}${-y}A`;
45
45
  else if (y > 0) ret += `${CSI2}${y}B`;
46
46
  return ret;
@@ -61,7 +61,7 @@ var require_src = __commonJS({
61
61
  up: (count = 1) => `${CSI2}S`.repeat(count),
62
62
  down: (count = 1) => `${CSI2}T`.repeat(count)
63
63
  };
64
- var erase = {
64
+ var erase3 = {
65
65
  screen: `${CSI2}2J`,
66
66
  up: (count = 1) => `${CSI2}1J`.repeat(count),
67
67
  down: (count = 1) => `${CSI2}J`.repeat(count),
@@ -70,82 +70,82 @@ var require_src = __commonJS({
70
70
  lineStart: `${CSI2}1K`,
71
71
  lines(count) {
72
72
  let clear = "";
73
- for (let i = 0; i < count; i++)
74
- clear += this.line + (i < count - 1 ? cursor.up() : "");
73
+ for (let i2 = 0; i2 < count; i2++)
74
+ clear += this.line + (i2 < count - 1 ? cursor3.up() : "");
75
75
  if (count)
76
- clear += cursor.left;
76
+ clear += cursor3.left;
77
77
  return clear;
78
78
  }
79
79
  };
80
- module.exports = { cursor, scroll, erase, beep };
80
+ module.exports = { cursor: cursor3, scroll, erase: erase3, beep };
81
81
  }
82
82
  });
83
83
 
84
84
  // node_modules/picocolors/picocolors.js
85
85
  var require_picocolors = __commonJS({
86
86
  "node_modules/picocolors/picocolors.js"(exports, module) {
87
- var p2 = process || {};
88
- var argv = p2.argv || [];
89
- var env = p2.env || {};
90
- var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p2.platform === "win32" || (p2.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
87
+ var p = process || {};
88
+ var argv = p.argv || [];
89
+ var env = p.env || {};
90
+ var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
91
91
  var formatter = (open, close, replace = open) => (input) => {
92
92
  let string = "" + input, index = string.indexOf(close, open.length);
93
93
  return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
94
94
  };
95
95
  var replaceClose = (string, close, replace, index) => {
96
- let result = "", cursor = 0;
96
+ let result = "", cursor3 = 0;
97
97
  do {
98
- result += string.substring(cursor, index) + replace;
99
- cursor = index + close.length;
100
- index = string.indexOf(close, cursor);
98
+ result += string.substring(cursor3, index) + replace;
99
+ cursor3 = index + close.length;
100
+ index = string.indexOf(close, cursor3);
101
101
  } while (~index);
102
- return result + string.substring(cursor);
102
+ return result + string.substring(cursor3);
103
103
  };
104
104
  var createColors = (enabled = isColorSupported) => {
105
- let f2 = enabled ? formatter : () => String;
105
+ let f = enabled ? formatter : () => String;
106
106
  return {
107
107
  isColorSupported: enabled,
108
- reset: f2("\x1B[0m", "\x1B[0m"),
109
- bold: f2("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
110
- dim: f2("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
111
- italic: f2("\x1B[3m", "\x1B[23m"),
112
- underline: f2("\x1B[4m", "\x1B[24m"),
113
- inverse: f2("\x1B[7m", "\x1B[27m"),
114
- hidden: f2("\x1B[8m", "\x1B[28m"),
115
- strikethrough: f2("\x1B[9m", "\x1B[29m"),
116
- black: f2("\x1B[30m", "\x1B[39m"),
117
- red: f2("\x1B[31m", "\x1B[39m"),
118
- green: f2("\x1B[32m", "\x1B[39m"),
119
- yellow: f2("\x1B[33m", "\x1B[39m"),
120
- blue: f2("\x1B[34m", "\x1B[39m"),
121
- magenta: f2("\x1B[35m", "\x1B[39m"),
122
- cyan: f2("\x1B[36m", "\x1B[39m"),
123
- white: f2("\x1B[37m", "\x1B[39m"),
124
- gray: f2("\x1B[90m", "\x1B[39m"),
125
- bgBlack: f2("\x1B[40m", "\x1B[49m"),
126
- bgRed: f2("\x1B[41m", "\x1B[49m"),
127
- bgGreen: f2("\x1B[42m", "\x1B[49m"),
128
- bgYellow: f2("\x1B[43m", "\x1B[49m"),
129
- bgBlue: f2("\x1B[44m", "\x1B[49m"),
130
- bgMagenta: f2("\x1B[45m", "\x1B[49m"),
131
- bgCyan: f2("\x1B[46m", "\x1B[49m"),
132
- bgWhite: f2("\x1B[47m", "\x1B[49m"),
133
- blackBright: f2("\x1B[90m", "\x1B[39m"),
134
- redBright: f2("\x1B[91m", "\x1B[39m"),
135
- greenBright: f2("\x1B[92m", "\x1B[39m"),
136
- yellowBright: f2("\x1B[93m", "\x1B[39m"),
137
- blueBright: f2("\x1B[94m", "\x1B[39m"),
138
- magentaBright: f2("\x1B[95m", "\x1B[39m"),
139
- cyanBright: f2("\x1B[96m", "\x1B[39m"),
140
- whiteBright: f2("\x1B[97m", "\x1B[39m"),
141
- bgBlackBright: f2("\x1B[100m", "\x1B[49m"),
142
- bgRedBright: f2("\x1B[101m", "\x1B[49m"),
143
- bgGreenBright: f2("\x1B[102m", "\x1B[49m"),
144
- bgYellowBright: f2("\x1B[103m", "\x1B[49m"),
145
- bgBlueBright: f2("\x1B[104m", "\x1B[49m"),
146
- bgMagentaBright: f2("\x1B[105m", "\x1B[49m"),
147
- bgCyanBright: f2("\x1B[106m", "\x1B[49m"),
148
- bgWhiteBright: f2("\x1B[107m", "\x1B[49m")
108
+ reset: f("\x1B[0m", "\x1B[0m"),
109
+ bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
110
+ dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
111
+ italic: f("\x1B[3m", "\x1B[23m"),
112
+ underline: f("\x1B[4m", "\x1B[24m"),
113
+ inverse: f("\x1B[7m", "\x1B[27m"),
114
+ hidden: f("\x1B[8m", "\x1B[28m"),
115
+ strikethrough: f("\x1B[9m", "\x1B[29m"),
116
+ black: f("\x1B[30m", "\x1B[39m"),
117
+ red: f("\x1B[31m", "\x1B[39m"),
118
+ green: f("\x1B[32m", "\x1B[39m"),
119
+ yellow: f("\x1B[33m", "\x1B[39m"),
120
+ blue: f("\x1B[34m", "\x1B[39m"),
121
+ magenta: f("\x1B[35m", "\x1B[39m"),
122
+ cyan: f("\x1B[36m", "\x1B[39m"),
123
+ white: f("\x1B[37m", "\x1B[39m"),
124
+ gray: f("\x1B[90m", "\x1B[39m"),
125
+ bgBlack: f("\x1B[40m", "\x1B[49m"),
126
+ bgRed: f("\x1B[41m", "\x1B[49m"),
127
+ bgGreen: f("\x1B[42m", "\x1B[49m"),
128
+ bgYellow: f("\x1B[43m", "\x1B[49m"),
129
+ bgBlue: f("\x1B[44m", "\x1B[49m"),
130
+ bgMagenta: f("\x1B[45m", "\x1B[49m"),
131
+ bgCyan: f("\x1B[46m", "\x1B[49m"),
132
+ bgWhite: f("\x1B[47m", "\x1B[49m"),
133
+ blackBright: f("\x1B[90m", "\x1B[39m"),
134
+ redBright: f("\x1B[91m", "\x1B[39m"),
135
+ greenBright: f("\x1B[92m", "\x1B[39m"),
136
+ yellowBright: f("\x1B[93m", "\x1B[39m"),
137
+ blueBright: f("\x1B[94m", "\x1B[39m"),
138
+ magentaBright: f("\x1B[95m", "\x1B[39m"),
139
+ cyanBright: f("\x1B[96m", "\x1B[39m"),
140
+ whiteBright: f("\x1B[97m", "\x1B[39m"),
141
+ bgBlackBright: f("\x1B[100m", "\x1B[49m"),
142
+ bgRedBright: f("\x1B[101m", "\x1B[49m"),
143
+ bgGreenBright: f("\x1B[102m", "\x1B[49m"),
144
+ bgYellowBright: f("\x1B[103m", "\x1B[49m"),
145
+ bgBlueBright: f("\x1B[104m", "\x1B[49m"),
146
+ bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
147
+ bgCyanBright: f("\x1B[106m", "\x1B[49m"),
148
+ bgWhiteBright: f("\x1B[107m", "\x1B[49m")
149
149
  };
150
150
  };
151
151
  module.exports = createColors();
@@ -161,10 +161,10 @@ import fs2 from "node:fs/promises";
161
161
  import path2 from "node:path";
162
162
 
163
163
  // node_modules/@clack/core/dist/index.mjs
164
- import { styleText as v } from "node:util";
165
- import { stdout as x, stdin as D } from "node:process";
166
- import * as b from "node:readline";
167
- import G from "node:readline";
164
+ import { styleText } from "node:util";
165
+ import { stdout, stdin } from "node:process";
166
+ import * as l from "node:readline";
167
+ import l__default from "node:readline";
168
168
 
169
169
  // node_modules/fast-string-truncated-width/dist/utils.js
170
170
  var getCodePointsLength = /* @__PURE__ */ (() => {
@@ -178,11 +178,11 @@ var getCodePointsLength = /* @__PURE__ */ (() => {
178
178
  return input.length - surrogatePairsNr;
179
179
  };
180
180
  })();
181
- var isFullWidth = (x3) => {
182
- return x3 === 12288 || x3 >= 65281 && x3 <= 65376 || x3 >= 65504 && x3 <= 65510;
181
+ var isFullWidth = (x) => {
182
+ return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
183
183
  };
184
- var isWideNotCJKTNotEmoji = (x3) => {
185
- return x3 === 8987 || x3 === 9001 || x3 >= 12272 && x3 <= 12287 || x3 >= 12289 && x3 <= 12350 || x3 >= 12441 && x3 <= 12543 || x3 >= 12549 && x3 <= 12591 || x3 >= 12593 && x3 <= 12686 || x3 >= 12688 && x3 <= 12771 || x3 >= 12783 && x3 <= 12830 || x3 >= 12832 && x3 <= 12871 || x3 >= 12880 && x3 <= 19903 || x3 >= 65040 && x3 <= 65049 || x3 >= 65072 && x3 <= 65106 || x3 >= 65108 && x3 <= 65126 || x3 >= 65128 && x3 <= 65131 || x3 >= 127488 && x3 <= 127490 || x3 >= 127504 && x3 <= 127547 || x3 >= 127552 && x3 <= 127560 || x3 >= 131072 && x3 <= 196605 || x3 >= 196608 && x3 <= 262141;
184
+ var isWideNotCJKTNotEmoji = (x) => {
185
+ return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
186
186
  };
187
187
 
188
188
  // node_modules/fast-string-truncated-width/dist/index.js
@@ -252,8 +252,8 @@ var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {})
252
252
  if (index >= length) {
253
253
  break outer;
254
254
  }
255
- for (let i = 0, l = PARSE_BLOCKS.length; i < l; i++) {
256
- const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
255
+ for (let i2 = 0, l2 = PARSE_BLOCKS.length; i2 < l2; i2++) {
256
+ const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i2];
257
257
  BLOCK_RE.lastIndex = index;
258
258
  if (BLOCK_RE.test(input)) {
259
259
  lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
@@ -456,8 +456,8 @@ var exec = (string, columns, options = {}) => {
456
456
  }
457
457
  const preString = rows.join("\n");
458
458
  let inSurrogate = false;
459
- for (let i = 0; i < preString.length; i++) {
460
- const character = preString[i];
459
+ for (let i2 = 0; i2 < preString.length; i2++) {
460
+ const character = preString[i2];
461
461
  returnValue += character;
462
462
  if (!inSurrogate) {
463
463
  inSurrogate = character >= "\uD800" && character <= "\uDBFF";
@@ -468,7 +468,7 @@ var exec = (string, columns, options = {}) => {
468
468
  inSurrogate = false;
469
469
  }
470
470
  if (character === ESC || character === CSI) {
471
- GROUP_REGEX.lastIndex = i + 1;
471
+ GROUP_REGEX.lastIndex = i2 + 1;
472
472
  const groupsResult = GROUP_REGEX.exec(preString);
473
473
  const groups = groupsResult?.groups;
474
474
  if (groups?.code !== void 0) {
@@ -478,7 +478,7 @@ var exec = (string, columns, options = {}) => {
478
478
  escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
479
479
  }
480
480
  }
481
- if (preString[i + 1] === "\n") {
481
+ if (preString[i2 + 1] === "\n") {
482
482
  if (escapeUrl) {
483
483
  returnValue += wrapAnsiHyperlink("");
484
484
  }
@@ -504,78 +504,144 @@ function wrapAnsi(string, columns, options) {
504
504
 
505
505
  // node_modules/@clack/core/dist/index.mjs
506
506
  var import_sisteransi = __toESM(require_src(), 1);
507
- import { ReadStream as O } from "node:tty";
508
- function f(r, t, s) {
509
- if (!s.some((o) => !o.disabled)) return r;
510
- const e2 = r + t, i = Math.max(s.length - 1, 0), n = e2 < 0 ? i : e2 > i ? 0 : e2;
511
- return s[n].disabled ? f(n, t < 0 ? -1 : 1, s) : n;
512
- }
513
- var K = ["up", "down", "left", "right", "space", "enter", "cancel"];
514
- var j = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
515
- var h = { actions: new Set(K), aliases: /* @__PURE__ */ new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true, date: { monthNames: [...j], messages: { required: "Please enter a valid date", invalidMonth: "There are only 12 months in a year", invalidDay: (r, t) => `There are only ${r} days in ${t}`, afterMin: (r) => `Date must be on or after ${r.toISOString().slice(0, 10)}`, beforeMax: (r) => `Date must be on or before ${r.toISOString().slice(0, 10)}` } } };
516
- function C(r, t) {
517
- if (typeof r == "string") return h.aliases.get(r) === t;
518
- for (const s of r) if (s !== void 0 && C(s, t)) return true;
507
+ import { ReadStream } from "node:tty";
508
+ function findCursor(s, o2, l2) {
509
+ if (!l2.some((r2) => !r2.disabled))
510
+ return s;
511
+ const t2 = s + o2, n2 = Math.max(l2.length - 1, 0), e = t2 < 0 ? n2 : t2 > n2 ? 0 : t2;
512
+ return l2[e].disabled ? findCursor(e, o2 < 0 ? -1 : 1, l2) : e;
513
+ }
514
+ var a$2 = ["up", "down", "left", "right", "space", "enter", "cancel"];
515
+ var t = [
516
+ "January",
517
+ "February",
518
+ "March",
519
+ "April",
520
+ "May",
521
+ "June",
522
+ "July",
523
+ "August",
524
+ "September",
525
+ "October",
526
+ "November",
527
+ "December"
528
+ ];
529
+ var settings = {
530
+ actions: new Set(a$2),
531
+ aliases: /* @__PURE__ */ new Map([
532
+ // vim support
533
+ ["k", "up"],
534
+ ["j", "down"],
535
+ ["h", "left"],
536
+ ["l", "right"],
537
+ ["", "cancel"],
538
+ // opinionated defaults!
539
+ ["escape", "cancel"]
540
+ ]),
541
+ messages: {
542
+ cancel: "Canceled",
543
+ error: "Something went wrong"
544
+ },
545
+ withGuide: true,
546
+ date: {
547
+ monthNames: [...t],
548
+ messages: {
549
+ required: "Please enter a valid date",
550
+ invalidMonth: "There are only 12 months in a year",
551
+ invalidDay: (n2, e) => `There are only ${n2} days in ${e}`,
552
+ afterMin: (n2) => `Date must be on or after ${n2.toISOString().slice(0, 10)}`,
553
+ beforeMax: (n2) => `Date must be on or before ${n2.toISOString().slice(0, 10)}`
554
+ }
555
+ }
556
+ };
557
+ function isActionKey(n2, e) {
558
+ if (typeof n2 == "string")
559
+ return settings.aliases.get(n2) === e;
560
+ for (const s of n2)
561
+ if (s !== void 0 && isActionKey(s, e))
562
+ return true;
519
563
  return false;
520
564
  }
521
- function Y(r, t) {
522
- if (r === t) return;
523
- const s = r.split(`
524
- `), e2 = t.split(`
525
- `), i = Math.max(s.length, e2.length), n = [];
526
- for (let o = 0; o < i; o++) s[o] !== e2[o] && n.push(o);
527
- return { lines: n, numLinesBefore: s.length, numLinesAfter: e2.length, numLines: i };
528
- }
529
- var q = globalThis.process.platform.startsWith("win");
530
- var k = /* @__PURE__ */ Symbol("clack:cancel");
531
- function R(r) {
532
- return r === k;
533
- }
534
- function w(r, t) {
535
- const s = r;
536
- s.isTTY && s.setRawMode(t);
537
- }
538
- function W({ input: r = D, output: t = x, overwrite: s = true, hideCursor: e2 = true } = {}) {
539
- const i = b.createInterface({ input: r, output: t, prompt: "", tabSize: 1 });
540
- b.emitKeypressEvents(r, i), r instanceof O && r.isTTY && r.setRawMode(true);
541
- const n = (o, { name: u, sequence: a }) => {
542
- const l = String(o);
543
- if (C([l, u, a], "cancel")) {
544
- e2 && t.write(import_sisteransi.cursor.show), process.exit(0);
565
+ function diffLines(i2, s) {
566
+ if (i2 === s) return;
567
+ const e = i2.split(`
568
+ `), t2 = s.split(`
569
+ `), r2 = Math.max(e.length, t2.length), f = [];
570
+ for (let n2 = 0; n2 < r2; n2++)
571
+ e[n2] !== t2[n2] && f.push(n2);
572
+ return {
573
+ lines: f,
574
+ numLinesBefore: e.length,
575
+ numLinesAfter: t2.length,
576
+ numLines: r2
577
+ };
578
+ }
579
+ var R = globalThis.process.platform.startsWith("win");
580
+ var CANCEL_SYMBOL = /* @__PURE__ */ Symbol("clack:cancel");
581
+ function isCancel(e) {
582
+ return e === CANCEL_SYMBOL;
583
+ }
584
+ function setRawMode(e, r2) {
585
+ const o2 = e;
586
+ o2.isTTY && o2.setRawMode(r2);
587
+ }
588
+ function block({
589
+ input: e = stdin,
590
+ output: r2 = stdout,
591
+ overwrite: o2 = true,
592
+ hideCursor: t2 = true
593
+ } = {}) {
594
+ const s = l.createInterface({
595
+ input: e,
596
+ output: r2,
597
+ prompt: "",
598
+ tabSize: 1
599
+ });
600
+ l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
601
+ const n2 = (f, { name: a3, sequence: p }) => {
602
+ const c2 = String(f);
603
+ if (isActionKey([c2, a3, p], "cancel")) {
604
+ t2 && r2.write(import_sisteransi.cursor.show), process.exit(0);
545
605
  return;
546
606
  }
547
- if (!s) return;
548
- const c = u === "return" ? 0 : -1, y = u === "return" ? -1 : 0;
549
- b.moveCursor(t, c, y, () => {
550
- b.clearLine(t, 1, () => {
551
- r.once("keypress", n);
607
+ if (!o2) return;
608
+ const i2 = a3 === "return" ? 0 : -1, m = a3 === "return" ? -1 : 0;
609
+ l.moveCursor(r2, i2, m, () => {
610
+ l.clearLine(r2, 1, () => {
611
+ e.once("keypress", n2);
552
612
  });
553
613
  });
554
614
  };
555
- return e2 && t.write(import_sisteransi.cursor.hide), r.once("keypress", n), () => {
556
- r.off("keypress", n), e2 && t.write(import_sisteransi.cursor.show), r instanceof O && r.isTTY && !q && r.setRawMode(false), i.terminal = false, i.close();
615
+ return t2 && r2.write(import_sisteransi.cursor.hide), e.once("keypress", n2), () => {
616
+ e.off("keypress", n2), t2 && r2.write(import_sisteransi.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
557
617
  };
558
618
  }
559
- var A = (r) => "columns" in r && typeof r.columns == "number" ? r.columns : 80;
560
- var L = (r) => "rows" in r && typeof r.rows == "number" ? r.rows : 20;
561
- function B(r, t, s, e2 = s, i = s, n) {
562
- const o = A(r ?? x);
563
- return wrapAnsi(t, o - s.length, { hard: true, trim: false }).split(`
564
- `).map((u, a, l) => {
565
- const c = n ? n(u, a) : u;
566
- return a === 0 ? `${e2}${c}` : a === l.length - 1 ? `${i}${c}` : `${s}${c}`;
619
+ var getColumns = (e) => "columns" in e && typeof e.columns == "number" ? e.columns : 80;
620
+ var getRows = (e) => "rows" in e && typeof e.rows == "number" ? e.rows : 20;
621
+ function wrapTextWithPrefix(e, r2, o2, t2 = o2, s = o2, n2) {
622
+ const f = getColumns(e ?? stdout);
623
+ return wrapAnsi(r2, f - o2.length, {
624
+ hard: true,
625
+ trim: false
626
+ }).split(`
627
+ `).map((c2, i2, m) => {
628
+ const d2 = n2 ? n2(c2, i2) : c2;
629
+ return i2 === 0 ? `${t2}${d2}` : i2 === m.length - 1 ? `${s}${d2}` : `${o2}${d2}`;
567
630
  }).join(`
568
631
  `);
569
632
  }
570
- function P(r, t) {
571
- if ("~standard" in r) {
572
- const s = r["~standard"].validate(t);
573
- if (s instanceof Promise) throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
574
- return s.issues?.at(0)?.message;
633
+ function runValidation(e, n2) {
634
+ if ("~standard" in e) {
635
+ const a3 = e["~standard"].validate(n2);
636
+ if (a3 instanceof Promise)
637
+ throw new TypeError(
638
+ "Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic."
639
+ );
640
+ return a3.issues?.at(0)?.message;
575
641
  }
576
- return r(t);
642
+ return e(n2);
577
643
  }
578
- var m = class {
644
+ var V = class {
579
645
  input;
580
646
  output;
581
647
  _abortSignal;
@@ -590,171 +656,215 @@ var m = class {
590
656
  error = "";
591
657
  value;
592
658
  userInput = "";
593
- constructor(t, s = true) {
594
- const { input: e2 = D, output: i = x, render: n, signal: o, ...u } = t;
595
- this.opts = u, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = o, this.input = e2, this.output = i;
659
+ constructor(t2, e = true) {
660
+ const { input: i2 = stdin, output: n2 = stdout, render: s, signal: r2, ...o2 } = t2;
661
+ this.opts = o2, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = s.bind(this), this._track = e, this._abortSignal = r2, this.input = i2, this.output = n2;
596
662
  }
663
+ /**
664
+ * Unsubscribe all listeners
665
+ */
597
666
  unsubscribe() {
598
667
  this._subscribers.clear();
599
668
  }
600
- setSubscriber(t, s) {
601
- const e2 = this._subscribers.get(t) ?? [];
602
- e2.push(s), this._subscribers.set(t, e2);
603
- }
604
- on(t, s) {
605
- this.setSubscriber(t, { cb: s });
606
- }
607
- once(t, s) {
608
- this.setSubscriber(t, { cb: s, once: true });
609
- }
610
- emit(t, ...s) {
611
- const e2 = this._subscribers.get(t) ?? [], i = [];
612
- for (const n of e2) n.cb(...s), n.once && i.push(() => e2.splice(e2.indexOf(n), 1));
613
- for (const n of i) n();
669
+ /**
670
+ * Set a subscriber with opts
671
+ * @param event - The event name
672
+ */
673
+ setSubscriber(t2, e) {
674
+ const i2 = this._subscribers.get(t2) ?? [];
675
+ i2.push(e), this._subscribers.set(t2, i2);
676
+ }
677
+ /**
678
+ * Subscribe to an event
679
+ * @param event - The event name
680
+ * @param cb - The callback
681
+ */
682
+ on(t2, e) {
683
+ this.setSubscriber(t2, { cb: e });
684
+ }
685
+ /**
686
+ * Subscribe to an event once
687
+ * @param event - The event name
688
+ * @param cb - The callback
689
+ */
690
+ once(t2, e) {
691
+ this.setSubscriber(t2, { cb: e, once: true });
692
+ }
693
+ /**
694
+ * Emit an event with data
695
+ * @param event - The event name
696
+ * @param data - The data to pass to the callback
697
+ */
698
+ emit(t2, ...e) {
699
+ const i2 = this._subscribers.get(t2) ?? [], n2 = [];
700
+ for (const s of i2)
701
+ s.cb(...e), s.once && n2.push(() => i2.splice(i2.indexOf(s), 1));
702
+ for (const s of n2)
703
+ s();
614
704
  }
615
705
  prompt() {
616
- return new Promise((t) => {
706
+ return new Promise((t2) => {
617
707
  if (this._abortSignal) {
618
- if (this._abortSignal.aborted) return this.state = "cancel", this.close(), t(k);
619
- this._abortSignal.addEventListener("abort", () => {
620
- this.state = "cancel", this.close();
621
- }, { once: true });
708
+ if (this._abortSignal.aborted)
709
+ return this.state = "cancel", this.close(), t2(CANCEL_SYMBOL);
710
+ this._abortSignal.addEventListener(
711
+ "abort",
712
+ () => {
713
+ this.state = "cancel", this.close();
714
+ },
715
+ { once: true }
716
+ );
622
717
  }
623
- this.rl = G.createInterface({ input: this.input, tabSize: 2, prompt: "", escapeCodeTimeout: 50, terminal: true }), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), w(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
624
- this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), w(this.input, false), t(this.value);
718
+ this.rl = l__default.createInterface({
719
+ input: this.input,
720
+ tabSize: 2,
721
+ prompt: "",
722
+ escapeCodeTimeout: 50,
723
+ terminal: true
724
+ }), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), setRawMode(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
725
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(this.value);
625
726
  }), this.once("cancel", () => {
626
- this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), w(this.input, false), t(k);
727
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(CANCEL_SYMBOL);
627
728
  });
628
729
  });
629
730
  }
630
- _isActionKey(t, s) {
631
- return t === " ";
731
+ _isActionKey(t2, e) {
732
+ return t2 === " ";
632
733
  }
633
- _shouldSubmit(t, s) {
734
+ _shouldSubmit(t2, e) {
634
735
  return true;
635
736
  }
636
- _setValue(t) {
637
- this.value = t, this.emit("value", this.value);
737
+ _setValue(t2) {
738
+ this.value = t2, this.emit("value", this.value);
638
739
  }
639
- _setUserInput(t, s) {
640
- this.userInput = t ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
740
+ _setUserInput(t2, e) {
741
+ this.userInput = t2 ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
641
742
  }
642
743
  _clearUserInput() {
643
744
  this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
644
745
  }
645
- onKeypress(t, s) {
646
- if (this._track && s.name !== "return" && (s.name && this._isActionKey(t, s) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && h.aliases.has(s.name) && this.emit("cursor", h.aliases.get(s.name)), h.actions.has(s.name) && this.emit("cursor", s.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t, s), s?.name === "return" && this._shouldSubmit(t, s)) {
746
+ onKeypress(t2, e) {
747
+ if (this._track && e.name !== "return" && (e.name && this._isActionKey(t2, e) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), e?.name && (!this._track && settings.aliases.has(e.name) && this.emit("cursor", settings.aliases.get(e.name)), settings.actions.has(e.name) && this.emit("cursor", e.name)), t2 && (t2.toLowerCase() === "y" || t2.toLowerCase() === "n") && this.emit("confirm", t2.toLowerCase() === "y"), this.emit("key", t2, e), e?.name === "return" && this._shouldSubmit(t2, e)) {
647
748
  if (this.opts.validate) {
648
- const e2 = P(this.opts.validate, this.value);
649
- e2 && (this.error = e2 instanceof Error ? e2.message : e2, this.state = "error", this.rl?.write(this.userInput));
749
+ const i2 = runValidation(this.opts.validate, this.value);
750
+ i2 && (this.error = i2 instanceof Error ? i2.message : i2, this.state = "error", this.rl?.write(this.userInput));
650
751
  }
651
752
  this.state !== "error" && (this.state = "submit");
652
753
  }
653
- C([t, s?.name, s?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
754
+ isActionKey([t2, e?.name, e?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
654
755
  }
655
756
  close() {
656
757
  this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
657
- `), w(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
758
+ `), setRawMode(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
658
759
  }
659
760
  restoreCursor() {
660
- const t = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
761
+ const t2 = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
661
762
  `).length - 1;
662
- this.output.write(import_sisteransi.cursor.move(-999, t * -1));
763
+ this.output.write(import_sisteransi.cursor.move(-999, t2 * -1));
663
764
  }
664
765
  render() {
665
- const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, { hard: true, trim: false });
666
- if (t !== this._prevFrame) {
667
- if (this.state === "initial") this.output.write(import_sisteransi.cursor.hide);
766
+ const t2 = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
767
+ hard: true,
768
+ trim: false
769
+ });
770
+ if (t2 !== this._prevFrame) {
771
+ if (this.state === "initial")
772
+ this.output.write(import_sisteransi.cursor.hide);
668
773
  else {
669
- const s = Y(this._prevFrame, t), e2 = L(this.output);
670
- if (this.restoreCursor(), s) {
671
- const i = Math.max(0, s.numLinesAfter - e2), n = Math.max(0, s.numLinesBefore - e2);
672
- let o = s.lines.find((u) => u >= i);
673
- if (o === void 0) {
674
- this._prevFrame = t;
774
+ const e = diffLines(this._prevFrame, t2), i2 = getRows(this.output);
775
+ if (this.restoreCursor(), e) {
776
+ const n2 = Math.max(0, e.numLinesAfter - i2), s = Math.max(0, e.numLinesBefore - i2);
777
+ let r2 = e.lines.find((o2) => o2 >= n2);
778
+ if (r2 === void 0) {
779
+ this._prevFrame = t2;
675
780
  return;
676
781
  }
677
- if (s.lines.length === 1) {
678
- this.output.write(import_sisteransi.cursor.move(0, o - n)), this.output.write(import_sisteransi.erase.lines(1));
679
- const u = t.split(`
782
+ if (e.lines.length === 1) {
783
+ this.output.write(import_sisteransi.cursor.move(0, r2 - s)), this.output.write(import_sisteransi.erase.lines(1));
784
+ const o2 = t2.split(`
680
785
  `);
681
- this.output.write(u[o]), this._prevFrame = t, this.output.write(import_sisteransi.cursor.move(0, u.length - o - 1));
786
+ this.output.write(o2[r2]), this._prevFrame = t2, this.output.write(import_sisteransi.cursor.move(0, o2.length - r2 - 1));
682
787
  return;
683
- } else if (s.lines.length > 1) {
684
- if (i < n) o = i;
788
+ } else if (e.lines.length > 1) {
789
+ if (n2 < s)
790
+ r2 = n2;
685
791
  else {
686
- const a = o - n;
687
- a > 0 && this.output.write(import_sisteransi.cursor.move(0, a));
792
+ const h2 = r2 - s;
793
+ h2 > 0 && this.output.write(import_sisteransi.cursor.move(0, h2));
688
794
  }
689
795
  this.output.write(import_sisteransi.erase.down());
690
- const u = t.split(`
691
- `).slice(o);
692
- this.output.write(u.join(`
693
- `)), this._prevFrame = t;
796
+ const f = t2.split(`
797
+ `).slice(r2);
798
+ this.output.write(f.join(`
799
+ `)), this._prevFrame = t2;
694
800
  return;
695
801
  }
696
802
  }
697
803
  this.output.write(import_sisteransi.erase.down());
698
804
  }
699
- this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
805
+ this.output.write(t2), this.state === "initial" && (this.state = "active"), this._prevFrame = t2;
700
806
  }
701
807
  }
702
808
  };
703
- var Z = class extends m {
809
+ var r = class extends V {
704
810
  get cursor() {
705
811
  return this.value ? 0 : 1;
706
812
  }
707
813
  get _value() {
708
814
  return this.cursor === 0;
709
815
  }
710
- constructor(t) {
711
- super(t, false), this.value = !!t.initialValue, this.on("userInput", () => {
816
+ constructor(t2) {
817
+ super(t2, false), this.value = !!t2.initialValue, this.on("userInput", () => {
712
818
  this.value = this._value;
713
- }), this.on("confirm", (s) => {
714
- this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = s, this.state = "submit", this.close();
819
+ }), this.on("confirm", (i2) => {
820
+ this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = i2, this.state = "submit", this.close();
715
821
  }), this.on("cursor", () => {
716
822
  this.value = !this.value;
717
823
  });
718
824
  }
719
825
  };
720
- var ut = class extends m {
826
+ var a$1 = class a extends V {
721
827
  options;
722
828
  cursor = 0;
723
829
  get _value() {
724
830
  return this.options[this.cursor].value;
725
831
  }
726
832
  get _enabledOptions() {
727
- return this.options.filter((t) => t.disabled !== true);
833
+ return this.options.filter((e) => e.disabled !== true);
728
834
  }
729
835
  toggleAll() {
730
- const t = this._enabledOptions, s = this.value !== void 0 && this.value.length === t.length;
731
- this.value = s ? [] : t.map((e2) => e2.value);
836
+ const e = this._enabledOptions, i2 = this.value !== void 0 && this.value.length === e.length;
837
+ this.value = i2 ? [] : e.map((t2) => t2.value);
732
838
  }
733
839
  toggleInvert() {
734
- const t = this.value;
735
- if (!t) return;
736
- const s = this._enabledOptions.filter((e2) => !t.includes(e2.value));
737
- this.value = s.map((e2) => e2.value);
840
+ const e = this.value;
841
+ if (!e)
842
+ return;
843
+ const i2 = this._enabledOptions.filter((t2) => !e.includes(t2.value));
844
+ this.value = i2.map((t2) => t2.value);
738
845
  }
739
846
  toggleValue() {
740
847
  this.value === void 0 && (this.value = []);
741
- const t = this.value.includes(this._value);
742
- this.value = t ? this.value.filter((s) => s !== this._value) : [...this.value, this._value];
743
- }
744
- constructor(t) {
745
- super(t, false), this.options = t.options, this.value = [...t.initialValues ?? []];
746
- const s = Math.max(this.options.findIndex(({ value: e2 }) => e2 === t.cursorAt), 0);
747
- this.cursor = this.options[s].disabled ? f(s, 1, this.options) : s, this.on("key", (e2, i) => {
748
- i.name === "a" && this.toggleAll(), i.name === "i" && this.toggleInvert();
749
- }), this.on("cursor", (e2) => {
750
- switch (e2) {
848
+ const e = this.value.includes(this._value);
849
+ this.value = e ? this.value.filter((i2) => i2 !== this._value) : [...this.value, this._value];
850
+ }
851
+ constructor(e) {
852
+ super(e, false), this.options = e.options, this.value = [...e.initialValues ?? []];
853
+ const i2 = Math.max(
854
+ this.options.findIndex(({ value: t2 }) => t2 === e.cursorAt),
855
+ 0
856
+ );
857
+ this.cursor = this.options[i2].disabled ? findCursor(i2, 1, this.options) : i2, this.on("key", (t2, l2) => {
858
+ l2.name === "a" && this.toggleAll(), l2.name === "i" && this.toggleInvert();
859
+ }), this.on("cursor", (t2) => {
860
+ switch (t2) {
751
861
  case "left":
752
862
  case "up":
753
- this.cursor = f(this.cursor, -1, this.options);
863
+ this.cursor = findCursor(this.cursor, -1, this.options);
754
864
  break;
755
865
  case "down":
756
866
  case "right":
757
- this.cursor = f(this.cursor, 1, this.options);
867
+ this.cursor = findCursor(this.cursor, 1, this.options);
758
868
  break;
759
869
  case "space":
760
870
  this.toggleValue();
@@ -763,7 +873,7 @@ var ut = class extends m {
763
873
  });
764
874
  }
765
875
  };
766
- var ht = class extends m {
876
+ var a2 = class extends V {
767
877
  options;
768
878
  cursor = 0;
769
879
  get _selectedValue() {
@@ -772,383 +882,568 @@ var ht = class extends m {
772
882
  changeValue() {
773
883
  this.value = this._selectedValue.value;
774
884
  }
775
- constructor(t) {
776
- super(t, false), this.options = t.options;
777
- const s = this.options.findIndex(({ value: i }) => i === t.initialValue), e2 = s === -1 ? 0 : s;
778
- this.cursor = this.options[e2].disabled ? f(e2, 1, this.options) : e2, this.changeValue(), this.on("cursor", (i) => {
779
- switch (i) {
885
+ constructor(t2) {
886
+ super(t2, false), this.options = t2.options;
887
+ const i2 = this.options.findIndex(({ value: s }) => s === t2.initialValue), e = i2 === -1 ? 0 : i2;
888
+ this.cursor = this.options[e].disabled ? findCursor(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (s) => {
889
+ switch (s) {
780
890
  case "left":
781
891
  case "up":
782
- this.cursor = f(this.cursor, -1, this.options);
892
+ this.cursor = findCursor(this.cursor, -1, this.options);
783
893
  break;
784
894
  case "down":
785
895
  case "right":
786
- this.cursor = f(this.cursor, 1, this.options);
896
+ this.cursor = findCursor(this.cursor, 1, this.options);
787
897
  break;
788
898
  }
789
899
  this.changeValue();
790
900
  });
791
901
  }
792
902
  };
793
- var ct = class extends m {
903
+ var n = class extends V {
794
904
  get userInputWithCursor() {
795
- if (this.state === "submit") return this.userInput;
796
- const t = this.userInput;
797
- if (this.cursor >= t.length) return `${this.userInput}\u2588`;
798
- const s = t.slice(0, this.cursor), [e2, ...i] = t.slice(this.cursor);
799
- return `${s}${v("inverse", e2)}${i.join("")}`;
905
+ if (this.state === "submit")
906
+ return this.userInput;
907
+ const t2 = this.userInput;
908
+ if (this.cursor >= t2.length)
909
+ return `${this.userInput}\u2588`;
910
+ const e = t2.slice(0, this.cursor), [s, ...r2] = t2.slice(this.cursor);
911
+ return `${e}${styleText("inverse", s)}${r2.join("")}`;
800
912
  }
801
913
  get cursor() {
802
914
  return this._cursor;
803
915
  }
804
- constructor(t) {
805
- super({ ...t, initialUserInput: t.initialUserInput ?? t.initialValue }), this.on("userInput", (s) => {
806
- this._setValue(s);
916
+ constructor(t2) {
917
+ super({
918
+ ...t2,
919
+ initialUserInput: t2.initialUserInput ?? t2.initialValue
920
+ }), this.on("userInput", (e) => {
921
+ this._setValue(e);
807
922
  }), this.on("finalize", () => {
808
- this.value || (this.value = t.defaultValue), this.value === void 0 && (this.value = "");
923
+ this.value || (this.value = t2.defaultValue), this.value === void 0 && (this.value = "");
809
924
  });
810
925
  }
811
926
  };
812
927
 
813
928
  // node_modules/@clack/prompts/dist/index.mjs
814
- import { styleText as e, stripVTControlCharacters as ot2 } from "node:util";
815
- import V2 from "node:process";
929
+ import { styleText as styleText2, stripVTControlCharacters } from "node:util";
930
+ import process$1 from "node:process";
816
931
  var import_sisteransi2 = __toESM(require_src(), 1);
817
- function se() {
818
- return V2.platform !== "win32" ? V2.env.TERM !== "linux" : !!V2.env.CI || !!V2.env.WT_SESSION || !!V2.env.TERMINUS_SUBLIME || V2.env.ConEmuTask === "{cmd::Cmder}" || V2.env.TERM_PROGRAM === "Terminus-Sublime" || V2.env.TERM_PROGRAM === "vscode" || V2.env.TERM === "xterm-256color" || V2.env.TERM === "alacritty" || V2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
819
- }
820
- var tt = se();
821
- var at2 = () => process.env.CI === "true";
822
- var w2 = (t, i) => tt ? t : i;
823
- var _t = w2("\u25C6", "*");
824
- var ut2 = w2("\u25A0", "x");
825
- var lt2 = w2("\u25B2", "x");
826
- var H = w2("\u25C7", "o");
827
- var ct2 = w2("\u250C", "T");
828
- var $ = w2("\u2502", "|");
829
- var x2 = w2("\u2514", "\u2014");
830
- var xt = w2("\u2510", "T");
831
- var Et = w2("\u2518", "\u2014");
832
- var z2 = w2("\u25CF", ">");
833
- var U = w2("\u25CB", " ");
834
- var et = w2("\u25FB", "[\u2022]");
835
- var K2 = w2("\u25FC", "[+]");
836
- var Y2 = w2("\u25FB", "[ ]");
837
- var Gt = w2("\u25AA", "\u2022");
838
- var st = w2("\u2500", "-");
839
- var $t = w2("\u256E", "+");
840
- var Mt = w2("\u251C", "+");
841
- var dt = w2("\u256F", "+");
842
- var ht2 = w2("\u2570", "+");
843
- var Ot = w2("\u256D", "+");
844
- var pt = w2("\u25CF", "\u2022");
845
- var mt = w2("\u25C6", "*");
846
- var gt = w2("\u25B2", "!");
847
- var yt = w2("\u25A0", "x");
848
- var P2 = (t) => {
849
- switch (t) {
932
+ function isUnicodeSupported() {
933
+ if (process$1.platform !== "win32") {
934
+ return process$1.env.TERM !== "linux";
935
+ }
936
+ return Boolean(process$1.env.CI) || Boolean(process$1.env.WT_SESSION) || Boolean(process$1.env.TERMINUS_SUBLIME) || process$1.env.ConEmuTask === "{cmd::Cmder}" || process$1.env.TERM_PROGRAM === "Terminus-Sublime" || process$1.env.TERM_PROGRAM === "vscode" || process$1.env.TERM === "xterm-256color" || process$1.env.TERM === "alacritty" || process$1.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
937
+ }
938
+ var unicode = isUnicodeSupported();
939
+ var isCI = () => process.env.CI === "true";
940
+ var unicodeOr = (e, o2) => unicode ? e : o2;
941
+ var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
942
+ var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
943
+ var S_STEP_ERROR = unicodeOr("\u25B2", "x");
944
+ var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
945
+ var S_BAR_START = unicodeOr("\u250C", "T");
946
+ var S_BAR = unicodeOr("\u2502", "|");
947
+ var S_BAR_END = unicodeOr("\u2514", "\u2014");
948
+ var S_BAR_START_RIGHT = unicodeOr("\u2510", "T");
949
+ var S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014");
950
+ var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
951
+ var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
952
+ var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
953
+ var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
954
+ var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
955
+ var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
956
+ var S_BAR_H = unicodeOr("\u2500", "-");
957
+ var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
958
+ var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
959
+ var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
960
+ var S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+");
961
+ var S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+");
962
+ var S_INFO = unicodeOr("\u25CF", "\u2022");
963
+ var S_SUCCESS = unicodeOr("\u25C6", "*");
964
+ var S_WARN = unicodeOr("\u25B2", "!");
965
+ var S_ERROR = unicodeOr("\u25A0", "x");
966
+ var symbol = (e) => {
967
+ switch (e) {
850
968
  case "initial":
851
969
  case "active":
852
- return e("cyan", _t);
970
+ return styleText2("cyan", S_STEP_ACTIVE);
853
971
  case "cancel":
854
- return e("red", ut2);
972
+ return styleText2("red", S_STEP_CANCEL);
855
973
  case "error":
856
- return e("yellow", lt2);
974
+ return styleText2("yellow", S_STEP_ERROR);
857
975
  case "submit":
858
- return e("green", H);
976
+ return styleText2("green", S_STEP_SUBMIT);
859
977
  }
860
978
  };
861
- var ft = (t) => {
862
- switch (t) {
979
+ var symbolBar = (e) => {
980
+ switch (e) {
863
981
  case "initial":
864
982
  case "active":
865
- return e("cyan", $);
983
+ return styleText2("cyan", S_BAR);
866
984
  case "cancel":
867
- return e("red", $);
985
+ return styleText2("red", S_BAR);
868
986
  case "error":
869
- return e("yellow", $);
987
+ return styleText2("yellow", S_BAR);
870
988
  case "submit":
871
- return e("green", $);
989
+ return styleText2("green", S_BAR);
872
990
  }
873
991
  };
874
- var Pt = (t, i, s, r, u, n = false) => {
875
- let a = i, c = 0;
876
- if (n) for (let o = r - 1; o >= s && (a -= t[o].length, c++, !(a <= u)); o--) ;
877
- else for (let o = s; o < r && (a -= t[o].length, c++, !(a <= u)); o++) ;
878
- return { lineCount: a, removals: c };
992
+ var E$1 = (l2, o2, g, c2, h2, O = false) => {
993
+ let r2 = o2, w = 0;
994
+ if (O)
995
+ for (let i2 = c2 - 1; i2 >= g && (r2 -= l2[i2].length, w++, !(r2 <= h2)); i2--)
996
+ ;
997
+ else
998
+ for (let i2 = g; i2 < c2 && (r2 -= l2[i2].length, w++, !(r2 <= h2)); i2++)
999
+ ;
1000
+ return { lineCount: r2, removals: w };
879
1001
  };
880
- var F = ({ cursor: t, options: i, style: s, output: r = process.stdout, maxItems: u = Number.POSITIVE_INFINITY, columnPadding: n = 0, rowPadding: a = 4 }) => {
881
- const c = A(r) - n, o = L(r), l = e("dim", "..."), d = Math.max(o - a, 0), g = Math.max(Math.min(u, d), 5);
882
- let p2 = 0;
883
- t >= g - 3 && (p2 = Math.max(Math.min(t - g + 3, i.length - g), 0));
884
- let f2 = g < i.length && p2 > 0, h2 = g < i.length && p2 + g < i.length;
885
- const I = Math.min(p2 + g, i.length), m2 = [];
886
- let y = 0;
887
- f2 && y++, h2 && y++;
888
- const v2 = p2 + (f2 ? 1 : 0), C2 = I - (h2 ? 1 : 0);
889
- for (let b2 = v2; b2 < C2; b2++) {
890
- const G2 = wrapAnsi(s(i[b2], b2 === t), c, { hard: true, trim: false }).split(`
1002
+ var limitOptions = ({
1003
+ cursor: l2,
1004
+ options: o2,
1005
+ style: g,
1006
+ output: c2 = process.stdout,
1007
+ maxItems: h2 = Number.POSITIVE_INFINITY,
1008
+ columnPadding: O = 0,
1009
+ rowPadding: r2 = 4
1010
+ }) => {
1011
+ const i2 = getColumns(c2) - O, I = getRows(c2), C2 = styleText2("dim", "..."), x = Math.max(I - r2, 0), m = Math.max(Math.min(h2, x), 5);
1012
+ let p = 0;
1013
+ l2 >= m - 3 && (p = Math.max(
1014
+ Math.min(l2 - m + 3, o2.length - m),
1015
+ 0
1016
+ ));
1017
+ let f = m < o2.length && p > 0, u3 = m < o2.length && p + m < o2.length;
1018
+ const W2 = Math.min(
1019
+ p + m,
1020
+ o2.length
1021
+ ), e = [];
1022
+ let d2 = 0;
1023
+ f && d2++, u3 && d2++;
1024
+ const v = p + (f ? 1 : 0), P = W2 - (u3 ? 1 : 0);
1025
+ for (let t2 = v; t2 < P; t2++) {
1026
+ const n2 = wrapAnsi(g(o2[t2], t2 === l2), i2, {
1027
+ hard: true,
1028
+ trim: false
1029
+ }).split(`
891
1030
  `);
892
- m2.push(G2), y += G2.length;
893
- }
894
- if (y > d) {
895
- let b2 = 0, G2 = 0, M = y;
896
- const N = t - v2;
897
- let O2 = d;
898
- const j2 = () => Pt(m2, M, 0, N, O2), k2 = () => Pt(m2, M, N + 1, m2.length, O2, true);
899
- f2 ? ({ lineCount: M, removals: b2 } = j2(), M > O2 && (h2 || (O2 -= 1), { lineCount: M, removals: G2 } = k2())) : (h2 || (O2 -= 1), { lineCount: M, removals: G2 } = k2(), M > O2 && (O2 -= 1, { lineCount: M, removals: b2 } = j2())), b2 > 0 && (f2 = true, m2.splice(0, b2)), G2 > 0 && (h2 = true, m2.splice(m2.length - G2, G2));
900
- }
901
- const S = [];
902
- f2 && S.push(l);
903
- for (const b2 of m2) for (const G2 of b2) S.push(G2);
904
- return h2 && S.push(l), S;
1031
+ e.push(n2), d2 += n2.length;
1032
+ }
1033
+ if (d2 > x) {
1034
+ let t2 = 0, n2 = 0, s = d2;
1035
+ const M = l2 - v;
1036
+ let a3 = x;
1037
+ const T = () => E$1(e, s, 0, M, a3), L = () => E$1(
1038
+ e,
1039
+ s,
1040
+ M + 1,
1041
+ e.length,
1042
+ a3,
1043
+ true
1044
+ );
1045
+ f ? ({ lineCount: s, removals: t2 } = T(), s > a3 && (u3 || (a3 -= 1), { lineCount: s, removals: n2 } = L())) : (u3 || (a3 -= 1), { lineCount: s, removals: n2 } = L(), s > a3 && (a3 -= 1, { lineCount: s, removals: t2 } = T())), t2 > 0 && (f = true, e.splice(0, t2)), n2 > 0 && (u3 = true, e.splice(e.length - n2, n2));
1046
+ }
1047
+ const b = [];
1048
+ f && b.push(C2);
1049
+ for (const t2 of e)
1050
+ for (const n2 of t2)
1051
+ b.push(n2);
1052
+ return u3 && b.push(C2), b;
905
1053
  };
906
- var le = (t) => {
907
- const i = t.active ?? "Yes", s = t.inactive ?? "No";
908
- return new Z({ active: i, inactive: s, signal: t.signal, input: t.input, output: t.output, initialValue: t.initialValue ?? true, render() {
909
- const r = t.withGuide ?? h.withGuide, u = `${P2(this.state)} `, n = r ? `${e("gray", $)} ` : "", a = B(t.output, t.message, n, u), c = `${r ? `${e("gray", $)}
910
- ` : ""}${a}
911
- `, o = this.value ? i : s;
912
- switch (this.state) {
913
- case "submit": {
914
- const l = r ? `${e("gray", $)} ` : "";
915
- return `${c}${l}${e("dim", o)}`;
916
- }
917
- case "cancel": {
918
- const l = r ? `${e("gray", $)} ` : "";
919
- return `${c}${l}${e(["strikethrough", "dim"], o)}${r ? `
920
- ${e("gray", $)}` : ""}`;
921
- }
922
- default: {
923
- const l = r ? `${e("cyan", $)} ` : "", d = r ? e("cyan", x2) : "";
924
- return `${c}${l}${this.value ? `${e("green", z2)} ${i}` : `${e("dim", U)} ${e("dim", i)}`}${t.vertical ? r ? `
925
- ${e("cyan", $)} ` : `
926
- ` : ` ${e("dim", "/")} `}${this.value ? `${e("dim", U)} ${e("dim", s)}` : `${e("green", z2)} ${s}`}
927
- ${d}
1054
+ var confirm = (i2) => {
1055
+ const a3 = i2.active ?? "Yes", s = i2.inactive ?? "No";
1056
+ return new r({
1057
+ active: a3,
1058
+ inactive: s,
1059
+ signal: i2.signal,
1060
+ input: i2.input,
1061
+ output: i2.output,
1062
+ initialValue: i2.initialValue ?? true,
1063
+ render() {
1064
+ const e = i2.withGuide ?? settings.withGuide, u3 = `${symbol(this.state)} `, l2 = e ? `${styleText2("gray", S_BAR)} ` : "", f = wrapTextWithPrefix(
1065
+ i2.output,
1066
+ i2.message,
1067
+ l2,
1068
+ u3
1069
+ ), o2 = `${e ? `${styleText2("gray", S_BAR)}
1070
+ ` : ""}${f}
1071
+ `, c2 = this.value ? a3 : s;
1072
+ switch (this.state) {
1073
+ case "submit": {
1074
+ const r2 = e ? `${styleText2("gray", S_BAR)} ` : "";
1075
+ return `${o2}${r2}${styleText2("dim", c2)}`;
1076
+ }
1077
+ case "cancel": {
1078
+ const r2 = e ? `${styleText2("gray", S_BAR)} ` : "";
1079
+ return `${o2}${r2}${styleText2(["strikethrough", "dim"], c2)}${e ? `
1080
+ ${styleText2("gray", S_BAR)}` : ""}`;
1081
+ }
1082
+ default: {
1083
+ const r2 = e ? `${styleText2("cyan", S_BAR)} ` : "", g = e ? styleText2("cyan", S_BAR_END) : "";
1084
+ return `${o2}${r2}${this.value ? `${styleText2("green", S_RADIO_ACTIVE)} ${a3}` : `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", a3)}`}${i2.vertical ? e ? `
1085
+ ${styleText2("cyan", S_BAR)} ` : `
1086
+ ` : ` ${styleText2("dim", "/")} `}${this.value ? `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", s)}` : `${styleText2("green", S_RADIO_ACTIVE)} ${s}`}
1087
+ ${g}
928
1088
  `;
1089
+ }
929
1090
  }
930
1091
  }
931
- } }).prompt();
1092
+ }).prompt();
932
1093
  };
933
- var ge = (t = "", i) => {
934
- const s = i?.output ?? process.stdout, r = i?.withGuide ?? h.withGuide ? `${e("gray", x2)} ` : "";
935
- s.write(`${r}${e("red", t)}
1094
+ var cancel = (o2 = "", t2) => {
1095
+ const i2 = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_END)} ` : "";
1096
+ i2.write(`${e}${styleText2("red", o2)}
936
1097
 
937
1098
  `);
938
1099
  };
939
- var ye = (t = "", i) => {
940
- const s = i?.output ?? process.stdout, r = i?.withGuide ?? h.withGuide ? `${e("gray", ct2)} ` : "";
941
- s.write(`${r}${t}
1100
+ var intro = (o2 = "", t2) => {
1101
+ const i2 = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_START)} ` : "";
1102
+ i2.write(`${e}${o2}
942
1103
  `);
943
1104
  };
944
- var fe = (t = "", i) => {
945
- const s = i?.output ?? process.stdout, r = i?.withGuide ?? h.withGuide ? `${e("gray", $)}
946
- ${e("gray", x2)} ` : "";
947
- s.write(`${r}${t}
1105
+ var outro = (o2 = "", t2) => {
1106
+ const i2 = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR)}
1107
+ ${styleText2("gray", S_BAR_END)} ` : "";
1108
+ i2.write(`${e}${o2}
948
1109
 
949
1110
  `);
950
1111
  };
951
- var Q = (t, i) => t.split(`
952
- `).map((s) => i(s)).join(`
1112
+ var d = (n2, a3) => n2.split(`
1113
+ `).map((m) => a3(m)).join(`
953
1114
  `);
954
- var we = (t) => {
955
- const i = (r, u) => {
956
- const n = r.label ?? String(r.value);
957
- return u === "disabled" ? `${e("gray", Y2)} ${Q(n, (a) => e(["strikethrough", "gray"], a))}${r.hint ? ` ${e("dim", `(${r.hint ?? "disabled"})`)}` : ""}` : u === "active" ? `${e("cyan", et)} ${n}${r.hint ? ` ${e("dim", `(${r.hint})`)}` : ""}` : u === "selected" ? `${e("green", K2)} ${Q(n, (a) => e("dim", a))}${r.hint ? ` ${e("dim", `(${r.hint})`)}` : ""}` : u === "cancelled" ? `${Q(n, (a) => e(["strikethrough", "dim"], a))}` : u === "active-selected" ? `${e("green", K2)} ${n}${r.hint ? ` ${e("dim", `(${r.hint})`)}` : ""}` : u === "submitted" ? `${Q(n, (a) => e("dim", a))}` : `${e("dim", Y2)} ${Q(n, (a) => e("dim", a))}`;
958
- }, s = t.required ?? true;
959
- return new ut({ options: t.options, signal: t.signal, input: t.input, output: t.output, initialValues: t.initialValues, required: s, cursorAt: t.cursorAt, validate(r) {
960
- if (s && (r === void 0 || r.length === 0)) return `Please select at least one option.
961
- ${e("reset", e("dim", `Press ${e(["gray", "bgWhite", "inverse"], " space ")} to select, ${e("gray", e("bgWhite", e("inverse", " enter ")))} to submit`))}`;
962
- }, render() {
963
- const r = t.withGuide ?? h.withGuide, u = B(t.output, t.message, r ? `${ft(this.state)} ` : "", `${P2(this.state)} `), n = `${r ? `${e("gray", $)}
964
- ` : ""}${u}
965
- `, a = this.value ?? [], c = (o, l) => {
966
- if (o.disabled) return i(o, "disabled");
967
- const d = a.includes(o.value);
968
- return l && d ? i(o, "active-selected") : d ? i(o, "selected") : i(o, l ? "active" : "inactive");
969
- };
970
- switch (this.state) {
971
- case "submit": {
972
- const o = this.options.filter(({ value: d }) => a.includes(d)).map((d) => i(d, "submitted")).join(e("dim", ", ")) || e("dim", "none"), l = B(t.output, o, r ? `${e("gray", $)} ` : "");
973
- return `${n}${l}`;
974
- }
975
- case "cancel": {
976
- const o = this.options.filter(({ value: d }) => a.includes(d)).map((d) => i(d, "cancelled")).join(e("dim", ", "));
977
- if (o.trim() === "") return `${n}${e("gray", $)}`;
978
- const l = B(t.output, o, r ? `${e("gray", $)} ` : "");
979
- return `${n}${l}${r ? `
980
- ${e("gray", $)}` : ""}`;
981
- }
982
- case "error": {
983
- const o = r ? `${e("yellow", $)} ` : "", l = this.error.split(`
984
- `).map((p2, f2) => f2 === 0 ? `${r ? `${e("yellow", x2)} ` : ""}${e("yellow", p2)}` : ` ${p2}`).join(`
985
- `), d = n.split(`
986
- `).length, g = l.split(`
1115
+ var multiselect = (n2) => {
1116
+ const a3 = (t2, o2) => {
1117
+ const r2 = t2.label ?? String(t2.value);
1118
+ return o2 === "disabled" ? `${styleText2("gray", S_CHECKBOX_INACTIVE)} ${d(r2, (l2) => styleText2(["strikethrough", "gray"], l2))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint ?? "disabled"})`)}` : ""}` : o2 === "active" ? `${styleText2("cyan", S_CHECKBOX_ACTIVE)} ${r2}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : o2 === "selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${d(r2, (l2) => styleText2("dim", l2))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : o2 === "cancelled" ? `${d(r2, (l2) => styleText2(["strikethrough", "dim"], l2))}` : o2 === "active-selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${r2}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : o2 === "submitted" ? `${d(r2, (l2) => styleText2("dim", l2))}` : `${styleText2("dim", S_CHECKBOX_INACTIVE)} ${d(r2, (l2) => styleText2("dim", l2))}`;
1119
+ }, m = n2.required ?? true;
1120
+ return new a$1({
1121
+ options: n2.options,
1122
+ signal: n2.signal,
1123
+ input: n2.input,
1124
+ output: n2.output,
1125
+ initialValues: n2.initialValues,
1126
+ required: m,
1127
+ cursorAt: n2.cursorAt,
1128
+ validate(t2) {
1129
+ if (m && (t2 === void 0 || t2.length === 0))
1130
+ return `Please select at least one option.
1131
+ ${styleText2(
1132
+ "reset",
1133
+ styleText2(
1134
+ "dim",
1135
+ `Press ${styleText2(["gray", "bgWhite", "inverse"], " space ")} to select, ${styleText2(
1136
+ "gray",
1137
+ styleText2("bgWhite", styleText2("inverse", " enter "))
1138
+ )} to submit`
1139
+ )
1140
+ )}`;
1141
+ },
1142
+ render() {
1143
+ const t2 = n2.withGuide ?? settings.withGuide, o2 = wrapTextWithPrefix(
1144
+ n2.output,
1145
+ n2.message,
1146
+ t2 ? `${symbolBar(this.state)} ` : "",
1147
+ `${symbol(this.state)} `
1148
+ ), r2 = `${t2 ? `${styleText2("gray", S_BAR)}
1149
+ ` : ""}${o2}
1150
+ `, l2 = this.value ?? [], g = (i2, u3) => {
1151
+ if (i2.disabled)
1152
+ return a3(i2, "disabled");
1153
+ const s = l2.includes(i2.value);
1154
+ return u3 && s ? a3(i2, "active-selected") : s ? a3(i2, "selected") : a3(i2, u3 ? "active" : "inactive");
1155
+ };
1156
+ switch (this.state) {
1157
+ case "submit": {
1158
+ const i2 = this.options.filter(({ value: s }) => l2.includes(s)).map((s) => a3(s, "submitted")).join(styleText2("dim", ", ")) || styleText2("dim", "none"), u3 = wrapTextWithPrefix(
1159
+ n2.output,
1160
+ i2,
1161
+ t2 ? `${styleText2("gray", S_BAR)} ` : ""
1162
+ );
1163
+ return `${r2}${u3}`;
1164
+ }
1165
+ case "cancel": {
1166
+ const i2 = this.options.filter(({ value: s }) => l2.includes(s)).map((s) => a3(s, "cancelled")).join(styleText2("dim", ", "));
1167
+ if (i2.trim() === "")
1168
+ return `${r2}${styleText2("gray", S_BAR)}`;
1169
+ const u3 = wrapTextWithPrefix(
1170
+ n2.output,
1171
+ i2,
1172
+ t2 ? `${styleText2("gray", S_BAR)} ` : ""
1173
+ );
1174
+ return `${r2}${u3}${t2 ? `
1175
+ ${styleText2("gray", S_BAR)}` : ""}`;
1176
+ }
1177
+ case "error": {
1178
+ const i2 = t2 ? `${styleText2("yellow", S_BAR)} ` : "", u3 = this.error.split(`
1179
+ `).map(
1180
+ (h2, x) => x === 0 ? `${t2 ? `${styleText2("yellow", S_BAR_END)} ` : ""}${styleText2("yellow", h2)}` : ` ${h2}`
1181
+ ).join(`
1182
+ `), s = r2.split(`
1183
+ `).length, v = u3.split(`
987
1184
  `).length + 1;
988
- return `${n}${o}${F({ output: t.output, options: this.options, cursor: this.cursor, maxItems: t.maxItems, columnPadding: o.length, rowPadding: d + g, style: c }).join(`
989
- ${o}`)}
990
- ${l}
1185
+ return `${r2}${i2}${limitOptions({
1186
+ output: n2.output,
1187
+ options: this.options,
1188
+ cursor: this.cursor,
1189
+ maxItems: n2.maxItems,
1190
+ columnPadding: i2.length,
1191
+ rowPadding: s + v,
1192
+ style: g
1193
+ }).join(`
1194
+ ${i2}`)}
1195
+ ${u3}
991
1196
  `;
992
- }
993
- default: {
994
- const o = r ? `${e("cyan", $)} ` : "", l = n.split(`
995
- `).length, d = r ? 2 : 1;
996
- return `${n}${o}${F({ output: t.output, options: this.options, cursor: this.cursor, maxItems: t.maxItems, columnPadding: o.length, rowPadding: l + d, style: c }).join(`
997
- ${o}`)}
998
- ${r ? e("cyan", x2) : ""}
1197
+ }
1198
+ default: {
1199
+ const i2 = t2 ? `${styleText2("cyan", S_BAR)} ` : "", u3 = r2.split(`
1200
+ `).length, s = t2 ? 2 : 1;
1201
+ return `${r2}${i2}${limitOptions({
1202
+ output: n2.output,
1203
+ options: this.options,
1204
+ cursor: this.cursor,
1205
+ maxItems: n2.maxItems,
1206
+ columnPadding: i2.length,
1207
+ rowPadding: u3 + s,
1208
+ style: g
1209
+ }).join(`
1210
+ ${i2}`)}
1211
+ ${t2 ? styleText2("cyan", S_BAR_END) : ""}
999
1212
  `;
1213
+ }
1000
1214
  }
1001
1215
  }
1002
- } }).prompt();
1216
+ }).prompt();
1003
1217
  };
1004
- var be = (t) => e("dim", t);
1005
- var Se = (t, i, s) => {
1006
- const r = { hard: true, trim: false }, u = wrapAnsi(t, i, r).split(`
1007
- `), n = u.reduce((o, l) => Math.max(dist_default2(l), o), 0), a = u.map(s).reduce((o, l) => Math.max(dist_default2(l), o), 0), c = i - (a - n);
1008
- return wrapAnsi(t, c, r);
1218
+ var W$1 = (o2) => styleText2("dim", o2);
1219
+ var C = (o2, e, s) => {
1220
+ const a3 = {
1221
+ hard: true,
1222
+ trim: false
1223
+ }, i2 = wrapAnsi(o2, e, a3).split(`
1224
+ `), c2 = i2.reduce((n2, r2) => Math.max(dist_default2(r2), n2), 0), u3 = i2.map(s).reduce((n2, r2) => Math.max(dist_default2(r2), n2), 0), g = e - (u3 - c2);
1225
+ return wrapAnsi(o2, g, a3);
1009
1226
  };
1010
- var Ce = (t = "", i = "", s) => {
1011
- const r = s?.output ?? V2.stdout, u = s?.withGuide ?? h.withGuide, n = s?.format ?? be, a = ["", ...Se(t, A(r) - 6, n).split(`
1012
- `).map(n), ""], c = dist_default2(i), o = Math.max(a.reduce((p2, f2) => {
1013
- const h2 = dist_default2(f2);
1014
- return h2 > p2 ? h2 : p2;
1015
- }, 0), c) + 2, l = a.map((p2) => `${e("gray", $)} ${p2}${" ".repeat(o - dist_default2(p2))}${e("gray", $)}`).join(`
1016
- `), d = u ? `${e("gray", $)}
1017
- ` : "", g = u ? Mt : ht2;
1018
- r.write(`${d}${e("green", H)} ${e("reset", i)} ${e("gray", st.repeat(Math.max(o - c - 1, 1)) + $t)}
1019
- ${l}
1020
- ${e("gray", g + st.repeat(o + 2) + dt)}
1021
- `);
1227
+ var note = (o2 = "", e = "", s) => {
1228
+ const a3 = s?.output ?? process$1.stdout, i2 = s?.withGuide ?? settings.withGuide, c2 = s?.format ?? W$1, g = ["", ...C(o2, getColumns(a3) - 6, c2).split(`
1229
+ `).map(c2), ""], n2 = dist_default2(e), r2 = Math.max(
1230
+ g.reduce((m, F) => {
1231
+ const O = dist_default2(F);
1232
+ return O > m ? O : m;
1233
+ }, 0),
1234
+ n2
1235
+ ) + 2, h2 = g.map(
1236
+ (m) => `${styleText2("gray", S_BAR)} ${m}${" ".repeat(r2 - dist_default2(m))}${styleText2("gray", S_BAR)}`
1237
+ ).join(`
1238
+ `), T = i2 ? `${styleText2("gray", S_BAR)}
1239
+ ` : "", l$1 = i2 ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
1240
+ a3.write(
1241
+ `${T}${styleText2("green", S_STEP_SUBMIT)} ${styleText2("reset", e)} ${styleText2(
1242
+ "gray",
1243
+ S_BAR_H.repeat(Math.max(r2 - n2 - 1, 1)) + S_CORNER_TOP_RIGHT
1244
+ )}
1245
+ ${h2}
1246
+ ${styleText2("gray", l$1 + S_BAR_H.repeat(r2 + 2) + S_CORNER_BOTTOM_RIGHT)}
1247
+ `
1248
+ );
1022
1249
  };
1023
- var _e = (t) => e("magenta", t);
1024
- var vt = ({ indicator: t = "dots", onCancel: i, output: s = process.stdout, cancelMessage: r, errorMessage: u, frames: n = tt ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"], delay: a = tt ? 80 : 120, signal: c, ...o } = {}) => {
1025
- const l = at2();
1026
- let d, g, p2 = false, f2 = false, h2 = "", I, m2 = performance.now();
1027
- const y = A(s), v2 = o?.styleFrame ?? _e, C2 = (_) => {
1028
- const A2 = _ > 1 ? u ?? h.messages.error : r ?? h.messages.cancel;
1029
- f2 = _ === 1, p2 && (W2(A2, _), f2 && typeof i == "function" && i());
1030
- }, S = () => C2(2), b2 = () => C2(1), G2 = () => {
1031
- process.on("uncaughtExceptionMonitor", S), process.on("unhandledRejection", S), process.on("SIGINT", b2), process.on("SIGTERM", b2), process.on("exit", C2), c && c.addEventListener("abort", b2);
1032
- }, M = () => {
1033
- process.removeListener("uncaughtExceptionMonitor", S), process.removeListener("unhandledRejection", S), process.removeListener("SIGINT", b2), process.removeListener("SIGTERM", b2), process.removeListener("exit", C2), c && c.removeEventListener("abort", b2);
1034
- }, N = () => {
1035
- if (I === void 0) return;
1036
- l && s.write(`
1250
+ var W = (l2) => styleText2("magenta", l2);
1251
+ var spinner = ({
1252
+ indicator: l2 = "dots",
1253
+ onCancel: h2,
1254
+ output: n2 = process.stdout,
1255
+ cancelMessage: G,
1256
+ errorMessage: O,
1257
+ frames: E = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
1258
+ delay: F = unicode ? 80 : 120,
1259
+ signal: m,
1260
+ ...I
1261
+ } = {}) => {
1262
+ const u3 = isCI();
1263
+ let M, T, d2 = false, S = false, s = "", p, w = performance.now();
1264
+ const x = getColumns(n2), k = I?.styleFrame ?? W, g = (e) => {
1265
+ const r2 = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
1266
+ S = e === 1, d2 && (a3(r2, e), S && typeof h2 == "function" && h2());
1267
+ }, f = () => g(2), i2 = () => g(1), A = () => {
1268
+ process.on("uncaughtExceptionMonitor", f), process.on("unhandledRejection", f), process.on("SIGINT", i2), process.on("SIGTERM", i2), process.on("exit", g), m && m.addEventListener("abort", i2);
1269
+ }, H = () => {
1270
+ process.removeListener("uncaughtExceptionMonitor", f), process.removeListener("unhandledRejection", f), process.removeListener("SIGINT", i2), process.removeListener("SIGTERM", i2), process.removeListener("exit", g), m && m.removeEventListener("abort", i2);
1271
+ }, y = () => {
1272
+ if (p === void 0) return;
1273
+ u3 && n2.write(`
1037
1274
  `);
1038
- const _ = wrapAnsi(I, y, { hard: true, trim: false }).split(`
1275
+ const r2 = wrapAnsi(p, x, {
1276
+ hard: true,
1277
+ trim: false
1278
+ }).split(`
1039
1279
  `);
1040
- _.length > 1 && s.write(import_sisteransi2.cursor.up(_.length - 1)), s.write(import_sisteransi2.cursor.to(0)), s.write(import_sisteransi2.erase.down());
1041
- }, O2 = (_) => _.replace(/\.+$/, ""), j2 = (_) => {
1042
- const A2 = (performance.now() - _) / 1e3, L2 = Math.floor(A2 / 60), D2 = Math.floor(A2 % 60);
1043
- return L2 > 0 ? `[${L2}m ${D2}s]` : `[${D2}s]`;
1044
- }, k2 = o.withGuide ?? h.withGuide, rt2 = (_ = "") => {
1045
- p2 = true, d = W({ output: s }), h2 = O2(_), m2 = performance.now(), k2 && s.write(`${e("gray", $)}
1280
+ r2.length > 1 && n2.write(import_sisteransi2.cursor.up(r2.length - 1)), n2.write(import_sisteransi2.cursor.to(0)), n2.write(import_sisteransi2.erase.down());
1281
+ }, C2 = (e) => e.replace(/\.+$/, ""), _ = (e) => {
1282
+ const r2 = (performance.now() - e) / 1e3, t2 = Math.floor(r2 / 60), o2 = Math.floor(r2 % 60);
1283
+ return t2 > 0 ? `[${t2}m ${o2}s]` : `[${o2}s]`;
1284
+ }, N = I.withGuide ?? settings.withGuide, P = (e = "") => {
1285
+ d2 = true, M = block({ output: n2 }), s = C2(e), w = performance.now(), N && n2.write(`${styleText2("gray", S_BAR)}
1046
1286
  `);
1047
- let A2 = 0, L2 = 0;
1048
- G2(), g = setInterval(() => {
1049
- if (l && h2 === I) return;
1050
- N(), I = h2;
1051
- const D2 = v2(n[A2]);
1052
- let Z2;
1053
- if (l) Z2 = `${D2} ${h2}...`;
1054
- else if (t === "timer") Z2 = `${D2} ${h2} ${j2(m2)}`;
1287
+ let r2 = 0, t2 = 0;
1288
+ A(), T = setInterval(() => {
1289
+ if (u3 && s === p)
1290
+ return;
1291
+ y(), p = s;
1292
+ const o2 = k(E[r2]);
1293
+ let v;
1294
+ if (u3)
1295
+ v = `${o2} ${s}...`;
1296
+ else if (l2 === "timer")
1297
+ v = `${o2} ${s} ${_(w)}`;
1055
1298
  else {
1056
- const Lt = ".".repeat(Math.floor(L2)).slice(0, 3);
1057
- Z2 = `${D2} ${h2}${Lt}`;
1299
+ const B = ".".repeat(Math.floor(t2)).slice(0, 3);
1300
+ v = `${o2} ${s}${B}`;
1058
1301
  }
1059
- const kt = wrapAnsi(Z2, y, { hard: true, trim: false });
1060
- s.write(kt), A2 = A2 + 1 < n.length ? A2 + 1 : 0, L2 = L2 < 4 ? L2 + 0.125 : 0;
1061
- }, a);
1062
- }, W2 = (_ = "", A2 = 0, L2 = false) => {
1063
- if (!p2) return;
1064
- p2 = false, clearInterval(g), N();
1065
- const D2 = A2 === 0 ? e("green", H) : A2 === 1 ? e("red", ut2) : e("red", lt2);
1066
- h2 = _ ?? h2, L2 || (t === "timer" ? s.write(`${D2} ${h2} ${j2(m2)}
1067
- `) : s.write(`${D2} ${h2}
1068
- `)), M(), d();
1302
+ const j = wrapAnsi(v, x, {
1303
+ hard: true,
1304
+ trim: false
1305
+ });
1306
+ n2.write(j), r2 = r2 + 1 < E.length ? r2 + 1 : 0, t2 = t2 < 4 ? t2 + 0.125 : 0;
1307
+ }, F);
1308
+ }, a3 = (e = "", r2 = 0, t2 = false) => {
1309
+ if (!d2) return;
1310
+ d2 = false, clearInterval(T), y();
1311
+ const o2 = r2 === 0 ? styleText2("green", S_STEP_SUBMIT) : r2 === 1 ? styleText2("red", S_STEP_CANCEL) : styleText2("red", S_STEP_ERROR);
1312
+ s = e ?? s, t2 || (l2 === "timer" ? n2.write(`${o2} ${s} ${_(w)}
1313
+ `) : n2.write(`${o2} ${s}
1314
+ `)), H(), M();
1315
+ };
1316
+ return {
1317
+ start: P,
1318
+ stop: (e = "") => a3(e, 0),
1319
+ message: (e = "") => {
1320
+ s = C2(e ?? s);
1321
+ },
1322
+ cancel: (e = "") => a3(e, 1),
1323
+ error: (e = "") => a3(e, 2),
1324
+ clear: () => a3("", 0, true),
1325
+ get isCancelled() {
1326
+ return S;
1327
+ }
1069
1328
  };
1070
- return { start: rt2, stop: (_ = "") => W2(_, 0), message: (_ = "") => {
1071
- h2 = O2(_ ?? h2);
1072
- }, cancel: (_ = "") => W2(_, 1), error: (_ = "") => W2(_, 2), clear: () => W2("", 0, true), get isCancelled() {
1073
- return f2;
1074
- } };
1075
1329
  };
1076
- var Nt = { light: w2("\u2500", "-"), heavy: w2("\u2501", "="), block: w2("\u2588", "#") };
1077
- var it2 = (t, i) => t.includes(`
1078
- `) ? t.split(`
1079
- `).map((s) => i(s)).join(`
1080
- `) : i(t);
1081
- var Ee = (t) => {
1082
- const i = (s, r) => {
1083
- const u = s.label ?? String(s.value);
1084
- switch (r) {
1330
+ var u2 = {
1331
+ light: unicodeOr("\u2500", "-"),
1332
+ heavy: unicodeOr("\u2501", "="),
1333
+ block: unicodeOr("\u2588", "#")
1334
+ };
1335
+ var c = (e, a3) => e.includes(`
1336
+ `) ? e.split(`
1337
+ `).map((t2) => a3(t2)).join(`
1338
+ `) : a3(e);
1339
+ var select = (e) => {
1340
+ const a3 = (t2, d2) => {
1341
+ const s = t2.label ?? String(t2.value);
1342
+ switch (d2) {
1085
1343
  case "disabled":
1086
- return `${e("gray", U)} ${it2(u, (n) => e("gray", n))}${s.hint ? ` ${e("dim", `(${s.hint ?? "disabled"})`)}` : ""}`;
1344
+ return `${styleText2("gray", S_RADIO_INACTIVE)} ${c(s, (n2) => styleText2("gray", n2))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint ?? "disabled"})`)}` : ""}`;
1087
1345
  case "selected":
1088
- return `${it2(u, (n) => e("dim", n))}`;
1346
+ return `${c(s, (n2) => styleText2("dim", n2))}`;
1089
1347
  case "active":
1090
- return `${e("green", z2)} ${u}${s.hint ? ` ${e("dim", `(${s.hint})`)}` : ""}`;
1348
+ return `${styleText2("green", S_RADIO_ACTIVE)} ${s}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}`;
1091
1349
  case "cancelled":
1092
- return `${it2(u, (n) => e(["strikethrough", "dim"], n))}`;
1350
+ return `${c(s, (n2) => styleText2(["strikethrough", "dim"], n2))}`;
1093
1351
  default:
1094
- return `${e("dim", U)} ${it2(u, (n) => e("dim", n))}`;
1352
+ return `${styleText2("dim", S_RADIO_INACTIVE)} ${c(s, (n2) => styleText2("dim", n2))}`;
1095
1353
  }
1096
1354
  };
1097
- return new ht({ options: t.options, signal: t.signal, input: t.input, output: t.output, initialValue: t.initialValue, render() {
1098
- const s = t.withGuide ?? h.withGuide, r = `${P2(this.state)} `, u = `${ft(this.state)} `, n = B(t.output, t.message, u, r), a = `${s ? `${e("gray", $)}
1099
- ` : ""}${n}
1355
+ return new a2({
1356
+ options: e.options,
1357
+ signal: e.signal,
1358
+ input: e.input,
1359
+ output: e.output,
1360
+ initialValue: e.initialValue,
1361
+ render() {
1362
+ const t2 = e.withGuide ?? settings.withGuide, d2 = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, n2 = wrapTextWithPrefix(
1363
+ e.output,
1364
+ e.message,
1365
+ s,
1366
+ d2
1367
+ ), u3 = `${t2 ? `${styleText2("gray", S_BAR)}
1368
+ ` : ""}${n2}
1369
+ `;
1370
+ switch (this.state) {
1371
+ case "submit": {
1372
+ const r2 = t2 ? `${styleText2("gray", S_BAR)} ` : "", l2 = wrapTextWithPrefix(
1373
+ e.output,
1374
+ a3(this.options[this.cursor], "selected"),
1375
+ r2
1376
+ );
1377
+ return `${u3}${l2}`;
1378
+ }
1379
+ case "cancel": {
1380
+ const r2 = t2 ? `${styleText2("gray", S_BAR)} ` : "", l2 = wrapTextWithPrefix(
1381
+ e.output,
1382
+ a3(this.options[this.cursor], "cancelled"),
1383
+ r2
1384
+ );
1385
+ return `${u3}${l2}${t2 ? `
1386
+ ${styleText2("gray", S_BAR)}` : ""}`;
1387
+ }
1388
+ default: {
1389
+ const r2 = t2 ? `${styleText2("cyan", S_BAR)} ` : "", l2 = t2 ? styleText2("cyan", S_BAR_END) : "", g = u3.split(`
1390
+ `).length, h2 = t2 ? 2 : 1;
1391
+ return `${u3}${r2}${limitOptions({
1392
+ output: e.output,
1393
+ cursor: this.cursor,
1394
+ options: this.options,
1395
+ maxItems: e.maxItems,
1396
+ columnPadding: r2.length,
1397
+ rowPadding: g + h2,
1398
+ style: (p, b) => a3(p, p.disabled ? "disabled" : b ? "active" : "inactive")
1399
+ }).join(`
1400
+ ${r2}`)}
1401
+ ${l2}
1100
1402
  `;
1403
+ }
1404
+ }
1405
+ }
1406
+ }).prompt();
1407
+ };
1408
+ var i = `${styleText2("gray", S_BAR)} `;
1409
+ var text = (t2) => new n({
1410
+ validate: t2.validate,
1411
+ placeholder: t2.placeholder,
1412
+ defaultValue: t2.defaultValue,
1413
+ initialValue: t2.initialValue,
1414
+ output: t2.output,
1415
+ signal: t2.signal,
1416
+ input: t2.input,
1417
+ render() {
1418
+ const i2 = t2?.withGuide ?? settings.withGuide, s = `${`${i2 ? `${styleText2("gray", S_BAR)}
1419
+ ` : ""}${symbol(this.state)} `}${t2.message}
1420
+ `, c2 = t2.placeholder ? styleText2("inverse", t2.placeholder[0]) + styleText2("dim", t2.placeholder.slice(1)) : styleText2(["inverse", "hidden"], "_"), o2 = this.userInput ? this.userInputWithCursor : c2, a3 = this.value ?? "";
1101
1421
  switch (this.state) {
1422
+ case "error": {
1423
+ const n2 = this.error ? ` ${styleText2("yellow", this.error)}` : "", r2 = i2 ? `${styleText2("yellow", S_BAR)} ` : "", d2 = i2 ? styleText2("yellow", S_BAR_END) : "";
1424
+ return `${s.trim()}
1425
+ ${r2}${o2}
1426
+ ${d2}${n2}
1427
+ `;
1428
+ }
1102
1429
  case "submit": {
1103
- const c = s ? `${e("gray", $)} ` : "", o = B(t.output, i(this.options[this.cursor], "selected"), c);
1104
- return `${a}${o}`;
1430
+ const n2 = a3 ? ` ${styleText2("dim", a3)}` : "", r2 = i2 ? styleText2("gray", S_BAR) : "";
1431
+ return `${s}${r2}${n2}`;
1105
1432
  }
1106
1433
  case "cancel": {
1107
- const c = s ? `${e("gray", $)} ` : "", o = B(t.output, i(this.options[this.cursor], "cancelled"), c);
1108
- return `${a}${o}${s ? `
1109
- ${e("gray", $)}` : ""}`;
1434
+ const n2 = a3 ? ` ${styleText2(["strikethrough", "dim"], a3)}` : "", r2 = i2 ? styleText2("gray", S_BAR) : "";
1435
+ return `${s}${r2}${n2}${a3.trim() ? `
1436
+ ${r2}` : ""}`;
1110
1437
  }
1111
1438
  default: {
1112
- const c = s ? `${e("cyan", $)} ` : "", o = s ? e("cyan", x2) : "", l = a.split(`
1113
- `).length, d = s ? 2 : 1;
1114
- return `${a}${c}${F({ output: t.output, cursor: this.cursor, options: this.options, maxItems: t.maxItems, columnPadding: c.length, rowPadding: l + d, style: (g, p2) => i(g, g.disabled ? "disabled" : p2 ? "active" : "inactive") }).join(`
1115
- ${c}`)}
1116
- ${o}
1439
+ const n2 = i2 ? `${styleText2("cyan", S_BAR)} ` : "", r2 = i2 ? styleText2("cyan", S_BAR_END) : "";
1440
+ return `${s}${n2}${o2}
1441
+ ${r2}
1117
1442
  `;
1118
1443
  }
1119
1444
  }
1120
- } }).prompt();
1121
- };
1122
- var Bt = `${e("gray", $)} `;
1123
- var Re = (t) => new ct({ validate: t.validate, placeholder: t.placeholder, defaultValue: t.defaultValue, initialValue: t.initialValue, output: t.output, signal: t.signal, input: t.input, render() {
1124
- const i = t?.withGuide ?? h.withGuide, s = `${`${i ? `${e("gray", $)}
1125
- ` : ""}${P2(this.state)} `}${t.message}
1126
- `, r = t.placeholder ? e("inverse", t.placeholder[0]) + e("dim", t.placeholder.slice(1)) : e(["inverse", "hidden"], "_"), u = this.userInput ? this.userInputWithCursor : r, n = this.value ?? "";
1127
- switch (this.state) {
1128
- case "error": {
1129
- const a = this.error ? ` ${e("yellow", this.error)}` : "", c = i ? `${e("yellow", $)} ` : "", o = i ? e("yellow", x2) : "";
1130
- return `${s.trim()}
1131
- ${c}${u}
1132
- ${o}${a}
1133
- `;
1134
- }
1135
- case "submit": {
1136
- const a = n ? ` ${e("dim", n)}` : "", c = i ? e("gray", $) : "";
1137
- return `${s}${c}${a}`;
1138
- }
1139
- case "cancel": {
1140
- const a = n ? ` ${e(["strikethrough", "dim"], n)}` : "", c = i ? e("gray", $) : "";
1141
- return `${s}${c}${a}${n.trim() ? `
1142
- ${c}` : ""}`;
1143
- }
1144
- default: {
1145
- const a = i ? `${e("cyan", $)} ` : "", c = i ? e("cyan", x2) : "";
1146
- return `${s}${a}${u}
1147
- ${c}
1148
- `;
1149
- }
1150
1445
  }
1151
- } }).prompt();
1446
+ }).prompt();
1152
1447
 
1153
1448
  // src/cli/configure.ts
1154
1449
  var import_picocolors2 = __toESM(require_picocolors(), 1);
@@ -1179,55 +1474,55 @@ var PKG_VERSION = {
1179
1474
  var TAILWIND_ENTRY = "styles/tailwind.css";
1180
1475
  var TAILWIND_CSS = `@import 'tailwindcss';
1181
1476
  `;
1182
- function styleEntry(p2) {
1183
- return `styles/main.${STYLE_EXT[p2]}`;
1477
+ function styleEntry(p) {
1478
+ return `styles/main.${STYLE_EXT[p]}`;
1184
1479
  }
1185
1480
  function preprocessorForExt(ext) {
1186
- const e2 = ext.replace(/^\./, "");
1187
- if (e2 === "sass") return "sass";
1188
- return PREPROCESSORS.find((p2) => STYLE_EXT[p2] === e2) ?? null;
1481
+ const e = ext.replace(/^\./, "");
1482
+ if (e === "sass") return "sass";
1483
+ return PREPROCESSORS.find((p) => STYLE_EXT[p] === e) ?? null;
1189
1484
  }
1190
- function requiredPackages(f2) {
1485
+ function requiredPackages(f) {
1191
1486
  const pkgs = [];
1192
- const pp = PREPROCESSOR_PKG[f2.preprocessor];
1487
+ const pp = PREPROCESSOR_PKG[f.preprocessor];
1193
1488
  if (pp) pkgs.push(pp);
1194
- if (f2.tailwind) pkgs.push(...TAILWIND_PKGS);
1489
+ if (f.tailwind) pkgs.push(...TAILWIND_PKGS);
1195
1490
  return pkgs;
1196
1491
  }
1197
1492
  function packageDiff(from, to) {
1198
1493
  const want = new Set(requiredPackages(to));
1199
1494
  const had = new Set(requiredPackages(from));
1200
1495
  return {
1201
- add: [...want].filter((p2) => !had.has(p2)),
1202
- remove: [...had].filter((p2) => !want.has(p2))
1496
+ add: [...want].filter((p) => !had.has(p)),
1497
+ remove: [...had].filter((p) => !want.has(p))
1203
1498
  };
1204
1499
  }
1205
- function styleImportLines(f2) {
1500
+ function styleImportLines(f) {
1206
1501
  const lines = [];
1207
- if (f2.tailwind) lines.push(`import './${TAILWIND_ENTRY}';`);
1208
- lines.push(`import './${styleEntry(f2.preprocessor)}';`);
1502
+ if (f.tailwind) lines.push(`import './${TAILWIND_ENTRY}';`);
1503
+ lines.push(`import './${styleEntry(f.preprocessor)}';`);
1209
1504
  return lines;
1210
1505
  }
1211
- function setStyleImports(source, f2) {
1506
+ function setStyleImports(source, f) {
1212
1507
  const stripped = source.replace(
1213
1508
  /^[ \t]*import\s+['"]\.\/styles\/[^'"]+['"];?[ \t]*\r?\n/gm,
1214
1509
  ""
1215
1510
  );
1216
- const block = styleImportLines(f2).join("\n") + "\n";
1511
+ const block2 = styleImportLines(f).join("\n") + "\n";
1217
1512
  const lines = stripped.split("\n");
1218
- const routesIdx = lines.findIndex((l) => /from\s+['"]toiljs\/routes['"]/.test(l));
1513
+ const routesIdx = lines.findIndex((l2) => /from\s+['"]toiljs\/routes['"]/.test(l2));
1219
1514
  let insertAt;
1220
1515
  if (routesIdx !== -1) {
1221
1516
  insertAt = routesIdx + 1;
1222
1517
  } else {
1223
- const lastImport = lines.reduce((acc, l, i) => /^\s*import\s/.test(l) ? i : acc, -1);
1518
+ const lastImport = lines.reduce((acc, l2, i2) => /^\s*import\s/.test(l2) ? i2 : acc, -1);
1224
1519
  insertAt = lastImport + 1;
1225
1520
  }
1226
1521
  const head = lines.slice(0, insertAt).join("\n");
1227
1522
  const tail = lines.slice(insertAt).join("\n");
1228
1523
  return `${head}
1229
1524
 
1230
- ${block}
1525
+ ${block2}
1231
1526
  ${tail}`.replace(/\n{3,}/g, "\n\n");
1232
1527
  }
1233
1528
  function defaultConfigSource(images) {
@@ -1286,17 +1581,17 @@ function capture(cmd, args, cwd) {
1286
1581
  return new Promise((resolve, reject) => {
1287
1582
  const onWindows = process.platform === "win32";
1288
1583
  const child = onWindows ? spawn([cmd, ...args].join(" "), { cwd, shell: true }) : spawn(cmd, args, { cwd });
1289
- let stdout = "";
1584
+ let stdout2 = "";
1290
1585
  let stderr = "";
1291
- child.stdout?.on("data", (d) => {
1292
- stdout += d.toString();
1586
+ child.stdout?.on("data", (d2) => {
1587
+ stdout2 += d2.toString();
1293
1588
  });
1294
- child.stderr?.on("data", (d) => {
1295
- stderr += d.toString();
1589
+ child.stderr?.on("data", (d2) => {
1590
+ stderr += d2.toString();
1296
1591
  });
1297
1592
  child.on("error", reject);
1298
1593
  child.on("close", (code) => {
1299
- resolve({ stdout, stderr, code: code ?? 1 });
1594
+ resolve({ stdout: stdout2, stderr, code: code ?? 1 });
1300
1595
  });
1301
1596
  });
1302
1597
  }
@@ -1337,24 +1632,24 @@ function success(s) {
1337
1632
  }
1338
1633
  var danger = import_picocolors.default.red;
1339
1634
  var warn = import_picocolors.default.yellow;
1340
- function lerp(a, b2, t) {
1341
- return Math.round(a + (b2 - a) * t);
1635
+ function lerp(a3, b, t2) {
1636
+ return Math.round(a3 + (b - a3) * t2);
1342
1637
  }
1343
- function gradientAt(t) {
1638
+ function gradientAt(t2) {
1344
1639
  const segments = GRADIENT.length - 1;
1345
- const scaled = t * segments;
1346
- const i = Math.min(Math.floor(scaled), segments - 1);
1347
- const a = GRADIENT[i];
1348
- const b2 = GRADIENT[i + 1];
1349
- const localT = scaled - i;
1350
- return [lerp(a[0], b2[0], localT), lerp(a[1], b2[1], localT), lerp(a[2], b2[2], localT)];
1640
+ const scaled = t2 * segments;
1641
+ const i2 = Math.min(Math.floor(scaled), segments - 1);
1642
+ const a3 = GRADIENT[i2];
1643
+ const b = GRADIENT[i2 + 1];
1644
+ const localT = scaled - i2;
1645
+ return [lerp(a3[0], b[0], localT), lerp(a3[1], b[1], localT), lerp(a3[2], b[2], localT)];
1351
1646
  }
1352
1647
  function gradientLine(line) {
1353
- const n = line.length;
1648
+ const n2 = line.length;
1354
1649
  let out = "";
1355
- for (let i = 0; i < n; i++) {
1356
- const [r, g, b2] = gradientAt(n > 1 ? i / (n - 1) : 0);
1357
- out += `\x1B[38;2;${r};${g};${b2}m${line[i]}`;
1650
+ for (let i2 = 0; i2 < n2; i2++) {
1651
+ const [r2, g, b] = gradientAt(n2 > 1 ? i2 / (n2 - 1) : 0);
1652
+ out += `\x1B[38;2;${r2};${g};${b}m${line[i2]}`;
1358
1653
  }
1359
1654
  return out + "\x1B[39m";
1360
1655
  }
@@ -1393,9 +1688,9 @@ var CONFIG_FILES = [
1393
1688
  ];
1394
1689
  async function readConfigFile(root) {
1395
1690
  for (const name of CONFIG_FILES) {
1396
- const p2 = path2.join(root, name);
1691
+ const p = path2.join(root, name);
1397
1692
  try {
1398
- return { path: p2, source: await fs2.readFile(p2, "utf8") };
1693
+ return { path: p, source: await fs2.readFile(p, "utf8") };
1399
1694
  } catch {
1400
1695
  }
1401
1696
  }
@@ -1434,16 +1729,16 @@ var PREPROCESSOR_LABEL = {
1434
1729
  stylus: "Stylus"
1435
1730
  };
1436
1731
  function bail(value) {
1437
- if (R(value)) {
1438
- ge("Configuration cancelled.");
1732
+ if (isCancel(value)) {
1733
+ cancel("Configuration cancelled.");
1439
1734
  process.exit(0);
1440
1735
  }
1441
1736
  }
1442
1737
  async function detectStylesheet(clientDir) {
1443
- for (const p2 of PREPROCESSORS) {
1738
+ for (const p of PREPROCESSORS) {
1444
1739
  try {
1445
- await fs2.access(path2.join(clientDir, styleEntry(p2)));
1446
- return p2;
1740
+ await fs2.access(path2.join(clientDir, styleEntry(p)));
1741
+ return p;
1447
1742
  } catch {
1448
1743
  }
1449
1744
  }
@@ -1456,10 +1751,10 @@ async function detectStylesheet(clientDir) {
1456
1751
  }
1457
1752
  async function findMainStylesheet(clientDir) {
1458
1753
  for (const ext of ["css", "scss", "sass", "less", "styl"]) {
1459
- const p2 = path2.join(clientDir, "styles", `main.${ext}`);
1754
+ const p = path2.join(clientDir, "styles", `main.${ext}`);
1460
1755
  try {
1461
- await fs2.access(p2);
1462
- return p2;
1756
+ await fs2.access(p);
1757
+ return p;
1463
1758
  } catch {
1464
1759
  }
1465
1760
  }
@@ -1522,7 +1817,7 @@ async function applyPackages(pkgPath, pkg, from, to) {
1522
1817
  delete deps[name];
1523
1818
  }
1524
1819
  const sortedDev = Object.fromEntries(
1525
- Object.entries(dev2).sort(([a], [b2]) => a.localeCompare(b2))
1820
+ Object.entries(dev2).sort(([a3], [b]) => a3.localeCompare(b))
1526
1821
  );
1527
1822
  const next = { ...pkg, devDependencies: sortedDev };
1528
1823
  if (Object.keys(deps).length) next.dependencies = deps;
@@ -1542,17 +1837,17 @@ function describe(from, to) {
1542
1837
  const { add, remove } = packageDiff(from, to);
1543
1838
  if (add.length) lines.push(`+ ${add.join(", ")}`);
1544
1839
  if (remove.length) lines.push(`- ${remove.join(", ")}`);
1545
- return lines.map((l) => dim(" ") + l).join("\n");
1840
+ return lines.map((l2) => dim(" ") + l2).join("\n");
1546
1841
  }
1547
1842
  async function runConfigure(opts) {
1548
- ye(accent(" toiljs configure "));
1843
+ intro(accent(" toiljs configure "));
1549
1844
  const root = path2.resolve(opts.root ?? opts.cwd);
1550
1845
  const pkgPath = path2.join(root, "package.json");
1551
1846
  let pkg;
1552
1847
  try {
1553
1848
  pkg = JSON.parse(await fs2.readFile(pkgPath, "utf8"));
1554
1849
  } catch {
1555
- ge(`No package.json in ${import_picocolors2.default.cyan(root)}, run this inside a toiljs project.`);
1850
+ cancel(`No package.json in ${import_picocolors2.default.cyan(root)}, run this inside a toiljs project.`);
1556
1851
  process.exit(1);
1557
1852
  }
1558
1853
  const clientAbsDir = await resolveClientDir(root);
@@ -1572,18 +1867,18 @@ async function runConfigure(opts) {
1572
1867
  };
1573
1868
  targetImages = opts.images ?? currentImages;
1574
1869
  } else {
1575
- const ppChoice = await Ee({
1870
+ const ppChoice = await select({
1576
1871
  message: "CSS preprocessor",
1577
1872
  options: PREPROCESSORS.map((value) => ({ value, label: PREPROCESSOR_LABEL[value] })),
1578
1873
  initialValue: current.preprocessor
1579
1874
  });
1580
1875
  bail(ppChoice);
1581
- const twChoice = await le({
1876
+ const twChoice = await confirm({
1582
1877
  message: "Use Tailwind CSS?",
1583
1878
  initialValue: current.tailwind
1584
1879
  });
1585
1880
  bail(twChoice);
1586
- const imChoice = await le({
1881
+ const imChoice = await confirm({
1587
1882
  message: "Optimize images at build time?",
1588
1883
  initialValue: currentImages
1589
1884
  });
@@ -1594,10 +1889,10 @@ async function runConfigure(opts) {
1594
1889
  const styleChanged = target.preprocessor !== current.preprocessor || target.tailwind !== current.tailwind;
1595
1890
  const imagesChanged = targetImages !== currentImages;
1596
1891
  if (!styleChanged && !imagesChanged) {
1597
- fe("No changes, your setup is already up to date.");
1892
+ outro("No changes, your setup is already up to date.");
1598
1893
  return;
1599
1894
  }
1600
- const s = vt();
1895
+ const s = spinner();
1601
1896
  s.start("Updating project files");
1602
1897
  if (styleChanged) await applyConfigure(clientAbsDir, pkgPath, pkg, current, target);
1603
1898
  let imagesWarning = "";
@@ -1610,15 +1905,15 @@ async function runConfigure(opts) {
1610
1905
  if (styleChanged) {
1611
1906
  const pm = await detectPackageManager(root);
1612
1907
  if (opts.install === false) {
1613
- Ce(`${import_picocolors2.default.cyan(`${pm} install`)} to sync the dependency changes.`, "Next step");
1908
+ note(`${import_picocolors2.default.cyan(`${pm} install`)} to sync the dependency changes.`, "Next step");
1614
1909
  } else {
1615
- const i = vt();
1616
- i.start(`Syncing dependencies with ${pm}`);
1910
+ const i2 = spinner();
1911
+ i2.start(`Syncing dependencies with ${pm}`);
1617
1912
  try {
1618
1913
  await run(pm, ["install"], root);
1619
- i.stop("Dependencies synced");
1914
+ i2.stop("Dependencies synced");
1620
1915
  } catch {
1621
- i.stop(import_picocolors2.default.yellow(`Could not run \`${pm} install\`, run it yourself to finish`));
1916
+ i2.stop(import_picocolors2.default.yellow(`Could not run \`${pm} install\`, run it yourself to finish`));
1622
1917
  }
1623
1918
  }
1624
1919
  }
@@ -1627,8 +1922,8 @@ async function runConfigure(opts) {
1627
1922
  imagesChanged ? dim(" ") + `image optimization: ${currentImages ? "on" : "off"} \u2192 ${targetImages ? "on" : "off"}` : "",
1628
1923
  imagesWarning
1629
1924
  ].filter(Boolean).join("\n");
1630
- Ce(summary, "Updated");
1631
- fe(`Reconfigured, restart \`${accent("toiljs dev")}\` to pick up the changes.`);
1925
+ note(summary, "Updated");
1926
+ outro(`Reconfigured, restart \`${accent("toiljs dev")}\` to pick up the changes.`);
1632
1927
  }
1633
1928
 
1634
1929
  // src/cli/create.ts
@@ -1665,8 +1960,8 @@ var PREPROCESSOR_LABEL2 = {
1665
1960
  };
1666
1961
  var DEFAULT_STYLE_CONTENT = ":root {\n color-scheme: dark;\n}\n\nbody {\n margin: 0;\n background: #080d11;\n color: #f5f6fa;\n font-family: system-ui, -apple-system, sans-serif;\n line-height: 1.6;\n}\n\na {\n color: #2563ff;\n text-decoration: none;\n}\n\na:hover {\n color: #22e3ab;\n}\n\ncode {\n background: #11161f;\n color: #22e3ab;\n padding: 0.1rem 0.4rem;\n border-radius: 4px;\n font-size: 0.9em;\n}\n\nh1 {\n background: linear-gradient(90deg, #2563ff, #7c3aed, #22e3ab);\n -webkit-background-clip: text;\n background-clip: text;\n color: transparent;\n}\n";
1667
1962
  function bail2(value) {
1668
- if (R(value)) {
1669
- ge("Scaffolding cancelled.");
1963
+ if (isCancel(value)) {
1964
+ cancel("Scaffolding cancelled.");
1670
1965
  process.exit(0);
1671
1966
  }
1672
1967
  }
@@ -1685,7 +1980,7 @@ function scaffold(name, template, features, aiTools, images) {
1685
1980
  "@types/react-dom": "^19.2.3",
1686
1981
  eslint: "^10.2.0",
1687
1982
  prettier: "^3.8.1",
1688
- toilscript: "^0.1.2",
1983
+ toilscript: "^0.1.13",
1689
1984
  typescript: "^6.0.3"
1690
1985
  };
1691
1986
  for (const dep of requiredPackages(features).sort()) {
@@ -1697,9 +1992,8 @@ function scaffold(name, template, features, aiTools, images) {
1697
1992
  type: "module",
1698
1993
  scripts: {
1699
1994
  dev: "toiljs dev",
1700
- build: "toiljs build && toilscript --target release",
1701
- "build:client": "toiljs build",
1702
- "build:server": "toilscript --target release",
1995
+ build: "toiljs build",
1996
+ "build:server": "toilscript --target release --rpcModule shared/server.ts",
1703
1997
  lint: "eslint client",
1704
1998
  typecheck: "tsc --noEmit",
1705
1999
  format: 'prettier --write "client/**/*.{ts,tsx,css,scss,less}" "client/public/**/*.html"'
@@ -1722,10 +2016,13 @@ export default defineConfig({
1722
2016
  },
1723
2017
  });
1724
2018
  `,
1725
- "tsconfig.json": '{\n "extends": "toiljs/tsconfig",\n "include": ["client", "toil-env.d.ts", "toil-routes.d.ts"]\n}\n',
2019
+ "tsconfig.json": '{\n "extends": "toiljs/tsconfig",\n "compilerOptions": {\n "paths": { "shared/*": ["./shared/*"] }\n },\n "include": ["client", "shared", "toil-env.d.ts", "toil-routes.d.ts"]\n}\n',
1726
2020
  "eslint.config.js": "import toiljs from 'toiljs/eslint';\n\nexport default toiljs;\n",
1727
2021
  ".prettierrc": '"toiljs/prettier"\n',
1728
- ".gitignore": "node_modules\nbuild\n.toil\ntoil-env.d.ts\ntoil-routes.d.ts\n",
2022
+ // Generated files don't need formatting. (toilscript server decorators like @main /
2023
+ // @remote-on-functions are handled by the toiljs/prettier-plugin, so server/ is not ignored.)
2024
+ ".prettierignore": "node_modules\nbuild\n.toil\nshared/server.ts\ntoil-env.d.ts\ntoil-routes.d.ts\n",
2025
+ ".gitignore": "node_modules\nbuild\n.toil\nshared/server.ts\ntoil-env.d.ts\ntoil-routes.d.ts\n",
1729
2026
  // Use the project's pinned TypeScript (node_modules) instead of VS Code's bundled version.
1730
2027
  ".vscode/settings.json": JSON.stringify({ "typescript.tsdk": "node_modules/typescript/lib" }, null, 4) + "\n",
1731
2028
  "toil-env.d.ts": TOIL_ENV_DTS,
@@ -1898,18 +2195,18 @@ async function writeFiles(dir, files) {
1898
2195
  }
1899
2196
  }
1900
2197
  async function runCreate(opts) {
1901
- ye(accent(" toiljs create "));
2198
+ intro(accent(" toiljs create "));
1902
2199
  let name = opts.name;
1903
2200
  if (!name) {
1904
2201
  if (opts.yes) {
1905
2202
  name = "my-toil-app";
1906
2203
  } else {
1907
- const answer = await Re({
2204
+ const answer = await text({
1908
2205
  message: "Project name",
1909
2206
  placeholder: "my-toil-app",
1910
2207
  defaultValue: "my-toil-app",
1911
- validate: (v2) => {
1912
- const result = isValidName(v2 || "my-toil-app");
2208
+ validate: (v) => {
2209
+ const result = isValidName(v || "my-toil-app");
1913
2210
  return result === true ? void 0 : result;
1914
2211
  }
1915
2212
  });
@@ -1919,27 +2216,27 @@ async function runCreate(opts) {
1919
2216
  }
1920
2217
  const valid = isValidName(name);
1921
2218
  if (valid !== true) {
1922
- ge(valid);
2219
+ cancel(valid);
1923
2220
  process.exit(1);
1924
2221
  }
1925
2222
  const targetDir = resolveProjectDir(opts.cwd, name);
1926
2223
  if (targetDir === null) {
1927
- ge('Project name must stay inside the current directory (no "..", no absolute paths).');
2224
+ cancel('Project name must stay inside the current directory (no "..", no absolute paths).');
1928
2225
  process.exit(1);
1929
2226
  }
1930
2227
  const rel = path4.relative(opts.cwd, targetDir) || ".";
1931
2228
  if (!await isEmptyDir(targetDir)) {
1932
2229
  if (opts.yes) {
1933
- ge(`Directory ${import_picocolors3.default.cyan(rel)} is not empty.`);
2230
+ cancel(`Directory ${import_picocolors3.default.cyan(rel)} is not empty.`);
1934
2231
  process.exit(1);
1935
2232
  }
1936
- const proceed = await le({
2233
+ const proceed = await confirm({
1937
2234
  message: `Directory ${import_picocolors3.default.cyan(rel)} is not empty. Scaffold into it anyway?`,
1938
2235
  initialValue: false
1939
2236
  });
1940
2237
  bail2(proceed);
1941
2238
  if (!proceed) {
1942
- ge("Scaffolding cancelled.");
2239
+ cancel("Scaffolding cancelled.");
1943
2240
  process.exit(0);
1944
2241
  }
1945
2242
  }
@@ -1953,7 +2250,7 @@ async function runCreate(opts) {
1953
2250
  },
1954
2251
  { value: "minimal", label: "Minimal", hint: "just a layout and a home route" }
1955
2252
  ];
1956
- const choice = await Ee({
2253
+ const choice = await select({
1957
2254
  message: "Which template?",
1958
2255
  options: templateOptions,
1959
2256
  initialValue: "app"
@@ -1965,7 +2262,7 @@ async function runCreate(opts) {
1965
2262
  let tailwind = opts.tailwind ?? false;
1966
2263
  if (!opts.yes) {
1967
2264
  if (opts.preprocessor === void 0) {
1968
- const choice = await Ee({
2265
+ const choice = await select({
1969
2266
  message: "Styling",
1970
2267
  options: PREPROCESSORS.map((value) => ({
1971
2268
  value,
@@ -1977,7 +2274,7 @@ async function runCreate(opts) {
1977
2274
  preprocessor = choice;
1978
2275
  }
1979
2276
  if (opts.tailwind === void 0) {
1980
- const tw = await le({ message: "Add Tailwind CSS?", initialValue: false });
2277
+ const tw = await confirm({ message: "Add Tailwind CSS?", initialValue: false });
1981
2278
  bail2(tw);
1982
2279
  tailwind = tw;
1983
2280
  }
@@ -1985,7 +2282,7 @@ async function runCreate(opts) {
1985
2282
  const features = { preprocessor, tailwind };
1986
2283
  let aiTools = opts.ai === false ? [] : [...AI_HELPER_IDS];
1987
2284
  if (opts.ai === void 0 && !opts.yes) {
1988
- const picked = await we({
2285
+ const picked = await multiselect({
1989
2286
  message: "AI assistant files (read by Claude, Cursor, Codex, Copilot)",
1990
2287
  options: [
1991
2288
  ...AI_HELPERS.map((h2) => ({ value: h2.id, label: h2.label })),
@@ -1999,7 +2296,7 @@ async function runCreate(opts) {
1999
2296
  }
2000
2297
  let images = opts.images ?? true;
2001
2298
  if (opts.images === void 0 && !opts.yes) {
2002
- const im = await le({ message: "Optimize images at build time?", initialValue: true });
2299
+ const im = await confirm({ message: "Optimize images at build time?", initialValue: true });
2003
2300
  bail2(im);
2004
2301
  images = im;
2005
2302
  }
@@ -2007,12 +2304,12 @@ async function runCreate(opts) {
2007
2304
  let install = opts.install ?? false;
2008
2305
  const pm = opts.pm ?? "npm";
2009
2306
  if (!isPackageManager(pm)) {
2010
- ge(`Unsupported package manager: ${pm} (use npm, pnpm, yarn, or bun).`);
2307
+ cancel(`Unsupported package manager: ${pm} (use npm, pnpm, yarn, or bun).`);
2011
2308
  process.exit(1);
2012
2309
  }
2013
2310
  if (!opts.yes) {
2014
2311
  if (opts.git === void 0) {
2015
- const g = await le({
2312
+ const g = await confirm({
2016
2313
  message: "Initialize a git repository?",
2017
2314
  initialValue: true
2018
2315
  });
@@ -2020,12 +2317,12 @@ async function runCreate(opts) {
2020
2317
  initGit = g;
2021
2318
  }
2022
2319
  if (opts.install === void 0) {
2023
- const i = await le({ message: "Install dependencies now?", initialValue: false });
2024
- bail2(i);
2025
- install = i;
2320
+ const i2 = await confirm({ message: "Install dependencies now?", initialValue: false });
2321
+ bail2(i2);
2322
+ install = i2;
2026
2323
  }
2027
2324
  }
2028
- const s = vt();
2325
+ const s = spinner();
2029
2326
  s.start("Scaffolding project");
2030
2327
  await writeFiles(targetDir, scaffold(name, template, features, aiTools, images));
2031
2328
  if (template === "app") {
@@ -2040,7 +2337,7 @@ async function runCreate(opts) {
2040
2337
  }
2041
2338
  s.stop(`Scaffolded ${import_picocolors3.default.cyan(rel)}`);
2042
2339
  if (initGit) {
2043
- const g = vt();
2340
+ const g = spinner();
2044
2341
  g.start("Initializing git repository");
2045
2342
  try {
2046
2343
  await run("git", ["init", "-q"], targetDir);
@@ -2051,13 +2348,13 @@ async function runCreate(opts) {
2051
2348
  }
2052
2349
  }
2053
2350
  if (install) {
2054
- const i = vt();
2055
- i.start(`Installing dependencies with ${pm}`);
2351
+ const i2 = spinner();
2352
+ i2.start(`Installing dependencies with ${pm}`);
2056
2353
  try {
2057
2354
  await run(pm, ["install"], targetDir);
2058
- i.stop("Installed dependencies");
2355
+ i2.stop("Installed dependencies");
2059
2356
  } catch {
2060
- i.stop(import_picocolors3.default.yellow(`Could not install with ${pm}, run it yourself later`));
2357
+ i2.stop(import_picocolors3.default.yellow(`Could not install with ${pm}, run it yourself later`));
2061
2358
  install = false;
2062
2359
  }
2063
2360
  }
@@ -2066,8 +2363,8 @@ async function runCreate(opts) {
2066
2363
  if (!install) steps.push("npm install");
2067
2364
  steps.push(`${accent("npm run dev")} ${dim("start the dev server")}`);
2068
2365
  steps.push(`${accent("npm run build")} ${dim("build for production")}`);
2069
- Ce(steps.map((l) => dim(" ") + l).join("\n"), "Next steps");
2070
- fe(`Created ${accent(path4.basename(name))}, happy building! ${dim("\xB7 v" + version())}`);
2366
+ note(steps.map((l2) => dim(" ") + l2).join("\n"), "Next steps");
2367
+ outro(`Created ${accent(path4.basename(name))}, happy building! ${dim("\xB7 v" + version())}`);
2071
2368
  }
2072
2369
 
2073
2370
  // src/cli/doctor.ts
@@ -2078,17 +2375,17 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
2078
2375
  import { loadConfig as loadConfig2, scanRoutes } from "toiljs/compiler";
2079
2376
 
2080
2377
  // src/cli/diagnostics.ts
2081
- function parseVersion(v2) {
2082
- const m2 = /(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(v2);
2083
- if (!m2) return [0, 0, 0];
2084
- return [Number(m2[1]), Number(m2[2] ?? 0), Number(m2[3] ?? 0)];
2378
+ function parseVersion(v) {
2379
+ const m = /(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(v);
2380
+ if (!m) return [0, 0, 0];
2381
+ return [Number(m[1]), Number(m[2] ?? 0), Number(m[3] ?? 0)];
2085
2382
  }
2086
2383
  function satisfiesMin(version2, range) {
2087
- const [a, b2, c] = parseVersion(version2);
2088
- const [x3, y, z3] = parseVersion(range);
2089
- if (a !== x3) return a > x3;
2090
- if (b2 !== y) return b2 > y;
2091
- return c >= z3;
2384
+ const [a3, b, c2] = parseVersion(version2);
2385
+ const [x, y, z] = parseVersion(range);
2386
+ if (a3 !== x) return a3 > x;
2387
+ if (b !== y) return b > y;
2388
+ return c2 >= z;
2092
2389
  }
2093
2390
  function checkNode(current, requiredRange) {
2094
2391
  const ok = satisfiesMin(current, requiredRange);
@@ -2210,9 +2507,9 @@ function checkRoutesPresent(routeCount) {
2210
2507
  function checkDuplicatePatterns(patterns) {
2211
2508
  const seen = /* @__PURE__ */ new Set();
2212
2509
  const dupes = /* @__PURE__ */ new Set();
2213
- for (const p2 of patterns) {
2214
- if (seen.has(p2)) dupes.add(p2);
2215
- else seen.add(p2);
2510
+ for (const p of patterns) {
2511
+ if (seen.has(p)) dupes.add(p);
2512
+ else seen.add(p);
2216
2513
  }
2217
2514
  return dupes.size === 0 ? { id: "route-dupes", label: "Unique route patterns", status: "pass" } : {
2218
2515
  id: "route-dupes",
@@ -2236,13 +2533,13 @@ function findRelativeAssets(files) {
2236
2533
  const attr = /\b(?:src|href)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
2237
2534
  for (const file of files) {
2238
2535
  const lines = file.source.split("\n");
2239
- for (let i = 0; i < lines.length; i++) {
2536
+ for (let i2 = 0; i2 < lines.length; i2++) {
2240
2537
  attr.lastIndex = 0;
2241
- let m2;
2242
- while ((m2 = attr.exec(lines[i])) !== null) {
2243
- const value = m2[1] ?? m2[2] ?? "";
2538
+ let m;
2539
+ while ((m = attr.exec(lines[i2])) !== null) {
2540
+ const value = m[1] ?? m[2] ?? "";
2244
2541
  if (isBrokenRelativeAsset(value)) {
2245
- issues.push({ file: file.path, line: i + 1, value });
2542
+ issues.push({ file: file.path, line: i2 + 1, value });
2246
2543
  }
2247
2544
  }
2248
2545
  }
@@ -2251,7 +2548,7 @@ function findRelativeAssets(files) {
2251
2548
  }
2252
2549
  function checkRelativeAssets(issues) {
2253
2550
  if (issues.length === 0) return { id: "rel-assets", label: "Asset paths", status: "pass" };
2254
- const shown = issues.slice(0, 5).map((i) => `${i.file}:${String(i.line)} "${i.value}"`).join("; ");
2551
+ const shown = issues.slice(0, 5).map((i2) => `${i2.file}:${String(i2.line)} "${i2.value}"`).join("; ");
2255
2552
  const more = issues.length > 5 ? `, and ${String(issues.length - 5)} more` : "";
2256
2553
  return {
2257
2554
  id: "rel-assets",
@@ -2297,18 +2594,18 @@ function checkSeoUrl(seoConfigured, hasUrl) {
2297
2594
  fix: "Set client.seo.url so sitemap.xml and canonical links are absolute."
2298
2595
  };
2299
2596
  }
2300
- function checkStyling(f2) {
2597
+ function checkStyling(f) {
2301
2598
  const label = "Styling";
2302
- if (f2.preprocessorImported && f2.preprocessorImported !== "css" && !f2.preprocessorInstalled) {
2599
+ if (f.preprocessorImported && f.preprocessorImported !== "css" && !f.preprocessorInstalled) {
2303
2600
  return {
2304
2601
  id: "styling",
2305
2602
  label,
2306
2603
  status: "fail",
2307
- detail: `${f2.preprocessorImported} stylesheet imported but ${f2.preprocessorImported} is not installed`,
2308
- fix: `Install ${f2.preprocessorImported}, or run toiljs configure.`
2604
+ detail: `${f.preprocessorImported} stylesheet imported but ${f.preprocessorImported} is not installed`,
2605
+ fix: `Install ${f.preprocessorImported}, or run toiljs configure.`
2309
2606
  };
2310
2607
  }
2311
- if (f2.tailwindImported && !f2.tailwindInstalled) {
2608
+ if (f.tailwindImported && !f.tailwindInstalled) {
2312
2609
  return {
2313
2610
  id: "styling",
2314
2611
  label,
@@ -2355,6 +2652,45 @@ function checkWasmBuilt(exists) {
2355
2652
  fix: "Run your server build (toilscript) before toiljs start."
2356
2653
  };
2357
2654
  }
2655
+ var RPC_TOILSCRIPT_MIN = "0.1.13";
2656
+ function checkRpcWiring(f) {
2657
+ const missing = [];
2658
+ if (!f.toilscriptOk) missing.push(`toilscript >=${RPC_TOILSCRIPT_MIN}`);
2659
+ if (!f.buildServerWired) missing.push("build:server --rpcModule");
2660
+ if (!f.tsconfigWired) missing.push("tsconfig shared/ + alias");
2661
+ if (!f.gitignoreWired) missing.push(".gitignore shared/server.ts");
2662
+ if (missing.length === 0) {
2663
+ return { id: "rpc-wiring", label: "typed RPC wiring", status: "pass" };
2664
+ }
2665
+ return {
2666
+ id: "rpc-wiring",
2667
+ label: "typed RPC wiring",
2668
+ status: "warn",
2669
+ detail: `missing: ${missing.join(", ")}`,
2670
+ fix: "Run `toiljs doctor --fix` to wire @data/@remote RPC (build:server, tsconfig, .gitignore, toilscript)."
2671
+ };
2672
+ }
2673
+ function checkPrettierPlugin(present) {
2674
+ return present ? { id: "prettier-plugin", label: "prettier toilscript plugin", status: "pass" } : {
2675
+ id: "prettier-plugin",
2676
+ label: "prettier toilscript plugin",
2677
+ status: "warn",
2678
+ detail: "prettier will fail on @main / @remote-on-function in server code",
2679
+ fix: "Run `toiljs doctor --fix` to add toiljs/prettier-plugin to your prettier config."
2680
+ };
2681
+ }
2682
+ function checkRestDispatch(f) {
2683
+ if (!f.hasControllers || f.dispatched) {
2684
+ return { id: "rest-dispatch", label: "REST dispatch wiring", status: "pass" };
2685
+ }
2686
+ return {
2687
+ id: "rest-dispatch",
2688
+ label: "REST dispatch wiring",
2689
+ status: "warn",
2690
+ detail: "@rest controllers found, but nothing calls Rest.dispatch(req) - their routes will not be served",
2691
+ fix: "In your handler add `const hit = Rest.dispatch(req); if (hit != null) return hit;`, or set `Server.handler = () => new RestHandler()`."
2692
+ };
2693
+ }
2358
2694
  function summarize(groups) {
2359
2695
  let pass = 0;
2360
2696
  let warn2 = 0;
@@ -2384,7 +2720,7 @@ function readJsonObject(file) {
2384
2720
  function stringRecord(value) {
2385
2721
  if (typeof value !== "object" || value === null) return {};
2386
2722
  const out = {};
2387
- for (const [k2, v2] of Object.entries(value)) if (typeof v2 === "string") out[k2] = v2;
2723
+ for (const [k, v] of Object.entries(value)) if (typeof v === "string") out[k] = v;
2388
2724
  return out;
2389
2725
  }
2390
2726
  function readFile(file) {
@@ -2394,6 +2730,255 @@ function readFile(file) {
2394
2730
  return null;
2395
2731
  }
2396
2732
  }
2733
+ function writeFile(file, content) {
2734
+ fs4.writeFileSync(file, content);
2735
+ }
2736
+ function isPackageInstalled(root, name) {
2737
+ const require2 = createRequire(path5.join(root, "package.json"));
2738
+ for (const id of [`${name}/package.json`, name]) {
2739
+ try {
2740
+ require2.resolve(id);
2741
+ return true;
2742
+ } catch {
2743
+ }
2744
+ }
2745
+ for (let dir = root; ; ) {
2746
+ if (fs4.existsSync(path5.join(dir, "node_modules", name, "package.json"))) return true;
2747
+ const parent = path5.dirname(dir);
2748
+ if (parent === dir) return false;
2749
+ dir = parent;
2750
+ }
2751
+ }
2752
+ function asRecord(value) {
2753
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
2754
+ }
2755
+ var RPC_MODULE_FLAG = "--rpcModule shared/server.ts";
2756
+ var RPC_GITIGNORE_LINE = "shared/server.ts";
2757
+ var RPC_GITIGNORE_RE = /(^|\n)\s*shared\/server\.ts\s*(\r?\n|$)/;
2758
+ function looksLikeSemverRange(range) {
2759
+ return /^\s*[v^~>=<]*\s*\d+\.\d+/.test(range);
2760
+ }
2761
+ function gatherRpcFacts(root) {
2762
+ const pkg = readJsonObject(path5.join(root, "package.json"));
2763
+ const scripts = pkg ? stringRecord(pkg.scripts) : {};
2764
+ const deps = {
2765
+ ...pkg ? stringRecord(pkg.dependencies) : {},
2766
+ ...pkg ? stringRecord(pkg.devDependencies) : {}
2767
+ };
2768
+ const tsconfig = readJsonObject(path5.join(root, "tsconfig.json"));
2769
+ const gitignore = readFile(path5.join(root, ".gitignore"));
2770
+ const buildServerWired = [scripts["build:server"], scripts["build"]].some(
2771
+ (s) => typeof s === "string" && s.includes("--rpcModule")
2772
+ );
2773
+ let tsconfigWired = false;
2774
+ if (tsconfig) {
2775
+ const include = tsconfig.include;
2776
+ const hasShared = !Array.isArray(include) || include.includes("shared");
2777
+ const paths = asRecord(asRecord(tsconfig.compilerOptions)?.paths);
2778
+ tsconfigWired = hasShared && paths !== null && "shared/*" in paths;
2779
+ }
2780
+ const gitignoreWired = gitignore !== null && RPC_GITIGNORE_RE.test(gitignore);
2781
+ const range = deps.toilscript;
2782
+ const toilscriptOk = range == null ? false : looksLikeSemverRange(range) ? satisfiesMin(range, RPC_TOILSCRIPT_MIN) : true;
2783
+ return { buildServerWired, tsconfigWired, gitignoreWired, toilscriptOk };
2784
+ }
2785
+ function serverSources(root, toilconfig) {
2786
+ const dirs = /* @__PURE__ */ new Set();
2787
+ const entries = Array.isArray(toilconfig?.entries) ? toilconfig.entries.filter((e) => typeof e === "string") : [];
2788
+ for (const e of entries) dirs.add(path5.dirname(path5.resolve(root, e)));
2789
+ const out = [];
2790
+ const cap = 200;
2791
+ const maxDepth = 16;
2792
+ const visit = (current, depth) => {
2793
+ if (out.length >= cap || depth > maxDepth) return;
2794
+ let listing;
2795
+ try {
2796
+ listing = fs4.readdirSync(current, { withFileTypes: true });
2797
+ } catch {
2798
+ return;
2799
+ }
2800
+ for (const entry of listing) {
2801
+ if (out.length >= cap) break;
2802
+ const full = path5.join(current, entry.name);
2803
+ if (entry.isDirectory()) {
2804
+ if (entry.name !== "node_modules") visit(full, depth + 1);
2805
+ } else if (entry.name.endsWith(".ts") && !entry.name.endsWith(".d.ts")) {
2806
+ const src = readFile(full);
2807
+ if (src !== null) out.push(src);
2808
+ }
2809
+ }
2810
+ };
2811
+ for (const dir of dirs) visit(dir, 0);
2812
+ return out;
2813
+ }
2814
+ function gatherRestFacts(root, toilconfig) {
2815
+ let hasControllers = false;
2816
+ let dispatched = false;
2817
+ for (const src of serverSources(root, toilconfig)) {
2818
+ if (/@rest\b/.test(src)) hasControllers = true;
2819
+ if (/\bRest\s*\.\s*dispatch\s*\(/.test(src) || /\bRestHandler\b/.test(src))
2820
+ dispatched = true;
2821
+ if (hasControllers && dispatched) break;
2822
+ }
2823
+ return { hasControllers, dispatched };
2824
+ }
2825
+ function applyRpcFix(root) {
2826
+ const changed = [];
2827
+ const skipped = [];
2828
+ const pkgPath = path5.join(root, "package.json");
2829
+ const pkgRaw = readFile(pkgPath);
2830
+ const pkg = pkgRaw !== null ? readJsonObject(pkgPath) : null;
2831
+ if (pkg !== null) {
2832
+ let touched = false;
2833
+ const scripts = asRecord(pkg.scripts) ?? {};
2834
+ for (const key of ["build", "build:server"]) {
2835
+ const value = scripts[key];
2836
+ if (typeof value === "string" && value.includes("toilscript") && !value.includes("--rpcModule")) {
2837
+ scripts[key] = `${value} ${RPC_MODULE_FLAG}`;
2838
+ pkg.scripts = scripts;
2839
+ touched = true;
2840
+ }
2841
+ }
2842
+ let toilscriptDeclared = false;
2843
+ for (const field of ["devDependencies", "dependencies"]) {
2844
+ const bag = asRecord(pkg[field]);
2845
+ const current = bag?.toilscript;
2846
+ if (bag && typeof current === "string") {
2847
+ toilscriptDeclared = true;
2848
+ if (looksLikeSemverRange(current) && !satisfiesMin(current, RPC_TOILSCRIPT_MIN)) {
2849
+ bag.toilscript = `^${RPC_TOILSCRIPT_MIN}`;
2850
+ touched = true;
2851
+ }
2852
+ }
2853
+ }
2854
+ if (!toilscriptDeclared) {
2855
+ const dd = asRecord(pkg.devDependencies) ?? {};
2856
+ dd.toilscript = `^${RPC_TOILSCRIPT_MIN}`;
2857
+ pkg.devDependencies = dd;
2858
+ touched = true;
2859
+ }
2860
+ if (touched) {
2861
+ writeFile(pkgPath, JSON.stringify(pkg, null, 4) + "\n");
2862
+ changed.push("package.json");
2863
+ }
2864
+ } else if (pkgRaw !== null) {
2865
+ skipped.push("package.json (unparseable)");
2866
+ }
2867
+ const tsPath = path5.join(root, "tsconfig.json");
2868
+ const tsRaw = readFile(tsPath);
2869
+ const tsconfig = tsRaw !== null ? readJsonObject(tsPath) : null;
2870
+ if (tsconfig !== null) {
2871
+ let touched = false;
2872
+ if (Array.isArray(tsconfig.include)) {
2873
+ const include = [...tsconfig.include];
2874
+ if (!include.includes("shared")) {
2875
+ const at = include.indexOf("client");
2876
+ include.splice(at >= 0 ? at + 1 : include.length, 0, "shared");
2877
+ tsconfig.include = include;
2878
+ touched = true;
2879
+ }
2880
+ }
2881
+ const co = asRecord(tsconfig.compilerOptions) ?? {};
2882
+ const paths = asRecord(co.paths) ?? {};
2883
+ if (!("shared/*" in paths)) {
2884
+ paths["shared/*"] = ["./shared/*"];
2885
+ co.paths = paths;
2886
+ tsconfig.compilerOptions = co;
2887
+ touched = true;
2888
+ }
2889
+ if (touched) {
2890
+ writeFile(tsPath, JSON.stringify(tsconfig, null, 4) + "\n");
2891
+ changed.push("tsconfig.json");
2892
+ }
2893
+ } else if (tsRaw !== null) {
2894
+ skipped.push('tsconfig.json (JSON with comments, add "shared" + paths by hand)');
2895
+ }
2896
+ const giPath = path5.join(root, ".gitignore");
2897
+ const giRaw = readFile(giPath);
2898
+ if (giRaw === null) {
2899
+ writeFile(giPath, `${RPC_GITIGNORE_LINE}
2900
+ `);
2901
+ changed.push(".gitignore");
2902
+ } else if (!RPC_GITIGNORE_RE.test(giRaw)) {
2903
+ const sep = giRaw.length === 0 || giRaw.endsWith("\n") ? "" : "\n";
2904
+ writeFile(giPath, `${giRaw}${sep}${RPC_GITIGNORE_LINE}
2905
+ `);
2906
+ changed.push(".gitignore");
2907
+ }
2908
+ return { changed, skipped };
2909
+ }
2910
+ var PRETTIER_PLUGIN = "toiljs/prettier-plugin";
2911
+ var PRETTIER_MENTION = /toiljs\/prettier(-plugin)?/;
2912
+ var PRETTIER_CONFIG_FILES = [
2913
+ ".prettierrc",
2914
+ ".prettierrc.json",
2915
+ ".prettierrc.json5",
2916
+ ".prettierrc.yaml",
2917
+ ".prettierrc.yml",
2918
+ ".prettierrc.js",
2919
+ ".prettierrc.cjs",
2920
+ ".prettierrc.mjs",
2921
+ ".prettierrc.ts",
2922
+ "prettier.config.js",
2923
+ "prettier.config.cjs",
2924
+ "prettier.config.mjs",
2925
+ "prettier.config.ts"
2926
+ ];
2927
+ function prettierPluginPresent(root, pkg) {
2928
+ if (pkg && pkg.prettier !== void 0 && PRETTIER_MENTION.test(JSON.stringify(pkg.prettier))) {
2929
+ return true;
2930
+ }
2931
+ for (const name of PRETTIER_CONFIG_FILES) {
2932
+ const raw = readFile(path5.join(root, name));
2933
+ if (raw !== null && PRETTIER_MENTION.test(raw)) return true;
2934
+ }
2935
+ return false;
2936
+ }
2937
+ function applyPrettierFix(root, pkg) {
2938
+ const changed = [];
2939
+ const skipped = [];
2940
+ if (prettierPluginPresent(root, pkg)) return { changed, skipped };
2941
+ const pkgPath = path5.join(root, "package.json");
2942
+ const pkgConfig = pkg ? asRecord(pkg.prettier) : null;
2943
+ if (pkgConfig !== null) {
2944
+ const full = readJsonObject(pkgPath);
2945
+ const target = full ? asRecord(full.prettier) : null;
2946
+ if (full && target) {
2947
+ target.plugins = [
2948
+ ...Array.isArray(target.plugins) ? target.plugins : [],
2949
+ PRETTIER_PLUGIN
2950
+ ];
2951
+ writeFile(pkgPath, JSON.stringify(full, null, 4) + "\n");
2952
+ changed.push("package.json");
2953
+ return { changed, skipped };
2954
+ }
2955
+ }
2956
+ for (const name of [".prettierrc", ".prettierrc.json"]) {
2957
+ const filePath = path5.join(root, name);
2958
+ const raw = readFile(filePath);
2959
+ if (raw === null) continue;
2960
+ const obj = readJsonObject(filePath);
2961
+ if (obj === null) {
2962
+ skipped.push(`${name} (add "${PRETTIER_PLUGIN}" to plugins by hand)`);
2963
+ return { changed, skipped };
2964
+ }
2965
+ obj.plugins = [...Array.isArray(obj.plugins) ? obj.plugins : [], PRETTIER_PLUGIN];
2966
+ writeFile(filePath, JSON.stringify(obj, null, 4) + "\n");
2967
+ changed.push(name);
2968
+ return { changed, skipped };
2969
+ }
2970
+ const jsConfig = PRETTIER_CONFIG_FILES.find((name) => readFile(path5.join(root, name)) !== null);
2971
+ if (jsConfig) {
2972
+ skipped.push(`${jsConfig} (add "${PRETTIER_PLUGIN}" to its plugins by hand)`);
2973
+ return { changed, skipped };
2974
+ }
2975
+ writeFile(
2976
+ path5.join(root, ".prettierrc.json"),
2977
+ JSON.stringify({ plugins: [PRETTIER_PLUGIN] }, null, 4) + "\n"
2978
+ );
2979
+ changed.push(".prettierrc.json");
2980
+ return { changed, skipped };
2981
+ }
2397
2982
  function frameworkMeta() {
2398
2983
  const pkgPath = path5.resolve(
2399
2984
  path5.dirname(fileURLToPath3(import.meta.url)),
@@ -2487,7 +3072,7 @@ async function runDoctor(opts) {
2487
3072
  const entrySource = readEntry(clientAbsDir);
2488
3073
  const indexHtml = readFile(path5.join(publicDir, "index.html"));
2489
3074
  const routes = scanRoutes(routesAbsDir);
2490
- const mainPatterns = routes.filter((r) => r.slot === void 0).map((r) => r.pattern);
3075
+ const mainPatterns = routes.filter((r2) => r2.slot === void 0).map((r2) => r2.pattern);
2491
3076
  const assetIssues = findRelativeAssets(collectSources(root, clientAbsDir, 200));
2492
3077
  let preprocessorImported = null;
2493
3078
  let tailwindImported = false;
@@ -2504,14 +3089,9 @@ async function runDoctor(opts) {
2504
3089
  let toilscriptInstalled = false;
2505
3090
  let wasmExists = false;
2506
3091
  if (toilconfig) {
2507
- const entries = Array.isArray(toilconfig.entries) ? toilconfig.entries.filter((e2) => typeof e2 === "string") : [];
2508
- missingEntries = entries.filter((e2) => !fs4.existsSync(path5.join(root, e2)));
2509
- try {
2510
- createRequire(path5.join(root, "package.json")).resolve("toilscript");
2511
- toilscriptInstalled = true;
2512
- } catch {
2513
- toilscriptInstalled = false;
2514
- }
3092
+ const entries = Array.isArray(toilconfig.entries) ? toilconfig.entries.filter((e) => typeof e === "string") : [];
3093
+ missingEntries = entries.filter((e) => !fs4.existsSync(path5.join(root, e)));
3094
+ toilscriptInstalled = isPackageInstalled(root, "toilscript");
2515
3095
  const targets = typeof toilconfig.targets === "object" && toilconfig.targets !== null ? toilconfig.targets : {};
2516
3096
  const outFiles = [];
2517
3097
  for (const target of Object.values(targets)) {
@@ -2520,17 +3100,29 @@ async function runDoctor(opts) {
2520
3100
  if (typeof outFile === "string") outFiles.push(outFile);
2521
3101
  }
2522
3102
  }
2523
- wasmExists = outFiles.some((f2) => fs4.existsSync(path5.join(root, f2)));
3103
+ wasmExists = outFiles.some((f) => fs4.existsSync(path5.join(root, f)));
2524
3104
  if (!wasmExists && outFiles.length === 0) {
2525
3105
  try {
2526
- wasmExists = fs4.readdirSync(path5.join(root, "build", "server")).some((f2) => f2.endsWith(".wasm"));
3106
+ wasmExists = fs4.readdirSync(path5.join(root, "build", "server")).some((f) => f.endsWith(".wasm"));
2527
3107
  } catch {
2528
3108
  wasmExists = false;
2529
3109
  }
2530
3110
  }
2531
3111
  }
2532
- const peerName = (n) => checkPeer(n, deps[n] ?? null, meta.peers[n] ?? "*");
3112
+ const peerName = (n2) => checkPeer(n2, deps[n2] ?? null, meta.peers[n2] ?? "*");
2533
3113
  const peerChecks = Object.keys(meta.peers).map(peerName);
3114
+ const rpcFix = serverPresent && opts.fix ? applyRpcFix(root) : null;
3115
+ const prettierFix = serverPresent && opts.fix ? applyPrettierFix(root, projectPkg) : null;
3116
+ const rpcFacts = gatherRpcFacts(root);
3117
+ const restFacts = gatherRestFacts(root, toilconfig);
3118
+ const prettierPresent = prettierPluginPresent(
3119
+ root,
3120
+ readJsonObject(path5.join(root, "package.json"))
3121
+ );
3122
+ const serverFix = rpcFix || prettierFix ? {
3123
+ changed: [...rpcFix?.changed ?? [], ...prettierFix?.changed ?? []],
3124
+ skipped: [...rpcFix?.skipped ?? [], ...prettierFix?.skipped ?? []]
3125
+ } : null;
2534
3126
  const groups = [
2535
3127
  {
2536
3128
  title: "Environment",
@@ -2538,7 +3130,7 @@ async function runDoctor(opts) {
2538
3130
  checkNode(process.versions.node, meta.node),
2539
3131
  checkToiljsInstalled("toiljs" in deps ? version() : null),
2540
3132
  ...peerChecks,
2541
- checkPackageManager(LOCKFILES.filter((f2) => fs4.existsSync(path5.join(root, f2))))
3133
+ checkPackageManager(LOCKFILES.filter((f) => fs4.existsSync(path5.join(root, f))))
2542
3134
  ]
2543
3135
  },
2544
3136
  {
@@ -2583,29 +3175,53 @@ async function runDoctor(opts) {
2583
3175
  checkToilconfig(true),
2584
3176
  checkServerEntry(missingEntries),
2585
3177
  checkToilscriptInstalled(toilscriptInstalled),
2586
- checkWasmBuilt(wasmExists)
3178
+ checkWasmBuilt(wasmExists),
3179
+ checkRpcWiring(rpcFacts),
3180
+ checkRestDispatch(restFacts),
3181
+ checkPrettierPlugin(prettierPresent)
2587
3182
  ] : [checkToilconfig(false)]
2588
3183
  }
2589
3184
  ];
2590
3185
  const summary = summarize(groups);
2591
3186
  if (opts.json) {
2592
- process.stdout.write(JSON.stringify({ groups, summary }, null, 2) + "\n");
3187
+ process.stdout.write(JSON.stringify({ groups, summary, fixed: serverFix }, null, 2) + "\n");
2593
3188
  } else {
2594
3189
  process.stdout.write("\n" + accent(" Doctor") + dim(` ${root}`) + "\n\n");
2595
3190
  renderHuman(groups);
3191
+ if (serverFix) renderRpcFix(serverFix);
3192
+ else if (opts.fix && !serverPresent) {
3193
+ process.stdout.write(
3194
+ " " + dim("--fix: no server (toilconfig.json) found, nothing to wire.") + "\n\n"
3195
+ );
3196
+ }
2596
3197
  }
2597
3198
  if (hasFailures(summary)) process.exitCode = 1;
2598
3199
  }
3200
+ function renderRpcFix(result) {
3201
+ const out = [];
3202
+ if (result.changed.length > 0) {
3203
+ out.push(" " + success("fixed RPC wiring") + dim(` ${result.changed.join(", ")}`));
3204
+ if (result.changed.includes("package.json")) {
3205
+ out.push(
3206
+ " " + dim("run your installer (npm/pnpm/yarn) if the toilscript version changed.")
3207
+ );
3208
+ }
3209
+ } else {
3210
+ out.push(" " + dim("RPC wiring already in place, nothing to fix."));
3211
+ }
3212
+ for (const item of result.skipped) out.push(" " + warn("skipped") + dim(` ${item}`));
3213
+ process.stdout.write(out.join("\n") + "\n\n");
3214
+ }
2599
3215
 
2600
3216
  // src/cli/update.ts
2601
3217
  import fs5 from "node:fs";
2602
3218
  import path6 from "node:path";
2603
3219
 
2604
3220
  // src/cli/updates.ts
2605
- function parseVersion2(v2) {
2606
- const m2 = /(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(v2);
2607
- if (!m2) return [0, 0, 0];
2608
- return [Number(m2[1]), Number(m2[2] ?? 0), Number(m2[3] ?? 0)];
3221
+ function parseVersion2(v) {
3222
+ const m = /(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(v);
3223
+ if (!m) return [0, 0, 0];
3224
+ return [Number(m[1]), Number(m[2] ?? 0), Number(m[3] ?? 0)];
2609
3225
  }
2610
3226
  function classifyBump(from, to) {
2611
3227
  const [fa, fb, fc] = parseVersion2(from);
@@ -2615,15 +3231,15 @@ function classifyBump(from, to) {
2615
3231
  if (tc !== fc) return "patch";
2616
3232
  return "other";
2617
3233
  }
2618
- function parseNcuJson(stdout) {
2619
- const start2 = stdout.indexOf("{");
2620
- const end = stdout.lastIndexOf("}");
3234
+ function parseNcuJson(stdout2) {
3235
+ const start2 = stdout2.indexOf("{");
3236
+ const end = stdout2.lastIndexOf("}");
2621
3237
  if (start2 === -1 || end <= start2) return {};
2622
3238
  try {
2623
- const parsed = JSON.parse(stdout.slice(start2, end + 1));
3239
+ const parsed = JSON.parse(stdout2.slice(start2, end + 1));
2624
3240
  if (typeof parsed !== "object" || parsed === null) return {};
2625
3241
  const out = {};
2626
- for (const [k2, v2] of Object.entries(parsed)) if (typeof v2 === "string") out[k2] = v2;
3242
+ for (const [k, v] of Object.entries(parsed)) if (typeof v === "string") out[k] = v;
2627
3243
  return out;
2628
3244
  } catch {
2629
3245
  return {};
@@ -2634,7 +3250,7 @@ function buildRows(upgraded, currentDeps) {
2634
3250
  return Object.entries(upgraded).map(([name, to]) => {
2635
3251
  const from = currentDeps[name] ?? "?";
2636
3252
  return { name, from, to, bump: classifyBump(from, to) };
2637
- }).sort((a, b2) => SEVERITY[a.bump] - SEVERITY[b2.bump] || a.name.localeCompare(b2.name));
3253
+ }).sort((a3, b) => SEVERITY[a3.bump] - SEVERITY[b.bump] || a3.name.localeCompare(b.name));
2638
3254
  }
2639
3255
 
2640
3256
  // src/cli/update.ts
@@ -2648,19 +3264,19 @@ function readDependencies(pkgPath) {
2648
3264
  const parsed = JSON.parse(fs5.readFileSync(pkgPath, "utf8"));
2649
3265
  if (typeof parsed !== "object" || parsed === null) return {};
2650
3266
  const pkg = parsed;
2651
- const merge = (v2) => {
2652
- if (typeof v2 !== "object" || v2 === null) return {};
3267
+ const merge = (v) => {
3268
+ if (typeof v !== "object" || v === null) return {};
2653
3269
  const out = {};
2654
- for (const [k2, val] of Object.entries(v2)) if (typeof val === "string") out[k2] = val;
3270
+ for (const [k, val] of Object.entries(v)) if (typeof val === "string") out[k] = val;
2655
3271
  return out;
2656
3272
  };
2657
3273
  return { ...merge(pkg.dependencies), ...merge(pkg.devDependencies) };
2658
3274
  }
2659
- function bumpColor(bump, text) {
2660
- if (bump === "major") return danger(text);
2661
- if (bump === "minor") return warn(text);
2662
- if (bump === "patch") return success(text);
2663
- return dim(text);
3275
+ function bumpColor(bump, text2) {
3276
+ if (bump === "major") return danger(text2);
3277
+ if (bump === "minor") return warn(text2);
3278
+ if (bump === "patch") return success(text2);
3279
+ return dim(text2);
2664
3280
  }
2665
3281
  function rowLine(row) {
2666
3282
  return `${row.name} ${dim(row.from)} ${dim("->")} ${bumpColor(row.bump, row.to)}`;
@@ -2684,51 +3300,51 @@ async function runUpdate(opts) {
2684
3300
  target,
2685
3301
  ...extra
2686
3302
  ];
2687
- ye(accent("toiljs update"));
2688
- const s = vt();
3303
+ intro(accent("toiljs update"));
3304
+ const s = spinner();
2689
3305
  s.start("Checking the registry for updates");
2690
3306
  const res = await capture("npx", ncuArgs(["--jsonUpgraded"]), root);
2691
3307
  if (res.code !== 0 && res.stdout.indexOf("{") === -1) {
2692
3308
  s.stop("Could not check for updates");
2693
- Ce(dim(res.stderr.trim() || "npm-check-updates failed."), "Error");
3309
+ note(dim(res.stderr.trim() || "npm-check-updates failed."), "Error");
2694
3310
  process.exitCode = 1;
2695
3311
  return;
2696
3312
  }
2697
3313
  const rows = buildRows(parseNcuJson(res.stdout), currentDeps);
2698
3314
  if (rows.length === 0) {
2699
3315
  s.stop("Everything is up to date");
2700
- fe(success("Nothing to update."));
3316
+ outro(success("Nothing to update."));
2701
3317
  return;
2702
3318
  }
2703
3319
  s.stop(`${String(rows.length)} update${rows.length === 1 ? "" : "s"} available`);
2704
3320
  const counts = { major: 0, minor: 0, patch: 0, other: 0 };
2705
- for (const r of rows) counts[r.bump]++;
2706
- Ce(
3321
+ for (const r2 of rows) counts[r2.bump]++;
3322
+ note(
2707
3323
  rows.map(rowLine).join("\n"),
2708
3324
  `${danger(`${String(counts.major)} major`)} ${warn(`${String(counts.minor)} minor`)} ${success(`${String(counts.patch)} patch`)}`
2709
3325
  );
2710
3326
  let selected;
2711
3327
  if (opts.yes) {
2712
- selected = rows.map((r) => r.name);
3328
+ selected = rows.map((r2) => r2.name);
2713
3329
  } else {
2714
- const answer = await we({
3330
+ const answer = await multiselect({
2715
3331
  message: "Select packages to update (space to toggle, enter to confirm)",
2716
- options: rows.map((r) => ({
2717
- value: r.name,
2718
- label: r.name,
2719
- hint: `${r.from} -> ${r.to}`
3332
+ options: rows.map((r2) => ({
3333
+ value: r2.name,
3334
+ label: r2.name,
3335
+ hint: `${r2.from} -> ${r2.to}`
2720
3336
  })),
2721
- initialValues: rows.map((r) => r.name),
3337
+ initialValues: rows.map((r2) => r2.name),
2722
3338
  required: false
2723
3339
  });
2724
- if (R(answer)) {
2725
- ge("Update cancelled.");
3340
+ if (isCancel(answer)) {
3341
+ cancel("Update cancelled.");
2726
3342
  return;
2727
3343
  }
2728
3344
  selected = answer;
2729
3345
  }
2730
3346
  if (selected.length === 0) {
2731
- fe(dim("No packages selected."));
3347
+ outro(dim("No packages selected."));
2732
3348
  return;
2733
3349
  }
2734
3350
  s.start("Updating package.json");
@@ -2738,7 +3354,7 @@ async function runUpdate(opts) {
2738
3354
  s.start(`Installing with ${pm.name}`);
2739
3355
  await run(pm.name, ["install"], root);
2740
3356
  s.stop("Dependencies installed");
2741
- fe(
3357
+ outro(
2742
3358
  success(`Updated ${String(selected.length)} package${selected.length === 1 ? "" : "s"}.`)
2743
3359
  );
2744
3360
  }
@@ -2746,28 +3362,31 @@ async function runUpdate(opts) {
2746
3362
  // src/cli/index.ts
2747
3363
  function parseArgs(argv) {
2748
3364
  const flags = {};
2749
- for (let i = 0; i < argv.length; i++) {
2750
- const arg = argv[i];
3365
+ for (let i2 = 0; i2 < argv.length; i2++) {
3366
+ const arg = argv[i2];
2751
3367
  switch (arg) {
2752
3368
  case "--root":
2753
- flags.root = argv[++i];
3369
+ flags.root = argv[++i2];
2754
3370
  break;
2755
3371
  case "--port": {
2756
- const port = Number(argv[++i]);
3372
+ const port = Number(argv[++i2]);
2757
3373
  if (!Number.isNaN(port)) flags.port = port;
2758
3374
  break;
2759
3375
  }
3376
+ case "--host":
3377
+ flags.host = argv[++i2];
3378
+ break;
2760
3379
  case "--template":
2761
3380
  case "-t": {
2762
- const t = argv[++i];
2763
- if (t === "app" || t === "minimal") flags.template = t;
3381
+ const t2 = argv[++i2];
3382
+ if (t2 === "app" || t2 === "minimal") flags.template = t2;
2764
3383
  break;
2765
3384
  }
2766
3385
  case "--pm":
2767
- flags.pm = argv[++i];
3386
+ flags.pm = argv[++i2];
2768
3387
  break;
2769
3388
  case "--style": {
2770
- const s = argv[++i];
3389
+ const s = argv[++i2];
2771
3390
  if (PREPROCESSORS.includes(s))
2772
3391
  flags.preprocessor = s;
2773
3392
  break;
@@ -2809,8 +3428,11 @@ function parseArgs(argv) {
2809
3428
  case "--json":
2810
3429
  flags.json = true;
2811
3430
  break;
3431
+ case "--fix":
3432
+ flags.fix = true;
3433
+ break;
2812
3434
  case "--target":
2813
- flags.target = argv[++i];
3435
+ flags.target = argv[++i2];
2814
3436
  break;
2815
3437
  default:
2816
3438
  if (!arg.startsWith("-") && flags.name === void 0) flags.name = arg;
@@ -2843,6 +3465,7 @@ function printHelp() {
2843
3465
  cmd("-y, --yes", "create: accept defaults (non-interactive)"),
2844
3466
  cmd("--no-install", "create: don't install dependencies"),
2845
3467
  cmd("--json", "doctor: machine-readable output"),
3468
+ cmd("--fix", "doctor: auto-fix what it can (typed-RPC wiring)"),
2846
3469
  cmd("--target <t>", "update: latest | minor | patch | newest | greatest"),
2847
3470
  cmd("-v, --version", "print the toiljs version"),
2848
3471
  ""
@@ -2898,7 +3521,7 @@ async function main() {
2898
3521
  case "start": {
2899
3522
  banner();
2900
3523
  process.stdout.write(dim(" self-hosting the built app\u2026") + "\n\n");
2901
- const server = await start({ root: flags.root, port: flags.port });
3524
+ const server = await start({ root: flags.root, port: flags.port, host: flags.host });
2902
3525
  process.stdout.write(
2903
3526
  accent(" \u279C ") + bold(`http://localhost:${String(server.port)}`) + dim(` ws channel: ${server.wsPath}`) + "\n\n"
2904
3527
  );
@@ -2906,7 +3529,7 @@ async function main() {
2906
3529
  }
2907
3530
  case "doctor":
2908
3531
  if (!flags.json) banner();
2909
- await runDoctor({ root: flags.root, cwd: process.cwd(), json: flags.json });
3532
+ await runDoctor({ root: flags.root, cwd: process.cwd(), json: flags.json, fix: flags.fix });
2910
3533
  break;
2911
3534
  case "update":
2912
3535
  banner();