tobogganSe connecter

library

Prebuilt pebble components: drop-in custom elements, no compiler needed

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

Dernier runAucun
0Étoiles
0Forks
2Issues
440 lignes · 15297 octetsBrut · Historique
1/* Timeline: lanes of phases over a shared axis, for <pebble-timeline>.
2 Light DOM, wrapped in @scope (pebble-timeline); :scope is the host. The @property
3 registrations of --pebble-timeline-start and --pebble-timeline-size cannot be scoped: they
4 are properties.css, page-wide.
5
6 Theming, two levels, every value with a fallback:
7 - --pebble-chart-*: what every library chart shares, so one set of page
8 tokens themes them all: series-1 … series-8 (the categorical slots, in
9 fixed order), muted, ink, ink-2, tick, grid, axis, surface, border,
10 hatch, focus.
11 - --pebble-timeline-*: this chart's own: bar (24px), gap (2px between
12 touching segments), radius (4px at a track's ends), row-gap (0.75rem),
13 font-size (0.875rem), label-on-fill (#fff), label-on-light (#0b0b0b).
14 Defaults are the dataviz reference palette, light and dark steps chosen
15 by prefers-color-scheme; a page with its own theme toggle sets the
16 --pebble-chart-* tokens for both.
17
18 Parts: timeline, legend, plot, track-label, lane, segment, total, axis,
19 axis-title, tooltip, table-view. State is attributes, never generated CSS:
20 [data-series], [data-texture], [data-first], [data-last], [data-active],
21 [data-unlabelled] on segments, [data-open] on the tooltip,
22 [data-enhanced] and [show-table] on the host; the element marks each
23 segment row of the table with [data-fill] (its palette slot) and
24 [data-track-start] (the first row of a run of one track). */
25
26:scope {
27 --_s1: var(--pebble-chart-series-1, #2a78d6);
28 --_s2: var(--pebble-chart-series-2, #eb6834);
29 --_s3: var(--pebble-chart-series-3, #1baf7a);
30 --_s4: var(--pebble-chart-series-4, #eda100);
31 --_s5: var(--pebble-chart-series-5, #e87ba4);
32 --_s6: var(--pebble-chart-series-6, #008300);
33 --_s7: var(--pebble-chart-series-7, #6250d6);
34 --_s8: var(--pebble-chart-series-8, #e34948);
35 --_muted: var(--pebble-chart-muted, #c3c2b7);
36 --_ink: var(--pebble-chart-ink, #0b0b0b);
37 --_ink-2: var(--pebble-chart-ink-2, #52514e);
38 --_tick: var(--pebble-chart-tick, #898781);
39 --_grid: var(--pebble-chart-grid, #e1e0d9);
40 --_axis: var(--pebble-chart-axis, #c3c2b7);
41 --_surface: var(--pebble-chart-surface, #fcfcfb);
42 --_border: var(--pebble-chart-border, rgba(11, 11, 11, 0.1));
43 --_hatch: var(--pebble-chart-hatch, rgba(255, 255, 255, 0.55));
44 --_focus: var(--pebble-chart-focus, var(--accent, #2a78d6));
45 --_bar: var(--pebble-timeline-bar, 24px);
46 --_gap: var(--pebble-timeline-gap, 2px);
47 --_radius: var(--pebble-timeline-radius, 4px);
48 --_row-gap: var(--pebble-timeline-row-gap, 0.75rem);
49
50 display: block;
51 container-type: inline-size;
52 color: var(--_ink);
53 font-size: var(--pebble-timeline-font-size, 0.875rem);
54 line-height: 1.4;
55}
56
57@media (prefers-color-scheme: dark) {
58 :scope {
59 --_s1: var(--pebble-chart-series-1, #3987e5);
60 --_s2: var(--pebble-chart-series-2, #d95926);
61 --_s3: var(--pebble-chart-series-3, #199e70);
62 --_s4: var(--pebble-chart-series-4, #c98500);
63 --_s5: var(--pebble-chart-series-5, #d55181);
64 --_s6: var(--pebble-chart-series-6, #008300);
65 --_s7: var(--pebble-chart-series-7, #9085e9);
66 --_s8: var(--pebble-chart-series-8, #e66767);
67 --_muted: var(--pebble-chart-muted, #52514e);
68 --_ink: var(--pebble-chart-ink, #f0efec);
69 --_ink-2: var(--pebble-chart-ink-2, #c3c2b7);
70 --_grid: var(--pebble-chart-grid, #2c2c2a);
71 --_axis: var(--pebble-chart-axis, #383835);
72 --_surface: var(--pebble-chart-surface, #1a1a19);
73 --_border: var(--pebble-chart-border, rgba(255, 255, 255, 0.1));
74 --_hatch: var(--pebble-chart-hatch, rgba(26, 26, 25, 0.5));
75 }
76}
77
78/* The table stays for screen readers and no-script readers. While it is the host's own child (no
79 [show-table]) it is visually hidden. A table ignores width: 1px and keeps its content's width,
80 so the usual visually-hidden box would still stick out of the page and scroll it sideways: the
81 scale shrinks the box itself, and the table stays in the accessibility tree. */
82:scope[data-enhanced] > table {
83 position: absolute;
84 overflow: hidden;
85 clip-path: inset(50%);
86 white-space: nowrap;
87 transform: scale(0.01);
88 transform-origin: 0 0;
89}
90
91/* The table view ([show-table]): the element moves the page's table into .table-view, under the
92 plot, and back where it was when the attribute goes or the element disconnects. The table takes
93 its natural width: an auto layout, every column at least as wide as its longest word, and no
94 word is ever broken (the page's own soft hyphens aside). Whatever the page's table holds (more
95 columns than the sample's five, long notes, a DOI), when it is wider than the element the view
96 scrolls sideways, never the page. The view is a focusable region (arrow keys scroll it), and a
97 shadow at an edge says there is more that way: a scroll-driven animation, so nothing shows where
98 the view does not scroll, or where the browser lacks scroll timelines. */
99.table-view {
100 --_edge: color-mix(in srgb, var(--_ink) 28%, transparent);
101 overflow-x: auto;
102 margin-top: 1.5rem;
103 border-radius: 4px;
104 outline: none;
105 animation: pebble-timeline-edges linear both;
106 animation-timeline: scroll(self inline);
107
108 &:focus-visible {
109 outline: 2px solid var(--_focus);
110 outline-offset: 2px;
111 }
112}
113
114/* Right edge, then left: both always, one transparent, so the lists interpolate. Inset shadows
115 sit on the view's background, under the table's text, and stay put as it scrolls. */
116@keyframes pebble-timeline-edges {
117 from { box-shadow: inset -12px 0 10px -10px var(--_edge), inset 12px 0 10px -10px transparent; }
118 5%, 95% { box-shadow: inset -12px 0 10px -10px var(--_edge), inset 12px 0 10px -10px var(--_edge); }
119 to { box-shadow: inset -12px 0 10px -10px transparent, inset 12px 0 10px -10px var(--_edge); }
120}
121
122.table-view > table {
123 --_cell-x: 0.75rem;
124 width: 100%;
125 border-collapse: collapse;
126 font-size: 0.8125rem;
127 /* Whole words, whatever the page's own CSS sets around it. */
128 white-space: normal;
129 overflow-wrap: normal;
130 word-break: normal;
131 hyphens: manual;
132
133 & caption {
134 caption-side: top;
135 padding-bottom: 0.5rem;
136 text-align: start;
137 font-size: 0.75rem;
138 color: var(--_ink-2);
139 }
140 & tr > * {
141 padding: 0.375rem var(--_cell-x);
142 text-align: start;
143 vertical-align: baseline;
144 }
145 & tr > :first-child { padding-inline-start: 0; }
146 & tr > :last-child { padding-inline-end: 0; }
147 & thead th {
148 vertical-align: bottom;
149 border-bottom: 1px solid var(--_tick);
150 font-size: 0.75rem;
151 font-weight: 600;
152 color: var(--_ink-2);
153 }
154 & tbody > tr > * {
155 border-top: 1px solid var(--_grid);
156 font-weight: 400;
157 }
158 /* Start and length: numbers, right-aligned on tabular figures. */
159 & tr > :nth-child(n + 3):nth-child(-n + 4) {
160 text-align: end;
161 font-variant-numeric: tabular-nums;
162 }
163
164 /* Tracks: a firmer rule where one starts, in the tick ink like the header's (the axis token is
165 too close to the hairlines, in dark above all), and the track's name repeated in a muted
166 ink. Under the header, the header's rule wins: with collapsed borders the upper cell's does. */
167 & tbody > tr[data-track-start] > * { border-top-color: var(--_tick); }
168 & tbody > tr[data-track-start] > :first-child { font-weight: 600; }
169 & tbody > tr[data-fill]:not([data-track-start]) > :first-child { color: var(--_ink-2); }
170
171 /* Each segment row's swatch, in its segment's fill and texture, hung in the cell's margin so
172 a wrapped label keeps to one column. */
173 & tr[data-fill] > :nth-child(2) {
174 padding-inline-start: calc(var(--_cell-x) + 18px);
175 text-indent: -18px;
176 }
177 & tr[data-fill] > :nth-child(2)::before {
178 content: "";
179 display: inline-block;
180 width: 10px;
181 height: 10px;
182 margin-inline-end: 8px;
183 border-radius: 2px;
184 vertical-align: -1px;
185 background-color: var(--_fill);
186 }
187}
188
189/* Fills: one slot per series, the muted one, and the 45° hatch over any of them. A table
190 row carries its slot too (data-fill), for its swatch; the hatch is only ever on marks. */
191[data-series="1"], [data-fill="1"] { --_fill: var(--_s1); }
192[data-series="2"], [data-fill="2"] { --_fill: var(--_s2); }
193[data-series="3"], [data-fill="3"] { --_fill: var(--_s3); }
194[data-series="4"], [data-fill="4"] { --_fill: var(--_s4); --_on-fill: var(--pebble-timeline-label-on-light, #0b0b0b); }
195[data-series="5"], [data-fill="5"] { --_fill: var(--_s5); }
196[data-series="6"], [data-fill="6"] { --_fill: var(--_s6); }
197[data-series="7"], [data-fill="7"] { --_fill: var(--_s7); }
198[data-series="8"], [data-fill="8"] { --_fill: var(--_s8); }
199[data-series="muted"], [data-fill="muted"] { --_fill: var(--_muted); --_on-fill: var(--_ink); }
200.segment[data-texture="hatch"],
201.swatch[data-texture="hatch"],
202tr[data-texture="hatch"] > :nth-child(2)::before {
203 background-image: repeating-linear-gradient(45deg, var(--_hatch) 0 2px, transparent 2px 6px);
204}
205
206.legend {
207 list-style: none;
208 display: flex;
209 flex-wrap: wrap;
210 gap: 0.375rem 1rem;
211 margin: 0 0 1rem;
212 padding: 0;
213 font-size: 0.8125rem;
214 color: var(--_ink-2);
215
216 & li {
217 display: inline-flex;
218 align-items: center;
219 gap: 0.375rem;
220 }
221}
222
223.swatch {
224 flex: none;
225 width: 12px;
226 height: 12px;
227 border-radius: 3px;
228 background-color: var(--_fill, var(--_muted));
229}
230
231/* The plot: one grid, a row per track; label, lane and total columns line up across tracks. */
232.plot {
233 position: relative;
234 display: grid;
235 grid-template-columns: [label] max-content [lane] minmax(0, 1fr) [total] max-content;
236 column-gap: 0.75rem;
237 row-gap: var(--_row-gap);
238 align-items: center;
239 outline: none;
240 border-radius: 4px;
241
242 &:focus-visible {
243 outline: 2px solid var(--_focus);
244 outline-offset: 6px;
245 }
246}
247
248.grid {
249 grid-column: lane;
250 grid-row: 1 / span var(--tracks);
251 align-self: stretch;
252 position: relative;
253 margin-block: calc(var(--_row-gap) * -0.5);
254}
255
256.gridline {
257 position: absolute;
258 top: 0;
259 bottom: 0;
260 left: calc(var(--at) * 100%);
261 width: 1px;
262 background: var(--_grid);
263
264 &[data-baseline] { background: var(--_axis); }
265}
266
267.track-label {
268 grid-column: label;
269 grid-row: var(--row);
270 font-weight: 600;
271 white-space: nowrap;
272}
273
274/* A lane is a size container so that a label can know its segment's target width (cqw):
275 see .segment-label. */
276.lane {
277 grid-column: lane;
278 grid-row: var(--row);
279 position: relative;
280 height: var(--_bar);
281 container-type: inline-size;
282}
283
284.total {
285 grid-column: total;
286 grid-row: var(--row);
287 font-weight: 600;
288 font-variant-numeric: tabular-nums;
289 white-space: nowrap;
290
291 & .delta {
292 font-weight: 400;
293 color: var(--_ink-2);
294 }
295}
296
297.segment {
298 position: absolute;
299 top: 0;
300 bottom: 0;
301 /* The label's cap (below): --pebble-timeline-start and -size are registered with
302 inherits: false (properties.css), so the segment hands its target width down by a name of
303 its own. */
304 --_target: calc(var(--pebble-timeline-size) * 100cqw - var(--_gap));
305 left: calc(var(--pebble-timeline-start) * 100%);
306 width: max(1px, calc(var(--pebble-timeline-size) * 100% - var(--_gap)));
307 display: flex;
308 align-items: center;
309 overflow: hidden;
310 background-color: var(--_fill, var(--_muted));
311
312 &[data-first] {
313 border-start-start-radius: var(--_radius);
314 border-end-start-radius: var(--_radius);
315 }
316 &[data-last] {
317 --_target: calc(var(--pebble-timeline-size) * 100cqw);
318 width: max(1px, calc(var(--pebble-timeline-size) * 100%));
319 border-start-end-radius: var(--_radius);
320 border-end-end-radius: var(--_radius);
321 }
322 &[data-active] { filter: brightness(1.12); }
323 &[data-unlabelled] .segment-label { visibility: hidden; }
324}
325
326/* A label is never wider than its segment's TARGET width, the one the width transition is
327 heading to: max-width uses the same formula as the segment's width (--_target, resolved in
328 the lane's cqw: the lane is the nearest container), and does not transition. So the element's fit (does the label's text overflow the label?) hides
329 a label as soon as a shrink starts, and shows it only once a grow has ended (it is fitted
330 again at transitionend): a shown label is never clipped mid-glide. */
331.segment-label {
332 box-sizing: border-box;
333 min-width: 0;
334 max-width: max(1px, var(--_target));
335 padding: 0 6px;
336 overflow: hidden;
337 white-space: nowrap;
338 font-size: 11px;
339 font-weight: 600;
340 color: var(--_on-fill, var(--pebble-timeline-label-on-fill, #fff));
341}
342
343.axis {
344 grid-column: lane;
345 position: relative;
346 height: 1rem;
347 margin-top: calc(var(--_row-gap) * -0.5);
348}
349
350.tick {
351 position: absolute;
352 left: calc(var(--at) * 100%);
353 transform: translateX(-50%);
354 font-size: 11px;
355 color: var(--_tick);
356 font-variant-numeric: tabular-nums;
357 white-space: nowrap;
358}
359
360.axis-title {
361 grid-column: lane;
362 margin: calc(var(--_row-gap) * -0.5) 0 0;
363 text-align: center;
364 font-size: 11px;
365 color: var(--_tick);
366
367 &:empty { display: none; }
368}
369
370/* The tooltip sits in the active track's lane area (an absolute grid item takes
371 its area as containing block), over the active segment, kept inside the lane
372 by moving its own anchor with --x. Nothing is measured. */
373.tooltip {
374 position: absolute;
375 grid-column: lane;
376 grid-row: var(--row);
377 bottom: calc(100% + 0.375rem);
378 left: calc(var(--x) * 100%);
379 transform: translateX(calc(var(--x) * -100%));
380 z-index: 1;
381 display: none;
382 min-width: 10rem;
383 max-width: 16rem;
384 padding: 0.5rem 0.625rem;
385 border: 1px solid var(--_border);
386 border-radius: 0.5rem;
387 background: var(--_surface);
388 color: var(--_ink);
389 box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
390 font-size: 0.8125rem;
391 pointer-events: none;
392
393 &[data-open] { display: block; }
394
395 & .heading { display: block; font-size: 0.875rem; }
396 & .track { display: block; color: var(--_ink-2); }
397 & ul { list-style: none; margin: 0.25rem 0 0; padding: 0; }
398 & .value { font-weight: 600; font-variant-numeric: tabular-nums; }
399 & .name { color: var(--_ink-2); }
400}
401
402/* Narrow: each track's label and total take a row above its lane, so the lane gets the
403 full width; the gridlines go, the ticks stay. */
404@container (max-width: 30rem) {
405 .plot {
406 grid-template-columns: [lane] minmax(0, 1fr) [total] max-content;
407 row-gap: 0.25rem;
408 }
409 .grid { display: none; }
410 .track-label,
411 .total {
412 grid-row: var(--label-row);
413 margin-top: 0.5rem;
414 }
415 .track-label { grid-column: lane; }
416 .lane,
417 .tooltip {
418 grid-column: 1 / -1;
419 grid-row: var(--lane-row);
420 }
421 .axis,
422 .axis-title {
423 grid-column: 1 / -1;
424 margin-top: 0.25rem;
425 }
426 /* The table at a phone's width: smaller type, tighter cells. */
427 .table-view > table {
428 --_cell-x: 0.375rem;
429 font-size: 0.75rem;
430 }
431}
432
433/* Motion: when the page rewrites a row, its segment glides to its new place and width (the
434 element keeps segment elements across re-reads). left and width transition, not the registered
435 --pebble-timeline-start and -size: the label's cap must jump to the target at once (see
436 .segment-label), and left and width are computed from them, so a change of either changes
437 them. A resize changes no computed value (they are percentages), so it never animates. */
438@media (prefers-reduced-motion: no-preference) {
439 .segment { transition: filter 120ms ease, left 350ms ease-out, width 350ms ease-out; }
440}