@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.
Files changed (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/_constants.cjs +94 -0
  4. package/_constants.d.cts +83 -0
  5. package/_constants.d.mts +83 -0
  6. package/_constants.mjs +86 -0
  7. package/_helpers/applyChildCount.cjs +26 -0
  8. package/_helpers/applyChildCount.d.cts +12 -0
  9. package/_helpers/applyChildCount.d.mts +13 -0
  10. package/_helpers/applyChildCount.mjs +24 -0
  11. package/_helpers/applyChildSize.cjs +27 -0
  12. package/_helpers/applyChildSize.d.cts +12 -0
  13. package/_helpers/applyChildSize.d.mts +13 -0
  14. package/_helpers/applyChildSize.mjs +25 -0
  15. package/_helpers/applySpacing.cjs +30 -0
  16. package/_helpers/applySpacing.d.cts +13 -0
  17. package/_helpers/applySpacing.d.mts +14 -0
  18. package/_helpers/applySpacing.mjs +28 -0
  19. package/_helpers/hasValue.cjs +15 -0
  20. package/_helpers/hasValue.d.cts +8 -0
  21. package/_helpers/hasValue.d.mts +9 -0
  22. package/_helpers/hasValue.mjs +14 -0
  23. package/_helpers/mergeLayoutResults.cjs +18 -0
  24. package/_helpers/mergeLayoutResults.d.cts +5 -0
  25. package/_helpers/mergeLayoutResults.d.mts +6 -0
  26. package/_helpers/mergeLayoutResults.mjs +16 -0
  27. package/_helpers/unit.cjs +16 -0
  28. package/_helpers/unit.d.cts +10 -0
  29. package/_helpers/unit.d.mts +11 -0
  30. package/_helpers/unit.mjs +15 -0
  31. package/_types.cjs +0 -0
  32. package/_types.d.cts +118 -0
  33. package/_types.d.mts +118 -0
  34. package/_types.mjs +1 -0
  35. package/_virtual/_rolldown/runtime.cjs +29 -0
  36. package/balance/balance.cjs +34 -0
  37. package/balance/balance.d.cts +11 -0
  38. package/balance/balance.d.mts +12 -0
  39. package/balance/balance.mjs +31 -0
  40. package/balance/index.cjs +3 -0
  41. package/balance/index.d.cts +3 -0
  42. package/balance/index.d.mts +3 -0
  43. package/balance/index.mjs +3 -0
  44. package/balance/styles.css +109 -0
  45. package/balance/types.cjs +0 -0
  46. package/balance/types.d.cts +6 -0
  47. package/balance/types.d.mts +6 -0
  48. package/balance/types.mjs +1 -0
  49. package/constants.cjs +341 -0
  50. package/constants.d.cts +299 -0
  51. package/constants.d.mts +299 -0
  52. package/constants.mjs +288 -0
  53. package/flow/flow.cjs +70 -0
  54. package/flow/flow.d.cts +12 -0
  55. package/flow/flow.d.mts +13 -0
  56. package/flow/flow.mjs +67 -0
  57. package/flow/index.cjs +3 -0
  58. package/flow/index.d.cts +3 -0
  59. package/flow/index.d.mts +3 -0
  60. package/flow/index.mjs +3 -0
  61. package/flow/styles.css +162 -0
  62. package/flow/types.cjs +0 -0
  63. package/flow/types.d.cts +21 -0
  64. package/flow/types.d.mts +21 -0
  65. package/flow/types.mjs +1 -0
  66. package/index.cjs +23 -0
  67. package/index.d.cts +16 -0
  68. package/index.d.mts +16 -0
  69. package/index.mjs +16 -0
  70. package/matrix/index.cjs +3 -0
  71. package/matrix/index.d.cts +3 -0
  72. package/matrix/index.d.mts +3 -0
  73. package/matrix/index.mjs +3 -0
  74. package/matrix/matrix.cjs +109 -0
  75. package/matrix/matrix.d.cts +11 -0
  76. package/matrix/matrix.d.mts +12 -0
  77. package/matrix/matrix.mjs +106 -0
  78. package/matrix/styles.css +59 -0
  79. package/matrix/types.cjs +0 -0
  80. package/matrix/types.d.cts +46 -0
  81. package/matrix/types.d.mts +46 -0
  82. package/matrix/types.mjs +1 -0
  83. package/pack/index.cjs +3 -0
  84. package/pack/index.d.cts +3 -0
  85. package/pack/index.d.mts +3 -0
  86. package/pack/index.mjs +3 -0
  87. package/pack/pack.cjs +28 -0
  88. package/pack/pack.d.cts +11 -0
  89. package/pack/pack.d.mts +12 -0
  90. package/pack/pack.mjs +25 -0
  91. package/pack/styles.css +27 -0
  92. package/pack/types.cjs +0 -0
  93. package/pack/types.d.cts +6 -0
  94. package/pack/types.d.mts +6 -0
  95. package/pack/types.mjs +1 -0
  96. package/package.json +45 -0
  97. package/pin/index.cjs +3 -0
  98. package/pin/index.d.cts +3 -0
  99. package/pin/index.d.mts +3 -0
  100. package/pin/index.mjs +3 -0
  101. package/pin/pin.cjs +22 -0
  102. package/pin/pin.d.cts +11 -0
  103. package/pin/pin.d.mts +12 -0
  104. package/pin/pin.mjs +22 -0
  105. package/pin/styles.css +15 -0
  106. package/pin/types.cjs +0 -0
  107. package/pin/types.d.cts +6 -0
  108. package/pin/types.d.mts +6 -0
  109. package/pin/types.mjs +1 -0
  110. package/stack/index.cjs +3 -0
  111. package/stack/index.d.cts +3 -0
  112. package/stack/index.d.mts +3 -0
  113. package/stack/index.mjs +3 -0
  114. package/stack/stack.cjs +98 -0
  115. package/stack/stack.d.cts +11 -0
  116. package/stack/stack.d.mts +12 -0
  117. package/stack/stack.mjs +95 -0
  118. package/stack/styles.css +171 -0
  119. package/stack/types.cjs +0 -0
  120. package/stack/types.d.cts +21 -0
  121. package/stack/types.d.mts +21 -0
  122. package/stack/types.mjs +1 -0
  123. package/tile/index.cjs +3 -0
  124. package/tile/index.d.cts +3 -0
  125. package/tile/index.d.mts +3 -0
  126. package/tile/index.mjs +3 -0
  127. package/tile/styles.css +104 -0
  128. package/tile/tile.cjs +85 -0
  129. package/tile/tile.d.cts +12 -0
  130. package/tile/tile.d.mts +13 -0
  131. package/tile/tile.mjs +82 -0
  132. package/tile/types.cjs +0 -0
  133. package/tile/types.d.cts +9 -0
  134. package/tile/types.d.mts +9 -0
  135. package/tile/types.mjs +1 -0
  136. package/types.cjs +0 -0
  137. package/types.d.cts +23 -0
  138. package/types.d.mts +23 -0
  139. package/types.mjs +1 -0
@@ -0,0 +1,95 @@
1
+ import { clsLayoutStack } from "../constants.mjs";
2
+ import { clsLayoutAdjust, clsLayoutAlign, clsLayoutChildSize, clsLayoutDirection, cssLayoutAxisSizeProp, 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/stack/stack.ts
12
+ /**
13
+ * stackレイアウト
14
+ *
15
+ * - 子要素を並べて配置する
16
+ */
17
+ const stack = (options = {}) => {
18
+ const { direction, alignX, alignY, adjustX, adjustY, spacing, spacingX = spacing, spacingY = spacing, childSizeX, childSizeY } = maybeDefault(options, {
19
+ direction: "x",
20
+ alignX: "left",
21
+ alignY: "top"
22
+ }, { overwriteNull: true });
23
+ const result = {
24
+ className: clsx(clsLayoutStack, clsLayoutDirection[direction], clsLayoutAlign.x[alignX], clsLayoutAlign.y[alignY]),
25
+ style: {}
26
+ };
27
+ applySpacing(result, spacing, spacingX, spacingY);
28
+ const resultList = [result];
29
+ if (direction === "x") {
30
+ resultList.push(_getStackMainAxisStyle("x", alignX, adjustX, childSizeX));
31
+ resultList.push(_getStackClossAxisStyle("y", alignY, adjustY, childSizeY));
32
+ } else {
33
+ resultList.push(_getStackClossAxisStyle("x", alignX, adjustX, childSizeX));
34
+ resultList.push(_getStackMainAxisStyle("y", alignY, adjustY, childSizeY));
35
+ }
36
+ return mergeLayoutResults(resultList);
37
+ };
38
+ /**
39
+ * 主軸方向のスタイル
40
+ * @param axis 横 or 縦
41
+ * @param align 位置
42
+ * @param adjust 子要素のサイズの調整
43
+ * @param childSize 子要素のサイズ
44
+ * @returns スタイル
45
+ */
46
+ function _getStackMainAxisStyle(axis, align, adjust, childSize) {
47
+ const result = { className: clsx(clsLayoutAlign[axis][align], clsLayoutAdjust[axis][adjust]) };
48
+ if (hasValue(childSize)) {
49
+ result.className = clsx(result.className, clsLayoutChildSize[axis]);
50
+ result.style = { [varLayoutChildSize[axis]]: unit(childSize) };
51
+ }
52
+ return result;
53
+ }
54
+ /**
55
+ * 交差軸方向のクラス
56
+ * @param axis 横 or 縦
57
+ * @param align 位置
58
+ * @param adjust 子要素のサイズの調整
59
+ * @param childSize 子要素のサイズ
60
+ * @returns スタイル
61
+ */
62
+ function _getStackClossAxisStyle(axis, align, adjust, childSize) {
63
+ if (adjust === "fit") return {
64
+ className: clsx(clsLayoutAlign[axis][align], clsLayoutAdjust[axis][adjust]),
65
+ style: {
66
+ [`min-${cssLayoutAxisSizeProp[axis]}`]: "100%",
67
+ [varLayoutChildSize[axis]]: `min(0, 100%)`
68
+ }
69
+ };
70
+ else if (adjust === "grow") {
71
+ const result = {
72
+ className: clsx(clsLayoutAlign[axis][align], clsLayoutAdjust[axis][adjust]),
73
+ style: { [`min-${cssLayoutAxisSizeProp[axis]}`]: "100%" }
74
+ };
75
+ if (hasValue(childSize)) {
76
+ result.className = clsx(result.className, clsLayoutChildSize[axis]);
77
+ result.style[varLayoutChildSize[axis]] = unit(childSize);
78
+ }
79
+ return result;
80
+ } else if (adjust === "shrink") {
81
+ const result = { className: clsx(clsLayoutAlign[axis][align], clsLayoutAdjust[axis][adjust]) };
82
+ if (hasValue(childSize)) {
83
+ result.className = clsx(result.className, clsLayoutChildSize[axis]);
84
+ result.style = { [varLayoutChildSize[axis]]: `min(${unit(childSize)}, 100%)` };
85
+ }
86
+ return result;
87
+ } else if (hasValue(childSize)) return {
88
+ className: clsx(clsLayoutAlign[axis][align], clsLayoutChildSize[axis]),
89
+ style: { [varLayoutChildSize[axis]]: unit(childSize) }
90
+ };
91
+ else return { className: clsx(clsLayoutAlign[axis][align]) };
92
+ }
93
+
94
+ //#endregion
95
+ export { stack as default };
@@ -0,0 +1,171 @@
1
+ .nws-layout-stack {
2
+ --nws-layout-spacingX: 0px;
3
+ --nws-layout-spacingY: 0px;
4
+ --nws-layout-childSizeX: auto;
5
+ --nws-layout-childSizeY: auto;
6
+ display: flex;
7
+ }
8
+ .nws-layout-stack.nws-layout-spacingX {
9
+ column-gap: var(--nws-layout-spacingX);
10
+ }
11
+ .nws-layout-stack.nws-layout-spacingY {
12
+ row-gap: var(--nws-layout-spacingY);
13
+ }
14
+ .nws-layout-stack.nws-layout-direction-x {
15
+ flex-direction: row;
16
+ }
17
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-alignX-left {
18
+ justify-content: flex-start;
19
+ }
20
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-alignX-center {
21
+ justify-content: center;
22
+ }
23
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-alignX-right {
24
+ justify-content: flex-end;
25
+ }
26
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-alignX-spaceBetween {
27
+ justify-content: space-between;
28
+ }
29
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-alignX-spaceAround {
30
+ justify-content: space-around;
31
+ }
32
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-alignX-spaceEvenly {
33
+ justify-content: space-evenly;
34
+ }
35
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-alignY-top {
36
+ align-items: flex-start;
37
+ }
38
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-alignY-middle {
39
+ align-items: center;
40
+ }
41
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-alignY-bottom {
42
+ align-items: flex-end;
43
+ }
44
+ .nws-layout-stack.nws-layout-direction-x > * {
45
+ flex-grow: 0;
46
+ flex-shrink: 0;
47
+ min-width: 0;
48
+ }
49
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-childSizeX > * {
50
+ flex-basis: var(--nws-layout-childSizeX);
51
+ }
52
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-adjustX-fit {
53
+ justify-content: flex-start;
54
+ }
55
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-adjustX-fit > * {
56
+ flex-grow: 1;
57
+ flex-shrink: 1;
58
+ flex-basis: auto;
59
+ min-width: 0;
60
+ }
61
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-adjustX-fit.nws-layout-childSizeX > * {
62
+ flex-basis: var(--nws-layout-childSizeX);
63
+ }
64
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-adjustX-grow > * {
65
+ flex-grow: 1;
66
+ }
67
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-adjustX-shrink > * {
68
+ flex-shrink: 1;
69
+ }
70
+ .nws-layout-stack.nws-layout-direction-x > * {
71
+ min-height: 0;
72
+ }
73
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-childSizeY > * {
74
+ height: var(--nws-layout-childSizeY);
75
+ }
76
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-adjustY-fit {
77
+ align-items: stretch;
78
+ }
79
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-adjustY-fit > * {
80
+ min-height: 100%;
81
+ max-height: 100%;
82
+ }
83
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-adjustY-fit.nws-layout-childSizeY > * {
84
+ height: auto;
85
+ }
86
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-adjustY-grow > * {
87
+ min-height: 100%;
88
+ }
89
+ .nws-layout-stack.nws-layout-direction-x.nws-layout-adjustY-shrink > * {
90
+ min-height: 0;
91
+ max-height: 100%;
92
+ }
93
+ .nws-layout-stack.nws-layout-direction-y {
94
+ flex-direction: column;
95
+ }
96
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-alignX-left {
97
+ align-items: flex-start;
98
+ }
99
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-alignX-center {
100
+ align-items: center;
101
+ }
102
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-alignX-right {
103
+ align-items: flex-end;
104
+ }
105
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-alignY-top {
106
+ justify-content: flex-start;
107
+ }
108
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-alignY-middle {
109
+ justify-content: center;
110
+ }
111
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-alignY-bottom {
112
+ justify-content: flex-end;
113
+ }
114
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-alignY-spaceBetween {
115
+ justify-content: space-between;
116
+ }
117
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-alignY-spaceAround {
118
+ justify-content: space-around;
119
+ }
120
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-alignY-spaceEvenly {
121
+ justify-content: space-evenly;
122
+ }
123
+ .nws-layout-stack.nws-layout-direction-y > * {
124
+ min-width: 0;
125
+ }
126
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-childSizeX > * {
127
+ width: var(--nws-layout-childSizeX);
128
+ }
129
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-adjustX-fit {
130
+ align-items: stretch;
131
+ }
132
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-adjustX-fit > * {
133
+ min-width: 100%;
134
+ max-width: 100%;
135
+ }
136
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-adjustX-fit.nws-layout-childSizeX > * {
137
+ width: auto;
138
+ }
139
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-adjustX-grow > * {
140
+ min-width: 100%;
141
+ }
142
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-adjustX-shrink > * {
143
+ min-width: 0;
144
+ max-width: 100%;
145
+ }
146
+ .nws-layout-stack.nws-layout-direction-y > * {
147
+ flex-grow: 0;
148
+ flex-shrink: 0;
149
+ min-height: 0;
150
+ }
151
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-childSizeY > * {
152
+ flex-basis: var(--nws-layout-childSizeY);
153
+ }
154
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-adjustY-fit {
155
+ justify-content: flex-start;
156
+ }
157
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-adjustY-fit > * {
158
+ flex-grow: 1;
159
+ flex-shrink: 1;
160
+ flex-basis: auto;
161
+ min-height: 0;
162
+ }
163
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-adjustY-fit.nws-layout-childSizeY > * {
164
+ flex-basis: var(--nws-layout-childSizeY);
165
+ }
166
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-adjustY-grow > * {
167
+ flex-grow: 1;
168
+ }
169
+ .nws-layout-stack.nws-layout-direction-y.nws-layout-adjustY-shrink > * {
170
+ flex-shrink: 1;
171
+ }
File without changes
@@ -0,0 +1,21 @@
1
+ import { AlignXBase, AlignYBase } from "../constants.cjs";
2
+ import { AdjustOptions, AlignOptions, ChildSizeOptions, DirectionOptions, SpacingOptions } from "../_types.cjs";
3
+
4
+ //#region src/stack/types.d.ts
5
+ /**
6
+ * stackのオプション
7
+ *
8
+ * - `direction='x'` 時: `alignY` に `space-between`,`space-around`,`space-evenly` 指定不可
9
+ * - `direction='y'` 時: `alignX` に `space-between`,`space-around`,`space-evenly` 指定不可
10
+ */
11
+ type StackLayoutOptions = AdjustOptions & ChildSizeOptions & SpacingOptions & StackDirectionWithAlignOptions;
12
+ /**
13
+ * direction & alignのオプション
14
+ */
15
+ type StackDirectionWithAlignOptions = (DirectionOptions<'x'> & Omit<AlignOptions, 'alignY'> & {
16
+ alignY?: AlignYBase;
17
+ }) | (DirectionOptions<'y'> & Omit<AlignOptions, 'alignX'> & {
18
+ alignX?: AlignXBase;
19
+ });
20
+ //#endregion
21
+ export { StackLayoutOptions };
@@ -0,0 +1,21 @@
1
+ import { AlignXBase, AlignYBase } from "../constants.mjs";
2
+ import { AdjustOptions, AlignOptions, ChildSizeOptions, DirectionOptions, SpacingOptions } from "../_types.mjs";
3
+
4
+ //#region src/stack/types.d.ts
5
+ /**
6
+ * stackのオプション
7
+ *
8
+ * - `direction='x'` 時: `alignY` に `space-between`,`space-around`,`space-evenly` 指定不可
9
+ * - `direction='y'` 時: `alignX` に `space-between`,`space-around`,`space-evenly` 指定不可
10
+ */
11
+ type StackLayoutOptions = AdjustOptions & ChildSizeOptions & SpacingOptions & StackDirectionWithAlignOptions;
12
+ /**
13
+ * direction & alignのオプション
14
+ */
15
+ type StackDirectionWithAlignOptions = (DirectionOptions<'x'> & Omit<AlignOptions, 'alignY'> & {
16
+ alignY?: AlignYBase;
17
+ }) | (DirectionOptions<'y'> & Omit<AlignOptions, 'alignX'> & {
18
+ alignX?: AlignXBase;
19
+ });
20
+ //#endregion
21
+ export { StackLayoutOptions };
@@ -0,0 +1 @@
1
+ export { };
package/tile/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ const require_tile_tile = require('./tile.cjs');
2
+
3
+ module.exports = require_tile_tile;
@@ -0,0 +1,3 @@
1
+ import { TileLayoutOptions } from "./types.cjs";
2
+ import tile from "./tile.cjs";
3
+ export { TileLayoutOptions, tile as default };
@@ -0,0 +1,3 @@
1
+ import { TileLayoutOptions } from "./types.mjs";
2
+ import tile from "./tile.mjs";
3
+ export { TileLayoutOptions, tile as default };
package/tile/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import tile from "./tile.mjs";
2
+
3
+ export { tile as default };
@@ -0,0 +1,104 @@
1
+ .nws-layout-tile {
2
+ --nws-layout-childX: none;
3
+ --nws-layout-childY: none;
4
+ --nws-layout-autoTracX: auto;
5
+ --nws-layout-autoTracY: auto;
6
+ --nws-layout-spacingX: 0px;
7
+ --nws-layout-spacingY: 0px;
8
+ --nws-layout-childSizeX: auto;
9
+ --nws-layout-childSizeY: auto;
10
+ display: grid;
11
+ }
12
+ .nws-layout-tile.nws-layout-spacingX {
13
+ column-gap: var(--nws-layout-spacingX);
14
+ }
15
+ .nws-layout-tile.nws-layout-spacingY {
16
+ row-gap: var(--nws-layout-spacingY);
17
+ }
18
+ .nws-layout-tile.nws-layout-direction-x {
19
+ grid-auto-flow: row;
20
+ grid-template-columns: var(--nws-layout-childX);
21
+ grid-auto-rows: var(--nws-layout-autoTracY);
22
+ }
23
+ .nws-layout-tile.nws-layout-direction-y {
24
+ grid-auto-flow: column;
25
+ grid-auto-columns: var(--nws-layout-autoTracX);
26
+ grid-template-rows: var(--nws-layout-childY);
27
+ }
28
+ .nws-layout-tile.nws-layout-alignX-left {
29
+ justify-content: flex-start;
30
+ }
31
+ .nws-layout-tile.nws-layout-alignX-center {
32
+ justify-content: center;
33
+ }
34
+ .nws-layout-tile.nws-layout-alignX-right {
35
+ justify-content: flex-end;
36
+ }
37
+ .nws-layout-tile.nws-layout-alignX-spaceBetween {
38
+ justify-content: space-between;
39
+ }
40
+ .nws-layout-tile.nws-layout-alignX-spaceAround {
41
+ justify-content: space-around;
42
+ }
43
+ .nws-layout-tile.nws-layout-alignX-spaceEvenly {
44
+ justify-content: space-evenly;
45
+ }
46
+ .nws-layout-tile.nws-layout-alignY-top {
47
+ align-content: flex-start;
48
+ }
49
+ .nws-layout-tile.nws-layout-alignY-middle {
50
+ align-content: center;
51
+ }
52
+ .nws-layout-tile.nws-layout-alignY-bottom {
53
+ align-content: flex-end;
54
+ }
55
+ .nws-layout-tile.nws-layout-alignY-spaceBetween {
56
+ align-content: space-between;
57
+ }
58
+ .nws-layout-tile.nws-layout-alignY-spaceAround {
59
+ align-content: space-around;
60
+ }
61
+ .nws-layout-tile.nws-layout-alignY-spaceEvenly {
62
+ align-content: space-evenly;
63
+ }
64
+ .nws-layout-tile > * {
65
+ min-width: 0;
66
+ }
67
+ .nws-layout-tile.nws-layout-childSizeX > * {
68
+ width: var(--nws-layout-childSizeX);
69
+ }
70
+ .nws-layout-tile.nws-layout-adjustX-fit > * {
71
+ width: auto;
72
+ }
73
+ .nws-layout-tile.nws-layout-adjustX-grow > * {
74
+ width: auto;
75
+ }
76
+ .nws-layout-tile.nws-layout-adjustX-shrink > * {
77
+ width: auto;
78
+ }
79
+ .nws-layout-tile > * {
80
+ min-height: 0;
81
+ }
82
+ .nws-layout-tile.nws-layout-childSizeY > * {
83
+ height: var(--nws-layout-childSizeY);
84
+ }
85
+ .nws-layout-tile.nws-layout-adjustY-fit {
86
+ align-content: stretch;
87
+ }
88
+ .nws-layout-tile.nws-layout-adjustY-fit > * {
89
+ height: auto;
90
+ }
91
+ .nws-layout-tile.nws-layout-adjustY-grow > * {
92
+ max-height: 100%;
93
+ height: 100%;
94
+ }
95
+ .nws-layout-tile.nws-layout-adjustY-grow.nws-layout-childSizeY > * {
96
+ min-height: var(--nws-layout-childSizeY);
97
+ }
98
+ .nws-layout-tile.nws-layout-adjustY-shrink > * {
99
+ min-height: 100%;
100
+ height: 100%;
101
+ }
102
+ .nws-layout-tile.nws-layout-adjustY-shrink.nws-layout-childSizeY > * {
103
+ max-height: var(--nws-layout-childSizeY);
104
+ }
package/tile/tile.cjs ADDED
@@ -0,0 +1,85 @@
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_applyChildSize = require('../_helpers/applyChildSize.cjs');
7
+ const require__helpers_applySpacing = require('../_helpers/applySpacing.cjs');
8
+ const require__helpers_mergeLayoutResults = require('../_helpers/mergeLayoutResults.cjs');
9
+ require('./styles.cjs');
10
+ let _niche_works_utils_object_maybeDefault = require("@niche-works/utils/object/maybeDefault");
11
+ _niche_works_utils_object_maybeDefault = require_runtime.__toESM(_niche_works_utils_object_maybeDefault, 1);
12
+ let clsx = require("clsx");
13
+ clsx = require_runtime.__toESM(clsx, 1);
14
+
15
+ //#region src/tile/tile.ts
16
+ /**
17
+ * tileレイアウト
18
+ *
19
+ * - 子要素の高さ・幅を基準にして格子状に並べる
20
+ * - 親要素のサイズが子要素に依存していないことを前提とする
21
+ */
22
+ const tile = (options = {}) => {
23
+ const { direction, alignX, alignY, adjustX, adjustY, spacing, spacingX, spacingY, childSizeX, childSizeY } = (0, _niche_works_utils_object_maybeDefault.default)(options, {
24
+ direction: "x",
25
+ alignX: "left",
26
+ alignY: "top"
27
+ }, { overwriteNull: true });
28
+ const result = {
29
+ className: (0, clsx.default)(require_constants.clsLayoutTile, require__constants.clsLayoutDirection[direction], require__constants.clsLayoutAlign.x[alignX], require__constants.clsLayoutAlign.y[alignY], require__constants.clsLayoutAdjust.x[adjustX], require__constants.clsLayoutAdjust.y[adjustY]),
30
+ style: {}
31
+ };
32
+ require__helpers_applySpacing(result, spacing, spacingX, spacingY);
33
+ require__helpers_applyChildSize(result, childSizeX, childSizeY);
34
+ return require__helpers_mergeLayoutResults([result, _getLayoutResultByDirection[direction](options)]);
35
+ };
36
+ /**
37
+ * 並べる方向によるスタイル
38
+ */
39
+ const _getLayoutResultByDirection = {
40
+ x: ({ adjustX, adjustY, childSizeX, childSizeY }) => {
41
+ return require__helpers_mergeLayoutResults([_getGridMainAxisTemplate(adjustX, childSizeX, require_constants.varLayoutTemplateX), _getGridClossAxisAuto(adjustY, childSizeY, require_constants.varLayoutAutoTracY)]);
42
+ },
43
+ y: ({ adjustX, adjustY, childSizeY, childSizeX }) => {
44
+ return require__helpers_mergeLayoutResults([_getGridClossAxisAuto(adjustX, childSizeX, require_constants.varLayoutAutoTracX), _getGridMainAxisTemplate(adjustY, childSizeY, require_constants.varLayoutTemplateY)]);
45
+ }
46
+ };
47
+ /**
48
+ * direction方向の子要素のサイズを指定するためのテンプレート
49
+ * @param align 子要素の配置
50
+ * @param childSize 子要素のサイズ
51
+ * @returns
52
+ */
53
+ function _getGridMainAxisTemplate(adjust, childSize, varName) {
54
+ const hasChildSize = require__helpers_hasValue(childSize);
55
+ const style = {};
56
+ if (adjust === "fit") if (hasChildSize) style[varName] = `repeat(auto-fit, minmax(clamp(0px, 100%, ${require__helpers_unit(childSize)}), 1fr))`;
57
+ else style[varName] = "repeat(auto-fit, minmax(0, 1fr))";
58
+ else if (adjust === "grow") if (hasChildSize) style[varName] = `repeat(auto-fit, minmax(${require__helpers_unit(childSize)}, 1fr))`;
59
+ else style[varName] = "repeat(auto-fit, minmax(0, 1fr))";
60
+ else if (adjust === "shrink") if (hasChildSize) style[varName] = `repeat(auto-fit, minmax(0, ${require__helpers_unit(childSize)}))`;
61
+ else style[varName] = "repeat(auto-fit, minmax(0, 1fr))";
62
+ else if (hasChildSize) style[varName] = `repeat(auto-fit, ${require__helpers_unit(childSize)})`;
63
+ else style[varName] = "repeat(auto-fit, minmax(max-content, 100%))";
64
+ return { style };
65
+ }
66
+ /**
67
+ * 交差軸方向
68
+ * @param adjust
69
+ * @param childSize
70
+ * @returns
71
+ */
72
+ function _getGridClossAxisAuto(adjust, childSize, varName) {
73
+ const hasChildSize = require__helpers_hasValue(childSize);
74
+ const style = {};
75
+ if (adjust === "fit") if (hasChildSize) style[varName] = `minmax(0, 100%)`;
76
+ else style[varName] = `minmax(0, 100%)`;
77
+ else if (adjust === "grow") if (hasChildSize) style[varName] = `minmax(${require__helpers_unit(childSize)}, 100%)`;
78
+ else style[varName] = `minmax(auto, 100%)`;
79
+ else if (adjust === "shrink") if (hasChildSize) style[varName] = `minmax(0, ${require__helpers_unit(childSize)})`;
80
+ else style[varName] = `minmax(0, auto)`;
81
+ return { style };
82
+ }
83
+
84
+ //#endregion
85
+ module.exports = tile;
@@ -0,0 +1,12 @@
1
+ import { CreateLayout } from "../types.cjs";
2
+ import { TileLayoutOptions } from "./types.cjs";
3
+
4
+ //#region src/tile/tile.d.ts
5
+ /**
6
+ * tileレイアウト
7
+ *
8
+ * - 子要素の高さ・幅を基準にして格子状に並べる
9
+ * - 親要素のサイズが子要素に依存していないことを前提とする
10
+ */
11
+ declare const tile: CreateLayout<TileLayoutOptions>;
12
+ export = tile;
@@ -0,0 +1,13 @@
1
+ import { CreateLayout } from "../types.mjs";
2
+ import { TileLayoutOptions } from "./types.mjs";
3
+
4
+ //#region src/tile/tile.d.ts
5
+ /**
6
+ * tileレイアウト
7
+ *
8
+ * - 子要素の高さ・幅を基準にして格子状に並べる
9
+ * - 親要素のサイズが子要素に依存していないことを前提とする
10
+ */
11
+ declare const tile: CreateLayout<TileLayoutOptions>;
12
+ //#endregion
13
+ export { tile as default };
package/tile/tile.mjs ADDED
@@ -0,0 +1,82 @@
1
+ import { clsLayoutTile, varLayoutAutoTracX, varLayoutAutoTracY, varLayoutTemplateX, varLayoutTemplateY } from "../constants.mjs";
2
+ import { clsLayoutAdjust, clsLayoutAlign, clsLayoutDirection } from "../_constants.mjs";
3
+ import hasValue from "../_helpers/hasValue.mjs";
4
+ import unit from "../_helpers/unit.mjs";
5
+ import applyChildSize from "../_helpers/applyChildSize.mjs";
6
+ import applySpacing from "../_helpers/applySpacing.mjs";
7
+ import mergeLayoutResults from "../_helpers/mergeLayoutResults.mjs";
8
+ import "./styles.css";
9
+ import maybeDefault from "@niche-works/utils/object/maybeDefault";
10
+ import clsx from "clsx";
11
+
12
+ //#region src/tile/tile.ts
13
+ /**
14
+ * tileレイアウト
15
+ *
16
+ * - 子要素の高さ・幅を基準にして格子状に並べる
17
+ * - 親要素のサイズが子要素に依存していないことを前提とする
18
+ */
19
+ const tile = (options = {}) => {
20
+ const { direction, alignX, alignY, adjustX, adjustY, spacing, spacingX, spacingY, childSizeX, childSizeY } = maybeDefault(options, {
21
+ direction: "x",
22
+ alignX: "left",
23
+ alignY: "top"
24
+ }, { overwriteNull: true });
25
+ const result = {
26
+ className: clsx(clsLayoutTile, clsLayoutDirection[direction], clsLayoutAlign.x[alignX], clsLayoutAlign.y[alignY], clsLayoutAdjust.x[adjustX], clsLayoutAdjust.y[adjustY]),
27
+ style: {}
28
+ };
29
+ applySpacing(result, spacing, spacingX, spacingY);
30
+ applyChildSize(result, childSizeX, childSizeY);
31
+ return mergeLayoutResults([result, _getLayoutResultByDirection[direction](options)]);
32
+ };
33
+ /**
34
+ * 並べる方向によるスタイル
35
+ */
36
+ const _getLayoutResultByDirection = {
37
+ x: ({ adjustX, adjustY, childSizeX, childSizeY }) => {
38
+ return mergeLayoutResults([_getGridMainAxisTemplate(adjustX, childSizeX, varLayoutTemplateX), _getGridClossAxisAuto(adjustY, childSizeY, varLayoutAutoTracY)]);
39
+ },
40
+ y: ({ adjustX, adjustY, childSizeY, childSizeX }) => {
41
+ return mergeLayoutResults([_getGridClossAxisAuto(adjustX, childSizeX, varLayoutAutoTracX), _getGridMainAxisTemplate(adjustY, childSizeY, varLayoutTemplateY)]);
42
+ }
43
+ };
44
+ /**
45
+ * direction方向の子要素のサイズを指定するためのテンプレート
46
+ * @param align 子要素の配置
47
+ * @param childSize 子要素のサイズ
48
+ * @returns
49
+ */
50
+ function _getGridMainAxisTemplate(adjust, childSize, varName) {
51
+ const hasChildSize = hasValue(childSize);
52
+ const style = {};
53
+ if (adjust === "fit") if (hasChildSize) style[varName] = `repeat(auto-fit, minmax(clamp(0px, 100%, ${unit(childSize)}), 1fr))`;
54
+ else style[varName] = "repeat(auto-fit, minmax(0, 1fr))";
55
+ else if (adjust === "grow") if (hasChildSize) style[varName] = `repeat(auto-fit, minmax(${unit(childSize)}, 1fr))`;
56
+ else style[varName] = "repeat(auto-fit, minmax(0, 1fr))";
57
+ else if (adjust === "shrink") if (hasChildSize) style[varName] = `repeat(auto-fit, minmax(0, ${unit(childSize)}))`;
58
+ else style[varName] = "repeat(auto-fit, minmax(0, 1fr))";
59
+ else if (hasChildSize) style[varName] = `repeat(auto-fit, ${unit(childSize)})`;
60
+ else style[varName] = "repeat(auto-fit, minmax(max-content, 100%))";
61
+ return { style };
62
+ }
63
+ /**
64
+ * 交差軸方向
65
+ * @param adjust
66
+ * @param childSize
67
+ * @returns
68
+ */
69
+ function _getGridClossAxisAuto(adjust, childSize, varName) {
70
+ const hasChildSize = hasValue(childSize);
71
+ const style = {};
72
+ if (adjust === "fit") if (hasChildSize) style[varName] = `minmax(0, 100%)`;
73
+ else style[varName] = `minmax(0, 100%)`;
74
+ else if (adjust === "grow") if (hasChildSize) style[varName] = `minmax(${unit(childSize)}, 100%)`;
75
+ else style[varName] = `minmax(auto, 100%)`;
76
+ else if (adjust === "shrink") if (hasChildSize) style[varName] = `minmax(0, ${unit(childSize)})`;
77
+ else style[varName] = `minmax(0, auto)`;
78
+ return { style };
79
+ }
80
+
81
+ //#endregion
82
+ export { tile as default };
package/tile/types.cjs ADDED
File without changes
@@ -0,0 +1,9 @@
1
+ import { AdjustOptions, AlignOptions, ChildSizeOptions, DirectionOptions, SpacingOptions } from "../_types.cjs";
2
+
3
+ //#region src/tile/types.d.ts
4
+ /**
5
+ * tileのオプション
6
+ */
7
+ type TileLayoutOptions = AdjustOptions & AlignOptions & ChildSizeOptions & DirectionOptions & SpacingOptions;
8
+ //#endregion
9
+ export { TileLayoutOptions };
@@ -0,0 +1,9 @@
1
+ import { AdjustOptions, AlignOptions, ChildSizeOptions, DirectionOptions, SpacingOptions } from "../_types.mjs";
2
+
3
+ //#region src/tile/types.d.ts
4
+ /**
5
+ * tileのオプション
6
+ */
7
+ type TileLayoutOptions = AdjustOptions & AlignOptions & ChildSizeOptions & DirectionOptions & SpacingOptions;
8
+ //#endregion
9
+ export { TileLayoutOptions };
package/tile/types.mjs ADDED
@@ -0,0 +1 @@
1
+ export { };
package/types.cjs ADDED
File without changes