documentation/components/source/primitives.css

1/* Axiomatic primitives. This stylesheet owns their geometry: flow, sizing,
2   gap lengths, overflow, and the arrangement of a Switcher. It depends only on
3   the `data-axiomatic*` attributes emitted by primitives.ts, and works on a
4   bare page or inside a shadow root. The host must impose an inline size
5   independent of the composition's block size; scrolling hosts with classic
6   scrollbars need `scrollbar-gutter: stable` to preserve that slot.
7
8   Inputs, all inherited, so a Switcher's measurement copy receives them
9   exactly as its real members do:
10     --axiomatic-space          spacing unit; levels 1/2/3 are 1x/2x/4x (8px)
11     --axiomatic-text-size      Text (14px)
12     --axiomatic-heading-size   Heading (22px)
13     --axiomatic-meta-size      Meta (12px)
14     --axiomatic-cue-color      boundary cue line
15   Font family, weight, letter spacing and the like inherit as usual. */
16
17/* Groups. Script states a structural level; these rules give it a length. */
18[data-axiomatic-level] {
19  display: flex;
20  align-items: stretch;
21  min-inline-size: 0;
22  gap: var(--axiomatic-gap);
23}
24[data-axiomatic-level="1"] {
25  --axiomatic-gap: var(--axiomatic-space, 8px);
26}
27[data-axiomatic-level="2"] {
28  --axiomatic-gap: calc(2 * var(--axiomatic-space, 8px));
29}
30[data-axiomatic-level="3"] {
31  --axiomatic-gap: calc(4 * var(--axiomatic-space, 8px));
32}
33[data-axiomatic="Stack"] {
34  flex-direction: column;
35}
36/* Members of a row are separated by at least 1em. In a column the
37   declaration is inert. */
38[data-axiomatic="Shelf"],
39[data-axiomatic="Switcher"] {
40  column-gap: max(1em, var(--axiomatic-gap));
41}
42/* A row member keeps its max-content size. A Shelf scrolls instead of
43   squeezing; a Switcher becomes a column instead. */
44[data-axiomatic="Shelf"] > *,
45[data-axiomatic="Switcher"] > * {
46  flex-shrink: 0;
47}
48[data-axiomatic="Shelf"] {
49  overflow-x: auto;
50}
51
52/* Switcher: all one row or all one column. The coordinator publishes whether
53   the row fits the slot. Until it has, the column is the safe arrangement. */
54[data-axiomatic="Switcher"] {
55  position: relative;
56  flex-direction: var(--axiomatic-unbounded-direction, column);
57}
58[data-axiomatic="Switcher"][data-axiomatic-arrangement="row"] {
59  flex-direction: row;
60}
61/* Under a row, a row. A Shelf, or a Switcher whose row fits, sizes every
62   member from its content, so nothing below bounds a nested Switcher: its
63   own width would follow its own arrangement, and no fresh measurement of it
64   is an available slot. The answer there is already known. The row requirement
65   counted every nested Switcher on one line, so each has its full row.
66   The context inherits through Stacks and stops at a member that bounds its
67   own inline size. `data-axiomatic-bounded` is reserved for fixture ablation,
68   not a supported child contract: no controlled kind emits it, and a future
69   bound would also have to reach the independent requirement copy. */
70:where(
71    [data-axiomatic="Shelf"],
72    [data-axiomatic="Switcher"][data-axiomatic-arrangement="row"]
73  )
74  > * {
75  --axiomatic-unbounded-direction: row;
76  --axiomatic-unbounded-cue: none;
77}
78[data-axiomatic-bounded] {
79  --axiomatic-unbounded-direction: initial;
80  --axiomatic-unbounded-cue: initial;
81}
82
83/* Boundary cue: a line in the middle of the gap before a member, where a
84   group's spacing has reached the ceiling. It appears in columns only. */
85[data-axiomatic-cue="1"] {
86  --axiomatic-cue-gap: var(--axiomatic-space, 8px);
87}
88[data-axiomatic-cue="2"] {
89  --axiomatic-cue-gap: calc(2 * var(--axiomatic-space, 8px));
90}
91[data-axiomatic-cue="3"] {
92  --axiomatic-cue-gap: calc(4 * var(--axiomatic-space, 8px));
93}
94:is([data-axiomatic="Stack"], [data-axiomatic="Switcher"])
95  > [data-axiomatic-cue] {
96  position: relative;
97}
98:is([data-axiomatic="Stack"], [data-axiomatic="Switcher"])
99  > [data-axiomatic-cue]::before {
100  content: "";
101  position: absolute;
102  inset-inline: 0;
103  inset-block-start: calc(var(--axiomatic-cue-gap) / -2);
104  border-block-start: 1px solid
105    var(
106      --axiomatic-cue-color,
107      color-mix(in srgb, currentColor 20%, transparent)
108    );
109}
110[data-axiomatic="Switcher"] > [data-axiomatic-cue]::before {
111  display: var(--axiomatic-unbounded-cue, block);
112}
113
114/* Controlled teaching leaves. Only declarations that affect size live here,
115   because the measurement copy must share them. */
116[data-axiomatic="Text"],
117[data-axiomatic="Heading"],
118[data-axiomatic="Meta"] {
119  margin: 0;
120  font-size: var(--axiomatic-text-size, 14px);
121  line-height: 1.5;
122  overflow-wrap: anywhere;
123}
124[data-axiomatic="Heading"] {
125  font-size: var(--axiomatic-heading-size, 22px);
126  line-height: 1.25;
127  font-weight: 650;
128  letter-spacing: -0.025em;
129  text-wrap: balance;
130}
131[data-axiomatic="Meta"] {
132  font-size: var(--axiomatic-meta-size, 12px);
133}
134
135/* Measurement boxes. They take no space, paint nothing, and are observed by
136   the coordinator's ResizeObserver; nothing reads their rectangles. */
137[data-axiomatic-mechanical] {
138  position: absolute;
139  inset-block-start: 0;
140  inset-inline-start: 0;
141  visibility: hidden;
142  pointer-events: none;
143  user-select: none;
144}
145/* The slot: the Switcher's content-box inline size at zero height, so an
146   arrangement change, which alters the Switcher's height, cannot resize it. */
147[data-axiomatic-mechanical="slot"] {
148  inset-inline-end: 0;
149  padding-inline: inherit;
150}
151[data-axiomatic-mechanical="slot"],
152[data-axiomatic-mechanical="slot"] > * {
153  block-size: 0;
154}
155/* The requirement: a copy of the Switcher's content on one line. Containment
156   is this subtree's proven boundary. Its layout never reaches the real boxes,
157   and its overflow never becomes scrollable extent. */
158[data-axiomatic-mechanical="requirement"] {
159  inline-size: 0;
160  block-size: 0;
161  contain: strict;
162}
163/* Every Switcher in the copy is a row at its max-content size, whatever its
164   real counterpart is doing. A rendered copy is never 0x0, which is how the
165   coordinator tells "hidden" from "needs no room". */
166[data-axiomatic-mechanical="requirement"] [data-axiomatic="Switcher"] {
167  flex-direction: row;
168  inline-size: max-content;
169  min-block-size: 1px;
170}
171[data-axiomatic-mechanical="requirement"] [data-axiomatic="Shelf"] {
172  overflow: visible;
173}
174[data-axiomatic-mechanical="requirement"]
175  :is(
176    [data-axiomatic="Text"],
177    [data-axiomatic="Heading"],
178    [data-axiomatic="Meta"]
179  ) {
180  white-space: nowrap;
181}