# Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project follows Semantic Versioning.

## [Unreleased]

## [4.3.0] - 2026-11-13

### Added
- `alwaysSticky` option: the always-docked sticky player previously provided by `stickyOnLoad` (never shown inline, close button hides it for the pageview, forced muted, `plcmt=2`, pauses other in-view players). Takes precedence over `stickyOnLoad`.
- `alwaysSticky`, `stickyAdHoldMs` and `waitForConsent` options in the tag generator.
- `waitForConsent` option (default `true`): automatic ad requests wait until the visitor has answered the IAB TCF v2 consent banner. Not held when there is no CMP, GDPR does not apply (e.g. US traffic), or the CMP does not respond within 3 seconds; a click on the player requests ads right away.
- `stickyAdHoldMs` option (default `5000`): sticky players hold their first automatic ad request until the visitor interacts with the page or the page has been visible for this long, to stop quick bounces from producing non-viewable impressions.

### Changed
- `stickyOnLoad` now means "start sticky on load": the player docks on page load without a scroll trigger (unless its inline slot is in view), snaps back inline when the slot scrolls into view and docks again whenever it is out of view, even before playback starts. It autoplays muted (`vpmute=1`), sends `plcmt=2`, and pauses other in-view players while docked. With `muted: false`, sound turns on after the user's first interaction. The close button behaves like the mini player close.
- Sticky players (`stickyOnLoad` and `alwaysSticky`) only hold other in-view players paused while the sticky player is playing (or about to autoplay, so players can't start alongside it on page load). Manually pausing the sticky player releases the other players, and a user-started play on another stpdVideo player or `<video>` element now pauses the sticky player (as a manual pause) instead of being blocked.
- Migration: configs that relied on the 4.2.x always-docked `stickyOnLoad` behaviour should switch to `alwaysSticky: true`.

## [4.2.1] - 2026-11-11

### Fixed
- Players were created twice (duplicate player markup, `player.ima is not a function`) on pages where a site script dispatches an extra `load` event. Each player is now created only once, and a player whose config is pushed after the page has loaded is created immediately.

## [4.2.0] - 2026-11-10

### Added
- `stickyOnLoad` option for an always-on sticky player that docks on page load without a scroll trigger. Follows Google sticky player rules: `plcmt=2`, muted start (IMA sends `vpmute` from the actual mute state), and a close button that dismisses the player for the full pageview. While open, other in-view stpdVideo players and `<video>` elements are paused.
- `stickyOnLoad` option in the tag generator.

### Fixed
- Sample ad tags in README and test pages now use `https://`; `http://` tags are blocked by the IMA SDK as mixed content (AdError 1005), so no ads were served.
- Fixed the IMA ad surface breaking (ad video disappearing while audio kept playing) during fast up/down scrolling on mobile. Rapid mini-player size toggles flooded the IMA SDK with `resize()` calls; ad resizes are now coalesced into a single animation frame and skipped when the resolved dimensions and view mode are unchanged.
- Fixed mobile mini-player occasionally rendering off-screen during fast/momentum scrolling while the ad kept playing (audio-only, non-viewable impressions). Removed the conflicting centering `transform` on the mobile fixed mini-player and rebuilt positioning to set explicit, conflict-free style declarations that are fully cleared on each transition.
- Mini-player no longer tears down or visually "jumps" when the page loses focus (e.g. clicking into DevTools) while staying visible. It now stays anchored through a transient focus/visibility auto-pause and resumes playback automatically when the page is re-entered, provided playback was not manually paused. Focus/visibility pause gating itself is unchanged.

### Changed
- A closed mini-player now re-enables when the main content player resumes playback, matching the existing behavior for ad playback.
- Mini-player (and sticky player) width is clamped to a minimum of 256px (256x144 at 16:9) to meet the Google Ad Manager minimum for programmatic video.
- `vid_d` is now the real duration of the current video (including playlist items) on each ad request instead of a fixed `10000`, and is omitted when unknown. A `vid_d` already present in the ad tag is kept.

## [4.1.0] - 2026-06-16

### Added
- Configurable `adDisplayInitMinDelayMs` option to control minimum delay between ad display container initialization and ad requests.
- Configurable `enforceAdPlayEligibility` option to require muted playback or user activation before requesting ads.
- Dedicated user activation utility module and tests, including fallback handling for `keydown`, `mousedown`, `pointerdown`, `pointerup`, and `touchend` when native UserActivation API is unavailable.
- Configurable `viewabilityThreshold` option (0..1, clamped) for ad/player viewability checks.
- Ad pause/resume debug trace logs with explicit reason tags.
- Unit tests for playback visibility helpers and manual pause state transitions.
- Utility modules for ad playback controls, visibility math, and pause-state synchronization.

### Changed
- Switched IMA request flow to manual request mode so ad requests are centrally gated by viewability, page state, initialization state, policy eligibility, and init delay.
- Refactored activation and ad-request code paths in runtime logic to reduce duplication and keep behavior modular.
- Updated playback visibility helper tests to cover autoplay policy eligibility and ad-request gate decisions.
- Visibility gating now considers document visibility and focus in addition to viewport position.
- Auto-resume and queued autoplay behavior now respects manual pause intent.

### Fixed
- Prevented ad requests from firing before playback eligibility is met.
- Improved autoplay/ad-start consistency after first valid user interaction across desktop and mobile browser policy constraints.
- Prevented hidden or out-of-focus ad/content playback.
- Fixed ad auto-resume edge cases around mini-player close/reopen and manual ad pause.
- Improved consistency of ad volume synchronization with player state.

### Developer Experience
- Added `npm test` script for unit test execution.
- Pre-commit now runs formatting automatically, then builds bundles and runs tests.
- Pre-commit now stages regenerated `dist` bundle output automatically to avoid follow-up bundle-only commits.
- Pre-publish gate validates formatting (`format:check`), tests, and production build.
- Added AGENTS.md with project-specific contribution and workflow instructions.
- Changelog policy documented for append-only updates: do not rewrite previous version sections unless explicitly requested.
- npm package metadata now includes CHANGELOG.md while excluding AGENTS.md from publication.

