@socketsecurity/lib 3.0.2 → 3.0.4
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/CHANGELOG.md +21 -1
- package/dist/abort.js +60 -1
- package/dist/abort.js.map +2 -2
- package/dist/agent.js +289 -1
- package/dist/agent.js.map +2 -2
- package/dist/ansi.js +60 -1
- package/dist/ansi.js.map +2 -2
- package/dist/argv/flags.js +282 -1
- package/dist/argv/flags.js.map +2 -2
- package/dist/argv/parse.js +171 -1
- package/dist/argv/parse.js.map +2 -2
- package/dist/arrays.js +85 -1
- package/dist/arrays.js.map +2 -2
- package/dist/bin.js +419 -5
- package/dist/bin.js.map +2 -2
- package/dist/cacache.js +139 -1
- package/dist/cacache.js.map +2 -2
- package/dist/cache-with-ttl.js +223 -1
- package/dist/cache-with-ttl.js.map +2 -2
- package/dist/constants/agents.js +126 -1
- package/dist/constants/agents.js.map +2 -2
- package/dist/constants/core.js +57 -2
- package/dist/constants/core.js.map +2 -2
- package/dist/constants/encoding.js +48 -1
- package/dist/constants/encoding.js.map +2 -2
- package/dist/constants/github.js +30 -1
- package/dist/constants/github.js.map +2 -2
- package/dist/constants/licenses.js +66 -1
- package/dist/constants/licenses.js.map +2 -2
- package/dist/constants/node.js +185 -1
- package/dist/constants/node.js.map +2 -2
- package/dist/constants/packages.js +128 -1
- package/dist/constants/packages.js.map +2 -2
- package/dist/constants/paths.js +150 -1
- package/dist/constants/paths.js.map +2 -2
- package/dist/constants/platform.js +41 -1
- package/dist/constants/platform.js.map +2 -2
- package/dist/constants/process.js +52 -1
- package/dist/constants/process.js.map +2 -2
- package/dist/constants/socket.js +102 -1
- package/dist/constants/socket.js.map +2 -2
- package/dist/constants/testing.js +36 -1
- package/dist/constants/testing.js.map +2 -2
- package/dist/constants/time.js +39 -1
- package/dist/constants/time.js.map +2 -2
- package/dist/constants/typescript.js +54 -1
- package/dist/constants/typescript.js.map +2 -2
- package/dist/cover/code.js +135 -1
- package/dist/cover/code.js.map +2 -2
- package/dist/cover/formatters.js +101 -11
- package/dist/cover/formatters.js.map +2 -2
- package/dist/cover/type.js +63 -1
- package/dist/cover/type.js.map +2 -2
- package/dist/cover/types.js +15 -1
- package/dist/cover/types.js.map +2 -2
- package/dist/debug.js +337 -2
- package/dist/debug.js.map +2 -2
- package/dist/dlx-binary.js +408 -7
- package/dist/dlx-binary.js.map +2 -2
- package/dist/dlx-package.js +278 -7
- package/dist/dlx-package.js.map +2 -2
- package/dist/dlx.js +214 -7
- package/dist/dlx.js.map +3 -3
- package/dist/effects/pulse-frames.js +64 -1
- package/dist/effects/pulse-frames.js.map +2 -2
- package/dist/effects/text-shimmer.js +174 -1
- package/dist/effects/text-shimmer.js.map +2 -2
- package/dist/effects/types.js +15 -1
- package/dist/effects/types.js.map +2 -2
- package/dist/effects/ultra.js +61 -1
- package/dist/effects/ultra.js.map +2 -2
- package/dist/env/ci.js +31 -1
- package/dist/env/ci.js.map +2 -2
- package/dist/env/debug.js +30 -1
- package/dist/env/debug.js.map +2 -2
- package/dist/env/github.js +65 -1
- package/dist/env/github.js.map +2 -2
- package/dist/env/helpers.js +47 -1
- package/dist/env/helpers.js.map +2 -2
- package/dist/env/home.js +30 -1
- package/dist/env/home.js.map +2 -2
- package/dist/env/locale.js +40 -1
- package/dist/env/locale.js.map +2 -2
- package/dist/env/node-auth-token.js +30 -1
- package/dist/env/node-auth-token.js.map +2 -2
- package/dist/env/node-env.js +30 -1
- package/dist/env/node-env.js.map +2 -2
- package/dist/env/npm.js +50 -1
- package/dist/env/npm.js.map +2 -2
- package/dist/env/package-manager.js +73 -1
- package/dist/env/package-manager.js.map +2 -2
- package/dist/env/path.js +30 -1
- package/dist/env/path.js.map +2 -2
- package/dist/env/pre-commit.js +31 -1
- package/dist/env/pre-commit.js.map +2 -2
- package/dist/env/rewire.js +72 -1
- package/dist/env/rewire.js.map +2 -2
- package/dist/env/shell.js +30 -1
- package/dist/env/shell.js.map +2 -2
- package/dist/env/socket-cli-shadow.js +51 -1
- package/dist/env/socket-cli-shadow.js.map +2 -2
- package/dist/env/socket-cli.js +86 -1
- package/dist/env/socket-cli.js.map +2 -2
- package/dist/env/socket.js +101 -1
- package/dist/env/socket.js.map +2 -2
- package/dist/env/temp-dir.js +40 -1
- package/dist/env/temp-dir.js.map +2 -2
- package/dist/env/term.js +30 -1
- package/dist/env/term.js.map +2 -2
- package/dist/env/test.js +43 -1
- package/dist/env/test.js.map +2 -2
- package/dist/env/windows.js +45 -1
- package/dist/env/windows.js.map +2 -2
- package/dist/env/xdg.js +40 -1
- package/dist/env/xdg.js.map +2 -2
- package/dist/env.js +170 -1
- package/dist/env.js.map +2 -2
- package/dist/external/@socketregistry/packageurl-js.js +12 -2
- package/dist/fs.js +670 -7
- package/dist/fs.js.map +2 -2
- package/dist/functions.js +68 -1
- package/dist/functions.js.map +2 -2
- package/dist/git.js +329 -2
- package/dist/git.js.map +2 -2
- package/dist/github.js +202 -1
- package/dist/github.js.map +2 -2
- package/dist/globs.js +149 -1
- package/dist/globs.js.map +2 -2
- package/dist/http-request.js +335 -3
- package/dist/http-request.js.map +2 -2
- package/dist/index.js +69 -1
- package/dist/index.js.map +2 -2
- package/dist/ipc.js +244 -1
- package/dist/ipc.js.map +2 -2
- package/dist/json.js +73 -1
- package/dist/json.js.map +2 -2
- package/dist/links/index.js +60 -1
- package/dist/links/index.js.map +2 -2
- package/dist/logger.js +1383 -6
- package/dist/logger.js.map +2 -2
- package/dist/maintained-node-versions.js +35 -1
- package/dist/maintained-node-versions.js.map +2 -2
- package/dist/memoization.js +210 -1
- package/dist/memoization.js.map +2 -2
- package/dist/objects.js +311 -1
- package/dist/objects.js.map +3 -3
- package/dist/packages/editable.js +356 -9
- package/dist/packages/editable.js.map +2 -2
- package/dist/packages/exports.js +162 -1
- package/dist/packages/exports.js.map +2 -2
- package/dist/packages/isolation.js +187 -1
- package/dist/packages/isolation.js.map +2 -2
- package/dist/packages/licenses.js +214 -1
- package/dist/packages/licenses.js.map +2 -2
- package/dist/packages/manifest.js +190 -1
- package/dist/packages/manifest.js.map +2 -2
- package/dist/packages/normalize.js +132 -1
- package/dist/packages/normalize.js.map +2 -2
- package/dist/packages/operations.js +320 -1
- package/dist/packages/operations.js.map +2 -2
- package/dist/packages/paths.js +53 -1
- package/dist/packages/paths.js.map +2 -2
- package/dist/packages/provenance.js +178 -1
- package/dist/packages/provenance.js.map +2 -2
- package/dist/packages/specs.js +83 -1
- package/dist/packages/specs.js.map +2 -2
- package/dist/packages/validation.js +51 -1
- package/dist/packages/validation.js.map +2 -2
- package/dist/packages.js +129 -1
- package/dist/packages.js.map +2 -2
- package/dist/path.js +446 -1
- package/dist/path.js.map +2 -2
- package/dist/paths/rewire.js +79 -1
- package/dist/paths/rewire.js.map +2 -2
- package/dist/paths.js +190 -1
- package/dist/paths.js.map +2 -2
- package/dist/performance.js +216 -15
- package/dist/performance.js.map +2 -2
- package/dist/process-lock.js +287 -8
- package/dist/process-lock.js.map +2 -2
- package/dist/promise-queue.js +109 -1
- package/dist/promise-queue.js.map +2 -2
- package/dist/promises.js +267 -1
- package/dist/promises.js.map +2 -2
- package/dist/prompts/index.js +45 -1
- package/dist/prompts/index.js.map +2 -2
- package/dist/prompts.js +58 -1
- package/dist/prompts.js.map +2 -2
- package/dist/regexps.js +30 -1
- package/dist/regexps.js.map +2 -2
- package/dist/sea.js +44 -1
- package/dist/sea.js.map +2 -2
- package/dist/shadow.js +58 -1
- package/dist/shadow.js.map +2 -2
- package/dist/signal-exit.js +248 -1
- package/dist/signal-exit.js.map +2 -2
- package/dist/sorts.js +94 -1
- package/dist/sorts.js.map +2 -2
- package/dist/spawn.js +200 -1
- package/dist/spawn.js.map +2 -2
- package/dist/spinner.js +965 -1
- package/dist/spinner.js.map +3 -3
- package/dist/ssri.js +71 -1
- package/dist/ssri.js.map +2 -2
- package/dist/stdio/clear.js +82 -1
- package/dist/stdio/clear.js.map +2 -2
- package/dist/stdio/divider.js +89 -3
- package/dist/stdio/divider.js.map +2 -2
- package/dist/stdio/footer.js +94 -2
- package/dist/stdio/footer.js.map +2 -2
- package/dist/stdio/header.js +100 -2
- package/dist/stdio/header.js.map +2 -2
- package/dist/stdio/mask.js +207 -5
- package/dist/stdio/mask.js.map +2 -2
- package/dist/stdio/progress.js +209 -2
- package/dist/stdio/progress.js.map +2 -2
- package/dist/stdio/prompts.js +88 -1
- package/dist/stdio/prompts.js.map +2 -2
- package/dist/stdio/stderr.js +89 -2
- package/dist/stdio/stderr.js.map +2 -2
- package/dist/stdio/stdout.js +103 -2
- package/dist/stdio/stdout.js.map +2 -2
- package/dist/streams.js +78 -1
- package/dist/streams.js.map +2 -2
- package/dist/strings.js +251 -3
- package/dist/strings.js.map +2 -2
- package/dist/suppress-warnings.js +98 -1
- package/dist/suppress-warnings.js.map +2 -2
- package/dist/tables.js +128 -3
- package/dist/tables.js.map +2 -2
- package/dist/temporary-executor.js +53 -1
- package/dist/temporary-executor.js.map +2 -2
- package/dist/themes/context.js +71 -1
- package/dist/themes/context.js.map +3 -3
- package/dist/themes/index.d.ts +2 -2
- package/dist/themes/index.js +57 -1
- package/dist/themes/index.js.map +3 -3
- package/dist/themes/themes.d.ts +5 -5
- package/dist/themes/themes.js +204 -1
- package/dist/themes/themes.js.map +3 -3
- package/dist/themes/types.js +15 -1
- package/dist/themes/types.js.map +2 -2
- package/dist/themes/utils.js +116 -1
- package/dist/themes/utils.js.map +2 -2
- package/dist/types.js +59 -1
- package/dist/types.js.map +2 -2
- package/dist/url.js +142 -1
- package/dist/url.js.map +2 -2
- package/dist/utils/get-ipc.js +58 -1
- package/dist/utils/get-ipc.js.map +2 -2
- package/dist/validation/json-parser.js +127 -1
- package/dist/validation/json-parser.js.map +2 -2
- package/dist/validation/types.js +15 -1
- package/dist/validation/types.js.map +2 -2
- package/dist/versions.js +154 -1
- package/dist/versions.js.map +2 -2
- package/dist/words.js +50 -1
- package/dist/words.js.map +2 -2
- package/dist/zod.js +27 -1
- package/dist/zod.js.map +2 -2
- package/package.json +2 -2
package/dist/stdio/mask.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/stdio/mask.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * @fileoverview Interactive output masking utilities for CLI tools.\n * Provides output control with keyboard toggling (ctrl+o).\n *\n * ANSI Escape Sequences Used:\n * - '\\r': Carriage return - moves cursor to beginning of current line.\n * - '\\x1b[K' or '\\x1b[0K': CSI K (erase line) - clear from cursor to end of line.\n * - '\\x1b[2K': CSI 2K - erase entire line.\n * - '\\x1b[1A': CSI A - move cursor up 1 line.\n *\n * Terminal Control:\n * - Raw mode (setRawMode(true)): Captures keypresses immediately without buffering.\n * - TTY detection: Ensures terminal manipulation only occurs in interactive terminals.\n *\n * Key Features:\n * - Output buffering: Stores up to 1000 lines when masked to prevent memory issues.\n * - Graceful cleanup: Always restores terminal to normal mode on exit/error.\n * - Visual feedback: Uses spinner to indicate process is running when output is masked.\n */\n\nimport type { ChildProcess, SpawnOptions } from 'child_process'\nimport { spawn } from 'child_process'\nimport readline from 'readline'\nimport { getDefaultSpinner } from '../spinner.js'\nimport { clearLine } from './clear.js'\nimport { write } from './stdout.js'\n\nexport interface OutputMaskOptions {\n /**\n * Current working directory for spawned process.\n * @default process.cwd()\n */\n cwd?: string | undefined\n /**\n * Environment variables for spawned process.\n * @default process.env\n */\n env?: NodeJS.ProcessEnv | undefined\n /**\n * Filter output before displaying or buffering.\n * Return `false` to skip the line, `true` to include it.\n *\n * Useful for filtering non-fatal warnings or noise from test runners.\n * The filter runs on every chunk of output before display/buffering.\n *\n * @param text - The output text chunk (may include ANSI codes)\n * @param stream - Whether this came from 'stdout' or 'stderr'\n * @returns `true` to include this output, `false` to skip it\n *\n * @example\n * ```ts\n * filterOutput: (text, stream) => {\n * // Skip vitest worker termination errors\n * if (text.includes('Terminating worker thread')) return false\n * return true\n * }\n * ```\n */\n filterOutput?:\n | ((text: string, stream: 'stdout' | 'stderr') => boolean)\n | undefined\n /**\n * Progress message to display in spinner.\n * @default 'Running\u2026'\n */\n message?: string | undefined\n /**\n * Override the exit code based on captured output.\n *\n * Useful for handling non-fatal errors that shouldn't fail the build.\n * Called after the process exits with the original code and all captured output.\n * Return a number to override the exit code, or `undefined` to keep original.\n *\n * @param code - Original exit code from the process\n * @param stdout - All captured stdout (even filtered lines are captured)\n * @param stderr - All captured stderr (even filtered lines are captured)\n * @returns New exit code, or `undefined` to keep original\n *\n * @example\n * ```ts\n * overrideExitCode: (code, stdout, stderr) => {\n * // If only worker termination errors, treat as success\n * const output = stdout + stderr\n * const hasWorkerError = output.includes('Terminating worker thread')\n * const hasRealFailure = output.includes('FAIL')\n * if (code !== 0 && hasWorkerError && !hasRealFailure) {\n * return 0 // Override to success\n * }\n * return undefined // Keep original\n * }\n * ```\n */\n overrideExitCode?:\n | ((code: number, stdout: string, stderr: string) => number | undefined)\n | undefined\n /**\n * Start with output visible instead of masked.\n * When `true`, output shows immediately without needing ctrl+o.\n * @default false\n */\n showOutput?: boolean | undefined\n /**\n * Text to show after \"ctrl+o\" in spinner message.\n * @default 'to see full output'\n */\n toggleText?: string | undefined\n}\n\nexport interface OutputMask {\n /** Whether spinner is currently active */\n isSpinning: boolean\n /** Buffered output lines */\n outputBuffer: string[]\n /** All stderr captured (for exit code override) */\n stderrCapture: string\n /** All stdout captured (for exit code override) */\n stdoutCapture: string\n /** Whether output is currently visible */\n verbose: boolean\n}\n\n/**\n * Create an output mask for controlling command output visibility.\n * The mask tracks whether output should be shown or hidden (buffered).\n * When hidden, output is buffered and a spinner is shown instead.\n */\nexport function createOutputMask(options: OutputMaskOptions = {}): OutputMask {\n const { showOutput = false } = options\n\n return {\n isSpinning: !showOutput,\n outputBuffer: [],\n stderrCapture: '',\n stdoutCapture: '',\n verbose: showOutput,\n }\n}\n\n/**\n * Create a keyboard handler for toggling output visibility.\n * Handles two key combinations:\n * - ctrl+o: Toggle between showing and hiding output.\n * - ctrl+c: Cancel the running process.\n * The handler manipulates terminal state using ANSI escape sequences.\n */\nexport function createKeyboardHandler(\n mask: OutputMask,\n child: ChildProcess,\n options: OutputMaskOptions = {},\n): (_str: string, key: readline.Key) => void {\n const { message = 'Running\u2026', toggleText = 'to see full output' } = options\n\n return (_str, key) => {\n // ctrl+o toggles verbose mode.\n if (key?.ctrl && key.name === 'o') {\n mask.verbose = !mask.verbose\n\n if (mask.verbose) {\n // Stop spinner and show buffered output.\n if (mask.isSpinning) {\n getDefaultSpinner().stop()\n mask.isSpinning = false\n }\n\n // Clear the current line (removes spinner remnants).\n clearLine()\n\n // Show buffered output.\n if (mask.outputBuffer.length > 0) {\n console.log('--- Output (ctrl+o to hide) ---')\n mask.outputBuffer.forEach(line => {\n write(line)\n })\n }\n } else {\n // Hide output and show spinner.\n // Clear all the output lines that were shown.\n if (mask.outputBuffer.length > 0) {\n // Calculate number of lines to clear (output + header line).\n const lineCount = mask.outputBuffer.join('').split('\\n').length + 1\n // Move up and clear each line using ANSI escape sequences:\n // - '\\x1b[1A' (CSI A): Move cursor up 1 line.\n // - '\\x1b[2K' (CSI K with param 2): Erase entire line.\n // This combination effectively \"rewinds\" the terminal output.\n for (let i = 0; i < lineCount; i += 1) {\n process.stdout.write('\\x1b[1A\\x1b[2K')\n }\n }\n clearLine()\n\n // Clear the buffer and restart spinner.\n mask.outputBuffer = []\n if (!mask.isSpinning) {\n getDefaultSpinner().start(`${message} (ctrl+o ${toggleText})`)\n mask.isSpinning = true\n }\n }\n }\n // ctrl+c to cancel.\n else if (key?.ctrl && key.name === 'c') {\n // Gracefully terminate child process.\n child.kill('SIGTERM')\n // Restore terminal to normal mode before exiting.\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(false)\n }\n throw new Error('Process cancelled by user')\n }\n }\n}\n\n/**\n * Attach output masking to a child process.\n * Returns a promise that resolves with the exit code.\n * This function:\n * - Sets up keyboard input handling in raw mode for immediate key capture.\n * - Buffers stdout/stderr when not in verbose mode.\n * - Shows a spinner when output is masked.\n * - Allows toggling between masked and unmasked output with ctrl+o.\n */\nexport function attachOutputMask(\n child: ChildProcess,\n options: OutputMaskOptions = {},\n): Promise<number> {\n return new Promise((resolve, reject) => {\n const { message = 'Running\u2026' } = options\n const mask = createOutputMask(options)\n\n // Start spinner if not verbose.\n if (mask.isSpinning && process.stdout.isTTY) {\n getDefaultSpinner().start(\n `${message} (ctrl+o ${options.toggleText || 'to see full output'})`,\n )\n }\n\n // Setup keyboard input handling.\n // Raw mode is required to capture ctrl+o without waiting for Enter.\n if (process.stdin.isTTY) {\n readline.emitKeypressEvents(process.stdin)\n process.stdin.setRawMode(true)\n\n const keypressHandler = createKeyboardHandler(mask, child, options)\n process.stdin.on('keypress', keypressHandler)\n\n // Cleanup on exit: restore terminal to normal mode.\n child.on('exit', () => {\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(false)\n process.stdin.removeListener('keypress', keypressHandler)\n }\n })\n }\n\n // Handle stdout: either show immediately or buffer for later.\n if (child.stdout) {\n child.stdout.on('data', data => {\n const text = data.toString()\n\n // Always capture for exit code override.\n mask.stdoutCapture += text\n\n // Apply filter if provided.\n if (options.filterOutput && !options.filterOutput(text, 'stdout')) {\n // Skip this output.\n return undefined\n }\n\n if (mask.verbose) {\n write(text)\n } else {\n // Buffer the output for later.\n mask.outputBuffer.push(text)\n\n // Keep buffer size reasonable (last 1000 lines).\n // This prevents unbounded memory growth for long-running processes.\n const lines = mask.outputBuffer.join('').split('\\n')\n if (lines.length > 1000) {\n mask.outputBuffer = [lines.slice(-1000).join('\\n')]\n }\n }\n return undefined\n })\n }\n\n // Handle stderr: same as stdout, but write to stderr stream when verbose.\n if (child.stderr) {\n child.stderr.on('data', data => {\n const text = data.toString()\n\n // Always capture for exit code override.\n mask.stderrCapture += text\n\n // Apply filter if provided.\n if (options.filterOutput && !options.filterOutput(text, 'stderr')) {\n // Skip this output.\n return undefined\n }\n\n if (mask.verbose) {\n process.stderr.write(text)\n } else {\n mask.outputBuffer.push(text)\n }\n return undefined\n })\n }\n\n child.on('exit', code => {\n // Cleanup keyboard if needed.\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(false)\n }\n\n // Allow caller to override exit code based on output.\n let finalCode = code || 0\n if (options.overrideExitCode) {\n const overridden = options.overrideExitCode(\n finalCode,\n mask.stdoutCapture,\n mask.stderrCapture,\n )\n if (overridden !== undefined) {\n finalCode = overridden\n }\n }\n\n if (mask.isSpinning) {\n const spinner = getDefaultSpinner()\n if (finalCode === 0) {\n spinner.successAndStop(`${message} completed`)\n } else {\n spinner.failAndStop(`${message} failed`)\n // Show buffered output on failure so user can see what went wrong.\n if (mask.outputBuffer.length > 0 && !mask.verbose) {\n console.log('\\n--- Output ---')\n mask.outputBuffer.forEach(line => {\n write(line)\n })\n }\n }\n }\n\n resolve(finalCode)\n })\n\n child.on('error', error => {\n // Ensure terminal is restored to normal mode on error.\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(false)\n }\n\n if (mask.isSpinning) {\n getDefaultSpinner().failAndStop(`${message} error`)\n }\n reject(error)\n })\n })\n}\n\n/**\n * Run a command with interactive output masking.\n * Convenience wrapper around spawn + attachOutputMask.\n * Spawns a child process and attaches the output masking system to it.\n * stdin is inherited, stdout and stderr are piped for masking control.\n */\nexport async function runWithMask(\n command: string,\n args: string[] = [],\n options: OutputMaskOptions & SpawnOptions = {},\n): Promise<number> {\n const {\n message = 'Running\u2026',\n showOutput = false,\n toggleText = 'to see output',\n ...spawnOptions\n } = options\n\n const child = spawn(command, args, {\n stdio: ['inherit', 'pipe', 'pipe'],\n ...spawnOptions,\n })\n\n return await attachOutputMask(child, { message, showOutput, toggleText })\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": ["
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBA,2BAAsB;AACtB,sBAAqB;AACrB,qBAAkC;AAClC,mBAA0B;AAC1B,oBAAsB;AA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AAO,QAAQ;AAAA,MACpD;AACA,aAAO,KAAK;AAAA,IACd,CAAC;AAAA,EACH,CAAC;AACH;AAQA,eAAsB,YACpB,SACA,OAAiB,CAAC,GAClB,UAA4C,CAAC,GAC5B;AACjB,QAAM;AAAA,IACJ,UAAU;AAAA,IACV,aAAa;AAAA,IACb,aAAa;AAAA,IACb,GAAG;AAAA,EACL,IAAI;AAEJ,QAAM,YAAQ,4BAAM,SAAS,MAAM;AAAA,IACjC,OAAO,CAAC,WAAW,QAAQ,MAAM;AAAA,IACjC,GAAG;AAAA,EACL,CAAC;AAED,SAAO,MAAM,iBAAiB,OAAO,EAAE,SAAS,YAAY,WAAW,CAAC;AAC1E;",
|
|
6
|
+
"names": ["readline"]
|
|
7
7
|
}
|
package/dist/stdio/progress.js
CHANGED
|
@@ -1,4 +1,211 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var progress_exports = {};
|
|
30
|
+
__export(progress_exports, {
|
|
31
|
+
ProgressBar: () => ProgressBar,
|
|
32
|
+
createProgressIndicator: () => createProgressIndicator
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(progress_exports);
|
|
35
|
+
var import_yoctocolors_cjs = __toESM(require("../external/yoctocolors-cjs"));
|
|
36
|
+
var import_strings = require("../strings");
|
|
37
|
+
class ProgressBar {
|
|
38
|
+
current = 0;
|
|
39
|
+
total;
|
|
40
|
+
startTime;
|
|
41
|
+
lastRender = 0;
|
|
42
|
+
stream;
|
|
43
|
+
options;
|
|
44
|
+
terminated = false;
|
|
45
|
+
lastDrawnWidth = 0;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new progress bar instance.
|
|
48
|
+
*
|
|
49
|
+
* @param total - Total number of units for the progress bar
|
|
50
|
+
* @param options - Configuration options for the progress bar
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const bar = new ProgressBar(100, {
|
|
55
|
+
* width: 50,
|
|
56
|
+
* format: ':bar :percent :current/:total :eta',
|
|
57
|
+
* color: 'green'
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
constructor(total, options) {
|
|
62
|
+
this.total = total;
|
|
63
|
+
this.startTime = Date.now();
|
|
64
|
+
this.stream = options?.stream || process.stderr;
|
|
65
|
+
this.options = {
|
|
66
|
+
width: 40,
|
|
67
|
+
format: ":bar :percent :current/:total",
|
|
68
|
+
complete: "\u2588",
|
|
69
|
+
incomplete: "\u2591",
|
|
70
|
+
head: "",
|
|
71
|
+
clear: false,
|
|
72
|
+
// ~60fps.
|
|
73
|
+
renderThrottle: 16,
|
|
74
|
+
stream: this.stream,
|
|
75
|
+
color: "cyan",
|
|
76
|
+
...options
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Update progress to a specific value and redraw the bar.
|
|
81
|
+
* Updates are throttled to prevent excessive rendering (default ~60fps).
|
|
82
|
+
*
|
|
83
|
+
* @param current - Current progress value (will be clamped to total)
|
|
84
|
+
* @param tokens - Optional custom tokens to replace in format string
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* bar.update(50)
|
|
89
|
+
* bar.update(75, { status: 'Processing...' })
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
update(current, tokens) {
|
|
93
|
+
if (this.terminated) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.current = Math.min(current, this.total);
|
|
97
|
+
const now = Date.now();
|
|
98
|
+
if (now - this.lastRender < this.options.renderThrottle && this.current < this.total) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.lastRender = now;
|
|
102
|
+
this.render(tokens);
|
|
103
|
+
if (this.current >= this.total) {
|
|
104
|
+
this.terminate();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Increment progress by a specified amount.
|
|
109
|
+
* Convenience method for `update(current + amount)`.
|
|
110
|
+
*
|
|
111
|
+
* @param amount - Amount to increment by
|
|
112
|
+
* @param tokens - Optional custom tokens to replace in format string
|
|
113
|
+
* @default amount 1
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* bar.tick() // Increment by 1
|
|
118
|
+
* bar.tick(5) // Increment by 5
|
|
119
|
+
* bar.tick(1, { file: 'data.json' })
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
tick(amount = 1, tokens) {
|
|
123
|
+
this.update(this.current + amount, tokens);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Render the progress bar.
|
|
127
|
+
*/
|
|
128
|
+
render(tokens) {
|
|
129
|
+
const colorFn = import_yoctocolors_cjs.default[this.options.color] || ((s) => s);
|
|
130
|
+
const percent = Math.floor(this.current / this.total * 100);
|
|
131
|
+
const elapsed = Date.now() - this.startTime;
|
|
132
|
+
const eta = this.current === 0 ? 0 : elapsed / this.current * (this.total - this.current);
|
|
133
|
+
const availableWidth = this.options.width;
|
|
134
|
+
const filledWidth = Math.floor(this.current / this.total * availableWidth);
|
|
135
|
+
const emptyWidth = availableWidth - filledWidth;
|
|
136
|
+
const filled = (0, import_strings.repeatString)(this.options.complete, filledWidth);
|
|
137
|
+
const empty = (0, import_strings.repeatString)(this.options.incomplete, emptyWidth);
|
|
138
|
+
const bar = colorFn(filled) + empty;
|
|
139
|
+
let output = this.options.format;
|
|
140
|
+
output = output.replace(":bar", bar);
|
|
141
|
+
output = output.replace(":percent", `${percent}%`);
|
|
142
|
+
output = output.replace(":current", String(this.current));
|
|
143
|
+
output = output.replace(":total", String(this.total));
|
|
144
|
+
output = output.replace(":elapsed", this.formatTime(elapsed));
|
|
145
|
+
output = output.replace(":eta", this.formatTime(eta));
|
|
146
|
+
if (tokens) {
|
|
147
|
+
for (const [key, value] of Object.entries(tokens)) {
|
|
148
|
+
output = output.replace(`:${key}`, String(value));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
this.clearLine();
|
|
152
|
+
this.stream.write(output);
|
|
153
|
+
this.lastDrawnWidth = (0, import_strings.stripAnsi)(output).length;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Clear the current line.
|
|
157
|
+
*/
|
|
158
|
+
clearLine() {
|
|
159
|
+
if (this.stream.isTTY) {
|
|
160
|
+
this.stream.cursorTo(0);
|
|
161
|
+
this.stream.clearLine(0);
|
|
162
|
+
} else if (this.lastDrawnWidth > 0) {
|
|
163
|
+
this.stream.write(`\r${(0, import_strings.repeatString)(" ", this.lastDrawnWidth)}\r`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Format time in seconds to human readable.
|
|
168
|
+
*/
|
|
169
|
+
formatTime(ms) {
|
|
170
|
+
const seconds = Math.round(ms / 1e3);
|
|
171
|
+
if (seconds < 60) {
|
|
172
|
+
return `${seconds}s`;
|
|
173
|
+
}
|
|
174
|
+
const minutes = Math.floor(seconds / 60);
|
|
175
|
+
const remainingSeconds = seconds % 60;
|
|
176
|
+
return `${minutes}m${remainingSeconds}s`;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Terminate the progress bar and optionally clear it.
|
|
180
|
+
* Called automatically when progress reaches 100%.
|
|
181
|
+
* If `clear` option is true, removes the bar from terminal.
|
|
182
|
+
* Otherwise, moves to next line to preserve the final state.
|
|
183
|
+
*/
|
|
184
|
+
terminate() {
|
|
185
|
+
if (this.terminated) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.terminated = true;
|
|
189
|
+
if (this.options.clear) {
|
|
190
|
+
this.clearLine();
|
|
191
|
+
} else {
|
|
192
|
+
this.stream.write("\n");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function createProgressIndicator(current, total, label) {
|
|
197
|
+
const percent = Math.floor(current / total * 100);
|
|
198
|
+
const progress = `${current}/${total}`;
|
|
199
|
+
let output = "";
|
|
200
|
+
if (label) {
|
|
201
|
+
output += `${label}: `;
|
|
202
|
+
}
|
|
203
|
+
output += `${import_yoctocolors_cjs.default.cyan(`[${percent}%]`)} ${progress}`;
|
|
204
|
+
return output;
|
|
205
|
+
}
|
|
206
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
207
|
+
0 && (module.exports = {
|
|
208
|
+
ProgressBar,
|
|
209
|
+
createProgressIndicator
|
|
210
|
+
});
|
|
4
211
|
//# sourceMappingURL=progress.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/stdio/progress.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * @fileoverview Progress bar utilities for CLI applications.\n * Provides various progress indicators including bars, percentages, and spinners.\n */\n\nimport colors from '../external/yoctocolors-cjs'\nimport { repeatString, stripAnsi } from '../strings'\n\nexport interface ProgressBarOptions {\n /**\n * Width of the progress bar in characters.\n * @default 40\n */\n width?: number | undefined\n /**\n * Format template for progress bar display.\n * Available tokens: `:bar`, `:percent`, `:current`, `:total`, `:elapsed`, `:eta`.\n * Custom tokens can be passed via the `tokens` parameter in `update()` or `tick()`.\n * @default ':bar :percent :current/:total'\n * @example\n * ```ts\n * format: ':bar :percent :current/:total :eta'\n * ```\n */\n format?: string | undefined\n /**\n * Character(s) to use for completed portion of bar.\n * @default '\u2588'\n */\n complete?: string | undefined\n /**\n * Character(s) to use for incomplete portion of bar.\n * @default '\u2591'\n */\n incomplete?: string | undefined\n /**\n * Character(s) to use for the head of the progress bar.\n * @default ''\n */\n head?: string | undefined\n /**\n * Clear the progress bar when complete.\n * @default false\n */\n clear?: boolean | undefined\n /**\n * Minimum time between renders in milliseconds.\n * ~60fps = 16ms throttle.\n * @default 16\n */\n renderThrottle?: number | undefined\n /**\n * Stream to write progress bar output to.\n * @default process.stderr\n */\n stream?: NodeJS.WriteStream | undefined\n /**\n * Color to apply to the completed portion of the bar.\n * @default 'cyan'\n */\n color?: 'cyan' | 'green' | 'yellow' | 'blue' | 'magenta' | undefined\n}\n\nexport class ProgressBar {\n private current: number = 0\n private total: number\n private startTime: number\n private lastRender: number = 0\n private stream: NodeJS.WriteStream\n private options: Required<ProgressBarOptions>\n private terminated: boolean = false\n private lastDrawnWidth: number = 0\n\n /**\n * Create a new progress bar instance.\n *\n * @param total - Total number of units for the progress bar\n * @param options - Configuration options for the progress bar\n *\n * @example\n * ```ts\n * const bar = new ProgressBar(100, {\n * width: 50,\n * format: ':bar :percent :current/:total :eta',\n * color: 'green'\n * })\n * ```\n */\n constructor(total: number, options?: ProgressBarOptions) {\n this.total = total\n this.startTime = Date.now()\n this.stream = options?.stream || process.stderr\n this.options = {\n width: 40,\n format: ':bar :percent :current/:total',\n complete: '\u2588',\n incomplete: '\u2591',\n head: '',\n clear: false,\n // ~60fps.\n renderThrottle: 16,\n stream: this.stream,\n color: 'cyan',\n ...options,\n }\n }\n\n /**\n * Update progress to a specific value and redraw the bar.\n * Updates are throttled to prevent excessive rendering (default ~60fps).\n *\n * @param current - Current progress value (will be clamped to total)\n * @param tokens - Optional custom tokens to replace in format string\n *\n * @example\n * ```ts\n * bar.update(50)\n * bar.update(75, { status: 'Processing...' })\n * ```\n */\n update(current: number, tokens?: Record<string, unknown>): void {\n if (this.terminated) {\n return\n }\n\n this.current = Math.min(current, this.total)\n\n // Throttle rendering\n const now = Date.now()\n if (\n now - this.lastRender < this.options.renderThrottle &&\n this.current < this.total\n ) {\n return\n }\n this.lastRender = now\n\n this.render(tokens)\n\n if (this.current >= this.total) {\n this.terminate()\n }\n }\n\n /**\n * Increment progress by a specified amount.\n * Convenience method for `update(current + amount)`.\n *\n * @param amount - Amount to increment by\n * @param tokens - Optional custom tokens to replace in format string\n * @default amount 1\n *\n * @example\n * ```ts\n * bar.tick() // Increment by 1\n * bar.tick(5) // Increment by 5\n * bar.tick(1, { file: 'data.json' })\n * ```\n */\n tick(amount: number = 1, tokens?: Record<string, unknown>): void {\n this.update(this.current + amount, tokens)\n }\n\n /**\n * Render the progress bar.\n */\n private render(tokens?: Record<string, unknown>): void {\n const colorFn = colors[this.options.color] || ((s: string) => s)\n\n // Calculate values\n const percent = Math.floor((this.current / this.total) * 100)\n const elapsed = Date.now() - this.startTime\n const eta =\n this.current === 0\n ? 0\n : (elapsed / this.current) * (this.total - this.current)\n\n // Build bar\n const availableWidth = this.options.width\n const filledWidth = Math.floor((this.current / this.total) * availableWidth)\n const emptyWidth = availableWidth - filledWidth\n\n const filled = repeatString(this.options.complete, filledWidth)\n const empty = repeatString(this.options.incomplete, emptyWidth)\n const bar = colorFn(filled) + empty\n\n // Format output\n let output = this.options.format\n output = output.replace(':bar', bar)\n output = output.replace(':percent', `${percent}%`)\n output = output.replace(':current', String(this.current))\n output = output.replace(':total', String(this.total))\n output = output.replace(':elapsed', this.formatTime(elapsed))\n output = output.replace(':eta', this.formatTime(eta))\n\n // Replace custom tokens\n if (tokens) {\n for (const [key, value] of Object.entries(tokens)) {\n output = output.replace(`:${key}`, String(value))\n }\n }\n\n // Clear line and write\n this.clearLine()\n this.stream.write(output)\n this.lastDrawnWidth = stripAnsi(output).length\n }\n\n /**\n * Clear the current line.\n */\n private clearLine(): void {\n if (this.stream.isTTY) {\n this.stream.cursorTo(0)\n this.stream.clearLine(0)\n } else if (this.lastDrawnWidth > 0) {\n this.stream.write(`\\r${repeatString(' ', this.lastDrawnWidth)}\\r`)\n }\n }\n\n /**\n * Format time in seconds to human readable.\n */\n private formatTime(ms: number): string {\n const seconds = Math.round(ms / 1000)\n if (seconds < 60) {\n return `${seconds}s`\n }\n const minutes = Math.floor(seconds / 60)\n const remainingSeconds = seconds % 60\n return `${minutes}m${remainingSeconds}s`\n }\n\n /**\n * Terminate the progress bar and optionally clear it.\n * Called automatically when progress reaches 100%.\n * If `clear` option is true, removes the bar from terminal.\n * Otherwise, moves to next line to preserve the final state.\n */\n terminate(): void {\n if (this.terminated) {\n return\n }\n this.terminated = true\n\n if (this.options.clear) {\n this.clearLine()\n } else {\n this.stream.write('\\n')\n }\n }\n}\n\n/**\n * Create a simple progress indicator without a graphical bar.\n * Returns a formatted string showing progress as percentage and fraction.\n *\n * @param current - Current progress value\n * @param total - Total progress value\n * @param label - Optional label prefix\n * @returns Formatted progress indicator string\n *\n * @example\n * ```ts\n * createProgressIndicator(50, 100)\n * // Returns: '[50%] 50/100'\n *\n * createProgressIndicator(3, 10, 'Files')\n * // Returns: 'Files: [30%] 3/10'\n * ```\n */\nexport function createProgressIndicator(\n current: number,\n total: number,\n label?: string | undefined,\n): string {\n const percent = Math.floor((current / total) * 100)\n const progress = `${current}/${total}`\n\n let output = ''\n if (label) {\n output += `${label}: `\n }\n\n output += `${colors.cyan(`[${percent}%]`)} ${progress}`\n\n return output\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": ["
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,6BAAmB;AACnB,qBAAwC;AAyDjC,MAAM,YAAY;AAAA,EACf,UAAkB;AAAA,EAClB;AAAA,EACA;AAAA,EACA,aAAqB;AAAA,EACrB;AAAA,EACA;AAAA,EACA,aAAsB;AAAA,EACtB,iBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBjC,YAAY,OAAe,SAA8B;AACvD,SAAK,QAAQ;AACb,SAAK,YAAY,KAAK,IAAI;AAC1B,SAAK,SAAS,SAAS,UAAU,QAAQ;AACzC,SAAK,UAAU;AAAA,MACb,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,MAAM;AAAA,MACN,OAAO;AAAA;AAAA,MAEP,gBAAgB;AAAA,MAChB,QAAQ,KAAK;AAAA,MACb,OAAO;AAAA,MACP,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,OAAO,SAAiB,QAAwC;AAC9D,QAAI,KAAK,YAAY;AACnB;AAAA,IACF;AAEA,SAAK,UAAU,KAAK,IAAI,SAAS,KAAK,KAAK;AAG3C,UAAM,MAAM,KAAK,IAAI;AACrB,Q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;AACb,MAAI,OAAO;AACT,cAAU,GAAG,KAAK;AAAA,EACpB;AAEA,YAAU,GAAG,uBAAAA,QAAO,KAAK,IAAI,OAAO,IAAI,CAAC,IAAI,QAAQ;AAErD,SAAO;AACT;",
|
|
6
|
+
"names": ["colors"]
|
|
7
7
|
}
|
package/dist/stdio/prompts.js
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var prompts_exports = {};
|
|
20
|
+
__export(prompts_exports, {
|
|
21
|
+
Separator: () => ActualSeparator,
|
|
22
|
+
confirm: () => confirm,
|
|
23
|
+
input: () => input,
|
|
24
|
+
password: () => password,
|
|
25
|
+
search: () => search,
|
|
26
|
+
select: () => select,
|
|
27
|
+
wrapPrompt: () => wrapPrompt
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(prompts_exports);
|
|
30
|
+
var import_process = require("#constants/process");
|
|
31
|
+
const abortSignal = (0, import_process.getAbortSignal)();
|
|
32
|
+
const spinner = (0, import_process.getSpinner)();
|
|
33
|
+
// @__NO_SIDE_EFFECTS__
|
|
34
|
+
function wrapPrompt(inquirerPrompt) {
|
|
35
|
+
return async (...args) => {
|
|
36
|
+
const origContext = args.length > 1 ? args[1] : void 0;
|
|
37
|
+
const { spinner: contextSpinner, ...contextWithoutSpinner } = origContext ?? {};
|
|
38
|
+
const spinnerInstance = contextSpinner !== void 0 ? contextSpinner : spinner;
|
|
39
|
+
const signal = abortSignal;
|
|
40
|
+
if (origContext) {
|
|
41
|
+
args[1] = {
|
|
42
|
+
signal,
|
|
43
|
+
...contextWithoutSpinner
|
|
44
|
+
};
|
|
45
|
+
} else {
|
|
46
|
+
args[1] = { signal };
|
|
47
|
+
}
|
|
48
|
+
const wasSpinning = !!spinnerInstance?.isSpinning;
|
|
49
|
+
spinnerInstance?.stop();
|
|
50
|
+
let result;
|
|
51
|
+
try {
|
|
52
|
+
result = await inquirerPrompt(...args);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
if (e instanceof TypeError) {
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (wasSpinning) {
|
|
59
|
+
spinnerInstance.start();
|
|
60
|
+
}
|
|
61
|
+
return typeof result === "string" ? result.trim() : result;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const confirmExport = require("../external/@inquirer/confirm");
|
|
65
|
+
const inputExport = require("../external/@inquirer/input");
|
|
66
|
+
const passwordExport = require("../external/@inquirer/password");
|
|
67
|
+
const searchExport = require("../external/@inquirer/search");
|
|
68
|
+
const selectExport = require("../external/@inquirer/select");
|
|
69
|
+
const confirmRaw = confirmExport.default ?? confirmExport;
|
|
70
|
+
const inputRaw = inputExport.default ?? inputExport;
|
|
71
|
+
const passwordRaw = passwordExport.default ?? passwordExport;
|
|
72
|
+
const searchRaw = searchExport.default ?? searchExport;
|
|
73
|
+
const selectRaw = selectExport.default ?? selectExport;
|
|
74
|
+
const ActualSeparator = selectExport.Separator;
|
|
75
|
+
const confirm = /* @__PURE__ */ wrapPrompt(confirmRaw);
|
|
76
|
+
const input = /* @__PURE__ */ wrapPrompt(inputRaw);
|
|
77
|
+
const password = /* @__PURE__ */ wrapPrompt(passwordRaw);
|
|
78
|
+
const search = /* @__PURE__ */ wrapPrompt(searchRaw);
|
|
79
|
+
const select = /* @__PURE__ */ wrapPrompt(selectRaw);
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
Separator,
|
|
83
|
+
confirm,
|
|
84
|
+
input,
|
|
85
|
+
password,
|
|
86
|
+
search,
|
|
87
|
+
select,
|
|
88
|
+
wrapPrompt
|
|
89
|
+
});
|
|
3
90
|
//# sourceMappingURL=prompts.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/stdio/prompts.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * @fileoverview User prompt utilities for interactive scripts.\n * Provides inquirer.js integration with spinner support and context handling.\n */\n\nimport { getAbortSignal, getSpinner } from '#constants/process'\n\nconst abortSignal = getAbortSignal()\nconst spinner = getSpinner()\n\n// Type definitions\n\n/**\n * Choice option for select and search prompts.\n *\n * @template Value - Type of the choice value\n */\nexport interface Choice<Value = unknown> {\n /** The value returned when this choice is selected */\n value: Value\n /** Whether this choice is disabled, or a reason string */\n disabled?: boolean | string | undefined\n /** Additional description text shown below the choice */\n description?: string | undefined\n /** Display name for the choice (defaults to value.toString()) */\n name?: string | undefined\n /** Short text shown after selection (defaults to name) */\n short?: string | undefined\n}\n\n/**\n * Context for inquirer prompts.\n * Minimal context interface used by Inquirer prompts.\n * Duplicated from `@inquirer/type` - InquirerContext.\n */\ninterface InquirerContext {\n /** Abort signal for cancelling the prompt */\n signal?: AbortSignal | undefined\n /** Input stream (defaults to process.stdin) */\n input?: NodeJS.ReadableStream | undefined\n /** Output stream (defaults to process.stdout) */\n output?: NodeJS.WritableStream | undefined\n /** Clear the prompt from terminal when done */\n clearPromptOnDone?: boolean | undefined\n}\n\n/**\n * Extended context with spinner support.\n * Allows passing a spinner instance to be managed during prompts.\n */\nexport type Context = import('../objects').Remap<\n InquirerContext & {\n /** Optional spinner to stop/start during prompt display */\n spinner?: import('../spinner').Spinner | undefined\n }\n>\n\n/**\n * Separator for visual grouping in select/checkbox prompts.\n * Creates a non-selectable visual separator line.\n * Duplicated from `@inquirer/select` - Separator.\n * This type definition ensures the Separator type is available in published packages.\n *\n * @example\n * import { Separator } from './prompts'\n *\n * const choices = [\n * { name: 'Option 1', value: 1 },\n * new Separator(),\n * { name: 'Option 2', value: 2 }\n * ]\n */\ndeclare class SeparatorType {\n readonly separator: string\n readonly type: 'separator'\n constructor(separator?: string)\n}\n\nexport type Separator = SeparatorType\n\n/**\n * Wrap an inquirer prompt with spinner handling and signal injection.\n * Automatically stops/starts spinners during prompt display and injects abort signals.\n * Trims string results and handles cancellation gracefully.\n *\n * @template T - Type of the prompt result\n * @param inquirerPrompt - The inquirer prompt function to wrap\n * @returns Wrapped prompt function with spinner and signal handling\n *\n * @example\n * const myPrompt = wrapPrompt(rawInquirerPrompt)\n * const result = await myPrompt({ message: 'Enter name:' })\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function wrapPrompt<T = unknown>(\n inquirerPrompt: (...args: unknown[]) => Promise<T>,\n): (...args: unknown[]) => Promise<T | undefined> {\n return async (...args) => {\n const origContext = (args.length > 1 ? args[1] : undefined) as\n | Context\n | undefined\n const { spinner: contextSpinner, ...contextWithoutSpinner } =\n origContext ?? ({} as Context)\n const spinnerInstance =\n contextSpinner !== undefined ? contextSpinner : spinner\n const signal = abortSignal\n if (origContext) {\n args[1] = {\n signal,\n ...contextWithoutSpinner,\n }\n } else {\n args[1] = { signal }\n }\n const wasSpinning = !!spinnerInstance?.isSpinning\n spinnerInstance?.stop()\n let result: unknown\n try {\n result = await inquirerPrompt(...args)\n } catch (e) {\n if (e instanceof TypeError) {\n throw e\n }\n }\n if (wasSpinning) {\n spinnerInstance.start()\n }\n return (typeof result === 'string' ? result.trim() : result) as\n | T\n | undefined\n }\n}\n\n// c8 ignore start - Third-party inquirer library requires and exports not testable in isolation.\nconst confirmExport = /*@__PURE__*/ require('../external/@inquirer/confirm')\nconst inputExport = /*@__PURE__*/ require('../external/@inquirer/input')\nconst passwordExport = /*@__PURE__*/ require('../external/@inquirer/password')\nconst searchExport = /*@__PURE__*/ require('../external/@inquirer/search')\nconst selectExport = /*@__PURE__*/ require('../external/@inquirer/select')\nconst confirmRaw = confirmExport.default ?? confirmExport\nconst inputRaw = inputExport.default ?? inputExport\nconst passwordRaw = passwordExport.default ?? passwordExport\nconst searchRaw = searchExport.default ?? searchExport\nconst selectRaw = selectExport.default ?? selectExport\nconst ActualSeparator = selectExport.Separator\n// c8 ignore stop\n\n/**\n * Prompt for a yes/no confirmation.\n * Wrapped with spinner handling and abort signal support.\n *\n * @example\n * const answer = await confirm({ message: 'Continue?' })\n * if (answer) { // user confirmed }\n */\nexport const confirm: typeof confirmRaw = wrapPrompt(confirmRaw)\n\n/**\n * Prompt for text input.\n * Wrapped with spinner handling and abort signal support.\n * Result is automatically trimmed.\n *\n * @example\n * const name = await input({ message: 'Enter your name:' })\n */\nexport const input: typeof inputRaw = wrapPrompt(inputRaw)\n\n/**\n * Prompt for password input (hidden characters).\n * Wrapped with spinner handling and abort signal support.\n *\n * @example\n * const token = await password({ message: 'Enter API token:' })\n */\nexport const password: typeof passwordRaw = wrapPrompt(passwordRaw)\n\n/**\n * Prompt with searchable/filterable choices.\n * Wrapped with spinner handling and abort signal support.\n *\n * @example\n * const result = await search({\n * message: 'Select a package:',\n * source: async (input) => fetchPackages(input)\n * })\n */\nexport const search: typeof searchRaw = wrapPrompt(searchRaw)\n\n/**\n * Prompt to select from a list of choices.\n * Wrapped with spinner handling and abort signal support.\n *\n * @example\n * const choice = await select({\n * message: 'Choose an option:',\n * choices: [\n * { name: 'Option 1', value: 'opt1' },\n * { name: 'Option 2', value: 'opt2' }\n * ]\n * })\n */\nexport const select: typeof selectRaw = wrapPrompt(selectRaw)\n\nexport { ActualSeparator as Separator }\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,qBAA2C;AAE3C,MAAM,kBAAc,+BAAe;AACnC,MAAM,cAAU,2BAAW;AAAA;AAsFpB,SAAS,WACd,gBACgD;AAChD,SAAO,UAAU,SAAS;AACxB,UAAM,cAAe,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI;AAGjD,UAAM,EAAE,SAAS,gBAAgB,GAAG,sBAAsB,IACxD,eAAgB,CAAC;AACnB,UAAM,kBACJ,mBAAmB,SAAY,iBAAiB;AAClD,UAAM,SAAS;AACf,QAAI,aAAa;AACf,WAAK,CAAC,IAAI;AAAA,QACR;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF,OAAO;AACL,WAAK,CAAC,IAAI,EAAE,OAAO;AAAA,IACrB;AACA,UAAM,cAAc,CAAC,CAAC,iBAAiB;AACvC,qBAAiB,KAAK;AACtB,QAAI;AACJ,QAAI;AACF,eAAS,MAAM,eAAe,GAAG,IAAI;AAAA,IACvC,SAAS,GAAG;AACV,UAAI,aAAa,WAAW;AAC1B,cAAM;AAAA,MACR;AAAA,IACF;AACA,QAAI,aAAa;AACf,sBAAgB,MAAM;AAAA,IACxB;AACA,WAAQ,OAAO,WAAW,WAAW,OAAO,KAAK,IAAI;AAAA,EAGvD;AACF;AAGA,MAAM,gBAA8B,QAAQ,+BAA+B;AAC3E,MAAM,cAA4B,QAAQ,6BAA6B;AACvE,MAAM,iBAA+B,QAAQ,gCAAgC;AAC7E,MAAM,eAA6B,QAAQ,8BAA8B;AACzE,MAAM,eAA6B,QAAQ,8BAA8B;AACzE,MAAM,aAAa,cAAc,WAAW;AAC5C,MAAM,WAAW,YAAY,WAAW;AACxC,MAAM,cAAc,eAAe,WAAW;AAC9C,MAAM,YAAY,aAAa,WAAW;AAC1C,MAAM,YAAY,aAAa,WAAW;AAC1C,MAAM,kBAAkB,aAAa;AAW9B,MAAM,UAA6B,2BAAW,UAAU;AAUxD,MAAM,QAAyB,2BAAW,QAAQ;AASlD,MAAM,WAA+B,2BAAW,WAAW;AAY3D,MAAM,SAA2B,2BAAW,SAAS;AAerD,MAAM,SAA2B,2BAAW,SAAS;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/stdio/stderr.js
CHANGED
|
@@ -1,4 +1,91 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var stderr_exports = {};
|
|
20
|
+
__export(stderr_exports, {
|
|
21
|
+
clearLine: () => clearLine,
|
|
22
|
+
cursorTo: () => cursorTo,
|
|
23
|
+
getColumns: () => getColumns,
|
|
24
|
+
getRows: () => getRows,
|
|
25
|
+
isTTY: () => isTTY,
|
|
26
|
+
stderr: () => stderr,
|
|
27
|
+
writeError: () => writeError,
|
|
28
|
+
writeErrorFormatted: () => writeErrorFormatted,
|
|
29
|
+
writeErrorLine: () => writeErrorLine,
|
|
30
|
+
writeStackTrace: () => writeStackTrace,
|
|
31
|
+
writeWarning: () => writeWarning
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(stderr_exports);
|
|
34
|
+
const stderr = process.stderr;
|
|
35
|
+
function writeErrorLine(text = "") {
|
|
36
|
+
stderr.write(`${text}
|
|
37
|
+
`);
|
|
38
|
+
}
|
|
39
|
+
function writeError(text) {
|
|
40
|
+
stderr.write(text);
|
|
41
|
+
}
|
|
42
|
+
function clearLine() {
|
|
43
|
+
if (stderr.isTTY) {
|
|
44
|
+
stderr.cursorTo(0);
|
|
45
|
+
stderr.clearLine(0);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function cursorTo(x, y) {
|
|
49
|
+
if (stderr.isTTY) {
|
|
50
|
+
stderr.cursorTo(x, y);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function isTTY() {
|
|
54
|
+
return stderr.isTTY || false;
|
|
55
|
+
}
|
|
56
|
+
function getColumns() {
|
|
57
|
+
return stderr.columns || 80;
|
|
58
|
+
}
|
|
59
|
+
function getRows() {
|
|
60
|
+
return stderr.rows || 24;
|
|
61
|
+
}
|
|
62
|
+
function writeWarning(message, prefix = "Warning") {
|
|
63
|
+
const formatted = `${prefix}: ${message}`;
|
|
64
|
+
writeErrorLine(formatted);
|
|
65
|
+
}
|
|
66
|
+
function writeErrorFormatted(message, prefix = "Error") {
|
|
67
|
+
const formatted = `${prefix}: ${message}`;
|
|
68
|
+
writeErrorLine(formatted);
|
|
69
|
+
}
|
|
70
|
+
function writeStackTrace(error) {
|
|
71
|
+
if (error.stack) {
|
|
72
|
+
writeErrorLine(error.stack);
|
|
73
|
+
} else {
|
|
74
|
+
writeErrorFormatted(error.message);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
clearLine,
|
|
80
|
+
cursorTo,
|
|
81
|
+
getColumns,
|
|
82
|
+
getRows,
|
|
83
|
+
isTTY,
|
|
84
|
+
stderr,
|
|
85
|
+
writeError,
|
|
86
|
+
writeErrorFormatted,
|
|
87
|
+
writeErrorLine,
|
|
88
|
+
writeStackTrace,
|
|
89
|
+
writeWarning
|
|
90
|
+
});
|
|
4
91
|
//# sourceMappingURL=stderr.js.map
|
package/dist/stdio/stderr.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/stdio/stderr.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * @fileoverview Standard error stream utilities.\n * Provides utilities for writing to stderr with formatting and control.\n */\n\n// Get the actual stderr stream\nconst stderr: NodeJS.WriteStream = process.stderr\n\n/**\n * Write a line to stderr with trailing newline.\n * Used for error messages, warnings, and diagnostic output.\n *\n * @param text - Text to write\n * @default text ''\n *\n * @example\n * ```ts\n * writeErrorLine('Error: File not found')\n * writeErrorLine() // Write empty line\n * ```\n */\nexport function writeErrorLine(text: string = ''): void {\n stderr.write(`${text}\\n`)\n}\n\n/**\n * Write text to stderr without adding a newline.\n *\n * @param text - Text to write\n *\n * @example\n * ```ts\n * writeError('Downloading...')\n * // Later update progress\n * ```\n */\nexport function writeError(text: string): void {\n stderr.write(text)\n}\n\n/**\n * Clear the current line on stderr.\n * Only works in TTY environments.\n *\n * @example\n * ```ts\n * writeError('Processing...')\n * clearLine()\n * writeError('Done!')\n * ```\n */\nexport function clearLine(): void {\n if (stderr.isTTY) {\n stderr.cursorTo(0)\n stderr.clearLine(0)\n }\n}\n\n/**\n * Move cursor to specific position on stderr.\n * Only works in TTY environments.\n *\n * @param x - Column position (0-based)\n * @param y - Row position (0-based, optional)\n *\n * @example\n * ```ts\n * cursorTo(0) // Move to start of line\n * cursorTo(10, 5) // Move to column 10, row 5\n * ```\n */\nexport function cursorTo(x: number, y?: number | undefined): void {\n if (stderr.isTTY) {\n stderr.cursorTo(x, y)\n }\n}\n\n/**\n * Check if stderr is connected to a TTY (terminal).\n *\n * @returns `true` if stderr is a TTY, `false` if piped/redirected\n *\n * @example\n * ```ts\n * if (isTTY()) {\n * // Show colored error messages\n * } else {\n * // Use plain text\n * }\n * ```\n */\nexport function isTTY(): boolean {\n return stderr.isTTY || false\n}\n\n/**\n * Get the number of columns (width) in the terminal.\n *\n * @returns Terminal width in characters\n * @default 80\n *\n * @example\n * ```ts\n * const width = getColumns()\n * console.error(`Terminal is ${width} characters wide`)\n * ```\n */\nexport function getColumns(): number {\n return stderr.columns || 80\n}\n\n/**\n * Get the number of rows (height) in the terminal.\n *\n * @returns Terminal height in lines\n * @default 24\n *\n * @example\n * ```ts\n * const height = getRows()\n * console.error(`Terminal is ${height} lines tall`)\n * ```\n */\nexport function getRows(): number {\n return stderr.rows || 24\n}\n\n/**\n * Write a formatted warning message to stderr.\n *\n * @param message - Warning message text\n * @param prefix - Prefix label for the warning\n * @default prefix 'Warning'\n *\n * @example\n * ```ts\n * writeWarning('Deprecated API usage')\n * // Output: 'Warning: Deprecated API usage'\n *\n * writeWarning('Invalid config', 'Config')\n * // Output: 'Config: Invalid config'\n * ```\n */\nexport function writeWarning(\n message: string,\n prefix: string = 'Warning',\n): void {\n const formatted = `${prefix}: ${message}`\n writeErrorLine(formatted)\n}\n\n/**\n * Write a formatted error message to stderr.\n *\n * @param message - Error message text\n * @param prefix - Prefix label for the error\n * @default prefix 'Error'\n *\n * @example\n * ```ts\n * writeErrorFormatted('File not found')\n * // Output: 'Error: File not found'\n *\n * writeErrorFormatted('Connection failed', 'Network')\n * // Output: 'Network: Connection failed'\n * ```\n */\nexport function writeErrorFormatted(\n message: string,\n prefix: string = 'Error',\n): void {\n const formatted = `${prefix}: ${message}`\n writeErrorLine(formatted)\n}\n\n/**\n * Write an error's stack trace to stderr.\n * Falls back to formatted error message if no stack is available.\n *\n * @param error - Error object to write\n *\n * @example\n * ```ts\n * try {\n * throw new Error('Something went wrong')\n * } catch (err) {\n * writeStackTrace(err as Error)\n * }\n * ```\n */\nexport function writeStackTrace(error: Error): void {\n if (error.stack) {\n writeErrorLine(error.stack)\n } else {\n writeErrorFormatted(error.message)\n }\n}\n\n// Export the raw stream for advanced usage\nexport { stderr }\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,MAAM,SAA6B,QAAQ;AAepC,SAAS,eAAe,OAAe,IAAU;AACtD,SAAO,MAAM,GAAG,IAAI;AAAA,CAAI;AAC1B;AAaO,SAAS,WAAW,MAAoB;AAC7C,SAAO,MAAM,IAAI;AACnB;AAaO,SAAS,YAAkB;AAChC,MAAI,OAAO,OAAO;AAChB,WAAO,SAAS,CAAC;AACjB,WAAO,UAAU,CAAC;AAAA,EACpB;AACF;AAeO,SAAS,SAAS,GAAW,GAA8B;AAChE,MAAI,OAAO,OAAO;AAChB,WAAO,SAAS,GAAG,CAAC;AAAA,EACtB;AACF;AAgBO,SAAS,QAAiB;AAC/B,SAAO,OAAO,SAAS;AACzB;AAcO,SAAS,aAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAcO,SAAS,UAAkB;AAChC,SAAO,OAAO,QAAQ;AACxB;AAkBO,SAAS,aACd,SACA,SAAiB,WACX;AACN,QAAM,YAAY,GAAG,MAAM,KAAK,OAAO;AACvC,iBAAe,SAAS;AAC1B;AAkBO,SAAS,oBACd,SACA,SAAiB,SACX;AACN,QAAM,YAAY,GAAG,MAAM,KAAK,OAAO;AACvC,iBAAe,SAAS;AAC1B;AAiBO,SAAS,gBAAgB,OAAoB;AAClD,MAAI,MAAM,OAAO;AACf,mBAAe,MAAM,KAAK;AAAA,EAC5B,OAAO;AACL,wBAAoB,MAAM,OAAO;AAAA,EACnC;AACF;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|