@yarcl/react 0.1.0 → 0.2.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/README.md +14 -2
- package/{src/apply.ts → dist/apply.d.ts} +4 -23
- package/dist/apply.js +37 -0
- package/dist/classes.d.ts +13 -0
- package/dist/classes.js +22 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +58 -0
- package/dist/color.js +49 -32
- package/dist/components/Accordion.d.ts +96 -0
- package/dist/components/Accordion.js +148 -0
- package/dist/components/Alert.d.ts +60 -0
- package/dist/components/Alert.js +61 -0
- package/dist/components/Avatar.d.ts +100 -0
- package/dist/components/Avatar.js +89 -0
- package/dist/components/Badge.d.ts +44 -0
- package/dist/components/Badge.js +43 -0
- package/dist/components/Breadcrumb.d.ts +77 -0
- package/dist/components/Breadcrumb.js +126 -0
- package/dist/components/Button.d.ts +18 -0
- package/dist/components/Button.js +33 -0
- package/dist/components/ButtonGroup.d.ts +29 -0
- package/dist/components/ButtonGroup.js +37 -0
- package/dist/components/Card.d.ts +36 -0
- package/dist/components/Card.js +26 -0
- package/dist/components/Checkbox.d.ts +28 -0
- package/dist/components/Checkbox.js +38 -0
- package/dist/components/Combobox.d.ts +75 -0
- package/dist/components/Combobox.js +362 -0
- package/dist/components/CommandPalette.d.ts +92 -0
- package/dist/components/CommandPalette.js +293 -0
- package/dist/components/DatePicker.d.ts +157 -0
- package/dist/components/DatePicker.js +230 -0
- package/dist/components/Dialog.d.ts +25 -0
- package/dist/components/Dialog.js +29 -0
- package/dist/components/Divider.d.ts +23 -0
- package/dist/components/Divider.js +25 -0
- package/dist/components/Drawer.d.ts +21 -0
- package/dist/components/Drawer.js +25 -0
- package/dist/components/EmptyState.d.ts +51 -0
- package/dist/components/EmptyState.js +47 -0
- package/dist/components/Field.d.ts +27 -0
- package/dist/components/Field.js +59 -0
- package/dist/components/Heading.d.ts +26 -0
- package/dist/components/Heading.js +25 -0
- package/dist/components/HoverCard.d.ts +47 -0
- package/dist/components/HoverCard.js +53 -0
- package/dist/components/IconButton.d.ts +19 -0
- package/dist/components/IconButton.js +32 -0
- package/dist/components/Inline.d.ts +21 -0
- package/dist/components/Inline.js +24 -0
- package/dist/components/Input.d.ts +19 -0
- package/dist/components/Input.js +25 -0
- package/dist/components/Label.d.ts +46 -0
- package/dist/components/Label.js +33 -0
- package/dist/components/Link.d.ts +27 -0
- package/dist/components/Link.js +26 -0
- package/dist/components/Menu.d.ts +73 -0
- package/dist/components/Menu.js +143 -0
- package/dist/components/Modal.d.ts +45 -0
- package/dist/components/Modal.js +110 -0
- package/dist/components/NumberInput.d.ts +49 -0
- package/dist/components/NumberInput.js +130 -0
- package/dist/components/Pagination.d.ts +86 -0
- package/dist/components/Pagination.js +119 -0
- package/dist/components/Popover.d.ts +72 -0
- package/dist/components/Popover.js +87 -0
- package/dist/components/Progress.d.ts +60 -0
- package/dist/components/Progress.js +59 -0
- package/dist/components/Radio.d.ts +32 -0
- package/dist/components/Radio.js +47 -0
- package/dist/components/RadioGroup.d.ts +57 -0
- package/dist/components/RadioGroup.js +68 -0
- package/dist/components/Select.d.ts +47 -0
- package/dist/components/Select.js +138 -0
- package/dist/components/Skeleton.d.ts +46 -0
- package/dist/components/Skeleton.js +40 -0
- package/dist/components/Slider.d.ts +126 -0
- package/dist/components/Slider.js +166 -0
- package/dist/components/Spinner.d.ts +23 -0
- package/dist/components/Spinner.js +23 -0
- package/dist/components/Stack.d.ts +35 -0
- package/dist/components/Stack.js +24 -0
- package/dist/components/Switch.d.ts +27 -0
- package/dist/components/Switch.js +33 -0
- package/dist/components/Table.d.ts +71 -0
- package/dist/components/Table.js +61 -0
- package/dist/components/Tabs.d.ts +66 -0
- package/dist/components/Tabs.js +109 -0
- package/dist/components/Text.d.ts +32 -0
- package/dist/components/Text.js +28 -0
- package/dist/components/Textarea.d.ts +15 -0
- package/dist/components/Textarea.js +24 -0
- package/dist/components/Toast.d.ts +90 -0
- package/dist/components/Toast.js +156 -0
- package/dist/components/ToggleGroup.d.ts +79 -0
- package/dist/components/ToggleGroup.js +101 -0
- package/dist/components/Tooltip.d.ts +46 -0
- package/dist/components/Tooltip.js +62 -0
- package/dist/components/VisuallyHidden.d.ts +18 -0
- package/dist/components/VisuallyHidden.js +22 -0
- package/dist/contrast.d.ts +32 -0
- package/dist/css.d.ts +2 -2
- package/dist/css.js +193 -157
- package/dist/define.d.ts +40 -15
- package/dist/define.js +30 -27
- package/dist/demo.d.ts +2 -0
- package/dist/demo.js +2 -0
- package/dist/esbuild.cjs +5 -0
- package/dist/esbuild.d.ts +4 -0
- package/dist/esbuild.js +6 -0
- package/dist/field-context.d.ts +16 -0
- package/dist/field-context.js +17 -0
- package/dist/floating.d.ts +12 -0
- package/dist/floating.js +52 -0
- package/dist/hooks.d.ts +1 -0
- package/dist/hooks.js +12 -0
- package/{src/index.ts → dist/index.d.ts} +11 -33
- package/dist/index.js +50 -0
- package/dist/init.d.ts +18 -0
- package/dist/init.js +224 -0
- package/dist/plugin.d.ts +10 -26
- package/dist/plugin.js +152 -78
- package/dist/reference/DemoYarcl.d.ts +12 -0
- package/dist/reference/DemoYarcl.js +312 -0
- package/dist/reference/DesignReference.d.ts +24 -0
- package/dist/reference/DesignReference.js +403 -0
- package/dist/reference/index.js +2 -0
- package/dist/rollup.cjs +5 -0
- package/dist/rollup.d.ts +4 -0
- package/dist/rollup.js +6 -0
- package/dist/rspack.cjs +5 -0
- package/dist/rspack.d.ts +4 -0
- package/dist/rspack.js +6 -0
- package/dist/runtime.d.ts +13 -0
- package/dist/runtime.js +30 -0
- package/dist/setup.d.ts +6 -0
- package/dist/setup.js +33 -0
- package/{src → dist}/styles.css +224 -106
- package/dist/themes/bloom.d.ts +295 -0
- package/dist/themes/bloom.js +202 -0
- package/dist/themes/brutalist.d.ts +277 -0
- package/dist/themes/brutalist.js +199 -0
- package/dist/themes/compact.d.ts +274 -0
- package/dist/themes/compact.js +200 -0
- package/dist/themes/contract.d.ts +23 -0
- package/dist/themes/editorial.d.ts +277 -0
- package/dist/themes/editorial.js +183 -0
- package/dist/themes/index.d.ts +1425 -0
- package/dist/themes/index.js +45 -0
- package/{src/types.ts → dist/types.d.ts} +40 -37
- package/dist/vite.cjs +5 -0
- package/dist/vite.d.ts +4 -0
- package/dist/vite.js +6 -0
- package/dist/webpack.cjs +5 -0
- package/dist/webpack.d.ts +4 -0
- package/dist/webpack.js +6 -0
- package/dist/yarcl.config.d.ts +276 -0
- package/dist/yarcl.config.js +273 -0
- package/package.json +69 -17
- package/src/classes.ts +0 -23
- package/src/color.ts +0 -48
- package/src/components/Accordion.tsx +0 -274
- package/src/components/Alert.tsx +0 -85
- package/src/components/Badge.tsx +0 -79
- package/src/components/Breadcrumb.tsx +0 -239
- package/src/components/Button.tsx +0 -58
- package/src/components/ButtonGroup.tsx +0 -61
- package/src/components/Card.tsx +0 -50
- package/src/components/Checkbox.tsx +0 -49
- package/src/components/Combobox.tsx +0 -522
- package/src/components/CommandPalette.tsx +0 -452
- package/src/components/DatePicker.tsx +0 -432
- package/src/components/Dialog.tsx +0 -39
- package/src/components/Divider.tsx +0 -34
- package/src/components/Drawer.tsx +0 -31
- package/src/components/Field.tsx +0 -61
- package/src/components/Heading.tsx +0 -40
- package/src/components/HoverCard.tsx +0 -108
- package/src/components/IconButton.tsx +0 -59
- package/src/components/Inline.tsx +0 -42
- package/src/components/Input.tsx +0 -28
- package/src/components/Label.tsx +0 -58
- package/src/components/Link.tsx +0 -41
- package/src/components/Menu.tsx +0 -207
- package/src/components/Modal.tsx +0 -164
- package/src/components/NumberInput.tsx +0 -208
- package/src/components/Pagination.tsx +0 -227
- package/src/components/Popover.tsx +0 -140
- package/src/components/Progress.tsx +0 -122
- package/src/components/Radio.tsx +0 -59
- package/src/components/RadioGroup.tsx +0 -114
- package/src/components/Select.tsx +0 -197
- package/src/components/Skeleton.tsx +0 -95
- package/src/components/Slider.tsx +0 -315
- package/src/components/Spinner.tsx +0 -38
- package/src/components/Stack.tsx +0 -57
- package/src/components/Switch.tsx +0 -42
- package/src/components/Table.tsx +0 -99
- package/src/components/Tabs.tsx +0 -159
- package/src/components/Text.tsx +0 -67
- package/src/components/Textarea.tsx +0 -26
- package/src/components/Toast.tsx +0 -190
- package/src/components/ToggleGroup.tsx +0 -227
- package/src/components/Tooltip.tsx +0 -78
- package/src/contrast.ts +0 -82
- package/src/css.ts +0 -228
- package/src/define.check.ts +0 -259
- package/src/define.ts +0 -379
- package/src/field-context.ts +0 -31
- package/src/floating.tsx +0 -61
- package/src/hooks.ts +0 -19
- package/src/plugin.ts +0 -94
- package/src/reference/DesignReference.tsx +0 -374
- package/src/runtime.ts +0 -38
- package/src/themes/bloom.ts +0 -72
- package/src/themes/brutalist.ts +0 -63
- package/src/themes/compact.ts +0 -63
- package/src/themes/contract.ts +0 -24
- package/src/themes/editorial.ts +0 -55
- package/src/themes/index.ts +0 -47
- package/src/yarcl.config.ts +0 -104
- /package/{src/reference/index.ts → dist/reference/index.d.ts} +0 -0
- /package/{src → dist}/reference/reference.css +0 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { useConfig } from "../runtime.js";
|
|
2
|
+
import { Button } from "../components/Button.js";
|
|
3
|
+
import { IconButton } from "../components/IconButton.js";
|
|
4
|
+
import { Input } from "../components/Input.js";
|
|
5
|
+
import { Text } from "../components/Text.js";
|
|
6
|
+
import { Heading } from "../components/Heading.js";
|
|
7
|
+
import { Stack } from "../components/Stack.js";
|
|
8
|
+
import { Inline } from "../components/Inline.js";
|
|
9
|
+
import { Card } from "../components/Card.js";
|
|
10
|
+
import { Table } from "../components/Table.js";
|
|
11
|
+
import { contrast, parseHex, readableOn } from "../color.js";
|
|
12
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
import "./reference.css";
|
|
14
|
+
//#region src/reference/DesignReference.tsx
|
|
15
|
+
var keys = (group) => Object.keys(group);
|
|
16
|
+
function ratio(background, token, mode) {
|
|
17
|
+
const bg = parseHex(background);
|
|
18
|
+
if (!bg) return "n/a";
|
|
19
|
+
const onValue = typeof token.on === "string" ? token.on : token.on?.[mode];
|
|
20
|
+
const fg = parseHex(onValue ?? readableOn(bg));
|
|
21
|
+
return fg ? `${contrast(bg, fg).toFixed(1)}:1` : "n/a";
|
|
22
|
+
}
|
|
23
|
+
function Section({ title, description, children }) {
|
|
24
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
25
|
+
as: "section",
|
|
26
|
+
className: "yarcl-ref-section",
|
|
27
|
+
children: [
|
|
28
|
+
/* @__PURE__ */ jsx(Heading, {
|
|
29
|
+
level: 2,
|
|
30
|
+
children: title
|
|
31
|
+
}),
|
|
32
|
+
description != null && /* @__PURE__ */ jsx(Text, {
|
|
33
|
+
as: "p",
|
|
34
|
+
muted: true,
|
|
35
|
+
children: description
|
|
36
|
+
}),
|
|
37
|
+
children
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function Code({ children }) {
|
|
42
|
+
return /* @__PURE__ */ jsx("code", {
|
|
43
|
+
className: "yarcl-ref-code",
|
|
44
|
+
children
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function KeyValues({ caption, rows }) {
|
|
48
|
+
const config = useConfig();
|
|
49
|
+
return /* @__PURE__ */ jsx(Table, {
|
|
50
|
+
caption,
|
|
51
|
+
density: config.defaults.density,
|
|
52
|
+
children: /* @__PURE__ */ jsx(Table.Body, { children: rows.map(([key, value]) => /* @__PURE__ */ jsxs(Table.Row, { children: [/* @__PURE__ */ jsx(Table.HeaderCell, {
|
|
53
|
+
scope: "row",
|
|
54
|
+
children: key
|
|
55
|
+
}), /* @__PURE__ */ jsx(Table.Cell, { children: value })] }, key)) })
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
var pair = (value) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
59
|
+
/* @__PURE__ */ jsx(Code, { children: value.light }),
|
|
60
|
+
" / ",
|
|
61
|
+
/* @__PURE__ */ jsx(Code, { children: value.dark })
|
|
62
|
+
] });
|
|
63
|
+
/**
|
|
64
|
+
* A living reference of the active design system, rendered from the consumer's config:
|
|
65
|
+
* colors with contrast ratios, the size scale with live controls, radii, variants, spacing,
|
|
66
|
+
* shadows, fonts, text styles, heading levels, density, other tokens and defaults.
|
|
67
|
+
* Import from `@yarcl/react/reference`.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```tsx
|
|
71
|
+
* import { DesignReference } from '@yarcl/react/reference';
|
|
72
|
+
*
|
|
73
|
+
* <DesignReference title="Acme design system" />
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
function DesignReference({ title = "Design reference" }) {
|
|
77
|
+
const config = useConfig();
|
|
78
|
+
const shape = config;
|
|
79
|
+
const colors = keys(config.colors);
|
|
80
|
+
const variants = keys(config.variants);
|
|
81
|
+
const { typography } = shape;
|
|
82
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
83
|
+
gap: config.defaults.padding,
|
|
84
|
+
className: "yarcl-ref",
|
|
85
|
+
children: [
|
|
86
|
+
/* @__PURE__ */ jsx(Heading, {
|
|
87
|
+
level: 1,
|
|
88
|
+
children: title
|
|
89
|
+
}),
|
|
90
|
+
/* @__PURE__ */ jsx(Section, {
|
|
91
|
+
title: "Colors",
|
|
92
|
+
description: "Semantic colors for the color prop. Ratios are foreground on background, light / dark.",
|
|
93
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
94
|
+
className: "yarcl-ref-grid",
|
|
95
|
+
children: colors.map((key) => {
|
|
96
|
+
const token = shape.colors[key];
|
|
97
|
+
return /* @__PURE__ */ jsxs(Card, {
|
|
98
|
+
padding: config.defaults.gap,
|
|
99
|
+
className: "yarcl-ref-color",
|
|
100
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
101
|
+
className: `yarcl-ref-swatch yarcl-color-${key}`,
|
|
102
|
+
children: "Aa"
|
|
103
|
+
}), /* @__PURE__ */ jsxs(Stack, {
|
|
104
|
+
gap: config.defaults.gap,
|
|
105
|
+
children: [
|
|
106
|
+
/* @__PURE__ */ jsx(Text, {
|
|
107
|
+
textStyle: config.defaults.labelStyle,
|
|
108
|
+
children: key
|
|
109
|
+
}),
|
|
110
|
+
/* @__PURE__ */ jsx(Text, {
|
|
111
|
+
textStyle: config.defaults.helperStyle,
|
|
112
|
+
muted: true,
|
|
113
|
+
children: pair(token)
|
|
114
|
+
}),
|
|
115
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
116
|
+
textStyle: config.defaults.helperStyle,
|
|
117
|
+
muted: true,
|
|
118
|
+
children: [
|
|
119
|
+
ratio(token.light, token, "light"),
|
|
120
|
+
" / ",
|
|
121
|
+
ratio(token.dark, token, "dark")
|
|
122
|
+
]
|
|
123
|
+
})
|
|
124
|
+
]
|
|
125
|
+
})]
|
|
126
|
+
}, key);
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
}),
|
|
130
|
+
/* @__PURE__ */ jsx(Section, {
|
|
131
|
+
title: "Neutrals",
|
|
132
|
+
description: "Backgrounds, text and borders.",
|
|
133
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
134
|
+
className: "yarcl-ref-grid",
|
|
135
|
+
children: Object.entries(shape.neutrals).map(([key, value]) => /* @__PURE__ */ jsxs(Card, {
|
|
136
|
+
padding: config.defaults.gap,
|
|
137
|
+
className: "yarcl-ref-color",
|
|
138
|
+
children: [
|
|
139
|
+
/* @__PURE__ */ jsx("div", {
|
|
140
|
+
className: "yarcl-ref-swatch yarcl-ref-neutral",
|
|
141
|
+
style: { background: `var(--yarcl-neutral-${key})` }
|
|
142
|
+
}),
|
|
143
|
+
/* @__PURE__ */ jsx(Text, {
|
|
144
|
+
textStyle: config.defaults.labelStyle,
|
|
145
|
+
children: key
|
|
146
|
+
}),
|
|
147
|
+
/* @__PURE__ */ jsx(Text, {
|
|
148
|
+
textStyle: config.defaults.helperStyle,
|
|
149
|
+
muted: true,
|
|
150
|
+
children: pair(value)
|
|
151
|
+
})
|
|
152
|
+
]
|
|
153
|
+
}, key))
|
|
154
|
+
})
|
|
155
|
+
}),
|
|
156
|
+
/* @__PURE__ */ jsx(Section, {
|
|
157
|
+
title: "Sizes",
|
|
158
|
+
description: "The base scale shared by every control, before per-component overrides.",
|
|
159
|
+
children: /* @__PURE__ */ jsxs(Table, {
|
|
160
|
+
caption: "Control sizes",
|
|
161
|
+
density: config.defaults.density,
|
|
162
|
+
children: [/* @__PURE__ */ jsx(Table.Head, { children: /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
163
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Size" }),
|
|
164
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Height" }),
|
|
165
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Padding X" }),
|
|
166
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Font" }),
|
|
167
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Icon" }),
|
|
168
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Preview" })
|
|
169
|
+
] }) }), /* @__PURE__ */ jsx(Table.Body, { children: keys(config.sizes).map((key) => {
|
|
170
|
+
const size = shape.sizes[key];
|
|
171
|
+
return /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
172
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, {
|
|
173
|
+
scope: "row",
|
|
174
|
+
children: key
|
|
175
|
+
}),
|
|
176
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Code, { children: size.height }) }),
|
|
177
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Code, { children: size.paddingX }) }),
|
|
178
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Code, { children: size.fontSize }) }),
|
|
179
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Code, { children: size.iconSize }) }),
|
|
180
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsxs(Inline, {
|
|
181
|
+
gap: config.defaults.gap,
|
|
182
|
+
wrap: false,
|
|
183
|
+
children: [
|
|
184
|
+
/* @__PURE__ */ jsx(Input, {
|
|
185
|
+
size: key,
|
|
186
|
+
placeholder: "Input",
|
|
187
|
+
"aria-label": `Input ${key}`,
|
|
188
|
+
className: "yarcl-ref-input"
|
|
189
|
+
}),
|
|
190
|
+
/* @__PURE__ */ jsx(Button, {
|
|
191
|
+
size: key,
|
|
192
|
+
children: "Button"
|
|
193
|
+
}),
|
|
194
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
195
|
+
size: key,
|
|
196
|
+
"aria-label": "Add",
|
|
197
|
+
children: "+"
|
|
198
|
+
})
|
|
199
|
+
]
|
|
200
|
+
}) })
|
|
201
|
+
] }, key);
|
|
202
|
+
}) })]
|
|
203
|
+
})
|
|
204
|
+
}),
|
|
205
|
+
/* @__PURE__ */ jsx(Section, {
|
|
206
|
+
title: "Radii",
|
|
207
|
+
description: shape.defaults.radius === "size" ? "Controls use the radius named like their size; other keys are exceptions." : `Default radius: ${shape.defaults.radius}.`,
|
|
208
|
+
children: /* @__PURE__ */ jsx(Inline, { children: keys(config.radii).map((key) => /* @__PURE__ */ jsxs(Stack, {
|
|
209
|
+
gap: config.defaults.gap,
|
|
210
|
+
align: "center",
|
|
211
|
+
children: [
|
|
212
|
+
/* @__PURE__ */ jsx("div", { className: `yarcl-ref-radius yarcl-radius-${key}` }),
|
|
213
|
+
/* @__PURE__ */ jsx(Text, {
|
|
214
|
+
textStyle: config.defaults.labelStyle,
|
|
215
|
+
children: key
|
|
216
|
+
}),
|
|
217
|
+
/* @__PURE__ */ jsx(Text, {
|
|
218
|
+
textStyle: config.defaults.helperStyle,
|
|
219
|
+
muted: true,
|
|
220
|
+
children: /* @__PURE__ */ jsx(Code, { children: shape.radii[key] })
|
|
221
|
+
})
|
|
222
|
+
]
|
|
223
|
+
}, key)) })
|
|
224
|
+
}),
|
|
225
|
+
/* @__PURE__ */ jsx(Section, {
|
|
226
|
+
title: "Variants",
|
|
227
|
+
description: "Recipes applied on top of any color.",
|
|
228
|
+
children: variants.map((key) => {
|
|
229
|
+
const recipe = shape.variants[key];
|
|
230
|
+
return /* @__PURE__ */ jsxs(Inline, { children: [
|
|
231
|
+
/* @__PURE__ */ jsx(Text, {
|
|
232
|
+
textStyle: config.defaults.labelStyle,
|
|
233
|
+
className: "yarcl-ref-label",
|
|
234
|
+
children: key
|
|
235
|
+
}),
|
|
236
|
+
colors.map((color) => /* @__PURE__ */ jsx(Button, {
|
|
237
|
+
variant: key,
|
|
238
|
+
color,
|
|
239
|
+
size: config.defaults.size,
|
|
240
|
+
children: color
|
|
241
|
+
}, color)),
|
|
242
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
243
|
+
textStyle: config.defaults.helperStyle,
|
|
244
|
+
muted: true,
|
|
245
|
+
children: [
|
|
246
|
+
"background ",
|
|
247
|
+
/* @__PURE__ */ jsx(Code, { children: recipe.background }),
|
|
248
|
+
", border ",
|
|
249
|
+
/* @__PURE__ */ jsx(Code, { children: recipe.border }),
|
|
250
|
+
", text ",
|
|
251
|
+
/* @__PURE__ */ jsx(Code, { children: recipe.text })
|
|
252
|
+
]
|
|
253
|
+
})
|
|
254
|
+
] }, key);
|
|
255
|
+
})
|
|
256
|
+
}),
|
|
257
|
+
/* @__PURE__ */ jsx(Section, {
|
|
258
|
+
title: "Spacing",
|
|
259
|
+
children: keys(config.spacing).map((key) => /* @__PURE__ */ jsxs(Inline, { children: [
|
|
260
|
+
/* @__PURE__ */ jsx(Text, {
|
|
261
|
+
textStyle: config.defaults.labelStyle,
|
|
262
|
+
className: "yarcl-ref-label",
|
|
263
|
+
children: key
|
|
264
|
+
}),
|
|
265
|
+
/* @__PURE__ */ jsx("div", {
|
|
266
|
+
className: "yarcl-ref-space",
|
|
267
|
+
style: { width: `var(--yarcl-space-${key})` }
|
|
268
|
+
}),
|
|
269
|
+
/* @__PURE__ */ jsx(Code, { children: shape.spacing[key] })
|
|
270
|
+
] }, key))
|
|
271
|
+
}),
|
|
272
|
+
/* @__PURE__ */ jsx(Section, {
|
|
273
|
+
title: "Shadows",
|
|
274
|
+
children: /* @__PURE__ */ jsx(Inline, {
|
|
275
|
+
gap: config.defaults.padding,
|
|
276
|
+
children: keys(config.shadows).map((key) => /* @__PURE__ */ jsx(Card, {
|
|
277
|
+
shadow: key,
|
|
278
|
+
className: "yarcl-ref-shadow",
|
|
279
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
280
|
+
textStyle: config.defaults.labelStyle,
|
|
281
|
+
children: key
|
|
282
|
+
})
|
|
283
|
+
}, key))
|
|
284
|
+
})
|
|
285
|
+
}),
|
|
286
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
287
|
+
title: "Typography",
|
|
288
|
+
children: [
|
|
289
|
+
(typography.fontFaces?.length ?? 0) > 0 && /* @__PURE__ */ jsxs(Table, {
|
|
290
|
+
caption: "Font files",
|
|
291
|
+
density: config.defaults.density,
|
|
292
|
+
children: [/* @__PURE__ */ jsx(Table.Head, { children: /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
293
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Family" }),
|
|
294
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Source" }),
|
|
295
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Weight" }),
|
|
296
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Style" })
|
|
297
|
+
] }) }), /* @__PURE__ */ jsx(Table.Body, { children: typography.fontFaces.map((face, i) => /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
298
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: face.family }),
|
|
299
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Code, { children: [face.src].flat().join(", ") }) }),
|
|
300
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: face.weight ?? "n/a" }),
|
|
301
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: face.style ?? "normal" })
|
|
302
|
+
] }, i)) })]
|
|
303
|
+
}),
|
|
304
|
+
/* @__PURE__ */ jsx(KeyValues, {
|
|
305
|
+
caption: "Families",
|
|
306
|
+
rows: Object.entries(typography.families).map(([key, stack]) => [key, /* @__PURE__ */ jsxs("span", {
|
|
307
|
+
style: { fontFamily: `var(--yarcl-font-${key})` },
|
|
308
|
+
children: ["The quick brown fox ", /* @__PURE__ */ jsx(Code, { children: stack })]
|
|
309
|
+
})])
|
|
310
|
+
}),
|
|
311
|
+
/* @__PURE__ */ jsx(Table, {
|
|
312
|
+
caption: "Text styles",
|
|
313
|
+
density: config.defaults.density,
|
|
314
|
+
children: /* @__PURE__ */ jsx(Table.Body, { children: keys(config.typography.styles).map((key) => {
|
|
315
|
+
const style = typography.styles[key];
|
|
316
|
+
return /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
317
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, {
|
|
318
|
+
scope: "row",
|
|
319
|
+
children: key
|
|
320
|
+
}),
|
|
321
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Text, {
|
|
322
|
+
textStyle: key,
|
|
323
|
+
children: "The quick brown fox"
|
|
324
|
+
}) }),
|
|
325
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsxs(Text, {
|
|
326
|
+
textStyle: config.defaults.helperStyle,
|
|
327
|
+
muted: true,
|
|
328
|
+
children: [
|
|
329
|
+
style.family,
|
|
330
|
+
" · ",
|
|
331
|
+
style.size,
|
|
332
|
+
" · ",
|
|
333
|
+
style.weight,
|
|
334
|
+
" · ",
|
|
335
|
+
style.lineHeight,
|
|
336
|
+
style.letterSpacing ? ` · ${style.letterSpacing}` : ""
|
|
337
|
+
]
|
|
338
|
+
}) })
|
|
339
|
+
] }, key);
|
|
340
|
+
}) })
|
|
341
|
+
}),
|
|
342
|
+
/* @__PURE__ */ jsx(KeyValues, {
|
|
343
|
+
caption: "Heading levels",
|
|
344
|
+
rows: [
|
|
345
|
+
"h1",
|
|
346
|
+
"h2",
|
|
347
|
+
"h3",
|
|
348
|
+
"h4",
|
|
349
|
+
"h5",
|
|
350
|
+
"h6"
|
|
351
|
+
].map((level) => [level, /* @__PURE__ */ jsx(Text, {
|
|
352
|
+
textStyle: config.typography.headings[level],
|
|
353
|
+
children: typography.headings[level]
|
|
354
|
+
})])
|
|
355
|
+
})
|
|
356
|
+
]
|
|
357
|
+
}),
|
|
358
|
+
/* @__PURE__ */ jsx(Section, {
|
|
359
|
+
title: "Modal sizes",
|
|
360
|
+
description: "Widths of dialogs and drawers.",
|
|
361
|
+
children: /* @__PURE__ */ jsx(KeyValues, {
|
|
362
|
+
caption: "Modal sizes",
|
|
363
|
+
rows: Object.entries(shape.modalSizes).map(([key, value]) => [key, /* @__PURE__ */ jsx(Code, { children: value })])
|
|
364
|
+
})
|
|
365
|
+
}),
|
|
366
|
+
/* @__PURE__ */ jsx(Section, {
|
|
367
|
+
title: "Density",
|
|
368
|
+
children: /* @__PURE__ */ jsx(KeyValues, {
|
|
369
|
+
caption: "Table density",
|
|
370
|
+
rows: keys(config.density).map((key) => {
|
|
371
|
+
const density = shape.density[key];
|
|
372
|
+
return [key, /* @__PURE__ */ jsx(Code, { children: `${density.paddingY} ${density.paddingX} · ${density.fontSize}` })];
|
|
373
|
+
})
|
|
374
|
+
})
|
|
375
|
+
}),
|
|
376
|
+
/* @__PURE__ */ jsx(Section, {
|
|
377
|
+
title: "Other tokens",
|
|
378
|
+
children: /* @__PURE__ */ jsx(KeyValues, {
|
|
379
|
+
caption: "Layers, motion, borders and focus",
|
|
380
|
+
rows: [
|
|
381
|
+
...Object.entries(shape.zIndex).map(([k, v]) => [`zIndex.${k}`, /* @__PURE__ */ jsx(Code, { children: v })]),
|
|
382
|
+
...Object.entries(shape.motion).map(([k, v]) => [`motion.${k}`, /* @__PURE__ */ jsx(Code, { children: v })]),
|
|
383
|
+
...Object.entries(shape.borders).map(([k, v]) => [`borders.${k}`, /* @__PURE__ */ jsx(Code, { children: v })]),
|
|
384
|
+
["focusRing", /* @__PURE__ */ jsx(Code, { children: `${shape.focusRing.width} · offset ${shape.focusRing.offset} · ${shape.focusRing.color}` })]
|
|
385
|
+
]
|
|
386
|
+
})
|
|
387
|
+
}),
|
|
388
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
389
|
+
title: "Defaults",
|
|
390
|
+
description: "Values used when a component prop is omitted: the prop, then an enclosing group, then component defaults, then global defaults.",
|
|
391
|
+
children: [Object.keys(shape.components ?? {}).length > 0 && /* @__PURE__ */ jsx(KeyValues, {
|
|
392
|
+
caption: "Component defaults",
|
|
393
|
+
rows: Object.entries(shape.components ?? {}).map(([name, values]) => [name, /* @__PURE__ */ jsx(Code, { children: Object.entries(values ?? {}).map(([prop, value]) => `${prop}: ${value}`).join(" · ") })])
|
|
394
|
+
}), /* @__PURE__ */ jsx(KeyValues, {
|
|
395
|
+
caption: "Global defaults",
|
|
396
|
+
rows: Object.entries(shape.defaults).map(([key, value]) => [key, /* @__PURE__ */ jsx(Code, { children: value })])
|
|
397
|
+
})]
|
|
398
|
+
})
|
|
399
|
+
]
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
//#endregion
|
|
403
|
+
export { DesignReference };
|
package/dist/rollup.cjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
let e=require("node:fs"),t=require("node:fs/promises"),n=require("node:module"),r=require("node:path"),i=require("jiti"),a=require("unplugin"),o=require("jsonc-parser");function s(e){let t=e.trim().replace(/^#/,``);if(!/^([0-9a-f]{3}|[0-9a-f]{6})$/i.test(t))return null;let n=t.length===3?[...t].map(e=>e+e).join(``):t;return[0,2,4].map(e=>parseInt(n.slice(e,e+2),16))}function c([e,t,n]){let[r,i,a]=[e,t,n].map(e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4});return .2126*r+.7152*i+.0722*a}function l(e,t){let[n,r]=[c(e),c(t)].sort((e,t)=>t-e);return(n+.05)/(r+.05)}var u=[255,255,255],d=[0,0,0];function f(e,t,n){return e.map((e,r)=>Math.round(e+(t[r]-e)*n))}function p(e){return`#${e.map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}function m(e,t,n,r){for(let i=0;i<=20;i++){let a=f(e,n,i/20);if(t.every(e=>l(a,e)>=r))return a}return n}function h(e){return l(e,u)>=l(e,d)?`#ffffff`:`#000000`}var g=4.5;function _(e){return e.replace(/[^a-zA-Z0-9_-]/g,e=>`\\${e}`)}function v({light:e,dark:t}){return e===t?e:`light-dark(${e}, ${t})`}function y(e,t,n){let r=[`light`,`dark`],i=typeof t.on==`string`?{light:t.on,dark:t.on}:t.on,a=r.map(r=>{let a=s(t[r]);if(i){let t=s(i[r]);return a&&t&&l(a,t)<g&&n(`colors.${e}: ${r} foreground contrast ${l(a,t).toFixed(2)}:1 is below ${g}:1`),i[r]}if(!a)return n(`colors.${e}: cannot compute a ${r} foreground from "${t[r]}"; use a hex value or set \`on\``),`#ffffff`;let o=h(a),c=l(a,s(o));return c<g&&n(`colors.${e}: best ${r} foreground contrast is ${c.toFixed(2)}:1, below ${g}:1`),o});return v({light:a[0],dark:a[1]})}var b=e=>`color-mix(in oklab, var(--yarcl-c) ${e}%, transparent)`,x=e=>`color-mix(in oklab, var(--yarcl-c), var(--yarcl-c-on) ${e}%)`,S={fill:[`var(--yarcl-c)`,x(12),x(20)],tint:[b(14),b(22),b(30)],none:[`transparent`,b(10),b(18)]},C={color:`var(--yarcl-c)`,neutral:`var(--yarcl-neutral-border)`,none:`transparent`},w={on:`var(--yarcl-c-on)`,color:`var(--yarcl-c-text)`,neutral:`var(--yarcl-neutral-text)`},T={woff2:`woff2`,woff:`woff`,ttf:`truetype`,otf:`opentype`};function E(e){let t=(Array.isArray(e.src)?e.src:[e.src]).map(e=>{if(e.startsWith(`local(`))return e;let t=T[e.split(/[?#]/)[0].split(`.`).pop()?.toLowerCase()??``];return`url(${JSON.stringify(e)})${t?` format("${t}")`:``}`});return k(`@font-face`,[[`font-family`,JSON.stringify(e.family)],[`src`,t.join(`, `)],...e.weight==null?[]:[[`font-weight`,e.weight]],...e.style?[[`font-style`,e.style]]:[],[`font-display`,e.display??`swap`]])}var D=[0,.14,.22];function O(e,t,n){if(t.text)return v(typeof t.text==`string`?{light:t.text,dark:t.text}:t.text);let r=[`light`,`dark`].map(e=>{let r=s(t[e]),i=s(n.text[e]),a=[s(n.bg[e]),s(n.surface[e])];return!r||!i||a.some(e=>!e)?t[e]:p(m(r,a.flatMap(e=>D.map(t=>f(e,r,t))),i,g))});return v({light:r[0],dark:r[1]})}function k(e,t){return`${e} {\n${t.map(([e,t])=>` ${e}: ${t};`).join(`
|
|
2
|
+
`)}\n}`}var A={height:`h`,paddingX:`px`,fontSize:`fs`,iconSize:`icon`};function j(e,t=()=>{}){let n=[[`color-scheme`,`light dark`]],r=[];for(let[i,a]of Object.entries(e.colors)){let o=_(i);n.push([`--yarcl-color-${o}`,v(a)],[`--yarcl-color-${o}-on`,y(i,a,t)],[`--yarcl-color-${o}-text`,O(i,a,e.neutrals)]),r.push(k(`.yarcl-color-${o}`,[[`--yarcl-c`,`var(--yarcl-color-${o})`],[`--yarcl-c-on`,`var(--yarcl-color-${o}-on)`],[`--yarcl-c-text`,`var(--yarcl-color-${o}-text)`]]))}for(let[t,r]of Object.entries(e.neutrals))n.push([`--yarcl-neutral-${_(t)}`,v(r)]);for(let[t,i]of Object.entries(e.sizes)){let e=_(t);n.push([`--yarcl-size-${e}-height`,i.height],[`--yarcl-size-${e}-padding-x`,i.paddingX],[`--yarcl-size-${e}-font-size`,i.fontSize],[`--yarcl-size-${e}-icon-size`,i.iconSize]),r.push(k(`.yarcl-size-${e}`,[[`--yarcl-h`,`var(--yarcl-size-${e}-height)`],[`--yarcl-px`,`var(--yarcl-size-${e}-padding-x)`],[`--yarcl-fs`,`var(--yarcl-size-${e}-font-size)`],[`--yarcl-icon`,`var(--yarcl-size-${e}-icon-size)`]]))}for(let[t,{sizeOverrides:n}]of Object.entries(e.components??{}))for(let[e,i]of Object.entries(n??{})){let n=Object.entries(i).map(([e,t])=>[`--yarcl-${A[e]}`,t]),a=`.yarcl-sized-${_(t)}`,o=`.yarcl-size-${_(e)}`;n.length&&r.push(k(`${a}${o},\n${a}${a} ${o}`,n))}for(let[t,i]of Object.entries(e.radii)){let e=_(t);n.push([`--yarcl-radius-${e}`,i]),r.push(k(`.yarcl-radius-${e}`,[[`--yarcl-r`,`var(--yarcl-radius-${e})`]]))}for(let[t,n]of Object.entries(e.variants)){let[e,i,a]=S[n.background];r.push(k(`.yarcl-variant-${_(t)}`,[[`--yarcl-v-bg`,e],[`--yarcl-v-bg-hover`,i],[`--yarcl-v-bg-active`,a],[`--yarcl-v-border`,C[n.border]],[`--yarcl-v-fg`,w[n.text]]]))}for(let[t,i]of Object.entries(e.spacing)){let e=_(t);n.push([`--yarcl-space-${e}`,i]),r.push(k(`.yarcl-gap-${e}`,[[`--yarcl-component-gap`,`var(--yarcl-space-${e})`]]),k(`.yarcl-padding-${e}`,[[`--yarcl-component-padding`,`var(--yarcl-space-${e})`]]))}for(let[t,i]of Object.entries(e.shadows)){let e=_(t);n.push([`--yarcl-shadow-${e}`,i]),r.push(k(`.yarcl-shadow-${e}`,[[`box-shadow`,`var(--yarcl-shadow-${e})`]]))}for(let[t,i]of Object.entries(e.modalSizes)){let e=_(t);n.push([`--yarcl-modal-${e}`,i]),r.push(k(`.yarcl-modal-size-${e}`,[[`--yarcl-modal-width`,`var(--yarcl-modal-${e})`]]))}for(let[t,n]of Object.entries(e.density))r.push(k(`.yarcl-density-${_(t)}`,[[`--yarcl-cell-px`,n.paddingX],[`--yarcl-cell-py`,n.paddingY],[`--yarcl-cell-fs`,n.fontSize]]));for(let[t,r]of Object.entries(e.typography.families))n.push([`--yarcl-font-${_(t)}`,r]);for(let[t,n]of Object.entries(e.typography.styles))r.push(k(`.yarcl-type-${_(t)}`,[[`font-family`,`var(--yarcl-font-${_(n.family)})`],[`font-size`,n.size],[`font-weight`,n.weight],[`line-height`,n.lineHeight],...n.letterSpacing?[[`letter-spacing`,n.letterSpacing]]:[]]));for(let[t,r]of Object.entries(e.zIndex))n.push([`--yarcl-z-${_(t)}`,r]);for(let[t,r]of Object.entries(e.motion))n.push([`--yarcl-motion-${_(t)}`,r]);for(let[t,r]of Object.entries(e.borders))n.push([`--yarcl-border-${_(t)}`,r]);let i=_(e.defaults.size),a=e.defaults.radius===`size`?i:_(e.defaults.radius);return n.push([`--yarcl-focus-width`,e.focusRing.width],[`--yarcl-focus-offset`,e.focusRing.offset],[`--yarcl-focus-style`,e.focusRing.style??`solid`],[`--yarcl-focus-color`,`var(--yarcl-color-${_(e.focusRing.color)})`],[`--yarcl-error`,`var(--yarcl-color-${_(e.defaults.errorColor)})`],[`--yarcl-floating-shadow`,`var(--yarcl-shadow-${_(e.defaults.floatingShadow)})`],[`--yarcl-padding`,`var(--yarcl-space-${_(e.defaults.padding)})`],[`--yarcl-gap`,`var(--yarcl-space-${_(e.defaults.gap)})`],[`--yarcl-h`,`var(--yarcl-size-${i}-height)`],[`--yarcl-px`,`var(--yarcl-size-${i}-padding-x)`],[`--yarcl-fs`,`var(--yarcl-size-${i}-font-size)`],[`--yarcl-icon`,`var(--yarcl-size-${i}-icon-size)`],[`--yarcl-r`,`var(--yarcl-radius-${a}, 0)`]),[...(e.typography.fontFaces??[]).map(E),k(`:root`,n),...r].join(`
|
|
3
|
+
|
|
4
|
+
`)+`
|
|
5
|
+
`}var M=`@yarcl/config`,N=[`tsconfig.app.json`,`tsconfig.json`];function P(t){return N.map(e=>(0,r.resolve)(t,e)).find(t=>(0,e.existsSync)(t))}function F(e,t){let n=(0,r.relative)(e,t).split(r.sep).join(`/`);return n.startsWith(`.`)?n:`./${n}`}function I(t,n,i=`build tool`){let a=P(t);if(!a)throw Error(`yarcl: No tsconfig.app.json or tsconfig.json found in ${t}. Run "yarcl init".`);let s=[],c=(0,o.parse)((0,e.readFileSync)(a,`utf8`),s,{allowTrailingComma:!0});if(s.length>0)throw Error(`yarcl: Could not parse ${F(t,a)}.`);let l=c?.compilerOptions?.paths?.[M],u=(0,r.resolve)(t,n),d=Array.isArray(l)&&typeof l[0]==`string`?(0,r.resolve)((0,r.dirname)(a),l[0]):void 0;if(d===u)return;let f=d?`"${F(t,d)}"`:`no path`;throw Error(`yarcl: Config path mismatch. ${i} uses "${n}", but ${F(t,a)} has ${f} for "${M}". Run "yarcl init --config ${n}".`)}var L=`@yarcl/react/styles.css`,R=`\0${L}`,z=`@yarcl/config`,B=`@yarcl/react`,V=(0,n.createRequire)(typeof __filename==`string`?__filename:{}.url),H=[``,`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`,`.json`],U=/(?:\bimport\s*(?:[\s\S]*?\sfrom\s*)?|\bexport\s*[\s\S]*?\sfrom\s*|\bimport\s*\()(['"])(\.{1,2}\/[^'"]+)\1/g;function W(t,n){let i=(0,r.resolve)((0,r.dirname)(t),n);for(let t of H){let n=`${i}${t}`;if((0,e.existsSync)(n))return n}for(let t of H.slice(1)){let n=(0,r.resolve)(i,`index${t}`);if((0,e.existsSync)(n))return n}}async function G(e){let n=new Set,i=async e=>{if(n.has(e)||(n.add(e),(0,r.extname)(e)===`.json`))return;let a=[...(await(0,t.readFile)(e,`utf8`)).matchAll(U)].map(t=>W(e,t[2])).filter(e=>e!==void 0);await Promise.all(a.map(i))};return await i(e),n}function K(){return V.resolve(`@yarcl/react/defaults`)}var q=(0,a.createUnplugin)((n={},a)=>{let o=n.config??`src/yarcl.config.ts`,s=(0,r.resolve)(n.root??process.cwd()),c=``,l=``,u=``,d=``,f=``,p=new Set,m=()=>{I(s,o,a.framework);let t=(0,r.resolve)(s,o),n=K();c=(0,e.existsSync)(t)?t:n,d=(0,r.resolve)((0,r.dirname)(n),`styles.css`),f=(0,r.resolve)((0,r.dirname)(n),`reference/reference.css`)};return{name:`yarcl`,enforce:`pre`,buildStart(){m()},resolveId:{filter:{id:/^(?:@yarcl\/config|@yarcl\/react\/styles\.css)$/},handler(e){if(e===z)return a.framework===`esbuild`?void 0:c;if(e===L)return R}},load:{filter:{id:/(?:@yarcl\/react\/styles\.css|\/(?:styles|reference)\.css)$/},async handler(n){if(a.framework===`rollup`&&(n===d||n===f))return l+=`${await(0,t.readFile)(n,`utf8`)}\n`,``;if(n!==R)return;let o=await(0,i.createJiti)((0,r.resolve)(s,`package.json`),{moduleCache:!1}).import(c,{default:!0});p=(0,e.existsSync)(c)?await G(c):new Set([c]),p.forEach(e=>this.addWatchFile(e));let m=j(o,e=>this.warn(e));return a.framework===`rollup`?(u=m,``):m}},rollup:{generateBundle(){this.emitFile({type:`asset`,fileName:`yarcl.css`,source:`${u}\n${l}`})}},vite:{config(e){return s=(0,r.resolve)(n.root??e.root??process.cwd()),{optimizeDeps:{exclude:[B],include:[`@floating-ui/react`,`date-fns`,`date-fns/locale`,`date-fns/locale/en-US`].map(e=>`${B} > ${e}`)},ssr:{noExternal:[B]}}},handleHotUpdate({file:e,server:t,modules:n}){if(!p.has(e))return;let r=t.moduleGraph.getModuleById(R);if(r)return t.moduleGraph.invalidateModule(r),[...n,r]}},webpack(e){s=(0,r.resolve)(n.root??e.context)},rspack(e){s=(0,r.resolve)(n.root??e.context)},esbuild:{config(e){s=(0,r.resolve)(n.root??e.absWorkingDir??process.cwd()),m()},setup(e){e.onResolve({filter:/^@yarcl\/config$/},()=>({path:c}))},loader:`css`}}}).rollup;module.exports=q;
|
package/dist/rollup.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Connects yarcl to Rollup. */
|
|
2
|
+
declare const yarcl: (options?: import("./plugin").YarclPluginOptions | undefined) => import("unplugin").RollupPlugin<any> | import("unplugin").RollupPlugin<any>[];
|
|
3
|
+
export type { YarclPluginOptions } from './plugin';
|
|
4
|
+
export default yarcl;
|
package/dist/rollup.js
ADDED
package/dist/rspack.cjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
let e=require("node:fs"),t=require("node:fs/promises"),n=require("node:module"),r=require("node:path"),i=require("jiti"),a=require("unplugin"),o=require("jsonc-parser");function s(e){let t=e.trim().replace(/^#/,``);if(!/^([0-9a-f]{3}|[0-9a-f]{6})$/i.test(t))return null;let n=t.length===3?[...t].map(e=>e+e).join(``):t;return[0,2,4].map(e=>parseInt(n.slice(e,e+2),16))}function c([e,t,n]){let[r,i,a]=[e,t,n].map(e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4});return .2126*r+.7152*i+.0722*a}function l(e,t){let[n,r]=[c(e),c(t)].sort((e,t)=>t-e);return(n+.05)/(r+.05)}var u=[255,255,255],d=[0,0,0];function f(e,t,n){return e.map((e,r)=>Math.round(e+(t[r]-e)*n))}function p(e){return`#${e.map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}function m(e,t,n,r){for(let i=0;i<=20;i++){let a=f(e,n,i/20);if(t.every(e=>l(a,e)>=r))return a}return n}function h(e){return l(e,u)>=l(e,d)?`#ffffff`:`#000000`}var g=4.5;function _(e){return e.replace(/[^a-zA-Z0-9_-]/g,e=>`\\${e}`)}function v({light:e,dark:t}){return e===t?e:`light-dark(${e}, ${t})`}function y(e,t,n){let r=[`light`,`dark`],i=typeof t.on==`string`?{light:t.on,dark:t.on}:t.on,a=r.map(r=>{let a=s(t[r]);if(i){let t=s(i[r]);return a&&t&&l(a,t)<g&&n(`colors.${e}: ${r} foreground contrast ${l(a,t).toFixed(2)}:1 is below ${g}:1`),i[r]}if(!a)return n(`colors.${e}: cannot compute a ${r} foreground from "${t[r]}"; use a hex value or set \`on\``),`#ffffff`;let o=h(a),c=l(a,s(o));return c<g&&n(`colors.${e}: best ${r} foreground contrast is ${c.toFixed(2)}:1, below ${g}:1`),o});return v({light:a[0],dark:a[1]})}var b=e=>`color-mix(in oklab, var(--yarcl-c) ${e}%, transparent)`,x=e=>`color-mix(in oklab, var(--yarcl-c), var(--yarcl-c-on) ${e}%)`,S={fill:[`var(--yarcl-c)`,x(12),x(20)],tint:[b(14),b(22),b(30)],none:[`transparent`,b(10),b(18)]},C={color:`var(--yarcl-c)`,neutral:`var(--yarcl-neutral-border)`,none:`transparent`},w={on:`var(--yarcl-c-on)`,color:`var(--yarcl-c-text)`,neutral:`var(--yarcl-neutral-text)`},T={woff2:`woff2`,woff:`woff`,ttf:`truetype`,otf:`opentype`};function E(e){let t=(Array.isArray(e.src)?e.src:[e.src]).map(e=>{if(e.startsWith(`local(`))return e;let t=T[e.split(/[?#]/)[0].split(`.`).pop()?.toLowerCase()??``];return`url(${JSON.stringify(e)})${t?` format("${t}")`:``}`});return k(`@font-face`,[[`font-family`,JSON.stringify(e.family)],[`src`,t.join(`, `)],...e.weight==null?[]:[[`font-weight`,e.weight]],...e.style?[[`font-style`,e.style]]:[],[`font-display`,e.display??`swap`]])}var D=[0,.14,.22];function O(e,t,n){if(t.text)return v(typeof t.text==`string`?{light:t.text,dark:t.text}:t.text);let r=[`light`,`dark`].map(e=>{let r=s(t[e]),i=s(n.text[e]),a=[s(n.bg[e]),s(n.surface[e])];return!r||!i||a.some(e=>!e)?t[e]:p(m(r,a.flatMap(e=>D.map(t=>f(e,r,t))),i,g))});return v({light:r[0],dark:r[1]})}function k(e,t){return`${e} {\n${t.map(([e,t])=>` ${e}: ${t};`).join(`
|
|
2
|
+
`)}\n}`}var A={height:`h`,paddingX:`px`,fontSize:`fs`,iconSize:`icon`};function j(e,t=()=>{}){let n=[[`color-scheme`,`light dark`]],r=[];for(let[i,a]of Object.entries(e.colors)){let o=_(i);n.push([`--yarcl-color-${o}`,v(a)],[`--yarcl-color-${o}-on`,y(i,a,t)],[`--yarcl-color-${o}-text`,O(i,a,e.neutrals)]),r.push(k(`.yarcl-color-${o}`,[[`--yarcl-c`,`var(--yarcl-color-${o})`],[`--yarcl-c-on`,`var(--yarcl-color-${o}-on)`],[`--yarcl-c-text`,`var(--yarcl-color-${o}-text)`]]))}for(let[t,r]of Object.entries(e.neutrals))n.push([`--yarcl-neutral-${_(t)}`,v(r)]);for(let[t,i]of Object.entries(e.sizes)){let e=_(t);n.push([`--yarcl-size-${e}-height`,i.height],[`--yarcl-size-${e}-padding-x`,i.paddingX],[`--yarcl-size-${e}-font-size`,i.fontSize],[`--yarcl-size-${e}-icon-size`,i.iconSize]),r.push(k(`.yarcl-size-${e}`,[[`--yarcl-h`,`var(--yarcl-size-${e}-height)`],[`--yarcl-px`,`var(--yarcl-size-${e}-padding-x)`],[`--yarcl-fs`,`var(--yarcl-size-${e}-font-size)`],[`--yarcl-icon`,`var(--yarcl-size-${e}-icon-size)`]]))}for(let[t,{sizeOverrides:n}]of Object.entries(e.components??{}))for(let[e,i]of Object.entries(n??{})){let n=Object.entries(i).map(([e,t])=>[`--yarcl-${A[e]}`,t]),a=`.yarcl-sized-${_(t)}`,o=`.yarcl-size-${_(e)}`;n.length&&r.push(k(`${a}${o},\n${a}${a} ${o}`,n))}for(let[t,i]of Object.entries(e.radii)){let e=_(t);n.push([`--yarcl-radius-${e}`,i]),r.push(k(`.yarcl-radius-${e}`,[[`--yarcl-r`,`var(--yarcl-radius-${e})`]]))}for(let[t,n]of Object.entries(e.variants)){let[e,i,a]=S[n.background];r.push(k(`.yarcl-variant-${_(t)}`,[[`--yarcl-v-bg`,e],[`--yarcl-v-bg-hover`,i],[`--yarcl-v-bg-active`,a],[`--yarcl-v-border`,C[n.border]],[`--yarcl-v-fg`,w[n.text]]]))}for(let[t,i]of Object.entries(e.spacing)){let e=_(t);n.push([`--yarcl-space-${e}`,i]),r.push(k(`.yarcl-gap-${e}`,[[`--yarcl-component-gap`,`var(--yarcl-space-${e})`]]),k(`.yarcl-padding-${e}`,[[`--yarcl-component-padding`,`var(--yarcl-space-${e})`]]))}for(let[t,i]of Object.entries(e.shadows)){let e=_(t);n.push([`--yarcl-shadow-${e}`,i]),r.push(k(`.yarcl-shadow-${e}`,[[`box-shadow`,`var(--yarcl-shadow-${e})`]]))}for(let[t,i]of Object.entries(e.modalSizes)){let e=_(t);n.push([`--yarcl-modal-${e}`,i]),r.push(k(`.yarcl-modal-size-${e}`,[[`--yarcl-modal-width`,`var(--yarcl-modal-${e})`]]))}for(let[t,n]of Object.entries(e.density))r.push(k(`.yarcl-density-${_(t)}`,[[`--yarcl-cell-px`,n.paddingX],[`--yarcl-cell-py`,n.paddingY],[`--yarcl-cell-fs`,n.fontSize]]));for(let[t,r]of Object.entries(e.typography.families))n.push([`--yarcl-font-${_(t)}`,r]);for(let[t,n]of Object.entries(e.typography.styles))r.push(k(`.yarcl-type-${_(t)}`,[[`font-family`,`var(--yarcl-font-${_(n.family)})`],[`font-size`,n.size],[`font-weight`,n.weight],[`line-height`,n.lineHeight],...n.letterSpacing?[[`letter-spacing`,n.letterSpacing]]:[]]));for(let[t,r]of Object.entries(e.zIndex))n.push([`--yarcl-z-${_(t)}`,r]);for(let[t,r]of Object.entries(e.motion))n.push([`--yarcl-motion-${_(t)}`,r]);for(let[t,r]of Object.entries(e.borders))n.push([`--yarcl-border-${_(t)}`,r]);let i=_(e.defaults.size),a=e.defaults.radius===`size`?i:_(e.defaults.radius);return n.push([`--yarcl-focus-width`,e.focusRing.width],[`--yarcl-focus-offset`,e.focusRing.offset],[`--yarcl-focus-style`,e.focusRing.style??`solid`],[`--yarcl-focus-color`,`var(--yarcl-color-${_(e.focusRing.color)})`],[`--yarcl-error`,`var(--yarcl-color-${_(e.defaults.errorColor)})`],[`--yarcl-floating-shadow`,`var(--yarcl-shadow-${_(e.defaults.floatingShadow)})`],[`--yarcl-padding`,`var(--yarcl-space-${_(e.defaults.padding)})`],[`--yarcl-gap`,`var(--yarcl-space-${_(e.defaults.gap)})`],[`--yarcl-h`,`var(--yarcl-size-${i}-height)`],[`--yarcl-px`,`var(--yarcl-size-${i}-padding-x)`],[`--yarcl-fs`,`var(--yarcl-size-${i}-font-size)`],[`--yarcl-icon`,`var(--yarcl-size-${i}-icon-size)`],[`--yarcl-r`,`var(--yarcl-radius-${a}, 0)`]),[...(e.typography.fontFaces??[]).map(E),k(`:root`,n),...r].join(`
|
|
3
|
+
|
|
4
|
+
`)+`
|
|
5
|
+
`}var M=`@yarcl/config`,N=[`tsconfig.app.json`,`tsconfig.json`];function P(t){return N.map(e=>(0,r.resolve)(t,e)).find(t=>(0,e.existsSync)(t))}function F(e,t){let n=(0,r.relative)(e,t).split(r.sep).join(`/`);return n.startsWith(`.`)?n:`./${n}`}function I(t,n,i=`build tool`){let a=P(t);if(!a)throw Error(`yarcl: No tsconfig.app.json or tsconfig.json found in ${t}. Run "yarcl init".`);let s=[],c=(0,o.parse)((0,e.readFileSync)(a,`utf8`),s,{allowTrailingComma:!0});if(s.length>0)throw Error(`yarcl: Could not parse ${F(t,a)}.`);let l=c?.compilerOptions?.paths?.[M],u=(0,r.resolve)(t,n),d=Array.isArray(l)&&typeof l[0]==`string`?(0,r.resolve)((0,r.dirname)(a),l[0]):void 0;if(d===u)return;let f=d?`"${F(t,d)}"`:`no path`;throw Error(`yarcl: Config path mismatch. ${i} uses "${n}", but ${F(t,a)} has ${f} for "${M}". Run "yarcl init --config ${n}".`)}var L=`@yarcl/react/styles.css`,R=`\0${L}`,z=`@yarcl/config`,B=`@yarcl/react`,V=(0,n.createRequire)(typeof __filename==`string`?__filename:{}.url),H=[``,`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`,`.json`],U=/(?:\bimport\s*(?:[\s\S]*?\sfrom\s*)?|\bexport\s*[\s\S]*?\sfrom\s*|\bimport\s*\()(['"])(\.{1,2}\/[^'"]+)\1/g;function W(t,n){let i=(0,r.resolve)((0,r.dirname)(t),n);for(let t of H){let n=`${i}${t}`;if((0,e.existsSync)(n))return n}for(let t of H.slice(1)){let n=(0,r.resolve)(i,`index${t}`);if((0,e.existsSync)(n))return n}}async function G(e){let n=new Set,i=async e=>{if(n.has(e)||(n.add(e),(0,r.extname)(e)===`.json`))return;let a=[...(await(0,t.readFile)(e,`utf8`)).matchAll(U)].map(t=>W(e,t[2])).filter(e=>e!==void 0);await Promise.all(a.map(i))};return await i(e),n}function K(){return V.resolve(`@yarcl/react/defaults`)}var q=(0,a.createUnplugin)((n={},a)=>{let o=n.config??`src/yarcl.config.ts`,s=(0,r.resolve)(n.root??process.cwd()),c=``,l=``,u=``,d=``,f=``,p=new Set,m=()=>{I(s,o,a.framework);let t=(0,r.resolve)(s,o),n=K();c=(0,e.existsSync)(t)?t:n,d=(0,r.resolve)((0,r.dirname)(n),`styles.css`),f=(0,r.resolve)((0,r.dirname)(n),`reference/reference.css`)};return{name:`yarcl`,enforce:`pre`,buildStart(){m()},resolveId:{filter:{id:/^(?:@yarcl\/config|@yarcl\/react\/styles\.css)$/},handler(e){if(e===z)return a.framework===`esbuild`?void 0:c;if(e===L)return R}},load:{filter:{id:/(?:@yarcl\/react\/styles\.css|\/(?:styles|reference)\.css)$/},async handler(n){if(a.framework===`rollup`&&(n===d||n===f))return l+=`${await(0,t.readFile)(n,`utf8`)}\n`,``;if(n!==R)return;let o=await(0,i.createJiti)((0,r.resolve)(s,`package.json`),{moduleCache:!1}).import(c,{default:!0});p=(0,e.existsSync)(c)?await G(c):new Set([c]),p.forEach(e=>this.addWatchFile(e));let m=j(o,e=>this.warn(e));return a.framework===`rollup`?(u=m,``):m}},rollup:{generateBundle(){this.emitFile({type:`asset`,fileName:`yarcl.css`,source:`${u}\n${l}`})}},vite:{config(e){return s=(0,r.resolve)(n.root??e.root??process.cwd()),{optimizeDeps:{exclude:[B],include:[`@floating-ui/react`,`date-fns`,`date-fns/locale`,`date-fns/locale/en-US`].map(e=>`${B} > ${e}`)},ssr:{noExternal:[B]}}},handleHotUpdate({file:e,server:t,modules:n}){if(!p.has(e))return;let r=t.moduleGraph.getModuleById(R);if(r)return t.moduleGraph.invalidateModule(r),[...n,r]}},webpack(e){s=(0,r.resolve)(n.root??e.context)},rspack(e){s=(0,r.resolve)(n.root??e.context)},esbuild:{config(e){s=(0,r.resolve)(n.root??e.absWorkingDir??process.cwd()),m()},setup(e){e.onResolve({filter:/^@yarcl\/config$/},()=>({path:c}))},loader:`css`}}}).rspack;module.exports=q;
|
package/dist/rspack.d.ts
ADDED
package/dist/rspack.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import buildConfig from '@yarcl/config';
|
|
2
|
+
import type { ComponentName, YarclShape } from './define';
|
|
3
|
+
import type { ComponentDefaults } from './types';
|
|
4
|
+
type Config = typeof buildConfig;
|
|
5
|
+
export declare function activeConfig(): Config;
|
|
6
|
+
export declare function setActiveConfig(next: YarclShape | null): void;
|
|
7
|
+
/**
|
|
8
|
+
* The config components currently read their defaults from: the build-time config, or the
|
|
9
|
+
* theme passed to `applyTheme`. Re-renders the caller when the theme changes.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useConfig(): Config;
|
|
12
|
+
export declare function useDefaults(component: ComponentName): ComponentDefaults;
|
|
13
|
+
export {};
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import buildConfig from "@yarcl/config";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
//#region src/runtime.ts
|
|
4
|
+
var active = buildConfig;
|
|
5
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
6
|
+
function subscribe(listener) {
|
|
7
|
+
listeners.add(listener);
|
|
8
|
+
return () => {
|
|
9
|
+
listeners.delete(listener);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function activeConfig() {
|
|
13
|
+
return active;
|
|
14
|
+
}
|
|
15
|
+
function setActiveConfig(next) {
|
|
16
|
+
active = next ?? buildConfig;
|
|
17
|
+
listeners.forEach((listener) => listener());
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The config components currently read their defaults from: the build-time config, or the
|
|
21
|
+
* theme passed to `applyTheme`. Re-renders the caller when the theme changes.
|
|
22
|
+
*/
|
|
23
|
+
function useConfig() {
|
|
24
|
+
return useSyncExternalStore(subscribe, activeConfig, () => buildConfig);
|
|
25
|
+
}
|
|
26
|
+
function useDefaults(component) {
|
|
27
|
+
return useConfig().components?.[component] ?? {};
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { activeConfig, setActiveConfig, useConfig, useDefaults };
|
package/dist/setup.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const DEFAULT_CONFIG_PATH = "src/yarcl.config.ts";
|
|
2
|
+
export declare const CONFIG_MODULE = "@yarcl/config";
|
|
3
|
+
export declare function findTsconfig(root: string): string | undefined;
|
|
4
|
+
export declare function projectPath(from: string, target: string): string;
|
|
5
|
+
export declare function configMappings(root: string, tsconfig: string, configPath: string): string[];
|
|
6
|
+
export declare function assertConfigMapping(root: string, configPath: string, buildTool?: string): void;
|
package/dist/setup.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { parse } from "jsonc-parser";
|
|
4
|
+
//#region src/setup.ts
|
|
5
|
+
var DEFAULT_CONFIG_PATH = "src/yarcl.config.ts";
|
|
6
|
+
var CONFIG_MODULE = "@yarcl/config";
|
|
7
|
+
var tsconfigNames = ["tsconfig.app.json", "tsconfig.json"];
|
|
8
|
+
function findTsconfig(root) {
|
|
9
|
+
return tsconfigNames.map((name) => resolve(root, name)).find((file) => existsSync(file));
|
|
10
|
+
}
|
|
11
|
+
function projectPath(from, target) {
|
|
12
|
+
const path = relative(from, target).split(sep).join("/");
|
|
13
|
+
return path.startsWith(".") ? path : `./${path}`;
|
|
14
|
+
}
|
|
15
|
+
function configMappings(root, tsconfig, configPath) {
|
|
16
|
+
const base = dirname(tsconfig);
|
|
17
|
+
return [projectPath(base, resolve(root, configPath)), projectPath(base, resolve(root, "node_modules/@yarcl/react/dist/yarcl.config.d.ts"))];
|
|
18
|
+
}
|
|
19
|
+
function assertConfigMapping(root, configPath, buildTool = "build tool") {
|
|
20
|
+
const tsconfig = findTsconfig(root);
|
|
21
|
+
if (!tsconfig) throw new Error(`yarcl: No tsconfig.app.json or tsconfig.json found in ${root}. Run "yarcl init".`);
|
|
22
|
+
const errors = [];
|
|
23
|
+
const config = parse(readFileSync(tsconfig, "utf8"), errors, { allowTrailingComma: true });
|
|
24
|
+
if (errors.length > 0) throw new Error(`yarcl: Could not parse ${projectPath(root, tsconfig)}.`);
|
|
25
|
+
const mapping = config?.compilerOptions?.paths?.[CONFIG_MODULE];
|
|
26
|
+
const expected = resolve(root, configPath);
|
|
27
|
+
const actual = Array.isArray(mapping) && typeof mapping[0] === "string" ? resolve(dirname(tsconfig), mapping[0]) : void 0;
|
|
28
|
+
if (actual === expected) return;
|
|
29
|
+
const current = actual ? `"${projectPath(root, actual)}"` : "no path";
|
|
30
|
+
throw new Error(`yarcl: Config path mismatch. ${buildTool} uses "${configPath}", but ${projectPath(root, tsconfig)} has ${current} for "${CONFIG_MODULE}". Run "yarcl init --config ${configPath}".`);
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { CONFIG_MODULE, DEFAULT_CONFIG_PATH, assertConfigMapping, configMappings, findTsconfig, projectPath };
|