You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
30 KiB

1 month ago
  1. {"ast":null,"code":"import createGrid from '../builders/build-grid.mjs';\nimport { DEFAULT_DYNAMIC_LIST_ITEM_SIZE, AUTO_ALIGNMENT, CENTERED_ALIGNMENT, END_ALIGNMENT, START_ALIGNMENT, SMART_ALIGNMENT } from '../defaults.mjs';\nimport { isFunction } from '@vue/shared';\nimport { throwError } from '../../../../utils/error.mjs';\nimport { isNumber, isUndefined } from '../../../../utils/types.mjs';\nconst {\n max,\n min,\n floor\n} = Math;\nconst SCOPE = \"ElDynamicSizeGrid\";\nconst ACCESS_SIZER_KEY_MAP = {\n column: \"columnWidth\",\n row: \"rowHeight\"\n};\nconst ACCESS_LAST_VISITED_KEY_MAP = {\n column: \"lastVisitedColumnIndex\",\n row: \"lastVisitedRowIndex\"\n};\nconst getItemFromCache = (props, index, gridCache, type) => {\n const [cachedItems, sizer, lastVisited] = [gridCache[type], props[ACCESS_SIZER_KEY_MAP[type]], gridCache[ACCESS_LAST_VISITED_KEY_MAP[type]]];\n if (index > lastVisited) {\n let offset = 0;\n if (lastVisited >= 0) {\n const item = cachedItems[lastVisited];\n offset = item.offset + item.size;\n }\n for (let i = lastVisited + 1; i <= index; i++) {\n const size = sizer(i);\n cachedItems[i] = {\n offset,\n size\n };\n offset += size;\n }\n gridCache[ACCESS_LAST_VISITED_KEY_MAP[type]] = index;\n }\n return cachedItems[index];\n};\nconst bs = (props, gridCache, low, high, offset, type) => {\n while (low <= high) {\n const mid = low + floor((high - low) / 2);\n const currentOffset = getItemFromCache(props, mid, gridCache, type).offset;\n if (currentOffset === offset) {\n return mid;\n } else if (currentOffset < offset) {\n low = mid + 1;\n } else {\n high = mid - 1;\n }\n }\n return max(0, low - 1);\n};\nconst es = (props, gridCache, idx, offset, type) => {\n const total = type === \"column\" ? props.totalColumn : props.totalRow;\n let exponent = 1;\n while (idx < total && getItemFromCache(props, idx, gridCache, type).offset < offset) {\n idx += exponent;\n exponent *= 2;\n }\n return bs(props, gridCache, floor(idx / 2), min(idx, total - 1), offset, type);\n};\nconst findItem = (props, gridCache, offset, type) => {\n const [cache, lastVisitedIndex] = [gridCache[type], gridCache[ACCESS_LAST_VISITED_KEY_MAP[type]]];\n const lastVisitedItemOffset = lastVisitedIndex > 0 ? cache[lastVisitedIndex].offset : 0;\n if (lastVisitedItemOffset >= offset) {\n return bs(props, gridCache, 0, lastVisitedIndex, offset, type);\n }\n return es(props, gridCache, max(0, lastVisitedIndex), offset, type);\n};\nconst getEstimatedTotalHeight = ({\n totalRow\n}, {\n estimatedRowHeight,\n lastVisitedRowIndex,\n row\n}) => {\n let sizeOfVisitedRows = 0;\n if (lastVisitedRowIndex >= totalRow) {\n lastVisitedRowIndex = totalRow - 1;\n }\n if (lastVisitedRowIndex >= 0) {\n const item = row[lastVisitedRowIndex];\n sizeOfVisitedRows = item.offset + item.size;\n }\n const unvisitedItems = totalRow - lastVisitedRowIndex - 1;\n const sizeOfUnvisitedItems = unvisitedItems * estimatedRowHeight;\n return sizeOfVisitedRows + sizeOfUnvisitedItems;\n};\nconst getEstimatedTotalWidth = ({\n totalColumn\n}, {\n column,\n estimatedColumnWidth,\n lastVisitedColumnIndex\n}) => {\n let sizeOfVisitedColumns = 0;\n if (lastVisitedColumnIndex > totalColumn) {\n lastVisitedColumnIndex = totalColumn - 1;\n }\n if (lastVisitedColumnIndex >= 0) {\n const item = column[lastVisitedColumnIndex];\n sizeOfVisitedColumns = item.offset + item.size;\n }\n const unvisitedItems = totalColumn - lastVisitedColumnIndex - 1;\n const sizeOfUnvisitedItems = unvisitedItems * estimatedColumnWidth;\n return sizeOfVisitedColumns + sizeOfUnvisitedItems;\n};\nconst ACCESS_ESTIMATED_SIZE_KEY_MAP = {\n column: getEstimatedTotalWidth,\n row: getEstimatedTotalHeight\n};\nconst getOffset = (props, index, alignment, scrollOffset, cache, type, scrollBarWidth) => {\n const [size, estimatedSizeAssociates] = [type === \"row\" ? props.height : props.width, ACCESS_ESTIMATED_SIZE_KEY_MAP[type]];\n const item = getItemFromCa