@elementor/editor-canvas 4.2.0-911 → 4.2.0-912

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.
@@ -1,50 +1,76 @@
1
1
  import { type GridTracks } from '../hooks/use-grid-tracks';
2
2
 
3
- export type OutlineGeometry = {
4
- vertical: number[];
5
- horizontal: number[];
6
- top: number;
7
- bottom: number;
8
- left: number;
9
- right: number;
3
+ export type CellRect = {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
10
8
  };
11
9
 
12
- export function computeOutlineGeometry( tracks: GridTracks, width: number, height: number ): OutlineGeometry {
13
- const { columns, rows, columnGap, rowGap, padding } = tracks;
10
+ type TrackSegment = {
11
+ start: number;
12
+ size: number;
13
+ };
14
14
 
15
+ export function toGridTracks( computedStyle: CSSStyleDeclaration ): GridTracks {
15
16
  return {
16
- vertical: computeBoundaries( columns, columnGap, padding.left ),
17
- horizontal: computeBoundaries( rows, rowGap, padding.top ),
18
- top: padding.top,
19
- bottom: height - padding.bottom,
20
- left: padding.left,
21
- right: width - padding.right,
17
+ columns: parseTrackList( computedStyle.gridTemplateColumns ),
18
+ rows: parseTrackList( computedStyle.gridTemplateRows ),
19
+ columnGap: toPx( computedStyle.columnGap ),
20
+ rowGap: toPx( computedStyle.rowGap ),
21
+ padding: {
22
+ top: toPx( computedStyle.paddingTop ),
23
+ right: toPx( computedStyle.paddingRight ),
24
+ bottom: toPx( computedStyle.paddingBottom ),
25
+ left: toPx( computedStyle.paddingLeft ),
26
+ },
27
+ borderColor: computedStyle.getPropertyValue( '--e-a-border-color-bold' ).trim(),
22
28
  };
23
29
  }
24
30
 
25
- function computeBoundaries( sizes: number[], gap: number, offset: number ): number[] {
26
- if ( sizes.length === 0 ) {
31
+ export function computeCellRects( tracks: GridTracks, width: number, height: number ): CellRect[] {
32
+ const { columns, rows, columnGap, rowGap, padding } = tracks;
33
+
34
+ const hasColumns = columns.length > 0;
35
+ const hasRows = rows.length > 0;
36
+
37
+ if ( ! hasColumns && ! hasRows ) {
27
38
  return [];
28
39
  }
29
40
 
30
- const boundaries: number[] = [];
31
- let cursor = offset;
41
+ const columnSegments = hasColumns
42
+ ? computeTrackSegments( columns, columnGap, padding.left )
43
+ : [ { start: padding.left, size: width - padding.left - padding.right } ];
32
44
 
33
- for ( let i = 0; i < sizes.length; i++ ) {
34
- if ( i === 0 ) {
35
- boundaries.push( cursor );
45
+ const rowSegments = hasRows
46
+ ? computeTrackSegments( rows, rowGap, padding.top )
47
+ : [ { start: padding.top, size: height - padding.top - padding.bottom } ];
48
+
49
+ const cells: CellRect[] = [];
50
+
51
+ for ( const row of rowSegments ) {
52
+ for ( const column of columnSegments ) {
53
+ cells.push( { x: column.start, y: row.start, width: column.size, height: row.size } );
36
54
  }
55
+ }
56
+
57
+ return cells;
58
+ }
37
59
 
60
+ function computeTrackSegments( sizes: number[], gap: number, offset: number ): TrackSegment[] {
61
+ const segments: TrackSegment[] = [];
62
+ let cursor = offset;
63
+
64
+ for ( let i = 0; i < sizes.length; i++ ) {
65
+ segments.push( { start: cursor, size: sizes[ i ] } );
38
66
  cursor += sizes[ i ];
39
- boundaries.push( cursor );
40
67
 
41
- if ( i < sizes.length - 1 && gap > 0 ) {
68
+ if ( i < sizes.length - 1 ) {
42
69
  cursor += gap;
43
- boundaries.push( cursor );
44
70
  }
45
71
  }
46
72
 
47
- return boundaries;
73
+ return segments;
48
74
  }
49
75
 
50
76
  export function snapToHalfPixel( value: number ): number {