@canonical/styles 0.37.0 → 0.40.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/src/fonts.css CHANGED
@@ -3,46 +3,73 @@
3
3
  * Variable fonts from @canonical/ds-assets.
4
4
  * Licensed under Ubuntu Font License v1.0.
5
5
  *
6
- * Opt-in: import this file to load the Ubuntu Sans font family.
6
+ * Opt-in: import this file to load the Ubuntu Sans font family. Only the sans
7
+ * is declared — see the note under the two faces for why the mono is not.
7
8
  *
8
9
  * @import url("@canonical/styles/fonts");
9
10
  * @import url("@canonical/styles");
11
+ *
12
+ * Deliberately unlayered. `@font-face` is not a style rule: it defines a font
13
+ * for the whole document and the cascade does not sort it, so putting it in a
14
+ * layer would say nothing and would only invite a reader to look for the layer
15
+ * that "wins".
16
+ *
17
+ * The descriptors below are the ranges the files actually carry, read from
18
+ * each file's variation table (`fvar`) rather than copied from a specimen: a
19
+ * range wider than the file's own is a claim the browser silently clamps, so
20
+ * `font-weight: 900` would render at the heaviest weight the file has and the
21
+ * stylesheet would say otherwise.
10
22
  */
11
23
 
24
+ /* Ubuntu Sans 1.006 — fvar: wdth 75–100, wght 100–800 (1000 units per em). */
12
25
  @font-face {
13
26
  font-family: "Ubuntu Sans";
14
27
  src: url("@canonical/ds-assets/fonts/ubuntu-sans/UbuntuSans[wdth,wght].woff2")
15
28
  format("woff2-variations");
16
- font-weight: 100 900;
17
- font-stretch: 62.5% 100%;
29
+ font-weight: 100 800;
30
+ font-stretch: 75% 100%;
18
31
  font-style: normal;
19
32
  font-display: swap;
20
33
  }
21
34
 
35
+ /* Ubuntu Sans Italic 1.006 — the same two axes over the same ranges. */
22
36
  @font-face {
23
37
  font-family: "Ubuntu Sans";
24
38
  src: url("@canonical/ds-assets/fonts/ubuntu-sans/UbuntuSans-Italic[wdth,wght].woff2")
25
39
  format("woff2-variations");
26
- font-weight: 100 900;
27
- font-stretch: 62.5% 100%;
40
+ font-weight: 100 800;
41
+ font-stretch: 75% 100%;
28
42
  font-style: italic;
29
43
  font-display: swap;
30
44
  }
31
45
 
32
- @font-face {
33
- font-family: "Ubuntu Sans Mono";
34
- src: url("@canonical/ds-assets/fonts/ubuntu-sans/UbuntuSansMono[wght].woff2")
35
- format("woff2-variations");
36
- font-weight: 100 900;
37
- font-style: normal;
38
- font-display: swap;
39
- }
40
-
41
- @font-face {
42
- font-family: "Ubuntu Sans Mono";
43
- src: url("@canonical/ds-assets/fonts/ubuntu-sans/UbuntuSansMono-Italic[wght].woff2")
44
- format("woff2-variations");
45
- font-weight: 100 900;
46
- font-style: italic;
47
- font-display: swap;
48
- }
46
+ /* Ubuntu Sans Mono is not declared, deliberately. The two files
47
+ * @canonical/ds-assets ships under those names are not fonts: each is a
48
+ * ~300 KB HTML error page committed in place of the font. A declared face
49
+ * pointing at one costs a page that renders monospace text a 304 KB download
50
+ * that can only fail, after which the text falls back to the generic
51
+ * monospace stack — which is where it lands with no declaration at all, for
52
+ * nothing. So the rules stay commented out until the real files exist.
53
+ *
54
+ * Tracking: PRA-146. Whoever replaces the assets: uncomment these, read the
55
+ * new files' variation table (`fvar`) and set the ranges to what it says,
56
+ * in the same change.
57
+ *
58
+ * @font-face {
59
+ * font-family: "Ubuntu Sans Mono";
60
+ * src: url("@canonical/ds-assets/fonts/ubuntu-sans/UbuntuSansMono[wght].woff2")
61
+ * format("woff2-variations");
62
+ * font-weight: 100 900;
63
+ * font-style: normal;
64
+ * font-display: swap;
65
+ * }
66
+ *
67
+ * @font-face {
68
+ * font-family: "Ubuntu Sans Mono";
69
+ * src: url("@canonical/ds-assets/fonts/ubuntu-sans/UbuntuSansMono-Italic[wght].woff2")
70
+ * format("woff2-variations");
71
+ * font-weight: 100 900;
72
+ * font-style: italic;
73
+ * font-display: swap;
74
+ * }
75
+ */
package/src/grid.css CHANGED
@@ -13,6 +13,7 @@
13
13
  * .grid.responsive Breakpoint-driven column grid
14
14
  * .grid.intrinsic Fluid auto-fill grid
15
15
  * .subgrid CSS subgrid child — inherits parent columns
16
+ * .content-flow Container whose children carry their own bottom margin
16
17
  *
17
18
  * Customization:
18
19
  * --grid-gap Shorthand: sets both row-gap and column-gap (default: var(--grid-gutter))
@@ -62,9 +63,27 @@
62
63
  *
63
64
  * <!-- Separate row/column gaps -->
64
65
  * <div class="grid responsive" style="--grid-row-gap: 1.5rem; --grid-column-gap: 1rem">...</div>
66
+ *
67
+ * Layers:
68
+ * `grid` and `subgrid` set real properties on any element that carries them;
69
+ * `responsive` and `intrinsic` set only `--modifier-grid-template`, which
70
+ * `grid` reads, and are the presets' other half. All four sit in
71
+ * `ds.components.global`.
72
+ *
73
+ * The tier, `ds.components.global`, is not decoration: a rule written
74
+ * directly into `@layer ds.components` lands in that layer's implicit final
75
+ * sublayer, which sits ABOVE every named sublayer — measured, such a rule beats
76
+ * one in `ds.components.apps`. Writing the presets into the parent would put
77
+ * them out of reach of every tier, so a tier's own sheet could not override a
78
+ * preset by layer at all. Nothing pragma ships is written directly into
79
+ * `ds.components`; everything in that layer sits in a tier, and the presets
80
+ * are the shared tier's.
81
+ *
82
+ * The `:root` defaults stay with the presets that read them, as component-
83
+ * scoped tokens, rather than moving to `ds.tokens`.
65
84
  */
66
85
 
67
- @layer ds.components {
86
+ @layer ds.components.global {
68
87
  :root {
69
88
  --grid-col-min: 100px;
70
89
 
@@ -107,3 +126,20 @@
107
126
  grid-column: var(--subgrid-span, 1 / -1);
108
127
  }
109
128
  }
129
+
130
+ /* Content-flow container: establishes element-owned spacing context. Children
131
+ * use their own margin-bottom; the last child is reset to 0 so the container
132
+ * does not gain a trailing gap.
133
+ *
134
+ * It lives here rather than with the spacing tokens it belongs to by subject,
135
+ * because it is a rule that styles an element and the tokens entry must carry
136
+ * none: a page that also runs another CSS framework takes the tokens and the
137
+ * layout presets and supplies its own element rules. This is a preset like the
138
+ * grid ones — it claims a class name and sets a real property — so it travels
139
+ * with them.
140
+ */
141
+ @layer ds.components.global {
142
+ .content-flow > :last-child {
143
+ margin-bottom: 0;
144
+ }
145
+ }
package/src/index.css CHANGED
@@ -2,18 +2,93 @@
2
2
  *
3
3
  * Single import for consumers:
4
4
  * @import url("@canonical/styles");
5
+ *
6
+ * Everything this package itself ships sits in a named cascade layer. Three of
7
+ * those layers select elements rather than declare custom properties —
8
+ * `normalize`, `ds.reset` and `ds.typography` — and they style the whole page,
9
+ * as a reset does. Nothing is confined and nothing has to be marked.
10
+ *
11
+ * A page that also runs another CSS framework, and so cannot let this stylesheet
12
+ * restyle the half it has not migrated, uses `@canonical/styles-vanilla-adapter`.
13
+ * That package ships a confined copy of those three element layers and a test
14
+ * that binds the copy to the files here, so the two cannot drift. Such a page
15
+ * imports `tokens.css` and `layout.css` from this package instead of this file,
16
+ * and takes its element rules from the adapter.
17
+ *
18
+ * This file is one of four entry points, and the one an ordinary page wants.
19
+ * `tokens.css` is every custom property and no rule that styles an element;
20
+ * `elements.css` is every rule that styles a plain element; `layout.css` is the
21
+ * grid presets. Each imports `layers.css` first, and none imports another — an `@layer` statement inside a layer block would declare sublayers
22
+ * rather than top-level layers. The README's "Entry points" section says more,
23
+ * and a test in this package holds both properties. The README's "Cascade
24
+ * layers" section is the reference for what is layered where and what is
25
+ * deliberately not; the reasoning behind the order — how a browser decides, why
26
+ * unlayered rules beat layered ones, and why a mixed page takes its element
27
+ * rules from the adapter — is in docs/explanations/STYLES_CASCADE.md.
28
+ *
29
+ * The order is declared in one place, `layers.css`, and this file imports it
30
+ * first. That import is what fixes the order for a page loading this entry,
31
+ * and it is the reason the order is written once rather than in each entry: a
32
+ * repeated list is a list that can drift. Measured in Chromium: a statement
33
+ * read through an `@import` orders the layers of the sheet that imported it,
34
+ * exactly as a statement written in place would.
35
+ *
36
+ * The import must stay first. An `@import` is only valid before other rules —
37
+ * a layer statement and `@charset` excepted — so "the order, then the rest" is
38
+ * the one legal shape. A consumer who must interleave their own layers
39
+ * prepends their own statement; a later statement can add names but never
40
+ * reorder the ones already fixed.
5
41
  */
6
42
 
7
- /* Layer ordering — deterministic cascade (spec §C.2) */
8
- @layer normalize, ds.reset, ds.modifiers, ds.components;
43
+ /* Read from the bottom up, each position is an argument:
44
+ * normalize pragma's own reset
45
+ * ds.tokens primitive values, spacing, motion, overflow
46
+ * ds.reset the page's baseline: font, colour, box-sizing
47
+ * ds.typography the semantic mapper and the baseline engines
48
+ * ds.modifiers theme, the typographic scale, the channel families and
49
+ * their shims, the density and context classes
50
+ * ds.surfaces the surface families
51
+ * ds.states the derived hover / active / disabled channels
52
+ * ds.components the parent of the tier layers. Nothing is written directly
53
+ * into it, by rule: a declaration in a parent layer sits in
54
+ * that layer's implicit final sublayer, above every named
55
+ * sublayer, so it would outrank every tier
56
+ * ds.components.global the shared component packages, and this
57
+ * package's own layout presets
58
+ * ds.components.sites } the four second-level tiers of the design
59
+ * ds.components.documentation } system's tier tree. They never share a
60
+ * ds.components.stores } page, so their order among themselves is
61
+ * ds.components.apps } arbitrary — but it is fixed here so that
62
+ * it can never depend on which package a bundler emits first
63
+ *
64
+ * The component layers follow the tier tree of the design system: who owns a
65
+ * component decides which layer its rules go in, and a deeper tier wins.
66
+ *
67
+ * The second level is named here in full, and only the second level. A package
68
+ * below it — one application's own tier, say — declares its own layer as the
69
+ * first rule of its CSS entry, `@layer ds.components.apps-lxd;`, and wraps its
70
+ * sheets in it. Because this statement always comes first, that name is new
71
+ * when the browser meets it and is appended after the names above, inside
72
+ * `ds.components`, so it sorts above them. That is the tree's own rule — the
73
+ * more specific tier wins — and it means this stylesheet never has to know
74
+ * which applications exist.
75
+ *
76
+ * The names are tier ids from that tree, lowercased and hyphenated for a
77
+ * sub-tier (`apps-lxd`), not the context words a page puts on its root
78
+ * (`app`, `site`, `docs`). A tier says who owns a component; a context says
79
+ * what kind of page it is being shown on. */
80
+ @import url("./layers.css");
9
81
 
10
- /* Reset */
11
- @import url("normalize.css");
82
+ /* Reset: pragma's own */
83
+ @import url("./normalize.css");
84
+ @import url("./reset.css");
12
85
 
13
86
  /* Typography: interpreter engine + scale tokens */
14
87
  @import url("@canonical/styles-typography");
15
88
 
16
- /* Design tokens — colour, spacing, surfaces, states */
89
+ /* Design tokens — colour, spacing, surfaces, states.
90
+ * Each generated file opens its own `@layer` block, so none of these imports
91
+ * carries a `layer()` keyword: that would nest the file's layer inside another. */
17
92
  @import url("@canonical/design-tokens/dist/sets.primitive.css");
18
93
  @import url("@canonical/design-tokens/dist/modifiers.theme.css");
19
94
  @import url("@canonical/design-tokens/dist/modifiers.surfaces.css");
package/src/layers.css ADDED
@@ -0,0 +1,45 @@
1
+ /* @canonical/styles — The layer order, on its own
2
+ *
3
+ * This file is the order statement and nothing else: no rule, no import, no
4
+ * declaration. It is the same statement the four real entries open with, so
5
+ * importing it changes nothing about a page that already loads one of them —
6
+ * a second identical statement names no layer the first has not already fixed,
7
+ * and a statement can only append names, never reorder them.
8
+ *
9
+ * It exists for one reader: a package whose components belong to a tier below
10
+ * the second level, one application's own tier. Such a package declares its own
11
+ * layer and wraps its sheets in it:
12
+ *
13
+ * @import url("@canonical/styles/layers.css");
14
+ * @layer ds.components.apps-lxd;
15
+ *
16
+ * @import url("./Button/styles.css");
17
+ * … the rest of the package's sheets …
18
+ *
19
+ * The import on the first line is what makes the second line mean the same
20
+ * thing every time. A layer name is placed the moment the browser first meets
21
+ * it, and a name met before this statement is read is placed BELOW the tier
22
+ * names it declares — so the sub-tier would sit under the very tiers it is
23
+ * meant to beat. Whether that happened used to depend on which file a bundler
24
+ * emitted first, which is not something a package can control from inside
25
+ * itself. Reading the statement first settles it: the thirteen names are fixed,
26
+ * and the sub-tier's name, being new, is appended after them inside
27
+ * `ds.components`, where it sorts above every tier — the tier tree's own rule,
28
+ * the more specific tier wins.
29
+ *
30
+ * A page that loads `@canonical/styles`, or the parts, does not need this file.
31
+ */
32
+
33
+ @layer normalize,
34
+ ds.tokens,
35
+ ds.reset,
36
+ ds.typography,
37
+ ds.modifiers,
38
+ ds.surfaces,
39
+ ds.states,
40
+ ds.components,
41
+ ds.components.global,
42
+ ds.components.sites,
43
+ ds.components.documentation,
44
+ ds.components.stores,
45
+ ds.components.apps;
package/src/layout.css ADDED
@@ -0,0 +1,67 @@
1
+ /* @canonical/styles — the layout presets
2
+ *
3
+ * The layout presets, and nothing else: `grid`, `subgrid`, `responsive`,
4
+ * `intrinsic` and `content-flow`. They set real properties on any element
5
+ * carrying one of those class names, so they are the design system claiming five
6
+ * names in a page's class namespace — which is why they are separable from the
7
+ * values and from the element rules, and why a page that already means something
8
+ * else by `grid` can leave this file out.
9
+ *
10
+ * One of four entry points. `index.css` is the whole stylesheet and is what an
11
+ * ordinary page imports; `tokens.css`, `elements.css` and `layout.css` are it
12
+ * in three parts, for a page that wants some of it and supplies the rest.
13
+ *
14
+ * Every entry imports `layers.css` first, and none of them imports another
15
+ * entry. Both of those matter. The order has to reach the browser before any
16
+ * rule of the page it orders, and it is declared in exactly one file so that
17
+ * two entries can never disagree — if they did, the same rules would arbitrate
18
+ * differently depending on which entry a consumer picked. Measured in Chromium:
19
+ * a statement read through an `@import` orders the importing sheet exactly as
20
+ * one written in place would. Entries stay independent of each other because an
21
+ * `@layer` statement inside a layer block would declare sublayers rather than
22
+ * top-level layers, so an entry composing another would nest the order instead
23
+ * of sharing it; independent, a page may load one, two or all three, in any
24
+ * order, and get the same result.
25
+ */
26
+
27
+ /* Read from the bottom up, each position is an argument:
28
+ * normalize pragma's own reset
29
+ * ds.tokens primitive values, spacing, motion, overflow
30
+ * ds.reset the page's baseline: font, colour, box-sizing
31
+ * ds.typography the semantic mapper and the baseline engines
32
+ * ds.modifiers theme, the typographic scale, the channel families and
33
+ * their shims, the density and context classes
34
+ * ds.surfaces the surface families
35
+ * ds.states the derived hover / active / disabled channels
36
+ * ds.components the parent of the tier layers. Nothing is written directly
37
+ * into it, by rule: a declaration in a parent layer sits in
38
+ * that layer's implicit final sublayer, above every named
39
+ * sublayer, so it would outrank every tier
40
+ * ds.components.global the shared component packages, and this
41
+ * package's own layout presets
42
+ * ds.components.sites } the four second-level tiers of the design
43
+ * ds.components.documentation } system's tier tree. They never share a
44
+ * ds.components.stores } page, so their order among themselves is
45
+ * ds.components.apps } arbitrary — but it is fixed here so that
46
+ * it can never depend on which package a bundler emits first
47
+ *
48
+ * The component layers follow the tier tree of the design system: who owns a
49
+ * component decides which layer its rules go in, and a deeper tier wins.
50
+ *
51
+ * The second level is named here in full, and only the second level. A package
52
+ * below it — one application's own tier, say — declares its own layer as the
53
+ * first rule of its CSS entry, `@layer ds.components.apps-lxd;`, and wraps its
54
+ * sheets in it. Because this statement always comes first, that name is new
55
+ * when the browser meets it and is appended after the names above, inside
56
+ * `ds.components`, so it sorts above them. That is the tree's own rule — the
57
+ * more specific tier wins — and it means this stylesheet never has to know
58
+ * which applications exist.
59
+ *
60
+ * The names are tier ids from that tree, lowercased and hyphenated for a
61
+ * sub-tier (`apps-lxd`), not the context words a page puts on its root
62
+ * (`app`, `site`, `docs`). A tier says who owns a component; a context says
63
+ * what kind of page it is being shown on. */
64
+ @import url("./layers.css");
65
+
66
+ /* Grid layout presets */
67
+ @import url("./grid.css");
@@ -35,9 +35,10 @@
35
35
  * per criticality; it just isn't wired into the modifier family. This exposes
36
36
  * it as a channel so on-surface criticality components read it generically.
37
37
  *
38
- * Imported into the `ds.modifiers` layer after the generated criticality
39
- * modifiers so these class rules compose at equal specificity, later source
40
- * order.
38
+ * Layer: ds.modifiers, the layer the generated `modifiers.criticality.css` this
39
+ * file extends opens for itself. Imported after it so these class rules compose
40
+ * at equal specificity, later source order. Custom properties only, so nothing
41
+ * here selects an element.
41
42
  */
42
43
 
43
44
  @layer ds.modifiers {