@smilodon/core 1.11.0 → 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
@@ -4121,6 +4121,7 @@
4121
4121
  this._pendingSearchRenderMark = false;
4122
4122
  this._rangeAnchorIndex = null;
4123
4123
  this._customOptionBoundElements = new WeakSet();
4124
+ this._customOptionManagedActiveClasses = new WeakMap();
4124
4125
  this._customOptionNormalizedIds = new WeakMap();
4125
4126
  this._customOptionNormalizedLabels = new WeakMap();
4126
4127
  this._mirrorGlobalStylesForCustomOptions = false;
@@ -4140,6 +4141,22 @@
4140
4141
  this._renderCycleWaiterTimeouts = new Map();
4141
4142
  this._suppressNextOpenClick = false;
4142
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
+ };
4143
4160
  this._multiScrollDrag = {
4144
4161
  active: false,
4145
4162
  moved: false,
@@ -4301,6 +4318,11 @@
4301
4318
  this._state.isSearching = false;
4302
4319
  this._state.preserveScrollPosition = false;
4303
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');
4304
4326
  // unregister instance
4305
4327
  EnhancedSelect._instances.delete(this);
4306
4328
  if (this._state.isOpen) {
@@ -5654,6 +5676,12 @@
5654
5676
  --select-dropdown-top: calc(100% + 6px);
5655
5677
  --select-dropdown-bottom: calc(100% + 6px);
5656
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);
5657
5685
  --select-dropdown-enter-from-opacity: 0;
5658
5686
  --select-dropdown-enter-from-transform: translateY(-8px) scale(0.98);
5659
5687
  --select-dropdown-enter-to-opacity: 1;
@@ -6356,8 +6384,26 @@
6356
6384
 
6357
6385
  .select-dropdown[data-placement="top"] {
6358
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));
6359
6388
  }
6360
-
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
+
6361
6407
  @keyframes dropdownEnter {
6362
6408
  0% {
6363
6409
  opacity: var(--select-dropdown-enter-from-opacity);
@@ -7363,6 +7409,10 @@
7363
7409
  if (!effects.some((effect) => effect.type === 'POPUP_OPENED'))
7364
7410
  return;
7365
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');
7366
7416
  this._markOpenStart();
7367
7417
  this.setAttribute('data-open', 'true');
7368
7418
  this._liftStackingAncestors();
@@ -7399,14 +7449,78 @@
7399
7449
  return;
7400
7450
  this.removeAttribute('data-open');
7401
7451
  this._restoreLiftedAncestors();
7402
- this._dropdown.style.display = 'none';
7403
7452
  this._dropdown.setAttribute('data-placement', this._resolvedDropdownPlacement);
7404
7453
  this._updateArrowRotation();
7454
+ // Engine + ARIA close immediately. Only the visual panel waits for exit.
7405
7455
  this._runEngineEffects(effects);
7456
+ this._beginDropdownExit(reason === 'disconnect' || !this.isConnected);
7406
7457
  this._emit('close', {});
7407
7458
  this._config.callbacks.onClose?.();
7408
7459
  this._announce('Options collapsed');
7409
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
+ }
7410
7524
  _updateDropdownVisibility() {
7411
7525
  if (this._state.isOpen) {
7412
7526
  this.setAttribute('data-open', 'true');
@@ -7797,8 +7911,7 @@
7797
7911
  prevOption.setActive(false);
7798
7912
  }
7799
7913
  else {
7800
- // Lightweight option - remove active class
7801
- prevOption.classList.remove('active', 'smilodon-option--active');
7914
+ this._syncCustomOptionActiveClasses(prevOption, false);
7802
7915
  }
7803
7916
  }
7804
7917
  }
@@ -7809,8 +7922,7 @@
7809
7922
  option.setActive(true);
7810
7923
  }
7811
7924
  else {
7812
- // Lightweight option - add active class
7813
- option.classList.add('active', 'smilodon-option--active');
7925
+ this._syncCustomOptionActiveClasses(option, true);
7814
7926
  }
7815
7927
  if (typeof option.scrollIntoView === 'function') {
7816
7928
  // Don't scroll wildly when just opening with pre-selections
@@ -10305,6 +10417,26 @@
10305
10417
  option.ensureRendered();
10306
10418
  }
10307
10419
  }
10420
+ /** Keep custom option active classes aligned with the engine, including previous class maps. */
10421
+ _syncCustomOptionActiveClasses(option, active) {
10422
+ const mapped = (this.classMap?.active ?? 'active sm-active').split(/\s+/).filter(Boolean);
10423
+ const styled = (this._config.styles.classNames?.activeOption ?? '').split(/\s+/).filter(Boolean);
10424
+ const current = [...new Set([...mapped, ...styled, 'smilodon-option--active'])];
10425
+ const previous = this._customOptionManagedActiveClasses.get(option) ?? [];
10426
+ option.classList.remove(...new Set([...previous, ...current, 'active', 'sm-active', 'smilodon-option--active']));
10427
+ if (active)
10428
+ option.classList.add(...current);
10429
+ this._customOptionManagedActiveClasses.set(option, current);
10430
+ const states = new Set((option.dataset.smState ?? '').split(/\s+/).filter(Boolean));
10431
+ if (active)
10432
+ states.add('active');
10433
+ else
10434
+ states.delete('active');
10435
+ if (states.size)
10436
+ option.dataset.smState = [...states].join(' ');
10437
+ else
10438
+ delete option.dataset.smState;
10439
+ }
10308
10440
  _normalizeCustomOptionElement(element, meta) {
10309
10441
  const optionEl = element instanceof HTMLElement ? element : document.createElement('div');
10310
10442
  // Add part attribute for styling
@@ -10326,7 +10458,6 @@
10326
10458
  const isDisabledInteractive = isDisabled && (isDisabledSelectable || isDisabledHoverable);
10327
10459
  // Resolve classes from classMap or defaults
10328
10460
  const selectedClasses = (this.classMap?.selected ?? 'selected sm-selected').split(' ').filter(Boolean);
10329
- const activeClasses = (this.classMap?.active ?? 'active sm-active').split(' ').filter(Boolean);
10330
10461
  const disabledClasses = (this.classMap?.disabled ?? 'disabled sm-disabled').split(' ').filter(Boolean);
10331
10462
  if (isSelected) {
10332
10463
  optionEl.classList.add(...selectedClasses);
@@ -10342,20 +10473,7 @@
10342
10473
  optionEl.classList.remove(...this._config.styles.classNames.selectedOption.split(' ').filter(Boolean));
10343
10474
  }
10344
10475
  }
10345
- if (isActive) {
10346
- optionEl.classList.add(...activeClasses);
10347
- optionEl.classList.add('smilodon-option--active');
10348
- if (this._config.styles.classNames?.activeOption) {
10349
- optionEl.classList.add(...this._config.styles.classNames.activeOption.split(' ').filter(Boolean));
10350
- }
10351
- }
10352
- else {
10353
- optionEl.classList.remove(...activeClasses);
10354
- optionEl.classList.remove('smilodon-option--active');
10355
- if (this._config.styles.classNames?.activeOption) {
10356
- optionEl.classList.remove(...this._config.styles.classNames.activeOption.split(' ').filter(Boolean));
10357
- }
10358
- }
10476
+ this._syncCustomOptionActiveClasses(optionEl, isActive);
10359
10477
  if (isDisabled) {
10360
10478
  optionEl.classList.add(...disabledClasses);
10361
10479
  optionEl.classList.add('smilodon-option--disabled');