diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php index 739b09f9a1..2d150e691c 100644 --- a/wp-admin/includes/image-edit.php +++ b/wp-admin/includes/image-edit.php @@ -390,6 +390,12 @@ function wp_stream_image( $image, $mime_type, $attachment_id ) { return imagewebp( $image, null, 90 ); } return false; + case 'image/avif': + if ( function_exists( 'imageavif' ) ) { + header( 'Content-Type: image/avif' ); + return imageavif( $image, null, 90 ); + } + return false; default: return false; } @@ -494,6 +500,11 @@ function wp_save_image_file( $filename, $image, $mime_type, $post_id ) { return imagewebp( $image, $filename ); } return false; + case 'image/avif': + if ( function_exists( 'imageavif' ) ) { + return imageavif( $image, $filename ); + } + return false; default: return false; } diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php index d60ec8508b..0f4ba818e6 100644 --- a/wp-admin/includes/image.php +++ b/wp-admin/includes/image.php @@ -1006,7 +1006,7 @@ function file_is_valid_image( $path ) { * @return bool True if suitable, false if not suitable. */ function file_is_displayable_image( $path ) { - $displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO, IMAGETYPE_WEBP ); + $displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO, IMAGETYPE_WEBP, IMAGETYPE_AVIF ); $info = wp_getimagesize( $path ); if ( empty( $info ) ) { diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 57df2bcbff..193e67f7dd 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -2198,6 +2198,11 @@ function media_upload_form( $errors = null ) { $plupload_init['webp_upload_error'] = true; } + // Check if AVIF images can be edited. + if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) { + $plupload_init['avif_upload_error'] = true; + } + /** * Filters the default Plupload settings. * diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index 20648d7dde..63655ccf17 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -1250,6 +1250,7 @@ We hope you enjoy your new site. Thanks! 'png', 'gif', 'webp', + 'avif', // Video. 'mov', 'avi', diff --git a/wp-includes/class-avif-info.php b/wp-includes/class-avif-info.php new file mode 100644 index 0000000000..93280b3806 --- /dev/null +++ b/wp-includes/class-avif-info.php @@ -0,0 +1,781 @@ += 2^31 on 32-bit systems. + // See https://www.php.net/manual/en/function.unpack.php#106041 + return unpack( 'N', $input ) [1]; + } +} + +/** + * Reads bytes and advances the stream position by the same count. + * + * @param stream $handle Bytes will be read from this resource. + * @param int $num_bytes Number of bytes read. Must be greater than 0. + * @return binary string|false The raw bytes or false on failure. + */ +function read( $handle, $num_bytes ) { + $data = fread( $handle, $num_bytes ); + return ( $data !== false && strlen( $data ) >= $num_bytes ) ? $data : false; +} + +/** + * Advances the stream position by the given offset. + * + * @param stream $handle Bytes will be skipped from this resource. + * @param int $num_bytes Number of skipped bytes. Can be 0. + * @return bool True on success or false on failure. + */ +// Skips 'num_bytes' from the 'stream'. 'num_bytes' can be zero. +function skip( $handle, $num_bytes ) { + return ( fseek( $handle, $num_bytes, SEEK_CUR ) == 0 ); +} + +//------------------------------------------------------------------------------ +// Features are parsed into temporary property associations. + +class Tile { // Tile item id <-> parent item id associations. + public $tile_item_id; + public $parent_item_id; +} + +class Prop { // Property index <-> item id associations. + public $property_index; + public $item_id; +} + +class Dim_Prop { // Property <-> features associations. + public $property_index; + public $width; + public $height; +} + +class Chan_Prop { // Property <-> features associations. + public $property_index; + public $bit_depth; + public $num_channels; +} + +class Features { + public $has_primary_item = false; // True if "pitm" was parsed. + public $has_alpha = false; // True if an alpha "auxC" was parsed. + public $primary_item_id; + public $primary_item_features = array( // Deduced from the data below. + 'width' => UNDEFINED, // In number of pixels. + 'height' => UNDEFINED, // Ignores mirror and rotation. + 'bit_depth' => UNDEFINED, // Likely 8, 10 or 12 bits per channel per pixel. + 'num_channels' => UNDEFINED // Likely 1, 2, 3 or 4 channels: + // (1 monochrome or 3 colors) + (0 or 1 alpha) + ); + + public $tiles = array(); // Tile[] + public $props = array(); // Prop[] + public $dim_props = array(); // Dim_Prop[] + public $chan_props = array(); // Chan_Prop[] + + /** + * Binds the width, height, bit depth and number of channels from stored internal features. + * + * @param int $target_item_id Id of the item whose features will be bound. + * @param int $tile_depth Maximum recursion to search within tile-parent relations. + * @return Status FOUND on success or NOT_FOUND on failure. + */ + private function get_item_features( $target_item_id, $tile_depth ) { + foreach ( $this->props as $prop ) { + if ( $prop->item_id != $target_item_id ) { + continue; + } + + // Retrieve the width and height of the primary item if not already done. + if ( $target_item_id == $this->primary_item_id && + ( $this->primary_item_features['width'] == UNDEFINED || + $this->primary_item_features['height'] == UNDEFINED ) ) { + foreach ( $this->dim_props as $dim_prop ) { + if ( $dim_prop->property_index != $prop->property_index ) { + continue; + } + $this->primary_item_features['width'] = $dim_prop->width; + $this->primary_item_features['height'] = $dim_prop->height; + if ( $this->primary_item_features['bit_depth'] != UNDEFINED && + $this->primary_item_features['num_channels'] != UNDEFINED ) { + return FOUND; + } + break; + } + } + // Retrieve the bit depth and number of channels of the target item if not + // already done. + if ( $this->primary_item_features['bit_depth'] == UNDEFINED || + $this->primary_item_features['num_channels'] == UNDEFINED ) { + foreach ( $this->chan_props as $chan_prop ) { + if ( $chan_prop->property_index != $prop->property_index ) { + continue; + } + $this->primary_item_features['bit_depth'] = $chan_prop->bit_depth; + $this->primary_item_features['num_channels'] = $chan_prop->num_channels; + if ( $this->primary_item_features['width'] != UNDEFINED && + $this->primary_item_features['height'] != UNDEFINED ) { + return FOUND; + } + break; + } + } + } + + // Check for the bit_depth and num_channels in a tile if not yet found. + if ( $tile_depth < 3 ) { + foreach ( $this->tiles as $tile ) { + if ( $tile->parent_item_id != $target_item_id ) { + continue; + } + $status = get_item_features( $tile->tile_item_id, $tile_depth + 1 ); + if ( $status != NOT_FOUND ) { + return $status; + } + } + } + return NOT_FOUND; + } + + /** + * Finds the width, height, bit depth and number of channels of the primary item. + * + * @return Status FOUND on success or NOT_FOUND on failure. + */ + public function get_primary_item_features() { + // Nothing to do without the primary item ID. + if ( !$this->has_primary_item ) { + return NOT_FOUND; + } + // Early exit. + if ( empty( $this->dim_props ) || empty( $this->chan_props ) ) { + return NOT_FOUND; + } + $status = $this->get_item_features( $this->primary_item_id, /*tile_depth=*/ 0 ); + if ( $status != FOUND ) { + return $status; + } + + // "auxC" is parsed before the "ipma" properties so it is known now, if any. + if ( $this->has_alpha ) { + ++$this->primary_item_features['num_channels']; + } + return FOUND; + } +} + +//------------------------------------------------------------------------------ + +class Box { + public $size; // In bytes. + public $type; // Four characters. + public $version; // 0 or actual version if this is a full box. + public $flags; // 0 or actual value if this is a full box. + public $content_size; // 'size' minus the header size. + + /** + * Reads the box header. + * + * @param stream $handle The resource the header will be parsed from. + * @param int $num_parsed_boxes The total number of parsed boxes. Prevents timeouts. + * @param int $num_remaining_bytes The number of bytes that should be available from the resource. + * @return Status FOUND on success or an error on failure. + */ + public function parse( $handle, &$num_parsed_boxes, $num_remaining_bytes = MAX_SIZE ) { + // See ISO/IEC 14496-12:2012(E) 4.2 + $header_size = 8; // box 32b size + 32b type (at least) + if ( $header_size > $num_remaining_bytes ) { + return INVALID; + } + if ( !( $data = read( $handle, 8 ) ) ) { + return TRUNCATED; + } + $this->size = read_big_endian( $data, 4 ); + $this->type = substr( $data, 4, 4 ); + // 'box->size==1' means 64-bit size should be read after the box type. + // 'box->size==0' means this box extends to all remaining bytes. + if ( $this->size == 1 ) { + $header_size += 8; + if ( $header_size > $num_remaining_bytes ) { + return INVALID; + } + if ( !( $data = read( $handle, 8 ) ) ) { + return TRUNCATED; + } + // Stop the parsing if any box has a size greater than 4GB. + if ( read_big_endian( $data, 4 ) != 0 ) { + return ABORTED; + } + // Read the 32 least-significant bits. + $this->size = read_big_endian( substr( $data, 4, 4 ), 4 ); + } else if ( $this->size == 0 ) { + $this->size = $num_remaining_bytes; + } + if ( $this->size < $header_size ) { + return INVALID; + } + if ( $this->size > $num_remaining_bytes ) { + return INVALID; + } + + $has_fullbox_header = $this->type == 'meta' || $this->type == 'pitm' || + $this->type == 'ipma' || $this->type == 'ispe' || + $this->type == 'pixi' || $this->type == 'iref' || + $this->type == 'auxC'; + if ( $has_fullbox_header ) { + $header_size += 4; + } + if ( $this->size < $header_size ) { + return INVALID; + } + $this->content_size = $this->size - $header_size; + // Avoid timeouts. The maximum number of parsed boxes is arbitrary. + ++$num_parsed_boxes; + if ( $num_parsed_boxes >= MAX_NUM_BOXES ) { + return ABORTED; + } + + $this->version = 0; + $this->flags = 0; + if ( $has_fullbox_header ) { + if ( !( $data = read( $handle, 4 ) ) ) { + return TRUNCATED; + } + $this->version = read_big_endian( $data, 1 ); + $this->flags = read_big_endian( substr( $data, 1, 3 ), 3 ); + // See AV1 Image File Format (AVIF) 8.1 + // at https://aomediacodec.github.io/av1-avif/#avif-boxes (available when + // https://github.com/AOMediaCodec/av1-avif/pull/170 is merged). + $is_parsable = ( $this->type == 'meta' && $this->version <= 0 ) || + ( $this->type == 'pitm' && $this->version <= 1 ) || + ( $this->type == 'ipma' && $this->version <= 1 ) || + ( $this->type == 'ispe' && $this->version <= 0 ) || + ( $this->type == 'pixi' && $this->version <= 0 ) || + ( $this->type == 'iref' && $this->version <= 1 ) || + ( $this->type == 'auxC' && $this->version <= 0 ); + // Instead of considering this file as invalid, skip unparsable boxes. + if ( !$is_parsable ) { + $this->type = 'unknownversion'; + } + } + // print_r( $this ); // Uncomment to print all boxes. + return FOUND; + } +} + +//------------------------------------------------------------------------------ + +class Parser { + private $handle; // Input stream. + private $num_parsed_boxes = 0; + private $data_was_skipped = false; + public $features; + + function __construct( $handle ) { + $this->handle = $handle; + $this->features = new Features(); + } + + /** + * Parses an "ipco" box. + * + * "ispe" is used for width and height, "pixi" and "av1C" are used for bit depth + * and number of channels, and "auxC" is used for alpha. + * + * @param stream $handle The resource the box will be parsed from. + * @param int $num_remaining_bytes The number of bytes that should be available from the resource. + * @return Status FOUND on success or an error on failure. + */ + private function parse_ipco( $num_remaining_bytes ) { + $box_index = 1; // 1-based index. Used for iterating over properties. + do { + $box = new Box(); + $status = $box->parse( $this->handle, $this->num_parsed_boxes, $num_remaining_bytes ); + if ( $status != FOUND ) { + return $status; + } + + if ( $box->type == 'ispe' ) { + // See ISO/IEC 23008-12:2017(E) 6.5.3.2 + if ( $box->content_size < 8 ) { + return INVALID; + } + if ( !( $data = read( $this->handle, 8 ) ) ) { + return TRUNCATED; + } + $width = read_big_endian( substr( $data, 0, 4 ), 4 ); + $height = read_big_endian( substr( $data, 4, 4 ), 4 ); + if ( $width == 0 || $height == 0 ) { + return INVALID; + } + if ( count( $this->features->dim_props ) <= MAX_FEATURES && + $box_index <= MAX_VALUE ) { + $dim_prop_count = count( $this->features->dim_props ); + $this->features->dim_props[$dim_prop_count] = new Dim_Prop(); + $this->features->dim_props[$dim_prop_count]->property_index = $box_index; + $this->features->dim_props[$dim_prop_count]->width = $width; + $this->features->dim_props[$dim_prop_count]->height = $height; + } else { + $this->data_was_skipped = true; + } + if ( !skip( $this->handle, $box->content_size - 8 ) ) { + return TRUNCATED; + } + } else if ( $box->type == 'pixi' ) { + // See ISO/IEC 23008-12:2017(E) 6.5.6.2 + if ( $box->content_size < 1 ) { + return INVALID; + } + if ( !( $data = read( $this->handle, 1 ) ) ) { + return TRUNCATED; + } + $num_channels = read_big_endian( $data, 1 ); + if ( $num_channels < 1 ) { + return INVALID; + } + if ( $box->content_size < 1 + $num_channels ) { + return INVALID; + } + if ( !( $data = read( $this->handle, 1 ) ) ) { + return TRUNCATED; + } + $bit_depth = read_big_endian( $data, 1 ); + if ( $bit_depth < 1 ) { + return INVALID; + } + for ( $i = 1; $i < $num_channels; ++$i ) { + if ( !( $data = read( $this->handle, 1 ) ) ) { + return TRUNCATED; + } + // Bit depth should be the same for all channels. + if ( read_big_endian( $data, 1 ) != $bit_depth ) { + return INVALID; + } + if ( $i > 32 ) { + return ABORTED; // Be reasonable. + } + } + if ( count( $this->features->chan_props ) <= MAX_FEATURES && + $box_index <= MAX_VALUE && $bit_depth <= MAX_VALUE && + $num_channels <= MAX_VALUE ) { + $chan_prop_count = count( $this->features->chan_props ); + $this->features->chan_props[$chan_prop_count] = new Chan_Prop(); + $this->features->chan_props[$chan_prop_count]->property_index = $box_index; + $this->features->chan_props[$chan_prop_count]->bit_depth = $bit_depth; + $this->features->chan_props[$chan_prop_count]->num_channels = $num_channels; + } else { + $this->data_was_skipped = true; + } + if ( !skip( $this->handle, $box->content_size - ( 1 + $num_channels ) ) ) { + return TRUNCATED; + } + } else if ( $box->type == 'av1C' ) { + // See AV1 Codec ISO Media File Format Binding 2.3.1 + // at https://aomediacodec.github.io/av1-isobmff/#av1c + // Only parse the necessary third byte. Assume that the others are valid. + if ( $box->content_size < 3 ) { + return INVALID; + } + if ( !( $data = read( $this->handle, 3 ) ) ) { + return TRUNCATED; + } + $byte = read_big_endian( substr( $data, 2, 1 ), 1 ); + $high_bitdepth = ( $byte & 0x40 ) != 0; + $twelve_bit = ( $byte & 0x20 ) != 0; + $monochrome = ( $byte & 0x10 ) != 0; + if ( $twelve_bit && !$high_bitdepth ) { + return INVALID; + } + if ( count( $this->features->chan_props ) <= MAX_FEATURES && + $box_index <= MAX_VALUE ) { + $chan_prop_count = count( $this->features->chan_props ); + $this->features->chan_props[$chan_prop_count] = new Chan_Prop(); + $this->features->chan_props[$chan_prop_count]->property_index = $box_index; + $this->features->chan_props[$chan_prop_count]->bit_depth = + $high_bitdepth ? $twelve_bit ? 12 : 10 : 8; + $this->features->chan_props[$chan_prop_count]->num_channels = $monochrome ? 1 : 3; + } else { + $this->data_was_skipped = true; + } + if ( !skip( $this->handle, $box->content_size - 3 ) ) { + return TRUNCATED; + } + } else if ( $box->type == 'auxC' ) { + // See AV1 Image File Format (AVIF) 4 + // at https://aomediacodec.github.io/av1-avif/#auxiliary-images + $kAlphaStr = "urn:mpeg:mpegB:cicp:systems:auxiliary:alpha\0"; + $kAlphaStrLength = 44; // Includes terminating character. + if ( $box->content_size >= $kAlphaStrLength ) { + if ( !( $data = read( $this->handle, $kAlphaStrLength ) ) ) { + return TRUNCATED; + } + if ( substr( $data, 0, $kAlphaStrLength ) == $kAlphaStr ) { + // Note: It is unlikely but it is possible that this alpha plane does + // not belong to the primary item or a tile. Ignore this issue. + $this->features->has_alpha = true; + } + if ( !skip( $this->handle, $box->content_size - $kAlphaStrLength ) ) { + return TRUNCATED; + } + } else { + if ( !skip( $this->handle, $box->content_size ) ) { + return TRUNCATED; + } + } + } else { + if ( !skip( $this->handle, $box->content_size ) ) { + return TRUNCATED; + } + } + ++$box_index; + $num_remaining_bytes -= $box->size; + } while ( $num_remaining_bytes > 0 ); + return NOT_FOUND; + } + + /** + * Parses an "iprp" box. + * + * The "ipco" box contain the properties which are linked to items by the "ipma" box. + * + * @param stream $handle The resource the box will be parsed from. + * @param int $num_remaining_bytes The number of bytes that should be available from the resource. + * @return Status FOUND on success or an error on failure. + */ + private function parse_iprp( $num_remaining_bytes ) { + do { + $box = new Box(); + $status = $box->parse( $this->handle, $this->num_parsed_boxes, $num_remaining_bytes ); + if ( $status != FOUND ) { + return $status; + } + + if ( $box->type == 'ipco' ) { + $status = $this->parse_ipco( $box->content_size ); + if ( $status != NOT_FOUND ) { + return $status; + } + } else if ( $box->type == 'ipma' ) { + // See ISO/IEC 23008-12:2017(E) 9.3.2 + $num_read_bytes = 4; + if ( $box->content_size < $num_read_bytes ) { + return INVALID; + } + if ( !( $data = read( $this->handle, $num_read_bytes ) ) ) { + return TRUNCATED; + } + $entry_count = read_big_endian( $data, 4 ); + $id_num_bytes = ( $box->version < 1 ) ? 2 : 4; + $index_num_bytes = ( $box->flags & 1 ) ? 2 : 1; + $essential_bit_mask = ( $box->flags & 1 ) ? 0x8000 : 0x80; + + for ( $entry = 0; $entry < $entry_count; ++$entry ) { + if ( $entry >= MAX_PROPS || + count( $this->features->props ) >= MAX_PROPS ) { + $this->data_was_skipped = true; + break; + } + $num_read_bytes += $id_num_bytes + 1; + if ( $box->content_size < $num_read_bytes ) { + return INVALID; + } + if ( !( $data = read( $this->handle, $id_num_bytes + 1 ) ) ) { + return TRUNCATED; + } + $item_id = read_big_endian( + substr( $data, 0, $id_num_bytes ), $id_num_bytes ); + $association_count = read_big_endian( + substr( $data, $id_num_bytes, 1 ), 1 ); + + for ( $property = 0; $property < $association_count; ++$property ) { + if ( $property >= MAX_PROPS || + count( $this->features->props ) >= MAX_PROPS ) { + $this->data_was_skipped = true; + break; + } + $num_read_bytes += $index_num_bytes; + if ( $box->content_size < $num_read_bytes ) { + return INVALID; + } + if ( !( $data = read( $this->handle, $index_num_bytes ) ) ) { + return TRUNCATED; + } + $value = read_big_endian( $data, $index_num_bytes ); + // $essential = ($value & $essential_bit_mask); // Unused. + $property_index = ( $value & ~$essential_bit_mask ); + if ( $property_index <= MAX_VALUE && $item_id <= MAX_VALUE ) { + $prop_count = count( $this->features->props ); + $this->features->props[$prop_count] = new Prop(); + $this->features->props[$prop_count]->property_index = $property_index; + $this->features->props[$prop_count]->item_id = $item_id; + } else { + $this->data_was_skipped = true; + } + } + if ( $property < $association_count ) { + break; // Do not read garbage. + } + } + + // If all features are available now, do not look further. + $status = $this->features->get_primary_item_features(); + if ( $status != NOT_FOUND ) { + return $status; + } + + // Mostly if 'data_was_skipped'. + if ( !skip( $this->handle, $box->content_size - $num_read_bytes ) ) { + return TRUNCATED; + } + } else { + if ( !skip( $this->handle, $box->content_size ) ) { + return TRUNCATED; + } + } + $num_remaining_bytes -= $box->size; + } while ( $num_remaining_bytes > 0 ); + return NOT_FOUND; + } + + /** + * Parses an "iref" box. + * + * The "dimg" boxes contain links between tiles and their parent items, which + * can be used to infer bit depth and number of channels for the primary item + * when the latter does not have these properties. + * + * @param stream $handle The resource the box will be parsed from. + * @param int $num_remaining_bytes The number of bytes that should be available from the resource. + * @return Status FOUND on success or an error on failure. + */ + private function parse_iref( $num_remaining_bytes ) { + do { + $box = new Box(); + $status = $box->parse( $this->handle, $this->num_parsed_boxes, $num_remaining_bytes ); + if ( $status != FOUND ) { + return $status; + } + + if ( $box->type == 'dimg' ) { + // See ISO/IEC 14496-12:2015(E) 8.11.12.2 + $num_bytes_per_id = ( $box->version == 0 ) ? 2 : 4; + $num_read_bytes = $num_bytes_per_id + 2; + if ( $box->content_size < $num_read_bytes ) { + return INVALID; + } + if ( !( $data = read( $this->handle, $num_read_bytes ) ) ) { + return TRUNCATED; + } + $from_item_id = read_big_endian( $data, $num_bytes_per_id ); + $reference_count = read_big_endian( substr( $data, $num_bytes_per_id, 2 ), 2 ); + + for ( $i = 0; $i < $reference_count; ++$i ) { + if ( $i >= MAX_TILES ) { + $this->data_was_skipped = true; + break; + } + $num_read_bytes += $num_bytes_per_id; + if ( $box->content_size < $num_read_bytes ) { + return INVALID; + } + if ( !( $data = read( $this->handle, $num_bytes_per_id ) ) ) { + return TRUNCATED; + } + $to_item_id = read_big_endian( $data, $num_bytes_per_id ); + $tile_count = count( $this->features->tiles ); + if ( $from_item_id <= MAX_VALUE && $to_item_id <= MAX_VALUE && + $tile_count < MAX_TILES ) { + $this->features->tiles[$tile_count] = new Tile(); + $this->features->tiles[$tile_count]->tile_item_id = $to_item_id; + $this->features->tiles[$tile_count]->parent_item_id = $from_item_id; + } else { + $this->data_was_skipped = true; + } + } + + // If all features are available now, do not look further. + $status = $this->features->get_primary_item_features(); + if ( $status != NOT_FOUND ) { + return $status; + } + + // Mostly if 'data_was_skipped'. + if ( !skip( $this->handle, $box->content_size - $num_read_bytes ) ) { + return TRUNCATED; + } + } else { + if ( !skip( $this->handle, $box->content_size ) ) { + return TRUNCATED; + } + } + $num_remaining_bytes -= $box->size; + } while ( $num_remaining_bytes > 0 ); + return NOT_FOUND; + } + + /** + * Parses a "meta" box. + * + * It looks for the primary item ID in the "pitm" box and recurses into other boxes + * to find its features. + * + * @param stream $handle The resource the box will be parsed from. + * @param int $num_remaining_bytes The number of bytes that should be available from the resource. + * @return Status FOUND on success or an error on failure. + */ + private function parse_meta( $num_remaining_bytes ) { + do { + $box = new Box(); + $status = $box->parse( $this->handle, $this->num_parsed_boxes, $num_remaining_bytes ); + if ( $status != FOUND ) { + return $status; + } + + if ( $box->type == 'pitm' ) { + // See ISO/IEC 14496-12:2015(E) 8.11.4.2 + $num_bytes_per_id = ( $box->version == 0 ) ? 2 : 4; + if ( $num_bytes_per_id > $num_remaining_bytes ) { + return INVALID; + } + if ( !( $data = read( $this->handle, $num_bytes_per_id ) ) ) { + return TRUNCATED; + } + $primary_item_id = read_big_endian( $data, $num_bytes_per_id ); + if ( $primary_item_id > MAX_VALUE ) { + return ABORTED; + } + $this->features->has_primary_item = true; + $this->features->primary_item_id = $primary_item_id; + if ( !skip( $this->handle, $box->content_size - $num_bytes_per_id ) ) { + return TRUNCATED; + } + } else if ( $box->type == 'iprp' ) { + $status = $this->parse_iprp( $box->content_size ); + if ( $status != NOT_FOUND ) { + return $status; + } + } else if ( $box->type == 'iref' ) { + $status = $this->parse_iref( $box->content_size ); + if ( $status != NOT_FOUND ) { + return $status; + } + } else { + if ( !skip( $this->handle, $box->content_size ) ) { + return TRUNCATED; + } + } + $num_remaining_bytes -= $box->size; + } while ( $num_remaining_bytes != 0 ); + // According to ISO/IEC 14496-12:2012(E) 8.11.1.1 there is at most one "meta". + return INVALID; + } + + /** + * Parses a file stream. + * + * The file type is checked through the "ftyp" box. + * + * @return bool True if the input stream is an AVIF bitstream or false. + */ + public function parse_ftyp() { + $box = new Box(); + $status = $box->parse( $this->handle, $this->num_parsed_boxes ); + if ( $status != FOUND ) { + return false; + } + + if ( $box->type != 'ftyp' ) { + return false; + } + // Iterate over brands. See ISO/IEC 14496-12:2012(E) 4.3.1 + if ( $box->content_size < 8 ) { + return false; + } + for ( $i = 0; $i + 4 <= $box->content_size; $i += 4 ) { + if ( !( $data = read( $this->handle, 4 ) ) ) { + return false; + } + if ( $i == 4 ) { + continue; // Skip minor_version. + } + if ( substr( $data, 0, 4 ) == 'avif' || substr( $data, 0, 4 ) == 'avis' ) { + return skip( $this->handle, $box->content_size - ( $i + 4 ) ); + } + if ( $i > 32 * 4 ) { + return false; // Be reasonable. + } + + } + return false; // No AVIF brand no good. + } + + /** + * Parses a file stream. + * + * Features are extracted from the "meta" box. + * + * @return bool True if the main features of the primary item were parsed or false. + */ + public function parse_file() { + $box = new Box(); + while ( $box->parse( $this->handle, $this->num_parsed_boxes ) == FOUND ) { + if ( $box->type === 'meta' ) { + if ( $this->parse_meta( $box->content_size ) != FOUND ) { + return false; + } + return true; + } + if ( !skip( $this->handle, $box->content_size ) ) { + return false; + } + } + return false; // No "meta" no good. + } +} diff --git a/wp-includes/class-wp-image-editor-gd.php b/wp-includes/class-wp-image-editor-gd.php index de079357fb..23331c7f19 100644 --- a/wp-includes/class-wp-image-editor-gd.php +++ b/wp-includes/class-wp-image-editor-gd.php @@ -71,6 +71,8 @@ class WP_Image_Editor_GD extends WP_Image_Editor { return ( $image_types & IMG_GIF ) != 0; case 'image/webp': return ( $image_types & IMG_WEBP ) != 0; + case 'image/avif': + return ( $image_types & IMG_AVIF ) != 0; } return false; @@ -111,6 +113,16 @@ class WP_Image_Editor_GD extends WP_Image_Editor { $this->image = @imagecreatefromstring( $file_contents ); } + // AVIF may not work with imagecreatefromstring(). + if ( + function_exists( 'imagecreatefromavif' ) && + ( 'image/avif' === wp_get_image_mime( $this->file ) ) + ) { + $this->image = @imagecreatefromavif( $this->file ); + } else { + $this->image = @imagecreatefromstring( $file_contents ); + } + if ( ! is_gd_image( $this->image ) ) { return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file ); } @@ -513,6 +525,10 @@ class WP_Image_Editor_GD extends WP_Image_Editor { if ( ! function_exists( 'imagewebp' ) || ! $this->make_image( $filename, 'imagewebp', array( $image, $filename, $this->get_quality() ) ) ) { return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) ); } + } elseif ( 'image/avif' == $mime_type ) { + if ( ! function_exists( 'imageavif' ) || ! $this->make_image( $filename, 'imageavif', array( $image, $filename, $this->get_quality() ) ) ) { + return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) ); + } } else { return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) ); } @@ -561,8 +577,17 @@ class WP_Image_Editor_GD extends WP_Image_Editor { if ( function_exists( 'imagewebp' ) ) { header( 'Content-Type: image/webp' ); return imagewebp( $this->image, null, $this->get_quality() ); + } else { + // Fall back to JPEG. + header( 'Content-Type: image/jpeg' ); + return imagejpeg( $this->image, null, $this->get_quality() ); } - // Fall back to the default if webp isn't supported. + case 'image/avif': + if ( function_exists( 'imageavif' ) ) { + header( 'Content-Type: image/avif' ); + return imageavif( $this->image, null, $this->get_quality() ); + } + // Fall back to JPEG. default: header( 'Content-Type: image/jpeg' ); return imagejpeg( $this->image, null, $this->get_quality() ); diff --git a/wp-includes/class-wp-image-editor-imagick.php b/wp-includes/class-wp-image-editor-imagick.php index 03fe0bca69..546ad3e799 100644 --- a/wp-includes/class-wp-image-editor-imagick.php +++ b/wp-includes/class-wp-image-editor-imagick.php @@ -219,6 +219,7 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { $this->image->setImageCompressionQuality( $quality ); } break; + case 'image/avif': default: $this->image->setImageCompressionQuality( $quality ); } @@ -256,6 +257,16 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { $height = $size['height']; } + /* + * If we still don't have the image size, fall back to `wp_getimagesize`. This ensures AVIF images + * are properly sized without affecting previous `getImageGeometry` behavior. + */ + if ( ( ! $width || ! $height ) && 'image/avif' === $this->mime_type ) { + $size = wp_getimagesize( $this->file ); + $width = $size[0]; + $height = $size[1]; + } + return parent::update_size( $width, $height ); } diff --git a/wp-includes/class-wp-image-editor.php b/wp-includes/class-wp-image-editor.php index 3c636dc6ba..6604685a02 100644 --- a/wp-includes/class-wp-image-editor.php +++ b/wp-includes/class-wp-image-editor.php @@ -318,6 +318,7 @@ abstract class WP_Image_Editor { $quality = 86; break; case 'image/jpeg': + case 'image/avif': default: $quality = $this->default_quality; } diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index 09905bee1b..2058a9e557 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -1263,7 +1263,7 @@ final class WP_Theme implements ArrayAccess { return false; } - foreach ( array( 'png', 'gif', 'jpg', 'jpeg', 'webp' ) as $ext ) { + foreach ( array( 'png', 'gif', 'jpg', 'jpeg', 'webp', 'avif' ) as $ext ) { if ( file_exists( $this->get_stylesheet_directory() . "/screenshot.$ext" ) ) { $this->cache_add( 'screenshot', 'screenshot.' . $ext ); if ( 'relative' === $uri ) { diff --git a/wp-includes/compat.php b/wp-includes/compat.php index 429c5f92e7..95c4af484d 100644 --- a/wp-includes/compat.php +++ b/wp-includes/compat.php @@ -529,3 +529,13 @@ if ( ! defined( 'IMAGETYPE_WEBP' ) ) { if ( ! defined( 'IMG_WEBP' ) ) { define( 'IMG_WEBP', IMAGETYPE_WEBP ); } + +// IMAGETYPE_AVIF constant is only defined in PHP 8.x or later. +if ( ! defined( 'IMAGETYPE_AVIF' ) ) { + define( 'IMAGETYPE_AVIF', 19 ); +} + +// IMG_AVIF constant is only defined in PHP 8.x or later. +if ( ! defined( 'IMG_AVIF' ) ) { + define( 'IMG_AVIF', IMAGETYPE_AVIF ); +} diff --git a/wp-includes/customize/class-wp-customize-media-control.php b/wp-includes/customize/class-wp-customize-media-control.php index f636892925..3bdc4e2dc1 100644 --- a/wp-includes/customize/class-wp-customize-media-control.php +++ b/wp-includes/customize/class-wp-customize-media-control.php @@ -93,7 +93,7 @@ class WP_Customize_Media_Control extends WP_Customize_Control { * Note that the default value must be a URL, NOT an attachment ID. */ $ext = substr( $this->setting->default, -3 ); - $type = in_array( $ext, array( 'jpg', 'png', 'gif', 'bmp', 'webp' ), true ) ? 'image' : 'document'; + $type = in_array( $ext, array( 'jpg', 'png', 'gif', 'bmp', 'webp', 'avif' ), true ) ? 'image' : 'document'; $default_attachment = array( 'id' => 1, diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 1fd62ae16e..45b4f89a9e 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -3336,7 +3336,9 @@ function gd_edit_image_support($mime_type) { return (imagetypes() & IMG_GIF) != 0; case 'image/webp': return (imagetypes() & IMG_WEBP) != 0; - } + case 'image/avif': + return (imagetypes() & IMG_AVIF) != 0; + } } else { switch( $mime_type ) { case 'image/jpeg': @@ -3347,6 +3349,8 @@ function gd_edit_image_support($mime_type) { return function_exists('imagecreatefromgif'); case 'image/webp': return function_exists('imagecreatefromwebp'); + case 'image/avif': + return function_exists('imagecreatefromavif'); } } return false; diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 05b103e6f7..ce8d035420 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -3464,7 +3464,7 @@ function translate_smiley( $matches ) { $matches = array(); $ext = preg_match( '/\.([^.]+)$/', $img, $matches ) ? strtolower( $matches[1] ) : false; - $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ); + $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp', 'avif' ); // Don't convert smilies that aren't images - they're probably emoji. if ( ! in_array( $ext, $image_exts, true ) ) { diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 94995206f1..17319c7f46 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3117,6 +3117,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { 'image/bmp' => 'bmp', 'image/tiff' => 'tif', 'image/webp' => 'webp', + 'image/avif' => 'avif', ) ); @@ -3295,6 +3296,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { * * @since 4.7.1 * @since 5.8.0 Added support for WebP images. + * @since 6.5.0 Added support for AVIF images. * * @param string $file Full path to the file. * @return string|false The actual mime type or false if the type cannot be determined. @@ -3349,6 +3351,25 @@ function wp_get_image_mime( $file ) { ) { $mime = 'image/webp'; } + + /** + * Add AVIF fallback detection when image library doesn't support AVIF. + * + * Detection based on section 4.3.1 File-type box definition of the ISO/IEC 14496-12 + * specification and the AV1-AVIF spec, see https://aomediacodec.github.io/av1-avif/v1.1.0.html#brands. + */ + + // Divide the header string into 4 byte groups. + $magic = str_split( $magic, 8 ); + + if ( + isset( $magic[1] ) && + isset( $magic[2] ) && + 'ftyp' === hex2bin( $magic[1] ) && + ( 'avif' === hex2bin( $magic[2] ) || 'avis' === hex2bin( $magic[2] ) ) + ) { + $mime = 'image/avif'; + } } catch ( Exception $e ) { $mime = false; } @@ -3388,6 +3409,7 @@ function wp_get_mime_types() { 'bmp' => 'image/bmp', 'tiff|tif' => 'image/tiff', 'webp' => 'image/webp', + 'avif' => 'image/avif', 'ico' => 'image/x-icon', 'heic' => 'image/heic', // Video formats. @@ -3509,7 +3531,7 @@ function wp_get_ext_types() { return apply_filters( 'ext2type', array( - 'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'webp' ), + 'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'webp', 'avif' ), 'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'flac', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ), 'video' => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ), 'document' => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf' ), diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index ca139ee13c..1c34e91003 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -1449,7 +1449,7 @@ Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar isImageAttachment: function( attachment ) { // If uploading, we know the filename but not the mime type. if ( attachment.get('uploading') ) { - return /\.(jpe?g|png|gif|webp)$/i.test( attachment.get('filename') ); + return /\.(jpe?g|png|gif|webp|avif)$/i.test( attachment.get('filename') ); } return attachment.get('type') === 'image'; diff --git a/wp-includes/js/media-views.min.js b/wp-includes/js/media-views.min.js index 0589034bd7..7935f8bd82 100644 --- a/wp-includes/js/media-views.min.js +++ b/wp-includes/js/media-views.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -(()=>{var i={1517:e=>{var s=wp.media.model.Selection,o=wp.media.controller.Library,t=o.extend({defaults:_.defaults({multiple:"add",filterable:"uploaded",priority:100,syncSelection:!1},o.prototype.defaults),initialize:function(){var e=this.get("collectionType");"video"===this.get("type")&&(e="video-"+e),this.set("id",e+"-library"),this.set("toolbar",e+"-add"),this.set("menu",e),this.get("library")||this.set("library",wp.media.query({type:this.get("type")})),o.prototype.initialize.apply(this,arguments)},activate:function(){var e=this.get("library"),t=this.get("editLibrary"),i=this.frame.state(this.get("collectionType")+"-edit").get("library");t&&t!==i&&e.unobserve(t),e.validator=function(e){return!!this.mirroring.get(e.cid)&&!i.get(e.cid)&&s.prototype.validator.apply(this,arguments)},e.reset(e.mirroring.models,{silent:!0}),e.observe(i),this.set("editLibrary",i),o.prototype.activate.apply(this,arguments)}});e.exports=t},1817:e=>{var t=wp.media.controller.Library,n=wp.media.view.l10n,r=jQuery,i=t.extend({defaults:{multiple:!1,sortable:!0,date:!1,searchable:!1,content:"browse",describe:!0,dragInfo:!0,idealColumnWidth:170,editing:!1,priority:60,SettingsView:!1,syncSelection:!1},initialize:function(){var e=this.get("collectionType");"video"===this.get("type")&&(e="video-"+e),this.set("id",e+"-edit"),this.set("toolbar",e+"-edit"),this.get("library")||this.set("library",new wp.media.model.Selection),this.get("AttachmentView")||this.set("AttachmentView",wp.media.view.Attachment.EditLibrary),t.prototype.initialize.apply(this,arguments)},activate:function(){this.get("library").props.set("type",this.get("type")),this.get("library").observe(wp.Uploader.queue),this.frame.on("content:render:browse",this.renderSettings,this),t.prototype.activate.apply(this,arguments)},deactivate:function(){this.get("library").unobserve(wp.Uploader.queue),this.frame.off("content:render:browse",this.renderSettings,this),t.prototype.deactivate.apply(this,arguments)},renderSettings:function(e){var t=this.get("library"),i=this.get("collectionType"),s=this.get("dragInfoText"),o=this.get("SettingsView"),a={};t&&e&&(t[i]=t[i]||new Backbone.Model,a[i]=new o({controller:this,model:t[i],priority:40}),e.sidebar.set(a),s&&e.toolbar.set("dragInfo",new wp.media.View({el:r('
'+s+"
")[0],priority:-40})),e.toolbar.set("reverse",{text:n.reverseOrder,priority:80,click:function(){t.reset(t.toArray().reverse())}}))}});e.exports=i},2288:e=>{var i=wp.media.view.l10n,t=wp.media.controller.State.extend({defaults:{id:"cropper",title:i.cropImage,toolbar:"crop",content:"crop",router:!1,canSkipCrop:!1,doCropArgs:{}},activate:function(){this.frame.on("content:create:crop",this.createCropContent,this),this.frame.on("close",this.removeCropper,this),this.set("selection",new Backbone.Collection(this.frame._selection.single))},deactivate:function(){this.frame.toolbar.mode("browse")},createCropContent:function(){this.cropperView=new wp.media.view.Cropper({controller:this,attachment:this.get("selection").first()}),this.cropperView.on("image-loaded",this.createCropToolbar,this),this.frame.content.set(this.cropperView)},removeCropper:function(){this.imgSelect.cancelSelection(),this.imgSelect.setOptions({remove:!0}),this.imgSelect.update(),this.cropperView.remove()},createCropToolbar:function(){var e=this.get("canSkipCrop")||!1,t={controller:this.frame,items:{insert:{style:"primary",text:i.cropImage,priority:80,requires:{library:!1,selection:!1},click:function(){var t=this.controller,e=t.state().get("selection").first();e.set({cropDetails:t.state().imgSelect.getSelection()}),this.$el.text(i.cropping),this.$el.attr("disabled",!0),t.state().doCrop(e).done(function(e){t.trigger("cropped",e),t.close()}).fail(function(){t.trigger("content:error:crop")})}}}};e&&_.extend(t.items,{skip:{style:"secondary",text:i.skipCropping,priority:70,requires:{library:!1,selection:!1},click:function(){var e=this.controller.state().get("selection").first();this.controller.state().cropperView.remove(),this.controller.trigger("skippedcrop",e),this.controller.close()}}}),this.frame.toolbar.set(new wp.media.view.Toolbar(t))},doCrop:function(e){return wp.ajax.post("custom-header-crop",_.extend({},this.defaults.doCropArgs,{nonce:e.get("nonces").edit,id:e.get("id"),cropDetails:e.get("cropDetails")}))}});e.exports=t},6934:e=>{var t=wp.media.controller.Cropper.extend({doCrop:function(e){var t=e.get("cropDetails"),i=this.get("control"),s=t.width/t.height;return i.params.flex_width&&i.params.flex_height?(t.dst_width=t.width,t.dst_height=t.height):(t.dst_width=i.params.flex_width?i.params.height*s:i.params.width,t.dst_height=i.params.flex_height?i.params.width/s:i.params.height),wp.ajax.post("crop-image",{wp_customize:"on",nonce:e.get("nonces").edit,id:e.get("id"),context:i.id,cropDetails:t})}});e.exports=t},7658:e=>{var s=wp.media.view.l10n,t=wp.media.controller.State.extend({defaults:{id:"edit-image",title:s.editImage,menu:!1,toolbar:"edit-image",content:"edit-image",url:""},activate:function(){this.frame.on("toolbar:render:edit-image",_.bind(this.toolbar,this))},deactivate:function(){this.frame.off("toolbar:render:edit-image")},toolbar:function(){var e=this.frame,t=e.lastState(),i=t&&t.id;e.toolbar.set(new wp.media.view.Toolbar({controller:e,items:{back:{style:"primary",text:s.back,priority:20,click:function(){i?e.setState(i):e.close()}}}}))}});e.exports=t},9067:e=>{var t=wp.media.view.l10n,n=Backbone.$,t=wp.media.controller.State.extend({defaults:{id:"embed",title:t.insertFromUrlTitle,content:"embed",menu:"default",toolbar:"main-embed",priority:120,type:"link",url:"",metadata:{}},sensitivity:400,initialize:function(e){this.metadata=e.metadata,this.debouncedScan=_.debounce(_.bind(this.scan,this),this.sensitivity),this.props=new Backbone.Model(this.metadata||{url:""}),this.props.on("change:url",this.debouncedScan,this),this.props.on("change:url",this.refresh,this),this.on("scan",this.scanImage,this)},scan:function(){var e,t=this,i={type:"link",scanners:[]};this.props.get("url")&&this.trigger("scan",i),i.scanners.length?(e=i.scanners=n.when.apply(n,i.scanners)).always(function(){t.get("scanners")===e&&t.set("loading",!1)}):i.scanners=null,i.loading=!!i.scanners,this.set(i)},scanImage:function(e){var t=this.frame,i=this,s=this.props.get("url"),o=new Image,a=n.Deferred();e.scanners.push(a.promise()),o.onload=function(){a.resolve(),i===t.state()&&s===i.props.get("url")&&(i.set({type:"image"}),i.props.set({width:o.width,height:o.height}))},o.onerror=a.reject,o.src=s},refresh:function(){this.frame.toolbar.get().refresh()},reset:function(){this.props.clear().set({url:""}),this.active&&this.refresh()}});e.exports=t},5095:e=>{var s=wp.media.model.Attachment,t=wp.media.controller.Library,i=wp.media.view.l10n,i=t.extend({defaults:_.defaults({id:"featured-image",title:i.setFeaturedImageTitle,multiple:!1,filterable:"uploaded",toolbar:"featured-image",priority:60,syncSelection:!0},t.prototype.defaults),initialize:function(){var e,o;this.get("library")||this.set("library",wp.media.query({type:"image"})),t.prototype.initialize.apply(this,arguments),e=this.get("library"),o=e.comparator,e.comparator=function(e,t){var i=!!this.mirroring.get(e.cid),s=!!this.mirroring.get(t.cid);return!i&&s?-1:i&&!s?1:o.apply(this,arguments)},e.observe(this.get("selection"))},activate:function(){this.frame.on("open",this.updateSelection,this),t.prototype.activate.apply(this,arguments)},deactivate:function(){this.frame.off("open",this.updateSelection,this),t.prototype.deactivate.apply(this,arguments)},updateSelection:function(){var e,t=this.get("selection"),i=wp.media.view.settings.post.featuredImageId;""!==i&&-1!==i&&(e=s.get(i)).fetch(),t.reset(e?[e]:[])}});e.exports=i},7323:e=>{var i=wp.media.model.Selection,s=wp.media.controller.Library,t=wp.media.view.l10n,t=s.extend({defaults:_.defaults({id:"gallery-library",title:t.addToGalleryTitle,multiple:"add",filterable:"uploaded",menu:"gallery",toolbar:"gallery-add",priority:100,syncSelection:!1},s.prototype.defaults),initialize:function(){this.get("library")||this.set("library",wp.media.query({type:"image"})),s.prototype.initialize.apply(this,arguments)},activate:function(){var e=this.get("library"),t=this.frame.state("gallery-edit").get("library");this.editLibrary&&this.editLibrary!==t&&e.unobserve(this.editLibrary),e.validator=function(e){return!!this.mirroring.get(e.cid)&&!t.get(e.cid)&&i.prototype.validator.apply(this,arguments)},e.reset(e.mirroring.models,{silent:!0}),e.observe(t),this.editLibrary=t,s.prototype.activate.apply(this,arguments)}});e.exports=t},6328:e=>{var t=wp.media.controller.Library,i=wp.media.view.l10n,s=t.extend({defaults:{id:"gallery-edit",title:i.editGalleryTitle,multiple:!1,searchable:!1,sortable:!0,date:!1,display:!1,content:"browse",toolbar:"gallery-edit",describe:!0,displaySettings:!0,dragInfo:!0,idealColumnWidth:170,editing:!1,priority:60,syncSelection:!1},initialize:function(){this.get("library")||this.set("library",new wp.media.model.Selection),this.get("AttachmentView")||this.set("AttachmentView",wp.media.view.Attachment.EditLibrary),t.prototype.initialize.apply(this,arguments)},activate:function(){this.get("library").props.set("type","image"),this.get("library").observe(wp.Uploader.queue),this.frame.on("content:render:browse",this.gallerySettings,this),t.prototype.activate.apply(this,arguments)},deactivate:function(){this.get("library").unobserve(wp.Uploader.queue),this.frame.off("content:render:browse",this.gallerySettings,this),t.prototype.deactivate.apply(this,arguments)},gallerySettings:function(e){var t;this.get("displaySettings")&&(t=this.get("library"))&&e&&(t.gallery=t.gallery||new Backbone.Model,e.sidebar.set({gallery:new wp.media.view.Settings.Gallery({controller:this,model:t.gallery,priority:40})}),e.toolbar.set("reverse",{text:i.reverseOrder,priority:80,click:function(){t.reset(t.toArray().reverse())}}))}});e.exports=s},3849:e=>{var t=wp.media.controller.State,i=wp.media.controller.Library,s=wp.media.view.l10n,s=t.extend({defaults:_.defaults({id:"image-details",title:s.imageDetailsTitle,content:"image-details",menu:!1,router:!1,toolbar:"image-details",editing:!1,priority:60},i.prototype.defaults),initialize:function(e){this.image=e.image,t.prototype.initialize.apply(this,arguments)},activate:function(){this.frame.modal.$el.addClass("image-details")}});e.exports=s},9024:e=>{var t=wp.media.view.l10n,i=window.getUserSetting,s=window.setUserSetting,t=wp.media.controller.State.extend({defaults:{id:"library",title:t.mediaLibraryTitle,multiple:!1,content:"upload",menu:"default",router:"browse",toolbar:"select",searchable:!0,filterable:!1,sortable:!0,autoSelect:!0,describe:!1,contentUserSetting:!0,syncSelection:!0},initialize:function(){var e=this.get("selection");this.get("library")||this.set("library",wp.media.query()),e instanceof wp.media.model.Selection||((e=e)||(e=this.get("library").props.toJSON(),e=_.omit(e,"orderby","query")),this.set("selection",new wp.media.model.Selection(null,{multiple:this.get("multiple"),props:e}))),this.resetDisplays()},activate:function(){this.syncSelection(),wp.Uploader.queue.on("add",this.uploading,this),this.get("selection").on("add remove reset",this.refreshContent,this),this.get("router")&&this.get("contentUserSetting")&&(this.frame.on("content:activate",this.saveContentMode,this),this.set("content",i("libraryContent",this.get("content"))))},deactivate:function(){this.recordSelection(),this.frame.off("content:activate",this.saveContentMode,this),this.get("selection").off(null,null,this),wp.Uploader.queue.off(null,null,this)},reset:function(){this.get("selection").reset(),this.resetDisplays(),this.refreshContent()},resetDisplays:function(){var e=wp.media.view.settings.defaultProps;this._displays=[],this._defaultDisplaySettings={align:i("align",e.align)||"none",size:i("imgsize",e.size)||"medium",link:i("urlbutton",e.link)||"none"}},display:function(e){var t=this._displays;return t[e.cid]||(t[e.cid]=new Backbone.Model(this.defaultDisplaySettings(e))),t[e.cid]},defaultDisplaySettings:function(e){var t=_.clone(this._defaultDisplaySettings);return t.canEmbed=this.canEmbed(e),t.canEmbed?t.link="embed":this.isImageAttachment(e)||"none"!==t.link||(t.link="file"),t},isImageAttachment:function(e){return e.get("uploading")?/\.(jpe?g|png|gif|webp)$/i.test(e.get("filename")):"image"===e.get("type")},canEmbed:function(e){if(!e.get("uploading")){var t=e.get("type");if("audio"!==t&&"video"!==t)return!1}return _.contains(wp.media.view.settings.embedExts,e.get("filename").split(".").pop())},refreshContent:function(){var e=this.get("selection"),t=this.frame,i=t.router.get(),t=t.content.mode();this.active&&!e.length&&i&&!i.get(t)&&this.frame.content.render(this.get("content"))},uploading:function(e){"upload"===this.frame.content.mode()&&this.frame.content.mode("browse"),this.get("autoSelect")&&(this.get("selection").add(e),this.frame.trigger("library:selection:add"))},saveContentMode:function(){var e,t;"browse"===this.get("router")&&(e=this.frame.content.mode(),t=this.frame.router.get())&&t.get(e)&&s("libraryContent",e)}});_.extend(t.prototype,wp.media.selectionSync),e.exports=t},3742:e=>{var t=wp.media.controller.Library,i=t.extend({defaults:_.defaults({filterable:"uploaded",displaySettings:!1,priority:80,syncSelection:!1},t.prototype.defaults),initialize:function(e){this.media=e.media,this.type=e.type,this.set("library",wp.media.query({type:this.type})),t.prototype.initialize.apply(this,arguments)},activate:function(){wp.media.frame.lastMime&&(this.set("library",wp.media.query({type:wp.media.frame.lastMime})),delete wp.media.frame.lastMime),t.prototype.activate.apply(this,arguments)}});e.exports=i},4903:e=>{function t(e){_.extend(this,_.pick(e||{},"id","view","selector"))}t.extend=Backbone.Model.extend,_.extend(t.prototype,{mode:function(e){return e?(e!==this._mode&&(this.trigger("deactivate"),this._mode=e,this.render(e),this.trigger("activate")),this):this._mode},render:function(e){return e&&e!==this._mode?this.mode(e):(this.trigger("create",e={view:null}),this.trigger("render",e=e.view),e&&this.set(e),this)},get:function(){return this.view.views.first(this.selector)},set:function(e,t){return t&&(t.add=!1),this.view.views.set(this.selector,e,t)},trigger:function(e){var t,i;if(this._mode)return i=_.toArray(arguments),t=this.id+":"+e,i[0]=t+":"+this._mode,this.view.trigger.apply(this.view,i),i[0]=t,this.view.trigger.apply(this.view,i),this}}),e.exports=t},8493:e=>{var i=wp.media.controller.Library,t=wp.media.view.l10n,t=i.extend({defaults:_.defaults({id:"replace-image",title:t.replaceImageTitle,multiple:!1,filterable:"uploaded",toolbar:"replace",menu:!1,priority:60,syncSelection:!0},i.prototype.defaults),initialize:function(e){var t,o;this.image=e.image,this.get("library")||this.set("library",wp.media.query({type:"image"})),i.prototype.initialize.apply(this,arguments),t=this.get("library"),o=t.comparator,t.comparator=function(e,t){var i=!!this.mirroring.get(e.cid),s=!!this.mirroring.get(t.cid);return!i&&s?-1:i&&!s?1:o.apply(this,arguments)},t.observe(this.get("selection"))},activate:function(){this.frame.on("content:render:browse",this.updateSelection,this),i.prototype.activate.apply(this,arguments)},deactivate:function(){this.frame.off("content:render:browse",this.updateSelection,this),i.prototype.deactivate.apply(this,arguments)},updateSelection:function(){var e=this.get("selection"),t=this.image.attachment;e.reset(t?[t]:[])}});e.exports=t},5274:e=>{var t=wp.media.controller.Cropper.extend({activate:function(){this.frame.on("content:create:crop",this.createCropContent,this),this.frame.on("close",this.removeCropper,this),this.set("selection",new Backbone.Collection(this.frame._selection.single))},createCropContent:function(){this.cropperView=new wp.media.view.SiteIconCropper({controller:this,attachment:this.get("selection").first()}),this.cropperView.on("image-loaded",this.createCropToolbar,this),this.frame.content.set(this.cropperView)},doCrop:function(e){var t=e.get("cropDetails"),i=this.get("control");return t.dst_width=i.params.width,t.dst_height=i.params.height,wp.ajax.post("crop-image",{nonce:e.get("nonces").edit,id:e.get("id"),context:"site-icon",cropDetails:t})}});e.exports=t},5466:e=>{function t(){return{extend:Backbone.Model.extend}}_.extend(t.prototype,Backbone.Events,{state:function(e){return this.states=this.states||new Backbone.Collection,(e=e||this._state)&&!this.states.get(e)&&this.states.add({id:e}),this.states.get(e)},setState:function(e){var t=this.state();return t&&e===t.id||!this.states||!this.states.get(e)||(t&&(t.trigger("deactivate"),this._lastState=t.id),this._state=e,this.state().trigger("activate")),this},lastState:function(){if(this._lastState)return this.state(this._lastState)}}),_.each(["on","off","trigger"],function(e){t.prototype[e]=function(){return this.states=this.states||new Backbone.Collection,this.states[e].apply(this.states,arguments),this}}),e.exports=t},5826:e=>{var i=Backbone.Model.extend({constructor:function(){this.on("activate",this._preActivate,this),this.on("activate",this.activate,this),this.on("activate",this._postActivate,this),this.on("deactivate",this._deactivate,this),this.on("deactivate",this.deactivate,this),this.on("reset",this.reset,this),this.on("ready",this._ready,this),this.on("ready",this.ready,this),Backbone.Model.apply(this,arguments),this.on("change:menu",this._updateMenu,this)},ready:function(){},activate:function(){},deactivate:function(){},reset:function(){},_ready:function(){this._updateMenu()},_preActivate:function(){this.active=!0},_postActivate:function(){this.on("change:menu",this._menu,this),this.on("change:titleMode",this._title,this),this.on("change:content",this._content,this),this.on("change:toolbar",this._toolbar,this),this.frame.on("title:render:default",this._renderTitle,this),this._title(),this._menu(),this._toolbar(),this._content(),this._router()},_deactivate:function(){this.active=!1,this.frame.off("title:render:default",this._renderTitle,this),this.off("change:menu",this._menu,this),this.off("change:titleMode",this._title,this),this.off("change:content",this._content,this),this.off("change:toolbar",this._toolbar,this)},_title:function(){this.frame.title.render(this.get("titleMode")||"default")},_renderTitle:function(e){e.$el.text(this.get("title")||"")},_router:function(){var e=this.frame.router,t=this.get("router");this.frame.$el.toggleClass("hide-router",!t),t&&(this.frame.router.render(t),t=e.get())&&t.select&&t.select(this.frame.content.mode())},_menu:function(){var e=this.frame.menu,t=this.get("menu");this.frame.$el.toggleClass("hide-menu",!t),t&&(e.mode(t),t=e.get())&&t.select&&t.select(this.id)},_updateMenu:function(){var e=this.previous("menu"),t=this.get("menu");e&&this.frame.off("menu:render:"+e,this._renderMenu,this),t&&this.frame.on("menu:render:"+t,this._renderMenu,this)},_renderMenu:function(e){var t=this.get("menuItem"),i=this.get("title"),s=this.get("priority");!t&&i&&(t={text:i},s)&&(t.priority=s),t&&e.set(this.id,t)}});_.each(["toolbar","content"],function(t){i.prototype["_"+t]=function(){var e=this.get(t);e&&this.frame[t].render(e)}}),e.exports=i},3526:e=>{e.exports={syncSelection:function(){var e=this.get("selection"),t=this.frame._selection;this.get("syncSelection")&&t&&e&&(e.multiple&&(e.reset([],{silent:!0}),e.validateAll(t.attachments),t.difference=_.difference(t.attachments.models,e.models)),e.single(t.single))},recordSelection:function(){var e=this.get("selection"),t=this.frame._selection;this.get("syncSelection")&&t&&e&&(e.multiple?(t.attachments.reset(e.toArray().concat(t.difference)),t.difference=[]):t.attachments.add(e.toArray()),t.single=e._single)}}},8093:e=>{var t=wp.media.View,i=t.extend({tagName:"form",className:"compat-item",events:{submit:"preventDefault","change input":"save","change select":"save","change textarea":"save"},initialize:function(){this.listenTo(this.model,"add",this.render)},dispose:function(){return this.$(":focus").length&&this.save(),t.prototype.dispose.apply(this,arguments)},render:function(){var e=this.model.get("compat");if(e&&e.item)return this.views.detach(),this.$el.html(e.item),this.views.render(),this},preventDefault:function(e){e.preventDefault()},save:function(e){var t={};e&&e.preventDefault(),_.each(this.$el.serializeArray(),function(e){t[e.name]=e.value}),this.controller.trigger("attachment:compat:waiting",["waiting"]),this.model.saveCompat(t).always(_.bind(this.postSave,this))},postSave:function(){this.controller.trigger("attachment:compat:ready",["ready"])}});e.exports=i},4906:e=>{var i=jQuery,t=wp.media.View.extend({tagName:"select",className:"attachment-filters",id:"media-attachment-filters",events:{change:"change"},keys:[],initialize:function(){this.createFilters(),_.extend(this.filters,this.options.filters),this.$el.html(_.chain(this.filters).map(function(e,t){return{el:i("").val(t).html(e.text)[0],priority:e.priority||50}},this).sortBy("priority").pluck("el").value()),this.listenTo(this.model,"change",this.select),this.select()},createFilters:function(){this.filters={}},change:function(){var e=this.filters[this.el.value];e&&this.model.set(e.props)},select:function(){var e=this.model,i="all",s=e.toJSON();_.find(this.filters,function(e,t){if(_.all(e.props,function(e,t){return e===(_.isUndefined(s[t])?null:s[t])}))return i=t}),this.$el.val(i)}});e.exports=t},2868:e=>{var t=wp.media.view.l10n,i=wp.media.view.AttachmentFilters.extend({createFilters:function(){var i={},e=window.userSettings?parseInt(window.userSettings.uid,10):0;_.each(wp.media.view.settings.mimeTypes||{},function(e,t){i[t]={text:e,props:{status:null,type:t,uploadedTo:null,orderby:"date",order:"DESC",author:null}}}),i.all={text:t.allMediaItems,props:{status:null,type:null,uploadedTo:null,orderby:"date",order:"DESC",author:null},priority:10},wp.media.view.settings.post.id&&(i.uploaded={text:t.uploadedToThisPost,props:{status:null,type:null,uploadedTo:wp.media.view.settings.post.id,orderby:"menuOrder",order:"ASC",author:null},priority:20}),i.unattached={text:t.unattached,props:{status:null,uploadedTo:0,type:null,orderby:"menuOrder",order:"ASC",author:null},priority:50},e&&(i.mine={text:t.mine,props:{status:null,type:null,uploadedTo:null,orderby:"date",order:"DESC",author:e},priority:50}),wp.media.view.settings.mediaTrash&&this.controller.isModeActive("grid")&&(i.trash={text:t.trash,props:{uploadedTo:null,status:"trash",type:null,orderby:"date",order:"DESC",author:null},priority:50}),this.filters=i}});e.exports=i},9663:e=>{var t=wp.media.view.l10n,i=wp.media.view.AttachmentFilters.extend({id:"media-attachment-date-filters",createFilters:function(){var i={};_.each(wp.media.view.settings.months||{},function(e,t){i[t]={text:e.text,props:{year:e.year,monthnum:e.month}}}),i.all={text:t.allDates,props:{monthnum:!1,year:!1},priority:10},this.filters=i}});e.exports=i},7040:e=>{var o=wp.media.view.l10n,t=wp.media.view.AttachmentFilters.extend({createFilters:function(){var e,t=this.model.get("type"),i=wp.media.view.settings.mimeTypes,s=window.userSettings?parseInt(window.userSettings.uid,10):0;i&&t&&(e=i[t]),this.filters={all:{text:e||o.allMediaItems,props:{uploadedTo:null,orderby:"date",order:"DESC",author:null},priority:10},uploaded:{text:o.uploadedToThisPost,props:{uploadedTo:wp.media.view.settings.post.id,orderby:"menuOrder",order:"ASC",author:null},priority:20},unattached:{text:o.unattached,props:{uploadedTo:0,orderby:"menuOrder",order:"ASC",author:null},priority:50}},s&&(this.filters.mine={text:o.mine,props:{orderby:"date",order:"DESC",author:s},priority:50})}});e.exports=t},5019:e=>{var t=wp.media.View,o=jQuery,i=t.extend({tagName:"li",className:"attachment",template:wp.template("attachment"),attributes:function(){return{tabIndex:0,role:"checkbox","aria-label":this.model.get("title"),"aria-checked":!1,"data-id":this.model.get("id")}},events:{click:"toggleSelectionHandler","change [data-setting]":"updateSetting","change [data-setting] input":"updateSetting","change [data-setting] select":"updateSetting","change [data-setting] textarea":"updateSetting","click .attachment-close":"removeFromLibrary","click .check":"checkClickHandler",keydown:"toggleSelectionHandler"},buttons:{},initialize:function(){var e=this.options.selection;_.defaults(this.options,{rerenderOnModelChange:!0}).rerenderOnModelChange?this.listenTo(this.model,"change",this.render):this.listenTo(this.model,"change:percent",this.progress),this.listenTo(this.model,"change:title",this._syncTitle),this.listenTo(this.model,"change:caption",this._syncCaption),this.listenTo(this.model,"change:artist",this._syncArtist),this.listenTo(this.model,"change:album",this._syncAlbum),this.listenTo(this.model,"add",this.select),this.listenTo(this.model,"remove",this.deselect),e&&(e.on("reset",this.updateSelect,this),this.listenTo(this.model,"selection:single selection:unsingle",this.details),this.details(this.model,this.controller.state().get("selection"))),this.listenTo(this.controller.states,"attachment:compat:waiting attachment:compat:ready",this.updateSave)},dispose:function(){var e=this.options.selection;return this.updateAll(),e&&e.off(null,null,this),t.prototype.dispose.apply(this,arguments),this},render:function(){var e=_.defaults(this.model.toJSON(),{orientation:"landscape",uploading:!1,type:"",subtype:"",icon:"",filename:"",caption:"",title:"",dateFormatted:"",width:"",height:"",compat:!1,alt:"",description:""},this.options);return e.buttons=this.buttons,e.describe=this.controller.state().get("describe"),"image"===e.type&&(e.size=this.imageSize()),e.can={},e.nonces&&(e.can.remove=!!e.nonces.delete,e.can.save=!!e.nonces.update),this.controller.state().get("allowLocalEdits")&&!e.uploading&&(e.allowLocalEdits=!0),e.uploading&&!e.percent&&(e.percent=0),this.views.detach(),this.$el.html(this.template(e)),this.$el.toggleClass("uploading",e.uploading),e.uploading?this.$bar=this.$(".media-progress-bar div"):delete this.$bar,this.updateSelect(),this.updateSave(),this.views.render(),this},progress:function(){this.$bar&&this.$bar.length&&this.$bar.width(this.model.get("percent")+"%")},toggleSelectionHandler:function(e){var t;if("INPUT"!==e.target.nodeName&&"BUTTON"!==e.target.nodeName)if(37===e.keyCode||38===e.keyCode||39===e.keyCode||40===e.keyCode)this.controller.trigger("attachment:keydown:arrow",e);else if("keydown"!==e.type||13===e.keyCode||32===e.keyCode){if(e.preventDefault(),this.controller.isModeActive("grid")){if(this.controller.isModeActive("edit"))return void this.controller.trigger("edit:attachment",this.model,e.currentTarget);this.controller.isModeActive("select")&&(t="toggle")}e.shiftKey?t="between":(e.ctrlKey||e.metaKey)&&(t="toggle"),this.toggleSelection({method:t}),this.controller.trigger("selection:toggle")}},toggleSelection:function(e){var t,i,s,o=this.collection,a=this.options.selection,n=this.model,e=e&&e.method;if(a){if(t=a.single(),"between"===(e=_.isUndefined(e)?a.multiple:e)&&t&&a.multiple)return t===n?void 0:(o=(i=o.indexOf(t))<(s=o.indexOf(this.model))?o.models.slice(i,s+1):o.models.slice(s,i+1),a.add(o),void a.single(n));"toggle"===e?(a[this.selected()?"remove":"add"](n),a.single(n)):"add"===e?(a.add(n),a.single(n)):("add"!==(e=e||"add")&&(e="reset"),this.selected()?a[t===n?"remove":"single"](n):(a[e](n),a.single(n)))}},updateSelect:function(){this[this.selected()?"select":"deselect"]()},selected:function(){var e=this.options.selection;if(e)return!!e.get(this.model.cid)},select:function(e,t){var i=this.options.selection,s=this.controller;!i||t&&t!==i||this.$el.hasClass("selected")||(this.$el.addClass("selected").attr("aria-checked",!0),s.isModeActive("grid")&&s.isModeActive("select"))||this.$(".check").attr("tabindex","0")},deselect:function(e,t){var i=this.options.selection;!i||t&&t!==i||this.$el.removeClass("selected").attr("aria-checked",!1).find(".check").attr("tabindex","-1")},details:function(e,t){var i=this.options.selection;i===t&&(t=i.single(),this.$el.toggleClass("details",t===this.model))},imageSize:function(e){var t=this.model.get("sizes"),i=!1;return e=e||"medium",t&&(t[e]?i=t[e]:t.large?i=t.large:t.thumbnail?i=t.thumbnail:t.full&&(i=t.full),i)?_.clone(i):{url:this.model.get("url"),width:this.model.get("width"),height:this.model.get("height"),orientation:this.model.get("orientation")}},updateSetting:function(e){var t=o(e.target).closest("[data-setting]");t.length&&(t=t.data("setting"),e=e.target.value,this.model.get(t)!==e)&&this.save(t,e)},save:function(){var e=this,t=this._save=this._save||{status:"ready"},i=this.model.save.apply(this.model,arguments),s=t.requests?o.when(i,t.requests):i;t.savedTimer&&clearTimeout(t.savedTimer),this.updateSave("waiting"),(t.requests=s).always(function(){t.requests===s&&(e.updateSave("resolved"===s.state()?"complete":"error"),t.savedTimer=setTimeout(function(){e.updateSave("ready"),delete t.savedTimer},2e3))})},updateSave:function(e){var t=this._save=this._save||{status:"ready"};return e&&e!==t.status&&(this.$el.removeClass("save-"+t.status),t.status=e),this.$el.addClass("save-"+t.status),this},updateAll:function(){var e=this.$("[data-setting]"),i=this.model,e=_.chain(e).map(function(e){var t=o("input, textarea, select, [value]",e);if(t.length)return e=o(e).data("setting"),t=t.val(),i.get(e)!==t?[e,t]:void 0}).compact().object().value();_.isEmpty(e)||i.save(e)},removeFromLibrary:function(e){"keydown"===e.type&&13!==e.keyCode&&32!==e.keyCode||(e.stopPropagation(),this.collection.remove(this.model))},checkClickHandler:function(e){var t=this.options.selection;t&&(e.stopPropagation(),t.where({id:this.model.get("id")}).length?(t.remove(this.model),this.$el.focus()):t.add(this.model),this.controller.trigger("selection:toggle"))}});_.each({caption:"_syncCaption",title:"_syncTitle",artist:"_syncArtist",album:"_syncAlbum"},function(e,s){i.prototype[e]=function(e,t){var i=this.$('[data-setting="'+s+'"]');return!i.length||t===i.find("input, textarea, select, [value]").val()?this:this.render()}}),e.exports=i},7274:e=>{var t=wp.media.view.Attachment,i=wp.media.view.l10n,o=jQuery,a=wp.i18n.__,s=t.extend({tagName:"div",className:"attachment-details",template:wp.template("attachment-details"),attributes:{},events:{"change [data-setting]":"updateSetting","change [data-setting] input":"updateSetting","change [data-setting] select":"updateSetting","change [data-setting] textarea":"updateSetting","click .delete-attachment":"deleteAttachment","click .trash-attachment":"trashAttachment","click .untrash-attachment":"untrashAttachment","click .edit-attachment":"editAttachment",keydown:"toggleSelectionHandler"},copyAttachmentDetailsURLClipboard:function(){var s;new ClipboardJS(".copy-attachment-url").on("success",function(e){var t=o(e.trigger),i=o(".success",t.closest(".copy-to-clipboard-container"));e.clearSelection(),clearTimeout(s),i.removeClass("hidden"),s=setTimeout(function(){i.addClass("hidden")},3e3),wp.a11y.speak(a("The file URL has been copied to your clipboard"))})},initialize:function(){this.options=_.defaults(this.options,{rerenderOnModelChange:!1}),t.prototype.initialize.apply(this,arguments),this.copyAttachmentDetailsURLClipboard()},getFocusableElements:function(){var e=o('li[data-id="'+this.model.id+'"]');this.previousAttachment=e.prev(),this.nextAttachment=e.next()},moveFocus:function(){this.previousAttachment.length?this.previousAttachment.trigger("focus"):this.nextAttachment.length?this.nextAttachment.trigger("focus"):this.controller.uploader&&this.controller.uploader.$browser?this.controller.uploader.$browser.trigger("focus"):this.moveFocusToLastFallback()},moveFocusToLastFallback:function(){o(".media-frame").attr("tabindex","-1").trigger("focus")},deleteAttachment:function(e){e.preventDefault(),this.getFocusableElements(),window.confirm(i.warnDelete)&&(this.model.destroy({wait:!0,error:function(){window.alert(i.errorDeleting)}}),this.moveFocus())},trashAttachment:function(e){var t=this.controller.library,i=this;e.preventDefault(),this.getFocusableElements(),wp.media.view.settings.mediaTrash&&"edit-metadata"===this.controller.content.mode()?(this.model.set("status","trash"),this.model.save().done(function(){t._requery(!0),i.moveFocusToLastFallback()})):(this.model.destroy(),this.moveFocus())},untrashAttachment:function(e){var t=this.controller.library;e.preventDefault(),this.model.set("status","inherit"),this.model.save().done(function(){t._requery(!0)})},editAttachment:function(e){var t=this.controller.states.get("edit-image");window.imageEdit&&t?(e.preventDefault(),t.set("image",this.model),this.controller.setState("edit-image")):this.$el.addClass("needs-refresh")},toggleSelectionHandler:function(e){if("keydown"===e.type&&9===e.keyCode&&e.shiftKey&&e.target===this.$(":tabbable").get(0))return this.controller.trigger("attachment:details:shift-tab",e),!1},render:function(){t.prototype.render.apply(this,arguments),wp.media.mixin.removeAllPlayers(),this.$("audio, video").each(function(e,t){t=wp.media.view.MediaDetails.prepareSrc(t);new window.MediaElementPlayer(t,wp.media.mixin.mejsSettings)})}});e.exports=s},4640:e=>{var t=wp.media.view.Attachment.extend({buttons:{close:!0}});e.exports=t},1009:e=>{var t=wp.media.view.Attachment.Selection.extend({buttons:{close:!0}});e.exports=t},9254:e=>{var t=wp.media.view.Attachment.extend({buttons:{check:!0}});e.exports=t},9003:e=>{var t=wp.media.view.Attachment.extend({className:"attachment selection",toggleSelection:function(){this.options.selection.single(this.model)}});e.exports=t},8408:e=>{var t=wp.media.View,a=jQuery,i=wp.media.view.settings.infiniteScrolling,s=t.extend({tagName:"ul",className:"attachments",attributes:{tabIndex:-1},initialize:function(){this.el.id=_.uniqueId("__attachments-view-"),_.defaults(this.options,{infiniteScrolling:i||!1,refreshSensitivity:wp.media.isTouchDevice?300:200,refreshThreshold:3,AttachmentView:wp.media.view.Attachment,sortable:!1,resize:!0,idealColumnWidth:a(window).width()<640?135:150}),this._viewsByCid={},this.$window=a(window),this.resizeEvent="resize.media-modal-columns",this.collection.on("add",function(e){this.views.add(this.createAttachmentView(e),{at:this.collection.indexOf(e)})},this),this.collection.on("remove",function(e){var t=this._viewsByCid[e.cid];delete this._viewsByCid[e.cid],t&&t.remove()},this),this.collection.on("reset",this.render,this),this.controller.on("library:selection:add",this.attachmentFocus,this),this.options.infiniteScrolling&&(this.scroll=_.chain(this.scroll).bind(this).throttle(this.options.refreshSensitivity).value(),this.options.scrollElement=this.options.scrollElement||this.el,a(this.options.scrollElement).on("scroll",this.scroll)),this.initSortable(),_.bindAll(this,"setColumns"),this.options.resize&&(this.on("ready",this.bindEvents),this.controller.on("open",this.setColumns),_.defer(this.setColumns,this))},bindEvents:function(){this.$window.off(this.resizeEvent).on(this.resizeEvent,_.debounce(this.setColumns,50))},attachmentFocus:function(){this.columns&&this.$el.focus()},restoreFocus:function(){this.$("li.selected:first").focus()},arrowEvent:function(e){var t=this.$el.children("li"),i=this.columns,s=t.filter(":focus").index(),o=s+1<=i?1:Math.ceil((s+1)/i);if(-1!==s){if(37===e.keyCode){if(0===s)return;t.eq(s-1).focus()}if(38===e.keyCode){if(1===o)return;t.eq(s-i).focus()}if(39===e.keyCode){if(t.length===s)return;t.eq(s+1).focus()}40===e.keyCode&&Math.ceil(t.length/i)!==o&&t.eq(s+i).focus()}},dispose:function(){this.collection.props.off(null,null,this),this.options.resize&&this.$window.off(this.resizeEvent),t.prototype.dispose.apply(this,arguments)},setColumns:function(){var e=this.columns,t=this.$el.width();t&&(this.columns=Math.min(Math.round(t/this.options.idealColumnWidth),12)||1,e&&e===this.columns||this.$el.closest(".media-frame-content").attr("data-columns",this.columns))},initSortable:function(){var o=this.collection;this.options.sortable&&a.fn.sortable&&(this.$el.sortable(_.extend({disabled:!!o.comparator,tolerance:"pointer",start:function(e,t){t.item.data("sortableIndexStart",t.item.index())},update:function(e,t){var i=o.at(t.item.data("sortableIndexStart")),s=o.comparator;delete o.comparator,o.remove(i,{silent:!0}),o.add(i,{silent:!0,at:t.item.index()}),o.comparator=s,o.trigger("reset",o),o.saveMenuOrder()}},this.options.sortable)),o.props.on("change:orderby",function(){this.$el.sortable("option","disabled",!!o.comparator)},this),this.collection.props.on("change:orderby",this.refreshSortable,this),this.refreshSortable())},refreshSortable:function(){var e;this.options.sortable&&a.fn.sortable&&(e="menuOrder"===(e=this.collection).props.get("orderby")||!e.comparator,this.$el.sortable("option","disabled",!e))},createAttachmentView:function(e){var t=new this.options.AttachmentView({controller:this.controller,model:e,collection:this.collection,selection:this.options.selection});return this._viewsByCid[e.cid]=t},prepare:function(){this.collection.length?this.views.set(this.collection.map(this.createAttachmentView,this)):(this.views.unset(),this.options.infiniteScrolling&&this.collection.more().done(this.scroll))},ready:function(){this.options.infiniteScrolling&&this.scroll()},scroll:function(){var e,t=this,i=this.options.scrollElement,s=i.scrollTop;i===document&&(i=document.body,s=a(document).scrollTop()),a(i).is(":visible")&&this.collection.hasMore()&&(e=this.views.parent.toolbar,i.scrollHeight-(s+i.clientHeight){var s=wp.media.View,o=wp.media.view.settings.mediaTrash,a=wp.media.view.l10n,n=jQuery,i=wp.media.view.settings.infiniteScrolling,r=wp.i18n.__,t=wp.i18n.sprintf,l=s.extend({tagName:"div",className:"attachments-browser",initialize:function(){_.defaults(this.options,{filters:!1,search:!0,date:!0,display:!1,sidebar:!0,AttachmentView:wp.media.view.Attachment.Library}),this.controller.on("toggle:upload:attachment",this.toggleUploader,this),this.controller.on("edit:selection",this.editSelection),this.options.sidebar&&"errors"===this.options.sidebar&&this.createSidebar(),this.controller.isModeActive("grid")?(this.createUploader(),this.createToolbar()):(this.createToolbar(),this.createUploader()),this.createAttachmentsHeading(),this.createAttachmentsWrapperView(),i||(this.$el.addClass("has-load-more"),this.createLoadMoreView()),this.options.sidebar&&"errors"!==this.options.sidebar&&this.createSidebar(),this.updateContent(),i||this.updateLoadMoreView(),this.options.sidebar&&"errors"!==this.options.sidebar||(this.$el.addClass("hide-sidebar"),"errors"===this.options.sidebar&&this.$el.addClass("sidebar-for-errors")),this.collection.on("add remove reset",this.updateContent,this),i||this.collection.on("add remove reset",this.updateLoadMoreView,this),this.collection.on("attachments:received",this.announceSearchResults,this)},announceSearchResults:_.debounce(function(){var e,t=r("Number of media items displayed: %d. Click load more for more results.");i&&(t=r("Number of media items displayed: %d. Scroll the page for more results.")),this.collection.mirroring&&this.collection.mirroring.args.s&&(0===(e=this.collection.length)?wp.a11y.speak(a.noMediaTryNewSearch):this.collection.hasMore()?wp.a11y.speak(t.replace("%d",e)):wp.a11y.speak(a.mediaFound.replace("%d",e)))},200),editSelection:function(e){e.$(".media-button-backToLibrary").focus()},dispose:function(){return this.options.selection.off(null,null,this),s.prototype.dispose.apply(this,arguments),this},createToolbar:function(){var e,t=-1!==n.inArray(this.options.filters,["uploaded","all"]),i={controller:this.controller};this.controller.isModeActive("grid")&&(i.className="media-toolbar wp-filter"),this.toolbar=new wp.media.view.Toolbar(i),this.views.add(this.toolbar),this.toolbar.set("spinner",new wp.media.view.Spinner({priority:-20})),(t||this.options.date)&&this.toolbar.set("filters-heading",new wp.media.view.Heading({priority:-100,text:a.filterAttachments,level:"h2",className:"media-attachments-filter-heading"}).render()),t&&(this.toolbar.set("filtersLabel",new wp.media.view.Label({value:a.filterByType,attributes:{for:"media-attachment-filters"},priority:-80}).render()),"uploaded"===this.options.filters?this.toolbar.set("filters",new wp.media.view.AttachmentFilters.Uploaded({controller:this.controller,model:this.collection.props,priority:-80}).render()):(e=new wp.media.view.AttachmentFilters.All({controller:this.controller,model:this.collection.props,priority:-80}),this.toolbar.set("filters",e.render()))),this.controller.isModeActive("grid")?(i=s.extend({className:"view-switch media-grid-view-switch",template:wp.template("media-library-view-switcher")}),this.toolbar.set("libraryViewSwitcher",new i({controller:this.controller,priority:-90}).render()),this.toolbar.set("dateFilterLabel",new wp.media.view.Label({value:a.filterByDate,attributes:{for:"media-attachment-date-filters"},priority:-75}).render()),this.toolbar.set("dateFilter",new wp.media.view.DateFilter({controller:this.controller,model:this.collection.props,priority:-75}).render()),this.toolbar.set("selectModeToggleButton",new wp.media.view.SelectModeToggleButton({text:a.bulkSelect,controller:this.controller,priority:-70}).render()),this.toolbar.set("deleteSelectedButton",new wp.media.view.DeleteSelectedButton({filters:e,style:"primary",disabled:!0,text:o?a.trashSelected:a.deletePermanently,controller:this.controller,priority:-80,click:function(){var t=[],i=[],e=this.controller.state().get("selection"),s=this.controller.state().get("library");!e.length||!o&&!window.confirm(a.warnBulkDelete)||o&&"trash"!==e.at(0).get("status")&&!window.confirm(a.warnBulkTrash)||(e.each(function(e){e.get("nonces").delete?o&&"trash"===e.get("status")?(e.set("status","inherit"),t.push(e.save()),i.push(e)):o?(e.set("status","trash"),t.push(e.save()),i.push(e)):e.destroy({wait:!0}):i.push(e)}),t.length?(e.remove(i),n.when.apply(null,t).then(_.bind(function(){s._requery(!0),this.controller.trigger("selection:action:done")},this))):this.controller.trigger("selection:action:done"))}}).render()),o&&this.toolbar.set("deleteSelectedPermanentlyButton",new wp.media.view.DeleteSelectedPermanentlyButton({filters:e,style:"link button-link-delete",disabled:!0,text:a.deletePermanently,controller:this.controller,priority:-55,click:function(){var t=[],i=[],e=this.controller.state().get("selection");e.length&&window.confirm(a.warnBulkDelete)&&(e.each(function(e){(e.get("nonces").delete?i:t).push(e)}),t.length&&e.remove(t),i.length)&&n.when.apply(null,i.map(function(e){return e.destroy()})).then(_.bind(function(){this.controller.trigger("selection:action:done")},this))}}).render())):this.options.date&&(this.toolbar.set("dateFilterLabel",new wp.media.view.Label({value:a.filterByDate,attributes:{for:"media-attachment-date-filters"},priority:-75}).render()),this.toolbar.set("dateFilter",new wp.media.view.DateFilter({controller:this.controller,model:this.collection.props,priority:-75}).render())),this.options.search&&(this.toolbar.set("searchLabel",new wp.media.view.Label({value:a.searchLabel,className:"media-search-input-label",attributes:{for:"media-search-input"},priority:60}).render()),this.toolbar.set("search",new wp.media.view.Search({controller:this.controller,model:this.collection.props,priority:60}).render())),this.options.dragInfo&&this.toolbar.set("dragInfo",new s({el:n('
'+a.dragInfo+"
")[0],priority:-40})),this.options.suggestedWidth&&this.options.suggestedHeight&&this.toolbar.set("suggestedDimensions",new s({el:n('
'+a.suggestedDimensions.replace("%1$s",this.options.suggestedWidth).replace("%2$s",this.options.suggestedHeight)+"
")[0],priority:-40}))},updateContent:function(){var e=this,t=this.controller.isModeActive("grid")?e.attachmentsNoResults:e.uploader;this.collection.length?(t.$el.addClass("hidden"),e.toolbar.get("spinner").hide()):(this.toolbar.get("spinner").show(),this.dfd=this.collection.more().done(function(){e.collection.length?t.$el.addClass("hidden"):t.$el.removeClass("hidden"),e.toolbar.get("spinner").hide()}))},createUploader:function(){this.uploader=new wp.media.view.UploaderInline({controller:this.controller,status:!1,message:this.controller.isModeActive("grid")?"":a.noItemsFound,canClose:this.controller.isModeActive("grid")}),this.uploader.$el.addClass("hidden"),this.views.add(this.uploader)},toggleUploader:function(){this.uploader.$el.hasClass("hidden")?this.uploader.show():this.uploader.hide()},createAttachmentsWrapperView:function(){this.attachmentsWrapper=new wp.media.View({className:"attachments-wrapper"}),this.views.add(this.attachmentsWrapper),this.createAttachments()},createAttachments:function(){this.attachments=new wp.media.view.Attachments({controller:this.controller,collection:this.collection,selection:this.options.selection,model:this.model,sortable:this.options.sortable,scrollElement:this.options.scrollElement,idealColumnWidth:this.options.idealColumnWidth,AttachmentView:this.options.AttachmentView}),this.controller.on("attachment:keydown:arrow",_.bind(this.attachments.arrowEvent,this.attachments)),this.controller.on("attachment:details:shift-tab",_.bind(this.attachments.restoreFocus,this.attachments)),this.views.add(".attachments-wrapper",this.attachments),this.controller.isModeActive("grid")&&(this.attachmentsNoResults=new s({controller:this.controller,tagName:"p"}),this.attachmentsNoResults.$el.addClass("hidden no-media"),this.attachmentsNoResults.$el.html(a.noMedia),this.views.add(this.attachmentsNoResults))},createLoadMoreView:function(){var e=this;this.loadMoreWrapper=new s({controller:this.controller,className:"load-more-wrapper"}),this.loadMoreCount=new s({controller:this.controller,tagName:"p",className:"load-more-count hidden"}),this.loadMoreButton=new wp.media.view.Button({text:r("Load more"),className:"load-more hidden",style:"primary",size:"",click:function(){e.loadMoreAttachments()}}),this.loadMoreSpinner=new wp.media.view.Spinner,this.loadMoreJumpToFirst=new wp.media.view.Button({text:r("Jump to first loaded item"),className:"load-more-jump hidden",size:"",click:function(){e.jumpToFirstAddedItem()}}),this.views.add(".attachments-wrapper",this.loadMoreWrapper),this.views.add(".load-more-wrapper",this.loadMoreSpinner),this.views.add(".load-more-wrapper",this.loadMoreCount),this.views.add(".load-more-wrapper",this.loadMoreButton),this.views.add(".load-more-wrapper",this.loadMoreJumpToFirst)},updateLoadMoreView:_.debounce(function(){this.loadMoreButton.$el.addClass("hidden"),this.loadMoreCount.$el.addClass("hidden"),this.loadMoreJumpToFirst.$el.addClass("hidden").prop("disabled",!0),this.collection.getTotalAttachments()&&(this.collection.length&&(this.loadMoreCount.$el.text(t(r("Showing %1$s of %2$s media items"),this.collection.length,this.collection.getTotalAttachments())),this.loadMoreCount.$el.removeClass("hidden")),this.collection.hasMore()&&this.loadMoreButton.$el.removeClass("hidden"),this.firstAddedMediaItem=this.$el.find(".attachment").eq(this.firstAddedMediaItemIndex),this.firstAddedMediaItem.length&&(this.firstAddedMediaItem.addClass("new-media"),this.loadMoreJumpToFirst.$el.removeClass("hidden").prop("disabled",!1)),this.firstAddedMediaItem.length)&&!this.collection.hasMore()&&this.loadMoreJumpToFirst.$el.trigger("focus")},10),loadMoreAttachments:function(){var e=this;this.collection.hasMore()&&(this.firstAddedMediaItemIndex=this.collection.length,this.$el.addClass("more-loaded"),this.collection.each(function(e){e=e.attributes.id;n('[data-id="'+e+'"]').addClass("found-media")}),e.loadMoreSpinner.show(),this.collection.once("attachments:received",function(){e.loadMoreSpinner.hide()}),this.collection.more())},jumpToFirstAddedItem:function(){this.firstAddedMediaItem.focus()},createAttachmentsHeading:function(){this.attachmentsHeading=new wp.media.view.Heading({text:a.attachmentsList,level:"h2",className:"media-views-heading screen-reader-text"}),this.views.add(this.attachmentsHeading)},createSidebar:function(){var e=this.options.selection,t=this.sidebar=new wp.media.view.Sidebar({controller:this.controller});this.views.add(t),this.controller.uploader&&t.set("uploads",new wp.media.view.UploaderStatus({controller:this.controller,priority:40})),e.on("selection:single",this.createSingle,this),e.on("selection:unsingle",this.disposeSingle,this),e.single()&&this.createSingle()},createSingle:function(){var e=this.sidebar,t=this.options.selection.single();e.set("details",new wp.media.view.Attachment.Details({controller:this.controller,model:t,priority:80})),e.set("compat",new wp.media.view.AttachmentCompat({controller:this.controller,model:t,priority:120})),this.options.display&&e.set("display",new wp.media.view.Settings.AttachmentDisplay({controller:this.controller,model:this.model.display(t),attachment:t,priority:160,userSettings:this.model.get("displayUserSettings")})),"insert"===this.model.id&&e.$el.addClass("visible")},disposeSingle:function(){var e=this.sidebar;e.unset("details"),e.unset("compat"),e.unset("display"),e.$el.removeClass("visible")}});e.exports=l},1223:e=>{var t=wp.media.view.Attachments,i=t.extend({events:{},initialize:function(){return _.defaults(this.options,{sortable:!1,resize:!1,AttachmentView:wp.media.view.Attachment.Selection}),t.prototype.initialize.apply(this,arguments)}});e.exports=i},4094:e=>{var t=Backbone.$,i=wp.media.View.extend({tagName:"div",className:"button-group button-large media-button-group",initialize:function(){this.buttons=_.map(this.options.buttons||[],function(e){return e instanceof Backbone.View?e:new wp.media.view.Button(e).render()}),delete this.options.buttons,this.options.classes&&this.$el.addClass(this.options.classes)},render:function(){return this.$el.html(t(_.pluck(this.buttons,"el")).detach()),this}});e.exports=i},3157:e=>{var t=wp.media.View.extend({tagName:"button",className:"media-button",attributes:{type:"button"},events:{click:"click"},defaults:{text:"",style:"",size:"large",disabled:!1},initialize:function(){this.model=new Backbone.Model(this.defaults),_.each(this.defaults,function(e,t){var i=this.options[t];_.isUndefined(i)||(this.model.set(t,i),delete this.options[t])},this),this.listenTo(this.model,"change",this.render)},render:function(){var e=["button",this.className],t=this.model.toJSON();return t.style&&e.push("button-"+t.style),t.size&&e.push("button-"+t.size),e=_.uniq(e.concat(this.options.classes)),this.el.className=e.join(" "),this.$el.attr("disabled",t.disabled),this.$el.text(this.model.get("text")),this},click:function(e){"#"===this.attributes.href&&e.preventDefault(),this.options.click&&!this.model.get("disabled")&&this.options.click.apply(this,arguments)}});e.exports=t},7137:e=>{var t=wp.media.View,i=wp.media.view.UploaderStatus,s=wp.media.view.l10n,o=jQuery,a=t.extend({className:"crop-content",template:wp.template("crop-content"),initialize:function(){_.bindAll(this,"onImageLoad")},ready:function(){this.controller.frame.on("content:error:crop",this.onError,this),this.$image=this.$el.find(".crop-image"),this.$image.on("load",this.onImageLoad),o(window).on("resize.cropper",_.debounce(this.onImageLoad,250))},remove:function(){o(window).off("resize.cropper"),this.$el.remove(),this.$el.off(),t.prototype.remove.apply(this,arguments)},prepare:function(){return{title:s.cropYourImage,url:this.options.attachment.get("url")}},onImageLoad:function(){var i,e=this.controller.get("imgSelectOptions");"function"==typeof e&&(e=e(this.options.attachment,this.controller)),e=_.extend(e,{parent:this.$el,onInit:function(){var t=i.getOptions().aspectRatio;this.parent.children().on("mousedown touchstart",function(e){!t&&e.shiftKey&&i.setOptions({aspectRatio:"1:1"})}),this.parent.children().on("mouseup touchend",function(){i.setOptions({aspectRatio:t||!1})})}}),this.trigger("image-loaded"),i=this.controller.imgSelect=this.$image.imgAreaSelect(e)},onError:function(){var e=this.options.attachment.get("filename");this.views.add(".upload-errors",new wp.media.view.UploaderStatusError({filename:i.prototype.filename(e),message:window._wpMediaViewsL10n.cropError}),{at:0})}});e.exports=a},5970:e=>{var t=wp.media.View,i=t.extend({className:"image-editor",template:wp.template("image-editor"),initialize:function(e){this.editor=window.imageEdit,this.controller=e.controller,t.prototype.initialize.apply(this,arguments)},prepare:function(){return this.model.toJSON()},loadEditor:function(){this.editor.open(this.model.get("id"),this.model.get("nonces").edit,this)},back:function(){var e=this.controller.lastState();this.controller.setState(e)},refresh:function(){this.model.fetch()},save:function(){var e=this.controller.lastState();this.model.fetch().done(_.bind(function(){this.controller.setState(e)},this))}});e.exports=i},5138:e=>{var t=wp.media.View.extend({className:"media-embed",initialize:function(){this.url=new wp.media.view.EmbedUrl({controller:this.controller,model:this.model.props}).render(),this.views.set([this.url]),this.refresh(),this.listenTo(this.model,"change:type",this.refresh),this.listenTo(this.model,"change:loading",this.loading)},settings:function(e){this._settings&&this._settings.remove(),this._settings=e,this.views.add(e)},refresh:function(){var e,t=this.model.get("type");if("image"===t)e=wp.media.view.EmbedImage;else{if("link"!==t)return;e=wp.media.view.EmbedLink}this.settings(new e({controller:this.controller,model:this.model.props,priority:40}))},loading:function(){this.$el.toggleClass("embed-loading",this.model.get("loading"))}});e.exports=t},1338:e=>{var t=wp.media.view.Settings.AttachmentDisplay,i=t.extend({className:"embed-media-settings",template:wp.template("embed-image-settings"),initialize:function(){t.prototype.initialize.apply(this,arguments),this.listenTo(this.model,"change:url",this.updateImage)},updateImage:function(){this.$("img").attr("src",this.model.get("url"))}});e.exports=i},6959:e=>{var i=jQuery,t=wp.media.view.Settings.extend({className:"embed-link-settings",template:wp.template("embed-link-settings"),initialize:function(){this.listenTo(this.model,"change:url",this.updateoEmbed)},updateoEmbed:_.debounce(function(){var e=this.model.get("url");this.$(".embed-container").hide().find(".embed-preview").empty(),this.$(".setting").hide(),e&&(e.length<11||!e.match(/^http(s)?:\/\//))||this.fetch()},wp.media.controller.Embed.sensitivity),fetch:function(){var e,t=this.model.get("url");i("#embed-url-field").val()===t&&(this.dfd&&"pending"===this.dfd.state()&&this.dfd.abort(),(e=/https?:\/\/www\.youtube\.com\/embed\/([^/]+)/.exec(t))&&(t="https://www.youtube.com/watch?v="+e[1]),this.dfd=wp.apiRequest({url:wp.media.view.settings.oEmbedProxyUrl,data:{url:t,maxwidth:this.model.get("width"),maxheight:this.model.get("height")},type:"GET",dataType:"json",context:this}).done(function(e){this.renderoEmbed({data:{body:e.html||""}})}).fail(this.renderFail))},renderFail:function(e,t){"abort"!==t&&this.$(".link-text").show()},renderoEmbed:function(e){e=e&&e.data&&e.data.body||"";e?this.$(".embed-container").show().find(".embed-preview").html(e):this.renderFail()}});e.exports=t},4848:e=>{var t=wp.media.View,i=jQuery,s=wp.media.view.l10n,o=t.extend({tagName:"span",className:"embed-url",events:{input:"url"},initialize:function(){this.$input=i('').attr("aria-label",s.insertFromUrlTitle).val(this.model.get("url")),this.input=this.$input[0],this.spinner=i('')[0],this.$el.append([this.input,this.spinner]),this.listenTo(this.model,"change:url",this.render),this.model.get("url")&&_.delay(_.bind(function(){this.model.trigger("change:url")},this),500)},render:function(){var e=this.$input;if(!e.is(":focus"))return this.model.get("url")?this.input.value=this.model.get("url"):this.input.setAttribute("placeholder","https://"),t.prototype.render.apply(this,arguments),this},url:function(e){e=e.target.value||"";this.model.set("url",e.trim())}});e.exports=o},6557:e=>{var o=jQuery,t=wp.media.View.extend({events:{keydown:"focusManagementMode"},initialize:function(e){this.mode=e.mode||"constrainTabbing",this.tabsAutomaticActivation=e.tabsAutomaticActivation||!1},focusManagementMode:function(e){"constrainTabbing"===this.mode&&this.constrainTabbing(e),"tabsNavigation"===this.mode&&this.tabsNavigation(e)},getTabbables:function(){return this.$(":tabbable").not('.moxie-shim input[type="file"]')},focus:function(){this.$(".media-modal").trigger("focus")},constrainTabbing:function(e){var t;if(9===e.keyCode)return(t=this.getTabbables()).last()[0]!==e.target||e.shiftKey?t.first()[0]===e.target&&e.shiftKey?(t.last().focus(),!1):void 0:(t.first().focus(),!1)},setAriaHiddenOnBodyChildren:function(t){var e,i=this;this.isBodyAriaHidden||(e=document.body.children,_.each(e,function(e){e!==t[0]&&i.elementShouldBeHidden(e)&&(e.setAttribute("aria-hidden","true"),i.ariaHiddenElements.push(e))}),this.isBodyAriaHidden=!0)},removeAriaHiddenFromBodyChildren:function(){_.each(this.ariaHiddenElements,function(e){e.removeAttribute("aria-hidden")}),this.ariaHiddenElements=[],this.isBodyAriaHidden=!1},elementShouldBeHidden:function(e){var t=e.getAttribute("role");return!("SCRIPT"===e.tagName||e.hasAttribute("aria-hidden")||e.hasAttribute("aria-live")||-1!==["alert","status","log","marquee","timer"].indexOf(t))},isBodyAriaHidden:!1,ariaHiddenElements:[],tabs:o(),setupAriaTabs:function(){this.tabs=this.$('[role="tab"]'),this.tabs.attr({"aria-selected":"false",tabIndex:"-1"}),this.tabs.filter(".active").removeAttr("tabindex").attr("aria-selected","true")},tabsNavigation:function(e){var t="horizontal";-1===[32,35,36,37,38,39,40].indexOf(e.which)||"horizontal"===(t="vertical"===this.$el.attr("aria-orientation")?"vertical":t)&&-1!==[38,40].indexOf(e.which)||"vertical"===t&&-1!==[37,39].indexOf(e.which)||this.switchTabs(e,this.tabs)},switchTabs:function(e){var t,i=e.which,s=this.tabs.index(o(e.target));switch(i){case 32:this.activateTab(this.tabs[s]);break;case 35:e.preventDefault(),this.activateTab(this.tabs[this.tabs.length-1]);break;case 36:e.preventDefault(),this.activateTab(this.tabs[0]);break;case 37:case 38:e.preventDefault(),t=s-1<0?this.tabs.length-1:s-1,this.activateTab(this.tabs[t]);break;case 39:case 40:e.preventDefault(),t=s+1===this.tabs.length?0:s+1,this.activateTab(this.tabs[t])}},activateTab:function(e){e&&(e.focus(),this.tabsAutomaticActivation?(e.removeAttribute("tabindex"),e.setAttribute("aria-selected","true"),e.click()):o(e).on("click",function(){e.removeAttribute("tabindex"),e.setAttribute("aria-selected","true")}))}});e.exports=t},3647:e=>{var t=wp.media.View.extend({initialize:function(){_.defaults(this.options,{mode:["select"]}),this._createRegions(),this._createStates(),this._createModes()},_createRegions:function(){this.regions=this.regions?this.regions.slice():[],_.each(this.regions,function(e){this[e]=new wp.media.controller.Region({view:this,id:e,selector:".media-frame-"+e})},this)},_createStates:function(){this.states=new Backbone.Collection(null,{model:wp.media.controller.State}),this.states.on("add",function(e){e.frame=this,e.trigger("ready")},this),this.options.states&&this.states.add(this.options.states)},_createModes:function(){this.activeModes=new Backbone.Collection,this.activeModes.on("add remove reset",_.bind(this.triggerModeEvents,this)),_.each(this.options.mode,function(e){this.activateMode(e)},this)},reset:function(){return this.states.invoke("trigger","reset"),this},triggerModeEvents:function(e,t,i){var s,o={add:"activate",remove:"deactivate"};_.each(i,function(e,t){e&&(s=t)}),_.has(o,s)&&(i=e.get("id")+":"+o[s],this.trigger(i))},activateMode:function(e){if(!this.isModeActive(e))return this.activeModes.add([{id:e}]),this.$el.addClass("mode-"+e),this},deactivateMode:function(e){return this.isModeActive(e)&&(this.activeModes.remove(this.activeModes.where({id:e})),this.$el.removeClass("mode-"+e),this.trigger(e+":deactivate")),this},isModeActive:function(e){return Boolean(this.activeModes.where({id:e}).length)}});_.extend(t.prototype,wp.media.controller.StateMachine.prototype),e.exports=t},9142:e=>{var t=wp.media.view.MediaFrame.Select,s=wp.media.view.l10n,i=t.extend({defaults:{id:"image",url:"",menu:"image-details",content:"image-details",toolbar:"image-details",type:"link",title:s.imageDetailsTitle,priority:120},initialize:function(e){this.image=new wp.media.model.PostImage(e.metadata),this.options.selection=new wp.media.model.Selection(this.image.attachment,{multiple:!1}),t.prototype.initialize.apply(this,arguments)},bindHandlers:function(){t.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:image-details",this.createMenu,this),this.on("content:create:image-details",this.imageDetailsContent,this),this.on("content:render:edit-image",this.editImageContent,this),this.on("toolbar:render:image-details",this.renderImageDetailsToolbar,this),this.on("toolbar:render:replace",this.renderReplaceImageToolbar,this)},createStates:function(){this.states.add([new wp.media.controller.ImageDetails({image:this.image,editable:!1}),new wp.media.controller.ReplaceImage({id:"replace-image",library:wp.media.query({type:"image"}),image:this.image,multiple:!1,title:s.imageReplaceTitle,toolbar:"replace",priority:80,displaySettings:!0}),new wp.media.controller.EditImage({image:this.image,selection:this.options.selection})])},imageDetailsContent:function(e){e.view=new wp.media.view.ImageDetails({controller:this,model:this.state().image,attachment:this.state().image.attachment})},editImageContent:function(){var e=this.state().get("image");e&&(e=new wp.media.view.EditImage({model:e,controller:this}).render(),this.content.set(e),e.loadEditor())},renderImageDetailsToolbar:function(){this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{select:{style:"primary",text:s.update,priority:80,click:function(){var e=this.controller,t=e.state();e.close(),t.trigger("update",e.image.toJSON()),e.setState(e.options.state),e.reset()}}}}))},renderReplaceImageToolbar:function(){var e=this,t=e.lastState(),i=t&&t.id;this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{back:{text:s.back,priority:80,click:function(){i?e.setState(i):e.close()}},replace:{style:"primary",text:s.replace,priority:20,requires:{selection:!0},click:function(){var e=this.controller,t=e.state(),i=t.get("selection").single();e.close(),e.image.changeAttachment(i,t.display(i)),t.trigger("replace",e.image.toJSON()),e.setState(e.options.state),e.reset()}}}}))}});e.exports=i},9075:e=>{var t=wp.media.view.MediaFrame.Select,i=wp.media.controller.Library,o=wp.media.view.l10n,s=t.extend({initialize:function(){this.counts={audio:{count:wp.media.view.settings.attachmentCounts.audio,state:"playlist"},video:{count:wp.media.view.settings.attachmentCounts.video,state:"video-playlist"}},_.defaults(this.options,{multiple:!0,editing:!1,state:"insert",metadata:{}}),t.prototype.initialize.apply(this,arguments),this.createIframeStates()},createStates:function(){var e=this.options;this.states.add([new i({id:"insert",title:o.insertMediaTitle,priority:20,toolbar:"main-insert",filterable:"all",library:wp.media.query(e.library),multiple:!!e.multiple&&"reset",editable:!0,allowLocalEdits:!0,displaySettings:!0,displayUserSettings:!0}),new i({id:"gallery",title:o.createGalleryTitle,priority:40,toolbar:"main-gallery",filterable:"uploaded",multiple:"add",editable:!1,library:wp.media.query(_.defaults({type:"image"},e.library))}),new wp.media.controller.Embed({metadata:e.metadata}),new wp.media.controller.EditImage({model:e.editImage}),new wp.media.controller.GalleryEdit({library:e.selection,editing:e.editing,menu:"gallery"}),new wp.media.controller.GalleryAdd,new i({id:"playlist",title:o.createPlaylistTitle,priority:60,toolbar:"main-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:wp.media.query(_.defaults({type:"audio"},e.library))}),new wp.media.controller.CollectionEdit({type:"audio",collectionType:"playlist",title:o.editPlaylistTitle,SettingsView:wp.media.view.Settings.Playlist,library:e.selection,editing:e.editing,menu:"playlist",dragInfoText:o.playlistDragInfo,dragInfo:!1}),new wp.media.controller.CollectionAdd({type:"audio",collectionType:"playlist",title:o.addToPlaylistTitle}),new i({id:"video-playlist",title:o.createVideoPlaylistTitle,priority:60,toolbar:"main-video-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:wp.media.query(_.defaults({type:"video"},e.library))}),new wp.media.controller.CollectionEdit({type:"video",collectionType:"playlist",title:o.editVideoPlaylistTitle,SettingsView:wp.media.view.Settings.Playlist,library:e.selection,editing:e.editing,menu:"video-playlist",dragInfoText:o.videoPlaylistDragInfo,dragInfo:!1}),new wp.media.controller.CollectionAdd({type:"video",collectionType:"playlist",title:o.addToVideoPlaylistTitle})]),wp.media.view.settings.post.featuredImageId&&this.states.add(new wp.media.controller.FeaturedImage)},bindHandlers:function(){t.prototype.bindHandlers.apply(this,arguments),this.on("activate",this.activate,this),void 0!==_.find(this.counts,function(e){return 0===e.count})&&this.listenTo(wp.media.model.Attachments.all,"change:type",this.mediaTypeCounts),this.on("menu:create:gallery",this.createMenu,this),this.on("menu:create:playlist",this.createMenu,this),this.on("menu:create:video-playlist",this.createMenu,this),this.on("toolbar:create:main-insert",this.createToolbar,this),this.on("toolbar:create:main-gallery",this.createToolbar,this),this.on("toolbar:create:main-playlist",this.createToolbar,this),this.on("toolbar:create:main-video-playlist",this.createToolbar,this),this.on("toolbar:create:featured-image",this.featuredImageToolbar,this),this.on("toolbar:create:main-embed",this.mainEmbedToolbar,this),_.each({menu:{default:"mainMenu",gallery:"galleryMenu",playlist:"playlistMenu","video-playlist":"videoPlaylistMenu"},content:{embed:"embedContent","edit-image":"editImageContent","edit-selection":"editSelectionContent"},toolbar:{"main-insert":"mainInsertToolbar","main-gallery":"mainGalleryToolbar","gallery-edit":"galleryEditToolbar","gallery-add":"galleryAddToolbar","main-playlist":"mainPlaylistToolbar","playlist-edit":"playlistEditToolbar","playlist-add":"playlistAddToolbar","main-video-playlist":"mainVideoPlaylistToolbar","video-playlist-edit":"videoPlaylistEditToolbar","video-playlist-add":"videoPlaylistAddToolbar"}},function(e,i){_.each(e,function(e,t){this.on(i+":render:"+t,this[e],this)},this)},this)},activate:function(){_.each(this.counts,function(e){e.count<1&&this.menuItemVisibility(e.state,"hide")},this)},mediaTypeCounts:function(e,t){void 0!==this.counts[t]&&this.counts[t].count<1&&(this.counts[t].count++,this.menuItemVisibility(this.counts[t].state,"show"))},mainMenu:function(e){e.set({"library-separator":new wp.media.View({className:"separator",priority:100,attributes:{role:"presentation"}})})},menuItemVisibility:function(e,t){var i=this.menu.get();"hide"===t?i.hide(e):"show"===t&&i.show(e)},galleryMenu:function(e){var t=this.lastState(),i=t&&t.id,s=this;e.set({cancel:{text:o.cancelGalleryTitle,priority:20,click:function(){i?s.setState(i):s.close(),this.controller.modal.focusManager.focus()}},separateCancel:new wp.media.View({className:"separator",priority:40})})},playlistMenu:function(e){var t=this.lastState(),i=t&&t.id,s=this;e.set({cancel:{text:o.cancelPlaylistTitle,priority:20,click:function(){i?s.setState(i):s.close(),this.controller.modal.focusManager.focus()}},separateCancel:new wp.media.View({className:"separator",priority:40})})},videoPlaylistMenu:function(e){var t=this.lastState(),i=t&&t.id,s=this;e.set({cancel:{text:o.cancelVideoPlaylistTitle,priority:20,click:function(){i?s.setState(i):s.close(),this.controller.modal.focusManager.focus()}},separateCancel:new wp.media.View({className:"separator",priority:40})})},embedContent:function(){var e=new wp.media.view.Embed({controller:this,model:this.state()}).render();this.content.set(e)},editSelectionContent:function(){var e=this.state(),t=e.get("selection"),t=new wp.media.view.AttachmentsBrowser({controller:this,collection:t,selection:t,model:e,sortable:!0,search:!1,date:!1,dragInfo:!0,AttachmentView:wp.media.view.Attachments.EditSelection}).render();t.toolbar.set("backToLibrary",{text:o.returnToLibrary,priority:-100,click:function(){this.controller.content.mode("browse"),this.controller.modal.focusManager.focus()}}),this.content.set(t),this.trigger("edit:selection",this)},editImageContent:function(){var e=this.state().get("image"),e=new wp.media.view.EditImage({model:e,controller:this}).render();this.content.set(e),e.loadEditor()},selectionStatusToolbar:function(e){var t=this.state().get("editable");e.set("selection",new wp.media.view.Selection({controller:this,collection:this.state().get("selection"),priority:-40,editable:t&&function(){this.controller.content.mode("edit-selection")}}).render())},mainInsertToolbar:function(e){var i=this;this.selectionStatusToolbar(e),e.set("insert",{style:"primary",priority:80,text:o.insertIntoPost,requires:{selection:!0},click:function(){var e=i.state(),t=e.get("selection");i.close(),e.trigger("insert",t).reset()}})},mainGalleryToolbar:function(e){var s=this;this.selectionStatusToolbar(e),e.set("gallery",{style:"primary",text:o.createNewGallery,priority:60,requires:{selection:!0},click:function(){var e=s.state().get("selection"),t=s.state("gallery-edit"),i=e.where({type:"image"});t.set("library",new wp.media.model.Selection(i,{props:e.props.toJSON(),multiple:!0})),this.controller.setState("gallery-edit"),this.controller.modal.focusManager.focus()}})},mainPlaylistToolbar:function(e){var s=this;this.selectionStatusToolbar(e),e.set("playlist",{style:"primary",text:o.createNewPlaylist,priority:100,requires:{selection:!0},click:function(){var e=s.state().get("selection"),t=s.state("playlist-edit"),i=e.where({type:"audio"});t.set("library",new wp.media.model.Selection(i,{props:e.props.toJSON(),multiple:!0})),this.controller.setState("playlist-edit"),this.controller.modal.focusManager.focus()}})},mainVideoPlaylistToolbar:function(e){var s=this;this.selectionStatusToolbar(e),e.set("video-playlist",{style:"primary",text:o.createNewVideoPlaylist,priority:100,requires:{selection:!0},click:function(){var e=s.state().get("selection"),t=s.state("video-playlist-edit"),i=e.where({type:"video"});t.set("library",new wp.media.model.Selection(i,{props:e.props.toJSON(),multiple:!0})),this.controller.setState("video-playlist-edit"),this.controller.modal.focusManager.focus()}})},featuredImageToolbar:function(e){this.createSelectToolbar(e,{text:o.setFeaturedImage,state:this.options.state})},mainEmbedToolbar:function(e){e.view=new wp.media.view.Toolbar.Embed({controller:this})},galleryEditToolbar:function(){var e=this.state().get("editing");this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:e?o.updateGallery:o.insertGallery,priority:80,requires:{library:!0},click:function(){var e=this.controller,t=e.state();e.close(),t.trigger("update",t.get("library")),e.setState(e.options.state),e.reset()}}}}))},galleryAddToolbar:function(){this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:o.addToGallery,priority:80,requires:{selection:!0},click:function(){var e=this.controller,t=e.state();e.state("gallery-edit").get("library").add(t.get("selection").models),t.trigger("reset"),e.setState("gallery-edit"),this.controller.modal.focusManager.focus()}}}}))},playlistEditToolbar:function(){var e=this.state().get("editing");this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:e?o.updatePlaylist:o.insertPlaylist,priority:80,requires:{library:!0},click:function(){var e=this.controller,t=e.state();e.close(),t.trigger("update",t.get("library")),e.setState(e.options.state),e.reset()}}}}))},playlistAddToolbar:function(){this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:o.addToPlaylist,priority:80,requires:{selection:!0},click:function(){var e=this.controller,t=e.state();e.state("playlist-edit").get("library").add(t.get("selection").models),t.trigger("reset"),e.setState("playlist-edit"),this.controller.modal.focusManager.focus()}}}}))},videoPlaylistEditToolbar:function(){var e=this.state().get("editing");this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:e?o.updateVideoPlaylist:o.insertVideoPlaylist,priority:140,requires:{library:!0},click:function(){var e=this.controller,t=e.state(),i=t.get("library");i.type="video",e.close(),t.trigger("update",i),e.setState(e.options.state),e.reset()}}}}))},videoPlaylistAddToolbar:function(){this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:o.addToVideoPlaylist,priority:140,requires:{selection:!0},click:function(){var e=this.controller,t=e.state();e.state("video-playlist-edit").get("library").add(t.get("selection").models),t.trigger("reset"),e.setState("video-playlist-edit"),this.controller.modal.focusManager.focus()}}}}))}});e.exports=s},8719:e=>{var t=wp.media.view.MediaFrame,i=wp.media.view.l10n,s=t.extend({initialize:function(){t.prototype.initialize.apply(this,arguments),_.defaults(this.options,{selection:[],library:{},multiple:!1,state:"library"}),this.createSelection(),this.createStates(),this.bindHandlers()},createSelection:function(){var e=this.options.selection;e instanceof wp.media.model.Selection||(this.options.selection=new wp.media.model.Selection(e,{multiple:this.options.multiple})),this._selection={attachments:new wp.media.model.Attachments,difference:[]}},editImageContent:function(){var e=this.state().get("image"),e=new wp.media.view.EditImage({model:e,controller:this}).render();this.content.set(e),e.loadEditor()},createStates:function(){var e=this.options;this.options.states||this.states.add([new wp.media.controller.Library({library:wp.media.query(e.library),multiple:e.multiple,title:e.title,priority:20}),new wp.media.controller.EditImage({model:e.editImage})])},bindHandlers:function(){this.on("router:create:browse",this.createRouter,this),this.on("router:render:browse",this.browseRouter,this),this.on("content:create:browse",this.browseContent,this),this.on("content:render:upload",this.uploadContent,this),this.on("toolbar:create:select",this.createSelectToolbar,this),this.on("content:render:edit-image",this.editImageContent,this)},browseRouter:function(e){e.set({upload:{text:i.uploadFilesTitle,priority:20},browse:{text:i.mediaLibraryTitle,priority:40}})},browseContent:function(e){var t=this.state();this.$el.removeClass("hide-toolbar"),e.view=new wp.media.view.AttachmentsBrowser({controller:this,collection:t.get("library"),selection:t.get("selection"),model:t,sortable:t.get("sortable"),search:t.get("searchable"),filters:t.get("filterable"),date:t.get("date"),display:t.has("display")?t.get("display"):t.get("displaySettings"),dragInfo:t.get("dragInfo"),idealColumnWidth:t.get("idealColumnWidth"),suggestedWidth:t.get("suggestedWidth"),suggestedHeight:t.get("suggestedHeight"),AttachmentView:t.get("AttachmentView")})},uploadContent:function(){this.$el.removeClass("hide-toolbar"),this.content.set(new wp.media.view.UploaderInline({controller:this}))},createSelectToolbar:function(e,t){(t=t||this.options.button||{}).controller=this,e.view=new wp.media.view.Toolbar.Select(t)}});e.exports=s},7990:e=>{var t=wp.media.View.extend({tagName:function(){return this.options.level||"h1"},className:"media-views-heading",initialize:function(){this.options.className&&this.$el.addClass(this.options.className),this.text=this.options.text},render:function(){return this.$el.html(this.text),this}});e.exports=t},6217:e=>{var t=wp.media.View.extend({className:"media-iframe",render:function(){return this.views.detach(),this.$el.html('