@learnosity/lib-qti-converter 0.16.0 → 0.16.2

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.
Files changed (41) hide show
  1. package/package.json +10 -10
  2. package/packages/cli/dist/{batchProcessors-C7czhqX0.js → batchProcessors-BGdELwug.js} +75 -102
  3. package/packages/cli/dist/batchProcessors-BGdELwug.js.map +1 -0
  4. package/packages/cli/dist/batchWorker.js +2 -3
  5. package/packages/cli/dist/{configOutput-FwkFyQmk.js → configOutput-DYPwNQf7.js} +5 -9
  6. package/packages/cli/dist/{configOutput-FwkFyQmk.js.map → configOutput-DYPwNQf7.js.map} +1 -1
  7. package/packages/cli/dist/{create-prompt-dWckcotJ.js → create-prompt-C3XKo-s3.js} +95 -71
  8. package/packages/cli/dist/create-prompt-C3XKo-s3.js.map +1 -0
  9. package/packages/cli/dist/{dist-DXDR2peT.js → dist-D7b9-VIt.js} +8 -11
  10. package/packages/cli/dist/dist-D7b9-VIt.js.map +1 -0
  11. package/packages/cli/dist/{learnosityToQti-D4ddrXaz.js → learnosityToQti-CN6KKSmF.js} +5 -6
  12. package/packages/cli/dist/{learnosityToQti-D4ddrXaz.js.map → learnosityToQti-CN6KKSmF.js.map} +1 -1
  13. package/packages/cli/dist/{learnosityToQtiPackage-Bwzm-uLX.js → learnosityToQtiPackage-CMOQRiCV.js} +29 -21
  14. package/packages/cli/dist/learnosityToQtiPackage-CMOQRiCV.js.map +1 -0
  15. package/packages/cli/dist/main.js +22 -29
  16. package/packages/cli/dist/main.js.map +1 -1
  17. package/packages/cli/dist/{nodeFileAccess-BhCoGDOi.js → nodeFileAccess-_jRCd340.js} +6 -10
  18. package/packages/cli/dist/{nodeFileAccess-BhCoGDOi.js.map → nodeFileAccess-_jRCd340.js.map} +1 -1
  19. package/packages/cli/dist/pathUtils-I2bRHUwu.js +2922 -0
  20. package/packages/cli/dist/pathUtils-I2bRHUwu.js.map +1 -0
  21. package/packages/cli/dist/{qtiPackageToLearnosity-CX9htPId.js → qtiPackageToLearnosity-JRb3TTyC.js} +7 -8
  22. package/packages/cli/dist/{qtiPackageToLearnosity-CX9htPId.js.map → qtiPackageToLearnosity-JRb3TTyC.js.map} +1 -1
  23. package/packages/cli/dist/{qtiToLearnosity-JQYOkNbM.js → qtiToLearnosity-C-jQYKqR.js} +6 -7
  24. package/packages/cli/dist/{qtiToLearnosity-JQYOkNbM.js.map → qtiToLearnosity-C-jQYKqR.js.map} +1 -1
  25. package/packages/cli/dist/{resolveOptions-BuNN2KMA.js → resolveOptions-ikupjaRQ.js} +322 -359
  26. package/packages/cli/dist/resolveOptions-ikupjaRQ.js.map +1 -0
  27. package/packages/cli/dist/{rolldown-runtime-DktXgydw.js → rolldown-runtime-BuRBZLzk.js} +13 -12
  28. package/packages/cli/dist/{table-DsKq-B4-.js → table-6SiZD7aK.js} +9944 -2294
  29. package/packages/cli/dist/table-6SiZD7aK.js.map +1 -0
  30. package/packages/core/dist/index.d.ts +8 -58
  31. package/packages/core/dist/index.js +9923 -2267
  32. package/packages/core/dist/node.d.ts +10 -80
  33. package/packages/core/dist/node.js +9951 -2311
  34. package/packages/cli/dist/batchProcessors-C7czhqX0.js.map +0 -1
  35. package/packages/cli/dist/create-prompt-dWckcotJ.js.map +0 -1
  36. package/packages/cli/dist/dist-DXDR2peT.js.map +0 -1
  37. package/packages/cli/dist/learnosityToQtiPackage-Bwzm-uLX.js.map +0 -1
  38. package/packages/cli/dist/pathUtils-D_VsVde8.js +0 -2272
  39. package/packages/cli/dist/pathUtils-D_VsVde8.js.map +0 -1
  40. package/packages/cli/dist/resolveOptions-BuNN2KMA.js.map +0 -1
  41. package/packages/cli/dist/table-DsKq-B4-.js.map +0 -1
@@ -1,15 +1,15 @@
1
- import { i as __toESM } from "./rolldown-runtime-DktXgydw.js";
2
- import { r as onExit } from "./create-prompt-dWckcotJ.js";
3
- import { t as dist_default } from "./dist-DXDR2peT.js";
4
- import { a as chalk, c as dist_default$1, i as boxen, o as eastAsianWidth, s as stripAnsi, t as expandTilde } from "./pathUtils-D_VsVde8.js";
5
- import { D as parseLearnosityItem, S as mapLearnosityToAst, a as require_cli_table3, b as serializeAssessmentItem, c as transformForwardAssetUrlsInXml, i as chalk$1, l as convertQtiAssessmentItemToLearnosity } from "./table-DsKq-B4-.js";
1
+ import { i as __toESM } from "./rolldown-runtime-BuRBZLzk.js";
2
+ import { r as onExit } from "./create-prompt-C3XKo-s3.js";
3
+ import { t as dist_default } from "./dist-D7b9-VIt.js";
4
+ import { a as stringWidth, i as boxen, o as dist_default$1, t as expandTilde } from "./pathUtils-I2bRHUwu.js";
5
+ import { E as parseLearnosityItem, a as require_cli_table3, c as convertQtiAssessmentItemToLearnosity, i as chalk, s as transformForwardAssetUrlsInXml, x as mapLearnosityToAst, y as serializeAssessmentItem } from "./table-6SiZD7aK.js";
6
6
  import process$1 from "node:process";
7
7
  import { stripVTControlCharacters } from "node:util";
8
8
  import { mkdir, readFile, stat, writeFile } from "fs/promises";
9
9
  import { dirname } from "path";
10
10
  import tty from "node:tty";
11
11
  import { createInterface } from "readline";
12
- //#region ../core/src/conversions.ts
12
+ // ../core/src/conversions.ts
13
13
  /**
14
14
  * Convert QTI XML to Learnosity JSON.
15
15
  *
@@ -84,8 +84,7 @@ function convertLearnosityToQti(input, opts) {
84
84
  diagnostics: allDiagnostics
85
85
  });
86
86
  }
87
- //#endregion
88
- //#region src/io/readInput.ts
87
+ // src/io/readInput.ts
89
88
  /**
90
89
  * Read input from file or stdin
91
90
  * @param inputPath - File path or '-' for stdin
@@ -107,7 +106,7 @@ async function readStdin() {
107
106
  const chunks = [];
108
107
  const rl = createInterface({
109
108
  input: process.stdin,
110
- crlfDelay: Infinity
109
+ crlfDelay: 1e400
111
110
  });
112
111
  for await (const line of rl) chunks.push(line);
113
112
  return chunks.join("\n");
@@ -124,8 +123,7 @@ function parseJsonInput(input) {
124
123
  throw new Error(`Failed to parse JSON input: ${error instanceof Error ? error.message : "unknown error"}`);
125
124
  }
126
125
  }
127
- //#endregion
128
- //#region src/io/writeOutput.ts
126
+ // src/io/writeOutput.ts
129
127
  /**
130
128
  * Write output to file or stdout
131
129
  * @param outputPath - File path or '-' for stdout
@@ -144,8 +142,7 @@ async function writeOutput(outputPath, content, pretty = false) {
144
142
  await writeFile(outputPath, output, "utf-8");
145
143
  }
146
144
  }
147
- //#endregion
148
- //#region src/ux/resolvedOptions.ts
145
+ // src/ux/resolvedOptions.ts
149
146
  var import_cli_table3 = /* @__PURE__ */ __toESM(require_cli_table3(), 1);
150
147
  /**
151
148
  * Display resolved options in a box
@@ -153,20 +150,20 @@ var import_cli_table3 = /* @__PURE__ */ __toESM(require_cli_table3(), 1);
153
150
  function showResolvedOptions(options, withSources, quiet = false) {
154
151
  if (quiet) return;
155
152
  const lines = [];
156
- lines.push(chalk$1.bold("Resolved Options"));
153
+ lines.push(chalk.bold("Resolved Options"));
157
154
  lines.push("");
158
- lines.push(`${chalk$1.dim("Input:")} ${options.inputPath}`);
159
- lines.push(`${chalk$1.dim("Output:")} ${options.outputPath}`);
160
- lines.push(`${chalk$1.dim("QTI Version:")} ${options.qtiVersion}`);
161
- lines.push(`${chalk$1.dim("Output Format:")} ${options.outputFormat}`);
162
- lines.push(`${chalk$1.dim("Diagnostics:")} ${options.diagnostics}`);
163
- lines.push(`${chalk$1.dim("Pretty:")} ${options.pretty}`);
164
- lines.push(`${chalk$1.dim("Verbose:")} ${options.verbose}`);
165
- if (options.organisationId !== void 0) lines.push(`${chalk$1.dim("Organisation ID:")} ${options.organisationId}`);
166
- if (options.mediaVault !== void 0) lines.push(`${chalk$1.dim("Media Vault:")} ${options.mediaVault}`);
167
- if (options.customAssetUrl !== void 0) lines.push(`${chalk$1.dim("Custom Asset URL:")} ${options.customAssetUrl}`);
168
- lines.push(`${chalk$1.dim("Preserve Asset Filenames:")} ${options.preserveAssetFilenames}`);
169
- lines.push(`${chalk$1.dim("Config:")} ${options.configPath ?? "none"}`);
155
+ lines.push(`${chalk.dim("Input:")} ${options.inputPath}`);
156
+ lines.push(`${chalk.dim("Output:")} ${options.outputPath}`);
157
+ lines.push(`${chalk.dim("QTI Version:")} ${options.qtiVersion}`);
158
+ lines.push(`${chalk.dim("Output Format:")} ${options.outputFormat}`);
159
+ lines.push(`${chalk.dim("Diagnostics:")} ${options.diagnostics}`);
160
+ lines.push(`${chalk.dim("Pretty:")} ${options.pretty}`);
161
+ lines.push(`${chalk.dim("Verbose:")} ${options.verbose}`);
162
+ if (options.organisationId !== void 0) lines.push(`${chalk.dim("Organisation ID:")} ${options.organisationId}`);
163
+ if (options.mediaVault !== void 0) lines.push(`${chalk.dim("Media Vault:")} ${options.mediaVault}`);
164
+ if (options.customAssetUrl !== void 0) lines.push(`${chalk.dim("Custom Asset URL:")} ${options.customAssetUrl}`);
165
+ lines.push(`${chalk.dim("Preserve Asset Filenames:")} ${options.preserveAssetFilenames}`);
166
+ lines.push(`${chalk.dim("Config:")} ${options.configPath ?? "none"}`);
170
167
  const box = boxen(lines.join("\n"), {
171
168
  padding: 1,
172
169
  margin: {
@@ -187,9 +184,9 @@ function showResolvedOptions(options, withSources, quiet = false) {
187
184
  function showOptionSources(withSources) {
188
185
  const table = new import_cli_table3.default({
189
186
  head: [
190
- chalk$1.bold("Option"),
191
- chalk$1.bold("Value"),
192
- chalk$1.bold("Source")
187
+ chalk.bold("Option"),
188
+ chalk.bold("Value"),
189
+ chalk.bold("Source")
193
190
  ],
194
191
  style: {
195
192
  head: [],
@@ -237,7 +234,7 @@ function showOptionSources(withSources) {
237
234
  String(withSources.preserveAssetFilenames.value),
238
235
  formatSource(withSources.preserveAssetFilenames.source)
239
236
  ]);
240
- console.log(chalk$1.dim("Option Sources:"));
237
+ console.log(chalk.dim("Option Sources:"));
241
238
  console.log(table.toString());
242
239
  console.log();
243
240
  }
@@ -246,14 +243,13 @@ function showOptionSources(withSources) {
246
243
  */
247
244
  function formatSource(source) {
248
245
  switch (source) {
249
- case "cli": return chalk$1.cyan("CLI");
250
- case "config": return chalk$1.green("Config");
251
- case "default": return chalk$1.dim("Default");
246
+ case "cli": return chalk.cyan("CLI");
247
+ case "config": return chalk.green("Config");
248
+ case "default": return chalk.dim("Default");
252
249
  default: return source;
253
250
  }
254
251
  }
255
- //#endregion
256
- //#region ../../node_modules/.pnpm/mimic-function@5.0.1/node_modules/mimic-function/index.js
252
+ // ../../node_modules/.pnpm/mimic-function@5.0.1/node_modules/mimic-function/index.js
257
253
  const copyProperty = (to, from, property, ignoreNonConfigurable) => {
258
254
  if (property === "length" || property === "prototype") return;
259
255
  if (property === "arguments" || property === "caller") return;
@@ -292,8 +288,7 @@ function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) {
292
288
  changeToString(to, from, name);
293
289
  return to;
294
290
  }
295
- //#endregion
296
- //#region ../../node_modules/.pnpm/onetime@7.0.0/node_modules/onetime/index.js
291
+ // ../../node_modules/.pnpm/onetime@7.0.0/node_modules/onetime/index.js
297
292
  const calledFunctions = /* @__PURE__ */ new WeakMap();
298
293
  const onetime = (function_, options = {}) => {
299
294
  if (typeof function_ !== "function") throw new TypeError("Expected a function");
@@ -316,16 +311,14 @@ onetime.callCount = (function_) => {
316
311
  if (!calledFunctions.has(function_)) throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
317
312
  return calledFunctions.get(function_);
318
313
  };
319
- //#endregion
320
- //#region ../../node_modules/.pnpm/restore-cursor@5.1.0/node_modules/restore-cursor/index.js
314
+ // ../../node_modules/.pnpm/restore-cursor@5.1.0/node_modules/restore-cursor/index.js
321
315
  const terminal = process$1.stderr.isTTY ? process$1.stderr : process$1.stdout.isTTY ? process$1.stdout : void 0;
322
316
  const restoreCursor = terminal ? onetime(() => {
323
317
  onExit(() => {
324
318
  terminal.write("\x1B[?25h");
325
319
  }, { alwaysLast: true });
326
320
  }) : () => {};
327
- //#endregion
328
- //#region ../../node_modules/.pnpm/cli-cursor@5.0.0/node_modules/cli-cursor/index.js
321
+ // ../../node_modules/.pnpm/cli-cursor@5.0.0/node_modules/cli-cursor/index.js
329
322
  let isHidden = false;
330
323
  const cliCursor = {};
331
324
  cliCursor.show = (writableStream = process$1.stderr) => {
@@ -344,8 +337,7 @@ cliCursor.toggle = (force, writableStream) => {
344
337
  if (isHidden) cliCursor.show(writableStream);
345
338
  else cliCursor.hide(writableStream);
346
339
  };
347
- //#endregion
348
- //#region ../../node_modules/.pnpm/cli-spinners@3.4.0/node_modules/cli-spinners/spinners.json
340
+ // ../../node_modules/.pnpm/cli-spinners@3.4.0/node_modules/cli-spinners/spinners.json
349
341
  var spinners_default = {
350
342
  dots: {
351
343
  "interval": 80,
@@ -2001,12 +1993,10 @@ var spinners_default = {
2001
1993
  ]
2002
1994
  }
2003
1995
  };
2004
- //#endregion
2005
- //#region ../../node_modules/.pnpm/cli-spinners@3.4.0/node_modules/cli-spinners/index.js
1996
+ // ../../node_modules/.pnpm/cli-spinners@3.4.0/node_modules/cli-spinners/index.js
2006
1997
  var cli_spinners_default = spinners_default;
2007
1998
  Object.keys(spinners_default);
2008
- //#endregion
2009
- //#region ../../node_modules/.pnpm/yoctocolors@2.2.0/node_modules/yoctocolors/base.js
1999
+ // ../../node_modules/.pnpm/yoctocolors@2.2.0/node_modules/yoctocolors/base.js
2010
2000
  const hasColors = tty?.WriteStream?.prototype?.hasColors?.() ?? false;
2011
2001
  const format = (open, close) => {
2012
2002
  if (!hasColors) return (input) => input;
@@ -2089,135 +2079,24 @@ format("58;5;12", 59);
2089
2079
  format("58;5;13", 59);
2090
2080
  format("58;5;14", 59);
2091
2081
  format("58;5;15", 59);
2092
- //#endregion
2093
- //#region ../../node_modules/.pnpm/is-unicode-supported@2.1.0/node_modules/is-unicode-supported/index.js
2082
+ // ../../node_modules/.pnpm/is-unicode-supported@2.1.0/node_modules/is-unicode-supported/index.js
2094
2083
  function isUnicodeSupported() {
2095
2084
  const { env } = process$1;
2096
2085
  const { TERM, TERM_PROGRAM } = env;
2097
2086
  if (process$1.platform !== "win32") return TERM !== "linux";
2098
2087
  return Boolean(env.WT_SESSION) || Boolean(env.TERMINUS_SUBLIME) || env.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
2099
2088
  }
2100
- //#endregion
2101
- //#region ../../node_modules/.pnpm/log-symbols@7.0.1/node_modules/log-symbols/symbols.js
2089
+ // ../../node_modules/.pnpm/log-symbols@7.0.1/node_modules/log-symbols/symbols.js
2102
2090
  const _isUnicodeSupported = isUnicodeSupported();
2103
2091
  const info = blue(_isUnicodeSupported ? "ℹ" : "i");
2104
2092
  const success = green(_isUnicodeSupported ? "✔" : "√");
2105
2093
  const warning = yellow(_isUnicodeSupported ? "⚠" : "‼");
2106
2094
  const error = red(_isUnicodeSupported ? "✖" : "×");
2107
- //#endregion
2108
- //#region ../../node_modules/.pnpm/string-width@8.3.0/node_modules/string-width/index.js
2109
- /**
2110
- Logic:
2111
- - Segment graphemes to match how terminals render clusters.
2112
- - Width rules:
2113
- 1. Skip non-printing clusters (Default_Ignorable, Control, pure nonspacing/enclosing Mark, lone Surrogates). Tabs are ignored by design.
2114
- 2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
2115
- 3. Minimally-qualified/unqualified emoji clusters (ZWJ sequences with 2+ Extended_Pictographic, or keycap sequences) are double-width.
2116
- 4. Hangul jamo collapse each standard modern Hangul L+V or L+V+T syllable piece to width 2.
2117
- Unmatched repeated leading/vowel/trailing jamo stay additive because that matches how the terminals we target render them.
2118
- 5. Otherwise use East Asian Width of the cluster's first visible code point, and add widths for trailing spacing marks and Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).
2119
- */
2120
- const segmenter = new Intl.Segmenter();
2121
- const visibleCharacterRegex = /[^\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Nonspacing_Mark}\p{Enclosing_Mark}\p{Surrogate}]/v;
2122
- const spacingMarkRegex = /\p{Spacing_Mark}/v;
2123
- const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
2124
- const unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
2125
- const extendedPictographicRegex = /\p{Extended_Pictographic}/gu;
2126
- function isDoubleWidthNonRgiEmojiSequence(segment) {
2127
- if (segment.length > 50) return false;
2128
- if (unqualifiedKeycapRegex.test(segment)) return true;
2129
- if (segment.includes("‍")) {
2130
- const pictographics = segment.match(extendedPictographicRegex);
2131
- return pictographics !== null && pictographics.length >= 2;
2132
- }
2133
- return false;
2134
- }
2135
- function baseVisible(segment) {
2136
- const index = segment.search(visibleCharacterRegex);
2137
- return index === -1 ? void 0 : segment.slice(index);
2138
- }
2139
- function isHangulLeadingJamo(codePoint) {
2140
- return codePoint >= 4352 && codePoint <= 4447 || codePoint >= 43360 && codePoint <= 43388;
2141
- }
2142
- function isHangulVowelJamo(codePoint) {
2143
- return codePoint >= 4448 && codePoint <= 4519 || codePoint >= 55216 && codePoint <= 55238;
2144
- }
2145
- function isHangulTrailingJamo(codePoint) {
2146
- return codePoint >= 4520 && codePoint <= 4607 || codePoint >= 55243 && codePoint <= 55291;
2147
- }
2148
- function isHangulJamo(codePoint) {
2149
- return isHangulLeadingJamo(codePoint) || isHangulVowelJamo(codePoint) || isHangulTrailingJamo(codePoint);
2150
- }
2151
- function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
2152
- const codePoints = [];
2153
- for (const character of visibleSegment) {
2154
- if (!visibleCharacterRegex.test(character)) continue;
2155
- codePoints.push(character.codePointAt(0));
2156
- }
2157
- if (codePoints.length === 0) return;
2158
- let width = 0;
2159
- for (let index = 0; index < codePoints.length; index++) {
2160
- const codePoint = codePoints[index];
2161
- if (!isHangulJamo(codePoint)) {
2162
- if (width === 0) return;
2163
- for (let remaining = index; remaining < codePoints.length; remaining++) width += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
2164
- return width;
2165
- }
2166
- if (isHangulLeadingJamo(codePoint) && isHangulVowelJamo(codePoints[index + 1])) {
2167
- width += 2;
2168
- index += isHangulTrailingJamo(codePoints[index + 2]) ? 2 : 1;
2169
- continue;
2170
- }
2171
- width += eastAsianWidth(codePoint, eastAsianWidthOptions);
2172
- }
2173
- return width;
2174
- }
2175
- function trailingWidth(visibleSegment, eastAsianWidthOptions) {
2176
- let extra = 0;
2177
- let first = true;
2178
- for (const character of visibleSegment) {
2179
- if (first) {
2180
- first = false;
2181
- continue;
2182
- }
2183
- if (spacingMarkRegex.test(character) || character >= "＀" && character <= "￯") extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
2184
- }
2185
- return extra;
2186
- }
2187
- function stringWidth(input, options = {}) {
2188
- if (typeof input !== "string" || input.length === 0) return 0;
2189
- const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options;
2190
- let string = input;
2191
- if (!countAnsiEscapeCodes && (string.includes("\x1B") || string.includes("›"))) string = stripAnsi(string);
2192
- if (string.length === 0) return 0;
2193
- if (/^[\u0020-\u007E]*$/.test(string)) return string.length;
2194
- let width = 0;
2195
- const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
2196
- for (const { segment } of segmenter.segment(string)) {
2197
- const visibleSegment = baseVisible(segment);
2198
- if (visibleSegment === void 0) continue;
2199
- if (rgiEmojiRegex.test(segment) || isDoubleWidthNonRgiEmojiSequence(segment)) {
2200
- width += 2;
2201
- continue;
2202
- }
2203
- const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
2204
- if (hangulWidth !== void 0) {
2205
- width += hangulWidth;
2206
- continue;
2207
- }
2208
- const codePoint = visibleSegment.codePointAt(0);
2209
- width += eastAsianWidth(codePoint, eastAsianWidthOptions);
2210
- width += trailingWidth(visibleSegment, eastAsianWidthOptions);
2211
- }
2212
- return width;
2213
- }
2214
- //#endregion
2215
- //#region ../../node_modules/.pnpm/is-interactive@2.0.0/node_modules/is-interactive/index.js
2095
+ // ../../node_modules/.pnpm/is-interactive@2.0.0/node_modules/is-interactive/index.js
2216
2096
  function isInteractive({ stream = process.stdout } = {}) {
2217
2097
  return Boolean(stream && stream.isTTY && process.env.TERM !== "dumb" && !("CI" in process.env));
2218
2098
  }
2219
- //#endregion
2220
- //#region ../../node_modules/.pnpm/stdin-discarder@0.3.2/node_modules/stdin-discarder/index.js
2099
+ // ../../node_modules/.pnpm/stdin-discarder@0.3.2/node_modules/stdin-discarder/index.js
2221
2100
  const ASCII_ETX_CODE = 3;
2222
2101
  var StdinDiscarder = class {
2223
2102
  #activeCount = 0;
@@ -2262,12 +2141,65 @@ var StdinDiscarder = class {
2262
2141
  };
2263
2142
  const stdinDiscarder = new StdinDiscarder();
2264
2143
  var stdin_discarder_default = Object.freeze(stdinDiscarder);
2265
- //#endregion
2266
- //#region ../../node_modules/.pnpm/ora@9.4.1/node_modules/ora/index.js
2267
- const RENDER_DEFERRAL_TIMEOUT = 200;
2144
+ // ../../node_modules/.pnpm/ora@10.0.0/node_modules/ora/index.js
2268
2145
  const SYNCHRONIZED_OUTPUT_ENABLE = "\x1B[?2026h";
2269
2146
  const SYNCHRONIZED_OUTPUT_DISABLE = "\x1B[?2026l";
2147
+ const TRUNCATION_MESSAGE = "... (content truncated to fit terminal)";
2148
+ const STYLE_RESET = "\x1B[0m";
2149
+ const TAB_STOP = 8;
2150
+ const segmenter = new Intl.Segmenter();
2151
+ const controlCharacter = /(?<control>[\t\n\r])/v;
2152
+ const printableAscii = /^[ -~]+$/v;
2153
+ const tabStopWidth = (column, columns) => {
2154
+ const nextStop = Math.floor(column / TAB_STOP) * TAB_STOP + TAB_STOP;
2155
+ return Math.max(0, Math.min(nextStop, columns - 1) - column);
2156
+ };
2157
+ const layOut = (text, columns) => {
2158
+ const rows = [];
2159
+ let cells;
2160
+ let column;
2161
+ let expandedText = "";
2162
+ const startRow = () => {
2163
+ cells = [];
2164
+ column = 0;
2165
+ rows.push(cells);
2166
+ };
2167
+ const writeGrapheme = (grapheme, width) => {
2168
+ if (width === 0) return;
2169
+ if (column + width > columns) startRow();
2170
+ cells[column++] = grapheme;
2171
+ for (let index = 1; index < width; index++) cells[column++] = "";
2172
+ };
2173
+ const writeTab = () => {
2174
+ const end = column + tabStopWidth(column, columns);
2175
+ expandedText += " ".repeat(end - column);
2176
+ for (; column < end; column++) cells[column] ??= " ";
2177
+ };
2178
+ startRow();
2179
+ for (const part of stripVTControlCharacters(text).split(controlCharacter)) {
2180
+ if (part === " ") {
2181
+ writeTab();
2182
+ continue;
2183
+ }
2184
+ expandedText += part;
2185
+ if (part === "\n") startRow();
2186
+ else if (part === "\r") column = 0;
2187
+ else if (printableAscii.test(part)) for (const character of part) writeGrapheme(character, 1);
2188
+ else for (const { segment } of segmenter.segment(part)) writeGrapheme(segment, stringWidth(segment));
2189
+ }
2190
+ return {
2191
+ rows,
2192
+ expandedText
2193
+ };
2194
+ };
2195
+ const rowCount = (text, columns) => layOut(text, columns).rows.length;
2196
+ const formatAffix = (value, separator, isPlaceBefore) => {
2197
+ const resolved = typeof value === "function" ? value() : value;
2198
+ if (typeof resolved === "string" && resolved !== "") return isPlaceBefore ? separator + resolved : resolved + separator;
2199
+ return "";
2200
+ };
2270
2201
  const activeHooksPerStream = /* @__PURE__ */ new Map();
2202
+ const originalWritesPerStream = /* @__PURE__ */ new Map();
2271
2203
  const validColors = /* @__PURE__ */ new Set([
2272
2204
  "black",
2273
2205
  "red",
@@ -2283,61 +2215,18 @@ var Ora = class {
2283
2215
  #linesToClear = 0;
2284
2216
  #frameIndex = -1;
2285
2217
  #lastFrameTime = 0;
2218
+ #renderedFrame;
2219
+ #renderedColumns;
2286
2220
  #options;
2287
2221
  #spinner;
2288
2222
  #stream;
2289
2223
  #id;
2290
- #hookedStreams = /* @__PURE__ */ new Map();
2224
+ #hookedStreams = /* @__PURE__ */ new Set();
2291
2225
  #isInternalWrite = false;
2292
2226
  #drainHandler;
2293
- #deferRenderTimer;
2227
+ #hasUnfinishedLine = false;
2294
2228
  #isDiscardingStdin = false;
2295
2229
  #color;
2296
- #internalWrite(fn) {
2297
- this.#isInternalWrite = true;
2298
- try {
2299
- return fn();
2300
- } finally {
2301
- this.#isInternalWrite = false;
2302
- }
2303
- }
2304
- #tryRender() {
2305
- if (this.isSpinning) this.render();
2306
- }
2307
- #stringifyChunk(chunk, encoding) {
2308
- if (chunk === void 0 || chunk === null) return "";
2309
- if (typeof chunk === "string") return chunk;
2310
- if (Buffer.isBuffer(chunk) || ArrayBuffer.isView(chunk)) {
2311
- const normalizedEncoding = typeof encoding === "string" && encoding && encoding !== "buffer" ? encoding : "utf8";
2312
- return Buffer.from(chunk).toString(normalizedEncoding);
2313
- }
2314
- return String(chunk);
2315
- }
2316
- #chunkTerminatesLine(chunkString) {
2317
- if (!chunkString) return false;
2318
- const lastCharacter = chunkString.at(-1);
2319
- return lastCharacter === "\n" || lastCharacter === "\r";
2320
- }
2321
- #scheduleRenderDeferral() {
2322
- if (this.#deferRenderTimer) return;
2323
- this.#deferRenderTimer = setTimeout(() => {
2324
- this.#deferRenderTimer = void 0;
2325
- if (this.isSpinning) this.#tryRender();
2326
- }, RENDER_DEFERRAL_TIMEOUT);
2327
- if (typeof this.#deferRenderTimer?.unref === "function") this.#deferRenderTimer.unref();
2328
- }
2329
- #clearRenderDeferral() {
2330
- if (this.#deferRenderTimer) {
2331
- clearTimeout(this.#deferRenderTimer);
2332
- this.#deferRenderTimer = void 0;
2333
- }
2334
- }
2335
- #buildOutputLine(symbol, text, prefixText, suffixText) {
2336
- const fullPrefixText = this.#getFullPrefixText(prefixText, " ");
2337
- const fullText = typeof text === "string" ? (symbol ? " " : "") + text : "";
2338
- const fullSuffixText = this.#getFullSuffixText(suffixText, " ");
2339
- return fullPrefixText + symbol + fullText + fullSuffixText;
2340
- }
2341
2230
  constructor(options) {
2342
2231
  if (typeof options === "string") options = { text: options };
2343
2232
  this.#options = {
@@ -2348,10 +2237,10 @@ var Ora = class {
2348
2237
  ...options
2349
2238
  };
2350
2239
  this.color = this.#options.color;
2351
- this.#stream = this.#options.stream;
2240
+ this.#stream = this.#options.stream ?? process$1.stderr;
2352
2241
  if (typeof this.#options.isEnabled !== "boolean") this.#options.isEnabled = isInteractive({ stream: this.#stream });
2353
2242
  if (typeof this.#options.isSilent !== "boolean") this.#options.isSilent = false;
2354
- if (this.#options.interval !== void 0 && !(Number.isInteger(this.#options.interval) && this.#options.interval > 0)) throw new Error("The `interval` option must be a positive integer");
2243
+ if (this.#options.interval !== void 0 && !(Number.isSafeInteger(this.#options.interval) && this.#options.interval > 0)) throw new Error("The `interval` option must be a positive integer");
2355
2244
  const userInterval = this.#options.interval;
2356
2245
  this.spinner = this.#options.spinner;
2357
2246
  this.#options.interval = userInterval;
@@ -2359,36 +2248,170 @@ var Ora = class {
2359
2248
  this.prefixText = this.#options.prefixText;
2360
2249
  this.suffixText = this.#options.suffixText;
2361
2250
  this.indent = this.#options.indent;
2362
- if (process$1.env.NODE_ENV === "test") {
2363
- this._stream = this.#stream;
2364
- this._isEnabled = this.#options.isEnabled;
2365
- Object.defineProperty(this, "_linesToClear", {
2251
+ if (process$1.env.NODE_ENV !== "test") return;
2252
+ this._stream = this.#stream;
2253
+ this._isEnabled = this.#options.isEnabled;
2254
+ Object.defineProperties(this, {
2255
+ _linesToClear: {
2366
2256
  get() {
2367
2257
  return this.#linesToClear;
2368
2258
  },
2369
2259
  set(newValue) {
2370
2260
  this.#linesToClear = newValue;
2371
2261
  }
2372
- });
2373
- Object.defineProperty(this, "_frameIndex", { get() {
2262
+ },
2263
+ _frameIndex: { get() {
2374
2264
  return this.#frameIndex;
2375
- } });
2376
- Object.defineProperty(this, "_lineCount", { get() {
2377
- const columns = this.#stream.columns ?? 80;
2378
- const prefixText = typeof this.#options.prefixText === "function" ? "" : this.#options.prefixText;
2379
- const suffixText = typeof this.#options.suffixText === "function" ? "" : this.#options.suffixText;
2380
- const fullPrefixText = typeof prefixText === "string" && prefixText !== "" ? prefixText + " " : "";
2381
- const fullSuffixText = typeof suffixText === "string" && suffixText !== "" ? " " + suffixText : "";
2382
- const fullText = " ".repeat(this.#options.indent) + fullPrefixText + "-" + (typeof this.#options.text === "string" ? " " + this.#options.text : "") + fullSuffixText;
2383
- return this.#computeLineCountFrom(fullText, columns);
2384
- } });
2265
+ } },
2266
+ _renderedFrame: { get() {
2267
+ return this.#renderedFrame;
2268
+ } },
2269
+ _renderedColumns: { get() {
2270
+ return this.#renderedColumns;
2271
+ } },
2272
+ _lineCount: { get() {
2273
+ const { prefixText, suffixText } = this.#options;
2274
+ const line = this.#buildOutputLine("-", this.#options.text, typeof prefixText === "function" ? "" : prefixText, typeof suffixText === "function" ? "" : suffixText);
2275
+ const fullText = " ".repeat(this.#options.indent) + line;
2276
+ return rowCount(fullText, this.#columns);
2277
+ } }
2278
+ });
2279
+ }
2280
+ #internalWrite(fn) {
2281
+ this.#isInternalWrite = true;
2282
+ try {
2283
+ return fn();
2284
+ } finally {
2285
+ this.#isInternalWrite = false;
2286
+ }
2287
+ }
2288
+ #tryRender() {
2289
+ if (!this.isSpinning) return;
2290
+ try {
2291
+ this.render();
2292
+ } catch {
2293
+ this.#release();
2294
+ this.#showCursor();
2295
+ }
2296
+ }
2297
+ #showCursor() {
2298
+ if (!this.#options.hideCursor) return;
2299
+ try {
2300
+ cliCursor.show(this.#stream);
2301
+ } catch {}
2302
+ }
2303
+ #stringifyChunk(chunk, encoding) {
2304
+ if (chunk === void 0 || chunk === null) return "";
2305
+ if (typeof chunk === "string") return chunk;
2306
+ if (Buffer.isBuffer(chunk) || ArrayBuffer.isView(chunk)) {
2307
+ const normalizedEncoding = typeof encoding === "string" && encoding && encoding !== "buffer" ? encoding : "utf8";
2308
+ return Buffer.from(chunk).toString(normalizedEncoding);
2309
+ }
2310
+ return String(chunk);
2311
+ }
2312
+ #release() {
2313
+ clearInterval(this.#id);
2314
+ this.#id = void 0;
2315
+ this.#frameIndex = -1;
2316
+ this.#lastFrameTime = 0;
2317
+ this.#uninstallHook();
2318
+ if (this.#drainHandler) {
2319
+ this.#stream.removeListener("drain", this.#drainHandler);
2320
+ this.#drainHandler = void 0;
2385
2321
  }
2322
+ this.#hasUnfinishedLine = false;
2323
+ if (!this.#isDiscardingStdin) return;
2324
+ this.#isDiscardingStdin = false;
2325
+ stdin_discarder_default.stop();
2326
+ }
2327
+ #buildOutputLine(symbol, text, prefixText, suffixText) {
2328
+ const hasSymbol = symbol !== "";
2329
+ const fullPrefixText = formatAffix(prefixText, hasSymbol || typeof text === "string" && text !== "" ? " " : "", false);
2330
+ const fullText = typeof text === "string" ? (hasSymbol ? " " : "") + text : "";
2331
+ const fullSuffixText = formatAffix(suffixText, hasSymbol && text === "" ? "" : " ", true);
2332
+ return fullPrefixText + symbol + fullText + fullSuffixText;
2333
+ }
2334
+ #startRenderTimer() {
2335
+ clearInterval(this.#id);
2336
+ this.#id = setInterval(this.#tryRender.bind(this), this.interval);
2337
+ }
2338
+ get #columns() {
2339
+ return this.#stream.columns || 80;
2340
+ }
2341
+ get #canMoveCursor() {
2342
+ return Boolean(this.#stream.isTTY) && typeof this.#stream.cursorTo === "function" && typeof this.#stream.moveCursor === "function" && typeof this.#stream.clearLine === "function";
2343
+ }
2344
+ #clearDisplay() {
2345
+ if (!this.#canMoveCursor || this.#linesToClear === 0) return;
2346
+ const columns = this.#columns;
2347
+ if (this.#renderedFrame !== void 0 && this.#renderedColumns !== columns) this.#linesToClear = Math.min(this.#linesToClear, rowCount(this.#renderedFrame, columns));
2348
+ try {
2349
+ this.#eraseRows(this.#linesToClear);
2350
+ } finally {
2351
+ this.#linesToClear = 0;
2352
+ this.#renderedFrame = void 0;
2353
+ }
2354
+ }
2355
+ #eraseRows(count) {
2356
+ this.#internalWrite(() => {
2357
+ this.#stream.cursorTo(0);
2358
+ for (let index = 0; index < count; index++) {
2359
+ if (index > 0) this.#stream.moveCursor(0, -1);
2360
+ this.#stream.clearLine(1);
2361
+ }
2362
+ });
2363
+ }
2364
+ #hookStream(stream) {
2365
+ if (!stream || this.#hookedStreams.has(stream) || !stream.isTTY || typeof stream.write !== "function") return;
2366
+ if (activeHooksPerStream.has(stream)) console.warn("[ora] Multiple concurrent spinners detected. This may cause visual corruption. Use one spinner at a time.");
2367
+ if (!originalWritesPerStream.has(stream)) originalWritesPerStream.set(stream, stream.write);
2368
+ const originalWrite = stream.write;
2369
+ this.#hookedStreams.add(stream);
2370
+ activeHooksPerStream.set(stream, this);
2371
+ stream.write = (chunk, encoding, callback) => this.#hookedWrite(stream, originalWrite, chunk, encoding, callback);
2372
+ }
2373
+ /**
2374
+ Intercept stream writes while spinner is active to handle external writes cleanly without visual corruption.
2375
+ Hooks process stdio streams and the active spinner stream so console.log(), console.error(), and direct writes stay tidy.
2376
+ */
2377
+ #installHook() {
2378
+ if (!this.isEnabled || this.#hookedStreams.size > 0) return;
2379
+ const streamsToHook = /* @__PURE__ */ new Set([
2380
+ this.#stream,
2381
+ process$1.stdout,
2382
+ process$1.stderr
2383
+ ]);
2384
+ for (const stream of streamsToHook) this.#hookStream(stream);
2385
+ }
2386
+ #uninstallHook() {
2387
+ for (const stream of this.#hookedStreams) {
2388
+ if (activeHooksPerStream.get(stream) === this) activeHooksPerStream.delete(stream);
2389
+ if (activeHooksPerStream.has(stream)) continue;
2390
+ const originalWrite = originalWritesPerStream.get(stream);
2391
+ if (originalWrite === void 0) continue;
2392
+ stream.write = originalWrite;
2393
+ originalWritesPerStream.delete(stream);
2394
+ }
2395
+ this.#hookedStreams.clear();
2396
+ }
2397
+ #hookedWrite(stream, originalWrite, chunk, encoding, callback) {
2398
+ if (typeof encoding === "function") {
2399
+ callback = encoding;
2400
+ encoding = void 0;
2401
+ }
2402
+ if (this.#isInternalWrite) return originalWrite.call(stream, chunk, encoding, callback);
2403
+ this.#clearDisplay();
2404
+ const chunkString = stripVTControlCharacters(this.#stringifyChunk(chunk, encoding));
2405
+ if (chunkString !== "") this.#hasUnfinishedLine = !chunkString.endsWith("\n");
2406
+ const writeResult = originalWrite.call(stream, chunk, encoding, callback);
2407
+ this.#tryRender();
2408
+ return writeResult;
2386
2409
  }
2387
2410
  get indent() {
2388
2411
  return this.#options.indent;
2389
2412
  }
2390
2413
  set indent(indent = 0) {
2391
- if (!(indent >= 0 && Number.isInteger(indent))) throw new Error("The `indent` option must be an integer from 0 and up");
2414
+ if (!(indent >= 0 && Number.isSafeInteger(indent))) throw new Error("The `indent` option must be an integer from 0 and up");
2392
2415
  this.#options.indent = indent;
2393
2416
  }
2394
2417
  get interval() {
@@ -2398,16 +2421,18 @@ var Ora = class {
2398
2421
  return this.#spinner;
2399
2422
  }
2400
2423
  set spinner(spinner) {
2401
- this.#frameIndex = -1;
2402
- this.#options.interval = void 0;
2403
- if (typeof spinner === "object") {
2424
+ if (typeof spinner === "object" && spinner !== null) {
2404
2425
  if (!Array.isArray(spinner.frames) || spinner.frames.length === 0 || spinner.frames.some((frame) => typeof frame !== "string")) throw new Error("The given spinner must have a non-empty `frames` array of strings");
2405
- if (spinner.interval !== void 0 && !(Number.isInteger(spinner.interval) && spinner.interval > 0)) throw new Error("`spinner.interval` must be a positive integer if provided");
2426
+ if (spinner.interval !== void 0 && !(Number.isSafeInteger(spinner.interval) && spinner.interval > 0)) throw new Error("`spinner.interval` must be a positive integer if provided");
2406
2427
  this.#spinner = spinner;
2407
- } else if (!isUnicodeSupported()) this.#spinner = cli_spinners_default.line;
2408
- else if (spinner === void 0) this.#spinner = cli_spinners_default.dots;
2409
- else if (spinner !== "default" && cli_spinners_default[spinner]) this.#spinner = cli_spinners_default[spinner];
2410
- else throw new Error(`There is no built-in spinner named '${spinner}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`);
2428
+ } else if (spinner !== void 0 && (spinner === "default" || !Object.hasOwn(cli_spinners_default, spinner))) throw new Error(`There is no built-in spinner named '${spinner}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`);
2429
+ else if (isUnicodeSupported()) this.#spinner = cli_spinners_default[spinner ?? "dots"];
2430
+ else this.#spinner = cli_spinners_default.line;
2431
+ this.#frameIndex = -1;
2432
+ this.#options.interval = void 0;
2433
+ if (!this.isSpinning) return;
2434
+ this.#startRenderTimer();
2435
+ this.render();
2411
2436
  }
2412
2437
  get text() {
2413
2438
  return this.#options.text;
@@ -2430,22 +2455,6 @@ var Ora = class {
2430
2455
  get isSpinning() {
2431
2456
  return this.#id !== void 0;
2432
2457
  }
2433
- #formatAffix(value, separator, placeBefore = false) {
2434
- const resolved = typeof value === "function" ? value() : value;
2435
- if (typeof resolved === "string" && resolved !== "") return placeBefore ? separator + resolved : resolved + separator;
2436
- return "";
2437
- }
2438
- #getFullPrefixText(prefixText = this.#options.prefixText, postfix = " ") {
2439
- return this.#formatAffix(prefixText, postfix, false);
2440
- }
2441
- #getFullSuffixText(suffixText = this.#options.suffixText, prefix = " ") {
2442
- return this.#formatAffix(suffixText, prefix, true);
2443
- }
2444
- #computeLineCountFrom(text, columns) {
2445
- let count = 0;
2446
- for (const line of stripVTControlCharacters(text).split("\n")) count += Math.max(1, Math.ceil(stringWidth(line) / columns));
2447
- return count;
2448
- }
2449
2458
  get color() {
2450
2459
  return this.#color;
2451
2460
  }
@@ -2476,69 +2485,17 @@ var Ora = class {
2476
2485
  const { frames } = this.#spinner;
2477
2486
  let frame = frames[this.#frameIndex];
2478
2487
  if (this.#color) frame = chalk[this.#color](frame);
2479
- const fullPrefixText = this.#getFullPrefixText(this.#options.prefixText, " ");
2480
- const fullText = typeof this.text === "string" ? " " + this.text : "";
2481
- const fullSuffixText = this.#getFullSuffixText(this.#options.suffixText, " ");
2482
- return fullPrefixText + frame + fullText + fullSuffixText;
2488
+ const line = this.#buildOutputLine(frame, this.text, this.#options.prefixText, this.#options.suffixText);
2489
+ return " ".repeat(this.#options.indent) + line;
2483
2490
  }
2484
2491
  clear() {
2485
- if (!this.isEnabled || !this.#stream.isTTY) return this;
2486
- this.#internalWrite(() => {
2487
- this.#stream.cursorTo(0);
2488
- for (let index = 0; index < this.#linesToClear; index++) {
2489
- if (index > 0) this.#stream.moveCursor(0, -1);
2490
- this.#stream.clearLine(1);
2491
- }
2492
- if (this.#options.indent) this.#stream.cursorTo(this.#options.indent);
2493
- });
2494
- this.#linesToClear = 0;
2492
+ if (!this.isEnabled) return this;
2493
+ this.#clearDisplay();
2495
2494
  return this;
2496
2495
  }
2497
- #hookStream(stream) {
2498
- if (!stream || this.#hookedStreams.has(stream) || !stream.isTTY || typeof stream.write !== "function") return;
2499
- if (activeHooksPerStream.has(stream)) console.warn("[ora] Multiple concurrent spinners detected. This may cause visual corruption. Use one spinner at a time.");
2500
- const originalWrite = stream.write;
2501
- this.#hookedStreams.set(stream, originalWrite);
2502
- activeHooksPerStream.set(stream, this);
2503
- stream.write = (chunk, encoding, callback) => this.#hookedWrite(stream, originalWrite, chunk, encoding, callback);
2504
- }
2505
- /**
2506
- Intercept stream writes while spinner is active to handle external writes cleanly without visual corruption.
2507
- Hooks process stdio streams and the active spinner stream so console.log(), console.error(), and direct writes stay tidy.
2508
- */
2509
- #installHook() {
2510
- if (!this.isEnabled || this.#hookedStreams.size > 0) return;
2511
- const streamsToHook = /* @__PURE__ */ new Set([
2512
- this.#stream,
2513
- process$1.stdout,
2514
- process$1.stderr
2515
- ]);
2516
- for (const stream of streamsToHook) this.#hookStream(stream);
2517
- }
2518
- #uninstallHook() {
2519
- for (const [stream, originalWrite] of this.#hookedStreams) {
2520
- stream.write = originalWrite;
2521
- if (activeHooksPerStream.get(stream) === this) activeHooksPerStream.delete(stream);
2522
- }
2523
- this.#hookedStreams.clear();
2524
- }
2525
- #hookedWrite(stream, originalWrite, chunk, encoding, callback) {
2526
- if (typeof encoding === "function") {
2527
- callback = encoding;
2528
- encoding = void 0;
2529
- }
2530
- if (this.#isInternalWrite) return originalWrite.call(stream, chunk, encoding, callback);
2531
- this.clear();
2532
- const chunkString = this.#stringifyChunk(chunk, encoding);
2533
- const chunkTerminatesLine = this.#chunkTerminatesLine(chunkString);
2534
- const writeResult = originalWrite.call(stream, chunk, encoding, callback);
2535
- if (chunkTerminatesLine) this.#clearRenderDeferral();
2536
- else if (chunkString.length > 0) this.#scheduleRenderDeferral();
2537
- if (this.isSpinning && !this.#deferRenderTimer) this.render();
2538
- return writeResult;
2539
- }
2540
2496
  render() {
2541
- if (!this.isEnabled || this.#drainHandler || this.#deferRenderTimer) return this;
2497
+ if (!this.isEnabled || this.#drainHandler || this.#hasUnfinishedLine) return this;
2498
+ let frameContent = this.frame();
2542
2499
  const useSynchronizedOutput = this.#stream.isTTY;
2543
2500
  let shouldDisableSynchronizedOutput = false;
2544
2501
  try {
@@ -2546,15 +2503,27 @@ var Ora = class {
2546
2503
  this.#internalWrite(() => this.#stream.write(SYNCHRONIZED_OUTPUT_ENABLE));
2547
2504
  shouldDisableSynchronizedOutput = true;
2548
2505
  }
2549
- this.clear();
2550
- let frameContent = this.frame();
2551
- const columns = this.#stream.columns ?? 80;
2552
- const actualLineCount = this.#computeLineCountFrom(frameContent, columns);
2553
- const consoleHeight = this.#stream.rows;
2554
- if (consoleHeight && consoleHeight > 1 && actualLineCount > consoleHeight) {
2555
- const lines = frameContent.split("\n");
2556
- const maxLines = consoleHeight - 1;
2557
- frameContent = [...lines.slice(0, maxLines), "... (content truncated to fit terminal)"].join("\n");
2506
+ if (this.#linesToClear > 0) this.#clearDisplay();
2507
+ else if (this.#canMoveCursor) this.#internalWrite(() => this.#stream.cursorTo(0));
2508
+ const columns = this.#columns;
2509
+ let layout = layOut(frameContent, columns);
2510
+ const maxRows = this.#stream.rows > 1 ? this.#stream.rows - 1 : void 0;
2511
+ if (layout.rows.length > maxRows) {
2512
+ let message = TRUNCATION_MESSAGE;
2513
+ while (message.length > 1 && rowCount(message, columns) > maxRows) message = message.slice(0, -1);
2514
+ let rowBudget = maxRows - rowCount(message, columns);
2515
+ const keptLines = [];
2516
+ for (const line of frameContent.split("\n")) {
2517
+ const lineRows = layOut(line, columns).rows;
2518
+ if (lineRows.length > rowBudget) {
2519
+ keptLines.push(...lineRows.slice(0, rowBudget).map((cells) => cells.join("")));
2520
+ break;
2521
+ }
2522
+ keptLines.push(line);
2523
+ rowBudget -= lineRows.length;
2524
+ }
2525
+ frameContent = [...keptLines, STYLE_RESET + message].join("\n");
2526
+ layout = layOut(frameContent, columns);
2558
2527
  }
2559
2528
  if (this.#internalWrite(() => this.#stream.write(frameContent)) === false && this.#stream.isTTY) {
2560
2529
  this.#drainHandler = () => {
@@ -2563,7 +2532,9 @@ var Ora = class {
2563
2532
  };
2564
2533
  this.#stream.once("drain", this.#drainHandler);
2565
2534
  }
2566
- this.#linesToClear = this.#computeLineCountFrom(frameContent, columns);
2535
+ this.#linesToClear = layout.rows.length;
2536
+ this.#renderedFrame = layout.expandedText;
2537
+ this.#renderedColumns = columns;
2567
2538
  } finally {
2568
2539
  if (shouldDisableSynchronizedOutput) this.#internalWrite(() => this.#stream.write(SYNCHRONIZED_OUTPUT_DISABLE));
2569
2540
  }
@@ -2571,43 +2542,36 @@ var Ora = class {
2571
2542
  }
2572
2543
  start(text) {
2573
2544
  if (text !== void 0) this.text = text;
2574
- if (this.isSilent) return this;
2545
+ if (this.isSpinning || this.isSilent) return this;
2575
2546
  if (!this.isEnabled) {
2576
2547
  const symbol = this.text ? "-" : "";
2577
2548
  const line = " ".repeat(this.#options.indent) + this.#buildOutputLine(symbol, this.text, this.#options.prefixText, this.#options.suffixText);
2578
2549
  if (line.trim() !== "") this.#internalWrite(() => this.#stream.write(line + "\n"));
2579
2550
  return this;
2580
2551
  }
2581
- if (this.isSpinning) return this;
2582
2552
  if (this.#options.hideCursor) cliCursor.hide(this.#stream);
2583
2553
  if (this.#options.discardStdin && process$1.stdin.isTTY) {
2584
2554
  stdin_discarder_default.start();
2585
2555
  this.#isDiscardingStdin = true;
2586
2556
  }
2587
2557
  this.#installHook();
2588
- this.render();
2589
- this.#id = setInterval(this.render.bind(this), this.interval);
2558
+ try {
2559
+ this.render();
2560
+ } catch (error) {
2561
+ this.#release();
2562
+ this.#showCursor();
2563
+ throw error;
2564
+ }
2565
+ this.#startRenderTimer();
2590
2566
  return this;
2591
2567
  }
2592
2568
  stop() {
2593
- clearInterval(this.#id);
2594
- this.#id = void 0;
2595
- this.#frameIndex = -1;
2596
- this.#lastFrameTime = 0;
2597
- this.#clearRenderDeferral();
2598
- this.#uninstallHook();
2599
- if (this.#drainHandler) {
2600
- this.#stream.removeListener("drain", this.#drainHandler);
2601
- this.#drainHandler = void 0;
2602
- }
2603
- if (this.isEnabled) {
2604
- this.clear();
2605
- if (this.#options.hideCursor) cliCursor.show(this.#stream);
2606
- }
2607
- if (this.#isDiscardingStdin) {
2608
- this.#isDiscardingStdin = false;
2609
- stdin_discarder_default.stop();
2610
- }
2569
+ const wasSpinning = this.isSpinning;
2570
+ this.#release();
2571
+ try {
2572
+ this.#clearDisplay();
2573
+ } catch {}
2574
+ if (wasSpinning) this.#showCursor();
2611
2575
  return this;
2612
2576
  }
2613
2577
  succeed(text) {
@@ -2634,14 +2598,16 @@ var Ora = class {
2634
2598
  text
2635
2599
  });
2636
2600
  }
2637
- stopAndPersist(options = {}) {
2638
- if (this.isSilent) return this;
2639
- const symbol = options.symbol ?? " ";
2640
- const text = options.text ?? this.text;
2641
- const prefixText = options.prefixText ?? this.#options.prefixText;
2642
- const suffixText = options.suffixText ?? this.#options.suffixText;
2643
- const textToWrite = this.#buildOutputLine(symbol, text, prefixText, suffixText) + "\n";
2601
+ stopAndPersist(options) {
2602
+ const hasUnfinishedLine = this.#hasUnfinishedLine;
2644
2603
  this.stop();
2604
+ if (this.isSilent) return this;
2605
+ const symbolText = String(options?.symbol ?? " ");
2606
+ const renderedSymbol = this.isEnabled && this.#stream.isTTY ? symbolText : stripVTControlCharacters(symbolText);
2607
+ const text = options?.text ?? this.text;
2608
+ const prefixText = options?.prefixText ?? this.#options.prefixText;
2609
+ const suffixText = options?.suffixText ?? this.#options.suffixText;
2610
+ const textToWrite = (hasUnfinishedLine ? "\n" : "") + " ".repeat(this.#options.indent) + this.#buildOutputLine(renderedSymbol, text, prefixText, suffixText) + "\n";
2645
2611
  this.#internalWrite(() => this.#stream.write(textToWrite));
2646
2612
  return this;
2647
2613
  }
@@ -2649,8 +2615,7 @@ var Ora = class {
2649
2615
  function ora(options) {
2650
2616
  return new Ora(options);
2651
2617
  }
2652
- //#endregion
2653
- //#region src/ux/progress.ts
2618
+ // src/ux/progress.ts
2654
2619
  /**
2655
2620
  * Progress tracker for conversion stages
2656
2621
  */
@@ -2680,7 +2645,7 @@ var ProgressTracker = class {
2680
2645
  succeedStage(message) {
2681
2646
  if (this.spinner) {
2682
2647
  const elapsed = this.getElapsed();
2683
- const suffix = this.verbose ? chalk$1.dim(` (${elapsed})`) : "";
2648
+ const suffix = this.verbose ? chalk.dim(` (${elapsed})`) : "";
2684
2649
  this.spinner.succeed((message ?? this.spinner.text) + suffix);
2685
2650
  this.spinner = null;
2686
2651
  }
@@ -2712,8 +2677,7 @@ var ProgressTracker = class {
2712
2677
  }
2713
2678
  }
2714
2679
  };
2715
- //#endregion
2716
- //#region src/options/resolveOptions.ts
2680
+ // src/options/resolveOptions.ts
2717
2681
  /**
2718
2682
  * Resolve a single option with precedence and source tracking
2719
2683
  */
@@ -2894,7 +2858,6 @@ async function resolveOptions(cliOpts, config, isPackageCommand, configPath) {
2894
2858
  withSources
2895
2859
  };
2896
2860
  }
2897
- //#endregion
2898
2861
  export { parseJsonInput as a, convertQtiToLearnosity as c, writeOutput as i, ProgressTracker as n, readInput as o, showResolvedOptions as r, convertLearnosityToQti as s, resolveOptions as t };
2899
2862
 
2900
- //# sourceMappingURL=resolveOptions-BuNN2KMA.js.map
2863
+ //# sourceMappingURL=resolveOptions-ikupjaRQ.js.map