@smilodon/core 1.11.1 → 1.12.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/index.umd.js CHANGED
@@ -4141,6 +4141,22 @@
4141
4141
  this._renderCycleWaiterTimeouts = new Map();
4142
4142
  this._suppressNextOpenClick = false;
4143
4143
  this._resolvedDropdownPlacement = 'bottom';
4144
+ // Presentation only: the popup engine is already closed while the exit runs.
4145
+ this._dropdownExitTimer = null;
4146
+ this._onDropdownExitAnimationEnd = (event) => {
4147
+ if (event.target !== this._dropdown || this._state.isOpen)
4148
+ return;
4149
+ if (this._dropdown.getAttribute('data-motion') !== 'closing')
4150
+ return;
4151
+ // A composite consumer animation must finish all timelines, not just the first.
4152
+ const names = getComputedStyle(this._dropdown).animationName
4153
+ .split(',').map((name) => name.trim()).filter((name) => name && name !== 'none');
4154
+ if (names.length > 1)
4155
+ return; // bounded timeout waits for the longest timeline
4156
+ if (event.animationName && names[0] && event.animationName !== names[0])
4157
+ return;
4158
+ this._finishDropdownExit();
4159
+ };
4144
4160
  this._multiScrollDrag = {
4145
4161
  active: false,
4146
4162
  moved: false,
@@ -4302,6 +4318,11 @@
4302
4318
  this._state.isSearching = false;
4303
4319
  this._state.preserveScrollPosition = false;
4304
4320
  }
4321
+ // A disconnected popup must not retain a visual exit or a live timer.
4322
+ this._cancelDropdownExit();
4323
+ this._dropdown.style.display = 'none';
4324
+ this._dropdown.setAttribute('inert', '');
4325
+ this._dropdown.setAttribute('aria-hidden', 'true');
4305
4326
  // unregister instance
4306
4327
  EnhancedSelect._instances.delete(this);
4307
4328
  if (this._state.isOpen) {
@@ -5655,6 +5676,12 @@
5655
5676
  --select-dropdown-top: calc(100% + 6px);
5656
5677
  --select-dropdown-bottom: calc(100% + 6px);
5657
5678
  --select-dropdown-animation: dropdownEnter 200ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
5679
+ --select-dropdown-exit-animation: dropdownExit 160ms cubic-bezier(0.4, 0, 1, 1) forwards;
5680
+ --select-dropdown-exit-from-opacity: 1;
5681
+ --select-dropdown-exit-from-transform: translateY(0) scale(1);
5682
+ --select-dropdown-exit-to-opacity: 0;
5683
+ --select-dropdown-exit-to-transform: translateY(-8px) scale(0.98);
5684
+ --select-dropdown-top-exit-to-transform: translateY(8px) scale(0.98);
5658
5685
  --select-dropdown-enter-from-opacity: 0;
5659
5686
  --select-dropdown-enter-from-transform: translateY(-8px) scale(0.98);
5660
5687
  --select-dropdown-enter-to-opacity: 1;
@@ -6357,8 +6384,26 @@
6357
6384
 
6358
6385
  .select-dropdown[data-placement="top"] {
6359
6386
  --select-dropdown-enter-from-transform: var(--select-dropdown-top-enter-from-transform, translateY(8px) scale(0.98));
6387
+ --select-dropdown-exit-to-transform: var(--select-dropdown-top-exit-to-transform, translateY(8px) scale(0.98));
6360
6388
  }
6361
-
6389
+
6390
+ /* A closed popup stays visually mounted for exit, but cannot be interacted with. */
6391
+ .select-dropdown[data-motion="closing"] {
6392
+ animation: var(--select-dropdown-exit-animation);
6393
+ pointer-events: none;
6394
+ }
6395
+
6396
+ @keyframes dropdownExit {
6397
+ from {
6398
+ opacity: var(--select-dropdown-exit-from-opacity);
6399
+ transform: var(--select-dropdown-exit-from-transform);
6400
+ }
6401
+ to {
6402
+ opacity: var(--select-dropdown-exit-to-opacity);
6403
+ transform: var(--select-dropdown-exit-to-transform);
6404
+ }
6405
+ }
6406
+
6362
6407
  @keyframes dropdownEnter {
6363
6408
  0% {
6364
6409
  opacity: var(--select-dropdown-enter-from-opacity);
@@ -7364,6 +7409,10 @@
7364
7409
  if (!effects.some((effect) => effect.type === 'POPUP_OPENED'))
7365
7410
  return;
7366
7411
  this._runEngineEffects(effects);
7412
+ // Reopening during exit cancels the old finish callback and restores interactivity.
7413
+ this._cancelDropdownExit();
7414
+ this._dropdown.removeAttribute('inert');
7415
+ this._dropdown.removeAttribute('aria-hidden');
7367
7416
  this._markOpenStart();
7368
7417
  this.setAttribute('data-open', 'true');
7369
7418
  this._liftStackingAncestors();
@@ -7400,14 +7449,78 @@
7400
7449
  return;
7401
7450
  this.removeAttribute('data-open');
7402
7451
  this._restoreLiftedAncestors();
7403
- this._dropdown.style.display = 'none';
7404
7452
  this._dropdown.setAttribute('data-placement', this._resolvedDropdownPlacement);
7405
7453
  this._updateArrowRotation();
7454
+ // Engine + ARIA close immediately. Only the visual panel waits for exit.
7406
7455
  this._runEngineEffects(effects);
7456
+ this._beginDropdownExit(reason === 'disconnect' || !this.isConnected);
7407
7457
  this._emit('close', {});
7408
7458
  this._config.callbacks.onClose?.();
7409
7459
  this._announce('Options collapsed');
7410
7460
  }
7461
+ /** Stop an outstanding exit before reopening, disconnecting or starting another one. */
7462
+ _cancelDropdownExit() {
7463
+ if (this._dropdownExitTimer !== null) {
7464
+ window.clearTimeout(this._dropdownExitTimer);
7465
+ this._dropdownExitTimer = null;
7466
+ }
7467
+ this._dropdown.removeEventListener('animationend', this._onDropdownExitAnimationEnd);
7468
+ this._dropdown.removeAttribute('data-motion');
7469
+ }
7470
+ _finishDropdownExit() {
7471
+ if (this._state.isOpen || this._dropdown.getAttribute('data-motion') !== 'closing')
7472
+ return;
7473
+ this._cancelDropdownExit();
7474
+ this._dropdown.style.display = 'none';
7475
+ }
7476
+ _beginDropdownExit(immediate) {
7477
+ this._cancelDropdownExit();
7478
+ // Inert + aria-hidden apply at logical close, not at animation completion.
7479
+ this._dropdown.setAttribute('inert', '');
7480
+ this._dropdown.setAttribute('aria-hidden', 'true');
7481
+ if (immediate || this._dropdown.style.display === 'none') {
7482
+ this._dropdown.style.display = 'none';
7483
+ return;
7484
+ }
7485
+ this._dropdown.setAttribute('data-motion', 'closing');
7486
+ const duration = this._getDropdownExitDurationMs();
7487
+ if (duration <= 0) {
7488
+ this._finishDropdownExit();
7489
+ return;
7490
+ }
7491
+ // animationend optimizes normal completion; timeout handles missing/cancelled events.
7492
+ this._dropdown.addEventListener('animationend', this._onDropdownExitAnimationEnd);
7493
+ this._dropdownExitTimer = window.setTimeout(() => this._finishDropdownExit(), duration + 34);
7494
+ }
7495
+ /** CSS animations may be disabled or customized by consumers; never wait forever. */
7496
+ _getDropdownExitDurationMs() {
7497
+ if (window.matchMedia?.('(prefers-reduced-motion: reduce)').matches)
7498
+ return 0;
7499
+ const style = getComputedStyle(this._dropdown);
7500
+ const names = style.animationName.split(',').map((value) => value.trim());
7501
+ if (!names.length || names.every((name) => !name || name === 'none'))
7502
+ return 0;
7503
+ const toMs = (value) => {
7504
+ const trimmed = value.trim();
7505
+ const parsed = Number.parseFloat(trimmed);
7506
+ if (!Number.isFinite(parsed))
7507
+ return 0;
7508
+ return trimmed.endsWith('ms') ? parsed : trimmed.endsWith('s') ? parsed * 1000 : 0;
7509
+ };
7510
+ const durations = style.animationDuration.split(',');
7511
+ const delays = style.animationDelay.split(',');
7512
+ const counts = style.animationIterationCount.split(',');
7513
+ const maximum = names.reduce((max, name, index) => {
7514
+ if (!name || name === 'none')
7515
+ return max;
7516
+ const duration = toMs(durations[index % durations.length] ?? '0s');
7517
+ const delay = toMs(delays[index % delays.length] ?? '0s');
7518
+ const count = Number.parseFloat(counts[index % counts.length] ?? '1');
7519
+ const iterations = Number.isFinite(count) ? Math.max(0, count) : 1;
7520
+ return Math.max(max, Math.max(0, duration * iterations + delay));
7521
+ }, 0);
7522
+ return Math.min(maximum, 10000);
7523
+ }
7411
7524
  _updateDropdownVisibility() {
7412
7525
  if (this._state.isOpen) {
7413
7526
  this.setAttribute('data-open', 'true');