@grandbazar/ui-baza 1.9.0 → 1.10.1
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/bento.cjs +102 -45
- package/dist/bento.d.ts +3 -2
- package/dist/bento.js +102 -45
- package/dist/index.d.ts +3 -2
- package/package.json +1 -1
package/dist/bento.cjs
CHANGED
|
@@ -55,23 +55,48 @@ const BENTO_TILE_SHAPE_BY_SIZE = {
|
|
|
55
55
|
"2x2": "square",
|
|
56
56
|
"4x1": "wideStrip",
|
|
57
57
|
"4x2": "wide",
|
|
58
|
+
"4x3": "wide",
|
|
58
59
|
"6x2": "long",
|
|
60
|
+
"6x3": "long",
|
|
59
61
|
"8x2": "long",
|
|
60
62
|
"8x3": "long",
|
|
61
|
-
"
|
|
63
|
+
"4x4": "large",
|
|
64
|
+
"4x5": "large",
|
|
65
|
+
"6x6": "large",
|
|
66
|
+
"6x7": "large"
|
|
62
67
|
};
|
|
63
68
|
|
|
64
|
-
const BENTO_SIZES = [
|
|
69
|
+
const BENTO_SIZES = [
|
|
70
|
+
"1x1",
|
|
71
|
+
"2x1",
|
|
72
|
+
"2x2",
|
|
73
|
+
"4x1",
|
|
74
|
+
"4x2",
|
|
75
|
+
"4x3",
|
|
76
|
+
"6x2",
|
|
77
|
+
"6x3",
|
|
78
|
+
"8x2",
|
|
79
|
+
"8x3",
|
|
80
|
+
"4x4",
|
|
81
|
+
"4x5",
|
|
82
|
+
"6x6",
|
|
83
|
+
"6x7"
|
|
84
|
+
];
|
|
65
85
|
const BENTO_SPANS = {
|
|
66
86
|
"1x1": { columns: 1, rows: 1 },
|
|
67
87
|
"2x1": { columns: 2, rows: 1 },
|
|
68
88
|
"2x2": { columns: 2, rows: 2 },
|
|
69
89
|
"4x1": { columns: 4, rows: 1 },
|
|
70
90
|
"4x2": { columns: 4, rows: 2 },
|
|
91
|
+
"4x3": { columns: 4, rows: 3 },
|
|
71
92
|
"6x2": { columns: 6, rows: 2 },
|
|
93
|
+
"6x3": { columns: 6, rows: 3 },
|
|
72
94
|
"8x2": { columns: 8, rows: 2 },
|
|
73
95
|
"8x3": { columns: 8, rows: 3 },
|
|
74
|
-
"
|
|
96
|
+
"4x4": { columns: 4, rows: 4 },
|
|
97
|
+
"4x5": { columns: 4, rows: 5 },
|
|
98
|
+
"6x6": { columns: 6, rows: 6 },
|
|
99
|
+
"6x7": { columns: 6, rows: 7 }
|
|
75
100
|
};
|
|
76
101
|
const BENTO_FALLBACKS = {
|
|
77
102
|
"1x1": ["2x1", "2x2"],
|
|
@@ -79,15 +104,20 @@ const BENTO_FALLBACKS = {
|
|
|
79
104
|
"2x2": ["4x2", "2x1", "6x2"],
|
|
80
105
|
"4x1": ["4x2", "2x1", "2x2"],
|
|
81
106
|
"4x2": ["2x2", "4x1", "6x2", "8x2", "8x3"],
|
|
107
|
+
"4x3": ["4x2", "4x1", "2x2"],
|
|
82
108
|
"6x2": ["4x2", "8x2", "8x3", "2x2"],
|
|
109
|
+
"6x3": ["6x2", "8x3", "4x2", "8x2"],
|
|
83
110
|
"8x2": ["8x3", "6x2", "4x2", "2x2"],
|
|
84
111
|
"8x3": ["8x2", "6x2", "4x2"],
|
|
85
|
-
"
|
|
112
|
+
"4x4": [],
|
|
113
|
+
"4x5": [],
|
|
114
|
+
"6x6": [],
|
|
115
|
+
"6x7": []
|
|
86
116
|
};
|
|
87
117
|
const BENTO_THIN_SIZES = ["2x1", "4x1"];
|
|
88
118
|
const BENTO_CONFIGURABLE_SIZES = {
|
|
89
|
-
mobile: ["2x2", "4x2", "4x1", "2x1", "1x1"],
|
|
90
|
-
desktop: ["2x2", "4x2", "6x2", "8x2", "8x3", "4x1"]
|
|
119
|
+
mobile: ["2x2", "4x2", "4x3", "4x1", "2x1", "1x1"],
|
|
120
|
+
desktop: ["2x2", "4x2", "6x2", "6x3", "8x2", "8x3", "4x1"]
|
|
91
121
|
};
|
|
92
122
|
const BENTO_AUTO_SIZES = {
|
|
93
123
|
mobile: ["2x2", "2x1", "4x2", "4x1"],
|
|
@@ -99,10 +129,15 @@ const BENTO_MOBILE_SIZE_BY_DESKTOP = {
|
|
|
99
129
|
"2x2": "2x2",
|
|
100
130
|
"4x1": "4x1",
|
|
101
131
|
"4x2": "4x2",
|
|
132
|
+
"4x3": "4x3",
|
|
102
133
|
"6x2": "4x2",
|
|
134
|
+
"6x3": "4x2",
|
|
103
135
|
"8x2": "4x2",
|
|
104
136
|
"8x3": "4x2",
|
|
105
|
-
"
|
|
137
|
+
"4x4": "4x4",
|
|
138
|
+
"4x5": "4x5",
|
|
139
|
+
"6x6": "4x4",
|
|
140
|
+
"6x7": "4x5"
|
|
106
141
|
};
|
|
107
142
|
const BENTO_MAX_RESIZES = 5;
|
|
108
143
|
const BENTO_SEARCH_NODE_LIMIT = 3e4;
|
|
@@ -112,6 +147,37 @@ function toBentoSpan(size, columns) {
|
|
|
112
147
|
return { columns: Math.min(span.columns, columns), rows: span.rows };
|
|
113
148
|
}
|
|
114
149
|
|
|
150
|
+
function countBentoHoles(sizes, columns) {
|
|
151
|
+
const takenRows = [];
|
|
152
|
+
let takenCellCount = 0;
|
|
153
|
+
const fits = (row, mask, rowSpan) => {
|
|
154
|
+
for (let offset = 0; offset < rowSpan; offset++) {
|
|
155
|
+
if ((takenRows[row + offset] ?? 0) & mask) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
};
|
|
161
|
+
for (const size of sizes) {
|
|
162
|
+
const span = toBentoSpan(size, columns);
|
|
163
|
+
const widthMask = (1 << span.columns) - 1;
|
|
164
|
+
let isPlaced = false;
|
|
165
|
+
for (let row = 0; !isPlaced; row++) {
|
|
166
|
+
for (let column = 0; column + span.columns <= columns && !isPlaced; column++) {
|
|
167
|
+
const mask = widthMask << column;
|
|
168
|
+
if (fits(row, mask, span.rows)) {
|
|
169
|
+
for (let offset = 0; offset < span.rows; offset++) {
|
|
170
|
+
takenRows[row + offset] = (takenRows[row + offset] ?? 0) | mask;
|
|
171
|
+
}
|
|
172
|
+
isPlaced = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
takenCellCount += span.columns * span.rows;
|
|
177
|
+
}
|
|
178
|
+
return takenRows.length * columns - takenCellCount;
|
|
179
|
+
}
|
|
180
|
+
|
|
115
181
|
function findHoleFreeBentoSizes(preferredSizes, slots, columns) {
|
|
116
182
|
const fullRow = (1 << columns) - 1;
|
|
117
183
|
const innerEdges = (1 << columns - 1) - 1;
|
|
@@ -206,6 +272,14 @@ function findHoleFreeBentoSizes(preferredSizes, slots, columns) {
|
|
|
206
272
|
return null;
|
|
207
273
|
}
|
|
208
274
|
|
|
275
|
+
function isBentoDevMode() {
|
|
276
|
+
try {
|
|
277
|
+
return process.env.NODE_ENV !== "production";
|
|
278
|
+
} catch {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
209
283
|
function arrangeBento(slots, { columns, presets, rhythm }) {
|
|
210
284
|
const fitAllowed = (size, { allowedSizes }) => {
|
|
211
285
|
return [size, ...BENTO_FALLBACKS[size]].find((candidate) => allowedSizes.includes(candidate)) ?? allowedSizes[0] ?? size;
|
|
@@ -224,7 +298,16 @@ function arrangeBento(slots, { columns, presets, rhythm }) {
|
|
|
224
298
|
});
|
|
225
299
|
};
|
|
226
300
|
const preferredSizes = layOut({ isPreferenceKept: true });
|
|
227
|
-
|
|
301
|
+
const arrangedSizes = findHoleFreeBentoSizes(preferredSizes, slots, columns) ?? findHoleFreeBentoSizes(layOut({ isPreferenceKept: false }), slots, columns) ?? preferredSizes;
|
|
302
|
+
if (isBentoDevMode()) {
|
|
303
|
+
const holeCount = countBentoHoles(arrangedSizes, columns);
|
|
304
|
+
if (holeCount > 0) {
|
|
305
|
+
console.warn(
|
|
306
|
+
`arrangeBento: no hole-free arrangement on a ${columns}-column grid, ${holeCount} cell(s) left empty: ${arrangedSizes.join(", ")}`
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return arrangedSizes;
|
|
228
311
|
}
|
|
229
312
|
|
|
230
313
|
function arrangeBentoGrids(slotsByGrid) {
|
|
@@ -236,47 +319,21 @@ function arrangeBentoGrids(slotsByGrid) {
|
|
|
236
319
|
});
|
|
237
320
|
}
|
|
238
321
|
|
|
239
|
-
function
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
const
|
|
243
|
-
for (let offset = 0; offset < rowSpan; offset++) {
|
|
244
|
-
if ((takenRows[row + offset] ?? 0) & mask) {
|
|
245
|
-
return false;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return true;
|
|
249
|
-
};
|
|
250
|
-
for (const size of sizes) {
|
|
251
|
-
const span = toBentoSpan(size, columns);
|
|
252
|
-
const widthMask = (1 << span.columns) - 1;
|
|
253
|
-
let isPlaced = false;
|
|
254
|
-
for (let row = 0; !isPlaced; row++) {
|
|
255
|
-
for (let column = 0; column + span.columns <= columns && !isPlaced; column++) {
|
|
256
|
-
const mask = widthMask << column;
|
|
257
|
-
if (fits(row, mask, span.rows)) {
|
|
258
|
-
for (let offset = 0; offset < span.rows; offset++) {
|
|
259
|
-
takenRows[row + offset] = (takenRows[row + offset] ?? 0) | mask;
|
|
260
|
-
}
|
|
261
|
-
isPlaced = true;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
takenCellCount += span.columns * span.rows;
|
|
266
|
-
}
|
|
267
|
-
return takenRows.length * columns - takenCellCount;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function toBentoSlot(grid, { allowedSizes, sizes, defaultSize }) {
|
|
271
|
-
const fixedSize = allowedSizes.length === 1 && allowedSizes[0] || sizes[grid];
|
|
322
|
+
function toBentoSlot(grid, { allowedSizes, sizes, defaultSize, isAdjustable = false }) {
|
|
323
|
+
const givenSize = sizes[grid];
|
|
324
|
+
const fixedSize = allowedSizes.length === 1 && allowedSizes[0] || !isAdjustable && givenSize;
|
|
325
|
+
const autoSizes = BENTO_AUTO_SIZES[grid].filter((size) => allowedSizes.includes(size));
|
|
272
326
|
if (fixedSize) {
|
|
273
327
|
return { preferredSize: fixedSize, allowedSizes: [fixedSize] };
|
|
274
328
|
}
|
|
329
|
+
if (givenSize) {
|
|
330
|
+
return {
|
|
331
|
+
preferredSize: givenSize,
|
|
332
|
+
allowedSizes: autoSizes.includes(givenSize) ? autoSizes : [...autoSizes, givenSize]
|
|
333
|
+
};
|
|
334
|
+
}
|
|
275
335
|
const sizeFromDesktop = grid === "mobile" && sizes.desktop && BENTO_MOBILE_SIZE_BY_DESKTOP[sizes.desktop];
|
|
276
|
-
return {
|
|
277
|
-
preferredSize: sizeFromDesktop || defaultSize,
|
|
278
|
-
allowedSizes: BENTO_AUTO_SIZES[grid].filter((size) => allowedSizes.includes(size))
|
|
279
|
-
};
|
|
336
|
+
return { preferredSize: sizeFromDesktop || defaultSize, allowedSizes: autoSizes };
|
|
280
337
|
}
|
|
281
338
|
|
|
282
339
|
exports.BENTO_AUTO_SIZES = BENTO_AUTO_SIZES;
|
package/dist/bento.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const BENTO_GRIDS: Record<TBentoGrid, TBentoGridRules>;
|
|
|
12
12
|
|
|
13
13
|
export declare const BENTO_MOBILE_SIZE_BY_DESKTOP: Record<TBentoSize, TBentoSize>;
|
|
14
14
|
|
|
15
|
-
export declare const BENTO_SIZES: readonly ["1x1", "2x1", "2x2", "4x1", "4x2", "6x2", "8x2", "8x3", "4x5"];
|
|
15
|
+
export declare const BENTO_SIZES: readonly ["1x1", "2x1", "2x2", "4x1", "4x2", "4x3", "6x2", "6x3", "8x2", "8x3", "4x4", "4x5", "6x6", "6x7"];
|
|
16
16
|
|
|
17
17
|
export declare const BENTO_THIN_SIZES: readonly TBentoSize[];
|
|
18
18
|
|
|
@@ -45,10 +45,11 @@ declare type TBentoSlotSource = {
|
|
|
45
45
|
allowedSizes: readonly TBentoSize[];
|
|
46
46
|
sizes: Partial<Record<TBentoGrid, TBentoSize | null>>;
|
|
47
47
|
defaultSize: TBentoSize | null;
|
|
48
|
+
isAdjustable?: boolean;
|
|
48
49
|
};
|
|
49
50
|
|
|
50
51
|
export declare type TBentoTileShape = TArrayElement<typeof BENTO_TILE_SHAPES>;
|
|
51
52
|
|
|
52
|
-
export declare function toBentoSlot(grid: TBentoGrid, { allowedSizes, sizes, defaultSize }: TBentoSlotSource): TBentoSlot;
|
|
53
|
+
export declare function toBentoSlot(grid: TBentoGrid, { allowedSizes, sizes, defaultSize, isAdjustable }: TBentoSlotSource): TBentoSlot;
|
|
53
54
|
|
|
54
55
|
export { }
|
package/dist/bento.js
CHANGED
|
@@ -51,23 +51,48 @@ const BENTO_TILE_SHAPE_BY_SIZE = {
|
|
|
51
51
|
"2x2": "square",
|
|
52
52
|
"4x1": "wideStrip",
|
|
53
53
|
"4x2": "wide",
|
|
54
|
+
"4x3": "wide",
|
|
54
55
|
"6x2": "long",
|
|
56
|
+
"6x3": "long",
|
|
55
57
|
"8x2": "long",
|
|
56
58
|
"8x3": "long",
|
|
57
|
-
"
|
|
59
|
+
"4x4": "large",
|
|
60
|
+
"4x5": "large",
|
|
61
|
+
"6x6": "large",
|
|
62
|
+
"6x7": "large"
|
|
58
63
|
};
|
|
59
64
|
|
|
60
|
-
const BENTO_SIZES = [
|
|
65
|
+
const BENTO_SIZES = [
|
|
66
|
+
"1x1",
|
|
67
|
+
"2x1",
|
|
68
|
+
"2x2",
|
|
69
|
+
"4x1",
|
|
70
|
+
"4x2",
|
|
71
|
+
"4x3",
|
|
72
|
+
"6x2",
|
|
73
|
+
"6x3",
|
|
74
|
+
"8x2",
|
|
75
|
+
"8x3",
|
|
76
|
+
"4x4",
|
|
77
|
+
"4x5",
|
|
78
|
+
"6x6",
|
|
79
|
+
"6x7"
|
|
80
|
+
];
|
|
61
81
|
const BENTO_SPANS = {
|
|
62
82
|
"1x1": { columns: 1, rows: 1 },
|
|
63
83
|
"2x1": { columns: 2, rows: 1 },
|
|
64
84
|
"2x2": { columns: 2, rows: 2 },
|
|
65
85
|
"4x1": { columns: 4, rows: 1 },
|
|
66
86
|
"4x2": { columns: 4, rows: 2 },
|
|
87
|
+
"4x3": { columns: 4, rows: 3 },
|
|
67
88
|
"6x2": { columns: 6, rows: 2 },
|
|
89
|
+
"6x3": { columns: 6, rows: 3 },
|
|
68
90
|
"8x2": { columns: 8, rows: 2 },
|
|
69
91
|
"8x3": { columns: 8, rows: 3 },
|
|
70
|
-
"
|
|
92
|
+
"4x4": { columns: 4, rows: 4 },
|
|
93
|
+
"4x5": { columns: 4, rows: 5 },
|
|
94
|
+
"6x6": { columns: 6, rows: 6 },
|
|
95
|
+
"6x7": { columns: 6, rows: 7 }
|
|
71
96
|
};
|
|
72
97
|
const BENTO_FALLBACKS = {
|
|
73
98
|
"1x1": ["2x1", "2x2"],
|
|
@@ -75,15 +100,20 @@ const BENTO_FALLBACKS = {
|
|
|
75
100
|
"2x2": ["4x2", "2x1", "6x2"],
|
|
76
101
|
"4x1": ["4x2", "2x1", "2x2"],
|
|
77
102
|
"4x2": ["2x2", "4x1", "6x2", "8x2", "8x3"],
|
|
103
|
+
"4x3": ["4x2", "4x1", "2x2"],
|
|
78
104
|
"6x2": ["4x2", "8x2", "8x3", "2x2"],
|
|
105
|
+
"6x3": ["6x2", "8x3", "4x2", "8x2"],
|
|
79
106
|
"8x2": ["8x3", "6x2", "4x2", "2x2"],
|
|
80
107
|
"8x3": ["8x2", "6x2", "4x2"],
|
|
81
|
-
"
|
|
108
|
+
"4x4": [],
|
|
109
|
+
"4x5": [],
|
|
110
|
+
"6x6": [],
|
|
111
|
+
"6x7": []
|
|
82
112
|
};
|
|
83
113
|
const BENTO_THIN_SIZES = ["2x1", "4x1"];
|
|
84
114
|
const BENTO_CONFIGURABLE_SIZES = {
|
|
85
|
-
mobile: ["2x2", "4x2", "4x1", "2x1", "1x1"],
|
|
86
|
-
desktop: ["2x2", "4x2", "6x2", "8x2", "8x3", "4x1"]
|
|
115
|
+
mobile: ["2x2", "4x2", "4x3", "4x1", "2x1", "1x1"],
|
|
116
|
+
desktop: ["2x2", "4x2", "6x2", "6x3", "8x2", "8x3", "4x1"]
|
|
87
117
|
};
|
|
88
118
|
const BENTO_AUTO_SIZES = {
|
|
89
119
|
mobile: ["2x2", "2x1", "4x2", "4x1"],
|
|
@@ -95,10 +125,15 @@ const BENTO_MOBILE_SIZE_BY_DESKTOP = {
|
|
|
95
125
|
"2x2": "2x2",
|
|
96
126
|
"4x1": "4x1",
|
|
97
127
|
"4x2": "4x2",
|
|
128
|
+
"4x3": "4x3",
|
|
98
129
|
"6x2": "4x2",
|
|
130
|
+
"6x3": "4x2",
|
|
99
131
|
"8x2": "4x2",
|
|
100
132
|
"8x3": "4x2",
|
|
101
|
-
"
|
|
133
|
+
"4x4": "4x4",
|
|
134
|
+
"4x5": "4x5",
|
|
135
|
+
"6x6": "4x4",
|
|
136
|
+
"6x7": "4x5"
|
|
102
137
|
};
|
|
103
138
|
const BENTO_MAX_RESIZES = 5;
|
|
104
139
|
const BENTO_SEARCH_NODE_LIMIT = 3e4;
|
|
@@ -108,6 +143,37 @@ function toBentoSpan(size, columns) {
|
|
|
108
143
|
return { columns: Math.min(span.columns, columns), rows: span.rows };
|
|
109
144
|
}
|
|
110
145
|
|
|
146
|
+
function countBentoHoles(sizes, columns) {
|
|
147
|
+
const takenRows = [];
|
|
148
|
+
let takenCellCount = 0;
|
|
149
|
+
const fits = (row, mask, rowSpan) => {
|
|
150
|
+
for (let offset = 0; offset < rowSpan; offset++) {
|
|
151
|
+
if ((takenRows[row + offset] ?? 0) & mask) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
};
|
|
157
|
+
for (const size of sizes) {
|
|
158
|
+
const span = toBentoSpan(size, columns);
|
|
159
|
+
const widthMask = (1 << span.columns) - 1;
|
|
160
|
+
let isPlaced = false;
|
|
161
|
+
for (let row = 0; !isPlaced; row++) {
|
|
162
|
+
for (let column = 0; column + span.columns <= columns && !isPlaced; column++) {
|
|
163
|
+
const mask = widthMask << column;
|
|
164
|
+
if (fits(row, mask, span.rows)) {
|
|
165
|
+
for (let offset = 0; offset < span.rows; offset++) {
|
|
166
|
+
takenRows[row + offset] = (takenRows[row + offset] ?? 0) | mask;
|
|
167
|
+
}
|
|
168
|
+
isPlaced = true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
takenCellCount += span.columns * span.rows;
|
|
173
|
+
}
|
|
174
|
+
return takenRows.length * columns - takenCellCount;
|
|
175
|
+
}
|
|
176
|
+
|
|
111
177
|
function findHoleFreeBentoSizes(preferredSizes, slots, columns) {
|
|
112
178
|
const fullRow = (1 << columns) - 1;
|
|
113
179
|
const innerEdges = (1 << columns - 1) - 1;
|
|
@@ -202,6 +268,14 @@ function findHoleFreeBentoSizes(preferredSizes, slots, columns) {
|
|
|
202
268
|
return null;
|
|
203
269
|
}
|
|
204
270
|
|
|
271
|
+
function isBentoDevMode() {
|
|
272
|
+
try {
|
|
273
|
+
return process.env.NODE_ENV !== "production";
|
|
274
|
+
} catch {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
205
279
|
function arrangeBento(slots, { columns, presets, rhythm }) {
|
|
206
280
|
const fitAllowed = (size, { allowedSizes }) => {
|
|
207
281
|
return [size, ...BENTO_FALLBACKS[size]].find((candidate) => allowedSizes.includes(candidate)) ?? allowedSizes[0] ?? size;
|
|
@@ -220,7 +294,16 @@ function arrangeBento(slots, { columns, presets, rhythm }) {
|
|
|
220
294
|
});
|
|
221
295
|
};
|
|
222
296
|
const preferredSizes = layOut({ isPreferenceKept: true });
|
|
223
|
-
|
|
297
|
+
const arrangedSizes = findHoleFreeBentoSizes(preferredSizes, slots, columns) ?? findHoleFreeBentoSizes(layOut({ isPreferenceKept: false }), slots, columns) ?? preferredSizes;
|
|
298
|
+
if (isBentoDevMode()) {
|
|
299
|
+
const holeCount = countBentoHoles(arrangedSizes, columns);
|
|
300
|
+
if (holeCount > 0) {
|
|
301
|
+
console.warn(
|
|
302
|
+
`arrangeBento: no hole-free arrangement on a ${columns}-column grid, ${holeCount} cell(s) left empty: ${arrangedSizes.join(", ")}`
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return arrangedSizes;
|
|
224
307
|
}
|
|
225
308
|
|
|
226
309
|
function arrangeBentoGrids(slotsByGrid) {
|
|
@@ -232,47 +315,21 @@ function arrangeBentoGrids(slotsByGrid) {
|
|
|
232
315
|
});
|
|
233
316
|
}
|
|
234
317
|
|
|
235
|
-
function
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
for (let offset = 0; offset < rowSpan; offset++) {
|
|
240
|
-
if ((takenRows[row + offset] ?? 0) & mask) {
|
|
241
|
-
return false;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return true;
|
|
245
|
-
};
|
|
246
|
-
for (const size of sizes) {
|
|
247
|
-
const span = toBentoSpan(size, columns);
|
|
248
|
-
const widthMask = (1 << span.columns) - 1;
|
|
249
|
-
let isPlaced = false;
|
|
250
|
-
for (let row = 0; !isPlaced; row++) {
|
|
251
|
-
for (let column = 0; column + span.columns <= columns && !isPlaced; column++) {
|
|
252
|
-
const mask = widthMask << column;
|
|
253
|
-
if (fits(row, mask, span.rows)) {
|
|
254
|
-
for (let offset = 0; offset < span.rows; offset++) {
|
|
255
|
-
takenRows[row + offset] = (takenRows[row + offset] ?? 0) | mask;
|
|
256
|
-
}
|
|
257
|
-
isPlaced = true;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
takenCellCount += span.columns * span.rows;
|
|
262
|
-
}
|
|
263
|
-
return takenRows.length * columns - takenCellCount;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function toBentoSlot(grid, { allowedSizes, sizes, defaultSize }) {
|
|
267
|
-
const fixedSize = allowedSizes.length === 1 && allowedSizes[0] || sizes[grid];
|
|
318
|
+
function toBentoSlot(grid, { allowedSizes, sizes, defaultSize, isAdjustable = false }) {
|
|
319
|
+
const givenSize = sizes[grid];
|
|
320
|
+
const fixedSize = allowedSizes.length === 1 && allowedSizes[0] || !isAdjustable && givenSize;
|
|
321
|
+
const autoSizes = BENTO_AUTO_SIZES[grid].filter((size) => allowedSizes.includes(size));
|
|
268
322
|
if (fixedSize) {
|
|
269
323
|
return { preferredSize: fixedSize, allowedSizes: [fixedSize] };
|
|
270
324
|
}
|
|
325
|
+
if (givenSize) {
|
|
326
|
+
return {
|
|
327
|
+
preferredSize: givenSize,
|
|
328
|
+
allowedSizes: autoSizes.includes(givenSize) ? autoSizes : [...autoSizes, givenSize]
|
|
329
|
+
};
|
|
330
|
+
}
|
|
271
331
|
const sizeFromDesktop = grid === "mobile" && sizes.desktop && BENTO_MOBILE_SIZE_BY_DESKTOP[sizes.desktop];
|
|
272
|
-
return {
|
|
273
|
-
preferredSize: sizeFromDesktop || defaultSize,
|
|
274
|
-
allowedSizes: BENTO_AUTO_SIZES[grid].filter((size) => allowedSizes.includes(size))
|
|
275
|
-
};
|
|
332
|
+
return { preferredSize: sizeFromDesktop || defaultSize, allowedSizes: autoSizes };
|
|
276
333
|
}
|
|
277
334
|
|
|
278
335
|
export { BENTO_AUTO_SIZES, BENTO_CONFIGURABLE_SIZES, BENTO_GRIDS, BENTO_GRID_NAMES, BENTO_MOBILE_SIZE_BY_DESKTOP, BENTO_SIZES, BENTO_THIN_SIZES, BENTO_TILE_SHAPES, BENTO_TILE_SHAPE_BY_SIZE, arrangeBento, arrangeBentoGrids, countBentoHoles, toBentoSlot };
|
package/dist/index.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ export declare const BENTO_GRIDS: Record<TBentoGrid, TBentoGridRules>;
|
|
|
64
64
|
|
|
65
65
|
export declare const BENTO_MOBILE_SIZE_BY_DESKTOP: Record<TBentoSize, TBentoSize>;
|
|
66
66
|
|
|
67
|
-
export declare const BENTO_SIZES: readonly ["1x1", "2x1", "2x2", "4x1", "4x2", "6x2", "8x2", "8x3", "4x5"];
|
|
67
|
+
export declare const BENTO_SIZES: readonly ["1x1", "2x1", "2x2", "4x1", "4x2", "4x3", "6x2", "6x3", "8x2", "8x3", "4x4", "4x5", "6x6", "6x7"];
|
|
68
68
|
|
|
69
69
|
export declare const BENTO_THIN_SIZES: readonly TBentoSize[];
|
|
70
70
|
|
|
@@ -821,6 +821,7 @@ declare type TBentoSlotSource = {
|
|
|
821
821
|
allowedSizes: readonly TBentoSize[];
|
|
822
822
|
sizes: Partial<Record<TBentoGrid, TBentoSize | null>>;
|
|
823
823
|
defaultSize: TBentoSize | null;
|
|
824
|
+
isAdjustable?: boolean;
|
|
824
825
|
};
|
|
825
826
|
|
|
826
827
|
export declare type TBentoTileShape = TArrayElement<typeof BENTO_TILE_SHAPES>;
|
|
@@ -986,7 +987,7 @@ declare type TNotificationInlineProps = Omit<React.HTMLAttributes<HTMLDivElement
|
|
|
986
987
|
onClose?: () => void;
|
|
987
988
|
};
|
|
988
989
|
|
|
989
|
-
export declare function toBentoSlot(grid: TBentoGrid, { allowedSizes, sizes, defaultSize }: TBentoSlotSource): TBentoSlot;
|
|
990
|
+
export declare function toBentoSlot(grid: TBentoGrid, { allowedSizes, sizes, defaultSize, isAdjustable }: TBentoSlotSource): TBentoSlot;
|
|
990
991
|
|
|
991
992
|
/**
|
|
992
993
|
* Tooltip is a compound component for displaying contextual hints.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grandbazar/ui-baza",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "A lightweight and modular UI kit for building modern, accessible web interfaces. Designed for flexibility, scalability, and developer happiness.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|