aem-eds-kit 0.4.25 → 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
@@ -7,17 +7,56 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
  ## [Unreleased]
8
8
 
9
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).
10
28
  - **Smaller published package (~206 kB → ~73 kB packed; 808 kB → ~220 kB
11
29
  unpacked).** The build no longer ships a source map (it was ~60% of the
12
30
  package; re-enable ad hoc with `tsup --sourcemap`) and now minifies the single
13
31
  bundled binary (`dist/bin/eds.js` 265 kB → ~170 kB).
14
32
 
15
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).
16
44
  - Removed the dangling `main`/`types` fields that pointed at a never-built
17
45
  `dist/index.js` (a bare `import "aem-eds-kit"` would have failed) - the package
18
46
  is a CLI, exposed via its `bin`.
19
47
 
20
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).
21
60
  - **`block from-design` records the design's frame widths** in the block's
22
61
  `.eds-meta.json` (`breakpoints`), so `eds block preview` is width-honest at the
23
62
  **real design widths**, not a fixed device set. The agent writes the widths it
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
 
@@ -284,10 +294,14 @@ eds block from-design "<figma-url>" --dry-run # just build the prompt
284
294
  | `--agent <type>` | Force `claude` \| `cursor` \| `codex` \| `none` |
285
295
  | `--dry-run` | Build the prompt only |
286
296
  | `--no-ue-model` | Skip the Universal Editor model |
287
- | `--no-screenshot` | Skip the screenshot (fewer tokens; structural verification) |
288
- | `--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) |
289
301
  | `--yes` | Skip confirmation prompts |
290
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
+
291
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.
292
306
 
293
307
  **Supported Figma URL formats:**
@@ -313,12 +327,15 @@ eds block list
313
327
  eds block list --json # machine-readable output
314
328
  ```
315
329
 
316
- ### `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).
317
333
 
318
- 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).
319
335
 
320
336
  ```bash
321
- eds block preview hero
337
+ eds block preview # gallery of all blocks
338
+ eds block preview hero # a single block
322
339
  eds block preview hero --widths 375,768,1280 # custom breakpoints
323
340
  eds block preview hero --port 9000 --no-open
324
341
  ```
@@ -449,23 +466,26 @@ The vendored framework (`scripts/aem.js` / `lib-franklin.js`) is never flagged.
449
466
 
450
467
  ## How Figma integration works
451
468
 
452
- 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:
453
470
 
454
471
  ```
455
- ┌──────────┐ prompt ┌─────────────┐ MCP calls ┌───────────┐
456
- │ eds-cli │ ──────────────→ │ Claude Code │ ──────────────→ │ Figma MCP │
457
- │ │ │ / Cursor │ ←────────────── │ Server │
458
- │ │ ←────────────── │ / Codex │ design data └───────────┘
459
- │ │ block files └─────────────┘
460
- └──────────┘
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) └─────────────┘
461
477
  ```
462
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
+
463
483
  The prompt includes:
464
- - Figma file key and node ID to fetch
465
- - 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)
466
486
  - CSS custom properties from your `styles/styles.css`
467
- - Universal Editor model generation (fields mapped from Figma layers/variants) - on by default
468
- - 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
469
489
  - Output file structure
470
490
 
471
491
  ## Configuration
@@ -475,9 +495,12 @@ Priority: CLI flags → env vars → `.edsrc.json` (project) → `~/.eds/config.
475
495
  **`~/.eds/config.json`** (created by `eds figma setup`):
476
496
  ```json
477
497
  {
478
- "agent": "claude"
498
+ "agent": "claude",
499
+ "model": "haiku",
500
+ "figma": { "token": "figd_…" }
479
501
  }
480
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.
481
504
 
482
505
  **`.edsrc.json`** (project root, optional):
483
506
  ```json