@alchemy.run/sigil 0.0.0-alpha.8 → 0.1.0-alpha.1

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 (40) hide show
  1. package/README.md +176 -0
  2. package/THIRD_PARTY_NOTICES.md +28 -0
  3. package/dist/ansi.d.ts +53 -53
  4. package/dist/capabilities.js +1 -1
  5. package/dist/{color-policy-DlrZXC0f.js → color-policy-BAC9-TZX.js} +15 -1
  6. package/dist/color.d.ts +8 -8
  7. package/dist/{devtools-DbthxoD1.js → devtools-B_2SDRaO.js} +3 -0
  8. package/dist/index.d.ts +209 -42
  9. package/dist/index.js +354 -171
  10. package/dist/jsx-dev-runtime.d.ts +3 -0
  11. package/dist/jsx-dev-runtime.js +7 -0
  12. package/dist/jsx-runtime-BS_OosoY.js +42 -0
  13. package/dist/jsx-runtime.d.ts +2 -0
  14. package/dist/jsx-runtime.js +8 -0
  15. package/dist/react-CeO3oT_g.js +394 -0
  16. package/dist/react.d.ts +2 -0
  17. package/dist/react.js +50 -0
  18. package/dist/rolldown-runtime-BPOCksWG.js +24 -0
  19. package/dist/router.d.ts +26 -26
  20. package/dist/router.js +45 -42
  21. package/dist/{session-Cg6STjFV.js → session-DDQ5V300.js} +34 -11
  22. package/dist/terminal.d.ts +9 -10
  23. package/dist/terminal.js +1 -1
  24. package/dist/use-focus-B1WVNBQm.js +8383 -0
  25. package/package.json +27 -15
  26. package/src/ansi/strip.ts +2 -2
  27. package/src/capabilities/query.ts +22 -0
  28. package/src/components/VirtualList.tsx +128 -0
  29. package/src/devtools.ts +5 -0
  30. package/src/hooks/use-virtual-scroll.ts +84 -0
  31. package/src/hooks/use-window-size.ts +10 -3
  32. package/src/index.ts +8 -0
  33. package/src/input-parser.ts +31 -11
  34. package/src/jsx-dev-runtime.ts +3 -0
  35. package/src/jsx-runtime.ts +6 -0
  36. package/src/react.ts +53 -0
  37. package/src/reconciler.ts +51 -0
  38. package/src/terminal/input.ts +11 -5
  39. package/src/virtual-scroll.ts +133 -0
  40. package/dist/use-focus-BNG0xsb7.js +0 -1337
@@ -0,0 +1,133 @@
1
+ /**
2
+ Windowing math shared by `useVirtualScroll` and `<VirtualList>`.
3
+
4
+ Items are stacked vertically and measured in terminal rows. The viewport shows
5
+ `viewportHeight` rows of that stack starting `scrollTop` rows from the top.
6
+ */
7
+ export type VirtualScrollOptions = {
8
+ /**
9
+ Number of items in the list.
10
+ */
11
+ readonly count: number;
12
+
13
+ /**
14
+ Height of the item at `index` in rows. It must match what the item renders:
15
+ the window is computed from these numbers, never from the rendered output.
16
+ */
17
+ readonly itemHeight: (index: number) => number;
18
+
19
+ /**
20
+ Rows available to show items.
21
+ */
22
+ readonly viewportHeight: number;
23
+
24
+ /**
25
+ Requested distance of the viewport from the top of the list in rows. It is
26
+ clamped to the scrollable range and then moved as little as necessary to keep
27
+ `focusedIndex` fully visible.
28
+ */
29
+ readonly scrollTop: number;
30
+
31
+ /**
32
+ Item that must stay fully visible. An item taller than the viewport is aligned
33
+ to the top. Out-of-range values are ignored.
34
+ */
35
+ readonly focusedIndex?: number;
36
+ };
37
+
38
+ export type VirtualScrollWindow = {
39
+ /**
40
+ Index of the first item that intersects the viewport.
41
+ */
42
+ readonly start: number;
43
+
44
+ /**
45
+ Index after the last item that intersects the viewport.
46
+ */
47
+ readonly end: number;
48
+
49
+ /**
50
+ Effective distance of the viewport from the top of the list in rows.
51
+ */
52
+ readonly scrollTop: number;
53
+
54
+ /**
55
+ Largest `scrollTop` that still fills the viewport.
56
+ */
57
+ readonly maxScrollTop: number;
58
+
59
+ /**
60
+ Height of every item combined in rows.
61
+ */
62
+ readonly totalHeight: number;
63
+
64
+ /**
65
+ Position of the `start` item relative to the top of the viewport. Zero or
66
+ negative: a negative value means the item is partially scrolled out above.
67
+ */
68
+ readonly offset: number;
69
+
70
+ /**
71
+ Rows scrolled out above the viewport.
72
+ */
73
+ readonly hiddenAbove: number;
74
+
75
+ /**
76
+ Rows left below the viewport.
77
+ */
78
+ readonly hiddenBelow: number;
79
+ };
80
+
81
+ const clamp = (value: number, min: number, max: number): number =>
82
+ Math.min(Math.max(value, min), max);
83
+
84
+ const wholeRows = (value: number): number => Math.max(0, Math.floor(value)) || 0;
85
+
86
+ /**
87
+ Compute which items intersect a viewport over a vertical stack of items.
88
+ */
89
+ export const virtualScrollWindow = (options: VirtualScrollOptions): VirtualScrollWindow => {
90
+ const count = wholeRows(options.count);
91
+ const viewportHeight = wholeRows(options.viewportHeight);
92
+
93
+ const tops: number[] = [];
94
+ let totalHeight = 0;
95
+ for (let index = 0; index < count; index++) {
96
+ tops.push(totalHeight);
97
+ totalHeight += wholeRows(options.itemHeight(index));
98
+ }
99
+ const bottomOf = (index: number): number => (index + 1 < count ? tops[index + 1]! : totalHeight);
100
+
101
+ const maxScrollTop = Math.max(0, totalHeight - viewportHeight);
102
+ let scrollTop = clamp(Math.floor(options.scrollTop) || 0, 0, maxScrollTop);
103
+
104
+ const focused = options.focusedIndex;
105
+ if (focused !== undefined && Number.isInteger(focused) && focused >= 0 && focused < count) {
106
+ const top = tops[focused]!;
107
+ const bottom = bottomOf(focused);
108
+ if (top < scrollTop) {
109
+ scrollTop = top;
110
+ } else if (bottom > scrollTop + viewportHeight) {
111
+ // Align the bottom edge; an item taller than the viewport shows its top.
112
+ scrollTop = Math.min(top, bottom - viewportHeight);
113
+ }
114
+ scrollTop = clamp(scrollTop, 0, maxScrollTop);
115
+ }
116
+
117
+ const viewportBottom = scrollTop + viewportHeight;
118
+ let start = 0;
119
+ while (start < count && bottomOf(start) <= scrollTop) start++;
120
+ let end = start;
121
+ while (end < count && tops[end]! < viewportBottom) end++;
122
+
123
+ return {
124
+ start,
125
+ end,
126
+ scrollTop,
127
+ maxScrollTop,
128
+ totalHeight,
129
+ offset: start < end ? tops[start]! - scrollTop : 0,
130
+ hiddenAbove: scrollTop,
131
+ hiddenBelow: Math.max(0, totalHeight - viewportBottom),
132
+ };
133
+ };