@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.js CHANGED
@@ -4135,6 +4135,22 @@ class EnhancedSelect extends HTMLElement {
4135
4135
  this._renderCycleWaiterTimeouts = new Map();
4136
4136
  this._suppressNextOpenClick = false;
4137
4137
  this._resolvedDropdownPlacement = 'bottom';
4138
+ // Presentation only: the popup engine is already closed while the exit runs.
4139
+ this._dropdownExitTimer = null;
4140
+ this._onDropdownExitAnimationEnd = (event) => {
4141
+ if (event.target !== this._dropdown || this._state.isOpen)
4142
+ return;
4143
+ if (this._dropdown.getAttribute('data-motion') !== 'closing')
4144
+ return;
4145
+ // A composite consumer animation must finish all timelines, not just the first.
4146
+ const names = getComputedStyle(this._dropdown).animationName
4147
+ .split(',').map((name) => name.trim()).filter((name) => name && name !== 'none');
4148
+ if (names.length > 1)
4149
+ return; // bounded timeout waits for the longest timeline
4150
+ if (event.animationName && names[0] && event.animationName !== names[0])
4151
+ return;
4152
+ this._finishDropdownExit();
4153
+ };
4138
4154
  this._multiScrollDrag = {
4139
4155
  active: false,
4140
4156
  moved: false,
@@ -4296,6 +4312,11 @@ class EnhancedSelect extends HTMLElement {
4296
4312
  this._state.isSearching = false;
4297
4313
  this._state.preserveScrollPosition = false;
4298
4314
  }
4315
+ // A disconnected popup must not retain a visual exit or a live timer.
4316
+ this._cancelDropdownExit();
4317
+ this._dropdown.style.display = 'none';
4318
+ this._dropdown.setAttribute('inert', '');
4319
+ this._dropdown.setAttribute('aria-hidden', 'true');
4299
4320
  // unregister instance
4300
4321
  EnhancedSelect._instances.delete(this);
4301
4322
  if (this._state.isOpen) {
@@ -5649,6 +5670,12 @@ class EnhancedSelect extends HTMLElement {
5649
5670
  --select-dropdown-top: calc(100% + 6px);
5650
5671
  --select-dropdown-bottom: calc(100% + 6px);
5651
5672
  --select-dropdown-animation: dropdownEnter 200ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
5673
+ --select-dropdown-exit-animation: dropdownExit 160ms cubic-bezier(0.4, 0, 1, 1) forwards;
5674
+ --select-dropdown-exit-from-opacity: 1;
5675
+ --select-dropdown-exit-from-transform: translateY(0) scale(1);
5676
+ --select-dropdown-exit-to-opacity: 0;
5677
+ --select-dropdown-exit-to-transform: translateY(-8px) scale(0.98);
5678
+ --select-dropdown-top-exit-to-transform: translateY(8px) scale(0.98);
5652
5679
  --select-dropdown-enter-from-opacity: 0;
5653
5680
  --select-dropdown-enter-from-transform: translateY(-8px) scale(0.98);
5654
5681
  --select-dropdown-enter-to-opacity: 1;
@@ -6351,8 +6378,26 @@ class EnhancedSelect extends HTMLElement {
6351
6378
 
6352
6379
  .select-dropdown[data-placement="top"] {
6353
6380
  --select-dropdown-enter-from-transform: var(--select-dropdown-top-enter-from-transform, translateY(8px) scale(0.98));
6381
+ --select-dropdown-exit-to-transform: var(--select-dropdown-top-exit-to-transform, translateY(8px) scale(0.98));
6354
6382
  }
6355
-
6383
+
6384
+ /* A closed popup stays visually mounted for exit, but cannot be interacted with. */
6385
+ .select-dropdown[data-motion="closing"] {
6386
+ animation: var(--select-dropdown-exit-animation);
6387
+ pointer-events: none;
6388
+ }
6389
+
6390
+ @keyframes dropdownExit {
6391
+ from {
6392
+ opacity: var(--select-dropdown-exit-from-opacity);
6393
+ transform: var(--select-dropdown-exit-from-transform);
6394
+ }
6395
+ to {
6396
+ opacity: var(--select-dropdown-exit-to-opacity);
6397
+ transform: var(--select-dropdown-exit-to-transform);
6398
+ }
6399
+ }
6400
+
6356
6401
  @keyframes dropdownEnter {
6357
6402
  0% {
6358
6403
  opacity: var(--select-dropdown-enter-from-opacity);
@@ -7358,6 +7403,10 @@ class EnhancedSelect extends HTMLElement {
7358
7403
  if (!effects.some((effect) => effect.type === 'POPUP_OPENED'))
7359
7404
  return;
7360
7405
  this._runEngineEffects(effects);
7406
+ // Reopening during exit cancels the old finish callback and restores interactivity.
7407
+ this._cancelDropdownExit();
7408
+ this._dropdown.removeAttribute('inert');
7409
+ this._dropdown.removeAttribute('aria-hidden');
7361
7410
  this._markOpenStart();
7362
7411
  this.setAttribute('data-open', 'true');
7363
7412
  this._liftStackingAncestors();
@@ -7394,14 +7443,78 @@ class EnhancedSelect extends HTMLElement {
7394
7443
  return;
7395
7444
  this.removeAttribute('data-open');
7396
7445
  this._restoreLiftedAncestors();
7397
- this._dropdown.style.display = 'none';
7398
7446
  this._dropdown.setAttribute('data-placement', this._resolvedDropdownPlacement);
7399
7447
  this._updateArrowRotation();
7448
+ // Engine + ARIA close immediately. Only the visual panel waits for exit.
7400
7449
  this._runEngineEffects(effects);
7450
+ this._beginDropdownExit(reason === 'disconnect' || !this.isConnected);
7401
7451
  this._emit('close', {});
7402
7452
  this._config.callbacks.onClose?.();
7403
7453
  this._announce('Options collapsed');
7404
7454
  }
7455
+ /** Stop an outstanding exit before reopening, disconnecting or starting another one. */
7456
+ _cancelDropdownExit() {
7457
+ if (this._dropdownExitTimer !== null) {
7458
+ window.clearTimeout(this._dropdownExitTimer);
7459
+ this._dropdownExitTimer = null;
7460
+ }
7461
+ this._dropdown.removeEventListener('animationend', this._onDropdownExitAnimationEnd);
7462
+ this._dropdown.removeAttribute('data-motion');
7463
+ }
7464
+ _finishDropdownExit() {
7465
+ if (this._state.isOpen || this._dropdown.getAttribute('data-motion') !== 'closing')
7466
+ return;
7467
+ this._cancelDropdownExit();
7468
+ this._dropdown.style.display = 'none';
7469
+ }
7470
+ _beginDropdownExit(immediate) {
7471
+ this._cancelDropdownExit();
7472
+ // Inert + aria-hidden apply at logical close, not at animation completion.
7473
+ this._dropdown.setAttribute('inert', '');
7474
+ this._dropdown.setAttribute('aria-hidden', 'true');
7475
+ if (immediate || this._dropdown.style.display === 'none') {
7476
+ this._dropdown.style.display = 'none';
7477
+ return;
7478
+ }
7479
+ this._dropdown.setAttribute('data-motion', 'closing');
7480
+ const duration = this._getDropdownExitDurationMs();
7481
+ if (duration <= 0) {
7482
+ this._finishDropdownExit();
7483
+ return;
7484
+ }
7485
+ // animationend optimizes normal completion; timeout handles missing/cancelled events.
7486
+ this._dropdown.addEventListener('animationend', this._onDropdownExitAnimationEnd);
7487
+ this._dropdownExitTimer = window.setTimeout(() => this._finishDropdownExit(), duration + 34);
7488
+ }
7489
+ /** CSS animations may be disabled or customized by consumers; never wait forever. */
7490
+ _getDropdownExitDurationMs() {
7491
+ if (window.matchMedia?.('(prefers-reduced-motion: reduce)').matches)
7492
+ return 0;
7493
+ const style = getComputedStyle(this._dropdown);
7494
+ const names = style.animationName.split(',').map((value) => value.trim());
7495
+ if (!names.length || names.every((name) => !name || name === 'none'))
7496
+ return 0;
7497
+ const toMs = (value) => {
7498
+ const trimmed = value.trim();
7499
+ const parsed = Number.parseFloat(trimmed);
7500
+ if (!Number.isFinite(parsed))
7501
+ return 0;
7502
+ return trimmed.endsWith('ms') ? parsed : trimmed.endsWith('s') ? parsed * 1000 : 0;
7503
+ };
7504
+ const durations = style.animationDuration.split(',');
7505
+ const delays = style.animationDelay.split(',');
7506
+ const counts = style.animationIterationCount.split(',');
7507
+ const maximum = names.reduce((max, name, index) => {
7508
+ if (!name || name === 'none')
7509
+ return max;
7510
+ const duration = toMs(durations[index % durations.length] ?? '0s');
7511
+ const delay = toMs(delays[index % delays.length] ?? '0s');
7512
+ const count = Number.parseFloat(counts[index % counts.length] ?? '1');
7513
+ const iterations = Number.isFinite(count) ? Math.max(0, count) : 1;
7514
+ return Math.max(max, Math.max(0, duration * iterations + delay));
7515
+ }, 0);
7516
+ return Math.min(maximum, 10000);
7517
+ }
7405
7518
  _updateDropdownVisibility() {
7406
7519
  if (this._state.isOpen) {
7407
7520
  this.setAttribute('data-open', 'true');