import { concepts, tokensFor, cssVars } from "../concepts/registry.js"; import { iconNames } from "../icons/icons.js"; function zip(files) { const enc = new TextEncoder(); let offset = 0; const chunks = [], central = []; const u16 = (v, n) => { v.push(n & 255, (n >>> 8) & 255); }, u32 = (v, n) => { u16(v, n); u16(v, n >>> 16); }; for (const [name, content] of Object.entries(files)) { const bytes = content instanceof Uint8Array ? content : enc.encode(content), nb = enc.encode(name); let crc = -1; for (const b of bytes) { crc ^= b; for (let k = 0; k < 8; k++) crc = (crc >>> 1) ^ (crc & 1 ? 0xedb88320 : 0); } crc = (crc ^ -1) >>> 0; const h = []; u32(h, 0x04034b50); u16(h, 20); u16(h, 0x800); u16(h, 0); u16(h, 0); u16(h, 0); u32(h, crc); u32(h, bytes.length); u32(h, bytes.length); u16(h, nb.length); u16(h, 0); h.push(...nb); chunks.push(new Uint8Array(h), bytes); const c = []; u32(c, 0x02014b50); u16(c, 20); u16(c, 20); u16(c, 0x800); u16(c, 0); u16(c, 0); u16(c, 0); u32(c, crc); u32(c, bytes.length); u32(c, bytes.length); u16(c, nb.length); u16(c, 0); u16(c, 0); u16(c, 0); u16(c, 0); u32(c, 0); u32(c, offset); c.push(...nb); central.push(new Uint8Array(c)); offset += h.length + bytes.length; } const size = central.reduce((n, c) => n + c.length, 0), end = []; u32(end, 0x06054b50); u16(end, 0); u16(end, 0); u16(end, central.length); u16(end, central.length); u32(end, size); u32(end, offset); u16(end, 0); return new Blob([...chunks, ...central, new Uint8Array(end)], { type: "application/zip", }); } export async function exportSystem( { page = "dashboard", theme = "light", density = "compact", locale = "ru", accent, }, notify = () => {}, ) { const c = concepts[0]; const state = { page, theme, density, locale, accents: accent ? { dock: accent } : {}, }; const files = {}; const paths = [ "icons/icons.js", "icons/index.html", "icons/catalog.css", "icons/catalog.js", "icons/manifest.json", "icons/README.md", "icons/sprite.svg", "icons/preview-light.svg", "icons/preview-dark.svg", "icons/anidev-dock-icons.zip", ...iconNames.map((name) => `icons/svg/${name}.svg`), "components/system.css", "components/toast.js", "components/copy-field.js", "components/search-select.js", "components/workspaces.css", "components/ssh-console.js", "components/log-reader.js", "patterns/demo-pty.js", "patterns/WORKSPACES.md", "vendor/xterm/xterm.js", "vendor/xterm/xterm.css", "vendor/xterm/addon-fit.js", "vendor/xterm/addon-search.js", "vendor/xterm/xterm.LICENSE", "vendor/xterm/addon-fit.LICENSE", "vendor/xterm/addon-search.LICENSE", "vendor/xterm/manifest.json", "components/export-system.js", "components/account-pages.js", "patterns/demo-identity.js", "concepts/registry.js", "playground/frame.html", "playground/frame.js", "tokens/schema.json", "components/CONTRACT.md", "patterns/UX.md", "patterns/IDENTITY.md", "prompts/SSO.md", "prompts/README.md", "layouts/README.md", "DESIGN.md", "ANTI-SLOP.md", ]; const fetched = await Promise.all( paths.map(async (p) => { const r = await fetch(new URL(p, new URL("../", import.meta.url))); if (!r.ok) throw Error(p); return [ p, p.endsWith(".zip") ? new Uint8Array(await r.arrayBuffer()) : await r.text(), ]; }), ); for (const [p, t] of fetched) files[p] = t; for (const theme of ["light", "dark"]) { const tokens = tokensFor( c.id, theme, state.accents[c.id] || undefined, state.density, ); files[`tokens/${theme}.json`] = JSON.stringify(tokens, null, 2); files[`tokens/${theme}.css`] = `:root {\n${cssVars(tokens)}\n}\n`; } files["selection.json"] = JSON.stringify( { version: "0.2.0", status: "approved-design", concept: c.id, page: state.page, accent, customAccent: state.accents[c.id] || null, density: state.density, theme: state.theme, locale: state.locale, }, null, 2, ); const exportParams = new URLSearchParams({ concept: c.id, page: state.page, density: state.density, theme: state.theme, locale: state.locale, }); if (state.accents[c.id]) exportParams.set("accent", state.accents[c.id]); files["index.html"] = `