Build Anidev design laboratory with six interactive concepts
This commit is contained in:
commit
ae037908ab
60 files changed
+5084
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile, mkdir, writeFile } from "node:fs/promises";
|
||||
import { concepts, tokensFor, cssVars } from "../concepts/registry.js";
|
||||
assert.equal(concepts.length, 6);
|
||||
assert.equal(new Set(concepts.map((c) => c.layout)).size, 6);
|
||||
const luminance = (hex) =>
|
||||
hex
|
||||
.match(/\w\w/g)
|
||||
.map((x) => parseInt(x, 16) / 255)
|
||||
.map((x) => (x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4))
|
||||
.reduce((s, v, i) => s + v * [0.2126, 0.7152, 0.0722][i], 0);
|
||||
const contrast = (a, b) => {
|
||||
const x = luminance(a),
|
||||
y = luminance(b);
|
||||
return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);
|
||||
};
|
||||
for (const c of concepts)
|
||||
for (const theme of ["light", "dark"])
|
||||
for (const density of ["compact", "normal", "relaxed"]) {
|
||||
const t = tokensFor(c.id, theme, undefined, density);
|
||||
for (const bg of ["color.bg", "color.surface"])
|
||||
for (const fg of [
|
||||
"color.text",
|
||||
"color.muted",
|
||||
"color.danger",
|
||||
"color.success",
|
||||
"color.accent",
|
||||
])
|
||||
assert.ok(
|
||||
contrast(t[fg], t[bg]) >= 4.5,
|
||||
`${c.id}/${theme}/${fg} contrast ${contrast(t[fg], t[bg])}`,
|
||||
);
|
||||
assert.ok(contrast(t["color.accent"], t["color.on-accent"]) >= 4.5);
|
||||
}
|
||||
for (const c of concepts)
|
||||
for (const theme of ["light", "dark"]) {
|
||||
const tokens = tokensFor(c.id, theme);
|
||||
await mkdir(`tokens/${c.id}`, { recursive: true });
|
||||
await writeFile(
|
||||
`tokens/${c.id}/${theme}.json`,
|
||||
JSON.stringify(tokens, null, 2) + "\n",
|
||||
);
|
||||
await writeFile(
|
||||
`tokens/${c.id}/${theme}.css`,
|
||||
`:root {\n${cssVars(tokens)}\n}\n`,
|
||||
);
|
||||
}
|
||||
for (const file of [
|
||||
"playground/index.html",
|
||||
"playground/frame.html",
|
||||
"components/system.css",
|
||||
"playground/frame.js",
|
||||
"playground/gallery.js",
|
||||
])
|
||||
assert.ok((await readFile(file, "utf8")).length > 100);
|
||||
console.log(
|
||||
"PASS: six layout grammars, 36 token sets, default text contrast, generated CSS/JSON.",
|
||||
);
|
||||
@@ -0,0 +1,35 @@
|
||||
import { chromium } from "playwright";
|
||||
const base = process.env.BASE_URL || "http://127.0.0.1:4173";
|
||||
const browser = await chromium.launch({
|
||||
executablePath:
|
||||
process.env.PLAYWRIGHT_EXECUTABLE_PATH ||
|
||||
(process.platform === "win32"
|
||||
? "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
|
||||
: undefined),
|
||||
headless: true,
|
||||
});
|
||||
try {
|
||||
const page = await browser.newPage();
|
||||
for (const device of ["desktop", "mobile"])
|
||||
for (const theme of ["light", "dark"]) {
|
||||
const width = device === "desktop" ? 640 : 300,
|
||||
height = device === "desktop" ? 570 : 780;
|
||||
await page.setViewportSize({
|
||||
width: width * 3,
|
||||
height: (height + 35) * 2,
|
||||
});
|
||||
await page.setContent(
|
||||
`<style>*{box-sizing:border-box}body{margin:0;background:#303335;color:white;display:grid;grid-template-columns:repeat(3,${width}px);font:14px Arial}section{width:${width}px;height:${height + 35}px;padding:0 8px 8px}header{height:35px;padding:10px}img{width:100%;height:${height - 8}px;object-fit:contain;object-position:top;background:#202224}</style>${["relay", "ledger", "signal", "axis", "dock", "grid"].map((c) => `<section><header>${c.toUpperCase()} / ${theme} / ${device}</header><img src="${base}/test-results/screenshots/${c}-${theme}-${device}-dashboard.png"></section>`).join("")}`,
|
||||
);
|
||||
await page
|
||||
.locator("img")
|
||||
.evaluateAll((imgs) => Promise.all(imgs.map((i) => i.decode())));
|
||||
await page.screenshot({
|
||||
path: `references/concepts-${theme}-${device}.jpg`,
|
||||
type: "jpeg",
|
||||
quality: 90,
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import http from "node:http";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
const root = path.resolve(fileURLToPath(new URL("../", import.meta.url)));
|
||||
const types = {
|
||||
".html": "text/html; charset=utf-8",
|
||||
".css": "text/css; charset=utf-8",
|
||||
".js": "text/javascript; charset=utf-8",
|
||||
".json": "application/json; charset=utf-8",
|
||||
".svg": "image/svg+xml",
|
||||
".md": "text/plain; charset=utf-8",
|
||||
};
|
||||
const port = Number(process.env.PORT || 4173);
|
||||
http
|
||||
.createServer(async (req, res) => {
|
||||
try {
|
||||
const pathname = decodeURIComponent(
|
||||
new URL(req.url, "http://localhost").pathname,
|
||||
);
|
||||
if (pathname === "/") {
|
||||
res.writeHead(302, { Location: "/playground/" });
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
const file = path.resolve(
|
||||
root,
|
||||
"." + (pathname.endsWith("/") ? pathname + "index.html" : pathname),
|
||||
);
|
||||
if (!file.startsWith(root + path.sep)) throw Error();
|
||||
const data = await readFile(file);
|
||||
res.writeHead(200, {
|
||||
"Content-Type": types[path.extname(file)] || "application/octet-stream",
|
||||
"Cache-Control": "no-store",
|
||||
});
|
||||
res.end(data);
|
||||
} catch {
|
||||
res.writeHead(404);
|
||||
res.end("Not found");
|
||||
}
|
||||
})
|
||||
.listen(port, "127.0.0.1", () =>
|
||||
console.log(`Anidev Design System: http://127.0.0.1:${port}`),
|
||||
);
|
||||
Reference in new issue
Block a user