@rickycourtes/designrail 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/README.md +97 -22
- package/kit/changes.json +152 -9
- package/kit/parts/base.css +6 -2
- package/kit/parts/button.css +65 -13
- package/kit/parts/card.css +16 -1
- package/kit/parts/dropdown.css +16 -5
- package/kit/parts/field.css +48 -9
- package/kit/parts/pill.css +35 -11
- package/kit/parts/sheet.css +36 -9
- package/kit/parts/toast.css +22 -6
- package/kit/tokens.css +3 -0
- package/package.json +2 -1
- package/rules/DESIGN.md +7 -2
- package/schema.json +2 -1
- package/src/check.js +45 -4
- package/src/cli.js +7 -0
- package/src/contract.js +2 -0
- package/src/init.js +20 -3
- package/src/model.js +2 -2
- package/src/project.js +25 -1
- package/src/sources.js +7 -1
- package/src/tokens.js +8 -4
package/kit/parts/card.css
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
.card > .inset a box inside: its corner is concentric (outer radius − padding)
|
|
4
4
|
.card-head a title and its line, tighter than the gap to the body
|
|
5
5
|
A box is only as big as what it holds: it never stretches to a column.
|
|
6
|
-
Knobs: --card-pad --card-gap --card-radius --card-bg --card-shadow --card-rim
|
|
6
|
+
Knobs: --card-pad --card-gap --card-radius --card-bg --card-shadow --card-rim
|
|
7
|
+
--card-blur (a backdrop-filter, none) --card-fg (inherit)
|
|
8
|
+
--card-align (align-items, normal) --card-align-content (normal: a card
|
|
9
|
+
set to display: grid packs its rows at the top with start)
|
|
10
|
+
--card-type (the whole font shorthand; initial, so the font inherits) */
|
|
7
11
|
|
|
8
12
|
@layer designrail.parts {
|
|
9
13
|
.card {
|
|
@@ -13,14 +17,25 @@
|
|
|
13
17
|
--card-bg: var(--surface-raised);
|
|
14
18
|
--card-shadow: var(--shadow-raised);
|
|
15
19
|
--card-rim: transparent;
|
|
20
|
+
--card-blur: none;
|
|
21
|
+
--card-fg: inherit;
|
|
22
|
+
--card-align: normal;
|
|
23
|
+
--card-align-content: normal;
|
|
24
|
+
--card-type: initial;
|
|
16
25
|
display: flex;
|
|
17
26
|
flex-direction: column;
|
|
18
27
|
gap: var(--card-gap);
|
|
28
|
+
align-items: var(--card-align);
|
|
29
|
+
align-content: var(--card-align-content);
|
|
19
30
|
padding: var(--card-pad);
|
|
20
31
|
border: 1px solid var(--card-rim);
|
|
21
32
|
border-radius: var(--card-radius);
|
|
22
33
|
background: var(--card-bg);
|
|
23
34
|
box-shadow: var(--card-shadow);
|
|
35
|
+
color: var(--card-fg);
|
|
36
|
+
font: var(--card-type);
|
|
37
|
+
-webkit-backdrop-filter: var(--card-blur);
|
|
38
|
+
backdrop-filter: var(--card-blur);
|
|
24
39
|
align-self: start;
|
|
25
40
|
}
|
|
26
41
|
.card.flat { --card-shadow: none; --card-rim: var(--border); }
|
package/kit/parts/dropdown.css
CHANGED
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
</div>
|
|
8
8
|
dropdown.js wires opening, arrow keys, Escape and outside clicks.
|
|
9
9
|
The menu's corner is concentric with its rows: radius − padding.
|
|
10
|
-
Knobs: --menu-pad --menu-radius --menu-bg --menu-shadow --menu-min-w --menu-item-h
|
|
10
|
+
Knobs: --menu-pad --menu-radius --menu-bg --menu-shadow --menu-min-w --menu-item-h
|
|
11
|
+
--menu-gap (between rows, 0) --menu-rim (an inside rim that takes no
|
|
12
|
+
room, transparent) --menu-fg (the text colour, inherit) --menu-origin
|
|
13
|
+
(where it grows from, top left; .end: top right).
|
|
14
|
+
A .menu that is a [popover] draws no browser rim: its rim is --menu-rim. */
|
|
11
15
|
|
|
12
16
|
@layer designrail.parts {
|
|
13
17
|
.dropdown { position: relative; display: inline-block; }
|
|
@@ -18,21 +22,28 @@
|
|
|
18
22
|
--menu-shadow: var(--shadow-overlay);
|
|
19
23
|
--menu-min-w: 220px;
|
|
20
24
|
--menu-item-h: 40px;
|
|
25
|
+
--menu-gap: 0px;
|
|
26
|
+
--menu-rim: transparent;
|
|
27
|
+
--menu-fg: inherit;
|
|
28
|
+
--menu-origin: top left;
|
|
21
29
|
position: absolute;
|
|
22
30
|
z-index: 50;
|
|
23
31
|
top: calc(100% + var(--space-6));
|
|
24
32
|
left: 0;
|
|
25
33
|
display: grid;
|
|
34
|
+
gap: var(--menu-gap);
|
|
26
35
|
min-width: var(--menu-min-w);
|
|
27
36
|
padding: var(--menu-pad);
|
|
28
37
|
border-radius: var(--menu-radius);
|
|
38
|
+
border: 0;
|
|
29
39
|
background: var(--menu-bg);
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
color: var(--menu-fg);
|
|
41
|
+
box-shadow: inset 0 0 0 1px var(--menu-rim), var(--menu-shadow);
|
|
42
|
+
transform-origin: var(--menu-origin);
|
|
32
43
|
animation: dr-menu-in var(--duration-fast) var(--ease-out);
|
|
33
44
|
}
|
|
34
45
|
.menu[hidden] { display: none; }
|
|
35
|
-
.menu.end { left: auto; right: 0;
|
|
46
|
+
.menu.end { --menu-origin: top right; left: auto; right: 0; }
|
|
36
47
|
.menu-item {
|
|
37
48
|
display: flex;
|
|
38
49
|
align-items: center;
|
|
@@ -47,7 +58,7 @@
|
|
|
47
58
|
text-align: start;
|
|
48
59
|
cursor: pointer;
|
|
49
60
|
}
|
|
50
|
-
.menu-item:hover, .menu-item:focus-visible { background: var(--fill); outline: none; }
|
|
61
|
+
.menu-item:hover, .menu-item.is-hover, .menu-item:focus-visible, .menu-item.is-focus { background: var(--fill); outline: none; }
|
|
51
62
|
.menu-item[aria-checked='true'] { color: var(--accent); }
|
|
52
63
|
.menu-sep { height: 1px; margin: var(--space-4) 0; background: var(--border); }
|
|
53
64
|
|
package/kit/parts/field.css
CHANGED
|
@@ -8,10 +8,22 @@
|
|
|
8
8
|
every side (unlike a button). Focus turns the rim to the accent; the ring
|
|
9
9
|
is for the keyboard only. .check is a checkbox or radio with its label.
|
|
10
10
|
Knobs: --input-h --input-line --input-rim-w --input-radius --input-bg
|
|
11
|
-
--input-fg --input-rim --input-rim-hover --input-rim-focus --field-gap
|
|
11
|
+
--input-fg --input-rim --input-rim-hover --input-rim-focus --field-gap
|
|
12
|
+
--input-pad-y (default derived from the height) --input-pad-x (--space-12)
|
|
13
|
+
--input-pad-end (--input-pad-x) --input-bg-hover (--input-bg)
|
|
14
|
+
--input-bg-focus (--input-bg, on :focus-within, so a wrapper .input
|
|
15
|
+
around its <input> lights too) --input-shadow (none) --input-font
|
|
16
|
+
(the font shorthand: --font-size-body / --input-line --font-ui)
|
|
17
|
+
--input-rim-style (solid: none for a wrapper .input with no rim at all)
|
|
18
|
+
--input-align (align-items, normal) --input-gap (gap, normal): for a
|
|
19
|
+
wrapper .input a page lays out as a flex row.
|
|
20
|
+
A .field may be a <fieldset>: its margin, padding and border reset.
|
|
21
|
+
.check knobs: --check-gap (--space-8) --check-pad-y (0) --check-fg
|
|
22
|
+
(inherit) --check-font (inherit) --check-line (1.5, after the font: set it
|
|
23
|
+
to the font's own line when --check-font names one). */
|
|
12
24
|
|
|
13
25
|
@layer designrail.parts {
|
|
14
|
-
.field { --field-gap: var(--space-6); display: grid; gap: var(--field-gap); align-content: start; }
|
|
26
|
+
.field { --field-gap: var(--space-6); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--field-gap); align-content: start; min-width: 0; margin: 0; padding: 0; border: 0; }
|
|
15
27
|
.field > .label { font-size: var(--font-size-small); font-weight: var(--weight-strong); color: var(--text); }
|
|
16
28
|
.field > .hint { font-size: var(--font-size-small); color: var(--text-muted); }
|
|
17
29
|
.field.invalid > .hint { color: var(--danger); }
|
|
@@ -20,27 +32,40 @@
|
|
|
20
32
|
--input-h: var(--control-h);
|
|
21
33
|
--input-line: 20px;
|
|
22
34
|
--input-rim-w: 1px;
|
|
35
|
+
--input-rim-style: solid;
|
|
36
|
+
--input-align: normal;
|
|
37
|
+
--input-gap: normal;
|
|
23
38
|
--input-radius: var(--radius-control);
|
|
24
39
|
--input-bg: var(--surface);
|
|
25
40
|
--input-fg: var(--text);
|
|
26
41
|
--input-rim: var(--border-strong);
|
|
27
42
|
--input-rim-hover: var(--text-faint);
|
|
28
43
|
--input-rim-focus: var(--accent);
|
|
44
|
+
--input-pad-y: calc((var(--input-h) - var(--input-line)) / 2 - var(--input-rim-w));
|
|
45
|
+
--input-pad-x: var(--space-12);
|
|
46
|
+
--input-pad-end: var(--input-pad-x);
|
|
47
|
+
--input-bg-hover: var(--input-bg);
|
|
48
|
+
--input-bg-focus: var(--input-bg);
|
|
49
|
+
--input-shadow: none;
|
|
50
|
+
--input-font: var(--font-size-body) / var(--input-line) var(--font-ui);
|
|
29
51
|
box-sizing: border-box;
|
|
30
52
|
width: 100%;
|
|
31
53
|
min-height: var(--input-h);
|
|
32
|
-
padding:
|
|
33
|
-
border: var(--input-rim-w)
|
|
54
|
+
padding: var(--input-pad-y) var(--input-pad-end) var(--input-pad-y) var(--input-pad-x);
|
|
55
|
+
border: var(--input-rim-w) var(--input-rim-style) var(--input-rim);
|
|
34
56
|
border-radius: var(--input-radius);
|
|
35
57
|
background: var(--input-bg);
|
|
58
|
+
box-shadow: var(--input-shadow);
|
|
59
|
+
align-items: var(--input-align);
|
|
60
|
+
gap: var(--input-gap);
|
|
36
61
|
color: var(--input-fg);
|
|
37
|
-
font: var(--
|
|
62
|
+
font: var(--input-font);
|
|
38
63
|
transition: border-color var(--duration-fast) var(--ease-out), background-color var(--duration-fast) var(--ease-out);
|
|
39
64
|
}
|
|
40
65
|
.input::placeholder { color: var(--text-faint); }
|
|
41
|
-
.input:hover { border-color: var(--input-rim-hover); }
|
|
42
|
-
.input:focus { border-color: var(--input-rim-focus); outline: none; }
|
|
43
|
-
.input:focus-visible { outline:
|
|
66
|
+
.input:hover, .input.is-hover { border-color: var(--input-rim-hover); background: var(--input-bg-hover); }
|
|
67
|
+
.input:focus, .input:focus-within, .input.is-focus { border-color: var(--input-rim-focus); background: var(--input-bg-focus); outline: none; }
|
|
68
|
+
.input:focus-visible { outline: var(--focus-ring); outline-offset: 1px; }
|
|
44
69
|
.field.invalid .input { --input-rim: var(--danger); --input-rim-hover: var(--danger); }
|
|
45
70
|
.input:disabled { --input-bg: var(--surface-sunken); --input-fg: var(--text-faint); }
|
|
46
71
|
textarea.input { min-height: calc(var(--input-h) * 2); resize: vertical; }
|
|
@@ -55,7 +80,21 @@
|
|
|
55
80
|
.input[type='search']::-webkit-search-cancel-button { display: none; }
|
|
56
81
|
|
|
57
82
|
/* A tick leads its label's first line: top-aligned, centred on that line. */
|
|
58
|
-
.check {
|
|
83
|
+
.check {
|
|
84
|
+
--check-gap: var(--space-8);
|
|
85
|
+
--check-pad-y: 0px;
|
|
86
|
+
--check-fg: inherit;
|
|
87
|
+
--check-font: inherit;
|
|
88
|
+
--check-line: 1.5;
|
|
89
|
+
display: flex;
|
|
90
|
+
align-items: flex-start;
|
|
91
|
+
gap: var(--check-gap);
|
|
92
|
+
padding: var(--check-pad-y) 0;
|
|
93
|
+
color: var(--check-fg);
|
|
94
|
+
font: var(--check-font);
|
|
95
|
+
line-height: var(--check-line);
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
}
|
|
59
98
|
.check > input {
|
|
60
99
|
--tick: 18px;
|
|
61
100
|
flex: none;
|
package/kit/parts/pill.css
CHANGED
|
@@ -1,21 +1,39 @@
|
|
|
1
1
|
/* pill: a short status or tag. .pill.accent / .danger / .success / .warning
|
|
2
2
|
tint it by what it says. .pill .dot leads with a mark --space-6 from the words.
|
|
3
3
|
.count is a number beside its label, never run into the text.
|
|
4
|
-
Knobs: --pill-tone (the colour it says) --pill-bg --pill-fg
|
|
4
|
+
Knobs: --pill-tone (the colour it says) --pill-bg --pill-fg
|
|
5
|
+
--pill-pad-y (--space-4) --pill-pad-x (--space-8) --pill-radius
|
|
6
|
+
(--radius-full) --pill-font (--weight-strong --font-size-small / 16px
|
|
7
|
+
--font-ui) --pill-blur (a backdrop-filter, none) --pill-text-shadow
|
|
8
|
+
(none). A pill may be a <button>: it draws no browser border.
|
|
9
|
+
.count knobs: --count-bg (--fill-hover) --count-fg (--text)
|
|
10
|
+
--count-font (--weight-strong --font-size-small / 1 --font-ui)
|
|
11
|
+
--count-pad-x (--space-6) --count-h (20px) --count-radius (--radius-full) */
|
|
5
12
|
|
|
6
13
|
@layer designrail.parts {
|
|
7
14
|
.pill {
|
|
8
15
|
--pill-tone: var(--text-muted);
|
|
9
16
|
--pill-bg: var(--fill);
|
|
10
17
|
--pill-fg: var(--pill-tone);
|
|
18
|
+
--pill-pad-y: var(--space-4);
|
|
19
|
+
--pill-pad-x: var(--space-8);
|
|
20
|
+
--pill-radius: var(--radius-full);
|
|
21
|
+
--pill-font: var(--weight-strong) var(--font-size-small) / 16px var(--font-ui);
|
|
22
|
+
--pill-blur: none;
|
|
23
|
+
--pill-text-shadow: none;
|
|
11
24
|
display: inline-flex;
|
|
12
25
|
align-items: center;
|
|
26
|
+
justify-content: center;
|
|
13
27
|
gap: var(--space-6);
|
|
14
|
-
padding: var(--
|
|
15
|
-
border
|
|
28
|
+
padding: var(--pill-pad-y) var(--pill-pad-x);
|
|
29
|
+
border: 0;
|
|
30
|
+
border-radius: var(--pill-radius);
|
|
16
31
|
background: var(--pill-bg);
|
|
17
32
|
color: var(--pill-fg);
|
|
18
|
-
font: var(--
|
|
33
|
+
font: var(--pill-font);
|
|
34
|
+
text-shadow: var(--pill-text-shadow);
|
|
35
|
+
-webkit-backdrop-filter: var(--pill-blur);
|
|
36
|
+
backdrop-filter: var(--pill-blur);
|
|
19
37
|
white-space: nowrap;
|
|
20
38
|
}
|
|
21
39
|
.pill > .dot { width: 6px; height: 6px; border-radius: var(--radius-full); background: currentColor; }
|
|
@@ -26,15 +44,21 @@
|
|
|
26
44
|
.pill.warning { --pill-tone: var(--warning); }
|
|
27
45
|
|
|
28
46
|
.count {
|
|
47
|
+
--count-bg: var(--fill-hover);
|
|
48
|
+
--count-fg: var(--text);
|
|
49
|
+
--count-font: var(--weight-strong) var(--font-size-small) / 1 var(--font-ui);
|
|
50
|
+
--count-pad-x: var(--space-6);
|
|
51
|
+
--count-h: 20px;
|
|
52
|
+
--count-radius: var(--radius-full);
|
|
29
53
|
display: inline-grid;
|
|
30
54
|
place-items: center;
|
|
31
|
-
min-width:
|
|
32
|
-
height:
|
|
33
|
-
padding: 0 var(--
|
|
34
|
-
border-radius: var(--radius
|
|
35
|
-
background: var(--
|
|
36
|
-
color: var(--
|
|
37
|
-
font: var(--
|
|
55
|
+
min-width: var(--count-h);
|
|
56
|
+
height: var(--count-h);
|
|
57
|
+
padding: 0 var(--count-pad-x);
|
|
58
|
+
border-radius: var(--count-radius);
|
|
59
|
+
background: var(--count-bg);
|
|
60
|
+
color: var(--count-fg);
|
|
61
|
+
font: var(--count-font);
|
|
38
62
|
font-variant-numeric: tabular-nums;
|
|
39
63
|
}
|
|
40
64
|
}
|
package/kit/parts/sheet.css
CHANGED
|
@@ -7,7 +7,18 @@
|
|
|
7
7
|
</dialog>
|
|
8
8
|
el.showModal() opens it. Nothing sits under the close button: the title
|
|
9
9
|
row stops a gap short of it.
|
|
10
|
-
Knobs: --sheet-pad --sheet-width --sheet-radius --sheet-bg --sheet-gap
|
|
10
|
+
Knobs: --sheet-pad --sheet-width --sheet-radius --sheet-bg --sheet-gap
|
|
11
|
+
--sheet-rim (an inside rim, transparent) --sheet-rim-w (1px)
|
|
12
|
+
--sheet-shadow (--shadow-overlay) --sheet-blur (a backdrop-filter, none)
|
|
13
|
+
--sheet-fg (--text) --sheet-border-w (0) --sheet-border-style (none): a
|
|
14
|
+
real border in --sheet-rim that can leave sides out (1px 0 0 is a
|
|
15
|
+
top-only rim, for a sheet standing on the page's foot); set --sheet-rim-w
|
|
16
|
+
to 0 with it so the ring doesn't draw too. --sheet-align-content (normal:
|
|
17
|
+
a sheet set to display: grid packs its rows at the top with start). The
|
|
18
|
+
gap applies on any sheet laid out as flex or grid, open or not.
|
|
19
|
+
Only dialog.sheet is sized and placed as a modal (width, max-height,
|
|
20
|
+
margin, the phone's bottom edge). A .sheet that is not a <dialog> is
|
|
21
|
+
placed by its page: a bottom dock, a side panel. */
|
|
11
22
|
|
|
12
23
|
@layer designrail.parts {
|
|
13
24
|
.sheet {
|
|
@@ -16,25 +27,41 @@
|
|
|
16
27
|
--sheet-width: 420px;
|
|
17
28
|
--sheet-radius: var(--radius-card);
|
|
18
29
|
--sheet-bg: var(--surface-raised);
|
|
30
|
+
--sheet-rim: transparent;
|
|
31
|
+
--sheet-rim-w: 1px;
|
|
32
|
+
--sheet-shadow: var(--shadow-overlay);
|
|
33
|
+
--sheet-blur: none;
|
|
34
|
+
--sheet-fg: var(--text);
|
|
35
|
+
--sheet-border-w: 0;
|
|
36
|
+
--sheet-border-style: none;
|
|
37
|
+
--sheet-align-content: normal;
|
|
19
38
|
box-sizing: border-box;
|
|
20
|
-
width: min(var(--sheet-width), calc(100vw - 2 * var(--space-16)));
|
|
21
|
-
max-height: calc(100dvh - 2 * var(--space-16));
|
|
22
39
|
padding: var(--sheet-pad);
|
|
23
|
-
border:
|
|
40
|
+
border-width: var(--sheet-border-w);
|
|
41
|
+
border-style: var(--sheet-border-style);
|
|
42
|
+
border-color: var(--sheet-rim);
|
|
24
43
|
border-radius: var(--sheet-radius);
|
|
25
44
|
background: var(--sheet-bg);
|
|
26
|
-
color: var(--
|
|
27
|
-
box-shadow: var(--
|
|
45
|
+
color: var(--sheet-fg);
|
|
46
|
+
box-shadow: inset 0 0 0 var(--sheet-rim-w) var(--sheet-rim), var(--sheet-shadow);
|
|
47
|
+
-webkit-backdrop-filter: var(--sheet-blur);
|
|
48
|
+
backdrop-filter: var(--sheet-blur);
|
|
49
|
+
gap: var(--sheet-gap);
|
|
50
|
+
align-content: var(--sheet-align-content);
|
|
28
51
|
overflow: auto;
|
|
29
52
|
}
|
|
30
|
-
.sheet
|
|
53
|
+
dialog.sheet {
|
|
54
|
+
width: min(var(--sheet-width), calc(100vw - 2 * var(--space-16)));
|
|
55
|
+
max-height: calc(100dvh - 2 * var(--space-16));
|
|
56
|
+
}
|
|
57
|
+
.sheet[open] { display: flex; flex-direction: column; animation: dr-sheet-in var(--duration-base) var(--ease-out); }
|
|
31
58
|
.sheet::backdrop { background: var(--surface-scrim); animation: dr-scrim-in var(--duration-base) var(--ease-out); }
|
|
32
59
|
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-12); margin: calc(var(--space-8) * -1) calc(var(--space-12) * -1) 0 0; }
|
|
33
60
|
.sheet-head > h2 { margin: 0; font: var(--weight-strong) var(--font-size-title) / 1.25 var(--font-display); }
|
|
34
61
|
|
|
35
62
|
@media (max-width: 520px) {
|
|
36
|
-
.sheet { width: 100vw; max-width: none; margin: auto 0 0; border-end-start-radius: 0; border-end-end-radius: 0; padding-bottom: max(var(--sheet-pad), env(safe-area-inset-bottom)); }
|
|
37
|
-
.sheet[open] { animation-name: dr-sheet-up; }
|
|
63
|
+
dialog.sheet { width: 100vw; max-width: none; margin: auto 0 0; border-end-start-radius: 0; border-end-end-radius: 0; padding-bottom: max(var(--sheet-pad), env(safe-area-inset-bottom)); }
|
|
64
|
+
dialog.sheet[open] { animation-name: dr-sheet-up; }
|
|
38
65
|
}
|
|
39
66
|
|
|
40
67
|
@keyframes dr-sheet-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
|
package/kit/parts/toast.css
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
toast.js builds them in one polite live region at the bottom of the page.
|
|
3
3
|
A filled box pads every side equally; an end that holds a button drops to
|
|
4
4
|
the top pad, so the button sits as far from the edge as from the top.
|
|
5
|
-
Knobs: --toast-bg --toast-fg --toast-radius --toast-max-w
|
|
5
|
+
Knobs: --toast-bg --toast-fg --toast-radius --toast-max-w
|
|
6
|
+
--toast-pad-y (--space-12) --toast-pad-start (--space-16) --toast-pad-end
|
|
7
|
+
(--space-16; --space-8 when the toast ends in a button) --toast-rim (an
|
|
8
|
+
inside rim, transparent) --toast-shadow (--shadow-overlay) --toast-gap
|
|
9
|
+
(--space-12) --toast-font (--font-size-body; inherits the rest)
|
|
10
|
+
--toast-type (the whole font shorthand; initial, so the font inherits):
|
|
11
|
+
its size still comes from --toast-font, so set that to the same size. */
|
|
6
12
|
|
|
7
13
|
@layer designrail.parts {
|
|
8
14
|
.toasts {
|
|
@@ -19,20 +25,30 @@
|
|
|
19
25
|
--toast-fg: var(--surface);
|
|
20
26
|
--toast-radius: var(--radius-card);
|
|
21
27
|
--toast-max-w: 420px;
|
|
28
|
+
--toast-pad-y: var(--space-12);
|
|
29
|
+
--toast-pad-start: var(--space-16);
|
|
30
|
+
--toast-pad-end: var(--space-16);
|
|
31
|
+
--toast-rim: transparent;
|
|
32
|
+
--toast-shadow: var(--shadow-overlay);
|
|
33
|
+
--toast-gap: var(--space-12);
|
|
34
|
+
--toast-font: var(--font-size-body);
|
|
35
|
+
--toast-type: initial;
|
|
22
36
|
display: flex;
|
|
23
37
|
align-items: center;
|
|
24
|
-
gap: var(--
|
|
38
|
+
gap: var(--toast-gap);
|
|
25
39
|
max-width: var(--toast-max-w);
|
|
26
|
-
padding: var(--
|
|
40
|
+
padding-block: var(--toast-pad-y);
|
|
41
|
+
padding-inline: var(--toast-pad-start) var(--toast-pad-end);
|
|
27
42
|
border-radius: var(--toast-radius);
|
|
28
43
|
background: var(--toast-bg);
|
|
29
44
|
color: var(--toast-fg);
|
|
30
|
-
box-shadow: var(--
|
|
31
|
-
font
|
|
45
|
+
box-shadow: inset 0 0 0 1px var(--toast-rim), var(--toast-shadow);
|
|
46
|
+
font: var(--toast-type);
|
|
47
|
+
font-size: var(--toast-font);
|
|
32
48
|
pointer-events: auto;
|
|
33
49
|
animation: dr-toast-in var(--duration-base) var(--ease-out);
|
|
34
50
|
}
|
|
35
|
-
.toast:has(> .btn:last-child) {
|
|
51
|
+
.toast:has(> .btn:last-child) { --toast-pad-end: var(--space-8); }
|
|
36
52
|
.toast > .btn { --btn-h: 32px; --btn-line: 16px; --btn-bg: color-mix(in srgb, var(--toast-fg) 14%, transparent); --btn-bg-hover: color-mix(in srgb, var(--toast-fg) 22%, transparent); --btn-fg: var(--toast-fg); }
|
|
37
53
|
.toast.leaving { opacity: 0; transform: translateY(8px); transition: opacity var(--duration-base) var(--ease-out), transform var(--duration-base) var(--ease-out); }
|
|
38
54
|
|
package/kit/tokens.css
CHANGED
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
--success: var(--green-500);
|
|
68
68
|
--warning: var(--amber-500);
|
|
69
69
|
--focus: var(--accent);
|
|
70
|
+
/* The keyboard focus mark: an outline, and a glow beside or instead of it. */
|
|
71
|
+
--focus-ring: 2px solid var(--focus);
|
|
72
|
+
--focus-glow: none;
|
|
70
73
|
|
|
71
74
|
/* --- semantic: type ---------------------------------------------------- */
|
|
72
75
|
--font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rickycourtes/designrail",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The design foundation for any web project: a token contract, layered parts every project builds on, and tooling to audit duplication, extract tokens, fix hardcoded values, gate drift and upgrade.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"./tokens.css": "./kit/tokens.css",
|
|
14
14
|
"./parts/*": "./kit/parts/*",
|
|
15
15
|
"./kit/*": "./kit/*",
|
|
16
|
+
"./rules/*": "./rules/*",
|
|
16
17
|
"./package.json": "./package.json"
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
package/rules/DESIGN.md
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
# Design rules
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The base rules: how every project on designrail builds its UI. A project's
|
|
4
|
+
own `DESIGN.md` extends this file (`@rickycourtes/designrail/rules/DESIGN.md`)
|
|
5
|
+
with rules of its own, and never reuses an `{id}` from here
|
|
6
|
+
(`designrail check`: rules-override). Every bullet ends with a tag
|
|
4
7
|
`{id · checks}`: `check` means `designrail check` fails a change that breaks
|
|
5
8
|
it, `audit` means `designrail audit` reports it, `eye` means a person or an
|
|
6
|
-
agent has to look.
|
|
9
|
+
agent has to look. A project can turn a rule up, never down: in
|
|
10
|
+
`designrail.config.json` → `rules` a level may rise from `warn` to `error`,
|
|
11
|
+
and `check` and `audit` refuse a config that lowers one.
|
|
7
12
|
|
|
8
13
|
## Tokens
|
|
9
14
|
|
package/schema.json
CHANGED
package/src/check.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Check: the drift gate. Every rule's hits on the project; with --staged or
|
|
2
2
|
// --base REF, only the hits the change adds (git is the baseline, there is no
|
|
3
3
|
// baseline file), so a messy codebase can adopt it today and only get cleaner.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
4
6
|
import { spawnSync } from 'node:child_process';
|
|
5
7
|
import { buildModel, slotOf } from './model.js';
|
|
6
8
|
import { analyze, ALL_EXT } from './sources.js';
|
|
@@ -13,8 +15,22 @@ import { splitTop } from './css.js';
|
|
|
13
15
|
|
|
14
16
|
// The tokens that make a project look like itself; the rest derive from them.
|
|
15
17
|
const CORE = ['--surface', '--text', '--accent', '--text-on-accent', '--font-ui'];
|
|
16
|
-
// Where a part is used may place it, never restyle it.
|
|
17
|
-
|
|
18
|
+
// Where a part is used may place it, never restyle it. Interaction
|
|
19
|
+
// properties (cursor, touch-action, overflow, scroll-*) aren't look either.
|
|
20
|
+
// The subject compound of one selector: :has()/:not() arguments dropped, then the part after the last combinator.
|
|
21
|
+
function subjectOf(sel) {
|
|
22
|
+
let out = '', i = 0;
|
|
23
|
+
const s = sel.trim();
|
|
24
|
+
while (i < s.length) {
|
|
25
|
+
const m = /^:(has|not)\(/.exec(s.slice(i));
|
|
26
|
+
if (!m) { out += s[i++]; continue; }
|
|
27
|
+
let depth = 0, j = i + m[0].length - 1;
|
|
28
|
+
for (; j < s.length; j++) { if (s[j] === '(') depth++; else if (s[j] === ')' && --depth === 0) break; }
|
|
29
|
+
i = j + 1;
|
|
30
|
+
}
|
|
31
|
+
return out.split(/[\s>+~]+/).filter(Boolean).pop() ?? '';
|
|
32
|
+
}
|
|
33
|
+
const LAYOUT = /^(margin(-[\w-]+)?|grid(-[\w-]+)?|flex(-[\w-]+)?|order|align-self|justify-self|place-self|(min-|max-)?(width|height|inline-size|block-size)|position|inset(-[\w-]+)?|top|right|bottom|left|z-index|display|visibility|opacity|pointer-events|transition(-[\w-]+)?|transform|animation(-[\w-]+)?|view-transition-name|contain|cursor|(-webkit-)?user-select|touch-action|-webkit-tap-highlight-color|-webkit-touch-callout|will-change|overflow(-x|-y)?|overscroll-behavior(-[\w-]+)?|scroll-[\w-]+)$/;
|
|
18
34
|
const HELPERS = new Set(['stack', 'row', 'tight', 'loose', 'muted', 'small', 'dot', 'inset', 'end', 'actions']);
|
|
19
35
|
|
|
20
36
|
// Classes the foundation's parts own: the first class each selector names
|
|
@@ -31,6 +47,21 @@ export function foundationClasses(foundation) {
|
|
|
31
47
|
return out;
|
|
32
48
|
}
|
|
33
49
|
|
|
50
|
+
// The `{id · checks}` tags of a rules file, with the line each sits on.
|
|
51
|
+
const BASE_RULES = new URL('../rules/DESIGN.md', import.meta.url);
|
|
52
|
+
export function ruleIds(text) {
|
|
53
|
+
const out = [];
|
|
54
|
+
text.split('\n').forEach((l, i) => { for (const m of l.matchAll(/\{([a-z][\w-]*\.[\w.-]+)\s*(?:·[^}]*)?\}/g)) out.push({ id: m[1], line: i + 1 }); });
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
let baseIds;
|
|
58
|
+
const baseRuleIds = () => (baseIds ??= new Set(ruleIds(fs.readFileSync(BASE_RULES, 'utf8')).map((r) => r.id)));
|
|
59
|
+
// The project's DESIGN.md: what `baselines` read from git, else the file.
|
|
60
|
+
function projectRules(model) {
|
|
61
|
+
if (model.designRules !== undefined) return model.designRules;
|
|
62
|
+
try { return fs.readFileSync(path.join(model.root, 'DESIGN.md'), 'utf8'); } catch { return null; }
|
|
63
|
+
}
|
|
64
|
+
|
|
34
65
|
const SLOTS = new Set(['color', 'space', 'radius', 'font-size', 'font', 'shadow']);
|
|
35
66
|
|
|
36
67
|
export function hits(model) {
|
|
@@ -89,7 +120,8 @@ export function hits(model) {
|
|
|
89
120
|
const looks = r.decls.filter((d) => !d.prop.startsWith('--') && !LAYOUT.test(d.prop));
|
|
90
121
|
if (!looks.length) continue;
|
|
91
122
|
for (const part of splitTop(r.sel)) {
|
|
92
|
-
|
|
123
|
+
// Only the subject compound counts: a class inside :has() or :not() is a condition, not what gets styled.
|
|
124
|
+
const last = subjectOf(part);
|
|
93
125
|
const classes = [...last.matchAll(/\.([\w-]+)/g)].map((m) => m[1]);
|
|
94
126
|
const hitPart = classes.find((c) => parts.has(c));
|
|
95
127
|
if (!hitPart) continue;
|
|
@@ -99,6 +131,12 @@ export function hits(model) {
|
|
|
99
131
|
}
|
|
100
132
|
}
|
|
101
133
|
}
|
|
134
|
+
if (on('rules-override') && model.root) {
|
|
135
|
+
// A project's rules extend the base; reusing a base id overrides it.
|
|
136
|
+
const text = projectRules(model);
|
|
137
|
+
const base = baseRuleIds();
|
|
138
|
+
if (text) for (const r of ruleIds(text)) if (base.has(r.id)) hit('rules-override', 'DESIGN.md', r.line, `{${r.id}} is a designrail base rule; a project rule adds to the base under an id of its own, never restates or overrides one`, r.id);
|
|
139
|
+
}
|
|
102
140
|
if (on('tracked-caps')) {
|
|
103
141
|
for (const f of model.files) for (const r of f.rules) {
|
|
104
142
|
const up = r.decls.some((d) => d.prop === 'text-transform' && /uppercase/.test(d.value));
|
|
@@ -122,6 +160,9 @@ export function baselines(project, { base = 'HEAD', staged = false }) {
|
|
|
122
160
|
const changed = new Set(git(root, staged ? ['diff', '--cached', '--name-only', base] : ['diff', '--name-only', base]).split('\n').filter((f) => ALL_EXT.test(f)));
|
|
123
161
|
if (!staged) for (const f of git(root, ['ls-files', '--others', '--exclude-standard']).split('\n')) if (ALL_EXT.test(f)) changed.add(f);
|
|
124
162
|
const show = (spec) => { const r = spawnSync('git', ['show', spec], { cwd: root, maxBuffer: 1 << 28, encoding: 'utf8' }); return r.status ? null : r.stdout; };
|
|
163
|
+
// DESIGN.md as it was and as it is, so rules-override counts only new overrides.
|
|
164
|
+
const rulesThen = show(`${base}:DESIGN.md`);
|
|
165
|
+
const rulesNow = staged ? show(':DESIGN.md') : undefined;
|
|
125
166
|
const keep = project.files.filter((f) => !changed.has(f.path));
|
|
126
167
|
const then = [...keep], now = staged ? [...keep] : [...project.files];
|
|
127
168
|
for (const rel of changed) {
|
|
@@ -129,7 +170,7 @@ export function baselines(project, { base = 'HEAD', staged = false }) {
|
|
|
129
170
|
if (was != null) then.push({ path: rel, ...analyze(rel, was) });
|
|
130
171
|
if (staged) { const is = show(`:${rel}`); if (is != null) now.push({ path: rel, ...analyze(rel, is) }); }
|
|
131
172
|
}
|
|
132
|
-
return { then: buildModel({ ...project, files: then }), now: buildModel({ ...project, files: now }), changed: [...changed] };
|
|
173
|
+
return { then: buildModel({ ...project, files: then, designRules: rulesThen }), now: buildModel({ ...project, files: now, ...(staged ? { designRules: rulesNow } : {}) }), changed: [...changed] };
|
|
133
174
|
}
|
|
134
175
|
|
|
135
176
|
// Hits in `now` beyond what `then` had: a count per key, so one more use of a
|
package/src/cli.js
CHANGED
|
@@ -102,6 +102,13 @@ export async function main(argv) {
|
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
if ((cmd === 'check' && !flags['--install-hook']) || cmd === 'audit') {
|
|
106
|
+
const { loadConfig, loosenedError } = await import('./project.js');
|
|
107
|
+
let msg;
|
|
108
|
+
try { msg = loosenedError(loadConfig(root)); } catch (e) { fail(e.message); }
|
|
109
|
+
if (msg) fail(msg);
|
|
110
|
+
}
|
|
111
|
+
|
|
105
112
|
const model = await load();
|
|
106
113
|
|
|
107
114
|
if (cmd === 'scan') {
|
package/src/contract.js
CHANGED
|
@@ -25,6 +25,8 @@ export const CONTRACT = [
|
|
|
25
25
|
{ name: '--success', group: 'colour', role: 'any', about: 'Something worked.', derive: '#16a34a' },
|
|
26
26
|
{ name: '--warning', group: 'colour', role: 'any', about: 'Careful.', derive: '#d97706' },
|
|
27
27
|
{ name: '--focus', group: 'colour', role: 'any', about: 'The keyboard focus ring.', derive: 'var(--accent)' },
|
|
28
|
+
{ name: '--focus-ring', group: 'colour', role: 'border', about: 'The focus outline (`none` for a glow only).', derive: '2px solid var(--focus)' },
|
|
29
|
+
{ name: '--focus-glow', group: 'colour', role: 'any', about: 'A focus glow, as a box-shadow (`none` by default).', derive: 'none' },
|
|
28
30
|
// type
|
|
29
31
|
{ name: '--font-ui', group: 'type', about: 'Every label and paragraph.', derive: "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif" },
|
|
30
32
|
{ name: '--font-display', group: 'type', about: 'Headings.', derive: 'var(--font-ui)' },
|
package/src/init.js
CHANGED
|
@@ -8,12 +8,29 @@ import { isTokenFile } from './model.js';
|
|
|
8
8
|
import { analyze } from './sources.js';
|
|
9
9
|
import { isSpecimenPage } from './specimens.js';
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
export const BASE_RULES = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'rules', 'DESIGN.md');
|
|
12
|
+
|
|
13
|
+
// The project's own rules file: it extends the base and starts empty.
|
|
14
|
+
export const PROJECT_RULES = `Extends @rickycourtes/designrail/rules/DESIGN.md
|
|
15
|
+
|
|
16
|
+
# Design rules
|
|
17
|
+
|
|
18
|
+
designrail's base rules (\`node_modules/@rickycourtes/designrail/rules/DESIGN.md\`)
|
|
19
|
+
hold for this project as written. This file only adds to them: a rule here
|
|
20
|
+
says something the base doesn't, and never reuses a base \`{id}\`
|
|
21
|
+
(\`designrail check\` fails that: rules-override). End each bullet with a tag
|
|
22
|
+
\`{id · checks}\` as the base does: \`check\`, \`audit\` or \`eye\`.
|
|
23
|
+
|
|
24
|
+
## Project rules
|
|
25
|
+
|
|
26
|
+
`;
|
|
12
27
|
|
|
13
28
|
const AGENT_BLOCK = `
|
|
14
29
|
## Design system (designrail)
|
|
15
30
|
|
|
16
|
-
Before touching UI, read
|
|
31
|
+
Before touching UI, read both rule files: designrail's base rules
|
|
32
|
+
(\`node_modules/@rickycourtes/designrail/rules/DESIGN.md\`) and this project's
|
|
33
|
+
\`DESIGN.md\`, which extends them. Build from the parts in \`{parts}/\` and
|
|
17
34
|
the tokens in {tokens}, on top of the designrail foundation (\`@rickycourtes/designrail/foundation.css\`). Restyle a foundation part with its knobs on a variant, never by editing it; never type a colour, spacing, radius or font size by
|
|
18
35
|
hand. Run \`npx designrail check\` before committing; \`npx designrail trace <selector>\`
|
|
19
36
|
shows where a value comes from. A part the foundation lacks: write it in \`{parts}/\` from tokens; \`npx designrail eject <part>\` only to own a copy.
|
|
@@ -37,7 +54,7 @@ export function init(root, { agents = false, force = false } = {}) {
|
|
|
37
54
|
done.push(`designrail.config.json${found.length ? ` (tokens found in ${found.join(', ')})` : ''}${pages.length ? ` (specimens: ${pages.join(', ')})` : ''}`);
|
|
38
55
|
}
|
|
39
56
|
const rulesPath = path.join(root, 'DESIGN.md');
|
|
40
|
-
if (!fs.existsSync(rulesPath) || force) { fs.
|
|
57
|
+
if (!fs.existsSync(rulesPath) || force) { fs.writeFileSync(rulesPath, PROJECT_RULES); done.push('DESIGN.md'); }
|
|
41
58
|
if (agents) {
|
|
42
59
|
const target = ['CLAUDE.md', 'AGENTS.md'].map((f) => path.join(root, f)).find((f) => fs.existsSync(f)) ?? path.join(root, 'CLAUDE.md');
|
|
43
60
|
const now = fs.existsSync(target) ? fs.readFileSync(target, 'utf8') : '';
|
package/src/model.js
CHANGED
|
@@ -44,9 +44,9 @@ export function buildModel(project) {
|
|
|
44
44
|
// A var() in a plain JS file may be a string in a test or a tool: it
|
|
45
45
|
// counts as a read (unused) but never fails unresolved or primitive-direct.
|
|
46
46
|
const js = JS_EXT.test(f.path);
|
|
47
|
-
for (const [name, line, fallback] of f.uses) {
|
|
47
|
+
for (const [name, line, fallback, quoted] of f.uses) {
|
|
48
48
|
if (!uses.has(name)) uses.set(name, []);
|
|
49
|
-
uses.get(name).push({ file: f.path, line, inTokens, js, fallback: Boolean(fallback) });
|
|
49
|
+
uses.get(name).push({ file: f.path, line, inTokens, js: js || Boolean(quoted), fallback: Boolean(fallback) });
|
|
50
50
|
}
|
|
51
51
|
for (const r of f.rules) {
|
|
52
52
|
if (r.sel === '@font-face') continue;
|