@karmo-co/drift-kit-public 24.0.0 → 24.2.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
@@ -3505,6 +3505,11 @@
3505
3505
  session.reposition(); }
3506
3506
  function sheetTitle() {
3507
3507
  var existing = menu.querySelector('.dk-component-select__sheet-title');
3508
+ if (root.getAttribute('data-sheet-title') === 'hidden') {
3509
+ if (existing)
3510
+ existing.remove();
3511
+ return;
3512
+ }
3508
3513
  var label = root.querySelector('.dk-component-select__label, .dk-component-input__label');
3509
3514
  var text = label ? (label.textContent || '').replace('*', '').trim()
3510
3515
  : (trigger.getAttribute('aria-label') || '').trim();
@@ -3707,6 +3712,10 @@
3707
3712
  if (isOpen())
3708
3713
  return;
3709
3714
  root.setAttribute('data-open', '');
3715
+ if (root.getAttribute('data-sheet-size') === 'tall')
3716
+ menu.setAttribute('data-sheet-size', 'tall');
3717
+ else
3718
+ menu.removeAttribute('data-sheet-size');
3710
3719
  session = dk.menu.open(menu, trigger, {
3711
3720
  root: root, placement: 'bottom', offset: 6,
3712
3721
  align: root.getAttribute('data-align') === 'end' ? 'end' : 'start',
@@ -4969,16 +4978,87 @@
4969
4978
  return 200;
4970
4979
  return /ms\s*$/.test(raw) ? n : n * 1000;
4971
4980
  }
4981
+ function settleMs(overlay) {
4982
+ var raw = '';
4983
+ try {
4984
+ raw = getComputedStyle(overlay).getPropertyValue('--dk-component-modal-settle-duration').trim();
4985
+ }
4986
+ catch (e) { }
4987
+ var n = parseFloat(raw);
4988
+ if (isNaN(n))
4989
+ return 200;
4990
+ return /ms\s*$/.test(raw) ? n : n * 1000;
4991
+ }
4972
4992
  function wantsSheet(overlay) {
4973
4993
  return dk.sheet.wants(overlay, '--dk-component-modal-sheet', overlay.getAttribute('data-sheet') || 'auto');
4974
4994
  }
4975
4995
  function stampSheet(overlay) {
4976
4996
  if (overlay.hasAttribute('data-closing'))
4977
4997
  return;
4998
+ var want = wantsSheet(overlay);
4999
+ if (want === overlay.hasAttribute('data-sheet-open'))
5000
+ return;
5001
+ var box = !overlay.hidden && overlay.querySelector('.dk-component-modal__box');
5002
+ var before = box && box.animate ? box.getBoundingClientRect() : null;
5003
+ var radius = before ? getComputedStyle(box).borderRadius : '';
4978
5004
  if (wantsSheet(overlay))
4979
5005
  overlay.setAttribute('data-sheet-open', '');
4980
5006
  else
4981
5007
  overlay.removeAttribute('data-sheet-open');
5008
+ if (before)
5009
+ morph(overlay, box, before, radius, want);
5010
+ }
5011
+ function releaseHeld(box) {
5012
+ if (!box || !box.__dcHeld)
5013
+ return;
5014
+ box.__dcHeld = false;
5015
+ box.style.animation = '';
5016
+ }
5017
+ function morph(overlay, box, before, radius, toSheet) {
5018
+ var ms = settleMs(overlay);
5019
+ if (!ms)
5020
+ return;
5021
+ if (box.__dcMorph) {
5022
+ try {
5023
+ box.__dcMorph.cancel();
5024
+ }
5025
+ catch (e) { }
5026
+ }
5027
+ box.style.animation = 'none';
5028
+ box.__dcHeld = true;
5029
+ var after = box.getBoundingClientRect();
5030
+ var dx = (before.left + before.width / 2) - (after.left + after.width / 2);
5031
+ var dy = toSheet ? before.bottom - after.bottom
5032
+ : (before.top + before.height / 2) - (after.top + after.height / 2);
5033
+ var cs = getComputedStyle(box);
5034
+ var easing = '';
5035
+ try {
5036
+ easing = getComputedStyle(overlay).getPropertyValue('--dk-component-modal-settle-easing').trim();
5037
+ }
5038
+ catch (e) { }
5039
+ try {
5040
+ box.__dcMorph = box.animate([
5041
+ { width: before.width + 'px', height: before.height + 'px', maxWidth: 'none', maxHeight: 'none',
5042
+ transform: 'translate(' + dx + 'px, ' + dy + 'px)', borderRadius: radius },
5043
+ { width: after.width + 'px', height: after.height + 'px', maxWidth: 'none', maxHeight: 'none',
5044
+ transform: 'translate(0px, 0px)', borderRadius: cs.borderRadius },
5045
+ ], { duration: ms, easing: easing || 'ease' });
5046
+ }
5047
+ catch (e) {
5048
+ return;
5049
+ }
5050
+ var m = box.__dcMorph;
5051
+ if (m && m.finished && m.finished.then)
5052
+ m.finished.then(function () { if (box.__dcMorph === m)
5053
+ box.__dcMorph = null; }, function () { });
5054
+ }
5055
+ function dragOff(overlay) {
5056
+ try {
5057
+ return getComputedStyle(overlay).getPropertyValue('--dk-component-modal-drag').trim() === '0';
5058
+ }
5059
+ catch (e) {
5060
+ return false;
5061
+ }
4982
5062
  }
4983
5063
  function focusables(box) {
4984
5064
  return Array.prototype.filter.call(box.querySelectorAll(FOCUSABLE), visible);
@@ -5054,6 +5134,11 @@
5054
5134
  };
5055
5135
  }
5056
5136
  var locks = opts.scrollLock !== false;
5137
+ var dragOn = opts.dismissible !== false && opts.dragDismiss !== false && !dragOff(overlay);
5138
+ if (dragOn)
5139
+ overlay.setAttribute('data-sheet-drag', '');
5140
+ else
5141
+ overlay.removeAttribute('data-sheet-drag');
5057
5142
  stampSheet(overlay);
5058
5143
  overlay.hidden = false;
5059
5144
  var inerted = markInert(overlay, container);
@@ -5138,7 +5223,118 @@
5138
5223
  if (onBackdrop && opts.backdropDismiss !== false)
5139
5224
  dismiss('backdrop');
5140
5225
  }
5226
+ var DRAG_DISTANCE = 0.3, DRAG_FLICK = 0.5, DRAG_RESIST = 5, DRAG_WINDOW = 100, DRAG_MIN = 8;
5227
+ var dragging = null, settleTimer = null;
5228
+ function now() { return (window.performance && performance.now) ? performance.now() : Date.now(); }
5229
+ function handle(t) {
5230
+ if (!dragOn || closed || !overlay.hasAttribute('data-sheet-open'))
5231
+ return false;
5232
+ if (t === box)
5233
+ return true;
5234
+ var head = t && t.closest && t.closest('.dk-component-modal__header');
5235
+ if (!head || !box.contains(head))
5236
+ return false;
5237
+ var control = t.closest('a, button, input, select, textarea, label, summary, [role="button"], [data-interactive], [contenteditable]');
5238
+ return !(control && head.contains(control));
5239
+ }
5240
+ function clearDrag() {
5241
+ if (settleTimer) {
5242
+ clearTimeout(settleTimer);
5243
+ settleTimer = null;
5244
+ }
5245
+ box.style.transform = '';
5246
+ box.style.paddingBottom = '';
5247
+ box.style.transition = '';
5248
+ if (bd) {
5249
+ bd.style.opacity = '';
5250
+ bd.style.transition = '';
5251
+ }
5252
+ }
5253
+ function settle() {
5254
+ var ms = settleMs(overlay);
5255
+ var how = ' var(--dk-component-modal-settle-duration) var(--dk-component-modal-settle-easing)';
5256
+ box.style.transition = 'transform' + how + ', padding-bottom' + how;
5257
+ if (bd)
5258
+ bd.style.transition = 'opacity' + how;
5259
+ box.style.transform = '';
5260
+ box.style.paddingBottom = '';
5261
+ if (bd)
5262
+ bd.style.opacity = '';
5263
+ settleTimer = setTimeout(function () { settleTimer = null; if (!closed)
5264
+ clearDrag(); }, ms);
5265
+ }
5266
+ function onDragMove(e) {
5267
+ if (!dragging)
5268
+ return;
5269
+ var raw = e.clientY - dragging.y0;
5270
+ var dy = raw >= 0 ? raw : raw / DRAG_RESIST;
5271
+ dragging.dy = dy;
5272
+ var t = now();
5273
+ dragging.samples.push([t, e.clientY]);
5274
+ while (dragging.samples.length > 2 && t - dragging.samples[0][0] > DRAG_WINDOW)
5275
+ dragging.samples.shift();
5276
+ box.style.transform = dy > 0 ? 'translateY(' + dy + 'px)' : '';
5277
+ box.style.paddingBottom = dy < 0 ? (-dy) + 'px' : '';
5278
+ if (bd)
5279
+ bd.style.opacity = String(Math.max(0, 1 - Math.max(0, dy) / dragging.h));
5280
+ if (e.cancelable)
5281
+ e.preventDefault();
5282
+ }
5283
+ function onDragEnd(e) {
5284
+ if (!dragging)
5285
+ return;
5286
+ document.removeEventListener('pointermove', onDragMove, true);
5287
+ document.removeEventListener('pointerup', onDragEnd, true);
5288
+ document.removeEventListener('pointercancel', onDragEnd, true);
5289
+ overlay.removeAttribute('data-dragging');
5290
+ var up = e && e.type === 'pointerup';
5291
+ if (up && typeof e.clientY === 'number')
5292
+ onDragMove(e);
5293
+ var g = dragging;
5294
+ dragging = null;
5295
+ var first = g.samples[0], last = g.samples[g.samples.length - 1];
5296
+ var speed = last[0] > first[0] ? (last[1] - first[1]) / (last[0] - first[0]) : 0;
5297
+ var go = up && g.dy > DRAG_MIN && (g.dy > g.h * DRAG_DISTANCE || speed > DRAG_FLICK);
5298
+ if (!go) {
5299
+ if (e)
5300
+ settle();
5301
+ return;
5302
+ }
5303
+ box.style.transition = '';
5304
+ if (bd)
5305
+ bd.style.transition = '';
5306
+ dismiss('drag');
5307
+ if (!closed)
5308
+ setTimeout(function () { if (!closed)
5309
+ settle(); }, DRAG_WINDOW);
5310
+ }
5311
+ function onDragStart(e) {
5312
+ if (dragging || (e.button && e.button !== 0) || !handle(e.target))
5313
+ return;
5314
+ if (settleTimer) {
5315
+ clearTimeout(settleTimer);
5316
+ settleTimer = null;
5317
+ }
5318
+ dragging = { y0: e.clientY, dy: 0, h: box.offsetHeight || 1, samples: [[now(), e.clientY]] };
5319
+ box.style.transition = 'none';
5320
+ if (bd)
5321
+ bd.style.transition = 'none';
5322
+ overlay.setAttribute('data-dragging', '');
5323
+ try {
5324
+ if (e.pointerId != null && box.setPointerCapture)
5325
+ box.setPointerCapture(e.pointerId);
5326
+ }
5327
+ catch (err) { }
5328
+ document.addEventListener('pointermove', onDragMove, true);
5329
+ document.addEventListener('pointerup', onDragEnd, true);
5330
+ document.addEventListener('pointercancel', onDragEnd, true);
5331
+ }
5141
5332
  function teardown() {
5333
+ if (dragging)
5334
+ onDragEnd(null);
5335
+ overlay.removeEventListener('pointerdown', onDragStart);
5336
+ clearDrag();
5337
+ overlay.removeAttribute('data-sheet-drag');
5142
5338
  if (orphanWatch) {
5143
5339
  orphanWatch.disconnect();
5144
5340
  orphanWatch = null;
@@ -5182,6 +5378,7 @@
5182
5378
  swapApply = apply;
5183
5379
  if (swapTimer)
5184
5380
  return;
5381
+ releaseHeld(box);
5185
5382
  overlay.setAttribute('data-swapping', '');
5186
5383
  function done() {
5187
5384
  swapTimer = null;
@@ -5205,6 +5402,8 @@
5205
5402
  }
5206
5403
  function closeIt(how) {
5207
5404
  endSwap();
5405
+ if (!closed)
5406
+ releaseHeld(box);
5208
5407
  if (closed) {
5209
5408
  if (how && how.immediate && exitTimer) {
5210
5409
  clearTimeout(exitTimer);
@@ -5242,6 +5441,7 @@
5242
5441
  document.addEventListener('keydown', onKey, true);
5243
5442
  document.addEventListener('focusin', onFocusIn, true);
5244
5443
  overlay.addEventListener('click', onClick);
5444
+ overlay.addEventListener('pointerdown', onDragStart);
5245
5445
  var orphanWatch = null;
5246
5446
  if (window.MutationObserver) {
5247
5447
  orphanWatch = new MutationObserver(function () {
@@ -5258,6 +5458,7 @@
5258
5458
  if (!overlay || overlay.__dcClosing || !overlay.isConnected)
5259
5459
  return;
5260
5460
  overlay.__dcClosing = true;
5461
+ releaseHeld(overlay.querySelector('.dk-component-modal__box'));
5261
5462
  var wait = exitMs(overlay);
5262
5463
  overlay.setAttribute('data-closing', '');
5263
5464
  setTimeout(function () { overlay.remove(); if (onDone)
@@ -5794,7 +5995,7 @@
5794
5995
  function create(root, track) {
5795
5996
  var pulls = new WeakMap();
5796
5997
  var pres = null, loop = false, made = [], current = -1, lastReal = [];
5797
- var scroller = null;
5998
+ var scroller = null, padL = 0;
5798
5999
  var down = false, active = false, settling = false, dragged = false, startX = 0, startScroll = 0;
5799
6000
  var raf = 0, quietT = 0, settleT = 0, dragT = 0;
5800
6001
  function cards() { return itemsOf(track).filter(function (it) { return !it.hidden; }); }
@@ -5804,6 +6005,7 @@
5804
6005
  return (r.left + r.width / 2 - track.getBoundingClientRect().left) / zoomOf(track) + track.scrollLeft - (pulls.get(card) || 0);
5805
6006
  }
5806
6007
  function startOf(card) { return cardMid(card) - card.offsetWidth / 2; }
6008
+ function restOf(card) { return startOf(card) - padL; }
5807
6009
  function edges() {
5808
6010
  var prev = root.querySelector(':scope > .' + P + '__prev');
5809
6011
  var next = root.querySelector(':scope > .' + P + '__next');
@@ -5842,6 +6044,7 @@
5842
6044
  }
5843
6045
  function bleed() {
5844
6046
  if (!root.hasAttribute('data-bleed')) {
6047
+ padL = 0;
5845
6048
  root.style.removeProperty('--_bleed-l');
5846
6049
  root.style.removeProperty('--_bleed-r');
5847
6050
  return;
@@ -5849,7 +6052,8 @@
5849
6052
  var z = zoomOf(track);
5850
6053
  var b = edgeOf();
5851
6054
  var w = root.getBoundingClientRect();
5852
- root.style.setProperty('--_bleed-l', Math.max(0, (w.left - b.left) / z) + 'px');
6055
+ padL = Math.max(0, (w.left - b.left) / z);
6056
+ root.style.setProperty('--_bleed-l', padL + 'px');
5853
6057
  root.style.setProperty('--_bleed-r', Math.max(0, (b.right - w.right) / z) + 'px');
5854
6058
  }
5855
6059
  function realIndex(i, list) {
@@ -5865,7 +6069,7 @@
5865
6069
  var mid = track.scrollLeft + track.clientWidth / 2;
5866
6070
  var best = 0, bd = Infinity;
5867
6071
  list.forEach(function (card, i) {
5868
- var d = pres === 'row' ? Math.abs(track.scrollLeft - startOf(card)) : Math.abs(mid - cardMid(card));
6072
+ var d = pres === 'row' ? Math.abs(track.scrollLeft - restOf(card)) : Math.abs(mid - cardMid(card));
5869
6073
  if (d < bd) {
5870
6074
  bd = d;
5871
6075
  best = i;
@@ -6059,7 +6263,7 @@
6059
6263
  var mid = track.scrollLeft + track.clientWidth / 2;
6060
6264
  var best = null, bd = Infinity;
6061
6265
  cards().forEach(function (card) {
6062
- var d = pres === 'row' ? Math.abs(track.scrollLeft - startOf(card)) : Math.abs(mid - cardMid(card));
6266
+ var d = pres === 'row' ? Math.abs(track.scrollLeft - restOf(card)) : Math.abs(mid - cardMid(card));
6063
6267
  if (d < bd) {
6064
6268
  bd = d;
6065
6269
  best = card;
@@ -6067,7 +6271,7 @@
6067
6271
  });
6068
6272
  settling = true;
6069
6273
  if (best)
6070
- track.scrollTo({ left: pres === 'row' ? startOf(best) : cardMid(best) - track.clientWidth / 2, behavior: smooth() });
6274
+ track.scrollTo({ left: pres === 'row' ? restOf(best) : cardMid(best) - track.clientWidth / 2, behavior: smooth() });
6071
6275
  settleT = setTimeout(onIdle, SETTLE);
6072
6276
  dragT = setTimeout(function () { dragged = false; }, 0);
6073
6277
  }
@@ -6121,6 +6325,7 @@
6121
6325
  hit = m !== orig || orig.matches(FOCUSABLE) ? m : orig.querySelector(FOCUSABLE) || orig;
6122
6326
  hit.click();
6123
6327
  }
6328
+ function onDragStart(e) { e.preventDefault(); }
6124
6329
  function onClick(e) {
6125
6330
  if (dragged) {
6126
6331
  e.preventDefault();
@@ -6153,6 +6358,7 @@
6153
6358
  on(track, 'pointerup', onUp);
6154
6359
  on(track, 'pointercancel', onUp);
6155
6360
  on(track, 'click', onClick, true);
6361
+ on(track, 'dragstart', onDragStart);
6156
6362
  on(root, 'click', onArrow);
6157
6363
  on(window, 'pointerup', onWinUp);
6158
6364
  on(window, 'pointercancel', onWinUp);
@@ -6183,6 +6389,37 @@
6183
6389
  }) : null;
6184
6390
  if (mo)
6185
6391
  mo.observe(root, { attributes: true, attributeFilter: ['data-presentation', 'data-presentation-fixed', 'data-device', 'data-loop', 'data-bleed'] });
6392
+ function arrowLook() {
6393
+ var given = root.getAttribute('data-arrow-look');
6394
+ if (given === 'solid' || given === 'raised-inverse')
6395
+ return given;
6396
+ var holder = root.closest('[data-theme]');
6397
+ return holder && holder.getAttribute('data-theme') === 'dark' ? 'raised-inverse' : 'solid';
6398
+ }
6399
+ function paintArrows() {
6400
+ var inverse = arrowLook() === 'raised-inverse';
6401
+ Array.prototype.forEach.call(root.children, function (b) {
6402
+ if (!b.classList.contains(P + '__prev') && !b.classList.contains(P + '__next'))
6403
+ return;
6404
+ var v = inverse ? 'raised' : 'solid';
6405
+ if (b.getAttribute('data-variant') !== v)
6406
+ b.setAttribute('data-variant', v);
6407
+ if (inverse && b.getAttribute('data-theme') !== 'light')
6408
+ b.setAttribute('data-theme', 'light');
6409
+ if (!inverse && b.hasAttribute('data-theme'))
6410
+ b.removeAttribute('data-theme');
6411
+ });
6412
+ }
6413
+ paintArrows();
6414
+ var themeMo = typeof MutationObserver !== 'undefined' ? new MutationObserver(function () {
6415
+ if (!root.isConnected) {
6416
+ teardown();
6417
+ return;
6418
+ }
6419
+ paintArrows();
6420
+ }) : null;
6421
+ if (themeMo)
6422
+ themeMo.observe(root.ownerDocument.documentElement, { attributes: true, subtree: true, attributeFilter: ['data-theme', 'data-arrow-look'] });
6186
6423
  function teardown() {
6187
6424
  bound.forEach(function (b) { b[0].removeEventListener(b[1], b[2], b[3]); });
6188
6425
  bound = [];
@@ -6190,6 +6427,8 @@
6190
6427
  ro.disconnect();
6191
6428
  if (mo)
6192
6429
  mo.disconnect();
6430
+ if (themeMo)
6431
+ themeMo.disconnect();
6193
6432
  if (unwatch)
6194
6433
  unwatch();
6195
6434
  if (raf)
@@ -9926,8 +10165,9 @@
9926
10165
  return qa(root, '.' + P + '__body .' + P + '__list:not([data-level="2"]) > li > .' + P + '__item');
9927
10166
  }
9928
10167
  function utilityRows() {
9929
- return foot ? qa(foot, '.' + P + '__list > li > .' + P + '__item').filter(function (i) { return !i.classList.contains(P + '__toggle'); }) : [];
10168
+ return foot ? qa(foot, '.' + P + '__list > li:not([data-rail-only]) > .' + P + '__item').filter(function (i) { return !i.classList.contains(P + '__toggle'); }) : [];
9930
10169
  }
10170
+ function railOnlyRows() { return foot ? qa(foot, '.' + P + '__list > li[data-rail-only]') : []; }
9931
10171
  function account() { return q(root, '.' + P + '__account'); }
9932
10172
  function railOnly(el) { return !el.closest('.' + P + '__panel'); }
9933
10173
  function decorate() {
@@ -10689,6 +10929,24 @@
10689
10929
  });
10690
10930
  });
10691
10931
  }
10932
+ function syncMark() {
10933
+ var logo = q(root, '.' + P + '__mark > .dk-component-logo');
10934
+ if (!logo || logo.getAttribute('data-rendered') === 'react')
10935
+ return;
10936
+ var own = logo.getAttribute('data-sb-lockup') || logo.getAttribute('data-lockup');
10937
+ if (own !== 'symbol-text')
10938
+ return;
10939
+ var want = isCollapsed() && isRail() ? 'symbol' : own;
10940
+ if (logo.getAttribute('data-lockup') === want)
10941
+ return;
10942
+ mute(function () {
10943
+ if (want === own)
10944
+ logo.removeAttribute('data-sb-lockup');
10945
+ else
10946
+ logo.setAttribute('data-sb-lockup', own);
10947
+ logo.setAttribute('data-lockup', want);
10948
+ });
10949
+ }
10692
10950
  function setCollapsed(on, fromUser) {
10693
10951
  if (on === isCollapsed())
10694
10952
  return;
@@ -10717,6 +10975,7 @@
10717
10975
  if (now && root.hasAttribute('data-rising'))
10718
10976
  mute(function () { root.removeAttribute('data-rising'); });
10719
10977
  wasCollapsed = now;
10978
+ syncMark();
10720
10979
  syncToggles();
10721
10980
  syncTips();
10722
10981
  syncGroups();
@@ -10771,6 +11030,7 @@
10771
11030
  var shown = needMore ? kept.slice(0, Math.max(room - 1, 0)) : kept;
10772
11031
  var rest = all.filter(function (r) { return shown.indexOf(r) === -1; });
10773
11032
  rest.forEach(function (r) { r.closest('li').setAttribute('data-bar-hidden', ''); });
11033
+ railOnlyRows().forEach(function (li) { li.setAttribute('data-bar-hidden', ''); });
10774
11034
  moreRows = needMore ? rest.concat(utils) : [];
10775
11035
  ensureMore();
10776
11036
  if (!more)
@@ -10993,6 +11253,7 @@
10993
11253
  clearance();
10994
11254
  syncGroups();
10995
11255
  syncPanel();
11256
+ syncMark();
10996
11257
  syncToggles();
10997
11258
  syncTips();
10998
11259
  paint(!changed && ready);