@elementor/editor-canvas 4.2.0-910 → 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.
- package/dist/index.js +228 -225
- package/dist/index.mjs +115 -112
- package/package.json +18 -18
- package/src/components/grid-outline/__tests__/grid-outline-overlay.test.tsx +2 -2
- package/src/components/grid-outline/__tests__/grid-outline.test.tsx +28 -27
- package/src/components/grid-outline/{grid-outline-line.tsx → grid-outline-cell.tsx} +11 -10
- package/src/components/grid-outline/grid-outline.tsx +10 -20
- package/src/hooks/__tests__/use-grid-tracks.test.ts +57 -35
- package/src/hooks/use-grid-tracks.ts +26 -25
- package/src/utils/__tests__/grid-outline-utils.test.ts +128 -38
- package/src/utils/grid-outline-utils.ts +52 -26
|
@@ -1,50 +1,76 @@
|
|
|
1
1
|
import { type GridTracks } from '../hooks/use-grid-tracks';
|
|
2
2
|
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
13
|
-
|
|
10
|
+
type TrackSegment = {
|
|
11
|
+
start: number;
|
|
12
|
+
size: number;
|
|
13
|
+
};
|
|
14
14
|
|
|
15
|
+
export function toGridTracks( computedStyle: CSSStyleDeclaration ): GridTracks {
|
|
15
16
|
return {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
26
|
-
|
|
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
|
|
31
|
-
|
|
41
|
+
const columnSegments = hasColumns
|
|
42
|
+
? computeTrackSegments( columns, columnGap, padding.left )
|
|
43
|
+
: [ { start: padding.left, size: width - padding.left - padding.right } ];
|
|
32
44
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
68
|
+
if ( i < sizes.length - 1 ) {
|
|
42
69
|
cursor += gap;
|
|
43
|
-
boundaries.push( cursor );
|
|
44
70
|
}
|
|
45
71
|
}
|
|
46
72
|
|
|
47
|
-
return
|
|
73
|
+
return segments;
|
|
48
74
|
}
|
|
49
75
|
|
|
50
76
|
export function snapToHalfPixel( value: number ): number {
|