@momoi-labs/kiso-react 0.22.1 → 0.23.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.
- package/dist/chart.d.ts +6 -2
- package/dist/chart.js +17 -3
- package/dist/code-block.d.ts +21 -0
- package/dist/code-block.js +148 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/scope-switcher.d.ts +49 -0
- package/dist/scope-switcher.js +297 -0
- package/dist/time-range-calendar.d.ts +12 -0
- package/dist/time-range-calendar.js +102 -0
- package/dist/time-range-control.d.ts +28 -12
- package/dist/time-range-control.js +41 -22
- package/dist/time-range-live.d.ts +18 -0
- package/dist/time-range-live.js +305 -0
- package/dist/time-range-shared.d.ts +91 -0
- package/dist/time-range-shared.js +87 -0
- package/dist/time-range-text.d.ts +13 -0
- package/dist/time-range-text.js +44 -0
- package/dist/time-zone.d.ts +15 -0
- package/dist/time-zone.js +121 -0
- package/package.json +2 -2
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export type TimeRange = {
|
|
2
|
+
from: number;
|
|
3
|
+
to: number;
|
|
4
|
+
};
|
|
5
|
+
/** A live value: relative follows the wall clock, absolute is paused. */
|
|
6
|
+
export type LiveTimeRange = {
|
|
7
|
+
kind: "relative";
|
|
8
|
+
duration: number;
|
|
9
|
+
} | {
|
|
10
|
+
kind: "absolute";
|
|
11
|
+
from: number;
|
|
12
|
+
to: number;
|
|
13
|
+
};
|
|
14
|
+
export type TimeRangePreset = {
|
|
15
|
+
label: string;
|
|
16
|
+
duration: number;
|
|
17
|
+
};
|
|
18
|
+
export type TimeRangeUnit = "second" | "minute" | "hour" | "day";
|
|
19
|
+
export type TimeRangeState = "live" | "paused";
|
|
20
|
+
export declare const defaultLabels: {
|
|
21
|
+
entireRun: string;
|
|
22
|
+
custom: string;
|
|
23
|
+
backToPresets: string;
|
|
24
|
+
backToLive: string;
|
|
25
|
+
apply: string;
|
|
26
|
+
from: (zone: string) => string;
|
|
27
|
+
to: (zone: string) => string;
|
|
28
|
+
error: string;
|
|
29
|
+
presets: string;
|
|
30
|
+
live: string;
|
|
31
|
+
paused: string;
|
|
32
|
+
pause: string;
|
|
33
|
+
resume: string;
|
|
34
|
+
reset: string;
|
|
35
|
+
relative: (count: number, unit: TimeRangeUnit) => string;
|
|
36
|
+
duration: (count: number, unit: TimeRangeUnit) => string;
|
|
37
|
+
/** Visible range text: short times and the zone name. */
|
|
38
|
+
range: (from: string, to: string, zone: string) => string;
|
|
39
|
+
/** Full timestamps for the tooltip and the accessible name. */
|
|
40
|
+
fullRange: (from: string, to: string) => string;
|
|
41
|
+
triggerName: ({ label, state, text, range }: {
|
|
42
|
+
label: string;
|
|
43
|
+
state: string;
|
|
44
|
+
text: string;
|
|
45
|
+
range: string;
|
|
46
|
+
}) => string;
|
|
47
|
+
now: string;
|
|
48
|
+
keeps: (duration: string) => string;
|
|
49
|
+
olderThanRetention: string;
|
|
50
|
+
releaseToLive: (text: string) => string;
|
|
51
|
+
fieldHint: string;
|
|
52
|
+
resolvedHint: (time: string, followsClock: boolean) => string;
|
|
53
|
+
invalidStart: string;
|
|
54
|
+
invalidEnd: string;
|
|
55
|
+
order: string;
|
|
56
|
+
retention: string;
|
|
57
|
+
future: string;
|
|
58
|
+
moveRange: string;
|
|
59
|
+
rangeStart: string;
|
|
60
|
+
rangeEnd: string;
|
|
61
|
+
chooseStartDate: string;
|
|
62
|
+
chooseEndDate: string;
|
|
63
|
+
previousMonth: string;
|
|
64
|
+
nextMonth: string;
|
|
65
|
+
outsideRetention: string;
|
|
66
|
+
timeZone: string;
|
|
67
|
+
timeZoneButton: (zone: string) => string;
|
|
68
|
+
browserTimeZone: (zone: string) => string;
|
|
69
|
+
utc: string;
|
|
70
|
+
searchTimeZones: string;
|
|
71
|
+
noTimeZones: string;
|
|
72
|
+
unavailable: string;
|
|
73
|
+
};
|
|
74
|
+
export type TimeRangeControlLabels = typeof defaultLabels;
|
|
75
|
+
export declare const defaultPresets: {
|
|
76
|
+
label: string;
|
|
77
|
+
duration: number;
|
|
78
|
+
}[];
|
|
79
|
+
export declare const validRange: (range: TimeRange) => boolean;
|
|
80
|
+
export declare const units: [TimeRangeUnit, number][];
|
|
81
|
+
export declare const positive: (value: number) => boolean;
|
|
82
|
+
export declare const ceilSecond: (value: number) => number;
|
|
83
|
+
export declare const floorSecond: (value: number) => number;
|
|
84
|
+
export declare function documentLocale(): string | undefined;
|
|
85
|
+
export declare function validLocale(locale: string | undefined): string | undefined;
|
|
86
|
+
/** A duration in the largest unit that divides it, through a label template. */
|
|
87
|
+
export declare function durationText(duration: number, template: (count: number, unit: TimeRangeUnit) => string): string;
|
|
88
|
+
/** The smallest span a drag or slider keeps: one second, or all of a shorter retention. */
|
|
89
|
+
export declare const minimumSpan: (maxDuration: number) => number;
|
|
90
|
+
/** A drag released at now: the minute when it fits retention, else the second. */
|
|
91
|
+
export declare function snapDuration(span: number, maxDuration: number): number;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { validInstant } from "./time-zone.js";
|
|
2
|
+
export const defaultLabels = {
|
|
3
|
+
entireRun: "Entire run",
|
|
4
|
+
custom: "Custom range",
|
|
5
|
+
backToPresets: "Back to presets",
|
|
6
|
+
backToLive: "Back to live",
|
|
7
|
+
apply: "Apply range",
|
|
8
|
+
from: (zone) => `From (${zone})`,
|
|
9
|
+
to: (zone) => `To (${zone})`,
|
|
10
|
+
error: "Choose a start before the end, within the collection window.",
|
|
11
|
+
presets: "Presets",
|
|
12
|
+
live: "Live",
|
|
13
|
+
paused: "Paused",
|
|
14
|
+
pause: "Pause",
|
|
15
|
+
resume: "Resume live",
|
|
16
|
+
reset: "Reset",
|
|
17
|
+
relative: (count, unit) => `Last ${count} ${unit}${count === 1 ? "" : "s"}`,
|
|
18
|
+
duration: (count, unit) => `${count} ${unit}${count === 1 ? "" : "s"}`,
|
|
19
|
+
/** Visible range text: short times and the zone name. */
|
|
20
|
+
range: (from, to, zone) => `${from} to ${to} ${zone}`,
|
|
21
|
+
/** Full timestamps for the tooltip and the accessible name. */
|
|
22
|
+
fullRange: (from, to) => `${from} to ${to}`,
|
|
23
|
+
triggerName: ({ label, state, text, range }) => `${label}, ${state}: ${text}, ${range}`,
|
|
24
|
+
now: "now",
|
|
25
|
+
keeps: (duration) => `Keeps ${duration}.`,
|
|
26
|
+
olderThanRetention: "This range is older than the data kept.",
|
|
27
|
+
releaseToLive: (text) => `Release to follow the clock: ${text}.`,
|
|
28
|
+
fieldHint: "Use now-15m, a time like 16:37, or 2026-10-28 16:37:05.",
|
|
29
|
+
resolvedHint: (time, followsClock) => followsClock ? `${time}, follows the clock` : time,
|
|
30
|
+
invalidStart: "Enter a start like now-15m, 16:37, or 2026-10-28 16:37:05.",
|
|
31
|
+
invalidEnd: "Enter an end like now, 16:37, or 2026-10-28 16:37:05.",
|
|
32
|
+
order: "The start must be before the end.",
|
|
33
|
+
retention: "The start must be within the data kept.",
|
|
34
|
+
future: "The end cannot be in the future.",
|
|
35
|
+
moveRange: "Move range",
|
|
36
|
+
rangeStart: "Range start",
|
|
37
|
+
rangeEnd: "Range end",
|
|
38
|
+
chooseStartDate: "Choose start date",
|
|
39
|
+
chooseEndDate: "Choose end date",
|
|
40
|
+
previousMonth: "Previous month",
|
|
41
|
+
nextMonth: "Next month",
|
|
42
|
+
outsideRetention: "outside the data kept",
|
|
43
|
+
timeZone: "Time zone",
|
|
44
|
+
timeZoneButton: (zone) => `Time zone: ${zone}`,
|
|
45
|
+
browserTimeZone: (zone) => `Browser time zone (${zone})`,
|
|
46
|
+
utc: "UTC",
|
|
47
|
+
searchTimeZones: "Search time zones",
|
|
48
|
+
noTimeZones: "No matching time zones.",
|
|
49
|
+
unavailable: "Time unavailable",
|
|
50
|
+
};
|
|
51
|
+
export const defaultPresets = [
|
|
52
|
+
{ label: "Last 5 minutes", duration: 300_000 },
|
|
53
|
+
{ label: "Last 15 minutes", duration: 900_000 },
|
|
54
|
+
{ label: "Last 30 minutes", duration: 1_800_000 },
|
|
55
|
+
];
|
|
56
|
+
export const validRange = (range) => validInstant(range.from) && validInstant(range.to) && range.from < range.to;
|
|
57
|
+
export const units = [["day", 86_400_000], ["hour", 3_600_000], ["minute", 60_000], ["second", 1000]];
|
|
58
|
+
export const positive = (value) => Number.isFinite(value) && value > 0;
|
|
59
|
+
export const ceilSecond = (value) => Math.ceil(value / 1000) * 1000;
|
|
60
|
+
export const floorSecond = (value) => Math.floor(value / 1000) * 1000;
|
|
61
|
+
export function documentLocale() {
|
|
62
|
+
return typeof document === "undefined" ? undefined : document.documentElement.lang || undefined;
|
|
63
|
+
}
|
|
64
|
+
export function validLocale(locale) {
|
|
65
|
+
if (locale === undefined)
|
|
66
|
+
return undefined;
|
|
67
|
+
try {
|
|
68
|
+
return Intl.getCanonicalLocales(locale)[0];
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** A duration in the largest unit that divides it, through a label template. */
|
|
75
|
+
export function durationText(duration, template) {
|
|
76
|
+
const [unit, size] = units.find(([, size]) => duration % size === 0) ?? ["second", 1000];
|
|
77
|
+
return template(Math.max(1, Math.round(duration / size)), unit);
|
|
78
|
+
}
|
|
79
|
+
/** The smallest span a drag or slider keeps: one second, or all of a shorter retention. */
|
|
80
|
+
export const minimumSpan = (maxDuration) => Math.min(1000, maxDuration);
|
|
81
|
+
/** A drag released at now: the minute when it fits retention, else the second. */
|
|
82
|
+
export function snapDuration(span, maxDuration) {
|
|
83
|
+
const minute = Math.round(span / 60_000) * 60_000;
|
|
84
|
+
if (minute >= 60_000 && minute <= maxDuration)
|
|
85
|
+
return minute;
|
|
86
|
+
return Math.min(maxDuration, Math.max(minimumSpan(maxDuration), Math.round(span / 1000) * 1000));
|
|
87
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type RangeText = {
|
|
2
|
+
kind: "relative";
|
|
3
|
+
offset: number;
|
|
4
|
+
} | {
|
|
5
|
+
kind: "absolute";
|
|
6
|
+
at: number;
|
|
7
|
+
};
|
|
8
|
+
/** Reads field text; `now` gives today's date for a time of day. Null when invalid. */
|
|
9
|
+
export declare function parseRangeText(text: string, zone: string, now: number): RangeText | null;
|
|
10
|
+
export declare const resolveRangeText: (text: RangeText, now: number) => number;
|
|
11
|
+
/** `now-30m`, in the largest unit that divides the duration. */
|
|
12
|
+
export declare function relativeRangeText(duration: number): string;
|
|
13
|
+
export declare const absoluteRangeText: (instant: number, zone: string) => string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Text for the live range fields: `now`, `now-15m`, `16:37[:05]`, or
|
|
2
|
+
// `2026-10-28 16:37[:05]`, read in a time zone. Values stay epoch milliseconds.
|
|
3
|
+
import { parseWallTime, validInstant, wallString } from "./time-zone.js";
|
|
4
|
+
const unitSizes = { d: 86_400_000, h: 3_600_000, m: 60_000, s: 1000 };
|
|
5
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
6
|
+
const daysIn = (year, month) => {
|
|
7
|
+
const date = new Date(0);
|
|
8
|
+
date.setUTCFullYear(year, month, 0);
|
|
9
|
+
return date.getUTCDate();
|
|
10
|
+
};
|
|
11
|
+
function wallInstant(date, hour, minute, second, zone) {
|
|
12
|
+
const [year, month, day] = date.split("-").map(Number);
|
|
13
|
+
if (month < 1 || month > 12 || day < 1 || day > daysIn(year, month))
|
|
14
|
+
return NaN;
|
|
15
|
+
if (hour > 23 || minute > 59 || second > 59)
|
|
16
|
+
return NaN;
|
|
17
|
+
return parseWallTime(`${date}T${pad(hour)}:${pad(minute)}:${pad(second)}`, zone);
|
|
18
|
+
}
|
|
19
|
+
/** Reads field text; `now` gives today's date for a time of day. Null when invalid. */
|
|
20
|
+
export function parseRangeText(text, zone, now) {
|
|
21
|
+
const value = text.trim().toLowerCase();
|
|
22
|
+
const relative = /^now(?:\s*-\s*(\d+)\s*([smhd]))?$/.exec(value);
|
|
23
|
+
if (relative) {
|
|
24
|
+
const offset = relative[1] ? Number(relative[1]) * unitSizes[relative[2]] : 0;
|
|
25
|
+
return Number.isSafeInteger(offset) ? { kind: "relative", offset } : null;
|
|
26
|
+
}
|
|
27
|
+
const full = /^(\d{4}-\d{2}-\d{2})[ t](\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(value);
|
|
28
|
+
const clock = full ? null : /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(value);
|
|
29
|
+
if (!full && !clock)
|
|
30
|
+
return null;
|
|
31
|
+
if (clock && !validInstant(now))
|
|
32
|
+
return null;
|
|
33
|
+
const date = full ? full[1] : wallString(now, zone, "second").slice(0, 10);
|
|
34
|
+
const [hour, minute, second = "0"] = (full ? full.slice(2) : clock.slice(1)).map(part => part ?? "0");
|
|
35
|
+
const at = wallInstant(date, Number(hour), Number(minute), Number(second), zone);
|
|
36
|
+
return validInstant(at) ? { kind: "absolute", at } : null;
|
|
37
|
+
}
|
|
38
|
+
export const resolveRangeText = (text, now) => text.kind === "relative" ? now - text.offset : text.at;
|
|
39
|
+
/** `now-30m`, in the largest unit that divides the duration. */
|
|
40
|
+
export function relativeRangeText(duration) {
|
|
41
|
+
const unit = Object.keys(unitSizes).find(key => duration % unitSizes[key] === 0);
|
|
42
|
+
return unit ? `now-${duration / unitSizes[unit]}${unit}` : `now-${Math.max(1, Math.round(duration / 1000))}s`;
|
|
43
|
+
}
|
|
44
|
+
export const absoluteRangeText = (instant, zone) => validInstant(instant) ? wallString(instant, zone, "second").replace("T", " ") : "";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function dateFormat(locale: string | undefined, options: Intl.DateTimeFormatOptions): Intl.DateTimeFormat;
|
|
2
|
+
export declare const browserTimeZone: () => string;
|
|
3
|
+
export declare const validTimeZone: (zone: unknown) => zone is string;
|
|
4
|
+
export declare const validInstant: (value: number) => boolean;
|
|
5
|
+
export declare function timeZones(): string[];
|
|
6
|
+
/** The zone's offset from UTC at an instant, in milliseconds. */
|
|
7
|
+
export declare function zoneOffset(value: number, zone: string): number;
|
|
8
|
+
/** Wall-clock time of an instant in a zone, as a datetime-local value. */
|
|
9
|
+
export declare function wallString(value: number, zone: string, precision: "second" | "millisecond"): string;
|
|
10
|
+
/** Instant of a datetime-local wall time in a zone. A wall time inside a
|
|
11
|
+
daylight-saving gap moves forward to the first valid instant; one inside an
|
|
12
|
+
overlap takes the earlier instant. Returns NaN for unparsable input. */
|
|
13
|
+
export declare function parseWallTime(text: string, zone: string): number;
|
|
14
|
+
/** A short zone name at an instant, such as "UTC" or "GMT-3". */
|
|
15
|
+
export declare function zoneName(value: number, zone: string, locale?: string): string;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Time zone helpers built on Intl only. Values stay epoch milliseconds; wall
|
|
2
|
+
// strings use the datetime-local shape YYYY-MM-DDTHH:mm:ss(.sss).
|
|
3
|
+
const formatters = new Map();
|
|
4
|
+
export function dateFormat(locale, options) {
|
|
5
|
+
const key = JSON.stringify([locale ?? "", options]);
|
|
6
|
+
let format = formatters.get(key);
|
|
7
|
+
if (!format)
|
|
8
|
+
formatters.set(key, format = new Intl.DateTimeFormat(locale, options));
|
|
9
|
+
return format;
|
|
10
|
+
}
|
|
11
|
+
export const browserTimeZone = () => {
|
|
12
|
+
try {
|
|
13
|
+
return new Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return "UTC";
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const validTimeZone = (zone) => {
|
|
20
|
+
if (typeof zone !== "string" || !zone)
|
|
21
|
+
return false;
|
|
22
|
+
try {
|
|
23
|
+
dateFormat("en-US", { timeZone: zone });
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export const validInstant = (value) => Number.isFinite(value) && Math.abs(value) <= 8.64e15;
|
|
31
|
+
export function timeZones() {
|
|
32
|
+
const zones = typeof Intl.supportedValuesOf === "function" ? Intl.supportedValuesOf("timeZone") : [];
|
|
33
|
+
return zones.includes("UTC") ? zones : [...zones, "UTC"];
|
|
34
|
+
}
|
|
35
|
+
const pad = (value, length = 2) => String(value).padStart(length, "0");
|
|
36
|
+
function wallParts(value, zone) {
|
|
37
|
+
const parts = {};
|
|
38
|
+
for (const part of dateFormat("en-US", { timeZone: zone, hourCycle: "h23", year: "numeric", month: "2-digit",
|
|
39
|
+
day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", era: "short" }).formatToParts(value)) {
|
|
40
|
+
parts[part.type] = part.value;
|
|
41
|
+
}
|
|
42
|
+
const year = Number(parts.year);
|
|
43
|
+
return { year: parts.era === "BC" || parts.era === "B" ? 1 - year : year, month: Number(parts.month),
|
|
44
|
+
day: Number(parts.day), hour: Number(parts.hour) % 24, minute: Number(parts.minute), second: Number(parts.second),
|
|
45
|
+
millisecond: ((value % 1000) + 1000) % 1000 };
|
|
46
|
+
}
|
|
47
|
+
const utc = (year, month, day, hour, minute, second, ms) => {
|
|
48
|
+
const date = new Date(0);
|
|
49
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
50
|
+
date.setUTCHours(hour, minute, second, ms);
|
|
51
|
+
return date.getTime();
|
|
52
|
+
};
|
|
53
|
+
/** The zone's offset from UTC at an instant, in milliseconds. */
|
|
54
|
+
export function zoneOffset(value, zone) {
|
|
55
|
+
const wall = wallParts(value, zone);
|
|
56
|
+
return utc(wall.year, wall.month, wall.day, wall.hour, wall.minute, wall.second, wall.millisecond) - value;
|
|
57
|
+
}
|
|
58
|
+
/** Wall-clock time of an instant in a zone, as a datetime-local value. */
|
|
59
|
+
export function wallString(value, zone, precision) {
|
|
60
|
+
if (zone === "UTC" && precision === "millisecond")
|
|
61
|
+
return new Date(value).toISOString().slice(0, 23);
|
|
62
|
+
const wall = wallParts(value, zone);
|
|
63
|
+
const year = wall.year < 0 ? `-${pad(-wall.year, 6)}` : wall.year > 9999 ? `+${pad(wall.year, 6)}` : pad(wall.year, 4);
|
|
64
|
+
const text = `${year}-${pad(wall.month)}-${pad(wall.day)}T${pad(wall.hour)}:${pad(wall.minute)}:${pad(wall.second)}`;
|
|
65
|
+
return precision === "millisecond" ? `${text}.${pad(wall.millisecond, 3)}` : text;
|
|
66
|
+
}
|
|
67
|
+
/** Instant of a datetime-local wall time in a zone. A wall time inside a
|
|
68
|
+
daylight-saving gap moves forward to the first valid instant; one inside an
|
|
69
|
+
overlap takes the earlier instant. Returns NaN for unparsable input. */
|
|
70
|
+
export function parseWallTime(text, zone) {
|
|
71
|
+
try {
|
|
72
|
+
return wallInstant(text, zone);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return NaN;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function wallInstant(text, zone) {
|
|
79
|
+
const match = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?$/.exec(text);
|
|
80
|
+
if (!match)
|
|
81
|
+
return NaN;
|
|
82
|
+
const [year, month, day, hour, minute, second = 0] = match.slice(1, 7).map(part => Number(part ?? 0));
|
|
83
|
+
const ms = Number((match[7] ?? "").padEnd(3, "0"));
|
|
84
|
+
const wall = utc(year, month, day, hour, minute, second, ms);
|
|
85
|
+
if (!validInstant(wall) || month < 1 || month > 12 || day < 1 || day > 31 || hour > 23 || minute > 59 || second > 59)
|
|
86
|
+
return NaN;
|
|
87
|
+
if (zone === "UTC")
|
|
88
|
+
return wall;
|
|
89
|
+
const oneDay = 86_400_000;
|
|
90
|
+
const before = zoneOffset(wall - oneDay, zone);
|
|
91
|
+
const after = zoneOffset(wall + oneDay, zone);
|
|
92
|
+
const same = (value) => {
|
|
93
|
+
const parts = wallParts(value, zone);
|
|
94
|
+
return utc(parts.year, parts.month, parts.day, parts.hour, parts.minute, parts.second, parts.millisecond) === wall;
|
|
95
|
+
};
|
|
96
|
+
const candidates = [...new Set([wall - before, wall - after])].filter(same);
|
|
97
|
+
if (candidates.length)
|
|
98
|
+
return Math.min(...candidates);
|
|
99
|
+
if (before === after)
|
|
100
|
+
return NaN;
|
|
101
|
+
// In a gap: find the transition instant between both readings.
|
|
102
|
+
let low = Math.min(wall - before, wall - after);
|
|
103
|
+
let high = Math.max(wall - before, wall - after);
|
|
104
|
+
const target = zoneOffset(high, zone);
|
|
105
|
+
while (high - low > 1) {
|
|
106
|
+
const middle = Math.floor((low + high) / 2);
|
|
107
|
+
if (zoneOffset(middle, zone) === target)
|
|
108
|
+
high = middle;
|
|
109
|
+
else
|
|
110
|
+
low = middle;
|
|
111
|
+
}
|
|
112
|
+
return high;
|
|
113
|
+
}
|
|
114
|
+
/** A short zone name at an instant, such as "UTC" or "GMT-3". */
|
|
115
|
+
export function zoneName(value, zone, locale) {
|
|
116
|
+
if (zone === "UTC")
|
|
117
|
+
return "UTC";
|
|
118
|
+
const at = validInstant(value) ? value : Date.now();
|
|
119
|
+
return dateFormat(locale, { timeZone: zone, timeZoneName: "short" }).formatToParts(at)
|
|
120
|
+
.find(part => part.type === "timeZoneName")?.value ?? zone;
|
|
121
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momoi-labs/kiso-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Kiso React components built with shadcn/ui and Radix",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"prepack": "npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@momoi-labs/kiso": "^1.0
|
|
35
|
+
"@momoi-labs/kiso": "^1.1.0",
|
|
36
36
|
"class-variance-authority": "0.7.1",
|
|
37
37
|
"clsx": "2.1.1",
|
|
38
38
|
"radix-ui": "1.6.7",
|