lilact 0.13.0 → 0.14.0

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 (43) hide show
  1. package/dist/lilact.development.js +269 -250
  2. package/dist/lilact.development.js.map +1 -1
  3. package/dist/lilact.development.min.js +1 -1
  4. package/dist/lilact.development.min.js.LICENSE.txt +1 -1
  5. package/dist/lilact.development.min.js.map +1 -1
  6. package/dist/lilact.production.min.js +1 -1
  7. package/dist/lilact.production.min.js.map +1 -1
  8. package/docs/assets/hierarchy.js +1 -1
  9. package/docs/assets/highlight.css +4 -4
  10. package/docs/assets/navigation.js +1 -1
  11. package/docs/assets/search.js +1 -1
  12. package/docs/classes/accessories.ErrorBoundary.html +11 -11
  13. package/docs/classes/accessories.Suspense.html +10 -10
  14. package/docs/classes/components.Component.html +11 -11
  15. package/docs/classes/components.HTMLComponent.html +11 -11
  16. package/docs/classes/components.RootComponent.html +12 -12
  17. package/docs/functions/accessories.DragHandle.html +12 -6
  18. package/docs/functions/accessories.Spinner.html +1 -1
  19. package/docs/functions/components.createComponent.html +1 -1
  20. package/docs/functions/components.createRoot.html +1 -1
  21. package/docs/functions/components.render.html +1 -1
  22. package/docs/hierarchy.html +1 -1
  23. package/docs/modules/accessories.html +1 -1
  24. package/docs/modules.html +1 -1
  25. package/docs/static/demos/capture.jsx +26 -0
  26. package/docs/static/index.html +4 -1
  27. package/docs/static/lilact.development.js +269 -250
  28. package/docs/static/lilact.development.min.js +1 -1
  29. package/docs/static/lilact.production.min.js +1 -1
  30. package/docs/variables/{pane.SplitPane.html → accessories.SplitPane.html} +3 -3
  31. package/package.json +1 -1
  32. package/root/demos/capture.jsx +26 -0
  33. package/root/index.html +4 -1
  34. package/root/lilact.development.js +269 -250
  35. package/root/lilact.development.min.js +1 -1
  36. package/root/lilact.production.min.js +1 -1
  37. package/src/accessories.jsx +293 -12
  38. package/src/components.jsx +7 -0
  39. package/src/lilact.jsx +1 -5
  40. package/src/misc.jsx +6 -1
  41. package/typedoc.json +0 -1
  42. package/docs/modules/pane.html +0 -1
  43. package/src/pane.jsx +0 -270
package/src/pane.jsx DELETED
@@ -1,270 +0,0 @@
1
- import { useEffect, useLayoutEffect, useMemo, useRef, useState, useImperativeHandle } from "./hooks.jsx";
2
- import { Children, forwardRef } from "./misc.jsx";
3
-
4
-
5
- const clamp = (n, min, max) => {
6
- if (!Number.isFinite(n)) return n;
7
- return Math.min(max, Math.max(min, n));
8
- };
9
-
10
- /**
11
- * A split-pane container with a draggable splitter, supporting both horizontal and vertical layouts.
12
- *
13
- * The pane can be either:
14
- * - **Controlled** via the `position` prop (number between `min` and `max`), or
15
- * - **Uncontrolled** via `defaultPosition` (used as the initial position).
16
- *
17
- * Layout behavior:
18
- * - `mode="horizontal"`: the `position` controls the width of the **left** pane.
19
- * - `mode="vertical"`: the `position` controls the height of the **top** pane.
20
- *
21
- * Ref API:
22
- * - Exposes imperative methods on `ref.current`:
23
- * - `getMode()` to get the current mode
24
- * - `setMode(mode)` to switch between `"horizontal"` and `"vertical"`
25
- * - `getPosition()` to get the current splitter position
26
- * - `setPosition(position)` to update the splitter position
27
- *
28
- * Events:
29
- * - Calls `onSizeChange(position)` whenever the pane size/position changes (e.g., via dragging).
30
- *
31
- * Rendering:
32
- * - Renders `children` into two separate containers (no portals).
33
- *
34
- * @param mode - Split direction: `"horizontal"` or `"vertical"`. Defaults to `"horizontal"`.
35
- * @param position - Controlled splitter position. Normalized value within `[min, max]`.
36
- * If provided, the component uses this value instead of internal state.
37
- * @param defaultPosition - Initial splitter position for uncontrolled usage. Defaults to `0.5`.
38
- * @param min - Minimum allowed position. Defaults to `0.1`.
39
- * @param max - Maximum allowed position. Defaults to `0.9`.
40
- * @param splitterSize - Thickness of the draggable splitter in pixels. Defaults to `8`.
41
- * @param onSizeChange - Callback invoked when the position changes. Receives the new normalized position.
42
- * @param style - Optional root container styles.
43
- * @param className - Optional root container CSS class.
44
- * @param leftPaneStyle - Optional styles applied to the left pane (or top pane in vertical mode).
45
- * @param rightPaneStyle - Optional styles applied to the right pane (or bottom pane in vertical mode).
46
- * @param splitterStyle - Optional styles applied to the splitter element.
47
- * @param children - React children to be rendered into the two pane containers.
48
- *
49
- * @example
50
- * ```tsx
51
- * const ref = useRef<SplitPaneHandle>(null);
52
- *
53
- * <SplitPane
54
- * ref={ref}
55
- * mode="horizontal"
56
- * defaultPosition={0.5}
57
- * min={0.1}
58
- * max={0.9}
59
- * onSizeChange={(pos) => console.log(pos)}
60
- * >
61
- * <div /> <div />
62
- * </SplitPane>
63
- * ```
64
- */
65
- export const SplitPane = forwardRef(function SplitPane(
66
- {
67
- mode = "horizontal",
68
- position, // controlled: number | undefined/null
69
- defaultPosition = 0.5,
70
- min = 0.1,
71
- max = 0.9,
72
- splitterSize = 8,
73
- onSizeChange,
74
- style,
75
- className,
76
- leftPaneStyle,
77
- rightPaneStyle,
78
- splitterStyle,
79
- children,
80
- },
81
- ref
82
- ) {
83
- const containerRef = useRef(null);
84
- const panes = Children.toArray(children);
85
- const leftChild = panes[0] ?? null;
86
- const rightChild = panes[1] ?? null;
87
-
88
- const isControlled = position != null;
89
-
90
- const [internalMode, setInternalMode] = useState(mode);
91
-
92
- const [posUncontrolled, setPosUncontrolled] = useState(() =>
93
- clamp(
94
- position ?? defaultPosition,
95
- min,
96
- max
97
- )
98
- );
99
-
100
- useEffect(() => {
101
- if (mode != null) setInternalMode(mode);
102
- }, [mode]);
103
-
104
- // keep internal position clamped if min/max change (uncontrolled only)
105
- useLayoutEffect(() => {
106
- if (isControlled) return;
107
- setPosUncontrolled((p) => clamp(p, min, max));
108
- }, [min, max, isControlled]);
109
-
110
- const posResolved = isControlled ? clamp(position, min, max) : posUncontrolled;
111
-
112
- const setPosition = (next) => {
113
- const clamped = clamp(next, min, max);
114
- if (!isControlled) setPosUncontrolled(clamped);
115
- onSizeChange?.(clamped);
116
- };
117
-
118
- const draggingRef = useRef(false);
119
- const pointerIdRef = useRef(null);
120
-
121
- const updateFromClient = (clientX, clientY) => {
122
- const el = containerRef.current;
123
- if (!el) return;
124
-
125
- const rect = el.getBoundingClientRect();
126
-
127
- if (internalMode === "horizontal") {
128
- const usable = rect.width;
129
- if (!Number.isFinite(usable) || usable <= 0) return; // no jump on init
130
- const raw = (clientX - rect.left) / usable;
131
- if (!Number.isFinite(raw)) return;
132
- setPosition(raw);
133
- } else {
134
- const usable = rect.height;
135
- if (!Number.isFinite(usable) || usable <= 0) return; // no jump on init
136
- const raw = (clientY - rect.top) / usable;
137
- if (!Number.isFinite(raw)) return;
138
- setPosition(raw);
139
- }
140
- };
141
-
142
- // stable global listeners: only act while draggingRef.current === true
143
- useEffect(() => {
144
- const onMove = (e) => {
145
- if (!draggingRef.current) return;
146
- if (pointerIdRef.current != null && e.pointerId !== pointerIdRef.current) return;
147
- updateFromClient(e.clientX, e.clientY);
148
- };
149
-
150
- const stop = (e) => {
151
- if (!draggingRef.current) return;
152
- if (pointerIdRef.current != null && e.pointerId !== pointerIdRef.current) return;
153
- draggingRef.current = false;
154
- pointerIdRef.current = null;
155
- };
156
-
157
- window.addEventListener("pointermove", onMove, { passive: true });
158
- window.addEventListener("pointerup", stop, { passive: true });
159
- window.addEventListener("pointercancel", stop, { passive: true });
160
-
161
- return () => {
162
- window.removeEventListener("pointermove", onMove);
163
- window.removeEventListener("pointerup", stop);
164
- window.removeEventListener("pointercancel", stop);
165
- };
166
- }, [internalMode]); // updateFromClient uses internalMode
167
-
168
- const onPointerDown = (e) => {
169
- if (e.button != null && e.button !== 0) return;
170
- e.preventDefault();
171
-
172
- draggingRef.current = true;
173
- pointerIdRef.current = e.pointerId;
174
-
175
- try {
176
- e.currentTarget.setPointerCapture?.(e.pointerId);
177
- } catch {}
178
-
179
- updateFromClient(e.clientX, e.clientY); // first update only if rect is sane
180
- };
181
-
182
- const onKeyDown = (e) => {
183
- const step = 0.02;
184
- let delta = 0;
185
-
186
- if (internalMode === "horizontal") {
187
- if (e.key === "ArrowLeft") delta = -step;
188
- if (e.key === "ArrowRight") delta = step;
189
- } else {
190
- if (e.key === "ArrowUp") delta = -step;
191
- if (e.key === "ArrowDown") delta = step;
192
- }
193
-
194
- if (delta !== 0) {
195
- e.preventDefault();
196
- setPosition(posResolved + delta);
197
- }
198
- };
199
-
200
- const sizes = useMemo(() => {
201
- const leftPct = `${posResolved * 100}%`;
202
- const rightCalc = `calc(${100 - posResolved * 100}% - ${splitterSize}px)`;
203
- return { leftPct, rightCalc };
204
- }, [posResolved, splitterSize]);
205
-
206
- const rootStyle = {
207
- display: "flex",
208
- width: "100%",
209
- height: "100%",
210
- overflow: "hidden",
211
- touchAction: "none",
212
- ...(style || {}),
213
- flexDirection: internalMode === "horizontal" ? "row" : "column",
214
- };
215
-
216
- const leftPaneComputed =
217
- internalMode === "horizontal"
218
- ? { width: sizes.leftPct, flex: `0 0 ${sizes.leftPct}`, overflow: "auto", ...(leftPaneStyle || {}) }
219
- : { height: sizes.leftPct, flex: `0 0 ${sizes.leftPct}`, overflow: "auto", ...(leftPaneStyle || {}) };
220
-
221
- const rightPaneComputed =
222
- internalMode === "horizontal"
223
- ? { width: sizes.rightCalc, flex: "1 1 auto", overflow: "auto", ...(rightPaneStyle || {}) }
224
- : { height: sizes.rightCalc, flex: "1 1 auto", overflow: "auto", ...(rightPaneStyle || {}) };
225
-
226
- const splitterComputed =
227
- internalMode === "horizontal"
228
- ? { width: `${splitterSize}px`, transform: "translateX(-50%)", height: '100%', flex: `0 0 ${splitterSize}px`, background: "rgba(0,0,0,0.08)", cursor: "col-resize", ...(splitterStyle || {}) }
229
- : { height: `${splitterSize}px`, transform: "translateY(-50%)", width: '100%', flex: `0 0 ${splitterSize}px`, background: "rgba(0,0,0,0.08)", cursor: "row-resize", ...(splitterStyle || {}) };
230
-
231
- const dividerVisualStyle =
232
- internalMode === "horizontal"
233
- ? { height: "100%", width: "100%" }
234
- : { width: "100%", height: "100%" };
235
-
236
- useImperativeHandle(ref, () => ({
237
- setPosition,
238
- setMode: (nextMode) => setInternalMode(nextMode === "vertical" ? "vertical" : "horizontal"),
239
- getPosition: () => posResolved,
240
- getMode: () => internalMode,
241
- }));
242
-
243
- return (
244
- <div ref={containerRef} className={className} style={rootStyle}>
245
- <div style={leftPaneComputed}>{leftChild}</div>
246
-
247
- <div
248
- role="separator"
249
- aria-orientation={internalMode === "horizontal" ? "vertical" : "horizontal"}
250
- aria-valuemin={min}
251
- aria-valuemax={max}
252
- aria-valuenow={posResolved}
253
- tabIndex={0}
254
- onPointerDown={onPointerDown}
255
- onPointerCancel={() => {
256
- draggingRef.current = false;
257
- pointerIdRef.current = null;
258
- }}
259
- onKeyDown={onKeyDown}
260
- style={splitterComputed}
261
- >
262
- <div style={dividerVisualStyle} />
263
- </div>
264
-
265
- <div style={rightPaneComputed}>{rightChild}</div>
266
- </div>
267
- );
268
- });
269
-
270
-