panelgrid 0.3.0 → 0.4.0
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/README.md +20 -1
- package/dist/helpers/animation.d.cts +20 -0
- package/dist/helpers/animation.d.mts +20 -0
- package/dist/helpers/gridCalculations.cjs +11 -0
- package/dist/helpers/gridCalculations.cjs.map +1 -1
- package/dist/helpers/gridCalculations.d.cts +53 -0
- package/dist/helpers/gridCalculations.d.mts +53 -0
- package/dist/helpers/gridCalculations.mjs +11 -1
- package/dist/helpers/gridCalculations.mjs.map +1 -1
- package/dist/helpers/index.cjs +17 -0
- package/dist/helpers/index.d.cts +5 -0
- package/dist/helpers/index.d.mts +5 -0
- package/dist/helpers/index.mjs +6 -0
- package/dist/helpers/panelDetection.d.cts +20 -0
- package/dist/helpers/panelDetection.d.mts +20 -0
- package/dist/helpers/rearrangement.cjs +4 -0
- package/dist/helpers/rearrangement.d.cts +42 -2
- package/dist/helpers/rearrangement.d.mts +42 -2
- package/dist/helpers/rearrangement.mjs +1 -1
- package/package.json +18 -2
package/README.md
CHANGED
|
@@ -133,7 +133,9 @@ export function PanelContent({ id }: { id: PanelId }) {
|
|
|
133
133
|
|
|
134
134
|
### Custom Rearrangement Logic
|
|
135
135
|
|
|
136
|
-
You can override the default collision resolution logic by providing a custom `rearrangement` function
|
|
136
|
+
You can override the default collision resolution logic by providing a custom `rearrangement` function.
|
|
137
|
+
|
|
138
|
+
For advanced use cases, PanelGrid exports [helper functions](./docs/helpers.md) for collision detection, grid calculations, and more. See the [Helper Functions API Reference](./docs/helpers.md) for detailed documentation and examples.
|
|
137
139
|
|
|
138
140
|
```tsx
|
|
139
141
|
import { PanelGridProvider, rearrangePanels } from 'panelgrid';
|
|
@@ -389,8 +391,25 @@ type RearrangementFunction = (
|
|
|
389
391
|
|
|
390
392
|
### Exported Functions
|
|
391
393
|
|
|
394
|
+
**Main Export:**
|
|
392
395
|
- `rearrangePanels(movingPanel, allPanels, columnCount)`: Default rearrangement function that can be imported and extended
|
|
393
396
|
|
|
397
|
+
**Helper Functions:**
|
|
398
|
+
|
|
399
|
+
PanelGrid exports a comprehensive set of helper functions for building custom rearrangement logic, including collision detection, grid calculations, panel detection, and animation utilities.
|
|
400
|
+
|
|
401
|
+
See the [Helper Functions API Reference](./docs/helpers.md) for complete documentation.
|
|
402
|
+
|
|
403
|
+
Quick example:
|
|
404
|
+
```tsx
|
|
405
|
+
import {
|
|
406
|
+
detectCollisions,
|
|
407
|
+
hasCollision,
|
|
408
|
+
snapToGrid,
|
|
409
|
+
findNewPosition
|
|
410
|
+
} from 'panelgrid/helpers';
|
|
411
|
+
```
|
|
412
|
+
|
|
394
413
|
## Development
|
|
395
414
|
|
|
396
415
|
```bash
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/helpers/animation.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Options for applying snap-back animation
|
|
4
|
+
*/
|
|
5
|
+
interface ApplySnapAnimationOptions {
|
|
6
|
+
element: HTMLElement;
|
|
7
|
+
droppedLeft: number;
|
|
8
|
+
droppedTop: number;
|
|
9
|
+
nextLeft: number;
|
|
10
|
+
nextTop: number;
|
|
11
|
+
originalTransition: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Applies snap-back animation to element
|
|
15
|
+
* Smoothly animates the element from its dropped position to the snapped grid position
|
|
16
|
+
*/
|
|
17
|
+
declare function applySnapAnimation(options: ApplySnapAnimationOptions): void;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { applySnapAnimation };
|
|
20
|
+
//# sourceMappingURL=animation.d.cts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/helpers/animation.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Options for applying snap-back animation
|
|
4
|
+
*/
|
|
5
|
+
interface ApplySnapAnimationOptions {
|
|
6
|
+
element: HTMLElement;
|
|
7
|
+
droppedLeft: number;
|
|
8
|
+
droppedTop: number;
|
|
9
|
+
nextLeft: number;
|
|
10
|
+
nextTop: number;
|
|
11
|
+
originalTransition: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Applies snap-back animation to element
|
|
15
|
+
* Smoothly animates the element from its dropped position to the snapped grid position
|
|
16
|
+
*/
|
|
17
|
+
declare function applySnapAnimation(options: ApplySnapAnimationOptions): void;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { applySnapAnimation };
|
|
20
|
+
//# sourceMappingURL=animation.d.mts.map
|
|
@@ -60,6 +60,16 @@ function gridPositionToPixels(gridCoord, baseSize, gap) {
|
|
|
60
60
|
return Math.max(0, gridCoord * (baseSize + gap));
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
+
* Snaps a pixel value to the nearest grid position
|
|
64
|
+
* Useful for aligning elements to the grid after drag/resize operations
|
|
65
|
+
*
|
|
66
|
+
* ピクセル値を最も近いグリッド位置にスナップします。
|
|
67
|
+
* ドラッグ・リサイズ操作後に要素をグリッドに整列させる際に利用する。
|
|
68
|
+
*/
|
|
69
|
+
function snapToGrid(pixels, baseSize, gap) {
|
|
70
|
+
return gridPositionToPixels(pixelsToGridPosition(pixels, baseSize, gap), baseSize, gap);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
63
73
|
* Gets the maximum Y coordinate of the panels
|
|
64
74
|
* パネルの最大Y座標を取得します。
|
|
65
75
|
*/
|
|
@@ -73,4 +83,5 @@ exports.gridPositionToPixels = gridPositionToPixels;
|
|
|
73
83
|
exports.gridToPixels = gridToPixels;
|
|
74
84
|
exports.pixelsToGridPosition = pixelsToGridPosition;
|
|
75
85
|
exports.pixelsToGridSize = pixelsToGridSize;
|
|
86
|
+
exports.snapToGrid = snapToGrid;
|
|
76
87
|
//# sourceMappingURL=gridCalculations.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gridCalculations.cjs","names":[],"sources":["../../src/helpers/gridCalculations.ts"],"sourcesContent":["import type { PanelCoordinate } from \"../types\";\n\n/**\n * Converts a pixel value to grid units by dividing by the cell size (baseSize + gap)\n * and rounding up with Math.ceil. Ensures the result is at least 1 and does not exceed available space.\n * When columnCount and xPosition are provided, ensures x + width <= columnCount.\n *\n * ピクセル値をグリッド単位に変換します。セルサイズ (baseSize + gap) で割り、小数点は切り上げて整数にします。\n * 結果は最小1で、columnCountとxPositionが指定された場合はx + width <= columnCountを満たすように制限されます。\n */\nexport function pixelsToGridSize(\n pixels: number,\n baseSize: number,\n gap: number,\n columnCount?: number,\n xPosition?: number\n): number {\n const gridSize = Math.ceil(pixels / (baseSize + gap));\n const constrainedSize = Math.max(1, gridSize);\n\n if (columnCount !== undefined && xPosition !== undefined) {\n // Ensure x + width <= columnCount\n const maxWidth = Math.max(1, columnCount - xPosition);\n return Math.min(constrainedSize, maxWidth);\n }\n\n if (columnCount !== undefined) {\n // Legacy behavior: constrain to columnCount\n return Math.min(constrainedSize, columnCount);\n }\n\n return constrainedSize;\n}\n\n/**\n * Converts a pixel coordinate to grid coordinate by dividing by the cell size\n * and rounding down with Math.floor, ensuring the result is not negative and does not cause overflow.\n * When columnCount and width are provided, ensures x + width <= columnCount\n *\n * ピクセル座標をグリッド座標に変換します。セルサイズで割り、小数点は切り捨てて整数にします。\n * 結果が負にならず、columnCountとwidthが指定された場合はx + width <= columnCountを満たすようにします。\n */\nexport function pixelsToGridPosition(\n pixels: number,\n baseSize: number,\n gap: number,\n columnCount?: number,\n width?: number\n): number {\n const gridPosition = Math.max(0, Math.floor(pixels / (baseSize + gap)));\n\n if (columnCount !== undefined && width !== undefined) {\n // Ensure x + width <= columnCount\n const maxPosition = Math.max(0, columnCount - width);\n return Math.min(gridPosition, maxPosition);\n }\n\n if (columnCount !== undefined) {\n // Legacy behavior: constrain to columnCount - 1\n return Math.min(gridPosition, columnCount - 1);\n }\n\n return gridPosition;\n}\n\n/**\n * Converts grid units to pixels\n * Formula: gridUnits * baseSize + max(0, gridUnits - 1) * gap\n * This accounts for gaps between grid cells but not after the last cell\n *\n * グリッド単位をピクセルに変換します。\n * 計算式: gridUnits * baseSize + max(0, gridUnits - 1) * gap\n * グリッドセル間の gap を考慮しますが、最後のセルの後には gap を含めません。\n */\nexport function gridToPixels(gridUnits: number, baseSize: number, gap: number): number {\n return gridUnits * baseSize + Math.max(0, gridUnits - 1) * gap;\n}\n\n/**\n * Converts grid coordinate to pixel coordinate for positioning\n * Formula: max(0, gridCoord * (baseSize + gap))\n * This includes the gap after each cell for proper positioning in the grid\n *\n * グリッド座標をピクセル座標に変換します(位置計算用)。\n * 計算式: max(0, gridCoord * (baseSize + gap))\n * 各セルの後に gap を含めて、グリッド内での適切な位置決めを行います。\n */\nexport function gridPositionToPixels(gridCoord: number, baseSize: number, gap: number): number {\n return Math.max(0, gridCoord * (baseSize + gap));\n}\n\n/**\n * Snaps a pixel value to the nearest grid position\n * Useful for aligning elements to the grid after drag/resize operations\n *\n * ピクセル値を最も近いグリッド位置にスナップします。\n * ドラッグ・リサイズ操作後に要素をグリッドに整列させる際に利用する。\n */\nexport function snapToGrid(pixels: number, baseSize: number, gap: number): number {\n const gridPosition = pixelsToGridPosition(pixels, baseSize, gap);\n return gridPositionToPixels(gridPosition, baseSize, gap);\n}\n\n/**\n * Gets the maximum Y coordinate of the panels\n * パネルの最大Y座標を取得します。\n */\nexport function getGridRowCount(panels: PanelCoordinate[]): number {\n return Math.max(...panels.map((p) => p.y + p.h));\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,iBACd,QACA,UACA,KACA,aACA,WACQ;CACR,MAAM,WAAW,KAAK,KAAK,UAAU,WAAW,KAAK;CACrD,MAAM,kBAAkB,KAAK,IAAI,GAAG,SAAS;AAE7C,KAAI,gBAAgB,UAAa,cAAc,QAAW;EAExD,MAAM,WAAW,KAAK,IAAI,GAAG,cAAc,UAAU;AACrD,SAAO,KAAK,IAAI,iBAAiB,SAAS;;AAG5C,KAAI,gBAAgB,OAElB,QAAO,KAAK,IAAI,iBAAiB,YAAY;AAG/C,QAAO;;;;;;;;;;AAWT,SAAgB,qBACd,QACA,UACA,KACA,aACA,OACQ;CACR,MAAM,eAAe,KAAK,IAAI,GAAG,KAAK,MAAM,UAAU,WAAW,KAAK,CAAC;AAEvE,KAAI,gBAAgB,UAAa,UAAU,QAAW;EAEpD,MAAM,cAAc,KAAK,IAAI,GAAG,cAAc,MAAM;AACpD,SAAO,KAAK,IAAI,cAAc,YAAY;;AAG5C,KAAI,gBAAgB,OAElB,QAAO,KAAK,IAAI,cAAc,cAAc,EAAE;AAGhD,QAAO;;;;;;;;;;;AAYT,SAAgB,aAAa,WAAmB,UAAkB,KAAqB;AACrF,QAAO,YAAY,WAAW,KAAK,IAAI,GAAG,YAAY,EAAE,GAAG;;;;;;;;;;;AAY7D,SAAgB,qBAAqB,WAAmB,UAAkB,KAAqB;AAC7F,QAAO,KAAK,IAAI,GAAG,aAAa,WAAW,KAAK;;;;;;
|
|
1
|
+
{"version":3,"file":"gridCalculations.cjs","names":[],"sources":["../../src/helpers/gridCalculations.ts"],"sourcesContent":["import type { PanelCoordinate } from \"../types\";\n\n/**\n * Converts a pixel value to grid units by dividing by the cell size (baseSize + gap)\n * and rounding up with Math.ceil. Ensures the result is at least 1 and does not exceed available space.\n * When columnCount and xPosition are provided, ensures x + width <= columnCount.\n *\n * ピクセル値をグリッド単位に変換します。セルサイズ (baseSize + gap) で割り、小数点は切り上げて整数にします。\n * 結果は最小1で、columnCountとxPositionが指定された場合はx + width <= columnCountを満たすように制限されます。\n */\nexport function pixelsToGridSize(\n pixels: number,\n baseSize: number,\n gap: number,\n columnCount?: number,\n xPosition?: number\n): number {\n const gridSize = Math.ceil(pixels / (baseSize + gap));\n const constrainedSize = Math.max(1, gridSize);\n\n if (columnCount !== undefined && xPosition !== undefined) {\n // Ensure x + width <= columnCount\n const maxWidth = Math.max(1, columnCount - xPosition);\n return Math.min(constrainedSize, maxWidth);\n }\n\n if (columnCount !== undefined) {\n // Legacy behavior: constrain to columnCount\n return Math.min(constrainedSize, columnCount);\n }\n\n return constrainedSize;\n}\n\n/**\n * Converts a pixel coordinate to grid coordinate by dividing by the cell size\n * and rounding down with Math.floor, ensuring the result is not negative and does not cause overflow.\n * When columnCount and width are provided, ensures x + width <= columnCount\n *\n * ピクセル座標をグリッド座標に変換します。セルサイズで割り、小数点は切り捨てて整数にします。\n * 結果が負にならず、columnCountとwidthが指定された場合はx + width <= columnCountを満たすようにします。\n */\nexport function pixelsToGridPosition(\n pixels: number,\n baseSize: number,\n gap: number,\n columnCount?: number,\n width?: number\n): number {\n const gridPosition = Math.max(0, Math.floor(pixels / (baseSize + gap)));\n\n if (columnCount !== undefined && width !== undefined) {\n // Ensure x + width <= columnCount\n const maxPosition = Math.max(0, columnCount - width);\n return Math.min(gridPosition, maxPosition);\n }\n\n if (columnCount !== undefined) {\n // Legacy behavior: constrain to columnCount - 1\n return Math.min(gridPosition, columnCount - 1);\n }\n\n return gridPosition;\n}\n\n/**\n * Converts grid units to pixels\n * Formula: gridUnits * baseSize + max(0, gridUnits - 1) * gap\n * This accounts for gaps between grid cells but not after the last cell\n *\n * グリッド単位をピクセルに変換します。\n * 計算式: gridUnits * baseSize + max(0, gridUnits - 1) * gap\n * グリッドセル間の gap を考慮しますが、最後のセルの後には gap を含めません。\n */\nexport function gridToPixels(gridUnits: number, baseSize: number, gap: number): number {\n return gridUnits * baseSize + Math.max(0, gridUnits - 1) * gap;\n}\n\n/**\n * Converts grid coordinate to pixel coordinate for positioning\n * Formula: max(0, gridCoord * (baseSize + gap))\n * This includes the gap after each cell for proper positioning in the grid\n *\n * グリッド座標をピクセル座標に変換します(位置計算用)。\n * 計算式: max(0, gridCoord * (baseSize + gap))\n * 各セルの後に gap を含めて、グリッド内での適切な位置決めを行います。\n */\nexport function gridPositionToPixels(gridCoord: number, baseSize: number, gap: number): number {\n return Math.max(0, gridCoord * (baseSize + gap));\n}\n\n/**\n * Snaps a pixel value to the nearest grid position\n * Useful for aligning elements to the grid after drag/resize operations\n *\n * ピクセル値を最も近いグリッド位置にスナップします。\n * ドラッグ・リサイズ操作後に要素をグリッドに整列させる際に利用する。\n */\nexport function snapToGrid(pixels: number, baseSize: number, gap: number): number {\n const gridPosition = pixelsToGridPosition(pixels, baseSize, gap);\n return gridPositionToPixels(gridPosition, baseSize, gap);\n}\n\n/**\n * Gets the maximum Y coordinate of the panels\n * パネルの最大Y座標を取得します。\n */\nexport function getGridRowCount(panels: PanelCoordinate[]): number {\n return Math.max(...panels.map((p) => p.y + p.h));\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,iBACd,QACA,UACA,KACA,aACA,WACQ;CACR,MAAM,WAAW,KAAK,KAAK,UAAU,WAAW,KAAK;CACrD,MAAM,kBAAkB,KAAK,IAAI,GAAG,SAAS;AAE7C,KAAI,gBAAgB,UAAa,cAAc,QAAW;EAExD,MAAM,WAAW,KAAK,IAAI,GAAG,cAAc,UAAU;AACrD,SAAO,KAAK,IAAI,iBAAiB,SAAS;;AAG5C,KAAI,gBAAgB,OAElB,QAAO,KAAK,IAAI,iBAAiB,YAAY;AAG/C,QAAO;;;;;;;;;;AAWT,SAAgB,qBACd,QACA,UACA,KACA,aACA,OACQ;CACR,MAAM,eAAe,KAAK,IAAI,GAAG,KAAK,MAAM,UAAU,WAAW,KAAK,CAAC;AAEvE,KAAI,gBAAgB,UAAa,UAAU,QAAW;EAEpD,MAAM,cAAc,KAAK,IAAI,GAAG,cAAc,MAAM;AACpD,SAAO,KAAK,IAAI,cAAc,YAAY;;AAG5C,KAAI,gBAAgB,OAElB,QAAO,KAAK,IAAI,cAAc,cAAc,EAAE;AAGhD,QAAO;;;;;;;;;;;AAYT,SAAgB,aAAa,WAAmB,UAAkB,KAAqB;AACrF,QAAO,YAAY,WAAW,KAAK,IAAI,GAAG,YAAY,EAAE,GAAG;;;;;;;;;;;AAY7D,SAAgB,qBAAqB,WAAmB,UAAkB,KAAqB;AAC7F,QAAO,KAAK,IAAI,GAAG,aAAa,WAAW,KAAK;;;;;;;;;AAUlD,SAAgB,WAAW,QAAgB,UAAkB,KAAqB;AAEhF,QAAO,qBADc,qBAAqB,QAAQ,UAAU,IAAI,EACtB,UAAU,IAAI;;;;;;AAO1D,SAAgB,gBAAgB,QAAmC;AACjE,QAAO,KAAK,IAAI,GAAG,OAAO,KAAK,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import "../types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/gridCalculations.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a pixel value to grid units by dividing by the cell size (baseSize + gap)
|
|
7
|
+
* and rounding up with Math.ceil. Ensures the result is at least 1 and does not exceed available space.
|
|
8
|
+
* When columnCount and xPosition are provided, ensures x + width <= columnCount.
|
|
9
|
+
*
|
|
10
|
+
* ピクセル値をグリッド単位に変換します。セルサイズ (baseSize + gap) で割り、小数点は切り上げて整数にします。
|
|
11
|
+
* 結果は最小1で、columnCountとxPositionが指定された場合はx + width <= columnCountを満たすように制限されます。
|
|
12
|
+
*/
|
|
13
|
+
declare function pixelsToGridSize(pixels: number, baseSize: number, gap: number, columnCount?: number, xPosition?: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Converts a pixel coordinate to grid coordinate by dividing by the cell size
|
|
16
|
+
* and rounding down with Math.floor, ensuring the result is not negative and does not cause overflow.
|
|
17
|
+
* When columnCount and width are provided, ensures x + width <= columnCount
|
|
18
|
+
*
|
|
19
|
+
* ピクセル座標をグリッド座標に変換します。セルサイズで割り、小数点は切り捨てて整数にします。
|
|
20
|
+
* 結果が負にならず、columnCountとwidthが指定された場合はx + width <= columnCountを満たすようにします。
|
|
21
|
+
*/
|
|
22
|
+
declare function pixelsToGridPosition(pixels: number, baseSize: number, gap: number, columnCount?: number, width?: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Converts grid units to pixels
|
|
25
|
+
* Formula: gridUnits * baseSize + max(0, gridUnits - 1) * gap
|
|
26
|
+
* This accounts for gaps between grid cells but not after the last cell
|
|
27
|
+
*
|
|
28
|
+
* グリッド単位をピクセルに変換します。
|
|
29
|
+
* 計算式: gridUnits * baseSize + max(0, gridUnits - 1) * gap
|
|
30
|
+
* グリッドセル間の gap を考慮しますが、最後のセルの後には gap を含めません。
|
|
31
|
+
*/
|
|
32
|
+
declare function gridToPixels(gridUnits: number, baseSize: number, gap: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Converts grid coordinate to pixel coordinate for positioning
|
|
35
|
+
* Formula: max(0, gridCoord * (baseSize + gap))
|
|
36
|
+
* This includes the gap after each cell for proper positioning in the grid
|
|
37
|
+
*
|
|
38
|
+
* グリッド座標をピクセル座標に変換します(位置計算用)。
|
|
39
|
+
* 計算式: max(0, gridCoord * (baseSize + gap))
|
|
40
|
+
* 各セルの後に gap を含めて、グリッド内での適切な位置決めを行います。
|
|
41
|
+
*/
|
|
42
|
+
declare function gridPositionToPixels(gridCoord: number, baseSize: number, gap: number): number;
|
|
43
|
+
/**
|
|
44
|
+
* Snaps a pixel value to the nearest grid position
|
|
45
|
+
* Useful for aligning elements to the grid after drag/resize operations
|
|
46
|
+
*
|
|
47
|
+
* ピクセル値を最も近いグリッド位置にスナップします。
|
|
48
|
+
* ドラッグ・リサイズ操作後に要素をグリッドに整列させる際に利用する。
|
|
49
|
+
*/
|
|
50
|
+
declare function snapToGrid(pixels: number, baseSize: number, gap: number): number;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { gridPositionToPixels, gridToPixels, pixelsToGridPosition, pixelsToGridSize, snapToGrid };
|
|
53
|
+
//# sourceMappingURL=gridCalculations.d.cts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import "../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/gridCalculations.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a pixel value to grid units by dividing by the cell size (baseSize + gap)
|
|
7
|
+
* and rounding up with Math.ceil. Ensures the result is at least 1 and does not exceed available space.
|
|
8
|
+
* When columnCount and xPosition are provided, ensures x + width <= columnCount.
|
|
9
|
+
*
|
|
10
|
+
* ピクセル値をグリッド単位に変換します。セルサイズ (baseSize + gap) で割り、小数点は切り上げて整数にします。
|
|
11
|
+
* 結果は最小1で、columnCountとxPositionが指定された場合はx + width <= columnCountを満たすように制限されます。
|
|
12
|
+
*/
|
|
13
|
+
declare function pixelsToGridSize(pixels: number, baseSize: number, gap: number, columnCount?: number, xPosition?: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Converts a pixel coordinate to grid coordinate by dividing by the cell size
|
|
16
|
+
* and rounding down with Math.floor, ensuring the result is not negative and does not cause overflow.
|
|
17
|
+
* When columnCount and width are provided, ensures x + width <= columnCount
|
|
18
|
+
*
|
|
19
|
+
* ピクセル座標をグリッド座標に変換します。セルサイズで割り、小数点は切り捨てて整数にします。
|
|
20
|
+
* 結果が負にならず、columnCountとwidthが指定された場合はx + width <= columnCountを満たすようにします。
|
|
21
|
+
*/
|
|
22
|
+
declare function pixelsToGridPosition(pixels: number, baseSize: number, gap: number, columnCount?: number, width?: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Converts grid units to pixels
|
|
25
|
+
* Formula: gridUnits * baseSize + max(0, gridUnits - 1) * gap
|
|
26
|
+
* This accounts for gaps between grid cells but not after the last cell
|
|
27
|
+
*
|
|
28
|
+
* グリッド単位をピクセルに変換します。
|
|
29
|
+
* 計算式: gridUnits * baseSize + max(0, gridUnits - 1) * gap
|
|
30
|
+
* グリッドセル間の gap を考慮しますが、最後のセルの後には gap を含めません。
|
|
31
|
+
*/
|
|
32
|
+
declare function gridToPixels(gridUnits: number, baseSize: number, gap: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Converts grid coordinate to pixel coordinate for positioning
|
|
35
|
+
* Formula: max(0, gridCoord * (baseSize + gap))
|
|
36
|
+
* This includes the gap after each cell for proper positioning in the grid
|
|
37
|
+
*
|
|
38
|
+
* グリッド座標をピクセル座標に変換します(位置計算用)。
|
|
39
|
+
* 計算式: max(0, gridCoord * (baseSize + gap))
|
|
40
|
+
* 各セルの後に gap を含めて、グリッド内での適切な位置決めを行います。
|
|
41
|
+
*/
|
|
42
|
+
declare function gridPositionToPixels(gridCoord: number, baseSize: number, gap: number): number;
|
|
43
|
+
/**
|
|
44
|
+
* Snaps a pixel value to the nearest grid position
|
|
45
|
+
* Useful for aligning elements to the grid after drag/resize operations
|
|
46
|
+
*
|
|
47
|
+
* ピクセル値を最も近いグリッド位置にスナップします。
|
|
48
|
+
* ドラッグ・リサイズ操作後に要素をグリッドに整列させる際に利用する。
|
|
49
|
+
*/
|
|
50
|
+
declare function snapToGrid(pixels: number, baseSize: number, gap: number): number;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { gridPositionToPixels, gridToPixels, pixelsToGridPosition, pixelsToGridSize, snapToGrid };
|
|
53
|
+
//# sourceMappingURL=gridCalculations.d.mts.map
|
|
@@ -59,6 +59,16 @@ function gridPositionToPixels(gridCoord, baseSize, gap) {
|
|
|
59
59
|
return Math.max(0, gridCoord * (baseSize + gap));
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
+
* Snaps a pixel value to the nearest grid position
|
|
63
|
+
* Useful for aligning elements to the grid after drag/resize operations
|
|
64
|
+
*
|
|
65
|
+
* ピクセル値を最も近いグリッド位置にスナップします。
|
|
66
|
+
* ドラッグ・リサイズ操作後に要素をグリッドに整列させる際に利用する。
|
|
67
|
+
*/
|
|
68
|
+
function snapToGrid(pixels, baseSize, gap) {
|
|
69
|
+
return gridPositionToPixels(pixelsToGridPosition(pixels, baseSize, gap), baseSize, gap);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
62
72
|
* Gets the maximum Y coordinate of the panels
|
|
63
73
|
* パネルの最大Y座標を取得します。
|
|
64
74
|
*/
|
|
@@ -67,5 +77,5 @@ function getGridRowCount(panels) {
|
|
|
67
77
|
}
|
|
68
78
|
|
|
69
79
|
//#endregion
|
|
70
|
-
export { getGridRowCount, gridPositionToPixels, gridToPixels, pixelsToGridPosition, pixelsToGridSize };
|
|
80
|
+
export { getGridRowCount, gridPositionToPixels, gridToPixels, pixelsToGridPosition, pixelsToGridSize, snapToGrid };
|
|
71
81
|
//# sourceMappingURL=gridCalculations.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gridCalculations.mjs","names":[],"sources":["../../src/helpers/gridCalculations.ts"],"sourcesContent":["import type { PanelCoordinate } from \"../types\";\n\n/**\n * Converts a pixel value to grid units by dividing by the cell size (baseSize + gap)\n * and rounding up with Math.ceil. Ensures the result is at least 1 and does not exceed available space.\n * When columnCount and xPosition are provided, ensures x + width <= columnCount.\n *\n * ピクセル値をグリッド単位に変換します。セルサイズ (baseSize + gap) で割り、小数点は切り上げて整数にします。\n * 結果は最小1で、columnCountとxPositionが指定された場合はx + width <= columnCountを満たすように制限されます。\n */\nexport function pixelsToGridSize(\n pixels: number,\n baseSize: number,\n gap: number,\n columnCount?: number,\n xPosition?: number\n): number {\n const gridSize = Math.ceil(pixels / (baseSize + gap));\n const constrainedSize = Math.max(1, gridSize);\n\n if (columnCount !== undefined && xPosition !== undefined) {\n // Ensure x + width <= columnCount\n const maxWidth = Math.max(1, columnCount - xPosition);\n return Math.min(constrainedSize, maxWidth);\n }\n\n if (columnCount !== undefined) {\n // Legacy behavior: constrain to columnCount\n return Math.min(constrainedSize, columnCount);\n }\n\n return constrainedSize;\n}\n\n/**\n * Converts a pixel coordinate to grid coordinate by dividing by the cell size\n * and rounding down with Math.floor, ensuring the result is not negative and does not cause overflow.\n * When columnCount and width are provided, ensures x + width <= columnCount\n *\n * ピクセル座標をグリッド座標に変換します。セルサイズで割り、小数点は切り捨てて整数にします。\n * 結果が負にならず、columnCountとwidthが指定された場合はx + width <= columnCountを満たすようにします。\n */\nexport function pixelsToGridPosition(\n pixels: number,\n baseSize: number,\n gap: number,\n columnCount?: number,\n width?: number\n): number {\n const gridPosition = Math.max(0, Math.floor(pixels / (baseSize + gap)));\n\n if (columnCount !== undefined && width !== undefined) {\n // Ensure x + width <= columnCount\n const maxPosition = Math.max(0, columnCount - width);\n return Math.min(gridPosition, maxPosition);\n }\n\n if (columnCount !== undefined) {\n // Legacy behavior: constrain to columnCount - 1\n return Math.min(gridPosition, columnCount - 1);\n }\n\n return gridPosition;\n}\n\n/**\n * Converts grid units to pixels\n * Formula: gridUnits * baseSize + max(0, gridUnits - 1) * gap\n * This accounts for gaps between grid cells but not after the last cell\n *\n * グリッド単位をピクセルに変換します。\n * 計算式: gridUnits * baseSize + max(0, gridUnits - 1) * gap\n * グリッドセル間の gap を考慮しますが、最後のセルの後には gap を含めません。\n */\nexport function gridToPixels(gridUnits: number, baseSize: number, gap: number): number {\n return gridUnits * baseSize + Math.max(0, gridUnits - 1) * gap;\n}\n\n/**\n * Converts grid coordinate to pixel coordinate for positioning\n * Formula: max(0, gridCoord * (baseSize + gap))\n * This includes the gap after each cell for proper positioning in the grid\n *\n * グリッド座標をピクセル座標に変換します(位置計算用)。\n * 計算式: max(0, gridCoord * (baseSize + gap))\n * 各セルの後に gap を含めて、グリッド内での適切な位置決めを行います。\n */\nexport function gridPositionToPixels(gridCoord: number, baseSize: number, gap: number): number {\n return Math.max(0, gridCoord * (baseSize + gap));\n}\n\n/**\n * Snaps a pixel value to the nearest grid position\n * Useful for aligning elements to the grid after drag/resize operations\n *\n * ピクセル値を最も近いグリッド位置にスナップします。\n * ドラッグ・リサイズ操作後に要素をグリッドに整列させる際に利用する。\n */\nexport function snapToGrid(pixels: number, baseSize: number, gap: number): number {\n const gridPosition = pixelsToGridPosition(pixels, baseSize, gap);\n return gridPositionToPixels(gridPosition, baseSize, gap);\n}\n\n/**\n * Gets the maximum Y coordinate of the panels\n * パネルの最大Y座標を取得します。\n */\nexport function getGridRowCount(panels: PanelCoordinate[]): number {\n return Math.max(...panels.map((p) => p.y + p.h));\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,iBACd,QACA,UACA,KACA,aACA,WACQ;CACR,MAAM,WAAW,KAAK,KAAK,UAAU,WAAW,KAAK;CACrD,MAAM,kBAAkB,KAAK,IAAI,GAAG,SAAS;AAE7C,KAAI,gBAAgB,UAAa,cAAc,QAAW;EAExD,MAAM,WAAW,KAAK,IAAI,GAAG,cAAc,UAAU;AACrD,SAAO,KAAK,IAAI,iBAAiB,SAAS;;AAG5C,KAAI,gBAAgB,OAElB,QAAO,KAAK,IAAI,iBAAiB,YAAY;AAG/C,QAAO;;;;;;;;;;AAWT,SAAgB,qBACd,QACA,UACA,KACA,aACA,OACQ;CACR,MAAM,eAAe,KAAK,IAAI,GAAG,KAAK,MAAM,UAAU,WAAW,KAAK,CAAC;AAEvE,KAAI,gBAAgB,UAAa,UAAU,QAAW;EAEpD,MAAM,cAAc,KAAK,IAAI,GAAG,cAAc,MAAM;AACpD,SAAO,KAAK,IAAI,cAAc,YAAY;;AAG5C,KAAI,gBAAgB,OAElB,QAAO,KAAK,IAAI,cAAc,cAAc,EAAE;AAGhD,QAAO;;;;;;;;;;;AAYT,SAAgB,aAAa,WAAmB,UAAkB,KAAqB;AACrF,QAAO,YAAY,WAAW,KAAK,IAAI,GAAG,YAAY,EAAE,GAAG;;;;;;;;;;;AAY7D,SAAgB,qBAAqB,WAAmB,UAAkB,KAAqB;AAC7F,QAAO,KAAK,IAAI,GAAG,aAAa,WAAW,KAAK;;;;;;
|
|
1
|
+
{"version":3,"file":"gridCalculations.mjs","names":[],"sources":["../../src/helpers/gridCalculations.ts"],"sourcesContent":["import type { PanelCoordinate } from \"../types\";\n\n/**\n * Converts a pixel value to grid units by dividing by the cell size (baseSize + gap)\n * and rounding up with Math.ceil. Ensures the result is at least 1 and does not exceed available space.\n * When columnCount and xPosition are provided, ensures x + width <= columnCount.\n *\n * ピクセル値をグリッド単位に変換します。セルサイズ (baseSize + gap) で割り、小数点は切り上げて整数にします。\n * 結果は最小1で、columnCountとxPositionが指定された場合はx + width <= columnCountを満たすように制限されます。\n */\nexport function pixelsToGridSize(\n pixels: number,\n baseSize: number,\n gap: number,\n columnCount?: number,\n xPosition?: number\n): number {\n const gridSize = Math.ceil(pixels / (baseSize + gap));\n const constrainedSize = Math.max(1, gridSize);\n\n if (columnCount !== undefined && xPosition !== undefined) {\n // Ensure x + width <= columnCount\n const maxWidth = Math.max(1, columnCount - xPosition);\n return Math.min(constrainedSize, maxWidth);\n }\n\n if (columnCount !== undefined) {\n // Legacy behavior: constrain to columnCount\n return Math.min(constrainedSize, columnCount);\n }\n\n return constrainedSize;\n}\n\n/**\n * Converts a pixel coordinate to grid coordinate by dividing by the cell size\n * and rounding down with Math.floor, ensuring the result is not negative and does not cause overflow.\n * When columnCount and width are provided, ensures x + width <= columnCount\n *\n * ピクセル座標をグリッド座標に変換します。セルサイズで割り、小数点は切り捨てて整数にします。\n * 結果が負にならず、columnCountとwidthが指定された場合はx + width <= columnCountを満たすようにします。\n */\nexport function pixelsToGridPosition(\n pixels: number,\n baseSize: number,\n gap: number,\n columnCount?: number,\n width?: number\n): number {\n const gridPosition = Math.max(0, Math.floor(pixels / (baseSize + gap)));\n\n if (columnCount !== undefined && width !== undefined) {\n // Ensure x + width <= columnCount\n const maxPosition = Math.max(0, columnCount - width);\n return Math.min(gridPosition, maxPosition);\n }\n\n if (columnCount !== undefined) {\n // Legacy behavior: constrain to columnCount - 1\n return Math.min(gridPosition, columnCount - 1);\n }\n\n return gridPosition;\n}\n\n/**\n * Converts grid units to pixels\n * Formula: gridUnits * baseSize + max(0, gridUnits - 1) * gap\n * This accounts for gaps between grid cells but not after the last cell\n *\n * グリッド単位をピクセルに変換します。\n * 計算式: gridUnits * baseSize + max(0, gridUnits - 1) * gap\n * グリッドセル間の gap を考慮しますが、最後のセルの後には gap を含めません。\n */\nexport function gridToPixels(gridUnits: number, baseSize: number, gap: number): number {\n return gridUnits * baseSize + Math.max(0, gridUnits - 1) * gap;\n}\n\n/**\n * Converts grid coordinate to pixel coordinate for positioning\n * Formula: max(0, gridCoord * (baseSize + gap))\n * This includes the gap after each cell for proper positioning in the grid\n *\n * グリッド座標をピクセル座標に変換します(位置計算用)。\n * 計算式: max(0, gridCoord * (baseSize + gap))\n * 各セルの後に gap を含めて、グリッド内での適切な位置決めを行います。\n */\nexport function gridPositionToPixels(gridCoord: number, baseSize: number, gap: number): number {\n return Math.max(0, gridCoord * (baseSize + gap));\n}\n\n/**\n * Snaps a pixel value to the nearest grid position\n * Useful for aligning elements to the grid after drag/resize operations\n *\n * ピクセル値を最も近いグリッド位置にスナップします。\n * ドラッグ・リサイズ操作後に要素をグリッドに整列させる際に利用する。\n */\nexport function snapToGrid(pixels: number, baseSize: number, gap: number): number {\n const gridPosition = pixelsToGridPosition(pixels, baseSize, gap);\n return gridPositionToPixels(gridPosition, baseSize, gap);\n}\n\n/**\n * Gets the maximum Y coordinate of the panels\n * パネルの最大Y座標を取得します。\n */\nexport function getGridRowCount(panels: PanelCoordinate[]): number {\n return Math.max(...panels.map((p) => p.y + p.h));\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,iBACd,QACA,UACA,KACA,aACA,WACQ;CACR,MAAM,WAAW,KAAK,KAAK,UAAU,WAAW,KAAK;CACrD,MAAM,kBAAkB,KAAK,IAAI,GAAG,SAAS;AAE7C,KAAI,gBAAgB,UAAa,cAAc,QAAW;EAExD,MAAM,WAAW,KAAK,IAAI,GAAG,cAAc,UAAU;AACrD,SAAO,KAAK,IAAI,iBAAiB,SAAS;;AAG5C,KAAI,gBAAgB,OAElB,QAAO,KAAK,IAAI,iBAAiB,YAAY;AAG/C,QAAO;;;;;;;;;;AAWT,SAAgB,qBACd,QACA,UACA,KACA,aACA,OACQ;CACR,MAAM,eAAe,KAAK,IAAI,GAAG,KAAK,MAAM,UAAU,WAAW,KAAK,CAAC;AAEvE,KAAI,gBAAgB,UAAa,UAAU,QAAW;EAEpD,MAAM,cAAc,KAAK,IAAI,GAAG,cAAc,MAAM;AACpD,SAAO,KAAK,IAAI,cAAc,YAAY;;AAG5C,KAAI,gBAAgB,OAElB,QAAO,KAAK,IAAI,cAAc,cAAc,EAAE;AAGhD,QAAO;;;;;;;;;;;AAYT,SAAgB,aAAa,WAAmB,UAAkB,KAAqB;AACrF,QAAO,YAAY,WAAW,KAAK,IAAI,GAAG,YAAY,EAAE,GAAG;;;;;;;;;;;AAY7D,SAAgB,qBAAqB,WAAmB,UAAkB,KAAqB;AAC7F,QAAO,KAAK,IAAI,GAAG,aAAa,WAAW,KAAK;;;;;;;;;AAUlD,SAAgB,WAAW,QAAgB,UAAkB,KAAqB;AAEhF,QAAO,qBADc,qBAAqB,QAAQ,UAAU,IAAI,EACtB,UAAU,IAAI;;;;;;AAO1D,SAAgB,gBAAgB,QAAmC;AACjE,QAAO,KAAK,IAAI,GAAG,OAAO,KAAK,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const require_rearrangement = require('./rearrangement.cjs');
|
|
2
|
+
const require_animation = require('./animation.cjs');
|
|
3
|
+
const require_gridCalculations = require('./gridCalculations.cjs');
|
|
4
|
+
const require_panelDetection = require('./panelDetection.cjs');
|
|
5
|
+
|
|
6
|
+
exports.applySnapAnimation = require_animation.applySnapAnimation;
|
|
7
|
+
exports.detectAnimatingPanels = require_panelDetection.detectAnimatingPanels;
|
|
8
|
+
exports.detectCollisions = require_rearrangement.detectCollisions;
|
|
9
|
+
exports.findNewPosition = require_rearrangement.findNewPosition;
|
|
10
|
+
exports.gridPositionToPixels = require_gridCalculations.gridPositionToPixels;
|
|
11
|
+
exports.gridToPixels = require_gridCalculations.gridToPixels;
|
|
12
|
+
exports.hasCollision = require_rearrangement.hasCollision;
|
|
13
|
+
exports.pixelsToGridPosition = require_gridCalculations.pixelsToGridPosition;
|
|
14
|
+
exports.pixelsToGridSize = require_gridCalculations.pixelsToGridSize;
|
|
15
|
+
exports.rearrangePanels = require_rearrangement.rearrangePanels;
|
|
16
|
+
exports.rectanglesOverlap = require_rearrangement.rectanglesOverlap;
|
|
17
|
+
exports.snapToGrid = require_gridCalculations.snapToGrid;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { applySnapAnimation } from "./animation.cjs";
|
|
2
|
+
import { gridPositionToPixels, gridToPixels, pixelsToGridPosition, pixelsToGridSize, snapToGrid } from "./gridCalculations.cjs";
|
|
3
|
+
import { detectAnimatingPanels } from "./panelDetection.cjs";
|
|
4
|
+
import { detectCollisions, findNewPosition, hasCollision, rearrangePanels, rectanglesOverlap } from "./rearrangement.cjs";
|
|
5
|
+
export { applySnapAnimation, detectAnimatingPanels, detectCollisions, findNewPosition, gridPositionToPixels, gridToPixels, hasCollision, pixelsToGridPosition, pixelsToGridSize, rearrangePanels, rectanglesOverlap, snapToGrid };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { applySnapAnimation } from "./animation.mjs";
|
|
2
|
+
import { gridPositionToPixels, gridToPixels, pixelsToGridPosition, pixelsToGridSize, snapToGrid } from "./gridCalculations.mjs";
|
|
3
|
+
import { detectAnimatingPanels } from "./panelDetection.mjs";
|
|
4
|
+
import { detectCollisions, findNewPosition, hasCollision, rearrangePanels, rectanglesOverlap } from "./rearrangement.mjs";
|
|
5
|
+
export { applySnapAnimation, detectAnimatingPanels, detectCollisions, findNewPosition, gridPositionToPixels, gridToPixels, hasCollision, pixelsToGridPosition, pixelsToGridSize, rearrangePanels, rectanglesOverlap, snapToGrid };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { detectCollisions, findNewPosition, hasCollision, rearrangePanels, rectanglesOverlap } from "./rearrangement.mjs";
|
|
2
|
+
import { applySnapAnimation } from "./animation.mjs";
|
|
3
|
+
import { gridPositionToPixels, gridToPixels, pixelsToGridPosition, pixelsToGridSize, snapToGrid } from "./gridCalculations.mjs";
|
|
4
|
+
import { detectAnimatingPanels } from "./panelDetection.mjs";
|
|
5
|
+
|
|
6
|
+
export { applySnapAnimation, detectAnimatingPanels, detectCollisions, findNewPosition, gridPositionToPixels, gridToPixels, hasCollision, pixelsToGridPosition, pixelsToGridSize, rearrangePanels, rectanglesOverlap, snapToGrid };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PanelCoordinate, PanelId } from "../types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/panelDetection.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for detecting animating panels
|
|
7
|
+
*/
|
|
8
|
+
interface DetectAnimatingPanelsOptions {
|
|
9
|
+
oldPanels: PanelCoordinate[];
|
|
10
|
+
newPanels: PanelCoordinate[];
|
|
11
|
+
excludePanelId: PanelId;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Detects which panels have changed position/size and marks them for animation
|
|
15
|
+
* Returns a Set of panel IDs that should be animated
|
|
16
|
+
*/
|
|
17
|
+
declare function detectAnimatingPanels(options: DetectAnimatingPanelsOptions): Set<PanelId>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { detectAnimatingPanels };
|
|
20
|
+
//# sourceMappingURL=panelDetection.d.cts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PanelCoordinate, PanelId } from "../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/panelDetection.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for detecting animating panels
|
|
7
|
+
*/
|
|
8
|
+
interface DetectAnimatingPanelsOptions {
|
|
9
|
+
oldPanels: PanelCoordinate[];
|
|
10
|
+
newPanels: PanelCoordinate[];
|
|
11
|
+
excludePanelId: PanelId;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Detects which panels have changed position/size and marks them for animation
|
|
15
|
+
* Returns a Set of panel IDs that should be animated
|
|
16
|
+
*/
|
|
17
|
+
declare function detectAnimatingPanels(options: DetectAnimatingPanelsOptions): Set<PanelId>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { detectAnimatingPanels };
|
|
20
|
+
//# sourceMappingURL=panelDetection.d.mts.map
|
|
@@ -203,6 +203,10 @@ function findNewPositionToAddPanel(panelToAdd, allPanels, columnCount) {
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
//#endregion
|
|
206
|
+
exports.detectCollisions = detectCollisions;
|
|
207
|
+
exports.findNewPosition = findNewPosition;
|
|
206
208
|
exports.findNewPositionToAddPanel = findNewPositionToAddPanel;
|
|
209
|
+
exports.hasCollision = hasCollision;
|
|
207
210
|
exports.rearrangePanels = rearrangePanels;
|
|
211
|
+
exports.rectanglesOverlap = rectanglesOverlap;
|
|
208
212
|
//# sourceMappingURL=rearrangement.cjs.map
|
|
@@ -1,7 +1,47 @@
|
|
|
1
|
-
import { PanelCoordinate } from "../types.cjs";
|
|
1
|
+
import { PanelCoordinate, PanelId } from "../types.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/rearrangement.d.ts
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Check if two rectangles overlap using AABB (Axis-Aligned Bounding Box) test
|
|
7
|
+
* 2つの矩形が重なっているかをAABBテストで判定
|
|
8
|
+
*/
|
|
9
|
+
declare function rectanglesOverlap(a: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
w: number;
|
|
13
|
+
h: number;
|
|
14
|
+
}, b: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
w: number;
|
|
18
|
+
h: number;
|
|
19
|
+
}): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Detect all panels that collide with the given panel
|
|
22
|
+
* 指定されたパネルと衝突する全てのパネルを検出
|
|
23
|
+
*/
|
|
24
|
+
declare function detectCollisions(panel: PanelCoordinate, panelMap: Map<PanelId, PanelCoordinate>): PanelId[];
|
|
25
|
+
/**
|
|
26
|
+
* Check if a panel at the given position would collide with any existing panels
|
|
27
|
+
* 指定された位置にパネルを配置した場合に衝突があるかをチェック
|
|
28
|
+
*/
|
|
29
|
+
declare function hasCollision(candidate: {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
w: number;
|
|
33
|
+
h: number;
|
|
34
|
+
}, excludeId: PanelId, panelMap: Map<PanelId, PanelCoordinate>): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Find a new position for a panel by pushing it away from the colliding panel
|
|
37
|
+
* Priority: horizontal (right) first, then vertical (down)
|
|
38
|
+
* 衝突したパネルを押しのける方向に移動させる
|
|
39
|
+
* 優先順位: 横方向(右)→縦方向(下)
|
|
40
|
+
*/
|
|
41
|
+
declare function findNewPosition(panel: PanelCoordinate, pusher: PanelCoordinate, columnCount: number): {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
};
|
|
5
45
|
/**
|
|
6
46
|
* Rearrange panels to resolve collisions when a panel is moved or resized
|
|
7
47
|
* Panels are moved horizontally first, then vertically if needed
|
|
@@ -12,5 +52,5 @@ import { PanelCoordinate } from "../types.cjs";
|
|
|
12
52
|
*/
|
|
13
53
|
declare function rearrangePanels(movingPanel: PanelCoordinate, allPanels: PanelCoordinate[], columnCount: number): PanelCoordinate[];
|
|
14
54
|
//#endregion
|
|
15
|
-
export { rearrangePanels };
|
|
55
|
+
export { detectCollisions, findNewPosition, hasCollision, rearrangePanels, rectanglesOverlap };
|
|
16
56
|
//# sourceMappingURL=rearrangement.d.cts.map
|
|
@@ -1,7 +1,47 @@
|
|
|
1
|
-
import { PanelCoordinate } from "../types.mjs";
|
|
1
|
+
import { PanelCoordinate, PanelId } from "../types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/rearrangement.d.ts
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Check if two rectangles overlap using AABB (Axis-Aligned Bounding Box) test
|
|
7
|
+
* 2つの矩形が重なっているかをAABBテストで判定
|
|
8
|
+
*/
|
|
9
|
+
declare function rectanglesOverlap(a: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
w: number;
|
|
13
|
+
h: number;
|
|
14
|
+
}, b: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
w: number;
|
|
18
|
+
h: number;
|
|
19
|
+
}): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Detect all panels that collide with the given panel
|
|
22
|
+
* 指定されたパネルと衝突する全てのパネルを検出
|
|
23
|
+
*/
|
|
24
|
+
declare function detectCollisions(panel: PanelCoordinate, panelMap: Map<PanelId, PanelCoordinate>): PanelId[];
|
|
25
|
+
/**
|
|
26
|
+
* Check if a panel at the given position would collide with any existing panels
|
|
27
|
+
* 指定された位置にパネルを配置した場合に衝突があるかをチェック
|
|
28
|
+
*/
|
|
29
|
+
declare function hasCollision(candidate: {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
w: number;
|
|
33
|
+
h: number;
|
|
34
|
+
}, excludeId: PanelId, panelMap: Map<PanelId, PanelCoordinate>): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Find a new position for a panel by pushing it away from the colliding panel
|
|
37
|
+
* Priority: horizontal (right) first, then vertical (down)
|
|
38
|
+
* 衝突したパネルを押しのける方向に移動させる
|
|
39
|
+
* 優先順位: 横方向(右)→縦方向(下)
|
|
40
|
+
*/
|
|
41
|
+
declare function findNewPosition(panel: PanelCoordinate, pusher: PanelCoordinate, columnCount: number): {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
};
|
|
5
45
|
/**
|
|
6
46
|
* Rearrange panels to resolve collisions when a panel is moved or resized
|
|
7
47
|
* Panels are moved horizontally first, then vertically if needed
|
|
@@ -12,5 +52,5 @@ import { PanelCoordinate } from "../types.mjs";
|
|
|
12
52
|
*/
|
|
13
53
|
declare function rearrangePanels(movingPanel: PanelCoordinate, allPanels: PanelCoordinate[], columnCount: number): PanelCoordinate[];
|
|
14
54
|
//#endregion
|
|
15
|
-
export { rearrangePanels };
|
|
55
|
+
export { detectCollisions, findNewPosition, hasCollision, rearrangePanels, rectanglesOverlap };
|
|
16
56
|
//# sourceMappingURL=rearrangement.d.mts.map
|
|
@@ -202,5 +202,5 @@ function findNewPositionToAddPanel(panelToAdd, allPanels, columnCount) {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
//#endregion
|
|
205
|
-
export { findNewPositionToAddPanel, rearrangePanels };
|
|
205
|
+
export { detectCollisions, findNewPosition, findNewPositionToAddPanel, hasCollision, rearrangePanels, rectanglesOverlap };
|
|
206
206
|
//# sourceMappingURL=rearrangement.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "panelgrid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A flexible and performant React grid layout library with drag-and-drop and resize capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -19,6 +19,16 @@
|
|
|
19
19
|
},
|
|
20
20
|
"default": "./dist/index.mjs"
|
|
21
21
|
},
|
|
22
|
+
"./helpers": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/helpers/index.d.mts",
|
|
25
|
+
"default": "./dist/helpers/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/helpers/index.d.cts",
|
|
29
|
+
"default": "./dist/helpers/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
22
32
|
"./styles.css": "./dist/styles.css",
|
|
23
33
|
"./package.json": "./package.json"
|
|
24
34
|
},
|
|
@@ -62,7 +72,12 @@
|
|
|
62
72
|
"typecheck": "tsc -b --noEmit",
|
|
63
73
|
"preview": "vite preview",
|
|
64
74
|
"test": "vitest",
|
|
65
|
-
"prepublishOnly": "yarn test run && yarn typecheck && yarn lint && yarn build"
|
|
75
|
+
"prepublishOnly": "yarn test run && yarn typecheck && yarn lint && yarn build",
|
|
76
|
+
"release": "commit-and-tag-version",
|
|
77
|
+
"release:patch": "commit-and-tag-version --release-as patch",
|
|
78
|
+
"release:minor": "commit-and-tag-version --release-as minor",
|
|
79
|
+
"release:major": "commit-and-tag-version --release-as major",
|
|
80
|
+
"release:dry-run": "commit-and-tag-version --dry-run"
|
|
66
81
|
},
|
|
67
82
|
"lint-staged": {
|
|
68
83
|
"*.{js,jsx,ts,tsx}": [
|
|
@@ -86,6 +101,7 @@
|
|
|
86
101
|
"@types/react": "^19.1.16",
|
|
87
102
|
"@types/react-dom": "^19.1.9",
|
|
88
103
|
"@vitejs/plugin-react-swc": "^4.1.0",
|
|
104
|
+
"commit-and-tag-version": "^12.6.1",
|
|
89
105
|
"husky": "^9.1.7",
|
|
90
106
|
"jsdom": "^27.0.1",
|
|
91
107
|
"lint-staged": "^16.2.6",
|