@overdoser/react-toolkit 0.11.0 → 0.13.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.
@@ -0,0 +1,64 @@
1
+ const s = /* @__PURE__ */ new Set([
2
+ "id",
3
+ "service",
4
+ "source",
5
+ "op",
6
+ "kind",
7
+ "level",
8
+ "message",
9
+ "payload",
10
+ "details",
11
+ "requestId",
12
+ "method",
13
+ "url",
14
+ "label",
15
+ "query",
16
+ "reqHeaders",
17
+ "reqBody",
18
+ "status",
19
+ "resHeaders",
20
+ "resBody",
21
+ "start",
22
+ "end"
23
+ ]), o = [
24
+ "method",
25
+ "url",
26
+ "status",
27
+ "query",
28
+ "reqHeaders",
29
+ "reqBody",
30
+ "resHeaders",
31
+ "resBody"
32
+ ], n = (e) => e.kind ? e.kind === "request" : o.some((r) => e[r] != null), u = (e) => e.op || e.requestId || e.reqHeaders && e.reqHeaders["x-request-id"] || e.id, i = (e) => e.source || (n(e) ? "client" : ""), l = (e) => {
33
+ const r = i(e);
34
+ return r ? r + " → " + e.service : e.service;
35
+ }, d = (e) => typeof e == "string" || typeof e == "number" || typeof e == "boolean", a = (e) => {
36
+ if (typeof e == "string") return e;
37
+ try {
38
+ return JSON.stringify(e, null, 2) ?? String(e);
39
+ } catch {
40
+ return String(e);
41
+ }
42
+ };
43
+ function c(e, r) {
44
+ return r ? { text: n(e) ? "pending" : "ongoing", tone: "pending" } : typeof e.status == "number" ? { text: String(e.status), tone: e.status >= 400 ? "error" : "ok" } : e.level ? {
45
+ text: e.level,
46
+ tone: e.level === "error" ? "error" : e.level === "warning" ? "warn" : e.level === "success" ? "ok" : "pending"
47
+ } : null;
48
+ }
49
+ function f(e, r) {
50
+ return Object.keys(e).filter(
51
+ (t) => !s.has(t) && !r?.includes(t) && e[t] !== void 0 && typeof e[t] != "function"
52
+ ).map((t) => ({ label: t, value: e[t] }));
53
+ }
54
+ export {
55
+ s as KNOWN_KEYS,
56
+ c as badgeOf,
57
+ f as extraFieldsOf,
58
+ d as isInline,
59
+ n as isRequestEvent,
60
+ u as ridOf,
61
+ l as routeOf,
62
+ i as srcOf,
63
+ a as toText
64
+ };
@@ -30,6 +30,17 @@ export declare function animateScrollTo(el: HTMLElement, target: {
30
30
  left?: number;
31
31
  top?: number;
32
32
  }, duration?: number): void;
33
+ /**
34
+ * How the wheel interacts with timeline zoom. `'ctrl'` (the timelines'
35
+ * default) zooms only while Ctrl/Cmd is held — plain scrolling passes
36
+ * through to the page, and trackpad pinch keeps zooming since browsers
37
+ * report it as a `ctrlKey` wheel. `'free'` zooms on any wheel/trackpad
38
+ * scroll over the canvas, and `'none'` never wheel-zooms (the toolbar zoom
39
+ * buttons still work).
40
+ */
41
+ export type TimelineWheelZoom = 'free' | 'ctrl' | 'none';
42
+ /** True when a wheel event should zoom under the given mode. */
43
+ export declare function wheelZoomAllowed(mode: TimelineWheelZoom, e: WheelEvent): boolean;
33
44
  /**
34
45
  * Attach a non-passive wheel listener (plain mouse wheel zooms; the default
35
46
  * scroll must be preventable, which React's synthetic onWheel cannot do).
@@ -1,5 +1,5 @@
1
- import { useState as E, useEffect as v, useRef as h, useCallback as p } from "react";
2
- function b(e) {
1
+ import { useState as y, useEffect as v, useRef as h, useCallback as p } from "react";
2
+ function W(e) {
3
3
  const n = h(null), o = h(!1), r = p(
4
4
  (i) => {
5
5
  const c = e.current;
@@ -8,21 +8,21 @@ function b(e) {
8
8
  [e]
9
9
  ), t = p(
10
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;
11
+ const c = n.current, u = e.current;
12
+ if (!c || !u) return;
13
+ const d = i.clientX - c.x, f = i.clientY - c.y;
14
+ Math.abs(d) + Math.abs(f) > 5 && (c.moved = !0), u.scrollLeft = c.l - d, u.scrollTop = c.t - f;
15
15
  },
16
16
  [e]
17
17
  ), s = p(() => {
18
18
  n.current && n.current.moved && (o.current = !0, setTimeout(() => {
19
19
  o.current = !1;
20
20
  }, 60)), n.current = null;
21
- }, []), u = p(() => o.current, []);
22
- return { onPointerDown: r, onPointerMove: t, onPointerUp: s, wasDragSuppressed: u };
21
+ }, []), l = p(() => o.current, []);
22
+ return { onPointerDown: r, onPointerMove: t, onPointerUp: s, wasDragSuppressed: l };
23
23
  }
24
- function y(e, n = 1100) {
25
- const [o, r] = E(n);
24
+ function b(e, n = 1100) {
25
+ const [o, r] = y(n);
26
26
  return v(() => {
27
27
  const t = e.current;
28
28
  if (!t) return;
@@ -32,50 +32,54 @@ function y(e, n = 1100) {
32
32
  return s.observe(t), t.clientWidth && r(t.clientWidth), () => s.disconnect();
33
33
  }, [e]), o;
34
34
  }
35
- function D(e, n = 450) {
36
- const [o, r] = E(() => Date.now());
35
+ function A(e, n = 450) {
36
+ const [o, r] = y(() => Date.now());
37
37
  return v(() => {
38
38
  if (!e) return;
39
39
  const t = setInterval(() => r(Date.now()), n);
40
40
  return () => clearInterval(t);
41
41
  }, [e, n]), e ? o : Date.now();
42
42
  }
43
- const m = /* @__PURE__ */ new WeakMap();
44
- function x(e, n, o = 900) {
45
- const r = m.get(e);
43
+ const w = /* @__PURE__ */ new WeakMap();
44
+ function D(e, n, o = 900) {
45
+ const r = w.get(e);
46
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;
47
+ const t = e.scrollLeft, s = e.scrollTop, l = n.left != null ? n.left - t : 0, i = n.top != null ? n.top - s : 0;
48
+ if (!l && !i) return;
49
49
  if (typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches || o <= 0) {
50
50
  n.left != null && (e.scrollLeft = n.left), n.top != null && (e.scrollTop = n.top);
51
51
  return;
52
52
  }
53
- const l = performance.now(), a = (w) => 1 - Math.pow(1 - w, 3);
53
+ const u = performance.now(), d = (m) => 1 - Math.pow(1 - m, 3);
54
54
  let f = !1;
55
- const d = () => {
56
- f = !0, e.removeEventListener("wheel", d), e.removeEventListener("pointerdown", d), m.delete(e);
55
+ const a = () => {
56
+ f = !0, e.removeEventListener("wheel", a), e.removeEventListener("pointerdown", a), w.delete(e);
57
57
  };
58
- e.addEventListener("wheel", d, { once: !0 }), e.addEventListener("pointerdown", d, { once: !0 });
59
- const L = (w) => {
58
+ e.addEventListener("wheel", a, { once: !0 }), e.addEventListener("pointerdown", a, { once: !0 });
59
+ const L = (m) => {
60
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();
61
+ const T = Math.min(1, (m - u) / o), M = d(T);
62
+ n.left != null && (e.scrollLeft = t + l * M), n.top != null && (e.scrollTop = s + i * M), T < 1 ? w.set(e, requestAnimationFrame(L)) : a();
63
63
  };
64
- m.set(e, requestAnimationFrame(L));
64
+ w.set(e, requestAnimationFrame(L));
65
65
  }
66
- function A(e, n, o) {
66
+ function x(e, n) {
67
+ return e === "free" || e === "ctrl" && (n.ctrlKey || n.metaKey);
68
+ }
69
+ function P(e, n, o) {
67
70
  const r = h(n);
68
71
  r.current = n, v(() => {
69
72
  const t = e.current;
70
73
  if (!t) return;
71
- const s = (u) => r.current(u);
74
+ const s = (l) => r.current(l);
72
75
  return t.addEventListener("wheel", s, { passive: !1 }), () => t.removeEventListener("wheel", s);
73
76
  }, [e, o]);
74
77
  }
75
78
  export {
76
- x as animateScrollTo,
77
- y as useContainerWidth,
78
- D as useNowTicker,
79
- b as useTimelinePan,
80
- A as useWheelZoom
79
+ D as animateScrollTo,
80
+ b as useContainerWidth,
81
+ A as useNowTicker,
82
+ W as useTimelinePan,
83
+ P as useWheelZoom,
84
+ x as wheelZoomAllowed
81
85
  };