SPB Git

Repository Public

marque.mjs 5.7 KB 82 lines javascript

1// Régénère les fichiers de marque du Groupe Ka dans public/ : favicon.svg, favicon-32.png, apple-touch-icon.png, og.png.2// Usage : CHROME_EXE=<Chromium de Playwright> node scripts/marque.mjs3import fs from "node:fs";4import path from "node:path";5import { fileURLToPath } from "node:url";6import { chromium } from "playwright-core";78const ici = path.dirname(fileURLToPath(import.meta.url));9const pub = path.join(ici, "..", "public");10const rad = (d) => (d * Math.PI) / 180;11const f = (n) => (Math.round(n * 100) / 100).toString();1213/** La rotonde en plan : six segments de mur, la porte du haut ouverte. */14function rotonde({ R = 23, mur = 6.5, battant = 4, c = 32, haut = 14, autres = 7 } = {}) {15  let s = "";16  const demi = (i) => (((i % 6) + 6) % 6 === 0 ? haut : autres);17  for (let i = 0; i < 6; i++) {18    const a0 = rad(-90 + 60 * i + demi(i)), a1 = rad(-90 + 60 * (i + 1) - demi(i + 1));19    s += `<path d="M${f(c + R * Math.cos(a0))} ${f(c + R * Math.sin(a0))}A${R} ${R} 0 0 1 ${f(c + R * Math.cos(a1))} ${f(c + R * Math.sin(a1))}"/>`;20  }21  const hx = c + R * Math.cos(rad(-90 - haut)), hy = c + R * Math.sin(rad(-90 - haut));22  const corde = 2 * R * Math.sin(rad(haut));23  s += `<path d="M${f(hx)} ${f(hy - 2)}v${f(corde + 2)}" stroke-width="${battant}" stroke-linecap="round"/>`;24  return `<g fill="none" stroke-width="${mur}">${s}</g>`;25}2627// favicon : encre sur papier, s'inverse en thème sombre ; baies élargies pour rester lisibles à 16 px28const favicon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><title>Groupe Ka</title><style>g{stroke:#1A1B1E}@media (prefers-color-scheme:dark){g{stroke:#EFEDE6}}</style>${rotonde({ R: 24, mur: 8, battant: 5, haut: 15, autres: 8 })}</svg>\n`;29fs.writeFileSync(path.join(pub, "favicon.svg"), favicon);3031const SYM = path.join(ici, "symboles"); // symboles officiels, copiés des systèmes de marque des six sites32const lire = (k) => fs.readFileSync(`${SYM}/${k}.svg`, "utf8").replace("<svg ", `<svg width="64" height="64" `);33const apps = ["louka", "immoka", "vraiprix", "autoka", "foodka", "fabrika"];34const b64 = (n) => fs.readFileSync(path.join(pub, "fonts", n)).toString("base64");35const fonts = `@font-face{font-family:Newsreader;font-weight:200 800;src:url(data:font/woff2;base64,${b64("newsreader-latin-v5.woff2")})}@font-face{font-family:Geist;font-weight:100 900;src:url(data:font/woff2;base64,${b64("geist-latin-v5.woff2")})}`;3637const browser = await chromium.launch({ executablePath: process.env.CHROME_EXE, headless: true });38async function png(html, w, h, out) {39  const page = await browser.newPage({ viewport: { width: w, height: h }, deviceScaleFactor: 1 });40  await page.setContent(html, { waitUntil: "load" });41  await page.evaluate(() => document.fonts.ready);42  await page.screenshot({ path: path.join(pub, out) });43  await page.close();44}45const icone = (taille, marge) =>46  `<body style="margin:0;background:#F4F2EC"><svg xmlns="http://www.w3.org/2000/svg" viewBox="${-marge} ${-marge} ${64 + 2 * marge} ${64 + 2 * marge}" width="${taille}" height="${taille}" style="display:block"><g stroke="#1A1B1E">${rotonde({ R: 24, mur: 8, battant: 5, haut: 15, autres: 8 })}</g></svg>`;47await png(icone(180, 14), 180, 180, "apple-touch-icon.png");48await png(icone(32, 2), 32, 32, "favicon-32.png");4950// Image de partage : la rotonde à gauche, les six symboles derrière leurs portes ; le mot-symbole à droite.51{52  const R = 170, cx = 315, cy = 315, d = 9;53  let plan = "";54  const coul = ["#E96B32", "#D12C37", "#2540A6", "#0A5F6B", "#8A1F52", "#855E00"];55  for (let i = 0; i < 6; i++) {56    const a0 = rad(-90 + 60 * i + d), a1 = rad(-90 + 60 * (i + 1) - d);57    plan += `<path d="M${f(cx + R * Math.cos(a0))} ${f(cy + R * Math.sin(a0))}A${R} ${R} 0 0 1 ${f(cx + R * Math.cos(a1))} ${f(cy + R * Math.sin(a1))}" fill="none" stroke="#1A1B1E" stroke-width="8"/>`;58    const t = -90 + 60 * i;59    const hx = cx + R * Math.cos(rad(t - d)), hy = cy + R * Math.sin(rad(t - d));60    const fx = cx + R * Math.cos(rad(t + d)), fy = cy + R * Math.sin(rad(t + d));61    const c = Math.hypot(fx - hx, fy - hy), qx = hx - (fy - hy), qy = hy + (fx - hx);62    // battants entrouverts à 28°63    const o = rad(28), ex = hx + (fx - hx) * Math.cos(o) - (fy - hy) * Math.sin(o), ey = hy + (fx - hx) * Math.sin(o) + (fy - hy) * Math.cos(o);64    plan += `<path d="M${f(fx)} ${f(fy)}A${f(c)} ${f(c)} 0 0 1 ${f(qx)} ${f(qy)}" fill="none" stroke="#BDB9AE" stroke-width="1.2" stroke-dasharray="3 6"/>`;65    plan += `<path d="M${f(hx)} ${f(hy)}L${f(ex)} ${f(ey)}" stroke="${coul[i]}" stroke-width="6" stroke-linecap="round"/><circle cx="${f(hx)}" cy="${f(hy)}" r="5.2" fill="#1A1B1E"/>`;66  }67  const syms = apps.map((k, i) => {68    const t = rad(-90 + 60 * i), r = 236;69    return `<div style="position:absolute;left:${f(cx + r * Math.cos(t) - 32)}px;top:${f(cy + r * Math.sin(t) - 32)}px;width:64px;height:64px">${lire(k)}</div>`;70  }).join("");71  const html = `<style>${fonts}body{margin:0;width:1200px;height:630px;background:#F4F2EC;color:#1A1B1E;position:relative;overflow:hidden}</style>72  <svg width="630" height="630" style="position:absolute;left:0;top:0">${plan}</svg>${syms}73  <div style="position:absolute;left:660px;top:0;bottom:0;right:70px;display:flex;flex-direction:column;justify-content:center">74    <div style="font:500 84px/1 Newsreader;letter-spacing:-0.022em"><span style="color:#67696E">Groupe</span> Ka</div>75    <div style="font:400 30px/1.35 Geist;color:#44464B;margin-top:26px">Six adresses québécoises,<br>six portes.</div>76    <div style="font:500 21px/1.5 Geist;color:#67696E;margin-top:34px;border-top:1px solid #BDB9AE;padding-top:20px">Lou-Ka · Immo-Ka · Vrai-Prix<br>Auto-Ka · Food-Ka · Fabri-Ka</div>77  </div>`;78  await png(html, 1200, 630, "og.png");79}80await browser.close();81console.log("marque : favicon.svg, favicon-32.png, apple-touch-icon.png, og.png");82
Files main
Menu

Theme