aem-eds-kit 0.4.22 → 0.4.26

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
@@ -6,7 +6,63 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ### Changed
10
+ - **`block from-design` now fetches the design once into a cached snapshot,
11
+ then generates from it** (fetch → cache → generate). The CLI resolves the
12
+ design via the cheapest adapter - local SVG/PNG export, a cached snapshot
13
+ (`tmp/eds-cli/design-cache/`), the **Figma REST** API (with a token), or a
14
+ **single** Figma MCP call the agent caches - so retries and refine passes
15
+ never re-fetch. Replaces the old flow where the agent made several MCP calls
16
+ mid-generation. New `src/lib/figma/rest.ts` and `design-source.ts`.
17
+ - **MCP usage cut to one call per block.** The prompt now uses only
18
+ `get_design_context` (dropped `get_variable_defs`; `get_screenshot` is opt-in
19
+ via `--screenshot`) - the Figma Dev Mode MCP server meters tool calls per plan
20
+ (Starter/View/Collab: ~6-20/month). Set a Figma token to skip MCP via REST.
21
+ - **Block generation defaults to the fastest model (Haiku)**, overridable with
22
+ `model` in config - block codegen is structured, bounded work.
23
+ - **`eds block preview` no longer auto-launches.** After `from-design` you get a
24
+ menu to refine the block or open the preview on demand; `--no-serve` became
25
+ `--serve` (opt-in, non-interactive runs only).
26
+ - **Shorter interactive-menu labels** (details moved to each choice's
27
+ description).
28
+ - **Smaller published package (~206 kB → ~73 kB packed; 808 kB → ~220 kB
29
+ unpacked).** The build no longer ships a source map (it was ~60% of the
30
+ package; re-enable ad hoc with `tsup --sourcemap`) and now minifies the single
31
+ bundled binary (`dist/bin/eds.js` 265 kB → ~170 kB).
32
+
33
+ ### Fixed
34
+ - **Block preview blank-screen cases.** The harness now (a) reduces a full-HTML
35
+ `_<name>.preview.html` mock to its `<body>` contents, (b) reveals the body past
36
+ the EDS `body.appear` visibility gate (which `scripts.js` would normally flip),
37
+ and (c) loads the block script via a defensive dynamic `import()` so a bad
38
+ import (e.g. a missing `scripts/*.js`) shows the authored markup instead of a
39
+ blank frame. The prompt now requires a bare preview fragment and self-contained
40
+ block JS.
41
+ - **`eds block preview header|footer`** now warns that these are page chrome and
42
+ can't render standalone (they fetch the nav/footer fragment and need the full
43
+ page runtime).
44
+ - Removed the dangling `main`/`types` fields that pointed at a never-built
45
+ `dist/index.js` (a bare `import "aem-eds-kit"` would have failed) - the package
46
+ is a CLI, exposed via its `bin`.
47
+
9
48
  ### Added
49
+ - **`eds block preview` with no name → a live gallery of every content block**,
50
+ each in its own width-honest iframe. Routes are computed per request, so a
51
+ block generated while the gallery is open appears on the next reload
52
+ (header/footer are skipped - page chrome can't render standalone). New
53
+ `buildGallery` + a dynamic request handler on the preview server.
54
+ - **`block from-design` accepts a local SVG/PNG export** (`eds block from-design
55
+ ./hero.svg`) - reads the design straight from disk, no network and no MCP.
56
+ - **Figma REST path** via a Personal Access Token (`FIGMA_TOKEN` env or
57
+ `figma.token` config, scope `file_content:read`) - a quota separate from the
58
+ MCP tool-call limit. New flags `--mcp` (force MCP) and `--refresh` (ignore the
59
+ cache).
60
+ - **`block from-design` records the design's frame widths** in the block's
61
+ `.eds-meta.json` (`breakpoints`), so `eds block preview` is width-honest at the
62
+ **real design widths**, not a fixed device set. The agent writes the widths it
63
+ reads from the design (prompt instruction), `--widths 390,768,1440` overrides,
64
+ and 375/768/1280 remains the fallback. New `src/lib/figma/breakpoints.ts`
65
+ (`parseWidths` / `normalizeBreakpoints`), extended `edsMetaSchema`.
10
66
  - **`eds init` writes a local-dev `.env` + `xwalk.json` by default.** `.env`
11
67
  carries the `aem up` config (`AEM_OPEN=/`, `AEM_PORT=3007`, `AEM_PAGES_URL`
12
68
  prefilled from the git remote); it's never overwritten and always gitignored.
package/README.md CHANGED
@@ -268,11 +268,21 @@ The generated `_<name>.json` uses the EDS block-plugin (xwalk) format (`definiti
268
268
 
269
269
  Translates a design - **Figma, Google Stitch, Canva, Sketch or Framer** - into an EDS block. Run with **no URL** for a step-by-step wizard (design source, name, link, content source, UE model, screenshot, run mode). It builds a prompt with EDS conventions + your project's design tokens and hands it to your AI agent (Claude Code, Cursor, or Codex). *(This was `from-figma` before it went design-agnostic; Figma is the most battle-tested source and stays pixel-perfect.)*
270
270
 
271
- The agent reads the design through its MCP connection (for Figma: `get_design_context`, `get_variable_defs`, `get_screenshot`), generates pixel-perfect code (JS + CSS) **and its Universal Editor model** by default, uses lightweight **placeholders** for not-yet-authored content (so the block is visible before Universal Editor takes over), then self-verifies. You see a **live, colour-coded log** with per-phase timings, and on success the **live preview starts automatically**.
271
+ **Fetch → cache → generate.** `eds` resolves the design **once** into a snapshot, then the agent generates from it — so retries and refine passes never re-fetch. It picks the cheapest source automatically:
272
+
273
+ 1. **Local file** — pass a path to an SVG/PNG export (`eds block from-design ./hero.svg`) → read from disk, no network.
274
+ 2. **Cache** — a snapshot already fetched for this file/node (`tmp/eds-cli/design-cache/`) is reused.
275
+ 3. **Figma REST** — if a Figma token is set, `eds` fetches the node itself and embeds a compact design spec. Separate, generous quota; **does not touch the MCP limit**.
276
+ 4. **Figma MCP** — fallback: the agent makes **one** `get_design_context` call and caches it.
277
+
278
+ The agent then generates pixel-perfect code (JS + CSS) **and its Universal Editor model** by default, with lightweight **placeholders** for not-yet-authored content. You see a **live, colour-coded log** with per-phase timings. On success you get a **menu** — refine the block with another pass, open the live preview, or finish (preview is **opt-in**, never auto-launched).
279
+
280
+ > **Figma MCP limits:** the Dev Mode MCP server is metered per plan (Starter / View / Collab seats: ~6–20 **tool calls a month**). `eds` uses **one** MCP call per block and caches it; set a Figma token to skip MCP entirely via REST. See [How Figma integration works](#how-figma-integration-works).
272
281
 
273
282
  ```bash
274
283
  eds block from-design # interactive wizard
275
- eds block from-design "<figma-url>" --name hero # non-interactive
284
+ eds block from-design "<figma-url>" --name hero # non-interactive (REST if a token is set, else MCP)
285
+ eds block from-design ./hero.svg --name hero # from a local export (no network)
276
286
  eds block from-design "<figma-url>" --dry-run # just build the prompt
277
287
  ```
278
288
 
@@ -280,13 +290,20 @@ eds block from-design "<figma-url>" --dry-run # just build the prompt
280
290
  |---|---|
281
291
  | `--name <name>` | Override the inferred block name |
282
292
  | `--source <type>` | Content source: `document` \| `ue` \| `cf` \| `mixed` |
293
+ | `--widths <list>` | Design frame widths for preview breakpoints (e.g. `390,768,1440`) |
283
294
  | `--agent <type>` | Force `claude` \| `cursor` \| `codex` \| `none` |
284
295
  | `--dry-run` | Build the prompt only |
285
296
  | `--no-ue-model` | Skip the Universal Editor model |
286
- | `--no-screenshot` | Skip the screenshot (fewer tokens; structural verification) |
287
- | `--no-serve` | Don't auto-start the live preview |
297
+ | `--screenshot` | Add a screenshot MCP call for a pixel check (opt-in — costs a call) |
298
+ | `--mcp` | Force the Figma MCP adapter even when a REST token is set |
299
+ | `--refresh` | Ignore the cached snapshot and re-fetch |
300
+ | `--serve` | Auto-start the live preview (non-interactive runs only) |
288
301
  | `--yes` | Skip confirmation prompts |
289
302
 
303
+ Set a **Figma Personal Access Token** (scope `file_content:read`) to use the REST path — via `FIGMA_TOKEN` env or `figma.token` in config. The block generation model defaults to the fastest (Haiku); override with `model` in config.
304
+
305
+ The generated block records the **design's frame widths** in its `.eds-meta.json` (`breakpoints`), so `eds block preview` shows it at the real design widths rather than a fixed device set. The agent writes the widths it reads from the design; `--widths` overrides them, and 375/768/1280 is only the fallback.
306
+
290
307
  **Supported Figma URL formats:**
291
308
  - `figma.com/design/:fileKey/:name?node-id=...`
292
309
  - `figma.com/file/:fileKey/:name?node-id=...` (legacy)
@@ -310,12 +327,15 @@ eds block list
310
327
  eds block list --json # machine-readable output
311
328
  ```
312
329
 
313
- ### `eds block preview <name>`
330
+ ### `eds block preview [name]`
331
+
332
+ Serves a **live, breakpoint-switchable preview** in your browser - no build, no files written to your project (the harness is served from memory). A dropdown switches widths inside a width-honest iframe, and **edits live-reload** the browser (the server watches the block folder).
314
333
 
315
- Serves a **live, breakpoint-switchable preview** of a block in your browser - no build, no files written to your project (the harness is served from memory). A dropdown switches widths inside an iframe, and **edits live-reload** the browser (the server watches the block folder).
334
+ Run it **with no name** for a **gallery** of every content block, each in its own iframe. Routes are computed per request, so a block generated while the gallery is open **appears on the next reload** (header/footer are skipped — they're page chrome and can't render standalone).
316
335
 
317
336
  ```bash
318
- eds block preview hero
337
+ eds block preview # gallery of all blocks
338
+ eds block preview hero # a single block
319
339
  eds block preview hero --widths 375,768,1280 # custom breakpoints
320
340
  eds block preview hero --port 9000 --no-open
321
341
  ```
@@ -446,23 +466,26 @@ The vendored framework (`scripts/aem.js` / `lib-franklin.js`) is never flagged.
446
466
 
447
467
  ## How Figma integration works
448
468
 
449
- You don't need a Figma API token. `aem-eds-kit` never talks to Figma directly - it writes a focused prompt and hands it to the AI agent you already use, which has its own Figma MCP connection. The agent reads the design and writes the files; `eds` orchestrates the handoff and checks the result.
469
+ The design is fetched **once** into a cached snapshot, then the agent generates from it. Separating the fetch from the generation means retries and refine passes never re-fetch, and the snapshot is inspectable (`tmp/eds-cli/design-cache/`). `eds` picks the cheapest adapter available:
450
470
 
451
471
  ```
452
- ┌──────────┐ prompt ┌─────────────┐ MCP calls ┌───────────┐
453
- │ eds-cli │ ──────────────→ │ Claude Code │ ──────────────→ │ Figma MCP │
454
- │ │ │ / Cursor │ ←────────────── │ Server │
455
- │ │ ←────────────── │ / Codex │ design data └───────────┘
456
- │ │ block files └─────────────┘
457
- └──────────┘
472
+ ┌─ local SVG/PNG ─┐
473
+ ├─ cache hit ──────┤ design.json ┌─────────────┐ block files
474
+ design reference ──┼─ Figma REST ─────┼───→ (cached) ───────→│ Claude Code │ ───────────────→ repo
475
+ (url / file) └─ Figma MCP ──────┘ snapshot │ /Cursor/Codex│
476
+ (1 call, agent dumps to cache) └─────────────┘
458
477
  ```
459
478
 
479
+ - **No token needed** for the MCP path — the agent uses its own Figma MCP connection and makes **one** `get_design_context` call per block (then caches it).
480
+ - **Set a Figma token** (`FIGMA_TOKEN` or `figma.token`) to use the **REST** path instead: `eds` fetches the node over HTTPS and embeds a compact spec — a **separate, far larger quota** than the MCP limit, so it works comfortably on Starter / Collab seats.
481
+ - **Local export** (`./file.svg|png`) reads straight from disk — zero network, best for vector/text-heavy frames.
482
+
460
483
  The prompt includes:
461
- - Figma file key and node ID to fetch
462
- - EDS block conventions (`decorate(block)`, vanilla JS, semantic HTML, full-width/mobile-first)
484
+ - The design data (embedded spec, local file, or a single-call MCP fetch) for the target node
485
+ - EDS block conventions (`decorate(block)`, vanilla JS, semantic HTML, full-width/mobile-first, self-contained JS)
463
486
  - CSS custom properties from your `styles/styles.css`
464
- - Universal Editor model generation (fields mapped from Figma layers/variants) - on by default
465
- - Lighthouse performance requirements + pixel-perfect self-verification
487
+ - Universal Editor model generation (fields mapped from design layers/variants) - on by default
488
+ - Lighthouse performance requirements + a single structural self-verification pass
466
489
  - Output file structure
467
490
 
468
491
  ## Configuration
@@ -472,9 +495,12 @@ Priority: CLI flags → env vars → `.edsrc.json` (project) → `~/.eds/config.
472
495
  **`~/.eds/config.json`** (created by `eds figma setup`):
473
496
  ```json
474
497
  {
475
- "agent": "claude"
498
+ "agent": "claude",
499
+ "model": "haiku",
500
+ "figma": { "token": "figd_…" }
476
501
  }
477
502
  ```
503
+ `model` sets the block-generation model (default: fastest / Haiku). `figma.token` (or the `FIGMA_TOKEN` env var) enables the REST fetch path — a Personal Access Token with scope `file_content:read`. Tokens are secrets; keep them out of the repo.
478
504
 
479
505
  **`.edsrc.json`** (project root, optional):
480
506
  ```json