@karmo-co/drift-kit-public 25.6.0 → 25.7.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/components.js CHANGED
@@ -1408,19 +1408,61 @@
1408
1408
  return;
1409
1409
  els.forEach(function (el) { set(el, q); });
1410
1410
  }
1411
- function onClick(e) {
1412
- var t = e.target && e.target.closest ? e.target.closest('[data-theme-toggle]') : null;
1413
- if (!t)
1414
- return;
1411
+ function flip(t) {
1415
1412
  var host = t.closest('[' + FROM + ']') || document.querySelector('[' + FROM + ']');
1416
1413
  if (host)
1417
1414
  toggle(host);
1418
1415
  }
1419
- dk.theme = { set: set, toggle: toggle, fromUrl: fromUrl };
1416
+ function onClick(e) {
1417
+ var t = e.target && e.target.closest ? e.target.closest('[data-theme-toggle]') : null;
1418
+ if (t)
1419
+ flip(t);
1420
+ }
1421
+ function native(el) { return /^(BUTTON|INPUT|SELECT|TEXTAREA|SUMMARY)$/.test(el.tagName) || (el.tagName === 'A' && el.hasAttribute('href')); }
1422
+ function onKey(e) {
1423
+ if (e.defaultPrevented || e.repeat)
1424
+ return;
1425
+ if (e.key !== 'Enter' && e.key !== ' ' && e.key !== 'Spacebar')
1426
+ return;
1427
+ var t = e.target && e.target.closest ? e.target.closest('[data-theme-toggle]') : null;
1428
+ if (!t || native(t) || e.target !== t)
1429
+ return;
1430
+ e.preventDefault();
1431
+ flip(t);
1432
+ }
1433
+ function init(scope) {
1434
+ var root = scope || document;
1435
+ var list = Array.prototype.slice.call(root.querySelectorAll ? root.querySelectorAll('[data-theme-toggle]') : []);
1436
+ if (root.matches && root.matches('[data-theme-toggle]'))
1437
+ list.push(root);
1438
+ list.forEach(function (t) {
1439
+ if (native(t))
1440
+ return;
1441
+ if (!t.hasAttribute('role'))
1442
+ t.setAttribute('role', 'button');
1443
+ if (!t.hasAttribute('tabindex'))
1444
+ t.setAttribute('tabindex', '0');
1445
+ });
1446
+ }
1447
+ dk.theme = { set: set, toggle: toggle, fromUrl: fromUrl, init: init };
1420
1448
  document.addEventListener('click', onClick);
1449
+ document.addEventListener('keydown', onKey);
1421
1450
  fromUrl();
1422
- if (document.readyState === 'loading')
1423
- document.addEventListener('DOMContentLoaded', fromUrl);
1451
+ if (!document.body && window.MutationObserver && document.documentElement) {
1452
+ var early = new MutationObserver(function () {
1453
+ if (!document.body)
1454
+ return;
1455
+ early.disconnect();
1456
+ fromUrl();
1457
+ });
1458
+ early.observe(document.documentElement, { childList: true });
1459
+ }
1460
+ if (document.readyState === 'loading') {
1461
+ document.addEventListener('DOMContentLoaded', function () { fromUrl(); init(document); });
1462
+ }
1463
+ else {
1464
+ init(document);
1465
+ }
1424
1466
  })();
1425
1467
  })(typeof window !== 'undefined' ? window : undefined);
1426
1468
  (function (w) {
@@ -5876,6 +5918,26 @@
5876
5918
  ind.style.transition = '';
5877
5919
  }
5878
5920
  }
5921
+ function reveal(root, opt, smooth) {
5922
+ if (!opt || root.getAttribute('data-overflow') !== 'scroll')
5923
+ return;
5924
+ var cs = getComputedStyle(root);
5925
+ var padL = parseFloat(cs.paddingLeft) || 0, padR = parseFloat(cs.paddingRight) || 0;
5926
+ var left = opt.offsetLeft, right = left + opt.offsetWidth, at = root.scrollLeft, w = root.clientWidth;
5927
+ var to = at;
5928
+ if (left - padL < at)
5929
+ to = left - padL;
5930
+ else if (right + padR > at + w)
5931
+ to = right + padR - w;
5932
+ if (to === at)
5933
+ return;
5934
+ var dk = window.dk;
5935
+ var reduced = dk && dk.motion && dk.motion.reduced ? dk.motion.reduced() : !!(window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches);
5936
+ if (root.scrollTo)
5937
+ root.scrollTo({ left: to, behavior: smooth && !reduced ? 'smooth' : 'auto' });
5938
+ else
5939
+ root.scrollLeft = to;
5940
+ }
5879
5941
  function showPanels(list) {
5880
5942
  if (!list.some(function (o) { return o.getAttribute('aria-controls'); }))
5881
5943
  return;
@@ -5897,6 +5959,10 @@
5897
5959
  showPanels(list);
5898
5960
  if (moveFocus && opt)
5899
5961
  opt.focus();
5962
+ if (opt !== root.__dcGliderShown) {
5963
+ root.__dcGliderShown = opt;
5964
+ reveal(root, opt, animate);
5965
+ }
5900
5966
  }
5901
5967
  function report(root, opt) {
5902
5968
  var values = chosen(root).map(valueOf);
@@ -5938,6 +6004,8 @@
5938
6004
  setup(root);
5939
6005
  function snap() { if (!multiple(root))
5940
6006
  pin(root, chosen(root)[0] || null, false); }
6007
+ requestAnimationFrame(function () { if (!multiple(root))
6008
+ reveal(root, chosen(root)[0] || null, false); });
5941
6009
  if (typeof ResizeObserver !== 'undefined') {
5942
6010
  var skip = true;
5943
6011
  new ResizeObserver(function () { if (skip) {
@@ -6032,14 +6100,19 @@
6032
6100
  }
6033
6101
  function isClone(it) { return it.hasAttribute('data-carousel-clone'); }
6034
6102
  function smooth() { return dk.motion && dk.motion.reduced && dk.motion.reduced() ? 'auto' : 'smooth'; }
6035
- function presentationOf(root) {
6036
- if (root.hasAttribute('data-presentation-fixed'))
6037
- return root.getAttribute('data-presentation') === 'row' ? 'row' : 'slider';
6103
+ function wantsPhone(root) {
6038
6104
  var holder = root.closest('[data-device]');
6039
6105
  var device = holder && holder.getAttribute('data-device');
6040
6106
  var force = device === 'phone' || device === 'tablet' ? 'always' : device === 'desktop' ? 'never' : 'auto';
6041
- var phone = dk.sheet ? dk.sheet.wants(root, '--dk-breakpoint-phone', force) : force === 'always';
6042
- return phone ? 'slider' : 'row';
6107
+ return dk.sheet ? dk.sheet.wants(root, '--dk-breakpoint-phone', force) : force === 'always';
6108
+ }
6109
+ function isViewer(root) { return root.getAttribute('data-variant') === 'viewer'; }
6110
+ function presentationOf(root) {
6111
+ if (isViewer(root))
6112
+ return 'viewer';
6113
+ if (root.hasAttribute('data-presentation-fixed'))
6114
+ return root.getAttribute('data-presentation') === 'row' ? 'row' : 'slider';
6115
+ return wantsPhone(root) ? 'slider' : 'row';
6043
6116
  }
6044
6117
  function topIn(node, item) {
6045
6118
  var y = 0, n = node, home = item.offsetParent;
@@ -6102,10 +6175,18 @@
6102
6175
  var prev = root.querySelector(':scope > .' + P + '__prev');
6103
6176
  var next = root.querySelector(':scope > .' + P + '__next');
6104
6177
  var max = track.scrollWidth - track.clientWidth, sl = track.scrollLeft;
6178
+ var focused = document.activeElement;
6105
6179
  if (prev)
6106
6180
  prev.hidden = !loop && sl <= 1;
6107
6181
  if (next)
6108
6182
  next.hidden = !loop && sl >= max - 1;
6183
+ if (focused && (focused === prev || focused === next) && focused.hidden) {
6184
+ var other = focused === prev ? next : prev;
6185
+ if (other && !other.hidden)
6186
+ other.focus();
6187
+ else if (track.tabIndex >= 0)
6188
+ track.focus();
6189
+ }
6109
6190
  if (pres === 'row') {
6110
6191
  root.toggleAttribute('data-at-start', sl <= 1);
6111
6192
  root.toggleAttribute('data-at-end', sl >= max - 1);
@@ -6177,11 +6258,38 @@
6177
6258
  if (!silent && i >= 0)
6178
6259
  root.dispatchEvent(new CustomEvent(P + ':change', { detail: { index: i }, bubbles: true }));
6179
6260
  }
6261
+ function viewer() {
6262
+ if (pres !== 'viewer') {
6263
+ if (root.hasAttribute('data-phone'))
6264
+ root.removeAttribute('data-phone');
6265
+ return;
6266
+ }
6267
+ if (!track.hasAttribute('tabindex'))
6268
+ track.setAttribute('tabindex', '0');
6269
+ if (!root.hasAttribute('role')) {
6270
+ root.setAttribute('role', 'group');
6271
+ root.setAttribute('aria-roledescription', 'carousel');
6272
+ }
6273
+ var ph = wantsPhone(root);
6274
+ if (root.hasAttribute('data-phone') !== ph)
6275
+ root.toggleAttribute('data-phone', ph);
6276
+ }
6277
+ function count() {
6278
+ var el = root.querySelector(':scope > .' + P + '__count');
6279
+ if (!el)
6280
+ return;
6281
+ if (!el.hasAttribute('aria-live'))
6282
+ el.setAttribute('aria-live', 'polite');
6283
+ var n = realItems().length, text = current >= 0 && n ? (current + 1) + ' / ' + n : '';
6284
+ if (el.textContent !== text)
6285
+ el.textContent = text;
6286
+ }
6180
6287
  function update(silent) {
6288
+ viewer();
6181
6289
  bleed();
6182
6290
  edges();
6183
6291
  var W = track.clientWidth;
6184
- if (pres !== 'row' && W) {
6292
+ if (pres === 'slider' && W) {
6185
6293
  var mid = track.scrollLeft + W / 2;
6186
6294
  var sel = root.getAttribute('data-lift');
6187
6295
  cards().forEach(function (card) {
@@ -6198,6 +6306,7 @@
6198
6306
  });
6199
6307
  }
6200
6308
  report(silent);
6309
+ count();
6201
6310
  }
6202
6311
  function clones(want) {
6203
6312
  made.forEach(function (c) { if (c.parentNode)
@@ -6235,7 +6344,8 @@
6235
6344
  pres = next;
6236
6345
  if (!root.hasAttribute('data-presentation-fixed') && root.getAttribute('data-presentation') !== pres)
6237
6346
  root.setAttribute('data-presentation', pres);
6238
- loop = pres === 'slider' && root.hasAttribute('data-loop') && real.length >= 3;
6347
+ viewer();
6348
+ loop = pres !== 'row' && root.hasAttribute('data-loop') && real.length >= 3;
6239
6349
  var unchanged = !first && !switched && loop === wasLoop && same(real, lastReal);
6240
6350
  lastReal = real;
6241
6351
  if (!unchanged)
@@ -6251,13 +6361,15 @@
6251
6361
  settling = false;
6252
6362
  track.style.scrollSnapType = '';
6253
6363
  }
6254
- if (pres === 'row') {
6364
+ if (pres !== 'slider') {
6255
6365
  itemsOf(track).forEach(function (card) {
6256
6366
  ['transform', 'opacity', 'scroll-margin-left', 'scroll-margin-right'].forEach(function (p) { card.style.removeProperty(p); });
6257
6367
  if (card.getAttribute('style') === '')
6258
6368
  card.removeAttribute('style');
6259
6369
  pulls.delete(card);
6260
6370
  });
6371
+ }
6372
+ if (pres === 'row') {
6261
6373
  if (first || switched)
6262
6374
  track.scrollLeft = 0;
6263
6375
  }
@@ -6426,6 +6538,17 @@
6426
6538
  }
6427
6539
  forward(e);
6428
6540
  }
6541
+ function onKey(e) {
6542
+ if (pres !== 'viewer' || e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey)
6543
+ return;
6544
+ if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight')
6545
+ return;
6546
+ var t = e.target;
6547
+ if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)))
6548
+ return;
6549
+ e.preventDefault();
6550
+ step(e.key === 'ArrowLeft' ? -1 : 1);
6551
+ }
6429
6552
  function onArrow(e) {
6430
6553
  var b = e.target.closest && e.target.closest('.' + P + '__prev, .' + P + '__next');
6431
6554
  if (!b || b.parentElement !== root || b.disabled)
@@ -6452,6 +6575,7 @@
6452
6575
  on(track, 'click', onClick, true);
6453
6576
  on(track, 'dragstart', onDragStart);
6454
6577
  on(root, 'click', onArrow);
6578
+ on(root, 'keydown', onKey);
6455
6579
  on(window, 'pointerup', onWinUp);
6456
6580
  on(window, 'pointercancel', onWinUp);
6457
6581
  on(window, 'blur', onWinUp);
@@ -6475,25 +6599,27 @@
6475
6599
  update();
6476
6600
  }) : null;
6477
6601
  var mo = typeof MutationObserver !== 'undefined' ? new MutationObserver(function (recs) {
6478
- var forced = recs.some(function (r) { return r.attributeName === 'data-loop' || r.attributeName === 'data-bleed' || r.attributeName === 'data-presentation-fixed'; });
6602
+ var forced = recs.some(function (r) { return r.attributeName === 'data-loop' || r.attributeName === 'data-bleed' || r.attributeName === 'data-presentation-fixed' || r.attributeName === 'data-variant'; });
6479
6603
  if (forced || presentationOf(root) !== pres)
6480
6604
  apply(false);
6481
6605
  }) : null;
6482
6606
  if (mo)
6483
- mo.observe(root, { attributes: true, attributeFilter: ['data-presentation', 'data-presentation-fixed', 'data-device', 'data-loop', 'data-bleed'] });
6607
+ mo.observe(root, { attributes: true, attributeFilter: ['data-presentation', 'data-presentation-fixed', 'data-device', 'data-loop', 'data-bleed', 'data-variant'] });
6484
6608
  function arrowLook() {
6485
6609
  var given = root.getAttribute('data-arrow-look');
6486
- if (given === 'solid' || given === 'raised-inverse')
6610
+ if (given === 'solid' || given === 'raised-inverse' || given === 'plain')
6487
6611
  return given;
6612
+ if (isViewer(root))
6613
+ return 'plain';
6488
6614
  var holder = root.closest('[data-theme]');
6489
6615
  return holder && holder.getAttribute('data-theme') === 'dark' ? 'raised-inverse' : 'solid';
6490
6616
  }
6491
6617
  function paintArrows() {
6492
- var inverse = arrowLook() === 'raised-inverse';
6618
+ var look = arrowLook(), inverse = look === 'raised-inverse';
6493
6619
  Array.prototype.forEach.call(root.children, function (b) {
6494
6620
  if (!b.classList.contains(P + '__prev') && !b.classList.contains(P + '__next'))
6495
6621
  return;
6496
- var v = inverse ? 'raised' : 'solid';
6622
+ var v = inverse ? 'raised' : look;
6497
6623
  if (b.getAttribute('data-variant') !== v)
6498
6624
  b.setAttribute('data-variant', v);
6499
6625
  if (inverse && b.getAttribute('data-theme') !== 'light')
@@ -8210,6 +8336,11 @@
8210
8336
  return Math.min(n, 12);
8211
8337
  }
8212
8338
  function makeCells(root, state) {
8339
+ var seams = state.group ? Math.max(0, Math.ceil(state.count / state.group) - 1) : 0;
8340
+ if (seams)
8341
+ root.style.setProperty('--_code-seams', String(seams));
8342
+ else
8343
+ root.style.removeProperty('--_code-seams');
8213
8344
  var host = state.cells;
8214
8345
  while (host.firstChild)
8215
8346
  host.removeChild(host.firstChild);