/**
 * Theme Name: errigal
 * Theme URI: https://projecterrigal.com/themes/errigal/
 * Author: Project errigal
 * Author URI: https://projecterrigal.com/
 * Version: 1.2.1
 */
( function() {
	'use strict';

	const ATTRIBUTE_TABINDEX = 'tabIndex';
	const ATTRIBUTE_VALUE_MINUS_ONE = '-1';
	const NULL_VALUE = null;

	function isFunction( value ) {
		return value instanceof Function;
	}

	const INDEX_FIRST = 0;

	function isHTMLCollection( elements ) {
		return elements instanceof HTMLCollection;
	}

	function isObjectType( value, expectedType ) {
		return Object.prototype.toString.call( value ) ===
			`[object ${ expectedType }]`;
	}

	function isNumber( value ) {
		return (
			! isNaN( value ) &&
			isObjectType( value, 'Number' ) &&
			isFinite( value )
		);
	}

	function isPositiveNumber( value ) {
		return isNumber( value ) && value > 0;
	}

	function isIterable( items ) {
		return !! items && isPositiveNumber( items.length );
	}

	function isTrue( value ) {
		return value === true;
	}

	function forEach( items, callback ) {
		if ( ! isIterable( items ) || ! isFunction( callback ) ) {
			return false;
		}

		if ( isHTMLCollection( items ) ) {
			items = Array.prototype.slice.call( items );
		}

		for ( let i = INDEX_FIRST; i < items.length; i++ ) {
			if ( isTrue( callback( items[ i ], i, items ) ) ) {
				return true;
			}
		}

		return false;
	}

	function hasClassList( element ) {
		return (
			!! element &&
			element.classList instanceof DOMTokenList &&
			isFunction( element.classList.contains )
		);
	}

	function isHTMLElement( element, ...classNames ) {
		if ( ! ( element instanceof HTMLElement ) ) {
			return false;
		}

		return (
			hasClassList( element ) &&
			! forEach(
				classNames,
				( className ) => ! element.classList.contains( className )
			)
		);
	}

	function getAttribute( element, name ) {
		return isHTMLElement( element ) && isFunction( element.getAttribute )
			? element.getAttribute( name )
			: NULL_VALUE;
	}

	function hasNegativeTabIndex( element ) {
		return getAttribute( element, ATTRIBUTE_TABINDEX ) ===
			ATTRIBUTE_VALUE_MINUS_ONE;
	}

	function removeAttribute( element, ...names ) {
		if (
			! isHTMLElement( element ) ||
			! isFunction( element.removeAttribute )
		) {
			return;
		}

		forEach( names, ( name ) => element.removeAttribute( name ) );
	}

	function removeTabIndex( element ) {
		removeAttribute( element, ATTRIBUTE_TABINDEX );
	}

	const EVENT_FOCUSOUT = 'focusout';

	function isBoolean( value ) {
		return isObjectType( value, 'Boolean' );
	}

	const EMPTY_STRING = '';

	function isString( value ) {
		return isObjectType( value, 'String' );
	}

	function isNonEmptyString( value ) {
		return (
			isString( value ) &&
			isFunction( value.trim ) &&
			value.trim() !== EMPTY_STRING
		);
	}

	function isObject( value ) {
		return value instanceof Object;
	}

	function isUndefined( value ) {
		return isObjectType( value, 'Undefined' );
	}

	function onDocumentEvent( eventType, callback, options ) {
		if (
			! isNonEmptyString( eventType ) ||
			! isFunction( callback ) ||
			! ( isUndefined( options ) || isObject( options ) || isBoolean( options ) )
		) {
			return;
		}

		document.addEventListener( eventType, callback, options || false );
	}

	function onDocumentFocusout( callback, options ) {
		onDocumentEvent( EVENT_FOCUSOUT, callback, options );
	}

	function isEvent( value ) {
		return (
			value instanceof Event &&
			isFunction( value.preventDefault ) &&
			isFunction( value.stopPropagation )
		);
	}

	function addTabIndexEvents() {
		onDocumentFocusout( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if ( hasNegativeTabIndex( event.target ) ) {
				removeTabIndex( event.target );
			}
		} );
	}

	function addAccessibilityEvents() {
		addTabIndexEvents();
	}

	const CLASS_SHARED_ACTIVE = 'active';
	const TAG_LABEL = 'label';
	const NULL_ELEMENT = null;

	function getFirstItem( items ) {
		return isIterable( items )
			? items[ INDEX_FIRST ]
			: NULL_VALUE;
	}

	function isDocument( element ) {
		return element instanceof Document;
	}

	function isisHTMLElementOrDocument( element ) {
		return isHTMLElement( element ) || isDocument( element );
	}

	function callElementMethod(
		methodName,
		nameOrSelectors,
		rootElement
	) {
		return (
			isNonEmptyString( methodName ) &&
			isNonEmptyString( nameOrSelectors ) &&
			isisHTMLElementOrDocument( rootElement ) &&
			isFunction( rootElement[ methodName ] )
		)
			? rootElement[ methodName ]( nameOrSelectors )
			: NULL_ELEMENT;
	}

	function getElementsByTagName(
		tagName,
		rootElement = document
	) {
		const ELEMENTS =
			callElementMethod(
				'getElementsByTagName',
				tagName,
				rootElement
			);

		return isHTMLCollection( ELEMENTS )
			? ELEMENTS
			: NULL_ELEMENT;
	}

	function getElementByTagName(
		tagName,
		rootElement = document
	) {
		return getFirstItem( getElementsByTagName( tagName, rootElement ) );
	}

	function getParentElement( element ) {
		return isHTMLElement( element )
			? element.parentElement
			: NULL_ELEMENT;
	}

	const CLASS_COMPONENT_INPUT_FIELD = 'input-field';
	const TAG_INPUT = 'input';
	const TAG_TEXTAREA = 'textarea';
	const SELECTOR_COMPONENT_INPUT_FIELD_INPUT_OR_TEXTAREA = `.${ CLASS_COMPONENT_INPUT_FIELD } > ${ TAG_INPUT }, .${ CLASS_COMPONENT_INPUT_FIELD } > ${ TAG_TEXTAREA }`;

	function matches( element, selectors ) {
		if ( ! isHTMLElement( element ) || ! isNonEmptyString( selectors ) ) {
			return false;
		}

		if ( isFunction( element.matches ) ) {
			return isTrue( element.matches( selectors ) );
		}

		if ( isFunction( element.msMatchesSelector ) ) {
			return isTrue( element.msMatchesSelector( selectors ) );
		}

		return false;
	}

	function isInputField( element ) {
		return matches( element, SELECTOR_COMPONENT_INPUT_FIELD_INPUT_OR_TEXTAREA );
	}

	function isInputFieldContainer( element ) {
		return isHTMLElement( element, CLASS_COMPONENT_INPUT_FIELD );
	}

	function getInputFieldLabel( inputField ) {
		if ( ! isInputField( inputField ) ) {
			return NULL_ELEMENT;
		}

		const INPUT_FIELD_CONTAINER = getParentElement( inputField );

		return isInputFieldContainer( INPUT_FIELD_CONTAINER )
			? getElementByTagName( TAG_LABEL, INPUT_FIELD_CONTAINER )
			: NULL_ELEMENT;
	}

	function isNullOrEmpty( value ) {
		return ! value || value === EMPTY_STRING;
	}

	function isInputFieldEmpty( element ) {
		return isInputField( element ) && isNullOrEmpty( element.value );
	}

	function addClass( element, className ) {
		if (
			! isHTMLElement( element ) ||
			! hasClassList( element ) ||
			! isFunction( element.classList.add ) ||
			! isNonEmptyString( className )
		) {
			return;
		}

		element.classList.add( className );
	}

	function floatInputFieldLabel( inputField ) {
		addClass( getInputFieldLabel( inputField ), CLASS_SHARED_ACTIVE );
	}

	const SELECTOR_COMPONENT_INPUT_FIELD = `.${ CLASS_COMPONENT_INPUT_FIELD } > ${ TAG_INPUT }, .${ CLASS_COMPONENT_INPUT_FIELD } > ${ TAG_TEXTAREA }`;

	function isNodeList( element ) {
		return element instanceof NodeList;
	}

	function querySelectorAll( selectors, rootElement = document ) {
		const ELEMENTS =
			callElementMethod(
				'querySelectorAll',
				selectors,
				rootElement
			);

		return isNodeList( ELEMENTS )
			? ELEMENTS
			: NULL_ELEMENT;
	}

	function getInputFields() {
		return querySelectorAll( SELECTOR_COMPONENT_INPUT_FIELD );
	}

	function isInputFieldFilled( element ) {
		return isInputField( element ) && isNonEmptyString( element.value );
	}

	function initialiseFloatingInputFieldLabel( inputField ) {
		if ( isInputFieldFilled( inputField ) ) {
			floatInputFieldLabel( inputField );
		}
	}

	function initialiseFloatingInputFieldLabels() {
		forEach( getInputFields(), initialiseFloatingInputFieldLabel );
	}

	function removeClass( element, className ) {
		if (
			! isHTMLElement( element ) ||
			! hasClassList( element ) ||
			! isFunction( element.classList.remove ) ||
			! isNonEmptyString( className )
		) {
			return;
		}

		element.classList.remove( className );
	}

	const EVENT_FOCUSIN = 'focusin';

	function onDocumentFocusin( callback, options ) {
		onDocumentEvent( EVENT_FOCUSIN, callback, options );
	}

	const EVENT_LOAD = 'load';

	function onWindowEvent( eventType, callback, options ) {
		if (
			! isNonEmptyString( eventType ) ||
			! isFunction( callback ) ||
			! ( isUndefined( options ) || isObject( options ) || isBoolean( options ) )
		) {
			return;
		}

		window.addEventListener( eventType, callback, options || false );
	}

	function onWindowLoad( callback, options ) {
		onWindowEvent( EVENT_LOAD, callback, options );
	}

	function unfloatInputFieldLabel( inputField ) {
		removeClass( getInputFieldLabel( inputField ), CLASS_SHARED_ACTIVE );
	}

	function addInputFieldEvents() {
		onDocumentFocusin( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if ( isInputField( event.target ) ) {
				floatInputFieldLabel( event.target );
			}
		} );
		onDocumentFocusout( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if ( isInputFieldEmpty( event.target ) ) {
				unfloatInputFieldLabel( event.target );
			}
		} );
		onWindowLoad( initialiseFloatingInputFieldLabels );
	}

	function addComponentEvents() {
		addInputFieldEvents();
	}

	const CALLBACK_INITIAL_ATTEMPT_COUNT = 0;
	const CALLBACK_INTERVAL = 50;
	const CALLBACK_MAX_ATTEMPT_COUNT = 20;
	const SCROLL_DISTANCE_ZERO = 0;
	const CHARACTER_HASH = '#';
	const INDEX_SECOND = 1;

	function stringStartsWith( fullString, partialString ) {
		return (
			isNonEmptyString( fullString ) &&
			isNonEmptyString( partialString ) &&
			fullString.indexOf( partialString ) === INDEX_FIRST
		);
	}

	function getElementById( id, rootElement = document ) {
		return (
			isNonEmptyString( id ) &&
			callElementMethod(
				'getElementById',
				stringStartsWith( id, CHARACTER_HASH )
					? id.slice( INDEX_SECOND )
					: id,
				rootElement
			)
		);
	}

	function hasHash( element ) {
		return !! element && isNonEmptyString( element.hash );
	}

	function getLastItem( items ) {
		return isIterable( items )
			? items[ items.length - 1 ]
			: NULL_VALUE;
	}

	const EMPTY_ARRAY = [];

	function toChars( value ) {
		return isNonEmptyString( value )
			? value.split( '' )
			: EMPTY_ARRAY;
	}

	function isIe() {
		return !! window.MSInputMethodContext && !! document.documentMode;
	}

	function isLocationObject( obj ) {
		return (
			isIe() &&
			!! obj &&
			isString( obj.hash ) &&
			isFunction( obj.assign ) &&
			isFunction( obj.replace ) &&
			isFunction( obj.reload )
		);
	}

	function isLocation( element ) {
		return element instanceof Location || isLocationObject( element );
	}

	function removeTrailingSlash( url ) {
		return isNonEmptyString( url )
			? url.replace( /\/+$/, '' )
			: EMPTY_STRING;
	}

	function isEmptyHref( href ) {
		if ( ! isNonEmptyString( href ) || ! isLocation( window.location ) ) {
			return false;
		}

		const ORIGIN = window.location.origin;

		return (
			isNonEmptyString( ORIGIN ) &&
			removeTrailingSlash( href ) === removeTrailingSlash( ORIGIN )
		);
	}

	function hasHref( element ) {
		return (
			!! element &&
			isNonEmptyString( element.href ) &&
			! isEmptyHref( element.href )
		);
	}

	function hasEmptyAnchorLink( element ) {
		return (
			hasHref( element ) &&
			getLastItem( toChars( element.href ) ) === CHARACTER_HASH
		);
	}

	function hasSearch( element ) {
		return !! element && isNonEmptyString( element.search );
	}

	const TAG_A = 'a';

	function toLowerCase( value ) {
		return isNonEmptyString( value ) && isFunction( value.toLowerCase )
			? value.toLowerCase()
			: EMPTY_STRING;
	}

	function areStringsEqualIgnoreCase( str1, str2 ) {
		return toLowerCase( str1 ) === toLowerCase( str2 );
	}

	function hasTagName( element ) {
		return !! element && isNonEmptyString( element.tagName );
	}

	function isElementOfType( element, tagName ) {
		return (
			hasTagName( element ) &&
			isNonEmptyString( tagName ) &&
			areStringsEqualIgnoreCase( element.tagName, tagName )
		);
	}

	function isHTMLElementOfType(
		tagName,
		element,
		...classNames
	) {
		return (
			isHTMLElement( element, ...classNames ) &&
			isElementOfType( element, tagName )
		);
	}

	function isAnchorElement( element, ...classNames ) {
		return isHTMLElementOfType( TAG_A, element, ...classNames );
	}

	function hasValidUrlPart( elementUrlPart, locationUrlPart, element ) {
		if (
			! isString( elementUrlPart ) ||
			! isString( locationUrlPart ) ||
			! isAnchorElement( element )
		) {
			return false;
		}

		return elementUrlPart === locationUrlPart
			? true
			: (
				stringStartsWith( elementUrlPart, locationUrlPart ) &&
				!! getElementById( element.hash )
			);
	}

	function isInternalLink( element ) {
		return isAnchorElement( element ) && element.host === window.location.host;
	}

	function anchorDestinationElementExists( element ) {
		return hasHash( element ) && !! getElementById( element.hash );
	}

	function hasValidHash( element ) {
		return hasHash( element ) || hasEmptyAnchorLink( element );
	}

	function isAnchorElementOrLocationWithAnchorLink( element ) {
		if ( ! hasValidHash( element ) ) {
			return false;
		}

		if ( isLocation( element ) ) {
			return (
				hasEmptyAnchorLink( element ) ||
				anchorDestinationElementExists( element )
			);
		}

		if ( ! isInternalLink( element ) ) {
			return false;
		}

		return hasSearch( element )
			? hasValidUrlPart( element.search, window.location.search, element )
			: hasValidUrlPart( element.pathname, window.location.pathname, element );
	}

	function getAnchorDestinationElement( element ) {
		if ( ! isAnchorElementOrLocationWithAnchorLink( element ) ) {
			return NULL_ELEMENT;
		}

		return hasHash( element )
			? getElementById( element.hash )
			: document.documentElement;
	}

	const TAG_TIME = 'time';

	function isTimeElement( element, ...classNames ) {
		return isHTMLElementOfType( TAG_TIME, element, ...classNames );
	}

	function getAnchorElement( element ) {
		const ANCHOR_ELEMENT = isTimeElement( element )
			? getParentElement( element )
			: element;

		return isAnchorElement( ANCHOR_ELEMENT )
			? ANCHOR_ELEMENT
			: NULL_ELEMENT;
	}

	const CLASS_NAV_PAGE_NUMBERS = 'page-numbers';
	const SELECTOR_NAV_PAGINATION_NAV_LINK = `${ TAG_A }.${ CLASS_NAV_PAGE_NUMBERS }`;

	function isPaginationNavLink( element ) {
		return matches( element, SELECTOR_NAV_PAGINATION_NAV_LINK );
	}

	function isAnchorLink( element ) {
		const ANCHOR_ELEMENT = getAnchorElement( element );

		return (
			isAnchorElementOrLocationWithAnchorLink( ANCHOR_ELEMENT ) &&
			! isPaginationNavLink( ANCHOR_ELEMENT )
		);
	}

	function isKey( event, key, keyCode ) {
		return isEvent( event ) && isNonEmptyString( key ) && isNumber( keyCode )
			? areStringsEqualIgnoreCase( event.key, key ) ||
			event.keyCode === keyCode
			: false;
	}

	function isEnterKey( event ) {
		return isKey( event, 'Enter', 13 );
	}

	const EVENT_CLICK = 'click';

	function onDocumentClick( callback, options ) {
		onDocumentEvent( EVENT_CLICK, callback, options );
	}

	const EVENT_KEYDOWN = 'keydown';

	function onDocumentKeydown( callback, options ) {
		onDocumentEvent( EVENT_KEYDOWN, callback, options );
	}

	function getScrollTop() {
		return isIe()
			? window.pageYOffset
			: window.scrollY || document.documentElement.scrollTop;
	}

	const DISTANCE_REM_LG = 2;
	const POSITION_ZERO = 0;
	const RECT_TOP = 'top';
	const PIXEL_ZERO = 0;

	function getObjectValue( obj, key ) {
		return isObject( obj ) && ( key in obj )
			? obj[ key ]
			: NULL_VALUE;
	}

	function getRectProp( element, property ) {
		if (
			! isHTMLElement( element ) ||
			! isFunction( element.getBoundingClientRect )
		) {
			return PIXEL_ZERO;
		}

		const RECT_PROP =
			getObjectValue(
				element.getBoundingClientRect(),
				property
			);

		return isNumber( RECT_PROP )
			? RECT_PROP
			: PIXEL_ZERO;
	}

	function getViewportTop( element ) {
		return getRectProp( element, RECT_TOP );
	}

	function getPageTop( element ) {
		return getViewportTop( element ) + getScrollTop();
	}

	const CSS_FONT_SIZE = 'font-size';

	function getStyleProp( element, property ) {
		if ( ! isHTMLElement( element ) ) {
			return NULL_VALUE;
		}

		const STYLE_PROP =
			getObjectValue(
				window.getComputedStyle( element ),
				property
			);

		return isString( STYLE_PROP )
			? STYLE_PROP
			: NULL_VALUE;
	}

	function getStylePropFloat( element, property ) {
		const STYLE_PROP = parseFloat( getStyleProp( element, property ) );

		return isNumber( STYLE_PROP )
			? STYLE_PROP
			: PIXEL_ZERO;
	}

	function convertRemToPx( rem ) {
		return isNumber( rem )
			? getStylePropFloat( document.documentElement, CSS_FONT_SIZE ) * rem
			: PIXEL_ZERO;
	}

	const CLASS_SHARED_STICKY = 'sticky';
	const CLASS_SECTION_SITE_HEADER = 'site-header';

	function getElementsByClassName(
		className,
		rootElement = document
	) {
		const ELEMENTS =
			callElementMethod(
				'getElementsByClassName',
				className,
				rootElement
			);

		return isHTMLCollection( ELEMENTS )
			? ELEMENTS
			: NULL_ELEMENT;
	}

	function getElementByClassName(
		className,
		rootElement = document
	) {
		return getFirstItem( getElementsByClassName( className, rootElement ) );
	}

	function getSiteHeader() {
		return getElementByClassName( CLASS_SECTION_SITE_HEADER );
	}

	function isSiteHeader( element ) {
		return isHTMLElement( element, CLASS_SECTION_SITE_HEADER );
	}

	const RECT_HEIGHT = 'height';

	function getHeight( element ) {
		return getRectProp( element, RECT_HEIGHT );
	}

	const RECT_BOTTOM = 'bottom';

	function getViewportBottom( element ) {
		return getRectProp( element, RECT_BOTTOM );
	}

	const CSS_POSITION = 'position';
	const CSS_VALUE_FIXED = 'fixed';

	function isFixedElement( element ) {
		return areStringsEqualIgnoreCase(
			getStyleProp( element, CSS_POSITION ),
			CSS_VALUE_FIXED
		);
	}

	function getSiteHeaderStickyElements( siteHeader ) {
		return isSiteHeader( siteHeader )
			? getElementsByClassName( CLASS_SHARED_STICKY, siteHeader )
			: NULL_ELEMENT;
	}

	function getFixedElementHeight() {
		const SITE_HEADER = getSiteHeader();

		if ( ! SITE_HEADER ) {
			return PIXEL_ZERO;
		}

		return isFixedElement( SITE_HEADER )
			? getHeight( SITE_HEADER )
			: getViewportBottom(
				getLastItem( getSiteHeaderStickyElements( SITE_HEADER ) )
			);
	}

	function getClearTopOffset() {
		return convertRemToPx( DISTANCE_REM_LG );
	}

	function getAdjustedElementPageTop( element ) {
		const TARGET_ELEMENT_PAGE_TOP = getPageTop( element );

		return TARGET_ELEMENT_PAGE_TOP === POSITION_ZERO
			? TARGET_ELEMENT_PAGE_TOP
			: TARGET_ELEMENT_PAGE_TOP - getFixedElementHeight() - getClearTopOffset();
	}

	function isAtScrollTop( anchorLinkDestinationElement ) {
		return getAdjustedElementPageTop( anchorLinkDestinationElement ) ===
			getScrollTop();
	}

	const SCROLL_DISTANCE_LONG = 2000;
	const SCROLL_DISTANCE_MODERATE = 1000;
	const SCROLL_DISTANCE_SHORT = 200;
	const SCROLL_DURATION_MODERATE = 200;
	const SCROLL_DURATION_NORMAL = 300;
	const SCROLL_DURATION_SLOW = 400;
	const SCROLL_DURATION_SWIFT = 50;
	const CLASS_ACCESSIBILITY_SKIP_LINK = 'skip-link';

	function getSkipLink() {
		return getElementByClassName( CLASS_ACCESSIBILITY_SKIP_LINK );
	}

	function setAttribute( element, name, value ) {
		if (
			! isHTMLElement( element ) ||
			! isFunction( element.setAttribute ) ||
			! isNonEmptyString( name )
		) {
			return;
		}

		element.setAttribute( name, value );
	}

	function setTabIndex( element ) {
		setAttribute( element, ATTRIBUTE_TABINDEX, ATTRIBUTE_VALUE_MINUS_ONE );
	}

	function getPageHeight() {
		return Math.max(
			document.body.scrollHeight,
			document.body.offsetHeight,
			document.documentElement.clientHeight,
			document.documentElement.scrollHeight,
			document.documentElement.offsetHeight
		);
	}

	function getScrollLeft() {
		return isIe()
			? window.pageXOffset
			: window.scrollX || document.documentElement.scrollLeft;
	}

	function getViewportHeight() {
		return (
			window.innerHeight ||
			document.documentElement.clientHeight ||
			document.body.clientHeight
		);
	}

	const NUMBER_ZERO = 0;
	const RADIX_DECIMAL = 10;

	function parseDecimalInt( value ) {
		const PARSED_INT = parseInt( value, RADIX_DECIMAL );

		return isNumber( PARSED_INT )
			? PARSED_INT
			: NUMBER_ZERO;
	}

	const TAG_BUTTON = 'button';
	const TAG_SELECT = 'select';
	const TAGS_FOCUSABLE_ELEMENTS = [
		TAG_A,
		TAG_BUTTON,
		TAG_INPUT,
		TAG_SELECT,
		TAG_TEXTAREA,
	];

	function isFocusableElement( element ) {
		if ( ! isHTMLElement( element ) || ! hasTagName( element ) ) {
			return false;
		}

		const TAG_NAME = element.tagName;

		return forEach(
			TAGS_FOCUSABLE_ELEMENTS,
			( tagName ) => areStringsEqualIgnoreCase( tagName, TAG_NAME )
		);
	}

	const CALLBACK_INITIAL_INTERVAL = 0;

	function focusElement(
		element,
		attemptCount = CALLBACK_INITIAL_ATTEMPT_COUNT,
		interval = CALLBACK_INITIAL_INTERVAL
	) {
		if (
			! isHTMLElement( element ) ||
			! isFunction( element.focus ) ||
			! isNumber( attemptCount ) ||
			! isNumber( interval ) ||
			attemptCount === CALLBACK_MAX_ATTEMPT_COUNT
		) {
			return;
		}

		element.focus();
		setTimeout(
			() => {
				if ( element === document.activeElement ) {
					return;
				}

				focusElement( element, ++attemptCount, CALLBACK_INTERVAL );
			},
			interval
		);
	}

	function getStartTime() {
		return performance.now();
	}

	function focusScrollTargetElement( element ) {
		if ( ! isHTMLElement( element ) ) {
			return;
		}

		if ( ! isFocusableElement( element ) ) {
			setTabIndex( element );
		}

		const SCROLL_LEFT = getScrollLeft();
		const SCROLL_TOP = getScrollTop();

		focusElement( element );
		window.scrollTo( SCROLL_LEFT, SCROLL_TOP );
	}

	function isBackToTopDestinationElement( element ) {
		return isHTMLElement( element ) || isAnchorElement( element )
			? element === document.documentElement || element === getSkipLink()
			: false;
	}

	function isPageScrolledToBottom() {
		return getViewportHeight() + getScrollTop() >= getPageHeight();
	}

	function isAtDestination( element ) {
		return parseDecimalInt( getScrollTop() ) ===
			parseDecimalInt( getAdjustedElementPageTop( element ) );
	}

	function shouldScroll( element ) {
		return isHTMLElement( element )
			? ! ( isAtDestination( element ) || isPageScrolledToBottom() ) ||
			isBackToTopDestinationElement( element )
			: false;
	}

	function scrollTo( element, duration ) {
		if ( ! isHTMLElement( element ) ) {
			return;
		}

		if ( ! shouldScroll( element ) ) {
			focusScrollTargetElement( element );

			return;
		}

		if ( ! isNumber( duration ) ) {
			const DISTANCE =
				Math.abs( getScrollTop() - getAdjustedElementPageTop( element ) );

			switch ( true ) {
				case DISTANCE < SCROLL_DISTANCE_SHORT:
					duration = SCROLL_DURATION_SWIFT;
					break;
				case DISTANCE < SCROLL_DISTANCE_MODERATE:
					duration = SCROLL_DURATION_MODERATE;
					break;
				case DISTANCE < SCROLL_DISTANCE_LONG:
					duration = SCROLL_DURATION_NORMAL;
					break;
				default:
					duration = SCROLL_DURATION_SLOW;
			}
		}

		const START_TIME = getStartTime();

		step( START_TIME, element, START_TIME, parseDecimalInt( duration ) );

		function step( timeStamp, element, startTime, duration ) {
			if ( isNullOrEmpty( timeStamp ) ) {
				timeStamp = startTime;
			}

			if (
				! isNumber( timeStamp ) ||
				! isHTMLElement( element ) ||
				! isNumber( startTime ) ||
				! isNumber( duration )
			) {
				return;
			}

			const DESTINATION_ELEMENT_PAGE_TOP = getAdjustedElementPageTop( element );
			const PROGRESSED_TIME = timeStamp - startTime;

			if ( PROGRESSED_TIME < duration && duration !== PIXEL_ZERO ) {
				const SCROLL_TOP = getScrollTop();
				const TIME = Math.min( 1, PROGRESSED_TIME / duration );
				const DISTANCE = ( DESTINATION_ELEMENT_PAGE_TOP - SCROLL_TOP ) * TIME;

				window.scrollTo( POSITION_ZERO, SCROLL_TOP + DISTANCE );
				requestAnimationFrame( ( currentTime ) =>
					step( currentTime, element, startTime, duration )
				);

				return;
			}

			window.scrollTo( POSITION_ZERO, DESTINATION_ELEMENT_PAGE_TOP );
			focusScrollTargetElement( element );

			if ( ! isNonEmptyString( element.id ) ) {
				return;
			}

			history.pushState( null, '', `#${ element.id }` );
		}
	}

	function ensureAnchorLinkDestinationElementIsVisible(
		anchorLinkDestinationElement
	) {
		scrollTo( anchorLinkDestinationElement, SCROLL_DISTANCE_ZERO );
	}

	function ensureAnchorLinkDestinationElementIsVisibleIe(
		anchorLinkDestinationElement,
		attemptCount = CALLBACK_INITIAL_ATTEMPT_COUNT
	) {
		if (
			! isHTMLElement( anchorLinkDestinationElement ) ||
			isNaN( attemptCount ) ||
			attemptCount >= CALLBACK_MAX_ATTEMPT_COUNT ||
			isAtScrollTop( anchorLinkDestinationElement )
		) {
			return;
		}

		scrollTo( anchorLinkDestinationElement, SCROLL_DISTANCE_ZERO );
		setTimeout(
			() => ensureAnchorLinkDestinationElementIsVisibleIe(
				anchorLinkDestinationElement,
				++attemptCount
			),
			CALLBACK_INTERVAL
		);
	}

	function initialiseAnchorLinkDestinationElementPageTop() {
		if ( ! isNonEmptyString( window.location.hash ) ) {
			return;
		}

		const ANCHOR_LINK_DESTINATION_ELEMENT =
			getAnchorDestinationElement( window.location );

		if ( ! ANCHOR_LINK_DESTINATION_ELEMENT ) {
			return;
		}

		if ( isIe() ) {
			ensureAnchorLinkDestinationElementIsVisibleIe(
				ANCHOR_LINK_DESTINATION_ELEMENT
			);

			return;
		}

		ensureAnchorLinkDestinationElementIsVisible(
			ANCHOR_LINK_DESTINATION_ELEMENT
		);
	}

	function scrollToAnchorLinkDestinationElement( element ) {
		scrollTo( getAnchorDestinationElement( getAnchorElement( element ) ) );
	}

	function addAnchorLinkEvents() {
		onDocumentClick( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if ( isAnchorLink( event.target ) ) {
				event.preventDefault();
				scrollToAnchorLinkDestinationElement( event.target );
			}
		} );
		onDocumentKeydown( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if ( isEnterKey( event ) ) {
				if ( isAnchorLink( event.target ) ) {
					event.preventDefault();
					scrollToAnchorLinkDestinationElement( event.target );
				}
			}
		} );
		onWindowLoad( initialiseAnchorLinkDestinationElementPageTop );
	}

	const CSS_HEIGHT = 'height';
	const CSS_WIDTH = 'width';
	const CSS_VALUE_100PCT = '100%';
	const RATIO_ZERO = 0;
	const CLASS_WP_BLOCK_EMBED__WRAPPER = 'wp-block-embed__wrapper';
	const CLASS_WP_BLOCK_EMBED_YOUTUBE = 'wp-block-embed-youtube';
	const TAG_IFRAME = 'iframe';
	const SELECTOR_CONTENT_WP_BLOCK_EMBED_YOUTUBE_IFRAME = `.${ CLASS_WP_BLOCK_EMBED_YOUTUBE } > .${ CLASS_WP_BLOCK_EMBED__WRAPPER } > ${ TAG_IFRAME }`;

	function isBlockYouTubeIframe( element ) {
		return matches( element, SELECTOR_CONTENT_WP_BLOCK_EMBED_YOUTUBE_IFRAME );
	}

	function getIframes() {
		return getElementsByTagName( TAG_IFRAME );
	}

	function isIframeElement( element, ...classNames ) {
		return isHTMLElementOfType( TAG_IFRAME, element, ...classNames );
	}

	function hasStyle( element ) {
		return (
			!! element &&
			element.style instanceof CSSStyleDeclaration &&
			isFunction( element.style.setProperty )
		);
	}

	function isStyleProperty( property ) {
		return (
			isString( property ) &&
			hasStyle( document.documentElement ) &&
			property in document.documentElement.style
		);
	}

	function updateInlineStyle(
		element,
		property,
		value,
		isPriority
	) {
		if (
			! element ||
			! hasStyle( element ) ||
			! isStyleProperty( property ) ||
			! ( isString( value ) || isNumber( value ) ) ||
			! isBoolean( isPriority )
		) {
			return;
		}

		if ( isTrue( isPriority ) ) {
			element.style.setProperty( property, value, 'important' );

			return;
		}

		element.style.setProperty( property, value );
	}

	function updateElementInlineStyle(
		element,
		property,
		value,
		isPriority = false
	) {
		if ( ! isHTMLElement( element ) ) {
			return;
		}

		updateInlineStyle( element, property, value, isPriority );
	}

	function toPx( value ) {
		return isNumber( value )
			? value + 'px'
			: EMPTY_STRING;
	}

	function calculateAspectRatio( width, height ) {
		const WIDTH = parseFloat( width );
		const HEIGHT = parseFloat( height );

		return isPositiveNumber( WIDTH ) && isPositiveNumber( HEIGHT )
			? WIDTH / HEIGHT
			: RATIO_ZERO;
	}

	function getParentElementWidth( element ) {
		return getStylePropFloat( getParentElement( element ), CSS_WIDTH );
	}

	function getIframeHeight( iframe ) {
		if ( ! shouldResizeIframe( iframe ) || ! isIframeSizeValid( iframe ) ) {
			return PIXEL_ZERO;
		}

		const PARENT_ELEMENT_WIDTH = getParentElementWidth( iframe );
		const ASPECT_RATIO = calculateAspectRatio( iframe.width, iframe.height );

		return (
			isPositiveNumber( PARENT_ELEMENT_WIDTH ) &&
			isPositiveNumber( ASPECT_RATIO )
		)
			? Math.round( PARENT_ELEMENT_WIDTH / ASPECT_RATIO )
			: PIXEL_ZERO;
	}

	function isIframeSizeValid( iframe ) {
		return (
			isIframeElement( iframe ) &&
			! isNaN( iframe.width ) &&
			! isNaN( iframe.height )
		);
	}

	function shouldResizeIframe( iframe ) {
		return isIframeElement( iframe ) && ! isBlockYouTubeIframe( iframe );
	}

	function setIframeSize( iframe ) {
		if ( ! shouldResizeIframe( iframe ) || ! isIframeSizeValid( iframe ) ) {
			return;
		}

		const IFRAME_HEIGHT = getIframeHeight( iframe );

		if ( ! isPositiveNumber( IFRAME_HEIGHT ) ) {
			return;
		}

		updateElementInlineStyle( iframe, CSS_WIDTH, CSS_VALUE_100PCT );
		updateElementInlineStyle( iframe, CSS_HEIGHT, toPx( IFRAME_HEIGHT ) );
	}

	function setIframeSizes() {
		forEach( getIframes(), setIframeSize );
	}

	const EVENT_DOMCONTENTLOADED = 'DOMContentLoaded';

	function onDocumentDomContentLoaded( callback, options ) {
		onDocumentEvent( EVENT_DOMCONTENTLOADED, callback, options );
	}

	const EVENT_RESIZE = 'resize';

	function onWindowResize( callback, options ) {
		onWindowEvent( EVENT_RESIZE, callback, options );
	}

	function addIframeEvents() {
		onDocumentDomContentLoaded( setIframeSizes );
		onWindowLoad( setIframeSizes );
		onWindowResize( setIframeSizes );
	}

	function addContentEvents() {
		addAnchorLinkEvents();
		addIframeEvents();
	}

	const CLASS_SHARED_BOTTOM = 'bottom';
	const CLASS_SHARED_SHOW = 'show';
	const CSS_BOTTOM = 'bottom';
	const DISTANCE_REM_MD = 1.5;
	const CLASS_NAV_BACK_TO_TOP_BUTTON = 'back-to-top';

	function getBackToTopButton() {
		return getElementByClassName( CLASS_NAV_BACK_TO_TOP_BUTTON );
	}

	const CLASS_NAV_BOTTOM_NAVBAR = 'bottom-navbar';

	function getBottomNavbar() {
		return getElementByClassName( CLASS_NAV_BOTTOM_NAVBAR );
	}

	function isBackToTopButton( element ) {
		return isHTMLElement( element, CLASS_NAV_BACK_TO_TOP_BUTTON );
	}

	const CLASS_SECTION_SITE_FOOTER = 'site-footer';

	function getSiteFooter() {
		return getElementByClassName( CLASS_SECTION_SITE_FOOTER );
	}

	function toggleClass( add, element, className ) {
		if ( ! isBoolean( add ) ) {
			return;
		}

		const TOGGLE_CLASS = isTrue( add ) ? addClass : removeClass;

		TOGGLE_CLASS( element, className );
	}

	const EVENT_SCROLL = 'scroll';

	function onWindowScroll( callback, options ) {
		onWindowEvent( EVENT_SCROLL, callback, options );
	}

	function adjustBackToTopBottom() {
		const BACK_TO_TOP_BUTTON = getBackToTopButton();

		if ( ! BACK_TO_TOP_BUTTON ) {
			return;
		}

		const BACK_TO_TOP_BOTTOM_MARGIN = convertRemToPx( DISTANCE_REM_MD );
		const BOTTOM_NAVBAR = getBottomNavbar();
		const BACK_TO_TOP_BUTTON_BOTTOM = BOTTOM_NAVBAR
			? getHeight( BOTTOM_NAVBAR ) + BACK_TO_TOP_BOTTOM_MARGIN
			: BACK_TO_TOP_BOTTOM_MARGIN;

		updateElementInlineStyle(
			BACK_TO_TOP_BUTTON,
			CSS_BOTTOM,
			toPx( BACK_TO_TOP_BUTTON_BOTTOM )
		);
	}

	function toggleBackToTopButtonPageBottom() {
		const BACK_TO_TOP_BUTTON = getBackToTopButton();

		if ( ! BACK_TO_TOP_BUTTON ) {
			return;
		}

		const SITE_FOOTER = getSiteFooter();

		if ( ! SITE_FOOTER ) {
			return;
		}

		const BOTTOM_NAVBAR = getBottomNavbar();
		const SITE_CONTENT_VIEWPORT_BOTTOM = BOTTOM_NAVBAR
			? getViewportTop( BOTTOM_NAVBAR )
			: getViewportHeight();
		const BACK_TO_TOP_BOTTOM_MARGIN = convertRemToPx( DISTANCE_REM_MD );
		const SITE_FOOTER_VIEWPORT_TOP =
			getViewportTop( SITE_FOOTER ) - BACK_TO_TOP_BOTTOM_MARGIN;

		toggleClass(
			SITE_CONTENT_VIEWPORT_BOTTOM > SITE_FOOTER_VIEWPORT_TOP,
			BACK_TO_TOP_BUTTON,
			CLASS_SHARED_BOTTOM
		);
		adjustBackToTopBottom();
	}

	function toggleBackToTopButtonVisibility() {
		const BACK_TO_TOP_BUTTON = getBackToTopButton();

		if ( ! BACK_TO_TOP_BUTTON ) {
			return;
		}

		const SCROLL_TOP = getScrollTop();
		const BACK_TO_TOP_BUTTON_SHOW_AT = convertRemToPx( DISTANCE_REM_MD );

		toggleClass(
			SCROLL_TOP > BACK_TO_TOP_BUTTON_SHOW_AT,
			BACK_TO_TOP_BUTTON,
			CLASS_SHARED_SHOW
		);
	}

	function toggleBackToTopButtonVisibilityAndPageBottom() {
		toggleBackToTopButtonVisibility();
		toggleBackToTopButtonPageBottom();
	}

	function backToSkipLink() {
		const SKIP_LINK = getSkipLink();

		if ( SKIP_LINK ) {
			scrollTo( SKIP_LINK );

			return;
		}

		backToTop();
	}

	function backToTop() {
		scrollTo( document.documentElement );
	}

	function addBackToTopEvents() {
		onDocumentClick( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if ( isBackToTopButton( event.target ) ) {
				backToTop();
			}
		} );
		onDocumentKeydown( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if ( isEnterKey( event ) ) {
				if ( isBackToTopButton( event.target ) ) {
					event.preventDefault();
					backToSkipLink();
				}
			}
		} );
		onWindowLoad( toggleBackToTopButtonVisibilityAndPageBottom );
		onWindowResize( toggleBackToTopButtonVisibilityAndPageBottom );
		onWindowScroll( toggleBackToTopButtonVisibilityAndPageBottom );
	}

	function addNavigationEvents() {
		addBackToTopEvents();
	}

	const CLASS_SHARED_NO_SCROLL = 'no-scroll';
	const TOGGLE_CLOSE = false;
	const TOGGLE_OPEN = true;
	const CLASS_MOBILE_SEARCH = 'mobile-search';

	function getMobileSearch() {
		return getElementByClassName( CLASS_MOBILE_SEARCH );
	}

	const CLASS_MOBILE_SEARCH_BUTTON = 'mobile-navigation__search-button';

	function getMobileSearchButton() {
		return getElementByClassName( CLASS_MOBILE_SEARCH_BUTTON );
	}

	const CLASS_MOBILE_SEARCH_CLOSE_BUTTON = 'mobile-search__close-search-button';

	function getMobileSearchCloseButton() {
		return getElementByClassName( CLASS_MOBILE_SEARCH_CLOSE_BUTTON );
	}

	const CLASS_SEARCH_FORM_SUBMIT = 'search-submit';
	const SELECTOR_MOBILE_SEARCH_OPENED = `.${ CLASS_MOBILE_SEARCH }.${ CLASS_SHARED_SHOW }`;
	const SELECTOR_MOBILE_SEARCH_SUBMIT_BUTTON = `${ SELECTOR_MOBILE_SEARCH_OPENED } .${ CLASS_SEARCH_FORM_SUBMIT }`;

	function querySelector( selectors, rootElement = document ) {
		return callElementMethod( 'querySelector', selectors, rootElement );
	}

	function getMobileSearchSubmitButton() {
		return querySelector( SELECTOR_MOBILE_SEARCH_SUBMIT_BUTTON );
	}

	const CLASS_MOBILE_SEARCH_CONTAINER = 'mobile-search__container';

	function isMobileSearchBackground( element ) {
		return (
			isHTMLElement( element, CLASS_MOBILE_SEARCH_CONTAINER ) ||
			isHTMLElement( element, CLASS_MOBILE_SEARCH, CLASS_SHARED_SHOW )
		);
	}

	function isMobileSearchButton( element ) {
		return isHTMLElement( element, CLASS_MOBILE_SEARCH_BUTTON );
	}

	function isMobileSearchCloseButton( element ) {
		return isHTMLElement( element, CLASS_MOBILE_SEARCH_CLOSE_BUTTON );
	}

	const CLASS_SEARCH_FORM = 'search-form';
	const SELECTOR_MOBILE_SEARCH_FORM = `.${ CLASS_MOBILE_SEARCH } .${ CLASS_SEARCH_FORM }`;

	function isMobileSearchForm( element ) {
		return matches( element, SELECTOR_MOBILE_SEARCH_FORM );
	}

	function isMobileSearchOpened() {
		return !! querySelector( SELECTOR_MOBILE_SEARCH_OPENED );
	}

	function isMobileSearchSubmitButton( element ) {
		return matches( element, SELECTOR_MOBILE_SEARCH_SUBMIT_BUTTON );
	}

	const ATTRIBUTE_ARIA_EXPANDED = 'aria-expanded';

	function toggleAriaExpanded( expanded, ...elements ) {
		if ( ! isBoolean( expanded ) ) {
			return;
		}

		forEach(
			elements,
			( element ) => setAttribute(
				element,
				ATTRIBUTE_ARIA_EXPANDED,
				isTrue( expanded )
			)
		);
	}

	const ATTRIBUTE_ARIA_HIDDEN = 'aria-hidden';

	function toggleAriaHidden( hidden, ...elements ) {
		if ( ! isBoolean( hidden ) ) {
			return;
		}

		forEach(
			elements,
			( element ) => setAttribute(
				element,
				ATTRIBUTE_ARIA_HIDDEN,
				isTrue( hidden )
			)
		);
	}

	function isEscapeKey( event ) {
		return isKey( event, 'Escape', 27 );
	}

	function isShiftKey( event ) {
		return isEvent( event ) && isTrue( event.shiftKey );
	}

	function isTabKey( event ) {
		return isKey( event, 'Tab', 9 );
	}

	function focusMobileSearchSubmitButton() {
		focusElement( getMobileSearchSubmitButton() );
	}

	function focusMobileSearchCloseButton() {
		focusElement( getMobileSearchCloseButton() );
	}

	function openMobileSearchAndFocusMobileSearchCloseButton() {
		toggleMobileSearch( TOGGLE_OPEN );
		focusMobileSearchCloseButton();
	}

	function focusMobileSearchButton() {
		focusElement( getMobileSearchButton() );
	}

	function toggleMobileSearch( open ) {
		if ( ! isBoolean( open ) ) {
			return;
		}

		const MOBILE_SEARCH = getMobileSearch();

		if ( ! MOBILE_SEARCH ) {
			return;
		}

		toggleAriaExpanded(
			open,
			getMobileSearchButton()
		);
		toggleAriaHidden(
			! open,
			MOBILE_SEARCH
		);
		toggleClass(
			open,
			document.documentElement,
			CLASS_SHARED_NO_SCROLL
		);
		toggleClass(
			open,
			MOBILE_SEARCH,
			CLASS_SHARED_SHOW
		);
	}

	function closeMobileSearchAndFocusMobileSearchButton() {
		toggleMobileSearch( TOGGLE_CLOSE );
		focusMobileSearchButton();
	}

	function addMobileSearchEvents() {
		onDocumentClick( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if (
				isMobileSearchBackground( event.target ) ||
				isMobileSearchCloseButton( event.target )
			) {
				closeMobileSearchAndFocusMobileSearchButton();

				return;
			}

			if ( isMobileSearchButton( event.target ) ) {
				openMobileSearchAndFocusMobileSearchCloseButton();

				return;
			}

			if ( isMobileSearchForm( event.target ) ) {
				event.stopPropagation();
			}
		} );
		onDocumentKeydown( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if ( isEnterKey( event ) ) {
				if ( isMobileSearchCloseButton( event.target ) ) {
					event.preventDefault();
					closeMobileSearchAndFocusMobileSearchButton();

					return;
				}

				if ( isMobileSearchButton( event.target ) ) {
					event.preventDefault();
					openMobileSearchAndFocusMobileSearchCloseButton();
				}

				return;
			}

			if ( isEscapeKey( event ) ) {
				if ( isMobileSearchOpened() ) {
					event.preventDefault();
					closeMobileSearchAndFocusMobileSearchButton();
				}

				return;
			}

			if ( isTabKey( event ) ) {
				if ( isShiftKey( event ) && isMobileSearchCloseButton( event.target ) ) {
					event.preventDefault();
					focusMobileSearchSubmitButton();

					return;
				}

				if (
					! isShiftKey( event ) &&
					isMobileSearchSubmitButton( event.target )
				) {
					event.preventDefault();
					focusMobileSearchCloseButton();
				}
			}
		} );
	}

	const CLASS_SEARCH_FORM_CLEAR_BUTTON = 'search-clear-button';
	const CLASS_SEARCH_FORM_FIELD = 'search-field';

	function isInputElement( element, ...classNames ) {
		return isHTMLElementOfType( TAG_INPUT, element, ...classNames );
	}

	function isSearchField( element ) {
		return isInputElement( element, CLASS_SEARCH_FORM_FIELD );
	}

	const CLASS_SEARCH_FORM_FIELD_CONTAINER = 'search-field-container';

	function isSearchFieldContainer( element ) {
		return isHTMLElement( element, CLASS_SEARCH_FORM_FIELD_CONTAINER );
	}

	function getSearchClearButton( searchField ) {
		if ( ! isSearchField( searchField ) ) {
			return NULL_ELEMENT;
		}

		const SEARCH_FIELD_CONTAINER = getParentElement( searchField );

		return isSearchFieldContainer( SEARCH_FIELD_CONTAINER )
			? getElementByClassName(
				CLASS_SEARCH_FORM_CLEAR_BUTTON,
				SEARCH_FIELD_CONTAINER
			)
			: NULL_ELEMENT;
	}

	function isSearchClearButton( element ) {
		return isHTMLElement(
			element,
			CLASS_SEARCH_FORM_CLEAR_BUTTON,
			CLASS_SHARED_SHOW
		);
	}

	function getSearchField( searchClearButton ) {
		if ( ! isSearchClearButton( searchClearButton ) ) {
			return NULL_ELEMENT;
		}

		const SEARCH_FIELD_CONTAINER = getParentElement( searchClearButton );

		return isSearchFieldContainer( SEARCH_FIELD_CONTAINER )
			? getElementByClassName( CLASS_SEARCH_FORM_FIELD, SEARCH_FIELD_CONTAINER )
			: NULL_ELEMENT;
	}

	function isTextAreaElement( element, ...classNames ) {
		return isHTMLElementOfType( TAG_TEXTAREA, element, ...classNames );
	}

	function setInputValue( element, value ) {
		if ( ! ( isInputElement( element ) || isTextAreaElement( element ) ) ) {
			return;
		}

		element.value = value;
	}

	const EVENT_INPUT = 'input';

	function onDocumentInput( callback, options ) {
		onDocumentEvent( EVENT_INPUT, callback, options );
	}

	function toggleSearchClearButton( searchField ) {
		if ( ! isSearchField( searchField ) ) {
			return;
		}

		toggleClass(
			! isNullOrEmpty( searchField.value ),
			getSearchClearButton( searchField ),
			CLASS_SHARED_SHOW
		);
	}

	function clearSearchField( searchField ) {
		if ( ! isSearchField( searchField ) ) {
			return;
		}

		setInputValue( searchField, EMPTY_STRING );
		focusElement( searchField );
	}

	function clearSearchFieldAndHideSearchClearButton( searchClearButton ) {
		const SEARCH_FIELD = getSearchField( searchClearButton );

		if ( ! SEARCH_FIELD ) {
			return;
		}

		clearSearchField( SEARCH_FIELD );
		toggleSearchClearButton( SEARCH_FIELD );
	}

	function addSearchFormEvents() {
		onDocumentClick( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if ( isSearchClearButton( event.target ) ) {
				clearSearchFieldAndHideSearchClearButton( event.target );
			}
		}, true );
		onDocumentInput( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if ( isSearchField( event.target ) ) {
				toggleSearchClearButton( event.target );
			}
		} );
		onDocumentKeydown( ( event ) => {
			if ( ! isEvent( event ) ) {
				return;
			}

			if ( isEnterKey( event ) ) {
				if ( isSearchClearButton( event.target ) ) {
					event.preventDefault();
					clearSearchFieldAndHideSearchClearButton( event.target );
				}
			}
		} );
	}

	function addSearchEvents() {
		addMobileSearchEvents();
		addSearchFormEvents();
	}

	addAccessibilityEvents();
	addContentEvents();
	addComponentEvents();
	addNavigationEvents();
	addSearchEvents();
}() );
