{"version":3,"file":"FilesSelectionMixin-JLsUiKnU.chunk.mjs","sources":["../src/services/TiledLayout.ts","../src/components/TiledLayout/TiledLayout.vue","../src/components/VirtualScrolling.vue","../src/components/FilesListViewer.vue","../src/mixins/FilesSelectionMixin.ts"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nexport type TiledItem = {\n\tid: string // Unique id for the item.\n\twidth: number // Real width of the item.\n\theight: number // Real height of the item.\n\tratio: number // The aspect ratio of the item.\n}\n\nexport type Section = {\n\tid: string // Unique id for the section.\n\titems: TiledItem[] // Real width of the item.\n}\n\nexport type TiledRow = {\n\titems: TiledItem[] // List of item in the row.\n\theight: number // Height of the row.\n\tkey: string // Unique key for the row.\n}\n\nexport type TiledSection = Section & {\n\tkey: string // Unique key for the section.\n\trows: TiledRow[] // Real width of the item.\n\theight: number // Height of the section.\n}\n\n/**\n * Split items in rows of equal width.\n * The last row will not be forced to match containerWidth.\n *\n * @param items\n * @param containerWidth\n * @param baseHeight\n */\nexport function splitItemsInRows(items: TiledItem[], containerWidth: number, baseHeight: number = 200): TiledRow[] {\n\tif (containerWidth === 0) {\n\t\treturn []\n\t}\n\n\tconst rows: TiledRow[] = []\n\tlet rowNumber = 0\n\tlet currentItem = 0\n\n\twhile (currentItem < items.length) {\n\t\tconst rowItems: TiledItem[] = []\n\n\t\t// Fill the row with new items as long as the width is less than containerWidth.\n\t\tdo {\n\t\t\trowItems.push(items[currentItem++])\n\t\t} while (\n\t\t\tcurrentItem < items.length\n\t\t\t&& computeRowWidth([...rowItems, items[currentItem]], baseHeight) <= containerWidth\n\t\t)\n\n\t\tconst rowHeight = computeRowHeight(\n\t\t\trowItems,\n\t\t\tcontainerWidth,\n\t\t\titems.length === currentItem,\n\t\t\tbaseHeight,\n\t\t)\n\n\t\trows[rowNumber] = {\n\t\t\titems: rowItems.map((item) => ({ ...item, width: rowHeight * item.ratio, height: rowHeight })),\n\t\t\t// Key to help vue to keep track of the row in VirtualScrolling.\n\t\t\theight: rowHeight,\n\t\t\tkey: rowItems.map((item) => item.id).join('-'),\n\t\t}\n\n\t\trowNumber += 1\n\t}\n\n\treturn rows\n}\n\n/**\n *\n * @param items\n * @param baseHeight\n */\nfunction computeRowWidth(items: TiledItem[], baseHeight: number): number {\n\treturn items\n\t\t.map((item) => baseHeight * item.ratio)\n\t\t.reduce((sum, itemWidth) => sum + itemWidth)\n}\n\n/**\n * Compute the row height based on its items and on the container's width.\n *\n * Math time !\n * With Rn the aspect ratio of item n\n * Wn the width of item n\n * Hn the height of item n\n * Wc the width of the container\n * Hr the height of the row\n * For n items we want: Wc = W1 + W2 + ... + Wn\n * We know Rn = Wn / Hn\n * So Wn = Rn * Hn\n * So Wc = (R1 * H1) + (R2 * H2) + ... + (Rn * Hn)\n * But we also want Hr === H1 === H2 === ... === Hn\n * So Wc = (R1 * Hr) + (R2 * Hr) + ... + (Rn * Hr)\n * So Wc = Hr * (R1 + R2 + ... + Rn)\n * So Hr = Wc / (R1 + R2 + ... + Rn)\n *\n * @param items\n * @param containerWidth\n * @param isLastRow\n * @param baseHeight\n */\nfunction computeRowHeight(items: TiledItem[], containerWidth: number, isLastRow: boolean, baseHeight: number): number {\n\tconst sumOfItemsRatio = items\n\t\t.map((item) => item.ratio)\n\t\t.reduce((sum, itemRatio) => sum + itemRatio)\n\n\tlet rowHeight = containerWidth / sumOfItemsRatio\n\n\t// Exception 1: there is only one item which is larger than containerWidth.\n\t// Limit its height so that itemWidth === containerWidth\n\tif (items.length === 1 && items[0].width > containerWidth) {\n\t\trowHeight = containerWidth / items[0].ratio\n\t}\n\n\t// Exception 2: we reached the last row.\n\t// Force the items width to match containerWidth, and limit their height to baseHeight + 20.\n\tif (isLastRow) {\n\t\trowHeight = Math.min(baseHeight + 20, rowHeight)\n\t}\n\n\treturn rowHeight\n}\n","\n\n\t