create-adjacent 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,2498 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
12
+ var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
20
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
21
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
22
+ for (let key of __getOwnPropNames(mod))
23
+ if (!__hasOwnProp.call(to, key))
24
+ __defProp(to, key, {
25
+ get: __accessProp.bind(mod, key),
26
+ enumerable: true
27
+ });
28
+ if (canCache)
29
+ cache.set(mod, to);
30
+ return to;
31
+ };
32
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+
34
+ // ../../node_modules/.bun/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
35
+ var require_src = __commonJS((exports, module) => {
36
+ var ESC2 = "\x1B";
37
+ var CSI2 = `${ESC2}[`;
38
+ var beep = "\x07";
39
+ var cursor = {
40
+ to(x, y) {
41
+ if (!y)
42
+ return `${CSI2}${x + 1}G`;
43
+ return `${CSI2}${y + 1};${x + 1}H`;
44
+ },
45
+ move(x, y) {
46
+ let ret = "";
47
+ if (x < 0)
48
+ ret += `${CSI2}${-x}D`;
49
+ else if (x > 0)
50
+ ret += `${CSI2}${x}C`;
51
+ if (y < 0)
52
+ ret += `${CSI2}${-y}A`;
53
+ else if (y > 0)
54
+ ret += `${CSI2}${y}B`;
55
+ return ret;
56
+ },
57
+ up: (count = 1) => `${CSI2}${count}A`,
58
+ down: (count = 1) => `${CSI2}${count}B`,
59
+ forward: (count = 1) => `${CSI2}${count}C`,
60
+ backward: (count = 1) => `${CSI2}${count}D`,
61
+ nextLine: (count = 1) => `${CSI2}E`.repeat(count),
62
+ prevLine: (count = 1) => `${CSI2}F`.repeat(count),
63
+ left: `${CSI2}G`,
64
+ hide: `${CSI2}?25l`,
65
+ show: `${CSI2}?25h`,
66
+ save: `${ESC2}7`,
67
+ restore: `${ESC2}8`
68
+ };
69
+ var scroll = {
70
+ up: (count = 1) => `${CSI2}S`.repeat(count),
71
+ down: (count = 1) => `${CSI2}T`.repeat(count)
72
+ };
73
+ var erase = {
74
+ screen: `${CSI2}2J`,
75
+ up: (count = 1) => `${CSI2}1J`.repeat(count),
76
+ down: (count = 1) => `${CSI2}J`.repeat(count),
77
+ line: `${CSI2}2K`,
78
+ lineEnd: `${CSI2}K`,
79
+ lineStart: `${CSI2}1K`,
80
+ lines(count) {
81
+ let clear = "";
82
+ for (let i = 0;i < count; i++)
83
+ clear += this.line + (i < count - 1 ? cursor.up() : "");
84
+ if (count)
85
+ clear += cursor.left;
86
+ return clear;
87
+ }
88
+ };
89
+ module.exports = { cursor, scroll, erase, beep };
90
+ });
91
+
92
+ // ../adjacent-cli/dist/arguments.js
93
+ function resolveCreateOptions(projectName, options) {
94
+ const name = (projectName ?? "").trim();
95
+ if (name.length === 0) {
96
+ throw new Error("A project name is required, for example: adj create my-app");
97
+ }
98
+ const directory = options.directory?.trim();
99
+ return {
100
+ ...directory === undefined || directory.length === 0 ? null : { directory },
101
+ install: options.install ?? true,
102
+ projectName: name
103
+ };
104
+ }
105
+ // ../adjacent-cli/dist/create.js
106
+ import { relative as relative4, resolve as resolve4 } from "node:path";
107
+
108
+ // ../adjacent-cli/dist/destination.js
109
+ import { readdir, stat } from "node:fs/promises";
110
+ import { isAbsolute, resolve } from "node:path";
111
+ var IGNORED_ENTRIES = new Set([".DS_Store", ".git"]);
112
+ function resolveDestination(projectName, directory, cwd) {
113
+ if (directory === undefined)
114
+ return resolve(cwd, projectName);
115
+ const trimmed = directory.trim();
116
+ if (trimmed.length === 0) {
117
+ throw new Error("--directory needs a path, for example: --directory ./apps/my-app");
118
+ }
119
+ return isAbsolute(trimmed) ? resolve(trimmed) : resolve(cwd, trimmed);
120
+ }
121
+ async function assertDestinationUsable(destination) {
122
+ const entry = await stat(destination).catch(() => {
123
+ return;
124
+ });
125
+ if (!entry)
126
+ return { existed: false };
127
+ if (!entry.isDirectory()) {
128
+ throw new Error(`Cannot create a project at ${destination} because a file of that name already exists.`);
129
+ }
130
+ const contents = (await readdir(destination)).filter((name) => !IGNORED_ENTRIES.has(name));
131
+ if (contents.length > 0) {
132
+ throw new Error(`The directory ${destination} is not empty. Choose another name, pass --directory, or empty it first.`);
133
+ }
134
+ return { existed: true };
135
+ }
136
+
137
+ // ../adjacent-cli/dist/init.js
138
+ import { readFile as readFile4 } from "node:fs/promises";
139
+ import { dirname as dirname3, join as join5, relative as relative3, resolve as resolve3, sep as sep3 } from "node:path";
140
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
141
+
142
+ // ../adjacent-cli/dist/dependencies.js
143
+ import { readFileSync } from "node:fs";
144
+ import { dirname, join, relative, sep } from "node:path";
145
+ import { fileURLToPath } from "node:url";
146
+ var ADJACENT_PACKAGES = [
147
+ { directory: "adjacent-core", name: "adjacent-core" },
148
+ { directory: "adjacent-next", name: "adjacent-next" },
149
+ { directory: "adjacent-react", name: "adjacent-react" },
150
+ { directory: "adjacent-ui", name: "adjacent-ui" }
151
+ ];
152
+ function readOwnVersion() {
153
+ const manifest = join(dirname(fileURLToPath(import.meta.url)), "..", "package.json");
154
+ const { version } = JSON.parse(readFileSync(manifest, "utf8"));
155
+ return version;
156
+ }
157
+ var ADJACENT_VERSION = readOwnVersion();
158
+ var PUBLISHED_ADJACENT_RANGE = `^${ADJACENT_VERSION}`;
159
+ function matchesWorkspaceGlob(path, glob) {
160
+ const pattern = glob.split("/").map((segment) => segment === "**" ? "[^\\0]*" : segment === "*" ? "[^/]+" : escapeSegment(segment)).join("/");
161
+ return new RegExp(`^${pattern}$`).test(path);
162
+ }
163
+ function escapeSegment(segment) {
164
+ return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
165
+ }
166
+ function workspaceSpecifiers() {
167
+ return Object.fromEntries(ADJACENT_PACKAGES.map(({ name }) => [name, "workspace:*"]));
168
+ }
169
+ function toSpecifierPath(path) {
170
+ return path.split(sep).join("/");
171
+ }
172
+ function linkedSpecifier(packagesRoot, directory, projectRoot) {
173
+ const target = join(packagesRoot, directory);
174
+ if (projectRoot === undefined)
175
+ return `file:${toSpecifierPath(target)}`;
176
+ const workspaceRoot = dirname(packagesRoot);
177
+ const fromWorkspace = relative(workspaceRoot, projectRoot);
178
+ const inCheckout = fromWorkspace !== "" && !fromWorkspace.startsWith("..") && !fromWorkspace.startsWith(sep);
179
+ return inCheckout ? `file:${toSpecifierPath(relative(projectRoot, target))}` : `file:${toSpecifierPath(target)}`;
180
+ }
181
+ function linkedSpecifiers(packagesRoot, projectRoot) {
182
+ return Object.fromEntries(ADJACENT_PACKAGES.map(({ directory, name }) => [
183
+ name,
184
+ linkedSpecifier(packagesRoot, directory, projectRoot)
185
+ ]));
186
+ }
187
+ function publishedSpecifiers() {
188
+ return Object.fromEntries(ADJACENT_PACKAGES.map(({ name }) => [name, PUBLISHED_ADJACENT_RANGE]));
189
+ }
190
+ function resolveAdjacentDependencies(options = {}) {
191
+ const { packagesRoot, projectRoot, workspaceMember } = options;
192
+ if (packagesRoot === undefined) {
193
+ return { dependencies: publishedSpecifiers(), linked: false, pathLinked: false };
194
+ }
195
+ if (workspaceMember) {
196
+ return { dependencies: workspaceSpecifiers(), linked: true, pathLinked: false };
197
+ }
198
+ const specifiers = linkedSpecifiers(packagesRoot, projectRoot);
199
+ return { dependencies: specifiers, linked: true, overrides: specifiers, pathLinked: true };
200
+ }
201
+
202
+ // ../adjacent-cli/dist/edits.js
203
+ import { mkdir, readFile, rmdir, stat as stat2, unlink, writeFile } from "node:fs/promises";
204
+ import { dirname as dirname2, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
205
+ async function exists(path) {
206
+ return stat2(path).then(() => true, () => false);
207
+ }
208
+ function assertInsideProject(root, path) {
209
+ const relation = relative2(root, path);
210
+ if (relation === "" || relation.startsWith("..") || relation.startsWith(sep2)) {
211
+ throw new Error(`Refusing to touch a path outside the project: ${path}`);
212
+ }
213
+ }
214
+ function createProjectEdits(root) {
215
+ const projectRoot = resolve2(root);
216
+ const added = [];
217
+ const rewritten = [];
218
+ const skipped = [];
219
+ const createdDirectories = [];
220
+ const restores = [];
221
+ async function ensureDirectory(path) {
222
+ if (await exists(path))
223
+ return;
224
+ if (!path.startsWith(projectRoot))
225
+ return;
226
+ await ensureDirectory(dirname2(path));
227
+ if (await exists(path))
228
+ return;
229
+ await mkdir(path);
230
+ createdDirectories.push(path);
231
+ }
232
+ function target(relativePath) {
233
+ const path = resolve2(projectRoot, relativePath);
234
+ assertInsideProject(projectRoot, path);
235
+ return path;
236
+ }
237
+ return {
238
+ root: projectRoot,
239
+ async addFile(relativePath, contents) {
240
+ const path = target(relativePath);
241
+ if (await exists(path)) {
242
+ skipped.push(relativePath);
243
+ return false;
244
+ }
245
+ await ensureDirectory(dirname2(path));
246
+ await writeFile(path, contents);
247
+ restores.push({ contents: undefined, path });
248
+ added.push(relativePath);
249
+ return true;
250
+ },
251
+ readFile: (relativePath) => readFile(target(relativePath), "utf8").catch(() => {
252
+ return;
253
+ }),
254
+ async removeFile(relativePath) {
255
+ const path = target(relativePath);
256
+ const original = await readFile(path).catch(() => {
257
+ return;
258
+ });
259
+ if (original === undefined)
260
+ return;
261
+ restores.push({ contents: original, path });
262
+ await unlink(path);
263
+ },
264
+ async rewriteFile(relativePath, contents) {
265
+ const path = target(relativePath);
266
+ const original = await readFile(path).catch(() => {
267
+ return;
268
+ });
269
+ await ensureDirectory(dirname2(path));
270
+ await writeFile(path, contents);
271
+ if (original === undefined) {
272
+ restores.push({ contents: undefined, path });
273
+ added.push(relativePath);
274
+ } else {
275
+ restores.push({ contents: original, path });
276
+ rewritten.push(relativePath);
277
+ }
278
+ },
279
+ async rollback() {
280
+ for (const restore of [...restores].reverse()) {
281
+ assertInsideProject(projectRoot, restore.path);
282
+ if (restore.contents === undefined) {
283
+ await unlink(restore.path).catch(() => {
284
+ return;
285
+ });
286
+ } else {
287
+ await writeFile(restore.path, restore.contents).catch(() => {
288
+ return;
289
+ });
290
+ }
291
+ }
292
+ for (const directory of [...createdDirectories].reverse()) {
293
+ assertInsideProject(projectRoot, directory);
294
+ await rmdir(directory).catch(() => {
295
+ return;
296
+ });
297
+ }
298
+ restores.length = 0;
299
+ createdDirectories.length = 0;
300
+ added.length = 0;
301
+ rewritten.length = 0;
302
+ },
303
+ summary: () => ({
304
+ added: [...added],
305
+ rewritten: [...rewritten],
306
+ skipped: [...skipped]
307
+ })
308
+ };
309
+ }
310
+
311
+ // ../adjacent-cli/dist/package-manager.js
312
+ import { stat as stat3 } from "node:fs/promises";
313
+ import { join as join2 } from "node:path";
314
+
315
+ // ../adjacent-cli/dist/process.js
316
+ import { spawn } from "node:child_process";
317
+ async function runCommand(command, args, options = {}) {
318
+ return new Promise((resolve3, reject) => {
319
+ const child = spawn(command, args, {
320
+ cwd: options.cwd,
321
+ env: options.env,
322
+ stdio: ["ignore", "pipe", "pipe"]
323
+ });
324
+ const stderr = [];
325
+ const stdout = [];
326
+ child.stderr.on("data", (chunk) => stderr.push(chunk));
327
+ child.stdout.on("data", (chunk) => stdout.push(chunk));
328
+ child.once("error", (error) => reject(error));
329
+ child.once("exit", (code) => {
330
+ const result = {
331
+ stderr: Buffer.concat(stderr).toString().trim(),
332
+ stdout: Buffer.concat(stdout).toString().trim()
333
+ };
334
+ if (code === 0) {
335
+ resolve3(result);
336
+ } else {
337
+ reject(new Error(`${command} ${args.join(" ")} failed (${code ?? "signal"}): ${result.stderr || result.stdout}`));
338
+ }
339
+ });
340
+ });
341
+ }
342
+ async function runInheritedCommand(command, args, options = {}) {
343
+ const exitCode = await new Promise((resolve3, reject) => {
344
+ const child = spawn(command, args, {
345
+ cwd: options.cwd,
346
+ env: options.env,
347
+ stdio: ["ignore", "inherit", "inherit"]
348
+ });
349
+ child.once("error", (error) => reject(error));
350
+ child.once("exit", (code, signal) => resolve3(code ?? (signal ? 1 : 0)));
351
+ });
352
+ if (exitCode !== 0) {
353
+ throw new Error(`${command} ${args.join(" ")} exited with code ${exitCode}.`);
354
+ }
355
+ }
356
+
357
+ // ../adjacent-cli/dist/package-manager.js
358
+ var LOCKFILES = [
359
+ ["bun", "bun.lock"],
360
+ ["bun", "bun.lockb"],
361
+ ["pnpm", "pnpm-lock.yaml"],
362
+ ["yarn", "yarn.lock"],
363
+ ["npm", "package-lock.json"]
364
+ ];
365
+ var MANAGERS = {
366
+ bun: {
367
+ exec: (specifier, args) => ({ args: [specifier, ...args], command: "bunx" }),
368
+ install: ({ isolated = false } = {}) => ({
369
+ args: isolated ? ["install", "--linker=isolated"] : ["install"],
370
+ command: "bun"
371
+ }),
372
+ name: "bun",
373
+ run: (script, args = []) => ({ args: ["run", script, ...args], command: "bun" }),
374
+ scaffoldFlag: "--use-bun"
375
+ },
376
+ npm: {
377
+ exec: (specifier, args) => ({
378
+ args: ["--yes", specifier, ...args],
379
+ command: "npx"
380
+ }),
381
+ install: () => ({ args: ["install"], command: "npm" }),
382
+ name: "npm",
383
+ run: (script, args = []) => ({
384
+ args: ["run", script, ...args.length > 0 ? ["--", ...args] : []],
385
+ command: "npm"
386
+ }),
387
+ scaffoldFlag: "--use-npm"
388
+ },
389
+ pnpm: {
390
+ exec: (specifier, args) => ({ args: ["dlx", specifier, ...args], command: "pnpm" }),
391
+ install: () => ({ args: ["install"], command: "pnpm" }),
392
+ name: "pnpm",
393
+ run: (script, args = []) => ({ args: ["run", script, ...args], command: "pnpm" }),
394
+ scaffoldFlag: "--use-pnpm"
395
+ },
396
+ yarn: {
397
+ exec: (specifier, args) => ({ args: ["dlx", specifier, ...args], command: "yarn" }),
398
+ install: () => ({ args: ["install"], command: "yarn" }),
399
+ name: "yarn",
400
+ run: (script, args = []) => ({ args: [script, ...args], command: "yarn" }),
401
+ scaffoldFlag: "--use-yarn"
402
+ }
403
+ };
404
+ function parseUserAgent(userAgent) {
405
+ if (!userAgent)
406
+ return;
407
+ const [first] = userAgent.split("/");
408
+ return first !== undefined && first in MANAGERS ? first : undefined;
409
+ }
410
+ async function detectFromLockfile(projectRoot) {
411
+ for (const [name, lockfile] of LOCKFILES) {
412
+ const found = await stat3(join2(projectRoot, lockfile)).catch(() => {
413
+ return;
414
+ });
415
+ if (found?.isFile())
416
+ return name;
417
+ }
418
+ return;
419
+ }
420
+ async function isInstalled(command) {
421
+ return runCommand(command, ["--version"]).then(() => true, () => false);
422
+ }
423
+ async function resolvePackageManager(options = {}) {
424
+ const { projectRoot, userAgent = process.env.npm_config_user_agent } = options;
425
+ const fromLockfile = projectRoot ? await detectFromLockfile(projectRoot) : undefined;
426
+ if (fromLockfile)
427
+ return MANAGERS[fromLockfile];
428
+ const fromAgent = parseUserAgent(userAgent);
429
+ if (fromAgent)
430
+ return MANAGERS[fromAgent];
431
+ if (await isInstalled("bun"))
432
+ return MANAGERS.bun;
433
+ return MANAGERS.npm;
434
+ }
435
+
436
+ // ../../node_modules/.bun/@clack+core@1.4.3/node_modules/@clack/core/dist/index.mjs
437
+ import { styleText } from "node:util";
438
+ import { stdout, stdin } from "node:process";
439
+ import * as l from "node:readline";
440
+ import l__default from "node:readline";
441
+
442
+ // ../../node_modules/.bun/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
443
+ var getCodePointsLength = (() => {
444
+ const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
445
+ return (input) => {
446
+ let surrogatePairsNr = 0;
447
+ SURROGATE_PAIR_RE.lastIndex = 0;
448
+ while (SURROGATE_PAIR_RE.test(input)) {
449
+ surrogatePairsNr += 1;
450
+ }
451
+ return input.length - surrogatePairsNr;
452
+ };
453
+ })();
454
+ var isFullWidth = (x) => {
455
+ return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
456
+ };
457
+ var isWideNotCJKTNotEmoji = (x) => {
458
+ 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;
459
+ };
460
+
461
+ // ../../node_modules/.bun/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/index.js
462
+ var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
463
+ var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
464
+ var CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu;
465
+ var TAB_RE = /\t{1,1000}/y;
466
+ var EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
467
+ var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
468
+ var MODIFIER_RE = /\p{M}+/gu;
469
+ var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
470
+ var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
471
+ const LIMIT = truncationOptions.limit ?? Infinity;
472
+ const ELLIPSIS = truncationOptions.ellipsis ?? "";
473
+ const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
474
+ const ANSI_WIDTH = 0;
475
+ const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
476
+ const TAB_WIDTH = widthOptions.tabWidth ?? 8;
477
+ const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
478
+ const FULL_WIDTH_WIDTH = 2;
479
+ const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
480
+ const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
481
+ const PARSE_BLOCKS = [
482
+ [LATIN_RE, REGULAR_WIDTH],
483
+ [ANSI_RE, ANSI_WIDTH],
484
+ [CONTROL_RE, CONTROL_WIDTH],
485
+ [TAB_RE, TAB_WIDTH],
486
+ [EMOJI_RE, EMOJI_WIDTH],
487
+ [CJKT_WIDE_RE, WIDE_WIDTH]
488
+ ];
489
+ let indexPrev = 0;
490
+ let index = 0;
491
+ let length = input.length;
492
+ let lengthExtra = 0;
493
+ let truncationEnabled = false;
494
+ let truncationIndex = length;
495
+ let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
496
+ let unmatchedStart = 0;
497
+ let unmatchedEnd = 0;
498
+ let width = 0;
499
+ let widthExtra = 0;
500
+ outer:
501
+ while (true) {
502
+ if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
503
+ const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
504
+ lengthExtra = 0;
505
+ for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
506
+ const codePoint = char.codePointAt(0) || 0;
507
+ if (isFullWidth(codePoint)) {
508
+ widthExtra = FULL_WIDTH_WIDTH;
509
+ } else if (isWideNotCJKTNotEmoji(codePoint)) {
510
+ widthExtra = WIDE_WIDTH;
511
+ } else {
512
+ widthExtra = REGULAR_WIDTH;
513
+ }
514
+ if (width + widthExtra > truncationLimit) {
515
+ truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
516
+ }
517
+ if (width + widthExtra > LIMIT) {
518
+ truncationEnabled = true;
519
+ break outer;
520
+ }
521
+ lengthExtra += char.length;
522
+ width += widthExtra;
523
+ }
524
+ unmatchedStart = unmatchedEnd = 0;
525
+ }
526
+ if (index >= length) {
527
+ break outer;
528
+ }
529
+ for (let i = 0, l = PARSE_BLOCKS.length;i < l; i++) {
530
+ const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
531
+ BLOCK_RE.lastIndex = index;
532
+ if (BLOCK_RE.test(input)) {
533
+ lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
534
+ widthExtra = lengthExtra * BLOCK_WIDTH;
535
+ if (width + widthExtra > truncationLimit) {
536
+ truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
537
+ }
538
+ if (width + widthExtra > LIMIT) {
539
+ truncationEnabled = true;
540
+ break outer;
541
+ }
542
+ width += widthExtra;
543
+ unmatchedStart = indexPrev;
544
+ unmatchedEnd = index;
545
+ index = indexPrev = BLOCK_RE.lastIndex;
546
+ continue outer;
547
+ }
548
+ }
549
+ index += 1;
550
+ }
551
+ return {
552
+ width: truncationEnabled ? truncationLimit : width,
553
+ index: truncationEnabled ? truncationIndex : length,
554
+ truncated: truncationEnabled,
555
+ ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
556
+ };
557
+ };
558
+ var dist_default = getStringTruncatedWidth;
559
+
560
+ // ../../node_modules/.bun/fast-string-width@3.0.2/node_modules/fast-string-width/dist/index.js
561
+ var NO_TRUNCATION2 = {
562
+ limit: Infinity,
563
+ ellipsis: "",
564
+ ellipsisWidth: 0
565
+ };
566
+ var fastStringWidth = (input, options = {}) => {
567
+ return dist_default(input, NO_TRUNCATION2, options).width;
568
+ };
569
+ var dist_default2 = fastStringWidth;
570
+
571
+ // ../../node_modules/.bun/fast-wrap-ansi@0.2.2/node_modules/fast-wrap-ansi/lib/main.js
572
+ var ESC = "\x1B";
573
+ var CSI = "›";
574
+ var END_CODE = 39;
575
+ var ANSI_ESCAPE_BELL = "\x07";
576
+ var ANSI_CSI = "[";
577
+ var ANSI_OSC = "]";
578
+ var ANSI_SGR_TERMINATOR = "m";
579
+ var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
580
+ var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
581
+ var getClosingCode = (openingCode) => {
582
+ if (openingCode >= 30 && openingCode <= 37)
583
+ return 39;
584
+ if (openingCode >= 90 && openingCode <= 97)
585
+ return 39;
586
+ if (openingCode >= 40 && openingCode <= 47)
587
+ return 49;
588
+ if (openingCode >= 100 && openingCode <= 107)
589
+ return 49;
590
+ if (openingCode === 1 || openingCode === 2)
591
+ return 22;
592
+ if (openingCode === 3)
593
+ return 23;
594
+ if (openingCode === 4)
595
+ return 24;
596
+ if (openingCode === 7)
597
+ return 27;
598
+ if (openingCode === 8)
599
+ return 28;
600
+ if (openingCode === 9)
601
+ return 29;
602
+ if (openingCode === 0)
603
+ return 0;
604
+ return;
605
+ };
606
+ var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
607
+ var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
608
+ var wrapWord = (rows, word, columns) => {
609
+ const characters = word[Symbol.iterator]();
610
+ let isInsideEscape = false;
611
+ let isInsideLinkEscape = false;
612
+ let lastRow = rows.at(-1);
613
+ let visible = lastRow === undefined ? 0 : dist_default2(lastRow);
614
+ let currentCharacter = characters.next();
615
+ let nextCharacter = characters.next();
616
+ let rawCharacterIndex = 0;
617
+ while (!currentCharacter.done) {
618
+ const character = currentCharacter.value;
619
+ const characterLength = dist_default2(character);
620
+ if (visible + characterLength <= columns) {
621
+ rows[rows.length - 1] += character;
622
+ } else {
623
+ rows.push(character);
624
+ visible = 0;
625
+ }
626
+ if (character === ESC || character === CSI) {
627
+ isInsideEscape = true;
628
+ isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
629
+ }
630
+ if (isInsideEscape) {
631
+ if (isInsideLinkEscape) {
632
+ if (character === ANSI_ESCAPE_BELL) {
633
+ isInsideEscape = false;
634
+ isInsideLinkEscape = false;
635
+ }
636
+ } else if (character === ANSI_SGR_TERMINATOR) {
637
+ isInsideEscape = false;
638
+ }
639
+ } else {
640
+ visible += characterLength;
641
+ if (visible === columns && !nextCharacter.done) {
642
+ rows.push("");
643
+ visible = 0;
644
+ }
645
+ }
646
+ currentCharacter = nextCharacter;
647
+ nextCharacter = characters.next();
648
+ rawCharacterIndex += character.length;
649
+ }
650
+ lastRow = rows.at(-1);
651
+ if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
652
+ rows[rows.length - 2] += rows.pop();
653
+ }
654
+ };
655
+ var stringVisibleTrimSpacesRight = (string) => {
656
+ const words = string.split(" ");
657
+ let last = words.length;
658
+ while (last) {
659
+ if (dist_default2(words[last - 1])) {
660
+ break;
661
+ }
662
+ last--;
663
+ }
664
+ if (last === words.length) {
665
+ return string;
666
+ }
667
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
668
+ };
669
+ var exec = (string, columns, options = {}) => {
670
+ if (options.trim !== false && string.trim() === "") {
671
+ return "";
672
+ }
673
+ let returnValue = "";
674
+ let escapeCode;
675
+ let escapeUrl;
676
+ const words = string.split(" ");
677
+ let rows = [""];
678
+ let rowLength = 0;
679
+ for (let index = 0;index < words.length; index++) {
680
+ const word = words[index];
681
+ if (options.trim !== false) {
682
+ const row = rows.at(-1) ?? "";
683
+ const trimmed = row.trimStart();
684
+ if (row.length !== trimmed.length) {
685
+ rows[rows.length - 1] = trimmed;
686
+ rowLength = dist_default2(trimmed);
687
+ }
688
+ }
689
+ if (index !== 0) {
690
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
691
+ rows.push("");
692
+ rowLength = 0;
693
+ }
694
+ if (rowLength || options.trim === false) {
695
+ rows[rows.length - 1] += " ";
696
+ rowLength++;
697
+ }
698
+ }
699
+ const wordLength = dist_default2(word);
700
+ if (options.hard && wordLength > columns) {
701
+ const remainingColumns = columns - rowLength;
702
+ const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
703
+ const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
704
+ if (breaksStartingNextLine < breaksStartingThisLine) {
705
+ rows.push("");
706
+ }
707
+ wrapWord(rows, word, columns);
708
+ rowLength = dist_default2(rows.at(-1) ?? "");
709
+ continue;
710
+ }
711
+ if (rowLength + wordLength > columns && rowLength && wordLength) {
712
+ if (options.wordWrap === false && rowLength < columns) {
713
+ wrapWord(rows, word, columns);
714
+ rowLength = dist_default2(rows.at(-1) ?? "");
715
+ continue;
716
+ }
717
+ rows.push("");
718
+ rowLength = 0;
719
+ }
720
+ if (rowLength + wordLength > columns && options.wordWrap === false) {
721
+ wrapWord(rows, word, columns);
722
+ rowLength = dist_default2(rows.at(-1) ?? "");
723
+ continue;
724
+ }
725
+ rows[rows.length - 1] += word;
726
+ rowLength += wordLength;
727
+ }
728
+ if (options.trim !== false) {
729
+ rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
730
+ }
731
+ const preString = rows.join(`
732
+ `);
733
+ let inSurrogate = false;
734
+ for (let i = 0;i < preString.length; i++) {
735
+ const character = preString[i];
736
+ returnValue += character;
737
+ if (!inSurrogate) {
738
+ inSurrogate = character >= "\uD800" && character <= "\uDBFF";
739
+ if (inSurrogate) {
740
+ continue;
741
+ }
742
+ } else {
743
+ inSurrogate = false;
744
+ }
745
+ if (character === ESC || character === CSI) {
746
+ GROUP_REGEX.lastIndex = i + 1;
747
+ const groupsResult = GROUP_REGEX.exec(preString);
748
+ const groups = groupsResult?.groups;
749
+ if (groups?.code !== undefined) {
750
+ const code = Number.parseFloat(groups.code);
751
+ escapeCode = code === END_CODE ? undefined : code;
752
+ } else if (groups?.uri !== undefined) {
753
+ escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
754
+ }
755
+ }
756
+ if (preString[i + 1] === `
757
+ `) {
758
+ if (escapeUrl) {
759
+ returnValue += wrapAnsiHyperlink("");
760
+ }
761
+ const closingCode = escapeCode ? getClosingCode(escapeCode) : undefined;
762
+ if (escapeCode && closingCode) {
763
+ returnValue += wrapAnsiCode(closingCode);
764
+ }
765
+ } else if (character === `
766
+ `) {
767
+ if (escapeCode && getClosingCode(escapeCode)) {
768
+ returnValue += wrapAnsiCode(escapeCode);
769
+ }
770
+ if (escapeUrl) {
771
+ returnValue += wrapAnsiHyperlink(escapeUrl);
772
+ }
773
+ }
774
+ }
775
+ return returnValue;
776
+ };
777
+ var CRLF_OR_LF = /\r?\n/;
778
+ function wrapAnsi(string, columns, options) {
779
+ return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join(`
780
+ `);
781
+ }
782
+
783
+ // ../../node_modules/.bun/@clack+core@1.4.3/node_modules/@clack/core/dist/index.mjs
784
+ var import_sisteransi = __toESM(require_src(), 1);
785
+ import { ReadStream } from "node:tty";
786
+ function findCursor(s, o, l2) {
787
+ if (!l2.some((r) => !r.disabled))
788
+ return s;
789
+ const t = s + o, n = Math.max(l2.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
790
+ return l2[e]?.disabled ? findCursor(e, o < 0 ? -1 : 1, l2) : e;
791
+ }
792
+ function findTextCursor(s, o, l2, i) {
793
+ const t = i.split(`
794
+ `);
795
+ let n = 0, e = s;
796
+ for (const r of t) {
797
+ if (e <= r.length)
798
+ break;
799
+ e -= r.length + 1, n++;
800
+ }
801
+ for (n = Math.max(0, Math.min(t.length - 1, n + l2)), e = Math.min(e, t[n].length) + o;e < 0 && n > 0; )
802
+ n--, e += t[n].length + 1;
803
+ for (;e > t[n].length && n < t.length - 1; )
804
+ e -= t[n].length + 1, n++;
805
+ e = Math.max(0, Math.min(t[n].length, e));
806
+ let h = 0;
807
+ for (let r = 0;r < n; r++)
808
+ h += t[r].length + 1;
809
+ return h + e;
810
+ }
811
+ var a$1 = ["up", "down", "left", "right", "space", "enter", "cancel"];
812
+ var t = [
813
+ "January",
814
+ "February",
815
+ "March",
816
+ "April",
817
+ "May",
818
+ "June",
819
+ "July",
820
+ "August",
821
+ "September",
822
+ "October",
823
+ "November",
824
+ "December"
825
+ ];
826
+ var settings = {
827
+ actions: new Set(a$1),
828
+ aliases: /* @__PURE__ */ new Map([
829
+ ["k", "up"],
830
+ ["j", "down"],
831
+ ["h", "left"],
832
+ ["l", "right"],
833
+ ["\x03", "cancel"],
834
+ ["escape", "cancel"]
835
+ ]),
836
+ messages: {
837
+ cancel: "Canceled",
838
+ error: "Something went wrong"
839
+ },
840
+ withGuide: true,
841
+ date: {
842
+ monthNames: [...t],
843
+ messages: {
844
+ required: "Please enter a valid date",
845
+ invalidMonth: "There are only 12 months in a year",
846
+ invalidDay: (n, e) => `There are only ${n} days in ${e}`,
847
+ afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
848
+ beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
849
+ }
850
+ }
851
+ };
852
+ function isActionKey(n, e) {
853
+ if (typeof n == "string")
854
+ return settings.aliases.get(n) === e;
855
+ for (const s of n)
856
+ if (s !== undefined && isActionKey(s, e))
857
+ return true;
858
+ return false;
859
+ }
860
+ function diffLines(i, s) {
861
+ if (i === s)
862
+ return;
863
+ const e = i.split(`
864
+ `), t2 = s.split(`
865
+ `), r = Math.max(e.length, t2.length), f = [];
866
+ for (let n = 0;n < r; n++)
867
+ e[n] !== t2[n] && f.push(n);
868
+ return {
869
+ lines: f,
870
+ numLinesBefore: e.length,
871
+ numLinesAfter: t2.length,
872
+ numLines: r
873
+ };
874
+ }
875
+ var R = globalThis.process.platform.startsWith("win");
876
+ var CANCEL_SYMBOL = Symbol("clack:cancel");
877
+ function setRawMode(e, r) {
878
+ const o = e;
879
+ o.isTTY && o.setRawMode(r);
880
+ }
881
+ function block({
882
+ input: e = stdin,
883
+ output: r = stdout,
884
+ overwrite: o = true,
885
+ hideCursor: t2 = true
886
+ } = {}) {
887
+ const s = l.createInterface({
888
+ input: e,
889
+ output: r,
890
+ prompt: "",
891
+ tabSize: 1
892
+ });
893
+ l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
894
+ const n = (f, { name: a, sequence: p }) => {
895
+ const c = String(f);
896
+ if (isActionKey([c, a, p], "cancel")) {
897
+ t2 && r.write(import_sisteransi.cursor.show), process.exit(0);
898
+ return;
899
+ }
900
+ if (!o)
901
+ return;
902
+ const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
903
+ l.moveCursor(r, i, m, () => {
904
+ l.clearLine(r, 1, () => {
905
+ e.once("keypress", n);
906
+ });
907
+ });
908
+ };
909
+ return t2 && r.write(import_sisteransi.cursor.hide), e.once("keypress", n), () => {
910
+ e.off("keypress", n), t2 && r.write(import_sisteransi.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
911
+ };
912
+ }
913
+ var getColumns = (e) => ("columns" in e) && typeof e.columns == "number" ? e.columns : 80;
914
+ var getRows = (e) => ("rows" in e) && typeof e.rows == "number" ? e.rows : 20;
915
+ function runValidation(e, n) {
916
+ if ("~standard" in e) {
917
+ const a = e["~standard"].validate(n);
918
+ if (a instanceof Promise)
919
+ throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
920
+ return a.issues?.at(0)?.message;
921
+ }
922
+ return e(n);
923
+ }
924
+
925
+ class V {
926
+ input;
927
+ output;
928
+ _abortSignal;
929
+ rl;
930
+ opts;
931
+ _render;
932
+ _track = false;
933
+ _prevFrame = "";
934
+ _subscribers = /* @__PURE__ */ new Map;
935
+ _cursor = 0;
936
+ state = "initial";
937
+ error = "";
938
+ value;
939
+ userInput = "";
940
+ constructor(t2, e = true) {
941
+ const { input: i = stdin, output: n = stdout, render: s, signal: r, ...o } = t2;
942
+ this.opts = o, 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 = r, this.input = i, this.output = n;
943
+ }
944
+ unsubscribe() {
945
+ this._subscribers.clear();
946
+ }
947
+ setSubscriber(t2, e) {
948
+ const i = this._subscribers.get(t2) ?? [];
949
+ i.push(e), this._subscribers.set(t2, i);
950
+ }
951
+ on(t2, e) {
952
+ this.setSubscriber(t2, { cb: e });
953
+ }
954
+ once(t2, e) {
955
+ this.setSubscriber(t2, { cb: e, once: true });
956
+ }
957
+ emit(t2, ...e) {
958
+ const i = this._subscribers.get(t2) ?? [], n = [];
959
+ for (const s of i)
960
+ s.cb(...e), s.once && n.push(() => i.splice(i.indexOf(s), 1));
961
+ for (const s of n)
962
+ s();
963
+ }
964
+ prompt() {
965
+ return new Promise((t2) => {
966
+ if (this._abortSignal) {
967
+ if (this._abortSignal.aborted)
968
+ return this.state = "cancel", this.close(), t2(CANCEL_SYMBOL);
969
+ this._abortSignal.addEventListener("abort", () => {
970
+ this.state = "cancel", this.close();
971
+ }, { once: true });
972
+ }
973
+ this.rl = l__default.createInterface({
974
+ input: this.input,
975
+ tabSize: 2,
976
+ prompt: "",
977
+ escapeCodeTimeout: 50,
978
+ terminal: true
979
+ }), this.rl.prompt(), this.opts.initialUserInput !== undefined && 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", () => {
980
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(this.value);
981
+ }), this.once("cancel", () => {
982
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(CANCEL_SYMBOL);
983
+ });
984
+ });
985
+ }
986
+ _isActionKey(t2, e) {
987
+ return t2 === "\t";
988
+ }
989
+ _shouldSubmit(t2, e) {
990
+ return true;
991
+ }
992
+ _setValue(t2) {
993
+ this.value = t2, this.emit("value", this.value);
994
+ }
995
+ _setUserInput(t2, e) {
996
+ this.userInput = t2 ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
997
+ }
998
+ _clearUserInput() {
999
+ this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
1000
+ }
1001
+ onKeypress(t2, e) {
1002
+ 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)) {
1003
+ if (this.opts.validate) {
1004
+ const i = runValidation(this.opts.validate, this.value);
1005
+ i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
1006
+ }
1007
+ this.state !== "error" && (this.state = "submit");
1008
+ }
1009
+ 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();
1010
+ }
1011
+ close() {
1012
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
1013
+ `), setRawMode(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
1014
+ }
1015
+ restoreCursor() {
1016
+ const t2 = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
1017
+ `).length - 1;
1018
+ this.output.write(import_sisteransi.cursor.move(-999, t2 * -1));
1019
+ }
1020
+ render() {
1021
+ const t2 = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
1022
+ hard: true,
1023
+ trim: false
1024
+ });
1025
+ if (t2 !== this._prevFrame) {
1026
+ if (this.state === "initial")
1027
+ this.output.write(import_sisteransi.cursor.hide);
1028
+ else {
1029
+ const e = diffLines(this._prevFrame, t2), i = getRows(this.output);
1030
+ if (this.restoreCursor(), e) {
1031
+ const n = Math.max(0, e.numLinesAfter - i), s = Math.max(0, e.numLinesBefore - i);
1032
+ let r = e.lines.find((o) => o >= n);
1033
+ if (r === undefined) {
1034
+ this._prevFrame = t2;
1035
+ return;
1036
+ }
1037
+ if (e.lines.length === 1) {
1038
+ this.output.write(import_sisteransi.cursor.move(0, r - s)), this.output.write(import_sisteransi.erase.lines(1));
1039
+ const o = t2.split(`
1040
+ `);
1041
+ this.output.write(o[r]), this._prevFrame = t2, this.output.write(import_sisteransi.cursor.move(0, o.length - r - 1));
1042
+ return;
1043
+ } else if (e.lines.length > 1) {
1044
+ if (n < s)
1045
+ r = n;
1046
+ else {
1047
+ const h = r - s;
1048
+ h > 0 && this.output.write(import_sisteransi.cursor.move(0, h));
1049
+ }
1050
+ this.output.write(import_sisteransi.erase.down());
1051
+ const f = t2.split(`
1052
+ `).slice(r);
1053
+ this.output.write(f.join(`
1054
+ `)), this._prevFrame = t2;
1055
+ return;
1056
+ }
1057
+ }
1058
+ this.output.write(import_sisteransi.erase.down());
1059
+ }
1060
+ this.output.write(t2), this.state === "initial" && (this.state = "active"), this._prevFrame = t2;
1061
+ }
1062
+ }
1063
+ }
1064
+ function p$1(l2, e) {
1065
+ if (l2 === undefined || e.length === 0)
1066
+ return 0;
1067
+ const i = e.findIndex((s) => s.value === l2);
1068
+ return i !== -1 ? i : 0;
1069
+ }
1070
+ function g(l2, e) {
1071
+ return (e.label ?? String(e.value)).toLowerCase().includes(l2.toLowerCase());
1072
+ }
1073
+ function m(l2, e) {
1074
+ if (e)
1075
+ return l2 ? e : e[0];
1076
+ }
1077
+ var T$1 = class T extends V {
1078
+ filteredOptions;
1079
+ multiple;
1080
+ isNavigating = false;
1081
+ selectedValues = [];
1082
+ focusedValue;
1083
+ #e = 0;
1084
+ #s = "";
1085
+ #t;
1086
+ #i;
1087
+ #n;
1088
+ get cursor() {
1089
+ return this.#e;
1090
+ }
1091
+ get userInputWithCursor() {
1092
+ if (!this.userInput)
1093
+ return styleText(["inverse", "hidden"], "_");
1094
+ if (this._cursor >= this.userInput.length)
1095
+ return `${this.userInput}█`;
1096
+ const e = this.userInput.slice(0, this.cursor), t2 = this.userInput.slice(this.cursor, this.cursor + 1), i = this.userInput.slice(this.cursor + 1);
1097
+ return `${e}${styleText("inverse", t2)}${i}`;
1098
+ }
1099
+ get options() {
1100
+ return typeof this.#i == "function" ? this.#i() : this.#i;
1101
+ }
1102
+ constructor(e) {
1103
+ super(e), this.#i = e.options, this.#n = e.placeholder;
1104
+ const t2 = this.options;
1105
+ this.filteredOptions = [...t2], this.multiple = e.multiple === true, this.#t = typeof e.options == "function" ? e.filter : e.filter ?? g;
1106
+ let i;
1107
+ if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0]?.value]), i)
1108
+ for (const s of i) {
1109
+ const n = t2.findIndex((o) => o.value === s);
1110
+ n !== -1 && (this.toggleSelected(s), this.#e = n);
1111
+ }
1112
+ this.focusedValue = this.options[this.#e]?.value, this.on("key", (s, n) => this.#l(s, n)), this.on("userInput", (s) => this.#u(s));
1113
+ }
1114
+ _isActionKey(e, t2) {
1115
+ return e === "\t" || this.multiple && this.isNavigating && t2.name === "space" && e !== undefined && e !== "";
1116
+ }
1117
+ #l(e, t2) {
1118
+ const i = t2.name === "up", s = t2.name === "down", n = t2.name === "return", o = this.userInput === "" || this.userInput === "\t", u = this.#n, a = this.options, f = u !== undefined && u !== "" && a.some((r) => !r.disabled && (this.#t ? this.#t(u, r) : true));
1119
+ if (t2.name === "tab" && o && f) {
1120
+ this.userInput === "\t" && this._clearUserInput(), this._setUserInput(u, true), this.isNavigating = false;
1121
+ return;
1122
+ }
1123
+ i || s ? (this.#e = findCursor(this.#e, i ? -1 : 1, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#e]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = m(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== undefined && (t2.name === "tab" || this.isNavigating && t2.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
1124
+ }
1125
+ deselectAll() {
1126
+ this.selectedValues = [];
1127
+ }
1128
+ toggleSelected(e) {
1129
+ this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((t2) => t2 !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
1130
+ }
1131
+ #u(e) {
1132
+ if (e !== this.#s) {
1133
+ this.#s = e;
1134
+ const t2 = this.options;
1135
+ e && this.#t ? this.filteredOptions = t2.filter((n) => this.#t?.(e, n)) : this.filteredOptions = [...t2];
1136
+ const i = p$1(this.focusedValue, this.filteredOptions);
1137
+ this.#e = findCursor(i, 0, this.filteredOptions);
1138
+ const s = this.filteredOptions[this.#e];
1139
+ s && !s.disabled ? this.focusedValue = s.value : this.focusedValue = undefined, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
1140
+ }
1141
+ }
1142
+ };
1143
+ var _ = {
1144
+ Y: { type: "year", len: 4 },
1145
+ M: { type: "month", len: 2 },
1146
+ D: { type: "day", len: 2 }
1147
+ };
1148
+ function M(r) {
1149
+ return [...r].map((t2) => _[t2]);
1150
+ }
1151
+ function P(r) {
1152
+ const i = new Intl.DateTimeFormat(r, {
1153
+ year: "numeric",
1154
+ month: "2-digit",
1155
+ day: "2-digit"
1156
+ }).formatToParts(new Date(2000, 0, 15)), s = [];
1157
+ let n = "/";
1158
+ for (const e of i)
1159
+ e.type === "literal" ? n = e.value.trim() || e.value : (e.type === "year" || e.type === "month" || e.type === "day") && s.push({ type: e.type, len: e.type === "year" ? 4 : 2 });
1160
+ return { segments: s, separator: n };
1161
+ }
1162
+ function p(r) {
1163
+ return Number.parseInt((r || "0").replace(/_/g, "0"), 10) || 0;
1164
+ }
1165
+ function f(r) {
1166
+ return {
1167
+ year: p(r.year),
1168
+ month: p(r.month),
1169
+ day: p(r.day)
1170
+ };
1171
+ }
1172
+ function c(r, t2) {
1173
+ return new Date(r || 2001, t2 || 1, 0).getDate();
1174
+ }
1175
+ function b(r) {
1176
+ const { year: t2, month: i, day: s } = f(r);
1177
+ if (!t2 || t2 < 0 || t2 > 9999 || !i || i < 1 || i > 12 || !s || s < 1)
1178
+ return;
1179
+ const n = new Date(Date.UTC(t2, i - 1, s));
1180
+ if (!(n.getUTCFullYear() !== t2 || n.getUTCMonth() !== i - 1 || n.getUTCDate() !== s))
1181
+ return { year: t2, month: i, day: s };
1182
+ }
1183
+ function C(r) {
1184
+ const t2 = b(r);
1185
+ return t2 ? new Date(Date.UTC(t2.year, t2.month - 1, t2.day)) : undefined;
1186
+ }
1187
+ function T2(r, t2, i, s) {
1188
+ const n = i ? {
1189
+ year: i.getUTCFullYear(),
1190
+ month: i.getUTCMonth() + 1,
1191
+ day: i.getUTCDate()
1192
+ } : null, e = s ? {
1193
+ year: s.getUTCFullYear(),
1194
+ month: s.getUTCMonth() + 1,
1195
+ day: s.getUTCDate()
1196
+ } : null;
1197
+ return r === "year" ? { min: n?.year ?? 1, max: e?.year ?? 9999 } : r === "month" ? {
1198
+ min: n && t2.year === n.year ? n.month : 1,
1199
+ max: e && t2.year === e.year ? e.month : 12
1200
+ } : {
1201
+ min: n && t2.year === n.year && t2.month === n.month ? n.day : 1,
1202
+ max: e && t2.year === e.year && t2.month === e.month ? e.day : c(t2.year, t2.month)
1203
+ };
1204
+ }
1205
+
1206
+ class U extends V {
1207
+ #i;
1208
+ #o;
1209
+ #t;
1210
+ #h;
1211
+ #u;
1212
+ #e = { segmentIndex: 0, positionInSegment: 0 };
1213
+ #n = true;
1214
+ #s = null;
1215
+ inlineError = "";
1216
+ get segmentCursor() {
1217
+ return { ...this.#e };
1218
+ }
1219
+ get segmentValues() {
1220
+ return { ...this.#t };
1221
+ }
1222
+ get segments() {
1223
+ return this.#i;
1224
+ }
1225
+ get separator() {
1226
+ return this.#o;
1227
+ }
1228
+ get formattedValue() {
1229
+ return this.#l(this.#t);
1230
+ }
1231
+ #l(t2) {
1232
+ return this.#i.map((i) => t2[i.type]).join(this.#o);
1233
+ }
1234
+ #r() {
1235
+ this._setUserInput(this.#l(this.#t)), this._setValue(C(this.#t) ?? undefined);
1236
+ }
1237
+ constructor(t2) {
1238
+ const i = t2.format ? { segments: M(t2.format), separator: t2.separator ?? "/" } : P(t2.locale), s = t2.separator ?? i.separator, n = t2.format ? M(t2.format) : i.segments, e = t2.initialValue ?? t2.defaultValue, m2 = e ? {
1239
+ year: String(e.getUTCFullYear()).padStart(4, "0"),
1240
+ month: String(e.getUTCMonth() + 1).padStart(2, "0"),
1241
+ day: String(e.getUTCDate()).padStart(2, "0")
1242
+ } : { year: "____", month: "__", day: "__" }, o = n.map((a) => m2[a.type]).join(s);
1243
+ super({ ...t2, initialUserInput: o }, false), this.#i = n, this.#o = s, this.#t = m2, this.#h = t2.minDate, this.#u = t2.maxDate, this.#r(), this.on("cursor", (a) => this.#f(a)), this.on("key", (a, u) => this.#y(a, u)), this.on("finalize", () => this.#p(t2));
1244
+ }
1245
+ #a() {
1246
+ const t2 = Math.max(0, Math.min(this.#e.segmentIndex, this.#i.length - 1)), i = this.#i[t2];
1247
+ if (i)
1248
+ return this.#e.positionInSegment = Math.max(0, Math.min(this.#e.positionInSegment, i.len - 1)), { segment: i, index: t2 };
1249
+ }
1250
+ #m(t2) {
1251
+ this.inlineError = "", this.#s = null;
1252
+ const i = this.#a();
1253
+ i && (this.#e.segmentIndex = Math.max(0, Math.min(this.#i.length - 1, i.index + t2)), this.#e.positionInSegment = 0, this.#n = true);
1254
+ }
1255
+ #d(t2) {
1256
+ const i = this.#a();
1257
+ if (!i)
1258
+ return;
1259
+ const { segment: s } = i, n = this.#t[s.type], e = !n || n.replace(/_/g, "") === "", m2 = Number.parseInt((n || "0").replace(/_/g, "0"), 10) || 0, o = T2(s.type, f(this.#t), this.#h, this.#u);
1260
+ let a;
1261
+ e ? a = t2 === 1 ? o.min : o.max : a = Math.max(Math.min(o.max, m2 + t2), o.min), this.#t = {
1262
+ ...this.#t,
1263
+ [s.type]: a.toString().padStart(s.len, "0")
1264
+ }, this.#n = true, this.#s = null, this.#r();
1265
+ }
1266
+ #f(t2) {
1267
+ if (t2)
1268
+ switch (t2) {
1269
+ case "right":
1270
+ return this.#m(1);
1271
+ case "left":
1272
+ return this.#m(-1);
1273
+ case "up":
1274
+ return this.#d(1);
1275
+ case "down":
1276
+ return this.#d(-1);
1277
+ }
1278
+ }
1279
+ #y(t2, i) {
1280
+ if (i?.name === "backspace" || i?.sequence === "" || i?.sequence === "\b" || t2 === "" || t2 === "\b") {
1281
+ this.inlineError = "";
1282
+ const n = this.#a();
1283
+ if (!n)
1284
+ return;
1285
+ if (!this.#t[n.segment.type].replace(/_/g, "")) {
1286
+ this.#m(-1);
1287
+ return;
1288
+ }
1289
+ this.#t[n.segment.type] = "_".repeat(n.segment.len), this.#n = true, this.#e.positionInSegment = 0, this.#r();
1290
+ return;
1291
+ }
1292
+ if (i?.name === "tab") {
1293
+ this.inlineError = "";
1294
+ const n = this.#a();
1295
+ if (!n)
1296
+ return;
1297
+ const e = i.shift ? -1 : 1, m2 = n.index + e;
1298
+ m2 >= 0 && m2 < this.#i.length && (this.#e.segmentIndex = m2, this.#e.positionInSegment = 0, this.#n = true);
1299
+ return;
1300
+ }
1301
+ if (t2 && /^[0-9]$/.test(t2)) {
1302
+ const n = this.#a();
1303
+ if (!n)
1304
+ return;
1305
+ const { segment: e } = n, m2 = !this.#t[e.type].replace(/_/g, "");
1306
+ if (this.#n && this.#s !== null && !m2) {
1307
+ const h = this.#s + t2, d = { ...this.#t, [e.type]: h }, g2 = this.#g(d, e);
1308
+ if (g2) {
1309
+ this.inlineError = g2, this.#s = null, this.#n = false;
1310
+ return;
1311
+ }
1312
+ this.inlineError = "", this.#t[e.type] = h, this.#s = null, this.#n = false, this.#r(), n.index < this.#i.length - 1 && (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true);
1313
+ return;
1314
+ }
1315
+ this.#n && !m2 && (this.#t[e.type] = "_".repeat(e.len), this.#e.positionInSegment = 0), this.#n = false, this.#s = null;
1316
+ const o = this.#t[e.type], a = o.indexOf("_"), u = a >= 0 ? a : Math.min(this.#e.positionInSegment, e.len - 1);
1317
+ if (u < 0 || u >= e.len)
1318
+ return;
1319
+ let l2 = o.slice(0, u) + t2 + o.slice(u + 1), D = false;
1320
+ if (u === 0 && o === "__" && (e.type === "month" || e.type === "day")) {
1321
+ const h = Number.parseInt(t2, 10);
1322
+ l2 = `0${t2}`, D = h <= (e.type === "month" ? 1 : 2);
1323
+ }
1324
+ if (e.type === "year" && (l2 = (o.replace(/_/g, "") + t2).padStart(e.len, "_")), !l2.includes("_")) {
1325
+ const h = { ...this.#t, [e.type]: l2 }, d = this.#g(h, e);
1326
+ if (d) {
1327
+ this.inlineError = d;
1328
+ return;
1329
+ }
1330
+ }
1331
+ this.inlineError = "", this.#t[e.type] = l2;
1332
+ const y = l2.includes("_") ? undefined : b(this.#t);
1333
+ if (y) {
1334
+ const { year: h, month: d } = y, g2 = c(h, d);
1335
+ this.#t = {
1336
+ year: String(Math.max(0, Math.min(9999, h))).padStart(4, "0"),
1337
+ month: String(Math.max(1, Math.min(12, d))).padStart(2, "0"),
1338
+ day: String(Math.max(1, Math.min(g2, y.day))).padStart(2, "0")
1339
+ };
1340
+ }
1341
+ this.#r();
1342
+ const S = l2.indexOf("_");
1343
+ D ? (this.#n = true, this.#s = t2) : S >= 0 ? this.#e.positionInSegment = S : a >= 0 && n.index < this.#i.length - 1 ? (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true) : this.#e.positionInSegment = Math.min(u + 1, e.len - 1);
1344
+ }
1345
+ }
1346
+ #g(t2, i) {
1347
+ const { month: s, day: n } = f(t2);
1348
+ if (i.type === "month" && (s < 0 || s > 12))
1349
+ return settings.date.messages.invalidMonth;
1350
+ if (i.type === "day" && (n < 0 || n > 31))
1351
+ return settings.date.messages.invalidDay(31, "any month");
1352
+ }
1353
+ #p(t2) {
1354
+ const { year: i, month: s, day: n } = f(this.#t);
1355
+ if (i && s && n) {
1356
+ const e = c(i, s);
1357
+ this.#t = {
1358
+ ...this.#t,
1359
+ day: String(Math.min(n, e)).padStart(2, "0")
1360
+ };
1361
+ }
1362
+ this.value = C(this.#t) ?? t2.defaultValue ?? undefined;
1363
+ }
1364
+ }
1365
+ var u$2 = class u extends V {
1366
+ options;
1367
+ cursor = 0;
1368
+ #t;
1369
+ getGroupItems(t2) {
1370
+ return this.options.filter((r) => r.group === t2);
1371
+ }
1372
+ isGroupSelected(t2) {
1373
+ const r = this.getGroupItems(t2), e = this.value;
1374
+ return e === undefined ? false : r.every((s) => e.includes(s.value));
1375
+ }
1376
+ toggleValue() {
1377
+ const t2 = this.options[this.cursor];
1378
+ if (t2 !== undefined)
1379
+ if (this.value === undefined && (this.value = []), t2.group === true) {
1380
+ const r = t2.value, e = this.getGroupItems(r);
1381
+ this.isGroupSelected(r) ? this.value = this.value.filter((s) => e.findIndex((i) => i.value === s) === -1) : this.value = [...this.value, ...e.map((s) => s.value)], this.value = Array.from(new Set(this.value));
1382
+ } else {
1383
+ const r = this.value.includes(t2.value);
1384
+ this.value = r ? this.value.filter((e) => e !== t2.value) : [...this.value, t2.value];
1385
+ }
1386
+ }
1387
+ constructor(t2) {
1388
+ super(t2, false);
1389
+ const { options: r } = t2;
1390
+ this.#t = t2.selectableGroups !== false, this.options = Object.entries(r).flatMap(([e, s]) => [
1391
+ { value: e, group: true, label: e },
1392
+ ...s.map((i) => ({ ...i, group: e }))
1393
+ ]), this.value = [...t2.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: e }) => e === t2.cursorAt), this.#t ? 0 : 1), this.on("cursor", (e) => {
1394
+ switch (e) {
1395
+ case "left":
1396
+ case "up": {
1397
+ this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
1398
+ const s = this.options[this.cursor]?.group === true;
1399
+ !this.#t && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
1400
+ break;
1401
+ }
1402
+ case "down":
1403
+ case "right": {
1404
+ this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
1405
+ const s = this.options[this.cursor]?.group === true;
1406
+ !this.#t && s && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
1407
+ break;
1408
+ }
1409
+ case "space":
1410
+ this.toggleValue();
1411
+ break;
1412
+ }
1413
+ });
1414
+ }
1415
+ };
1416
+ var o = /* @__PURE__ */ new Set(["up", "down", "left", "right"]);
1417
+
1418
+ class h extends V {
1419
+ #t = false;
1420
+ #s;
1421
+ focused = "editor";
1422
+ get userInputWithCursor() {
1423
+ if (this.state === "submit")
1424
+ return this.userInput;
1425
+ const t2 = this.userInput;
1426
+ if (this.cursor >= t2.length)
1427
+ return `${t2}█`;
1428
+ const s = t2.slice(0, this.cursor), r = t2.slice(this.cursor, this.cursor + 1), i = t2.slice(this.cursor + 1);
1429
+ return r === `
1430
+ ` ? `${s}█
1431
+ ${i}` : `${s}${styleText("inverse", r)}${i}`;
1432
+ }
1433
+ get cursor() {
1434
+ return this._cursor;
1435
+ }
1436
+ #r(t2) {
1437
+ if (this.userInput.length === 0) {
1438
+ this._setUserInput(t2);
1439
+ return;
1440
+ }
1441
+ this._setUserInput(this.userInput.slice(0, this.cursor) + t2 + this.userInput.slice(this.cursor));
1442
+ }
1443
+ #i(t2) {
1444
+ const s = this.value ?? "";
1445
+ switch (t2) {
1446
+ case "up":
1447
+ this._cursor = findTextCursor(this._cursor, 0, -1, s);
1448
+ return;
1449
+ case "down":
1450
+ this._cursor = findTextCursor(this._cursor, 0, 1, s);
1451
+ return;
1452
+ case "left":
1453
+ this._cursor = findTextCursor(this._cursor, -1, 0, s);
1454
+ return;
1455
+ case "right":
1456
+ this._cursor = findTextCursor(this._cursor, 1, 0, s);
1457
+ return;
1458
+ }
1459
+ }
1460
+ _shouldSubmit(t2, s) {
1461
+ if (this.#s)
1462
+ return this.focused === "submit" ? true : (this.#r(`
1463
+ `), this._cursor++, false);
1464
+ const r = this.#t;
1465
+ return this.#t = true, r && this.cursor === this.userInput.length ? (this.userInput[this.cursor - 1] === `
1466
+ ` && (this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--), true) : (this.#r(`
1467
+ `), this._cursor++, false);
1468
+ }
1469
+ constructor(t2) {
1470
+ const s = t2.initialUserInput ?? t2.initialValue;
1471
+ super({
1472
+ ...t2,
1473
+ initialUserInput: s
1474
+ }, false), s !== undefined && (this._cursor = s.length), this.#s = t2.showSubmit ?? false, this.on("key", (r, i) => {
1475
+ if (i?.name && o.has(i.name)) {
1476
+ this.#t = false, this.#i(i.name);
1477
+ return;
1478
+ }
1479
+ if (r === "\t" && this.#s) {
1480
+ this.focused = this.focused === "editor" ? "submit" : "editor";
1481
+ return;
1482
+ }
1483
+ if (i?.name !== "return") {
1484
+ if (this.#t = false, i?.name === "backspace" && this.cursor > 0) {
1485
+ this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--;
1486
+ return;
1487
+ }
1488
+ if (i?.name === "delete" && this.cursor < this.userInput.length) {
1489
+ this._setUserInput(this.userInput.slice(0, this.cursor) + this.userInput.slice(this.cursor + 1));
1490
+ return;
1491
+ }
1492
+ r && (this.#s && this.focused === "submit" && (this.focused = "editor"), this.#r(r ?? ""), this._cursor++);
1493
+ }
1494
+ }), this.on("userInput", (r) => {
1495
+ this._setValue(r);
1496
+ }), this.on("finalize", () => {
1497
+ this.value || (this.value = t2.defaultValue), this.value === undefined && (this.value = "");
1498
+ });
1499
+ }
1500
+ }
1501
+
1502
+ // ../../node_modules/.bun/@clack+prompts@1.7.0/node_modules/@clack/prompts/dist/index.mjs
1503
+ import { styleText as styleText2, stripVTControlCharacters } from "node:util";
1504
+ import process$1 from "node:process";
1505
+ var import_sisteransi2 = __toESM(require_src(), 1);
1506
+ function isUnicodeSupported() {
1507
+ if (process$1.platform !== "win32") {
1508
+ return process$1.env.TERM !== "linux";
1509
+ }
1510
+ 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";
1511
+ }
1512
+ var unicode = isUnicodeSupported();
1513
+ var isCI = () => process.env.CI === "true";
1514
+ var unicodeOr = (o2, e) => unicode ? o2 : e;
1515
+ var S_STEP_ACTIVE = unicodeOr("◆", "*");
1516
+ var S_STEP_CANCEL = unicodeOr("■", "x");
1517
+ var S_STEP_ERROR = unicodeOr("▲", "x");
1518
+ var S_STEP_SUBMIT = unicodeOr("◇", "o");
1519
+ var S_BAR_START = unicodeOr("┌", "T");
1520
+ var S_BAR = unicodeOr("│", "|");
1521
+ var S_BAR_END = unicodeOr("└", "—");
1522
+ var S_BAR_START_RIGHT = unicodeOr("┐", "T");
1523
+ var S_BAR_END_RIGHT = unicodeOr("┘", "—");
1524
+ var S_RADIO_ACTIVE = unicodeOr("●", ">");
1525
+ var S_RADIO_INACTIVE = unicodeOr("○", " ");
1526
+ var S_CHECKBOX_ACTIVE = unicodeOr("◻", "[•]");
1527
+ var S_CHECKBOX_SELECTED = unicodeOr("◼", "[+]");
1528
+ var S_CHECKBOX_INACTIVE = unicodeOr("◻", "[ ]");
1529
+ var S_PASSWORD_MASK = unicodeOr("▪", "•");
1530
+ var S_BAR_H = unicodeOr("─", "-");
1531
+ var S_CORNER_TOP_RIGHT = unicodeOr("╮", "+");
1532
+ var S_CONNECT_LEFT = unicodeOr("├", "+");
1533
+ var S_CORNER_BOTTOM_RIGHT = unicodeOr("╯", "+");
1534
+ var S_CORNER_BOTTOM_LEFT = unicodeOr("╰", "+");
1535
+ var S_CORNER_TOP_LEFT = unicodeOr("╭", "+");
1536
+ var S_INFO = unicodeOr("●", "•");
1537
+ var S_SUCCESS = unicodeOr("◆", "*");
1538
+ var S_WARN = unicodeOr("▲", "!");
1539
+ var S_ERROR = unicodeOr("■", "x");
1540
+ var MULTISELECT_INSTRUCTIONS = [
1541
+ `${styleText2("dim", "↑/↓")} to navigate`,
1542
+ `${styleText2("dim", "Space:")} select`,
1543
+ `${styleText2("dim", "Enter:")} confirm`
1544
+ ];
1545
+ var log = {
1546
+ message: (s = [], {
1547
+ symbol: e = styleText2("gray", S_BAR),
1548
+ secondarySymbol: r2 = styleText2("gray", S_BAR),
1549
+ output: m2 = process.stdout,
1550
+ spacing: l2 = 1,
1551
+ withGuide: c2
1552
+ } = {}) => {
1553
+ const t2 = [], o2 = c2 ?? settings.withGuide, f2 = o2 ? r2 : "", O = o2 ? `${e} ` : "", u3 = o2 ? `${r2} ` : "";
1554
+ for (let i = 0;i < l2; i++)
1555
+ t2.push(f2);
1556
+ const g2 = Array.isArray(s) ? s : s.split(`
1557
+ `);
1558
+ if (g2.length > 0) {
1559
+ const [i, ...y] = g2;
1560
+ i.length > 0 ? t2.push(`${O}${i}`) : t2.push(o2 ? e : "");
1561
+ for (const p2 of y)
1562
+ p2.length > 0 ? t2.push(`${u3}${p2}`) : t2.push(o2 ? r2 : "");
1563
+ }
1564
+ m2.write(`${t2.join(`
1565
+ `)}
1566
+ `);
1567
+ },
1568
+ info: (s, e) => {
1569
+ log.message(s, { ...e, symbol: styleText2("blue", S_INFO) });
1570
+ },
1571
+ success: (s, e) => {
1572
+ log.message(s, { ...e, symbol: styleText2("green", S_SUCCESS) });
1573
+ },
1574
+ step: (s, e) => {
1575
+ log.message(s, { ...e, symbol: styleText2("green", S_STEP_SUBMIT) });
1576
+ },
1577
+ warn: (s, e) => {
1578
+ log.message(s, { ...e, symbol: styleText2("yellow", S_WARN) });
1579
+ },
1580
+ warning: (s, e) => {
1581
+ log.warn(s, e);
1582
+ },
1583
+ error: (s, e) => {
1584
+ log.message(s, { ...e, symbol: styleText2("red", S_ERROR) });
1585
+ }
1586
+ };
1587
+ var intro = (o2 = "", t2) => {
1588
+ const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_START)} ` : "";
1589
+ i.write(`${e}${o2}
1590
+ `);
1591
+ };
1592
+ var outro = (o2 = "", t2) => {
1593
+ const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR)}
1594
+ ${styleText2("gray", S_BAR_END)} ` : "";
1595
+ i.write(`${e}${o2}
1596
+
1597
+ `);
1598
+ };
1599
+ var W = (l2) => styleText2("magenta", l2);
1600
+ var spinner = ({
1601
+ indicator: l2 = "dots",
1602
+ onCancel: h2,
1603
+ output: n2 = process.stdout,
1604
+ cancelMessage: G,
1605
+ errorMessage: O,
1606
+ frames: E = unicode ? ["◒", "◐", "◓", "◑"] : ["•", "o", "O", "0"],
1607
+ delay: F = unicode ? 80 : 120,
1608
+ signal: m2,
1609
+ ...I
1610
+ } = {}) => {
1611
+ const u3 = isCI();
1612
+ let M2, T3, d = false, S = false, s = "", p2, w = performance.now();
1613
+ const x = getColumns(n2), k = I?.styleFrame ?? W, g2 = (e) => {
1614
+ const r2 = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
1615
+ S = e === 1, d && (a2(r2, e), S && typeof h2 == "function" && h2());
1616
+ }, f2 = () => g2(2), i = () => g2(1), A = () => {
1617
+ process.on("uncaughtExceptionMonitor", f2), process.on("unhandledRejection", f2), process.on("SIGINT", i), process.on("SIGTERM", i), process.on("exit", g2), m2 && m2.addEventListener("abort", i);
1618
+ }, H = () => {
1619
+ process.removeListener("uncaughtExceptionMonitor", f2), process.removeListener("unhandledRejection", f2), process.removeListener("SIGINT", i), process.removeListener("SIGTERM", i), process.removeListener("exit", g2), m2 && m2.removeEventListener("abort", i);
1620
+ }, y = () => {
1621
+ if (p2 === undefined)
1622
+ return;
1623
+ u3 && n2.write(`
1624
+ `);
1625
+ const r2 = wrapAnsi(p2, x, {
1626
+ hard: true,
1627
+ trim: false
1628
+ }).split(`
1629
+ `);
1630
+ 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());
1631
+ }, C2 = (e) => e.replace(/\.+$/, ""), _2 = (e) => {
1632
+ const r2 = (performance.now() - e) / 1000, t2 = Math.floor(r2 / 60), o2 = Math.floor(r2 % 60);
1633
+ return t2 > 0 ? `[${t2}m ${o2}s]` : `[${o2}s]`;
1634
+ }, N = I.withGuide ?? settings.withGuide, P2 = (e = "") => {
1635
+ d = true, M2 = block({ output: n2 }), s = C2(e), w = performance.now(), N && n2.write(`${styleText2("gray", S_BAR)}
1636
+ `);
1637
+ let r2 = 0, t2 = 0;
1638
+ A(), T3 = setInterval(() => {
1639
+ if (u3 && s === p2)
1640
+ return;
1641
+ y(), p2 = s;
1642
+ const o2 = k(E[r2]);
1643
+ let v;
1644
+ if (u3)
1645
+ v = `${o2} ${s}...`;
1646
+ else if (l2 === "timer")
1647
+ v = `${o2} ${s} ${_2(w)}`;
1648
+ else {
1649
+ const B = ".".repeat(Math.floor(t2)).slice(0, 3);
1650
+ v = `${o2} ${s}${B}`;
1651
+ }
1652
+ const j = wrapAnsi(v, x, {
1653
+ hard: true,
1654
+ trim: false
1655
+ });
1656
+ n2.write(j), r2 = r2 + 1 < E.length ? r2 + 1 : 0, t2 = t2 < 4 ? t2 + 0.125 : 0;
1657
+ }, F);
1658
+ }, a2 = (e = "", r2 = 0, t2 = false) => {
1659
+ if (!d)
1660
+ return;
1661
+ d = false, clearInterval(T3), y();
1662
+ const o2 = r2 === 0 ? styleText2("green", S_STEP_SUBMIT) : r2 === 1 ? styleText2("red", S_STEP_CANCEL) : styleText2("red", S_STEP_ERROR);
1663
+ s = e ?? s, t2 || (l2 === "timer" ? n2.write(`${o2} ${s} ${_2(w)}
1664
+ `) : n2.write(`${o2} ${s}
1665
+ `)), H(), M2();
1666
+ };
1667
+ return {
1668
+ start: P2,
1669
+ stop: (e = "") => a2(e, 0),
1670
+ message: (e = "") => {
1671
+ s = C2(e ?? s);
1672
+ },
1673
+ cancel: (e = "") => a2(e, 1),
1674
+ error: (e = "") => a2(e, 2),
1675
+ clear: () => a2("", 0, true),
1676
+ get isCancelled() {
1677
+ return S;
1678
+ }
1679
+ };
1680
+ };
1681
+ var u3 = {
1682
+ light: unicodeOr("─", "-"),
1683
+ heavy: unicodeOr("━", "="),
1684
+ block: unicodeOr("█", "#")
1685
+ };
1686
+ var SELECT_INSTRUCTIONS = [
1687
+ `${styleText2("dim", "↑/↓")} to navigate`,
1688
+ `${styleText2("dim", "Enter:")} confirm`
1689
+ ];
1690
+ var i = `${styleText2("gray", S_BAR)} `;
1691
+
1692
+ // ../adjacent-cli/dist/ui.js
1693
+ function intro2(message) {
1694
+ if (process.stdout.isTTY)
1695
+ intro(message);
1696
+ else
1697
+ console.log(message);
1698
+ }
1699
+ function step(message) {
1700
+ log.step(message);
1701
+ }
1702
+ function success(message) {
1703
+ log.success(message);
1704
+ }
1705
+ function outro2(message) {
1706
+ if (process.stdout.isTTY)
1707
+ outro(message);
1708
+ else
1709
+ console.log(message);
1710
+ }
1711
+ async function task(message, operation) {
1712
+ if (!process.stdout.isTTY) {
1713
+ step(message);
1714
+ return operation();
1715
+ }
1716
+ const progress = spinner();
1717
+ progress.start(message);
1718
+ try {
1719
+ const result = await operation();
1720
+ progress.stop(message);
1721
+ return result;
1722
+ } catch (error) {
1723
+ progress.stop(`Failed: ${message}`);
1724
+ throw error;
1725
+ }
1726
+ }
1727
+
1728
+ // ../adjacent-cli/dist/reporter.js
1729
+ var TERMINAL_REPORTER = { intro: intro2, outro: outro2, step, success, task };
1730
+
1731
+ // ../adjacent-cli/dist/rewrite.js
1732
+ var ADJACENT_NEXT = "adjacent-next";
1733
+ function hasImportFrom(source, module) {
1734
+ return new RegExp(`from\\s+["']${module.replace("/", "\\/")}["']`).test(source);
1735
+ }
1736
+ function addImport(source, statement) {
1737
+ if (source.includes(statement))
1738
+ return source;
1739
+ const imports = [...source.matchAll(/^import\s[^\n]*;[ \t]*$/gm)];
1740
+ const last = imports.at(-1);
1741
+ if (last === undefined || last.index === undefined) {
1742
+ return `${statement}
1743
+ ${source}`;
1744
+ }
1745
+ const end = last.index + last[0].length;
1746
+ return `${source.slice(0, end)}
1747
+ ${statement}${source.slice(end)}`;
1748
+ }
1749
+ var NEXT_CONFIG_OPTIONS = `{
1750
+ connectivityRecovery: true,
1751
+ partialPrefetching: true,
1752
+ }`;
1753
+ function createNextConfig() {
1754
+ return `import { withAdjacent } from "${ADJACENT_NEXT}";
1755
+
1756
+ export default withAdjacent(${NEXT_CONFIG_OPTIONS});
1757
+ `;
1758
+ }
1759
+ function wrapNextConfig(source) {
1760
+ if (source.includes("withAdjacent"))
1761
+ return { kind: "unchanged" };
1762
+ const identifier = /^export\s+default\s+([A-Za-z_$][\w$]*)\s*;?\s*$/m.exec(source);
1763
+ if (identifier?.[1]) {
1764
+ const wrapped = source.replace(identifier[0], `export default withAdjacent({
1765
+ connectivityRecovery: true,
1766
+ partialPrefetching: true,
1767
+ ${identifier[1] === "nextConfig" ? "nextConfig" : `nextConfig: ${identifier[1]}`},
1768
+ });`);
1769
+ return {
1770
+ contents: addImport(wrapped, `import { withAdjacent } from "${ADJACENT_NEXT}";`),
1771
+ kind: "rewritten"
1772
+ };
1773
+ }
1774
+ const inline = /^export\s+default\s+(\{[\s\S]*\})\s*(?:as\s+\w+\s*)?;?\s*$/m.exec(source);
1775
+ if (inline?.[1]) {
1776
+ const wrapped = source.replace(inline[0], `export default withAdjacent({
1777
+ connectivityRecovery: true,
1778
+ partialPrefetching: true,
1779
+ nextConfig: ${inline[1]},
1780
+ });`);
1781
+ return {
1782
+ contents: addImport(wrapped, `import { withAdjacent } from "${ADJACENT_NEXT}";`),
1783
+ kind: "rewritten"
1784
+ };
1785
+ }
1786
+ return {
1787
+ instruction: `Wrap the Next.js config so Adjacent can configure development origins, headers, and package transpilation:
1788
+
1789
+ ` + ` import { withAdjacent } from "${ADJACENT_NEXT}";
1790
+
1791
+ ` + ` export default withAdjacent({
1792
+ ` + ` connectivityRecovery: true,
1793
+ ` + ` partialPrefetching: true,
1794
+ ` + ` nextConfig: yourExistingConfig,
1795
+ ` + ` });`,
1796
+ kind: "manual"
1797
+ };
1798
+ }
1799
+ var LAYOUT_INSTRUCTION = (configImportPath) => `Wrap the root layout so Adjacent can supply metadata and inject its browser runtime:
1800
+
1801
+ ` + ` import { createAdjacent, withAdjacentLayout } from "${ADJACENT_NEXT}";
1802
+ ` + ` import config from "${configImportPath}";
1803
+
1804
+ ` + ` const adjacent = createAdjacent(config);
1805
+ ` + ` export const { metadata, viewport } = adjacent;
1806
+
1807
+ ` + ` function RootLayout({ children }) { /* your existing layout */ }
1808
+
1809
+ ` + ` export default withAdjacentLayout(adjacent)(RootLayout);`;
1810
+ var METADATA_TYPE_IMPORT = /^import\s+type\s*\{\s*Metadata\s*\}\s*from\s*"next";\n/m;
1811
+ var SCAFFOLDED_METADATA = /^export\s+const\s+metadata(?:\s*:\s*Metadata)?\s*=\s*\{[^{}]*\};?\n+/m;
1812
+ function dropScaffoldedMetadata(source) {
1813
+ const without = source.replace(SCAFFOLDED_METADATA, "");
1814
+ if (without === source || /\bMetadata\b/.test(without.replace(METADATA_TYPE_IMPORT, ""))) {
1815
+ return without;
1816
+ }
1817
+ return without.replace(METADATA_TYPE_IMPORT, "");
1818
+ }
1819
+ function wrapRootLayout(source, { configImportPath, scaffolded = false }) {
1820
+ if (source.includes("withAdjacentLayout"))
1821
+ return { kind: "unchanged" };
1822
+ const defaultExport = /^export\s+default\s+(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(/m.exec(source);
1823
+ if (!defaultExport?.[1]) {
1824
+ return { instruction: LAYOUT_INSTRUCTION(configImportPath), kind: "manual" };
1825
+ }
1826
+ const layoutName = defaultExport[1];
1827
+ let contents = scaffolded ? dropScaffoldedMetadata(source) : source;
1828
+ const metadataExport = /^export\s+const\s+metadata(\s*:\s*Metadata)?\s*=/m.exec(contents);
1829
+ const hasOwnMetadata = metadataExport !== null;
1830
+ if (metadataExport) {
1831
+ contents = contents.replace(metadataExport[0], `const applicationMetadata${metadataExport[1] ?? ""} =`);
1832
+ }
1833
+ if (/^export\s+const\s+viewport\b/m.test(contents)) {
1834
+ return { instruction: LAYOUT_INSTRUCTION(configImportPath), kind: "manual" };
1835
+ }
1836
+ contents = contents.replace(defaultExport[0], defaultExport[0].replace(/^export\s+default\s+/, ""));
1837
+ contents = addImport(contents, `import { createAdjacent, withAdjacentLayout } from "${ADJACENT_NEXT}";`);
1838
+ if (!hasImportFrom(contents, configImportPath)) {
1839
+ contents = addImport(contents, `import config from "${configImportPath}";`);
1840
+ }
1841
+ const creation = hasOwnMetadata ? `const adjacent = createAdjacent(config, { metadata: applicationMetadata });` : `const adjacent = createAdjacent(config);`;
1842
+ return {
1843
+ contents: `${contents.trimEnd()}
1844
+
1845
+ ${creation}
1846
+
1847
+ export const { metadata, viewport } = adjacent;
1848
+
1849
+ ` + `export default withAdjacentLayout(adjacent)(${layoutName});
1850
+ `,
1851
+ kind: "rewritten"
1852
+ };
1853
+ }
1854
+ var STYLE_START = "/* adjacent:start */";
1855
+ var STYLE_END = "/* adjacent:end */";
1856
+ var ADJACENT_TOKENS = `:root {
1857
+ --primary: #171717;
1858
+ --primary-foreground: #ffffff;
1859
+ --secondary: #f4f4f5;
1860
+ --secondary-foreground: #171717;
1861
+ --accent: #f4f4f5;
1862
+ --accent-foreground: #171717;
1863
+ --muted: #f4f4f5;
1864
+ --muted-foreground: #71717a;
1865
+ --destructive: #b3261e;
1866
+ --border: #e4e4e7;
1867
+ --ring: #171717;
1868
+
1869
+ /* The navigation rail is a sidebar, and reads these from 768px up. */
1870
+ --sidebar: #fafafa;
1871
+ --sidebar-foreground: #171717;
1872
+ --sidebar-accent: #e4e4e7;
1873
+ --sidebar-accent-foreground: #171717;
1874
+
1875
+ --radius: 0.625rem;
1876
+ --radius-sm: 0.375rem;
1877
+ --radius-lg: 0.75rem;
1878
+ --radius-full: 9999px;
1879
+ }
1880
+
1881
+ @media (prefers-color-scheme: dark) {
1882
+ :root {
1883
+ --primary: #fafafa;
1884
+ --primary-foreground: #0c0c0e;
1885
+ --secondary: #27272a;
1886
+ --secondary-foreground: #fafafa;
1887
+ --accent: #27272a;
1888
+ --accent-foreground: #fafafa;
1889
+ --muted: #27272a;
1890
+ --muted-foreground: #a1a1aa;
1891
+ --destructive: #f2b8b5;
1892
+ --border: #27272a;
1893
+ --ring: #fafafa;
1894
+
1895
+ --sidebar: #17171a;
1896
+ --sidebar-foreground: #fafafa;
1897
+ --sidebar-accent: #27272a;
1898
+ --sidebar-accent-foreground: #fafafa;
1899
+ }
1900
+ }`;
1901
+ var TAILWIND_THEME = `@theme inline {
1902
+ --color-primary: var(--primary);
1903
+ --color-primary-foreground: var(--primary-foreground);
1904
+ --color-secondary: var(--secondary);
1905
+ --color-secondary-foreground: var(--secondary-foreground);
1906
+ --color-accent: var(--accent);
1907
+ --color-accent-foreground: var(--accent-foreground);
1908
+ --color-muted: var(--muted);
1909
+ --color-muted-foreground: var(--muted-foreground);
1910
+ --color-destructive: var(--destructive);
1911
+ --color-border: var(--border);
1912
+ --color-ring: var(--ring);
1913
+ --color-sidebar: var(--sidebar);
1914
+ --color-sidebar-foreground: var(--sidebar-foreground);
1915
+ --color-sidebar-accent: var(--sidebar-accent);
1916
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
1917
+ }`;
1918
+ var SHELL_STYLES = `body {
1919
+ /* Keeps iOS from rubber-banding the document out from under fixed chrome. */
1920
+ overscroll-behavior-y: none;
1921
+ }
1922
+
1923
+ html {
1924
+ /*
1925
+ * Anything scrolled to stops above the navigation rather than under it. The
1926
+ * shell already reserves the room; this covers an anchor jump, a focused
1927
+ * field, and scrollIntoView, which would otherwise ignore it. The same at the
1928
+ * top, where a sticky header would otherwise cover what was scrolled to.
1929
+ */
1930
+ scroll-padding-block-start: var(--adj-header-inset-block-start, 0px);
1931
+ scroll-padding-block-end: var(--adj-navigation-inset-block-end, 0px);
1932
+ }
1933
+
1934
+ /*
1935
+ * An installed app should not show a browser's scrollbar down its edge. Keyed
1936
+ * on a coarse pointer rather than a narrow width, so a touch device is what
1937
+ * this hides for and a narrow desktop window keeps the scrollbar it needs.
1938
+ * Scrolling itself is untouched: the bar goes, the page still moves.
1939
+ */
1940
+ @media (pointer: coarse) {
1941
+ html {
1942
+ /* The standard property, and the one that does the work. */
1943
+ scrollbar-width: none;
1944
+ }
1945
+
1946
+ /*
1947
+ * For iOS Safari before 18.2 and Chrome before 121, which is a real share of
1948
+ * phones. Delete this once the floor is above both and scrollbar-width is
1949
+ * enough on its own.
1950
+ */
1951
+ html::-webkit-scrollbar,
1952
+ body::-webkit-scrollbar {
1953
+ display: none;
1954
+ }
1955
+ }`;
1956
+ function injectAdjacentStyles(source, { tailwind }) {
1957
+ const block2 = [
1958
+ STYLE_START,
1959
+ "/* Adjacent components read these tokens. Edit them to restyle the app. */",
1960
+ ADJACENT_TOKENS,
1961
+ ...tailwind ? [TAILWIND_THEME] : [],
1962
+ SHELL_STYLES,
1963
+ STYLE_END
1964
+ ].join(`
1965
+
1966
+ `);
1967
+ const start = source.indexOf(STYLE_START);
1968
+ if (start !== -1) {
1969
+ const end = source.indexOf(STYLE_END);
1970
+ if (end === -1) {
1971
+ return {
1972
+ instruction: `The Adjacent block in this stylesheet has a ${STYLE_START} marker but no ` + `${STYLE_END} marker, so it cannot be replaced safely. Close the block, or ` + `delete both markers and run this again.`,
1973
+ kind: "manual"
1974
+ };
1975
+ }
1976
+ const replaced = source.slice(0, start) + block2 + source.slice(end + STYLE_END.length);
1977
+ return replaced === source ? { kind: "unchanged" } : { contents: replaced, kind: "rewritten" };
1978
+ }
1979
+ return { contents: `${source.trimEnd()}
1980
+
1981
+ ${block2}
1982
+ `, kind: "rewritten" };
1983
+ }
1984
+
1985
+ // ../adjacent-cli/dist/template.js
1986
+ import { readdir as readdir2, readFile as readFile2 } from "node:fs/promises";
1987
+ import { join as join3 } from "node:path";
1988
+ var TEXT_EXTENSIONS = new Set([".css", ".json", ".md", ".svg", ".ts", ".tsx"]);
1989
+ var FILENAME_OVERRIDES = {
1990
+ _gitignore: ".gitignore"
1991
+ };
1992
+ var PLACEHOLDER = /\{\{\s*([a-zA-Z][a-zA-Z0-9]*)\s*\}\}/g;
1993
+ var IGNORED_ENTRIES2 = new Set([".DS_Store"]);
1994
+ function isTextTemplate(path) {
1995
+ const dot = path.lastIndexOf(".");
1996
+ return dot === -1 ? false : TEXT_EXTENSIONS.has(path.slice(dot));
1997
+ }
1998
+ function applyTemplateName(name) {
1999
+ return FILENAME_OVERRIDES[name] ?? name;
2000
+ }
2001
+ function renderTemplate(source, values) {
2002
+ return source.replace(PLACEHOLDER, (_match, key) => {
2003
+ const value = values[key];
2004
+ if (value === undefined) {
2005
+ throw new Error(`The bundled template referenced an unknown value: {{${key}}}`);
2006
+ }
2007
+ return value;
2008
+ });
2009
+ }
2010
+ async function collectTemplateEntries(templateRoot, base = "") {
2011
+ const entries = await readdir2(join3(templateRoot, base), { withFileTypes: true });
2012
+ const collected = [];
2013
+ for (const entry of entries.sort((a2, b2) => a2.name.localeCompare(b2.name))) {
2014
+ if (IGNORED_ENTRIES2.has(entry.name))
2015
+ continue;
2016
+ const sourcePath = base === "" ? entry.name : `${base}/${entry.name}`;
2017
+ if (entry.isDirectory()) {
2018
+ collected.push(...await collectTemplateEntries(templateRoot, sourcePath));
2019
+ continue;
2020
+ }
2021
+ collected.push({ path: sourcePath });
2022
+ }
2023
+ return collected;
2024
+ }
2025
+ function toDestinationPath(templateRelativePath) {
2026
+ return templateRelativePath.split("/").map((segment) => applyTemplateName(segment)).join("/");
2027
+ }
2028
+ async function renderTemplateTree({ relocate, sink, templateRoot, values }) {
2029
+ const entries = await collectTemplateEntries(templateRoot);
2030
+ const written = [];
2031
+ for (const entry of entries) {
2032
+ const source = join3(templateRoot, ...entry.path.split("/"));
2033
+ const mapped = toDestinationPath(entry.path);
2034
+ const destinationPath = relocate ? relocate(mapped) : mapped;
2035
+ const contents = isTextTemplate(entry.path) ? renderTemplate(await readFile2(source, "utf8"), values) : await readFile2(source);
2036
+ if (await sink(destinationPath, contents))
2037
+ written.push(destinationPath);
2038
+ }
2039
+ return written;
2040
+ }
2041
+
2042
+ // ../adjacent-cli/dist/survey.js
2043
+ import { readFile as readFile3, stat as stat4 } from "node:fs/promises";
2044
+ import { join as join4 } from "node:path";
2045
+
2046
+ // ../adjacent-cli/dist/project-name.js
2047
+ var PACKAGE_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
2048
+ var SHORT_NAME_LIMIT = 12;
2049
+ var RESERVED_NAMES = new Set(["favicon.ico", "node_modules"]);
2050
+ var MIN_LENGTH = 2;
2051
+ var MAX_LENGTH = 214;
2052
+ function fail(name, reason) {
2053
+ throw new Error(`Invalid project name "${name}": ${reason}`);
2054
+ }
2055
+ function assertProjectName(name) {
2056
+ if (name.trim().length === 0) {
2057
+ throw new Error("A project name is required, for example: adj create my-app");
2058
+ }
2059
+ const value = name.trim();
2060
+ if (value.includes("/") || value.includes("\\")) {
2061
+ fail(value, "a name cannot contain a path separator. Use --directory to choose where the project is written.");
2062
+ }
2063
+ if (value === "." || value === ".." || value.startsWith(".")) {
2064
+ fail(value, "a name cannot begin with a dot.");
2065
+ }
2066
+ if (value.length < MIN_LENGTH) {
2067
+ fail(value, `a name has to be at least ${MIN_LENGTH} characters, because a web app manifest rejects a shorter one.`);
2068
+ }
2069
+ if (value.length > MAX_LENGTH) {
2070
+ fail(value, `a name cannot be longer than ${MAX_LENGTH} characters.`);
2071
+ }
2072
+ if (RESERVED_NAMES.has(value)) {
2073
+ fail(value, "that name is reserved by npm.");
2074
+ }
2075
+ if (value !== value.toLowerCase()) {
2076
+ fail(value, `a name must be lowercase. Try "${value.toLowerCase()}".`);
2077
+ }
2078
+ if (!PACKAGE_NAME.test(value)) {
2079
+ fail(value, "a name must be lowercase letters and digits separated by single hyphens, for example: my-app.");
2080
+ }
2081
+ return value;
2082
+ }
2083
+ function toTitleCase(word) {
2084
+ return word.charAt(0).toUpperCase() + word.slice(1);
2085
+ }
2086
+ function deriveAppName(packageName) {
2087
+ return packageName.split("-").map(toTitleCase).join(" ");
2088
+ }
2089
+ function deriveShortName(appName) {
2090
+ if (appName.length <= SHORT_NAME_LIMIT)
2091
+ return appName;
2092
+ const [firstWord = appName] = appName.split(" ");
2093
+ return firstWord.slice(0, SHORT_NAME_LIMIT);
2094
+ }
2095
+ function deriveProjectIdentity(name) {
2096
+ const packageName = assertProjectName(name);
2097
+ const appName = deriveAppName(packageName);
2098
+ return {
2099
+ appName,
2100
+ packageName,
2101
+ shortName: deriveShortName(appName),
2102
+ slug: packageName
2103
+ };
2104
+ }
2105
+
2106
+ // ../adjacent-cli/dist/survey.js
2107
+ var APP_DIRECTORIES = ["app", join4("src", "app")];
2108
+ var LAYOUT_NAMES = ["layout.tsx", "layout.jsx", "layout.ts", "layout.js"];
2109
+ var NEXT_CONFIG_NAMES = [
2110
+ "next.config.ts",
2111
+ "next.config.mjs",
2112
+ "next.config.js",
2113
+ "next.config.mts"
2114
+ ];
2115
+ var STYLESHEET_NAMES = ["globals.css", "global.css", "index.css"];
2116
+ async function exists2(path) {
2117
+ return stat4(path).then(() => true, () => false);
2118
+ }
2119
+ async function firstExisting(root, candidates) {
2120
+ for (const candidate of candidates) {
2121
+ if (await exists2(join4(root, candidate)))
2122
+ return candidate;
2123
+ }
2124
+ return;
2125
+ }
2126
+ function readDependencyNames(manifest) {
2127
+ const names = new Set;
2128
+ for (const field of ["dependencies", "devDependencies"]) {
2129
+ const section = manifest[field];
2130
+ if (typeof section === "object" && section !== null) {
2131
+ Object.keys(section).forEach((name) => names.add(name));
2132
+ }
2133
+ }
2134
+ return names;
2135
+ }
2136
+ function toProjectName(packageName, fallback) {
2137
+ const raw = typeof packageName === "string" ? packageName : "";
2138
+ const withoutScope = raw.includes("/") ? raw.split("/").pop() ?? "" : raw;
2139
+ const cleaned = withoutScope.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").replace(/-{2,}/g, "-");
2140
+ return cleaned.length > 0 ? cleaned : fallback;
2141
+ }
2142
+
2143
+ class NotANextApplicationError extends Error {
2144
+ }
2145
+ async function surveyProject(root) {
2146
+ const manifestPath = join4(root, "package.json");
2147
+ const rawManifest = await readFile3(manifestPath, "utf8").catch(() => {
2148
+ return;
2149
+ });
2150
+ if (rawManifest === undefined) {
2151
+ throw new NotANextApplicationError(`No package.json found in ${root}. Run this inside a Next.js application, or create one with: adj create my-app`);
2152
+ }
2153
+ let packageJson;
2154
+ try {
2155
+ packageJson = JSON.parse(rawManifest);
2156
+ } catch (error) {
2157
+ const detail = error instanceof Error ? error.message : String(error);
2158
+ throw new NotANextApplicationError(`Could not read ${manifestPath}: ${detail}`);
2159
+ }
2160
+ const dependencies = readDependencyNames(packageJson);
2161
+ if (!dependencies.has("next")) {
2162
+ throw new NotANextApplicationError(`${root} does not depend on Next.js. Adjacent adds to a Next.js application; create one with: adj create my-app`);
2163
+ }
2164
+ const appDirectory = await firstExisting(root, APP_DIRECTORIES);
2165
+ if (appDirectory === undefined) {
2166
+ throw new NotANextApplicationError(`No App Router directory found in ${root}. Adjacent needs an app/ or src/app/ directory; the Pages Router is not supported.`);
2167
+ }
2168
+ const layoutFile = await firstExisting(root, LAYOUT_NAMES.map((name) => join4(appDirectory, name)));
2169
+ if (layoutFile === undefined) {
2170
+ throw new NotANextApplicationError(`No root layout found in ${join4(root, appDirectory)}. Adjacent wraps the root layout, so one has to exist.`);
2171
+ }
2172
+ const globalsCss = await firstExisting(root, STYLESHEET_NAMES.map((name) => join4(appDirectory, name)));
2173
+ return {
2174
+ appDirectory,
2175
+ ...globalsCss === undefined ? null : { globalsCss },
2176
+ hasAdjacentConfig: await exists2(join4(root, "app.config.ts")),
2177
+ hasTailwind: dependencies.has("tailwindcss") || dependencies.has("@tailwindcss/postcss"),
2178
+ identity: deriveProjectIdentity(toProjectName(packageJson.name, "adjacent-app")),
2179
+ layoutFile,
2180
+ ...await firstExisting(root, NEXT_CONFIG_NAMES).then((file) => file === undefined ? null : { nextConfigFile: file }),
2181
+ packageJson,
2182
+ root,
2183
+ typescript: layoutFile.endsWith(".tsx") || layoutFile.endsWith(".ts")
2184
+ };
2185
+ }
2186
+
2187
+ // ../adjacent-cli/dist/init.js
2188
+ function moduleDirectory() {
2189
+ return dirname3(fileURLToPath2(import.meta.url));
2190
+ }
2191
+ function defaultTemplatesRoot(from = moduleDirectory()) {
2192
+ return resolve3(from, "..", "templates");
2193
+ }
2194
+ async function findWorkspacePackagesRoot(from = moduleDirectory()) {
2195
+ let current = resolve3(from);
2196
+ while (true) {
2197
+ const candidate = join5(current, "packages", "adjacent-core", "package.json");
2198
+ const manifest = await readFile4(candidate, "utf8").catch(() => {
2199
+ return;
2200
+ });
2201
+ if (manifest !== undefined) {
2202
+ const parsed = JSON.parse(manifest);
2203
+ if (parsed.name === "adjacent-core")
2204
+ return join5(current, "packages");
2205
+ }
2206
+ const parent = dirname3(current);
2207
+ if (parent === current)
2208
+ return;
2209
+ current = parent;
2210
+ }
2211
+ }
2212
+ async function isWorkspaceMember(workspaceRoot, projectRoot) {
2213
+ const raw = await readFile4(join5(workspaceRoot, "package.json"), "utf8").catch(() => {
2214
+ return;
2215
+ });
2216
+ if (raw === undefined)
2217
+ return false;
2218
+ let globs = [];
2219
+ try {
2220
+ const manifest = JSON.parse(raw);
2221
+ if (Array.isArray(manifest.workspaces)) {
2222
+ globs = manifest.workspaces.filter((glob) => typeof glob === "string");
2223
+ }
2224
+ } catch {
2225
+ return false;
2226
+ }
2227
+ const location = relative3(workspaceRoot, projectRoot).split(sep3).join("/");
2228
+ if (location === "" || location.startsWith(".."))
2229
+ return false;
2230
+ return globs.some((glob) => matchesWorkspaceGlob(location, glob));
2231
+ }
2232
+ function addAdjacentDependencies(manifest, dependencies) {
2233
+ const existing = typeof manifest.dependencies === "object" && manifest.dependencies !== null ? manifest.dependencies : {};
2234
+ const scripts = typeof manifest.scripts === "object" && manifest.scripts !== null ? manifest.scripts : {};
2235
+ const merged = {
2236
+ ...manifest,
2237
+ dependencies: Object.fromEntries(Object.entries({ ...existing, ...dependencies.dependencies }).sort(([a2], [b2]) => a2.localeCompare(b2))),
2238
+ scripts: {
2239
+ ...scripts,
2240
+ ...scripts.typecheck ? null : { typecheck: "next typegen && tsc --noEmit" }
2241
+ }
2242
+ };
2243
+ if (dependencies.overrides) {
2244
+ const configured = typeof manifest.overrides === "object" && manifest.overrides !== null ? manifest.overrides : {};
2245
+ merged.overrides = { ...configured, ...dependencies.overrides };
2246
+ }
2247
+ return merged;
2248
+ }
2249
+ async function installDependencies(root, options = {}) {
2250
+ const manager = await resolvePackageManager({ projectRoot: root });
2251
+ const { args, command } = manager.install(options);
2252
+ await runInheritedCommand(command, args, { cwd: root }).catch((error) => {
2253
+ const detail = error instanceof Error ? error.message : String(error);
2254
+ throw new Error(`Could not install dependencies in ${root}: ${detail}
2255
+ ` + `Adjacent was added to the project. Install by hand with: ${command} ${args.join(" ")}`);
2256
+ });
2257
+ }
2258
+ async function applyRewrite({ edits, file, manual, outcome }) {
2259
+ if (outcome.kind === "rewritten") {
2260
+ await edits.rewriteFile(file, outcome.contents);
2261
+ return;
2262
+ }
2263
+ if (outcome.kind === "manual") {
2264
+ manual.push({ file, instruction: outcome.instruction });
2265
+ }
2266
+ }
2267
+ async function runInit(options, ports = {}) {
2268
+ const report = ports.reporter ?? TERMINAL_REPORTER;
2269
+ const root = resolve3(options.projectRoot);
2270
+ const survey = await surveyProject(root);
2271
+ const templatesRoot = ports.templatesRoot ?? defaultTemplatesRoot();
2272
+ const manager = await resolvePackageManager({ projectRoot: root });
2273
+ const packagesRoot = await findWorkspacePackagesRoot();
2274
+ const dependencies = ports.dependencies ?? resolveAdjacentDependencies({
2275
+ ...packagesRoot === undefined ? null : { packagesRoot },
2276
+ projectRoot: root,
2277
+ workspaceMember: packagesRoot !== undefined && await isWorkspaceMember(dirname3(packagesRoot), root)
2278
+ });
2279
+ const installOptions = { isolated: dependencies.pathLinked };
2280
+ const edits = createProjectEdits(root);
2281
+ const manual = [];
2282
+ const sourceRoot = dirname3(survey.appDirectory);
2283
+ const relocate = (path) => sourceRoot === "." ? path : join5(sourceRoot, path);
2284
+ try {
2285
+ const configFromApp = sourceRoot === "." ? "../app.config" : "../../app.config";
2286
+ const values = {
2287
+ appName: survey.identity.appName,
2288
+ configFromApp,
2289
+ configFromRoute: `../${configFromApp}`,
2290
+ packageName: survey.identity.packageName,
2291
+ shortName: survey.identity.shortName,
2292
+ slug: survey.identity.slug
2293
+ };
2294
+ const injected = await renderTemplateTree({
2295
+ relocate: (path) => path === "app.config.ts" || path.startsWith("public/") ? path : relocate(path),
2296
+ sink: (path, contents) => edits.addFile(path, contents),
2297
+ templateRoot: join5(templatesRoot, "adjacent"),
2298
+ values
2299
+ });
2300
+ const navigationFile = relocate("components/navigation.tsx");
2301
+ if (!injected.includes(navigationFile)) {
2302
+ manual.push({
2303
+ file: navigationFile,
2304
+ instruction: "A file of this name already exists, so Adjacent's navigation was " + `not written and nothing here imports it yet.
2305
+
2306
+ ` + "Either rename the existing file and run `adj init` again, or build " + "the navigation yourself with `Tabs` and `Tab` from `adjacent-ui`, " + "and render it through the `navigation` prop of `NavigationShell`."
2307
+ });
2308
+ }
2309
+ if (options.scaffold) {
2310
+ await renderTemplateTree({
2311
+ relocate,
2312
+ sink: (path, contents) => edits.addFile(path, contents),
2313
+ templateRoot: join5(templatesRoot, "starter"),
2314
+ values
2315
+ });
2316
+ await edits.removeFile(join5(survey.appDirectory, "page.tsx"));
2317
+ }
2318
+ const nextConfigFile = survey.nextConfigFile ?? "next.config.ts";
2319
+ const nextConfigSource = await edits.readFile(nextConfigFile);
2320
+ if (nextConfigSource === undefined) {
2321
+ await edits.addFile(nextConfigFile, createNextConfig());
2322
+ } else {
2323
+ await applyRewrite({
2324
+ edits,
2325
+ file: nextConfigFile,
2326
+ manual,
2327
+ outcome: wrapNextConfig(nextConfigSource)
2328
+ });
2329
+ }
2330
+ const layoutSource = await edits.readFile(survey.layoutFile);
2331
+ if (layoutSource !== undefined) {
2332
+ await applyRewrite({
2333
+ edits,
2334
+ file: survey.layoutFile,
2335
+ manual,
2336
+ outcome: wrapRootLayout(layoutSource, {
2337
+ configImportPath: sourceRoot === "." ? "../app.config" : "../../app.config",
2338
+ scaffolded: options.scaffold === true
2339
+ })
2340
+ });
2341
+ }
2342
+ if (survey.globalsCss) {
2343
+ const styles = await edits.readFile(survey.globalsCss);
2344
+ if (styles !== undefined) {
2345
+ await applyRewrite({
2346
+ edits,
2347
+ file: survey.globalsCss,
2348
+ manual,
2349
+ outcome: injectAdjacentStyles(styles, { tailwind: survey.hasTailwind })
2350
+ });
2351
+ }
2352
+ }
2353
+ await edits.rewriteFile("package.json", `${JSON.stringify(addAdjacentDependencies(survey.packageJson, dependencies), null, 2)}
2354
+ `);
2355
+ } catch (error) {
2356
+ await edits.rollback();
2357
+ const detail = error instanceof Error ? error.message : String(error);
2358
+ throw new Error(`Could not add Adjacent to ${root}: ${detail}`);
2359
+ }
2360
+ const summary = edits.summary();
2361
+ report.success(`Added ${summary.added.length} file${summary.added.length === 1 ? "" : "s"} and updated ${summary.rewritten.length}`);
2362
+ let installed = false;
2363
+ if (options.install) {
2364
+ report.step("Installing dependencies with Bun");
2365
+ await (ports.install ?? installDependencies)(root, installOptions);
2366
+ installed = true;
2367
+ report.success("Installed dependencies");
2368
+ }
2369
+ for (const step2 of manual) {
2370
+ report.step(`${step2.file} needs one edit by hand:
2371
+
2372
+ ${step2.instruction}
2373
+ `);
2374
+ }
2375
+ return {
2376
+ added: summary.added,
2377
+ installed,
2378
+ installOptions,
2379
+ manual,
2380
+ packageManager: manager,
2381
+ rewritten: summary.rewritten,
2382
+ root,
2383
+ survey
2384
+ };
2385
+ }
2386
+
2387
+ // ../adjacent-cli/dist/create.js
2388
+ function createNextAppArguments(destination, manager) {
2389
+ return [
2390
+ destination,
2391
+ "--app",
2392
+ "--empty",
2393
+ "--import-alias",
2394
+ "@/*",
2395
+ "--no-eslint",
2396
+ "--no-src-dir",
2397
+ "--tailwind",
2398
+ "--typescript",
2399
+ manager.scaffoldFlag,
2400
+ "--disable-git",
2401
+ "--yes"
2402
+ ];
2403
+ }
2404
+ async function scaffoldNextApp({ destination }) {
2405
+ const manager = await resolvePackageManager();
2406
+ const { args, command } = manager.exec("create-next-app@latest", createNextAppArguments(destination, manager));
2407
+ await runInheritedCommand(command, args).catch((error) => {
2408
+ const detail = error instanceof Error ? error.message : String(error);
2409
+ throw new Error(`Could not create the Next.js application at ${destination}: ${detail}`);
2410
+ });
2411
+ }
2412
+ function describeNextSteps({ cwd, destination, installOptions, installed, packageManager }) {
2413
+ const relativePath = relative4(cwd, destination);
2414
+ const target = relativePath === "" || relativePath.startsWith("..") ? destination : relativePath;
2415
+ const install = packageManager.install(installOptions);
2416
+ const dev = packageManager.run("dev");
2417
+ return [
2418
+ `cd ${target}`,
2419
+ ...installed ? [] : [`${install.command} ${install.args.join(" ")}`],
2420
+ `${dev.command} ${dev.args.join(" ")}`,
2421
+ "adj dev --android"
2422
+ ];
2423
+ }
2424
+ async function runCreate(options, ports = {}) {
2425
+ const report = ports.reporter ?? TERMINAL_REPORTER;
2426
+ const cwd = options.cwd ?? process.cwd();
2427
+ const identity = deriveProjectIdentity(options.projectName);
2428
+ const destination = resolveDestination(identity.packageName, options.directory, cwd);
2429
+ report.intro("Adjacent project");
2430
+ await assertDestinationUsable(destination);
2431
+ report.step("Creating a Next.js application");
2432
+ await (ports.createNextApp ?? scaffoldNextApp)({
2433
+ destination,
2434
+ projectName: identity.packageName
2435
+ });
2436
+ const result = await runInit({ install: options.install, projectRoot: destination, scaffold: true }, { ...ports, reporter: report });
2437
+ const steps = describeNextSteps({
2438
+ cwd,
2439
+ destination,
2440
+ installOptions: result.installOptions,
2441
+ installed: result.installed,
2442
+ packageManager: result.packageManager
2443
+ });
2444
+ report.step(`Next steps:
2445
+ ${steps.map((command) => ` ${command}`).join(`
2446
+ `)}`);
2447
+ report.outro(`${result.survey.identity.appName} is ready.`);
2448
+ return { ...result, destination: resolve4(destination) };
2449
+ }
2450
+ // ../adjacent-cli/dist/dev-channel.js
2451
+ import { join as join6 } from "node:path";
2452
+ var STATE_FILE = join6(".adjacent", "dev.json");
2453
+ // ../adjacent-cli/dist/checks.js
2454
+ var PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
2455
+ // ../adjacent-cli/dist/shutdown.js
2456
+ var lifecycle = process;
2457
+ // src/index.ts
2458
+ var USAGE = `Create an Adjacent application.
2459
+
2460
+ npm create adjacent@latest my-app
2461
+ npm create adjacent@latest my-app -- --directory apps/my-app --no-install
2462
+
2463
+ Options
2464
+ --directory <path> Write the project here instead of ./<project-name>
2465
+ --no-install Skip installing dependencies`;
2466
+ function parseArguments(argv) {
2467
+ if (argv.length === 0 || argv.includes("--help") || argv.includes("-h")) {
2468
+ return { help: true, install: true };
2469
+ }
2470
+ const directoryIndex = argv.indexOf("--directory");
2471
+ const directory = directoryIndex === -1 ? undefined : argv[directoryIndex + 1];
2472
+ const directoryValueIndex = directoryIndex === -1 ? -1 : directoryIndex + 1;
2473
+ const projectName = argv.find((argument, index) => !argument.startsWith("-") && index !== directoryValueIndex);
2474
+ return {
2475
+ ...directory === undefined ? null : { directory },
2476
+ help: false,
2477
+ install: !argv.includes("--no-install"),
2478
+ ...projectName === undefined ? null : { projectName }
2479
+ };
2480
+ }
2481
+ async function main() {
2482
+ const parsed = parseArguments(process.argv.slice(2));
2483
+ if (parsed.help) {
2484
+ console.log(USAGE);
2485
+ return;
2486
+ }
2487
+ await runCreate(resolveCreateOptions(parsed.projectName, {
2488
+ ...parsed.directory === undefined ? null : { directory: parsed.directory },
2489
+ install: parsed.install
2490
+ }));
2491
+ }
2492
+ main().catch((error) => {
2493
+ console.error(`Adjacent failed: ${error instanceof Error ? error.message : String(error)}`);
2494
+ process.exitCode = 1;
2495
+ });
2496
+ export {
2497
+ parseArguments
2498
+ };