@niche-works/style-layouts 0.2.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 (227) hide show
  1. package/LICENSE +21 -0
  2. package/README.ja.md +320 -0
  3. package/README.md +320 -0
  4. package/_virtual/_rolldown/runtime.cjs +29 -0
  5. package/balance/index.cjs +4 -0
  6. package/balance/index.d.cts +3 -0
  7. package/balance/index.d.mts +3 -0
  8. package/balance/index.mjs +4 -0
  9. package/center/index.cjs +4 -0
  10. package/center/index.d.cts +3 -0
  11. package/center/index.d.mts +3 -0
  12. package/center/index.mjs +4 -0
  13. package/constants.cjs +59 -0
  14. package/constants.d.cts +2 -0
  15. package/constants.d.mts +2 -0
  16. package/constants.mjs +3 -0
  17. package/core/_constants.cjs +94 -0
  18. package/core/_constants.d.cts +83 -0
  19. package/core/_constants.d.mts +83 -0
  20. package/core/_constants.mjs +86 -0
  21. package/core/_internal/applyChildCount.cjs +26 -0
  22. package/core/_internal/applyChildCount.d.cts +11 -0
  23. package/core/_internal/applyChildCount.d.mts +12 -0
  24. package/core/_internal/applyChildCount.mjs +24 -0
  25. package/core/_internal/applyChildRatio.cjs +22 -0
  26. package/core/_internal/applyChildRatio.d.cts +11 -0
  27. package/core/_internal/applyChildRatio.d.mts +12 -0
  28. package/core/_internal/applyChildRatio.mjs +20 -0
  29. package/core/_internal/applyChildSize.cjs +27 -0
  30. package/core/_internal/applyChildSize.d.cts +11 -0
  31. package/core/_internal/applyChildSize.d.mts +12 -0
  32. package/core/_internal/applyChildSize.mjs +25 -0
  33. package/core/_internal/applyGap.cjs +30 -0
  34. package/core/_internal/applyGap.d.cts +12 -0
  35. package/core/_internal/applyGap.d.mts +13 -0
  36. package/core/_internal/applyGap.mjs +28 -0
  37. package/core/_internal/hasValue.cjs +15 -0
  38. package/core/_internal/hasValue.d.cts +8 -0
  39. package/core/_internal/hasValue.d.mts +9 -0
  40. package/core/_internal/hasValue.mjs +14 -0
  41. package/core/_internal/mergeLayoutResults.cjs +18 -0
  42. package/core/_internal/mergeLayoutResults.d.cts +5 -0
  43. package/core/_internal/mergeLayoutResults.d.mts +6 -0
  44. package/core/_internal/mergeLayoutResults.mjs +16 -0
  45. package/core/_internal/unit.cjs +16 -0
  46. package/core/_internal/unit.d.cts +10 -0
  47. package/core/_internal/unit.d.mts +11 -0
  48. package/core/_internal/unit.mjs +15 -0
  49. package/core/_internal/warnIfUnsupported.cjs +15 -0
  50. package/core/_internal/warnIfUnsupported.d.cts +3 -0
  51. package/core/_internal/warnIfUnsupported.d.mts +4 -0
  52. package/core/_internal/warnIfUnsupported.mjs +14 -0
  53. package/core/_styles.scss.cjs +1 -0
  54. package/core/_styles.scss.d.cts +1 -0
  55. package/core/_styles.scss.d.mts +1 -0
  56. package/core/_styles.scss.mjs +3 -0
  57. package/core/_types.cjs +0 -0
  58. package/core/_types.d.cts +123 -0
  59. package/core/_types.d.mts +123 -0
  60. package/core/_types.mjs +1 -0
  61. package/core/balance/balance.cjs +35 -0
  62. package/core/balance/balance.d.cts +11 -0
  63. package/core/balance/balance.d.mts +12 -0
  64. package/core/balance/balance.mjs +32 -0
  65. package/core/balance/index.cjs +3 -0
  66. package/core/balance/index.d.cts +3 -0
  67. package/core/balance/index.d.mts +3 -0
  68. package/core/balance/index.mjs +3 -0
  69. package/core/balance/styles.css +113 -0
  70. package/core/balance/types.cjs +0 -0
  71. package/core/balance/types.d.cts +21 -0
  72. package/core/balance/types.d.mts +21 -0
  73. package/core/balance/types.mjs +1 -0
  74. package/core/center/center.cjs +31 -0
  75. package/core/center/center.d.cts +11 -0
  76. package/core/center/center.d.mts +12 -0
  77. package/core/center/center.mjs +28 -0
  78. package/core/center/index.cjs +3 -0
  79. package/core/center/index.d.cts +3 -0
  80. package/core/center/index.d.mts +3 -0
  81. package/core/center/index.mjs +3 -0
  82. package/core/center/styles.css +166 -0
  83. package/core/center/types.cjs +0 -0
  84. package/core/center/types.d.cts +9 -0
  85. package/core/center/types.d.mts +9 -0
  86. package/core/center/types.mjs +1 -0
  87. package/core/constants.cjs +362 -0
  88. package/core/constants.d.cts +316 -0
  89. package/core/constants.d.mts +316 -0
  90. package/core/constants.mjs +305 -0
  91. package/core/flow/flow.cjs +71 -0
  92. package/core/flow/flow.d.cts +12 -0
  93. package/core/flow/flow.d.mts +13 -0
  94. package/core/flow/flow.mjs +68 -0
  95. package/core/flow/index.cjs +3 -0
  96. package/core/flow/index.d.cts +3 -0
  97. package/core/flow/index.d.mts +3 -0
  98. package/core/flow/index.mjs +3 -0
  99. package/core/flow/styles.css +166 -0
  100. package/core/flow/types.cjs +0 -0
  101. package/core/flow/types.d.cts +21 -0
  102. package/core/flow/types.d.mts +21 -0
  103. package/core/flow/types.mjs +1 -0
  104. package/core/index.cjs +20 -0
  105. package/core/index.d.cts +20 -0
  106. package/core/index.d.mts +20 -0
  107. package/core/index.mjs +11 -0
  108. package/core/layer/index.cjs +3 -0
  109. package/core/layer/index.d.cts +3 -0
  110. package/core/layer/index.d.mts +3 -0
  111. package/core/layer/index.mjs +3 -0
  112. package/core/layer/layer.cjs +34 -0
  113. package/core/layer/layer.d.cts +13 -0
  114. package/core/layer/layer.d.mts +14 -0
  115. package/core/layer/layer.mjs +31 -0
  116. package/core/layer/styles.css +64 -0
  117. package/core/layer/types.cjs +0 -0
  118. package/core/layer/types.d.cts +13 -0
  119. package/core/layer/types.d.mts +13 -0
  120. package/core/layer/types.mjs +1 -0
  121. package/core/matrix/index.cjs +3 -0
  122. package/core/matrix/index.d.cts +3 -0
  123. package/core/matrix/index.d.mts +3 -0
  124. package/core/matrix/index.mjs +3 -0
  125. package/core/matrix/matrix.cjs +110 -0
  126. package/core/matrix/matrix.d.cts +11 -0
  127. package/core/matrix/matrix.d.mts +12 -0
  128. package/core/matrix/matrix.mjs +107 -0
  129. package/core/matrix/styles.css +63 -0
  130. package/core/matrix/types.cjs +0 -0
  131. package/core/matrix/types.d.cts +46 -0
  132. package/core/matrix/types.d.mts +46 -0
  133. package/core/matrix/types.mjs +1 -0
  134. package/core/pack/index.cjs +3 -0
  135. package/core/pack/index.d.cts +3 -0
  136. package/core/pack/index.d.mts +3 -0
  137. package/core/pack/index.mjs +3 -0
  138. package/core/pack/pack.cjs +27 -0
  139. package/core/pack/pack.d.cts +11 -0
  140. package/core/pack/pack.d.mts +12 -0
  141. package/core/pack/pack.mjs +24 -0
  142. package/core/pack/styles.css +36 -0
  143. package/core/pack/types.cjs +0 -0
  144. package/core/pack/types.d.cts +6 -0
  145. package/core/pack/types.d.mts +6 -0
  146. package/core/pack/types.mjs +1 -0
  147. package/core/pin/index.cjs +3 -0
  148. package/core/pin/index.d.cts +3 -0
  149. package/core/pin/index.d.mts +3 -0
  150. package/core/pin/index.mjs +3 -0
  151. package/core/pin/pin.cjs +23 -0
  152. package/core/pin/pin.d.cts +11 -0
  153. package/core/pin/pin.d.mts +12 -0
  154. package/core/pin/pin.mjs +23 -0
  155. package/core/pin/styles.css +18 -0
  156. package/core/pin/types.cjs +0 -0
  157. package/core/pin/types.d.cts +6 -0
  158. package/core/pin/types.d.mts +6 -0
  159. package/core/pin/types.mjs +1 -0
  160. package/core/stack/index.cjs +3 -0
  161. package/core/stack/index.d.cts +3 -0
  162. package/core/stack/index.d.mts +3 -0
  163. package/core/stack/index.mjs +3 -0
  164. package/core/stack/stack.cjs +99 -0
  165. package/core/stack/stack.d.cts +11 -0
  166. package/core/stack/stack.d.mts +12 -0
  167. package/core/stack/stack.mjs +96 -0
  168. package/core/stack/styles.css +175 -0
  169. package/core/stack/types.cjs +0 -0
  170. package/core/stack/types.d.cts +21 -0
  171. package/core/stack/types.d.mts +21 -0
  172. package/core/stack/types.mjs +1 -0
  173. package/core/styles.css +917 -0
  174. package/core/tile/index.cjs +3 -0
  175. package/core/tile/index.d.cts +3 -0
  176. package/core/tile/index.d.mts +3 -0
  177. package/core/tile/index.mjs +3 -0
  178. package/core/tile/styles.css +108 -0
  179. package/core/tile/tile.cjs +86 -0
  180. package/core/tile/tile.d.cts +12 -0
  181. package/core/tile/tile.d.mts +13 -0
  182. package/core/tile/tile.mjs +83 -0
  183. package/core/tile/types.cjs +0 -0
  184. package/core/tile/types.d.cts +9 -0
  185. package/core/tile/types.d.mts +9 -0
  186. package/core/tile/types.mjs +1 -0
  187. package/core/types.cjs +0 -0
  188. package/core/types.d.cts +23 -0
  189. package/core/types.d.mts +23 -0
  190. package/core/types.mjs +1 -0
  191. package/flow/index.cjs +4 -0
  192. package/flow/index.d.cts +3 -0
  193. package/flow/index.d.mts +3 -0
  194. package/flow/index.mjs +4 -0
  195. package/index.cjs +20 -0
  196. package/index.d.cts +20 -0
  197. package/index.d.mts +20 -0
  198. package/index.mjs +11 -0
  199. package/layer/index.cjs +4 -0
  200. package/layer/index.d.cts +3 -0
  201. package/layer/index.d.mts +3 -0
  202. package/layer/index.mjs +4 -0
  203. package/matrix/index.cjs +4 -0
  204. package/matrix/index.d.cts +3 -0
  205. package/matrix/index.d.mts +3 -0
  206. package/matrix/index.mjs +4 -0
  207. package/pack/index.cjs +4 -0
  208. package/pack/index.d.cts +3 -0
  209. package/pack/index.d.mts +3 -0
  210. package/pack/index.mjs +4 -0
  211. package/package.json +51 -0
  212. package/pin/index.cjs +4 -0
  213. package/pin/index.d.cts +3 -0
  214. package/pin/index.d.mts +3 -0
  215. package/pin/index.mjs +4 -0
  216. package/stack/index.cjs +4 -0
  217. package/stack/index.d.cts +3 -0
  218. package/stack/index.d.mts +3 -0
  219. package/stack/index.mjs +4 -0
  220. package/tile/index.cjs +4 -0
  221. package/tile/index.d.cts +3 -0
  222. package/tile/index.d.mts +3 -0
  223. package/tile/index.mjs +4 -0
  224. package/types.cjs +0 -0
  225. package/types.d.cts +2 -0
  226. package/types.d.mts +2 -0
  227. package/types.mjs +1 -0
@@ -0,0 +1,110 @@
1
+ const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
2
+ const require_core_constants = require('../constants.cjs');
3
+ const require_core__constants = require('../_constants.cjs');
4
+ const require_core__internal_hasValue = require('../_internal/hasValue.cjs');
5
+ const require_core__internal_applyChildRatio = require('../_internal/applyChildRatio.cjs');
6
+ const require_core__internal_unit = require('../_internal/unit.cjs');
7
+ const require_core__internal_applyGap = require('../_internal/applyGap.cjs');
8
+ const require_core__internal_mergeLayoutResults = require('../_internal/mergeLayoutResults.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/core/matrix/matrix.ts
15
+ /**
16
+ * matrixレイアウト
17
+ *
18
+ * - 子要素の縦の数、横の数を基準にして格子状に配置する
19
+ */
20
+ const matrix = (options) => {
21
+ const { direction, alignX, alignY, adjustX, adjustY, gap, gapX = gap, gapY = gap, childSizeX, childSizeY, childRatioX, childRatioY, childCountX, childCountY, tracksX, tracksY } = (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_core_constants.clsLayoutMatrix, require_core__constants.clsLayoutDirection[direction], require_core__constants.clsLayoutAlign.x[alignX], require_core__constants.clsLayoutAlign.y[alignY], require_core__constants.clsLayoutAdjust.x[adjustX], require_core__constants.clsLayoutAdjust.y[adjustY]),
28
+ style: {}
29
+ };
30
+ require_core__internal_applyGap(result, gap, gapX, gapY);
31
+ require_core__internal_applyChildRatio(result, childRatioX, childRatioY);
32
+ return require_core__internal_mergeLayoutResults([
33
+ result,
34
+ _getGridTemplate("x", adjustX, childSizeX, childCountX, tracksX),
35
+ _getGridTemplate("y", adjustY, childSizeY, childCountY, tracksY)
36
+ ]);
37
+ };
38
+ /**
39
+ * gridTemplateColumns / gridTemplateRowsを生成する
40
+ * @param axis 軸
41
+ * @param adjust 子要素のサイズ調整
42
+ * @param childSize 子要素のサイズ
43
+ * @param childCount 子要素数
44
+ * @param child 子要素数 & サイズ
45
+ * @returns
46
+ */
47
+ function _getGridTemplate(axis, adjust, childSize, childCount, child) {
48
+ let template;
49
+ if (Array.isArray(child)) {
50
+ const pxTotal = child.reduce((sum, value) => {
51
+ const px = _extractPx(value);
52
+ return px !== null ? sum + px : sum;
53
+ }, 0);
54
+ template = child.map((value) => _applyAdjustToTrack(axis, adjust, value, child.length, pxTotal)).join(" ");
55
+ } else {
56
+ const hasChildSize = require_core__internal_hasValue(childSize);
57
+ const hasCount = require_core__internal_hasValue(childCount);
58
+ if (adjust === "fit") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(clamp(0px, ${`calc((100% - var(${require_core__constants.varLayoutGap[axis]}) * (${childCount} - 1)) / ${childCount})`}, ${require_core__internal_unit(childSize)}), 1fr))`;
59
+ else if (hasChildSize) template = `repeat(auto-fit, minmax(clamp(0px, 100%, ${require_core__internal_unit(childSize)}), 1fr))`;
60
+ else if (hasCount) template = `repeat(${childCount}, 1fr)`;
61
+ else template = "repeat(auto-fit, 1fr)";
62
+ else if (adjust === "grow") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(${require_core__internal_unit(childSize)}, 1fr))`;
63
+ else if (hasChildSize) template = `repeat(auto-fit, minmax(${require_core__internal_unit(childSize)}, 1fr))`;
64
+ else if (hasCount) template = `repeat(${childCount}, 1fr)`;
65
+ else template = "repeat(auto-fit, 1fr)";
66
+ else if (adjust === "shrink") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(0, ${require_core__internal_unit(childSize)}))`;
67
+ else if (hasChildSize) template = `repeat(auto-fit, minmax(0, ${require_core__internal_unit(childSize)}))`;
68
+ else if (hasCount) template = `repeat(${childCount}, auto)`;
69
+ else template = "repeat(auto-fit, auto)";
70
+ else if (hasChildSize && hasCount) template = `repeat(${childCount}, ${require_core__internal_unit(childSize)})`;
71
+ else if (hasChildSize) template = `repeat(auto-fit, ${require_core__internal_unit(childSize)})`;
72
+ else if (hasCount) template = `repeat(${childCount}, auto)`;
73
+ else template = "repeat(auto-fit, auto)";
74
+ }
75
+ return { style: { [require_core__constants.varLayoutTemplate[axis]]: template } };
76
+ }
77
+ /**
78
+ * tracksX/tracksYの各トラック値にadjustを適用する
79
+ * fr単位の値はminmax()のminに使えないため特別扱いになり、
80
+ * 伸縮の比率には影響しない
81
+ */
82
+ function _applyAdjustToTrack(axis, adjust, size, childCount, pxTotal) {
83
+ const childSize = require_core__internal_unit(size);
84
+ const isFr = typeof size === "string" && size.trim().endsWith("fr");
85
+ const pxValue = _extractPx(size);
86
+ const isPx = pxValue !== null;
87
+ if (adjust === "fit") {
88
+ if (isPx && pxTotal > 0) return `minmax(0, max(${`calc((100% - var(${require_core__constants.varLayoutGap[axis]}) * (${childCount} - 1)) * ${pxValue} / ${pxTotal})`}, ${childSize}))`;
89
+ return isFr ? childSize : `minmax(0, ${childSize})`;
90
+ } else if (adjust === "grow") {
91
+ if (isPx && pxTotal > 0) return `minmax(${childSize}, calc(${pxValue} / ${pxTotal} * (100% - var(${require_core__constants.varLayoutGap[axis]}) * (${childCount} - 1))))`;
92
+ return isFr ? childSize : `minmax(${childSize}, 1fr)`;
93
+ } else if (adjust === "shrink") {
94
+ if (isPx && pxTotal > 0) return `minmax(0, min(${`calc((100% - var(${require_core__constants.varLayoutGap[axis]}) * (${childCount} - 1)) * ${pxValue} / ${pxTotal})`}, ${childSize}))`;
95
+ return isFr ? childSize : `minmax(0, ${childSize})`;
96
+ }
97
+ return childSize;
98
+ }
99
+ /**
100
+ * px値を数値として抽出する
101
+ * px以外の単位はnullを返す
102
+ */
103
+ function _extractPx(childSize) {
104
+ if (typeof childSize === "number") return childSize;
105
+ const match = childSize.trim().match(/^([\d.]+)px$/);
106
+ return match ? parseFloat(match[1]) : null;
107
+ }
108
+
109
+ //#endregion
110
+ module.exports = matrix;
@@ -0,0 +1,11 @@
1
+ import { StyleLayout } from "../types.cjs";
2
+ import { MatrixLayoutOptions } from "./types.cjs";
3
+
4
+ //#region src/core/matrix/matrix.d.ts
5
+ /**
6
+ * matrixレイアウト
7
+ *
8
+ * - 子要素の縦の数、横の数を基準にして格子状に配置する
9
+ */
10
+ declare const matrix: StyleLayout<MatrixLayoutOptions>;
11
+ export = matrix;
@@ -0,0 +1,12 @@
1
+ import { StyleLayout } from "../types.mjs";
2
+ import { MatrixLayoutOptions } from "./types.mjs";
3
+
4
+ //#region src/core/matrix/matrix.d.ts
5
+ /**
6
+ * matrixレイアウト
7
+ *
8
+ * - 子要素の縦の数、横の数を基準にして格子状に配置する
9
+ */
10
+ declare const matrix: StyleLayout<MatrixLayoutOptions>;
11
+ //#endregion
12
+ export { matrix as default };
@@ -0,0 +1,107 @@
1
+ import { clsLayoutMatrix } from "../constants.mjs";
2
+ import { clsLayoutAdjust, clsLayoutAlign, clsLayoutDirection, varLayoutGap, varLayoutTemplate } from "../_constants.mjs";
3
+ import hasValue from "../_internal/hasValue.mjs";
4
+ import applyChildRatio from "../_internal/applyChildRatio.mjs";
5
+ import unit from "../_internal/unit.mjs";
6
+ import applyGap from "../_internal/applyGap.mjs";
7
+ import mergeLayoutResults from "../_internal/mergeLayoutResults.mjs";
8
+ import maybeDefault from "@niche-works/utils/object/maybeDefault";
9
+ import clsx from "clsx";
10
+
11
+ //#region src/core/matrix/matrix.ts
12
+ /**
13
+ * matrixレイアウト
14
+ *
15
+ * - 子要素の縦の数、横の数を基準にして格子状に配置する
16
+ */
17
+ const matrix = (options) => {
18
+ const { direction, alignX, alignY, adjustX, adjustY, gap, gapX = gap, gapY = gap, childSizeX, childSizeY, childRatioX, childRatioY, childCountX, childCountY, tracksX, tracksY } = 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
+ applyGap(result, gap, gapX, gapY);
28
+ applyChildRatio(result, childRatioX, childRatioY);
29
+ return mergeLayoutResults([
30
+ result,
31
+ _getGridTemplate("x", adjustX, childSizeX, childCountX, tracksX),
32
+ _getGridTemplate("y", adjustY, childSizeY, childCountY, tracksY)
33
+ ]);
34
+ };
35
+ /**
36
+ * gridTemplateColumns / gridTemplateRowsを生成する
37
+ * @param axis 軸
38
+ * @param adjust 子要素のサイズ調整
39
+ * @param childSize 子要素のサイズ
40
+ * @param childCount 子要素数
41
+ * @param child 子要素数 & サイズ
42
+ * @returns
43
+ */
44
+ function _getGridTemplate(axis, adjust, childSize, childCount, child) {
45
+ let template;
46
+ if (Array.isArray(child)) {
47
+ const pxTotal = child.reduce((sum, value) => {
48
+ const px = _extractPx(value);
49
+ return px !== null ? sum + px : sum;
50
+ }, 0);
51
+ template = child.map((value) => _applyAdjustToTrack(axis, adjust, value, child.length, pxTotal)).join(" ");
52
+ } else {
53
+ const hasChildSize = hasValue(childSize);
54
+ const hasCount = hasValue(childCount);
55
+ if (adjust === "fit") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(clamp(0px, ${`calc((100% - var(${varLayoutGap[axis]}) * (${childCount} - 1)) / ${childCount})`}, ${unit(childSize)}), 1fr))`;
56
+ else if (hasChildSize) template = `repeat(auto-fit, minmax(clamp(0px, 100%, ${unit(childSize)}), 1fr))`;
57
+ else if (hasCount) template = `repeat(${childCount}, 1fr)`;
58
+ else template = "repeat(auto-fit, 1fr)";
59
+ else if (adjust === "grow") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(${unit(childSize)}, 1fr))`;
60
+ else if (hasChildSize) template = `repeat(auto-fit, minmax(${unit(childSize)}, 1fr))`;
61
+ else if (hasCount) template = `repeat(${childCount}, 1fr)`;
62
+ else template = "repeat(auto-fit, 1fr)";
63
+ else if (adjust === "shrink") if (hasChildSize && hasCount) template = `repeat(${childCount}, minmax(0, ${unit(childSize)}))`;
64
+ else if (hasChildSize) template = `repeat(auto-fit, minmax(0, ${unit(childSize)}))`;
65
+ else if (hasCount) template = `repeat(${childCount}, auto)`;
66
+ else template = "repeat(auto-fit, auto)";
67
+ else if (hasChildSize && hasCount) template = `repeat(${childCount}, ${unit(childSize)})`;
68
+ else if (hasChildSize) template = `repeat(auto-fit, ${unit(childSize)})`;
69
+ else if (hasCount) template = `repeat(${childCount}, auto)`;
70
+ else template = "repeat(auto-fit, auto)";
71
+ }
72
+ return { style: { [varLayoutTemplate[axis]]: template } };
73
+ }
74
+ /**
75
+ * tracksX/tracksYの各トラック値にadjustを適用する
76
+ * fr単位の値はminmax()のminに使えないため特別扱いになり、
77
+ * 伸縮の比率には影響しない
78
+ */
79
+ function _applyAdjustToTrack(axis, adjust, size, childCount, pxTotal) {
80
+ const childSize = unit(size);
81
+ const isFr = typeof size === "string" && size.trim().endsWith("fr");
82
+ const pxValue = _extractPx(size);
83
+ const isPx = pxValue !== null;
84
+ if (adjust === "fit") {
85
+ if (isPx && pxTotal > 0) return `minmax(0, max(${`calc((100% - var(${varLayoutGap[axis]}) * (${childCount} - 1)) * ${pxValue} / ${pxTotal})`}, ${childSize}))`;
86
+ return isFr ? childSize : `minmax(0, ${childSize})`;
87
+ } else if (adjust === "grow") {
88
+ if (isPx && pxTotal > 0) return `minmax(${childSize}, calc(${pxValue} / ${pxTotal} * (100% - var(${varLayoutGap[axis]}) * (${childCount} - 1))))`;
89
+ return isFr ? childSize : `minmax(${childSize}, 1fr)`;
90
+ } else if (adjust === "shrink") {
91
+ if (isPx && pxTotal > 0) return `minmax(0, min(${`calc((100% - var(${varLayoutGap[axis]}) * (${childCount} - 1)) * ${pxValue} / ${pxTotal})`}, ${childSize}))`;
92
+ return isFr ? childSize : `minmax(0, ${childSize})`;
93
+ }
94
+ return childSize;
95
+ }
96
+ /**
97
+ * px値を数値として抽出する
98
+ * px以外の単位はnullを返す
99
+ */
100
+ function _extractPx(childSize) {
101
+ if (typeof childSize === "number") return childSize;
102
+ const match = childSize.trim().match(/^([\d.]+)px$/);
103
+ return match ? parseFloat(match[1]) : null;
104
+ }
105
+
106
+ //#endregion
107
+ export { matrix as default };
@@ -0,0 +1,63 @@
1
+ .nws-layout-matrix {
2
+ --nws-layout-gapX: 0px;
3
+ --nws-layout-gapY: 0px;
4
+ --nws-layout-childRatio: auto;
5
+ --nws-layout-templateX: none;
6
+ --nws-layout-templateY: none;
7
+ display: grid;
8
+ }
9
+ .nws-layout-matrix.nws-layout-direction-x {
10
+ grid-auto-flow: row;
11
+ grid-template-columns: var(--nws-layout-templateX);
12
+ grid-template-rows: var(--nws-layout-templateY);
13
+ }
14
+ .nws-layout-matrix.nws-layout-direction-y {
15
+ grid-auto-flow: column;
16
+ grid-template-columns: var(--nws-layout-templateX);
17
+ grid-template-rows: var(--nws-layout-templateY);
18
+ }
19
+ .nws-layout-matrix.nws-layout-alignX-left {
20
+ justify-content: flex-start;
21
+ }
22
+ .nws-layout-matrix.nws-layout-alignX-center {
23
+ justify-content: center;
24
+ }
25
+ .nws-layout-matrix.nws-layout-alignX-right {
26
+ justify-content: flex-end;
27
+ }
28
+ .nws-layout-matrix.nws-layout-alignX-spaceBetween {
29
+ justify-content: space-between;
30
+ }
31
+ .nws-layout-matrix.nws-layout-alignX-spaceAround {
32
+ justify-content: space-around;
33
+ }
34
+ .nws-layout-matrix.nws-layout-alignX-spaceEvenly {
35
+ justify-content: space-evenly;
36
+ }
37
+ .nws-layout-matrix.nws-layout-alignY-top {
38
+ align-content: flex-start;
39
+ }
40
+ .nws-layout-matrix.nws-layout-alignY-middle {
41
+ align-content: center;
42
+ }
43
+ .nws-layout-matrix.nws-layout-alignY-bottom {
44
+ align-content: flex-end;
45
+ }
46
+ .nws-layout-matrix.nws-layout-alignY-spaceBetween {
47
+ align-content: space-between;
48
+ }
49
+ .nws-layout-matrix.nws-layout-alignY-spaceAround {
50
+ align-content: space-around;
51
+ }
52
+ .nws-layout-matrix.nws-layout-alignY-spaceEvenly {
53
+ align-content: space-evenly;
54
+ }
55
+ .nws-layout-matrix.nws-layout-childRatio > * {
56
+ aspect-ratio: var(--nws-layout-childRatio);
57
+ }
58
+ .nws-layout-matrix.nws-layout-gapX {
59
+ column-gap: var(--nws-layout-gapX);
60
+ }
61
+ .nws-layout-matrix.nws-layout-gapY {
62
+ row-gap: var(--nws-layout-gapY);
63
+ }
File without changes
@@ -0,0 +1,46 @@
1
+ import { AdjustOptions, AlignOptions, ChildCountOptions, ChildRatioOptions, ChildSizeOptions, DirectionOptions, GapOptions, TracksOptions } from "../_types.cjs";
2
+
3
+ //#region src/core/matrix/types.d.ts
4
+ type MatrixLayoutOptions = DirectionOptions & AlignOptions & AdjustOptions & ChildRatioOptions & GapOptions & MatrixAxisXOptions & MatrixAxisYOptions;
5
+ /**
6
+ * 横軸、要素数指定
7
+ */
8
+ type MatrixAxisXWithCountOptions = {
9
+ childCountX: ChildCountOptions['childCountX'];
10
+ childSizeX?: ChildSizeOptions['childSizeX'];
11
+ tracksX?: never;
12
+ };
13
+ /**
14
+ * 横軸、テンプレート指定
15
+ */
16
+ type MatrixAxisXWithTemplateOptions = {
17
+ childCountX?: never;
18
+ childSizeX?: never;
19
+ tracksX: TracksOptions['tracksX'];
20
+ };
21
+ /**
22
+ * 横軸用オプション
23
+ */
24
+ type MatrixAxisXOptions = MatrixAxisXWithCountOptions | MatrixAxisXWithTemplateOptions;
25
+ /**
26
+ * 縦軸、要素数指定
27
+ */
28
+ type MatrixAxisYWithCountOptions = {
29
+ childCountY: ChildCountOptions['childCountY'];
30
+ childSizeY?: ChildSizeOptions['childSizeY'];
31
+ tracksY?: never;
32
+ };
33
+ /**
34
+ * 縦軸、テンプレート指定
35
+ */
36
+ type MatrixAxisYWithTemplateOptions = {
37
+ childCountY?: never;
38
+ childSizeY?: never;
39
+ tracksY: TracksOptions['tracksY'];
40
+ };
41
+ /**
42
+ * 縦軸用オプション
43
+ */
44
+ type MatrixAxisYOptions = MatrixAxisYWithCountOptions | MatrixAxisYWithTemplateOptions;
45
+ //#endregion
46
+ export { MatrixLayoutOptions };
@@ -0,0 +1,46 @@
1
+ import { AdjustOptions, AlignOptions, ChildCountOptions, ChildRatioOptions, ChildSizeOptions, DirectionOptions, GapOptions, TracksOptions } from "../_types.mjs";
2
+
3
+ //#region src/core/matrix/types.d.ts
4
+ type MatrixLayoutOptions = DirectionOptions & AlignOptions & AdjustOptions & ChildRatioOptions & GapOptions & MatrixAxisXOptions & MatrixAxisYOptions;
5
+ /**
6
+ * 横軸、要素数指定
7
+ */
8
+ type MatrixAxisXWithCountOptions = {
9
+ childCountX: ChildCountOptions['childCountX'];
10
+ childSizeX?: ChildSizeOptions['childSizeX'];
11
+ tracksX?: never;
12
+ };
13
+ /**
14
+ * 横軸、テンプレート指定
15
+ */
16
+ type MatrixAxisXWithTemplateOptions = {
17
+ childCountX?: never;
18
+ childSizeX?: never;
19
+ tracksX: TracksOptions['tracksX'];
20
+ };
21
+ /**
22
+ * 横軸用オプション
23
+ */
24
+ type MatrixAxisXOptions = MatrixAxisXWithCountOptions | MatrixAxisXWithTemplateOptions;
25
+ /**
26
+ * 縦軸、要素数指定
27
+ */
28
+ type MatrixAxisYWithCountOptions = {
29
+ childCountY: ChildCountOptions['childCountY'];
30
+ childSizeY?: ChildSizeOptions['childSizeY'];
31
+ tracksY?: never;
32
+ };
33
+ /**
34
+ * 縦軸、テンプレート指定
35
+ */
36
+ type MatrixAxisYWithTemplateOptions = {
37
+ childCountY?: never;
38
+ childSizeY?: never;
39
+ tracksY: TracksOptions['tracksY'];
40
+ };
41
+ /**
42
+ * 縦軸用オプション
43
+ */
44
+ type MatrixAxisYOptions = MatrixAxisYWithCountOptions | MatrixAxisYWithTemplateOptions;
45
+ //#endregion
46
+ export { MatrixLayoutOptions };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,3 @@
1
+ const require_core_pack_pack = require('./pack.cjs');
2
+
3
+ module.exports = require_core_pack_pack;
@@ -0,0 +1,3 @@
1
+ import { PackLayoutOptions } from "./types.cjs";
2
+ import pack from "./pack.cjs";
3
+ export { PackLayoutOptions, pack as default };
@@ -0,0 +1,3 @@
1
+ import { PackLayoutOptions } from "./types.mjs";
2
+ import pack from "./pack.mjs";
3
+ export { PackLayoutOptions, pack as default };
@@ -0,0 +1,3 @@
1
+ import pack from "./pack.mjs";
2
+
3
+ export { pack as default };
@@ -0,0 +1,27 @@
1
+ const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
2
+ const require_core_constants = require('../constants.cjs');
3
+ const require_core__constants = require('../_constants.cjs');
4
+ const require_core__internal_applyGap = require('../_internal/applyGap.cjs');
5
+ let _niche_works_utils_object_maybeDefault = require("@niche-works/utils/object/maybeDefault");
6
+ _niche_works_utils_object_maybeDefault = require_runtime.__toESM(_niche_works_utils_object_maybeDefault, 1);
7
+ let clsx = require("clsx");
8
+ clsx = require_runtime.__toESM(clsx, 1);
9
+
10
+ //#region src/core/pack/pack.ts
11
+ /**
12
+ * packレイアウト
13
+ *
14
+ * - 子要素で親要素を満たす
15
+ */
16
+ const pack = (options = {}) => {
17
+ const { direction, gap, gapX, gapY } = (0, _niche_works_utils_object_maybeDefault.default)(options, { direction: "x" }, { overwriteNull: true });
18
+ const result = {
19
+ className: (0, clsx.default)(require_core_constants.clsLayoutPack, require_core__constants.clsLayoutDirection[direction]),
20
+ style: {}
21
+ };
22
+ require_core__internal_applyGap(result, gap, gapX, gapY);
23
+ return result;
24
+ };
25
+
26
+ //#endregion
27
+ module.exports = pack;
@@ -0,0 +1,11 @@
1
+ import { StyleLayout } from "../types.cjs";
2
+ import { PackLayoutOptions } from "./types.cjs";
3
+
4
+ //#region src/core/pack/pack.d.ts
5
+ /**
6
+ * packレイアウト
7
+ *
8
+ * - 子要素で親要素を満たす
9
+ */
10
+ declare const pack: StyleLayout<PackLayoutOptions>;
11
+ export = pack;
@@ -0,0 +1,12 @@
1
+ import { StyleLayout } from "../types.mjs";
2
+ import { PackLayoutOptions } from "./types.mjs";
3
+
4
+ //#region src/core/pack/pack.d.ts
5
+ /**
6
+ * packレイアウト
7
+ *
8
+ * - 子要素で親要素を満たす
9
+ */
10
+ declare const pack: StyleLayout<PackLayoutOptions>;
11
+ //#endregion
12
+ export { pack as default };
@@ -0,0 +1,24 @@
1
+ import { clsLayoutPack } from "../constants.mjs";
2
+ import { clsLayoutDirection } from "../_constants.mjs";
3
+ import applyGap from "../_internal/applyGap.mjs";
4
+ import maybeDefault from "@niche-works/utils/object/maybeDefault";
5
+ import clsx from "clsx";
6
+
7
+ //#region src/core/pack/pack.ts
8
+ /**
9
+ * packレイアウト
10
+ *
11
+ * - 子要素で親要素を満たす
12
+ */
13
+ const pack = (options = {}) => {
14
+ const { direction, gap, gapX, gapY } = maybeDefault(options, { direction: "x" }, { overwriteNull: true });
15
+ const result = {
16
+ className: clsx(clsLayoutPack, clsLayoutDirection[direction]),
17
+ style: {}
18
+ };
19
+ applyGap(result, gap, gapX, gapY);
20
+ return result;
21
+ };
22
+
23
+ //#endregion
24
+ export { pack as default };
@@ -0,0 +1,36 @@
1
+ .nws-layout-pack {
2
+ --nws-layout-gapX: 0px;
3
+ --nws-layout-gapY: 0px;
4
+ --nws-layout-childRatio: auto;
5
+ display: flex;
6
+ justify-content: flex-start;
7
+ align-items: stretch;
8
+ }
9
+ .nws-layout-pack.nws-layout-direction-x {
10
+ flex-direction: row;
11
+ }
12
+ .nws-layout-pack.nws-layout-direction-x > * {
13
+ flex-basis: 0;
14
+ flex-grow: 1;
15
+ flex-shrink: 1;
16
+ min-width: 0;
17
+ min-height: 100%;
18
+ max-height: 100%;
19
+ }
20
+ .nws-layout-pack.nws-layout-direction-y {
21
+ flex-direction: column;
22
+ }
23
+ .nws-layout-pack.nws-layout-direction-y > * {
24
+ flex-basis: 0;
25
+ flex-grow: 1;
26
+ flex-shrink: 1;
27
+ min-height: 0;
28
+ min-width: 100%;
29
+ max-width: 100%;
30
+ }
31
+ .nws-layout-pack.nws-layout-gapX {
32
+ column-gap: var(--nws-layout-gapX);
33
+ }
34
+ .nws-layout-pack.nws-layout-gapY {
35
+ row-gap: var(--nws-layout-gapY);
36
+ }
File without changes
@@ -0,0 +1,6 @@
1
+ import { DirectionOptions, GapOptions } from "../_types.cjs";
2
+
3
+ //#region src/core/pack/types.d.ts
4
+ type PackLayoutOptions = DirectionOptions & GapOptions;
5
+ //#endregion
6
+ export { PackLayoutOptions };
@@ -0,0 +1,6 @@
1
+ import { DirectionOptions, GapOptions } from "../_types.mjs";
2
+
3
+ //#region src/core/pack/types.d.ts
4
+ type PackLayoutOptions = DirectionOptions & GapOptions;
5
+ //#endregion
6
+ export { PackLayoutOptions };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,3 @@
1
+ const require_core_pin_pin = require('./pin.cjs');
2
+
3
+ module.exports = require_core_pin_pin;
@@ -0,0 +1,3 @@
1
+ import { PinLayoutOptions } from "./types.cjs";
2
+ import pin from "./pin.cjs";
3
+ export { PinLayoutOptions, pin as default };
@@ -0,0 +1,3 @@
1
+ import { PinLayoutOptions } from "./types.mjs";
2
+ import pin from "./pin.mjs";
3
+ export { PinLayoutOptions, pin as default };
@@ -0,0 +1,3 @@
1
+ import pin from "./pin.mjs";
2
+
3
+ export { pin as default };
@@ -0,0 +1,23 @@
1
+ const require_core_constants = require('../constants.cjs');
2
+ const require_core__internal_applyChildRatio = require('../_internal/applyChildRatio.cjs');
3
+ const require_core__internal_applyChildSize = require('../_internal/applyChildSize.cjs');
4
+
5
+ //#region src/core/pin/pin.ts
6
+ /**
7
+ * pinレイアウト
8
+ *
9
+ * - 子要素のtop,left,bottom,rightに従い配置する
10
+ */
11
+ const pin = (options = {}) => {
12
+ const { childSizeX, childSizeY, childRatioX, childRatioY } = options;
13
+ const result = {
14
+ className: require_core_constants.clsLayoutPin,
15
+ style: {}
16
+ };
17
+ require_core__internal_applyChildSize(result, childSizeX, childSizeY);
18
+ require_core__internal_applyChildRatio(result, childRatioX, childRatioY);
19
+ return result;
20
+ };
21
+
22
+ //#endregion
23
+ module.exports = pin;
@@ -0,0 +1,11 @@
1
+ import { StyleLayout } from "../types.cjs";
2
+ import { PinLayoutOptions } from "./types.cjs";
3
+
4
+ //#region src/core/pin/pin.d.ts
5
+ /**
6
+ * pinレイアウト
7
+ *
8
+ * - 子要素のtop,left,bottom,rightに従い配置する
9
+ */
10
+ declare const pin: StyleLayout<PinLayoutOptions>;
11
+ export = pin;
@@ -0,0 +1,12 @@
1
+ import { StyleLayout } from "../types.mjs";
2
+ import { PinLayoutOptions } from "./types.mjs";
3
+
4
+ //#region src/core/pin/pin.d.ts
5
+ /**
6
+ * pinレイアウト
7
+ *
8
+ * - 子要素のtop,left,bottom,rightに従い配置する
9
+ */
10
+ declare const pin: StyleLayout<PinLayoutOptions>;
11
+ //#endregion
12
+ export { pin as default };
@@ -0,0 +1,23 @@
1
+ import { clsLayoutPin } from "../constants.mjs";
2
+ import applyChildRatio from "../_internal/applyChildRatio.mjs";
3
+ import applyChildSize from "../_internal/applyChildSize.mjs";
4
+
5
+ //#region src/core/pin/pin.ts
6
+ /**
7
+ * pinレイアウト
8
+ *
9
+ * - 子要素のtop,left,bottom,rightに従い配置する
10
+ */
11
+ const pin = (options = {}) => {
12
+ const { childSizeX, childSizeY, childRatioX, childRatioY } = options;
13
+ const result = {
14
+ className: clsLayoutPin,
15
+ style: {}
16
+ };
17
+ applyChildSize(result, childSizeX, childSizeY);
18
+ applyChildRatio(result, childRatioX, childRatioY);
19
+ return result;
20
+ };
21
+
22
+ //#endregion
23
+ export { pin as default };