usage-board 4.0.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +40 -22
- package/dist/public/_nuxt/3inMrCcs.js +146 -0
- package/dist/public/_nuxt/5M1aAlPv.js +6 -0
- package/dist/public/_nuxt/{C0GhHHgI.js → BHGcQrYH.js} +2 -2
- package/dist/public/_nuxt/{DF2WsXH3.js → BgVTqBr9.js} +1 -1
- package/dist/public/_nuxt/{DXWxIyGU.js → BhTZzeJU.js} +1 -1
- package/dist/public/_nuxt/{D7qEPtpx.js → BlxNEZ3W.js} +1 -1
- package/dist/public/_nuxt/BwYRMC0_.js +1 -0
- package/dist/public/_nuxt/C3BLG0Zo.js +21 -0
- package/dist/public/_nuxt/{De8DvPWL.js → C8lAAJpL.js} +1 -1
- package/dist/public/_nuxt/Cxd8QZxF.js +261 -0
- package/dist/public/_nuxt/DXeNXt_b.js +1 -0
- package/dist/public/_nuxt/DavRiQHq.js +25 -0
- package/dist/public/_nuxt/{Jp5cgQZi.js → DfL4oXhq.js} +3 -3
- package/dist/public/_nuxt/DjKivtvZ.js +1 -0
- package/dist/public/_nuxt/{37OOe3RF.js → OPi16VNs.js} +1 -1
- package/dist/public/_nuxt/builds/latest.json +1 -1
- package/dist/public/_nuxt/builds/meta/eff380a6-8407-4f41-af1f-39f3ae1dface.json +1 -0
- package/dist/public/_nuxt/{entry.DnkKc-6G.css → entry.BYVbC6M5.css} +1 -1
- package/dist/public/_nuxt/error-404.ABvo6GrV.css +1 -0
- package/dist/public/_nuxt/error-500.CaR7LJUF.css +1 -0
- package/dist/public/pricing-data/fast-multiplier-overrides.json +12 -0
- package/dist/public/pricing-data/litellm-pricing.json +43714 -0
- package/dist/public/pricing-data/models-dev-pricing.json +178004 -0
- package/dist/server/chunks/_/analysis-handlers.mjs +54 -0
- package/dist/server/chunks/_/pagination.mjs +16 -0
- package/dist/server/chunks/build/client.precomputed.mjs +1 -1
- package/dist/server/chunks/nitro/nitro.mjs +4976 -5765
- package/dist/server/chunks/routes/api/analysis/agent/session.json.mjs +28 -4
- package/dist/server/chunks/routes/api/analysis/agent/token.json.mjs +14 -4
- package/dist/server/chunks/routes/api/analysis/cache.json.mjs +12 -3
- package/dist/server/chunks/routes/api/analysis/hot-project.json.mjs +15 -5
- package/dist/server/chunks/routes/api/analysis/live-state.json.mjs +32 -0
- package/dist/server/chunks/routes/api/analysis/model.json.mjs +12 -3
- package/dist/server/chunks/routes/api/analysis/overview-cards.json.mjs +12 -3
- package/dist/server/chunks/routes/api/analysis/session.json.mjs +12 -3
- package/dist/server/chunks/routes/api/analysis/token/daily.json.mjs +25 -4
- package/dist/server/chunks/routes/api/analysis/token/today-hourly.json.mjs +12 -3
- package/dist/server/chunks/routes/api/analysis/token.json.mjs +12 -3
- package/dist/server/chunks/routes/api/projects/_project/modules.get.mjs +14 -6
- package/dist/server/chunks/routes/api/projects/catalog.get.mjs +12 -4
- package/dist/server/chunks/routes/renderer.mjs +11 -3
- package/dist/server/chunks/routes/ws.mjs +64 -59
- package/dist/server/index.mjs +11 -3
- package/dist/server/node_modules/@clack/core/dist/index.mjs +17 -0
- package/dist/server/node_modules/@clack/core/package.json +63 -0
- package/dist/server/node_modules/@clack/prompts/dist/index.mjs +145 -0
- package/dist/server/node_modules/@clack/prompts/package.json +68 -0
- package/dist/server/node_modules/dayjs/dayjs.min.js +1 -0
- package/dist/server/node_modules/dayjs/package.json +85 -0
- package/dist/server/node_modules/dayjs/plugin/utc.js +1 -0
- package/dist/server/node_modules/fast-string-truncated-width/dist/index.js +111 -0
- package/dist/server/node_modules/fast-string-truncated-width/dist/utils.js +20 -0
- package/dist/server/node_modules/fast-string-truncated-width/package.json +35 -0
- package/dist/server/node_modules/fast-string-width/dist/index.js +14 -0
- package/dist/server/node_modules/fast-string-width/package.json +34 -0
- package/dist/server/node_modules/fast-wrap-ansi/lib/main.js +218 -0
- package/dist/server/node_modules/fast-wrap-ansi/package.json +51 -0
- package/dist/server/node_modules/sisteransi/package.json +34 -0
- package/dist/server/node_modules/sisteransi/src/index.js +58 -0
- package/dist/server/node_modules/xdg-basedir/index.js +30 -0
- package/dist/server/node_modules/xdg-basedir/package.json +47 -0
- package/dist/server/package.json +10 -2
- package/package.json +11 -9
- package/dist/public/_nuxt/65Ayv2XK.js +0 -146
- package/dist/public/_nuxt/BOWwkrCY.js +0 -25
- package/dist/public/_nuxt/D9-Yw1TR.js +0 -1
- package/dist/public/_nuxt/DKaPq50Z.js +0 -6
- package/dist/public/_nuxt/DgMMKsPE.js +0 -258
- package/dist/public/_nuxt/DxvuOJRP.js +0 -1
- package/dist/public/_nuxt/builds/meta/34b12f78-e5b7-490f-99ba-b4a8ab41b914.json +0 -1
- package/dist/public/_nuxt/error-404.CFBEg71j.css +0 -1
- package/dist/public/_nuxt/error-500.BqCnH31G.css +0 -1
- package/dist/public/_nuxt/qXgLTL_3.js +0 -21
- package/dist/public/_nuxt/y6mAKUDU.js +0 -1
- package/dist/server/chunks/routes/api/payload.json.mjs +0 -26
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as defineWebSocketHandler, u as useRuntimeConfig, r as resolveConfig, a as getUsageDataRuntime, P as PROJECT_USAGE_DATA_MODULES, j as PROJECT_USAGE_PLATFORMS, n as normalizeStringList } from '../nitro/nitro.mjs';
|
|
2
2
|
import 'node:http';
|
|
3
3
|
import 'node:https';
|
|
4
4
|
import 'node:events';
|
|
@@ -6,25 +6,41 @@ import 'node:buffer';
|
|
|
6
6
|
import 'node:fs';
|
|
7
7
|
import 'node:path';
|
|
8
8
|
import 'node:crypto';
|
|
9
|
-
import 'node:sqlite';
|
|
10
|
-
import '@lonewolfyx/utils';
|
|
11
9
|
import 'glob';
|
|
10
|
+
import 'dayjs';
|
|
11
|
+
import 'dayjs/plugin/utc.js';
|
|
12
|
+
import '@lonewolfyx/utils';
|
|
13
|
+
import 'node:sqlite';
|
|
14
|
+
import 'node:fs/promises';
|
|
15
|
+
import '@clack/prompts';
|
|
12
16
|
import 'chokidar';
|
|
13
17
|
import 'node:os';
|
|
14
18
|
import 'path-type';
|
|
19
|
+
import 'os';
|
|
20
|
+
import 'path';
|
|
21
|
+
import 'fs';
|
|
22
|
+
import 'xdg-basedir';
|
|
15
23
|
import 'node:url';
|
|
16
24
|
import '@iconify/utils';
|
|
17
25
|
import 'consola';
|
|
18
26
|
|
|
27
|
+
const MAX_PAGE_SIZE = 100;
|
|
28
|
+
const MAX_CONNECTIONS = 50;
|
|
29
|
+
const peerSubscriptions = /* @__PURE__ */ new Map();
|
|
19
30
|
const ws = defineWebSocketHandler({
|
|
20
31
|
open(peer) {
|
|
21
|
-
|
|
32
|
+
if (peerSubscriptions.size >= MAX_CONNECTIONS) {
|
|
33
|
+
peer.send(JSON.stringify({ message: "Too many connections.", type: "error" }));
|
|
34
|
+
peer.close();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
subscribePeerToUsageUpdates(peer);
|
|
22
38
|
},
|
|
23
39
|
async message(peer, message) {
|
|
24
40
|
try {
|
|
25
|
-
const request = parseProjectRequest(message);
|
|
41
|
+
const request = parseProjectRequest(message.json());
|
|
26
42
|
const runtimeConfig = useRuntimeConfig();
|
|
27
|
-
const config = resolveConfig(runtimeConfig.public);
|
|
43
|
+
const config = await resolveConfig(runtimeConfig.public);
|
|
28
44
|
const runtime = getUsageDataRuntime(config);
|
|
29
45
|
if (request.type === "project") {
|
|
30
46
|
sendData(peer, request, await runtime.getProjectCatalog());
|
|
@@ -32,75 +48,41 @@ const ws = defineWebSocketHandler({
|
|
|
32
48
|
sendData(peer, request, await runtime.getProjectDataModules(request));
|
|
33
49
|
}
|
|
34
50
|
} catch (error) {
|
|
35
|
-
|
|
51
|
+
peer.send(JSON.stringify({ message: error instanceof Error ? error.message : "Failed to handle websocket request.", type: "error" }));
|
|
36
52
|
}
|
|
37
53
|
},
|
|
38
|
-
close(peer
|
|
39
|
-
|
|
54
|
+
close(peer) {
|
|
55
|
+
unsubscribePeer(peer.id);
|
|
40
56
|
},
|
|
41
57
|
error(peer, error) {
|
|
42
58
|
console.error(`[ws] error: ${peer.id}`, error);
|
|
43
59
|
}
|
|
44
60
|
});
|
|
45
|
-
function parseProjectRequest(
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} catch {
|
|
50
|
-
return normalizeProjectRequest(parseTextRequest(text));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function sendError(peer, message) {
|
|
54
|
-
peer.send(JSON.stringify({
|
|
55
|
-
message,
|
|
56
|
-
type: "error"
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
function parseTextRequest(text) {
|
|
60
|
-
var _a, _b, _c, _d;
|
|
61
|
-
if (text === "project" || text === "project_data") {
|
|
62
|
-
return { type: text };
|
|
63
|
-
}
|
|
64
|
-
const params = new URLSearchParams(text.startsWith("?") ? text.slice(1) : text);
|
|
65
|
-
const type = params.get("type");
|
|
66
|
-
if (!type) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
module: (_a = params.get("module")) != null ? _a : void 0,
|
|
71
|
-
modules: params.getAll("modules").flatMap((item) => {
|
|
72
|
-
var _a2;
|
|
73
|
-
return (_a2 = normalizeStringList(item)) != null ? _a2 : [];
|
|
74
|
-
}),
|
|
75
|
-
platform: (_b = params.get("platform")) != null ? _b : void 0,
|
|
76
|
-
project: (_c = params.get("project")) != null ? _c : void 0,
|
|
77
|
-
requestId: (_d = params.get("requestId")) != null ? _d : void 0,
|
|
78
|
-
type
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function normalizeProjectRequest(value) {
|
|
82
|
-
var _a;
|
|
83
|
-
if (typeof value === "string") {
|
|
84
|
-
return normalizeProjectRequest(parseTextRequest(value.trim()));
|
|
61
|
+
function parseProjectRequest(value) {
|
|
62
|
+
const record = value && typeof value === "object" ? value : null;
|
|
63
|
+
if (!record) {
|
|
64
|
+
throw new Error('Websocket message must be a JSON object with a "type" field.');
|
|
85
65
|
}
|
|
86
|
-
|
|
87
|
-
throw new Error("Websocket message must include a supported type.");
|
|
88
|
-
}
|
|
89
|
-
const record = value;
|
|
90
|
-
const type = (_a = normalizeStringValue(record.type)) != null ? _a : "";
|
|
66
|
+
const type = typeof record.type === "string" ? record.type.trim() : "";
|
|
91
67
|
if (type === "project") {
|
|
92
68
|
return {
|
|
93
|
-
requestId:
|
|
69
|
+
requestId: typeof record.requestId === "string" ? record.requestId.trim() : "",
|
|
94
70
|
type
|
|
95
71
|
};
|
|
96
72
|
}
|
|
97
73
|
if (type === "project_data") {
|
|
74
|
+
const rawPageSize = typeof record.pageSize === "number" && Number.isFinite(record.pageSize) ? record.pageSize : void 0;
|
|
75
|
+
const pageSize = rawPageSize === void 0 ? void 0 : Math.min(Math.max(rawPageSize, 1), MAX_PAGE_SIZE);
|
|
76
|
+
const module = typeof record.module === "string" && PROJECT_USAGE_DATA_MODULES.includes(record.module) ? record.module : void 0;
|
|
77
|
+
const platform = typeof record.platform === "string" && (record.platform === "all" || PROJECT_USAGE_PLATFORMS.includes(record.platform)) ? record.platform : void 0;
|
|
98
78
|
return {
|
|
99
|
-
module
|
|
79
|
+
module,
|
|
100
80
|
modules: normalizeStringList(record.modules),
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
81
|
+
page: typeof record.page === "number" && Number.isFinite(record.page) ? record.page : void 0,
|
|
82
|
+
pageSize,
|
|
83
|
+
platform,
|
|
84
|
+
project: typeof record.project === "string" ? record.project.trim() : "",
|
|
85
|
+
requestId: typeof record.requestId === "string" ? record.requestId.trim() : "",
|
|
104
86
|
type
|
|
105
87
|
};
|
|
106
88
|
}
|
|
@@ -116,5 +98,28 @@ function sendData(peer, request, data) {
|
|
|
116
98
|
requestId: request.requestId
|
|
117
99
|
}));
|
|
118
100
|
}
|
|
101
|
+
async function subscribePeerToUsageUpdates(peer) {
|
|
102
|
+
unsubscribePeer(peer.id);
|
|
103
|
+
const runtimeConfig = useRuntimeConfig();
|
|
104
|
+
const config = await resolveConfig(runtimeConfig.public);
|
|
105
|
+
const runtime = getUsageDataRuntime(config);
|
|
106
|
+
const unsubscribe = runtime.subscribeToUpdates((update) => {
|
|
107
|
+
peer.send(JSON.stringify({
|
|
108
|
+
payload: {
|
|
109
|
+
affectedProjects: update.affectedProjects,
|
|
110
|
+
updatedAt: update.updatedAt,
|
|
111
|
+
updatedPlatforms: [...update.updatedPlatforms],
|
|
112
|
+
updatedSessions: update.updatedSessions
|
|
113
|
+
},
|
|
114
|
+
type: "usage_update"
|
|
115
|
+
}));
|
|
116
|
+
});
|
|
117
|
+
peerSubscriptions.set(peer.id, unsubscribe);
|
|
118
|
+
}
|
|
119
|
+
function unsubscribePeer(peerId) {
|
|
120
|
+
var _a;
|
|
121
|
+
(_a = peerSubscriptions.get(peerId)) == null ? void 0 : _a();
|
|
122
|
+
peerSubscriptions.delete(peerId);
|
|
123
|
+
}
|
|
119
124
|
|
|
120
125
|
export { ws as default };
|
package/dist/server/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import process from 'node:process';globalThis._importMeta_={url:import.meta.url,env:process.env};export {
|
|
1
|
+
import process from 'node:process';globalThis._importMeta_={url:import.meta.url,env:process.env};export { x as handler, y as listener, z as websocket } from './chunks/nitro/nitro.mjs';
|
|
2
2
|
import 'node:http';
|
|
3
3
|
import 'node:https';
|
|
4
4
|
import 'node:events';
|
|
@@ -6,12 +6,20 @@ import 'node:buffer';
|
|
|
6
6
|
import 'node:fs';
|
|
7
7
|
import 'node:path';
|
|
8
8
|
import 'node:crypto';
|
|
9
|
-
import 'node:sqlite';
|
|
10
|
-
import '@lonewolfyx/utils';
|
|
11
9
|
import 'glob';
|
|
10
|
+
import 'dayjs';
|
|
11
|
+
import 'dayjs/plugin/utc.js';
|
|
12
|
+
import '@lonewolfyx/utils';
|
|
13
|
+
import 'node:sqlite';
|
|
14
|
+
import 'node:fs/promises';
|
|
15
|
+
import '@clack/prompts';
|
|
12
16
|
import 'chokidar';
|
|
13
17
|
import 'node:os';
|
|
14
18
|
import 'path-type';
|
|
19
|
+
import 'os';
|
|
20
|
+
import 'path';
|
|
21
|
+
import 'fs';
|
|
22
|
+
import 'xdg-basedir';
|
|
15
23
|
import 'node:url';
|
|
16
24
|
import '@iconify/utils';
|
|
17
25
|
import 'consola';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import{styleText as v}from"node:util";import{stdout as x,stdin as D}from"node:process";import*as b from"node:readline";import E from"node:readline";import{wrapAnsi as M}from"fast-wrap-ansi";import{cursor as p,erase as V}from"sisteransi";import{ReadStream as O}from"node:tty";function f(r,t,s){if(!s.some(o=>!o.disabled))return r;const e=r+t,i=Math.max(s.length-1,0),n=e<0?i:e>i?0:e;return s[n].disabled?f(n,t<0?-1:1,s):n}function I(r,t,s,e){const i=e.split(`
|
|
2
|
+
`);let n=0,o=r;for(const a of i){if(o<=a.length)break;o-=a.length+1,n++}for(n=Math.max(0,Math.min(i.length-1,n+s)),o=Math.min(o,i[n].length)+t;o<0&&n>0;)n--,o+=i[n].length+1;for(;o>i[n].length&&n<i.length-1;)o-=i[n].length+1,n++;o=Math.max(0,Math.min(i[n].length,o));let u=0;for(let a=0;a<n;a++)u+=i[a].length+1;return u+o}const G=["up","down","left","right","space","enter","cancel"],K=["January","February","March","April","May","June","July","August","September","October","November","December"],h={actions:new Set(G),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,date:{monthNames:[...K],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(r,t)=>`There are only ${r} days in ${t}`,afterMin:r=>`Date must be on or after ${r.toISOString().slice(0,10)}`,beforeMax:r=>`Date must be on or before ${r.toISOString().slice(0,10)}`}}};function j(r){if(r.aliases!==void 0){const t=r.aliases;for(const s in t){if(!Object.hasOwn(t,s))continue;const e=t[s];h.actions.has(e)&&(h.aliases.has(s)||h.aliases.set(s,e))}}if(r.messages!==void 0){const t=r.messages;t.cancel!==void 0&&(h.messages.cancel=t.cancel),t.error!==void 0&&(h.messages.error=t.error)}if(r.withGuide!==void 0&&(h.withGuide=r.withGuide!==!1),r.date!==void 0){const t=r.date;t.monthNames!==void 0&&(h.date.monthNames=[...t.monthNames]),t.messages!==void 0&&(t.messages.required!==void 0&&(h.date.messages.required=t.messages.required),t.messages.invalidMonth!==void 0&&(h.date.messages.invalidMonth=t.messages.invalidMonth),t.messages.invalidDay!==void 0&&(h.date.messages.invalidDay=t.messages.invalidDay),t.messages.afterMin!==void 0&&(h.date.messages.afterMin=t.messages.afterMin),t.messages.beforeMax!==void 0&&(h.date.messages.beforeMax=t.messages.beforeMax))}}function C(r,t){if(typeof r=="string")return h.aliases.get(r)===t;for(const s of r)if(s!==void 0&&C(s,t))return!0;return!1}function z(r,t){if(r===t)return;const s=r.split(`
|
|
3
|
+
`),e=t.split(`
|
|
4
|
+
`),i=Math.max(s.length,e.length),n=[];for(let o=0;o<i;o++)s[o]!==e[o]&&n.push(o);return{lines:n,numLinesBefore:s.length,numLinesAfter:e.length,numLines:i}}const Y=globalThis.process.platform.startsWith("win"),k=Symbol("clack:cancel");function q(r){return r===k}function w(r,t){const s=r;s.isTTY&&s.setRawMode(t)}function R({input:r=D,output:t=x,overwrite:s=!0,hideCursor:e=!0}={}){const i=b.createInterface({input:r,output:t,prompt:"",tabSize:1});b.emitKeypressEvents(r,i),r instanceof O&&r.isTTY&&r.setRawMode(!0);const n=(o,{name:u,sequence:a})=>{const l=String(o);if(C([l,u,a],"cancel")){e&&t.write(p.show),process.exit(0);return}if(!s)return;const c=u==="return"?0:-1,y=u==="return"?-1:0;b.moveCursor(t,c,y,()=>{b.clearLine(t,1,()=>{r.once("keypress",n)})})};return e&&t.write(p.hide),r.once("keypress",n),()=>{r.off("keypress",n),e&&t.write(p.show),r instanceof O&&r.isTTY&&!Y&&r.setRawMode(!1),i.terminal=!1,i.close()}}const A=r=>"columns"in r&&typeof r.columns=="number"?r.columns:80,L=r=>"rows"in r&&typeof r.rows=="number"?r.rows:20;function W(r,t,s,e=s,i=s,n){const o=A(r??x);return M(t,o-s.length,{hard:!0,trim:!1}).split(`
|
|
5
|
+
`).map((u,a,l)=>{const c=n?n(u,a):u;return a===0?`${e}${c}`:a===l.length-1?`${i}${c}`:`${s}${c}`}).join(`
|
|
6
|
+
`)}let m=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(t,s=!0){const{input:e=D,output:i=x,render:n,signal:o,...u}=t;this.opts=u,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=n.bind(this),this._track=s,this._abortSignal=o,this.input=e,this.output=i}unsubscribe(){this._subscribers.clear()}setSubscriber(t,s){const e=this._subscribers.get(t)??[];e.push(s),this._subscribers.set(t,e)}on(t,s){this.setSubscriber(t,{cb:s})}once(t,s){this.setSubscriber(t,{cb:s,once:!0})}emit(t,...s){const e=this._subscribers.get(t)??[],i=[];for(const n of e)n.cb(...s),n.once&&i.push(()=>e.splice(e.indexOf(n),1));for(const n of i)n()}prompt(){return new Promise(t=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),t(k);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=E.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),w(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(p.show),this.output.off("resize",this.render),w(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(p.show),this.output.off("resize",this.render),w(this.input,!1),t(k)})})}_isActionKey(t,s){return t===" "}_shouldSubmit(t,s){return!0}_setValue(t){this.value=t,this.emit("value",this.value)}_setUserInput(t,s){this.userInput=t??"",this.emit("userInput",this.userInput),s&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(t,s){if(this._track&&s.name!=="return"&&(s.name&&this._isActionKey(t,s)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),s?.name&&(!this._track&&h.aliases.has(s.name)&&this.emit("cursor",h.aliases.get(s.name)),h.actions.has(s.name)&&this.emit("cursor",s.name)),t&&(t.toLowerCase()==="y"||t.toLowerCase()==="n")&&this.emit("confirm",t.toLowerCase()==="y"),this.emit("key",t?.toLowerCase(),s),s?.name==="return"&&this._shouldSubmit(t,s)){if(this.opts.validate){const e=this.opts.validate(this.value);e&&(this.error=e instanceof Error?e.message:e,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}C([t,s?.name,s?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
|
|
7
|
+
`),w(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){const t=M(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
|
|
8
|
+
`).length-1;this.output.write(p.move(-999,t*-1))}render(){const t=M(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(t!==this._prevFrame){if(this.state==="initial")this.output.write(p.hide);else{const s=z(this._prevFrame,t),e=L(this.output);if(this.restoreCursor(),s){const i=Math.max(0,s.numLinesAfter-e),n=Math.max(0,s.numLinesBefore-e);let o=s.lines.find(u=>u>=i);if(o===void 0){this._prevFrame=t;return}if(s.lines.length===1){this.output.write(p.move(0,o-n)),this.output.write(V.lines(1));const u=t.split(`
|
|
9
|
+
`);this.output.write(u[o]),this._prevFrame=t,this.output.write(p.move(0,u.length-o-1));return}else if(s.lines.length>1){if(i<n)o=i;else{const a=o-n;a>0&&this.output.write(p.move(0,a))}this.output.write(V.down());const u=t.split(`
|
|
10
|
+
`).slice(o);this.output.write(u.join(`
|
|
11
|
+
`)),this._prevFrame=t;return}}this.output.write(V.down())}this.output.write(t),this.state==="initial"&&(this.state="active"),this._prevFrame=t}}};function B(r,t){if(r===void 0||t.length===0)return 0;const s=t.findIndex(e=>e.value===r);return s!==-1?s:0}function J(r,t){return(t.label??String(t.value)).toLowerCase().includes(r.toLowerCase())}function H(r,t){if(t)return r?t:t[0]}let Q=class extends m{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#s=0;#r="";#t;#n;#u;get cursor(){return this.#s}get userInputWithCursor(){if(!this.userInput)return v(["inverse","hidden"],"_");if(this._cursor>=this.userInput.length)return`${this.userInput}\u2588`;const t=this.userInput.slice(0,this._cursor),[s,...e]=this.userInput.slice(this._cursor);return`${t}${v("inverse",s)}${e.join("")}`}get options(){return typeof this.#n=="function"?this.#n():this.#n}constructor(t){super(t),this.#n=t.options,this.#u=t.placeholder;const s=this.options;this.filteredOptions=[...s],this.multiple=t.multiple===!0,this.#t=typeof t.options=="function"?t.filter:t.filter??J;let e;if(t.initialValue&&Array.isArray(t.initialValue)?this.multiple?e=t.initialValue:e=t.initialValue.slice(0,1):!this.multiple&&this.options.length>0&&(e=[this.options[0].value]),e)for(const i of e){const n=s.findIndex(o=>o.value===i);n!==-1&&(this.toggleSelected(i),this.#s=n)}this.focusedValue=this.options[this.#s]?.value,this.on("key",(i,n)=>this.#e(i,n)),this.on("userInput",i=>this.#i(i))}_isActionKey(t,s){return t===" "||this.multiple&&this.isNavigating&&s.name==="space"&&t!==void 0&&t!==""}#e(t,s){const e=s.name==="up",i=s.name==="down",n=s.name==="return",o=this.userInput===""||this.userInput===" ",u=this.#u,a=this.options,l=u!==void 0&&u!==""&&a.some(c=>!c.disabled&&(this.#t?this.#t(u,c):!0));if(s.name==="tab"&&o&&l){this.userInput===" "&&this._clearUserInput(),this._setUserInput(u,!0),this.isNavigating=!1;return}e||i?(this.#s=f(this.#s,e?-1:1,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#s]?.value,this.multiple||(this.selectedValues=[this.focusedValue]),this.isNavigating=!0):n?this.value=H(this.multiple,this.selectedValues):this.multiple?this.focusedValue!==void 0&&(s.name==="tab"||this.isNavigating&&s.name==="space")?this.toggleSelected(this.focusedValue):this.isNavigating=!1:(this.focusedValue&&(this.selectedValues=[this.focusedValue]),this.isNavigating=!1)}deselectAll(){this.selectedValues=[]}toggleSelected(t){this.filteredOptions.length!==0&&(this.multiple?this.selectedValues.includes(t)?this.selectedValues=this.selectedValues.filter(s=>s!==t):this.selectedValues=[...this.selectedValues,t]:this.selectedValues=[t])}#i(t){if(t!==this.#r){this.#r=t;const s=this.options;t&&this.#t?this.filteredOptions=s.filter(n=>this.#t?.(t,n)):this.filteredOptions=[...s];const e=B(this.focusedValue,this.filteredOptions);this.#s=f(e,0,this.filteredOptions);const i=this.filteredOptions[this.#s];i&&!i.disabled?this.focusedValue=i.value:this.focusedValue=void 0,this.multiple||(this.focusedValue!==void 0?this.toggleSelected(this.focusedValue):this.deselectAll())}}};class X extends m{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(t){super(t,!1),this.value=!!t.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",s=>{this.output.write(p.move(0,-1)),this.value=s,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}const Z={Y:{type:"year",len:4},M:{type:"month",len:2},D:{type:"day",len:2}};function P(r){return[...r].map(t=>Z[t])}function tt(r){const t=new Intl.DateTimeFormat(r,{year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(new Date(2e3,0,15)),s=[];let e="/";for(const i of t)i.type==="literal"?e=i.value.trim()||i.value:(i.type==="year"||i.type==="month"||i.type==="day")&&s.push({type:i.type,len:i.type==="year"?4:2});return{segments:s,separator:e}}function $(r){return Number.parseInt((r||"0").replace(/_/g,"0"),10)||0}function S(r){return{year:$(r.year),month:$(r.month),day:$(r.day)}}function U(r,t){return new Date(r||2001,t||1,0).getDate()}function F(r){const{year:t,month:s,day:e}=S(r);if(!t||t<0||t>9999||!s||s<1||s>12||!e||e<1)return;const i=new Date(Date.UTC(t,s-1,e));if(!(i.getUTCFullYear()!==t||i.getUTCMonth()!==s-1||i.getUTCDate()!==e))return{year:t,month:s,day:e}}function N(r){const t=F(r);return t?new Date(Date.UTC(t.year,t.month-1,t.day)):void 0}function st(r,t,s,e){const i=s?{year:s.getUTCFullYear(),month:s.getUTCMonth()+1,day:s.getUTCDate()}:null,n=e?{year:e.getUTCFullYear(),month:e.getUTCMonth()+1,day:e.getUTCDate()}:null;return r==="year"?{min:i?.year??1,max:n?.year??9999}:r==="month"?{min:i&&t.year===i.year?i.month:1,max:n&&t.year===n.year?n.month:12}:{min:i&&t.year===i.year&&t.month===i.month?i.day:1,max:n&&t.year===n.year&&t.month===n.month?n.day:U(t.year,t.month)}}class et extends m{#s;#r;#t;#n;#u;#e={segmentIndex:0,positionInSegment:0};#i=!0;#o=null;inlineError="";get segmentCursor(){return{...this.#e}}get segmentValues(){return{...this.#t}}get segments(){return this.#s}get separator(){return this.#r}get formattedValue(){return this.#c(this.#t)}#c(t){return this.#s.map(s=>t[s.type]).join(this.#r)}#a(){this._setUserInput(this.#c(this.#t)),this._setValue(N(this.#t)??void 0)}constructor(t){const s=t.format?{segments:P(t.format),separator:t.separator??"/"}:tt(t.locale),e=t.separator??s.separator,i=t.format?P(t.format):s.segments,n=t.initialValue??t.defaultValue,o=n?{year:String(n.getUTCFullYear()).padStart(4,"0"),month:String(n.getUTCMonth()+1).padStart(2,"0"),day:String(n.getUTCDate()).padStart(2,"0")}:{year:"____",month:"__",day:"__"},u=i.map(a=>o[a.type]).join(e);super({...t,initialUserInput:u},!1),this.#s=i,this.#r=e,this.#t=o,this.#n=t.minDate,this.#u=t.maxDate,this.#a(),this.on("cursor",a=>this.#d(a)),this.on("key",(a,l)=>this.#f(a,l)),this.on("finalize",()=>this.#g(t))}#h(){const t=Math.max(0,Math.min(this.#e.segmentIndex,this.#s.length-1)),s=this.#s[t];if(s)return this.#e.positionInSegment=Math.max(0,Math.min(this.#e.positionInSegment,s.len-1)),{segment:s,index:t}}#l(t){this.inlineError="",this.#o=null;const s=this.#h();s&&(this.#e.segmentIndex=Math.max(0,Math.min(this.#s.length-1,s.index+t)),this.#e.positionInSegment=0,this.#i=!0)}#p(t){const s=this.#h();if(!s)return;const{segment:e}=s,i=this.#t[e.type],n=!i||i.replace(/_/g,"")==="",o=Number.parseInt((i||"0").replace(/_/g,"0"),10)||0,u=st(e.type,S(this.#t),this.#n,this.#u);let a;n?a=t===1?u.min:u.max:a=Math.max(Math.min(u.max,o+t),u.min),this.#t={...this.#t,[e.type]:a.toString().padStart(e.len,"0")},this.#i=!0,this.#o=null,this.#a()}#d(t){if(t)switch(t){case"right":return this.#l(1);case"left":return this.#l(-1);case"up":return this.#p(1);case"down":return this.#p(-1)}}#f(t,s){if(s?.name==="backspace"||s?.sequence==="\x7F"||s?.sequence==="\b"||t==="\x7F"||t==="\b"){this.inlineError="";const e=this.#h();if(!e)return;if(!this.#t[e.segment.type].replace(/_/g,"")){this.#l(-1);return}this.#t[e.segment.type]="_".repeat(e.segment.len),this.#i=!0,this.#e.positionInSegment=0,this.#a();return}if(s?.name==="tab"){this.inlineError="";const e=this.#h();if(!e)return;const i=s.shift?-1:1,n=e.index+i;n>=0&&n<this.#s.length&&(this.#e.segmentIndex=n,this.#e.positionInSegment=0,this.#i=!0);return}if(t&&/^[0-9]$/.test(t)){const e=this.#h();if(!e)return;const{segment:i}=e,n=!this.#t[i.type].replace(/_/g,"");if(this.#i&&this.#o!==null&&!n){const d=this.#o+t,g={...this.#t,[i.type]:d},_=this.#m(g,i);if(_){this.inlineError=_,this.#o=null,this.#i=!1;return}this.inlineError="",this.#t[i.type]=d,this.#o=null,this.#i=!1,this.#a(),e.index<this.#s.length-1&&(this.#e.segmentIndex=e.index+1,this.#e.positionInSegment=0,this.#i=!0);return}this.#i&&!n&&(this.#t[i.type]="_".repeat(i.len),this.#e.positionInSegment=0),this.#i=!1,this.#o=null;const o=this.#t[i.type],u=o.indexOf("_"),a=u>=0?u:Math.min(this.#e.positionInSegment,i.len-1);if(a<0||a>=i.len)return;let l=o.slice(0,a)+t+o.slice(a+1),c=!1;if(a===0&&o==="__"&&(i.type==="month"||i.type==="day")){const d=Number.parseInt(t,10);l=`0${t}`,c=d<=(i.type==="month"?1:2)}if(i.type==="year"&&(l=(o.replace(/_/g,"")+t).padStart(i.len,"_")),!l.includes("_")){const d={...this.#t,[i.type]:l},g=this.#m(d,i);if(g){this.inlineError=g;return}}this.inlineError="",this.#t[i.type]=l;const y=l.includes("_")?void 0:F(this.#t);if(y){const{year:d,month:g}=y,_=U(d,g);this.#t={year:String(Math.max(0,Math.min(9999,d))).padStart(4,"0"),month:String(Math.max(1,Math.min(12,g))).padStart(2,"0"),day:String(Math.max(1,Math.min(_,y.day))).padStart(2,"0")}}this.#a();const T=l.indexOf("_");c?(this.#i=!0,this.#o=t):T>=0?this.#e.positionInSegment=T:u>=0&&e.index<this.#s.length-1?(this.#e.segmentIndex=e.index+1,this.#e.positionInSegment=0,this.#i=!0):this.#e.positionInSegment=Math.min(a+1,i.len-1)}}#m(t,s){const{month:e,day:i}=S(t);if(s.type==="month"&&(e<0||e>12))return h.date.messages.invalidMonth;if(s.type==="day"&&(i<0||i>31))return h.date.messages.invalidDay(31,"any month")}#g(t){const{year:s,month:e,day:i}=S(this.#t);if(s&&e&&i){const n=U(s,e);this.#t={...this.#t,day:String(Math.min(i,n)).padStart(2,"0")}}this.value=N(this.#t)??t.defaultValue??void 0}}class it extends m{options;cursor=0;#s;getGroupItems(t){return this.options.filter(s=>s.group===t)}isGroupSelected(t){const s=this.getGroupItems(t),e=this.value;return e===void 0?!1:s.every(i=>e.includes(i.value))}toggleValue(){const t=this.options[this.cursor];if(this.value===void 0&&(this.value=[]),t.group===!0){const s=t.value,e=this.getGroupItems(s);this.isGroupSelected(s)?this.value=this.value.filter(i=>e.findIndex(n=>n.value===i)===-1):this.value=[...this.value,...e.map(i=>i.value)],this.value=Array.from(new Set(this.value))}else{const s=this.value.includes(t.value);this.value=s?this.value.filter(e=>e!==t.value):[...this.value,t.value]}}constructor(t){super(t,!1);const{options:s}=t;this.#s=t.selectableGroups!==!1,this.options=Object.entries(s).flatMap(([e,i])=>[{value:e,group:!0,label:e},...i.map(n=>({...n,group:e}))]),this.value=[...t.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:e})=>e===t.cursorAt),this.#s?0:1),this.on("cursor",e=>{switch(e){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;const i=this.options[this.cursor]?.group===!0;!this.#s&&i&&(this.cursor=this.cursor===0?this.options.length-1:this.cursor-1);break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;const i=this.options[this.cursor]?.group===!0;!this.#s&&i&&(this.cursor=this.cursor===this.options.length-1?0:this.cursor+1);break}case"space":this.toggleValue();break}})}}class rt extends m{#s=!1;#r;focused="editor";get userInputWithCursor(){if(this.state==="submit")return this.userInput;const t=this.userInput;if(this.cursor>=t.length)return`${t}\u2588`;const s=t.slice(0,this.cursor),e=t[this.cursor],i=t.slice(this.cursor+1);return e===`
|
|
12
|
+
`?`${s}\u2588
|
|
13
|
+
${i}`:`${s}${v("inverse",e)}${i}`}get cursor(){return this._cursor}#t(t){if(this.userInput.length===0){this._setUserInput(t);return}this._setUserInput(this.userInput.slice(0,this.cursor)+t+this.userInput.slice(this.cursor))}#n(t){const s=this.value??"";switch(t){case"up":this._cursor=I(this._cursor,0,-1,s);return;case"down":this._cursor=I(this._cursor,0,1,s);return;case"left":this._cursor=I(this._cursor,-1,0,s);return;case"right":this._cursor=I(this._cursor,1,0,s);return}}_shouldSubmit(t,s){if(this.#r)return this.focused==="submit"?!0:(this.#t(`
|
|
14
|
+
`),this._cursor++,!1);const e=this.#s;return this.#s=!0,e?(this.userInput[this.cursor-1]===`
|
|
15
|
+
`&&(this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--),!0):(this.#t(`
|
|
16
|
+
`),this._cursor++,!1)}constructor(t){super(t,!1),this.#r=t.showSubmit??!1,this.on("key",(s,e)=>{if(e?.name&&h.actions.has(e.name)){this.#n(e.name);return}if(s===" "&&this.#r){this.focused=this.focused==="editor"?"submit":"editor";return}if(e?.name!=="return"){if(this.#s=!1,e?.name==="backspace"&&this.cursor>0){this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--;return}if(e?.name==="delete"&&this.cursor<this.userInput.length){this._setUserInput(this.userInput.slice(0,this.cursor)+this.userInput.slice(this.cursor+1));return}s&&(this.#r&&this.focused==="submit"&&(this.focused="editor"),this.#t(s??""),this._cursor++)}}),this.on("userInput",s=>{this._setValue(s)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}}let nt=class extends m{options;cursor=0;get _value(){return this.options[this.cursor].value}get _enabledOptions(){return this.options.filter(t=>t.disabled!==!0)}toggleAll(){const t=this._enabledOptions,s=this.value!==void 0&&this.value.length===t.length;this.value=s?[]:t.map(e=>e.value)}toggleInvert(){const t=this.value;if(!t)return;const s=this._enabledOptions.filter(e=>!t.includes(e.value));this.value=s.map(e=>e.value)}toggleValue(){this.value===void 0&&(this.value=[]);const t=this.value.includes(this._value);this.value=t?this.value.filter(s=>s!==this._value):[...this.value,this._value]}constructor(t){super(t,!1),this.options=t.options,this.value=[...t.initialValues??[]];const s=Math.max(this.options.findIndex(({value:e})=>e===t.cursorAt),0);this.cursor=this.options[s].disabled?f(s,1,this.options):s,this.on("key",e=>{e==="a"&&this.toggleAll(),e==="i"&&this.toggleInvert()}),this.on("cursor",e=>{switch(e){case"left":case"up":this.cursor=f(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=f(this.cursor,1,this.options);break;case"space":this.toggleValue();break}})}};class ot extends m{_mask="\u2022";get cursor(){return this._cursor}get masked(){return this.userInput.replaceAll(/./g,this._mask)}get userInputWithCursor(){if(this.state==="submit"||this.state==="cancel")return this.masked;const t=this.userInput;if(this.cursor>=t.length)return`${this.masked}${v(["inverse","hidden"],"_")}`;const s=this.masked,e=s.slice(0,this.cursor),i=s.slice(this.cursor);return`${e}${v("inverse",i[0])}${i.slice(1)}`}clear(){this._clearUserInput()}constructor({mask:t,...s}){super(s),this._mask=t??"\u2022",this.on("userInput",e=>{this._setValue(e)})}}class ut extends m{options;cursor=0;get _selectedValue(){return this.options[this.cursor]}changeValue(){this.value=this._selectedValue.value}constructor(t){super(t,!1),this.options=t.options;const s=this.options.findIndex(({value:i})=>i===t.initialValue),e=s===-1?0:s;this.cursor=this.options[e].disabled?f(e,1,this.options):e,this.changeValue(),this.on("cursor",i=>{switch(i){case"left":case"up":this.cursor=f(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=f(this.cursor,1,this.options);break}this.changeValue()})}}class at extends m{options;cursor=0;constructor(t){super(t,!1),this.options=t.options;const s=t.caseSensitive===!0,e=this.options.map(({value:[i]})=>s?i:i?.toLowerCase());this.cursor=Math.max(e.indexOf(t.initialValue),0),this.on("key",(i,n)=>{if(!i)return;const o=s&&n.shift?i.toUpperCase():i;if(!e.includes(o))return;const u=this.options.find(({value:[a]})=>s?a===o:a?.toLowerCase()===i);u&&(this.value=u.value,this.state="submit",this.emit("submit"))})}}class ht extends m{get userInputWithCursor(){if(this.state==="submit")return this.userInput;const t=this.userInput;if(this.cursor>=t.length)return`${this.userInput}\u2588`;const s=t.slice(0,this.cursor),[e,...i]=t.slice(this.cursor);return`${s}${v("inverse",e)}${i.join("")}`}get cursor(){return this._cursor}constructor(t){super({...t,initialUserInput:t.initialUserInput??t.initialValue}),this.on("userInput",s=>{this._setValue(s)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}}export{Q as AutocompletePrompt,X as ConfirmPrompt,et as DatePrompt,it as GroupMultiSelectPrompt,rt as MultiLinePrompt,nt as MultiSelectPrompt,ot as PasswordPrompt,m as Prompt,at as SelectKeyPrompt,ut as SelectPrompt,ht as TextPrompt,R as block,A as getColumns,L as getRows,q as isCancel,h as settings,j as updateSettings,W as wrapTextWithPrefix};
|
|
17
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clack/core",
|
|
3
|
+
"version": "1.3.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.mjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.mts",
|
|
10
|
+
"default": "./dist/index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/index.d.mts",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/bombshell-dev/clack.git",
|
|
18
|
+
"directory": "packages/core"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/bombshell-dev/clack/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/bombshell-dev/clack/tree/main/packages/core#readme",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"CHANGELOG.md"
|
|
27
|
+
],
|
|
28
|
+
"keywords": [
|
|
29
|
+
"ask",
|
|
30
|
+
"clack",
|
|
31
|
+
"cli",
|
|
32
|
+
"command-line",
|
|
33
|
+
"command",
|
|
34
|
+
"input",
|
|
35
|
+
"interact",
|
|
36
|
+
"interface",
|
|
37
|
+
"menu",
|
|
38
|
+
"prompt",
|
|
39
|
+
"prompts",
|
|
40
|
+
"stdin",
|
|
41
|
+
"ui"
|
|
42
|
+
],
|
|
43
|
+
"author": {
|
|
44
|
+
"name": "Nate Moore",
|
|
45
|
+
"email": "nate@natemoo.re",
|
|
46
|
+
"url": "https://twitter.com/n_moore"
|
|
47
|
+
},
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">= 20.12.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"fast-wrap-ansi": "^0.2.0",
|
|
54
|
+
"sisteransi": "^1.0.5"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"vitest": "^3.2.4"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "unbuild",
|
|
61
|
+
"test": "vitest run"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import{getColumns as X,getRows as Lt,AutocompletePrompt as vt,settings as T,ConfirmPrompt as Dt,wrapTextWithPrefix as E,DatePrompt as Wt,isCancel as Ft,GroupMultiSelectPrompt as Ht,MultiLinePrompt as Ut,MultiSelectPrompt as Kt,PasswordPrompt as qt,block as Jt,SelectPrompt as Yt,SelectKeyPrompt as Xt,TextPrompt as zt}from"@clack/core";export{isCancel,settings,updateSettings}from"@clack/core";import{styleText as e,stripVTControlCharacters as nt}from"node:util";import V from"node:process";import{wrapAnsi as J}from"fast-wrap-ansi";import B from"fast-string-width";import{existsSync as Qt,lstatSync as wt,readdirSync as Zt}from"node:fs";import{dirname as bt,join as te}from"node:path";import{cursor as St,erase as Ct}from"sisteransi";function ee(){return V.platform!=="win32"?V.env.TERM!=="linux":!!V.env.CI||!!V.env.WT_SESSION||!!V.env.TERMINUS_SUBLIME||V.env.ConEmuTask==="{cmd::Cmder}"||V.env.TERM_PROGRAM==="Terminus-Sublime"||V.env.TERM_PROGRAM==="vscode"||V.env.TERM==="xterm-256color"||V.env.TERM==="alacritty"||V.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const tt=ee(),ot=()=>process.env.CI==="true",It=t=>t.isTTY===!0,w=(t,i)=>tt?t:i,Tt=w("\u25C6","*"),at=w("\u25A0","x"),ut=w("\u25B2","x"),H=w("\u25C7","o"),lt=w("\u250C","T"),$=w("\u2502","|"),x=w("\u2514","\u2014"),_t=w("\u2510","T"),xt=w("\u2518","\u2014"),z=w("\u25CF",">"),U=w("\u25CB"," "),et=w("\u25FB","[\u2022]"),K=w("\u25FC","[+]"),Y=w("\u25FB","[ ]"),Et=w("\u25AA","\u2022"),st=w("\u2500","-"),ct=w("\u256E","+"),Gt=w("\u251C","+"),$t=w("\u256F","+"),dt=w("\u2570","+"),Mt=w("\u256D","+"),ht=w("\u25CF","\u2022"),pt=w("\u25C6","*"),mt=w("\u25B2","!"),gt=w("\u25A0","x"),P=t=>{switch(t){case"initial":case"active":return e("cyan",Tt);case"cancel":return e("red",at);case"error":return e("yellow",ut);case"submit":return e("green",H)}},yt=t=>{switch(t){case"initial":case"active":return e("cyan",$);case"cancel":return e("red",$);case"error":return e("yellow",$);case"submit":return e("green",$)}},Ot=(t,i,s,r,u,n=!1)=>{let a=i,c=0;if(n)for(let o=r-1;o>=s&&(a-=t[o].length,c++,!(a<=u));o--);else for(let o=s;o<r&&(a-=t[o].length,c++,!(a<=u));o++);return{lineCount:a,removals:c}},F=({cursor:t,options:i,style:s,output:r=process.stdout,maxItems:u=Number.POSITIVE_INFINITY,columnPadding:n=0,rowPadding:a=4})=>{const c=X(r)-n,o=Lt(r),l=e("dim","..."),d=Math.max(o-a,0),g=Math.max(Math.min(u,d),5);let p=0;t>=g-3&&(p=Math.max(Math.min(t-g+3,i.length-g),0));let f=g<i.length&&p>0,h=g<i.length&&p+g<i.length;const I=Math.min(p+g,i.length),m=[];let y=0;f&&y++,h&&y++;const v=p+(f?1:0),C=I-(h?1:0);for(let b=v;b<C;b++){const G=J(s(i[b],b===t),c,{hard:!0,trim:!1}).split(`
|
|
2
|
+
`);m.push(G),y+=G.length}if(y>d){let b=0,G=0,M=y;const N=t-v;let O=d;const j=()=>Ot(m,M,0,N,O),k=()=>Ot(m,M,N+1,m.length,O,!0);f?({lineCount:M,removals:b}=j(),M>O&&(h||(O-=1),{lineCount:M,removals:G}=k())):(h||(O-=1),{lineCount:M,removals:G}=k(),M>O&&(O-=1,{lineCount:M,removals:b}=j())),b>0&&(f=!0,m.splice(0,b)),G>0&&(h=!0,m.splice(m.length-G,G))}const S=[];f&&S.push(l);for(const b of m)for(const G of b)S.push(G);return h&&S.push(l),S};function Pt(t){return t.label??String(t.value??"")}function Rt(t,i){if(!t)return!0;const s=(i.label??String(i.value??"")).toLowerCase(),r=(i.hint??"").toLowerCase(),u=String(i.value).toLowerCase(),n=t.toLowerCase();return s.includes(n)||r.includes(n)||u.includes(n)}function se(t,i){const s=[];for(const r of i)t.includes(r.value)&&s.push(r);return s}const At=t=>new vt({options:t.options,initialValue:t.initialValue?[t.initialValue]:void 0,initialUserInput:t.initialUserInput,placeholder:t.placeholder,filter:t.filter??((i,s)=>Rt(i,s)),signal:t.signal,input:t.input,output:t.output,validate:t.validate,render(){const i=t.withGuide??T.withGuide,s=i?[`${e("gray",$)}`,`${P(this.state)} ${t.message}`]:[`${P(this.state)} ${t.message}`],r=this.userInput,u=this.options,n=t.placeholder,a=r===""&&n!==void 0,c=(o,l)=>{const d=Pt(o),g=o.hint&&o.value===this.focusedValue?e("dim",` (${o.hint})`):"";switch(l){case"active":return`${e("green",z)} ${d}${g}`;case"inactive":return`${e("dim",U)} ${e("dim",d)}`;case"disabled":return`${e("gray",U)} ${e(["strikethrough","gray"],d)}`}};switch(this.state){case"submit":{const o=se(this.selectedValues,u),l=o.length>0?` ${e("dim",o.map(Pt).join(", "))}`:"",d=i?e("gray",$):"";return`${s.join(`
|
|
3
|
+
`)}
|
|
4
|
+
${d}${l}`}case"cancel":{const o=r?` ${e(["strikethrough","dim"],r)}`:"",l=i?e("gray",$):"";return`${s.join(`
|
|
5
|
+
`)}
|
|
6
|
+
${l}${o}`}default:{const o=this.state==="error"?"yellow":"cyan",l=i?`${e(o,$)} `:"",d=i?e(o,x):"";let g="";if(this.isNavigating||a){const v=a?n:r;g=v!==""?` ${e("dim",v)}`:""}else g=` ${this.userInputWithCursor}`;const p=this.filteredOptions.length!==u.length?e("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"",f=this.filteredOptions.length===0&&r?[`${l}${e("yellow","No matches found")}`]:[],h=this.state==="error"?[`${l}${e("yellow",this.error)}`]:[];i&&s.push(`${l.trimEnd()}`),s.push(`${l}${e("dim","Search:")}${g}${p}`,...f,...h);const I=[`${e("dim","\u2191/\u2193")} to select`,`${e("dim","Enter:")} confirm`,`${e("dim","Type:")} to search`],m=[`${l}${I.join(" \u2022 ")}`,d],y=this.filteredOptions.length===0?[]:F({cursor:this.cursor,options:this.filteredOptions,columnPadding:i?3:0,rowPadding:s.length+m.length,style:(v,C)=>c(v,v.disabled?"disabled":C?"active":"inactive"),maxItems:t.maxItems,output:t.output});return[...s,...y.map(v=>`${l}${v}`),...m].join(`
|
|
7
|
+
`)}}}}).prompt(),ie=t=>{const i=(r,u,n,a)=>{const c=n.includes(r.value),o=r.label??String(r.value??""),l=r.hint&&a!==void 0&&r.value===a?e("dim",` (${r.hint})`):"",d=c?e("green",K):e("dim",Y);return r.disabled?`${e("gray",Y)} ${e(["strikethrough","gray"],o)}`:u?`${d} ${o}${l}`:`${d} ${e("dim",o)}`},s=new vt({options:t.options,multiple:!0,placeholder:t.placeholder,filter:t.filter??((r,u)=>Rt(r,u)),validate:()=>{if(t.required&&s.selectedValues.length===0)return"Please select at least one item"},initialValue:t.initialValues,signal:t.signal,input:t.input,output:t.output,render(){const r=t.withGuide??T.withGuide,u=`${r?`${e("gray",$)}
|
|
8
|
+
`:""}${P(this.state)} ${t.message}
|
|
9
|
+
`,n=this.userInput,a=t.placeholder,c=n===""&&a!==void 0,o=this.isNavigating||c?e("dim",c?a:n):this.userInputWithCursor,l=this.options,d=this.filteredOptions.length!==l.length?e("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"";switch(this.state){case"submit":return`${u}${r?`${e("gray",$)} `:""}${e("dim",`${this.selectedValues.length} items selected`)}`;case"cancel":return`${u}${r?`${e("gray",$)} `:""}${e(["strikethrough","dim"],n)}`;default:{const g=this.state==="error"?"yellow":"cyan",p=r?`${e(g,$)} `:"",f=r?e(g,x):"",h=[`${e("dim","\u2191/\u2193")} to navigate`,`${e("dim",this.isNavigating?"Space/Tab:":"Tab:")} select`,`${e("dim","Enter:")} confirm`,`${e("dim","Type:")} to search`],I=this.filteredOptions.length===0&&n?[`${p}${e("yellow","No matches found")}`]:[],m=this.state==="error"?[`${p}${e("yellow",this.error)}`]:[],y=[...`${u}${r?e(g,$):""}`.split(`
|
|
10
|
+
`),`${p}${e("dim","Search:")} ${o}${d}`,...I,...m],v=[`${p}${h.join(" \u2022 ")}`,f],C=F({cursor:this.cursor,options:this.filteredOptions,style:(S,b)=>i(S,b,this.selectedValues,this.focusedValue),maxItems:t.maxItems,output:t.output,rowPadding:y.length+v.length});return[...y,...C.map(S=>`${p}${S}`),...v].join(`
|
|
11
|
+
`)}}}});return s.prompt()},re=[Mt,ct,dt,$t],ne=[lt,_t,x,xt];function Vt(t,i,s,r){let u=s,n=s;return r==="center"?u=Math.floor((i-t)/2):r==="right"&&(u=i-t-s),n=i-u-t,[u,n]}const oe=t=>t,ae=(t="",i="",s)=>{const r=s?.output??process.stdout,u=X(r),n=2,a=s?.titlePadding??1,c=s?.contentPadding??2,o=s?.width===void 0||s.width==="auto"?1:Math.min(1,s.width),l=s?.withGuide??T.withGuide?`${$} `:"",d=s?.formatBorder??oe,g=(s?.rounded?re:ne).map(d),p=d(st),f=d($),h=B(l),I=B(i),m=u-h;let y=Math.floor(u*o)-h;if(s?.width==="auto"){const O=t.split(`
|
|
12
|
+
`);let j=I+a*2;for(const rt of O){const W=B(rt)+c*2;W>j&&(j=W)}const k=j+n;k<y&&(y=k)}y%2!==0&&(y<m?y++:y--);const v=y-n,C=v-a*2,S=I>C?`${i.slice(0,C-3)}...`:i,[b,G]=Vt(B(S),v,a,s?.titleAlign),M=J(t,v-c*2,{hard:!0,trim:!1});r.write(`${l}${g[0]}${p.repeat(b)}${S}${p.repeat(G)}${g[1]}
|
|
13
|
+
`);const N=M.split(`
|
|
14
|
+
`);for(const O of N){const[j,k]=Vt(B(O),v,c,s?.contentAlign);r.write(`${l}${f}${" ".repeat(j)}${O}${" ".repeat(k)}${f}
|
|
15
|
+
`)}r.write(`${l}${g[2]}${p.repeat(v)}${g[3]}
|
|
16
|
+
`)},ue=t=>{const i=t.active??"Yes",s=t.inactive??"No";return new Dt({active:i,inactive:s,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue??!0,render(){const r=t.withGuide??T.withGuide,u=`${P(this.state)} `,n=r?`${e("gray",$)} `:"",a=E(t.output,t.message,n,u),c=`${r?`${e("gray",$)}
|
|
17
|
+
`:""}${a}
|
|
18
|
+
`,o=this.value?i:s;switch(this.state){case"submit":{const l=r?`${e("gray",$)} `:"";return`${c}${l}${e("dim",o)}`}case"cancel":{const l=r?`${e("gray",$)} `:"";return`${c}${l}${e(["strikethrough","dim"],o)}${r?`
|
|
19
|
+
${e("gray",$)}`:""}`}default:{const l=r?`${e("cyan",$)} `:"",d=r?e("cyan",x):"";return`${c}${l}${this.value?`${e("green",z)} ${i}`:`${e("dim",U)} ${e("dim",i)}`}${t.vertical?r?`
|
|
20
|
+
${e("cyan",$)} `:`
|
|
21
|
+
`:` ${e("dim","/")} `}${this.value?`${e("dim",U)} ${e("dim",s)}`:`${e("green",z)} ${s}`}
|
|
22
|
+
${d}
|
|
23
|
+
`}}}}).prompt()},le=t=>{const i=t.validate;return new Wt({...t,validate(s){if(s===void 0)return t.defaultValue!==void 0?void 0:i?i(s):T.date.messages.required;const r=u=>u.toISOString().slice(0,10);if(t.minDate&&r(s)<r(t.minDate))return T.date.messages.afterMin(t.minDate);if(t.maxDate&&r(s)>r(t.maxDate))return T.date.messages.beforeMax(t.maxDate);if(i)return i(s)},render(){const s=(t?.withGuide??T.withGuide)!==!1,r=`${`${s?`${e("gray",$)}
|
|
24
|
+
`:""}${P(this.state)} `}${t.message}
|
|
25
|
+
`,u=this.state!=="initial"?this.state:"active",n=ce(this,u),a=this.value instanceof Date?this.formattedValue:"";switch(this.state){case"error":{const c=this.error?` ${e("yellow",this.error)}`:"",o=s?`${e("yellow",$)} `:"",l=s?e("yellow",x):"";return`${r.trim()}
|
|
26
|
+
${o}${n}
|
|
27
|
+
${l}${c}
|
|
28
|
+
`}case"submit":{const c=a?` ${e("dim",a)}`:"",o=s?e("gray",$):"";return`${r}${o}${c}`}case"cancel":{const c=a?` ${e(["strikethrough","dim"],a)}`:"",o=s?e("gray",$):"";return`${r}${o}${c}${a.trim()?`
|
|
29
|
+
${o}`:""}`}default:{const c=s?`${e("cyan",$)} `:"",o=s?e("cyan",x):"",l=s?`${e("cyan",$)} `:"",d=this.inlineError?`
|
|
30
|
+
${l}${e("yellow",this.inlineError)}`:"";return`${r}${c}${n}${d}
|
|
31
|
+
${o}
|
|
32
|
+
`}}}}).prompt()};function ce(t,i){const s=t.segmentValues,r=t.segmentCursor;if(i==="submit"||i==="cancel")return t.formattedValue;const u=e("gray",t.separator);return t.segments.map((n,a)=>{const c=a===r.segmentIndex&&!["submit","cancel"].includes(i),o=de[n.type];return $e(s[n.type],{isActive:c,label:o})}).join(u)}function $e(t,i){const s=!t||t.replace(/_/g,"")==="";return i.isActive?e("inverse",s?i.label:t.replace(/_/g," ")):s?e("dim",i.label):t.replace(/_/g,e("dim"," "))}const de={year:"yyyy",month:"mm",day:"dd"},he=async(t,i)=>{const s={},r=Object.keys(t);for(const u of r){const n=t[u],a=await n({results:s})?.catch(c=>{throw c});if(typeof i?.onCancel=="function"&&Ft(a)){s[u]="canceled",i.onCancel({results:s});continue}s[u]=a}return s},pe=t=>{const{selectableGroups:i=!0,groupSpacing:s=0}=t,r=(n,a,c=[])=>{const o=n.label??String(n.value),l=typeof n.group=="string",d=l&&(c[c.indexOf(n)+1]??{group:!0}),g=l&&d&&d.group===!0;let p="",f="";l&&(i?(p=g?`${x} `:`${$} `,f=g?" ":`${$} `):p=" ");let h="";if(s>0&&!l&&(h=`
|
|
33
|
+
`.repeat(s)),a==="active")return E(t.output,`${o}${n.hint?` ${e("dim",`(${n.hint})`)}`:""}`,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${e("cyan",et)} `,`${h}${e("dim",f)} `);if(a==="group-active")return E(t.output,o,`${h}${p} `,`${h}${p}${e("cyan",et)} `,`${h}${f} `,m=>e("dim",m));if(a==="group-active-selected")return E(t.output,o,`${h}${p} `,`${h}${p}${e("green",K)} `,`${h}${f} `,m=>e("dim",m));if(a==="selected"){const m=l||i?e("green",K):"";return E(t.output,`${o}${n.hint?` (${n.hint})`:""}`,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${m} `,`${h}${e("dim",f)} `,y=>e("dim",y))}if(a==="cancelled")return`${e(["strikethrough","dim"],o)}`;if(a==="active-selected")return E(t.output,`${o}${n.hint?` ${e("dim",`(${n.hint})`)}`:""}`,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${e("green",K)} `,`${h}${e("dim",f)} `);if(a==="submitted")return`${e("dim",o)}`;const I=l||i?e("dim",Y):"";return E(t.output,o,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${I} `,`${h}${e("dim",f)} `,m=>e("dim",m))},u=t.required??!0;return new Ht({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValues:t.initialValues,required:u,cursorAt:t.cursorAt,selectableGroups:i,validate(n){if(u&&(n===void 0||n.length===0))return`Please select at least one option.
|
|
34
|
+
${e("reset",e("dim",`Press ${e(["gray","bgWhite","inverse"]," space ")} to select, ${e("gray",e(["bgWhite","inverse"]," enter "))} to submit`))}`},render(){const n=t.withGuide??T.withGuide,a=`${n?`${e("gray",$)}
|
|
35
|
+
`:""}${P(this.state)} ${t.message}
|
|
36
|
+
`,c=this.value??[],o=(l,d)=>{const g=this.options,p=c.includes(l.value)||l.group===!0&&this.isGroupSelected(`${l.value}`);return!d&&typeof l.group=="string"&&this.options[this.cursor].value===l.group?r(l,p?"group-active-selected":"group-active",g):d&&p?r(l,"active-selected",g):p?r(l,"selected",g):r(l,d?"active":"inactive",g)};switch(this.state){case"submit":{const l=this.options.filter(({value:g})=>c.includes(g)).map(g=>r(g,"submitted")),d=l.length===0?"":` ${l.join(e("dim",", "))}`;return`${a}${n?e("gray",$):""}${d}`}case"cancel":{const l=this.options.filter(({value:d})=>c.includes(d)).map(d=>r(d,"cancelled")).join(e("dim",", "));return`${a}${n?`${e("gray",$)} `:""}${l.trim()?`${l}${n?`
|
|
37
|
+
${e("gray",$)}`:""}`:""}`}case"error":{const l=n?`${e("yellow",$)} `:"",d=this.error.split(`
|
|
38
|
+
`).map((h,I)=>I===0?`${n?`${e("yellow",x)} `:""}${e("yellow",h)}`:` ${h}`).join(`
|
|
39
|
+
`),g=a.split(`
|
|
40
|
+
`).length,p=d.split(`
|
|
41
|
+
`).length+1,f=F({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:l.length,rowPadding:g+p,style:o}).join(`
|
|
42
|
+
${l}`);return`${a}${l}${f}
|
|
43
|
+
${d}
|
|
44
|
+
`}default:{const l=n?`${e("cyan",$)} `:"",d=a.split(`
|
|
45
|
+
`).length,g=(n?1:0)+1,p=F({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:l.length,rowPadding:d+g,style:o}).join(`
|
|
46
|
+
${l}`);return`${a}${l}${p}
|
|
47
|
+
${n?e("cyan",x):""}
|
|
48
|
+
`}}}}).prompt()},R={message:(t=[],{symbol:i=e("gray",$),secondarySymbol:s=e("gray",$),output:r=process.stdout,spacing:u=1,withGuide:n}={})=>{const a=[],c=n??T.withGuide,o=c?s:"",l=c?`${i} `:"",d=c?`${s} `:"";for(let p=0;p<u;p++)a.push(o);const g=Array.isArray(t)?t:t.split(`
|
|
49
|
+
`);if(g.length>0){const[p,...f]=g;p.length>0?a.push(`${l}${p}`):a.push(c?i:"");for(const h of f)h.length>0?a.push(`${d}${h}`):a.push(c?s:"")}r.write(`${a.join(`
|
|
50
|
+
`)}
|
|
51
|
+
`)},info:(t,i)=>{R.message(t,{...i,symbol:e("blue",ht)})},success:(t,i)=>{R.message(t,{...i,symbol:e("green",pt)})},step:(t,i)=>{R.message(t,{...i,symbol:e("green",H)})},warn:(t,i)=>{R.message(t,{...i,symbol:e("yellow",mt)})},warning:(t,i)=>{R.warn(t,i)},error:(t,i)=>{R.message(t,{...i,symbol:e("red",gt)})}},me=(t="",i)=>{const s=i?.output??process.stdout,r=i?.withGuide??T.withGuide?`${e("gray",x)} `:"";s.write(`${r}${e("red",t)}
|
|
52
|
+
|
|
53
|
+
`)},ge=(t="",i)=>{const s=i?.output??process.stdout,r=i?.withGuide??T.withGuide?`${e("gray",lt)} `:"";s.write(`${r}${t}
|
|
54
|
+
`)},ye=(t="",i)=>{const s=i?.output??process.stdout,r=i?.withGuide??T.withGuide?`${e("gray",$)}
|
|
55
|
+
${e("gray",x)} `:"";s.write(`${r}${t}
|
|
56
|
+
|
|
57
|
+
`)},fe=t=>new Ut({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,showSubmit:t.showSubmit,output:t.output,signal:t.signal,input:t.input,render(){const i=t?.withGuide??T.withGuide,s=`${`${i?`${e("gray",$)}
|
|
58
|
+
`:""}${P(this.state)} `}${t.message}
|
|
59
|
+
`,r=t.placeholder?e("inverse",t.placeholder[0])+e("dim",t.placeholder.slice(1)):e(["inverse","hidden"],"_"),u=this.userInput?this.userInputWithCursor:r,n=this.value??"",a=t.showSubmit?`
|
|
60
|
+
${e(this.focused==="submit"?"cyan":"dim","[ submit ]")}`:"";switch(this.state){case"error":{const c=`${e("yellow",$)} `,o=i?E(t.output,u,c,void 0):u,l=e("yellow",x);return`${s}${o}
|
|
61
|
+
${l} ${e("yellow",this.error)}${a}
|
|
62
|
+
`}case"submit":{const c=`${e("gray",$)} `,o=i?E(t.output,n,c,void 0,void 0,l=>e("dim",l)):n?e("dim",n):"";return`${s}${o}`}case"cancel":{const c=`${e("gray",$)} `,o=i?E(t.output,n,c,void 0,void 0,l=>e(["strikethrough","dim"],l)):n?e(["strikethrough","dim"],n):"";return`${s}${o}`}default:{const c=i?`${e("cyan",$)} `:"",o=i?e("cyan",x):"",l=i?E(t.output,u,c):u;return`${s}${l}
|
|
63
|
+
${o}${a}
|
|
64
|
+
`}}}}).prompt(),Q=(t,i)=>t.split(`
|
|
65
|
+
`).map(s=>i(s)).join(`
|
|
66
|
+
`),ve=t=>{const i=(r,u)=>{const n=r.label??String(r.value);return u==="disabled"?`${e("gray",Y)} ${Q(n,a=>e(["strikethrough","gray"],a))}${r.hint?` ${e("dim",`(${r.hint??"disabled"})`)}`:""}`:u==="active"?`${e("cyan",et)} ${n}${r.hint?` ${e("dim",`(${r.hint})`)}`:""}`:u==="selected"?`${e("green",K)} ${Q(n,a=>e("dim",a))}${r.hint?` ${e("dim",`(${r.hint})`)}`:""}`:u==="cancelled"?`${Q(n,a=>e(["strikethrough","dim"],a))}`:u==="active-selected"?`${e("green",K)} ${n}${r.hint?` ${e("dim",`(${r.hint})`)}`:""}`:u==="submitted"?`${Q(n,a=>e("dim",a))}`:`${e("dim",Y)} ${Q(n,a=>e("dim",a))}`},s=t.required??!0;return new Kt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValues:t.initialValues,required:s,cursorAt:t.cursorAt,validate(r){if(s&&(r===void 0||r.length===0))return`Please select at least one option.
|
|
67
|
+
${e("reset",e("dim",`Press ${e(["gray","bgWhite","inverse"]," space ")} to select, ${e("gray",e("bgWhite",e("inverse"," enter ")))} to submit`))}`},render(){const r=t.withGuide??T.withGuide,u=E(t.output,t.message,r?`${yt(this.state)} `:"",`${P(this.state)} `),n=`${r?`${e("gray",$)}
|
|
68
|
+
`:""}${u}
|
|
69
|
+
`,a=this.value??[],c=(o,l)=>{if(o.disabled)return i(o,"disabled");const d=a.includes(o.value);return l&&d?i(o,"active-selected"):d?i(o,"selected"):i(o,l?"active":"inactive")};switch(this.state){case"submit":{const o=this.options.filter(({value:d})=>a.includes(d)).map(d=>i(d,"submitted")).join(e("dim",", "))||e("dim","none"),l=E(t.output,o,r?`${e("gray",$)} `:"");return`${n}${l}`}case"cancel":{const o=this.options.filter(({value:d})=>a.includes(d)).map(d=>i(d,"cancelled")).join(e("dim",", "));if(o.trim()==="")return`${n}${e("gray",$)}`;const l=E(t.output,o,r?`${e("gray",$)} `:"");return`${n}${l}${r?`
|
|
70
|
+
${e("gray",$)}`:""}`}case"error":{const o=r?`${e("yellow",$)} `:"",l=this.error.split(`
|
|
71
|
+
`).map((p,f)=>f===0?`${r?`${e("yellow",x)} `:""}${e("yellow",p)}`:` ${p}`).join(`
|
|
72
|
+
`),d=n.split(`
|
|
73
|
+
`).length,g=l.split(`
|
|
74
|
+
`).length+1;return`${n}${o}${F({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:o.length,rowPadding:d+g,style:c}).join(`
|
|
75
|
+
${o}`)}
|
|
76
|
+
${l}
|
|
77
|
+
`}default:{const o=r?`${e("cyan",$)} `:"",l=n.split(`
|
|
78
|
+
`).length,d=r?2:1;return`${n}${o}${F({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:o.length,rowPadding:l+d,style:c}).join(`
|
|
79
|
+
${o}`)}
|
|
80
|
+
${r?e("cyan",x):""}
|
|
81
|
+
`}}}}).prompt()},we=t=>e("dim",t),be=(t,i,s)=>{const r={hard:!0,trim:!1},u=J(t,i,r).split(`
|
|
82
|
+
`),n=u.reduce((o,l)=>Math.max(B(l),o),0),a=u.map(s).reduce((o,l)=>Math.max(B(l),o),0),c=i-(a-n);return J(t,c,r)},Se=(t="",i="",s)=>{const r=s?.output??V.stdout,u=s?.withGuide??T.withGuide,n=s?.format??we,a=["",...be(t,X(r)-6,n).split(`
|
|
83
|
+
`).map(n),""],c=B(i),o=Math.max(a.reduce((p,f)=>{const h=B(f);return h>p?h:p},0),c)+2,l=a.map(p=>`${e("gray",$)} ${p}${" ".repeat(o-B(p))}${e("gray",$)}`).join(`
|
|
84
|
+
`),d=u?`${e("gray",$)}
|
|
85
|
+
`:"",g=u?Gt:dt;r.write(`${d}${e("green",H)} ${e("reset",i)} ${e("gray",st.repeat(Math.max(o-c-1,1))+ct)}
|
|
86
|
+
${l}
|
|
87
|
+
${e("gray",g+st.repeat(o+2)+$t)}
|
|
88
|
+
`)},Ce=t=>new qt({validate:t.validate,mask:t.mask??Et,signal:t.signal,input:t.input,output:t.output,render(){const i=t.withGuide??T.withGuide,s=`${i?`${e("gray",$)}
|
|
89
|
+
`:""}${P(this.state)} ${t.message}
|
|
90
|
+
`,r=this.userInputWithCursor,u=this.masked;switch(this.state){case"error":{const n=i?`${e("yellow",$)} `:"",a=i?`${e("yellow",x)} `:"",c=u??"";return t.clearOnError&&this.clear(),`${s.trim()}
|
|
91
|
+
${n}${c}
|
|
92
|
+
${a}${e("yellow",this.error)}
|
|
93
|
+
`}case"submit":{const n=i?`${e("gray",$)} `:"",a=u?e("dim",u):"";return`${s}${n}${a}`}case"cancel":{const n=i?`${e("gray",$)} `:"",a=u?e(["strikethrough","dim"],u):"";return`${s}${n}${a}${u&&i?`
|
|
94
|
+
${e("gray",$)}`:""}`}default:{const n=i?`${e("cyan",$)} `:"",a=i?e("cyan",x):"";return`${s}${n}${r}
|
|
95
|
+
${a}
|
|
96
|
+
`}}}}).prompt(),Ie=t=>{const i=t.validate;return At({...t,initialUserInput:t.initialValue??t.root??process.cwd(),maxItems:5,validate(s){if(!Array.isArray(s)){if(!s)return"Please select a path";if(i)return i(s)}},options(){const s=this.userInput;if(s==="")return[];try{let r;Qt(s)?wt(s).isDirectory()&&(!t.directory||s.endsWith("/"))?r=s:r=bt(s):r=bt(s);const u=s.length>1&&s.endsWith("/")?s.slice(0,-1):s;return Zt(r).map(n=>{const a=te(r,n),c=wt(a);return{name:n,path:a,isDirectory:c.isDirectory()}}).filter(({path:n,isDirectory:a})=>n.startsWith(u)&&(a||!t.directory)).map(n=>({value:n.path}))}catch{return[]}}})},Te=t=>e("magenta",t),ft=({indicator:t="dots",onCancel:i,output:s=process.stdout,cancelMessage:r,errorMessage:u,frames:n=tt?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:a=tt?80:120,signal:c,...o}={})=>{const l=ot();let d,g,p=!1,f=!1,h="",I,m=performance.now();const y=X(s),v=o?.styleFrame??Te,C=_=>{const A=_>1?u??T.messages.error:r??T.messages.cancel;f=_===1,p&&(W(A,_),f&&typeof i=="function"&&i())},S=()=>C(2),b=()=>C(1),G=()=>{process.on("uncaughtExceptionMonitor",S),process.on("unhandledRejection",S),process.on("SIGINT",b),process.on("SIGTERM",b),process.on("exit",C),c&&c.addEventListener("abort",b)},M=()=>{process.removeListener("uncaughtExceptionMonitor",S),process.removeListener("unhandledRejection",S),process.removeListener("SIGINT",b),process.removeListener("SIGTERM",b),process.removeListener("exit",C),c&&c.removeEventListener("abort",b)},N=()=>{if(I===void 0)return;l&&s.write(`
|
|
97
|
+
`);const _=J(I,y,{hard:!0,trim:!1}).split(`
|
|
98
|
+
`);_.length>1&&s.write(St.up(_.length-1)),s.write(St.to(0)),s.write(Ct.down())},O=_=>_.replace(/\.+$/,""),j=_=>{const A=(performance.now()-_)/1e3,L=Math.floor(A/60),D=Math.floor(A%60);return L>0?`[${L}m ${D}s]`:`[${D}s]`},k=o.withGuide??T.withGuide,rt=(_="")=>{p=!0,d=Jt({output:s}),h=O(_),m=performance.now(),k&&s.write(`${e("gray",$)}
|
|
99
|
+
`);let A=0,L=0;G(),g=setInterval(()=>{if(l&&h===I)return;N(),I=h;const D=v(n[A]);let Z;if(l)Z=`${D} ${h}...`;else if(t==="timer")Z=`${D} ${h} ${j(m)}`;else{const kt=".".repeat(Math.floor(L)).slice(0,3);Z=`${D} ${h}${kt}`}const Bt=J(Z,y,{hard:!0,trim:!1});s.write(Bt),A=A+1<n.length?A+1:0,L=L<4?L+.125:0},a)},W=(_="",A=0,L=!1)=>{if(!p)return;p=!1,clearInterval(g),N();const D=A===0?e("green",H):A===1?e("red",at):e("red",ut);h=_??h,L||(t==="timer"?s.write(`${D} ${h} ${j(m)}
|
|
100
|
+
`):s.write(`${D} ${h}
|
|
101
|
+
`)),M(),d()};return{start:rt,stop:(_="")=>W(_,0),message:(_="")=>{h=O(_??h)},cancel:(_="")=>W(_,1),error:(_="")=>W(_,2),clear:()=>W("",0,!0),get isCancelled(){return f}}},jt={light:w("\u2500","-"),heavy:w("\u2501","="),block:w("\u2588","#")};function _e({style:t="heavy",max:i=100,size:s=40,...r}={}){const u=ft(r);let n=0,a="";const c=Math.max(1,i),o=Math.max(1,s),l=f=>{switch(f){case"initial":case"active":return h=>e("magenta",h);case"error":case"cancel":return h=>e("red",h);case"submit":return h=>e("green",h);default:return h=>e("magenta",h)}},d=(f,h)=>{const I=Math.floor(n/c*o);return`${l(f)(jt[t].repeat(I))}${e("dim",jt[t].repeat(o-I))} ${h}`},g=(f="")=>{a=f,u.start(d("initial",f))},p=(f=1,h)=>{n=Math.min(c,f+n),u.message(d("active",h??a)),a=h??a};return{start:g,stop:u.stop,cancel:u.cancel,error:u.error,clear:u.clear,advance:p,isCancelled:u.isCancelled,message:f=>p(0,f)}}const it=(t,i)=>t.includes(`
|
|
102
|
+
`)?t.split(`
|
|
103
|
+
`).map(s=>i(s)).join(`
|
|
104
|
+
`):i(t),xe=t=>{const i=(s,r)=>{const u=s.label??String(s.value);switch(r){case"disabled":return`${e("gray",U)} ${it(u,n=>e("gray",n))}${s.hint?` ${e("dim",`(${s.hint??"disabled"})`)}`:""}`;case"selected":return`${it(u,n=>e("dim",n))}`;case"active":return`${e("green",z)} ${u}${s.hint?` ${e("dim",`(${s.hint})`)}`:""}`;case"cancelled":return`${it(u,n=>e(["strikethrough","dim"],n))}`;default:return`${e("dim",U)} ${it(u,n=>e("dim",n))}`}};return new Yt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){const s=t.withGuide??T.withGuide,r=`${P(this.state)} `,u=`${yt(this.state)} `,n=E(t.output,t.message,u,r),a=`${s?`${e("gray",$)}
|
|
105
|
+
`:""}${n}
|
|
106
|
+
`;switch(this.state){case"submit":{const c=s?`${e("gray",$)} `:"",o=E(t.output,i(this.options[this.cursor],"selected"),c);return`${a}${o}`}case"cancel":{const c=s?`${e("gray",$)} `:"",o=E(t.output,i(this.options[this.cursor],"cancelled"),c);return`${a}${o}${s?`
|
|
107
|
+
${e("gray",$)}`:""}`}default:{const c=s?`${e("cyan",$)} `:"",o=s?e("cyan",x):"",l=a.split(`
|
|
108
|
+
`).length,d=s?2:1;return`${a}${c}${F({output:t.output,cursor:this.cursor,options:this.options,maxItems:t.maxItems,columnPadding:c.length,rowPadding:l+d,style:(g,p)=>i(g,g.disabled?"disabled":p?"active":"inactive")}).join(`
|
|
109
|
+
${c}`)}
|
|
110
|
+
${o}
|
|
111
|
+
`}}}}).prompt()},Ee=t=>{const i=(s,r="inactive")=>{const u=s.label??String(s.value);return r==="selected"?`${e("dim",u)}`:r==="cancelled"?`${e(["strikethrough","dim"],u)}`:r==="active"?`${e(["bgCyan","gray"],` ${s.value} `)} ${u}${s.hint?` ${e("dim",`(${s.hint})`)}`:""}`:`${e(["gray","bgWhite","inverse"],` ${s.value} `)} ${u}${s.hint?` ${e("dim",`(${s.hint})`)}`:""}`};return new Xt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,caseSensitive:t.caseSensitive,render(){const s=t.withGuide??T.withGuide,r=`${s?`${e("gray",$)}
|
|
112
|
+
`:""}${P(this.state)} ${t.message}
|
|
113
|
+
`;switch(this.state){case"submit":{const u=s?`${e("gray",$)} `:"",n=this.options.find(c=>c.value===this.value)??t.options[0],a=E(t.output,i(n,"selected"),u);return`${r}${a}`}case"cancel":{const u=s?`${e("gray",$)} `:"",n=E(t.output,i(this.options[0],"cancelled"),u);return`${r}${n}${s?`
|
|
114
|
+
${e("gray",$)}`:""}`}default:{const u=s?`${e("cyan",$)} `:"",n=s?e("cyan",x):"",a=this.options.map((c,o)=>E(t.output,i(c,o===this.cursor?"active":"inactive"),u)).join(`
|
|
115
|
+
`);return`${r}${a}
|
|
116
|
+
${n}
|
|
117
|
+
`}}}}).prompt()},Nt=`${e("gray",$)} `,q={message:async(t,{symbol:i=e("gray",$)}={})=>{process.stdout.write(`${e("gray",$)}
|
|
118
|
+
${i} `);let s=3;for await(let r of t){r=r.replace(/\n/g,`
|
|
119
|
+
${Nt}`),r.includes(`
|
|
120
|
+
`)&&(s=3+nt(r.slice(r.lastIndexOf(`
|
|
121
|
+
`))).length);const u=nt(r).length;s+u<process.stdout.columns?(s+=u,process.stdout.write(r)):(process.stdout.write(`
|
|
122
|
+
${Nt}${r.trimStart()}`),s=3+nt(r.trimStart()).length)}process.stdout.write(`
|
|
123
|
+
`)},info:t=>q.message(t,{symbol:e("blue",ht)}),success:t=>q.message(t,{symbol:e("green",pt)}),step:t=>q.message(t,{symbol:e("green",H)}),warn:t=>q.message(t,{symbol:e("yellow",mt)}),warning:t=>q.warn(t),error:t=>q.message(t,{symbol:e("red",gt)})},Ge=async(t,i)=>{for(const s of t){if(s.enabled===!1)continue;const r=ft(i);r.start(s.title);const u=await s.task(r.message);r.stop(u||s.title)}},Me=t=>t.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g,""),Oe=t=>{const i=t.output??process.stdout,s=X(i),r=e("gray",$),u=t.spacing??1,n=3,a=t.retainLog===!0,c=!ot()&&It(i);i.write(`${r}
|
|
124
|
+
`),i.write(`${e("green",H)} ${t.title}
|
|
125
|
+
`);for(let m=0;m<u;m++)i.write(`${r}
|
|
126
|
+
`);const o=[{value:"",full:""}];let l=!1;const d=m=>{if(o.length===0)return;let y=0;m&&(y+=u+2);for(const v of o){const{value:C,result:S}=v;let b=S?.message??C;if(b.length===0)continue;S===void 0&&v.header!==void 0&&v.header!==""&&(b+=`
|
|
127
|
+
${v.header}`);const G=b.split(`
|
|
128
|
+
`).reduce((M,N)=>N===""?M+1:M+Math.ceil((N.length+n)/s),0);y+=G}y>0&&(y+=1,i.write(Ct.lines(y)))},g=(m,y,v)=>{const C=v?`${m.full}
|
|
129
|
+
${m.value}`:m.value;m.header!==void 0&&m.header!==""&&R.message(m.header.split(`
|
|
130
|
+
`).map(S=>e("bold",S)),{output:i,secondarySymbol:r,symbol:r,spacing:0}),R.message(C.split(`
|
|
131
|
+
`).map(S=>e("dim",S)),{output:i,secondarySymbol:r,symbol:r,spacing:y??u})},p=()=>{for(const m of o){const{header:y,value:v,full:C}=m;(y===void 0||y.length===0)&&v.length===0||g(m,void 0,a===!0&&C.length>0)}},f=(m,y,v)=>{if(d(!1),(v?.raw!==!0||!l)&&m.value!==""&&(m.value+=`
|
|
132
|
+
`),m.value+=Me(y),l=v?.raw===!0,t.limit!==void 0){const C=m.value.split(`
|
|
133
|
+
`),S=C.length-t.limit;if(S>0){const b=C.splice(0,S);a&&(m.full+=(m.full===""?"":`
|
|
134
|
+
`)+b.join(`
|
|
135
|
+
`))}m.value=C.join(`
|
|
136
|
+
`)}c&&h()},h=()=>{for(const m of o)m.result?m.result.status==="error"?R.error(m.result.message,{output:i,secondarySymbol:r,spacing:0}):R.success(m.result.message,{output:i,secondarySymbol:r,spacing:0}):m.value!==""&&g(m,0)},I=(m,y)=>{d(!1),m.result=y,c&&h()};return{message(m,y){f(o[0],m,y)},group(m){const y={header:m,value:"",full:""};return o.push(y),{message(v,C){f(y,v,C)},error(v){I(y,{status:"error",message:v})},success(v){I(y,{status:"success",message:v})}}},error(m,y){d(!0),R.error(m,{output:i,secondarySymbol:r,spacing:1}),y?.showLog!==!1&&p(),o.splice(1,o.length-1),o[0].value="",o[0].full=""},success(m,y){d(!0),R.success(m,{output:i,secondarySymbol:r,spacing:1}),y?.showLog===!0&&p(),o.splice(1,o.length-1),o[0].value="",o[0].full=""}}},Pe=t=>new zt({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,output:t.output,signal:t.signal,input:t.input,render(){const i=t?.withGuide??T.withGuide,s=`${`${i?`${e("gray",$)}
|
|
137
|
+
`:""}${P(this.state)} `}${t.message}
|
|
138
|
+
`,r=t.placeholder?e("inverse",t.placeholder[0])+e("dim",t.placeholder.slice(1)):e(["inverse","hidden"],"_"),u=this.userInput?this.userInputWithCursor:r,n=this.value??"";switch(this.state){case"error":{const a=this.error?` ${e("yellow",this.error)}`:"",c=i?`${e("yellow",$)} `:"",o=i?e("yellow",x):"";return`${s.trim()}
|
|
139
|
+
${c}${u}
|
|
140
|
+
${o}${a}
|
|
141
|
+
`}case"submit":{const a=n?` ${e("dim",n)}`:"",c=i?e("gray",$):"";return`${s}${c}${a}`}case"cancel":{const a=n?` ${e(["strikethrough","dim"],n)}`:"",c=i?e("gray",$):"";return`${s}${c}${a}${n.trim()?`
|
|
142
|
+
${c}`:""}`}default:{const a=i?`${e("cyan",$)} `:"",c=i?e("cyan",x):"";return`${s}${a}${u}
|
|
143
|
+
${c}
|
|
144
|
+
`}}}}).prompt();export{$ as S_BAR,x as S_BAR_END,xt as S_BAR_END_RIGHT,st as S_BAR_H,lt as S_BAR_START,_t as S_BAR_START_RIGHT,et as S_CHECKBOX_ACTIVE,Y as S_CHECKBOX_INACTIVE,K as S_CHECKBOX_SELECTED,Gt as S_CONNECT_LEFT,dt as S_CORNER_BOTTOM_LEFT,$t as S_CORNER_BOTTOM_RIGHT,Mt as S_CORNER_TOP_LEFT,ct as S_CORNER_TOP_RIGHT,gt as S_ERROR,ht as S_INFO,Et as S_PASSWORD_MASK,z as S_RADIO_ACTIVE,U as S_RADIO_INACTIVE,Tt as S_STEP_ACTIVE,at as S_STEP_CANCEL,ut as S_STEP_ERROR,H as S_STEP_SUBMIT,pt as S_SUCCESS,mt as S_WARN,At as autocomplete,ie as autocompleteMultiselect,ae as box,me as cancel,ue as confirm,le as date,he as group,pe as groupMultiselect,ge as intro,ot as isCI,It as isTTY,F as limitOptions,R as log,fe as multiline,ve as multiselect,Se as note,ye as outro,Ce as password,Ie as path,_e as progress,xe as select,Ee as selectKey,ft as spinner,q as stream,P as symbol,yt as symbolBar,Oe as taskLog,Ge as tasks,Pe as text,tt as unicode,w as unicodeOr};
|
|
145
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clack/prompts",
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.mjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.mts",
|
|
10
|
+
"default": "./dist/index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/index.d.mts",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/bombshell-dev/clack.git",
|
|
18
|
+
"directory": "packages/prompts"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/bombshell-dev/clack/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/bombshell-dev/clack/tree/main/packages/prompts#readme",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"CHANGELOG.md"
|
|
27
|
+
],
|
|
28
|
+
"author": {
|
|
29
|
+
"name": "Nate Moore",
|
|
30
|
+
"email": "nate@natemoo.re",
|
|
31
|
+
"url": "https://twitter.com/n_moore"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"ask",
|
|
36
|
+
"clack",
|
|
37
|
+
"cli",
|
|
38
|
+
"command-line",
|
|
39
|
+
"command",
|
|
40
|
+
"input",
|
|
41
|
+
"interact",
|
|
42
|
+
"interface",
|
|
43
|
+
"menu",
|
|
44
|
+
"prompt",
|
|
45
|
+
"prompts",
|
|
46
|
+
"stdin",
|
|
47
|
+
"ui"
|
|
48
|
+
],
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">= 20.12.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"fast-string-width": "^3.0.2",
|
|
54
|
+
"fast-wrap-ansi": "^0.2.0",
|
|
55
|
+
"sisteransi": "^1.0.5",
|
|
56
|
+
"@clack/core": "1.3.1"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"is-unicode-supported": "^1.3.0",
|
|
60
|
+
"memfs": "^4.17.2",
|
|
61
|
+
"vitest": "^3.2.4",
|
|
62
|
+
"vitest-ansi-serializer": "^0.1.2"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "unbuild",
|
|
66
|
+
"test": "vitest run"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).dayjs=e()}(this,(function(){"use strict";var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return"["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return+(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",D={};D[g]=M;var p="$isDayjsObject",S=function(t){return t instanceof _||!(!t||!t[p])},w=function t(e,n,r){var i;if(!e)return g;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else{var a=e.name;D[a]=e,i=a}return!r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init()},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},m.$utils=function(){return b},m.isValid=function(){return!(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<O(t)},m.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!b.u(e)||e,f=b.p(t),l=function(t,e){var i=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+"Hours",0);case u:return $(v+"Minutes",1);case s:return $(v+"Seconds",2);case i:return $(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=b.p(t),f="set"+(this.$u?"UTC":""),l=(n={},n[a]=f+"Date",n[d]=f+"Date",n[c]=f+"Month",n[h]=f+"FullYear",n[u]=f+"Hours",n[s]=f+"Minutes",n[i]=f+"Seconds",n[r]=f+"Milliseconds",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[b.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=b.p(f),y=function(t){var e=O(l);return b.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return b.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=b.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return b.s(s%12||12,t,"0")},$=f||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return b.s(e.$y,4,"0");case"M":return a+1;case"MM":return b.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,c,3);case"MMMM":return h(c,a);case"D":return e.$D;case"DD":return b.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,o,2);case"ddd":return h(n.weekdaysShort,e.$W,o,3);case"dddd":return o[e.$W];case"H":return String(s);case"HH":return b.s(s,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return $(s,u,!0);case"A":return $(s,u,!1);case"m":return String(u);case"mm":return b.s(u,2,"0");case"s":return String(e.$s);case"ss":return b.s(e.$s,2,"0");case"SSS":return b.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=b.p(d),m=O(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return b.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g}return l?$:b.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=w(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return b.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),Y=_.prototype;return O.prototype=Y,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",c],["$y",h],["$D",d]].forEach((function(t){Y[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),O.extend=function(t,e){return t.$i||(t(e,_,O),t.$i=!0),O},O.locale=w,O.isDayjs=S,O.unix=function(t){return O(1e3*t)},O.en=D[g],O.Ls=D,O.p={},O}));
|