@n1kname/components 0.65.2 → 0.66.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n1kname/components",
3
- "version": "0.65.2",
3
+ "version": "0.66.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -39,7 +39,7 @@
39
39
  "@n1kname/charts": "0.15.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "@n1kname/tokens": "^0.11.0",
42
+ "@n1kname/tokens": "^0.11.1",
43
43
  "astro": "^7.4.4"
44
44
  },
45
45
  "publishConfig": {
@@ -137,6 +137,7 @@ const layerSizes = (width: number) =>
137
137
  `(max-width: 760px) ${Math.round(width * 0.85)}vw, ${Math.round(width * (layout === 'wide' ? 7 : 6))}px`;
138
138
  const figures = layout === 'wide' ? metrics.slice(0, 4) : [];
139
139
  const meta = metaProp ?? overline;
140
+ // Each dot is held to the item before it (a no-break space), so a wrapped line never starts on one.
140
141
  // The link is named title first, then the line, the meta and the note, so a screen reader
141
142
  // hears the case before its dates. Ids from the href, so the build stays the same each run.
142
143
  const uid = `case-tile-${href.replace(/[^a-z0-9]+/gi, '-').replace(/^-|-$/g, '') || 'home'}`;
@@ -153,7 +154,7 @@ const labelledby = [`${uid}-title`, text && `${uid}-text`, meta && `${uid}-meta`
153
154
  <div class="frame">
154
155
  <div class="copy">
155
156
  <Heading class="title" id={`${uid}-title`}>{title}</Heading>
156
- {meta && <p class="meta" id={`${uid}-meta`}>{meta}</p>}
157
+ {meta && <p class="meta" id={`${uid}-meta`}>{meta.split(' · ').join('\u00a0· ')}</p>}
157
158
  {text && <p class="text" id={`${uid}-text`}>{text}</p>}
158
159
  {note && <p class="note" id={`${uid}-note`}>{note}</p>}
159
160
  {
@@ -48,7 +48,12 @@ const Tag = as;
48
48
  </script>
49
49
 
50
50
  <style>
51
+ /* A column, so the panel can fill a figure that a grid stretches (two charts side by side)
52
+ * without counting the caption: height: 100% took the caption's height into the panel and left
53
+ * that much empty under the legend. */
51
54
  .chart-figure {
55
+ display: flex;
56
+ flex-direction: column;
52
57
  margin-block: var(--sp-6) var(--sp-7);
53
58
  }
54
59
  .chart-figure.panel {
@@ -57,7 +62,7 @@ const Tag = as;
57
62
 
58
63
  .frame {
59
64
  container-type: inline-size;
60
- height: 100%;
65
+ flex: 1 1 auto;
61
66
  padding: var(--sp-5);
62
67
  background: var(--c-surface);
63
68
  border: 1px solid var(--c-border);
package/src/Facts.astro CHANGED
@@ -199,6 +199,20 @@ const hl = highlight && variant === 'tiles';
199
199
  color: var(--c-text-secondary);
200
200
  }
201
201
 
202
+ /* A label that would get less than 7rem beside its icon (a narrow tile, two across on a phone)
203
+ drops under it and takes the tile's whole width: beside the icon it had about 70px and broke
204
+ a word to a line. Done with wrapping, not a container query: a container on the tile would
205
+ switch off its subgrid, and the figures would no longer share a baseline. */
206
+ .tiles :global(dt) {
207
+ flex-wrap: wrap;
208
+ row-gap: var(--sp-2);
209
+ }
210
+
211
+ .tiles :global(.fact-label) {
212
+ flex: 1 1 7rem;
213
+ min-width: 0;
214
+ }
215
+
202
216
  .tiles :global(.fact-icon) {
203
217
  width: 28px;
204
218
  height: 28px;
@@ -2,8 +2,11 @@
2
2
  /**
3
3
  * The light and dark switch: a round button whose icon shows the theme it goes to, the moon
4
4
  * in light and the sun in dark. The two icons share a cell and cross-fade. The choice is kept
5
- * under `theme` in localStorage, and the page's own head script applies it before paint (see
6
- * the docs page), so nothing flashes. Without that, it follows the system, as tokens.css does.
5
+ * in a `theme` cookie, so sites on one host share it (a cookie ignores the port) and, with
6
+ * `cookieDomain`, so do the subdomains of one domain. It is also kept under `theme` in
7
+ * localStorage, for pages whose head script predates the cookie. The page's own head script
8
+ * applies it before paint (see the docs page), so nothing flashes. Without that, it follows
9
+ * the system, as tokens.css does.
7
10
  *
8
11
  * Where the browser has view transitions, the whole page eases into the new colours over
9
12
  * --motion-base instead of snapping. Not under reduced motion.
@@ -13,14 +16,17 @@
13
16
  interface Props {
14
17
  /** What the button says to a screen reader, in each direction. */
15
18
  labels?: { toDark: string; toLight: string };
19
+ /** Share the choice with every subdomain of this domain, e.g. `example.com`. Ignored on a
20
+ * host outside it (a LAN address, localhost), where the cookie stays with the host. */
21
+ cookieDomain?: string;
16
22
  id?: string;
17
23
  class?: string;
18
24
  }
19
25
 
20
- const { labels = { toDark: 'Switch to dark', toLight: 'Switch to light' }, id, class: className } = Astro.props;
26
+ const { labels = { toDark: 'Switch to dark', toLight: 'Switch to light' }, cookieDomain, id, class: className } = Astro.props;
21
27
  ---
22
28
 
23
- <button type="button" class:list={['theme-toggle', className]} id={id} data-theme-toggle>
29
+ <button type="button" class:list={['theme-toggle', className]} id={id} data-theme-toggle data-cookie-domain={cookieDomain}>
24
30
  <span class="sr to-dark">{labels.toDark}</span><span class="sr to-light">{labels.toLight}</span>
25
31
  <svg class="moon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
26
32
  <path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"></path>
@@ -32,27 +38,37 @@ const { labels = { toDark: 'Switch to dark', toLight: 'Switch to light' }, id, c
32
38
  </button>
33
39
 
34
40
  <script>
35
- const apply = (next: string) => {
41
+ // A year, on the whole host, or the whole domain where the page asks and is on it.
42
+ const keep = (next: string, domain?: string) => {
43
+ const host = location.hostname;
44
+ const shared = domain && (host === domain || host.endsWith('.' + domain)) ? `; domain=${domain}` : '';
45
+ const secure = location.protocol === 'https:' ? '; secure' : '';
46
+ document.cookie = `theme=${next}; path=/; max-age=31536000; samesite=lax${shared}${secure}`;
47
+ };
48
+
49
+ const apply = (next: string, domain?: string) => {
36
50
  document.documentElement.dataset.theme = next;
37
51
  // The browser bar follows the choice too, where the page marks its two theme-colors.
38
52
  document.querySelectorAll<HTMLMetaElement>('meta[name="theme-color"][data-for]').forEach((m) => {
39
53
  m.media = m.dataset.for === next ? 'all' : 'not all';
40
54
  });
55
+ keep(next, domain);
41
56
  try {
42
57
  localStorage.setItem('theme', next);
43
58
  } catch {}
44
59
  };
45
60
 
46
- document.querySelectorAll('[data-theme-toggle]').forEach((button) =>
61
+ document.querySelectorAll<HTMLElement>('[data-theme-toggle]').forEach((button) =>
47
62
  button.addEventListener('click', () => {
63
+ const domain = button.dataset.cookieDomain;
48
64
  const root = document.documentElement;
49
65
  const dark = root.dataset.theme ? root.dataset.theme === 'dark' : matchMedia('(prefers-color-scheme: dark)').matches;
50
66
  const next = dark ? 'light' : 'dark';
51
67
  // The page eases into its new colours: one cross-fade of the whole page, which costs far
52
68
  // less than a transition on every element.
53
- if (!document.startViewTransition || matchMedia('(prefers-reduced-motion: reduce)').matches) return apply(next);
69
+ if (!document.startViewTransition || matchMedia('(prefers-reduced-motion: reduce)').matches) return apply(next, domain);
54
70
  root.dataset.themeChange = '';
55
- document.startViewTransition(() => apply(next)).finished.finally(() => delete root.dataset.themeChange);
71
+ document.startViewTransition(() => apply(next, domain)).finished.finally(() => delete root.dataset.themeChange);
56
72
  }),
57
73
  );
58
74
  </script>
package/src/facts.js CHANGED
@@ -26,7 +26,7 @@ const deltaOf = (d) => (d == null || d === '' ? null : typeof d === 'string' ? {
26
26
  const hasLine = (f) => f.context != null || f.contextId != null || deltaOf(f.delta) != null;
27
27
  const sizeOf = (variant) => (variant === 'tiles' ? 16 : 14);
28
28
 
29
- const dtHTML = (f, size) => `${f.icon ? `<span class="fact-icon">${icon(f.icon, size)}</span>` : ''}${esc(f.label)}`;
29
+ const dtHTML = (f, size) => `${f.icon ? `<span class="fact-icon">${icon(f.icon, size)}</span>` : ''}<span class="fact-label">${esc(f.label)}</span>`;
30
30
  const lineHTML = (f) => {
31
31
  const d = deltaOf(f.delta);
32
32
  return `${d ? `<strong class="fact-delta" data-tone="${d.tone}">${esc(d.text)}</strong> ` : ''}${esc(f.context)}`;