diff --git a/eh-view-enhance.user.js b/eh-view-enhance.user.js index 9a972f4..a5b5a3e 100644 --- a/eh-view-enhance.user.js +++ b/eh-view-enhance.user.js @@ -2733,6 +2733,7 @@ Report issues here: { const root2 = entries[0]; @@ -7400,21 +7401,14 @@ before contentType: ${contentType}, after contentType: ${blob.type} if (!this.lastRow) this.lastRow = this.createRow(conf.colCount); const lastChild = this.lastRow.lastElementChild; - let isFirst = lastChild === null; if (lastChild) { const nodeWidth = this.lastRow.offsetHeight * (node.ratio ?? 1); const gap = (this.lastRow.childElementCount + 1) * 10; - const ratios = this.childrenRatio(this.lastRow).concat([node.ratio ?? 1]); - const factor = ratios.reduce((prev, curr) => prev * Math.max(1, curr), 1); - if (this.childrenWidth(this.lastRow) + gap + nodeWidth * (0.5 / factor) > this.root.offsetWidth) { - isFirst = true; - this.resizeRow(this.lastRow); - this.lastRow = this.createRow(conf.colCount); - } - } - if (isFirst) { - if ((node.ratio ?? 1) > 1) { - this.lastRow.style.height = this.lastRow.offsetHeight / node.ratio + "px"; + const factor = 0.5 / Math.max(1, node.ratio ?? 1); + if (this.lastRow.childElementCount > 7 || this.childrenWidth(this.lastRow) + gap + nodeWidth * factor > this.root.offsetWidth) { + if (this.resizeRow(this.lastRow, nodeWidth)) { + this.lastRow = this.createRow(conf.colCount); + } } } this.lastRow.appendChild(node.element); @@ -7431,13 +7425,19 @@ before contentType: ${contentType}, after contentType: ${blob.type} row.childNodes.forEach((c) => ret.push(c.offsetWidth / c.offsetHeight)); return ret; } - resizeRow(row) { + resizeRow(row, _nextChildWidth) { + if (row.childElementCount < 4) + return false; + const ratios = this.childrenRatio(row).filter((r) => r >= 1); + if (ratios.length === row.childElementCount && row.childElementCount < 5) + return false; const gap = (row.childElementCount + 1) * 10; const width = this.childrenWidth(row) + gap; const scale = width / this.root.offsetWidth; row.style.height = row.offsetHeight / scale + "px"; row.childNodes.forEach((c) => c.style.marginLeft = ""); row.style.justifyContent = "space-around"; + return true; } nearBottom() { const last = this.lastRow; diff --git a/src/img-node.ts b/src/img-node.ts index e895fbc..fd19df5 100644 --- a/src/img-node.ts +++ b/src/img-node.ts @@ -70,6 +70,7 @@ export default class ImageNode { if (this.rect) { this.canvasElement.width = 1000; this.canvasElement.height = Math.floor(1000 * (this.rect.h / this.rect.w)); + this.canvasSized = true; } this.canvasCtx = this.canvasElement.getContext("2d")!; this.canvasCtx.fillStyle = "#aaa"; diff --git a/src/ui/full-view-grid-manager.ts b/src/ui/full-view-grid-manager.ts index 86e7bc6..4172865 100644 --- a/src/ui/full-view-grid-manager.ts +++ b/src/ui/full-view-grid-manager.ts @@ -169,7 +169,7 @@ class FlowVisionLayout extends Layout { this.root = root; this.root.classList.add("fvg-flow"); this.root.classList.remove("fvg-grid"); - this.defaultHeight = window.screen.availHeight / 3.4; + this.defaultHeight = window.screen.availHeight / 3; this.lastRootWidth = this.root.offsetWidth; this.resizeObserver = new ResizeObserver((entries) => { const root = entries[0]; @@ -194,21 +194,15 @@ class FlowVisionLayout extends Layout { node.element.style.marginLeft = "10px"; if (!this.lastRow) this.lastRow = this.createRow(conf.colCount); const lastChild = this.lastRow.lastElementChild as HTMLElement | null; - let isFirst = lastChild === null; if (lastChild) { const nodeWidth = this.lastRow.offsetHeight * (node.ratio ?? 1); const gap = (this.lastRow.childElementCount + 1) * 10; - const ratios = this.childrenRatio(this.lastRow).concat([node.ratio ?? 1]); - const factor = ratios.reduce((prev, curr) => prev * Math.max(1, curr), 1); - if (this.childrenWidth(this.lastRow) + gap + (nodeWidth * (0.5 / factor)) > this.root.offsetWidth) { - isFirst = true; - this.resizeRow(this.lastRow); - this.lastRow = this.createRow(conf.colCount); - } - } - if (isFirst) { - if ((node.ratio ?? 1) > 1) { - this.lastRow.style.height = this.lastRow.offsetHeight / node.ratio! + "px"; + const factor = 0.5 / Math.max(1, node.ratio ?? 1); + if (this.lastRow.childElementCount > 7 + || this.childrenWidth(this.lastRow) + gap + (nodeWidth * factor) > this.root.offsetWidth) { + if (this.resizeRow(this.lastRow, nodeWidth)) { + this.lastRow = this.createRow(conf.colCount); + } } } this.lastRow.appendChild(node.element); @@ -225,13 +219,19 @@ class FlowVisionLayout extends Layout { row.childNodes.forEach(c => ret.push((c as HTMLElement).offsetWidth / (c as HTMLElement).offsetHeight)); return ret; } - resizeRow(row: HTMLElement) { + resizeRow(row: HTMLElement, _nextChildWidth?: number): boolean { + if (row.childElementCount < 4) return false; + + const ratios = this.childrenRatio(row).filter(r => r >= 1); + if (ratios.length === row.childElementCount && row.childElementCount < 5) return false; + const gap = (row.childElementCount + 1) * 10; const width = this.childrenWidth(row) + gap; const scale = width / this.root.offsetWidth; row.style.height = (row.offsetHeight / scale) + "px"; row.childNodes.forEach(c => (c as HTMLElement).style.marginLeft = ""); row.style.justifyContent = "space-around"; + return true; } nearBottom(): boolean { // return false;