Penpot design workflow: baseline export, importer plugin, tokens
Mirror to Gitea / mirror (push) Skipped
Mirror to Gitea / mirror (push) Skipped
- tools/penpot/capture.mjs captures every page at 390 and 1440 px as editable layers (text, boxes, images) grouped by section - tools/penpot/plugin: Penpot plugin that rebuilds the captures as native boards; serve.py hosts it locally; preview.html shows the result - tools/penpot/tokens.mjs exports colours and fonts as design tokens - design/README.md documents the design -> hand-off -> code loop
This commit is contained in:
263 files changed
+1054
-1
No files matched your search
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Export src/styles/tokens.css → design/tokens.json (W3C design-token format,
|
||||
* which Penpot's Tokens panel imports). Colours and font families only.
|
||||
*
|
||||
* node tools/penpot/tokens.mjs
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
|
||||
const css = fs.readFileSync('src/styles/tokens.css', 'utf8');
|
||||
const root = css.slice(css.indexOf(':root'), css.indexOf('}', css.indexOf(':root')));
|
||||
const vars = Object.fromEntries([...root.matchAll(/--([\w-]+):\s*([^;]+);/g)].map((m) => [m[1], m[2].trim()]));
|
||||
const resolve = (v, seen = 0) => {
|
||||
const m = v.match(/^var\(--([\w-]+)\)$/);
|
||||
return m && seen < 5 ? resolve(vars[m[1]] ?? v, seen + 1) : v;
|
||||
};
|
||||
|
||||
const tokens = { color: {}, fontFamily: {} };
|
||||
for (const [name, raw] of Object.entries(vars)) {
|
||||
const v = resolve(raw);
|
||||
if (/^#[0-9a-f]{3,8}$/i.test(v)) {
|
||||
const [group, ...rest] = name.split('-');
|
||||
const key = rest.length ? rest.join('-') : 'base';
|
||||
(tokens.color[group] ??= {})[key] = { $type: 'color', $value: v };
|
||||
} else if (name.startsWith('ff-')) {
|
||||
tokens.fontFamily[name.slice(3)] = { $type: 'fontFamilies', $value: v.split(',')[0].replace(/['"]/g, '').replace(/ Variable$/, '').trim() };
|
||||
}
|
||||
}
|
||||
fs.mkdirSync('design', { recursive: true });
|
||||
fs.writeFileSync('design/tokens.json', JSON.stringify({ 'yoyos.sh': tokens }, null, 2));
|
||||
console.log(`design/tokens.json: ${Object.values(tokens.color).reduce((a, g) => a + Object.keys(g).length, 0)} colours, ${Object.keys(tokens.fontFamily).length} font families`);
|
||||
Reference in new issue
Block a user