/**
 * 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';

	var CALLBACK_INITIAL_ATTEMPT_COUNT = 0;
	var CALLBACK_INTERVAL = 50;
	var CALLBACK_MAX_ATTEMPT_COUNT = 20;
	var CSS_HEIGHT = 'height';
	var CSS_WIDTH = 'width';
	var CSS_VALUE_100PCT = '100%';
	var PIXEL_ZERO = 0;
	var RATIO_ZERO = 0;
	var CLASS_WP_BLOCK_EMBED__WRAPPER = 'wp-block-embed__wrapper';
	var CLASS_WP_BLOCK_EMBED_YOUTUBE = 'wp-block-embed-youtube';
	var TAG_IFRAME = 'iframe';
	var SELECTOR_CONTENT_WP_BLOCK_EMBED_YOUTUBE_IFRAME = '.'.concat( CLASS_WP_BLOCK_EMBED_YOUTUBE, ' > .' ).concat( CLASS_WP_BLOCK_EMBED__WRAPPER, ' > ' ).concat( TAG_IFRAME );

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

	var INDEX_FIRST = 0;

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

	function isObjectType( value, expectedType ) {
		return Object.prototype.toString.call( value ) === '[object '.concat( 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 ( var 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 ) {
		if ( ! ( element instanceof HTMLElement ) ) {
			return false;
		}

		for ( var _len = arguments.length, classNames = new Array( _len > 1 ? _len - 1 : 0 ), _key = 1; _key < _len; _key++ ) {
			classNames[ _key - 1 ] = arguments[ _key ];
		}

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

	var EMPTY_STRING = '';

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

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

	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 isBlockYouTubeIframe( element ) {
		return matches( element, SELECTOR_CONTENT_WP_BLOCK_EMBED_YOUTUBE_IFRAME );
	}

	var NULL_ELEMENT = null;

	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 ) {
		var rootElement = arguments.length > 1 && arguments[ 1 ] !== undefined ? arguments[ 1 ] : document;
		var ELEMENTS = callElementMethod( 'getElementsByTagName', tagName, rootElement );

		return isHTMLCollection( ELEMENTS ) ? ELEMENTS : NULL_ELEMENT;
	}

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

	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 ) {
		for ( var _len = arguments.length, classNames = new Array( _len > 2 ? _len - 2 : 0 ), _key = 2; _key < _len; _key++ ) {
			classNames[ _key - 2 ] = arguments[ _key ];
		}

		return isHTMLElement.apply( void 0, [ element ].concat( classNames ) ) && isElementOfType( element, tagName );
	}

	function isIframeElement( element ) {
		for ( var _len = arguments.length, classNames = new Array( _len > 1 ? _len - 1 : 0 ), _key = 1; _key < _len; _key++ ) {
			classNames[ _key - 1 ] = arguments[ _key ];
		}

		return isHTMLElementOfType.apply( void 0, [ TAG_IFRAME, element ].concat( classNames ) );
	}

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

	var NULL_VALUE = null;

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

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

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

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

		return isString( STYLE_PROP ) ? STYLE_PROP : NULL_VALUE;
	}

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

		return isNumber( STYLE_PROP ) ? STYLE_PROP : PIXEL_ZERO;
	}

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

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

	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 ) {
		var isPriority = arguments.length > 3 && arguments[ 3 ] !== undefined ? arguments[ 3 ] : false;

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

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

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

	function calculateAspectRatio( width, height ) {
		var WIDTH = parseFloat( width );
		var 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;
		}

		var PARENT_ELEMENT_WIDTH = getParentElementWidth( iframe );
		var 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;
		}

		var 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 );
	}

	var EVENT_DOMCONTENTLOADED = 'DOMContentLoaded';

	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 onDocumentDomContentLoaded( callback, options ) {
		onDocumentEvent( EVENT_DOMCONTENTLOADED, callback, options );
	}

	var 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 );
	}

	var EVENT_RESIZE = 'resize';

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

	function setIframeSizesInEditor() {
		var attemptCount = arguments.length > 0 && arguments[ 0 ] !== undefined ? arguments[ 0 ] : CALLBACK_INITIAL_ATTEMPT_COUNT;

		if ( ! isNumber( attemptCount ) || attemptCount >= CALLBACK_MAX_ATTEMPT_COUNT ) {
			return;
		}

		setIframeSizes();
		setTimeout( function() {
			return setIframeSizesInEditor( ++attemptCount );
		}, CALLBACK_INTERVAL );
	}

	function addIframeEventsInEditor() {
		onDocumentDomContentLoaded( setIframeSizesInEditor );
		onWindowLoad( setIframeSizesInEditor );
		onWindowResize( setIframeSizesInEditor );
	}

	function addContentEvents() {
		addIframeEventsInEditor();
	}

	addContentEvents();
}() );
