@alchemy.run/sigil 0.0.0-alpha.1 → 0.0.0-alpha.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 (121) hide show
  1. package/README.md +299 -299
  2. package/dist/ansi.d.ts +223 -0
  3. package/dist/ansi.js +2 -0
  4. package/dist/{devtools-QpCMm9JH.mjs → devtools-BhYGjb7h.js} +1 -1
  5. package/dist/index-DDVME65c.d.ts +919 -0
  6. package/dist/index.d.ts +1657 -0
  7. package/dist/index.js +4643 -0
  8. package/dist/sgr-CMfEpjSk.d.ts +91 -0
  9. package/dist/truncate-CBiyyZzw.js +2156 -0
  10. package/dist/yoga-5jKhYCJC.js +3465 -0
  11. package/dist/yoga.d.ts +2 -0
  12. package/dist/yoga.js +2 -0
  13. package/package.json +37 -17
  14. package/src/ansi/chalk.ts +179 -0
  15. package/src/ansi/cursor.ts +48 -0
  16. package/src/ansi/east-asian-width.ts +215 -0
  17. package/src/ansi/escapes.ts +128 -0
  18. package/src/ansi/index.ts +27 -0
  19. package/src/ansi/sgr.ts +237 -0
  20. package/src/ansi/slice.ts +43 -0
  21. package/src/ansi/string-width.ts +236 -0
  22. package/src/ansi/strip.ts +33 -0
  23. package/src/ansi/supports-color.ts +213 -0
  24. package/src/ansi/tokenize.ts +453 -0
  25. package/src/ansi/truncate.ts +194 -0
  26. package/src/ansi/widest-line.ts +12 -0
  27. package/src/ansi/wrap.ts +766 -0
  28. package/src/ansi-tokenizer.ts +510 -0
  29. package/src/auto-bind.ts +41 -0
  30. package/src/boxes.ts +100 -0
  31. package/src/code-excerpt.ts +39 -0
  32. package/src/colorize.ts +60 -0
  33. package/src/components/AccessibilityContext.ts +5 -0
  34. package/src/components/AnimationContext.ts +24 -0
  35. package/src/components/App.tsx +781 -0
  36. package/src/components/AppContext.ts +111 -0
  37. package/src/components/BackgroundContext.ts +8 -0
  38. package/src/components/Box.tsx +116 -0
  39. package/src/components/CursorContext.ts +19 -0
  40. package/src/components/ErrorBoundary.tsx +38 -0
  41. package/src/components/ErrorOverview.tsx +133 -0
  42. package/src/components/FocusContext.ts +30 -0
  43. package/src/components/Newline.tsx +15 -0
  44. package/src/components/Spacer.tsx +10 -0
  45. package/src/components/Static.tsx +59 -0
  46. package/src/components/StderrContext.ts +26 -0
  47. package/src/components/StdinContext.ts +49 -0
  48. package/src/components/StdoutContext.ts +28 -0
  49. package/src/components/Text.tsx +144 -0
  50. package/src/components/Transform.tsx +37 -0
  51. package/src/cursor-position.ts +103 -0
  52. package/src/devtools-window-polyfill.ts +73 -0
  53. package/src/devtools.ts +43 -0
  54. package/src/dom.ts +292 -0
  55. package/src/get-max-width.ts +11 -0
  56. package/src/global.d.ts +36 -0
  57. package/src/hooks/use-animation.ts +142 -0
  58. package/src/hooks/use-app.ts +8 -0
  59. package/src/hooks/use-box-metrics.ts +134 -0
  60. package/src/hooks/use-cursor.ts +33 -0
  61. package/src/hooks/use-focus-manager.ts +62 -0
  62. package/src/hooks/use-focus.ts +83 -0
  63. package/src/hooks/use-input.ts +267 -0
  64. package/src/hooks/use-is-screen-reader-enabled.ts +12 -0
  65. package/src/hooks/use-paste.ts +78 -0
  66. package/src/hooks/use-stderr.ts +8 -0
  67. package/src/hooks/use-stdin.ts +10 -0
  68. package/src/hooks/use-stdout.ts +8 -0
  69. package/src/hooks/use-window-size.ts +41 -0
  70. package/src/indent-string.ts +16 -0
  71. package/src/index.ts +44 -0
  72. package/src/ink.tsx +1506 -0
  73. package/src/input-parser.ts +283 -0
  74. package/src/instances.ts +9 -0
  75. package/src/is-in-ci.ts +7 -0
  76. package/src/kitty-keyboard.ts +57 -0
  77. package/src/log-update.ts +370 -0
  78. package/src/measure-element.ts +62 -0
  79. package/src/measure-text.ts +31 -0
  80. package/src/output.ts +308 -0
  81. package/src/parse-keypress.ts +516 -0
  82. package/src/parse-stack-line.ts +139 -0
  83. package/src/patch-console.ts +62 -0
  84. package/src/quick-lru.ts +85 -0
  85. package/src/reconciler.ts +451 -0
  86. package/src/render-background.ts +38 -0
  87. package/src/render-border.ts +134 -0
  88. package/src/render-node-to-output.ts +191 -0
  89. package/src/render-to-string.ts +131 -0
  90. package/src/render.ts +276 -0
  91. package/src/renderer.ts +73 -0
  92. package/src/sanitize-ansi.ts +33 -0
  93. package/src/signal-exit.ts +107 -0
  94. package/src/squash-text-nodes.ts +40 -0
  95. package/src/stream.ts +30 -0
  96. package/src/styles.ts +748 -0
  97. package/src/terminal-size.ts +57 -0
  98. package/src/throttle.ts +73 -0
  99. package/src/types.ts +15 -0
  100. package/src/utils.ts +40 -0
  101. package/src/wrap-text.ts +50 -0
  102. package/src/write-synchronized.ts +9 -0
  103. package/src/yoga/config.ts +57 -0
  104. package/src/yoga/core/absoluteLayout.ts +626 -0
  105. package/src/yoga/core/baseline.ts +66 -0
  106. package/src/yoga/core/cache.ts +136 -0
  107. package/src/yoga/core/calculateLayout.ts +2920 -0
  108. package/src/yoga/core/config.ts +104 -0
  109. package/src/yoga/core/flexLine.ts +177 -0
  110. package/src/yoga/core/helpers.ts +293 -0
  111. package/src/yoga/core/layoutResults.ts +167 -0
  112. package/src/yoga/core/node.ts +611 -0
  113. package/src/yoga/core/numeric.ts +44 -0
  114. package/src/yoga/core/pixelGrid.ts +151 -0
  115. package/src/yoga/core/style.ts +887 -0
  116. package/src/yoga/core/types.ts +224 -0
  117. package/src/yoga/generated/YGEnums.ts +263 -0
  118. package/src/yoga/index.ts +19 -0
  119. package/src/yoga/node.ts +1140 -0
  120. package/dist/index.d.mts +0 -2379
  121. package/dist/index.mjs +0 -10072
@@ -0,0 +1,194 @@
1
+ // Truncate a string to a visible width, ANSI-aware.
2
+ // Ported from `cli-truncate` (MIT, Sindre Sorhus) on top of the shared
3
+ // slice and width modules.
4
+ import { sliceAnsi } from "./slice.ts";
5
+ import { stringWidth } from "./string-width.ts";
6
+
7
+ export type TruncateOptions = {
8
+ readonly position?: "start" | "middle" | "end";
9
+ readonly space?: boolean;
10
+ readonly preferTruncationOnSpace?: boolean;
11
+ readonly truncationCharacter?: string;
12
+ };
13
+
14
+ function getIndexOfNearestSpace(
15
+ string: string,
16
+ wantedIndex: number,
17
+ shouldSearchRight = false,
18
+ ): number {
19
+ if (string.charAt(wantedIndex) === " ") {
20
+ return wantedIndex;
21
+ }
22
+
23
+ const direction = shouldSearchRight ? 1 : -1;
24
+
25
+ for (let index = 0; index <= 3; index++) {
26
+ const finalIndex = wantedIndex + index * direction;
27
+ if (string.charAt(finalIndex) === " ") {
28
+ return finalIndex;
29
+ }
30
+ }
31
+
32
+ return wantedIndex;
33
+ }
34
+
35
+ const ANSI_ESC = 27;
36
+ const ANSI_LEFT_BRACKET = 91;
37
+ const ANSI_LETTER_M = 109;
38
+
39
+ const isSgrParameter = (code: number): boolean => (code >= 48 && code <= 57) || code === 59; // 0-9 or ;
40
+
41
+ function leadingSgrSpanEndIndex(string: string): number {
42
+ let index = 0;
43
+ while (
44
+ index + 2 < string.length &&
45
+ string.codePointAt(index) === ANSI_ESC &&
46
+ string.codePointAt(index + 1) === ANSI_LEFT_BRACKET
47
+ ) {
48
+ let scan = index + 2;
49
+ while (scan < string.length && isSgrParameter(string.codePointAt(scan)!)) {
50
+ scan++;
51
+ }
52
+
53
+ if (scan < string.length && string.codePointAt(scan) === ANSI_LETTER_M) {
54
+ index = scan + 1;
55
+ continue;
56
+ }
57
+
58
+ break;
59
+ }
60
+
61
+ return index;
62
+ }
63
+
64
+ function trailingSgrSpanStartIndex(string: string): number {
65
+ let start = string.length;
66
+ while (start > 1 && string.codePointAt(start - 1) === ANSI_LETTER_M) {
67
+ let scan = start - 2;
68
+ while (scan >= 0 && isSgrParameter(string.codePointAt(scan)!)) {
69
+ scan--;
70
+ }
71
+
72
+ if (
73
+ scan >= 1 &&
74
+ string.codePointAt(scan - 1) === ANSI_ESC &&
75
+ string.codePointAt(scan) === ANSI_LEFT_BRACKET
76
+ ) {
77
+ start = scan - 1;
78
+ continue;
79
+ }
80
+
81
+ break;
82
+ }
83
+
84
+ return start;
85
+ }
86
+
87
+ // Insert the truncation character before the trailing SGR close codes, so the
88
+ // visible truncation character inherits the styling of the truncated text.
89
+ function appendWithInheritedStyleFromEnd(visible: string, suffix: string): string {
90
+ const start = trailingSgrSpanStartIndex(visible);
91
+ if (start === visible.length) {
92
+ return visible + suffix;
93
+ }
94
+
95
+ return visible.slice(0, start) + suffix + visible.slice(start);
96
+ }
97
+
98
+ function prependWithInheritedStyleFromStart(prefix: string, visible: string): string {
99
+ const end = leadingSgrSpanEndIndex(visible);
100
+ if (end === 0) {
101
+ return prefix + visible;
102
+ }
103
+
104
+ return visible.slice(0, end) + prefix + visible.slice(end);
105
+ }
106
+
107
+ export function cliTruncate(text: string, columns: number, options: TruncateOptions = {}): string {
108
+ const { position = "end", space = false, preferTruncationOnSpace = false } = options;
109
+
110
+ let { truncationCharacter = "…" } = options;
111
+
112
+ if (columns < 1) {
113
+ return "";
114
+ }
115
+
116
+ const length = stringWidth(text);
117
+
118
+ if (length <= columns) {
119
+ return text;
120
+ }
121
+
122
+ if (columns === 1) {
123
+ return truncationCharacter;
124
+ }
125
+
126
+ if (position === "start") {
127
+ if (preferTruncationOnSpace) {
128
+ const nearestSpace = getIndexOfNearestSpace(
129
+ text,
130
+ length - columns + stringWidth(truncationCharacter),
131
+ true,
132
+ );
133
+ const right = sliceAnsi(text, nearestSpace, length).trim();
134
+ return prependWithInheritedStyleFromStart(truncationCharacter, right);
135
+ }
136
+
137
+ if (space) {
138
+ truncationCharacter += " ";
139
+ }
140
+
141
+ const right = sliceAnsi(text, length - columns + stringWidth(truncationCharacter), length);
142
+ return prependWithInheritedStyleFromStart(truncationCharacter, right);
143
+ }
144
+
145
+ if (position === "middle") {
146
+ if (space) {
147
+ truncationCharacter = ` ${truncationCharacter} `;
148
+
149
+ // Drop the padding spaces if the padded character does not fit, so the
150
+ // truncation character itself never exceeds the budget.
151
+ if (stringWidth(truncationCharacter) >= columns) {
152
+ truncationCharacter = truncationCharacter.trim();
153
+ }
154
+ }
155
+
156
+ const truncationWidth = stringWidth(truncationCharacter);
157
+ // Reserve room for the truncation character before splitting the budget
158
+ // between the two sides, otherwise small budgets overflow.
159
+ const half = Math.min(Math.floor(columns / 2), Math.max(0, columns - truncationWidth));
160
+
161
+ if (preferTruncationOnSpace) {
162
+ const spaceNearFirstBreakPoint = getIndexOfNearestSpace(text, half);
163
+ const spaceNearSecondBreakPoint = getIndexOfNearestSpace(
164
+ text,
165
+ length - (columns - half) + truncationWidth,
166
+ true,
167
+ );
168
+ return (
169
+ sliceAnsi(text, 0, spaceNearFirstBreakPoint) +
170
+ truncationCharacter +
171
+ sliceAnsi(text, spaceNearSecondBreakPoint, length).trim()
172
+ );
173
+ }
174
+
175
+ return (
176
+ sliceAnsi(text, 0, half) +
177
+ truncationCharacter +
178
+ sliceAnsi(text, length - (columns - half) + truncationWidth, length)
179
+ );
180
+ }
181
+
182
+ if (preferTruncationOnSpace) {
183
+ const nearestSpace = getIndexOfNearestSpace(text, columns - stringWidth(truncationCharacter));
184
+ const left = sliceAnsi(text, 0, nearestSpace);
185
+ return appendWithInheritedStyleFromEnd(left, truncationCharacter);
186
+ }
187
+
188
+ if (space) {
189
+ truncationCharacter = ` ${truncationCharacter}`;
190
+ }
191
+
192
+ const left = sliceAnsi(text, 0, columns - stringWidth(truncationCharacter));
193
+ return appendWithInheritedStyleFromEnd(left, truncationCharacter);
194
+ }
@@ -0,0 +1,12 @@
1
+ // Derived from `widest-line` (MIT, Sindre Sorhus).
2
+ import { stringWidth } from "./string-width.ts";
3
+
4
+ export const widestLine = (string: string): number => {
5
+ let lineWidth = 0;
6
+
7
+ for (const line of string.split("\n")) {
8
+ lineWidth = Math.max(lineWidth, stringWidth(line));
9
+ }
10
+
11
+ return lineWidth;
12
+ };