@kubb/agent 5.0.0-alpha.35 → 5.0.0-alpha.36
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/.output/nitro.json +1 -1
- package/.output/server/chunks/nitro/nitro.mjs +1293 -20554
- package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
- package/.output/server/chunks/routes/api/health.get.mjs +16 -14
- package/.output/server/chunks/routes/api/health.get.mjs.map +1 -1
- package/.output/server/index.mjs +16 -14
- package/.output/server/index.mjs.map +1 -1
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/constants.js +18 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/permessage-deflate.js +514 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/sender.js +602 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/stream.js +159 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/websocket-server.js +540 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/websocket.js +1388 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/package.json +69 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/wrapper.mjs +8 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/buffer-util.js +131 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/event-target.js +292 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/extension.js +203 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/limiter.js +55 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/receiver.js +706 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/subprotocol.js +62 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/validation.js +152 -0
- package/.output/server/node_modules/@clack/core/dist/index.mjs +11 -0
- package/.output/server/node_modules/@clack/core/package.json +60 -0
- package/.output/server/node_modules/@clack/prompts/dist/index.mjs +137 -0
- package/.output/server/node_modules/@clack/prompts/package.json +65 -0
- package/.output/server/node_modules/@kubb/ast/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/ast/dist/index.js +423 -0
- package/.output/server/node_modules/@kubb/ast/package.json +70 -0
- package/.output/server/node_modules/@kubb/core/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/core/dist/hooks.js +23 -0
- package/.output/server/node_modules/@kubb/core/dist/index.js +2311 -0
- package/.output/server/node_modules/@kubb/core/package.json +109 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/chunk-O_arW02_.js +17 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/defaultParser-iCpMSYCp.js +15 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/getRelativePath-NAm_Y-vp.js +55 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/index.js +653 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/onProcessExit-Cput7j2c.js +742 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/parsers/typescript.js +101 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/parsers.js +17 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/plugins.js +375 -0
- package/.output/server/node_modules/@kubb/fabric-core/package.json +111 -0
- package/.output/server/node_modules/@kubb/oas/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/oas/dist/index.js +918 -0
- package/.output/server/node_modules/@kubb/oas/package.json +94 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/StaticClassClient-bCe7RG_w.js +636 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/components.js +2 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/generators-BffddRNu.js +723 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/index.js +124 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/templates/clients/axios.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/templates/clients/fetch.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/templates/config.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-client/package.json +153 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/components-BK_6GU4v.js +257 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/generators-D5YFtyyC.js +71 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/index.js +79 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/package.json +108 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/components-BkBIov4R.js +419 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/fakerGenerator-BztogaeO.js +200 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/index.js +141 -0
- package/.output/server/node_modules/@kubb/plugin-faker/package.json +103 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/Server-H3SwqhwF.js +178 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/generators-BqkMrcs9.js +274 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/index.js +122 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/package.json +107 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/components-DgtTZkWX.js +277 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/generators-C34kqa1L.js +161 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/index.js +84 -0
- package/.output/server/node_modules/@kubb/plugin-msw/package.json +109 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/SchemaMapper-CqMkO2T1.js +58 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/generators-D7C3CXsN.js +79 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/generators.js +2 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/getFooter-Pw3tLCiV.js +112 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/hooks.js +200 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/index.js +408 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/requestBody-pRavthCw.js +1336 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/utils.js +268 -0
- package/.output/server/node_modules/@kubb/plugin-oas/package.json +122 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/components-CpyHYGOw.js +1520 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/generators-CpiBv5eE.js +1427 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/index.js +166 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/package.json +112 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/dist/index.js +65 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/package.json +85 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/static/redoc.hbs +22 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/components-BhStIi1M.js +665 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/generators-CQClzsST.js +415 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/index.js +145 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/package.json +113 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/components-DntKBsnB.js +666 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/generators-BtTsGGrM.js +414 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/index.js +145 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/package.json +113 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/components-DRDGvgXG.js +702 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/generators-ClWZJ-YG.js +399 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/index.js +144 -0
- package/.output/server/node_modules/@kubb/plugin-swr/package.json +115 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/components-C7fu-sK1.js +723 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/index.js +2 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/plugin-CYC-FGXe.js +479 -0
- package/.output/server/node_modules/@kubb/plugin-ts/package.json +105 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/components-_AMBl0g-.js +1029 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/generators-Zb1s5Wmb.js +661 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/index.js +157 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/package.json +114 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/components-eECfXVou.js +842 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/generators-D1R6NNf2.js +290 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/index.js +175 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/templates/ToZod.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-zod/package.json +112 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/chunk-BGCRLu6H.js +38 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/index.js +525 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/jsx-runtime-Bl0DfUmV.js +1448 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/jsx-runtime.js +12 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/parsers.js +2 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/plugins.js +4 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/reactPlugin-QQPrjNuQ.js +17813 -0
- package/.output/server/node_modules/@kubb/react-fabric/package.json +143 -0
- package/.output/server/node_modules/buffer-from/index.js +72 -0
- package/.output/server/node_modules/buffer-from/package.json +19 -0
- package/.output/server/node_modules/empathic/access.js +39 -0
- package/.output/server/node_modules/empathic/access.mjs +34 -0
- package/.output/server/node_modules/empathic/find.js +81 -0
- package/.output/server/node_modules/empathic/find.mjs +76 -0
- package/.output/server/node_modules/empathic/package.json +49 -0
- package/.output/server/node_modules/empathic/package.mjs +52 -0
- package/.output/server/node_modules/empathic/resolve.js +31 -0
- package/.output/server/node_modules/empathic/resolve.mjs +27 -0
- package/.output/server/node_modules/empathic/walk.js +22 -0
- package/.output/server/node_modules/empathic/walk.mjs +20 -0
- package/.output/server/node_modules/fast-string-truncated-width/dist/index.js +171 -0
- package/.output/server/node_modules/fast-string-truncated-width/dist/utils.js +15 -0
- package/.output/server/node_modules/fast-string-truncated-width/package.json +35 -0
- package/.output/server/node_modules/fast-string-width/dist/index.js +14 -0
- package/.output/server/node_modules/fast-string-width/package.json +34 -0
- package/.output/server/node_modules/fast-wrap-ansi/lib/main.js +216 -0
- package/.output/server/node_modules/fast-wrap-ansi/package.json +51 -0
- package/.output/server/node_modules/p-limit/index.js +127 -0
- package/.output/server/node_modules/p-limit/package.json +58 -0
- package/.output/server/node_modules/react-devtools-core/dist/backend.js +18302 -0
- package/.output/server/node_modules/react-devtools-core/package.json +38 -0
- package/.output/server/node_modules/sisteransi/package.json +34 -0
- package/.output/server/node_modules/sisteransi/src/index.js +58 -0
- package/.output/server/node_modules/source-map-support/package.json +31 -0
- package/.output/server/node_modules/source-map-support/source-map-support.js +625 -0
- package/.output/server/node_modules/typescript/lib/typescript.js +200276 -0
- package/.output/server/node_modules/typescript/package.json +120 -0
- package/.output/server/node_modules/yocto-queue/index.js +90 -0
- package/.output/server/node_modules/yocto-queue/package.json +48 -0
- package/.output/server/package.json +34 -2
- package/package.json +20 -20
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/buffer-util.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/event-target.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/extension.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/limiter.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/receiver.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/subprotocol.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/validation.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/constants.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/permessage-deflate.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/sender.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/stream.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/websocket-server.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/websocket.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/package.json +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/wrapper.mjs +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/* IMPORT */
|
|
2
|
+
import { isAmbiguous, isFullWidth, isWide } from './utils.js';
|
|
3
|
+
/* HELPERS */
|
|
4
|
+
const ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
|
|
5
|
+
const CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
6
|
+
const TAB_RE = /\t{1,1000}/y;
|
|
7
|
+
const 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;
|
|
8
|
+
const LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
9
|
+
const MODIFIER_RE = /\p{M}+/gu;
|
|
10
|
+
const NO_TRUNCATION = { limit: Infinity, ellipsis: '' };
|
|
11
|
+
/* MAIN */
|
|
12
|
+
//TODO: Optimize matching non-latin letters
|
|
13
|
+
const getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
14
|
+
/* CONSTANTS */
|
|
15
|
+
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
16
|
+
const ELLIPSIS = truncationOptions.ellipsis ?? '';
|
|
17
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
|
|
18
|
+
const ANSI_WIDTH = widthOptions.ansiWidth ?? 0;
|
|
19
|
+
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
20
|
+
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
21
|
+
const AMBIGUOUS_WIDTH = widthOptions.ambiguousWidth ?? 1;
|
|
22
|
+
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
23
|
+
const FULL_WIDTH_WIDTH = widthOptions.fullWidthWidth ?? 2;
|
|
24
|
+
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
25
|
+
const WIDE_WIDTH = widthOptions.wideWidth ?? 2;
|
|
26
|
+
/* STATE */
|
|
27
|
+
let indexPrev = 0;
|
|
28
|
+
let index = 0;
|
|
29
|
+
let length = input.length;
|
|
30
|
+
let lengthExtra = 0;
|
|
31
|
+
let truncationEnabled = false;
|
|
32
|
+
let truncationIndex = length;
|
|
33
|
+
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
34
|
+
let unmatchedStart = 0;
|
|
35
|
+
let unmatchedEnd = 0;
|
|
36
|
+
let width = 0;
|
|
37
|
+
let widthExtra = 0;
|
|
38
|
+
/* PARSE LOOP */
|
|
39
|
+
outer: while (true) {
|
|
40
|
+
/* UNMATCHED */
|
|
41
|
+
if ((unmatchedEnd > unmatchedStart) || (index >= length && index > indexPrev)) {
|
|
42
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
43
|
+
lengthExtra = 0;
|
|
44
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, '')) {
|
|
45
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
46
|
+
if (isFullWidth(codePoint)) {
|
|
47
|
+
widthExtra = FULL_WIDTH_WIDTH;
|
|
48
|
+
}
|
|
49
|
+
else if (isWide(codePoint)) {
|
|
50
|
+
widthExtra = WIDE_WIDTH;
|
|
51
|
+
}
|
|
52
|
+
else if (AMBIGUOUS_WIDTH !== REGULAR_WIDTH && isAmbiguous(codePoint)) {
|
|
53
|
+
widthExtra = AMBIGUOUS_WIDTH;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
widthExtra = REGULAR_WIDTH;
|
|
57
|
+
}
|
|
58
|
+
if ((width + widthExtra) > truncationLimit) {
|
|
59
|
+
truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
60
|
+
}
|
|
61
|
+
if ((width + widthExtra) > LIMIT) {
|
|
62
|
+
truncationEnabled = true;
|
|
63
|
+
break outer;
|
|
64
|
+
}
|
|
65
|
+
lengthExtra += char.length;
|
|
66
|
+
width += widthExtra;
|
|
67
|
+
}
|
|
68
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
69
|
+
}
|
|
70
|
+
/* EXITING */
|
|
71
|
+
if (index >= length)
|
|
72
|
+
break;
|
|
73
|
+
/* LATIN */
|
|
74
|
+
LATIN_RE.lastIndex = index;
|
|
75
|
+
if (LATIN_RE.test(input)) {
|
|
76
|
+
lengthExtra = LATIN_RE.lastIndex - index;
|
|
77
|
+
widthExtra = lengthExtra * REGULAR_WIDTH;
|
|
78
|
+
if ((width + widthExtra) > truncationLimit) {
|
|
79
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / REGULAR_WIDTH));
|
|
80
|
+
}
|
|
81
|
+
if ((width + widthExtra) > LIMIT) {
|
|
82
|
+
truncationEnabled = true;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
width += widthExtra;
|
|
86
|
+
unmatchedStart = indexPrev;
|
|
87
|
+
unmatchedEnd = index;
|
|
88
|
+
index = indexPrev = LATIN_RE.lastIndex;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
/* ANSI */
|
|
92
|
+
ANSI_RE.lastIndex = index;
|
|
93
|
+
if (ANSI_RE.test(input)) {
|
|
94
|
+
if ((width + ANSI_WIDTH) > truncationLimit) {
|
|
95
|
+
truncationIndex = Math.min(truncationIndex, index);
|
|
96
|
+
}
|
|
97
|
+
if ((width + ANSI_WIDTH) > LIMIT) {
|
|
98
|
+
truncationEnabled = true;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
width += ANSI_WIDTH;
|
|
102
|
+
unmatchedStart = indexPrev;
|
|
103
|
+
unmatchedEnd = index;
|
|
104
|
+
index = indexPrev = ANSI_RE.lastIndex;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
/* CONTROL */
|
|
108
|
+
CONTROL_RE.lastIndex = index;
|
|
109
|
+
if (CONTROL_RE.test(input)) {
|
|
110
|
+
lengthExtra = CONTROL_RE.lastIndex - index;
|
|
111
|
+
widthExtra = lengthExtra * CONTROL_WIDTH;
|
|
112
|
+
if ((width + widthExtra) > truncationLimit) {
|
|
113
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / CONTROL_WIDTH));
|
|
114
|
+
}
|
|
115
|
+
if ((width + widthExtra) > LIMIT) {
|
|
116
|
+
truncationEnabled = true;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
width += widthExtra;
|
|
120
|
+
unmatchedStart = indexPrev;
|
|
121
|
+
unmatchedEnd = index;
|
|
122
|
+
index = indexPrev = CONTROL_RE.lastIndex;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
/* TAB */
|
|
126
|
+
TAB_RE.lastIndex = index;
|
|
127
|
+
if (TAB_RE.test(input)) {
|
|
128
|
+
lengthExtra = TAB_RE.lastIndex - index;
|
|
129
|
+
widthExtra = lengthExtra * TAB_WIDTH;
|
|
130
|
+
if ((width + widthExtra) > truncationLimit) {
|
|
131
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / TAB_WIDTH));
|
|
132
|
+
}
|
|
133
|
+
if ((width + widthExtra) > LIMIT) {
|
|
134
|
+
truncationEnabled = true;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
width += widthExtra;
|
|
138
|
+
unmatchedStart = indexPrev;
|
|
139
|
+
unmatchedEnd = index;
|
|
140
|
+
index = indexPrev = TAB_RE.lastIndex;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
/* EMOJI */
|
|
144
|
+
EMOJI_RE.lastIndex = index;
|
|
145
|
+
if (EMOJI_RE.test(input)) {
|
|
146
|
+
if ((width + EMOJI_WIDTH) > truncationLimit) {
|
|
147
|
+
truncationIndex = Math.min(truncationIndex, index);
|
|
148
|
+
}
|
|
149
|
+
if ((width + EMOJI_WIDTH) > LIMIT) {
|
|
150
|
+
truncationEnabled = true;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
width += EMOJI_WIDTH;
|
|
154
|
+
unmatchedStart = indexPrev;
|
|
155
|
+
unmatchedEnd = index;
|
|
156
|
+
index = indexPrev = EMOJI_RE.lastIndex;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
/* UNMATCHED INDEX */
|
|
160
|
+
index += 1;
|
|
161
|
+
}
|
|
162
|
+
/* RETURN */
|
|
163
|
+
return {
|
|
164
|
+
width: truncationEnabled ? truncationLimit : width,
|
|
165
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
166
|
+
truncated: truncationEnabled,
|
|
167
|
+
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
/* EXPORT */
|
|
171
|
+
export default getStringTruncatedWidth;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* MAIN */
|
|
2
|
+
//URL: https://github.com/sindresorhus/get-east-asian-width/blob/main/lookup.js
|
|
3
|
+
//LICENSE: https://github.com/sindresorhus/get-east-asian-width/blob/main/license
|
|
4
|
+
//TODO: Replace these with some unicode property classes, if the ones we need exist
|
|
5
|
+
const isAmbiguous = (x) => {
|
|
6
|
+
return x === 0xA1 || x === 0xA4 || x === 0xA7 || x === 0xA8 || x === 0xAA || x === 0xAD || x === 0xAE || x >= 0xB0 && x <= 0xB4 || x >= 0xB6 && x <= 0xBA || x >= 0xBC && x <= 0xBF || x === 0xC6 || x === 0xD0 || x === 0xD7 || x === 0xD8 || x >= 0xDE && x <= 0xE1 || x === 0xE6 || x >= 0xE8 && x <= 0xEA || x === 0xEC || x === 0xED || x === 0xF0 || x === 0xF2 || x === 0xF3 || x >= 0xF7 && x <= 0xFA || x === 0xFC || x === 0xFE || x === 0x101 || x === 0x111 || x === 0x113 || x === 0x11B || x === 0x126 || x === 0x127 || x === 0x12B || x >= 0x131 && x <= 0x133 || x === 0x138 || x >= 0x13F && x <= 0x142 || x === 0x144 || x >= 0x148 && x <= 0x14B || x === 0x14D || x === 0x152 || x === 0x153 || x === 0x166 || x === 0x167 || x === 0x16B || x === 0x1CE || x === 0x1D0 || x === 0x1D2 || x === 0x1D4 || x === 0x1D6 || x === 0x1D8 || x === 0x1DA || x === 0x1DC || x === 0x251 || x === 0x261 || x === 0x2C4 || x === 0x2C7 || x >= 0x2C9 && x <= 0x2CB || x === 0x2CD || x === 0x2D0 || x >= 0x2D8 && x <= 0x2DB || x === 0x2DD || x === 0x2DF || x >= 0x300 && x <= 0x36F || x >= 0x391 && x <= 0x3A1 || x >= 0x3A3 && x <= 0x3A9 || x >= 0x3B1 && x <= 0x3C1 || x >= 0x3C3 && x <= 0x3C9 || x === 0x401 || x >= 0x410 && x <= 0x44F || x === 0x451 || x === 0x2010 || x >= 0x2013 && x <= 0x2016 || x === 0x2018 || x === 0x2019 || x === 0x201C || x === 0x201D || x >= 0x2020 && x <= 0x2022 || x >= 0x2024 && x <= 0x2027 || x === 0x2030 || x === 0x2032 || x === 0x2033 || x === 0x2035 || x === 0x203B || x === 0x203E || x === 0x2074 || x === 0x207F || x >= 0x2081 && x <= 0x2084 || x === 0x20AC || x === 0x2103 || x === 0x2105 || x === 0x2109 || x === 0x2113 || x === 0x2116 || x === 0x2121 || x === 0x2122 || x === 0x2126 || x === 0x212B || x === 0x2153 || x === 0x2154 || x >= 0x215B && x <= 0x215E || x >= 0x2160 && x <= 0x216B || x >= 0x2170 && x <= 0x2179 || x === 0x2189 || x >= 0x2190 && x <= 0x2199 || x === 0x21B8 || x === 0x21B9 || x === 0x21D2 || x === 0x21D4 || x === 0x21E7 || x === 0x2200 || x === 0x2202 || x === 0x2203 || x === 0x2207 || x === 0x2208 || x === 0x220B || x === 0x220F || x === 0x2211 || x === 0x2215 || x === 0x221A || x >= 0x221D && x <= 0x2220 || x === 0x2223 || x === 0x2225 || x >= 0x2227 && x <= 0x222C || x === 0x222E || x >= 0x2234 && x <= 0x2237 || x === 0x223C || x === 0x223D || x === 0x2248 || x === 0x224C || x === 0x2252 || x === 0x2260 || x === 0x2261 || x >= 0x2264 && x <= 0x2267 || x === 0x226A || x === 0x226B || x === 0x226E || x === 0x226F || x === 0x2282 || x === 0x2283 || x === 0x2286 || x === 0x2287 || x === 0x2295 || x === 0x2299 || x === 0x22A5 || x === 0x22BF || x === 0x2312 || x >= 0x2460 && x <= 0x24E9 || x >= 0x24EB && x <= 0x254B || x >= 0x2550 && x <= 0x2573 || x >= 0x2580 && x <= 0x258F || x >= 0x2592 && x <= 0x2595 || x === 0x25A0 || x === 0x25A1 || x >= 0x25A3 && x <= 0x25A9 || x === 0x25B2 || x === 0x25B3 || x === 0x25B6 || x === 0x25B7 || x === 0x25BC || x === 0x25BD || x === 0x25C0 || x === 0x25C1 || x >= 0x25C6 && x <= 0x25C8 || x === 0x25CB || x >= 0x25CE && x <= 0x25D1 || x >= 0x25E2 && x <= 0x25E5 || x === 0x25EF || x === 0x2605 || x === 0x2606 || x === 0x2609 || x === 0x260E || x === 0x260F || x === 0x261C || x === 0x261E || x === 0x2640 || x === 0x2642 || x === 0x2660 || x === 0x2661 || x >= 0x2663 && x <= 0x2665 || x >= 0x2667 && x <= 0x266A || x === 0x266C || x === 0x266D || x === 0x266F || x === 0x269E || x === 0x269F || x === 0x26BF || x >= 0x26C6 && x <= 0x26CD || x >= 0x26CF && x <= 0x26D3 || x >= 0x26D5 && x <= 0x26E1 || x === 0x26E3 || x === 0x26E8 || x === 0x26E9 || x >= 0x26EB && x <= 0x26F1 || x === 0x26F4 || x >= 0x26F6 && x <= 0x26F9 || x === 0x26FB || x === 0x26FC || x === 0x26FE || x === 0x26FF || x === 0x273D || x >= 0x2776 && x <= 0x277F || x >= 0x2B56 && x <= 0x2B59 || x >= 0x3248 && x <= 0x324F || x >= 0xE000 && x <= 0xF8FF || x >= 0xFE00 && x <= 0xFE0F || x === 0xFFFD || x >= 0x1F100 && x <= 0x1F10A || x >= 0x1F110 && x <= 0x1F12D || x >= 0x1F130 && x <= 0x1F169 || x >= 0x1F170 && x <= 0x1F18D || x === 0x1F18F || x === 0x1F190 || x >= 0x1F19B && x <= 0x1F1AC || x >= 0xE0100 && x <= 0xE01EF || x >= 0xF0000 && x <= 0xFFFFD || x >= 0x100000 && x <= 0x10FFFD;
|
|
7
|
+
};
|
|
8
|
+
const isFullWidth = (x) => {
|
|
9
|
+
return x === 0x3000 || x >= 0xFF01 && x <= 0xFF60 || x >= 0xFFE0 && x <= 0xFFE6;
|
|
10
|
+
};
|
|
11
|
+
const isWide = (x) => {
|
|
12
|
+
return x >= 0x1100 && x <= 0x115F || x === 0x231A || x === 0x231B || x === 0x2329 || x === 0x232A || x >= 0x23E9 && x <= 0x23EC || x === 0x23F0 || x === 0x23F3 || x === 0x25FD || x === 0x25FE || x === 0x2614 || x === 0x2615 || x >= 0x2648 && x <= 0x2653 || x === 0x267F || x === 0x2693 || x === 0x26A1 || x === 0x26AA || x === 0x26AB || x === 0x26BD || x === 0x26BE || x === 0x26C4 || x === 0x26C5 || x === 0x26CE || x === 0x26D4 || x === 0x26EA || x === 0x26F2 || x === 0x26F3 || x === 0x26F5 || x === 0x26FA || x === 0x26FD || x === 0x2705 || x === 0x270A || x === 0x270B || x === 0x2728 || x === 0x274C || x === 0x274E || x >= 0x2753 && x <= 0x2755 || x === 0x2757 || x >= 0x2795 && x <= 0x2797 || x === 0x27B0 || x === 0x27BF || x === 0x2B1B || x === 0x2B1C || x === 0x2B50 || x === 0x2B55 || x >= 0x2E80 && x <= 0x2E99 || x >= 0x2E9B && x <= 0x2EF3 || x >= 0x2F00 && x <= 0x2FD5 || x >= 0x2FF0 && x <= 0x2FFF || x >= 0x3001 && x <= 0x303E || x >= 0x3041 && x <= 0x3096 || x >= 0x3099 && x <= 0x30FF || x >= 0x3105 && x <= 0x312F || x >= 0x3131 && x <= 0x318E || x >= 0x3190 && x <= 0x31E3 || x >= 0x31EF && x <= 0x321E || x >= 0x3220 && x <= 0x3247 || x >= 0x3250 && x <= 0x4DBF || x >= 0x4E00 && x <= 0xA48C || x >= 0xA490 && x <= 0xA4C6 || x >= 0xA960 && x <= 0xA97C || x >= 0xAC00 && x <= 0xD7A3 || x >= 0xF900 && x <= 0xFAFF || x >= 0xFE10 && x <= 0xFE19 || x >= 0xFE30 && x <= 0xFE52 || x >= 0xFE54 && x <= 0xFE66 || x >= 0xFE68 && x <= 0xFE6B || x >= 0x16FE0 && x <= 0x16FE4 || x === 0x16FF0 || x === 0x16FF1 || x >= 0x17000 && x <= 0x187F7 || x >= 0x18800 && x <= 0x18CD5 || x >= 0x18D00 && x <= 0x18D08 || x >= 0x1AFF0 && x <= 0x1AFF3 || x >= 0x1AFF5 && x <= 0x1AFFB || x === 0x1AFFD || x === 0x1AFFE || x >= 0x1B000 && x <= 0x1B122 || x === 0x1B132 || x >= 0x1B150 && x <= 0x1B152 || x === 0x1B155 || x >= 0x1B164 && x <= 0x1B167 || x >= 0x1B170 && x <= 0x1B2FB || x === 0x1F004 || x === 0x1F0CF || x === 0x1F18E || x >= 0x1F191 && x <= 0x1F19A || x >= 0x1F200 && x <= 0x1F202 || x >= 0x1F210 && x <= 0x1F23B || x >= 0x1F240 && x <= 0x1F248 || x === 0x1F250 || x === 0x1F251 || x >= 0x1F260 && x <= 0x1F265 || x >= 0x1F300 && x <= 0x1F320 || x >= 0x1F32D && x <= 0x1F335 || x >= 0x1F337 && x <= 0x1F37C || x >= 0x1F37E && x <= 0x1F393 || x >= 0x1F3A0 && x <= 0x1F3CA || x >= 0x1F3CF && x <= 0x1F3D3 || x >= 0x1F3E0 && x <= 0x1F3F0 || x === 0x1F3F4 || x >= 0x1F3F8 && x <= 0x1F43E || x === 0x1F440 || x >= 0x1F442 && x <= 0x1F4FC || x >= 0x1F4FF && x <= 0x1F53D || x >= 0x1F54B && x <= 0x1F54E || x >= 0x1F550 && x <= 0x1F567 || x === 0x1F57A || x === 0x1F595 || x === 0x1F596 || x === 0x1F5A4 || x >= 0x1F5FB && x <= 0x1F64F || x >= 0x1F680 && x <= 0x1F6C5 || x === 0x1F6CC || x >= 0x1F6D0 && x <= 0x1F6D2 || x >= 0x1F6D5 && x <= 0x1F6D7 || x >= 0x1F6DC && x <= 0x1F6DF || x === 0x1F6EB || x === 0x1F6EC || x >= 0x1F6F4 && x <= 0x1F6FC || x >= 0x1F7E0 && x <= 0x1F7EB || x === 0x1F7F0 || x >= 0x1F90C && x <= 0x1F93A || x >= 0x1F93C && x <= 0x1F945 || x >= 0x1F947 && x <= 0x1F9FF || x >= 0x1FA70 && x <= 0x1FA7C || x >= 0x1FA80 && x <= 0x1FA88 || x >= 0x1FA90 && x <= 0x1FABD || x >= 0x1FABF && x <= 0x1FAC5 || x >= 0x1FACE && x <= 0x1FADB || x >= 0x1FAE0 && x <= 0x1FAE8 || x >= 0x1FAF0 && x <= 0x1FAF8 || x >= 0x20000 && x <= 0x2FFFD || x >= 0x30000 && x <= 0x3FFFD;
|
|
13
|
+
};
|
|
14
|
+
/* EXPORT */
|
|
15
|
+
export { isAmbiguous, isFullWidth, isWide };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fast-string-truncated-width",
|
|
3
|
+
"repository": "github:fabiospampinato/fast-string-truncated-width",
|
|
4
|
+
"description": "A fast function for calculating where a string should be truncated, given an optional width limit and an ellipsis string.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"version": "1.2.1",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"exports": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"benchmark": "tsex benchmark",
|
|
13
|
+
"benchmark:watch": "tsex benchmark --watch",
|
|
14
|
+
"clean": "tsex clean",
|
|
15
|
+
"compile": "tsex compile",
|
|
16
|
+
"compile:watch": "tsex compile --watch",
|
|
17
|
+
"test": "tsex test",
|
|
18
|
+
"test:watch": "tsex test --watch",
|
|
19
|
+
"prepublishOnly": "tsex prepare"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"fast",
|
|
23
|
+
"string",
|
|
24
|
+
"truncated",
|
|
25
|
+
"width",
|
|
26
|
+
"cli",
|
|
27
|
+
"terminal"
|
|
28
|
+
],
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"benchloop": "^2.1.1",
|
|
31
|
+
"fava": "^0.3.4",
|
|
32
|
+
"tsex": "^4.0.2",
|
|
33
|
+
"typescript": "^5.7.3"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* IMPORT */
|
|
2
|
+
import fastStringTruncatedWidth from 'fast-string-truncated-width';
|
|
3
|
+
/* HELPERS */
|
|
4
|
+
const NO_TRUNCATION = {
|
|
5
|
+
limit: Infinity,
|
|
6
|
+
ellipsis: '',
|
|
7
|
+
ellipsisWidth: 0,
|
|
8
|
+
};
|
|
9
|
+
/* MAIN */
|
|
10
|
+
const fastStringWidth = (input, options = {}) => {
|
|
11
|
+
return fastStringTruncatedWidth(input, NO_TRUNCATION, options).width;
|
|
12
|
+
};
|
|
13
|
+
/* EXPORT */
|
|
14
|
+
export default fastStringWidth;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fast-string-width",
|
|
3
|
+
"repository": "github:fabiospampinato/fast-string-width",
|
|
4
|
+
"description": "A fast function for calculating the visual width of a string once printed to the terminal.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"version": "1.1.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"exports": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"clean": "tsex clean",
|
|
13
|
+
"compile": "tsex compile",
|
|
14
|
+
"compile:watch": "tsex compile --watch",
|
|
15
|
+
"test": "tsex test",
|
|
16
|
+
"test:watch": "tsex test --watch",
|
|
17
|
+
"prepublishOnly": "tsex prepare"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"fast",
|
|
21
|
+
"string",
|
|
22
|
+
"width",
|
|
23
|
+
"cli",
|
|
24
|
+
"terminal"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"fast-string-truncated-width": "^1.2.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"fava": "^0.3.4",
|
|
31
|
+
"tsex": "^4.0.2",
|
|
32
|
+
"typescript": "^5.7.3"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import stringWidth from 'fast-string-width';
|
|
2
|
+
const ESC = '\x1B';
|
|
3
|
+
const CSI = '\x9B';
|
|
4
|
+
const END_CODE = 39;
|
|
5
|
+
const ANSI_ESCAPE_BELL = '\u0007';
|
|
6
|
+
const ANSI_CSI = '[';
|
|
7
|
+
const ANSI_OSC = ']';
|
|
8
|
+
const ANSI_SGR_TERMINATOR = 'm';
|
|
9
|
+
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
10
|
+
const GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, 'y');
|
|
11
|
+
const getClosingCode = (openingCode) => {
|
|
12
|
+
if (openingCode >= 30 && openingCode <= 37)
|
|
13
|
+
return 39;
|
|
14
|
+
if (openingCode >= 90 && openingCode <= 97)
|
|
15
|
+
return 39;
|
|
16
|
+
if (openingCode >= 40 && openingCode <= 47)
|
|
17
|
+
return 49;
|
|
18
|
+
if (openingCode >= 100 && openingCode <= 107)
|
|
19
|
+
return 49;
|
|
20
|
+
if (openingCode === 1 || openingCode === 2)
|
|
21
|
+
return 22;
|
|
22
|
+
if (openingCode === 3)
|
|
23
|
+
return 23;
|
|
24
|
+
if (openingCode === 4)
|
|
25
|
+
return 24;
|
|
26
|
+
if (openingCode === 7)
|
|
27
|
+
return 27;
|
|
28
|
+
if (openingCode === 8)
|
|
29
|
+
return 28;
|
|
30
|
+
if (openingCode === 9)
|
|
31
|
+
return 29;
|
|
32
|
+
if (openingCode === 0)
|
|
33
|
+
return 0;
|
|
34
|
+
return undefined;
|
|
35
|
+
};
|
|
36
|
+
const wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
37
|
+
const wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
38
|
+
const wrapWord = (rows, word, columns) => {
|
|
39
|
+
const characters = word[Symbol.iterator]();
|
|
40
|
+
let isInsideEscape = false;
|
|
41
|
+
let isInsideLinkEscape = false;
|
|
42
|
+
let lastRow = rows.at(-1);
|
|
43
|
+
let visible = lastRow === undefined ? 0 : stringWidth(lastRow);
|
|
44
|
+
let currentCharacter = characters.next();
|
|
45
|
+
let nextCharacter = characters.next();
|
|
46
|
+
let rawCharacterIndex = 0;
|
|
47
|
+
while (!currentCharacter.done) {
|
|
48
|
+
const character = currentCharacter.value;
|
|
49
|
+
const characterLength = stringWidth(character);
|
|
50
|
+
if (visible + characterLength <= columns) {
|
|
51
|
+
rows[rows.length - 1] += character;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
rows.push(character);
|
|
55
|
+
visible = 0;
|
|
56
|
+
}
|
|
57
|
+
if (character === ESC || character === CSI) {
|
|
58
|
+
isInsideEscape = true;
|
|
59
|
+
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
60
|
+
}
|
|
61
|
+
if (isInsideEscape) {
|
|
62
|
+
if (isInsideLinkEscape) {
|
|
63
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
64
|
+
isInsideEscape = false;
|
|
65
|
+
isInsideLinkEscape = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (character === ANSI_SGR_TERMINATOR) {
|
|
69
|
+
isInsideEscape = false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
visible += characterLength;
|
|
74
|
+
if (visible === columns && !nextCharacter.done) {
|
|
75
|
+
rows.push('');
|
|
76
|
+
visible = 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
currentCharacter = nextCharacter;
|
|
80
|
+
nextCharacter = characters.next();
|
|
81
|
+
rawCharacterIndex += character.length;
|
|
82
|
+
}
|
|
83
|
+
lastRow = rows.at(-1);
|
|
84
|
+
if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
|
|
85
|
+
rows[rows.length - 2] += rows.pop();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const stringVisibleTrimSpacesRight = (string) => {
|
|
89
|
+
const words = string.split(' ');
|
|
90
|
+
let last = words.length;
|
|
91
|
+
while (last) {
|
|
92
|
+
if (stringWidth(words[last - 1])) {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
last--;
|
|
96
|
+
}
|
|
97
|
+
if (last === words.length) {
|
|
98
|
+
return string;
|
|
99
|
+
}
|
|
100
|
+
return words.slice(0, last).join(' ') + words.slice(last).join('');
|
|
101
|
+
};
|
|
102
|
+
const exec = (string, columns, options = {}) => {
|
|
103
|
+
if (options.trim !== false && string.trim() === '') {
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
let returnValue = '';
|
|
107
|
+
let escapeCode;
|
|
108
|
+
let escapeUrl;
|
|
109
|
+
const words = string.split(' ');
|
|
110
|
+
let rows = [''];
|
|
111
|
+
let rowLength = 0;
|
|
112
|
+
for (let index = 0; index < words.length; index++) {
|
|
113
|
+
const word = words[index];
|
|
114
|
+
if (options.trim !== false) {
|
|
115
|
+
const row = rows.at(-1) ?? '';
|
|
116
|
+
const trimmed = row.trimStart();
|
|
117
|
+
if (row.length !== trimmed.length) {
|
|
118
|
+
rows[rows.length - 1] = trimmed;
|
|
119
|
+
rowLength = stringWidth(trimmed);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (index !== 0) {
|
|
123
|
+
if (rowLength >= columns &&
|
|
124
|
+
(options.wordWrap === false || options.trim === false)) {
|
|
125
|
+
rows.push('');
|
|
126
|
+
rowLength = 0;
|
|
127
|
+
}
|
|
128
|
+
if (rowLength || options.trim === false) {
|
|
129
|
+
rows[rows.length - 1] += ' ';
|
|
130
|
+
rowLength++;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const wordLength = stringWidth(word);
|
|
134
|
+
if (options.hard && wordLength > columns) {
|
|
135
|
+
const remainingColumns = columns - rowLength;
|
|
136
|
+
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
137
|
+
const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
|
|
138
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
139
|
+
rows.push('');
|
|
140
|
+
}
|
|
141
|
+
wrapWord(rows, word, columns);
|
|
142
|
+
rowLength = stringWidth(rows.at(-1) ?? '');
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
146
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
147
|
+
wrapWord(rows, word, columns);
|
|
148
|
+
rowLength = stringWidth(rows.at(-1) ?? '');
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
rows.push('');
|
|
152
|
+
rowLength = 0;
|
|
153
|
+
}
|
|
154
|
+
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
155
|
+
wrapWord(rows, word, columns);
|
|
156
|
+
rowLength = stringWidth(rows.at(-1) ?? '');
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
rows[rows.length - 1] += word;
|
|
160
|
+
rowLength += wordLength;
|
|
161
|
+
}
|
|
162
|
+
if (options.trim !== false) {
|
|
163
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
164
|
+
}
|
|
165
|
+
const preString = rows.join('\n');
|
|
166
|
+
let inSurrogate = false;
|
|
167
|
+
for (let i = 0; i < preString.length; i++) {
|
|
168
|
+
const character = preString[i];
|
|
169
|
+
returnValue += character;
|
|
170
|
+
if (!inSurrogate) {
|
|
171
|
+
inSurrogate = character >= '\ud800' && character <= '\udbff';
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (character === ESC || character === CSI) {
|
|
177
|
+
GROUP_REGEX.lastIndex = i + 1;
|
|
178
|
+
const groupsResult = GROUP_REGEX.exec(preString);
|
|
179
|
+
const groups = groupsResult?.groups;
|
|
180
|
+
if (groups?.code !== undefined) {
|
|
181
|
+
const code = Number.parseFloat(groups.code);
|
|
182
|
+
escapeCode = code === END_CODE ? undefined : code;
|
|
183
|
+
}
|
|
184
|
+
else if (groups?.uri !== undefined) {
|
|
185
|
+
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (preString[i + 1] === '\n') {
|
|
189
|
+
if (escapeUrl) {
|
|
190
|
+
returnValue += wrapAnsiHyperlink('');
|
|
191
|
+
}
|
|
192
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : undefined;
|
|
193
|
+
if (escapeCode && closingCode) {
|
|
194
|
+
returnValue += wrapAnsiCode(closingCode);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else if (character === '\n') {
|
|
198
|
+
if (escapeCode && getClosingCode(escapeCode)) {
|
|
199
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
200
|
+
}
|
|
201
|
+
if (escapeUrl) {
|
|
202
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return returnValue;
|
|
207
|
+
};
|
|
208
|
+
const CRLF_OR_LF = /\r?\n/;
|
|
209
|
+
export function wrapAnsi(string, columns, options) {
|
|
210
|
+
return String(string)
|
|
211
|
+
.normalize()
|
|
212
|
+
.split(CRLF_OR_LF)
|
|
213
|
+
.map((line) => exec(line, columns, options))
|
|
214
|
+
.join('\n');
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fast-wrap-ansi",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"files": [
|
|
5
|
+
"lib"
|
|
6
|
+
],
|
|
7
|
+
"description": "A tiny and fast text wrap library which takes ANSI escapes into account.",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"wrap",
|
|
10
|
+
"ansi",
|
|
11
|
+
"term",
|
|
12
|
+
"colors"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/43081j/fast-wrap-ansi#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/43081j/fast-wrap-ansi/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/43081j/fast-wrap-ansi.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "James Garbutt (https://github.com/43081j)",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "lib/main.js",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"format": "prettier --write src test",
|
|
28
|
+
"lint": "npm run lint:js && npm run lint:format && npm run lint:types",
|
|
29
|
+
"lint:js": "eslint src test",
|
|
30
|
+
"lint:format": "prettier --check src test",
|
|
31
|
+
"lint:types": "npx tsc --noEmit -p tsconfig.test.json",
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"test": "vitest run"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@eslint/js": "^9.32.0",
|
|
37
|
+
"@types/node": "^24.2.0",
|
|
38
|
+
"eslint": "^9.32.0",
|
|
39
|
+
"fast-wrap-ansi-prod": "npm:fast-wrap-ansi@*",
|
|
40
|
+
"picocolors": "^1.1.1",
|
|
41
|
+
"prettier": "^3.6.2",
|
|
42
|
+
"tinybench": "^5.0.1",
|
|
43
|
+
"typescript": "^5.8.3",
|
|
44
|
+
"typescript-eslint": "^8.38.0",
|
|
45
|
+
"vitest": "^3.2.4",
|
|
46
|
+
"wrap-ansi": "^9.0.2"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"fast-string-width": "^1.1.0"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import Queue from 'yocto-queue';
|
|
2
|
+
|
|
3
|
+
export default function pLimit(concurrency) {
|
|
4
|
+
let rejectOnClear = false;
|
|
5
|
+
|
|
6
|
+
if (typeof concurrency === 'object') {
|
|
7
|
+
({concurrency, rejectOnClear = false} = concurrency);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
validateConcurrency(concurrency);
|
|
11
|
+
|
|
12
|
+
if (typeof rejectOnClear !== 'boolean') {
|
|
13
|
+
throw new TypeError('Expected `rejectOnClear` to be a boolean');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const queue = new Queue();
|
|
17
|
+
let activeCount = 0;
|
|
18
|
+
|
|
19
|
+
const resumeNext = () => {
|
|
20
|
+
// Process the next queued function if we're under the concurrency limit
|
|
21
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
22
|
+
activeCount++;
|
|
23
|
+
queue.dequeue().run();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const next = () => {
|
|
28
|
+
activeCount--;
|
|
29
|
+
resumeNext();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const run = async (function_, resolve, arguments_) => {
|
|
33
|
+
// Execute the function and capture the result promise
|
|
34
|
+
const result = (async () => function_(...arguments_))();
|
|
35
|
+
|
|
36
|
+
// Resolve immediately with the promise (don't wait for completion)
|
|
37
|
+
resolve(result);
|
|
38
|
+
|
|
39
|
+
// Wait for the function to complete (success or failure)
|
|
40
|
+
// We catch errors here to prevent unhandled rejections,
|
|
41
|
+
// but the original promise rejection is preserved for the caller
|
|
42
|
+
try {
|
|
43
|
+
await result;
|
|
44
|
+
} catch {}
|
|
45
|
+
|
|
46
|
+
// Decrement active count and process next queued function
|
|
47
|
+
next();
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const enqueue = (function_, resolve, reject, arguments_) => {
|
|
51
|
+
const queueItem = {reject};
|
|
52
|
+
|
|
53
|
+
// Queue the internal resolve function instead of the run function
|
|
54
|
+
// to preserve the asynchronous execution context.
|
|
55
|
+
new Promise(internalResolve => { // eslint-disable-line promise/param-names
|
|
56
|
+
queueItem.run = internalResolve;
|
|
57
|
+
queue.enqueue(queueItem);
|
|
58
|
+
}).then(run.bind(undefined, function_, resolve, arguments_)); // eslint-disable-line promise/prefer-await-to-then
|
|
59
|
+
|
|
60
|
+
// Start processing immediately if we haven't reached the concurrency limit
|
|
61
|
+
if (activeCount < concurrency) {
|
|
62
|
+
resumeNext();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const generator = (function_, ...arguments_) => new Promise((resolve, reject) => {
|
|
67
|
+
enqueue(function_, resolve, reject, arguments_);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
Object.defineProperties(generator, {
|
|
71
|
+
activeCount: {
|
|
72
|
+
get: () => activeCount,
|
|
73
|
+
},
|
|
74
|
+
pendingCount: {
|
|
75
|
+
get: () => queue.size,
|
|
76
|
+
},
|
|
77
|
+
clearQueue: {
|
|
78
|
+
value() {
|
|
79
|
+
if (!rejectOnClear) {
|
|
80
|
+
queue.clear();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const abortError = AbortSignal.abort().reason;
|
|
85
|
+
|
|
86
|
+
while (queue.size > 0) {
|
|
87
|
+
queue.dequeue().reject(abortError);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
concurrency: {
|
|
92
|
+
get: () => concurrency,
|
|
93
|
+
|
|
94
|
+
set(newConcurrency) {
|
|
95
|
+
validateConcurrency(newConcurrency);
|
|
96
|
+
concurrency = newConcurrency;
|
|
97
|
+
|
|
98
|
+
queueMicrotask(() => {
|
|
99
|
+
// eslint-disable-next-line no-unmodified-loop-condition
|
|
100
|
+
while (activeCount < concurrency && queue.size > 0) {
|
|
101
|
+
resumeNext();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
map: {
|
|
107
|
+
async value(iterable, function_) {
|
|
108
|
+
const promises = Array.from(iterable, (value, index) => this(function_, value, index));
|
|
109
|
+
return Promise.all(promises);
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return generator;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function limitFunction(function_, options) {
|
|
118
|
+
const limit = pLimit(options);
|
|
119
|
+
|
|
120
|
+
return (...arguments_) => limit(() => function_(...arguments_));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function validateConcurrency(concurrency) {
|
|
124
|
+
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
|
125
|
+
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
|
|
126
|
+
}
|
|
127
|
+
}
|