@react-spectrum/card 3.0.0-alpha.30 → 3.0.0-alpha.32

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 (229) hide show
  1. package/dist/BaseLayout.main.js +218 -0
  2. package/dist/BaseLayout.main.js.map +1 -0
  3. package/dist/BaseLayout.mjs +213 -0
  4. package/dist/BaseLayout.module.js +213 -0
  5. package/dist/BaseLayout.module.js.map +1 -0
  6. package/dist/Card.main.js +51 -0
  7. package/dist/Card.main.js.map +1 -0
  8. package/dist/Card.mjs +42 -0
  9. package/dist/Card.module.js +42 -0
  10. package/dist/Card.module.js.map +1 -0
  11. package/dist/CardBase.main.js +205 -0
  12. package/dist/CardBase.main.js.map +1 -0
  13. package/dist/CardBase.mjs +200 -0
  14. package/dist/CardBase.module.js +200 -0
  15. package/dist/CardBase.module.js.map +1 -0
  16. package/dist/CardView.main.js +232 -0
  17. package/dist/CardView.main.js.map +1 -0
  18. package/dist/CardView.mjs +227 -0
  19. package/dist/CardView.module.js +227 -0
  20. package/dist/CardView.module.js.map +1 -0
  21. package/dist/CardViewContext.main.js +31 -0
  22. package/dist/CardViewContext.main.js.map +1 -0
  23. package/dist/CardViewContext.mjs +21 -0
  24. package/dist/CardViewContext.module.js +21 -0
  25. package/dist/CardViewContext.module.js.map +1 -0
  26. package/dist/GalleryLayout.main.js +229 -0
  27. package/dist/GalleryLayout.main.js.map +1 -0
  28. package/dist/GalleryLayout.mjs +224 -0
  29. package/dist/GalleryLayout.module.js +224 -0
  30. package/dist/GalleryLayout.module.js.map +1 -0
  31. package/dist/GridLayout.main.js +198 -0
  32. package/dist/GridLayout.main.js.map +1 -0
  33. package/dist/GridLayout.mjs +193 -0
  34. package/dist/GridLayout.module.js +193 -0
  35. package/dist/GridLayout.module.js.map +1 -0
  36. package/dist/WaterfallLayout.main.js +181 -0
  37. package/dist/WaterfallLayout.main.js.map +1 -0
  38. package/dist/WaterfallLayout.mjs +176 -0
  39. package/dist/WaterfallLayout.module.js +176 -0
  40. package/dist/WaterfallLayout.module.js.map +1 -0
  41. package/dist/ar-AE.main.js +7 -0
  42. package/dist/ar-AE.main.js.map +1 -0
  43. package/dist/ar-AE.mjs +9 -0
  44. package/dist/ar-AE.module.js +9 -0
  45. package/dist/ar-AE.module.js.map +1 -0
  46. package/dist/bg-BG.main.js +7 -0
  47. package/dist/bg-BG.main.js.map +1 -0
  48. package/dist/bg-BG.mjs +9 -0
  49. package/dist/bg-BG.module.js +9 -0
  50. package/dist/bg-BG.module.js.map +1 -0
  51. package/dist/card_vars_css.main.js +116 -0
  52. package/dist/card_vars_css.main.js.map +1 -0
  53. package/dist/card_vars_css.mjs +118 -0
  54. package/dist/card_vars_css.module.js +118 -0
  55. package/dist/card_vars_css.module.js.map +1 -0
  56. package/dist/cs-CZ.main.js +7 -0
  57. package/dist/cs-CZ.main.js.map +1 -0
  58. package/dist/cs-CZ.mjs +9 -0
  59. package/dist/cs-CZ.module.js +9 -0
  60. package/dist/cs-CZ.module.js.map +1 -0
  61. package/dist/da-DK.main.js +7 -0
  62. package/dist/da-DK.main.js.map +1 -0
  63. package/dist/da-DK.mjs +9 -0
  64. package/dist/da-DK.module.js +9 -0
  65. package/dist/da-DK.module.js.map +1 -0
  66. package/dist/de-DE.main.js +7 -0
  67. package/dist/de-DE.main.js.map +1 -0
  68. package/dist/de-DE.mjs +9 -0
  69. package/dist/de-DE.module.js +9 -0
  70. package/dist/de-DE.module.js.map +1 -0
  71. package/dist/el-GR.main.js +7 -0
  72. package/dist/el-GR.main.js.map +1 -0
  73. package/dist/el-GR.mjs +9 -0
  74. package/dist/el-GR.module.js +9 -0
  75. package/dist/el-GR.module.js.map +1 -0
  76. package/dist/en-US.main.js +7 -0
  77. package/dist/en-US.main.js.map +1 -0
  78. package/dist/en-US.mjs +9 -0
  79. package/dist/en-US.module.js +9 -0
  80. package/dist/en-US.module.js.map +1 -0
  81. package/dist/es-ES.main.js +7 -0
  82. package/dist/es-ES.main.js.map +1 -0
  83. package/dist/es-ES.mjs +9 -0
  84. package/dist/es-ES.module.js +9 -0
  85. package/dist/es-ES.module.js.map +1 -0
  86. package/dist/et-EE.main.js +7 -0
  87. package/dist/et-EE.main.js.map +1 -0
  88. package/dist/et-EE.mjs +9 -0
  89. package/dist/et-EE.module.js +9 -0
  90. package/dist/et-EE.module.js.map +1 -0
  91. package/dist/fi-FI.main.js +7 -0
  92. package/dist/fi-FI.main.js.map +1 -0
  93. package/dist/fi-FI.mjs +9 -0
  94. package/dist/fi-FI.module.js +9 -0
  95. package/dist/fi-FI.module.js.map +1 -0
  96. package/dist/fr-FR.main.js +7 -0
  97. package/dist/fr-FR.main.js.map +1 -0
  98. package/dist/fr-FR.mjs +9 -0
  99. package/dist/fr-FR.module.js +9 -0
  100. package/dist/fr-FR.module.js.map +1 -0
  101. package/dist/he-IL.main.js +7 -0
  102. package/dist/he-IL.main.js.map +1 -0
  103. package/dist/he-IL.mjs +9 -0
  104. package/dist/he-IL.module.js +9 -0
  105. package/dist/he-IL.module.js.map +1 -0
  106. package/dist/hr-HR.main.js +7 -0
  107. package/dist/hr-HR.main.js.map +1 -0
  108. package/dist/hr-HR.mjs +9 -0
  109. package/dist/hr-HR.module.js +9 -0
  110. package/dist/hr-HR.module.js.map +1 -0
  111. package/dist/hu-HU.main.js +7 -0
  112. package/dist/hu-HU.main.js.map +1 -0
  113. package/dist/hu-HU.mjs +9 -0
  114. package/dist/hu-HU.module.js +9 -0
  115. package/dist/hu-HU.module.js.map +1 -0
  116. package/dist/import.mjs +5 -1628
  117. package/dist/intlStrings.main.js +108 -0
  118. package/dist/intlStrings.main.js.map +1 -0
  119. package/dist/intlStrings.mjs +110 -0
  120. package/dist/intlStrings.module.js +110 -0
  121. package/dist/intlStrings.module.js.map +1 -0
  122. package/dist/it-IT.main.js +7 -0
  123. package/dist/it-IT.main.js.map +1 -0
  124. package/dist/it-IT.mjs +9 -0
  125. package/dist/it-IT.module.js +9 -0
  126. package/dist/it-IT.module.js.map +1 -0
  127. package/dist/ja-JP.main.js +7 -0
  128. package/dist/ja-JP.main.js.map +1 -0
  129. package/dist/ja-JP.mjs +9 -0
  130. package/dist/ja-JP.module.js +9 -0
  131. package/dist/ja-JP.module.js.map +1 -0
  132. package/dist/ko-KR.main.js +7 -0
  133. package/dist/ko-KR.main.js.map +1 -0
  134. package/dist/ko-KR.mjs +9 -0
  135. package/dist/ko-KR.module.js +9 -0
  136. package/dist/ko-KR.module.js.map +1 -0
  137. package/dist/lt-LT.main.js +7 -0
  138. package/dist/lt-LT.main.js.map +1 -0
  139. package/dist/lt-LT.mjs +9 -0
  140. package/dist/lt-LT.module.js +9 -0
  141. package/dist/lt-LT.module.js.map +1 -0
  142. package/dist/lv-LV.main.js +7 -0
  143. package/dist/lv-LV.main.js.map +1 -0
  144. package/dist/lv-LV.mjs +9 -0
  145. package/dist/lv-LV.module.js +9 -0
  146. package/dist/lv-LV.module.js.map +1 -0
  147. package/dist/main.js +10 -1629
  148. package/dist/main.js.map +1 -1
  149. package/dist/module.js +5 -1628
  150. package/dist/module.js.map +1 -1
  151. package/dist/nb-NO.main.js +7 -0
  152. package/dist/nb-NO.main.js.map +1 -0
  153. package/dist/nb-NO.mjs +9 -0
  154. package/dist/nb-NO.module.js +9 -0
  155. package/dist/nb-NO.module.js.map +1 -0
  156. package/dist/nl-NL.main.js +7 -0
  157. package/dist/nl-NL.main.js.map +1 -0
  158. package/dist/nl-NL.mjs +9 -0
  159. package/dist/nl-NL.module.js +9 -0
  160. package/dist/nl-NL.module.js.map +1 -0
  161. package/dist/pl-PL.main.js +7 -0
  162. package/dist/pl-PL.main.js.map +1 -0
  163. package/dist/pl-PL.mjs +9 -0
  164. package/dist/pl-PL.module.js +9 -0
  165. package/dist/pl-PL.module.js.map +1 -0
  166. package/dist/pt-BR.main.js +7 -0
  167. package/dist/pt-BR.main.js.map +1 -0
  168. package/dist/pt-BR.mjs +9 -0
  169. package/dist/pt-BR.module.js +9 -0
  170. package/dist/pt-BR.module.js.map +1 -0
  171. package/dist/pt-PT.main.js +7 -0
  172. package/dist/pt-PT.main.js.map +1 -0
  173. package/dist/pt-PT.mjs +9 -0
  174. package/dist/pt-PT.module.js +9 -0
  175. package/dist/pt-PT.module.js.map +1 -0
  176. package/dist/ro-RO.main.js +7 -0
  177. package/dist/ro-RO.main.js.map +1 -0
  178. package/dist/ro-RO.mjs +9 -0
  179. package/dist/ro-RO.module.js +9 -0
  180. package/dist/ro-RO.module.js.map +1 -0
  181. package/dist/ru-RU.main.js +7 -0
  182. package/dist/ru-RU.main.js.map +1 -0
  183. package/dist/ru-RU.mjs +9 -0
  184. package/dist/ru-RU.module.js +9 -0
  185. package/dist/ru-RU.module.js.map +1 -0
  186. package/dist/sk-SK.main.js +7 -0
  187. package/dist/sk-SK.main.js.map +1 -0
  188. package/dist/sk-SK.mjs +9 -0
  189. package/dist/sk-SK.module.js +9 -0
  190. package/dist/sk-SK.module.js.map +1 -0
  191. package/dist/sl-SI.main.js +7 -0
  192. package/dist/sl-SI.main.js.map +1 -0
  193. package/dist/sl-SI.mjs +9 -0
  194. package/dist/sl-SI.module.js +9 -0
  195. package/dist/sl-SI.module.js.map +1 -0
  196. package/dist/sr-SP.main.js +7 -0
  197. package/dist/sr-SP.main.js.map +1 -0
  198. package/dist/sr-SP.mjs +9 -0
  199. package/dist/sr-SP.module.js +9 -0
  200. package/dist/sr-SP.module.js.map +1 -0
  201. package/dist/sv-SE.main.js +7 -0
  202. package/dist/sv-SE.main.js.map +1 -0
  203. package/dist/sv-SE.mjs +9 -0
  204. package/dist/sv-SE.module.js +9 -0
  205. package/dist/sv-SE.module.js.map +1 -0
  206. package/dist/tr-TR.main.js +7 -0
  207. package/dist/tr-TR.main.js.map +1 -0
  208. package/dist/tr-TR.mjs +9 -0
  209. package/dist/tr-TR.module.js +9 -0
  210. package/dist/tr-TR.module.js.map +1 -0
  211. package/dist/uk-UA.main.js +7 -0
  212. package/dist/uk-UA.main.js.map +1 -0
  213. package/dist/uk-UA.mjs +9 -0
  214. package/dist/uk-UA.module.js +9 -0
  215. package/dist/uk-UA.module.js.map +1 -0
  216. package/dist/vars.e5a6cd16.css +1671 -0
  217. package/dist/vars.e5a6cd16.css.map +1 -0
  218. package/dist/zh-CN.main.js +7 -0
  219. package/dist/zh-CN.main.js.map +1 -0
  220. package/dist/zh-CN.mjs +9 -0
  221. package/dist/zh-CN.module.js +9 -0
  222. package/dist/zh-CN.module.js.map +1 -0
  223. package/dist/zh-TW.main.js +7 -0
  224. package/dist/zh-TW.main.js.map +1 -0
  225. package/dist/zh-TW.mjs +9 -0
  226. package/dist/zh-TW.module.js +9 -0
  227. package/dist/zh-TW.module.js.map +1 -0
  228. package/package.json +18 -18
  229. package/dist/main.css +0 -1
@@ -0,0 +1,229 @@
1
+ var $5ee605f09afaa4de$exports = require("./BaseLayout.main.js");
2
+ var $lJHSi$reactstatelyvirtualizer = require("@react-stately/virtualizer");
3
+
4
+
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
+ }
8
+
9
+ $parcel$export(module.exports, "GalleryLayout", () => $8019a3d2c7d098ea$export$8e52095834484b61);
10
+ /*
11
+ * Copyright 2021 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */
21
+
22
+ const $8019a3d2c7d098ea$var$DEFAULT_OPTIONS = {
23
+ S: {
24
+ idealRowHeight: 112,
25
+ minItemSize: new (0, $lJHSi$reactstatelyvirtualizer.Size)(96, 96),
26
+ itemSpacing: new (0, $lJHSi$reactstatelyvirtualizer.Size)(8, 16),
27
+ itemPadding: 24,
28
+ dropSpacing: 50,
29
+ margin: 8
30
+ },
31
+ L: {
32
+ idealRowHeight: 208,
33
+ minItemSize: new (0, $lJHSi$reactstatelyvirtualizer.Size)(136, 136),
34
+ itemSpacing: new (0, $lJHSi$reactstatelyvirtualizer.Size)(18, 18),
35
+ itemPadding: {
36
+ "medium": 78,
37
+ "large": 99
38
+ },
39
+ dropSpacing: 100,
40
+ margin: 24
41
+ }
42
+ };
43
+ class $8019a3d2c7d098ea$export$8e52095834484b61 extends (0, $5ee605f09afaa4de$exports.BaseLayout) {
44
+ get layoutType() {
45
+ return "gallery";
46
+ }
47
+ /**
48
+ * Takes a row of widths and if there are any widths smaller than the min-width, leech width starting from
49
+ * the widest in the row until it can't give anymore, then move to the second widest and so forth.
50
+ * Do this until all assets meet the min-width.
51
+ * */ _distributeWidths(widths) {
52
+ // create a copy of the widths array and sort it largest to smallest
53
+ let sortedWidths = widths.concat().sort((a, b)=>a[1] > b[1] ? -1 : 1);
54
+ for (let width of widths)// for each width, if it's smaller than the min width
55
+ if (width[1] < this.minItemSize.width) {
56
+ // then figure out how much smaller
57
+ let delta = this.minItemSize.width - width[1];
58
+ for (let item of sortedWidths)// go from the largest width in the row to the smallest
59
+ // if the width is greater than the min width
60
+ if (widths[item[0]][1] > this.minItemSize.width) {
61
+ // subtract the delta from the width, if it's still greater than the min width
62
+ // then we have finished, subtract the delta permanently from that width
63
+ // eslint-disable-next-line max-depth
64
+ if (widths[item[0]][1] - delta > this.minItemSize.width) {
65
+ widths[item[0]][1] -= delta;
66
+ delta = 0;
67
+ break;
68
+ } else {
69
+ // otherwise, we take as much as we can from the current width and then move on to
70
+ // the next largest and take some width from it
71
+ let maxChange = widths[item[0]][1] - this.minItemSize.width;
72
+ delta -= maxChange;
73
+ widths[item[0]][1] -= maxChange;
74
+ }
75
+ }
76
+ if (delta > 0) return false;
77
+ // force the width to be the min width that we just rebalanced for
78
+ width[1] = this.minItemSize.width;
79
+ }
80
+ return true;
81
+ }
82
+ buildCollection() {
83
+ let visibleWidth = this.virtualizer.visibleRect.width;
84
+ let visibleHeight = this.virtualizer.visibleRect.height;
85
+ let y = this.margin;
86
+ let availableWidth = visibleWidth - this.margin * 2;
87
+ // If avaliable width is not greater than 0, skip node layout calculations
88
+ if (availableWidth > 0) {
89
+ // Compute aspect ratios for all of the items, and the total width if all items were on in a single row.
90
+ let ratios = [];
91
+ let totalWidth = 0;
92
+ let minRatio = this.minItemSize.width / this.minItemSize.height;
93
+ let maxRatio = availableWidth / this.minItemSize.height;
94
+ for (let node of this.collection){
95
+ let ratio = node.props.width / node.props.height;
96
+ if (ratio < minRatio) ratio = minRatio;
97
+ else if (ratio > maxRatio && ratio !== minRatio) ratio = maxRatio;
98
+ let itemWidth = ratio * this.minItemSize.height;
99
+ ratios.push(ratio);
100
+ totalWidth += itemWidth;
101
+ }
102
+ totalWidth += this.itemSpacing.width * (this.collection.size - 1);
103
+ // Determine how many rows we'll need, and partition the items into rows
104
+ // using the aspect ratios as weights.
105
+ let rows = Math.max(1, Math.ceil(totalWidth / availableWidth));
106
+ // if the available width can't hold two items, then every item will get its own row
107
+ // this leads to a faster run through linear partition and more dependable output for small row widths
108
+ if (availableWidth <= this.minItemSize.width * 2 + this.itemPadding * 2) rows = this.collection.size;
109
+ let weightedRatios = ratios.map((ratio)=>ratio < this.threshold ? ratio + 0.5 * (1 / ratio) : ratio);
110
+ let partition = $8019a3d2c7d098ea$var$linearPartition(weightedRatios, rows);
111
+ let index = 0;
112
+ for (let row of partition){
113
+ // Compute the total weight for this row
114
+ let totalWeight = 0;
115
+ for(let j = index; j < index + row.length; j++)totalWeight += ratios[j];
116
+ // Determine the row height based on the total available width and weight of this row.
117
+ let bestRowHeight = (availableWidth - (row.length - 1) * this.itemSpacing.width) / totalWeight;
118
+ // if this is the last row and the row height is >2x the ideal row height, then cap to the ideal height
119
+ // probably doing this because if the last row has one extremely tall image, then the row becomes huge
120
+ // though that can happen anywhere if a row has lots of tall images... so i'm not sure why this one matters
121
+ if (row === partition[partition.length - 1] && bestRowHeight > this.idealRowHeight * 2) bestRowHeight = this.idealRowHeight;
122
+ let itemHeight = Math.round(bestRowHeight) + this.itemPadding;
123
+ let x = this.margin;
124
+ // if any items are going to end up too small, add a bit of width to them and subtract it from wider objects
125
+ let widths = [];
126
+ for(let j = index; j < index + row.length; j++){
127
+ let width = Math.round(bestRowHeight * ratios[j]);
128
+ widths.push([
129
+ j - index,
130
+ width
131
+ ]);
132
+ }
133
+ this._distributeWidths(widths);
134
+ // Create items for this row.
135
+ for(let j = index; j < index + row.length; j++){
136
+ let node = this.collection.rows[j];
137
+ let itemWidth = Math.max(widths[j - index][1], this.minItemSize.width);
138
+ let rect = new (0, $lJHSi$reactstatelyvirtualizer.Rect)(x, y, itemWidth, itemHeight);
139
+ let layoutInfo = new (0, $lJHSi$reactstatelyvirtualizer.LayoutInfo)(node.type, node.key, rect);
140
+ layoutInfo.allowOverflow = true;
141
+ this.layoutInfos.set(node.key, layoutInfo);
142
+ x += itemWidth + this.itemSpacing.width;
143
+ }
144
+ y += itemHeight + this.itemSpacing.height;
145
+ index += row.length;
146
+ }
147
+ if (this.isLoading) {
148
+ let loaderY = y;
149
+ let loaderHeight = 60;
150
+ // If there aren't any items, make loader take all avaliable room and remove margin from y calculation
151
+ // so it doesn't scroll
152
+ if (this.collection.size === 0) {
153
+ loaderY = 0;
154
+ loaderHeight = visibleHeight || 60;
155
+ }
156
+ let rect = new (0, $lJHSi$reactstatelyvirtualizer.Rect)(0, loaderY, visibleWidth, loaderHeight);
157
+ let loader = new (0, $lJHSi$reactstatelyvirtualizer.LayoutInfo)("loader", "loader", rect);
158
+ this.layoutInfos.set("loader", loader);
159
+ y = loader.rect.maxY;
160
+ }
161
+ if (this.collection.size === 0 && !this.isLoading) {
162
+ let rect = new (0, $lJHSi$reactstatelyvirtualizer.Rect)(0, 0, visibleWidth, visibleHeight);
163
+ let placeholder = new (0, $lJHSi$reactstatelyvirtualizer.LayoutInfo)("placeholder", "placeholder", rect);
164
+ this.layoutInfos.set("placeholder", placeholder);
165
+ y = placeholder.rect.maxY;
166
+ }
167
+ }
168
+ this.contentSize = new (0, $lJHSi$reactstatelyvirtualizer.Size)(visibleWidth, y);
169
+ }
170
+ constructor(options = {}){
171
+ super(options);
172
+ let cardSize = "L";
173
+ this.idealRowHeight = options.idealRowHeight || $8019a3d2c7d098ea$var$DEFAULT_OPTIONS[cardSize].idealRowHeight;
174
+ this.itemSpacing = options.itemSpacing || $8019a3d2c7d098ea$var$DEFAULT_OPTIONS[cardSize].itemSpacing;
175
+ this.itemPadding = options.itemPadding != null ? options.itemPadding : $8019a3d2c7d098ea$var$DEFAULT_OPTIONS[cardSize].itemPadding[this.scale];
176
+ this.minItemSize = options.minItemSize || $8019a3d2c7d098ea$var$DEFAULT_OPTIONS[cardSize].minItemSize;
177
+ this.threshold = options.threshold || 1;
178
+ this.margin = options.margin != null ? options.margin : $8019a3d2c7d098ea$var$DEFAULT_OPTIONS[cardSize].margin;
179
+ }
180
+ }
181
+ // https://www8.cs.umu.se/kurser/TDBA77/VT06/algorithms/BOOK/BOOK2/NODE45.HTM
182
+ function $8019a3d2c7d098ea$var$linearPartition(seq, k) {
183
+ let n = seq.length;
184
+ if (k <= 0) return [];
185
+ if (k >= n) return seq.map((x)=>[
186
+ x
187
+ ]);
188
+ if (n === 1) return [
189
+ seq
190
+ ];
191
+ let table = Array(n).fill(0).map(()=>Array(k).fill(0));
192
+ let solution = Array(n - 1).fill(0).map(()=>Array(k - 1).fill(0));
193
+ for(let i = 0; i < n; i++)table[i][0] = seq[i] + (i > 0 ? table[i - 1][0] : 0);
194
+ for(let i = 0; i < k; i++)table[0][i] = seq[0];
195
+ for(let i = 1; i < n; i++)for(let j = 1; j < k; j++){
196
+ let currentMin = 0;
197
+ let minX = Infinity;
198
+ for(let x = 0; x < i; x++){
199
+ let c1 = table[x][j - 1];
200
+ let c2 = table[i][0] - table[x][0];
201
+ let cost = Math.max(c1, c2);
202
+ if (!x || cost < currentMin) {
203
+ currentMin = cost;
204
+ minX = x;
205
+ }
206
+ }
207
+ table[i][j] = currentMin;
208
+ solution[i - 1][j - 1] = minX;
209
+ }
210
+ n = n - 1;
211
+ k = k - 2;
212
+ let result = [];
213
+ while(k >= 0){
214
+ if (n >= 1) {
215
+ let row = [];
216
+ for(let i = solution[n - 1][k] + 1; i < n + 1; i++)row.push(seq[i]);
217
+ result.unshift(row);
218
+ n = solution[n - 1][k];
219
+ }
220
+ k--;
221
+ }
222
+ let row = [];
223
+ for(let i = 0; i < n + 1; i++)row.push(seq[i]);
224
+ result.unshift(row);
225
+ return result;
226
+ }
227
+
228
+
229
+ //# sourceMappingURL=GalleryLayout.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAsCD,MAAM,wCAAkB;IACtB,GAAG;QACD,gBAAgB;QAChB,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;QAC1B,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,GAAG;QACzB,aAAa;QACb,aAAa;QACb,QAAQ;IACV;IACA,GAAG;QACD,gBAAgB;QAChB,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;QAC3B,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;QAC1B,aAAa;YACX,UAAU;YACV,SAAS;QACX;QACA,aAAa;QACb,QAAQ;IACV;AACF;AAEO,MAAM,kDAAyB,CAAA,GAAA,oCAAS;IAkB7C,IAAI,aAAa;QACf,OAAO;IACT;IAEA;;;;KAIG,GACH,kBAAkB,MAAM,EAAE;QACxB,oEAAoE;QACpE,IAAI,eAAe,OAAO,MAAM,GAAG,IAAI,CAAC,CAAC,GAAG,IAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,KAAK;QACrE,KAAK,IAAI,SAAS,OAChB,qDAAqD;QACrD,IAAI,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,WAAW,CA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,CAAC,KAAK,OAAO,YAAY;gBAC3B,aAAa;gBACb,OAAO;YACT;QACF;QAEA,KAAK,CAAC,EAAE,CAAC,EAAE,GAAG;QACd,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG;IAC3B;IAGF,IAAI,IAAI;IACR,IAAI,IAAI;IAER,IAAI,SAAS,EAAE;IACf,MAAO,KAAK,EAAG;QACb,IAAI,KAAK,GAAG;YACV,IAAI,MAAM,EAAE;YACZ,IAAK,IAAI,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,GAAG,IAAI,IAAI,GAAG,IAC9C,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE;YAGjB,OAAO,OAAO,CAAC;YACf,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE;QACxB;QAEA;IACF;IAEA,IAAI,MAAM,EAAE;IACZ,IAAK,IAAI,IAAI,GAAG,IAAI,IAAI,GAAG,IACzB,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE;IAGjB,OAAO,OAAO,CAAC;IAEf,OAAO;AACT","sources":["packages/@react-spectrum/card/src/GalleryLayout.tsx"],"sourcesContent":["/*\n * Copyright 2021 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {BaseLayout, BaseLayoutOptions} from './BaseLayout';\nimport {LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GalleryLayoutOptions extends BaseLayoutOptions {\n // /**\n // * The card size in the grid.\n // */\n // cardSize?: 'S' | 'M' | 'L',\n /**\n * The the default row height. Note this must be larger than the min item height.\n * @default 208\n */\n idealRowHeight?: number,\n /**\n * The spacing between items.\n * @default 18 x 18\n */\n itemSpacing?: Size,\n /**\n * The vertical padding for an item.\n * @default 78\n */\n itemPadding?: number,\n /**\n * Minimum size for a item in the grid.\n * @default 136 x 136\n */\n minItemSize?: Size,\n /**\n * Target for adding extra weight to elements during linear partitioning. Anything with an aspect ratio smaler than this value\n * will be targeted.\n * @type {number}\n */\n threshold?: number\n}\n\nconst DEFAULT_OPTIONS = {\n S: {\n idealRowHeight: 112,\n minItemSize: new Size(96, 96),\n itemSpacing: new Size(8, 16),\n itemPadding: 24,\n dropSpacing: 50,\n margin: 8\n },\n L: {\n idealRowHeight: 208,\n minItemSize: new Size(136, 136),\n itemSpacing: new Size(18, 18),\n itemPadding: {\n 'medium': 78,\n 'large': 99\n },\n dropSpacing: 100,\n margin: 24\n }\n};\n\nexport class GalleryLayout<T> extends BaseLayout<T> {\n protected idealRowHeight: number;\n protected itemSpacing: Size;\n itemPadding: number;\n protected minItemSize: Size;\n protected threshold: number;\n\n constructor(options: GalleryLayoutOptions = {}) {\n super(options);\n let cardSize = 'L';\n this.idealRowHeight = options.idealRowHeight || DEFAULT_OPTIONS[cardSize].idealRowHeight;\n this.itemSpacing = options.itemSpacing || DEFAULT_OPTIONS[cardSize].itemSpacing;\n this.itemPadding = options.itemPadding != null ? options.itemPadding : DEFAULT_OPTIONS[cardSize].itemPadding[this.scale];\n this.minItemSize = options.minItemSize || DEFAULT_OPTIONS[cardSize].minItemSize;\n this.threshold = options.threshold || 1;\n this.margin = options.margin != null ? options.margin : DEFAULT_OPTIONS[cardSize].margin;\n }\n\n get layoutType() {\n return 'gallery';\n }\n\n /**\n * Takes a row of widths and if there are any widths smaller than the min-width, leech width starting from\n * the widest in the row until it can't give anymore, then move to the second widest and so forth.\n * Do this until all assets meet the min-width.\n * */\n _distributeWidths(widths) {\n // create a copy of the widths array and sort it largest to smallest\n let sortedWidths = widths.concat().sort((a, b) => a[1] > b[1] ? -1 : 1);\n for (let width of widths) {\n // for each width, if it's smaller than the min width\n if (width[1] < this.minItemSize.width) {\n // then figure out how much smaller\n let delta = this.minItemSize.width - width[1];\n for (let item of sortedWidths) {\n // go from the largest width in the row to the smallest\n // if the width is greater than the min width\n if (widths[item[0]][1] > this.minItemSize.width) {\n // subtract the delta from the width, if it's still greater than the min width\n // then we have finished, subtract the delta permanently from that width\n // eslint-disable-next-line max-depth\n if (widths[item[0]][1] - delta > this.minItemSize.width) {\n widths[item[0]][1] -= delta;\n delta = 0;\n break;\n } else {\n // otherwise, we take as much as we can from the current width and then move on to\n // the next largest and take some width from it\n let maxChange = widths[item[0]][1] - this.minItemSize.width;\n delta -= maxChange;\n widths[item[0]][1] -= maxChange;\n }\n }\n }\n if (delta > 0) {\n return false;\n }\n // force the width to be the min width that we just rebalanced for\n width[1] = this.minItemSize.width;\n }\n }\n return true;\n }\n\n buildCollection() {\n let visibleWidth = this.virtualizer.visibleRect.width;\n let visibleHeight = this.virtualizer.visibleRect.height;\n let y = this.margin;\n let availableWidth = visibleWidth - this.margin * 2;\n\n // If avaliable width is not greater than 0, skip node layout calculations\n if (availableWidth > 0) {\n // Compute aspect ratios for all of the items, and the total width if all items were on in a single row.\n let ratios = [];\n let totalWidth = 0;\n let minRatio = this.minItemSize.width / this.minItemSize.height;\n let maxRatio = availableWidth / this.minItemSize.height;\n\n for (let node of this.collection) {\n let ratio = node.props.width / node.props.height;\n if (ratio < minRatio) {\n ratio = minRatio;\n } else if (ratio > maxRatio && ratio !== minRatio) {\n ratio = maxRatio;\n }\n\n let itemWidth = ratio * this.minItemSize.height;\n ratios.push(ratio);\n totalWidth += itemWidth;\n }\n\n totalWidth += this.itemSpacing.width * (this.collection.size - 1);\n\n // Determine how many rows we'll need, and partition the items into rows\n // using the aspect ratios as weights.\n let rows = Math.max(1, Math.ceil(totalWidth / availableWidth));\n // if the available width can't hold two items, then every item will get its own row\n // this leads to a faster run through linear partition and more dependable output for small row widths\n if (availableWidth <= (this.minItemSize.width * 2) + (this.itemPadding * 2)) {\n rows = this.collection.size;\n }\n\n let weightedRatios = ratios.map(ratio => ratio < this.threshold ? ratio + (0.5 * (1 / ratio)) : ratio);\n let partition = linearPartition(weightedRatios, rows);\n\n let index = 0;\n for (let row of partition) {\n // Compute the total weight for this row\n let totalWeight = 0;\n for (let j = index; j < index + row.length; j++) {\n totalWeight += ratios[j];\n }\n\n // Determine the row height based on the total available width and weight of this row.\n let bestRowHeight = (availableWidth - (row.length - 1) * this.itemSpacing.width) / totalWeight;\n\n // if this is the last row and the row height is >2x the ideal row height, then cap to the ideal height\n // probably doing this because if the last row has one extremely tall image, then the row becomes huge\n // though that can happen anywhere if a row has lots of tall images... so i'm not sure why this one matters\n if (row === partition[partition.length - 1] && bestRowHeight > this.idealRowHeight * 2) {\n bestRowHeight = this.idealRowHeight;\n }\n let itemHeight = Math.round(bestRowHeight) + this.itemPadding;\n let x = this.margin;\n\n // if any items are going to end up too small, add a bit of width to them and subtract it from wider objects\n let widths = [];\n for (let j = index; j < index + row.length; j++) {\n let width = Math.round(bestRowHeight * ratios[j]);\n widths.push([j - index, width]);\n }\n this._distributeWidths(widths);\n\n // Create items for this row.\n for (let j = index; j < index + row.length; j++) {\n let node = this.collection.rows[j];\n let itemWidth = Math.max(widths[j - index][1], this.minItemSize.width);\n let rect = new Rect(x, y, itemWidth, itemHeight);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n layoutInfo.allowOverflow = true;\n this.layoutInfos.set(node.key, layoutInfo);\n x += itemWidth + this.itemSpacing.width;\n }\n\n y += itemHeight + this.itemSpacing.height;\n index += row.length;\n }\n\n if (this.isLoading) {\n let loaderY = y;\n let loaderHeight = 60;\n // If there aren't any items, make loader take all avaliable room and remove margin from y calculation\n // so it doesn't scroll\n if (this.collection.size === 0) {\n loaderY = 0;\n loaderHeight = visibleHeight || 60;\n }\n\n let rect = new Rect(0, loaderY, visibleWidth, loaderHeight);\n let loader = new LayoutInfo('loader', 'loader', rect);\n this.layoutInfos.set('loader', loader);\n y = loader.rect.maxY;\n }\n\n if (this.collection.size === 0 && !this.isLoading) {\n let rect = new Rect(0, 0, visibleWidth, visibleHeight);\n let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);\n this.layoutInfos.set('placeholder', placeholder);\n y = placeholder.rect.maxY;\n }\n }\n this.contentSize = new Size(visibleWidth, y);\n }\n}\n\n// https://www8.cs.umu.se/kurser/TDBA77/VT06/algorithms/BOOK/BOOK2/NODE45.HTM\nfunction linearPartition(seq, k) {\n let n = seq.length;\n if (k <= 0) {\n return [];\n }\n\n if (k >= n) {\n return seq.map(x => [x]);\n }\n\n if (n === 1) {\n return [seq];\n }\n\n let table = Array(n).fill(0).map(() => Array(k).fill(0));\n let solution = Array(n - 1).fill(0).map(() => Array(k - 1).fill(0));\n\n for (let i = 0; i < n; i++) {\n table[i][0] = seq[i] + (i > 0 ? table[i - 1][0] : 0);\n }\n\n for (let i = 0; i < k; i++) {\n table[0][i] = seq[0];\n }\n\n for (let i = 1; i < n; i++) {\n for (let j = 1; j < k; j++) {\n let currentMin = 0;\n let minX = Infinity;\n\n for (let x = 0; x < i; x++) {\n let c1 = table[x][j - 1];\n let c2 = table[i][0] - table[x][0];\n let cost = Math.max(c1, c2);\n\n if (!x || cost < currentMin) {\n currentMin = cost;\n minX = x;\n }\n }\n\n table[i][j] = currentMin;\n solution[i - 1][j - 1] = minX;\n }\n }\n\n n = n - 1;\n k = k - 2;\n\n let result = [];\n while (k >= 0) {\n if (n >= 1) {\n let row = [];\n for (let i = solution[n - 1][k] + 1; i < n + 1; i++) {\n row.push(seq[i]);\n }\n\n result.unshift(row);\n n = solution[n - 1][k];\n }\n\n k--;\n }\n\n let row = [];\n for (let i = 0; i < n + 1; i++) {\n row.push(seq[i]);\n }\n\n result.unshift(row);\n\n return result;\n}\n"],"names":[],"version":3,"file":"GalleryLayout.main.js.map"}
@@ -0,0 +1,224 @@
1
+ import {BaseLayout as $3d424c147206bac9$export$64943d2e59d72a29} from "./BaseLayout.mjs";
2
+ import {Size as $lQvIB$Size, Rect as $lQvIB$Rect, LayoutInfo as $lQvIB$LayoutInfo} from "@react-stately/virtualizer";
3
+
4
+ /*
5
+ * Copyright 2021 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ const $c0ba81539c443916$var$DEFAULT_OPTIONS = {
17
+ S: {
18
+ idealRowHeight: 112,
19
+ minItemSize: new (0, $lQvIB$Size)(96, 96),
20
+ itemSpacing: new (0, $lQvIB$Size)(8, 16),
21
+ itemPadding: 24,
22
+ dropSpacing: 50,
23
+ margin: 8
24
+ },
25
+ L: {
26
+ idealRowHeight: 208,
27
+ minItemSize: new (0, $lQvIB$Size)(136, 136),
28
+ itemSpacing: new (0, $lQvIB$Size)(18, 18),
29
+ itemPadding: {
30
+ "medium": 78,
31
+ "large": 99
32
+ },
33
+ dropSpacing: 100,
34
+ margin: 24
35
+ }
36
+ };
37
+ class $c0ba81539c443916$export$8e52095834484b61 extends (0, $3d424c147206bac9$export$64943d2e59d72a29) {
38
+ get layoutType() {
39
+ return "gallery";
40
+ }
41
+ /**
42
+ * Takes a row of widths and if there are any widths smaller than the min-width, leech width starting from
43
+ * the widest in the row until it can't give anymore, then move to the second widest and so forth.
44
+ * Do this until all assets meet the min-width.
45
+ * */ _distributeWidths(widths) {
46
+ // create a copy of the widths array and sort it largest to smallest
47
+ let sortedWidths = widths.concat().sort((a, b)=>a[1] > b[1] ? -1 : 1);
48
+ for (let width of widths)// for each width, if it's smaller than the min width
49
+ if (width[1] < this.minItemSize.width) {
50
+ // then figure out how much smaller
51
+ let delta = this.minItemSize.width - width[1];
52
+ for (let item of sortedWidths)// go from the largest width in the row to the smallest
53
+ // if the width is greater than the min width
54
+ if (widths[item[0]][1] > this.minItemSize.width) {
55
+ // subtract the delta from the width, if it's still greater than the min width
56
+ // then we have finished, subtract the delta permanently from that width
57
+ // eslint-disable-next-line max-depth
58
+ if (widths[item[0]][1] - delta > this.minItemSize.width) {
59
+ widths[item[0]][1] -= delta;
60
+ delta = 0;
61
+ break;
62
+ } else {
63
+ // otherwise, we take as much as we can from the current width and then move on to
64
+ // the next largest and take some width from it
65
+ let maxChange = widths[item[0]][1] - this.minItemSize.width;
66
+ delta -= maxChange;
67
+ widths[item[0]][1] -= maxChange;
68
+ }
69
+ }
70
+ if (delta > 0) return false;
71
+ // force the width to be the min width that we just rebalanced for
72
+ width[1] = this.minItemSize.width;
73
+ }
74
+ return true;
75
+ }
76
+ buildCollection() {
77
+ let visibleWidth = this.virtualizer.visibleRect.width;
78
+ let visibleHeight = this.virtualizer.visibleRect.height;
79
+ let y = this.margin;
80
+ let availableWidth = visibleWidth - this.margin * 2;
81
+ // If avaliable width is not greater than 0, skip node layout calculations
82
+ if (availableWidth > 0) {
83
+ // Compute aspect ratios for all of the items, and the total width if all items were on in a single row.
84
+ let ratios = [];
85
+ let totalWidth = 0;
86
+ let minRatio = this.minItemSize.width / this.minItemSize.height;
87
+ let maxRatio = availableWidth / this.minItemSize.height;
88
+ for (let node of this.collection){
89
+ let ratio = node.props.width / node.props.height;
90
+ if (ratio < minRatio) ratio = minRatio;
91
+ else if (ratio > maxRatio && ratio !== minRatio) ratio = maxRatio;
92
+ let itemWidth = ratio * this.minItemSize.height;
93
+ ratios.push(ratio);
94
+ totalWidth += itemWidth;
95
+ }
96
+ totalWidth += this.itemSpacing.width * (this.collection.size - 1);
97
+ // Determine how many rows we'll need, and partition the items into rows
98
+ // using the aspect ratios as weights.
99
+ let rows = Math.max(1, Math.ceil(totalWidth / availableWidth));
100
+ // if the available width can't hold two items, then every item will get its own row
101
+ // this leads to a faster run through linear partition and more dependable output for small row widths
102
+ if (availableWidth <= this.minItemSize.width * 2 + this.itemPadding * 2) rows = this.collection.size;
103
+ let weightedRatios = ratios.map((ratio)=>ratio < this.threshold ? ratio + 0.5 * (1 / ratio) : ratio);
104
+ let partition = $c0ba81539c443916$var$linearPartition(weightedRatios, rows);
105
+ let index = 0;
106
+ for (let row of partition){
107
+ // Compute the total weight for this row
108
+ let totalWeight = 0;
109
+ for(let j = index; j < index + row.length; j++)totalWeight += ratios[j];
110
+ // Determine the row height based on the total available width and weight of this row.
111
+ let bestRowHeight = (availableWidth - (row.length - 1) * this.itemSpacing.width) / totalWeight;
112
+ // if this is the last row and the row height is >2x the ideal row height, then cap to the ideal height
113
+ // probably doing this because if the last row has one extremely tall image, then the row becomes huge
114
+ // though that can happen anywhere if a row has lots of tall images... so i'm not sure why this one matters
115
+ if (row === partition[partition.length - 1] && bestRowHeight > this.idealRowHeight * 2) bestRowHeight = this.idealRowHeight;
116
+ let itemHeight = Math.round(bestRowHeight) + this.itemPadding;
117
+ let x = this.margin;
118
+ // if any items are going to end up too small, add a bit of width to them and subtract it from wider objects
119
+ let widths = [];
120
+ for(let j = index; j < index + row.length; j++){
121
+ let width = Math.round(bestRowHeight * ratios[j]);
122
+ widths.push([
123
+ j - index,
124
+ width
125
+ ]);
126
+ }
127
+ this._distributeWidths(widths);
128
+ // Create items for this row.
129
+ for(let j = index; j < index + row.length; j++){
130
+ let node = this.collection.rows[j];
131
+ let itemWidth = Math.max(widths[j - index][1], this.minItemSize.width);
132
+ let rect = new (0, $lQvIB$Rect)(x, y, itemWidth, itemHeight);
133
+ let layoutInfo = new (0, $lQvIB$LayoutInfo)(node.type, node.key, rect);
134
+ layoutInfo.allowOverflow = true;
135
+ this.layoutInfos.set(node.key, layoutInfo);
136
+ x += itemWidth + this.itemSpacing.width;
137
+ }
138
+ y += itemHeight + this.itemSpacing.height;
139
+ index += row.length;
140
+ }
141
+ if (this.isLoading) {
142
+ let loaderY = y;
143
+ let loaderHeight = 60;
144
+ // If there aren't any items, make loader take all avaliable room and remove margin from y calculation
145
+ // so it doesn't scroll
146
+ if (this.collection.size === 0) {
147
+ loaderY = 0;
148
+ loaderHeight = visibleHeight || 60;
149
+ }
150
+ let rect = new (0, $lQvIB$Rect)(0, loaderY, visibleWidth, loaderHeight);
151
+ let loader = new (0, $lQvIB$LayoutInfo)("loader", "loader", rect);
152
+ this.layoutInfos.set("loader", loader);
153
+ y = loader.rect.maxY;
154
+ }
155
+ if (this.collection.size === 0 && !this.isLoading) {
156
+ let rect = new (0, $lQvIB$Rect)(0, 0, visibleWidth, visibleHeight);
157
+ let placeholder = new (0, $lQvIB$LayoutInfo)("placeholder", "placeholder", rect);
158
+ this.layoutInfos.set("placeholder", placeholder);
159
+ y = placeholder.rect.maxY;
160
+ }
161
+ }
162
+ this.contentSize = new (0, $lQvIB$Size)(visibleWidth, y);
163
+ }
164
+ constructor(options = {}){
165
+ super(options);
166
+ let cardSize = "L";
167
+ this.idealRowHeight = options.idealRowHeight || $c0ba81539c443916$var$DEFAULT_OPTIONS[cardSize].idealRowHeight;
168
+ this.itemSpacing = options.itemSpacing || $c0ba81539c443916$var$DEFAULT_OPTIONS[cardSize].itemSpacing;
169
+ this.itemPadding = options.itemPadding != null ? options.itemPadding : $c0ba81539c443916$var$DEFAULT_OPTIONS[cardSize].itemPadding[this.scale];
170
+ this.minItemSize = options.minItemSize || $c0ba81539c443916$var$DEFAULT_OPTIONS[cardSize].minItemSize;
171
+ this.threshold = options.threshold || 1;
172
+ this.margin = options.margin != null ? options.margin : $c0ba81539c443916$var$DEFAULT_OPTIONS[cardSize].margin;
173
+ }
174
+ }
175
+ // https://www8.cs.umu.se/kurser/TDBA77/VT06/algorithms/BOOK/BOOK2/NODE45.HTM
176
+ function $c0ba81539c443916$var$linearPartition(seq, k) {
177
+ let n = seq.length;
178
+ if (k <= 0) return [];
179
+ if (k >= n) return seq.map((x)=>[
180
+ x
181
+ ]);
182
+ if (n === 1) return [
183
+ seq
184
+ ];
185
+ let table = Array(n).fill(0).map(()=>Array(k).fill(0));
186
+ let solution = Array(n - 1).fill(0).map(()=>Array(k - 1).fill(0));
187
+ for(let i = 0; i < n; i++)table[i][0] = seq[i] + (i > 0 ? table[i - 1][0] : 0);
188
+ for(let i = 0; i < k; i++)table[0][i] = seq[0];
189
+ for(let i = 1; i < n; i++)for(let j = 1; j < k; j++){
190
+ let currentMin = 0;
191
+ let minX = Infinity;
192
+ for(let x = 0; x < i; x++){
193
+ let c1 = table[x][j - 1];
194
+ let c2 = table[i][0] - table[x][0];
195
+ let cost = Math.max(c1, c2);
196
+ if (!x || cost < currentMin) {
197
+ currentMin = cost;
198
+ minX = x;
199
+ }
200
+ }
201
+ table[i][j] = currentMin;
202
+ solution[i - 1][j - 1] = minX;
203
+ }
204
+ n = n - 1;
205
+ k = k - 2;
206
+ let result = [];
207
+ while(k >= 0){
208
+ if (n >= 1) {
209
+ let row = [];
210
+ for(let i = solution[n - 1][k] + 1; i < n + 1; i++)row.push(seq[i]);
211
+ result.unshift(row);
212
+ n = solution[n - 1][k];
213
+ }
214
+ k--;
215
+ }
216
+ let row = [];
217
+ for(let i = 0; i < n + 1; i++)row.push(seq[i]);
218
+ result.unshift(row);
219
+ return result;
220
+ }
221
+
222
+
223
+ export {$c0ba81539c443916$export$8e52095834484b61 as GalleryLayout};
224
+ //# sourceMappingURL=GalleryLayout.mjs.map