@overdoser/react-toolkit 0.8.3 → 0.10.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 (33) hide show
  1. package/AGENTS.md +6 -0
  2. package/CHANGELOG.md +88 -0
  3. package/README.md +2 -0
  4. package/components/Timeline/GanttTimeline.d.ts +144 -0
  5. package/components/Timeline/GanttTimeline.js +312 -0
  6. package/components/Timeline/GanttTimeline.module.scss.js +55 -0
  7. package/components/Timeline/HistoryTimeline.d.ts +184 -0
  8. package/components/Timeline/HistoryTimeline.js +445 -0
  9. package/components/Timeline/HistoryTimeline.module.scss.js +59 -0
  10. package/components/Timeline/Timeline.module.scss.js +111 -0
  11. package/components/Timeline/TimelineShared.d.ts +79 -0
  12. package/components/Timeline/TimelineShared.js +173 -0
  13. package/components/Timeline/TraceTimeline.d.ts +180 -0
  14. package/components/Timeline/TraceTimeline.js +536 -0
  15. package/components/Timeline/TraceTimeline.module.scss.js +111 -0
  16. package/components/Timeline/demoData.d.ts +42 -0
  17. package/components/Timeline/historyLayout.d.ts +82 -0
  18. package/components/Timeline/historyLayout.js +264 -0
  19. package/components/Timeline/index.d.ts +7 -0
  20. package/components/Timeline/timelineCore.d.ts +100 -0
  21. package/components/Timeline/timelineCore.js +193 -0
  22. package/components/Timeline/traceLayout.d.ts +72 -0
  23. package/components/Timeline/traceLayout.js +92 -0
  24. package/components/Timeline/useTimeline.d.ts +39 -0
  25. package/components/Timeline/useTimeline.js +81 -0
  26. package/index.css +1 -1
  27. package/index.d.ts +2 -0
  28. package/index.js +93 -87
  29. package/index.layered.css +1 -1
  30. package/llms.txt +115 -1
  31. package/manifest.json +323 -0
  32. package/package.json +2 -1
  33. package/recipes/live-timeline-feed.tsx +147 -0
@@ -0,0 +1,72 @@
1
+ /**
2
+ * TraceTimeline band layout, ported near-verbatim from the design handoff
3
+ * (`Manifest Trace.dc.html` logic block). Pure so it can be unit-tested for
4
+ * the no-overlap guarantees:
5
+ *
6
+ * - overlapping/simultaneous bars pack into vertical sub-rows (first-fit by
7
+ * x-extent);
8
+ * - description chips get up to 4 label rows above + 4 below the band,
9
+ * processed newest-first so recent events keep the short stems. A chip
10
+ * placement conflicts when (a) its extent overlaps a placed chip on that
11
+ * row, (b) its vertical stem would pass through a nearer placed chip, or
12
+ * (c) an already-placed farther stem would cross it. Pass 1 places clean;
13
+ * pass 2 slides left up to 140px with an elbow line back to the bar; pass 3
14
+ * accepts a stem crossing rather than hiding the chip.
15
+ */
16
+ export interface TraceLayoutInput {
17
+ /** Stable id (kept on the output). */
18
+ id: string;
19
+ /** Bar left edge, px (inner canvas coordinates). */
20
+ left: number;
21
+ /** Bar width, px. */
22
+ width: number;
23
+ /** Chip width, px. */
24
+ labelW: number;
25
+ }
26
+ export interface TraceLayoutItem extends TraceLayoutInput {
27
+ /** Vertical sub-row of the bar within the band (0-based). */
28
+ sub: number;
29
+ /** Chip row: 0-3 above the band (near→far), 4-7 below; -1 = hidden. */
30
+ row: number;
31
+ /** Chip left edge after nudging, px. */
32
+ labelX: number;
33
+ /** Whether the chip is shown. */
34
+ showLabel: boolean;
35
+ /** Bar top, px. */
36
+ barTop: number;
37
+ /** Chip top, px (when shown). */
38
+ labelTop: number;
39
+ /** Vertical stem segment (under the chip). */
40
+ conn: boolean;
41
+ connTop: number;
42
+ connH: number;
43
+ /** Horizontal elbow segment (when the chip slid off its bar x). */
44
+ hconn: boolean;
45
+ hconnLeft: number;
46
+ hconnTop: number;
47
+ hconnW: number;
48
+ }
49
+ export interface TraceLayoutResult {
50
+ items: TraceLayoutItem[];
51
+ /** Total band height in px (canvas height for the lane). */
52
+ h: number;
53
+ /** Y of the central axis line. */
54
+ axisY: number;
55
+ /** Number of bar sub-rows. */
56
+ subRows: number;
57
+ /** Rightmost extent (bar or chip) in px. */
58
+ maxExt: number;
59
+ }
60
+ export interface TraceLayoutOpts {
61
+ /** Bar height. @default 26 */
62
+ barH?: number;
63
+ /** Label row height. @default 66 */
64
+ rowH?: number;
65
+ /** Chip height. @default 51 */
66
+ chipH?: number;
67
+ /** Minimum canvas height. @default 420 */
68
+ minH?: number;
69
+ }
70
+ export declare function layoutTraceBand(inputs: TraceLayoutInput[], opts?: TraceLayoutOpts): TraceLayoutResult;
71
+ /** Chip width estimate from its three text rows (mono 10px ≈ 6px/char + padding). */
72
+ export declare function traceChipWidth(source: string, target: string, rid: string): number;
@@ -0,0 +1,92 @@
1
+ function G(d, a = {}) {
2
+ const f = a.barH ?? 26, c = a.rowH ?? 66, x = a.chipH ?? 51, S = a.minH ?? 420, w = d.map((o) => ({
3
+ ...o,
4
+ sub: 0,
5
+ row: -1,
6
+ labelX: o.left,
7
+ showLabel: !1,
8
+ barTop: 0,
9
+ labelTop: 0,
10
+ conn: !1,
11
+ connTop: 0,
12
+ connH: 0,
13
+ hconn: !1,
14
+ hconnLeft: 0,
15
+ hconnTop: 0,
16
+ hconnW: 0
17
+ })), t = w.slice().sort((o, n) => o.left - n.left || n.width - o.width), u = [];
18
+ t.forEach((o) => {
19
+ let n = 0;
20
+ for (; n < u.length && o.left < u[n] + 3; ) n++;
21
+ o.sub = n, u[n] = o.left + o.width;
22
+ });
23
+ const H = Math.max(1, u.length), T = [0, 4, 1, 5, 2, 6, 3, 7], E = [], W = [], g = (o, n, e, r) => {
24
+ const X = o < 4, v = X ? o + 1 : o - 3;
25
+ for (const l of E) {
26
+ const b = l.row < 4;
27
+ if (b !== X) continue;
28
+ if ((b ? l.row + 1 : l.row - 3) <= v && r >= l.x1 - 3 && r <= l.x2 + 3) return !0;
29
+ }
30
+ for (const l of W) {
31
+ const b = l.row < 4;
32
+ if (b !== X) continue;
33
+ if ((b ? l.row + 1 : l.row - 3) >= v && l.x >= n - 3 && l.x <= e + 3) return !0;
34
+ }
35
+ return !1;
36
+ }, s = [1e9, 1e9, 1e9, 1e9, 1e9, 1e9, 1e9, 1e9];
37
+ t.slice().reverse().forEach((o) => {
38
+ const n = o.labelW;
39
+ o.row = -1, o.labelX = o.left;
40
+ for (const e of T)
41
+ if (o.left + n <= s[e] - 14 && !g(e, o.left, o.left + n, o.left)) {
42
+ o.row = e, o.labelX = o.left;
43
+ break;
44
+ }
45
+ if (o.row < 0)
46
+ for (const e of T) {
47
+ const r = Math.min(o.left, s[e] - 14 - n);
48
+ if (r >= o.left - 140 && !g(e, r, r + n, o.left)) {
49
+ o.row = e, o.labelX = r;
50
+ break;
51
+ }
52
+ }
53
+ if (o.row < 0)
54
+ for (const e of T) {
55
+ const r = Math.min(o.left, s[e] - 14 - n);
56
+ if (r >= o.left - 140) {
57
+ o.row = e, o.labelX = r;
58
+ break;
59
+ }
60
+ }
61
+ o.row >= 0 && (s[o.row] = Math.min(s[o.row], o.labelX), E.push({ row: o.row, x1: o.labelX, x2: o.labelX + n }), W.push({ row: o.row, x: o.left })), o.showLabel = o.row >= 0;
62
+ });
63
+ const L = t.reduce(
64
+ (o, n) => n.row >= 0 && n.row < 4 ? Math.max(o, n.row + 1) : o,
65
+ 1
66
+ ), N = t.reduce((o, n) => n.row >= 4 ? Math.max(o, n.row - 3) : o, 0), h = H * (f + 4) - 4, k = 10 + L * c + h + N * c + 14, m = Math.max(S, k), p = Math.max(
67
+ 10 + L * c,
68
+ Math.min(Math.round((m - h) / 2), m - h - N * c - 14)
69
+ );
70
+ w.forEach((o) => {
71
+ if (o.barTop = p + o.sub * (f + 4), o.row < 0) return;
72
+ const n = o.row < 4;
73
+ o.labelTop = n ? p - (o.row + 1) * c : p + h + 10 + (o.row - 4) * c, n ? (o.connTop = o.labelTop + x, o.connH = o.barTop - o.connTop - 1) : (o.connTop = o.barTop + f + 1, o.connH = o.labelTop - o.connTop + 2), o.conn = o.connH > 2, o.labelX > o.left + 2 ? (o.hconn = !0, o.hconnTop = o.labelTop + Math.round(x / 2), o.hconnLeft = o.left + 1, o.hconnW = Math.max(2, o.labelX - o.left - 3), o.conn = !0) : o.labelX + o.labelW < o.left - 2 && (o.hconn = !0, o.hconnTop = o.labelTop + Math.round(x / 2), o.hconnLeft = o.labelX + o.labelW - 1, o.hconnW = Math.max(2, o.left - (o.labelX + o.labelW) + 2), o.conn = !0);
74
+ });
75
+ let M = 0;
76
+ return w.forEach((o) => {
77
+ M = Math.max(M, o.left + o.width, o.showLabel ? o.labelX + o.labelW : 0);
78
+ }), {
79
+ items: w,
80
+ h: m,
81
+ axisY: p + Math.round(h / 2),
82
+ subRows: H,
83
+ maxExt: M
84
+ };
85
+ }
86
+ function U(d, a, f) {
87
+ return Math.max(String(d).length + String(a).length + 4, String(f).length, 23) * 6 + 20;
88
+ }
89
+ export {
90
+ G as layoutTraceBand,
91
+ U as traceChipWidth
92
+ };
@@ -0,0 +1,39 @@
1
+ import { RefObject } from 'react';
2
+ /**
3
+ * Drag-to-pan on a scroll container via pointer events. A 5px movement
4
+ * threshold flags the gesture as a drag so the click that ends it can be
5
+ * suppressed (check `wasDragSuppressed()` in click handlers).
6
+ */
7
+ export declare function useTimelinePan(scrollerRef: RefObject<HTMLDivElement | null>): {
8
+ onPointerDown: (e: React.PointerEvent) => void;
9
+ onPointerMove: (e: React.PointerEvent) => void;
10
+ onPointerUp: () => void;
11
+ wasDragSuppressed: () => boolean;
12
+ };
13
+ /**
14
+ * Track the client width of the scroll container (fit mode re-derives layout
15
+ * from it, e.g. when the detail panel opens and the timeline area shrinks).
16
+ */
17
+ export declare function useContainerWidth(ref: RefObject<HTMLDivElement | null>, fallback?: number): number;
18
+ /**
19
+ * Re-render on an interval while `active` (an event is in flight), so open
20
+ * bars/badges grow. Returns the current timestamp.
21
+ */
22
+ export declare function useNowTicker(active: boolean, interval?: number): number;
23
+ /**
24
+ * Animate the element's scroll position to `target` with an ease-out-cubic
25
+ * (fast start, decelerating finish). A new call replaces a running animation;
26
+ * user input on the element (wheel, grabbing to pan) cancels it. Respects
27
+ * `prefers-reduced-motion` by jumping instantly.
28
+ */
29
+ export declare function animateScrollTo(el: HTMLElement, target: {
30
+ left?: number;
31
+ top?: number;
32
+ }, duration?: number): void;
33
+ /**
34
+ * Attach a non-passive wheel listener (plain mouse wheel zooms; the default
35
+ * scroll must be preventable, which React's synthetic onWheel cannot do).
36
+ */
37
+ export declare function useWheelZoom(ref: RefObject<HTMLDivElement | null>, onWheel: (e: WheelEvent) => void,
38
+ /** Re-attach when this changes (e.g. the scroller remounts on orientation switch). */
39
+ remountKey?: unknown): void;
@@ -0,0 +1,81 @@
1
+ import { useState as E, useEffect as v, useRef as h, useCallback as p } from "react";
2
+ function b(e) {
3
+ const n = h(null), o = h(!1), r = p(
4
+ (i) => {
5
+ const c = e.current;
6
+ c && (n.current = { x: i.clientX, y: i.clientY, l: c.scrollLeft, t: c.scrollTop, moved: !1 });
7
+ },
8
+ [e]
9
+ ), t = p(
10
+ (i) => {
11
+ const c = n.current, l = e.current;
12
+ if (!c || !l) return;
13
+ const a = i.clientX - c.x, f = i.clientY - c.y;
14
+ Math.abs(a) + Math.abs(f) > 5 && (c.moved = !0), l.scrollLeft = c.l - a, l.scrollTop = c.t - f;
15
+ },
16
+ [e]
17
+ ), s = p(() => {
18
+ n.current && n.current.moved && (o.current = !0, setTimeout(() => {
19
+ o.current = !1;
20
+ }, 60)), n.current = null;
21
+ }, []), u = p(() => o.current, []);
22
+ return { onPointerDown: r, onPointerMove: t, onPointerUp: s, wasDragSuppressed: u };
23
+ }
24
+ function y(e, n = 1100) {
25
+ const [o, r] = E(n);
26
+ return v(() => {
27
+ const t = e.current;
28
+ if (!t) return;
29
+ const s = new ResizeObserver(() => {
30
+ t.clientWidth && r(t.clientWidth);
31
+ });
32
+ return s.observe(t), t.clientWidth && r(t.clientWidth), () => s.disconnect();
33
+ }, [e]), o;
34
+ }
35
+ function D(e, n = 450) {
36
+ const [o, r] = E(() => Date.now());
37
+ return v(() => {
38
+ if (!e) return;
39
+ const t = setInterval(() => r(Date.now()), n);
40
+ return () => clearInterval(t);
41
+ }, [e, n]), e ? o : Date.now();
42
+ }
43
+ const m = /* @__PURE__ */ new WeakMap();
44
+ function x(e, n, o = 900) {
45
+ const r = m.get(e);
46
+ r != null && cancelAnimationFrame(r);
47
+ const t = e.scrollLeft, s = e.scrollTop, u = n.left != null ? n.left - t : 0, i = n.top != null ? n.top - s : 0;
48
+ if (!u && !i) return;
49
+ if (typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches || o <= 0) {
50
+ n.left != null && (e.scrollLeft = n.left), n.top != null && (e.scrollTop = n.top);
51
+ return;
52
+ }
53
+ const l = performance.now(), a = (w) => 1 - Math.pow(1 - w, 3);
54
+ let f = !1;
55
+ const d = () => {
56
+ f = !0, e.removeEventListener("wheel", d), e.removeEventListener("pointerdown", d), m.delete(e);
57
+ };
58
+ e.addEventListener("wheel", d, { once: !0 }), e.addEventListener("pointerdown", d, { once: !0 });
59
+ const L = (w) => {
60
+ if (f) return;
61
+ const T = Math.min(1, (w - l) / o), M = a(T);
62
+ n.left != null && (e.scrollLeft = t + u * M), n.top != null && (e.scrollTop = s + i * M), T < 1 ? m.set(e, requestAnimationFrame(L)) : d();
63
+ };
64
+ m.set(e, requestAnimationFrame(L));
65
+ }
66
+ function A(e, n, o) {
67
+ const r = h(n);
68
+ r.current = n, v(() => {
69
+ const t = e.current;
70
+ if (!t) return;
71
+ const s = (u) => r.current(u);
72
+ return t.addEventListener("wheel", s, { passive: !1 }), () => t.removeEventListener("wheel", s);
73
+ }, [e, o]);
74
+ }
75
+ export {
76
+ x as animateScrollTo,
77
+ y as useContainerWidth,
78
+ D as useNowTicker,
79
+ b as useTimelinePan,
80
+ A as useWheelZoom
81
+ };