@xds/core 0.2.0 → 1.0.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/animation.js +3 -1
- package/dist/date-picker.d.ts +7 -2
- package/dist/date-picker.js +26 -8
- package/dist/date-range-picker.d.ts +1 -0
- package/dist/date-range-picker.js +12 -7
- package/dist/defaults.js +4 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/slider.d.ts +6 -2
- package/dist/slider.js +6 -3
- package/dist/theme-scope.d.ts +31 -0
- package/dist/theme-scope.js +81 -0
- package/package.json +2 -2
package/dist/animation.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export function afterAnimations(elements, done) {
|
|
2
2
|
let waiting = true;
|
|
3
|
-
const running = elements
|
|
3
|
+
const running = elements
|
|
4
|
+
.flatMap((element) => element?.getAnimations() ?? [])
|
|
5
|
+
.filter((animation) => animation.effect?.getTiming().iterations !== Number.POSITIVE_INFINITY);
|
|
4
6
|
void Promise.allSettled(running.map((animation) => animation.finished)).then(() => {
|
|
5
7
|
if (waiting)
|
|
6
8
|
done();
|
package/dist/date-picker.d.ts
CHANGED
|
@@ -25,7 +25,11 @@ export type DatePickerBaseProps = {
|
|
|
25
25
|
previousLabel?: string;
|
|
26
26
|
/** Names the calendar's button to the month after, for assistive technology. */
|
|
27
27
|
nextLabel?: string;
|
|
28
|
+
/** Formats dates and calendar headings in a fixed locale (avoids SSR locale mismatches). */
|
|
29
|
+
locale?: string;
|
|
28
30
|
};
|
|
31
|
+
/** Parses a strict calendar `YYYY-MM-DD` day, returning `undefined` for malformed or impossible dates. */
|
|
32
|
+
export declare function parseIsoDate(value: IsoDate | undefined): DateValue | undefined;
|
|
29
33
|
/**
|
|
30
34
|
* The day as the field shows it: the locale's medium form ("Mar 10, 2026", "2026. 3. 10.").
|
|
31
35
|
* Read at noon UTC and formatted in UTC, so no time zone can move it to another day.
|
|
@@ -42,9 +46,9 @@ export declare function clampDay(day: IsoDate, min?: IsoDate, max?: IsoDate): Is
|
|
|
42
46
|
export declare function openingDay(props: Pick<DatePickerBaseProps, "value" | "min" | "max">, now?: IsoDate): IsoDate;
|
|
43
47
|
/**
|
|
44
48
|
* The language of the names of the days and months, and of the field's form of a day: the
|
|
45
|
-
*
|
|
49
|
+
* explicit `locale` prop if given, otherwise the page's language (falling back to English on SSR).
|
|
46
50
|
*/
|
|
47
|
-
export declare function datePickerLocale(): string;
|
|
51
|
+
export declare function datePickerLocale(locale?: string): string;
|
|
48
52
|
/** The ids of the parts the library names itself, under the DatePicker's own id. */
|
|
49
53
|
export declare function datePickerIds(id: string): {
|
|
50
54
|
label: string;
|
|
@@ -62,6 +66,7 @@ export declare function datePickerMachineProps(props: DatePickerBaseProps, optio
|
|
|
62
66
|
id: string;
|
|
63
67
|
locale: string;
|
|
64
68
|
onChange: (value: IsoDate) => void;
|
|
69
|
+
gutter?: number;
|
|
65
70
|
}): datePicker.Props;
|
|
66
71
|
/**
|
|
67
72
|
* Zag's strings that the calendar shows assistive technology. A day is named by its long
|
package/dist/date-picker.js
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { space } from "@xds/tokens";
|
|
2
2
|
import { getLocalTimeZone, parseDate, today } from "@internationalized/date";
|
|
3
3
|
import { buttonClass } from "./button.js";
|
|
4
|
+
export function parseIsoDate(value) {
|
|
5
|
+
if (value === undefined || !/^\d{4}-\d{2}-\d{2}$/.test(value))
|
|
6
|
+
return undefined;
|
|
7
|
+
try {
|
|
8
|
+
const parsed = parseDate(value);
|
|
9
|
+
return parsed.toString() === value ? parsed : undefined;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
4
15
|
export function formatDay(value, locale) {
|
|
16
|
+
if (!parseIsoDate(value))
|
|
17
|
+
return "";
|
|
5
18
|
return new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeZone: "UTC" }).format(new Date(`${value}T12:00:00Z`));
|
|
6
19
|
}
|
|
7
20
|
export function todayIso() {
|
|
8
21
|
return today(getLocalTimeZone()).toString();
|
|
9
22
|
}
|
|
10
23
|
export function clampDay(day, min, max) {
|
|
24
|
+
if (min !== undefined && max !== undefined && min > max)
|
|
25
|
+
return day;
|
|
11
26
|
if (min !== undefined && day < min)
|
|
12
27
|
return min;
|
|
13
28
|
if (max !== undefined && day > max)
|
|
@@ -15,10 +30,11 @@ export function clampDay(day, min, max) {
|
|
|
15
30
|
return day;
|
|
16
31
|
}
|
|
17
32
|
export function openingDay(props, now = todayIso()) {
|
|
18
|
-
|
|
33
|
+
const valid = (value) => (parseIsoDate(value) ? value : undefined);
|
|
34
|
+
return clampDay(valid(props.value) ?? now, valid(props.min), valid(props.max));
|
|
19
35
|
}
|
|
20
|
-
export function datePickerLocale() {
|
|
21
|
-
return typeof navigator === "undefined" ? "en-US" : navigator.language;
|
|
36
|
+
export function datePickerLocale(locale) {
|
|
37
|
+
return locale ?? (typeof navigator === "undefined" ? "en-US" : navigator.language);
|
|
22
38
|
}
|
|
23
39
|
export function datePickerIds(id) {
|
|
24
40
|
return {
|
|
@@ -29,14 +45,16 @@ export function datePickerIds(id) {
|
|
|
29
45
|
};
|
|
30
46
|
}
|
|
31
47
|
export function datePickerMachineProps(props, options) {
|
|
32
|
-
const
|
|
48
|
+
const value = parseIsoDate(props.value);
|
|
49
|
+
const min = parseIsoDate(props.min);
|
|
50
|
+
const max = parseIsoDate(props.max);
|
|
33
51
|
return {
|
|
34
52
|
id: options.id,
|
|
35
53
|
locale: options.locale,
|
|
36
54
|
timeZone: getLocalTimeZone(),
|
|
37
|
-
value:
|
|
38
|
-
min
|
|
39
|
-
max
|
|
55
|
+
value: value === undefined ? [] : [value],
|
|
56
|
+
min,
|
|
57
|
+
max,
|
|
40
58
|
defaultFocusedValue: parseDate(openingDay(props)),
|
|
41
59
|
onValueChange: (details) => {
|
|
42
60
|
const next = details.value[0];
|
|
@@ -48,7 +66,7 @@ export function datePickerMachineProps(props, options) {
|
|
|
48
66
|
outsideDaySelectable: false,
|
|
49
67
|
minView: "day",
|
|
50
68
|
maxView: "day",
|
|
51
|
-
positioning: { placement: "bottom-start", gutter: space[1] },
|
|
69
|
+
positioning: { placement: "bottom-start", gutter: options.gutter ?? space[1] },
|
|
52
70
|
translations: datePickerTranslations(props),
|
|
53
71
|
};
|
|
54
72
|
}
|
|
@@ -67,6 +67,7 @@ export declare function dateRangeMachineProps(props: DateRangePickerBaseProps, s
|
|
|
67
67
|
months: number;
|
|
68
68
|
onDraft: (draft: RangeDraft | null) => void;
|
|
69
69
|
onChange: (value: DateRange) => void;
|
|
70
|
+
gutter?: number;
|
|
70
71
|
}): datePicker.Props;
|
|
71
72
|
/**
|
|
72
73
|
* DatePicker's strings, with the two ends named by `startLabel` and `endLabel` ahead of the
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { space } from "@xds/tokens";
|
|
2
2
|
import { getLocalTimeZone, parseDate } from "@internationalized/date";
|
|
3
|
-
import { datePickerTranslations, formatDay, openingDay, } from "./date-picker.js";
|
|
3
|
+
import { datePickerTranslations, formatDay, openingDay, parseIsoDate, } from "./date-picker.js";
|
|
4
4
|
export function daysBetween(from, to) {
|
|
5
5
|
return Math.round((Date.parse(`${to}T00:00:00Z`) - Date.parse(`${from}T00:00:00Z`)) / 86_400_000);
|
|
6
6
|
}
|
|
@@ -18,7 +18,10 @@ export function rangeDayChoice(draft, day, props) {
|
|
|
18
18
|
return "end";
|
|
19
19
|
}
|
|
20
20
|
export function formatRange(value, locale) {
|
|
21
|
-
|
|
21
|
+
if (!parseIsoDate(value.start) || !parseIsoDate(value.end))
|
|
22
|
+
return "";
|
|
23
|
+
const [start, end] = value.start <= value.end ? [value.start, value.end] : [value.end, value.start];
|
|
24
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeZone: "UTC" }).formatRange(new Date(`${start}T12:00:00Z`), new Date(`${end}T12:00:00Z`));
|
|
22
25
|
}
|
|
23
26
|
export function shownRange(value, draft) {
|
|
24
27
|
return draft ?? (value === undefined ? [] : [value.start, value.end]);
|
|
@@ -27,7 +30,9 @@ export function rangeMonths() {
|
|
|
27
30
|
return typeof matchMedia === "function" && matchMedia("(min-width: 40rem)").matches ? 2 : 1;
|
|
28
31
|
}
|
|
29
32
|
export function dateRangeMachineProps(props, shown, options) {
|
|
30
|
-
const
|
|
33
|
+
const parsedShown = shown
|
|
34
|
+
.map((value) => parseIsoDate(value))
|
|
35
|
+
.filter((value) => value !== undefined);
|
|
31
36
|
const [first] = shown;
|
|
32
37
|
return {
|
|
33
38
|
id: options.id,
|
|
@@ -35,9 +40,9 @@ export function dateRangeMachineProps(props, shown, options) {
|
|
|
35
40
|
timeZone: getLocalTimeZone(),
|
|
36
41
|
selectionMode: "range",
|
|
37
42
|
numOfMonths: options.months,
|
|
38
|
-
value:
|
|
39
|
-
min:
|
|
40
|
-
max:
|
|
43
|
+
value: parsedShown,
|
|
44
|
+
min: parseIsoDate(props.min),
|
|
45
|
+
max: parseIsoDate(props.max),
|
|
41
46
|
defaultFocusedValue: parseDate(openingDay({ ...props, value: props.value?.start })),
|
|
42
47
|
isDateUnavailable: (date) => shown.length === 1 &&
|
|
43
48
|
first !== undefined &&
|
|
@@ -61,7 +66,7 @@ export function dateRangeMachineProps(props, shown, options) {
|
|
|
61
66
|
outsideDaySelectable: false,
|
|
62
67
|
minView: "day",
|
|
63
68
|
maxView: "day",
|
|
64
|
-
positioning: { placement: "bottom-start", gutter: space[1] },
|
|
69
|
+
positioning: { placement: "bottom-start", gutter: options.gutter ?? space[1] },
|
|
65
70
|
translations: dateRangeTranslations(props),
|
|
66
71
|
};
|
|
67
72
|
}
|
package/dist/defaults.js
CHANGED
|
@@ -21,8 +21,10 @@ export function mergeDefaults(outer, inner) {
|
|
|
21
21
|
return outer;
|
|
22
22
|
const merged = { ...outer };
|
|
23
23
|
for (const [name, options] of Object.entries(inner)) {
|
|
24
|
-
if (options)
|
|
25
|
-
|
|
24
|
+
if (!options)
|
|
25
|
+
continue;
|
|
26
|
+
const defined = Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined));
|
|
27
|
+
merged[name] = { ...merged[name], ...defined };
|
|
26
28
|
}
|
|
27
29
|
return merged;
|
|
28
30
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { CHECKBOX_MARK, type CheckboxBaseProps, checkboxBoxClass, checkboxClass,
|
|
|
10
10
|
export { type ChipBaseProps, chipClass, chipIcon } from "./chip.ts";
|
|
11
11
|
export { type ChipBarBaseProps, chipBarClass } from "./chip-bar.ts";
|
|
12
12
|
export { type CountBadgeBaseProps, countBadgeAnchorClass, countBadgeClass, countBadgeText, } from "./count-badge.ts";
|
|
13
|
-
export { clampDay, DATE_PICKER_NAV_CLASS, type DatePickerBaseProps, datePickerContentAttrs, datePickerIds, datePickerLocale, datePickerMachineProps, datePickerTranslations, datePickerTriggerAttrs, focusOpeningDay, formatDay, type IsoDate, keepCalendarFocus, keepDayFocused, openingDay, todayIso, } from "./date-picker.ts";
|
|
13
|
+
export { clampDay, DATE_PICKER_NAV_CLASS, type DatePickerBaseProps, datePickerContentAttrs, datePickerIds, datePickerLocale, datePickerMachineProps, datePickerTranslations, datePickerTriggerAttrs, focusOpeningDay, formatDay, type IsoDate, keepCalendarFocus, keepDayFocused, openingDay, parseIsoDate, todayIso, } from "./date-picker.ts";
|
|
14
14
|
export { type DateRange, type DateRangePickerBaseProps, dateRangeMachineProps, dateRangeTranslations, daysBetween, endRangeChoiceOnClose, formatRange, keepRangePreview, type RangeDraft, type RangeMonth, rangeDayChoice, rangeDayClick, rangeGridKeyDown, rangeMonths, rangeMonthViews, rangeSummary, restartRange, shownRange, } from "./date-range-picker.ts";
|
|
15
15
|
export { type ComponentDefaults, DEFAULT_OPTIONS, type DefaultedComponent, mergeDefaults, } from "./defaults.ts";
|
|
16
16
|
export type { DialogBaseProps } from "./dialog.ts";
|
|
@@ -37,6 +37,7 @@ export { PEER_FOCUS, type SwitchBaseProps, switchClass, switchLabelClass, switch
|
|
|
37
37
|
export { type TabsBaseProps, tabStopIndex, tabsClass } from "./tabs.ts";
|
|
38
38
|
export { type TextBaseProps, type TextTone, type TextVariant, textClass } from "./text.ts";
|
|
39
39
|
export type { SearchFieldBaseProps, TextFieldBaseProps, TextFieldType } from "./text-field.ts";
|
|
40
|
+
export { readCssMs, readCssPx, readThemeScope, syncThemeScope, type ThemeScope, underlayLayerStyle, } from "./theme-scope.ts";
|
|
40
41
|
export { THUMBNAIL_PARTS, type ThumbnailBaseProps, type ThumbnailRatio, thumbnailBadgeClass, thumbnailClass, thumbnailWatched, } from "./thumbnail.ts";
|
|
41
42
|
export { classes, rootPart } from "./parts.ts";
|
|
42
43
|
export { TOAST_PARTS, type ToastAction, type ToastBaseProps } from "./toast.ts";
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { CHECKBOX_MARK, checkboxBoxClass, checkboxClass, checkboxLabelClass, che
|
|
|
10
10
|
export { chipClass, chipIcon } from "./chip.js";
|
|
11
11
|
export { chipBarClass } from "./chip-bar.js";
|
|
12
12
|
export { countBadgeAnchorClass, countBadgeClass, countBadgeText, } from "./count-badge.js";
|
|
13
|
-
export { clampDay, DATE_PICKER_NAV_CLASS, datePickerContentAttrs, datePickerIds, datePickerLocale, datePickerMachineProps, datePickerTranslations, datePickerTriggerAttrs, focusOpeningDay, formatDay, keepCalendarFocus, keepDayFocused, openingDay, todayIso, } from "./date-picker.js";
|
|
13
|
+
export { clampDay, DATE_PICKER_NAV_CLASS, datePickerContentAttrs, datePickerIds, datePickerLocale, datePickerMachineProps, datePickerTranslations, datePickerTriggerAttrs, focusOpeningDay, formatDay, keepCalendarFocus, keepDayFocused, openingDay, parseIsoDate, todayIso, } from "./date-picker.js";
|
|
14
14
|
export { dateRangeMachineProps, dateRangeTranslations, daysBetween, endRangeChoiceOnClose, formatRange, keepRangePreview, rangeDayChoice, rangeDayClick, rangeGridKeyDown, rangeMonths, rangeMonthViews, rangeSummary, restartRange, shownRange, } from "./date-range-picker.js";
|
|
15
15
|
export { DEFAULT_OPTIONS, mergeDefaults, } from "./defaults.js";
|
|
16
16
|
export { dividerClass } from "./divider.js";
|
|
@@ -34,6 +34,7 @@ export { spinnerClass } from "./spinner.js";
|
|
|
34
34
|
export { PEER_FOCUS, switchClass, switchLabelClass, switchThumbClass, switchTrackClass, } from "./switch.js";
|
|
35
35
|
export { tabStopIndex, tabsClass } from "./tabs.js";
|
|
36
36
|
export { textClass } from "./text.js";
|
|
37
|
+
export { readCssMs, readCssPx, readThemeScope, syncThemeScope, underlayLayerStyle, } from "./theme-scope.js";
|
|
37
38
|
export { THUMBNAIL_PARTS, thumbnailBadgeClass, thumbnailClass, thumbnailWatched, } from "./thumbnail.js";
|
|
38
39
|
export { classes, rootPart } from "./parts.js";
|
|
39
40
|
export { TOAST_PARTS } from "./toast.js";
|
package/dist/slider.d.ts
CHANGED
|
@@ -12,9 +12,13 @@ export type SliderBaseProps = {
|
|
|
12
12
|
disabled?: boolean;
|
|
13
13
|
/** Shows the current value at the end of the label's line. */
|
|
14
14
|
showValue?: boolean;
|
|
15
|
+
/** The name the value is submitted under with a form. */
|
|
16
|
+
name?: string;
|
|
17
|
+
/** Formats the displayed value in a fixed locale (useful for SSR). */
|
|
18
|
+
locale?: string;
|
|
15
19
|
};
|
|
16
|
-
/** The value as it is shown beside the label and read out: a number in the reader's
|
|
17
|
-
export declare function sliderValueText(value: number): string;
|
|
20
|
+
/** The value as it is shown beside the label and read out: a number in the chosen or reader's locale. */
|
|
21
|
+
export declare function sliderValueText(value: number, locale?: string): string;
|
|
18
22
|
/**
|
|
19
23
|
* How far Page Up, Page Down and a shifted arrow key move the thumb: a tenth of the range,
|
|
20
24
|
* rounded to a whole number of steps and never less than one.
|
package/dist/slider.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { focusWithoutRing } from "./focus.js";
|
|
2
|
-
export function sliderValueText(value) {
|
|
3
|
-
|
|
2
|
+
export function sliderValueText(value, locale) {
|
|
3
|
+
const tag = locale ?? (typeof navigator === "undefined" ? "en-US" : navigator.language);
|
|
4
|
+
return new Intl.NumberFormat(tag).format(value);
|
|
4
5
|
}
|
|
5
6
|
export function sliderPageSize(options) {
|
|
6
7
|
const { min, max, step } = options;
|
|
@@ -13,7 +14,9 @@ export function sliderArrowValue(event, options) {
|
|
|
13
14
|
if (direction === 0)
|
|
14
15
|
return undefined;
|
|
15
16
|
const { value, min, max, step, pageSize } = options;
|
|
16
|
-
const
|
|
17
|
+
const delta = event.shiftKey ? pageSize : step;
|
|
18
|
+
const decimals = Math.max(String(step).split(".")[1]?.length ?? 0, String(delta).split(".")[1]?.length ?? 0);
|
|
19
|
+
const next = Number((value + direction * delta).toFixed(decimals));
|
|
17
20
|
return Math.min(max, Math.max(min, next));
|
|
18
21
|
}
|
|
19
22
|
export function focusThumbOnPress(event, thumb) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type ThemeScope = {
|
|
2
|
+
mode?: string;
|
|
3
|
+
theme?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Finds the nearest subtree color mode and theme attributes around `origin`, ignoring attributes
|
|
7
|
+
* on `<html>` because those already inherit into `document.body`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readThemeScope(origin: Element | null | undefined): ThemeScope;
|
|
10
|
+
/**
|
|
11
|
+
* Mirrors the nearest subtree `[data-theme]` and `[data-xds-theme]` onto `target` (typically a
|
|
12
|
+
* portaled overlay wrapper in `document.body`) and keeps them synchronized when ancestors change.
|
|
13
|
+
*/
|
|
14
|
+
export declare function syncThemeScope(origin: Element | null | undefined, target: HTMLElement | null | undefined): () => void;
|
|
15
|
+
/**
|
|
16
|
+
* Reads a length custom property (in px) from `element` (or `:root`), falling back to `fallback`
|
|
17
|
+
* outside a browser or when the property is unset. Allows Layer 3 themes to override JS-positioned
|
|
18
|
+
* overlay offsets (Menu, Select, DatePicker, Tooltip).
|
|
19
|
+
*/
|
|
20
|
+
export declare function readCssPx(element: Element | null | undefined, property: string, fallback: number): number;
|
|
21
|
+
/**
|
|
22
|
+
* Reads a duration custom property (in ms) from `element` (or `:root`), falling back to `fallback`.
|
|
23
|
+
* Allows Layer 3 themes to override motion durations read by JS timers (Toast, Tooltip).
|
|
24
|
+
*/
|
|
25
|
+
export declare function readCssMs(element: Element | null | undefined, property: string, fallback: number): number;
|
|
26
|
+
/**
|
|
27
|
+
* Extracts Zag's `--layer-index` custom property from a positioner's `style` (object or string)
|
|
28
|
+
* so an overlay's sibling underlay stacks directly beneath its own positioner even inside nested
|
|
29
|
+
* dialogs.
|
|
30
|
+
*/
|
|
31
|
+
export declare function underlayLayerStyle(style: unknown): Record<string, string> | undefined;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const MODE_ATTR = "data-theme";
|
|
2
|
+
const THEME_ATTR = "data-xds-theme";
|
|
3
|
+
export function readThemeScope(origin) {
|
|
4
|
+
if (!origin || typeof document === "undefined")
|
|
5
|
+
return {};
|
|
6
|
+
const root = document.documentElement;
|
|
7
|
+
const modeHost = origin.closest(`[${MODE_ATTR}]`);
|
|
8
|
+
const themeHost = origin.closest(`[${THEME_ATTR}]`);
|
|
9
|
+
const mode = modeHost && modeHost !== root ? (modeHost.getAttribute(MODE_ATTR) ?? undefined) : undefined;
|
|
10
|
+
const theme = themeHost && themeHost !== root ? (themeHost.getAttribute(THEME_ATTR) ?? undefined) : undefined;
|
|
11
|
+
return { mode, theme };
|
|
12
|
+
}
|
|
13
|
+
export function syncThemeScope(origin, target) {
|
|
14
|
+
if (!origin || !target || typeof document === "undefined")
|
|
15
|
+
return () => { };
|
|
16
|
+
const apply = () => {
|
|
17
|
+
const { mode, theme } = readThemeScope(origin);
|
|
18
|
+
if (mode !== undefined)
|
|
19
|
+
target.setAttribute(MODE_ATTR, mode);
|
|
20
|
+
else
|
|
21
|
+
target.removeAttribute(MODE_ATTR);
|
|
22
|
+
if (theme !== undefined)
|
|
23
|
+
target.setAttribute(THEME_ATTR, theme);
|
|
24
|
+
else
|
|
25
|
+
target.removeAttribute(THEME_ATTR);
|
|
26
|
+
};
|
|
27
|
+
apply();
|
|
28
|
+
if (typeof MutationObserver === "undefined")
|
|
29
|
+
return () => { };
|
|
30
|
+
const observer = new MutationObserver(apply);
|
|
31
|
+
let node = origin;
|
|
32
|
+
while (node && node !== document.documentElement) {
|
|
33
|
+
observer.observe(node, { attributes: true, attributeFilter: [MODE_ATTR, THEME_ATTR] });
|
|
34
|
+
node = node.parentElement;
|
|
35
|
+
}
|
|
36
|
+
return () => observer.disconnect();
|
|
37
|
+
}
|
|
38
|
+
export function readCssPx(element, property, fallback) {
|
|
39
|
+
if (typeof getComputedStyle === "undefined" || typeof document === "undefined")
|
|
40
|
+
return fallback;
|
|
41
|
+
const raw = getComputedStyle(element ?? document.documentElement)
|
|
42
|
+
.getPropertyValue(property)
|
|
43
|
+
.trim();
|
|
44
|
+
if (!raw)
|
|
45
|
+
return fallback;
|
|
46
|
+
const value = Number.parseFloat(raw);
|
|
47
|
+
if (!Number.isFinite(value))
|
|
48
|
+
return fallback;
|
|
49
|
+
if (raw.endsWith("rem")) {
|
|
50
|
+
const rootFont = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
51
|
+
return value * rootFont;
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
export function readCssMs(element, property, fallback) {
|
|
56
|
+
if (typeof getComputedStyle === "undefined" || typeof document === "undefined")
|
|
57
|
+
return fallback;
|
|
58
|
+
const raw = getComputedStyle(element ?? document.documentElement)
|
|
59
|
+
.getPropertyValue(property)
|
|
60
|
+
.trim();
|
|
61
|
+
if (!raw)
|
|
62
|
+
return fallback;
|
|
63
|
+
const value = Number.parseFloat(raw);
|
|
64
|
+
if (!Number.isFinite(value))
|
|
65
|
+
return fallback;
|
|
66
|
+
return raw.endsWith("s") && !raw.endsWith("ms") ? value * 1000 : value;
|
|
67
|
+
}
|
|
68
|
+
export function underlayLayerStyle(style) {
|
|
69
|
+
if (typeof style === "string") {
|
|
70
|
+
const match = /(?:^|;)\s*--layer-index\s*:\s*([^;]+)/.exec(style);
|
|
71
|
+
const value = match?.[1]?.trim();
|
|
72
|
+
return value ? { "--layer-index": value } : undefined;
|
|
73
|
+
}
|
|
74
|
+
if (style && typeof style === "object" && "--layer-index" in style) {
|
|
75
|
+
const value = style["--layer-index"];
|
|
76
|
+
if (typeof value === "number" || (typeof value === "string" && value !== "")) {
|
|
77
|
+
return { "--layer-index": String(value) };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xds/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "What the xds web component libraries share: prop types, class recipes and DOM helpers. Install a framework's package instead.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design-system",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@xds/tokens": "0.
|
|
37
|
+
"@xds/tokens": "1.0.0",
|
|
38
38
|
"@internationalized/date": "3.12.4",
|
|
39
39
|
"@zag-js/date-picker": "2.0.0-next.4"
|
|
40
40
|
},
|