designlang 12.13.0 → 12.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # Changelog
2
2
 
3
+ ## [12.14.0] — 2026-05-17
4
+
5
+ **Real downloadable PDFs everywhere + a one-shot agent prompt every AI can paste.**
6
+
7
+ Two big shipping themes: every extraction now produces a real
8
+ print-ready PDF on demand (not just an HTML brand book), and every
9
+ extraction writes a self-contained agent prompt that drops into any
10
+ LLM — Claude, GPT, Gemini, Cursor, Windsurf, v0.
11
+
12
+ - **`--pdf` flag in the main `extract` command** — renders the
13
+ brand-book HTML to a 13-chapter PDF (chapter bookmarks, running
14
+ footer, embedded fonts, selectable text). Verified ~440KB per brand.
15
+
16
+ ```bash
17
+ npx designlang stripe.com --pdf --paper letter --landscape
18
+ ```
19
+
20
+ - **One-shot agent prompt (`<host>-AGENT.md`)** — a single file you
21
+ paste into any AI agent. Includes colour roles, type, spacing, radii,
22
+ motion, voice (tone / pronoun / CTA verbs / real headlines),
23
+ component anatomy, WCAG score, 7 build rules ("never invent a hex",
24
+ "snap spacing to scale", etc.), and a manifest of every other
25
+ artefact designlang produced for context.
26
+
27
+ - **Server-side PDF endpoint** — `GET /api/pdf/<hash>` renders the
28
+ cached extraction's brand book to PDF via the same Browserless /
29
+ Chromium path the `/api/extract` route uses. Cached for an hour on
30
+ CDN edge with 24h stale-while-revalidate.
31
+
32
+ - **Website UI** — `/gallery/[slug]` hero CTA is now
33
+ `Download brand book PDF`; new full-width "Agent prompt" section
34
+ with a `Copy NN.NKB prompt` button. Post-extraction share row gains
35
+ `Download brand PDF` and `Copy agent prompt`.
36
+
37
+ - **Pre-rendered static assets** — all 8 featured brand books in
38
+ `website/public/gallery/<slug>/` now include the new `.brand.pdf`,
39
+ `-AGENT.md`, `-reset.css`, `-gradients.css/.json` files so the
40
+ static gallery has working downloads from minute one.
41
+
3
42
  ## [12.13.0] — 2026-05-16
4
43
 
5
44
  **Six new emitters + a public programmatic API.**
@@ -26,6 +26,7 @@ import { formatTailwindV4 } from '../src/formatters/tailwind-v4.js';
26
26
  import { formatTsDefs } from '../src/formatters/ts-defs.js';
27
27
  import { formatCssReset } from '../src/formatters/css-reset.js';
28
28
  import { formatGradientsCss, formatGradientsJson } from '../src/formatters/gradients.js';
29
+ import { formatAgentPrompt } from '../src/formatters/agent-prompt.js';
29
30
  import { formatCssVars } from '../src/formatters/css-vars.js';
30
31
  import { formatPreview } from '../src/formatters/preview.js';
31
32
  import { formatFigma } from '../src/formatters/figma.js';
@@ -113,6 +114,9 @@ program
113
114
  .option('--responsive-shots', 'capture full-page PNGs at 4 breakpoints × (light,dark)')
114
115
  .option('--perf', 'measure Core Web Vitals + bundle profile (LCP/CLS/INP, JS/CSS/font/img bytes, third-party count)')
115
116
  .option('--palette <n>', 'compress the extracted palette to N perceptually distinct colours via LAB-space k-means (default: emit every unique colour)', parseInt)
117
+ .option('--pdf', 'also render a print-ready brand-book PDF (chapter bookmarks, running footer, embedded tokens)')
118
+ .option('--paper <size>', 'PDF paper size when --pdf is set: a4 | letter | tabloid', 'a4')
119
+ .option('--landscape', 'PDF landscape orientation when --pdf is set')
116
120
  .option('--json', 'output raw JSON to stdout (for CI/CD)')
117
121
  .option('--json-pretty', 'output formatted JSON to stdout')
118
122
  .option('--no-history', 'skip saving to history')
@@ -346,6 +350,7 @@ program
346
350
  { name: `${prefix}-reset.css`, content: formatCssReset(design), label: 'Brand-aware CSS reset' },
347
351
  { name: `${prefix}-gradients.css`, content: formatGradientsCss(design), label: 'Extracted gradients (utility classes)' },
348
352
  { name: `${prefix}-gradients.json`, content: formatGradientsJson(design), label: 'Extracted gradients (structured)' },
353
+ { name: `${prefix}-AGENT.md`, content: formatAgentPrompt(design), label: 'Agent system prompt (paste into Claude/GPT/Cursor)' },
349
354
  { name: `${prefix}-variables.css`, content: formatCssVars(design), label: 'CSS Variables' },
350
355
  { name: `${prefix}-preview.html`, content: formatPreview(design), label: 'Visual Preview' },
351
356
  { name: `${prefix}-figma-variables.json`, content: formatFigma(design), label: 'Figma Variables' },
@@ -448,6 +453,32 @@ program
448
453
  writeFileSync(join(outDir, file.name), file.content, 'utf-8');
449
454
  }
450
455
 
456
+ // Brand book — always emit the HTML (cheap, ~100KB). Optionally
457
+ // render it to PDF behind --pdf (needs Playwright, ~3–5s).
458
+ try {
459
+ const brandHtml = formatBrandBook(design, { version: PKG_VERSION });
460
+ const brandHtmlPath = join(outDir, `${prefix}.brand.html`);
461
+ writeFileSync(brandHtmlPath, brandHtml, 'utf-8');
462
+ files.push({ name: `${prefix}.brand.html`, label: 'Brand book (HTML)' });
463
+
464
+ if (opts.pdf) {
465
+ spinner.text = 'Rendering brand book PDF...';
466
+ const pdfPath = join(outDir, `${prefix}.brand.pdf`);
467
+ await htmlToPdf(brandHtml, {
468
+ paper: opts.paper || 'a4',
469
+ landscape: !!opts.landscape,
470
+ outPath: pdfPath,
471
+ metadata: {
472
+ title: `${new URL(design?.meta?.url || `https://${prefix}`).hostname} brand guidelines`,
473
+ subject: `${prefix} brand guidelines`,
474
+ },
475
+ });
476
+ files.push({ name: `${prefix}.brand.pdf`, label: 'Brand book (PDF · print-ready)' });
477
+ }
478
+ } catch (e) {
479
+ if (!merged.quiet) console.warn(`(brand book skipped: ${e.message})`);
480
+ }
481
+
451
482
  // Multi-platform emission (v7.0). web is already emitted above.
452
483
  const platforms = merged.platforms || ['web'];
453
484
  const dtcgTokens = formatDtcgTokens(design);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "designlang",
3
- "version": "12.13.0",
3
+ "version": "12.14.0",
4
4
  "description": "Extract the complete design language from any website and ship it — clone to a working Next.js starter, guard tokens with a CI drift bot, or browse everything in a local studio. Outputs W3C DTCG tokens, motion tokens, typed anatomy stubs, Tailwind config, and ready-to-paste v0 / Lovable / Cursor / Claude-Artifacts prompts.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,214 @@
1
+ // One-shot agent prompt — `<host>-AGENT.md`.
2
+ //
3
+ // Drop the contents into Claude / GPT / Gemini / Cursor / Windsurf
4
+ // and the agent will build any UI you ask for *in the extracted brand*.
5
+ //
6
+ // Distinct from the existing prompt-pack (which targets v0 / Lovable /
7
+ // Cursor with tool-specific syntax). This file is one self-contained
8
+ // system-prompt that works in any context window — every token, every
9
+ // component anatomy slot, every brand voice rule, ready to paste.
10
+
11
+ function hex(c) { return c?.hex || c || null; }
12
+ function pickHex(role, design) { return hex(design?.colors?.[role]) || null; }
13
+
14
+ function topN(arr, n) {
15
+ if (Array.isArray(arr)) return arr.slice(0, n);
16
+ if (arr && typeof arr === 'object') return Object.values(arr).slice(0, n);
17
+ return [];
18
+ }
19
+
20
+ function listColors(design) {
21
+ const out = [];
22
+ for (const role of ['primary', 'secondary', 'accent', 'background', 'foreground']) {
23
+ const v = pickHex(role, design);
24
+ if (v) out.push(`- ${role.padEnd(11)} ${v}`);
25
+ }
26
+ const neutrals = topN(design?.colors?.neutrals, 6).map((n) => hex(n)).filter(Boolean);
27
+ if (neutrals.length) out.push(`- neutrals ${neutrals.join(' · ')}`);
28
+ return out.join('\n');
29
+ }
30
+
31
+ function listType(design) {
32
+ const fams = topN(design?.typography?.families, 4).map((f) => f?.name || f).filter(Boolean);
33
+ const weights = topN(design?.typography?.weights, 6).map((w) => w?.weight || w?.value || w).filter(Boolean);
34
+ const base = design?.typography?.base || 16;
35
+ return [
36
+ fams.length ? `- families ${fams.join(' · ')}` : null,
37
+ weights.length ? `- weights ${weights.join(' · ')}` : null,
38
+ `- base size ${base}px`,
39
+ ].filter(Boolean).join('\n');
40
+ }
41
+
42
+ function listSpacing(design) {
43
+ const scale = topN(design?.spacing?.scale, 12).map((px) => `${px}px`);
44
+ if (!scale.length) return null;
45
+ return `- scale ${scale.join(' · ')}`;
46
+ }
47
+
48
+ function listRadii(design) {
49
+ const radii = topN(design?.borders?.radii, 6).map((r) => `${typeof r === 'object' ? r.value : r}px`);
50
+ if (!radii.length) return null;
51
+ return `- scale ${radii.join(' · ')}`;
52
+ }
53
+
54
+ function listMotion(design) {
55
+ const durs = topN(design?.motion?.durations, 4).map((d) => `${typeof d === 'object' ? (d.value || d.ms) : d}ms`);
56
+ const eas = topN(design?.motion?.easings, 4).map((e) => typeof e === 'object' ? e.value : e).filter(Boolean);
57
+ return [
58
+ durs.length ? `- durations ${durs.join(' · ')}` : null,
59
+ eas.length ? `- easings ${eas.join(' · ')}` : null,
60
+ ].filter(Boolean).join('\n');
61
+ }
62
+
63
+ function listVoice(design) {
64
+ const v = design?.voice || {};
65
+ const ctas = topN(v.ctaVerbs, 6).map((c) => c?.value || c).filter(Boolean);
66
+ const headings = topN(v.headlines || v.headings, 3).map((h) => h?.text || h).filter(Boolean);
67
+ return [
68
+ v.tone ? `- tone ${v.tone}` : null,
69
+ v.pronoun ? `- pronoun ${v.pronoun}` : null,
70
+ v.headingStyle ? `- headings ${v.headingStyle}` : null,
71
+ ctas.length ? `- CTA verbs ${ctas.join(' · ')}` : null,
72
+ headings.length ? `- real headlines:\n${headings.map(h => ` > "${String(h).slice(0, 120)}"`).join('\n')}` : null,
73
+ ].filter(Boolean).join('\n');
74
+ }
75
+
76
+ function listAnatomy(design) {
77
+ const list = design?.componentAnatomy || design?.componentClusters || [];
78
+ if (!Array.isArray(list) || list.length === 0) return null;
79
+ return topN(list, 8).map((c) => {
80
+ const kind = String(c?.kind || c?.name || 'component');
81
+ const variants = topN(c?.variants, 4).map(String).join(' · ') || '—';
82
+ const slots = topN(c?.slots, 4).map(String).join(' · ') || '—';
83
+ return `- ${kind.padEnd(10)} variants: ${variants} · slots: ${slots}`;
84
+ }).join('\n');
85
+ }
86
+
87
+ function listA11y(design) {
88
+ const a = design?.accessibility || {};
89
+ const score = a.score ?? null;
90
+ const fails = a.failCount ?? (a.remediation?.length ?? 0);
91
+ return `- WCAG score ${score == null ? '—' : `${score}%`} · failing pairs: ${fails}`;
92
+ }
93
+
94
+ export function formatAgentPrompt(design) {
95
+ const host = design?.meta?.url ? new URL(design.meta.url).hostname.replace(/^www\./, '') : 'this site';
96
+ const title = design?.meta?.title || host;
97
+ const intent = design?.pageIntent?.label || 'landing';
98
+ const material = design?.materialLanguage?.label || 'flat';
99
+ const library = design?.componentLibrary?.label || null;
100
+ const grade = design?.score?.grade || null;
101
+
102
+ const blocks = [];
103
+ blocks.push(
104
+ `# You are building UI in the ${host} design system.`,
105
+ '',
106
+ `Source: ${design?.meta?.url || '—'}`,
107
+ `Extracted by designlang on ${new Date().toISOString().slice(0, 10)}.`,
108
+ '',
109
+ '## Brand at a glance',
110
+ '',
111
+ `- title ${title}`,
112
+ `- page intent ${intent}`,
113
+ `- material ${material}`,
114
+ library ? `- library ${library}` : null,
115
+ grade ? `- design grade ${grade}` : null,
116
+ '',
117
+ '## Colour',
118
+ '',
119
+ listColors(design) || '_(no colour roles detected)_',
120
+ '',
121
+ '## Typography',
122
+ '',
123
+ listType(design),
124
+ '',
125
+ );
126
+
127
+ const spacing = listSpacing(design);
128
+ if (spacing) blocks.push('## Spacing', '', spacing, '');
129
+
130
+ const radii = listRadii(design);
131
+ if (radii) blocks.push('## Radii', '', radii, '');
132
+
133
+ const motion = listMotion(design);
134
+ if (motion) blocks.push('## Motion', '', motion, '');
135
+
136
+ const voice = listVoice(design);
137
+ if (voice) blocks.push('## Voice', '', voice, '');
138
+
139
+ const anatomy = listAnatomy(design);
140
+ if (anatomy) blocks.push('## Component anatomy', '', anatomy, '');
141
+
142
+ blocks.push('## Accessibility', '', listA11y(design), '');
143
+
144
+ blocks.push(
145
+ '## Build rules',
146
+ '',
147
+ '1. Use the colours above. **Never invent a new hex.** If you need a',
148
+ ' shade between two existing colours, derive it via HSL adjustment',
149
+ ' from the closest extracted colour and call out the derivation.',
150
+ '2. Use the extracted typography families. If you need a missing weight,',
151
+ ' pick the nearest available weight from the list and note it.',
152
+ '3. Snap spacing values to the scale above. No off-scale paddings or',
153
+ ' margins.',
154
+ '4. Snap border radii to the scale above.',
155
+ '5. Match the voice: same tone, same pronoun stance, same heading',
156
+ ' style. Reuse the listed CTA verbs.',
157
+ '6. Aim for WCAG AA contrast minimum. When the brand colours fail,',
158
+ ' prefer the foreground colour on the background colour rather than',
159
+ ' mid-tone neutrals.',
160
+ '7. Reuse component anatomy when it exists — do not invent novel',
161
+ ' structures for things the site already has.',
162
+ '',
163
+ '## Available context files',
164
+ '',
165
+ 'designlang wrote these alongside this prompt. Reach for them when',
166
+ 'you need ground truth:',
167
+ '',
168
+ '- `<host>-design-tokens.json` — DTCG primitive · semantic · composite tokens',
169
+ '- `<host>-tailwind.config.js` — Tailwind v3 config',
170
+ '- `<host>-tailwind-v4.css` — Tailwind v4 `@theme` block',
171
+ '- `<host>-tokens.d.ts` — TypeScript literal-union types',
172
+ '- `<host>-variables.css` — bare CSS custom properties',
173
+ '- `<host>-reset.css` — brand-aware base styles',
174
+ '- `<host>-gradients.css` — `.grad-N` utility classes',
175
+ '- `<host>-anatomy.tsx` — typed React component scaffolds',
176
+ '- `<host>-shadcn-theme.css` — shadcn/ui theme',
177
+ '- `<host>-theme.js` — React / Vue / Svelte theme object',
178
+ '- `<host>-mcp.json` — MCP server payload (load via stdio)',
179
+ '- `<host>.brand.pdf` — print-ready 13-chapter brand book',
180
+ '',
181
+ 'When you reference the system in code, prefer importing from these',
182
+ 'files over hard-coding values.',
183
+ '',
184
+ '## Output expectations',
185
+ '',
186
+ 'When asked to "build a pricing page" or "make a card" or any UI:',
187
+ '',
188
+ '- Produce a single self-contained component file in the appropriate',
189
+ ' framework (React / Vue / Svelte — match what the user is using).',
190
+ '- Use Tailwind utility classes wired to the v4 `@theme` if Tailwind',
191
+ ' is available; otherwise use the CSS custom properties from',
192
+ ' `variables.css`.',
193
+ '- Write the headline copy using the brand voice; do not invent',
194
+ ' generic Lorem.',
195
+ '- Annotate any choice where you had to bend the system, with a',
196
+ ' one-line `// note:` comment explaining what and why.',
197
+ '',
198
+ `## One-line install`,
199
+ '',
200
+ '```bash',
201
+ `npx designlang ${host}`,
202
+ '```',
203
+ '',
204
+ 'Run this against any other URL to extract its system in the same',
205
+ 'shape as the one above.',
206
+ '',
207
+ '---',
208
+ '',
209
+ `Generated by designlang. Re-extract by running \`npx designlang ${host}\`.`,
210
+ '',
211
+ );
212
+
213
+ return blocks.filter((b) => b !== null).join('\n');
214
+ }