(measurementCache)
| 41997 | }; |
| 41998 | }; |
| 41999 | var getNextResizeGroupStateProvider = function(measurementCache) { |
| 42000 | if (measurementCache === void 0) measurementCache = getMeasurementCache(); |
| 42001 | var _measurementCache = measurementCache; |
| 42002 | var _containerDimension; |
| 42003 | /** |
| 42004 | * Gets the width/height of the data rendered in a hidden div. |
| 42005 | * @param measuredData - The data corresponding to the measurement we wish to take. |
| 42006 | * @param getElementToMeasureDimension - A function that returns the measurement of the rendered data. |
| 42007 | * Only called when the measurement is not in the cache. |
| 42008 | */ function _getMeasuredDimension(measuredData, getElementToMeasureDimension) { |
| 42009 | var cachedDimension = _measurementCache.getCachedMeasurement(measuredData); |
| 42010 | if (cachedDimension !== undefined) return cachedDimension; |
| 42011 | var measuredDimension = getElementToMeasureDimension(); |
| 42012 | _measurementCache.addMeasurementToCache(measuredData, measuredDimension); |
| 42013 | return measuredDimension; |
| 42014 | } |
| 42015 | /** |
| 42016 | * Will get the next IResizeGroupState based on the current data while trying to shrink contents |
| 42017 | * to fit in the container. |
| 42018 | * @param data - The initial data point to start measuring. |
| 42019 | * @param onReduceData - Function that transforms the data into something that should render with less width/height. |
| 42020 | * @param getElementToMeasureDimension - A function that returns the measurement of the rendered data. |
| 42021 | * Only called when the measurement is not in the cache. |
| 42022 | */ function _shrinkContentsUntilTheyFit(data, onReduceData, getElementToMeasureDimension) { |
| 42023 | var dataToMeasure = data; |
| 42024 | var measuredDimension = _getMeasuredDimension(data, getElementToMeasureDimension); |
| 42025 | while(measuredDimension > _containerDimension){ |
| 42026 | var nextMeasuredData = onReduceData(dataToMeasure); |
| 42027 | // We don't want to get stuck in an infinite render loop when there are no more |
| 42028 | // scaling steps, so implementations of onReduceData should return undefined when |
| 42029 | // there are no more scaling states to apply. |
| 42030 | if (nextMeasuredData === undefined) return { |
| 42031 | renderedData: dataToMeasure, |
| 42032 | resizeDirection: undefined, |
| 42033 | dataToMeasure: undefined |
| 42034 | }; |
| 42035 | measuredDimension = _measurementCache.getCachedMeasurement(nextMeasuredData); |
| 42036 | // If the measurement isn't in the cache, we need to rerender with some data in a hidden div |
| 42037 | if (measuredDimension === undefined) return { |
| 42038 | dataToMeasure: nextMeasuredData, |
| 42039 | resizeDirection: "shrink" |
| 42040 | }; |
| 42041 | dataToMeasure = nextMeasuredData; |
| 42042 | } |
| 42043 | return { |
| 42044 | renderedData: dataToMeasure, |
| 42045 | resizeDirection: undefined, |
| 42046 | dataToMeasure: undefined |
| 42047 | }; |
| 42048 | } |
| 42049 | /** |
| 42050 | * This function should be called when the state changes in a manner that might allow for more content to fit |
| 42051 | * on the screen, such as the window width/height growing. |
| 42052 | * @param data - The initial data point to start measuring. |
| 42053 | * @param onGrowData - Function that transforms the data into something that may take up more space when rendering. |
| 42054 | * @param getElementToMeasureDimension - A function that returns the measurement of the rendered data. |
| 42055 | * Only called when the measurement is not in the cache. |
| 42056 | */ function _growDataUntilItDoesNotFit(data, onGrowData, getElementToMeasureDimension, onReduceData) { |
no test coverage detected