"use strict"; const SCALABLE_TOOLS = new Set(scalableToolIds()); const SIZE_ORDER = typeof TOOL_SIZE_ORDER !== "undefined" ? TOOL_SIZE_ORDER : ["small", "medium", "large"]; const SIZE_LABELS = typeof TOOL_SIZE_LABELS !== "undefined" ? TOOL_SIZE_LABELS : { small: "小", medium: "中", large: "大" }; function renderToolPalette() { if (!ui?.toolPalette || typeof toolCategories !== "function") return; ui.toolPalette.innerHTML = ""; const frag = document.createDocumentFragment(); for (const category of toolCategories()) { const section = document.createElement("section"); section.className = `tool-category ${category.themeClass || ""}`.trim(); section.dataset.toolCategory = category.id; const toggle = document.createElement("button"); toggle.className = "tool-category-toggle"; toggle.type = "button"; toggle.setAttribute("aria-expanded", "true"); toggle.textContent = category.label || category.id; const body = document.createElement("div"); body.className = "tool-grid tool-category-body"; for (const toolId of category.toolIds || []) { const def = toolDefinition(toolId); if (!def || def.simulationOnly) continue; const btn = document.createElement("button"); btn.className = "tool"; btn.dataset.tool = toolId; btn.textContent = def.label || toolId; if (toolId === world?.tool) btn.classList.add("selected"); body.appendChild(btn); } section.append(toggle, body); frag.appendChild(section); } ui.toolPalette.appendChild(frag); } function toolSizeFor(tool) { if (!SCALABLE_TOOLS.has(tool)) return ""; return typeof normalizedToolSizeFor === "function" ? normalizedToolSizeFor(world, tool) : ((world.toolSizes && world.toolSizes[tool]) || world.toolSize || "medium"); } function cycleToolSize(tool) { if (!SCALABLE_TOOLS.has(tool)) return false; if (!world.toolSizes) world.toolSizes = {}; const current = toolSizeFor(tool); const idx = SIZE_ORDER.indexOf(current); const next = SIZE_ORDER[(idx + 1 + SIZE_ORDER.length) % SIZE_ORDER.length]; world.toolSizes[tool] = next; world.toolSize = next; syncToolSizeBadges(); showToast(`\u30b5\u30a4\u30ba: ${SIZE_LABELS[next] || next}`); return true; } function syncToolSizeBadges() { for (const btn of uiCache.toolButtons || []) { const tool = btn.dataset.tool || ""; const old = btn.querySelector(".tool-size-badge"); if (!SCALABLE_TOOLS.has(tool)) { btn.removeAttribute("data-size"); if (old) old.remove(); continue; } const size = toolSizeFor(tool); btn.dataset.size = size; let badge = old; if (!badge) { badge = document.createElement("b"); badge.className = "tool-size-badge"; btn.appendChild(badge); } badge.textContent = SIZE_LABELS[size] || size; } }