@mariozechner/pi-tui 0.7.17 → 0.7.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAU;IACjD,8CAA8C;IAC9C,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC7C,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC;AAAA,CAC/B","sourcesContent":["import stringWidth from \"string-width\";\n\n/**\n * Calculate the visible width of a string in terminal columns.\n * This correctly handles:\n * - ANSI escape codes (ignored)\n * - Emojis and wide characters (counted as 2 columns)\n * - Combining characters (counted correctly)\n * - Tabs (replaced with 3 spaces for consistent width)\n */\nexport function visibleWidth(str: string): number {\n\t// Replace tabs with 3 spaces before measuring\n\tconst normalized = str.replace(/\\t/g, \" \");\n\treturn stringWidth(normalized);\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAU;IACjD,8CAA8C;IAC9C,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC7C,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC;AAAA,CAC/B;AAED;;;GAGG;AACH,SAAS,eAAe,CAAC,GAAW,EAAE,GAAW,EAA2C;IAC3F,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,MAAM,IAAI,GAAG,CAAC,GAAG,GAAG,C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AAI,cAAc,CAAC;IACrB,CAAC;IAED,8DAA8D;IAC9D,IAAI,WAAW,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,KAAK,CAAC;AAAA,CACb","sourcesContent":["import stringWidth from \"string-width\";\n\n/**\n * Calculate the visible width of a string in terminal columns.\n * This correctly handles:\n * - ANSI escape codes (ignored)\n * - Emojis and wide characters (counted as 2 columns)\n * - Combining characters (counted correctly)\n * - Tabs (replaced with 3 spaces for consistent width)\n */\nexport function visibleWidth(str: string): number {\n\t// Replace tabs with 3 spaces before measuring\n\tconst normalized = str.replace(/\\t/g, \" \");\n\treturn stringWidth(normalized);\n}\n\n/**\n * Extract ANSI escape sequences from a string at the given position.\n * Returns the ANSI code and the length consumed, or null if no ANSI code found.\n */\nfunction extractAnsiCode(str: string, pos: number): { code: string; length: number } | null {\n\tif (pos >= str.length || str[pos] !== \"\\x1b\" || str[pos + 1] !== \"[\") {\n\t\treturn null;\n\t}\n\n\tlet j = pos + 2;\n\twhile (j < str.length && str[j] && !/[mGKHJ]/.test(str[j]!)) {\n\t\tj++;\n\t}\n\n\tif (j < str.length) {\n\t\treturn {\n\t\t\tcode: str.substring(pos, j + 1),\n\t\t\tlength: j + 1 - pos,\n\t\t};\n\t}\n\n\treturn null;\n}\n\n/**\n * Track and manage active ANSI codes for preserving styling across wrapped lines.\n */\nclass AnsiCodeTracker {\n\tprivate activeAnsiCodes: string[] = [];\n\n\t/**\n\t * Process an ANSI code and update the active codes.\n\t */\n\tprocess(ansiCode: string): void {\n\t\t// Check if it's a styling code (ends with 'm')\n\t\tif (!ansiCode.endsWith(\"m\")) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Reset code clears all active codes\n\t\tif (ansiCode === \"\\x1b[0m\" || ansiCode === \"\\x1b[m\") {\n\t\t\tthis.activeAnsiCodes.length = 0;\n\t\t} else {\n\t\t\t// Add to active codes\n\t\t\tthis.activeAnsiCodes.push(ansiCode);\n\t\t}\n\t}\n\n\t/**\n\t * Get all active ANSI codes as a single string.\n\t */\n\tgetActiveCodes(): string {\n\t\treturn this.activeAnsiCodes.join(\"\");\n\t}\n\n\t/**\n\t * Check if there are any active codes.\n\t */\n\thasActiveCodes(): boolean {\n\t\treturn this.activeAnsiCodes.length > 0;\n\t}\n\n\t/**\n\t * Get the reset code.\n\t */\n\tgetResetCode(): string {\n\t\treturn \"\\x1b[0m\";\n\t}\n}\n\n/**\n * Wrap text lines with word-based wrapping while preserving ANSI escape codes.\n * This function properly handles:\n * - ANSI escape codes (preserved and tracked across lines)\n * - Word-based wrapping (breaks at spaces when possible)\n * - Multi-byte characters (emoji, surrogate pairs)\n * - Newlines within text\n *\n * @param text - The text to wrap (can contain ANSI codes and newlines)\n * @param width - The maximum width in terminal columns\n * @returns Array of wrapped lines with ANSI codes preserved\n */\nexport function wrapTextWithAnsi(text: string, width: number): string[] {\n\tif (!text) {\n\t\treturn [\"\"];\n\t}\n\n\t// Handle newlines by processing each line separately\n\tconst inputLines = text.split(\"\\n\");\n\tconst result: string[] = [];\n\n\tfor (const inputLine of inputLines) {\n\t\tresult.push(...wrapSingleLineWithAnsi(inputLine, width));\n\t}\n\n\treturn result.length > 0 ? result : [\"\"];\n}\n\n/**\n * Wrap a single line (no newlines) with word-based wrapping while preserving ANSI codes.\n */\nfunction wrapSingleLineWithAnsi(line: string, width: number): string[] {\n\tif (!line) {\n\t\treturn [\"\"];\n\t}\n\n\tconst visibleLength = visibleWidth(line);\n\tif (visibleLength <= width) {\n\t\treturn [line];\n\t}\n\n\tconst wrapped: string[] = [];\n\tconst tracker = new AnsiCodeTracker();\n\n\t// First, split the line into words while preserving ANSI codes with their words\n\tconst words = splitIntoWordsWithAnsi(line);\n\n\tlet currentLine = \"\";\n\tlet currentVisibleLength = 0;\n\n\tfor (const word of words) {\n\t\tconst wordVisibleLength = visibleWidth(word);\n\n\t\t// If the word itself is longer than the width, we need to break it character by character\n\t\tif (wordVisibleLength > width) {\n\t\t\t// Flush current line if any\n\t\t\tif (currentLine) {\n\t\t\t\twrapped.push(closeLineAndPrepareNext(currentLine, tracker));\n\t\t\t\tcurrentLine = tracker.getActiveCodes();\n\t\t\t\tcurrentVisibleLength = 0;\n\t\t\t}\n\n\t\t\t// Break the long word\n\t\t\tconst brokenLines = breakLongWordWithAnsi(word, width, tracker);\n\t\t\twrapped.push(...brokenLines.slice(0, -1));\n\t\t\tcurrentLine = brokenLines[brokenLines.length - 1];\n\t\t\tcurrentVisibleLength = visibleWidth(currentLine);\n\t\t} else {\n\t\t\t// Check if adding this word would exceed the width\n\t\t\tconst spaceNeeded = currentVisibleLength > 0 ? 1 : 0; // Space before word if not at line start\n\t\t\tconst totalNeeded = currentVisibleLength + spaceNeeded + wordVisibleLength;\n\n\t\t\tif (totalNeeded > width) {\n\t\t\t\t// Word doesn't fit, wrap to next line\n\t\t\t\tif (currentLine) {\n\t\t\t\t\twrapped.push(closeLineAndPrepareNext(currentLine, tracker));\n\t\t\t\t}\n\t\t\t\tcurrentLine = tracker.getActiveCodes() + word;\n\t\t\t\tcurrentVisibleLength = wordVisibleLength;\n\t\t\t} else {\n\t\t\t\t// Word fits, add it\n\t\t\t\tif (currentVisibleLength > 0) {\n\t\t\t\t\tcurrentLine += \" \" + word;\n\t\t\t\t\tcurrentVisibleLength += 1 + wordVisibleLength;\n\t\t\t\t} else {\n\t\t\t\t\tcurrentLine += word;\n\t\t\t\t\tcurrentVisibleLength = wordVisibleLength;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Update tracker with ANSI codes from this word\n\t\t\tupdateTrackerFromText(word, tracker);\n\t\t}\n\t}\n\n\t// Add final line\n\tif (currentLine) {\n\t\twrapped.push(currentLine);\n\t}\n\n\treturn wrapped.length > 0 ? wrapped : [\"\"];\n}\n\n/**\n * Close current line with reset code if needed, and prepare the next line with active codes.\n */\nfunction closeLineAndPrepareNext(line: string, tracker: AnsiCodeTracker): string {\n\tif (tracker.hasActiveCodes()) {\n\t\treturn line + tracker.getResetCode();\n\t}\n\treturn line;\n}\n\n/**\n * Update the ANSI code tracker by scanning through text.\n */\nfunction updateTrackerFromText(text: string, tracker: AnsiCodeTracker): void {\n\tlet i = 0;\n\twhile (i < text.length) {\n\t\tconst ansiResult = extractAnsiCode(text, i);\n\t\tif (ansiResult) {\n\t\t\ttracker.process(ansiResult.code);\n\t\t\ti += ansiResult.length;\n\t\t} else {\n\t\t\ti++;\n\t\t}\n\t}\n}\n\n/**\n * Split text into words while keeping ANSI codes attached to their words.\n */\nfunction splitIntoWordsWithAnsi(text: string): string[] {\n\tconst words: string[] = [];\n\tlet currentWord = \"\";\n\tlet i = 0;\n\n\twhile (i < text.length) {\n\t\tconst char = text[i];\n\n\t\t// Check for ANSI code\n\t\tconst ansiResult = extractAnsiCode(text, i);\n\t\tif (ansiResult) {\n\t\t\tcurrentWord += ansiResult.code;\n\t\t\ti += ansiResult.length;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Check for space (word boundary)\n\t\tif (char === \" \") {\n\t\t\tif (currentWord) {\n\t\t\t\twords.push(currentWord);\n\t\t\t\tcurrentWord = \"\";\n\t\t\t}\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Regular character\n\t\tcurrentWord += char;\n\t\ti++;\n\t}\n\n\t// Add final word\n\tif (currentWord) {\n\t\twords.push(currentWord);\n\t}\n\n\treturn words;\n}\n\n/**\n * Break a long word that doesn't fit on a single line, character by character.\n */\nfunction breakLongWordWithAnsi(word: string, width: number, tracker: AnsiCodeTracker): string[] {\n\tconst lines: string[] = [];\n\tlet currentLine = tracker.getActiveCodes();\n\tlet currentVisibleLength = 0;\n\tlet i = 0;\n\n\twhile (i < word.length) {\n\t\t// Check for ANSI code\n\t\tconst ansiResult = extractAnsiCode(word, i);\n\t\tif (ansiResult) {\n\t\t\tcurrentLine += ansiResult.code;\n\t\t\ttracker.process(ansiResult.code);\n\t\t\ti += ansiResult.length;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Get character (handle surrogate pairs)\n\t\tconst codePoint = word.charCodeAt(i);\n\t\tlet char: string;\n\t\tlet charByteLength: number;\n\n\t\tif (codePoint >= 0xd800 && codePoint <= 0xdbff && i + 1 < word.length) {\n\t\t\t// High surrogate - get the pair\n\t\t\tchar = word.substring(i, i + 2);\n\t\t\tcharByteLength = 2;\n\t\t} else {\n\t\t\t// Regular character\n\t\t\tchar = word[i];\n\t\t\tcharByteLength = 1;\n\t\t}\n\n\t\tconst charWidth = visibleWidth(char);\n\n\t\t// Check if adding this character would exceed width\n\t\tif (currentVisibleLength + charWidth > width) {\n\t\t\t// Need to wrap\n\t\t\tif (tracker.hasActiveCodes()) {\n\t\t\t\tlines.push(currentLine + tracker.getResetCode());\n\t\t\t\tcurrentLine = tracker.getActiveCodes();\n\t\t\t} else {\n\t\t\t\tlines.push(currentLine);\n\t\t\t\tcurrentLine = \"\";\n\t\t\t}\n\t\t\tcurrentVisibleLength = 0;\n\t\t}\n\n\t\tcurrentLine += char;\n\t\tcurrentVisibleLength += charWidth;\n\t\ti += charByteLength;\n\t}\n\n\t// Add final line (don't close it, let the caller handle that)\n\tif (currentLine || lines.length === 0) {\n\t\tlines.push(currentLine);\n\t}\n\n\treturn lines;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mariozechner/pi-tui",
3
- "version": "0.7.17",
3
+ "version": "0.7.20",
4
4
  "description": "Terminal User Interface library with differential rendering for efficient text-based applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",