File size: 5,951 Bytes
b462a9f
2e787a2
 
2f568d8
2e787a2
2f568d8
f717bcd
ddf672c
b462a9f
 
 
 
 
 
 
 
 
 
d091da8
 
 
 
 
78b81a5
 
 
 
 
 
d091da8
 
 
814c197
 
d091da8
78b81a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d091da8
 
 
814c197
 
d091da8
b462a9f
2e787a2
b462a9f
 
78b81a5
b462a9f
78b81a5
 
 
 
 
 
 
 
 
 
 
 
d091da8
 
 
814c197
 
d091da8
78b81a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d091da8
 
 
39c89a5
 
d091da8
78b81a5
 
 
 
 
 
b462a9f
ddf672c
b462a9f
 
78b81a5
b462a9f
78b81a5
 
 
 
 
 
 
 
 
 
 
 
39c89a5
 
 
 
 
 
78b81a5
 
 
 
 
 
 
 
 
 
 
 
814c197
1e8f4c6
39c89a5
 
78b81a5
39c89a5
 
 
2e787a2
 
39c89a5
 
78b81a5
 
 
 
 
 
 
 
 
 
 
 
d091da8
 
 
 
 
 
39c89a5
d091da8
 
eca7f7a
 
 
1e8f4c6
78b81a5
 
eca7f7a
 
d091da8
1e8f4c6
 
39c89a5
1e8f4c6
 
 
 
eca7f7a
39c89a5
1e8f4c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eca7f7a
39c89a5
1e8f4c6
 
 
 
 
 
 
39c89a5
 
d091da8
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// Panel size constants
export const PANEL_SIZES = {
  PORTRAIT: { width: 512, height: 768 },
  COLUMN: { width: 512, height: 1024 },
  LANDSCAPE: { width: 768, height: 512 },
  PANORAMIC: { width: 1024, height: 512 },
  COVER_SIZE: { width: 512, height: 1024 },
  SQUARE: { width: 512, height: 512 },
};

// Grid span helpers
const GRID = {
  FULL_WIDTH: "1 / span 3",
  TWO_THIRDS: "1 / span 2",
  FULL_HEIGHT: "1 / span 2",
  FULL_HEIGHT_FROM_2: "2 / span 2", // Pour les éléments qui commencent à partir de la ligne 2
};

export const LAYOUTS = {
  COVER: {
    gridCols: 1,
    gridRows: 1,
    panels: [
      {
        ...PANEL_SIZES.COVER_SIZE,
        gridColumn: "1",
        gridRow: "1",
        acceptText: true,
      }, // Format portrait
    ],
  },
  LAYOUT_1: {
    gridCols: 2,
    gridRows: 2,
    panels: [
      {
        ...PANEL_SIZES.LANDSCAPE,
        gridColumn: "1",
        gridRow: "1",
        acceptText: true,
      }, // Landscape top left
      {
        ...PANEL_SIZES.PORTRAIT,
        gridColumn: "2",
        gridRow: "1",
        acceptText: false,
      }, // Portrait top right
      {
        ...PANEL_SIZES.LANDSCAPE,
        gridColumn: "1",
        gridRow: "2",
        acceptText: true,
      }, // Landscape middle left
      {
        ...PANEL_SIZES.PORTRAIT,
        gridColumn: "2",
        gridRow: "2",
        acceptText: false,
      }, // Portrait right
    ],
  },
  LAYOUT_2: {
    gridCols: 3,
    gridRows: 2,
    panels: [
      {
        ...PANEL_SIZES.LANDSCAPE,
        gridColumn: GRID.TWO_THIRDS,
        gridRow: "1",
        acceptText: true,
      }, // Large square top left
      {
        ...PANEL_SIZES.PORTRAIT,
        gridColumn: "3",
        gridRow: "1",
        acceptText: false,
      }, // Portrait top right
      {
        ...PANEL_SIZES.LANDSCAPE,
        gridColumn: GRID.FULL_WIDTH,
        gridRow: "2",
        acceptText: false,
      }, // Full width landscape bottom
    ],
  },
  LAYOUT_3: {
    gridCols: 3,
    gridRows: 2,
    panels: [
      {
        ...PANEL_SIZES.SQUARE,
        gridColumn: GRID.TWO_THIRDS,
        gridRow: "1",
        acceptText: true,
      }, // Wide landscape top left
      {
        ...PANEL_SIZES.COLUMN,
        gridColumn: "3",
        gridRow: "1",
        acceptText: false,
      }, // COLUMN top right
      {
        ...PANEL_SIZES.COLUMN,
        gridColumn: "1",
        gridRow: "2",
        acceptText: false,
      }, // COLUMN bottom left
      {
        ...PANEL_SIZES.SQUARE,
        gridColumn: "2 / span 2",
        gridRow: "2",
        acceptText: true,
      }, // Wide landscape bottom right
    ],
  },
  LAYOUT_4: {
    gridCols: 2,
    gridRows: 3,
    panels: [
      {
        ...PANEL_SIZES.PANORAMIC,
        gridColumn: "1 / span 2",
        gridRow: "1",
        acceptText: true,
      }, // Wide panoramic top
      {
        ...PANEL_SIZES.COLUMN,
        gridColumn: "1",
        gridRow: GRID.FULL_HEIGHT_FROM_2,
        acceptText: false,
      }, // Tall portrait left
      {
        ...PANEL_SIZES.SQUARE,
        gridColumn: "2",
        gridRow: "2",
        acceptText: false,
      }, // Square middle right
      {
        ...PANEL_SIZES.SQUARE,
        gridColumn: "2",
        gridRow: "3",
        acceptText: false,
      }, // Square bottom right
    ],
  },
  LAYOUT_5: {
    gridCols: 3,
    gridRows: 3,
    panels: [
      {
        ...PANEL_SIZES.PANORAMIC,
        gridColumn: GRID.FULL_WIDTH,
        gridRow: "1",
        acceptText: false,
      }, // Wide panoramic top
      {
        ...PANEL_SIZES.COLUMN,
        gridColumn: "1",
        gridRow: "2 / span 2",
        acceptText: false,
      }, // Tall portrait left
      {
        ...PANEL_SIZES.POTRAIT,
        gridColumn: "2 / span 2",
        gridRow: "2 / span 2",
        acceptText: true,
      }, // Large square right
    ],
  },
  LAYOUT_7: {
    gridCols: 1,
    gridRows: 2,
    panels: [
      {
        ...PANEL_SIZES.LANDSCAPE,
        gridColumn: GRID.FULL_WIDTH,
        gridRow: "1",
        acceptText: true,
      }, // Portrait top right
      {
        ...PANEL_SIZES.LANDSCAPE,
        gridColumn: GRID.FULL_WIDTH,
        gridRow: "2",
        acceptText: true,
      }, // Full width landscape bottom
    ],
  },
};

export const defaultLayout = "LAYOUT_1";
export const nonRandomLayouts = Object.keys(LAYOUTS).filter(
  (layout) => layout !== "COVER"
);

// Grouper les layouts par nombre de panneaux
export const LAYOUTS_BY_PANEL_COUNT = {
  1: ["COVER"],
  2: ["LAYOUT_7"],
  3: ["LAYOUT_2", "LAYOUT_5"], //"LAYOUT_5"
  4: ["LAYOUT_3", "LAYOUT_4"], //, "LAYOUT_4"
};

// Helper functions for layout configuration
export const getNextLayoutType = (layoutCounter, imageCount) => {
  console.log("Getting layout for", { layoutCounter, imageCount });

  // Si pas d'images ou nombre invalide, utiliser COVER
  if (!imageCount || imageCount <= 0) {
    console.log("No images or invalid count, using COVER layout");
    return "COVER";
  }

  // Si on n'a qu'une seule image, toujours utiliser COVER
  if (imageCount === 1) {
    console.log("Single image, using COVER layout");
    return "COVER";
  }

  // Obtenir les layouts disponibles pour ce nombre d'images
  const availableLayouts = LAYOUTS_BY_PANEL_COUNT[imageCount];

  // Si on n'a pas de layout pour ce nombre d'images, utiliser COVER par défaut
  if (!availableLayouts) {
    console.warn(
      `No layout available for ${imageCount} images, falling back to COVER`
    );
    return "COVER";
  }

  // Sélectionner un layout de manière cyclique
  const layoutIndex = layoutCounter % availableLayouts.length;
  const selectedLayout = availableLayouts[layoutIndex];
  console.log(
    `Selected ${selectedLayout} for ${imageCount} images (layout counter: ${layoutCounter})`
  );
  return selectedLayout;
};

export const getLayoutDimensions = (layoutType, panelIndex) =>
  LAYOUTS[layoutType]?.panels[panelIndex];