@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/README.md CHANGED
@@ -336,7 +336,7 @@ select.optionRenderer = (item, index) => {
336
336
 
337
337
  ### Active state on custom option roots
338
338
 
339
- For custom-rendered options, `classMap.active` names the class or classes applied to the active option root. 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.
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
340
 
341
341
  ```typescript
342
342
  select.classMap = { active: 'is-active keyboard-focus' };
@@ -389,6 +389,29 @@ const selectedItems = select.getSelectedItems();
389
389
 
390
390
  ## Advanced Usage
391
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
+
392
415
  ### Custom Styling
393
416
 
394
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
@@ -4137,6 +4137,22 @@ class EnhancedSelect extends HTMLElement {
4137
4137
  this._renderCycleWaiterTimeouts = new Map();
4138
4138
  this._suppressNextOpenClick = false;
4139
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
+ };
4140
4156
  this._multiScrollDrag = {
4141
4157
  active: false,
4142
4158
  moved: false,
@@ -4298,6 +4314,11 @@ class EnhancedSelect extends HTMLElement {
4298
4314
  this._state.isSearching = false;
4299
4315
  this._state.preserveScrollPosition = false;
4300
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');
4301
4322
  // unregister instance
4302
4323
  EnhancedSelect._instances.delete(this);
4303
4324
  if (this._state.isOpen) {
@@ -5651,6 +5672,12 @@ class EnhancedSelect extends HTMLElement {
5651
5672
  --select-dropdown-top: calc(100% + 6px);
5652
5673
  --select-dropdown-bottom: calc(100% + 6px);
5653
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);
5654
5681
  --select-dropdown-enter-from-opacity: 0;
5655
5682
  --select-dropdown-enter-from-transform: translateY(-8px) scale(0.98);
5656
5683
  --select-dropdown-enter-to-opacity: 1;
@@ -6353,8 +6380,26 @@ class EnhancedSelect extends HTMLElement {
6353
6380
 
6354
6381
  .select-dropdown[data-placement="top"] {
6355
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));
6356
6384
  }
6357
-
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
+
6358
6403
  @keyframes dropdownEnter {
6359
6404
  0% {
6360
6405
  opacity: var(--select-dropdown-enter-from-opacity);
@@ -7360,6 +7405,10 @@ class EnhancedSelect extends HTMLElement {
7360
7405
  if (!effects.some((effect) => effect.type === 'POPUP_OPENED'))
7361
7406
  return;
7362
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');
7363
7412
  this._markOpenStart();
7364
7413
  this.setAttribute('data-open', 'true');
7365
7414
  this._liftStackingAncestors();
@@ -7396,14 +7445,78 @@ class EnhancedSelect extends HTMLElement {
7396
7445
  return;
7397
7446
  this.removeAttribute('data-open');
7398
7447
  this._restoreLiftedAncestors();
7399
- this._dropdown.style.display = 'none';
7400
7448
  this._dropdown.setAttribute('data-placement', this._resolvedDropdownPlacement);
7401
7449
  this._updateArrowRotation();
7450
+ // Engine + ARIA close immediately. Only the visual panel waits for exit.
7402
7451
  this._runEngineEffects(effects);
7452
+ this._beginDropdownExit(reason === 'disconnect' || !this.isConnected);
7403
7453
  this._emit('close', {});
7404
7454
  this._config.callbacks.onClose?.();
7405
7455
  this._announce('Options collapsed');
7406
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
+ }
7407
7520
  _updateDropdownVisibility() {
7408
7521
  if (this._state.isOpen) {
7409
7522
  this.setAttribute('data-open', 'true');