jfs-components 0.1.35 → 0.1.36

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
@@ -4,6 +4,20 @@ All notable changes to this project are documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
6
 
7
+ ## [0.1.34] - 2026-07-21
8
+
9
+ - `jfs-extract-modes` now automatically loads `FIGMA_ACCESS_TOKEN` from the
10
+ consuming project's root `.env` without overriding a token exported in the
11
+ shell. `dotenv` is now an explicit runtime dependency.
12
+ - Simplified `D2C.md` for use as a Cursor slash command: clearer input handling,
13
+ ancestor-mode inheritance (`inheritedFromAncestors` + path merges), accurate
14
+ `unresolved` reasons, verify-before-invent component APIs, and practical
15
+ visual QA (fix implementation diffs; report environment-only diffs).
16
+ - Added focused tests for `.env` precedence and extracted mode diagnostics.
17
+ - Ignore local `.env` / `.env.*` secrets in git (keep `.env.example` allowed).
18
+
19
+ ---
20
+
7
21
  ## [0.1.33] - 2026-07-20
8
22
 
9
23
  - **Use [`D2C.md`](./D2C.md) for Design-to-Code.** This is the playbook we want agents and consumers to follow when implementing a Figma screen with `jfs-components`. It ships in the npm package (see `package.json` `files`) so it is available at `node_modules/jfs-components/D2C.md` after install. The workflow is mandatory end-to-end: Figma MCP (`get_design_context` + `get_screenshot`) → mode extraction via `npx jfs-extract-modes` (REST API; Dev seat / file-read token is enough) → build with exact modes → visual QA against the Figma screenshot. Point Cursor rules / agent instructions at this file rather than inventing a parallel D2C process.
package/D2C.md CHANGED
@@ -1,118 +1,113 @@
1
- # D2C — Design to Code (jfs-components)
1
+ # D2C — Design to Code with jfs-components
2
2
 
3
- You are implementing a screen from a Figma design using the `jfs-components`
4
- library. The user has pasted a Figma link. Follow this workflow exactly, in
5
- order. Do not skip steps and do not improvise substitutes for them.
3
+ Implement the supplied Figma design using the installed `jfs-components`
4
+ package. Follow all four stages in order.
6
5
 
7
- ## Step 1 — Pull the design through the Figma MCP
6
+ ## Input
8
7
 
9
- Extract `fileKey` and `nodeId` from the pasted URL
10
- (`https://www.figma.com/design/<fileKey>/...?node-id=<a>-<b>` nodeId is
11
- `<a>:<b>`).
8
+ Use the Figma URL supplied after `/D2C` or in the user's latest message. If no
9
+ Figma URL was supplied, ask for one before doing anything else.
12
10
 
13
- 1. Call `get_design_context` for the node. This gives you the component
14
- structure, layout, props, variants, text content, and Code Connect hints.
15
- 2. Call `get_screenshot` for the same node and keep the image. This is the
16
- visual ground truth you will QA against in Step 4.
11
+ ## 1. Read the design
17
12
 
18
- The Figma MCP gives you almost everything — except one thing: the **variable
19
- modes explicitly set on each layer**. Those are invisible to the MCP and they
20
- change how components render (size, emphasis, appearance, color mode, etc.).
21
- That is what Step 2 is for.
13
+ 1. Call the Figma MCP `get_design_context` for the linked node.
14
+ 2. Call `get_screenshot` for the same node. Keep it as the visual reference for
15
+ final QA.
16
+ 3. Follow Code Connect mappings, design annotations, and provided assets. If
17
+ Figma supplies an image or SVG URL, use it directly; do not create a
18
+ placeholder or install an icon package.
22
19
 
23
- ## Step 2 Extract the modes (mandatory, never skip)
20
+ If the Figma MCP is unavailable or cannot read the node, report the blocker and
21
+ stop. Do not recreate the design from the URL or from assumptions.
24
22
 
25
- Run the mode extractor that ships with this package. It needs a Figma personal
26
- access token with plain file-read access (a view-only / Dev seat token works;
27
- no Enterprise scopes, no edit access):
23
+ ## 2. Extract and resolve explicit modes
24
+
25
+ From the consuming project's root, run:
28
26
 
29
27
  ```bash
30
- export FIGMA_ACCESS_TOKEN=figd_...
31
- npx jfs-extract-modes "<the pasted Figma URL>" --out modes.json
28
+ npx jfs-extract-modes "<figma-url>" --out modes.json
32
29
  ```
33
30
 
34
- If `npx` cannot find the bin (e.g. unusual monorepo setup), call the script by
35
- its path inside the installed package:
31
+ The CLI automatically loads `FIGMA_ACCESS_TOKEN` from the project-root `.env`.
32
+ An already exported shell value takes precedence. The token only needs the
33
+ Figma `file_content:read` scope. Never print, log, or ask the user to paste the
34
+ token into chat.
36
35
 
37
- ```bash
38
- node node_modules/jfs-components/scripts/extract-figma-modes.js "<figma-url>" --out modes.json
39
- ```
36
+ If the token is missing, stop and direct the user to `[Open .env](.env)` and
37
+ add `FIGMA_ACCESS_TOKEN=` if needed. To create a token: in Figma's file browser,
38
+ open the account menu → **Settings** → **Security** → **Personal access
39
+ tokens** → **Generate new token**, choose an expiration, grant only
40
+ `file_content:read`, generate it, and copy it immediately into `.env`. Figma
41
+ shows the value only once. Use the
42
+ [official PAT documentation](https://developers.figma.com/docs/rest-api/personal-access-tokens/)
43
+ if the UI has changed. Never create or overwrite a token value yourself.
40
44
 
41
- The output is a flat list one entry per layer that has explicit modes:
45
+ If the bin is unavailable in a nonstandard monorepo, run:
42
46
 
43
- ```json
44
- {
45
- "modes": [
46
- { "layer": "Icon Button", "nodeId": "1:10638",
47
- "path": "CC / Unsub > AppBar > Slot 2 > Icon Button",
48
- "modes": { "Button / Size": "S", "Emphasis": "Low", "AppearanceBrand": "Neutral" } }
49
- ]
50
- }
47
+ ```bash
48
+ node node_modules/jfs-components/scripts/extract-figma-modes.js "<figma-url>" --out modes.json
51
49
  ```
52
50
 
53
- Rules for using it:
51
+ Resolve the effective modes for each represented component as follows:
54
52
 
55
- - Children inherit ancestor modes unless they set their own. To get the
56
- effective modes of any layer, merge every entry whose `path` is a prefix of
57
- that layer's path, top-down.
58
- - Correlate entries with the Figma MCP structure by layer name and position;
59
- use `nodeId` when two layers share a name.
60
- - If the output contains an `unresolved` array, STOP and report it to the user
61
- before building. It means the packaged variables JSON is out of date and the
62
- screen cannot be built faithfully. Do not guess missing modes.
53
+ 1. Start with `inheritedFromAncestors`, when present.
54
+ 2. Find every `modes` entry whose `path` is the component's path or an ancestor
55
+ of it.
56
+ 3. Merge those entries from root to leaf; deeper entries override inherited
57
+ values.
58
+ 4. Match by layer name and position, using `nodeId` to disambiguate duplicate
59
+ names.
63
60
 
64
- ## Step 3 Build the screen
61
+ If `unresolved` is present, report every item and its exact `reason`, then stop
62
+ before implementation because mode fidelity cannot be guaranteed:
65
63
 
66
- Implement with `jfs-components` components, mapping Figma component names to
67
- library exports.
64
+ - `local collection` means the design uses a file-local collection that the
65
+ packaged library data cannot resolve.
66
+ - `key not in variables JSON` or `mode not in collection` means the packaged
67
+ design-token JSON is out of date.
68
68
 
69
- **Modes are non-negotiable.** Apply every extracted mode exactly as given —
70
- collection name → mode name, on exactly the layer (or subtree) the extractor
71
- reported. There is zero tolerance for inconsistency here:
69
+ Do not guess or silently omit an unresolved mode.
72
70
 
73
- - Do not substitute a "close enough" mode (`Emphasis: Medium` is not
74
- `Emphasis: Low`).
75
- - Do not drop modes that seem redundant — if the design sets
76
- `AppearanceBrand: Neutral` on one Icon Button and `Appearance: Primary` on
77
- another, those are different and intentional.
78
- - Do not apply a child's modes to its parent or vice versa.
71
+ ## 3. Implement
79
72
 
80
- For everything else (spacing, order, text, icons, variants, props), follow the
81
- Figma MCP output one-to-one. Reuse existing screens in the consuming app as
82
- convention references for file placement, navigation registration, and asset
83
- handling.
73
+ Before editing, inspect the installed package's exports/types and the consuming
74
+ app's existing screens. Reuse its file placement, navigation, styling, and
75
+ asset conventions. Never invent a `jfs-components` component or prop.
84
76
 
85
- ## Step 4 QA against the design (mandatory, never skip)
77
+ - Prefer mapped `jfs-components` over rebuilding them from primitives.
78
+ - Apply extracted collection/mode pairs exactly through each component's
79
+ `modes` prop.
80
+ - Put a mode on the closest code component that represents the reported Figma
81
+ layer or subtree. Preserve parent inheritance and child overrides; never
82
+ flatten a child override into its parent.
83
+ - Do not substitute similar-looking modes, remove apparently redundant modes,
84
+ or move modes between layers.
85
+ - Match Figma content, order, visibility, variants, spacing, and assets.
86
86
 
87
- After the screen compiles and renders, you MUST verify it visually against the
88
- Step 1 screenshot:
87
+ Run the consuming app's existing typecheck, tests, or build command relevant to
88
+ the changed screen and fix implementation errors.
89
89
 
90
- - **Native app:** use the mobile MCP — launch the app, navigate to the new
91
- screen, and take a screenshot (`mobile_take_screenshot`).
92
- - **Web deployment:** use the browser tooling — navigate to the deployed/dev
93
- URL and take a screenshot.
90
+ ## 4. Render and visually verify
94
91
 
95
- Compare your screenshot with the Figma screenshot side by side. Check:
92
+ Render the implemented screen on the target platform and capture it with the
93
+ available mobile or browser tooling. Compare it with the Figma screenshot for:
96
94
 
97
- 1. Component sizes and emphasis levels (these are where wrong modes show up)
98
- 2. Colors / appearance (brand vs neutral vs secondary treatments)
99
- 3. Spacing, padding, and gaps
100
- 4. Text content and truncation
101
- 5. Icon choices and visibility (some layers in the design are hidden)
95
+ 1. component size, variant, and emphasis;
96
+ 2. color and appearance;
97
+ 3. spacing, padding, alignment, and gaps;
98
+ 4. text, wrapping, and truncation; and
99
+ 5. icons, imagery, and layer visibility.
102
100
 
103
- If there is ANY visible difference, fix it and re-screenshot. Repeat until the
104
- implementation matches the design. Typical root causes, in order of
105
- likelihood: a mode applied to the wrong layer, a missing mode (falling back to
106
- the collection default), a wrong variant, a wrong icon.
101
+ Fix every implementation-caused difference and capture the screen again.
102
+ Platform or environment differences that cannot be fixed in code, such as a
103
+ missing system font or renderer-specific antialiasing, must be identified
104
+ explicitly rather than hidden.
107
105
 
108
- ## Summary contract
106
+ If no suitable render or screenshot tooling is available, do not claim visual
107
+ completion. Report what remains to be checked and give the exact manual run and
108
+ comparison steps.
109
109
 
110
- | Step | Tool | Skippable? |
111
- |---|---|---|
112
- | Design context + screenshot | Figma MCP | No |
113
- | Mode extraction | `npx jfs-extract-modes` | No |
114
- | Build | jfs-components | — |
115
- | Visual QA loop | Mobile MCP or browser | No |
110
+ ## Completion report
116
111
 
117
- Report back to the user with: the screen file(s) created, the modes applied per
118
- layer, and the final QA screenshot comparison.
112
+ Report the files changed, the effective modes applied to each component, the
113
+ validation commands and results, and the final visual comparison status.