@react-spectrum/card 3.0.0-nightly.3066 → 3.0.0-nightly.3074

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -974,84 +974,87 @@ class $22fcfd471bc7ee86$export$8e52095834484b61 extends $ce95ffe2429f6396$export
974
974
  let visibleHeight = this.virtualizer.visibleRect.height;
975
975
  let y = this.margin;
976
976
  let availableWidth = visibleWidth - this.margin * 2;
977
- // Compute aspect ratios for all of the items, and the total width if all items were on in a single row.
978
- let ratios = [];
979
- let totalWidth = 0;
980
- let minRatio = this.minItemSize.width / this.minItemSize.height;
981
- let maxRatio = availableWidth / this.minItemSize.height;
982
- for (let node of this.collection){
983
- let ratio = node.props.width / node.props.height;
984
- if (ratio < minRatio) ratio = minRatio;
985
- else if (ratio > maxRatio && ratio !== minRatio) ratio = maxRatio;
986
- let itemWidth = ratio * this.minItemSize.height;
987
- ratios.push(ratio);
988
- totalWidth += itemWidth;
989
- }
990
- totalWidth += this.itemSpacing.width * (this.collection.size - 1);
991
- // Determine how many rows we'll need, and partition the items into rows
992
- // using the aspect ratios as weights.
993
- let rows = Math.max(1, Math.ceil(totalWidth / availableWidth));
994
- // if the available width can't hold two items, then every item will get its own row
995
- // this leads to a faster run through linear partition and more dependable output for small row widths
996
- if (availableWidth <= this.minItemSize.width * 2 + this.itemPadding * 2) rows = this.collection.size;
997
- let weightedRatios = ratios.map((ratio)=>ratio < this.threshold ? ratio + 0.5 * (1 / ratio) : ratio
998
- );
999
- let partition = $22fcfd471bc7ee86$var$linearPartition(weightedRatios, rows);
1000
- let index = 0;
1001
- for (let row of partition){
1002
- // Compute the total weight for this row
1003
- let totalWeight = 0;
1004
- for(let j = index; j < index + row.length; j++)totalWeight += ratios[j];
1005
- // Determine the row height based on the total available width and weight of this row.
1006
- let bestRowHeight = (availableWidth - (row.length - 1) * this.itemSpacing.width) / totalWeight;
1007
- // if this is the last row and the row height is >2x the ideal row height, then cap to the ideal height
1008
- // probably doing this because if the last row has one extremely tall image, then the row becomes huge
1009
- // though that can happen anywhere if a row has lots of tall images... so i'm not sure why this one matters
1010
- if (row === partition[partition.length - 1] && bestRowHeight > this.idealRowHeight * 2) bestRowHeight = this.idealRowHeight;
1011
- let itemHeight = Math.round(bestRowHeight) + this.itemPadding;
1012
- let x = this.margin;
1013
- // if any items are going to end up too small, add a bit of width to them and subtract it from wider objects
1014
- let widths = [];
1015
- for(let j1 = index; j1 < index + row.length; j1++){
1016
- let width = Math.round(bestRowHeight * ratios[j1]);
1017
- widths.push([
1018
- j1 - index,
1019
- width
1020
- ]);
977
+ // If avaliable width is not greater than 0, skip node layout calculations
978
+ if (availableWidth > 0) {
979
+ // Compute aspect ratios for all of the items, and the total width if all items were on in a single row.
980
+ let ratios = [];
981
+ let totalWidth = 0;
982
+ let minRatio = this.minItemSize.width / this.minItemSize.height;
983
+ let maxRatio = availableWidth / this.minItemSize.height;
984
+ for (let node of this.collection){
985
+ let ratio = node.props.width / node.props.height;
986
+ if (ratio < minRatio) ratio = minRatio;
987
+ else if (ratio > maxRatio && ratio !== minRatio) ratio = maxRatio;
988
+ let itemWidth = ratio * this.minItemSize.height;
989
+ ratios.push(ratio);
990
+ totalWidth += itemWidth;
1021
991
  }
1022
- this._distributeWidths(widths);
1023
- // Create items for this row.
1024
- for(let j2 = index; j2 < index + row.length; j2++){
1025
- let node = this.collection.rows[j2];
1026
- let itemWidth = Math.max(widths[j2 - index][1], this.minItemSize.width);
1027
- let rect = new $k8Xpo$Rect(x, y, itemWidth, itemHeight);
1028
- let layoutInfo = new $k8Xpo$LayoutInfo(node.type, node.key, rect);
1029
- layoutInfo.allowOverflow = true;
1030
- this.layoutInfos.set(node.key, layoutInfo);
1031
- x += itemWidth + this.itemSpacing.width;
992
+ totalWidth += this.itemSpacing.width * (this.collection.size - 1);
993
+ // Determine how many rows we'll need, and partition the items into rows
994
+ // using the aspect ratios as weights.
995
+ let rows = Math.max(1, Math.ceil(totalWidth / availableWidth));
996
+ // if the available width can't hold two items, then every item will get its own row
997
+ // this leads to a faster run through linear partition and more dependable output for small row widths
998
+ if (availableWidth <= this.minItemSize.width * 2 + this.itemPadding * 2) rows = this.collection.size;
999
+ let weightedRatios = ratios.map((ratio)=>ratio < this.threshold ? ratio + 0.5 * (1 / ratio) : ratio
1000
+ );
1001
+ let partition = $22fcfd471bc7ee86$var$linearPartition(weightedRatios, rows);
1002
+ let index = 0;
1003
+ for (let row of partition){
1004
+ // Compute the total weight for this row
1005
+ let totalWeight = 0;
1006
+ for(let j = index; j < index + row.length; j++)totalWeight += ratios[j];
1007
+ // Determine the row height based on the total available width and weight of this row.
1008
+ let bestRowHeight = (availableWidth - (row.length - 1) * this.itemSpacing.width) / totalWeight;
1009
+ // if this is the last row and the row height is >2x the ideal row height, then cap to the ideal height
1010
+ // probably doing this because if the last row has one extremely tall image, then the row becomes huge
1011
+ // though that can happen anywhere if a row has lots of tall images... so i'm not sure why this one matters
1012
+ if (row === partition[partition.length - 1] && bestRowHeight > this.idealRowHeight * 2) bestRowHeight = this.idealRowHeight;
1013
+ let itemHeight = Math.round(bestRowHeight) + this.itemPadding;
1014
+ let x = this.margin;
1015
+ // if any items are going to end up too small, add a bit of width to them and subtract it from wider objects
1016
+ let widths = [];
1017
+ for(let j1 = index; j1 < index + row.length; j1++){
1018
+ let width = Math.round(bestRowHeight * ratios[j1]);
1019
+ widths.push([
1020
+ j1 - index,
1021
+ width
1022
+ ]);
1023
+ }
1024
+ this._distributeWidths(widths);
1025
+ // Create items for this row.
1026
+ for(let j2 = index; j2 < index + row.length; j2++){
1027
+ let node = this.collection.rows[j2];
1028
+ let itemWidth = Math.max(widths[j2 - index][1], this.minItemSize.width);
1029
+ let rect = new $k8Xpo$Rect(x, y, itemWidth, itemHeight);
1030
+ let layoutInfo = new $k8Xpo$LayoutInfo(node.type, node.key, rect);
1031
+ layoutInfo.allowOverflow = true;
1032
+ this.layoutInfos.set(node.key, layoutInfo);
1033
+ x += itemWidth + this.itemSpacing.width;
1034
+ }
1035
+ y += itemHeight + this.itemSpacing.height;
1036
+ index += row.length;
1032
1037
  }
1033
- y += itemHeight + this.itemSpacing.height;
1034
- index += row.length;
1035
- }
1036
- if (this.isLoading) {
1037
- let loaderY = y;
1038
- let loaderHeight = 60;
1039
- // If there aren't any items, make loader take all avaliable room and remove margin from y calculation
1040
- // so it doesn't scroll
1041
- if (this.collection.size === 0) {
1042
- loaderY = 0;
1043
- loaderHeight = visibleHeight || 60;
1038
+ if (this.isLoading) {
1039
+ let loaderY = y;
1040
+ let loaderHeight = 60;
1041
+ // If there aren't any items, make loader take all avaliable room and remove margin from y calculation
1042
+ // so it doesn't scroll
1043
+ if (this.collection.size === 0) {
1044
+ loaderY = 0;
1045
+ loaderHeight = visibleHeight || 60;
1046
+ }
1047
+ let rect = new $k8Xpo$Rect(0, loaderY, visibleWidth, loaderHeight);
1048
+ let loader = new $k8Xpo$LayoutInfo('loader', 'loader', rect);
1049
+ this.layoutInfos.set('loader', loader);
1050
+ y = loader.rect.maxY;
1051
+ }
1052
+ if (this.collection.size === 0 && !this.isLoading) {
1053
+ let rect = new $k8Xpo$Rect(0, 0, visibleWidth, visibleHeight);
1054
+ let placeholder = new $k8Xpo$LayoutInfo('placeholder', 'placeholder', rect);
1055
+ this.layoutInfos.set('placeholder', placeholder);
1056
+ y = placeholder.rect.maxY;
1044
1057
  }
1045
- let rect = new $k8Xpo$Rect(0, loaderY, visibleWidth, loaderHeight);
1046
- let loader = new $k8Xpo$LayoutInfo('loader', 'loader', rect);
1047
- this.layoutInfos.set('loader', loader);
1048
- y = loader.rect.maxY;
1049
- }
1050
- if (this.collection.size === 0 && !this.isLoading) {
1051
- let rect = new $k8Xpo$Rect(0, 0, visibleWidth, visibleHeight);
1052
- let placeholder = new $k8Xpo$LayoutInfo('placeholder', 'placeholder', rect);
1053
- this.layoutInfos.set('placeholder', placeholder);
1054
- y = placeholder.rect.maxY;
1055
1058
  }
1056
1059
  this.contentSize = new $k8Xpo$Size(visibleWidth, y);
1057
1060
  }