@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
package/dist/css.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { YarclShape } from './define
|
|
1
|
+
import type { YarclShape } from './define';
|
|
2
2
|
/**
|
|
3
3
|
* Generates the stylesheet for a config: CSS variables on `:root`, one class per key and
|
|
4
|
-
* `@font-face` rules. The
|
|
4
|
+
* `@font-face` rules. The build plugin calls this at build time; call it yourself to preview
|
|
5
5
|
* or switch themes at runtime (inject the result into a `<style>` element).
|
|
6
6
|
*
|
|
7
7
|
* @param config A config from `defineConfig`, e.g. one of `@yarcl/react/themes`.
|
package/dist/css.js
CHANGED
|
@@ -1,175 +1,211 @@
|
|
|
1
1
|
import { contrast, mix, parseHex, readableOn, readableText, toHex } from "./color.js";
|
|
2
|
-
|
|
2
|
+
//#region src/css.ts
|
|
3
|
+
var MIN_CONTRAST = 4.5;
|
|
3
4
|
function ident(key) {
|
|
4
|
-
|
|
5
|
+
return key.replace(/[^a-zA-Z0-9_-]/g, (c) => `\\${c}`);
|
|
5
6
|
}
|
|
6
7
|
function pair({ light, dark }) {
|
|
7
|
-
|
|
8
|
+
return light === dark ? light : `light-dark(${light}, ${dark})`;
|
|
8
9
|
}
|
|
9
10
|
function foreground(name, token, warn) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
const modes = ["light", "dark"];
|
|
12
|
+
const on = typeof token.on === "string" ? {
|
|
13
|
+
light: token.on,
|
|
14
|
+
dark: token.on
|
|
15
|
+
} : token.on;
|
|
16
|
+
const resolved = modes.map((mode) => {
|
|
17
|
+
const bg = parseHex(token[mode]);
|
|
18
|
+
if (on) {
|
|
19
|
+
const fg = parseHex(on[mode]);
|
|
20
|
+
if (bg && fg && contrast(bg, fg) < MIN_CONTRAST) warn(`colors.${name}: ${mode} foreground contrast ${contrast(bg, fg).toFixed(2)}:1 is below ${MIN_CONTRAST}:1`);
|
|
21
|
+
return on[mode];
|
|
22
|
+
}
|
|
23
|
+
if (!bg) {
|
|
24
|
+
warn(`colors.${name}: cannot compute a ${mode} foreground from "${token[mode]}"; use a hex value or set \`on\``);
|
|
25
|
+
return "#ffffff";
|
|
26
|
+
}
|
|
27
|
+
const fg = readableOn(bg);
|
|
28
|
+
const ratio = contrast(bg, parseHex(fg));
|
|
29
|
+
if (ratio < MIN_CONTRAST) warn(`colors.${name}: best ${mode} foreground contrast is ${ratio.toFixed(2)}:1, below ${MIN_CONTRAST}:1`);
|
|
30
|
+
return fg;
|
|
31
|
+
});
|
|
32
|
+
return pair({
|
|
33
|
+
light: resolved[0],
|
|
34
|
+
dark: resolved[1]
|
|
35
|
+
});
|
|
33
36
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
var tint = (percent) => `color-mix(in oklab, var(--yarcl-c) ${percent}%, transparent)`;
|
|
38
|
+
var shade = (percent) => `color-mix(in oklab, var(--yarcl-c), var(--yarcl-c-on) ${percent}%)`;
|
|
39
|
+
var backgrounds = {
|
|
40
|
+
fill: [
|
|
41
|
+
"var(--yarcl-c)",
|
|
42
|
+
shade(12),
|
|
43
|
+
shade(20)
|
|
44
|
+
],
|
|
45
|
+
tint: [
|
|
46
|
+
tint(14),
|
|
47
|
+
tint(22),
|
|
48
|
+
tint(30)
|
|
49
|
+
],
|
|
50
|
+
none: [
|
|
51
|
+
"transparent",
|
|
52
|
+
tint(10),
|
|
53
|
+
tint(18)
|
|
54
|
+
]
|
|
40
55
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
var borders = {
|
|
57
|
+
color: "var(--yarcl-c)",
|
|
58
|
+
neutral: "var(--yarcl-neutral-border)",
|
|
59
|
+
none: "transparent"
|
|
45
60
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
var texts = {
|
|
62
|
+
on: "var(--yarcl-c-on)",
|
|
63
|
+
color: "var(--yarcl-c-text)",
|
|
64
|
+
neutral: "var(--yarcl-neutral-text)"
|
|
65
|
+
};
|
|
66
|
+
var formats = {
|
|
67
|
+
woff2: "woff2",
|
|
68
|
+
woff: "woff",
|
|
69
|
+
ttf: "truetype",
|
|
70
|
+
otf: "opentype"
|
|
50
71
|
};
|
|
51
|
-
const formats = { woff2: 'woff2', woff: 'woff', ttf: 'truetype', otf: 'opentype' };
|
|
52
72
|
function fontFace(face) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
]);
|
|
73
|
+
const sources = (Array.isArray(face.src) ? face.src : [face.src]).map((src) => {
|
|
74
|
+
if (src.startsWith("local(")) return src;
|
|
75
|
+
const format = formats[src.split(/[?#]/)[0].split(".").pop()?.toLowerCase() ?? ""];
|
|
76
|
+
return `url(${JSON.stringify(src)})${format ? ` format("${format}")` : ""}`;
|
|
77
|
+
});
|
|
78
|
+
return rule("@font-face", [
|
|
79
|
+
["font-family", JSON.stringify(face.family)],
|
|
80
|
+
["src", sources.join(", ")],
|
|
81
|
+
...face.weight != null ? [["font-weight", face.weight]] : [],
|
|
82
|
+
...face.style ? [["font-style", face.style]] : [],
|
|
83
|
+
["font-display", face.display ?? "swap"]
|
|
84
|
+
]);
|
|
66
85
|
}
|
|
67
|
-
|
|
86
|
+
var TEXT_TINTS = [
|
|
87
|
+
0,
|
|
88
|
+
.14,
|
|
89
|
+
.22
|
|
90
|
+
];
|
|
68
91
|
function textShade(name, token, neutrals) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
92
|
+
if (token.text) return pair(typeof token.text === "string" ? {
|
|
93
|
+
light: token.text,
|
|
94
|
+
dark: token.text
|
|
95
|
+
} : token.text);
|
|
96
|
+
const resolved = ["light", "dark"].map((mode) => {
|
|
97
|
+
const color = parseHex(token[mode]);
|
|
98
|
+
const text = parseHex(neutrals.text[mode]);
|
|
99
|
+
const grounds = [parseHex(neutrals.bg[mode]), parseHex(neutrals.surface[mode])];
|
|
100
|
+
if (!color || !text || grounds.some((g) => !g)) return token[mode];
|
|
101
|
+
const backgrounds = grounds.flatMap((ground) => TEXT_TINTS.map((alpha) => mix(ground, color, alpha)));
|
|
102
|
+
return toHex(readableText(color, backgrounds, text, MIN_CONTRAST));
|
|
103
|
+
});
|
|
104
|
+
return pair({
|
|
105
|
+
light: resolved[0],
|
|
106
|
+
dark: resolved[1]
|
|
107
|
+
});
|
|
82
108
|
}
|
|
83
109
|
function rule(selector, declarations) {
|
|
84
|
-
|
|
110
|
+
return `${selector} {\n${declarations.map(([p, v]) => ` ${p}: ${v};`).join("\n")}\n}`;
|
|
85
111
|
}
|
|
112
|
+
var sizeProperties = {
|
|
113
|
+
height: "h",
|
|
114
|
+
paddingX: "px",
|
|
115
|
+
fontSize: "fs",
|
|
116
|
+
iconSize: "icon"
|
|
117
|
+
};
|
|
86
118
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
119
|
+
* Generates the stylesheet for a config: CSS variables on `:root`, one class per key and
|
|
120
|
+
* `@font-face` rules. The build plugin calls this at build time; call it yourself to preview
|
|
121
|
+
* or switch themes at runtime (inject the result into a `<style>` element).
|
|
122
|
+
*
|
|
123
|
+
* @param config A config from `defineConfig`, e.g. one of `@yarcl/react/themes`.
|
|
124
|
+
* @param warn Receives contrast warnings.
|
|
125
|
+
*/
|
|
126
|
+
function generateCss(config, warn = () => {}) {
|
|
127
|
+
const root = [["color-scheme", "light dark"]];
|
|
128
|
+
const rules = [];
|
|
129
|
+
for (const [key, token] of Object.entries(config.colors)) {
|
|
130
|
+
const k = ident(key);
|
|
131
|
+
root.push([`--yarcl-color-${k}`, pair(token)], [`--yarcl-color-${k}-on`, foreground(key, token, warn)], [`--yarcl-color-${k}-text`, textShade(key, token, config.neutrals)]);
|
|
132
|
+
rules.push(rule(`.yarcl-color-${k}`, [
|
|
133
|
+
["--yarcl-c", `var(--yarcl-color-${k})`],
|
|
134
|
+
["--yarcl-c-on", `var(--yarcl-color-${k}-on)`],
|
|
135
|
+
["--yarcl-c-text", `var(--yarcl-color-${k}-text)`]
|
|
136
|
+
]));
|
|
137
|
+
}
|
|
138
|
+
for (const [key, value] of Object.entries(config.neutrals)) root.push([`--yarcl-neutral-${ident(key)}`, pair(value)]);
|
|
139
|
+
for (const [key, size] of Object.entries(config.sizes)) {
|
|
140
|
+
const k = ident(key);
|
|
141
|
+
root.push([`--yarcl-size-${k}-height`, size.height], [`--yarcl-size-${k}-padding-x`, size.paddingX], [`--yarcl-size-${k}-font-size`, size.fontSize], [`--yarcl-size-${k}-icon-size`, size.iconSize]);
|
|
142
|
+
rules.push(rule(`.yarcl-size-${k}`, [
|
|
143
|
+
["--yarcl-h", `var(--yarcl-size-${k}-height)`],
|
|
144
|
+
["--yarcl-px", `var(--yarcl-size-${k}-padding-x)`],
|
|
145
|
+
["--yarcl-fs", `var(--yarcl-size-${k}-font-size)`],
|
|
146
|
+
["--yarcl-icon", `var(--yarcl-size-${k}-icon-size)`]
|
|
147
|
+
]));
|
|
148
|
+
}
|
|
149
|
+
for (const [component, { sizeOverrides }] of Object.entries(config.components ?? {})) for (const [key, overrides] of Object.entries(sizeOverrides ?? {})) {
|
|
150
|
+
const declarations = Object.entries(overrides).map(([property, value]) => [`--yarcl-${sizeProperties[property]}`, value]);
|
|
151
|
+
const marker = `.yarcl-sized-${ident(component)}`;
|
|
152
|
+
const sized = `.yarcl-size-${ident(key)}`;
|
|
153
|
+
if (declarations.length) rules.push(rule(`${marker}${sized},\n${marker}${marker} ${sized}`, declarations));
|
|
154
|
+
}
|
|
155
|
+
for (const [key, value] of Object.entries(config.radii)) {
|
|
156
|
+
const k = ident(key);
|
|
157
|
+
root.push([`--yarcl-radius-${k}`, value]);
|
|
158
|
+
rules.push(rule(`.yarcl-radius-${k}`, [["--yarcl-r", `var(--yarcl-radius-${k})`]]));
|
|
159
|
+
}
|
|
160
|
+
for (const [key, variant] of Object.entries(config.variants)) {
|
|
161
|
+
const [bg, hover, active] = backgrounds[variant.background];
|
|
162
|
+
rules.push(rule(`.yarcl-variant-${ident(key)}`, [
|
|
163
|
+
["--yarcl-v-bg", bg],
|
|
164
|
+
["--yarcl-v-bg-hover", hover],
|
|
165
|
+
["--yarcl-v-bg-active", active],
|
|
166
|
+
["--yarcl-v-border", borders[variant.border]],
|
|
167
|
+
["--yarcl-v-fg", texts[variant.text]]
|
|
168
|
+
]));
|
|
169
|
+
}
|
|
170
|
+
for (const [key, value] of Object.entries(config.spacing)) {
|
|
171
|
+
const k = ident(key);
|
|
172
|
+
root.push([`--yarcl-space-${k}`, value]);
|
|
173
|
+
rules.push(rule(`.yarcl-gap-${k}`, [["--yarcl-component-gap", `var(--yarcl-space-${k})`]]), rule(`.yarcl-padding-${k}`, [["--yarcl-component-padding", `var(--yarcl-space-${k})`]]));
|
|
174
|
+
}
|
|
175
|
+
for (const [key, value] of Object.entries(config.shadows)) {
|
|
176
|
+
const k = ident(key);
|
|
177
|
+
root.push([`--yarcl-shadow-${k}`, value]);
|
|
178
|
+
rules.push(rule(`.yarcl-shadow-${k}`, [["box-shadow", `var(--yarcl-shadow-${k})`]]));
|
|
179
|
+
}
|
|
180
|
+
for (const [key, value] of Object.entries(config.modalSizes)) {
|
|
181
|
+
const k = ident(key);
|
|
182
|
+
root.push([`--yarcl-modal-${k}`, value]);
|
|
183
|
+
rules.push(rule(`.yarcl-modal-size-${k}`, [["--yarcl-modal-width", `var(--yarcl-modal-${k})`]]));
|
|
184
|
+
}
|
|
185
|
+
for (const [key, density] of Object.entries(config.density)) rules.push(rule(`.yarcl-density-${ident(key)}`, [
|
|
186
|
+
["--yarcl-cell-px", density.paddingX],
|
|
187
|
+
["--yarcl-cell-py", density.paddingY],
|
|
188
|
+
["--yarcl-cell-fs", density.fontSize]
|
|
189
|
+
]));
|
|
190
|
+
for (const [key, value] of Object.entries(config.typography.families)) root.push([`--yarcl-font-${ident(key)}`, value]);
|
|
191
|
+
for (const [key, style] of Object.entries(config.typography.styles)) rules.push(rule(`.yarcl-type-${ident(key)}`, [
|
|
192
|
+
["font-family", `var(--yarcl-font-${ident(style.family)})`],
|
|
193
|
+
["font-size", style.size],
|
|
194
|
+
["font-weight", style.weight],
|
|
195
|
+
["line-height", style.lineHeight],
|
|
196
|
+
...style.letterSpacing ? [["letter-spacing", style.letterSpacing]] : []
|
|
197
|
+
]));
|
|
198
|
+
for (const [key, value] of Object.entries(config.zIndex)) root.push([`--yarcl-z-${ident(key)}`, value]);
|
|
199
|
+
for (const [key, value] of Object.entries(config.motion)) root.push([`--yarcl-motion-${ident(key)}`, value]);
|
|
200
|
+
for (const [key, value] of Object.entries(config.borders)) root.push([`--yarcl-border-${ident(key)}`, value]);
|
|
201
|
+
const defaultSize = ident(config.defaults.size);
|
|
202
|
+
const defaultRadius = config.defaults.radius === "size" ? defaultSize : ident(config.defaults.radius);
|
|
203
|
+
root.push(["--yarcl-focus-width", config.focusRing.width], ["--yarcl-focus-offset", config.focusRing.offset], ["--yarcl-focus-style", config.focusRing.style ?? "solid"], ["--yarcl-focus-color", `var(--yarcl-color-${ident(config.focusRing.color)})`], ["--yarcl-error", `var(--yarcl-color-${ident(config.defaults.errorColor)})`], ["--yarcl-floating-shadow", `var(--yarcl-shadow-${ident(config.defaults.floatingShadow)})`], ["--yarcl-padding", `var(--yarcl-space-${ident(config.defaults.padding)})`], ["--yarcl-gap", `var(--yarcl-space-${ident(config.defaults.gap)})`], ["--yarcl-h", `var(--yarcl-size-${defaultSize}-height)`], ["--yarcl-px", `var(--yarcl-size-${defaultSize}-padding-x)`], ["--yarcl-fs", `var(--yarcl-size-${defaultSize}-font-size)`], ["--yarcl-icon", `var(--yarcl-size-${defaultSize}-icon-size)`], ["--yarcl-r", `var(--yarcl-radius-${defaultRadius}, 0)`]);
|
|
204
|
+
return [
|
|
205
|
+
...(config.typography.fontFaces ?? []).map(fontFace),
|
|
206
|
+
rule(":root", root),
|
|
207
|
+
...rules
|
|
208
|
+
].join("\n\n") + "\n";
|
|
175
209
|
}
|
|
210
|
+
//#endregion
|
|
211
|
+
export { generateCss };
|
package/dist/define.d.ts
CHANGED
|
@@ -21,8 +21,8 @@ export interface ColorToken extends ColorPair {
|
|
|
21
21
|
text?: string | ColorPair;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* A single step of the
|
|
25
|
-
*
|
|
24
|
+
* A single step of the base control size scale. Sized controls share it unless their component
|
|
25
|
+
* config overrides individual fields.
|
|
26
26
|
*/
|
|
27
27
|
export interface SizeToken {
|
|
28
28
|
/** Control height, e.g. `'2.5rem'`. */
|
|
@@ -106,7 +106,9 @@ export interface ComponentTokenProps {
|
|
|
106
106
|
Switch: 'size' | 'color';
|
|
107
107
|
Slider: 'size' | 'radius' | 'color';
|
|
108
108
|
Badge: 'size' | 'radius' | 'color' | 'variant';
|
|
109
|
-
|
|
109
|
+
Avatar: 'size' | 'radius' | 'color' | 'variant';
|
|
110
|
+
AvatarGroup: 'size' | 'radius' | 'color' | 'variant';
|
|
111
|
+
Alert: 'radius' | 'color' | 'variant' | 'gap' | 'padding' | 'textStyle';
|
|
110
112
|
Card: 'radius' | 'padding' | 'shadow';
|
|
111
113
|
Popover: 'radius' | 'padding';
|
|
112
114
|
HoverCard: 'radius' | 'padding';
|
|
@@ -117,20 +119,33 @@ export interface ComponentTokenProps {
|
|
|
117
119
|
Tabs: 'size' | 'color';
|
|
118
120
|
Pagination: 'size' | 'radius' | 'color' | 'variant' | 'selectedVariant';
|
|
119
121
|
Accordion: 'size' | 'radius' | 'color';
|
|
120
|
-
Table: 'density';
|
|
122
|
+
Table: 'density' | 'radius';
|
|
121
123
|
Stack: 'gap';
|
|
122
124
|
Inline: 'gap';
|
|
123
125
|
Text: 'textStyle' | 'color';
|
|
124
|
-
Label: 'textStyle' | 'color';
|
|
126
|
+
Label: 'textStyle' | 'color' | 'variant' | 'size' | 'radius';
|
|
125
127
|
Link: 'color';
|
|
126
128
|
Breadcrumb: 'textStyle' | 'color';
|
|
127
129
|
Spinner: 'size' | 'color';
|
|
128
130
|
Skeleton: 'size' | 'radius';
|
|
129
131
|
Progress: 'size' | 'color' | 'radius';
|
|
130
|
-
|
|
132
|
+
EmptyState: 'color' | 'gap' | 'padding' | 'textStyle';
|
|
133
|
+
Tooltip: 'radius' | 'padding' | 'textStyle';
|
|
134
|
+
Toast: 'radius' | 'color' | 'gap' | 'padding' | 'textStyle';
|
|
131
135
|
}
|
|
132
136
|
/** Names of components that accept defaults in `components`. */
|
|
133
137
|
export type ComponentName = keyof ComponentTokenProps;
|
|
138
|
+
type ControlSizeComponentName = Exclude<{
|
|
139
|
+
[C in ComponentName]: 'size' extends ComponentTokenProps[C] ? C : never;
|
|
140
|
+
}[ComponentName], 'Dialog' | 'Drawer'>;
|
|
141
|
+
type ComponentConfig<C extends ComponentName> = {
|
|
142
|
+
[P in ComponentTokenProps[C]]?: string;
|
|
143
|
+
} & (C extends ControlSizeComponentName ? {
|
|
144
|
+
/** Global size keys this component accepts. All global sizes are accepted when omitted. */
|
|
145
|
+
allowedSizes?: readonly string[];
|
|
146
|
+
/** Partial overrides of global size tokens, scoped to this component. */
|
|
147
|
+
sizeOverrides?: Record<string, Partial<SizeToken>>;
|
|
148
|
+
} : object);
|
|
134
149
|
/**
|
|
135
150
|
* The structure every yarcl config must satisfy.
|
|
136
151
|
*
|
|
@@ -155,7 +170,7 @@ export interface YarclShape {
|
|
|
155
170
|
/** Default border. */
|
|
156
171
|
border: ColorPair;
|
|
157
172
|
};
|
|
158
|
-
/**
|
|
173
|
+
/** Base control size scale. Keys become valid `size` values unless a component restricts them. */
|
|
159
174
|
sizes: Record<string, SizeToken>;
|
|
160
175
|
/**
|
|
161
176
|
* Border radii. Keys become the valid values of the `radius` prop. Name them after your
|
|
@@ -240,13 +255,11 @@ export interface YarclShape {
|
|
|
240
255
|
style?: 'solid' | 'dashed' | 'dotted' | 'double';
|
|
241
256
|
};
|
|
242
257
|
/**
|
|
243
|
-
* Per-component defaults, e.g. `{ Button: { radius: 'square' } }`.
|
|
244
|
-
*
|
|
258
|
+
* Per-component defaults and sizing, e.g. `{ Button: { radius: 'square', allowedSizes: ['sm', 'md'] } }`.
|
|
259
|
+
* Defaults apply when a prop is omitted, before the global `defaults`.
|
|
245
260
|
*/
|
|
246
261
|
components?: {
|
|
247
|
-
[C in ComponentName]?:
|
|
248
|
-
[P in ComponentTokenProps[C]]?: string;
|
|
249
|
-
};
|
|
262
|
+
[C in ComponentName]?: ComponentConfig<C>;
|
|
250
263
|
};
|
|
251
264
|
/** Values used when a component prop is omitted. Each must be a key of its group. */
|
|
252
265
|
defaults: {
|
|
@@ -300,8 +313,20 @@ interface TokenKeys<T extends YarclShape> {
|
|
|
300
313
|
}
|
|
301
314
|
type ComponentChecks<T extends YarclShape> = {
|
|
302
315
|
[C in keyof T['components']]: C extends ComponentName ? {
|
|
303
|
-
[P in keyof T['components'][C]]: P extends ComponentTokenProps[C] ? C extends 'Dialog' | 'Drawer' ? P extends 'size' ? keyof T['modalSizes'] : TokenKeys<T>[P] :
|
|
304
|
-
|
|
316
|
+
[P in keyof T['components'][C]]: P extends ComponentTokenProps[C] ? C extends 'Dialog' | 'Drawer' ? P extends 'size' ? keyof T['modalSizes'] : TokenKeys<T>[P] : P extends 'size' ? T['components'][C] extends {
|
|
317
|
+
allowedSizes: readonly (infer S)[];
|
|
318
|
+
} ? S : keyof T['sizes'] : TokenKeys<T>[P] : P extends 'allowedSizes' ? C extends ControlSizeComponentName ? readonly [keyof T['sizes'], ...(keyof T['sizes'])[]] : never : P extends 'sizeOverrides' ? C extends ControlSizeComponentName ? {
|
|
319
|
+
[K in keyof T['components'][C][P]]: K extends keyof T['sizes'] ? T['components'][C] extends {
|
|
320
|
+
allowedSizes: readonly (infer S)[];
|
|
321
|
+
} ? K extends S ? Partial<SizeToken> : never : Partial<SizeToken> : never;
|
|
322
|
+
} : never : never;
|
|
323
|
+
} & (C extends ControlSizeComponentName ? T['components'][C] extends {
|
|
324
|
+
allowedSizes: readonly (infer S)[];
|
|
325
|
+
} ? T['components'][C] extends {
|
|
326
|
+
size: unknown;
|
|
327
|
+
} ? object : T['defaults']['size'] extends S ? object : {
|
|
328
|
+
size: S;
|
|
329
|
+
} : object : object) : {
|
|
305
330
|
error: `Unknown component "${C & string}"`;
|
|
306
331
|
};
|
|
307
332
|
};
|
|
@@ -360,7 +385,7 @@ type Checks<T extends YarclShape> = {
|
|
|
360
385
|
* - every color has a `light` and `dark` value
|
|
361
386
|
* - `defaults`, `focusRing.color`, `typography.headings` and each text style's `family` reference existing keys
|
|
362
387
|
* - no key contains whitespace
|
|
363
|
-
* - `components` only names known components, only sets
|
|
388
|
+
* - `components` only names known components, only sets supported options, and only uses existing keys
|
|
364
389
|
*
|
|
365
390
|
* Returns the config unchanged with literal types preserved, so the library can derive
|
|
366
391
|
* its prop types from it. Spread `@yarcl/react/defaults` to extend the library defaults instead
|
package/dist/define.js
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
|
+
//#region src/define.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
3
|
+
* Declares a yarcl design system config.
|
|
4
|
+
*
|
|
5
|
+
* Checks at compile time that:
|
|
6
|
+
* - every color has a `light` and `dark` value
|
|
7
|
+
* - `defaults`, `focusRing.color`, `typography.headings` and each text style's `family` reference existing keys
|
|
8
|
+
* - no key contains whitespace
|
|
9
|
+
* - `components` only names known components, only sets supported options, and only uses existing keys
|
|
10
|
+
*
|
|
11
|
+
* Returns the config unchanged with literal types preserved, so the library can derive
|
|
12
|
+
* its prop types from it. Spread `@yarcl/react/defaults` to extend the library defaults instead
|
|
13
|
+
* of replacing them.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // src/yarcl.config.ts
|
|
18
|
+
* import { defineConfig } from '@yarcl/react/define';
|
|
19
|
+
* import defaults from '@yarcl/react/defaults';
|
|
20
|
+
*
|
|
21
|
+
* export default defineConfig({
|
|
22
|
+
* ...defaults,
|
|
23
|
+
* colors: { ...defaults.colors, brand: { light: '#2d4bb8', dark: '#8aa2ff' } },
|
|
24
|
+
* defaults: { ...defaults.defaults, color: 'brand' },
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function defineConfig(config) {
|
|
29
|
+
return config;
|
|
29
30
|
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { defineConfig };
|
package/dist/demo.d.ts
ADDED
package/dist/demo.js
ADDED
package/dist/esbuild.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`}}}).esbuild;module.exports=q;
|