@aitrien/motifspec 1.25.1 → 1.27.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/dist/codex.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // MotifSpec behaviour: theme toggle, the backdrop header's scroll state, tooltip dismissal, code copy buttons,
2
- // TOC docking and active section.
2
+ // TOC docking and active section, alert dismissal, toasts, date pickers and dialogs.
3
3
  // Shipped as dist/codex.js (@aitrien/motifspec/codex.js).
4
4
  // Enhancement only. Without this script: themes follow the system, code is selectable, the TOC is a plain open list,
5
5
  // and every control that needs script stays hidden. Load it with `defer`; it also works inline at the end of <body>.
@@ -31,8 +31,17 @@
31
31
  function ms(name) {
32
32
  var v = getComputedStyle(root).getPropertyValue(name).trim();
33
33
  return v.endsWith('ms') ? parseFloat(v) : parseFloat(v) * 1000;
34
+ } // A length token in pixels, measured by the browser, so rem, clamp() and calc() values all resolve.
35
+ function px(name) {
36
+ var probe = document.createElement('div');
37
+ probe.style.cssText = 'position:absolute;visibility:hidden;pointer-events:none;inline-size:var(' + name + ')';
38
+ (document.body || document.documentElement).appendChild(probe);
39
+ var w = probe.getBoundingClientRect().width;
40
+ probe.remove();
41
+ return w;
34
42
  }
35
43
 
44
+
36
45
  var theme = read();
37
46
  apply(theme);
38
47
  if (system && system.addEventListener) system.addEventListener('change', function () { apply(theme); });
@@ -128,14 +137,34 @@
128
137
  });
129
138
 
130
139
  // Component previews: size each frame to its document's body (the root is never shorter than the frame), and keep
131
- // its theme. Inside a preview, links don't navigate.
140
+ // its theme. An open dialog or popover (a calendar) sits above the body, so while one is open the frame also grows
141
+ // to hold it, and shrinks back when it closes. Inside a preview, links don't navigate.
132
142
  document.querySelectorAll('.cx-preview__frame').forEach(function (f) {
133
143
  var fit = function () {
134
- try { var d = f.contentDocument; if (d && d.body) f.style.setProperty('--_frame-height', d.body.offsetHeight + 'px'); } catch (e) { /* cross-origin: keep the default height */ }
144
+ try {
145
+ var d = f.contentDocument; if (!d || !d.body) return;
146
+ var need = d.body.offsetHeight, room = px('--cx-space-section-sm');
147
+ d.querySelectorAll('dialog[open], [popover]').forEach(function (o) {
148
+ if (o.matches('dialog[open]')) {
149
+ // its parts' full heights, since a dialog with too little room scrolls its body and reports less
150
+ var h = 0;
151
+ o.querySelectorAll(':scope > :not(form), :scope > form > *').forEach(function (c) { h += c.scrollHeight; });
152
+ need = Math.max(need, h + 2 * room);
153
+ }
154
+ else if (o.matches(':popover-open')) need = Math.max(need, o.offsetTop + o.offsetHeight + room);
155
+ });
156
+ f.style.setProperty('--_frame-height', need + 'px');
157
+ } catch (e) { /* cross-origin: keep the default height */ }
135
158
  };
136
159
  var start = function () {
137
160
  apply(theme); fit();
138
161
  try { if ('ResizeObserver' in window) new ResizeObserver(fit).observe(f.contentDocument.body); } catch (e) { /* keep the measured height */ }
162
+ try {
163
+ var d = f.contentDocument, later = function () { window.requestAnimationFrame(fit); };
164
+ d.addEventListener('toggle', later, true);
165
+ d.addEventListener('close', later, true);
166
+ if ('MutationObserver' in window) new MutationObserver(later).observe(d.body, { subtree: true, attributes: true, attributeFilter: ['open'] });
167
+ } catch (e) { /* keep the measured height */ }
139
168
  };
140
169
  f.addEventListener('load', start);
141
170
  try { if (f.contentDocument && f.contentDocument.readyState === 'complete' && f.contentDocument.body && f.contentDocument.body.childNodes.length) start(); } catch (e) { /* wait for load */ }
@@ -282,6 +311,275 @@
282
311
  });
283
312
  });
284
313
 
314
+ // Alerts (alert.md): show each dismiss button, and hide its alert when pressed. With a key, data-alert-dismiss="x",
315
+ // the alert stays hidden on later pages too (localStorage "cx-alert:x"). Focus moves to the main column, since the
316
+ // button it was on has gone. One listener on the document, so an alert an app adds later works the same way.
317
+ var dismissed = function (key) { try { return Boolean(key) && localStorage.getItem('cx-alert:' + key) === 'dismissed'; } catch (e) { return false; } };
318
+ document.querySelectorAll('.cx-alert [data-alert-dismiss]').forEach(function (btn) {
319
+ var alert = btn.closest('.cx-alert');
320
+ if (dismissed(btn.dataset.alertDismiss)) alert.hidden = true; else btn.hidden = false;
321
+ });
322
+ document.addEventListener('click', function (e) {
323
+ var btn = e.target.closest && e.target.closest('.cx-alert [data-alert-dismiss]');
324
+ if (!btn) return;
325
+ var key = btn.dataset.alertDismiss;
326
+ btn.closest('.cx-alert').hidden = true;
327
+ if (key) { try { localStorage.setItem('cx-alert:' + key, 'dismissed'); } catch (err) { /* storage blocked: hidden for this view only */ } }
328
+ var main = document.getElementById('main');
329
+ if (main) main.focus({ preventScroll: true });
330
+ });
331
+
332
+ // Toasts (toast.md): document.dispatchEvent(new CustomEvent('cx-toast', { detail: { text: 'Saved', kind: 'success' } })).
333
+ // One polite live region per page, made here if the page has none, holds up to three; each goes after
334
+ // motion.duration.toast, a time that starts again while the pointer or focus is on it. Escape inside one, or its
335
+ // button, closes it. The text is set as text, never as HTML.
336
+ var region = document.querySelector('.cx-toasts');
337
+ if (!region) {
338
+ region = document.createElement('div'); region.className = 'cx-toasts'; region.setAttribute('role', 'status');
339
+ document.body.appendChild(region);
340
+ }
341
+ var toastIcon = function (id, cls) {
342
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
343
+ svg.setAttribute('class', 'cx-icon cx-icon--sm' + (cls ? ' ' + cls : '')); svg.setAttribute('aria-hidden', 'true'); svg.setAttribute('focusable', 'false');
344
+ var use = document.createElementNS('http://www.w3.org/2000/svg', 'use'); use.setAttribute('href', '#cx-icon-' + id);
345
+ svg.appendChild(use); return svg;
346
+ };
347
+ var closeToast = function (toast) {
348
+ if (toast.classList.contains('is-leaving')) return;
349
+ clearTimeout(toast._cxTimer);
350
+ var hadFocus = toast.contains(document.activeElement);
351
+ toast.classList.add('is-leaving'); toast.classList.remove('is-shown');
352
+ setTimeout(function () { toast.remove(); }, ms('--cx-motion-duration-base'));
353
+ if (hadFocus) { var main = document.getElementById('main'); if (main) main.focus({ preventScroll: true }); }
354
+ };
355
+ document.addEventListener('cx-toast', function (e) {
356
+ var d = e.detail || {};
357
+ if (!d.text) return;
358
+ var toast = document.createElement('div'); toast.className = 'cx-toast';
359
+ if (d.kind === 'success') toast.appendChild(toastIcon('check'));
360
+ var p = document.createElement('p'); p.className = 'cx-toast__text'; p.textContent = d.text; toast.appendChild(p);
361
+ var btn = document.createElement('button'); btn.type = 'button'; btn.className = 'cx-toast__dismiss'; btn.setAttribute('aria-label', 'Dismiss');
362
+ btn.appendChild(toastIcon('close')); btn.addEventListener('click', function () { closeToast(toast); }); toast.appendChild(btn);
363
+ var wait = function () { clearTimeout(toast._cxTimer); toast._cxTimer = setTimeout(function () { closeToast(toast); }, ms('--cx-motion-duration-toast')); };
364
+ var hold = function () { clearTimeout(toast._cxTimer); };
365
+ toast.addEventListener('mouseenter', hold); toast.addEventListener('focusin', hold);
366
+ toast.addEventListener('mouseleave', function () { if (!toast.contains(document.activeElement)) wait(); });
367
+ toast.addEventListener('focusout', function (ev) { if (!toast.contains(ev.relatedTarget) && !toast.matches(':hover')) wait(); });
368
+ toast.addEventListener('keydown', function (ev) { if (ev.key === 'Escape') { ev.stopPropagation(); closeToast(toast); } });
369
+ var live = region.querySelectorAll('.cx-toast:not(.is-leaving)');
370
+ if (live.length >= 3) closeToast(live[0]);
371
+ region.appendChild(toast);
372
+ window.requestAnimationFrame(function () { window.requestAnimationFrame(function () { toast.classList.add('is-shown'); }); });
373
+ wait();
374
+ });
375
+
376
+ // Dialogs (dialog.md): [data-dialog-open="id"] opens a .cx-dialog with showModal(), which moves focus in, closes on
377
+ // Escape and returns focus when closed. [data-dialog-close] inside one closes it, and so does a click on the
378
+ // backdrop, unless the dialog has data-dialog-keep (a form, whose typing a stray click would lose).
379
+ document.addEventListener('click', function (e) {
380
+ var t = e.target.closest ? e.target : null;
381
+ if (!t) return;
382
+ var opener = t.closest('[data-dialog-open]');
383
+ if (opener) {
384
+ var d = document.getElementById(opener.dataset.dialogOpen);
385
+ if (d && d.showModal && !d.open) d.showModal();
386
+ return;
387
+ }
388
+ var dialog = t.closest('dialog.cx-dialog');
389
+ if (!dialog) return;
390
+ if (t.closest('[data-dialog-close]')) { dialog.close(); return; }
391
+ if (t === dialog && !dialog.hasAttribute('data-dialog-keep')) {
392
+ var r = dialog.getBoundingClientRect();
393
+ if (e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom) dialog.close();
394
+ }
395
+ });
396
+
397
+ // Date pickers (date-picker.md): each [data-date-picker] box gets its calendar button, and the page gets one
398
+ // calendar, made the first time it's opened. Dates are day first (DD/MM/YYYY) and weeks start on Monday. The
399
+ // calendar sits under its field, or above it when there's more room there, in page coordinates so it scrolls
400
+ // with the field. Days, months and years are each a grid with one tab stop, moved by the arrow keys.
401
+ var pickers = document.querySelectorAll('[data-date-picker]');
402
+ if (pickers.length) {
403
+ var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
404
+ var DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
405
+ var PAGE = 20;
406
+ var cal = null, calBody, calDays, calList, calTitle, monthBtn, yearBtn, navs;
407
+ var field = null, opener = null, selected = null, focusDay = null, view = 'days';
408
+ var today = function () { var n = new Date(); return new Date(n.getFullYear(), n.getMonth(), n.getDate()); };
409
+ var same = function (a, b) { return a && b && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate(); };
410
+ var pad = function (n) { return String(n).padStart(2, '0'); };
411
+ var parse = function (v) {
412
+ var m = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.exec(v.trim());
413
+ if (!m) return null;
414
+ var d = new Date(+m[3], +m[2] - 1, +m[1]);
415
+ return d.getMonth() === +m[2] - 1 ? d : null;
416
+ };
417
+ var clampDay = function (y, m, d) { return new Date(y, m, Math.min(d, new Date(y, m + 1, 0).getDate())); };
418
+ var icon = function (id) {
419
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
420
+ svg.setAttribute('class', 'cx-icon'); svg.setAttribute('aria-hidden', 'true'); svg.setAttribute('focusable', 'false');
421
+ var use = document.createElementNS('http://www.w3.org/2000/svg', 'use'); use.setAttribute('href', '#cx-icon-' + id);
422
+ svg.appendChild(use); return svg;
423
+ };
424
+ var el = function (tag, cls, attrs) {
425
+ var n = document.createElement(tag); if (cls) n.className = cls;
426
+ Object.keys(attrs || {}).forEach(function (k) { n.setAttribute(k, attrs[k]); });
427
+ return n;
428
+ };
429
+ var build = function () {
430
+ cal = el('div', 'cx-calendar', { popover: '', role: 'dialog', 'aria-label': 'Choose a date' });
431
+ var head = el('div', 'cx-calendar__head');
432
+ var prev = el('button', 'cx-calendar__nav', { type: 'button', 'data-step': '-1' }); prev.appendChild(icon('arrow-back'));
433
+ var next = el('button', 'cx-calendar__nav', { type: 'button', 'data-step': '1' }); next.appendChild(icon('arrow-forward'));
434
+ var pick = el('div', 'cx-calendar__pickers');
435
+ monthBtn = el('button', 'cx-calendar__pick', { type: 'button', 'aria-expanded': 'false' });
436
+ yearBtn = el('button', 'cx-calendar__pick', { type: 'button', 'aria-expanded': 'false' });
437
+ [monthBtn, yearBtn].forEach(function (b) { b.appendChild(document.createElement('span')); b.appendChild(icon('expand')); pick.appendChild(b); });
438
+ head.appendChild(prev); head.appendChild(pick); head.appendChild(next);
439
+ calTitle = el('p', 'cx-visually-hidden', { 'aria-live': 'polite' });
440
+ calDays = el('table', 'cx-calendar__grid', { role: 'grid' });
441
+ var thead = el('thead'), tr = el('tr');
442
+ [1, 2, 3, 4, 5, 6, 0].forEach(function (i) { var th = el('th', '', { scope: 'col', abbr: DAYS[i] }); th.textContent = DAYS[i].slice(0, 2); tr.appendChild(th); });
443
+ thead.appendChild(tr); calDays.appendChild(thead); calBody = el('tbody'); calDays.appendChild(calBody);
444
+ calList = el('div', 'cx-calendar__list'); calList.hidden = true;
445
+ var foot = el('div', 'cx-calendar__foot');
446
+ var todayBtn = el('button', '', { type: 'button' }); todayBtn.textContent = 'Today';
447
+ var closeBtn = el('button', '', { type: 'button' }); closeBtn.textContent = 'Close';
448
+ foot.appendChild(todayBtn); foot.appendChild(closeBtn);
449
+ [head, calTitle, calDays, calList, foot].forEach(function (n) { cal.appendChild(n); });
450
+ document.body.appendChild(cal);
451
+ navs = [prev, next];
452
+ var labelId = 'cx-calendar-title'; calTitle.id = labelId; calDays.setAttribute('aria-labelledby', labelId);
453
+ monthBtn.setAttribute('aria-controls', 'cx-calendar-list'); yearBtn.setAttribute('aria-controls', 'cx-calendar-list'); calList.id = 'cx-calendar-list';
454
+
455
+ calBody.addEventListener('click', function (e) {
456
+ var b = e.target.closest('.cx-calendar__day'); if (!b) return;
457
+ var v = b.dataset.value.split('-'); choose(new Date(+v[0], +v[1], +v[2]));
458
+ });
459
+ calList.addEventListener('click', function (e) {
460
+ var b = e.target.closest('.cx-calendar__cell'); if (!b) return;
461
+ var v = +b.dataset.value;
462
+ if (view === 'years') { focusDay = clampDay(v, focusDay.getMonth(), focusDay.getDate()); setView('months'); }
463
+ else { focusDay = clampDay(focusDay.getFullYear(), v, focusDay.getDate()); setView('days'); }
464
+ });
465
+ monthBtn.addEventListener('click', function () { setView(view === 'months' ? 'days' : 'months'); });
466
+ yearBtn.addEventListener('click', function () { setView(view === 'years' ? 'days' : 'years'); });
467
+ navs.forEach(function (n) {
468
+ n.addEventListener('click', function () {
469
+ var st = +n.dataset.step, y = focusDay.getFullYear(), m = focusDay.getMonth(), d = focusDay.getDate();
470
+ focusDay = view === 'days' ? clampDay(y, m + st, d) : view === 'months' ? clampDay(y + st, m, d) : clampDay(y + st * PAGE, m, d);
471
+ render(false);
472
+ });
473
+ });
474
+ todayBtn.addEventListener('click', function () { view = 'days'; focusDay = today(); render(true); });
475
+ closeBtn.addEventListener('click', close);
476
+ cal.addEventListener('toggle', function (e) { if (e.newState !== 'open') view = 'days'; });
477
+ calBody.addEventListener('keydown', function (e) {
478
+ var d = new Date(focusDay), k = e.key;
479
+ if (k === 'ArrowLeft') d.setDate(d.getDate() - 1);
480
+ else if (k === 'ArrowRight') d.setDate(d.getDate() + 1);
481
+ else if (k === 'ArrowUp') d.setDate(d.getDate() - 7);
482
+ else if (k === 'ArrowDown') d.setDate(d.getDate() + 7);
483
+ else if (k === 'PageUp') d = clampDay(d.getFullYear(), d.getMonth() - 1, d.getDate());
484
+ else if (k === 'PageDown') d = clampDay(d.getFullYear(), d.getMonth() + 1, d.getDate());
485
+ else if (k === 'Home') d.setDate(d.getDate() - ((d.getDay() + 6) % 7));
486
+ else if (k === 'End') d.setDate(d.getDate() + (6 - (d.getDay() + 6) % 7));
487
+ else return;
488
+ e.preventDefault(); focusDay = d; render(true);
489
+ });
490
+ calList.addEventListener('keydown', function (e) {
491
+ var cols = view === 'years' ? 4 : 3, k = e.key, y = focusDay.getFullYear(), m = focusDay.getMonth(), dd = focusDay.getDate(), delta = 0;
492
+ if (k === 'ArrowLeft') delta = -1; else if (k === 'ArrowRight') delta = 1;
493
+ else if (k === 'ArrowUp') delta = -cols; else if (k === 'ArrowDown') delta = cols;
494
+ else if (k === 'PageUp') delta = view === 'years' ? -PAGE : -12; else if (k === 'PageDown') delta = view === 'years' ? PAGE : 12;
495
+ else return;
496
+ e.preventDefault();
497
+ if (view === 'months' && Math.abs(delta) < 12) { if (m + delta < 0 || m + delta > 11) return; focusDay = clampDay(y, m + delta, dd); }
498
+ else focusDay = view === 'years' ? clampDay(y + delta, m, dd) : clampDay(y + delta / 12, m, dd);
499
+ render(true);
500
+ });
501
+ window.addEventListener('resize', place);
502
+ document.addEventListener('scroll', place, true);
503
+ };
504
+ var cell = function (cls, text, label, o) {
505
+ var b = el('button', cls, { type: 'button', 'aria-label': label, 'aria-pressed': o.pressed ? 'true' : 'false' });
506
+ if (o.current) b.setAttribute('aria-current', 'date');
507
+ b.textContent = text; b.tabIndex = o.focus ? 0 : -1; b.dataset.value = o.value;
508
+ return b;
509
+ };
510
+ var render = function (moveFocus) {
511
+ var y = focusDay.getFullYear(), m = focusDay.getMonth(), now = today();
512
+ monthBtn.firstChild.textContent = MONTHS[m]; yearBtn.firstChild.textContent = y;
513
+ monthBtn.setAttribute('aria-expanded', String(view === 'months')); yearBtn.setAttribute('aria-expanded', String(view === 'years'));
514
+ monthBtn.setAttribute('aria-label', 'Choose the month, ' + MONTHS[m]); yearBtn.setAttribute('aria-label', 'Choose the year, ' + y);
515
+ calDays.hidden = view !== 'days'; calList.hidden = view === 'days';
516
+ var labels = { days: ['Previous month', 'Next month'], months: ['Previous year', 'Next year'], years: ['Previous ' + PAGE + ' years', 'Next ' + PAGE + ' years'] }[view];
517
+ navs[0].setAttribute('aria-label', labels[0]); navs[1].setAttribute('aria-label', labels[1]);
518
+ if (view === 'days') {
519
+ calTitle.textContent = MONTHS[m] + ' ' + y;
520
+ var first = new Date(y, m, 1), start = new Date(y, m, 1 - ((first.getDay() + 6) % 7));
521
+ calBody.textContent = '';
522
+ for (var w = 0; w < 6; w++) {
523
+ var row = el('tr');
524
+ for (var i = 0; i < 7; i++) {
525
+ var d = new Date(start.getFullYear(), start.getMonth(), start.getDate() + w * 7 + i), td = el('td');
526
+ td.appendChild(cell('cx-calendar__day' + (d.getMonth() !== m ? ' is-other' : ''), d.getDate(),
527
+ DAYS[d.getDay()] + ' ' + d.getDate() + ' ' + MONTHS[d.getMonth()] + ' ' + d.getFullYear(),
528
+ { pressed: same(d, selected), current: same(d, now), focus: same(d, focusDay), value: d.getFullYear() + '-' + d.getMonth() + '-' + d.getDate() }));
529
+ row.appendChild(td);
530
+ }
531
+ calBody.appendChild(row);
532
+ }
533
+ } else if (view === 'months') {
534
+ calTitle.textContent = 'Months of ' + y; calList.className = 'cx-calendar__list cx-calendar__list--months'; calList.textContent = '';
535
+ MONTHS.forEach(function (name, i) {
536
+ calList.appendChild(cell('cx-calendar__cell', name.slice(0, 3), name + ' ' + y,
537
+ { pressed: selected && selected.getFullYear() === y && selected.getMonth() === i, current: now.getFullYear() === y && now.getMonth() === i, focus: i === m, value: i }));
538
+ });
539
+ } else {
540
+ var from = Math.floor(y / PAGE) * PAGE;
541
+ calTitle.textContent = from + ' to ' + (from + PAGE - 1); calList.className = 'cx-calendar__list cx-calendar__list--years'; calList.textContent = '';
542
+ for (var k = from; k < from + PAGE; k++) {
543
+ calList.appendChild(cell('cx-calendar__cell', k, String(k), { pressed: selected && selected.getFullYear() === k, current: now.getFullYear() === k, focus: k === y, value: k }));
544
+ }
545
+ }
546
+ place();
547
+ if (moveFocus) { var f = (view === 'days' ? calBody : calList).querySelector('[tabindex="0"]'); if (f) f.focus(); }
548
+ };
549
+ var setView = function (v) { view = v; render(true); };
550
+ var place = function () {
551
+ if (!cal || !field || !cal.matches(':popover-open')) return;
552
+ var r = field.getBoundingClientRect(), vw = document.documentElement.clientWidth, h = cal.offsetHeight, w = cal.offsetWidth, gap = px('--cx-space-inline-xs'), edge = px('--cx-space-inline-sm');
553
+ var below = window.innerHeight - r.bottom - gap, above = r.top - gap;
554
+ var top = (below < h && above > below) ? r.top - h - gap : r.bottom + gap;
555
+ cal.style.top = (top + window.scrollY) + 'px';
556
+ cal.style.left = (Math.max(edge, Math.min(r.left, vw - w - edge)) + window.scrollX) + 'px';
557
+ };
558
+ var close = function () { cal.hidePopover(); if (opener) opener.focus(); };
559
+ var choose = function (d) {
560
+ selected = d;
561
+ var input = field.querySelector('.cx-field__control');
562
+ input.value = pad(d.getDate()) + '/' + pad(d.getMonth() + 1) + '/' + d.getFullYear();
563
+ input.dispatchEvent(new Event('input', { bubbles: true })); input.dispatchEvent(new Event('change', { bubbles: true }));
564
+ close();
565
+ };
566
+ pickers.forEach(function (box) {
567
+ var btn = box.querySelector('.cx-date__button');
568
+ if (!btn || !HTMLElement.prototype.hasOwnProperty('popover')) return;
569
+ btn.hidden = false;
570
+ btn.addEventListener('click', function () {
571
+ if (!cal) build();
572
+ if (cal.matches(':popover-open') && opener === btn) { cal.hidePopover(); return; }
573
+ if (cal.matches(':popover-open')) cal.hidePopover();
574
+ opener = btn; field = box;
575
+ selected = parse(box.querySelector('.cx-field__control').value);
576
+ focusDay = new Date(selected || today()); view = 'days';
577
+ cal.setAttribute('aria-label', btn.getAttribute('aria-label') || 'Choose a date');
578
+ cal.showPopover(); render(true);
579
+ });
580
+ });
581
+ }
582
+
285
583
  // Docs navigation: dock it (sticky, scrolling on its own) while it sits beside the main column, as the TOC does.
286
584
  document.querySelectorAll('.cx-docs').forEach(function (docs) {
287
585
  var nav = docs.querySelector('.cx-docs-nav');
package/dist/contrast.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Contrast report (generated)
2
2
 
3
- 99 declared pairs, each measured in both themes. Target is the pair's `min`.
3
+ 107 declared pairs, each measured in both themes. Target is the pair's `min`.
4
4
 
5
5
  | Foreground | Background | Min | Light | Dark | Result |
6
6
  |---|---|---|---|---|---|
@@ -9,6 +9,7 @@
9
9
  | `color.text.primary` | `color.surface.sunken` | 7 | 15.28 | 15.28 | pass |
10
10
  | `color.text.primary` | `color.surface.hover` | 7 | 15.28 | 10.21 | pass |
11
11
  | `color.text.primary` | `color.surface.highlight` | 7 | 15.47 | 9.91 | pass |
12
+ | `color.text.primary` | `color.surface.selected` | 7 | 15.47 | 9.91 | pass |
12
13
  | `color.text.primary` | `color.status.success.surface` | 7 | 16.48 | 15.12 | pass |
13
14
  | `color.text.primary` | `color.status.warning.surface` | 7 | 16.29 | 15.28 | pass |
14
15
  | `color.text.primary` | `color.status.danger.surface` | 7 | 16.23 | 15.57 | pass |
@@ -26,6 +27,8 @@
26
27
  | `color.text.inverse` | `color.surface.inverse` | 7 | 13.61 | 12.71 | pass |
27
28
  | `color.text.on-accent` | `color.accent.fill.rest` | 4.5 | 6.77 | 12.02 | pass |
28
29
  | `color.text.on-accent` | `color.accent.fill.hover` | 4.5 | 11.20 | 15.03 | pass |
30
+ | `color.text.on-danger` | `color.status.danger.fill` | 4.5 | 7.67 | 11.29 | pass |
31
+ | `color.text.on-danger` | `color.status.danger.fill-hover` | 4.5 | 12.15 | 14.36 | pass |
29
32
  | `color.link.rest` | `color.surface.base` | 7 | 10.61 | 9.18 | pass |
30
33
  | `color.link.rest` | `color.surface.raised` | 7 | 11.20 | 8.12 | pass |
31
34
  | `color.link.rest` | `color.surface.sunken` | 7 | 9.91 | 11.03 | pass |
@@ -58,6 +61,11 @@
58
61
  | `color.status.danger.text` | `color.surface.raised` | 4.5 | 7.67 | 7.63 | pass |
59
62
  | `color.status.danger.text` | `color.surface.hover` | 4.5 | 6.79 | 6.92 | pass |
60
63
  | `color.status.danger.border` | `color.status.danger.surface` | 3 | 5.04 | 7.39 | pass |
64
+ | `color.status.danger.fill` | `color.surface.base` | 3 | 7.27 | 8.62 | pass |
65
+ | `color.status.danger.fill` | `color.surface.raised` | 3 | 7.67 | 7.63 | pass |
66
+ | `color.status.danger.fill` | `color.surface.sunken` | 3 | 6.79 | 10.36 | pass |
67
+ | `color.status.danger.fill-hover` | `color.surface.raised` | 3 | 12.15 | 9.70 | pass |
68
+ | `color.status.danger.fill-hover` | `color.surface.sunken` | 3 | 10.75 | 13.18 | pass |
61
69
  | `color.status.info.text` | `color.status.info.surface` | 4.5 | 6.72 | 10.74 | pass |
62
70
  | `color.status.info.text` | `color.surface.base` | 4.5 | 6.76 | 8.95 | pass |
63
71
  | `color.status.info.text` | `color.surface.raised` | 4.5 | 7.13 | 7.92 | pass |
package/dist/icons.svg CHANGED
@@ -28,4 +28,5 @@
28
28
  <symbol id="cx-icon-settings" viewBox="0 -960 960 960"><path d="m400.69-100-18.07-120.23q-20.54-7-44.23-20.35-23.7-13.34-40.85-28.27l-111.85 50.93-79.92-141.31 101.08-74.38q-2-10.54-2.89-23.01-.88-12.46-.88-23 0-10.15.88-22.61.89-12.46 2.89-24.16l-101.08-74.76 79.92-140.16 111.46 50.16q18.31-14.93 41.24-28.08 22.92-13.15 43.84-19.54L400.69-860h158.62l18.07 120.62q22.08 8.15 44.16 20.23 22.07 12.07 39.77 28l113.38-50.16 79.54 140.16-102.62 74.3q2.77 11.93 3.47 24 .69 12.08.69 22.85 0 10.38-.89 22.15-.88 11.77-3.27 24.47l102.23 74.15-79.92 141.31-112.61-51.31q-18.7 15.69-40.35 28.96-21.65 13.27-43.58 19.65L559.31-100H400.69Zm36.46-45.39h85.31L536.85-257q31.84-8 59.42-23.85 27.58-15.84 52.73-40.23l104.46 45.23 40-70.84L701-414.92q4-17.77 6.31-33.5 2.3-15.73 2.3-31.58 0-16.62-2-31.96-2-15.35-6.61-32.35l93.23-69-40-70.84-105.62 45.23q-21.07-23.69-50.84-41.77Q568-698.77 536.46-703l-13.61-111.61h-85.7l-13.23 111.23q-33.23 6.61-61.19 22.65t-52.11 41.42l-104.85-44.84-40 70.84 92.46 67.85q-4.38 15.84-6.69 32.15-2.31 16.31-2.31 33.69 0 16.62 2.31 32.54 2.31 15.93 6.31 32.16l-92.08 68.23 40 70.84 104.46-44.84q24 24.38 52.15 40.23 28.16 15.84 61.16 23.84l13.61 111.23Zm41.7-221.92q47.07 0 79.88-32.81 32.81-32.8 32.81-79.88t-32.81-79.88q-32.81-32.81-79.88-32.81-46.7 0-79.7 32.81-32.99 32.8-32.99 79.88t32.99 79.88q33 32.81 79.7 32.81ZM480-480Z"/></symbol>
29
29
  <symbol id="cx-icon-restart" viewBox="0 -960 960 960"><path d="M447.92-142.77q-113.77-11.15-190.84-96Q180-323.62 180-439.38q0-68.93 31.08-130.2 31.07-61.26 86.23-102.34l32.23 32.61q-49.85 33-77 86.46-27.15 53.47-27.15 113.47 0 96.92 63.49 167.99 63.5 71.08 159.04 83.24v45.38Zm65.39.77v-45.39q96.15-14.3 159.04-84.88 62.88-70.58 62.88-167.11 0-106.7-73.96-180.66T480.62-694h-26.54l65.77 65.77-32.62 32.61-121.07-121.07 121.07-121.08 32.62 32.62-65.77 65.77h26.54q125.53 0 212.76 87.73 87.23 87.73 87.23 212.27 0 115.76-76.76 200.42-76.77 84.65-190.54 96.96Z"/></symbol>
30
30
  <symbol id="cx-icon-logs" viewBox="0 -960 960 960"><path d="M100-180v-600h760v600H100Zm45.39-45.39h669.22v-426.38H145.39v426.38ZM300-303.15l-31.61-31.23 103-104-104-104L300-574l135.61 135.62L300-303.15Zm197.31 7.46v-45.39h205.38v45.39H497.31Z"/></symbol>
31
+ <symbol id="cx-icon-calendar" viewBox="0 -960 960 960"><path d="M140-100v-694.61h131.54v-70h50.38v70h317.69v-70h49.23v70H820V-100H140Zm45.39-45.39h589.22V-555H185.39v409.61Zm0-454.99h589.22v-148.85H185.39v148.85Zm0 0v-148.85 148.85Z"/></symbol>
31
32
  </svg>
package/dist/tokens.css CHANGED
@@ -1,4 +1,4 @@
1
- /* MotifSpec 1.25.1 — generated from tokens/*.json. Do not edit.
1
+ /* MotifSpec 1.27.0 — generated from tokens/*.json. Do not edit.
2
2
  Themes: semantic colours use light-dark(); color-scheme follows the system unless
3
3
  <html data-theme="light|dark"> pins it. --cx-primitive-* are for this file only. */
4
4
  :root {
@@ -100,6 +100,7 @@
100
100
  --cx-color-surface-hover: light-dark(var(--cx-primitive-color-ash-100), var(--cx-primitive-color-ash-800));
101
101
  --cx-color-surface-inverse: light-dark(var(--cx-primitive-color-ash-900), var(--cx-primitive-color-ash-100));
102
102
  --cx-color-surface-highlight: light-dark(var(--cx-primitive-color-sap-100), var(--cx-primitive-color-sap-800));
103
+ --cx-color-surface-selected: light-dark(var(--cx-primitive-color-sap-100), var(--cx-primitive-color-sap-800));
103
104
 
104
105
  /* color.text */
105
106
  --cx-color-text-primary: light-dark(var(--cx-primitive-color-ash-950), var(--cx-primitive-color-ash-100));
@@ -108,6 +109,7 @@
108
109
  --cx-color-text-accent: light-dark(var(--cx-primitive-color-sap-700), var(--cx-primitive-color-sap-300));
109
110
  --cx-color-text-inverse: light-dark(var(--cx-primitive-color-ash-50), var(--cx-primitive-color-ash-900));
110
111
  --cx-color-text-on-accent: light-dark(var(--cx-primitive-color-ash-0), var(--cx-primitive-color-ash-1000));
112
+ --cx-color-text-on-danger: light-dark(var(--cx-primitive-color-ash-0), var(--cx-primitive-color-ash-1000));
111
113
 
112
114
  /* color.link */
113
115
  --cx-color-link-rest: light-dark(var(--cx-primitive-color-sap-800), var(--cx-primitive-color-sap-300));
@@ -141,6 +143,8 @@
141
143
  --cx-color-status-danger-text: light-dark(var(--cx-primitive-color-madder-700), var(--cx-primitive-color-madder-300));
142
144
  --cx-color-status-danger-surface: light-dark(var(--cx-primitive-color-madder-50), var(--cx-primitive-color-madder-950));
143
145
  --cx-color-status-danger-border: light-dark(var(--cx-primitive-color-madder-600), var(--cx-primitive-color-madder-400));
146
+ --cx-color-status-danger-fill: light-dark(var(--cx-primitive-color-madder-700), var(--cx-primitive-color-madder-300));
147
+ --cx-color-status-danger-fill-hover: light-dark(var(--cx-primitive-color-madder-800), var(--cx-primitive-color-madder-200));
144
148
  --cx-color-status-info-text: light-dark(var(--cx-primitive-color-woad-700), var(--cx-primitive-color-woad-300));
145
149
  --cx-color-status-info-surface: light-dark(var(--cx-primitive-color-woad-50), var(--cx-primitive-color-woad-950));
146
150
  --cx-color-status-info-border: light-dark(var(--cx-primitive-color-woad-600), var(--cx-primitive-color-woad-400));
@@ -190,7 +194,8 @@
190
194
  --cx-primitive-motion-duration-3: 320ms;
191
195
  --cx-primitive-motion-duration-4: 1600ms;
192
196
  --cx-primitive-motion-duration-5: 3200ms;
193
- --cx-primitive-motion-duration-6: 60000ms;
197
+ --cx-primitive-motion-duration-6: 6000ms;
198
+ --cx-primitive-motion-duration-7: 60000ms;
194
199
 
195
200
  /* primitive.motion.easing */
196
201
  --cx-primitive-motion-easing-out-strong: cubic-bezier(0.2, 0, 0, 1);
@@ -208,8 +213,9 @@
208
213
  --cx-motion-duration-base: var(--cx-primitive-motion-duration-2);
209
214
  --cx-motion-duration-slow: var(--cx-primitive-motion-duration-3);
210
215
  --cx-motion-duration-plate: var(--cx-primitive-motion-duration-4);
211
- --cx-motion-duration-drift: var(--cx-primitive-motion-duration-6);
216
+ --cx-motion-duration-drift: var(--cx-primitive-motion-duration-7);
212
217
  --cx-motion-duration-settle: var(--cx-primitive-motion-duration-5);
218
+ --cx-motion-duration-toast: var(--cx-primitive-motion-duration-6);
213
219
  --cx-motion-duration-pulse: var(--cx-primitive-motion-duration-5); /* Deprecated: Unused since the contour plate; removed in 2.0.0. */
214
220
 
215
221
  /* motion.easing */
package/dist/tokens.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Generated by npm run build. Do not edit.
2
- export const version = "1.25.1";
2
+ export const version = "1.27.0";
3
3
  export const changelog = "https://github.com/Aitrien/motifspec/blob/main/CHANGELOG.md";
4
4
  export const showcase = "https://motifspec.com";
5
5
  export const tokens = [
@@ -571,7 +571,7 @@ export const tokens = [
571
571
  "referencesDark": "primitive.color.ash.100",
572
572
  "value": "#252a28",
573
573
  "valueDark": "#eaf1ee",
574
- "description": "Background of tooltips and other small transient labels that must stand out from every surface. Never for panels or cards."
574
+ "description": "Background of tooltips, toasts and other small transient labels that must stand out from every surface. Never for panels or cards."
575
575
  },
576
576
  {
577
577
  "name": "color.surface.highlight",
@@ -584,6 +584,17 @@ export const tokens = [
584
584
  "valueDark": "#01441f",
585
585
  "description": "Text selection and <mark>. Never for large areas or decoration."
586
586
  },
587
+ {
588
+ "name": "color.surface.selected",
589
+ "css": "--cx-color-surface-selected",
590
+ "tier": "semantic",
591
+ "type": "color",
592
+ "references": "primitive.color.sap.100",
593
+ "referencesDark": "primitive.color.sap.800",
594
+ "value": "#d8f9df",
595
+ "valueDark": "#01441f",
596
+ "description": "The chosen item among options the reader picks from: a calendar's date, month or year (date-picker.md). With color.text.primary. Never for large areas or decoration."
597
+ },
587
598
  {
588
599
  "name": "color.text.primary",
589
600
  "css": "--cx-color-text-primary",
@@ -615,6 +626,10 @@ export const tokens = [
615
626
  "token": "color.surface.highlight",
616
627
  "min": 7
617
628
  },
629
+ {
630
+ "token": "color.surface.selected",
631
+ "min": 7
632
+ },
618
633
  {
619
634
  "token": "color.status.success.surface",
620
635
  "min": 7
@@ -721,7 +736,7 @@ export const tokens = [
721
736
  "referencesDark": "primitive.color.ash.900",
722
737
  "value": "#f4f8f6",
723
738
  "valueDark": "#252a28",
724
- "description": "Text on color.surface.inverse (tooltips). Only there.",
739
+ "description": "Text on color.surface.inverse (tooltips and toasts), and the focus ring inside a toast. Only there.",
725
740
  "pairsWith": [
726
741
  {
727
742
  "token": "color.surface.inverse",
@@ -750,6 +765,27 @@ export const tokens = [
750
765
  }
751
766
  ]
752
767
  },
768
+ {
769
+ "name": "color.text.on-danger",
770
+ "css": "--cx-color-text-on-danger",
771
+ "tier": "semantic",
772
+ "type": "color",
773
+ "references": "primitive.color.ash.0",
774
+ "referencesDark": "primitive.color.ash.1000",
775
+ "value": "#fbfefd",
776
+ "valueDark": "#0e100f",
777
+ "description": "Text and icons on color.status.danger.fill and its hover, such as a danger button’s label. Only there.",
778
+ "pairsWith": [
779
+ {
780
+ "token": "color.status.danger.fill",
781
+ "min": 4.5
782
+ },
783
+ {
784
+ "token": "color.status.danger.fill-hover",
785
+ "min": 4.5
786
+ }
787
+ ]
788
+ },
753
789
  {
754
790
  "name": "color.link.rest",
755
791
  "css": "--cx-color-link-rest",
@@ -1137,6 +1173,52 @@ export const tokens = [
1137
1173
  }
1138
1174
  ]
1139
1175
  },
1176
+ {
1177
+ "name": "color.status.danger.fill",
1178
+ "css": "--cx-color-status-danger-fill",
1179
+ "tier": "semantic",
1180
+ "type": "color",
1181
+ "references": "primitive.color.madder.700",
1182
+ "referencesDark": "primitive.color.madder.300",
1183
+ "value": "#942f29",
1184
+ "valueDark": "#feb5ac",
1185
+ "description": "Fill of a button that deletes or stops something, in a dialog asking to confirm it (cx-button--danger, button-and-link.md). Its label says what it does; never the only sign.",
1186
+ "pairsWith": [
1187
+ {
1188
+ "token": "color.surface.base",
1189
+ "min": 3
1190
+ },
1191
+ {
1192
+ "token": "color.surface.raised",
1193
+ "min": 3
1194
+ },
1195
+ {
1196
+ "token": "color.surface.sunken",
1197
+ "min": 3
1198
+ }
1199
+ ]
1200
+ },
1201
+ {
1202
+ "name": "color.status.danger.fill-hover",
1203
+ "css": "--cx-color-status-danger-fill-hover",
1204
+ "tier": "semantic",
1205
+ "type": "color",
1206
+ "references": "primitive.color.madder.800",
1207
+ "referencesDark": "primitive.color.madder.200",
1208
+ "value": "#651916",
1209
+ "valueDark": "#ffd6d1",
1210
+ "description": "Fill of a danger button while hovered or pressed.",
1211
+ "pairsWith": [
1212
+ {
1213
+ "token": "color.surface.raised",
1214
+ "min": 3
1215
+ },
1216
+ {
1217
+ "token": "color.surface.sunken",
1218
+ "min": 3
1219
+ }
1220
+ ]
1221
+ },
1140
1222
  {
1141
1223
  "name": "color.status.info.text",
1142
1224
  "css": "--cx-color-status-info-text",
@@ -1737,6 +1819,13 @@ export const tokens = [
1737
1819
  "css": "--cx-primitive-motion-duration-6",
1738
1820
  "tier": "primitive",
1739
1821
  "type": "duration",
1822
+ "value": "6000ms"
1823
+ },
1824
+ {
1825
+ "name": "primitive.motion.duration.7",
1826
+ "css": "--cx-primitive-motion-duration-7",
1827
+ "tier": "primitive",
1828
+ "type": "duration",
1740
1829
  "value": "60000ms"
1741
1830
  },
1742
1831
  {
@@ -1831,7 +1920,7 @@ export const tokens = [
1831
1920
  "css": "--cx-motion-duration-drift",
1832
1921
  "tier": "semantic",
1833
1922
  "type": "duration",
1834
- "references": "primitive.motion.duration.6",
1923
+ "references": "primitive.motion.duration.7",
1835
1924
  "value": "60000ms",
1836
1925
  "description": "Time the specimen plate's terrain takes to drift one noise unit, so its lines reshape slowly and continuously. The only looping motion in the system: one plate per page, with a visible pause control, stopped under prefers-reduced-motion. The backdrop doesn't drift."
1837
1926
  },
@@ -1844,6 +1933,15 @@ export const tokens = [
1844
1933
  "value": "3200ms",
1845
1934
  "description": "The backdrop's response time. The home page's contours settle into place over it on arrival and then stay still, and a hill the pointer warms takes about two-thirds of it to rise and twice it to flatten. Under five seconds, so nothing runs long enough to need a pause control; none of it happens under prefers-reduced-motion."
1846
1935
  },
1936
+ {
1937
+ "name": "motion.duration.toast",
1938
+ "css": "--cx-motion-duration-toast",
1939
+ "tier": "semantic",
1940
+ "type": "duration",
1941
+ "references": "primitive.motion.duration.6",
1942
+ "value": "6000ms",
1943
+ "description": "How long a toast (toast.md) stays before it goes on its own. The time starts again while the pointer or focus is on it, and isn't shortened under prefers-reduced-motion: it is time to read, not motion."
1944
+ },
1847
1945
  {
1848
1946
  "name": "motion.duration.pulse",
1849
1947
  "css": "--cx-motion-duration-pulse",
@@ -1870,7 +1968,7 @@ export const tokens = [
1870
1968
  "type": "cubicBezier",
1871
1969
  "references": "primitive.motion.easing.decelerate",
1872
1970
  "value": "cubic-bezier(0, 0, 0.2, 1)",
1873
- "description": "Elements appearing: disclosures opening, a toast arriving."
1971
+ "description": "Elements appearing: disclosures opening, a toast arriving (toast.md)."
1874
1972
  },
1875
1973
  {
1876
1974
  "name": "motion.easing.exit",