@karmo-co/drift-kit-public 25.5.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) {
@@ -5683,6 +5725,9 @@
5683
5725
  if (!tab || root.scrollWidth <= root.clientWidth)
5684
5726
  return;
5685
5727
  var l = tab.offsetLeft, r = l + tab.offsetWidth;
5728
+ var cs = getComputedStyle(root);
5729
+ l -= parseFloat(cs.scrollPaddingInlineStart) || 0;
5730
+ r += parseFloat(cs.scrollPaddingInlineEnd) || 0;
5686
5731
  if (l < root.scrollLeft)
5687
5732
  root.scrollLeft = l;
5688
5733
  else if (r > root.scrollLeft + root.clientWidth)
@@ -5873,6 +5918,26 @@
5873
5918
  ind.style.transition = '';
5874
5919
  }
5875
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
+ }
5876
5941
  function showPanels(list) {
5877
5942
  if (!list.some(function (o) { return o.getAttribute('aria-controls'); }))
5878
5943
  return;
@@ -5894,6 +5959,10 @@
5894
5959
  showPanels(list);
5895
5960
  if (moveFocus && opt)
5896
5961
  opt.focus();
5962
+ if (opt !== root.__dcGliderShown) {
5963
+ root.__dcGliderShown = opt;
5964
+ reveal(root, opt, animate);
5965
+ }
5897
5966
  }
5898
5967
  function report(root, opt) {
5899
5968
  var values = chosen(root).map(valueOf);
@@ -5935,6 +6004,8 @@
5935
6004
  setup(root);
5936
6005
  function snap() { if (!multiple(root))
5937
6006
  pin(root, chosen(root)[0] || null, false); }
6007
+ requestAnimationFrame(function () { if (!multiple(root))
6008
+ reveal(root, chosen(root)[0] || null, false); });
5938
6009
  if (typeof ResizeObserver !== 'undefined') {
5939
6010
  var skip = true;
5940
6011
  new ResizeObserver(function () { if (skip) {
@@ -6029,14 +6100,19 @@
6029
6100
  }
6030
6101
  function isClone(it) { return it.hasAttribute('data-carousel-clone'); }
6031
6102
  function smooth() { return dk.motion && dk.motion.reduced && dk.motion.reduced() ? 'auto' : 'smooth'; }
6032
- function presentationOf(root) {
6033
- if (root.hasAttribute('data-presentation-fixed'))
6034
- return root.getAttribute('data-presentation') === 'row' ? 'row' : 'slider';
6103
+ function wantsPhone(root) {
6035
6104
  var holder = root.closest('[data-device]');
6036
6105
  var device = holder && holder.getAttribute('data-device');
6037
6106
  var force = device === 'phone' || device === 'tablet' ? 'always' : device === 'desktop' ? 'never' : 'auto';
6038
- var phone = dk.sheet ? dk.sheet.wants(root, '--dk-breakpoint-phone', force) : force === 'always';
6039
- 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';
6040
6116
  }
6041
6117
  function topIn(node, item) {
6042
6118
  var y = 0, n = node, home = item.offsetParent;
@@ -6099,10 +6175,18 @@
6099
6175
  var prev = root.querySelector(':scope > .' + P + '__prev');
6100
6176
  var next = root.querySelector(':scope > .' + P + '__next');
6101
6177
  var max = track.scrollWidth - track.clientWidth, sl = track.scrollLeft;
6178
+ var focused = document.activeElement;
6102
6179
  if (prev)
6103
6180
  prev.hidden = !loop && sl <= 1;
6104
6181
  if (next)
6105
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
+ }
6106
6190
  if (pres === 'row') {
6107
6191
  root.toggleAttribute('data-at-start', sl <= 1);
6108
6192
  root.toggleAttribute('data-at-end', sl >= max - 1);
@@ -6174,11 +6258,38 @@
6174
6258
  if (!silent && i >= 0)
6175
6259
  root.dispatchEvent(new CustomEvent(P + ':change', { detail: { index: i }, bubbles: true }));
6176
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
+ }
6177
6287
  function update(silent) {
6288
+ viewer();
6178
6289
  bleed();
6179
6290
  edges();
6180
6291
  var W = track.clientWidth;
6181
- if (pres !== 'row' && W) {
6292
+ if (pres === 'slider' && W) {
6182
6293
  var mid = track.scrollLeft + W / 2;
6183
6294
  var sel = root.getAttribute('data-lift');
6184
6295
  cards().forEach(function (card) {
@@ -6195,6 +6306,7 @@
6195
6306
  });
6196
6307
  }
6197
6308
  report(silent);
6309
+ count();
6198
6310
  }
6199
6311
  function clones(want) {
6200
6312
  made.forEach(function (c) { if (c.parentNode)
@@ -6232,7 +6344,8 @@
6232
6344
  pres = next;
6233
6345
  if (!root.hasAttribute('data-presentation-fixed') && root.getAttribute('data-presentation') !== pres)
6234
6346
  root.setAttribute('data-presentation', pres);
6235
- loop = pres === 'slider' && root.hasAttribute('data-loop') && real.length >= 3;
6347
+ viewer();
6348
+ loop = pres !== 'row' && root.hasAttribute('data-loop') && real.length >= 3;
6236
6349
  var unchanged = !first && !switched && loop === wasLoop && same(real, lastReal);
6237
6350
  lastReal = real;
6238
6351
  if (!unchanged)
@@ -6248,13 +6361,15 @@
6248
6361
  settling = false;
6249
6362
  track.style.scrollSnapType = '';
6250
6363
  }
6251
- if (pres === 'row') {
6364
+ if (pres !== 'slider') {
6252
6365
  itemsOf(track).forEach(function (card) {
6253
6366
  ['transform', 'opacity', 'scroll-margin-left', 'scroll-margin-right'].forEach(function (p) { card.style.removeProperty(p); });
6254
6367
  if (card.getAttribute('style') === '')
6255
6368
  card.removeAttribute('style');
6256
6369
  pulls.delete(card);
6257
6370
  });
6371
+ }
6372
+ if (pres === 'row') {
6258
6373
  if (first || switched)
6259
6374
  track.scrollLeft = 0;
6260
6375
  }
@@ -6423,6 +6538,17 @@
6423
6538
  }
6424
6539
  forward(e);
6425
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
+ }
6426
6552
  function onArrow(e) {
6427
6553
  var b = e.target.closest && e.target.closest('.' + P + '__prev, .' + P + '__next');
6428
6554
  if (!b || b.parentElement !== root || b.disabled)
@@ -6449,6 +6575,7 @@
6449
6575
  on(track, 'click', onClick, true);
6450
6576
  on(track, 'dragstart', onDragStart);
6451
6577
  on(root, 'click', onArrow);
6578
+ on(root, 'keydown', onKey);
6452
6579
  on(window, 'pointerup', onWinUp);
6453
6580
  on(window, 'pointercancel', onWinUp);
6454
6581
  on(window, 'blur', onWinUp);
@@ -6472,25 +6599,27 @@
6472
6599
  update();
6473
6600
  }) : null;
6474
6601
  var mo = typeof MutationObserver !== 'undefined' ? new MutationObserver(function (recs) {
6475
- 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'; });
6476
6603
  if (forced || presentationOf(root) !== pres)
6477
6604
  apply(false);
6478
6605
  }) : null;
6479
6606
  if (mo)
6480
- 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'] });
6481
6608
  function arrowLook() {
6482
6609
  var given = root.getAttribute('data-arrow-look');
6483
- if (given === 'solid' || given === 'raised-inverse')
6610
+ if (given === 'solid' || given === 'raised-inverse' || given === 'plain')
6484
6611
  return given;
6612
+ if (isViewer(root))
6613
+ return 'plain';
6485
6614
  var holder = root.closest('[data-theme]');
6486
6615
  return holder && holder.getAttribute('data-theme') === 'dark' ? 'raised-inverse' : 'solid';
6487
6616
  }
6488
6617
  function paintArrows() {
6489
- var inverse = arrowLook() === 'raised-inverse';
6618
+ var look = arrowLook(), inverse = look === 'raised-inverse';
6490
6619
  Array.prototype.forEach.call(root.children, function (b) {
6491
6620
  if (!b.classList.contains(P + '__prev') && !b.classList.contains(P + '__next'))
6492
6621
  return;
6493
- var v = inverse ? 'raised' : 'solid';
6622
+ var v = inverse ? 'raised' : look;
6494
6623
  if (b.getAttribute('data-variant') !== v)
6495
6624
  b.setAttribute('data-variant', v);
6496
6625
  if (inverse && b.getAttribute('data-theme') !== 'light')
@@ -8207,6 +8336,11 @@
8207
8336
  return Math.min(n, 12);
8208
8337
  }
8209
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');
8210
8344
  var host = state.cells;
8211
8345
  while (host.firstChild)
8212
8346
  host.removeChild(host.firstChild);