@synapsync/synk 1.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.
@@ -0,0 +1,399 @@
1
+ import y from "node:process";
2
+ import os from "node:os";
3
+ import tty from "node:tty";
4
+ const ANSI_BACKGROUND_OFFSET = 10;
5
+ const wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
6
+ const wrapAnsi256 = (offset = 0) => (code) => `\u001B[${38 + offset};5;${code}m`;
7
+ const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
8
+ const styles$1 = {
9
+ modifier: {
10
+ reset: [0, 0],
11
+ bold: [1, 22],
12
+ dim: [2, 22],
13
+ italic: [3, 23],
14
+ underline: [4, 24],
15
+ overline: [53, 55],
16
+ inverse: [7, 27],
17
+ hidden: [8, 28],
18
+ strikethrough: [9, 29]
19
+ },
20
+ color: {
21
+ black: [30, 39],
22
+ red: [31, 39],
23
+ green: [32, 39],
24
+ yellow: [33, 39],
25
+ blue: [34, 39],
26
+ magenta: [35, 39],
27
+ cyan: [36, 39],
28
+ white: [37, 39],
29
+ blackBright: [90, 39],
30
+ gray: [90, 39],
31
+ grey: [90, 39],
32
+ redBright: [91, 39],
33
+ greenBright: [92, 39],
34
+ yellowBright: [93, 39],
35
+ blueBright: [94, 39],
36
+ magentaBright: [95, 39],
37
+ cyanBright: [96, 39],
38
+ whiteBright: [97, 39]
39
+ },
40
+ bgColor: {
41
+ bgBlack: [40, 49],
42
+ bgRed: [41, 49],
43
+ bgGreen: [42, 49],
44
+ bgYellow: [43, 49],
45
+ bgBlue: [44, 49],
46
+ bgMagenta: [45, 49],
47
+ bgCyan: [46, 49],
48
+ bgWhite: [47, 49],
49
+ bgBlackBright: [100, 49],
50
+ bgGray: [100, 49],
51
+ bgGrey: [100, 49],
52
+ bgRedBright: [101, 49],
53
+ bgGreenBright: [102, 49],
54
+ bgYellowBright: [103, 49],
55
+ bgBlueBright: [104, 49],
56
+ bgMagentaBright: [105, 49],
57
+ bgCyanBright: [106, 49],
58
+ bgWhiteBright: [107, 49]
59
+ }
60
+ };
61
+ Object.keys(styles$1.modifier);
62
+ const foregroundColorNames = Object.keys(styles$1.color);
63
+ const backgroundColorNames = Object.keys(styles$1.bgColor);
64
+ [...foregroundColorNames, ...backgroundColorNames];
65
+ function assembleStyles() {
66
+ const codes = /* @__PURE__ */ new Map();
67
+ for (const [groupName, group] of Object.entries(styles$1)) {
68
+ for (const [styleName, style] of Object.entries(group)) {
69
+ styles$1[styleName] = {
70
+ open: `\u001B[${style[0]}m`,
71
+ close: `\u001B[${style[1]}m`
72
+ };
73
+ group[styleName] = styles$1[styleName];
74
+ codes.set(style[0], style[1]);
75
+ }
76
+ Object.defineProperty(styles$1, groupName, {
77
+ value: group,
78
+ enumerable: false
79
+ });
80
+ }
81
+ Object.defineProperty(styles$1, "codes", {
82
+ value: codes,
83
+ enumerable: false
84
+ });
85
+ styles$1.color.close = "\x1B[39m";
86
+ styles$1.bgColor.close = "\x1B[49m";
87
+ styles$1.color.ansi = wrapAnsi16();
88
+ styles$1.color.ansi256 = wrapAnsi256();
89
+ styles$1.color.ansi16m = wrapAnsi16m();
90
+ styles$1.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
91
+ styles$1.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
92
+ styles$1.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
93
+ Object.defineProperties(styles$1, {
94
+ rgbToAnsi256: {
95
+ value(red, green, blue) {
96
+ if (red === green && green === blue) {
97
+ if (red < 8) return 16;
98
+ if (red > 248) return 231;
99
+ return Math.round((red - 8) / 247 * 24) + 232;
100
+ }
101
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
102
+ },
103
+ enumerable: false
104
+ },
105
+ hexToRgb: {
106
+ value(hex) {
107
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
108
+ if (!matches) return [
109
+ 0,
110
+ 0,
111
+ 0
112
+ ];
113
+ let [colorString] = matches;
114
+ if (colorString.length === 3) colorString = [...colorString].map((character) => character + character).join("");
115
+ const integer = Number.parseInt(colorString, 16);
116
+ return [
117
+ integer >> 16 & 255,
118
+ integer >> 8 & 255,
119
+ integer & 255
120
+ ];
121
+ },
122
+ enumerable: false
123
+ },
124
+ hexToAnsi256: {
125
+ value: (hex) => styles$1.rgbToAnsi256(...styles$1.hexToRgb(hex)),
126
+ enumerable: false
127
+ },
128
+ ansi256ToAnsi: {
129
+ value(code) {
130
+ if (code < 8) return 30 + code;
131
+ if (code < 16) return 90 + (code - 8);
132
+ let red;
133
+ let green;
134
+ let blue;
135
+ if (code >= 232) {
136
+ red = ((code - 232) * 10 + 8) / 255;
137
+ green = red;
138
+ blue = red;
139
+ } else {
140
+ code -= 16;
141
+ const remainder = code % 36;
142
+ red = Math.floor(code / 36) / 5;
143
+ green = Math.floor(remainder / 6) / 5;
144
+ blue = remainder % 6 / 5;
145
+ }
146
+ const value = Math.max(red, green, blue) * 2;
147
+ if (value === 0) return 30;
148
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
149
+ if (value === 2) result += 60;
150
+ return result;
151
+ },
152
+ enumerable: false
153
+ },
154
+ rgbToAnsi: {
155
+ value: (red, green, blue) => styles$1.ansi256ToAnsi(styles$1.rgbToAnsi256(red, green, blue)),
156
+ enumerable: false
157
+ },
158
+ hexToAnsi: {
159
+ value: (hex) => styles$1.ansi256ToAnsi(styles$1.hexToAnsi256(hex)),
160
+ enumerable: false
161
+ }
162
+ });
163
+ return styles$1;
164
+ }
165
+ var ansi_styles_default = assembleStyles();
166
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : y.argv) {
167
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
168
+ const position = argv.indexOf(prefix + flag);
169
+ const terminatorPosition = argv.indexOf("--");
170
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
171
+ }
172
+ const { env } = y;
173
+ let flagForceColor;
174
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) flagForceColor = 0;
175
+ else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) flagForceColor = 1;
176
+ function envForceColor() {
177
+ if ("FORCE_COLOR" in env) {
178
+ if (env.FORCE_COLOR === "true") return 1;
179
+ if (env.FORCE_COLOR === "false") return 0;
180
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
181
+ }
182
+ }
183
+ function translateLevel(level) {
184
+ if (level === 0) return false;
185
+ return {
186
+ level,
187
+ hasBasic: true,
188
+ has256: level >= 2,
189
+ has16m: level >= 3
190
+ };
191
+ }
192
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
193
+ const noFlagForceColor = envForceColor();
194
+ if (noFlagForceColor !== void 0) flagForceColor = noFlagForceColor;
195
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
196
+ if (forceColor === 0) return 0;
197
+ if (sniffFlags) {
198
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) return 3;
199
+ if (hasFlag("color=256")) return 2;
200
+ }
201
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) return 1;
202
+ if (haveStream && !streamIsTTY && forceColor === void 0) return 0;
203
+ const min = forceColor || 0;
204
+ if (env.TERM === "dumb") return min;
205
+ if (y.platform === "win32") {
206
+ const osRelease = os.release().split(".");
207
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
208
+ return 1;
209
+ }
210
+ if ("CI" in env) {
211
+ if ([
212
+ "GITHUB_ACTIONS",
213
+ "GITEA_ACTIONS",
214
+ "CIRCLECI"
215
+ ].some((key) => key in env)) return 3;
216
+ if ([
217
+ "TRAVIS",
218
+ "APPVEYOR",
219
+ "GITLAB_CI",
220
+ "BUILDKITE",
221
+ "DRONE"
222
+ ].some((sign) => sign in env) || env.CI_NAME === "codeship") return 1;
223
+ return min;
224
+ }
225
+ if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
226
+ if (env.COLORTERM === "truecolor") return 3;
227
+ if (env.TERM === "xterm-kitty") return 3;
228
+ if (env.TERM === "xterm-ghostty") return 3;
229
+ if (env.TERM === "wezterm") return 3;
230
+ if ("TERM_PROGRAM" in env) {
231
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
232
+ switch (env.TERM_PROGRAM) {
233
+ case "iTerm.app": return version >= 3 ? 3 : 2;
234
+ case "Apple_Terminal": return 2;
235
+ }
236
+ }
237
+ if (/-256(color)?$/i.test(env.TERM)) return 2;
238
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) return 1;
239
+ if ("COLORTERM" in env) return 1;
240
+ return min;
241
+ }
242
+ function createSupportsColor(stream, options = {}) {
243
+ return translateLevel(_supportsColor(stream, {
244
+ streamIsTTY: stream && stream.isTTY,
245
+ ...options
246
+ }));
247
+ }
248
+ var supports_color_default = {
249
+ stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
250
+ stderr: createSupportsColor({ isTTY: tty.isatty(2) })
251
+ };
252
+ function stringReplaceAll(string, substring, replacer) {
253
+ let index = string.indexOf(substring);
254
+ if (index === -1) return string;
255
+ const substringLength = substring.length;
256
+ let endIndex = 0;
257
+ let returnValue = "";
258
+ do {
259
+ returnValue += string.slice(endIndex, index) + substring + replacer;
260
+ endIndex = index + substringLength;
261
+ index = string.indexOf(substring, endIndex);
262
+ } while (index !== -1);
263
+ returnValue += string.slice(endIndex);
264
+ return returnValue;
265
+ }
266
+ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
267
+ let endIndex = 0;
268
+ let returnValue = "";
269
+ do {
270
+ const gotCR = string[index - 1] === "\r";
271
+ returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
272
+ endIndex = index + 1;
273
+ index = string.indexOf("\n", endIndex);
274
+ } while (index !== -1);
275
+ returnValue += string.slice(endIndex);
276
+ return returnValue;
277
+ }
278
+ const { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
279
+ const GENERATOR = Symbol("GENERATOR");
280
+ const STYLER = Symbol("STYLER");
281
+ const IS_EMPTY = Symbol("IS_EMPTY");
282
+ const levelMapping = [
283
+ "ansi",
284
+ "ansi",
285
+ "ansi256",
286
+ "ansi16m"
287
+ ];
288
+ const styles = Object.create(null);
289
+ const applyOptions = (object, options = {}) => {
290
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) throw new Error("The `level` option should be an integer from 0 to 3");
291
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
292
+ object.level = options.level === void 0 ? colorLevel : options.level;
293
+ };
294
+ const chalkFactory = (options) => {
295
+ const chalk = (...strings) => strings.join(" ");
296
+ applyOptions(chalk, options);
297
+ Object.setPrototypeOf(chalk, createChalk.prototype);
298
+ return chalk;
299
+ };
300
+ function createChalk(options) {
301
+ return chalkFactory(options);
302
+ }
303
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
304
+ for (const [styleName, style] of Object.entries(ansi_styles_default)) styles[styleName] = { get() {
305
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
306
+ Object.defineProperty(this, styleName, { value: builder });
307
+ return builder;
308
+ } };
309
+ styles.visible = { get() {
310
+ const builder = createBuilder(this, this[STYLER], true);
311
+ Object.defineProperty(this, "visible", { value: builder });
312
+ return builder;
313
+ } };
314
+ const getModelAnsi = (model, level, type, ...arguments_) => {
315
+ if (model === "rgb") {
316
+ if (level === "ansi16m") return ansi_styles_default[type].ansi16m(...arguments_);
317
+ if (level === "ansi256") return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
318
+ return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
319
+ }
320
+ if (model === "hex") return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
321
+ return ansi_styles_default[type][model](...arguments_);
322
+ };
323
+ for (const model of [
324
+ "rgb",
325
+ "hex",
326
+ "ansi256"
327
+ ]) {
328
+ styles[model] = { get() {
329
+ const { level } = this;
330
+ return function(...arguments_) {
331
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
332
+ return createBuilder(this, styler, this[IS_EMPTY]);
333
+ };
334
+ } };
335
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
336
+ styles[bgModel] = { get() {
337
+ const { level } = this;
338
+ return function(...arguments_) {
339
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
340
+ return createBuilder(this, styler, this[IS_EMPTY]);
341
+ };
342
+ } };
343
+ }
344
+ const proto = Object.defineProperties(() => {}, {
345
+ ...styles,
346
+ level: {
347
+ enumerable: true,
348
+ get() {
349
+ return this[GENERATOR].level;
350
+ },
351
+ set(level) {
352
+ this[GENERATOR].level = level;
353
+ }
354
+ }
355
+ });
356
+ const createStyler = (open, close, parent) => {
357
+ let openAll;
358
+ let closeAll;
359
+ if (parent === void 0) {
360
+ openAll = open;
361
+ closeAll = close;
362
+ } else {
363
+ openAll = parent.openAll + open;
364
+ closeAll = close + parent.closeAll;
365
+ }
366
+ return {
367
+ open,
368
+ close,
369
+ openAll,
370
+ closeAll,
371
+ parent
372
+ };
373
+ };
374
+ const createBuilder = (self, _styler, _isEmpty) => {
375
+ const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
376
+ Object.setPrototypeOf(builder, proto);
377
+ builder[GENERATOR] = self;
378
+ builder[STYLER] = _styler;
379
+ builder[IS_EMPTY] = _isEmpty;
380
+ return builder;
381
+ };
382
+ const applyStyle = (self, string) => {
383
+ if (self.level <= 0 || !string) return self[IS_EMPTY] ? "" : string;
384
+ let styler = self[STYLER];
385
+ if (styler === void 0) return string;
386
+ const { openAll, closeAll } = styler;
387
+ if (string.includes("\x1B")) while (styler !== void 0) {
388
+ string = stringReplaceAll(string, styler.close, styler.open);
389
+ styler = styler.parent;
390
+ }
391
+ const lfIndex = string.indexOf("\n");
392
+ if (lfIndex !== -1) string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
393
+ return openAll + string + closeAll;
394
+ };
395
+ Object.defineProperties(createChalk.prototype, styles);
396
+ const chalk = createChalk();
397
+ createChalk({ level: stderrColor ? stderrColor.level : 0 });
398
+ var source_default = chalk;
399
+ export { source_default as t };
@@ -0,0 +1,257 @@
1
+ import y from "node:process";
2
+ const copyProperty = (to, from, property, ignoreNonConfigurable) => {
3
+ if (property === "length" || property === "prototype") return;
4
+ if (property === "arguments" || property === "caller") return;
5
+ const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
6
+ const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
7
+ if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) return;
8
+ Object.defineProperty(to, property, fromDescriptor);
9
+ };
10
+ const canCopyProperty = function(toDescriptor, fromDescriptor) {
11
+ return toDescriptor === void 0 || toDescriptor.configurable || toDescriptor.writable === fromDescriptor.writable && toDescriptor.enumerable === fromDescriptor.enumerable && toDescriptor.configurable === fromDescriptor.configurable && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value);
12
+ };
13
+ const changePrototype = (to, from) => {
14
+ const fromPrototype = Object.getPrototypeOf(from);
15
+ if (fromPrototype === Object.getPrototypeOf(to)) return;
16
+ Object.setPrototypeOf(to, fromPrototype);
17
+ };
18
+ const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`;
19
+ const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, "toString");
20
+ const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, "name");
21
+ const changeToString = (to, from, name) => {
22
+ const withName = name === "" ? "" : `with ${name.trim()}() `;
23
+ const newToString = wrappedToString.bind(null, withName, from.toString());
24
+ Object.defineProperty(newToString, "name", toStringName);
25
+ const { writable, enumerable, configurable } = toStringDescriptor;
26
+ Object.defineProperty(to, "toString", {
27
+ value: newToString,
28
+ writable,
29
+ enumerable,
30
+ configurable
31
+ });
32
+ };
33
+ function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) {
34
+ const { name } = to;
35
+ for (const property of Reflect.ownKeys(from)) copyProperty(to, from, property, ignoreNonConfigurable);
36
+ changePrototype(to, from);
37
+ changeToString(to, from, name);
38
+ return to;
39
+ }
40
+ const calledFunctions = /* @__PURE__ */ new WeakMap();
41
+ const onetime = (function_, options = {}) => {
42
+ if (typeof function_ !== "function") throw new TypeError("Expected a function");
43
+ let returnValue;
44
+ let callCount = 0;
45
+ const functionName = function_.displayName || function_.name || "<anonymous>";
46
+ const onetime = function(...arguments_) {
47
+ calledFunctions.set(onetime, ++callCount);
48
+ if (callCount === 1) {
49
+ returnValue = function_.apply(this, arguments_);
50
+ function_ = void 0;
51
+ } else if (options.throw === true) throw new Error(`Function \`${functionName}\` can only be called once`);
52
+ return returnValue;
53
+ };
54
+ mimicFunction(onetime, function_);
55
+ calledFunctions.set(onetime, callCount);
56
+ return onetime;
57
+ };
58
+ onetime.callCount = (function_) => {
59
+ if (!calledFunctions.has(function_)) throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
60
+ return calledFunctions.get(function_);
61
+ };
62
+ var onetime_default = onetime;
63
+ const signals = [];
64
+ signals.push("SIGHUP", "SIGINT", "SIGTERM");
65
+ if (process.platform !== "win32") signals.push("SIGALRM", "SIGABRT", "SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT");
66
+ if (process.platform === "linux") signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
67
+ const processOk = (process) => !!process && typeof process === "object" && typeof process.removeListener === "function" && typeof process.emit === "function" && typeof process.reallyExit === "function" && typeof process.listeners === "function" && typeof process.kill === "function" && typeof process.pid === "number" && typeof process.on === "function";
68
+ const kExitEmitter = Symbol.for("signal-exit emitter");
69
+ const global = globalThis;
70
+ const ObjectDefineProperty = Object.defineProperty.bind(Object);
71
+ var Emitter = class {
72
+ emitted = {
73
+ afterExit: false,
74
+ exit: false
75
+ };
76
+ listeners = {
77
+ afterExit: [],
78
+ exit: []
79
+ };
80
+ count = 0;
81
+ id = Math.random();
82
+ constructor() {
83
+ if (global[kExitEmitter]) return global[kExitEmitter];
84
+ ObjectDefineProperty(global, kExitEmitter, {
85
+ value: this,
86
+ writable: false,
87
+ enumerable: false,
88
+ configurable: false
89
+ });
90
+ }
91
+ on(ev, fn) {
92
+ this.listeners[ev].push(fn);
93
+ }
94
+ removeListener(ev, fn) {
95
+ const list = this.listeners[ev];
96
+ const i = list.indexOf(fn);
97
+ /* c8 ignore start */
98
+ if (i === -1) return;
99
+ /* c8 ignore stop */
100
+ if (i === 0 && list.length === 1) list.length = 0;
101
+ else list.splice(i, 1);
102
+ }
103
+ emit(ev, code, signal) {
104
+ if (this.emitted[ev]) return false;
105
+ this.emitted[ev] = true;
106
+ let ret = false;
107
+ for (const fn of this.listeners[ev]) ret = fn(code, signal) === true || ret;
108
+ if (ev === "exit") ret = this.emit("afterExit", code, signal) || ret;
109
+ return ret;
110
+ }
111
+ };
112
+ var SignalExitBase = class {};
113
+ const signalExitWrap = (handler) => {
114
+ return {
115
+ onExit(cb, opts) {
116
+ return handler.onExit(cb, opts);
117
+ },
118
+ load() {
119
+ return handler.load();
120
+ },
121
+ unload() {
122
+ return handler.unload();
123
+ }
124
+ };
125
+ };
126
+ var SignalExitFallback = class extends SignalExitBase {
127
+ onExit() {
128
+ return () => {};
129
+ }
130
+ load() {}
131
+ unload() {}
132
+ };
133
+ var SignalExit = class extends SignalExitBase {
134
+ /* c8 ignore start */
135
+ #hupSig = process$1.platform === "win32" ? "SIGINT" : "SIGHUP";
136
+ /* c8 ignore stop */
137
+ #emitter = new Emitter();
138
+ #process;
139
+ #originalProcessEmit;
140
+ #originalProcessReallyExit;
141
+ #sigListeners = {};
142
+ #loaded = false;
143
+ constructor(process) {
144
+ super();
145
+ this.#process = process;
146
+ this.#sigListeners = {};
147
+ for (const sig of signals) this.#sigListeners[sig] = () => {
148
+ const listeners = this.#process.listeners(sig);
149
+ let { count } = this.#emitter;
150
+ /* c8 ignore start */
151
+ const p = process;
152
+ if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") count += p.__signal_exit_emitter__.count;
153
+ /* c8 ignore stop */
154
+ if (listeners.length === count) {
155
+ this.unload();
156
+ const ret = this.#emitter.emit("exit", null, sig);
157
+ /* c8 ignore start */
158
+ const s = sig === "SIGHUP" ? this.#hupSig : sig;
159
+ if (!ret) process.kill(process.pid, s);
160
+ }
161
+ };
162
+ this.#originalProcessReallyExit = process.reallyExit;
163
+ this.#originalProcessEmit = process.emit;
164
+ }
165
+ onExit(cb, opts) {
166
+ /* c8 ignore start */
167
+ if (!processOk(this.#process)) return () => {};
168
+ /* c8 ignore stop */
169
+ if (this.#loaded === false) this.load();
170
+ const ev = opts?.alwaysLast ? "afterExit" : "exit";
171
+ this.#emitter.on(ev, cb);
172
+ return () => {
173
+ this.#emitter.removeListener(ev, cb);
174
+ if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) this.unload();
175
+ };
176
+ }
177
+ load() {
178
+ if (this.#loaded) return;
179
+ this.#loaded = true;
180
+ this.#emitter.count += 1;
181
+ for (const sig of signals) try {
182
+ const fn = this.#sigListeners[sig];
183
+ if (fn) this.#process.on(sig, fn);
184
+ } catch (_) {}
185
+ this.#process.emit = (ev, ...a) => {
186
+ return this.#processEmit(ev, ...a);
187
+ };
188
+ this.#process.reallyExit = (code) => {
189
+ return this.#processReallyExit(code);
190
+ };
191
+ }
192
+ unload() {
193
+ if (!this.#loaded) return;
194
+ this.#loaded = false;
195
+ signals.forEach((sig) => {
196
+ const listener = this.#sigListeners[sig];
197
+ /* c8 ignore start */
198
+ if (!listener) throw new Error("Listener not defined for signal: " + sig);
199
+ /* c8 ignore stop */
200
+ try {
201
+ this.#process.removeListener(sig, listener);
202
+ } catch (_) {}
203
+ /* c8 ignore stop */
204
+ });
205
+ this.#process.emit = this.#originalProcessEmit;
206
+ this.#process.reallyExit = this.#originalProcessReallyExit;
207
+ this.#emitter.count -= 1;
208
+ }
209
+ #processReallyExit(code) {
210
+ /* c8 ignore start */
211
+ if (!processOk(this.#process)) return 0;
212
+ this.#process.exitCode = code || 0;
213
+ /* c8 ignore stop */
214
+ this.#emitter.emit("exit", this.#process.exitCode, null);
215
+ return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
216
+ }
217
+ #processEmit(ev, ...args) {
218
+ const og = this.#originalProcessEmit;
219
+ if (ev === "exit" && processOk(this.#process)) {
220
+ if (typeof args[0] === "number") this.#process.exitCode = args[0];
221
+ /* c8 ignore start */
222
+ const ret = og.call(this.#process, ev, ...args);
223
+ /* c8 ignore start */
224
+ this.#emitter.emit("exit", this.#process.exitCode, null);
225
+ /* c8 ignore stop */
226
+ return ret;
227
+ } else return og.call(this.#process, ev, ...args);
228
+ }
229
+ };
230
+ const process$1 = globalThis.process;
231
+ const { onExit, load, unload } = signalExitWrap(processOk(process$1) ? new SignalExit(process$1) : new SignalExitFallback());
232
+ const terminal = y.stderr.isTTY ? y.stderr : y.stdout.isTTY ? y.stdout : void 0;
233
+ var restore_cursor_default = terminal ? onetime_default(() => {
234
+ onExit(() => {
235
+ terminal.write("\x1B[?25h");
236
+ }, { alwaysLast: true });
237
+ }) : () => {};
238
+ let isHidden = false;
239
+ const cliCursor = {};
240
+ cliCursor.show = (writableStream = y.stderr) => {
241
+ if (!writableStream.isTTY) return;
242
+ isHidden = false;
243
+ writableStream.write("\x1B[?25h");
244
+ };
245
+ cliCursor.hide = (writableStream = y.stderr) => {
246
+ if (!writableStream.isTTY) return;
247
+ restore_cursor_default();
248
+ isHidden = true;
249
+ writableStream.write("\x1B[?25l");
250
+ };
251
+ cliCursor.toggle = (force, writableStream) => {
252
+ if (force !== void 0) isHidden = force;
253
+ if (isHidden) cliCursor.show(writableStream);
254
+ else cliCursor.hide(writableStream);
255
+ };
256
+ var cli_cursor_default = cliCursor;
257
+ export { cli_cursor_default as t };