Update app.js
Browse files
app.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
| 1 |
-
// ==========================================================================
|
| 2 |
-
// 📝 TODO (Architecture / Enhancements)
|
| 3 |
-
// ==========================================================================
|
| 4 |
-
// 1. [Prompt Presets] 实现基于 ID 的 Prompt 远程动态加载
|
| 5 |
-
// - 方案:将超长 Prompt 抽离为集中的 JSON 文件(如: prompt-assets/presets.json)。
|
| 6 |
-
// - 逻辑:图库 (Gallery) 跳转时仅传递 ?id=xxx,前端 (Studio) 接收到 ID 后,跨域 fetch 该 JSON 并自动填充 Prompt 输入框。
|
| 7 |
-
// - 优点:彻底解决 URL 长度限制,实现前后端数据彻底解耦,方便统一维护。
|
| 8 |
-
// commit@70f742a386b9cbbfd6df774b19d727485ef5446f
|
| 9 |
-
|
| 10 |
|
|
|
|
| 11 |
// ==========================================================================
|
| 12 |
// 🛡️ Dynamic API Base URL
|
| 13 |
// ==========================================================================
|
|
@@ -1304,13 +1296,9 @@ async function loadInitialData() {
|
|
| 1304 |
applyPresetForDeepLink(targetItem, targetModel);
|
| 1305 |
}
|
| 1306 |
|
| 1307 |
-
|
| 1308 |
-
|
| 1309 |
-
|
| 1310 |
-
console.log(`🟢 [Init] 执行滚动定位`);
|
| 1311 |
-
targetCard.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
| 1312 |
-
}
|
| 1313 |
-
}, 150);
|
| 1314 |
|
| 1315 |
} else {
|
| 1316 |
console.warn(`⚠️ [Init] 在返回的数据中不存在该 LoRA: ${loraParam}`);
|
|
@@ -1663,6 +1651,82 @@ document.getElementById("char-enable").addEventListener("change", (e) => {
|
|
| 1663 |
if (strengthEl) strengthEl.disabled = !on;
|
| 1664 |
});
|
| 1665 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1666 |
function loadMoreCards() {
|
| 1667 |
const grid = document.getElementById('gallery-grid');
|
| 1668 |
const nextBatch = currentGalleryData.slice(renderedCount, renderedCount + BATCH_SIZE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
+
// commit@70f742a386b9cbbfd6df774b19d727485ef5446f
|
| 3 |
// ==========================================================================
|
| 4 |
// 🛡️ Dynamic API Base URL
|
| 5 |
// ==========================================================================
|
|
|
|
| 1296 |
applyPresetForDeepLink(targetItem, targetModel);
|
| 1297 |
}
|
| 1298 |
|
| 1299 |
+
// 🎯 深链滚动定位:hidden tab(右键新标签打开)下 smooth 滚动会被丢弃,
|
| 1300 |
+
// 交给带可见性判断 + 几何校验 + 重试的 focusCardInGallery
|
| 1301 |
+
focusCardInGallery(loraParam);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1302 |
|
| 1303 |
} else {
|
| 1304 |
console.warn(`⚠️ [Init] 在返回的数据中不存在该 LoRA: ${loraParam}`);
|
|
|
|
| 1651 |
if (strengthEl) strengthEl.disabled = !on;
|
| 1652 |
});
|
| 1653 |
|
| 1654 |
+
// ==========================================================================
|
| 1655 |
+
// 🎯 深链滚动定位(hidden tab 安全版)
|
| 1656 |
+
// ==========================================================================
|
| 1657 |
+
// 问题:右键"在新标签页打开"时文档是 hidden:
|
| 1658 |
+
// · scrollIntoView({behavior:'smooth'}) 在隐藏文档里被直接丢弃,且不会重试
|
| 1659 |
+
// · rAF 不执行 → 图片 shimmer / 布局在切回前台那一瞬才稳定
|
| 1660 |
+
// · setTimeout 被节流,靠它做定位时机不可控
|
| 1661 |
+
// 解法:把目标记成"待办",只有 visibilityState==='visible' 且几何就绪时才滚;
|
| 1662 |
+
// 切回前台自动补做,并带少量重试(应对图片加载引起的布局微调)
|
| 1663 |
+
let _pendingScrollTarget = "";
|
| 1664 |
+
let _scrollRetryTimer = null;
|
| 1665 |
+
const SCROLL_RETRY_DELAYS = [300, 150, 200, 300, 500, 800, 1200];
|
| 1666 |
+
|
| 1667 |
+
function _clearScrollRetry() {
|
| 1668 |
+
if (_scrollRetryTimer) { clearTimeout(_scrollRetryTimer); _scrollRetryTimer = null; }
|
| 1669 |
+
}
|
| 1670 |
+
|
| 1671 |
+
function focusCardInGallery(filename) {
|
| 1672 |
+
if (!filename) return;
|
| 1673 |
+
_pendingScrollTarget = filename;
|
| 1674 |
+
_clearScrollRetry();
|
| 1675 |
+
_scrollStep(0);
|
| 1676 |
+
}
|
| 1677 |
+
|
| 1678 |
+
function _scrollStep(attempt) {
|
| 1679 |
+
const filename = _pendingScrollTarget;
|
| 1680 |
+
if (!filename) return;
|
| 1681 |
+
|
| 1682 |
+
// ① 隐藏时不滚(滚了也会被丢弃),交给 visibilitychange 补做
|
| 1683 |
+
if (document.visibilityState !== "visible") return;
|
| 1684 |
+
|
| 1685 |
+
const container = document.getElementById("gallery-container");
|
| 1686 |
+
const card = document.querySelector(`.lora-card[data-filename="${CSS.escape(filename)}"]`);
|
| 1687 |
+
|
| 1688 |
+
// ② 几何还没就绪(布局未完成 / 跨架构清空过 / 卡片还没渲染到)→ 退避重试
|
| 1689 |
+
const ready = container && card && container.clientHeight > 50 && card.offsetHeight > 10;
|
| 1690 |
+
if (!ready) {
|
| 1691 |
+
if (attempt < SCROLL_RETRY_DELAYS.length) {
|
| 1692 |
+
_clearScrollRetry();
|
| 1693 |
+
_scrollRetryTimer = setTimeout(() => _scrollStep(attempt + 1), SCROLL_RETRY_DELAYS[attempt]);
|
| 1694 |
+
}
|
| 1695 |
+
return;
|
| 1696 |
+
}
|
| 1697 |
+
|
| 1698 |
+
// ③ 用容器自身 scrollTop 计算,不用 scrollIntoView(后者会连带滚动整个页面)
|
| 1699 |
+
const cRect = container.getBoundingClientRect();
|
| 1700 |
+
const kRect = card.getBoundingClientRect();
|
| 1701 |
+
const desiredOffset = (container.clientHeight - card.offsetHeight) / 2;
|
| 1702 |
+
const currentOffset = kRect.top - cRect.top;
|
| 1703 |
+
const targetTop = Math.max(0, container.scrollTop + currentOffset - desiredOffset);
|
| 1704 |
+
const arrived = Math.abs(currentOffset - desiredOffset) <= 24;
|
| 1705 |
+
|
| 1706 |
+
if (!arrived) {
|
| 1707 |
+
// 首次 smooth;后续重试一律 auto(避免"平滑动画还在跑就被判失败又跳一次")
|
| 1708 |
+
container.scrollTo({ top: targetTop, behavior: attempt === 0 ? "smooth" : "auto" });
|
| 1709 |
+
|
| 1710 |
+
if (attempt < SCROLL_RETRY_DELAYS.length) {
|
| 1711 |
+
_clearScrollRetry();
|
| 1712 |
+
_scrollRetryTimer = setTimeout(() => _scrollStep(attempt + 1), SCROLL_RETRY_DELAYS[attempt]);
|
| 1713 |
+
return;
|
| 1714 |
+
}
|
| 1715 |
+
}
|
| 1716 |
+
|
| 1717 |
+
console.log(`🟢 [Init] 滚动定位完成: ${filename}${arrived ? "" : "(重试兜底)"}`);
|
| 1718 |
+
_pendingScrollTarget = "";
|
| 1719 |
+
_clearScrollRetry();
|
| 1720 |
+
}
|
| 1721 |
+
|
| 1722 |
+
// 切回前台:补做被丢弃的定位(双 rAF 让布局/shimmer 先稳定)
|
| 1723 |
+
document.addEventListener("visibilitychange", () => {
|
| 1724 |
+
if (document.visibilityState !== "visible" || !_pendingScrollTarget) return;
|
| 1725 |
+
console.log("🟢 [Init] 页面已可见,补做滚动定位");
|
| 1726 |
+
_clearScrollRetry();
|
| 1727 |
+
requestAnimationFrame(() => requestAnimationFrame(() => _scrollStep(0)));
|
| 1728 |
+
});
|
| 1729 |
+
|
| 1730 |
function loadMoreCards() {
|
| 1731 |
const grid = document.getElementById('gallery-grid');
|
| 1732 |
const nextBatch = currentGalleryData.slice(renderedCount, renderedCount + BATCH_SIZE);
|