Files
upstream-twenty/packages/twenty-docs/scripts/generate-halftone-illustrations.mjs
upstream-mirror e7da97194a
Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 2s
snapshot of https://github.com/twentyhq/twenty.git (main, 2026-09-17; blobs > 131072B omitted)
2026-09-17 23:28:13 +05:00

145 lines
5.0 KiB
JavaScript

/**
* Converts existing User Guide illustrations into halftone style.
* Uses Playwright to run a canvas-based halftone filter in the browser.
* No dev server needed.
*
* Usage:
* node packages/twenty-docs/scripts/generate-halftone-illustrations.mjs
*/
import { chromium } from 'playwright';
import { writeFileSync, readFileSync, mkdirSync } from 'fs';
import { join, dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const DOCS_IMAGES = join(__dirname, '..', 'images');
const OUTPUT_DIR = join(DOCS_IMAGES, 'user-guide', 'halftone');
const ILLUSTRATIONS = [
{ name: 'data-model', source: 'user-guide/fields/custom_data_model.png' },
{ name: 'data-migration', source: 'user-guide/import-export-data/cloud.png' },
{ name: 'calendar-emails', source: 'user-guide/emails/emails_header.png' },
{ name: 'workflows', source: 'user-guide/workflows/workflow.png' },
{ name: 'ai', source: 'user-guide/workflows/robot.png' },
{ name: 'layout', source: 'user-guide/table-views/table_pink.png' },
{ name: 'dashboards', source: 'user-guide/reporting/pie-chart.png' },
{ name: 'permissions', source: 'user-guide/permissions/permissions.png' },
{ name: 'billing', source: 'user-guide/setup/pricing.png' },
{ name: 'settings', source: 'user-guide/setup/settings.png' },
// Developers section
{ name: 'dev-apps', source: 'user-guide/integrations/plug.png' },
{ name: 'dev-api', source: 'user-guide/api/api-overview.png' },
{ name: 'dev-self-host', source: 'user-guide/what-is-twenty/20.png' },
{ name: 'dev-contribute', source: 'user-guide/github/github-header.png' },
];
async function main() {
mkdirSync(OUTPUT_DIR, { recursive: true });
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
await page.setContent('<html><body></body></html>');
console.log(
`Converting ${ILLUSTRATIONS.length} illustrations to halftone...\n`,
);
for (const illust of ILLUSTRATIONS) {
const sourcePath = resolve(DOCS_IMAGES, illust.source);
console.log(` ${illust.name} ← ${illust.source}`);
const imageBytes = readFileSync(sourcePath);
const base64 = imageBytes.toString('base64');
const mime = sourcePath.endsWith('.png') ? 'image/png' : 'image/jpeg';
const resultBase64 = await page.evaluate(
async ({ b64, m }) => {
const LINE_SPACING = 8;
const MIN_LINE_WIDTH = 0.5;
const MAX_LINE_WIDTH = 6;
const COLOR = { r: 74, g: 56, b: 245 }; // #4A38F5
const TRANSPARENT_BG = true;
const img = new Image();
await new Promise((res, rej) => {
img.onload = res;
img.onerror = rej;
img.src = `data:${m};base64,${b64}`;
});
const { width, height } = img;
const scale = 2;
const outW = width * scale;
const outH = height * scale;
// Read source pixels
const tmp = document.createElement('canvas');
tmp.width = width;
tmp.height = height;
const tmpCtx = tmp.getContext('2d');
tmpCtx.drawImage(img, 0, 0);
const px = tmpCtx.getImageData(0, 0, width, height).data;
// Output canvas
const out = document.createElement('canvas');
out.width = outW;
out.height = outH;
const ctx = out.getContext('2d');
// Transparent background — adapts to both light and dark mode
const sp = LINE_SPACING * scale;
for (let y = sp / 2; y < outH; y += sp) {
const srcY = Math.min(Math.floor(y / scale), height - 1);
let x = 0;
while (x < outW) {
const srcX = Math.min(Math.floor(x / scale), width - 1);
const i = (srcY * width + srcX) * 4;
const lum =
(0.299 * px[i] + 0.587 * px[i + 1] + 0.114 * px[i + 2]) / 255;
const a = px[i + 3] / 255;
const dark = (1 - lum) * a;
if (dark > 0.2) {
const w =
(MIN_LINE_WIDTH + (MAX_LINE_WIDTH - MIN_LINE_WIDTH) * dark) *
scale;
const dashLen = sp * (0.3 + 0.7 * dark);
const gap = sp * (0.1 + 0.4 * (1 - dark));
const alpha = 0.3 + 0.7 * dark;
ctx.strokeStyle = `rgba(${COLOR.r},${COLOR.g},${COLOR.b},${alpha})`;
ctx.lineWidth = w;
ctx.lineCap = 'round';
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(Math.min(x + dashLen, outW), y);
ctx.stroke();
x += dashLen + gap;
} else {
x += sp * 0.5;
}
}
}
return out.toDataURL('image/png').split(',')[1];
},
{ b64: base64, m: mime },
);
const outputPath = join(OUTPUT_DIR, `${illust.name}.png`);
writeFileSync(outputPath, Buffer.from(resultBase64, 'base64'));
console.log(` → ${outputPath}`);
}
await browser.close();
console.log('\nDone!');
}
main().catch((err) => {
console.error('Failed:', err);
process.exit(1);
});