@stackone/malachite 2.136.0 → 2.137.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.
@@ -1,55 +1,55 @@
1
- import { MONTHS_SHORT as D, daysInMonth as k } from "../dateMath.js";
2
- const M = 6e4, g = 60 * M, h = 24 * g, _ = {
3
- minute: M,
1
+ import { fromParts as k, partsOf as Y, MONTHS_SHORT as p, daysInMonth as I } from "../dateMath.js";
2
+ const i = 6e4, g = 60 * i, h = 24 * g, y = {
3
+ minute: i,
4
4
  hour: g,
5
5
  day: h,
6
6
  week: 7 * h
7
- }, $ = /^\d{4}-\d{2}-\d{2}(?:[ T]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?$/, P = (t) => {
7
+ }, H = /^\d{4}-\d{2}-\d{2}(?:[ T]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?$/, G = (t) => {
8
8
  if (typeof t == "number") return t;
9
9
  if (t instanceof Date) return t.getTime();
10
- const n = t.trim();
11
- if ($.test(n)) {
12
- const [e, o = "00:00:00"] = n.split(/[ T]/);
13
- return Date.parse(`${e}T${o}Z`);
10
+ const e = t.trim();
11
+ if (H.test(e)) {
12
+ const [o, n = "00:00:00"] = e.split(/[ T]/);
13
+ return Date.parse(`${o}T${n}Z`);
14
14
  }
15
- return Date.parse(n);
16
- }, T = (t) => Math.max(1, Math.floor(t.step ?? 1)), C = (t, n, e = 1) => {
17
- const o = _[n.unit];
18
- if (o !== void 0) return t + o * T(n) * e;
15
+ return Date.parse(e);
16
+ }, l = (t) => Math.max(1, Math.floor(t.step ?? 1)), $ = (t, e, o = 1) => {
17
+ const n = y[e.unit];
18
+ if (n !== void 0) return t + n * l(e) * o;
19
19
  const r = new Date(t);
20
20
  return Date.UTC(
21
21
  r.getUTCFullYear(),
22
- r.getUTCMonth() + T(n) * e,
22
+ r.getUTCMonth() + l(e) * o,
23
23
  r.getUTCDate(),
24
24
  r.getUTCHours(),
25
25
  r.getUTCMinutes()
26
26
  );
27
- }, w = 4 * h, i = (t, n) => {
28
- const e = T(n);
29
- if (n.unit === "month") {
30
- const a = new Date(t), s = a.getUTCFullYear() * 12 + a.getUTCMonth(), u = s - s % e;
31
- return Date.UTC(Math.floor(u / 12), u % 12, 1);
27
+ }, w = 4 * h, C = (t, e) => {
28
+ const o = l(e);
29
+ if (e.unit === "month") {
30
+ const s = new Date(t), c = s.getUTCFullYear() * 12 + s.getUTCMonth(), a = c - c % o;
31
+ return Date.UTC(Math.floor(a / 12), a % 12, 1);
32
32
  }
33
- const o = (_[n.unit] ?? h) * e, r = n.unit === "week" ? w : 0;
34
- return Math.floor((t - r) / o) * o + r;
35
- }, U = 2e3, Z = (t, n, e) => {
36
- const o = [], r = i(n, e), a = Math.max(i(t, e), C(r, e, 1 - U));
37
- for (let s = a; s <= r && o.length < U; ) {
38
- const u = C(s, e);
39
- o.push({ start: s, end: u }), s = u;
33
+ const n = (y[e.unit] ?? h) * o, r = e.unit === "week" ? w : 0;
34
+ return Math.floor((t - r) / n) * n + r;
35
+ }, _ = 2e3, Q = (t, e, o) => {
36
+ const n = [], r = C(e, o), s = Math.max(C(t, o), $(r, o, 1 - _));
37
+ for (let c = s; c <= r && n.length < _; ) {
38
+ const a = $(c, o);
39
+ n.push({ start: c, end: a }), c = a;
40
40
  }
41
- return o;
42
- }, K = (t, n) => {
43
- if (!Number.isFinite(n)) return -1;
44
- let e = 0, o = t.length - 1;
45
- for (; e <= o; ) {
46
- const r = e + o >> 1;
47
- if (n < t[r].start) o = r - 1;
48
- else if (n >= t[r].end) e = r + 1;
41
+ return n;
42
+ }, V = (t, e) => {
43
+ if (!Number.isFinite(e)) return -1;
44
+ let o = 0, n = t.length - 1;
45
+ for (; o <= n; ) {
46
+ const r = o + n >> 1;
47
+ if (e < t[r].start) n = r - 1;
48
+ else if (e >= t[r].end) o = r + 1;
49
49
  else return r;
50
50
  }
51
51
  return -1;
52
- }, y = [
52
+ }, F = [
53
53
  "January",
54
54
  "February",
55
55
  "March",
@@ -62,72 +62,76 @@ const M = 6e4, g = 60 * M, h = 24 * g, _ = {
62
62
  "October",
63
63
  "November",
64
64
  "December"
65
- ], I = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], f = (t) => String(t).padStart(2, "0"), p = (t) => `${f(t.getUTCHours())}:${f(t.getUTCMinutes())}`, Y = (t) => `${I[t.getUTCDay()]} ${t.getUTCDate()}`, S = (t) => `${D[t.getUTCMonth()]} ${f(t.getUTCDate())}`, j = (t, n) => {
66
- const e = new Date(t);
67
- return n === "month" ? `${y[e.getUTCMonth()]} ${e.getUTCFullYear()}` : n === "day" || n === "week" ? `${S(e)}, ${e.getUTCFullYear()}` : `${S(e)} ${p(e)}`;
68
- }, b = 3 * g, H = 72 * g, E = 92 * h, L = (t, n) => t === "month" || n >= E ? "month" : t === "day" || t === "week" || n >= H ? "day" : t === "hour" || n >= b ? "hour" : "minute", N = {
65
+ ], E = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], T = (t) => String(t).padStart(2, "0"), d = (t) => `${T(t.getUTCHours())}:${T(t.getUTCMinutes())}`, L = (t) => `${E[t.getUTCDay()]} ${t.getUTCDate()}`, M = (t) => `${p[t.getUTCMonth()]} ${T(t.getUTCDate())}`, f = (t, e) => k(Y(new Date(t), e), "utc"), N = (t, e) => {
66
+ if (e === "utc") return "";
67
+ const o = Math.round((f(t, "local").getTime() - t) / i);
68
+ return ` UTC${o < 0 ? "-" : "+"}${T(Math.floor(Math.abs(o) / 60))}:${T(Math.abs(o) % 60)}`;
69
+ }, Z = (t, e, o = "utc") => {
70
+ const n = f(t, o), r = N(t, o);
71
+ return e === "minute" || e === "hour" ? `${M(n)} ${d(n)}${r}` : n.getUTCHours() || n.getUTCMinutes() ? `${M(n)}, ${n.getUTCFullYear()} ${d(n)}${r}` : e === "month" ? `${F[n.getUTCMonth()]} ${n.getUTCFullYear()}${r}` : `${M(n)}, ${n.getUTCFullYear()}${r}`;
72
+ }, R = 3 * g, X = 72 * g, x = 92 * h, B = (t, e) => t === "month" || e >= x ? "month" : t === "day" || t === "week" || e >= X ? "day" : t === "hour" || e >= R ? "hour" : "minute", J = {
69
73
  minute: [1, 5, 10, 15, 30, 60, 120, 180, 360, 720],
70
74
  hour: [1, 2, 3, 4, 6, 12, 24],
71
75
  day: [1, 2, 3, 7, 14],
72
76
  month: [1, 2, 3, 6, 12]
73
- }, R = (t, n, e) => {
77
+ }, P = (t, e, o) => {
78
+ const n = new Date(t);
79
+ if (e === "minute") return (n.getUTCHours() * 60 + n.getUTCMinutes()) % o === 0;
80
+ if (e === "hour") return n.getUTCHours() % o === 0;
81
+ if (e === "month") return n.getUTCMonth() % o === 0;
82
+ const r = I({ year: n.getUTCFullYear(), month: n.getUTCMonth() });
83
+ return (n.getUTCDate() - 1) % o === 0 && n.getUTCDate() + o <= r + 1;
84
+ }, O = (t, e) => {
85
+ if (e === "minute") return t + i;
86
+ if (e === "hour") return t + g;
87
+ if (e === "day") return t + h;
74
88
  const o = new Date(t);
75
- if (n === "minute") return (o.getUTCHours() * 60 + o.getUTCMinutes()) % e === 0;
76
- if (n === "hour") return o.getUTCHours() % e === 0;
77
- if (n === "month") return o.getUTCMonth() % e === 0;
78
- const r = k({ year: o.getUTCFullYear(), month: o.getUTCMonth() });
79
- return (o.getUTCDate() - 1) % e === 0 && o.getUTCDate() + e <= r + 1;
80
- }, F = (t, n) => {
81
- if (n === "minute") return t + M;
82
- if (n === "hour") return t + g;
83
- if (n === "day") return t + h;
84
- const e = new Date(t);
85
- return Date.UTC(e.getUTCFullYear(), e.getUTCMonth() + 1, 1);
86
- }, X = (t, n) => {
87
- const e = i(t, {
88
- unit: n === "month" ? "month" : n
89
+ return Date.UTC(o.getUTCFullYear(), o.getUTCMonth() + 1, 1);
90
+ }, W = (t, e) => {
91
+ const o = C(t, {
92
+ unit: e === "month" ? "month" : e
89
93
  });
90
- return e < t ? F(e, n) : e;
91
- }, B = 64, x = {
94
+ return o < t ? O(o, e) : o;
95
+ }, z = 64, K = {
92
96
  minute: "hour",
93
97
  hour: "day",
94
98
  day: "month",
95
99
  month: void 0
96
- }, q = (t, n, e, o) => O(t, n, L(e, n - t), o), O = (t, n, e, o) => {
97
- const r = [];
98
- for (let c = X(t, e); c <= n && r.length < 5e3; c = F(c, e))
99
- r.push(c);
100
- const a = Math.max(1, Math.floor(o / B)), s = N[e], u = s.find((c) => r.length / c <= a), l = x[e];
101
- if (u === void 0 && l) return O(t, n, l, o);
102
- const A = u ?? s[s.length - 1], m = r.filter((c) => R(c, e, A));
103
- return m.map((c, d) => ({
104
- at: c,
105
- label: J(c, e, d === 0 ? c - 1 : m[d - 1])
100
+ }, v = (t, e, o, n, r = "utc") => A(t, e, B(o, e - t), n, r), A = (t, e, o, n, r) => {
101
+ const s = [];
102
+ for (let u = W(t, o); u <= e && s.length < 5e3; u = O(u, o))
103
+ s.push(u);
104
+ const c = Math.max(1, Math.floor(n / z)), a = J[o], m = a.find((u) => s.length / u <= c), U = K[o];
105
+ if (m === void 0 && U) return A(t, e, U, n, r);
106
+ const b = m ?? a[a.length - 1], S = s.filter((u) => P(u, o, b));
107
+ return S.map((u, D) => ({
108
+ at: u,
109
+ label: j(u, o, D === 0 ? u - 1 : S[D - 1], r)
106
110
  }));
107
- }, J = (t, n, e) => {
108
- const o = new Date(t), r = new Date(e);
109
- return o.getUTCFullYear() !== r.getUTCFullYear() ? String(o.getUTCFullYear()) : o.getUTCMonth() !== r.getUTCMonth() ? y[o.getUTCMonth()] : n === "month" ? D[o.getUTCMonth()] : o.getUTCDate() !== r.getUTCDate() || n === "day" ? Y(o) : p(o);
110
- }, z = (t, n = 4) => {
111
+ }, j = (t, e, o, n) => {
112
+ const r = f(t, n), s = f(o, n);
113
+ return r.getUTCFullYear() !== s.getUTCFullYear() ? String(r.getUTCFullYear()) : r.getUTCMonth() !== s.getUTCMonth() ? F[r.getUTCMonth()] : e === "month" ? p[r.getUTCMonth()] : r.getUTCDate() !== s.getUTCDate() || e === "day" ? L(r) : d(r);
114
+ }, tt = (t, e = 4) => {
111
115
  if (t <= 0) return [0, 1];
112
- const e = t / n, o = 10 ** Math.floor(Math.log10(e)), r = Math.max(
116
+ const o = t / e, n = 10 ** Math.floor(Math.log10(o)), r = Math.max(
113
117
  1,
114
- [1, 2, 5, 10].map((s) => s * o).find((s) => s >= e) ?? 10 * o
115
- ), a = Math.ceil(t / r) * r;
116
- return Array.from({ length: a / r + 1 }, (s, u) => u * r);
117
- }, G = (t) => t.toLocaleString("en", { notation: "compact", maximumFractionDigits: 1 }), Q = (t) => t.toLocaleString("en");
118
+ [1, 2, 5, 10].map((c) => c * n).find((c) => c >= o) ?? 10 * n
119
+ ), s = Math.ceil(t / r) * r;
120
+ return Array.from({ length: s / r + 1 }, (c, a) => a * r);
121
+ }, et = (t) => t.toLocaleString("en", { notation: "compact", maximumFractionDigits: 1 }), ot = (t) => t.toLocaleString("en");
118
122
  export {
119
- B as AXIS_LABEL_WIDTH_PX,
120
- U as MAX_SLOTS,
121
- C as addBuckets,
122
- q as axisTicks,
123
- L as axisUnitFor,
124
- Z as bucketSlots,
125
- i as bucketStart,
126
- j as formatBucket,
127
- G as formatCompact,
128
- Q as formatCount,
129
- K as slotIndexOf,
130
- P as toInstant,
131
- z as valueTicks
123
+ z as AXIS_LABEL_WIDTH_PX,
124
+ _ as MAX_SLOTS,
125
+ $ as addBuckets,
126
+ v as axisTicks,
127
+ B as axisUnitFor,
128
+ Q as bucketSlots,
129
+ C as bucketStart,
130
+ Z as formatBucket,
131
+ et as formatCompact,
132
+ ot as formatCount,
133
+ V as slotIndexOf,
134
+ G as toInstant,
135
+ tt as valueTicks
132
136
  };
133
137
  //# sourceMappingURL=timeBuckets.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"timeBuckets.js","sources":["../../../src/components/TimeBarChart/timeBuckets.ts"],"sourcesContent":["import { MONTHS_SHORT, daysInMonth } from '../dateMath';\n\n// UTC time arithmetic for TimeBarChart, kept free of a date library so the component adds no\n// dependency. Every instant is milliseconds since the epoch, read and written in UTC.\n\nexport type TimeBarChartUnit = 'minute' | 'hour' | 'day' | 'week' | 'month';\n\nexport interface TimeBarChartInterval {\n unit: TimeBarChartUnit;\n /** How many `unit`s one bucket spans, e.g. 3 with `hour` for 3-hour buckets. Default 1. */\n step?: number;\n}\n\nexport type TimeInput = string | number | Date;\n\nexport interface TimeSlot {\n start: number;\n end: number;\n}\n\nconst MINUTE_MS = 60_000;\nconst HOUR_MS = 60 * MINUTE_MS;\nconst DAY_MS = 24 * HOUR_MS;\n\nconst FIXED_UNIT_MS: Partial<Record<TimeBarChartUnit, number>> = {\n minute: MINUTE_MS,\n hour: HOUR_MS,\n day: DAY_MS,\n week: 7 * DAY_MS,\n};\n\n// A date and time with no zone, as APIs often send bucket starts (\"2026-10-14 12:00:00\").\nconst ZONELESS = /^\\d{4}-\\d{2}-\\d{2}(?:[ T]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?)?$/;\n\n/** An instant in ms. A string with no zone is read as UTC, not as the viewer's local time. */\nexport const toInstant = (value: TimeInput): number => {\n if (typeof value === 'number') return value;\n if (value instanceof Date) return value.getTime();\n const text = value.trim();\n if (ZONELESS.test(text)) {\n const [date, time = '00:00:00'] = text.split(/[ T]/);\n return Date.parse(`${date}T${time}Z`);\n }\n return Date.parse(text);\n};\n\nconst stepOf = (interval: TimeBarChartInterval) => Math.max(1, Math.floor(interval.step ?? 1));\n\n/** `instant` moved on by `count` buckets. Months move by calendar month, keeping the day. */\nexport const addBuckets = (instant: number, interval: TimeBarChartInterval, count = 1): number => {\n const fixed = FIXED_UNIT_MS[interval.unit];\n if (fixed !== undefined) return instant + fixed * stepOf(interval) * count;\n const date = new Date(instant);\n return Date.UTC(\n date.getUTCFullYear(),\n date.getUTCMonth() + stepOf(interval) * count,\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n );\n};\n\n// The Unix epoch was a Thursday; ISO weeks start on Monday, three days later.\nconst FIRST_MONDAY_MS = 4 * DAY_MS;\n\n/**\n * The start of the bucket holding `instant`. Minute, hour and day buckets count from the epoch,\n * as bucketing APIs do, weeks from a Monday and months from the 1st.\n */\nexport const bucketStart = (instant: number, interval: TimeBarChartInterval): number => {\n const step = stepOf(interval);\n if (interval.unit === 'month') {\n const date = new Date(instant);\n const months = date.getUTCFullYear() * 12 + date.getUTCMonth();\n const first = months - (months % step);\n return Date.UTC(Math.floor(first / 12), first % 12, 1);\n }\n const length = (FIXED_UNIT_MS[interval.unit] ?? DAY_MS) * step;\n const origin = interval.unit === 'week' ? FIRST_MONDAY_MS : 0;\n return Math.floor((instant - origin) / length) * length + origin;\n};\n\n/** Bounded so a range thousands of buckets wide cannot hang the page. */\nexport const MAX_SLOTS = 2000;\n\n/**\n * A slot for every bucket from the one holding `from` to the one holding `to`, empty ones\n * included, so an empty bucket can still be hovered and selected. Past `MAX_SLOTS` the newest\n * are kept, so a live window still ends at \"now\".\n */\nexport const bucketSlots = (\n from: number,\n to: number,\n interval: TimeBarChartInterval,\n): TimeSlot[] => {\n const slots: TimeSlot[] = [];\n const last = bucketStart(to, interval);\n const first = Math.max(bucketStart(from, interval), addBuckets(last, interval, 1 - MAX_SLOTS));\n for (let start = first; start <= last && slots.length < MAX_SLOTS; ) {\n const end = addBuckets(start, interval);\n slots.push({ start, end });\n start = end;\n }\n return slots;\n};\n\n/** The index of the slot whose span holds `instant`, or -1. */\nexport const slotIndexOf = (slots: TimeSlot[], instant: number): number => {\n if (!Number.isFinite(instant)) return -1;\n let low = 0;\n let high = slots.length - 1;\n while (low <= high) {\n const middle = (low + high) >> 1;\n if (instant < slots[middle].start) high = middle - 1;\n else if (instant >= slots[middle].end) low = middle + 1;\n else return middle;\n }\n return -1;\n};\n\nconst MONTHS = [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n];\nconst WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nconst pad = (value: number) => String(value).padStart(2, '0');\n\nconst clock = (date: Date) => `${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}`;\nconst weekday = (date: Date) => `${WEEKDAYS[date.getUTCDay()]} ${date.getUTCDate()}`;\nconst shortDate = (date: Date) => `${MONTHS_SHORT[date.getUTCMonth()]} ${pad(date.getUTCDate())}`;\n\n/** How a bucket is named in the tooltip, e.g. \"Oct 29 14:00\" or \"Oct 29, 2026\". */\nexport const formatBucket = (instant: number, unit: TimeBarChartUnit): string => {\n const date = new Date(instant);\n if (unit === 'month') return `${MONTHS[date.getUTCMonth()]} ${date.getUTCFullYear()}`;\n if (unit === 'day' || unit === 'week') {\n return `${shortDate(date)}, ${date.getUTCFullYear()}`;\n }\n return `${shortDate(date)} ${clock(date)}`;\n};\n\nexport type AxisUnit = 'minute' | 'hour' | 'day' | 'month';\n\n// Below these spans a minute or hour axis is labelled in its own unit; from them, in a coarser\n// one, as 3-hour buckets over 14 days read better against days.\nconst HOUR_AXIS_FROM_MS = 3 * HOUR_MS;\nconst DAY_AXIS_FROM_MS = 72 * HOUR_MS;\nconst MONTH_AXIS_FROM_MS = 92 * DAY_MS;\n\nexport const axisUnitFor = (unit: TimeBarChartUnit, span: number): AxisUnit => {\n if (unit === 'month' || span >= MONTH_AXIS_FROM_MS) return 'month';\n if (unit === 'day' || unit === 'week' || span >= DAY_AXIS_FROM_MS) return 'day';\n if (unit === 'hour' || span >= HOUR_AXIS_FROM_MS) return 'hour';\n return 'minute';\n};\n\n// Steps a label may sit on, smallest first. Minute and hour steps divide a day and day steps\n// start each month on the 1st, so labels stay even and land on the boundaries.\nconst LABEL_STEPS: Record<AxisUnit, number[]> = {\n minute: [1, 5, 10, 15, 30, 60, 120, 180, 360, 720],\n hour: [1, 2, 3, 4, 6, 12, 24],\n day: [1, 2, 3, 7, 14],\n month: [1, 2, 3, 6, 12],\n};\n\nconst isOnStep = (instant: number, unit: AxisUnit, step: number): boolean => {\n const date = new Date(instant);\n if (unit === 'minute') return (date.getUTCHours() * 60 + date.getUTCMinutes()) % step === 0;\n if (unit === 'hour') return date.getUTCHours() % step === 0;\n if (unit === 'month') return date.getUTCMonth() % step === 0;\n // Day 1 is always on the step, so a day too close to the next month's 1st is dropped\n // rather than crowding it.\n const monthLength = daysInMonth({ year: date.getUTCFullYear(), month: date.getUTCMonth() });\n return (date.getUTCDate() - 1) % step === 0 && date.getUTCDate() + step <= monthLength + 1;\n};\n\nconst nextBoundary = (instant: number, unit: AxisUnit): number => {\n if (unit === 'minute') return instant + MINUTE_MS;\n if (unit === 'hour') return instant + HOUR_MS;\n if (unit === 'day') return instant + DAY_MS;\n const date = new Date(instant);\n return Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 1);\n};\n\nconst firstBoundary = (from: number, unit: AxisUnit): number => {\n const start = bucketStart(from, {\n unit: unit === 'month' ? 'month' : unit,\n });\n return start < from ? nextBoundary(start, unit) : start;\n};\n\n/** Roughly the width a label needs, gap included. */\nexport const AXIS_LABEL_WIDTH_PX = 64;\n\nexport interface AxisTick {\n at: number;\n label: string;\n}\n\nconst COARSER_AXIS: Record<AxisUnit, AxisUnit | undefined> = {\n minute: 'hour',\n hour: 'day',\n day: 'month',\n month: undefined,\n};\n\n/**\n * The labelled ticks between `from` and `to`, on the smallest clock- or calendar-aligned step\n * that fits `width`, moving to a coarser unit when no step of this one does. A tick names a\n * boundary it passes instead of its short form: the year on a new year, the month on a new\n * month, the day on a new day.\n */\nexport const axisTicks = (\n from: number,\n to: number,\n unit: TimeBarChartUnit,\n width: number,\n): AxisTick[] => ticksOn(from, to, axisUnitFor(unit, to - from), width);\n\nconst ticksOn = (from: number, to: number, axisUnit: AxisUnit, width: number): AxisTick[] => {\n const boundaries: number[] = [];\n for (\n let at = firstBoundary(from, axisUnit);\n at <= to && boundaries.length < 5000;\n at = nextBoundary(at, axisUnit)\n ) {\n boundaries.push(at);\n }\n const capacity = Math.max(1, Math.floor(width / AXIS_LABEL_WIDTH_PX));\n const steps = LABEL_STEPS[axisUnit];\n const fitting = steps.find((candidate) => boundaries.length / candidate <= capacity);\n const coarser = COARSER_AXIS[axisUnit];\n if (fitting === undefined && coarser) return ticksOn(from, to, coarser, width);\n const step = fitting ?? steps[steps.length - 1];\n const kept = boundaries.filter((at) => isOnStep(at, axisUnit, step));\n return kept.map((at, index) => ({\n at,\n label: tickLabel(at, axisUnit, index === 0 ? at - 1 : kept[index - 1]),\n }));\n};\n\nconst tickLabel = (at: number, unit: AxisUnit, previousAt: number): string => {\n const date = new Date(at);\n const previous = new Date(previousAt);\n if (date.getUTCFullYear() !== previous.getUTCFullYear()) return String(date.getUTCFullYear());\n if (date.getUTCMonth() !== previous.getUTCMonth()) return MONTHS[date.getUTCMonth()];\n if (unit === 'month') return MONTHS_SHORT[date.getUTCMonth()];\n if (date.getUTCDate() !== previous.getUTCDate() || unit === 'day') return weekday(date);\n return clock(date);\n};\n\n/**\n * A y-axis that ends on a round number, with about `count` steps of 1, 2 or 5 times a power of\n * ten, never below 1 since the values are counts.\n */\nexport const valueTicks = (max: number, count = 4): number[] => {\n if (max <= 0) return [0, 1];\n const rough = max / count;\n const magnitude = 10 ** Math.floor(Math.log10(rough));\n const step = Math.max(\n 1,\n [1, 2, 5, 10].map((factor) => factor * magnitude).find((size) => size >= rough) ??\n 10 * magnitude,\n );\n const top = Math.ceil(max / step) * step;\n return Array.from({ length: top / step + 1 }, (_unused, index) => index * step);\n};\n\n// Built per call rather than at module scope: nothing in the library may run at import time.\nexport const formatCompact = (value: number): string =>\n value.toLocaleString('en', { notation: 'compact', maximumFractionDigits: 1 });\nexport const formatCount = (value: number): string => value.toLocaleString('en');\n"],"names":["MINUTE_MS","HOUR_MS","DAY_MS","FIXED_UNIT_MS","ZONELESS","toInstant","value","text","date","time","stepOf","interval","addBuckets","instant","count","fixed","FIRST_MONDAY_MS","bucketStart","step","months","first","length","origin","MAX_SLOTS","bucketSlots","from","to","slots","last","start","end","slotIndexOf","low","high","middle","MONTHS","WEEKDAYS","pad","clock","weekday","shortDate","MONTHS_SHORT","formatBucket","unit","HOUR_AXIS_FROM_MS","DAY_AXIS_FROM_MS","MONTH_AXIS_FROM_MS","axisUnitFor","span","LABEL_STEPS","isOnStep","monthLength","daysInMonth","nextBoundary","firstBoundary","AXIS_LABEL_WIDTH_PX","COARSER_AXIS","axisTicks","width","ticksOn","axisUnit","boundaries","at","capacity","steps","fitting","candidate","coarser","kept","index","tickLabel","previousAt","previous","valueTicks","max","rough","magnitude","factor","size","top","_unused","formatCompact","formatCount"],"mappings":";AAoBA,MAAMA,IAAY,KACZC,IAAU,KAAKD,GACfE,IAAS,KAAKD,GAEdE,IAA2D;AAAA,EAC7D,QAAQH;AAAA,EACR,MAAMC;AAAA,EACN,KAAKC;AAAA,EACL,MAAM,IAAIA;AACd,GAGME,IAAW,gEAGJC,IAAY,CAACC,MAA6B;AACnD,MAAI,OAAOA,KAAU,SAAU,QAAOA;AACtC,MAAIA,aAAiB,KAAM,QAAOA,EAAM,QAAA;AACxC,QAAMC,IAAOD,EAAM,KAAA;AACnB,MAAIF,EAAS,KAAKG,CAAI,GAAG;AACrB,UAAM,CAACC,GAAMC,IAAO,UAAU,IAAIF,EAAK,MAAM,MAAM;AACnD,WAAO,KAAK,MAAM,GAAGC,CAAI,IAAIC,CAAI,GAAG;AAAA,EACxC;AACA,SAAO,KAAK,MAAMF,CAAI;AAC1B,GAEMG,IAAS,CAACC,MAAmC,KAAK,IAAI,GAAG,KAAK,MAAMA,EAAS,QAAQ,CAAC,CAAC,GAGhFC,IAAa,CAACC,GAAiBF,GAAgCG,IAAQ,MAAc;AAC9F,QAAMC,IAAQZ,EAAcQ,EAAS,IAAI;AACzC,MAAII,MAAU,OAAW,QAAOF,IAAUE,IAAQL,EAAOC,CAAQ,IAAIG;AACrE,QAAMN,IAAO,IAAI,KAAKK,CAAO;AAC7B,SAAO,KAAK;AAAA,IACRL,EAAK,eAAA;AAAA,IACLA,EAAK,YAAA,IA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AAKD,CAAU;AACpC,SAAI/D,EAAK,eAAA,MAAqBgE,EAAS,eAAA,IAAyB,OAAOhE,EAAK,gBAAgB,IACxFA,EAAK,YAAA,MAAkBgE,EAAS,YAAA,IAAsBrC,EAAO3B,EAAK,aAAa,IAC/EmC,MAAS,UAAgBF,EAAajC,EAAK,aAAa,IACxDA,EAAK,WAAA,MAAiBgE,EAAS,gBAAgB7B,MAAS,QAAcJ,EAAQ/B,CAAI,IAC/E8B,EAAM9B,CAAI;AACrB,GAMaiE,IAAa,CAACC,GAAa5D,IAAQ,MAAgB;AAC5D,MAAI4D,KAAO,EAAG,QAAO,CAAC,GAAG,CAAC;AAC1B,QAAMC,IAAQD,IAAM5D,GACd8D,IAAY,MAAM,KAAK,MAAM,KAAK,MAAMD,CAAK,CAAC,GAC9CzD,IAAO,KAAK;AAAA,IACd;AAAA,IACA,CAAC,GAAG,GAAG,GAAG,EAAE,EAAE,IAAI,CAAC2D,MAAWA,IAASD,CAAS,EAAE,KAAK,CAACE,MAASA,KAAQH,CAAK,KAC1E,KAAKC;AAAA,EAAA,GAEPG,IAAM,KAAK,KAAKL,IAAMxD,CAAI,IAAIA;AACpC,SAAO,MAAM,KAAK,EAAE,QAAQ6D,IAAM7D,IAAO,EAAA,GAAK,CAAC8D,GAASX,MAAUA,IAAQnD,CAAI;AAClF,GAGa+D,IAAgB,CAAC3E,MAC1BA,EAAM,eAAe,MAAM,EAAE,UAAU,WAAW,uBAAuB,EAAA,CAAG,GACnE4E,IAAc,CAAC5E,MAA0BA,EAAM,eAAe,IAAI;"}
1
+ {"version":3,"file":"timeBuckets.js","sources":["../../../src/components/TimeBarChart/timeBuckets.ts"],"sourcesContent":["import { type DatePickerTimeZone, MONTHS_SHORT, daysInMonth, fromParts, partsOf } from '../dateMath';\n\n// Time arithmetic for TimeBarChart, kept free of a date library so the component adds no\n// dependency. Every instant is milliseconds since the epoch. Buckets and tick positions are UTC,\n// as the data is bucketed; only labels follow a local display zone, so a tick stays on a bar.\n\nexport type TimeBarChartUnit = 'minute' | 'hour' | 'day' | 'week' | 'month';\n\nexport interface TimeBarChartInterval {\n unit: TimeBarChartUnit;\n /** How many `unit`s one bucket spans, e.g. 3 with `hour` for 3-hour buckets. Default 1. */\n step?: number;\n}\n\nexport type TimeInput = string | number | Date;\n\nexport interface TimeSlot {\n start: number;\n end: number;\n}\n\nconst MINUTE_MS = 60_000;\nconst HOUR_MS = 60 * MINUTE_MS;\nconst DAY_MS = 24 * HOUR_MS;\n\nconst FIXED_UNIT_MS: Partial<Record<TimeBarChartUnit, number>> = {\n minute: MINUTE_MS,\n hour: HOUR_MS,\n day: DAY_MS,\n week: 7 * DAY_MS,\n};\n\n// A date and time with no zone, as APIs often send bucket starts (\"2026-10-14 12:00:00\").\nconst ZONELESS = /^\\d{4}-\\d{2}-\\d{2}(?:[ T]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?)?$/;\n\n/** An instant in ms. A string with no zone is read as UTC, not as the viewer's local time. */\nexport const toInstant = (value: TimeInput): number => {\n if (typeof value === 'number') return value;\n if (value instanceof Date) return value.getTime();\n const text = value.trim();\n if (ZONELESS.test(text)) {\n const [date, time = '00:00:00'] = text.split(/[ T]/);\n return Date.parse(`${date}T${time}Z`);\n }\n return Date.parse(text);\n};\n\nconst stepOf = (interval: TimeBarChartInterval) => Math.max(1, Math.floor(interval.step ?? 1));\n\n/** `instant` moved on by `count` buckets. Months move by calendar month, keeping the day. */\nexport const addBuckets = (instant: number, interval: TimeBarChartInterval, count = 1): number => {\n const fixed = FIXED_UNIT_MS[interval.unit];\n if (fixed !== undefined) return instant + fixed * stepOf(interval) * count;\n const date = new Date(instant);\n return Date.UTC(\n date.getUTCFullYear(),\n date.getUTCMonth() + stepOf(interval) * count,\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n );\n};\n\n// The Unix epoch was a Thursday; ISO weeks start on Monday, three days later.\nconst FIRST_MONDAY_MS = 4 * DAY_MS;\n\n/**\n * The start of the bucket holding `instant`. Minute, hour and day buckets count from the epoch,\n * as bucketing APIs do, weeks from a Monday and months from the 1st.\n */\nexport const bucketStart = (instant: number, interval: TimeBarChartInterval): number => {\n const step = stepOf(interval);\n if (interval.unit === 'month') {\n const date = new Date(instant);\n const months = date.getUTCFullYear() * 12 + date.getUTCMonth();\n const first = months - (months % step);\n return Date.UTC(Math.floor(first / 12), first % 12, 1);\n }\n const length = (FIXED_UNIT_MS[interval.unit] ?? DAY_MS) * step;\n const origin = interval.unit === 'week' ? FIRST_MONDAY_MS : 0;\n return Math.floor((instant - origin) / length) * length + origin;\n};\n\n/** Bounded so a range thousands of buckets wide cannot hang the page. */\nexport const MAX_SLOTS = 2000;\n\n/**\n * A slot for every bucket from the one holding `from` to the one holding `to`, empty ones\n * included, so an empty bucket can still be hovered and selected. Past `MAX_SLOTS` the newest\n * are kept, so a live window still ends at \"now\".\n */\nexport const bucketSlots = (\n from: number,\n to: number,\n interval: TimeBarChartInterval,\n): TimeSlot[] => {\n const slots: TimeSlot[] = [];\n const last = bucketStart(to, interval);\n const first = Math.max(bucketStart(from, interval), addBuckets(last, interval, 1 - MAX_SLOTS));\n for (let start = first; start <= last && slots.length < MAX_SLOTS; ) {\n const end = addBuckets(start, interval);\n slots.push({ start, end });\n start = end;\n }\n return slots;\n};\n\n/** The index of the slot whose span holds `instant`, or -1. */\nexport const slotIndexOf = (slots: TimeSlot[], instant: number): number => {\n if (!Number.isFinite(instant)) return -1;\n let low = 0;\n let high = slots.length - 1;\n while (low <= high) {\n const middle = (low + high) >> 1;\n if (instant < slots[middle].start) high = middle - 1;\n else if (instant >= slots[middle].end) low = middle + 1;\n else return middle;\n }\n return -1;\n};\n\nconst MONTHS = [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n];\nconst WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nconst pad = (value: number) => String(value).padStart(2, '0');\n\nconst clock = (date: Date) => `${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}`;\nconst weekday = (date: Date) => `${WEEKDAYS[date.getUTCDay()]} ${date.getUTCDate()}`;\nconst shortDate = (date: Date) => `${MONTHS_SHORT[date.getUTCMonth()]} ${pad(date.getUTCDate())}`;\n\nexport type TimeBarChartTimeZone = DatePickerTimeZone;\n\n/** A date whose UTC fields read as the wall clock of `timeZone` at `instant`. */\nconst displayDate = (instant: number, timeZone: TimeBarChartTimeZone): Date =>\n fromParts(partsOf(new Date(instant), timeZone), 'utc');\n\nconst zoneSuffix = (instant: number, timeZone: TimeBarChartTimeZone): string => {\n if (timeZone === 'utc') return '';\n const offset = Math.round((displayDate(instant, 'local').getTime() - instant) / MINUTE_MS);\n return ` UTC${offset < 0 ? '-' : '+'}${pad(Math.floor(Math.abs(offset) / 60))}:${pad(Math.abs(offset) % 60)}`;\n};\n\n/** Formats a bucket in the requested zone; its instant and bucket boundaries remain UTC. */\nexport const formatBucket = (\n instant: number,\n unit: TimeBarChartUnit,\n timeZone: TimeBarChartTimeZone = 'utc',\n): string => {\n const date = displayDate(instant, timeZone);\n const suffix = zoneSuffix(instant, timeZone);\n if (unit === 'minute' || unit === 'hour') return `${shortDate(date)} ${clock(date)}${suffix}`;\n // A UTC-aligned bucket shown in a non-UTC zone starts mid-day, so its date alone misnames it.\n if (date.getUTCHours() || date.getUTCMinutes()) {\n return `${shortDate(date)}, ${date.getUTCFullYear()} ${clock(date)}${suffix}`;\n }\n if (unit === 'month') return `${MONTHS[date.getUTCMonth()]} ${date.getUTCFullYear()}${suffix}`;\n return `${shortDate(date)}, ${date.getUTCFullYear()}${suffix}`;\n};\n\nexport type AxisUnit = 'minute' | 'hour' | 'day' | 'month';\n\n// Below these spans a minute or hour axis is labelled in its own unit; from them, in a coarser\n// one, as 3-hour buckets over 14 days read better against days.\nconst HOUR_AXIS_FROM_MS = 3 * HOUR_MS;\nconst DAY_AXIS_FROM_MS = 72 * HOUR_MS;\nconst MONTH_AXIS_FROM_MS = 92 * DAY_MS;\n\nexport const axisUnitFor = (unit: TimeBarChartUnit, span: number): AxisUnit => {\n if (unit === 'month' || span >= MONTH_AXIS_FROM_MS) return 'month';\n if (unit === 'day' || unit === 'week' || span >= DAY_AXIS_FROM_MS) return 'day';\n if (unit === 'hour' || span >= HOUR_AXIS_FROM_MS) return 'hour';\n return 'minute';\n};\n\n// Steps a label may sit on, smallest first. Minute and hour steps divide a day and day steps\n// start each month on the 1st, so labels stay even and land on the boundaries.\nconst LABEL_STEPS: Record<AxisUnit, number[]> = {\n minute: [1, 5, 10, 15, 30, 60, 120, 180, 360, 720],\n hour: [1, 2, 3, 4, 6, 12, 24],\n day: [1, 2, 3, 7, 14],\n month: [1, 2, 3, 6, 12],\n};\n\nconst isOnStep = (instant: number, unit: AxisUnit, step: number): boolean => {\n const date = new Date(instant);\n if (unit === 'minute') return (date.getUTCHours() * 60 + date.getUTCMinutes()) % step === 0;\n if (unit === 'hour') return date.getUTCHours() % step === 0;\n if (unit === 'month') return date.getUTCMonth() % step === 0;\n // Day 1 is always on the step, so a day too close to the next month's 1st is dropped\n // rather than crowding it.\n const monthLength = daysInMonth({ year: date.getUTCFullYear(), month: date.getUTCMonth() });\n return (date.getUTCDate() - 1) % step === 0 && date.getUTCDate() + step <= monthLength + 1;\n};\n\nconst nextBoundary = (instant: number, unit: AxisUnit): number => {\n if (unit === 'minute') return instant + MINUTE_MS;\n if (unit === 'hour') return instant + HOUR_MS;\n if (unit === 'day') return instant + DAY_MS;\n const date = new Date(instant);\n return Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 1);\n};\n\nconst firstBoundary = (from: number, unit: AxisUnit): number => {\n const start = bucketStart(from, {\n unit: unit === 'month' ? 'month' : unit,\n });\n return start < from ? nextBoundary(start, unit) : start;\n};\n\n/** Roughly the width a label needs, gap included. */\nexport const AXIS_LABEL_WIDTH_PX = 64;\n\nexport interface AxisTick {\n at: number;\n label: string;\n}\n\nconst COARSER_AXIS: Record<AxisUnit, AxisUnit | undefined> = {\n minute: 'hour',\n hour: 'day',\n day: 'month',\n month: undefined,\n};\n\n/**\n * The labelled ticks between `from` and `to`, on the smallest clock- or calendar-aligned step\n * that fits `width`, moving to a coarser unit when no step of this one does. A tick names a\n * boundary it passes instead of its short form: the year on a new year, the month on a new\n * month, the day on a new day.\n */\nexport const axisTicks = (\n from: number,\n to: number,\n unit: TimeBarChartUnit,\n width: number,\n timeZone: TimeBarChartTimeZone = 'utc',\n): AxisTick[] => ticksOn(from, to, axisUnitFor(unit, to - from), width, timeZone);\n\nconst ticksOn = (\n from: number,\n to: number,\n axisUnit: AxisUnit,\n width: number,\n timeZone: TimeBarChartTimeZone,\n): AxisTick[] => {\n const boundaries: number[] = [];\n for (\n let at = firstBoundary(from, axisUnit);\n at <= to && boundaries.length < 5000;\n at = nextBoundary(at, axisUnit)\n ) {\n boundaries.push(at);\n }\n const capacity = Math.max(1, Math.floor(width / AXIS_LABEL_WIDTH_PX));\n const steps = LABEL_STEPS[axisUnit];\n const fitting = steps.find((candidate) => boundaries.length / candidate <= capacity);\n const coarser = COARSER_AXIS[axisUnit];\n if (fitting === undefined && coarser) return ticksOn(from, to, coarser, width, timeZone);\n const step = fitting ?? steps[steps.length - 1];\n const kept = boundaries.filter((at) => isOnStep(at, axisUnit, step));\n return kept.map((at, index) => ({\n at,\n label: tickLabel(at, axisUnit, index === 0 ? at - 1 : kept[index - 1], timeZone),\n }));\n};\n\nconst tickLabel = (\n at: number,\n unit: AxisUnit,\n previousAt: number,\n timeZone: TimeBarChartTimeZone,\n): string => {\n const date = displayDate(at, timeZone);\n const previous = displayDate(previousAt, timeZone);\n if (date.getUTCFullYear() !== previous.getUTCFullYear()) return String(date.getUTCFullYear());\n if (date.getUTCMonth() !== previous.getUTCMonth()) return MONTHS[date.getUTCMonth()];\n if (unit === 'month') return MONTHS_SHORT[date.getUTCMonth()];\n if (date.getUTCDate() !== previous.getUTCDate() || unit === 'day') return weekday(date);\n return clock(date);\n};\n\n/**\n * A y-axis that ends on a round number, with about `count` steps of 1, 2 or 5 times a power of\n * ten, never below 1 since the values are counts.\n */\nexport const valueTicks = (max: number, count = 4): number[] => {\n if (max <= 0) return [0, 1];\n const rough = max / count;\n const magnitude = 10 ** Math.floor(Math.log10(rough));\n const step = Math.max(\n 1,\n [1, 2, 5, 10].map((factor) => factor * magnitude).find((size) => size >= rough) ??\n 10 * magnitude,\n );\n const top = Math.ceil(max / step) * step;\n return Array.from({ length: top / step + 1 }, (_unused, index) => index * step);\n};\n\n// Built per call rather than at module scope: nothing in the library may run at import time.\nexport const formatCompact = (value: number): string =>\n value.toLocaleString('en', { notation: 'compact', maximumFractionDigits: 1 });\nexport const formatCount = (value: number): string => value.toLocaleString('en');\n"],"names":["MINUTE_MS","HOUR_MS","DAY_MS","FIXED_UNIT_MS","ZONELESS","toInstant","value","text","date","time","stepOf","interval","addBuckets","instant","count","fixed","FIRST_MONDAY_MS","bucketStart","step","months","first","length","origin","MAX_SLOTS","bucketSlots","from","to","slots","last","start","end","slotIndexOf","low","high","middle","MONTHS","WEEKDAYS","pad","clock","weekday","shortDate","MONTHS_SHORT","displayDate","timeZone","fromParts","partsOf","zoneSuffix","offset","formatBucket","unit","suffix","HOUR_AXIS_FROM_MS","DAY_AXIS_FROM_MS","MONTH_AXIS_FROM_MS","axisUnitFor","span","LABEL_STEPS","isOnStep","monthLength","daysInMonth","nextBoundary","firstBoundary","AXIS_LABEL_WIDTH_PX","COARSER_AXIS","axisTicks","width","ticksOn","axisUnit","boundaries","at","capacity","steps","fitting","candidate","coarser","kept","index","tickLabel","previousAt","previous","valueTicks","max","rough","magnitude","factor","size","top","_unused","formatCompact","formatCount"],"mappings":";AAqBA,MAAMA,IAAY,KACZC,IAAU,KAAKD,GACfE,IAAS,KAAKD,GAEdE,IAA2D;AAAA,EAC7D,QAAQH;AAAA,EACR,MAAMC;AAAA,EACN,KAAKC;AAAA,EACL,MAAM,IAAIA;AACd,GAGME,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State as v, useRef as m, useCallback as K, useId as ut, useEffect as w, useInsertionEffect as mt } from "react";
3
- import { createPortal as pt } from "react-dom";
4
- import { FOCUS_RING as ht } from "./focusRing.js";
5
- import { ensureOverlayStyles as gt, overlayIdentity as bt } from "./portalOverlay.js";
6
- import { useTopLayer as yt } from "./topLayer.js";
7
- import { useFollowTrigger as vt } from "./useFollowTrigger.js";
8
- const wt = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), xt = (o) => o.split(wt).map((s, R) => /* @__PURE__ */ D(B.Fragment, { children: [
1
+ import { jsx as p, jsxs as J, Fragment as ut } from "react/jsx-runtime";
2
+ import B, { useState as v, useRef as m, useCallback as X, useId as mt, useEffect as w, useInsertionEffect as pt } from "react";
3
+ import { createPortal as ht } from "react-dom";
4
+ import { FOCUS_RING as gt } from "./focusRing.js";
5
+ import { ensureOverlayStyles as bt, overlayIdentity as yt } from "./portalOverlay.js";
6
+ import { useTopLayer as vt } from "./topLayer.js";
7
+ import { useFollowTrigger as wt } from "./useFollowTrigger.js";
8
+ const xt = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), Tt = (o) => o.split(xt).map((s, T) => /* @__PURE__ */ J(B.Fragment, { children: [
9
9
  s,
10
10
  /* @__PURE__ */ p("wbr", {})
11
- ] }, R)), Rt = {
11
+ ] }, T)), Rt = {
12
12
  minWidth: 0,
13
13
  overflow: "hidden"
14
- }, X = {
14
+ }, D = {
15
15
  flex: 1,
16
16
  minWidth: 0
17
- }, x = 8, It = '"Inter", ui-sans-serif, system-ui, sans-serif', Mt = ({
17
+ }, x = 8, It = '"Inter", ui-sans-serif, system-ui, sans-serif', Ot = ({
18
18
  text: o,
19
19
  children: s,
20
- delay: R = 0.2,
21
- wrapChildren: J = !1,
22
- triggerAs: Q = "div",
20
+ delay: T = 0.2,
21
+ wrapChildren: Q = !1,
22
+ triggerAs: Z = "div",
23
23
  inline: M = !1,
24
- placement: I = "top",
25
- isShrinkable: W = !1,
26
- maxWidth: E = "320px",
24
+ placement: R = "top",
25
+ isShrinkable: O = !1,
26
+ maxWidth: I = "320px",
27
27
  fill: S = !1,
28
28
  shouldShow: h,
29
- suppressed: i = !1,
30
- describesTrigger: $ = !0,
29
+ suppressed: r = !1,
30
+ describesTrigger: W = !0,
31
31
  showOnFocus: f = !0,
32
32
  focusableTrigger: g = !1
33
33
  }) => {
34
- const Z = W || S ? { ...W ? Rt : {}, ...S ? X : {} } : void 0, [e, d] = v(!1), [tt, et] = v(!1), b = tt || g, y = m(null), a = m(null), n = K(() => {
34
+ const tt = O || S ? { ...O ? Rt : {}, ...S ? D : {} } : void 0, [e, d] = v(!1), [et, nt] = v(!1), b = et || g, y = m(null), a = m(null), n = X(() => {
35
35
  y.current && (clearTimeout(y.current), y.current = null), a.current !== null && (cancelAnimationFrame(a.current), a.current = null);
36
- }, []), P = () => {
37
- et(!0), a.current !== null && cancelAnimationFrame(a.current), a.current = requestAnimationFrame(() => {
36
+ }, []), $ = () => {
37
+ nt(!0), a.current !== null && cancelAnimationFrame(a.current), a.current = requestAnimationFrame(() => {
38
38
  a.current = null, d(!0);
39
39
  });
40
- }, L = m(null), u = m(null);
41
- yt(L, e);
42
- const C = ut(), l = o != null && o !== "" && o !== !1, nt = (t) => {
43
- t.stopPropagation(), !(!l || i || h && !h()) && (n(), y.current = setTimeout(() => {
44
- P();
45
- }, R * 1e3));
46
- }, ot = (t) => {
47
- t.stopPropagation(), n(), d(!1);
40
+ }, E = m(null), u = m(null);
41
+ vt(E, e);
42
+ const C = mt(), l = o != null && o !== "" && o !== !1, N = (t) => !(t.relatedTarget instanceof Node && t.currentTarget.contains(t.relatedTarget)), ot = (t) => {
43
+ !N(t) || !l || r || h && !h() || (n(), y.current = setTimeout(() => {
44
+ $();
45
+ }, T * 1e3));
46
+ }, rt = (t) => {
47
+ N(t) && (n(), d(!1));
48
48
  }, H = () => {
49
- !f || !l || i || h && !h() || (n(), P());
49
+ !f || !l || r || h && !h() || (n(), $());
50
50
  }, it = () => {
51
51
  n(), d(!1);
52
- }, N = m(f);
52
+ }, P = m(f);
53
53
  w(() => {
54
- var r;
55
- const t = f && !N.current;
56
- N.current = f, t && ((r = u.current) != null && r.matches(":focus-within")) && H();
54
+ var i;
55
+ const t = f && !P.current;
56
+ P.current = f, t && ((i = u.current) != null && i.matches(":focus-within")) && H();
57
57
  });
58
- const [rt, st] = v(i);
59
- i !== rt && (st(i), i && d(!1)), w(() => {
60
- i && n();
61
- }, [i, n]);
62
- const [, T] = v({}), at = K(() => {
58
+ const [st, at] = v(r);
59
+ r !== st && (at(r), r && d(!1)), w(() => {
60
+ r && n();
61
+ }, [r, n]);
62
+ const [, F] = v({}), lt = X(() => {
63
63
  n(), d(!1);
64
64
  }, [n]);
65
- vt(e, u, () => T({}), at), w(() => {
65
+ wt(e, u, () => F({}), lt), w(() => {
66
66
  if (!e)
67
67
  return () => {
68
68
  n();
69
69
  };
70
70
  const t = () => {
71
- T({});
71
+ F({});
72
72
  };
73
73
  return window.addEventListener("resize", t), () => {
74
74
  n(), window.removeEventListener("resize", t);
75
75
  };
76
76
  }, [e, n]), w(() => {
77
- e && T({});
77
+ e && F({});
78
78
  }, [e]);
79
- const lt = () => {
80
- var z;
79
+ const ct = () => {
80
+ var U;
81
81
  if (!u.current)
82
82
  return { display: "none" };
83
- const t = u.current.getBoundingClientRect(), r = {
83
+ const t = u.current.getBoundingClientRect(), i = {
84
84
  position: "fixed",
85
85
  display: "flex",
86
86
  width: "max-content",
87
- maxWidth: typeof E == "number" ? `${E}px` : E,
87
+ maxWidth: typeof I == "number" ? `${I}px` : I,
88
88
  minWidth: "32px",
89
89
  minHeight: "32px",
90
90
  padding: "8px 12px",
@@ -103,83 +103,83 @@ const wt = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), xt = (o) => o.split(wt).map((s
103
103
  opacity: e ? 1 : 0,
104
104
  visibility: e ? "visible" : "hidden",
105
105
  transition: "opacity 150ms ease-in-out, transform 150ms ease-in-out, visibility 150ms ease-in-out"
106
- }, c = (z = L.current) == null ? void 0 : z.getBoundingClientRect(), V = (c == null ? void 0 : c.width) ?? 0, Y = (c == null ? void 0 : c.height) ?? 0, A = () => {
106
+ }, c = (U = E.current) == null ? void 0 : U.getBoundingClientRect(), Y = (c == null ? void 0 : c.width) ?? 0, j = (c == null ? void 0 : c.height) ?? 0, A = () => {
107
107
  const _ = t.left + t.width / 2;
108
- if (V === 0)
108
+ if (Y === 0)
109
109
  return _;
110
- const U = V / 2, G = x + U, q = window.innerWidth - x - U;
111
- return G > q ? _ : Math.min(Math.max(_, G), q);
112
- }, j = t.top - 8 - Y >= x, k = t.bottom + 8 + Y <= window.innerHeight - x;
113
- switch (I === "top" && !j && k ? "bottom" : I === "bottom" && !k && j ? "top" : I) {
110
+ const G = Y / 2, q = x + G, K = window.innerWidth - x - G;
111
+ return q > K ? _ : Math.min(Math.max(_, q), K);
112
+ }, k = t.top - 8 - j >= x, z = t.bottom + 8 + j <= window.innerHeight - x;
113
+ switch (R === "top" && !k && z ? "bottom" : R === "bottom" && !z && k ? "top" : R) {
114
114
  case "top":
115
115
  return {
116
- ...r,
116
+ ...i,
117
117
  top: t.top - 8,
118
118
  left: A(),
119
119
  transform: `translate(-50%, -100%) ${e ? "scale(1)" : "scale(0.95)"}`
120
120
  };
121
121
  case "bottom":
122
122
  return {
123
- ...r,
123
+ ...i,
124
124
  top: t.bottom + 8,
125
125
  left: A(),
126
126
  transform: `translateX(-50%) ${e ? "scale(1)" : "scale(0.95)"}`
127
127
  };
128
128
  case "left":
129
129
  return {
130
- ...r,
130
+ ...i,
131
131
  top: t.top + t.height / 2,
132
132
  left: t.left - 8,
133
133
  transform: `translate(-100%, -50%) ${e ? "scale(1)" : "scale(0.95)"}`
134
134
  };
135
135
  case "right":
136
136
  return {
137
- ...r,
137
+ ...i,
138
138
  top: t.top + t.height / 2,
139
139
  left: t.right + 8,
140
140
  transform: `translateY(-50%) ${e ? "scale(1)" : "scale(0.95)"}`
141
141
  };
142
142
  default:
143
143
  return {
144
- ...r,
144
+ ...i,
145
145
  top: t.top - 8,
146
146
  left: A(),
147
147
  transform: `translate(-50%, -100%) ${e ? "scale(1)" : "scale(0.95)"}`
148
148
  };
149
149
  }
150
- }, F = l && b && $ ? C : void 0;
151
- mt(() => {
152
- l && b && gt();
150
+ }, L = l && b && W ? C : void 0;
151
+ pt(() => {
152
+ l && b && bt();
153
153
  }, [l, b]);
154
- const ct = g ? s : J || !B.isValidElement(s) ? /* @__PURE__ */ p("span", { "aria-describedby": F, style: S ? X : void 0, children: s }) : B.cloneElement(s, {
155
- "aria-describedby": [s.props["aria-describedby"], F].filter(Boolean).join(" ") || void 0
156
- }), ft = M ? "span" : Q, O = g && l && !i && f;
157
- return /* @__PURE__ */ D(dt, { children: [
154
+ const ft = g ? s : Q || !B.isValidElement(s) ? /* @__PURE__ */ p("span", { "aria-describedby": L, style: S ? D : void 0, children: s }) : B.cloneElement(s, {
155
+ "aria-describedby": [s.props["aria-describedby"], L].filter(Boolean).join(" ") || void 0
156
+ }), dt = M ? "span" : Z, V = g && l && !r && f;
157
+ return /* @__PURE__ */ J(ut, { children: [
158
158
  /* @__PURE__ */ p(
159
- ft,
159
+ dt,
160
160
  {
161
161
  ref: u,
162
- className: `relative ${M ? "inline-flex max-w-full align-middle" : "flex"} items-center${O ? ` ${ht}` : ""}`,
163
- style: Z,
164
- tabIndex: O ? 0 : void 0,
165
- "aria-describedby": g ? F : void 0,
166
- onMouseEnter: nt,
167
- onMouseLeave: ot,
162
+ className: `relative ${M ? "inline-flex max-w-full align-middle" : "flex"} items-center${V ? ` ${gt}` : ""}`,
163
+ style: tt,
164
+ tabIndex: V ? 0 : void 0,
165
+ "aria-describedby": g ? L : void 0,
166
+ onMouseOver: ot,
167
+ onMouseOut: rt,
168
168
  onFocus: H,
169
169
  onBlur: it,
170
- children: ct
170
+ children: ft
171
171
  }
172
172
  ),
173
- l && b && pt(
173
+ l && b && ht(
174
174
  /* @__PURE__ */ p(
175
175
  "div",
176
176
  {
177
- ref: L,
177
+ ref: E,
178
178
  id: C,
179
179
  role: "tooltip",
180
- "aria-hidden": $ ? void 0 : !0,
181
- ...bt("tooltip"),
182
- style: lt(),
180
+ "aria-hidden": W ? void 0 : !0,
181
+ ...yt("tooltip"),
182
+ style: ct(),
183
183
  children: /* @__PURE__ */ p(
184
184
  "span",
185
185
  {
@@ -187,7 +187,7 @@ const wt = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), xt = (o) => o.split(wt).map((s
187
187
  minWidth: 0,
188
188
  overflowWrap: "anywhere"
189
189
  },
190
- children: typeof o == "string" ? xt(o) : o
190
+ children: typeof o == "string" ? Tt(o) : o
191
191
  }
192
192
  )
193
193
  }
@@ -197,6 +197,6 @@ const wt = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), xt = (o) => o.split(wt).map((s
197
197
  ] });
198
198
  };
199
199
  export {
200
- Mt as default
200
+ Ot as default
201
201
  };
202
202
  //# sourceMappingURL=Tooltip.js.map