Spaces:
Running
Running
Download static/gallery.js from minjiechen/OpenPELS: direct link, hf CLI and curl.
- Browser
- Download file 5.93 kB
-
https://huggingface.co/spaces/minjiechen/OpenPELS/resolve/main/static/gallery.js
- Command line
-
hf download hf://spaces/minjiechen/OpenPELS/static/gallery.js
-
curl -L -o gallery.js https://huggingface.co/spaces/minjiechen/OpenPELS/resolve/main/static/gallery.js
5.93 kB
| import "./compare/recommend.js?v=buck-stacked-coss"; | |
| export const FAMILY_RATIOS = [2, 4, 6, 8, 16]; | |
| const presets = { | |
| buck_stacked: { | |
| name: "2:1 Buck_Stacked", | |
| image: "buck-stacked-candidate.svg", | |
| starter: "buck_stacked", | |
| simulator: "buck_stacked", | |
| magneticsLabel: "2 inverse-coupled windings", | |
| simulatorRatio: 2, | |
| }, | |
| si2: { | |
| name: "2:1 switched inductor", | |
| image: "si2-candidate.svg", | |
| starter: "si2", | |
| simulator: "si2", | |
| magneticsLabel: "2 inverse-coupled windings", | |
| simulatorRatio: 2, | |
| }, | |
| rsc2: { | |
| name: "2:1 resonant SC", | |
| simulatorRatio: 2, | |
| image: "rsc2-candidate.svg", | |
| starter: "rsc2", | |
| simulator: "rsc2", | |
| magneticsLabel: "2 uncoupled series inductors", | |
| }, | |
| sp2: { | |
| name: "2:1 series-parallel SC", | |
| simulatorRatio: 2, | |
| image: "sp2-candidate.svg", | |
| starter: "sp2", | |
| simulator: "sp2", | |
| magneticsLabel: "no power windings", | |
| }, | |
| xfly2p: { | |
| name: "XFLY6S", | |
| image: "xfly6s-candidate.svg", | |
| starter: "xfly6s", | |
| simulator: "xfly6s", | |
| }, | |
| xfly4p: { | |
| name: "XFLY8S", | |
| image: "xfly4p-candidate.svg", | |
| starter: "xfly8s", | |
| simulator: "xfly8s", | |
| simulationRelation: "related", | |
| simulationNote: | |
| "Related simulation and editor preset: two cross-linked capacitors, no clamp capacitors. The analytical circuit includes Cc1 and Cc2.", | |
| }, | |
| "3lbuck": { | |
| name: "Three-level buck", | |
| image: "3lbuck-candidate.svg", | |
| simulator: "c3l", | |
| }, | |
| "2sbuck": { name: "Capacitor-clamped buck", image: "2sbuck-candidate.svg" }, | |
| buck: { name: "Stacked synchronous buck", image: "buck-candidate.svg" }, | |
| buck2: { | |
| name: "Two-phase coupled buck", | |
| image: "buck2-candidate.svg", | |
| starter: "buck2", | |
| }, | |
| }; | |
| export function createGallery({ onSelect, report }) { | |
| let entries = [], | |
| filter = null, | |
| selected = null; | |
| const list = document.querySelector("#gallery-cards"); | |
| const filters = document.querySelector("#gallery-ratios"); | |
| function render() { | |
| list.replaceChildren(); | |
| const matches = entries.filter( | |
| (entry) => filter === null || entry.ratios.includes(filter), | |
| ); | |
| document.querySelector("#gallery-count").textContent = | |
| `${matches.length} ${matches.length === 1 ? "topology" : "topologies"}${filter ? ` for ${filter}:1` : " in the library"}`; | |
| document.querySelector("#gallery-empty").hidden = matches.length > 0; | |
| document.querySelector("#gallery-empty-text").textContent = | |
| `Qualified topology references are not yet validated for ${filter}:1. Choose 2:1 or 4:1 to explore the supported families.`; | |
| filters.querySelectorAll("button").forEach((button) => { | |
| const active = | |
| button.dataset.family === (filter === null ? "all" : String(filter)); | |
| button.classList.toggle("active", active); | |
| button.setAttribute("aria-pressed", String(active)); | |
| }); | |
| for (const entry of matches) { | |
| const button = document.createElement("button"); | |
| button.className = | |
| "topology-tile" + (selected === entry.id ? " selected" : ""); | |
| button.dataset.topologyId = entry.id; | |
| const ratio = filter ?? (entry.ratios.includes(4) ? 4 : entry.ratios[0]); | |
| const heading = document.createElement("div"); | |
| heading.className = "tile-heading"; | |
| const name = document.createElement("strong"); | |
| name.textContent = entry.name; | |
| const tag = document.createElement("span"); | |
| tag.textContent = entry.ratios.map((value) => `${value}:1`).join(" · "); | |
| heading.append(name, tag); | |
| const image = document.createElement("img"); | |
| image.src = "./compare/assets/" + entry.image; | |
| image.alt = entry.name + " circuit schematic"; | |
| const meta = document.createElement("div"); | |
| meta.className = "tile-meta"; | |
| meta.textContent = `${entry.switches} switches · ${entry.magneticsLabel ?? "coupled magnetics"}`; | |
| const capability = document.createElement("span"); | |
| capability.className = "tile-capability"; | |
| capability.textContent = | |
| entry.simulator && ratio === (entry.simulatorRatio ?? 4) | |
| ? entry.simulationRelation === "related" | |
| ? "Analysis · related simulation" | |
| : "Analysis + simulation" | |
| : "Analytical model"; | |
| const action = document.createElement("span"); | |
| action.className = "tile-action"; | |
| action.textContent = "Explore topology →"; | |
| button.append(heading, image, meta, capability, action); | |
| button.onclick = () => { | |
| selected = entry.id; | |
| render(); | |
| onSelect(entry, ratio); | |
| }; | |
| list.append(button); | |
| } | |
| } | |
| for (const [value, label] of [ | |
| [null, "All topologies"], | |
| ...FAMILY_RATIOS.map((ratio) => [ratio, `${ratio}:1`]), | |
| ]) { | |
| const button = document.createElement("button"); | |
| button.textContent = label; | |
| button.dataset.family = value === null ? "all" : String(value); | |
| button.onclick = () => { | |
| filter = value; | |
| render(); | |
| }; | |
| filters.append(button); | |
| } | |
| async function load() { | |
| try { | |
| const response = await fetch("./compare/models-data.json", { cache: "no-store" }); | |
| if (!response.ok) throw Error("Topology gallery unavailable"); | |
| const data = await response.json(); | |
| entries = data.catalog | |
| .filter((meta) => presets[meta.id]) | |
| .map((meta) => ({ | |
| ...meta, | |
| ...presets[meta.id], | |
| ratios: FAMILY_RATIOS.filter((ratio) => | |
| window.OpenPELSRecommendation.referenceFamilyIds(ratio).includes(meta.id), | |
| ), | |
| })) | |
| .filter((entry) => entry.ratios.length); | |
| render(); | |
| return entries; | |
| } catch (error) { | |
| report(error.message); | |
| throw error; | |
| } | |
| } | |
| return { | |
| load, | |
| get: (id) => entries.find((entry) => entry.id === id), | |
| forSimulator: (id) => entries.find((entry) => entry.simulator === id), | |
| highlight(id) { | |
| selected = id; | |
| render(); | |
| }, | |
| }; | |
| } | |