@karmo-co/drift-kit-public 24.0.0 → 24.1.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
@@ -4969,16 +4969,87 @@
4969
4969
  return 200;
4970
4970
  return /ms\s*$/.test(raw) ? n : n * 1000;
4971
4971
  }
4972
+ function settleMs(overlay) {
4973
+ var raw = '';
4974
+ try {
4975
+ raw = getComputedStyle(overlay).getPropertyValue('--dk-component-modal-settle-duration').trim();
4976
+ }
4977
+ catch (e) { }
4978
+ var n = parseFloat(raw);
4979
+ if (isNaN(n))
4980
+ return 200;
4981
+ return /ms\s*$/.test(raw) ? n : n * 1000;
4982
+ }
4972
4983
  function wantsSheet(overlay) {
4973
4984
  return dk.sheet.wants(overlay, '--dk-component-modal-sheet', overlay.getAttribute('data-sheet') || 'auto');
4974
4985
  }
4975
4986
  function stampSheet(overlay) {
4976
4987
  if (overlay.hasAttribute('data-closing'))
4977
4988
  return;
4989
+ var want = wantsSheet(overlay);
4990
+ if (want === overlay.hasAttribute('data-sheet-open'))
4991
+ return;
4992
+ var box = !overlay.hidden && overlay.querySelector('.dk-component-modal__box');
4993
+ var before = box && box.animate ? box.getBoundingClientRect() : null;
4994
+ var radius = before ? getComputedStyle(box).borderRadius : '';
4978
4995
  if (wantsSheet(overlay))
4979
4996
  overlay.setAttribute('data-sheet-open', '');
4980
4997
  else
4981
4998
  overlay.removeAttribute('data-sheet-open');
4999
+ if (before)
5000
+ morph(overlay, box, before, radius, want);
5001
+ }
5002
+ function releaseHeld(box) {
5003
+ if (!box || !box.__dcHeld)
5004
+ return;
5005
+ box.__dcHeld = false;
5006
+ box.style.animation = '';
5007
+ }
5008
+ function morph(overlay, box, before, radius, toSheet) {
5009
+ var ms = settleMs(overlay);
5010
+ if (!ms)
5011
+ return;
5012
+ if (box.__dcMorph) {
5013
+ try {
5014
+ box.__dcMorph.cancel();
5015
+ }
5016
+ catch (e) { }
5017
+ }
5018
+ box.style.animation = 'none';
5019
+ box.__dcHeld = true;
5020
+ var after = box.getBoundingClientRect();
5021
+ var dx = (before.left + before.width / 2) - (after.left + after.width / 2);
5022
+ var dy = toSheet ? before.bottom - after.bottom
5023
+ : (before.top + before.height / 2) - (after.top + after.height / 2);
5024
+ var cs = getComputedStyle(box);
5025
+ var easing = '';
5026
+ try {
5027
+ easing = getComputedStyle(overlay).getPropertyValue('--dk-component-modal-settle-easing').trim();
5028
+ }
5029
+ catch (e) { }
5030
+ try {
5031
+ box.__dcMorph = box.animate([
5032
+ { width: before.width + 'px', height: before.height + 'px', maxWidth: 'none', maxHeight: 'none',
5033
+ transform: 'translate(' + dx + 'px, ' + dy + 'px)', borderRadius: radius },
5034
+ { width: after.width + 'px', height: after.height + 'px', maxWidth: 'none', maxHeight: 'none',
5035
+ transform: 'translate(0px, 0px)', borderRadius: cs.borderRadius },
5036
+ ], { duration: ms, easing: easing || 'ease' });
5037
+ }
5038
+ catch (e) {
5039
+ return;
5040
+ }
5041
+ var m = box.__dcMorph;
5042
+ if (m && m.finished && m.finished.then)
5043
+ m.finished.then(function () { if (box.__dcMorph === m)
5044
+ box.__dcMorph = null; }, function () { });
5045
+ }
5046
+ function dragOff(overlay) {
5047
+ try {
5048
+ return getComputedStyle(overlay).getPropertyValue('--dk-component-modal-drag').trim() === '0';
5049
+ }
5050
+ catch (e) {
5051
+ return false;
5052
+ }
4982
5053
  }
4983
5054
  function focusables(box) {
4984
5055
  return Array.prototype.filter.call(box.querySelectorAll(FOCUSABLE), visible);
@@ -5054,6 +5125,11 @@
5054
5125
  };
5055
5126
  }
5056
5127
  var locks = opts.scrollLock !== false;
5128
+ var dragOn = opts.dismissible !== false && opts.dragDismiss !== false && !dragOff(overlay);
5129
+ if (dragOn)
5130
+ overlay.setAttribute('data-sheet-drag', '');
5131
+ else
5132
+ overlay.removeAttribute('data-sheet-drag');
5057
5133
  stampSheet(overlay);
5058
5134
  overlay.hidden = false;
5059
5135
  var inerted = markInert(overlay, container);
@@ -5138,7 +5214,118 @@
5138
5214
  if (onBackdrop && opts.backdropDismiss !== false)
5139
5215
  dismiss('backdrop');
5140
5216
  }
5217
+ var DRAG_DISTANCE = 0.3, DRAG_FLICK = 0.5, DRAG_RESIST = 5, DRAG_WINDOW = 100, DRAG_MIN = 8;
5218
+ var dragging = null, settleTimer = null;
5219
+ function now() { return (window.performance && performance.now) ? performance.now() : Date.now(); }
5220
+ function handle(t) {
5221
+ if (!dragOn || closed || !overlay.hasAttribute('data-sheet-open'))
5222
+ return false;
5223
+ if (t === box)
5224
+ return true;
5225
+ var head = t && t.closest && t.closest('.dk-component-modal__header');
5226
+ if (!head || !box.contains(head))
5227
+ return false;
5228
+ var control = t.closest('a, button, input, select, textarea, label, summary, [role="button"], [data-interactive], [contenteditable]');
5229
+ return !(control && head.contains(control));
5230
+ }
5231
+ function clearDrag() {
5232
+ if (settleTimer) {
5233
+ clearTimeout(settleTimer);
5234
+ settleTimer = null;
5235
+ }
5236
+ box.style.transform = '';
5237
+ box.style.paddingBottom = '';
5238
+ box.style.transition = '';
5239
+ if (bd) {
5240
+ bd.style.opacity = '';
5241
+ bd.style.transition = '';
5242
+ }
5243
+ }
5244
+ function settle() {
5245
+ var ms = settleMs(overlay);
5246
+ var how = ' var(--dk-component-modal-settle-duration) var(--dk-component-modal-settle-easing)';
5247
+ box.style.transition = 'transform' + how + ', padding-bottom' + how;
5248
+ if (bd)
5249
+ bd.style.transition = 'opacity' + how;
5250
+ box.style.transform = '';
5251
+ box.style.paddingBottom = '';
5252
+ if (bd)
5253
+ bd.style.opacity = '';
5254
+ settleTimer = setTimeout(function () { settleTimer = null; if (!closed)
5255
+ clearDrag(); }, ms);
5256
+ }
5257
+ function onDragMove(e) {
5258
+ if (!dragging)
5259
+ return;
5260
+ var raw = e.clientY - dragging.y0;
5261
+ var dy = raw >= 0 ? raw : raw / DRAG_RESIST;
5262
+ dragging.dy = dy;
5263
+ var t = now();
5264
+ dragging.samples.push([t, e.clientY]);
5265
+ while (dragging.samples.length > 2 && t - dragging.samples[0][0] > DRAG_WINDOW)
5266
+ dragging.samples.shift();
5267
+ box.style.transform = dy > 0 ? 'translateY(' + dy + 'px)' : '';
5268
+ box.style.paddingBottom = dy < 0 ? (-dy) + 'px' : '';
5269
+ if (bd)
5270
+ bd.style.opacity = String(Math.max(0, 1 - Math.max(0, dy) / dragging.h));
5271
+ if (e.cancelable)
5272
+ e.preventDefault();
5273
+ }
5274
+ function onDragEnd(e) {
5275
+ if (!dragging)
5276
+ return;
5277
+ document.removeEventListener('pointermove', onDragMove, true);
5278
+ document.removeEventListener('pointerup', onDragEnd, true);
5279
+ document.removeEventListener('pointercancel', onDragEnd, true);
5280
+ overlay.removeAttribute('data-dragging');
5281
+ var up = e && e.type === 'pointerup';
5282
+ if (up && typeof e.clientY === 'number')
5283
+ onDragMove(e);
5284
+ var g = dragging;
5285
+ dragging = null;
5286
+ var first = g.samples[0], last = g.samples[g.samples.length - 1];
5287
+ var speed = last[0] > first[0] ? (last[1] - first[1]) / (last[0] - first[0]) : 0;
5288
+ var go = up && g.dy > DRAG_MIN && (g.dy > g.h * DRAG_DISTANCE || speed > DRAG_FLICK);
5289
+ if (!go) {
5290
+ if (e)
5291
+ settle();
5292
+ return;
5293
+ }
5294
+ box.style.transition = '';
5295
+ if (bd)
5296
+ bd.style.transition = '';
5297
+ dismiss('drag');
5298
+ if (!closed)
5299
+ setTimeout(function () { if (!closed)
5300
+ settle(); }, DRAG_WINDOW);
5301
+ }
5302
+ function onDragStart(e) {
5303
+ if (dragging || (e.button && e.button !== 0) || !handle(e.target))
5304
+ return;
5305
+ if (settleTimer) {
5306
+ clearTimeout(settleTimer);
5307
+ settleTimer = null;
5308
+ }
5309
+ dragging = { y0: e.clientY, dy: 0, h: box.offsetHeight || 1, samples: [[now(), e.clientY]] };
5310
+ box.style.transition = 'none';
5311
+ if (bd)
5312
+ bd.style.transition = 'none';
5313
+ overlay.setAttribute('data-dragging', '');
5314
+ try {
5315
+ if (e.pointerId != null && box.setPointerCapture)
5316
+ box.setPointerCapture(e.pointerId);
5317
+ }
5318
+ catch (err) { }
5319
+ document.addEventListener('pointermove', onDragMove, true);
5320
+ document.addEventListener('pointerup', onDragEnd, true);
5321
+ document.addEventListener('pointercancel', onDragEnd, true);
5322
+ }
5141
5323
  function teardown() {
5324
+ if (dragging)
5325
+ onDragEnd(null);
5326
+ overlay.removeEventListener('pointerdown', onDragStart);
5327
+ clearDrag();
5328
+ overlay.removeAttribute('data-sheet-drag');
5142
5329
  if (orphanWatch) {
5143
5330
  orphanWatch.disconnect();
5144
5331
  orphanWatch = null;
@@ -5182,6 +5369,7 @@
5182
5369
  swapApply = apply;
5183
5370
  if (swapTimer)
5184
5371
  return;
5372
+ releaseHeld(box);
5185
5373
  overlay.setAttribute('data-swapping', '');
5186
5374
  function done() {
5187
5375
  swapTimer = null;
@@ -5205,6 +5393,8 @@
5205
5393
  }
5206
5394
  function closeIt(how) {
5207
5395
  endSwap();
5396
+ if (!closed)
5397
+ releaseHeld(box);
5208
5398
  if (closed) {
5209
5399
  if (how && how.immediate && exitTimer) {
5210
5400
  clearTimeout(exitTimer);
@@ -5242,6 +5432,7 @@
5242
5432
  document.addEventListener('keydown', onKey, true);
5243
5433
  document.addEventListener('focusin', onFocusIn, true);
5244
5434
  overlay.addEventListener('click', onClick);
5435
+ overlay.addEventListener('pointerdown', onDragStart);
5245
5436
  var orphanWatch = null;
5246
5437
  if (window.MutationObserver) {
5247
5438
  orphanWatch = new MutationObserver(function () {
@@ -5258,6 +5449,7 @@
5258
5449
  if (!overlay || overlay.__dcClosing || !overlay.isConnected)
5259
5450
  return;
5260
5451
  overlay.__dcClosing = true;
5452
+ releaseHeld(overlay.querySelector('.dk-component-modal__box'));
5261
5453
  var wait = exitMs(overlay);
5262
5454
  overlay.setAttribute('data-closing', '');
5263
5455
  setTimeout(function () { overlay.remove(); if (onDone)