@elementor/editor-audits 4.3.2 → 4.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ import { type ElementSnapshotNode } from '../types';
2
+ import { type ImageLikeMedia } from './image-like-sources';
3
+ import { walkElements } from './walk';
4
+
5
+ const BACKGROUND_IMAGE_SETTING_KEYS = [
6
+ 'background_image',
7
+ 'background_hover_image',
8
+ 'background_overlay_image',
9
+ 'background_overlay_hover_image',
10
+ '_background_image',
11
+ '_background_hover_image',
12
+ ] as const;
13
+
14
+ export type BackgroundImageSourceVisit = {
15
+ node: ElementSnapshotNode;
16
+ media: ImageLikeMedia;
17
+ };
18
+
19
+ export function walkBackgroundImageSources(
20
+ tree: ElementSnapshotNode[],
21
+ visit: ( source: BackgroundImageSourceVisit ) => void
22
+ ): void {
23
+ walkElements( tree, ( node ) => {
24
+ for ( const key of BACKGROUND_IMAGE_SETTING_KEYS ) {
25
+ const media = node.settings[ key ] as ImageLikeMedia | undefined;
26
+
27
+ if ( media?.id || media?.url ) {
28
+ visit( { node, media } );
29
+ }
30
+ }
31
+ } );
32
+ }
@@ -1,5 +1,6 @@
1
1
  import { type PageContextResponse } from '../types';
2
2
  import { type ImageLikeMedia } from './image-like-sources';
3
+ import { buildImageSizeKey } from './image-size-key';
3
4
 
4
5
  export function hasMeaningfulAlt( media: ImageLikeMedia, pageContext: PageContextResponse ): boolean {
5
6
  if ( ! media.id && ! media.url ) {
@@ -7,7 +8,8 @@ export function hasMeaningfulAlt( media: ImageLikeMedia, pageContext: PageContex
7
8
  }
8
9
 
9
10
  if ( media.id ) {
10
- const alt = pageContext.image_sizes[ media.id ]?.alt ?? '';
11
+ const key = buildImageSizeKey( { id: media.id, size: media.size } );
12
+ const alt = pageContext.image_sizes[ key ]?.alt ?? '';
11
13
  return alt.trim().length > 0;
12
14
  }
13
15
 
@@ -7,6 +7,7 @@ export type ImageLikeMedia = {
7
7
  id?: number;
8
8
  url?: string;
9
9
  alt?: string;
10
+ size?: string;
10
11
  };
11
12
 
12
13
  export type ImageLikeSourceVisit = {
@@ -51,7 +52,7 @@ function collectMediaFromNode( node: ElementSnapshotNode ): ImageLikeMedia[] {
51
52
  const image = node.settings.image as ImageLikeMedia | undefined;
52
53
 
53
54
  if ( image?.id || image?.url ) {
54
- sources.push( image );
55
+ sources.push( { ...image, size: node.settings.image_size as string | undefined } );
55
56
  }
56
57
 
57
58
  const gallery = ( node.settings.carousel ?? node.settings.gallery ?? node.settings.wp_gallery ) as
@@ -59,9 +60,11 @@ function collectMediaFromNode( node: ElementSnapshotNode ): ImageLikeMedia[] {
59
60
  | undefined;
60
61
 
61
62
  if ( Array.isArray( gallery ) ) {
63
+ const gallerySize = node.settings.thumbnail_size as string | undefined;
64
+
62
65
  for ( const item of gallery ) {
63
66
  if ( item?.id || item?.url ) {
64
- sources.push( item );
67
+ sources.push( { ...item, size: gallerySize } );
65
68
  }
66
69
  }
67
70
  }
@@ -0,0 +1,8 @@
1
+ export type ImageSizeRequest = {
2
+ id: number;
3
+ size?: string;
4
+ };
5
+
6
+ export function buildImageSizeKey( { id, size }: ImageSizeRequest ): string {
7
+ return `${ id }:${ size || 'full' }`;
8
+ }
@@ -1,14 +1,23 @@
1
1
  import { type ElementSnapshotNode } from '../types';
2
- import { walkImageLikeSources } from './image-like-sources';
2
+ import { walkAtomicBackgroundImageSources } from './atomic-background-image-sources';
3
+ import { walkAtomicImageSources } from './atomic-image-sources';
4
+ import { walkBackgroundImageSources } from './background-image-sources';
5
+ import { type ImageLikeMedia, walkImageLikeSources } from './image-like-sources';
6
+ import { buildImageSizeKey } from './image-size-key';
3
7
 
4
- export function extractAttachmentIds( tree: ElementSnapshotNode[] ): number[] {
5
- const ids = new Set< number >();
8
+ export function extractImageSizeRequests( tree: ElementSnapshotNode[] ): string[] {
9
+ const keys = new Set< string >();
6
10
 
7
- walkImageLikeSources( tree, ( { media } ) => {
11
+ const collect = ( media: ImageLikeMedia ) => {
8
12
  if ( media.id ) {
9
- ids.add( media.id );
13
+ keys.add( buildImageSizeKey( { id: media.id, size: media.size } ) );
10
14
  }
11
- } );
15
+ };
12
16
 
13
- return Array.from( ids ).sort( ( a, b ) => a - b );
17
+ walkImageLikeSources( tree, ( { media } ) => collect( media ) );
18
+ walkBackgroundImageSources( tree, ( { media } ) => collect( media ) );
19
+ walkAtomicImageSources( tree, ( { media } ) => collect( media ) );
20
+ walkAtomicBackgroundImageSources( tree, ( { media } ) => collect( media ) );
21
+
22
+ return Array.from( keys ).sort();
14
23
  }
@@ -0,0 +1,7 @@
1
+ // Script sources of known accessibility widgets. Ally is listed first; append third-party
2
+ // widget script sources here (UserWay, AccessiBe, EqualWeb, etc.) once confirmed.
3
+ const ACCESSIBILITY_WIDGET_SCRIPT_SOURCES = [ 'cdn.elementor.com/a11y/widget.js' ];
4
+
5
+ export function hasAccessibilityWidgetScript( html: string ): boolean {
6
+ return ACCESSIBILITY_WIDGET_SCRIPT_SOURCES.some( ( src ) => html.includes( src ) );
7
+ }