@slurp-ui/react 1.0.1 → 1.1.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/CHANGELOG.md +11 -0
- package/dist/Carousel/Carousel.d.ts +36 -0
- package/dist/Carousel/Carousel.js +179 -0
- package/dist/Carousel/Carousel.js.map +1 -0
- package/dist/Carousel/index.d.ts +3 -0
- package/dist/Carousel/index.js +2 -0
- package/dist/Pages/Pages.d.ts +45 -0
- package/dist/Pages/Pages.js +128 -0
- package/dist/Pages/Pages.js.map +1 -0
- package/dist/Pages/index.d.ts +3 -0
- package/dist/Pages/index.js +2 -0
- package/dist/Rating/Rating.d.ts +36 -0
- package/dist/Rating/Rating.js +118 -0
- package/dist/Rating/Rating.js.map +1 -0
- package/dist/Rating/index.d.ts +3 -0
- package/dist/Rating/index.js +2 -0
- package/dist/Steps/Steps.d.ts +41 -0
- package/dist/Steps/Steps.js +89 -0
- package/dist/Steps/Steps.js.map +1 -0
- package/dist/Steps/index.d.ts +3 -0
- package/dist/Steps/index.js +2 -0
- package/dist/Suggest/Suggest.d.ts +54 -0
- package/dist/Suggest/Suggest.js +257 -0
- package/dist/Suggest/Suggest.js.map +1 -0
- package/dist/Suggest/index.d.ts +3 -0
- package/dist/Suggest/index.js +2 -0
- package/dist/Table/Table.d.ts +52 -0
- package/dist/Table/Table.js +127 -0
- package/dist/Table/Table.js.map +1 -0
- package/dist/Table/index.d.ts +3 -0
- package/dist/Table/index.js +2 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +7 -1
- package/dist/lib/theme.d.ts +30 -0
- package/dist/lib/theme.js.map +1 -1
- package/dist/styles.css +859 -8
- package/package.json +3 -3
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useTheme } from "../internal/context.js";
|
|
3
|
+
import { cx } from "../utils/src/index.js";
|
|
4
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
5
|
+
import { useCss, useParts, useThemeProps } from "../internal/styled.js";
|
|
6
|
+
import { useControlled } from "../utils/useControlled.js";
|
|
7
|
+
import { useId, useMemo } from "react";
|
|
8
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { ArrowDownIcon, ArrowUpIcon, SortIcon } from "@slurp-ui/icons";
|
|
10
|
+
// src/Table/Table.tsx
|
|
11
|
+
const TABLE_LABELS = { empty: "Nessun elemento" };
|
|
12
|
+
const field = (row, key) => row[key];
|
|
13
|
+
/**
|
|
14
|
+
* A plain data table, without a frame: hairlines between rows, numbers aligned at the end. Sortable headers are
|
|
15
|
+
* buttons and the sorted column carries `aria-sort`. Wide tables scroll inside a named, focusable region.
|
|
16
|
+
*/
|
|
17
|
+
function Table(props) {
|
|
18
|
+
const { as, css, className, caption, hideCaption = false, columns, rows, rowKey, sort: sortProp, defaultSort = null, onSortChange, manualSort = false, labels: labelsProp, parts, partProps, classNames, ...rest } = useThemeProps("Table", props);
|
|
19
|
+
const labels = {
|
|
20
|
+
...TABLE_LABELS,
|
|
21
|
+
...labelsProp
|
|
22
|
+
};
|
|
23
|
+
const [sort, setSort] = useControlled({
|
|
24
|
+
value: sortProp,
|
|
25
|
+
defaultValue: defaultSort,
|
|
26
|
+
onChange: onSortChange
|
|
27
|
+
});
|
|
28
|
+
const { locale } = useTheme();
|
|
29
|
+
const captionId = useId();
|
|
30
|
+
const Root = as ?? "div";
|
|
31
|
+
const styled = useCss("Table", "root", css);
|
|
32
|
+
const { part, style } = useParts("Table", {
|
|
33
|
+
parts,
|
|
34
|
+
partProps,
|
|
35
|
+
classNames
|
|
36
|
+
});
|
|
37
|
+
const root = useAnimationRoot(rest);
|
|
38
|
+
const sorted = useMemo(() => {
|
|
39
|
+
const column = sort && columns.find((c) => c.key === sort.key);
|
|
40
|
+
if (manualSort || !sort || !column) return rows;
|
|
41
|
+
const collator = new Intl.Collator(locale, {
|
|
42
|
+
numeric: true,
|
|
43
|
+
sensitivity: "base"
|
|
44
|
+
});
|
|
45
|
+
const read = column.sortValue ?? ((r) => field(r, column.key));
|
|
46
|
+
const sign = sort.direction === "ascending" ? 1 : -1;
|
|
47
|
+
return [...rows].sort((a, b) => {
|
|
48
|
+
const x = read(a);
|
|
49
|
+
const y = read(b);
|
|
50
|
+
if (x == null || x === "") return y == null || y === "" ? 0 : 1;
|
|
51
|
+
if (y == null || y === "") return -1;
|
|
52
|
+
return (typeof x === "number" && typeof y === "number" ? x - y : collator.compare(String(x), String(y))) * sign;
|
|
53
|
+
});
|
|
54
|
+
}, [
|
|
55
|
+
rows,
|
|
56
|
+
columns,
|
|
57
|
+
sort,
|
|
58
|
+
manualSort,
|
|
59
|
+
locale
|
|
60
|
+
]);
|
|
61
|
+
const toggle = (key) => setSort({
|
|
62
|
+
key,
|
|
63
|
+
direction: sort?.key === key && sort.direction === "ascending" ? "descending" : "ascending"
|
|
64
|
+
});
|
|
65
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
66
|
+
styled.style,
|
|
67
|
+
style,
|
|
68
|
+
/* @__PURE__ */ jsx(Root, {
|
|
69
|
+
className: cx("slurp-table", styled.className, className),
|
|
70
|
+
role: "region",
|
|
71
|
+
"aria-labelledby": captionId,
|
|
72
|
+
tabIndex: 0,
|
|
73
|
+
...root,
|
|
74
|
+
children: part("table", "table", {
|
|
75
|
+
className: "slurp-table-table",
|
|
76
|
+
children: /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
77
|
+
part("caption", "caption", {
|
|
78
|
+
id: captionId,
|
|
79
|
+
className: cx("slurp-table-caption", hideCaption && "slurp-visually-hidden"),
|
|
80
|
+
children: caption
|
|
81
|
+
}),
|
|
82
|
+
columns.some((c) => c.width != null) && /* @__PURE__ */ jsx("colgroup", { children: columns.map((c) => /* @__PURE__ */ jsx("col", { style: c.width != null ? { width: c.width } : void 0 }, c.key)) }),
|
|
83
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: columns.map((c) => {
|
|
84
|
+
const on = sort?.key === c.key ? sort.direction : void 0;
|
|
85
|
+
return /* @__PURE__ */ jsx("th", {
|
|
86
|
+
scope: "col",
|
|
87
|
+
className: "slurp-table-head",
|
|
88
|
+
"data-align": c.align ?? "start",
|
|
89
|
+
"aria-sort": on,
|
|
90
|
+
children: c.sortable ? /* @__PURE__ */ jsxs("button", {
|
|
91
|
+
type: "button",
|
|
92
|
+
className: "slurp-table-sort",
|
|
93
|
+
"data-sorted": on ? "" : void 0,
|
|
94
|
+
onClick: () => toggle(c.key),
|
|
95
|
+
children: [/* @__PURE__ */ jsx("span", { children: c.header }), /* @__PURE__ */ jsx("span", {
|
|
96
|
+
className: "slurp-table-sort-icon",
|
|
97
|
+
"aria-hidden": "true",
|
|
98
|
+
children: on === "ascending" ? /* @__PURE__ */ jsx(ArrowUpIcon, { size: 16 }) : on === "descending" ? /* @__PURE__ */ jsx(ArrowDownIcon, { size: 16 }) : /* @__PURE__ */ jsx(SortIcon, { size: 16 })
|
|
99
|
+
})]
|
|
100
|
+
}) : c.header
|
|
101
|
+
}, c.key);
|
|
102
|
+
}) }) }),
|
|
103
|
+
/* @__PURE__ */ jsx("tbody", { children: sorted.length === 0 ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", {
|
|
104
|
+
className: "slurp-table-empty",
|
|
105
|
+
colSpan: columns.length,
|
|
106
|
+
children: labels.empty
|
|
107
|
+
}) }) : sorted.map((row, i) => /* @__PURE__ */ jsx("tr", {
|
|
108
|
+
className: "slurp-table-row",
|
|
109
|
+
children: columns.map((c) => {
|
|
110
|
+
const Cell = c.rowHeader ? "th" : "td";
|
|
111
|
+
const content = c.cell ? c.cell(row, i) : field(row, c.key);
|
|
112
|
+
return /* @__PURE__ */ jsx(Cell, {
|
|
113
|
+
scope: c.rowHeader ? "row" : void 0,
|
|
114
|
+
className: "slurp-table-cell",
|
|
115
|
+
"data-align": c.align ?? "start",
|
|
116
|
+
children: content
|
|
117
|
+
}, c.key);
|
|
118
|
+
})
|
|
119
|
+
}, rowKey ? rowKey(row, i) : i)) })
|
|
120
|
+
] })
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
] });
|
|
124
|
+
}
|
|
125
|
+
export { TABLE_LABELS, Table };
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=Table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Table.js","names":[],"sources":["../../src/Table/Table.tsx"],"sourcesContent":["import { ArrowDownIcon, ArrowUpIcon, SortIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { useId, useMemo, type ElementType, type Key, type ReactNode } from 'react';\n\nimport { useTheme } from '../internal/context';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\n\ntype Row = object;\n\nexport interface TableColumn<R extends Row = Row> {\n /** Identifies the column; also the field read when there is no `cell` or `sortValue`. */\n key: string;\n header: ReactNode;\n /** Content of a cell. Default the field `key` of the row. */\n cell?: (row: R, index: number) => ReactNode;\n /** `end` for numbers and prices (tabular figures). Default `start`. */\n align?: 'start' | 'center' | 'end';\n sortable?: boolean;\n /** Value compared when sorting. Default the field `key` of the row. */\n sortValue?: (row: R) => string | number | null | undefined;\n /** The cells of this column name their row (`th scope=\"row\"`): usually the first column. */\n rowHeader?: boolean;\n /** CSS width of the column. */\n width?: string | number;\n}\n\nexport interface TableSort {\n key: string;\n direction: 'ascending' | 'descending';\n}\n\nexport interface TableLabels {\n /** Shown in place of the rows when there are none. */\n empty: string;\n}\n\nexport const TABLE_LABELS: TableLabels = { empty: 'Nessun elemento' };\n\nexport interface TableOwnProps<R extends Row = Row> extends PartsProps<'table' | 'caption'> {\n /** Title of the table: names it and its scroll region. Hide it with `hideCaption` when a heading already says it. */\n caption: ReactNode;\n hideCaption?: boolean;\n columns: TableColumn<R>[];\n rows: R[];\n /** Stable key of a row. Default its index. */\n rowKey?: (row: R, index: number) => Key;\n sort?: TableSort | null;\n defaultSort?: TableSort | null;\n onSortChange?: (sort: TableSort) => void;\n /** The rows are already sorted (by a server): the table only reports `onSortChange`. */\n manualSort?: boolean;\n labels?: Partial<TableLabels>;\n}\n\nexport type TableProps<R extends Row = Row, E extends ElementType = 'div'> = PolymorphicProps<\n E,\n TableOwnProps<R>\n>;\n\nconst field = (row: Row, key: string): unknown => (row as Record<string, unknown>)[key];\n\n/**\n * A plain data table, without a frame: hairlines between rows, numbers aligned at the end. Sortable headers are\n * buttons and the sorted column carries `aria-sort`. Wide tables scroll inside a named, focusable region.\n */\nexport function Table<R extends Row = Row, E extends ElementType = 'div'>(props: TableProps<R, E>) {\n const {\n as,\n css,\n className,\n caption,\n hideCaption = false,\n columns,\n rows,\n rowKey,\n sort: sortProp,\n defaultSort = null,\n onSortChange,\n manualSort = false,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Table', props as unknown as TableProps);\n const labels = { ...TABLE_LABELS, ...labelsProp };\n const [sort, setSort] = useControlled<TableSort | null>({\n value: sortProp,\n defaultValue: defaultSort,\n onChange: onSortChange as ((s: TableSort | null) => void) | undefined,\n });\n const { locale } = useTheme();\n const captionId = useId();\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Table', 'root', css);\n const { part, style } = useParts('Table', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n const sorted = useMemo(() => {\n const column = sort && columns.find((c) => c.key === sort.key);\n if (manualSort || !sort || !column) return rows;\n const collator = new Intl.Collator(locale, { numeric: true, sensitivity: 'base' });\n const read = column.sortValue ?? ((r: Row) => field(r, column.key) as string | number);\n const sign = sort.direction === 'ascending' ? 1 : -1;\n // Empty values last whatever the direction; a stable sort keeps ties in their order.\n return [...rows].sort((a, b) => {\n const x = read(a);\n const y = read(b);\n if (x == null || x === '') return y == null || y === '' ? 0 : 1;\n if (y == null || y === '') return -1;\n const d =\n typeof x === 'number' && typeof y === 'number'\n ? x - y\n : collator.compare(String(x), String(y));\n return d * sign;\n });\n }, [rows, columns, sort, manualSort, locale]);\n\n const toggle = (key: string) =>\n setSort({\n key,\n direction: sort?.key === key && sort.direction === 'ascending' ? 'descending' : 'ascending',\n });\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-table', styled.className, className)}\n role=\"region\"\n aria-labelledby={captionId}\n tabIndex={0}\n {...root}\n >\n {part('table', 'table', {\n className: 'slurp-table-table',\n children: (\n <>\n {part('caption', 'caption', {\n id: captionId,\n className: cx('slurp-table-caption', hideCaption && 'slurp-visually-hidden'),\n children: caption,\n })}\n {columns.some((c) => c.width != null) && (\n <colgroup>\n {columns.map((c) => (\n <col key={c.key} style={c.width != null ? { width: c.width } : undefined} />\n ))}\n </colgroup>\n )}\n <thead>\n <tr>\n {columns.map((c) => {\n const on = sort?.key === c.key ? sort.direction : undefined;\n return (\n <th\n key={c.key}\n scope=\"col\"\n className=\"slurp-table-head\"\n data-align={c.align ?? 'start'}\n aria-sort={on}\n >\n {c.sortable ? (\n <button\n type=\"button\"\n className=\"slurp-table-sort\"\n data-sorted={on ? '' : undefined}\n onClick={() => toggle(c.key)}\n >\n <span>{c.header}</span>\n <span className=\"slurp-table-sort-icon\" aria-hidden=\"true\">\n {on === 'ascending' ? (\n <ArrowUpIcon size={16} />\n ) : on === 'descending' ? (\n <ArrowDownIcon size={16} />\n ) : (\n <SortIcon size={16} />\n )}\n </span>\n </button>\n ) : (\n c.header\n )}\n </th>\n );\n })}\n </tr>\n </thead>\n <tbody>\n {sorted.length === 0 ? (\n <tr>\n <td className=\"slurp-table-empty\" colSpan={columns.length}>\n {labels.empty}\n </td>\n </tr>\n ) : (\n sorted.map((row, i) => (\n <tr key={rowKey ? rowKey(row as R, i) : i} className=\"slurp-table-row\">\n {columns.map((c) => {\n const Cell = c.rowHeader ? 'th' : 'td';\n const content = c.cell\n ? c.cell(row as R, i)\n : (field(row, c.key) as ReactNode);\n return (\n <Cell\n key={c.key}\n scope={c.rowHeader ? 'row' : undefined}\n className=\"slurp-table-cell\"\n data-align={c.align ?? 'start'}\n >\n {content}\n </Cell>\n );\n })}\n </tr>\n ))\n )}\n </tbody>\n </>\n ),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAuCA,MAAa,eAA4B,EAAE,OAAO,kBAAkB;AAuBpE,MAAM,SAAS,KAAU,QAA0B,IAAgC;;;;;AAMnF,SAAgB,MAA0D,OAAyB;CACjG,MAAM,EACJ,IACA,KACA,WACA,SACA,cAAc,OACd,SACA,MACA,QACA,MAAM,UACN,cAAc,MACd,cACA,aAAa,OACb,QAAQ,YACR,OACA,WACA,YACA,GAAG,SACD,cAAc,SAAS,KAA8B;CACzD,MAAM,SAAS;EAAE,GAAG;EAAc,GAAG;CAAW;CAChD,MAAM,CAAC,MAAM,WAAW,cAAgC;EACtD,OAAO;EACP,cAAc;EACd,UAAU;CACZ,CAAC;CACD,MAAM,EAAE,WAAW,SAAS;CAC5B,MAAM,YAAY,MAAM;CACxB,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,SAAS,QAAQ,GAAG;CAC1C,MAAM,EAAE,MAAM,UAAU,SAAS,SAAS;EAAE;EAAO;EAAW;CAAW,CAAC;CAC1E,MAAM,OAAO,iBAAiB,IAAI;CAElC,MAAM,SAAS,cAAc;EAC3B,MAAM,SAAS,QAAQ,QAAQ,MAAM,MAAM,EAAE,QAAQ,KAAK,GAAG;EAC7D,IAAI,cAAc,CAAC,QAAQ,CAAC,QAAQ,OAAO;EAC3C,MAAM,WAAW,IAAI,KAAK,SAAS,QAAQ;GAAE,SAAS;GAAM,aAAa;EAAO,CAAC;EACjF,MAAM,OAAO,OAAO,eAAe,MAAW,MAAM,GAAG,OAAO,GAAG;EACjE,MAAM,OAAO,KAAK,cAAc,cAAc,IAAI;EAElD,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,MAAM,GAAG,MAAM;GAC9B,MA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UAAA,EAAE,WACD,qBAAC,UAAD;QACE,MAAK;QACL,WAAU;QACV,eAAa,KAAK,KAAK,KAAA;QACvB,eAAe,OAAO,EAAE,GAAG;QAJ7B,UAAA,CAME,oBAAC,QAAD,EAAA,UAAO,EAAE,OAAa,CAAA,GACtB,oBAAC,QAAD;SAAM,WAAU;SAAwB,eAAY;SACjD,UAAA,OAAO,cACN,oBAAC,aAAD,EAAa,MAAM,GAAK,CAAA,IACtB,OAAO,eACT,oBAAC,eAAD,EAAe,MAAM,GAAK,CAAA,IAE1B,oBAAC,UAAD,EAAU,MAAM,GAAK,CAAA;QAEnB,CAAA,CACA;OAER,CAAA,IAAA,EAAE;MAEF,GA3BG,EAAE,GA2BL;KAER,CAAC,EACC,CAAA,EACC,CAAA;KACP,oBAAC,SAAD,EAAA,UACG,OAAO,WAAW,IACjB,oBAAC,MAAD,EAAA,UACE,oBAAC,MAAD;MAAI,WAAU;MAAoB,SAAS,QAAQ;MAChD,UAAA,OAAO;KACN,CAAA,EACF,CAAA,IAEJ,OAAO,KAAK,KAAK,MACf,oBAAC,MAAD;MAA2C,WAAU;MAClD,UAAA,QAAQ,KAAK,MAAM;OAClB,MAAM,OAAO,EAAE,YAAY,OAAO;OAClC,MAAM,UAAU,EAAE,OACd,EAAE,KAAK,KAAU,CAAC,IACjB,MAAM,KAAK,EAAE,GAAG;OACrB,OACE,oBAAC,MAAD;QAEE,OAAO,EAAE,YAAY,QAAQ,KAAA;QAC7B,WAAU;QACV,cAAY,EAAE,SAAS;QAEtB,UAAA;OACG,GANC,EAAE,GAMH;MAEV,CAAC;KACC,GAjBK,SAAS,OAAO,KAAU,CAAC,IAAI,CAiBpC,CACL,EAEE,CAAA;IACP,EAAA,CAAA;GAEN,CAAC;EACG,CAAA;CACN,EAAA,CAAA;AAEN"}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ import "./Bubble/index.js";
|
|
|
16
16
|
import "./Button/index.js";
|
|
17
17
|
import { Card, CardProps } from "./Card/Card.js";
|
|
18
18
|
import "./Card/index.js";
|
|
19
|
+
import { CAROUSEL_LABELS, Carousel, CarouselLabels, CarouselProps } from "./Carousel/Carousel.js";
|
|
20
|
+
import "./Carousel/index.js";
|
|
19
21
|
import { Cell, CellProps } from "./Cell/Cell.js";
|
|
20
22
|
import "./Cell/index.js";
|
|
21
23
|
import { Checkbox, CheckboxProps } from "./Checkbox/Checkbox.js";
|
|
@@ -57,6 +59,8 @@ import { Menu, MenuItem, MenuItemProps, MenuProps } from "./Menu/Menu.js";
|
|
|
57
59
|
import "./Menu/index.js";
|
|
58
60
|
import { NOTICE_LABELS, Notice, NoticeLabels, NoticeProps, StatusTone } from "./Notice/Notice.js";
|
|
59
61
|
import "./Notice/index.js";
|
|
62
|
+
import { PAGES_LABELS, PageItem, Pages, PagesLabels, PagesProps, pageItems } from "./Pages/Pages.js";
|
|
63
|
+
import "./Pages/index.js";
|
|
60
64
|
import { Placeholder, PlaceholderProps } from "./Placeholder/Placeholder.js";
|
|
61
65
|
import "./Placeholder/index.js";
|
|
62
66
|
import { Portal, PortalProps } from "./Portal/Portal.js";
|
|
@@ -67,6 +71,8 @@ import { Radio, RadioGroup, RadioGroupProps, RadioProps } from "./Radio/Radio.js
|
|
|
67
71
|
import "./Radio/index.js";
|
|
68
72
|
import { Range, RangeProps } from "./Range/Range.js";
|
|
69
73
|
import "./Range/index.js";
|
|
74
|
+
import { RATING_LABELS, Rating, RatingLabels, RatingProps } from "./Rating/Rating.js";
|
|
75
|
+
import "./Rating/index.js";
|
|
70
76
|
import { ResultRow, ResultRowProps } from "./ResultRow/ResultRow.js";
|
|
71
77
|
import "./ResultRow/index.js";
|
|
72
78
|
import { Score, ScoreProps } from "./Score/Score.js";
|
|
@@ -83,6 +89,9 @@ import { Shelf, ShelfProps } from "./Shelf/Shelf.js";
|
|
|
83
89
|
import "./Shelf/index.js";
|
|
84
90
|
import { Stage, StageProps } from "./Stage/Stage.js";
|
|
85
91
|
import { Tile, TileProps } from "./Tile/Tile.js";
|
|
92
|
+
import { STEPS_LABELS, StepItem, Steps, StepsLabels, StepsProps } from "./Steps/Steps.js";
|
|
93
|
+
import { SUGGEST_LABELS, Suggest, SuggestLabels, SuggestOption, SuggestProps } from "./Suggest/Suggest.js";
|
|
94
|
+
import { TABLE_LABELS, Table, TableColumn, TableLabels, TableProps, TableSort } from "./Table/Table.js";
|
|
86
95
|
import { Surface, SurfaceProps } from "./Surface/Surface.js";
|
|
87
96
|
import { Swatch, SwatchGroup, SwatchGroupProps, SwatchOption, SwatchProps } from "./Swatch/Swatch.js";
|
|
88
97
|
import { Switch, SwitchProps } from "./Switch/Switch.js";
|
|
@@ -94,9 +103,12 @@ import { ColorSchemeScript, ColorSchemeScriptProps } from "./SlurpProvider/Color
|
|
|
94
103
|
import { ColorSchemeState, useColorScheme, useTheme } from "./internal/context.js";
|
|
95
104
|
import "./SlurpProvider/index.js";
|
|
96
105
|
import "./Stage/index.js";
|
|
106
|
+
import "./Steps/index.js";
|
|
107
|
+
import "./Suggest/index.js";
|
|
97
108
|
import "./Surface/index.js";
|
|
98
109
|
import "./Swatch/index.js";
|
|
99
110
|
import "./Switch/index.js";
|
|
111
|
+
import "./Table/index.js";
|
|
100
112
|
import "./Tabs/index.js";
|
|
101
113
|
import "./Text/index.js";
|
|
102
114
|
import "./Tile/index.js";
|
|
@@ -118,4 +130,4 @@ import { COMPACT_QUERY, useMediaQuery } from "./utils/useMediaQuery.js";
|
|
|
118
130
|
import { RovingFocusOptions, useRovingFocus } from "./utils/useRovingFocus.js";
|
|
119
131
|
import { FindInPage, focusHit, useFindInPage } from "./utils/useFindInPage.js";
|
|
120
132
|
import "./utils/index.js";
|
|
121
|
-
export { type AccentInput, AccentScope, type AccentScopeProps, AnimationGroup, type AnimationGroupProps, type AnimationProps, type Appearance, Avatar, type AvatarProps, type BaseProps, Bento, type BentoItem, type BentoProps, type BentoSpan, Bloom, type BloomPlacement, type BloomProps, Bubble, type BubbleProps, Button, type ButtonProps, type ButtonTone, CHOICE_LABELS, COMPACT_QUERY, CONTRAST_MIN, Card, type CardProps, Cell, type CellProps, Checkbox, type CheckboxProps, Chip, type ChipProps, Choice, type ChoiceLabels, type ChoiceOption, type ChoiceProps, type ColorSchemeMode, ColorSchemeScript, type ColorSchemeScriptProps, type ColorSchemeState, type ColorValue, type ComponentsConfig, type ContentRef, type ControlSize, type ControlledOptions, Count, type CountProps, type CrumbEnd, DEFAULT_STORAGE_KEY, DIALOG_LABELS, DOCK_LABELS, Dialog, type DialogLabels, type DialogProps, type DismissOptions, Dock, type DockActionProps, type DockBackProps, type DockCrumbProps, type DockCrumbsProps, type DockLabels, type DockProps, type DockSearchProps, Empty, type EmptyProps, FILTERS_LABELS, FOCUSABLE, Fact, type FactProps, Field, type FieldProps, Filters, type FiltersGroupProps, type FiltersLabels, type FiltersProps, type FindInPage, Flow, type FlowProps, Fold, type FoldProps, Frame, type FrameProps, Ground, Hint, type HintProps, Link, type LinkProps, List, type ListProps, ListRow, type ListRowProps, Mark, type MarkProps, type MaybeResponsive, Menu, MenuItem, type MenuItemProps, type MenuProps, type MotionOptions, type MoveFocusOptions, NOTICE_LABELS, Notice, type NoticeLabels, type NoticeProps, Placeholder, type PlaceholderProps, type PolymorphicProps, Portal, type PortalProps, Progress, type ProgressProps, Radio, RadioGroup, type RadioGroupProps, type RadioProps, type RadiusValue, Range, type RangeProps, type ResolvedColorScheme, type Responsive, ResultRow, type ResultRowProps, type RovingFocusOptions, SEARCH_LABELS, SETTINGS_LABELS, Score, type ScoreProps, Search, type SearchLabels, type SearchProps, Segmented, type SegmentedOption, type SegmentedProps, Settings, type SettingsLabels, type SettingsLanguage, type SettingsProps, Sheet, type SheetProps, Shelf, type ShelfProps, type SlurpControls, type SlurpCss, type SlurpEnterOptions, type SlurpNavigate, type SlurpNavigateOptions, SlurpProvider, type SlurpProviderProps, type SpaceValue, Stage, type StageProps, type StatusTone, Surface, type SurfaceProps, Swatch, SwatchGroup, type SwatchGroupProps, type SwatchOption, type SwatchProps, Switch, type SwitchProps, TOAST_LABELS, type TabItem, Tabs, type TabsProps, Text, type TextProps, type TextTone, type Theme, type ThemeOptions, Tile, type TileProps, type ToastLabels, type ToastOptions, ToastProvider, type ToastProviderProps, type TokenOverrides, VisuallyHidden, type VisuallyHiddenProps, alpha, bentoLayout, contrast, createTheme, crumbPath, focusFirst, focusHit, matchRanges, matchesAll, meetsContrast, moveFocus, normalizeText, onColor, useAnimationTarget, useColorScheme, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus, useSlurp, useSlurpEnter, useSlurpNavigate, useTheme, useToast, vivid };
|
|
133
|
+
export { type AccentInput, AccentScope, type AccentScopeProps, AnimationGroup, type AnimationGroupProps, type AnimationProps, type Appearance, Avatar, type AvatarProps, type BaseProps, Bento, type BentoItem, type BentoProps, type BentoSpan, Bloom, type BloomPlacement, type BloomProps, Bubble, type BubbleProps, Button, type ButtonProps, type ButtonTone, CAROUSEL_LABELS, CHOICE_LABELS, COMPACT_QUERY, CONTRAST_MIN, Card, type CardProps, Carousel, type CarouselLabels, type CarouselProps, Cell, type CellProps, Checkbox, type CheckboxProps, Chip, type ChipProps, Choice, type ChoiceLabels, type ChoiceOption, type ChoiceProps, type ColorSchemeMode, ColorSchemeScript, type ColorSchemeScriptProps, type ColorSchemeState, type ColorValue, type ComponentsConfig, type ContentRef, type ControlSize, type ControlledOptions, Count, type CountProps, type CrumbEnd, DEFAULT_STORAGE_KEY, DIALOG_LABELS, DOCK_LABELS, Dialog, type DialogLabels, type DialogProps, type DismissOptions, Dock, type DockActionProps, type DockBackProps, type DockCrumbProps, type DockCrumbsProps, type DockLabels, type DockProps, type DockSearchProps, Empty, type EmptyProps, FILTERS_LABELS, FOCUSABLE, Fact, type FactProps, Field, type FieldProps, Filters, type FiltersGroupProps, type FiltersLabels, type FiltersProps, type FindInPage, Flow, type FlowProps, Fold, type FoldProps, Frame, type FrameProps, Ground, Hint, type HintProps, Link, type LinkProps, List, type ListProps, ListRow, type ListRowProps, Mark, type MarkProps, type MaybeResponsive, Menu, MenuItem, type MenuItemProps, type MenuProps, type MotionOptions, type MoveFocusOptions, NOTICE_LABELS, Notice, type NoticeLabels, type NoticeProps, PAGES_LABELS, type PageItem, Pages, type PagesLabels, type PagesProps, Placeholder, type PlaceholderProps, type PolymorphicProps, Portal, type PortalProps, Progress, type ProgressProps, RATING_LABELS, Radio, RadioGroup, type RadioGroupProps, type RadioProps, type RadiusValue, Range, type RangeProps, Rating, type RatingLabels, type RatingProps, type ResolvedColorScheme, type Responsive, ResultRow, type ResultRowProps, type RovingFocusOptions, SEARCH_LABELS, SETTINGS_LABELS, STEPS_LABELS, SUGGEST_LABELS, Score, type ScoreProps, Search, type SearchLabels, type SearchProps, Segmented, type SegmentedOption, type SegmentedProps, Settings, type SettingsLabels, type SettingsLanguage, type SettingsProps, Sheet, type SheetProps, Shelf, type ShelfProps, type SlurpControls, type SlurpCss, type SlurpEnterOptions, type SlurpNavigate, type SlurpNavigateOptions, SlurpProvider, type SlurpProviderProps, type SpaceValue, Stage, type StageProps, type StatusTone, type StepItem, Steps, type StepsLabels, type StepsProps, Suggest, type SuggestLabels, type SuggestOption, type SuggestProps, Surface, type SurfaceProps, Swatch, SwatchGroup, type SwatchGroupProps, type SwatchOption, type SwatchProps, Switch, type SwitchProps, TABLE_LABELS, TOAST_LABELS, type TabItem, Table, type TableColumn, type TableLabels, type TableProps, type TableSort, Tabs, type TabsProps, Text, type TextProps, type TextTone, type Theme, type ThemeOptions, Tile, type TileProps, type ToastLabels, type ToastOptions, ToastProvider, type ToastProviderProps, type TokenOverrides, VisuallyHidden, type VisuallyHiddenProps, alpha, bentoLayout, contrast, createTheme, crumbPath, focusFirst, focusHit, matchRanges, matchesAll, meetsContrast, moveFocus, normalizeText, onColor, pageItems, useAnimationTarget, useColorScheme, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus, useSlurp, useSlurpEnter, useSlurpNavigate, useTheme, useToast, vivid };
|
package/dist/index.js
CHANGED
|
@@ -65,5 +65,11 @@ import { COMPACT_QUERY, useMediaQuery } from "./utils/useMediaQuery.js";
|
|
|
65
65
|
import { DOCK_LABELS, Dock } from "./Dock/Dock.js";
|
|
66
66
|
import { SETTINGS_LABELS, Settings } from "./Settings/Settings.js";
|
|
67
67
|
import { FILTERS_LABELS, Filters } from "./Filters/Filters.js";
|
|
68
|
+
import { SUGGEST_LABELS, Suggest } from "./Suggest/Suggest.js";
|
|
69
|
+
import { PAGES_LABELS, Pages, pageItems } from "./Pages/Pages.js";
|
|
70
|
+
import { STEPS_LABELS, Steps } from "./Steps/Steps.js";
|
|
71
|
+
import { RATING_LABELS, Rating } from "./Rating/Rating.js";
|
|
72
|
+
import { TABLE_LABELS, Table } from "./Table/Table.js";
|
|
73
|
+
import { CAROUSEL_LABELS, Carousel } from "./Carousel/Carousel.js";
|
|
68
74
|
import { focusHit, useFindInPage } from "./utils/useFindInPage.js";
|
|
69
|
-
export { AccentScope, AnimationGroup, Avatar, Bento, Bloom, Bubble, Button, CHOICE_LABELS, COMPACT_QUERY, CONTRAST_MIN, Card, Cell, Checkbox, Chip, Choice, ColorSchemeScript, Count, DEFAULT_STORAGE_KEY, DIALOG_LABELS, DOCK_LABELS, Dialog, Dock, Empty, FILTERS_LABELS, FOCUSABLE, Fact, Field, Filters, Flow, Fold, Frame, Ground, Hint, Link, List, ListRow, Mark, Menu, MenuItem, NOTICE_LABELS, Notice, Placeholder, Portal, Progress, Radio, RadioGroup, Range, ResultRow, SEARCH_LABELS, SETTINGS_LABELS, Score, Search, Segmented, Settings, Sheet, Shelf, SlurpProvider, Stage, Surface, Swatch, SwatchGroup, Switch, TOAST_LABELS, Tabs, Text, Tile, ToastProvider, VisuallyHidden, alpha, bentoLayout, contrast, createTheme, crumbPath, focusFirst, focusHit, matchRanges, matchesAll, meetsContrast, moveFocus, normalizeText, onColor, useAnimationTarget, useColorScheme, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus, useSlurp, useSlurpEnter, useSlurpNavigate, useTheme, useToast, vivid };
|
|
75
|
+
export { AccentScope, AnimationGroup, Avatar, Bento, Bloom, Bubble, Button, CAROUSEL_LABELS, CHOICE_LABELS, COMPACT_QUERY, CONTRAST_MIN, Card, Carousel, Cell, Checkbox, Chip, Choice, ColorSchemeScript, Count, DEFAULT_STORAGE_KEY, DIALOG_LABELS, DOCK_LABELS, Dialog, Dock, Empty, FILTERS_LABELS, FOCUSABLE, Fact, Field, Filters, Flow, Fold, Frame, Ground, Hint, Link, List, ListRow, Mark, Menu, MenuItem, NOTICE_LABELS, Notice, PAGES_LABELS, Pages, Placeholder, Portal, Progress, RATING_LABELS, Radio, RadioGroup, Range, Rating, ResultRow, SEARCH_LABELS, SETTINGS_LABELS, STEPS_LABELS, SUGGEST_LABELS, Score, Search, Segmented, Settings, Sheet, Shelf, SlurpProvider, Stage, Steps, Suggest, Surface, Swatch, SwatchGroup, Switch, TABLE_LABELS, TOAST_LABELS, Table, Tabs, Text, Tile, ToastProvider, VisuallyHidden, alpha, bentoLayout, contrast, createTheme, crumbPath, focusFirst, focusHit, matchRanges, matchesAll, meetsContrast, moveFocus, normalizeText, onColor, pageItems, useAnimationTarget, useColorScheme, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus, useSlurp, useSlurpEnter, useSlurpNavigate, useTheme, useToast, vivid };
|
package/dist/lib/theme.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { BloomProps } from "../Bloom/Bloom.js";
|
|
|
7
7
|
import { ButtonProps } from "../Button/Button.js";
|
|
8
8
|
import { BubbleProps } from "../Bubble/Bubble.js";
|
|
9
9
|
import { CardProps } from "../Card/Card.js";
|
|
10
|
+
import { CarouselProps } from "../Carousel/Carousel.js";
|
|
10
11
|
import { CellProps } from "../Cell/Cell.js";
|
|
11
12
|
import { CheckboxProps } from "../Checkbox/Checkbox.js";
|
|
12
13
|
import { ChipProps } from "../Chip/Chip.js";
|
|
@@ -26,10 +27,12 @@ import { LinkProps } from "../Link/Link.js";
|
|
|
26
27
|
import { ListProps, ListRowProps } from "../ListRow/ListRow.js";
|
|
27
28
|
import { MenuProps } from "../Menu/Menu.js";
|
|
28
29
|
import { NoticeProps } from "../Notice/Notice.js";
|
|
30
|
+
import { PagesProps } from "../Pages/Pages.js";
|
|
29
31
|
import { PlaceholderProps } from "../Placeholder/Placeholder.js";
|
|
30
32
|
import { ProgressProps } from "../Progress/Progress.js";
|
|
31
33
|
import { RadioGroupProps, RadioProps } from "../Radio/Radio.js";
|
|
32
34
|
import { RangeProps } from "../Range/Range.js";
|
|
35
|
+
import { RatingProps } from "../Rating/Rating.js";
|
|
33
36
|
import { ResultRowProps } from "../ResultRow/ResultRow.js";
|
|
34
37
|
import { ScoreProps } from "../Score/Score.js";
|
|
35
38
|
import { SearchProps } from "../Search/Search.js";
|
|
@@ -39,6 +42,9 @@ import { SheetProps } from "../Sheet/Sheet.js";
|
|
|
39
42
|
import { ShelfProps } from "../Shelf/Shelf.js";
|
|
40
43
|
import { StageProps } from "../Stage/Stage.js";
|
|
41
44
|
import { TileProps } from "../Tile/Tile.js";
|
|
45
|
+
import { StepsProps } from "../Steps/Steps.js";
|
|
46
|
+
import { SuggestProps } from "../Suggest/Suggest.js";
|
|
47
|
+
import { TableProps } from "../Table/Table.js";
|
|
42
48
|
import { SurfaceProps } from "../Surface/Surface.js";
|
|
43
49
|
import { SwatchGroupProps, SwatchProps } from "../Swatch/Swatch.js";
|
|
44
50
|
import { SwitchProps } from "../Switch/Switch.js";
|
|
@@ -258,6 +264,30 @@ export interface ThemeComponents {
|
|
|
258
264
|
props: TextProps;
|
|
259
265
|
parts: 'root';
|
|
260
266
|
};
|
|
267
|
+
Suggest: {
|
|
268
|
+
props: SuggestProps;
|
|
269
|
+
parts: 'root' | 'label' | 'control' | 'list' | 'option' | 'hint' | 'error';
|
|
270
|
+
};
|
|
271
|
+
Pages: {
|
|
272
|
+
props: PagesProps;
|
|
273
|
+
parts: 'root' | 'list' | 'item' | 'previous' | 'next' | 'status';
|
|
274
|
+
};
|
|
275
|
+
Steps: {
|
|
276
|
+
props: StepsProps;
|
|
277
|
+
parts: 'root' | 'list' | 'step';
|
|
278
|
+
};
|
|
279
|
+
Rating: {
|
|
280
|
+
props: RatingProps;
|
|
281
|
+
parts: 'root';
|
|
282
|
+
};
|
|
283
|
+
Table: {
|
|
284
|
+
props: TableProps;
|
|
285
|
+
parts: 'root' | 'table' | 'caption';
|
|
286
|
+
};
|
|
287
|
+
Carousel: {
|
|
288
|
+
props: CarouselProps;
|
|
289
|
+
parts: 'root' | 'track' | 'slide' | 'controls' | 'previous' | 'next' | 'dot';
|
|
290
|
+
};
|
|
261
291
|
}
|
|
262
292
|
export type ComponentName = keyof ThemeComponents;
|
|
263
293
|
export type ComponentsConfig = { [K in ComponentName]?: {
|
package/dist/lib/theme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","names":[],"sources":["../../src/lib/theme.ts"],"sourcesContent":["// createTheme() and the stylesheet that applies a theme. Server-safe: a theme is plain, serialisable data,\n// so it can be created in a server component and passed to <SlurpProvider>.\nimport { MOTION_DEFAULTS, type GhostKind, type SlurpDefaults } from '@slurp-ui/motion';\nimport type { blur, ColorToken, HueToken, RadiusToken, shadow, SpaceToken } from '@slurp-ui/tokens';\n\nimport type { AccentScopeProps } from '../AccentScope/AccentScope';\nimport type { BentoProps } from '../Bento/Bento';\nimport type { CardProps } from '../Card/Card';\nimport type { DockProps } from '../Dock/Dock';\nimport type { EmptyProps } from '../Empty/Empty';\nimport type { FactProps } from '../Fact/Fact';\nimport type { FiltersProps } from '../Filters/Filters';\nimport type { LinkProps } from '../Link/Link';\nimport type { ListProps, ListRowProps } from '../ListRow/ListRow';\nimport type { ResultRowProps } from '../ResultRow/ResultRow';\nimport type { ScoreProps } from '../Score/Score';\nimport type { SettingsProps } from '../Settings/Settings';\nimport type { ShelfProps } from '../Shelf/Shelf';\nimport type { StageProps } from '../Stage/Stage';\nimport type { TileProps } from '../Tile/Tile';\nimport type { AvatarProps } from '../Avatar/Avatar';\nimport type { BloomProps } from '../Bloom/Bloom';\nimport type { BubbleProps } from '../Bubble/Bubble';\nimport type { ButtonProps } from '../Button/Button';\nimport type { CellProps } from '../Cell/Cell';\nimport type { CheckboxProps } from '../Checkbox/Checkbox';\nimport type { ChipProps } from '../Chip/Chip';\nimport type { ChoiceProps } from '../Choice/Choice';\nimport type { CountProps } from '../Count/Count';\nimport type { DialogProps } from '../Dialog/Dialog';\nimport type { FieldProps } from '../Field/Field';\nimport type { FlowProps } from '../Flow/Flow';\nimport type { FoldProps } from '../Fold/Fold';\nimport type { FrameProps } from '../Frame/Frame';\nimport type { HintProps } from '../Hint/Hint';\nimport type { MenuProps } from '../Menu/Menu';\nimport type { NoticeProps } from '../Notice/Notice';\nimport type { PlaceholderProps } from '../Placeholder/Placeholder';\nimport type { ProgressProps } from '../Progress/Progress';\nimport type { RadioGroupProps, RadioProps } from '../Radio/Radio';\nimport type { RangeProps } from '../Range/Range';\nimport type { SearchProps } from '../Search/Search';\nimport type { SegmentedProps } from '../Segmented/Segmented';\nimport type { SheetProps } from '../Sheet/Sheet';\nimport type { SurfaceProps } from '../Surface/Surface';\nimport type { SwatchGroupProps, SwatchProps } from '../Swatch/Swatch';\nimport type { SwitchProps } from '../Switch/Switch';\nimport type { TabsProps } from '../Tabs/Tabs';\nimport type { TextProps } from '../Text/Text';\nimport { accentVars, resolveAccent } from './color';\nimport { hash, LAYER_ORDER, type SlurpCss } from './css';\n\nexport type ColorSchemeMode = 'light' | 'dark' | 'system';\nexport type ResolvedColorScheme = 'light' | 'dark';\n/** A `hue-*` preset (used as is) or any hex colour (turned into an accent with `vivid()`). */\nexport type AccentInput = `hue-${HueToken}` | `#${string}`;\n\ntype Themed = string | { light: string; dark: string };\ntype Length = string | number;\n\nexport interface TokenOverrides {\n color?: Partial<Record<ColorToken | `hue-${HueToken}`, Themed>>;\n space?: Partial<Record<SpaceToken, Length>>;\n radius?: Partial<Record<RadiusToken, Length>>;\n shadow?: Partial<Record<keyof typeof shadow, Themed>>;\n blur?: Partial<Record<keyof typeof blur, Length>>;\n}\n\n/** Defaults of the collapse / expand transitions started with useSlurp() (serialisable values only). */\nexport interface MotionOptions extends Pick<\n SlurpDefaults,\n 'duration' | 'stagger' | 'curve' | 'swell' | 'drop' | 'reducedMotion' | 'interrupt'\n> {\n goo: boolean | 'auto';\n ghost: GhostKind;\n order: 'distance' | 'dom';\n}\n\nconst { duration, stagger, curve, swell, drop, reducedMotion, interrupt } = MOTION_DEFAULTS;\nconst DEFAULT_MOTION: MotionOptions = {\n duration,\n stagger,\n curve,\n swell,\n drop,\n reducedMotion,\n interrupt,\n goo: 'auto',\n ghost: 'shape',\n order: 'distance',\n};\n\n/** Components that read defaults and `css` overrides from the theme, with their parts. */\nexport interface ThemeComponents {\n AccentScope: { props: AccentScopeProps; parts: 'root' };\n Bento: { props: BentoProps; parts: 'root' };\n Card: { props: CardProps; parts: 'root' | 'media' | 'badge' | 'title' | 'description' };\n Dock: { props: DockProps; parts: 'root' };\n Empty: { props: EmptyProps; parts: 'root' };\n Fact: { props: FactProps; parts: 'root' };\n Filters: { props: FiltersProps; parts: 'root' };\n Link: { props: LinkProps; parts: 'root' };\n List: { props: ListProps; parts: 'root' };\n ListRow: {\n props: ListRowProps;\n parts: 'root' | 'mark' | 'title' | 'tag' | 'meta' | 'value' | 'action';\n };\n ResultRow: { props: ResultRowProps; parts: 'root' };\n Score: { props: ScoreProps; parts: 'root' };\n Settings: { props: SettingsProps; parts: 'root' };\n Shelf: { props: ShelfProps; parts: 'root' };\n Stage: { props: StageProps; parts: 'root' };\n Tile: {\n props: TileProps;\n parts: 'root' | 'blob' | 'text' | 'title' | 'subtitle' | 'badge' | 'media';\n };\n Avatar: { props: AvatarProps; parts: 'root' };\n Bloom: { props: BloomProps; parts: 'root' | 'surface' | 'trigger' | 'panel' };\n Bubble: { props: BubbleProps; parts: 'root' };\n Button: { props: ButtonProps; parts: 'root' | 'icon' | 'label' | 'endIcon' };\n Cell: { props: CellProps; parts: 'root' };\n Checkbox: { props: CheckboxProps; parts: 'root' | 'input' | 'box' | 'label' };\n Chip: { props: ChipProps; parts: 'root' };\n Choice: { props: ChoiceProps; parts: 'root' };\n Count: { props: CountProps; parts: 'root' };\n Dialog: {\n props: DialogProps;\n parts: 'root' | 'header' | 'title' | 'description' | 'body' | 'footer' | 'close';\n };\n Field: { props: FieldProps; parts: 'root' | 'label' | 'control' | 'hint' | 'error' };\n Flow: { props: FlowProps; parts: 'root' };\n Fold: { props: FoldProps; parts: 'root' | 'heading' | 'trigger' | 'region' };\n Frame: { props: FrameProps; parts: 'root' };\n Hint: { props: HintProps; parts: 'root' };\n Menu: { props: MenuProps; parts: 'root' };\n Notice: { props: NoticeProps; parts: 'root' | 'icon' | 'title' | 'body' | 'dismiss' };\n Placeholder: { props: PlaceholderProps; parts: 'root' };\n Progress: { props: ProgressProps; parts: 'root' };\n Radio: { props: RadioProps; parts: 'root' | 'input' | 'dot' | 'label' };\n RadioGroup: { props: RadioGroupProps; parts: 'root' | 'legend' };\n Range: { props: RangeProps; parts: 'root' | 'label' | 'value' | 'control' };\n Search: { props: SearchProps; parts: 'root' | 'icon' | 'control' | 'clear' | 'status' };\n Segmented: { props: SegmentedProps; parts: 'root' | 'item' };\n Sheet: {\n props: SheetProps;\n parts: 'root' | 'header' | 'title' | 'description' | 'body' | 'footer' | 'close';\n };\n Surface: { props: SurfaceProps; parts: 'root' };\n Swatch: { props: SwatchProps; parts: 'root' };\n SwatchGroup: { props: SwatchGroupProps; parts: 'root' };\n Switch: { props: SwitchProps; parts: 'root' | 'input' | 'track' | 'thumb' | 'label' };\n Tabs: { props: TabsProps; parts: 'root' | 'list' | 'tab' | 'indicator' | 'panel' };\n Text: { props: TextProps; parts: 'root' };\n}\nexport type ComponentName = keyof ThemeComponents;\n\nexport type ComponentsConfig = {\n [K in ComponentName]?: {\n defaults?: Partial<Omit<ThemeComponents[K]['props'], 'ref' | 'children' | 'css'>>;\n css?: Partial<Record<ThemeComponents[K]['parts'], SlurpCss>>;\n };\n};\n\nexport interface ThemeOptions {\n /** Initial colour scheme, until the person chooses one (default `system`). */\n colorScheme?: ColorSchemeMode;\n /** Default `hue-violet`. */\n accent?: AccentInput;\n /** Used only by Intl (numbers, prices). Not an i18n system. Default `it-IT`. */\n locale?: string;\n tokens?: TokenOverrides;\n motion?: Partial<MotionOptions>;\n components?: ComponentsConfig;\n}\n\nexport interface Theme {\n colorScheme: ColorSchemeMode;\n accent: AccentInput;\n /** The accent actually painted (hex). */\n accentColor: string;\n locale: string;\n tokens: TokenOverrides;\n motion: MotionOptions;\n components: ComponentsConfig;\n}\n\nconst DEFAULT_ACCENT: AccentInput = 'hue-violet';\n\n/** localStorage key of the chosen colour scheme (same as the design system's setTheme()). */\nexport const DEFAULT_STORAGE_KEY = 'slurp-theme';\n\nexport function createTheme(options: ThemeOptions = {}): Theme {\n const accent = options.accent ?? DEFAULT_ACCENT;\n return {\n colorScheme: options.colorScheme ?? 'system',\n accent,\n accentColor: resolveAccent(accent),\n locale: options.locale ?? 'it-IT',\n tokens: options.tokens ?? {},\n motion: { ...DEFAULT_MOTION, ...options.motion },\n components: options.components ?? {},\n };\n}\n\nexport const defaultTheme: Theme = createTheme();\n\nconst px = (v: Length) => (typeof v === 'number' ? `${v}px` : v);\n\n/** Light / dark declarations of the token overrides of a theme. */\nfunction overrideDeclarations(tokens: TokenOverrides) {\n const light: string[] = [];\n const dark: string[] = [];\n const add = (name: string, v: Themed | number) => {\n if (typeof v === 'object') {\n light.push(`--slurp-${name}:${v.light}`);\n dark.push(`--slurp-${name}:${v.dark}`);\n } else light.push(`--slurp-${name}:${px(v)}`);\n };\n for (const [k, v] of Object.entries(tokens.color ?? {})) if (v !== undefined) add(k, v);\n for (const [k, v] of Object.entries(tokens.space ?? {}))\n if (v !== undefined) add(`space-${k}`, v);\n for (const [k, v] of Object.entries(tokens.radius ?? {}))\n if (v !== undefined) add(`radius-${k}`, v);\n for (const [k, v] of Object.entries(tokens.shadow ?? {}))\n if (v !== undefined) add(`shadow-${k}`, v);\n for (const [k, v] of Object.entries(tokens.blur ?? {})) if (v !== undefined) add(`blur-${k}`, v);\n return { light, dark };\n}\n\nfunction selectors(scope: string | undefined) {\n if (!scope) {\n return {\n base: ':root,[data-theme]',\n dark: \"[data-theme='dark']\",\n systemDark: \":root:not([data-theme='light'])\",\n };\n }\n const s = `[data-slurp-theme=\"${scope}\"]`;\n return {\n base: `${s},${s} [data-theme]`,\n dark: `:root[data-theme='dark'] ${s},${s} [data-theme='dark']`,\n systemDark: `:root:not([data-theme='light']) ${s}`,\n };\n}\n\n/**\n * The stylesheet of a theme: accent variables and token overrides, on the root (or on a nested provider's `scope`)\n * and on every `data-theme` subtree, so derived values re-resolve per theme. Empty for the default theme.\n * tokens.css uses `:where()`, so these plain selectors win whatever the stylesheet order.\n */\nexport function themeCss(theme: Theme, scope?: string): string {\n const { light, dark } = overrideDeclarations(theme.tokens);\n const accent =\n theme.accent === DEFAULT_ACCENT\n ? []\n : Object.entries(accentVars(theme.accentColor)).map(([k, v]) => `${k}:${v}`);\n const base = [...accent, ...light];\n if (!base.length && !dark.length) return '';\n const sel = selectors(scope);\n const rules = [`${sel.base}{${base.join(';')}}`];\n if (dark.length) {\n rules.push(\n `${sel.dark}{${dark.join(';')}}`,\n `@media (prefers-color-scheme: dark){${sel.systemDark}{${dark.join(';')}}}`,\n );\n }\n return `${LAYER_ORDER}@layer slurp.base{${rules.join('')}}`;\n}\n\n/** Stable id of a stylesheet, for React's <style href> de-duplication. */\nexport const styleId = (prefix: string, css: string) => `slurp-${prefix}-${hash(css)}`;\n"],"mappings":";;;;;AA8EA,MAAM,EAAE,UAAU,SAAS,OAAO,OAAO,MAAM,eAAe,cAAc;AAC5E,MAAM,iBAAgC;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA,KAAK;CACL,OAAO;CACP,OAAO;AACT;AAgGA,MAAM,iBAA8B;;AA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AC,GAAG,MAAM,OAAO,QAAQ,OAAO,QAAQ,CAAC,CAAC,GAAG,IAAI,MAAM,KAAA,GAAW,IAAI,QAAQ,KAAK,CAAC;CAC/F,OAAO;EAAE;EAAO;CAAK;AACvB;AAEA,SAAS,UAAU,OAA2B;CAC5C,IAAI,CAAC,OACH,OAAO;EACL,MAAM;EACN,MAAM;EACN,YAAY;CACd;CAEF,MAAM,IAAI,sBAAsB,MAAM;CACtC,OAAO;EACL,MAAM,GAAG,EAAE,GAAG,EAAE;EAChB,MAAM,4BAA4B,EAAE,GAAG,EAAE;EACzC,YAAY,mCAAmC;CACjD;AACF;;;;;;AAOA,SAAgB,SAAS,OAAc,OAAwB;CAC7D,MAAM,EAAE,OAAO,SAAS,qBAAqB,MAAM,MAAM;CAKzD,MAAM,OAAO,CAAC,GAHZ,MAAM,WAAW,iBACb,CAAC,IACD,OAAO,QAAQ,WAAW,MAAM,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,GAAG,GACtD,GAAG,KAAK;CACjC,IAAI,CAAC,KAAK,UAAU,CAAC,KAAK,QAAQ,OAAO;CACzC,MAAM,MAAM,UAAU,KAAK;CAC3B,MAAM,QAAQ,CAAC,GAAG,IAAI,KAAK,GAAG,KAAK,KAAK,GAAG,EAAE,EAAE;CAC/C,IAAI,KAAK,QACP,MAAM,KACJ,GAAG,IAAI,KAAK,GAAG,KAAK,KAAK,GAAG,EAAE,IAC9B,uCAAuC,IAAI,WAAW,GAAG,KAAK,KAAK,GAAG,EAAE,GAC1E;CAEF,OAAO,GAAG,YAAY,oBAAoB,MAAM,KAAK,EAAE,EAAE;AAC3D;;AAGA,MAAa,WAAW,QAAgB,QAAgB,SAAS,OAAO,GAAG,KAAK,GAAG"}
|
|
1
|
+
{"version":3,"file":"theme.js","names":[],"sources":["../../src/lib/theme.ts"],"sourcesContent":["// createTheme() and the stylesheet that applies a theme. Server-safe: a theme is plain, serialisable data,\n// so it can be created in a server component and passed to <SlurpProvider>.\nimport { MOTION_DEFAULTS, type GhostKind, type SlurpDefaults } from '@slurp-ui/motion';\nimport type { blur, ColorToken, HueToken, RadiusToken, shadow, SpaceToken } from '@slurp-ui/tokens';\n\nimport type { AccentScopeProps } from '../AccentScope/AccentScope';\nimport type { BentoProps } from '../Bento/Bento';\nimport type { CardProps } from '../Card/Card';\nimport type { DockProps } from '../Dock/Dock';\nimport type { EmptyProps } from '../Empty/Empty';\nimport type { FactProps } from '../Fact/Fact';\nimport type { FiltersProps } from '../Filters/Filters';\nimport type { LinkProps } from '../Link/Link';\nimport type { ListProps, ListRowProps } from '../ListRow/ListRow';\nimport type { ResultRowProps } from '../ResultRow/ResultRow';\nimport type { ScoreProps } from '../Score/Score';\nimport type { SettingsProps } from '../Settings/Settings';\nimport type { ShelfProps } from '../Shelf/Shelf';\nimport type { StageProps } from '../Stage/Stage';\nimport type { TileProps } from '../Tile/Tile';\nimport type { CarouselProps } from '../Carousel/Carousel';\nimport type { PagesProps } from '../Pages/Pages';\nimport type { RatingProps } from '../Rating/Rating';\nimport type { StepsProps } from '../Steps/Steps';\nimport type { SuggestProps } from '../Suggest/Suggest';\nimport type { TableProps } from '../Table/Table';\nimport type { AvatarProps } from '../Avatar/Avatar';\nimport type { BloomProps } from '../Bloom/Bloom';\nimport type { BubbleProps } from '../Bubble/Bubble';\nimport type { ButtonProps } from '../Button/Button';\nimport type { CellProps } from '../Cell/Cell';\nimport type { CheckboxProps } from '../Checkbox/Checkbox';\nimport type { ChipProps } from '../Chip/Chip';\nimport type { ChoiceProps } from '../Choice/Choice';\nimport type { CountProps } from '../Count/Count';\nimport type { DialogProps } from '../Dialog/Dialog';\nimport type { FieldProps } from '../Field/Field';\nimport type { FlowProps } from '../Flow/Flow';\nimport type { FoldProps } from '../Fold/Fold';\nimport type { FrameProps } from '../Frame/Frame';\nimport type { HintProps } from '../Hint/Hint';\nimport type { MenuProps } from '../Menu/Menu';\nimport type { NoticeProps } from '../Notice/Notice';\nimport type { PlaceholderProps } from '../Placeholder/Placeholder';\nimport type { ProgressProps } from '../Progress/Progress';\nimport type { RadioGroupProps, RadioProps } from '../Radio/Radio';\nimport type { RangeProps } from '../Range/Range';\nimport type { SearchProps } from '../Search/Search';\nimport type { SegmentedProps } from '../Segmented/Segmented';\nimport type { SheetProps } from '../Sheet/Sheet';\nimport type { SurfaceProps } from '../Surface/Surface';\nimport type { SwatchGroupProps, SwatchProps } from '../Swatch/Swatch';\nimport type { SwitchProps } from '../Switch/Switch';\nimport type { TabsProps } from '../Tabs/Tabs';\nimport type { TextProps } from '../Text/Text';\nimport { accentVars, resolveAccent } from './color';\nimport { hash, LAYER_ORDER, type SlurpCss } from './css';\n\nexport type ColorSchemeMode = 'light' | 'dark' | 'system';\nexport type ResolvedColorScheme = 'light' | 'dark';\n/** A `hue-*` preset (used as is) or any hex colour (turned into an accent with `vivid()`). */\nexport type AccentInput = `hue-${HueToken}` | `#${string}`;\n\ntype Themed = string | { light: string; dark: string };\ntype Length = string | number;\n\nexport interface TokenOverrides {\n color?: Partial<Record<ColorToken | `hue-${HueToken}`, Themed>>;\n space?: Partial<Record<SpaceToken, Length>>;\n radius?: Partial<Record<RadiusToken, Length>>;\n shadow?: Partial<Record<keyof typeof shadow, Themed>>;\n blur?: Partial<Record<keyof typeof blur, Length>>;\n}\n\n/** Defaults of the collapse / expand transitions started with useSlurp() (serialisable values only). */\nexport interface MotionOptions extends Pick<\n SlurpDefaults,\n 'duration' | 'stagger' | 'curve' | 'swell' | 'drop' | 'reducedMotion' | 'interrupt'\n> {\n goo: boolean | 'auto';\n ghost: GhostKind;\n order: 'distance' | 'dom';\n}\n\nconst { duration, stagger, curve, swell, drop, reducedMotion, interrupt } = MOTION_DEFAULTS;\nconst DEFAULT_MOTION: MotionOptions = {\n duration,\n stagger,\n curve,\n swell,\n drop,\n reducedMotion,\n interrupt,\n goo: 'auto',\n ghost: 'shape',\n order: 'distance',\n};\n\n/** Components that read defaults and `css` overrides from the theme, with their parts. */\nexport interface ThemeComponents {\n AccentScope: { props: AccentScopeProps; parts: 'root' };\n Bento: { props: BentoProps; parts: 'root' };\n Card: { props: CardProps; parts: 'root' | 'media' | 'badge' | 'title' | 'description' };\n Dock: { props: DockProps; parts: 'root' };\n Empty: { props: EmptyProps; parts: 'root' };\n Fact: { props: FactProps; parts: 'root' };\n Filters: { props: FiltersProps; parts: 'root' };\n Link: { props: LinkProps; parts: 'root' };\n List: { props: ListProps; parts: 'root' };\n ListRow: {\n props: ListRowProps;\n parts: 'root' | 'mark' | 'title' | 'tag' | 'meta' | 'value' | 'action';\n };\n ResultRow: { props: ResultRowProps; parts: 'root' };\n Score: { props: ScoreProps; parts: 'root' };\n Settings: { props: SettingsProps; parts: 'root' };\n Shelf: { props: ShelfProps; parts: 'root' };\n Stage: { props: StageProps; parts: 'root' };\n Tile: {\n props: TileProps;\n parts: 'root' | 'blob' | 'text' | 'title' | 'subtitle' | 'badge' | 'media';\n };\n Avatar: { props: AvatarProps; parts: 'root' };\n Bloom: { props: BloomProps; parts: 'root' | 'surface' | 'trigger' | 'panel' };\n Bubble: { props: BubbleProps; parts: 'root' };\n Button: { props: ButtonProps; parts: 'root' | 'icon' | 'label' | 'endIcon' };\n Cell: { props: CellProps; parts: 'root' };\n Checkbox: { props: CheckboxProps; parts: 'root' | 'input' | 'box' | 'label' };\n Chip: { props: ChipProps; parts: 'root' };\n Choice: { props: ChoiceProps; parts: 'root' };\n Count: { props: CountProps; parts: 'root' };\n Dialog: {\n props: DialogProps;\n parts: 'root' | 'header' | 'title' | 'description' | 'body' | 'footer' | 'close';\n };\n Field: { props: FieldProps; parts: 'root' | 'label' | 'control' | 'hint' | 'error' };\n Flow: { props: FlowProps; parts: 'root' };\n Fold: { props: FoldProps; parts: 'root' | 'heading' | 'trigger' | 'region' };\n Frame: { props: FrameProps; parts: 'root' };\n Hint: { props: HintProps; parts: 'root' };\n Menu: { props: MenuProps; parts: 'root' };\n Notice: { props: NoticeProps; parts: 'root' | 'icon' | 'title' | 'body' | 'dismiss' };\n Placeholder: { props: PlaceholderProps; parts: 'root' };\n Progress: { props: ProgressProps; parts: 'root' };\n Radio: { props: RadioProps; parts: 'root' | 'input' | 'dot' | 'label' };\n RadioGroup: { props: RadioGroupProps; parts: 'root' | 'legend' };\n Range: { props: RangeProps; parts: 'root' | 'label' | 'value' | 'control' };\n Search: { props: SearchProps; parts: 'root' | 'icon' | 'control' | 'clear' | 'status' };\n Segmented: { props: SegmentedProps; parts: 'root' | 'item' };\n Sheet: {\n props: SheetProps;\n parts: 'root' | 'header' | 'title' | 'description' | 'body' | 'footer' | 'close';\n };\n Surface: { props: SurfaceProps; parts: 'root' };\n Swatch: { props: SwatchProps; parts: 'root' };\n SwatchGroup: { props: SwatchGroupProps; parts: 'root' };\n Switch: { props: SwitchProps; parts: 'root' | 'input' | 'track' | 'thumb' | 'label' };\n Tabs: { props: TabsProps; parts: 'root' | 'list' | 'tab' | 'indicator' | 'panel' };\n Text: { props: TextProps; parts: 'root' };\n Suggest: {\n props: SuggestProps;\n parts: 'root' | 'label' | 'control' | 'list' | 'option' | 'hint' | 'error';\n };\n Pages: { props: PagesProps; parts: 'root' | 'list' | 'item' | 'previous' | 'next' | 'status' };\n Steps: { props: StepsProps; parts: 'root' | 'list' | 'step' };\n Rating: { props: RatingProps; parts: 'root' };\n Table: { props: TableProps; parts: 'root' | 'table' | 'caption' };\n Carousel: {\n props: CarouselProps;\n parts: 'root' | 'track' | 'slide' | 'controls' | 'previous' | 'next' | 'dot';\n };\n}\nexport type ComponentName = keyof ThemeComponents;\n\nexport type ComponentsConfig = {\n [K in ComponentName]?: {\n defaults?: Partial<Omit<ThemeComponents[K]['props'], 'ref' | 'children' | 'css'>>;\n css?: Partial<Record<ThemeComponents[K]['parts'], SlurpCss>>;\n };\n};\n\nexport interface ThemeOptions {\n /** Initial colour scheme, until the person chooses one (default `system`). */\n colorScheme?: ColorSchemeMode;\n /** Default `hue-violet`. */\n accent?: AccentInput;\n /** Used only by Intl (numbers, prices). Not an i18n system. Default `it-IT`. */\n locale?: string;\n tokens?: TokenOverrides;\n motion?: Partial<MotionOptions>;\n components?: ComponentsConfig;\n}\n\nexport interface Theme {\n colorScheme: ColorSchemeMode;\n accent: AccentInput;\n /** The accent actually painted (hex). */\n accentColor: string;\n locale: string;\n tokens: TokenOverrides;\n motion: MotionOptions;\n components: ComponentsConfig;\n}\n\nconst DEFAULT_ACCENT: AccentInput = 'hue-violet';\n\n/** localStorage key of the chosen colour scheme (same as the design system's setTheme()). */\nexport const DEFAULT_STORAGE_KEY = 'slurp-theme';\n\nexport function createTheme(options: ThemeOptions = {}): Theme {\n const accent = options.accent ?? DEFAULT_ACCENT;\n return {\n colorScheme: options.colorScheme ?? 'system',\n accent,\n accentColor: resolveAccent(accent),\n locale: options.locale ?? 'it-IT',\n tokens: options.tokens ?? {},\n motion: { ...DEFAULT_MOTION, ...options.motion },\n components: options.components ?? {},\n };\n}\n\nexport const defaultTheme: Theme = createTheme();\n\nconst px = (v: Length) => (typeof v === 'number' ? `${v}px` : v);\n\n/** Light / dark declarations of the token overrides of a theme. */\nfunction overrideDeclarations(tokens: TokenOverrides) {\n const light: string[] = [];\n const dark: string[] = [];\n const add = (name: string, v: Themed | number) => {\n if (typeof v === 'object') {\n light.push(`--slurp-${name}:${v.light}`);\n dark.push(`--slurp-${name}:${v.dark}`);\n } else light.push(`--slurp-${name}:${px(v)}`);\n };\n for (const [k, v] of Object.entries(tokens.color ?? {})) if (v !== undefined) add(k, v);\n for (const [k, v] of Object.entries(tokens.space ?? {}))\n if (v !== undefined) add(`space-${k}`, v);\n for (const [k, v] of Object.entries(tokens.radius ?? {}))\n if (v !== undefined) add(`radius-${k}`, v);\n for (const [k, v] of Object.entries(tokens.shadow ?? {}))\n if (v !== undefined) add(`shadow-${k}`, v);\n for (const [k, v] of Object.entries(tokens.blur ?? {})) if (v !== undefined) add(`blur-${k}`, v);\n return { light, dark };\n}\n\nfunction selectors(scope: string | undefined) {\n if (!scope) {\n return {\n base: ':root,[data-theme]',\n dark: \"[data-theme='dark']\",\n systemDark: \":root:not([data-theme='light'])\",\n };\n }\n const s = `[data-slurp-theme=\"${scope}\"]`;\n return {\n base: `${s},${s} [data-theme]`,\n dark: `:root[data-theme='dark'] ${s},${s} [data-theme='dark']`,\n systemDark: `:root:not([data-theme='light']) ${s}`,\n };\n}\n\n/**\n * The stylesheet of a theme: accent variables and token overrides, on the root (or on a nested provider's `scope`)\n * and on every `data-theme` subtree, so derived values re-resolve per theme. Empty for the default theme.\n * tokens.css uses `:where()`, so these plain selectors win whatever the stylesheet order.\n */\nexport function themeCss(theme: Theme, scope?: string): string {\n const { light, dark } = overrideDeclarations(theme.tokens);\n const accent =\n theme.accent === DEFAULT_ACCENT\n ? []\n : Object.entries(accentVars(theme.accentColor)).map(([k, v]) => `${k}:${v}`);\n const base = [...accent, ...light];\n if (!base.length && !dark.length) return '';\n const sel = selectors(scope);\n const rules = [`${sel.base}{${base.join(';')}}`];\n if (dark.length) {\n rules.push(\n `${sel.dark}{${dark.join(';')}}`,\n `@media (prefers-color-scheme: dark){${sel.systemDark}{${dark.join(';')}}}`,\n );\n }\n return `${LAYER_ORDER}@layer slurp.base{${rules.join('')}}`;\n}\n\n/** Stable id of a stylesheet, for React's <style href> de-duplication. */\nexport const styleId = (prefix: string, css: string) => `slurp-${prefix}-${hash(css)}`;\n"],"mappings":";;;;;AAoFA,MAAM,EAAE,UAAU,SAAS,OAAO,OAAO,MAAM,eAAe,cAAc;AAC5E,MAAM,iBAAgC;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA,KAAK;CACL,OAAO;CACP,OAAO;AACT;AA4GA,MAAM,iBAA8B;;AAGpC,MAAa,sBAAsB;AAEnC,SAAgB,YAAY,UAAwB,CAAC,GAAU;CAC7D,MAAM,SAAS,QAAQ,UAAU;CACjC,OAAO;EACL,aAAa,QAAQ,eAAe;EACpC;EACA,aAAa,cAAc,MAAM;EACjC,QAAQ,QAAQ,UAAU;EAC1B,QAAQ,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