@sguisse/react-grid-layout 2.2.3-sguisse.3

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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -0
  3. package/css/styles.css +120 -0
  4. package/dist/ResponsiveGridLayout-B_6TXsWM.d.ts +80 -0
  5. package/dist/ResponsiveGridLayout-Bin5MBC3.d.mts +80 -0
  6. package/dist/calculate-CoBSgofg.d.mts +196 -0
  7. package/dist/calculate-K0IBpu53.d.ts +196 -0
  8. package/dist/chunk-7BT7XXIT.js +74 -0
  9. package/dist/chunk-G3PAJYGP.mjs +72 -0
  10. package/dist/chunk-ITLZ7N2R.mjs +456 -0
  11. package/dist/chunk-J4LTYI7L.js +485 -0
  12. package/dist/chunk-KKV4ZCG4.mjs +583 -0
  13. package/dist/chunk-LQOPWRJR.js +623 -0
  14. package/dist/chunk-O3KX3VYW.mjs +1 -0
  15. package/dist/chunk-STBCV65G.js +3159 -0
  16. package/dist/chunk-UZL6BMXQ.mjs +3146 -0
  17. package/dist/chunk-ZJHF4QM5.js +2 -0
  18. package/dist/core.d.mts +160 -0
  19. package/dist/core.d.ts +160 -0
  20. package/dist/core.js +268 -0
  21. package/dist/core.mjs +3 -0
  22. package/dist/extras.d.mts +208 -0
  23. package/dist/extras.d.ts +208 -0
  24. package/dist/extras.js +388 -0
  25. package/dist/extras.mjs +380 -0
  26. package/dist/index.d.mts +7 -0
  27. package/dist/index.d.ts +7 -0
  28. package/dist/index.js +152 -0
  29. package/dist/index.mjs +5 -0
  30. package/dist/legacy.d.mts +163 -0
  31. package/dist/legacy.d.ts +163 -0
  32. package/dist/legacy.js +331 -0
  33. package/dist/legacy.mjs +319 -0
  34. package/dist/position-BeP60S5h.d.ts +316 -0
  35. package/dist/position-CeG3Nr4z.d.mts +316 -0
  36. package/dist/react.d.mts +214 -0
  37. package/dist/react.d.ts +214 -0
  38. package/dist/react.js +94 -0
  39. package/dist/react.mjs +5 -0
  40. package/dist/responsive-D4zBXLkH.d.ts +145 -0
  41. package/dist/responsive-DQi_9rBi.d.mts +145 -0
  42. package/dist/types-Dbg8jAWj.d.mts +458 -0
  43. package/dist/types-Dbg8jAWj.d.ts +458 -0
  44. package/index-dev.js +23 -0
  45. package/index.js +8 -0
  46. package/package.json +238 -0
package/dist/extras.js ADDED
@@ -0,0 +1,388 @@
1
+ 'use strict';
2
+
3
+ var chunkJ4LTYI7L_js = require('./chunk-J4LTYI7L.js');
4
+ var react = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ function GridBackground({
8
+ width,
9
+ cols,
10
+ rowHeight,
11
+ margin = [10, 10],
12
+ containerPadding,
13
+ rows = 10,
14
+ height,
15
+ color = "#e0e0e0",
16
+ borderRadius = 4,
17
+ className,
18
+ style
19
+ }) {
20
+ const dims = react.useMemo(
21
+ () => chunkJ4LTYI7L_js.calcGridCellDimensions({
22
+ width,
23
+ cols,
24
+ rowHeight,
25
+ margin,
26
+ containerPadding
27
+ }),
28
+ [width, cols, rowHeight, margin, containerPadding]
29
+ );
30
+ const rowCount = react.useMemo(() => {
31
+ if (rows !== "auto") return rows;
32
+ if (height) {
33
+ const padding = containerPadding ?? margin;
34
+ return Math.ceil(
35
+ (height - padding[1] * 2 + margin[1]) / (rowHeight + margin[1])
36
+ );
37
+ }
38
+ return 10;
39
+ }, [rows, height, rowHeight, margin, containerPadding]);
40
+ const totalHeight = react.useMemo(() => {
41
+ const padding = containerPadding ?? margin;
42
+ return padding[1] * 2 + rowCount * rowHeight + (rowCount - 1) * margin[1];
43
+ }, [rowCount, rowHeight, margin, containerPadding]);
44
+ const cells = react.useMemo(() => {
45
+ const rects = [];
46
+ const { cellWidth, cellHeight, offsetX, offsetY, gapX, gapY } = dims;
47
+ for (let row = 0; row < rowCount; row++) {
48
+ for (let col = 0; col < cols; col++) {
49
+ const x = offsetX + col * (cellWidth + gapX);
50
+ const y = offsetY + row * (cellHeight + gapY);
51
+ rects.push(
52
+ /* @__PURE__ */ jsxRuntime.jsx(
53
+ "rect",
54
+ {
55
+ x,
56
+ y,
57
+ width: cellWidth,
58
+ height: cellHeight,
59
+ rx: borderRadius,
60
+ ry: borderRadius,
61
+ fill: color
62
+ },
63
+ `${row}-${col}`
64
+ )
65
+ );
66
+ }
67
+ }
68
+ return rects;
69
+ }, [dims, rowCount, cols, borderRadius, color]);
70
+ return /* @__PURE__ */ jsxRuntime.jsx(
71
+ "svg",
72
+ {
73
+ className,
74
+ style: {
75
+ position: "absolute",
76
+ top: 0,
77
+ left: 0,
78
+ width,
79
+ height: totalHeight,
80
+ pointerEvents: "none",
81
+ ...style
82
+ },
83
+ "aria-hidden": "true",
84
+ children: cells
85
+ }
86
+ );
87
+ }
88
+
89
+ // src/extras/fastVerticalCompactor.ts
90
+ function collides(l1, l2) {
91
+ if (l1.i === l2.i) return false;
92
+ return l1.x < l2.x + l2.w && l1.x + l1.w > l2.x && l1.y < l2.y + l2.h && l1.y + l1.h > l2.y;
93
+ }
94
+ function compactVerticalFast(layout, cols, allowOverlap) {
95
+ const numItems = layout.length;
96
+ layout.sort((a, b) => {
97
+ if (a.y < b.y) return -1;
98
+ if (a.y > b.y) return 1;
99
+ if (a.x < b.x) return -1;
100
+ if (a.x > b.x) return 1;
101
+ if (a.static && !b.static) return -1;
102
+ if (!a.static && b.static) return 1;
103
+ return 0;
104
+ });
105
+ const tide = new Array(cols).fill(0);
106
+ const staticItems = layout.filter((item) => item.static);
107
+ const numStatics = staticItems.length;
108
+ let staticOffset = 0;
109
+ for (let i = 0; i < numItems; i++) {
110
+ const item = layout[i];
111
+ let x2 = item.x + item.w;
112
+ if (x2 > cols) {
113
+ x2 = cols;
114
+ }
115
+ if (item.static) {
116
+ ++staticOffset;
117
+ } else {
118
+ let minGap = Infinity;
119
+ for (let x = item.x; x < x2; ++x) {
120
+ const tideValue = tide[x] ?? 0;
121
+ const gap = item.y - tideValue;
122
+ if (gap < minGap) {
123
+ minGap = gap;
124
+ }
125
+ }
126
+ if (!allowOverlap || minGap > 0) {
127
+ item.y -= minGap;
128
+ }
129
+ for (let j = staticOffset; !allowOverlap && j < numStatics; ++j) {
130
+ const staticItem = staticItems[j];
131
+ if (staticItem === void 0) continue;
132
+ if (staticItem.y >= item.y + item.h) {
133
+ break;
134
+ }
135
+ if (collides(item, staticItem)) {
136
+ item.y = staticItem.y + staticItem.h;
137
+ if (j > staticOffset) {
138
+ j = staticOffset;
139
+ }
140
+ }
141
+ }
142
+ item.moved = false;
143
+ }
144
+ const t = item.y + item.h;
145
+ for (let x = item.x; x < x2; ++x) {
146
+ const currentTide = tide[x] ?? 0;
147
+ if (currentTide < t) {
148
+ tide[x] = t;
149
+ }
150
+ }
151
+ }
152
+ }
153
+ var fastVerticalCompactor = {
154
+ type: "vertical",
155
+ allowOverlap: false,
156
+ compact(layout, cols) {
157
+ const out = chunkJ4LTYI7L_js.cloneLayout(layout);
158
+ compactVerticalFast(out, cols, false);
159
+ return out;
160
+ }
161
+ };
162
+ var fastVerticalOverlapCompactor = {
163
+ ...fastVerticalCompactor,
164
+ allowOverlap: true,
165
+ compact(layout, cols) {
166
+ const out = chunkJ4LTYI7L_js.cloneLayout(layout);
167
+ compactVerticalFast(out, cols, true);
168
+ return out;
169
+ }
170
+ };
171
+
172
+ // src/extras/fastHorizontalCompactor.ts
173
+ function ensureTideRows(tide, neededRows) {
174
+ while (tide.length < neededRows) {
175
+ tide.push(0);
176
+ }
177
+ }
178
+ function getMaxTideForItem(tide, y, h) {
179
+ let maxTide = 0;
180
+ for (let row = y; row < y + h; row++) {
181
+ const tideValue = tide[row] ?? 0;
182
+ if (tideValue > maxTide) {
183
+ maxTide = tideValue;
184
+ }
185
+ }
186
+ return maxTide;
187
+ }
188
+ function canPlaceAt(item, x, y, staticItems, cols) {
189
+ if (x + item.w > cols) return false;
190
+ for (const staticItem of staticItems) {
191
+ if (x < staticItem.x + staticItem.w && x + item.w > staticItem.x && y < staticItem.y + staticItem.h && y + item.h > staticItem.y) {
192
+ return false;
193
+ }
194
+ }
195
+ return true;
196
+ }
197
+ function compactHorizontalFast(layout, cols, allowOverlap) {
198
+ const numItems = layout.length;
199
+ if (numItems === 0) return;
200
+ layout.sort((a, b) => {
201
+ if (a.x !== b.x) return a.x - b.x;
202
+ if (a.y !== b.y) return a.y - b.y;
203
+ if (a.static !== b.static) return a.static ? -1 : 1;
204
+ return 0;
205
+ });
206
+ let maxRow = 0;
207
+ for (let i = 0; i < numItems; i++) {
208
+ const item = layout[i];
209
+ if (item !== void 0) {
210
+ const bottom = item.y + item.h;
211
+ if (bottom > maxRow) maxRow = bottom;
212
+ }
213
+ }
214
+ const tide = new Array(maxRow).fill(0);
215
+ const staticItems = layout.filter((item) => item.static);
216
+ const maxRowLimit = Math.max(1e4, numItems * 100);
217
+ for (let i = 0; i < numItems; i++) {
218
+ const item = layout[i];
219
+ if (item.static) {
220
+ ensureTideRows(tide, item.y + item.h);
221
+ const t2 = item.x + item.w;
222
+ for (let y = item.y; y < item.y + item.h; y++) {
223
+ if ((tide[y] ?? 0) < t2) {
224
+ tide[y] = t2;
225
+ }
226
+ }
227
+ continue;
228
+ }
229
+ let targetY = item.y;
230
+ let targetX = 0;
231
+ let placed = false;
232
+ while (!placed) {
233
+ ensureTideRows(tide, targetY + item.h);
234
+ const maxTide = getMaxTideForItem(tide, targetY, item.h);
235
+ targetX = maxTide;
236
+ if (targetX + item.w <= cols) {
237
+ if (allowOverlap || canPlaceAt(item, targetX, targetY, staticItems, cols)) {
238
+ placed = true;
239
+ } else {
240
+ let maxStaticRight = targetX;
241
+ let foundCollision = false;
242
+ for (const staticItem of staticItems) {
243
+ if (targetX < staticItem.x + staticItem.w && targetX + item.w > staticItem.x && targetY < staticItem.y + staticItem.h && targetY + item.h > staticItem.y) {
244
+ maxStaticRight = Math.max(
245
+ maxStaticRight,
246
+ staticItem.x + staticItem.w
247
+ );
248
+ foundCollision = true;
249
+ }
250
+ }
251
+ if (foundCollision) {
252
+ targetX = maxStaticRight;
253
+ }
254
+ if (foundCollision && targetX + item.w <= cols) {
255
+ if (canPlaceAt(item, targetX, targetY, staticItems, cols)) {
256
+ placed = true;
257
+ } else {
258
+ targetY++;
259
+ }
260
+ } else if (foundCollision) {
261
+ targetY++;
262
+ } else {
263
+ placed = true;
264
+ }
265
+ }
266
+ } else {
267
+ targetY++;
268
+ }
269
+ if (targetY > maxRowLimit) {
270
+ if (typeof console !== "undefined" && console.warn) {
271
+ console.warn(
272
+ `Fast horizontal compactor: Item "${item.i}" exceeded max row limit (${targetY}). This may indicate a layout that cannot be compacted within grid bounds.`
273
+ );
274
+ }
275
+ targetX = 0;
276
+ placed = true;
277
+ }
278
+ }
279
+ item.x = targetX;
280
+ item.y = targetY;
281
+ item.moved = false;
282
+ ensureTideRows(tide, targetY + item.h);
283
+ const t = targetX + item.w;
284
+ for (let y = targetY; y < targetY + item.h; y++) {
285
+ if ((tide[y] ?? 0) < t) {
286
+ tide[y] = t;
287
+ }
288
+ }
289
+ }
290
+ }
291
+ var fastHorizontalCompactor = {
292
+ type: "horizontal",
293
+ allowOverlap: false,
294
+ compact(layout, cols) {
295
+ const out = chunkJ4LTYI7L_js.cloneLayout(layout);
296
+ compactHorizontalFast(out, cols, false);
297
+ return out;
298
+ }
299
+ };
300
+ var fastHorizontalOverlapCompactor = {
301
+ ...fastHorizontalCompactor,
302
+ allowOverlap: true,
303
+ compact(layout, cols) {
304
+ const out = chunkJ4LTYI7L_js.cloneLayout(layout);
305
+ compactHorizontalFast(out, cols, true);
306
+ return out;
307
+ }
308
+ };
309
+
310
+ // src/extras/wrapCompactor.ts
311
+ function sortByWrapOrder(layout) {
312
+ return [...layout].sort((a, b) => {
313
+ if (a.y !== b.y) return a.y - b.y;
314
+ return a.x - b.x;
315
+ });
316
+ }
317
+ function fromWrapPosition(pos, cols) {
318
+ return {
319
+ x: pos % cols,
320
+ y: Math.floor(pos / cols)
321
+ };
322
+ }
323
+ function compactWrap(layout, cols) {
324
+ if (layout.length === 0) return [];
325
+ const sorted = sortByWrapOrder(layout);
326
+ const out = new Array(layout.length);
327
+ const statics = sorted.filter((item) => item.static);
328
+ const staticPositions = /* @__PURE__ */ new Set();
329
+ for (const s of statics) {
330
+ for (let dy = 0; dy < s.h; dy++) {
331
+ for (let dx = 0; dx < s.w; dx++) {
332
+ staticPositions.add((s.y + dy) * cols + (s.x + dx));
333
+ }
334
+ }
335
+ }
336
+ let nextPos = 0;
337
+ for (let i = 0; i < sorted.length; i++) {
338
+ const sortedItem = sorted[i];
339
+ if (sortedItem === void 0) continue;
340
+ const l = chunkJ4LTYI7L_js.cloneLayoutItem(sortedItem);
341
+ if (l.static) {
342
+ const originalIndex2 = layout.indexOf(sortedItem);
343
+ out[originalIndex2] = l;
344
+ l.moved = false;
345
+ continue;
346
+ }
347
+ while (staticPositions.has(nextPos)) {
348
+ nextPos++;
349
+ }
350
+ const { x, y } = fromWrapPosition(nextPos, cols);
351
+ if (x + l.w > cols) {
352
+ nextPos = (y + 1) * cols;
353
+ while (staticPositions.has(nextPos)) {
354
+ nextPos++;
355
+ }
356
+ }
357
+ const newCoords = fromWrapPosition(nextPos, cols);
358
+ l.x = newCoords.x;
359
+ l.y = newCoords.y;
360
+ nextPos += l.w;
361
+ const originalIndex = layout.indexOf(sortedItem);
362
+ out[originalIndex] = l;
363
+ l.moved = false;
364
+ }
365
+ return out;
366
+ }
367
+ var wrapCompactor = {
368
+ type: "wrap",
369
+ allowOverlap: false,
370
+ compact(layout, cols) {
371
+ return compactWrap(layout, cols);
372
+ }
373
+ };
374
+ var wrapOverlapCompactor = {
375
+ ...wrapCompactor,
376
+ allowOverlap: true,
377
+ compact(layout, _cols) {
378
+ return chunkJ4LTYI7L_js.cloneLayout(layout);
379
+ }
380
+ };
381
+
382
+ exports.GridBackground = GridBackground;
383
+ exports.fastHorizontalCompactor = fastHorizontalCompactor;
384
+ exports.fastHorizontalOverlapCompactor = fastHorizontalOverlapCompactor;
385
+ exports.fastVerticalCompactor = fastVerticalCompactor;
386
+ exports.fastVerticalOverlapCompactor = fastVerticalOverlapCompactor;
387
+ exports.wrapCompactor = wrapCompactor;
388
+ exports.wrapOverlapCompactor = wrapOverlapCompactor;