@niche-works/css-layouts 0.1.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/LICENSE +21 -0
- package/README.md +3 -0
- package/_constants.cjs +94 -0
- package/_constants.d.cts +83 -0
- package/_constants.d.mts +83 -0
- package/_constants.mjs +86 -0
- package/_helpers/applyChildCount.cjs +26 -0
- package/_helpers/applyChildCount.d.cts +12 -0
- package/_helpers/applyChildCount.d.mts +13 -0
- package/_helpers/applyChildCount.mjs +24 -0
- package/_helpers/applyChildSize.cjs +27 -0
- package/_helpers/applyChildSize.d.cts +12 -0
- package/_helpers/applyChildSize.d.mts +13 -0
- package/_helpers/applyChildSize.mjs +25 -0
- package/_helpers/applySpacing.cjs +30 -0
- package/_helpers/applySpacing.d.cts +13 -0
- package/_helpers/applySpacing.d.mts +14 -0
- package/_helpers/applySpacing.mjs +28 -0
- package/_helpers/hasValue.cjs +15 -0
- package/_helpers/hasValue.d.cts +8 -0
- package/_helpers/hasValue.d.mts +9 -0
- package/_helpers/hasValue.mjs +14 -0
- package/_helpers/mergeLayoutResults.cjs +18 -0
- package/_helpers/mergeLayoutResults.d.cts +5 -0
- package/_helpers/mergeLayoutResults.d.mts +6 -0
- package/_helpers/mergeLayoutResults.mjs +16 -0
- package/_helpers/unit.cjs +16 -0
- package/_helpers/unit.d.cts +10 -0
- package/_helpers/unit.d.mts +11 -0
- package/_helpers/unit.mjs +15 -0
- package/_types.cjs +0 -0
- package/_types.d.cts +118 -0
- package/_types.d.mts +118 -0
- package/_types.mjs +1 -0
- package/_virtual/_rolldown/runtime.cjs +29 -0
- package/balance/balance.cjs +34 -0
- package/balance/balance.d.cts +11 -0
- package/balance/balance.d.mts +12 -0
- package/balance/balance.mjs +31 -0
- package/balance/index.cjs +3 -0
- package/balance/index.d.cts +3 -0
- package/balance/index.d.mts +3 -0
- package/balance/index.mjs +3 -0
- package/balance/styles.css +109 -0
- package/balance/types.cjs +0 -0
- package/balance/types.d.cts +6 -0
- package/balance/types.d.mts +6 -0
- package/balance/types.mjs +1 -0
- package/constants.cjs +341 -0
- package/constants.d.cts +299 -0
- package/constants.d.mts +299 -0
- package/constants.mjs +288 -0
- package/flow/flow.cjs +70 -0
- package/flow/flow.d.cts +12 -0
- package/flow/flow.d.mts +13 -0
- package/flow/flow.mjs +67 -0
- package/flow/index.cjs +3 -0
- package/flow/index.d.cts +3 -0
- package/flow/index.d.mts +3 -0
- package/flow/index.mjs +3 -0
- package/flow/styles.css +162 -0
- package/flow/types.cjs +0 -0
- package/flow/types.d.cts +21 -0
- package/flow/types.d.mts +21 -0
- package/flow/types.mjs +1 -0
- package/index.cjs +23 -0
- package/index.d.cts +16 -0
- package/index.d.mts +16 -0
- package/index.mjs +16 -0
- package/matrix/index.cjs +3 -0
- package/matrix/index.d.cts +3 -0
- package/matrix/index.d.mts +3 -0
- package/matrix/index.mjs +3 -0
- package/matrix/matrix.cjs +109 -0
- package/matrix/matrix.d.cts +11 -0
- package/matrix/matrix.d.mts +12 -0
- package/matrix/matrix.mjs +106 -0
- package/matrix/styles.css +59 -0
- package/matrix/types.cjs +0 -0
- package/matrix/types.d.cts +46 -0
- package/matrix/types.d.mts +46 -0
- package/matrix/types.mjs +1 -0
- package/pack/index.cjs +3 -0
- package/pack/index.d.cts +3 -0
- package/pack/index.d.mts +3 -0
- package/pack/index.mjs +3 -0
- package/pack/pack.cjs +28 -0
- package/pack/pack.d.cts +11 -0
- package/pack/pack.d.mts +12 -0
- package/pack/pack.mjs +25 -0
- package/pack/styles.css +27 -0
- package/pack/types.cjs +0 -0
- package/pack/types.d.cts +6 -0
- package/pack/types.d.mts +6 -0
- package/pack/types.mjs +1 -0
- package/package.json +45 -0
- package/pin/index.cjs +3 -0
- package/pin/index.d.cts +3 -0
- package/pin/index.d.mts +3 -0
- package/pin/index.mjs +3 -0
- package/pin/pin.cjs +22 -0
- package/pin/pin.d.cts +11 -0
- package/pin/pin.d.mts +12 -0
- package/pin/pin.mjs +22 -0
- package/pin/styles.css +15 -0
- package/pin/types.cjs +0 -0
- package/pin/types.d.cts +6 -0
- package/pin/types.d.mts +6 -0
- package/pin/types.mjs +1 -0
- package/stack/index.cjs +3 -0
- package/stack/index.d.cts +3 -0
- package/stack/index.d.mts +3 -0
- package/stack/index.mjs +3 -0
- package/stack/stack.cjs +98 -0
- package/stack/stack.d.cts +11 -0
- package/stack/stack.d.mts +12 -0
- package/stack/stack.mjs +95 -0
- package/stack/styles.css +171 -0
- package/stack/types.cjs +0 -0
- package/stack/types.d.cts +21 -0
- package/stack/types.d.mts +21 -0
- package/stack/types.mjs +1 -0
- package/tile/index.cjs +3 -0
- package/tile/index.d.cts +3 -0
- package/tile/index.d.mts +3 -0
- package/tile/index.mjs +3 -0
- package/tile/styles.css +104 -0
- package/tile/tile.cjs +85 -0
- package/tile/tile.d.cts +12 -0
- package/tile/tile.d.mts +13 -0
- package/tile/tile.mjs +82 -0
- package/tile/types.cjs +0 -0
- package/tile/types.d.cts +9 -0
- package/tile/types.d.mts +9 -0
- package/tile/types.mjs +1 -0
- package/types.cjs +0 -0
- package/types.d.cts +23 -0
- package/types.d.mts +23 -0
- package/types.mjs +1 -0
package/flow/flow.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { clsLayoutFlow } from "../constants.mjs";
|
|
2
|
+
import { clsLayoutAdjust, clsLayoutAlign, clsLayoutChildSize, clsLayoutDirection, varLayoutChildSize } from "../_constants.mjs";
|
|
3
|
+
import hasValue from "../_helpers/hasValue.mjs";
|
|
4
|
+
import unit from "../_helpers/unit.mjs";
|
|
5
|
+
import applySpacing from "../_helpers/applySpacing.mjs";
|
|
6
|
+
import mergeLayoutResults from "../_helpers/mergeLayoutResults.mjs";
|
|
7
|
+
import "./styles.css";
|
|
8
|
+
import maybeDefault from "@niche-works/utils/object/maybeDefault";
|
|
9
|
+
import clsx from "clsx";
|
|
10
|
+
|
|
11
|
+
//#region src/flow/flow.ts
|
|
12
|
+
/**
|
|
13
|
+
* flowレイアウト
|
|
14
|
+
*
|
|
15
|
+
* - 子要素を並べて配置し、親要素のサイズに達したら折り返す
|
|
16
|
+
* - stackとの違いは flex-wrap: wrap が常に有効な点
|
|
17
|
+
*/
|
|
18
|
+
const flow = (options = {}) => {
|
|
19
|
+
const { direction, alignX, alignY, adjustX, adjustY, spacing, spacingX = spacing, spacingY = spacing, childSizeX, childSizeY } = maybeDefault(options, {
|
|
20
|
+
direction: "x",
|
|
21
|
+
alignX: "left",
|
|
22
|
+
alignY: "top"
|
|
23
|
+
}, { overwriteNull: true });
|
|
24
|
+
const result = {
|
|
25
|
+
className: clsx(clsLayoutFlow, clsLayoutDirection[direction], clsLayoutAlign.x[alignX], clsLayoutAlign.y[alignY]),
|
|
26
|
+
style: {}
|
|
27
|
+
};
|
|
28
|
+
applySpacing(result, spacing, spacingX, spacingY);
|
|
29
|
+
const resultList = [result];
|
|
30
|
+
if (direction === "x") {
|
|
31
|
+
resultList.push(_getFlowMainAxisStyle("x", alignX, adjustX, childSizeX));
|
|
32
|
+
resultList.push(_getFlowCrossAxisStyle("y", alignY, childSizeY));
|
|
33
|
+
} else {
|
|
34
|
+
resultList.push(_getFlowCrossAxisStyle("x", alignX, childSizeX));
|
|
35
|
+
resultList.push(_getFlowMainAxisStyle("y", alignY, adjustY, childSizeY));
|
|
36
|
+
}
|
|
37
|
+
return mergeLayoutResults(resultList);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* 主軸方向のスタイル
|
|
41
|
+
*
|
|
42
|
+
* stackの _getStackMainAxisStyle に相当。flowでは主軸の挙動はstackと同じ。
|
|
43
|
+
*/
|
|
44
|
+
function _getFlowMainAxisStyle(axis, align, adjust, childSize) {
|
|
45
|
+
const result = { className: clsx(clsLayoutAlign[axis][align], clsLayoutAdjust[axis][adjust]) };
|
|
46
|
+
if (hasValue(childSize)) {
|
|
47
|
+
result.className = clsx(result.className, clsLayoutChildSize[axis]);
|
|
48
|
+
result.style = { [varLayoutChildSize[axis]]: unit(childSize) };
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 交差軸方向のスタイル
|
|
54
|
+
*
|
|
55
|
+
* stackの _getStackClossAxisStyle に相当。
|
|
56
|
+
* flowは交差軸方向のadjustはできないため、常にnoneのスタイルを返す
|
|
57
|
+
*/
|
|
58
|
+
function _getFlowCrossAxisStyle(axis, align, childSize) {
|
|
59
|
+
if (hasValue(childSize)) return {
|
|
60
|
+
className: clsx(clsLayoutAlign[axis][align], clsLayoutChildSize[axis]),
|
|
61
|
+
style: { [varLayoutChildSize[axis]]: unit(childSize) }
|
|
62
|
+
};
|
|
63
|
+
else return { className: clsLayoutAlign[axis][align] };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { flow as default };
|
package/flow/index.cjs
ADDED
package/flow/index.d.cts
ADDED
package/flow/index.d.mts
ADDED
package/flow/index.mjs
ADDED
package/flow/styles.css
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
.nws-layout-flow {
|
|
2
|
+
--nws-layout-spacingX: 0px;
|
|
3
|
+
--nws-layout-spacingY: 0px;
|
|
4
|
+
--nws-layout-childSizeX: auto;
|
|
5
|
+
--nws-layout-childSizeY: auto;
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-wrap: wrap;
|
|
8
|
+
}
|
|
9
|
+
.nws-layout-flow.nws-layout-spacingX {
|
|
10
|
+
column-gap: var(--nws-layout-spacingX);
|
|
11
|
+
}
|
|
12
|
+
.nws-layout-flow.nws-layout-spacingY {
|
|
13
|
+
row-gap: var(--nws-layout-spacingY);
|
|
14
|
+
}
|
|
15
|
+
.nws-layout-flow.nws-layout-direction-x {
|
|
16
|
+
flex-direction: row;
|
|
17
|
+
}
|
|
18
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignX-left {
|
|
19
|
+
justify-content: flex-start;
|
|
20
|
+
}
|
|
21
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignX-center {
|
|
22
|
+
justify-content: center;
|
|
23
|
+
}
|
|
24
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignX-right {
|
|
25
|
+
justify-content: flex-end;
|
|
26
|
+
}
|
|
27
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignX-spaceBetween {
|
|
28
|
+
justify-content: space-between;
|
|
29
|
+
}
|
|
30
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignX-spaceAround {
|
|
31
|
+
justify-content: space-around;
|
|
32
|
+
}
|
|
33
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignX-spaceEvenly {
|
|
34
|
+
justify-content: space-evenly;
|
|
35
|
+
}
|
|
36
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignY-top {
|
|
37
|
+
align-items: flex-start;
|
|
38
|
+
align-content: flex-start;
|
|
39
|
+
}
|
|
40
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignY-middle {
|
|
41
|
+
align-items: center;
|
|
42
|
+
align-content: center;
|
|
43
|
+
}
|
|
44
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignY-bottom {
|
|
45
|
+
align-items: flex-end;
|
|
46
|
+
align-content: flex-end;
|
|
47
|
+
}
|
|
48
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignY-spaceBetween {
|
|
49
|
+
align-content: space-between;
|
|
50
|
+
}
|
|
51
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignY-spaceAround {
|
|
52
|
+
align-content: space-around;
|
|
53
|
+
}
|
|
54
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-alignY-spaceEvenly {
|
|
55
|
+
align-content: space-evenly;
|
|
56
|
+
}
|
|
57
|
+
.nws-layout-flow.nws-layout-direction-x > * {
|
|
58
|
+
flex-grow: 0;
|
|
59
|
+
flex-shrink: 0;
|
|
60
|
+
min-width: 0;
|
|
61
|
+
}
|
|
62
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-childSizeX > * {
|
|
63
|
+
flex-basis: var(--nws-layout-childSizeX);
|
|
64
|
+
}
|
|
65
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-adjustX-fit {
|
|
66
|
+
justify-content: flex-start;
|
|
67
|
+
}
|
|
68
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-adjustX-fit > * {
|
|
69
|
+
flex-grow: 1;
|
|
70
|
+
flex-shrink: 1;
|
|
71
|
+
flex-basis: auto;
|
|
72
|
+
min-width: 0;
|
|
73
|
+
}
|
|
74
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-adjustX-fit.nws-layout-childSizeX > * {
|
|
75
|
+
flex-basis: var(--nws-layout-childSizeX);
|
|
76
|
+
}
|
|
77
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-adjustX-grow > * {
|
|
78
|
+
flex-grow: 1;
|
|
79
|
+
}
|
|
80
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-adjustX-shrink > * {
|
|
81
|
+
flex-shrink: 1;
|
|
82
|
+
}
|
|
83
|
+
.nws-layout-flow.nws-layout-direction-x > * {
|
|
84
|
+
min-height: 0;
|
|
85
|
+
}
|
|
86
|
+
.nws-layout-flow.nws-layout-direction-x.nws-layout-childSizeY > * {
|
|
87
|
+
height: var(--nws-layout-childSizeY);
|
|
88
|
+
}
|
|
89
|
+
.nws-layout-flow.nws-layout-direction-y {
|
|
90
|
+
flex-direction: column;
|
|
91
|
+
}
|
|
92
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignX-left {
|
|
93
|
+
align-items: flex-start;
|
|
94
|
+
align-content: flex-start;
|
|
95
|
+
}
|
|
96
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignX-center {
|
|
97
|
+
align-items: center;
|
|
98
|
+
align-content: center;
|
|
99
|
+
}
|
|
100
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignX-right {
|
|
101
|
+
align-items: flex-end;
|
|
102
|
+
align-content: flex-end;
|
|
103
|
+
}
|
|
104
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignX-spaceBetween {
|
|
105
|
+
align-content: space-between;
|
|
106
|
+
}
|
|
107
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignX-spaceAround {
|
|
108
|
+
align-content: space-around;
|
|
109
|
+
}
|
|
110
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignX-spaceEvenly {
|
|
111
|
+
align-content: space-evenly;
|
|
112
|
+
}
|
|
113
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignY-top {
|
|
114
|
+
justify-content: flex-start;
|
|
115
|
+
}
|
|
116
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignY-middle {
|
|
117
|
+
justify-content: center;
|
|
118
|
+
}
|
|
119
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignY-bottom {
|
|
120
|
+
justify-content: flex-end;
|
|
121
|
+
}
|
|
122
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignY-spaceBetween {
|
|
123
|
+
justify-content: space-between;
|
|
124
|
+
}
|
|
125
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignY-spaceAround {
|
|
126
|
+
justify-content: space-around;
|
|
127
|
+
}
|
|
128
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-alignY-spaceEvenly {
|
|
129
|
+
justify-content: space-evenly;
|
|
130
|
+
}
|
|
131
|
+
.nws-layout-flow.nws-layout-direction-y > * {
|
|
132
|
+
min-width: 0;
|
|
133
|
+
}
|
|
134
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-childSizeX > * {
|
|
135
|
+
width: var(--nws-layout-childSizeX);
|
|
136
|
+
}
|
|
137
|
+
.nws-layout-flow.nws-layout-direction-y > * {
|
|
138
|
+
flex-grow: 0;
|
|
139
|
+
flex-shrink: 0;
|
|
140
|
+
min-height: 0;
|
|
141
|
+
}
|
|
142
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-childSizeY > * {
|
|
143
|
+
flex-basis: var(--nws-layout-childSizeY);
|
|
144
|
+
}
|
|
145
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-adjustY-fit {
|
|
146
|
+
justify-content: flex-start;
|
|
147
|
+
}
|
|
148
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-adjustY-fit > * {
|
|
149
|
+
flex-grow: 1;
|
|
150
|
+
flex-shrink: 1;
|
|
151
|
+
flex-basis: auto;
|
|
152
|
+
min-height: 0;
|
|
153
|
+
}
|
|
154
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-adjustY-fit.nws-layout-childSizeY > * {
|
|
155
|
+
flex-basis: var(--nws-layout-childSizeY);
|
|
156
|
+
}
|
|
157
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-adjustY-grow > * {
|
|
158
|
+
flex-grow: 1;
|
|
159
|
+
}
|
|
160
|
+
.nws-layout-flow.nws-layout-direction-y.nws-layout-adjustY-shrink > * {
|
|
161
|
+
flex-shrink: 1;
|
|
162
|
+
}
|
package/flow/types.cjs
ADDED
|
File without changes
|
package/flow/types.d.cts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AdjustBase } from "../constants.cjs";
|
|
2
|
+
import { AdjustOptions, AlignOptions, ChildSizeOptions, DirectionOptions, SpacingOptions } from "../_types.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/flow/types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* flowのオプション
|
|
7
|
+
*
|
|
8
|
+
* - `direction='x'` 時: `adjustY` に `fit`,`grow`,`shrink` 指定不可
|
|
9
|
+
* - `direction='y'` 時: `adjustX` に `fit`,`grow`,`shrink` 指定不可
|
|
10
|
+
*/
|
|
11
|
+
type FlowLayoutOptions = AlignOptions & ChildSizeOptions & SpacingOptions & FlowDirectionWithAdjustOptions;
|
|
12
|
+
/**
|
|
13
|
+
* direction & adjustのオプション
|
|
14
|
+
*/
|
|
15
|
+
type FlowDirectionWithAdjustOptions = (DirectionOptions<'x'> & Omit<AdjustOptions, 'adjustY'> & {
|
|
16
|
+
adjustY?: AdjustBase;
|
|
17
|
+
}) | (DirectionOptions<'y'> & Omit<AdjustOptions, 'adjustX'> & {
|
|
18
|
+
adjustX?: AdjustBase;
|
|
19
|
+
});
|
|
20
|
+
//#endregion
|
|
21
|
+
export { FlowLayoutOptions };
|
package/flow/types.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AdjustBase } from "../constants.mjs";
|
|
2
|
+
import { AdjustOptions, AlignOptions, ChildSizeOptions, DirectionOptions, SpacingOptions } from "../_types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/flow/types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* flowのオプション
|
|
7
|
+
*
|
|
8
|
+
* - `direction='x'` 時: `adjustY` に `fit`,`grow`,`shrink` 指定不可
|
|
9
|
+
* - `direction='y'` 時: `adjustX` に `fit`,`grow`,`shrink` 指定不可
|
|
10
|
+
*/
|
|
11
|
+
type FlowLayoutOptions = AlignOptions & ChildSizeOptions & SpacingOptions & FlowDirectionWithAdjustOptions;
|
|
12
|
+
/**
|
|
13
|
+
* direction & adjustのオプション
|
|
14
|
+
*/
|
|
15
|
+
type FlowDirectionWithAdjustOptions = (DirectionOptions<'x'> & Omit<AdjustOptions, 'adjustY'> & {
|
|
16
|
+
adjustY?: AdjustBase;
|
|
17
|
+
}) | (DirectionOptions<'y'> & Omit<AdjustOptions, 'adjustX'> & {
|
|
18
|
+
adjustX?: AdjustBase;
|
|
19
|
+
});
|
|
20
|
+
//#endregion
|
|
21
|
+
export { FlowLayoutOptions };
|
package/flow/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/index.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_balance_balance = require('./balance/balance.cjs');
|
|
3
|
+
require('./balance/index.cjs');
|
|
4
|
+
const require_flow_flow = require('./flow/flow.cjs');
|
|
5
|
+
require('./flow/index.cjs');
|
|
6
|
+
const require_matrix_matrix = require('./matrix/matrix.cjs');
|
|
7
|
+
require('./matrix/index.cjs');
|
|
8
|
+
const require_pack_pack = require('./pack/pack.cjs');
|
|
9
|
+
require('./pack/index.cjs');
|
|
10
|
+
const require_pin_pin = require('./pin/pin.cjs');
|
|
11
|
+
require('./pin/index.cjs');
|
|
12
|
+
const require_stack_stack = require('./stack/stack.cjs');
|
|
13
|
+
require('./stack/index.cjs');
|
|
14
|
+
const require_tile_tile = require('./tile/tile.cjs');
|
|
15
|
+
require('./tile/index.cjs');
|
|
16
|
+
|
|
17
|
+
exports.balance = require_balance_balance;
|
|
18
|
+
exports.flow = require_flow_flow;
|
|
19
|
+
exports.matrix = require_matrix_matrix;
|
|
20
|
+
exports.pack = require_pack_pack;
|
|
21
|
+
exports.pin = require_pin_pin;
|
|
22
|
+
exports.stack = require_stack_stack;
|
|
23
|
+
exports.tile = require_tile_tile;
|
package/index.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CreateLayout, LayoutResult } from "./types.cjs";
|
|
2
|
+
import { BalanceLayoutOptions } from "./balance/types.cjs";
|
|
3
|
+
import balance from "./balance/balance.cjs";
|
|
4
|
+
import { FlowLayoutOptions } from "./flow/types.cjs";
|
|
5
|
+
import flow from "./flow/flow.cjs";
|
|
6
|
+
import { MatrixLayoutOptions } from "./matrix/types.cjs";
|
|
7
|
+
import matrix from "./matrix/matrix.cjs";
|
|
8
|
+
import { PackLayoutOptions } from "./pack/types.cjs";
|
|
9
|
+
import pack from "./pack/pack.cjs";
|
|
10
|
+
import { PinLayoutOptions } from "./pin/types.cjs";
|
|
11
|
+
import pin from "./pin/pin.cjs";
|
|
12
|
+
import { StackLayoutOptions } from "./stack/types.cjs";
|
|
13
|
+
import stack from "./stack/stack.cjs";
|
|
14
|
+
import { TileLayoutOptions } from "./tile/types.cjs";
|
|
15
|
+
import tile from "./tile/tile.cjs";
|
|
16
|
+
export { BalanceLayoutOptions, CreateLayout, FlowLayoutOptions, LayoutResult, MatrixLayoutOptions, PackLayoutOptions, PinLayoutOptions, StackLayoutOptions, TileLayoutOptions, balance, flow, matrix, pack, pin, stack, tile };
|
package/index.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CreateLayout, LayoutResult } from "./types.mjs";
|
|
2
|
+
import { BalanceLayoutOptions } from "./balance/types.mjs";
|
|
3
|
+
import balance from "./balance/balance.mjs";
|
|
4
|
+
import { FlowLayoutOptions } from "./flow/types.mjs";
|
|
5
|
+
import flow from "./flow/flow.mjs";
|
|
6
|
+
import { MatrixLayoutOptions } from "./matrix/types.mjs";
|
|
7
|
+
import matrix from "./matrix/matrix.mjs";
|
|
8
|
+
import { PackLayoutOptions } from "./pack/types.mjs";
|
|
9
|
+
import pack from "./pack/pack.mjs";
|
|
10
|
+
import { PinLayoutOptions } from "./pin/types.mjs";
|
|
11
|
+
import pin from "./pin/pin.mjs";
|
|
12
|
+
import { StackLayoutOptions } from "./stack/types.mjs";
|
|
13
|
+
import stack from "./stack/stack.mjs";
|
|
14
|
+
import { TileLayoutOptions } from "./tile/types.mjs";
|
|
15
|
+
import tile from "./tile/tile.mjs";
|
|
16
|
+
export { BalanceLayoutOptions, CreateLayout, FlowLayoutOptions, LayoutResult, MatrixLayoutOptions, PackLayoutOptions, PinLayoutOptions, StackLayoutOptions, TileLayoutOptions, balance, flow, matrix, pack, pin, stack, tile };
|
package/index.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import balance from "./balance/balance.mjs";
|
|
2
|
+
import "./balance/index.mjs";
|
|
3
|
+
import flow from "./flow/flow.mjs";
|
|
4
|
+
import "./flow/index.mjs";
|
|
5
|
+
import matrix from "./matrix/matrix.mjs";
|
|
6
|
+
import "./matrix/index.mjs";
|
|
7
|
+
import pack from "./pack/pack.mjs";
|
|
8
|
+
import "./pack/index.mjs";
|
|
9
|
+
import pin from "./pin/pin.mjs";
|
|
10
|
+
import "./pin/index.mjs";
|
|
11
|
+
import stack from "./stack/stack.mjs";
|
|
12
|
+
import "./stack/index.mjs";
|
|
13
|
+
import tile from "./tile/tile.mjs";
|
|
14
|
+
import "./tile/index.mjs";
|
|
15
|
+
|
|
16
|
+
export { balance, flow, matrix, pack, pin, stack, tile };
|
package/matrix/index.cjs
ADDED
package/matrix/index.mjs
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_constants = require('../constants.cjs');
|
|
3
|
+
const require__constants = require('../_constants.cjs');
|
|
4
|
+
const require__helpers_hasValue = require('../_helpers/hasValue.cjs');
|
|
5
|
+
const require__helpers_unit = require('../_helpers/unit.cjs');
|
|
6
|
+
const require__helpers_applySpacing = require('../_helpers/applySpacing.cjs');
|
|
7
|
+
const require__helpers_mergeLayoutResults = require('../_helpers/mergeLayoutResults.cjs');
|
|
8
|
+
require('./styles.cjs');
|
|
9
|
+
let _niche_works_utils_object_maybeDefault = require("@niche-works/utils/object/maybeDefault");
|
|
10
|
+
_niche_works_utils_object_maybeDefault = require_runtime.__toESM(_niche_works_utils_object_maybeDefault, 1);
|
|
11
|
+
let clsx = require("clsx");
|
|
12
|
+
clsx = require_runtime.__toESM(clsx, 1);
|
|
13
|
+
|
|
14
|
+
//#region src/matrix/matrix.ts
|
|
15
|
+
/**
|
|
16
|
+
* matrixレイアウト
|
|
17
|
+
*
|
|
18
|
+
* - 子要素の縦の数、横の数を基準にして格子状に配置する
|
|
19
|
+
*/
|
|
20
|
+
const matrix = (options) => {
|
|
21
|
+
const { direction, alignX, alignY, adjustX, adjustY, spacing, spacingX = spacing, spacingY = spacing, childSizeX, childSizeY, childCountX, childCountY, childX, childY } = (0, _niche_works_utils_object_maybeDefault.default)(options, {
|
|
22
|
+
direction: "x",
|
|
23
|
+
alignX: "left",
|
|
24
|
+
alignY: "top"
|
|
25
|
+
}, { overwriteNull: true });
|
|
26
|
+
const result = {
|
|
27
|
+
className: (0, clsx.default)(require_constants.clsLayoutMatrix, require__constants.clsLayoutDirection[direction], require__constants.clsLayoutAlign.x[alignX], require__constants.clsLayoutAlign.y[alignY], require__constants.clsLayoutAdjust.x[adjustX], require__constants.clsLayoutAdjust.y[adjustY]),
|
|
28
|
+
style: {}
|
|
29
|
+
};
|
|
30
|
+
require__helpers_applySpacing(result, spacing, spacingX, spacingY);
|
|
31
|
+
return require__helpers_mergeLayoutResults([
|
|
32
|
+
result,
|
|
33
|
+
_getGridTemplate("x", adjustX, childSizeX, childCountX, childX),
|
|
34
|
+
_getGridTemplate("y", adjustY, childSizeY, childCountY, childY)
|
|
35
|
+
]);
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* gridTemplateColumns / gridTemplateRowsを生成する
|
|
39
|
+
* @param axis 軸
|
|
40
|
+
* @param adjust 子要素のサイズ調整
|
|
41
|
+
* @param childSize 子要素のサイズ
|
|
42
|
+
* @param childCount 子要素数
|
|
43
|
+
* @param child 子要素数 & サイズ
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
function _getGridTemplate(axis, adjust, childSize, childCount, child) {
|
|
47
|
+
let template;
|
|
48
|
+
if (Array.isArray(child)) {
|
|
49
|
+
const pxTotal = child.reduce((sum, value) => {
|
|
50
|
+
const px = _extractPx(value);
|
|
51
|
+
return px !== null ? sum + px : sum;
|
|
52
|
+
}, 0);
|
|
53
|
+
template = child.map((value) => _applyAdjustToTrack(axis, adjust, value, child.length, pxTotal)).join(" ");
|
|
54
|
+
} else {
|
|
55
|
+
const hasChildSize = require__helpers_hasValue(childSize);
|
|
56
|
+
const hasCount = require__helpers_hasValue(childCount);
|
|
57
|
+
if (adjust === "fit") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(clamp(0px, ${`calc((100% - var(${require__constants.varLayoutSpacing[axis]}) * (${childCount} - 1)) / ${childCount})`}, ${require__helpers_unit(childSize)}), 1fr))`;
|
|
58
|
+
else if (hasChildSize) template = `repeat(auto-fit, minmax(clamp(0px, 100%, ${require__helpers_unit(childSize)}), 1fr))`;
|
|
59
|
+
else if (hasCount) template = `repeat(${childCount}, 1fr)`;
|
|
60
|
+
else template = "repeat(auto-fit, 1fr)";
|
|
61
|
+
else if (adjust === "grow") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(${require__helpers_unit(childSize)}, 1fr))`;
|
|
62
|
+
else if (hasChildSize) template = `repeat(auto-fit, minmax(${require__helpers_unit(childSize)}, 1fr))`;
|
|
63
|
+
else if (hasCount) template = `repeat(${childCount}, 1fr)`;
|
|
64
|
+
else template = "repeat(auto-fit, 1fr)";
|
|
65
|
+
else if (adjust === "shrink") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(0, ${require__helpers_unit(childSize)}))`;
|
|
66
|
+
else if (hasChildSize) template = `repeat(auto-fit, minmax(0, ${require__helpers_unit(childSize)}))`;
|
|
67
|
+
else if (hasCount) template = `repeat(${childCount}, auto)`;
|
|
68
|
+
else template = "repeat(auto-fit, auto)";
|
|
69
|
+
else if (hasChildSize && hasCount) template = `repeat(${childCount}, ${require__helpers_unit(childSize)})`;
|
|
70
|
+
else if (hasChildSize) template = `repeat(auto-fit, ${require__helpers_unit(childSize)})`;
|
|
71
|
+
else if (hasCount) template = `repeat(${childCount}, auto)`;
|
|
72
|
+
else template = "repeat(auto-fit, auto)";
|
|
73
|
+
}
|
|
74
|
+
return { style: { [require__constants.varLayoutTemplate[axis]]: template } };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* childX/childYの各トラック値にadjustを適用する
|
|
78
|
+
* fr単位の値はminmax()のminに使えないため特別扱いになり、
|
|
79
|
+
* 伸縮の比率には影響しない
|
|
80
|
+
*/
|
|
81
|
+
function _applyAdjustToTrack(axis, adjust, size, childCount, pxTotal) {
|
|
82
|
+
const childSize = require__helpers_unit(size);
|
|
83
|
+
const isFr = typeof size === "string" && size.trim().endsWith("fr");
|
|
84
|
+
const pxValue = _extractPx(size);
|
|
85
|
+
const isPx = pxValue !== null;
|
|
86
|
+
if (adjust === "fit") {
|
|
87
|
+
if (isPx && pxTotal > 0) return `minmax(0, max(${`calc((100% - var(${require__constants.varLayoutSpacing[axis]}) * (${childCount} - 1)) * ${pxValue} / ${pxTotal})`}, ${childSize}))`;
|
|
88
|
+
return isFr ? childSize : `minmax(0, ${childSize})`;
|
|
89
|
+
} else if (adjust === "grow") {
|
|
90
|
+
if (isPx && pxTotal > 0) return `minmax(${childSize}, calc(${pxValue} / ${pxTotal} * (100% - var(${require__constants.varLayoutSpacing[axis]}) * (${childCount} - 1))))`;
|
|
91
|
+
return isFr ? childSize : `minmax(${childSize}, 1fr)`;
|
|
92
|
+
} else if (adjust === "shrink") {
|
|
93
|
+
if (isPx && pxTotal > 0) return `minmax(0, min(${`calc((100% - var(${require__constants.varLayoutSpacing[axis]}) * (${childCount} - 1)) * ${pxValue} / ${pxTotal})`}, ${childSize}))`;
|
|
94
|
+
return isFr ? childSize : `minmax(0, ${childSize})`;
|
|
95
|
+
}
|
|
96
|
+
return childSize;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* px値を数値として抽出する
|
|
100
|
+
* px以外の単位はnullを返す
|
|
101
|
+
*/
|
|
102
|
+
function _extractPx(childSize) {
|
|
103
|
+
if (typeof childSize === "number") return childSize;
|
|
104
|
+
const match = childSize.trim().match(/^([\d.]+)px$/);
|
|
105
|
+
return match ? parseFloat(match[1]) : null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
module.exports = matrix;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CreateLayout } from "../types.cjs";
|
|
2
|
+
import { MatrixLayoutOptions } from "./types.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/matrix/matrix.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* matrixレイアウト
|
|
7
|
+
*
|
|
8
|
+
* - 子要素の縦の数、横の数を基準にして格子状に配置する
|
|
9
|
+
*/
|
|
10
|
+
declare const matrix: CreateLayout<MatrixLayoutOptions>;
|
|
11
|
+
export = matrix;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CreateLayout } from "../types.mjs";
|
|
2
|
+
import { MatrixLayoutOptions } from "./types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/matrix/matrix.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* matrixレイアウト
|
|
7
|
+
*
|
|
8
|
+
* - 子要素の縦の数、横の数を基準にして格子状に配置する
|
|
9
|
+
*/
|
|
10
|
+
declare const matrix: CreateLayout<MatrixLayoutOptions>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { matrix as default };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { clsLayoutMatrix } from "../constants.mjs";
|
|
2
|
+
import { clsLayoutAdjust, clsLayoutAlign, clsLayoutDirection, varLayoutSpacing, varLayoutTemplate } from "../_constants.mjs";
|
|
3
|
+
import hasValue from "../_helpers/hasValue.mjs";
|
|
4
|
+
import unit from "../_helpers/unit.mjs";
|
|
5
|
+
import applySpacing from "../_helpers/applySpacing.mjs";
|
|
6
|
+
import mergeLayoutResults from "../_helpers/mergeLayoutResults.mjs";
|
|
7
|
+
import "./styles.css";
|
|
8
|
+
import maybeDefault from "@niche-works/utils/object/maybeDefault";
|
|
9
|
+
import clsx from "clsx";
|
|
10
|
+
|
|
11
|
+
//#region src/matrix/matrix.ts
|
|
12
|
+
/**
|
|
13
|
+
* matrixレイアウト
|
|
14
|
+
*
|
|
15
|
+
* - 子要素の縦の数、横の数を基準にして格子状に配置する
|
|
16
|
+
*/
|
|
17
|
+
const matrix = (options) => {
|
|
18
|
+
const { direction, alignX, alignY, adjustX, adjustY, spacing, spacingX = spacing, spacingY = spacing, childSizeX, childSizeY, childCountX, childCountY, childX, childY } = maybeDefault(options, {
|
|
19
|
+
direction: "x",
|
|
20
|
+
alignX: "left",
|
|
21
|
+
alignY: "top"
|
|
22
|
+
}, { overwriteNull: true });
|
|
23
|
+
const result = {
|
|
24
|
+
className: clsx(clsLayoutMatrix, clsLayoutDirection[direction], clsLayoutAlign.x[alignX], clsLayoutAlign.y[alignY], clsLayoutAdjust.x[adjustX], clsLayoutAdjust.y[adjustY]),
|
|
25
|
+
style: {}
|
|
26
|
+
};
|
|
27
|
+
applySpacing(result, spacing, spacingX, spacingY);
|
|
28
|
+
return mergeLayoutResults([
|
|
29
|
+
result,
|
|
30
|
+
_getGridTemplate("x", adjustX, childSizeX, childCountX, childX),
|
|
31
|
+
_getGridTemplate("y", adjustY, childSizeY, childCountY, childY)
|
|
32
|
+
]);
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* gridTemplateColumns / gridTemplateRowsを生成する
|
|
36
|
+
* @param axis 軸
|
|
37
|
+
* @param adjust 子要素のサイズ調整
|
|
38
|
+
* @param childSize 子要素のサイズ
|
|
39
|
+
* @param childCount 子要素数
|
|
40
|
+
* @param child 子要素数 & サイズ
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
function _getGridTemplate(axis, adjust, childSize, childCount, child) {
|
|
44
|
+
let template;
|
|
45
|
+
if (Array.isArray(child)) {
|
|
46
|
+
const pxTotal = child.reduce((sum, value) => {
|
|
47
|
+
const px = _extractPx(value);
|
|
48
|
+
return px !== null ? sum + px : sum;
|
|
49
|
+
}, 0);
|
|
50
|
+
template = child.map((value) => _applyAdjustToTrack(axis, adjust, value, child.length, pxTotal)).join(" ");
|
|
51
|
+
} else {
|
|
52
|
+
const hasChildSize = hasValue(childSize);
|
|
53
|
+
const hasCount = hasValue(childCount);
|
|
54
|
+
if (adjust === "fit") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(clamp(0px, ${`calc((100% - var(${varLayoutSpacing[axis]}) * (${childCount} - 1)) / ${childCount})`}, ${unit(childSize)}), 1fr))`;
|
|
55
|
+
else if (hasChildSize) template = `repeat(auto-fit, minmax(clamp(0px, 100%, ${unit(childSize)}), 1fr))`;
|
|
56
|
+
else if (hasCount) template = `repeat(${childCount}, 1fr)`;
|
|
57
|
+
else template = "repeat(auto-fit, 1fr)";
|
|
58
|
+
else if (adjust === "grow") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(${unit(childSize)}, 1fr))`;
|
|
59
|
+
else if (hasChildSize) template = `repeat(auto-fit, minmax(${unit(childSize)}, 1fr))`;
|
|
60
|
+
else if (hasCount) template = `repeat(${childCount}, 1fr)`;
|
|
61
|
+
else template = "repeat(auto-fit, 1fr)";
|
|
62
|
+
else if (adjust === "shrink") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(0, ${unit(childSize)}))`;
|
|
63
|
+
else if (hasChildSize) template = `repeat(auto-fit, minmax(0, ${unit(childSize)}))`;
|
|
64
|
+
else if (hasCount) template = `repeat(${childCount}, auto)`;
|
|
65
|
+
else template = "repeat(auto-fit, auto)";
|
|
66
|
+
else if (hasChildSize && hasCount) template = `repeat(${childCount}, ${unit(childSize)})`;
|
|
67
|
+
else if (hasChildSize) template = `repeat(auto-fit, ${unit(childSize)})`;
|
|
68
|
+
else if (hasCount) template = `repeat(${childCount}, auto)`;
|
|
69
|
+
else template = "repeat(auto-fit, auto)";
|
|
70
|
+
}
|
|
71
|
+
return { style: { [varLayoutTemplate[axis]]: template } };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* childX/childYの各トラック値にadjustを適用する
|
|
75
|
+
* fr単位の値はminmax()のminに使えないため特別扱いになり、
|
|
76
|
+
* 伸縮の比率には影響しない
|
|
77
|
+
*/
|
|
78
|
+
function _applyAdjustToTrack(axis, adjust, size, childCount, pxTotal) {
|
|
79
|
+
const childSize = unit(size);
|
|
80
|
+
const isFr = typeof size === "string" && size.trim().endsWith("fr");
|
|
81
|
+
const pxValue = _extractPx(size);
|
|
82
|
+
const isPx = pxValue !== null;
|
|
83
|
+
if (adjust === "fit") {
|
|
84
|
+
if (isPx && pxTotal > 0) return `minmax(0, max(${`calc((100% - var(${varLayoutSpacing[axis]}) * (${childCount} - 1)) * ${pxValue} / ${pxTotal})`}, ${childSize}))`;
|
|
85
|
+
return isFr ? childSize : `minmax(0, ${childSize})`;
|
|
86
|
+
} else if (adjust === "grow") {
|
|
87
|
+
if (isPx && pxTotal > 0) return `minmax(${childSize}, calc(${pxValue} / ${pxTotal} * (100% - var(${varLayoutSpacing[axis]}) * (${childCount} - 1))))`;
|
|
88
|
+
return isFr ? childSize : `minmax(${childSize}, 1fr)`;
|
|
89
|
+
} else if (adjust === "shrink") {
|
|
90
|
+
if (isPx && pxTotal > 0) return `minmax(0, min(${`calc((100% - var(${varLayoutSpacing[axis]}) * (${childCount} - 1)) * ${pxValue} / ${pxTotal})`}, ${childSize}))`;
|
|
91
|
+
return isFr ? childSize : `minmax(0, ${childSize})`;
|
|
92
|
+
}
|
|
93
|
+
return childSize;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* px値を数値として抽出する
|
|
97
|
+
* px以外の単位はnullを返す
|
|
98
|
+
*/
|
|
99
|
+
function _extractPx(childSize) {
|
|
100
|
+
if (typeof childSize === "number") return childSize;
|
|
101
|
+
const match = childSize.trim().match(/^([\d.]+)px$/);
|
|
102
|
+
return match ? parseFloat(match[1]) : null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { matrix as default };
|