@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/README.md CHANGED
@@ -334,6 +334,16 @@ select.optionRenderer = (item, index) => {
334
334
 
335
335
  `optionRenderer` is the maintained `EnhancedSelect` API. The legacy `NativeSelectElement` has a separate compatibility surface; do not copy its `optionTemplate` examples into `enhanced-select` integrations.
336
336
 
337
+ ### Active state on custom option roots
338
+
339
+ For custom-rendered options, `classMap.active` names the class or classes applied to the active option root. This fixes [Issue #82](https://github.com/navidrezadoost/Smilodon/issues/82) in the Core source (merged prior to this release). Core removes its built-in active aliases and previously configured active classes when another option becomes active, when the option is rendered again, or when `classMap` changes. The active `data-sm-state` token is reconciled with those classes, so an inactive option does not retain stale active styling.
340
+
341
+ ```typescript
342
+ select.classMap = { active: 'is-active keyboard-focus' };
343
+ ```
344
+
345
+ Style the returned option root using the configured class. If the active class map changes, Core removes classes from the prior map before applying the current active state.
346
+
337
347
  ---
338
348
 
339
349
  ### Events
@@ -379,6 +389,29 @@ const selectedItems = select.getSelectedItems();
379
389
 
380
390
  ## Advanced Usage
381
391
 
392
+ ### Dropdown enter and exit animations (Core 1.12.0 release candidate)
393
+
394
+ The default entry animation uses `--select-dropdown-animation`. The new exit animation mirrors that control through `--select-dropdown-exit-animation`, defaulting to `dropdownExit 160ms cubic-bezier(0.4, 0, 1, 1) forwards`.
395
+
396
+ ```css
397
+ enhanced-select {
398
+ --select-dropdown-animation: dropdownEnter 250ms ease-out forwards;
399
+ --select-dropdown-exit-animation: dropdownExit 180ms ease-in forwards;
400
+ --select-dropdown-exit-to-transform: translateY(-10px) scale(0.98);
401
+ --select-dropdown-top-exit-to-transform: translateY(10px) scale(0.98);
402
+ }
403
+ enhanced-select.instant {
404
+ --select-dropdown-animation: none;
405
+ --select-dropdown-exit-animation: none;
406
+ }
407
+ ```
408
+
409
+ Opacity and starting transform can be adjusted using `--select-dropdown-exit-from-opacity`, `--select-dropdown-exit-to-opacity`, and `--select-dropdown-exit-from-transform`. Closing updates engine and ARIA immediately; the panel is inert and hidden from assistive technology while exiting. Reopening cancels the exit. Reduced-motion preferences are respected.
410
+
411
+ **Qualification:** merged and locally qualified on Chrome 156 (8/8 focused Core tests, 4/4 browser scenarios, 723 passed/7 skipped in the full suite, as reported for PR #86). The repository's pinned Playwright Chromium 147 run remains unverified. This README is packaged with Core; check the npm registry for the availability of the version you intend to install. See [implementation and qualification notes](../../docs/architecture/DROPDOWN-EXIT-ANIMATION.md).
412
+
413
+ For the related fixes, stable option-hover geometry shipped earlier in Core `1.11.0` ([Issue #77](https://github.com/navidrezadoost/Smilodon/issues/77)); custom active-class reconciliation is documented [above](#active-state-on-custom-option-roots) and is included in the `1.12.0` candidate. See the [release checklist](../../docs/releases/CORE-1.12.0-RELEASE.md) for exact package scope and publication status.
414
+
382
415
  ### Custom Styling
383
416
 
384
417
  Smilodon uses CSS custom properties (CSS variables) for easy theming and customization. The default theme is **light mode** with a clean white background.
package/dist/index.cjs CHANGED
@@ -4117,6 +4117,7 @@ class EnhancedSelect extends HTMLElement {
4117
4117
  this._pendingSearchRenderMark = false;
4118
4118
  this._rangeAnchorIndex = null;
4119
4119
  this._customOptionBoundElements = new WeakSet();
4120
+ this._customOptionManagedActiveClasses = new WeakMap();
4120
4121
  this._customOptionNormalizedIds = new WeakMap();
4121
4122
  this._customOptionNormalizedLabels = new WeakMap();
4122
4123
  this._mirrorGlobalStylesForCustomOptions = false;
@@ -4136,6 +4137,22 @@ class EnhancedSelect extends HTMLElement {
4136
4137
  this._renderCycleWaiterTimeouts = new Map();
4137
4138
  this._suppressNextOpenClick = false;
4138
4139
  this._resolvedDropdownPlacement = 'bottom';
4140
+ // Presentation only: the popup engine is already closed while the exit runs.
4141
+ this._dropdownExitTimer = null;
4142
+ this._onDropdownExitAnimationEnd = (event) => {
4143
+ if (event.target !== this._dropdown || this._state.isOpen)
4144
+ return;
4145
+ if (this._dropdown.getAttribute('data-motion') !== 'closing')
4146
+ return;
4147
+ // A composite consumer animation must finish all timelines, not just the first.
4148
+ const names = getComputedStyle(this._dropdown).animationName
4149
+ .split(',').map((name) => name.trim()).filter((name) => name && name !== 'none');
4150
+ if (names.length > 1)
4151
+ return; // bounded timeout waits for the longest timeline
4152
+ if (event.animationName && names[0] && event.animationName !== names[0])
4153
+ return;
4154
+ this._finishDropdownExit();
4155
+ };
4139
4156
  this._multiScrollDrag = {
4140
4157
  active: false,
4141
4158
  moved: false,
@@ -4297,6 +4314,11 @@ class EnhancedSelect extends HTMLElement {
4297
4314
  this._state.isSearching = false;
4298
4315
  this._state.preserveScrollPosition = false;
4299
4316
  }
4317
+ // A disconnected popup must not retain a visual exit or a live timer.
4318
+ this._cancelDropdownExit();
4319
+ this._dropdown.style.display = 'none';
4320
+ this._dropdown.setAttribute('inert', '');
4321
+ this._dropdown.setAttribute('aria-hidden', 'true');
4300
4322
  // unregister instance
4301
4323
  EnhancedSelect._instances.delete(this);
4302
4324
  if (this._state.isOpen) {
@@ -5650,6 +5672,12 @@ class EnhancedSelect extends HTMLElement {
5650
5672
  --select-dropdown-top: calc(100% + 6px);
5651
5673
  --select-dropdown-bottom: calc(100% + 6px);
5652
5674
  --select-dropdown-animation: dropdownEnter 200ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
5675
+ --select-dropdown-exit-animation: dropdownExit 160ms cubic-bezier(0.4, 0, 1, 1) forwards;
5676
+ --select-dropdown-exit-from-opacity: 1;
5677
+ --select-dropdown-exit-from-transform: translateY(0) scale(1);
5678
+ --select-dropdown-exit-to-opacity: 0;
5679
+ --select-dropdown-exit-to-transform: translateY(-8px) scale(0.98);
5680
+ --select-dropdown-top-exit-to-transform: translateY(8px) scale(0.98);
5653
5681
  --select-dropdown-enter-from-opacity: 0;
5654
5682
  --select-dropdown-enter-from-transform: translateY(-8px) scale(0.98);
5655
5683
  --select-dropdown-enter-to-opacity: 1;
@@ -6352,8 +6380,26 @@ class EnhancedSelect extends HTMLElement {
6352
6380
 
6353
6381
  .select-dropdown[data-placement="top"] {
6354
6382
  --select-dropdown-enter-from-transform: var(--select-dropdown-top-enter-from-transform, translateY(8px) scale(0.98));
6383
+ --select-dropdown-exit-to-transform: var(--select-dropdown-top-exit-to-transform, translateY(8px) scale(0.98));
6355
6384
  }
6356
-
6385
+
6386
+ /* A closed popup stays visually mounted for exit, but cannot be interacted with. */
6387
+ .select-dropdown[data-motion="closing"] {
6388
+ animation: var(--select-dropdown-exit-animation);
6389
+ pointer-events: none;
6390
+ }
6391
+
6392
+ @keyframes dropdownExit {
6393
+ from {
6394
+ opacity: var(--select-dropdown-exit-from-opacity);
6395
+ transform: var(--select-dropdown-exit-from-transform);
6396
+ }
6397
+ to {
6398
+ opacity: var(--select-dropdown-exit-to-opacity);
6399
+ transform: var(--select-dropdown-exit-to-transform);
6400
+ }
6401
+ }
6402
+
6357
6403
  @keyframes dropdownEnter {
6358
6404
  0% {
6359
6405
  opacity: var(--select-dropdown-enter-from-opacity);
@@ -7359,6 +7405,10 @@ class EnhancedSelect extends HTMLElement {
7359
7405
  if (!effects.some((effect) => effect.type === 'POPUP_OPENED'))
7360
7406
  return;
7361
7407
  this._runEngineEffects(effects);
7408
+ // Reopening during exit cancels the old finish callback and restores interactivity.
7409
+ this._cancelDropdownExit();
7410
+ this._dropdown.removeAttribute('inert');
7411
+ this._dropdown.removeAttribute('aria-hidden');
7362
7412
  this._markOpenStart();
7363
7413
  this.setAttribute('data-open', 'true');
7364
7414
  this._liftStackingAncestors();
@@ -7395,14 +7445,78 @@ class EnhancedSelect extends HTMLElement {
7395
7445
  return;
7396
7446
  this.removeAttribute('data-open');
7397
7447
  this._restoreLiftedAncestors();
7398
- this._dropdown.style.display = 'none';
7399
7448
  this._dropdown.setAttribute('data-placement', this._resolvedDropdownPlacement);
7400
7449
  this._updateArrowRotation();
7450
+ // Engine + ARIA close immediately. Only the visual panel waits for exit.
7401
7451
  this._runEngineEffects(effects);
7452
+ this._beginDropdownExit(reason === 'disconnect' || !this.isConnected);
7402
7453
  this._emit('close', {});
7403
7454
  this._config.callbacks.onClose?.();
7404
7455
  this._announce('Options collapsed');
7405
7456
  }
7457
+ /** Stop an outstanding exit before reopening, disconnecting or starting another one. */
7458
+ _cancelDropdownExit() {
7459
+ if (this._dropdownExitTimer !== null) {
7460
+ window.clearTimeout(this._dropdownExitTimer);
7461
+ this._dropdownExitTimer = null;
7462
+ }
7463
+ this._dropdown.removeEventListener('animationend', this._onDropdownExitAnimationEnd);
7464
+ this._dropdown.removeAttribute('data-motion');
7465
+ }
7466
+ _finishDropdownExit() {
7467
+ if (this._state.isOpen || this._dropdown.getAttribute('data-motion') !== 'closing')
7468
+ return;
7469
+ this._cancelDropdownExit();
7470
+ this._dropdown.style.display = 'none';
7471
+ }
7472
+ _beginDropdownExit(immediate) {
7473
+ this._cancelDropdownExit();
7474
+ // Inert + aria-hidden apply at logical close, not at animation completion.
7475
+ this._dropdown.setAttribute('inert', '');
7476
+ this._dropdown.setAttribute('aria-hidden', 'true');
7477
+ if (immediate || this._dropdown.style.display === 'none') {
7478
+ this._dropdown.style.display = 'none';
7479
+ return;
7480
+ }
7481
+ this._dropdown.setAttribute('data-motion', 'closing');
7482
+ const duration = this._getDropdownExitDurationMs();
7483
+ if (duration <= 0) {
7484
+ this._finishDropdownExit();
7485
+ return;
7486
+ }
7487
+ // animationend optimizes normal completion; timeout handles missing/cancelled events.
7488
+ this._dropdown.addEventListener('animationend', this._onDropdownExitAnimationEnd);
7489
+ this._dropdownExitTimer = window.setTimeout(() => this._finishDropdownExit(), duration + 34);
7490
+ }
7491
+ /** CSS animations may be disabled or customized by consumers; never wait forever. */
7492
+ _getDropdownExitDurationMs() {
7493
+ if (window.matchMedia?.('(prefers-reduced-motion: reduce)').matches)
7494
+ return 0;
7495
+ const style = getComputedStyle(this._dropdown);
7496
+ const names = style.animationName.split(',').map((value) => value.trim());
7497
+ if (!names.length || names.every((name) => !name || name === 'none'))
7498
+ return 0;
7499
+ const toMs = (value) => {
7500
+ const trimmed = value.trim();
7501
+ const parsed = Number.parseFloat(trimmed);
7502
+ if (!Number.isFinite(parsed))
7503
+ return 0;
7504
+ return trimmed.endsWith('ms') ? parsed : trimmed.endsWith('s') ? parsed * 1000 : 0;
7505
+ };
7506
+ const durations = style.animationDuration.split(',');
7507
+ const delays = style.animationDelay.split(',');
7508
+ const counts = style.animationIterationCount.split(',');
7509
+ const maximum = names.reduce((max, name, index) => {
7510
+ if (!name || name === 'none')
7511
+ return max;
7512
+ const duration = toMs(durations[index % durations.length] ?? '0s');
7513
+ const delay = toMs(delays[index % delays.length] ?? '0s');
7514
+ const count = Number.parseFloat(counts[index % counts.length] ?? '1');
7515
+ const iterations = Number.isFinite(count) ? Math.max(0, count) : 1;
7516
+ return Math.max(max, Math.max(0, duration * iterations + delay));
7517
+ }, 0);
7518
+ return Math.min(maximum, 10000);
7519
+ }
7406
7520
  _updateDropdownVisibility() {
7407
7521
  if (this._state.isOpen) {
7408
7522
  this.setAttribute('data-open', 'true');
@@ -7793,8 +7907,7 @@ class EnhancedSelect extends HTMLElement {
7793
7907
  prevOption.setActive(false);
7794
7908
  }
7795
7909
  else {
7796
- // Lightweight option - remove active class
7797
- prevOption.classList.remove('active', 'smilodon-option--active');
7910
+ this._syncCustomOptionActiveClasses(prevOption, false);
7798
7911
  }
7799
7912
  }
7800
7913
  }
@@ -7805,8 +7918,7 @@ class EnhancedSelect extends HTMLElement {
7805
7918
  option.setActive(true);
7806
7919
  }
7807
7920
  else {
7808
- // Lightweight option - add active class
7809
- option.classList.add('active', 'smilodon-option--active');
7921
+ this._syncCustomOptionActiveClasses(option, true);
7810
7922
  }
7811
7923
  if (typeof option.scrollIntoView === 'function') {
7812
7924
  // Don't scroll wildly when just opening with pre-selections
@@ -10301,6 +10413,26 @@ class EnhancedSelect extends HTMLElement {
10301
10413
  option.ensureRendered();
10302
10414
  }
10303
10415
  }
10416
+ /** Keep custom option active classes aligned with the engine, including previous class maps. */
10417
+ _syncCustomOptionActiveClasses(option, active) {
10418
+ const mapped = (this.classMap?.active ?? 'active sm-active').split(/\s+/).filter(Boolean);
10419
+ const styled = (this._config.styles.classNames?.activeOption ?? '').split(/\s+/).filter(Boolean);
10420
+ const current = [...new Set([...mapped, ...styled, 'smilodon-option--active'])];
10421
+ const previous = this._customOptionManagedActiveClasses.get(option) ?? [];
10422
+ option.classList.remove(...new Set([...previous, ...current, 'active', 'sm-active', 'smilodon-option--active']));
10423
+ if (active)
10424
+ option.classList.add(...current);
10425
+ this._customOptionManagedActiveClasses.set(option, current);
10426
+ const states = new Set((option.dataset.smState ?? '').split(/\s+/).filter(Boolean));
10427
+ if (active)
10428
+ states.add('active');
10429
+ else
10430
+ states.delete('active');
10431
+ if (states.size)
10432
+ option.dataset.smState = [...states].join(' ');
10433
+ else
10434
+ delete option.dataset.smState;
10435
+ }
10304
10436
  _normalizeCustomOptionElement(element, meta) {
10305
10437
  const optionEl = element instanceof HTMLElement ? element : document.createElement('div');
10306
10438
  // Add part attribute for styling
@@ -10322,7 +10454,6 @@ class EnhancedSelect extends HTMLElement {
10322
10454
  const isDisabledInteractive = isDisabled && (isDisabledSelectable || isDisabledHoverable);
10323
10455
  // Resolve classes from classMap or defaults
10324
10456
  const selectedClasses = (this.classMap?.selected ?? 'selected sm-selected').split(' ').filter(Boolean);
10325
- const activeClasses = (this.classMap?.active ?? 'active sm-active').split(' ').filter(Boolean);
10326
10457
  const disabledClasses = (this.classMap?.disabled ?? 'disabled sm-disabled').split(' ').filter(Boolean);
10327
10458
  if (isSelected) {
10328
10459
  optionEl.classList.add(...selectedClasses);
@@ -10338,20 +10469,7 @@ class EnhancedSelect extends HTMLElement {
10338
10469
  optionEl.classList.remove(...this._config.styles.classNames.selectedOption.split(' ').filter(Boolean));
10339
10470
  }
10340
10471
  }
10341
- if (isActive) {
10342
- optionEl.classList.add(...activeClasses);
10343
- optionEl.classList.add('smilodon-option--active');
10344
- if (this._config.styles.classNames?.activeOption) {
10345
- optionEl.classList.add(...this._config.styles.classNames.activeOption.split(' ').filter(Boolean));
10346
- }
10347
- }
10348
- else {
10349
- optionEl.classList.remove(...activeClasses);
10350
- optionEl.classList.remove('smilodon-option--active');
10351
- if (this._config.styles.classNames?.activeOption) {
10352
- optionEl.classList.remove(...this._config.styles.classNames.activeOption.split(' ').filter(Boolean));
10353
- }
10354
- }
10472
+ this._syncCustomOptionActiveClasses(optionEl, isActive);
10355
10473
  if (isDisabled) {
10356
10474
  optionEl.classList.add(...disabledClasses);
10357
10475
  optionEl.classList.add('smilodon-option--disabled');