figma-json-tree 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +79 -60
  2. package/package.json +9 -1
package/README.md CHANGED
@@ -1,24 +1,21 @@
1
1
  # figma-json-tree
2
2
 
3
- Figma JSON 다운로드하고, 선택자로 트리를 탐색하여 디자인 IR·Tailwind v4 IR·HTML로 변환하는 TypeScript 라이브러리입니다.
3
+ A TypeScript library for downloading Figma JSON, querying design trees with CSS-like selectors, and converting subtrees into extensible design IR, Tailwind v4 IR, and HTML fragments.
4
4
 
5
- ## 시작하기
5
+ ## Getting started
6
6
 
7
- Node.js **22.12 이상**, npm을 사용합니다. 저장소에서 다음 명령으로 개발 환경을 준비합니다.
7
+ Requires **Node.js 22.12 or later**. The package provides ESM modules and TypeScript declarations.
8
8
 
9
9
  ```sh
10
- npm install
11
- npm run check
10
+ npm install figma-json-tree
12
11
  ```
13
12
 
14
- ESM과 TypeScript 선언 파일을 빌드합니다. 코어와 다운로드 클라이언트는 현대 브라우저에서도 사용할 수 있으며, 브라우저에 비밀 토큰을 포함하지 않고 서버에서 다운로드한 JSON을 전달하는 구성을 권장합니다.
15
-
16
13
  ```ts
17
14
  import { FigmaTree } from 'figma-json-tree'
18
15
  import { FigmaClient } from 'figma-json-tree/figma-json-fetch'
19
16
 
20
17
  const client = new FigmaClient({ token: process.env.FIGMA_TOKEN! })
21
- const figmaJson = await client.getFile(fileKey)
18
+ const figmaJson = await client.getFile('YOUR_FIGMA_FILE_KEY')
22
19
  const figma = FigmaTree.fromJson(figmaJson)
23
20
 
24
21
  const searchFilter = figma.query('FRAME[name="SearchFilter"]')
@@ -31,15 +28,17 @@ const table = figma
31
28
 
32
29
  const subtrees = figma
33
30
  .queryAll({ name: /^ToBe/ })
34
- .map(node => node.toJSON()) // 원본 노드 + 전체 children
31
+ .map(node => node.toJSON()) // Original node JSON, including all descendants
35
32
 
36
33
  const ir = searchFilter?.toIR()
37
34
  const tailwindIR = ir?.toTailwind()
38
35
  ```
39
36
 
40
- `fromJson`은 파싱된 파일 전체 응답, `/nodes` 응답, 단일 노드를 받습니다. 다운로드와 파싱을 분리하므로 로컬 JSON도 그대로 사용할 있습니다. 일치하지 않으면 `query`는 `undefined`, `queryAll`은 배열을 반환합니다.
37
+ `FigmaTree.fromJson()` accepts a parsed full-file API response, a `/nodes` API response, or a single Figma node. Downloading and parsing are separate, so you can also use local JSON. When nothing matches, `query()` returns `undefined` and `queryAll()` returns an empty array.
41
38
 
42
- ## 정규식과 선택자
39
+ The core library and download client also work in modern browsers. Keep private Figma tokens on the server and pass downloaded JSON to browser applications.
40
+
41
+ ## Selectors and regular expressions
43
42
 
44
43
  ```ts
45
44
  figma.queryAll({ name: /^ToBe/i, type: 'FRAME' })
@@ -48,11 +47,15 @@ figma.queryAll('FRAME > INSTANCE[visible=true]')
48
47
  figma.queryAll('FRAME[name="ProductPage"] TEXT')
49
48
  ```
50
49
 
51
- 타입, 속성 존재, 일치·포함·접두·접미, 복수 조건, 자손과 직계 자식 선택자를 지원합니다. 정규식은 객체 조건에서 JavaScript `RegExp`로 전달합니다. 검색은 `children`만 따라가며, 결과는 깊이 우선 전위 순서입니다. 노드의 `query`는 자신을 제외한 자손만 검색하고 scope 밖의 조상을 참조하지 않습니다.
50
+ Selectors support node types, attribute existence, exact matches, substring/prefix/suffix matches, multiple conditions, descendants, and direct children. Pass JavaScript `RegExp` values through object selectors for regular expression matching.
51
+
52
+ Search follows `children` in depth-first preorder. Queries on a node search its descendants, excluding the node itself, and cannot reference ancestors outside that subtree.
52
53
 
53
- 자세한 문법과 반환 계약은 [API 문서](docs/api.md) 참고하세요.
54
+ See the [API documentation](docs/api.md) for selector syntax and return contracts.
54
55
 
55
- ## IR 플러그인
56
+ ## IR plugins
57
+
58
+ Customize the intermediate representation before converting it to Tailwind IR or HTML.
56
59
 
57
60
  ```ts
58
61
  import { FigmaTree, type IRPlugin } from 'figma-json-tree'
@@ -72,101 +75,117 @@ const tree = FigmaTree.fromJson(figmaJson, { irPlugins: [semanticPlugin] })
72
75
  const result = tree.query('INSTANCE')?.toIR().toTailwind()
73
76
  ```
74
77
 
75
- 자식 변환 부모를 처리합니다. 노드에서 기본 변환, 등록 플러그인, `toIR({ plugins })`의 호출별 플러그인을 순서대로 적용합니다. 플러그인은 읽기 전용 IR 받아 표준 IR 필드를 교체하거나 JSON `extensions`를 추가합니다.
78
+ Children are converted before their parent. For each node, the pipeline applies the default conversion, registered plugins, and per-call plugins supplied through `toIR({ plugins })`, in that order. Plugins receive read-only IR and return a node with updated standard fields or JSON-compatible `extensions`.
76
79
 
77
- [IR·플러그인·Tailwind 문서](docs/ir.md) 지원 속성, 확장 계약, CSS 연결 방법을 정리했습니다.
80
+ See [IR, plugins, and Tailwind](docs/ir.md) for supported properties, plugin contracts, and CSS integration.
78
81
 
79
- ## 다운로드 CLI
82
+ ## Download CLI
80
83
 
81
- 환경에 `FIGMA_TOKEN`을 설정한 실행합니다. 토큰 값을 인자나 파일에 넣을 필요는 없습니다.
84
+ Set the `FIGMA_TOKEN` environment variable before downloading. The CLI reads the token from the environment.
82
85
 
83
86
  ```sh
84
- npm run build
85
- node dist/cli/index.js download --file FILE_KEY --out figma.json
86
- node dist/cli/index.js download --file FILE_KEY --nodes 49:7390 --out nodes.json
87
+ figma-json-tree download --file FILE_KEY --out figma.json
88
+ figma-json-tree download --file FILE_KEY --nodes 49:7390 --out nodes.json
87
89
  ```
88
90
 
89
- 설치된 패키지에서는 `figma-json-tree download ...`로 실행합니다. `--out`이 없으면 JSON을 stdout으로 출력합니다. 기존 파일은 `--force`가 있어야 덮어씁니다. URL의 `node-id=49-7390`은 API 형식인 `49:7390`으로 전달합니다.
91
+ When working from this repository, run `npm run build` and replace `figma-json-tree` with `node dist/cli/index.js`. You can also invoke the installed package with `npx figma-json-tree`.
90
92
 
91
- ## 검색 CLI
93
+ Without `--out`, JSON is written to stdout. Use `--force` to overwrite an existing file. Convert a URL node ID such as `node-id=49-7390` to the API format `49:7390`.
92
94
 
93
- 로컬 JSON을 `query` 또는 `queryAll`로 검색합니다. 토큰이나 네트워크 요청이 필요하지 않습니다.
95
+ ## Query CLI
96
+
97
+ Search local JSON with `query` or `queryAll`. These commands require no token or network access.
94
98
 
95
99
  ```sh
96
- # 번째 Hover Card Frame과 전체 자식 추출
97
- node dist/cli/index.js query --input artifacts/live/file.json \
100
+ # Extract the first Hover Card frame and all its descendants
101
+ figma-json-tree query --input figma.json \
98
102
  --selector 'FRAME[name="Hover Card"]' --out hover-card.json
99
103
 
100
- # 이름이 Hover Card인 모든 노드 추출
101
- node dist/cli/index.js queryAll --input artifacts/live/file.json \
104
+ # Extract every node named Hover Card
105
+ figma-json-tree queryAll --input figma.json \
102
106
  --selector '[name="Hover Card"]'
103
107
 
104
- # JavaScript 정규식으로 이름 검색
105
- node dist/cli/index.js queryAll --input artifacts/live/file.json \
108
+ # Match names with a JavaScript regular expression
109
+ figma-json-tree queryAll --input figma.json \
106
110
  --name-regex '^ToBe' --regex-flags i
107
111
 
108
- # 추출한 단일 subtree에서 다시 검색
109
- node dist/cli/index.js queryAll --input hover-card.json --selector TEXT
112
+ # Query an extracted subtree again
113
+ figma-json-tree queryAll --input hover-card.json --selector TEXT
110
114
  ```
111
115
 
112
- 설치된 패키지는 `node dist/cli/index.js` 대신 `figma-json-tree`로 실행합니다. `query`는 원본 노드 객체 하나 또는 `null`, `queryAll`은 원본 노드 배열 또는 `[]`를 출력합니다. 일치 없음은 정상 종료(0)이며 오류는 stderr 종료 코드 1로 전달합니다.
116
+ `query` writes one original node object or `null`. `queryAll` writes an array of original nodes or `[]`. No match is a successful result with exit code 0; errors are written to stderr with exit code 1.
117
+
118
+ Specify exactly one of `--selector` and `--name-regex`. Supply regular expressions without `/…/` delimiters and use `--regex-flags` for flags. `--out` and `--force` behave as they do for downloads.
113
119
 
114
- `--selector`와 `--name-regex` 하나를 지정합니다. 정규식은 `/…/`로 감싸지 않고 패턴만 전달하며 플래그는 `--regex-flags`에 지정합니다. `--out`과 `--force`는 다운로드와 동일하게 동작합니다. 파일·노드 API 응답 또는 단일 subtree를 입력받으며 `queryAll` 결과 배열 자체를 재입력하는 기능은 제공하지 않습니다.
120
+ Input can be a file API response, a nodes API response, or a single subtree. Arrays produced by `queryAll` cannot be passed directly back as input.
115
121
 
116
- ## HTML 출력
122
+ ## HTML output
117
123
 
118
- 별도 `figma-html` 모듈에서 표준 IR 또는 Tailwind IR HTML 조각으로 변환합니다.
124
+ The separate `figma-html` module renders standard IR or Tailwind IR as HTML fragments.
119
125
 
120
126
  ```ts
121
- import { renderHTML } from 'figma-json-tree/figma-html'
127
+ import { renderHTML, collectTailwindClasses } from 'figma-json-tree/figma-html'
122
128
 
123
129
  const frame = figma.query('FRAME[name="Hover Card"]')!
124
- const html = renderHTML(frame.toIR()) // inline CSS
125
- const tailwindHTML = renderHTML(frame.toIR().toTailwind()) // class + 잔여 inline CSS
130
+ const html = renderHTML(frame.toIR()) // Inline CSS
131
+ const tailwindIR = frame.toIR().toTailwind()
132
+ const tailwindHTML = renderHTML(tailwindIR) // Classes and residual inline CSS
133
+ const classes = collectTailwindClasses(tailwindIR)
126
134
  ```
127
135
 
128
- 라이브러리와 CLI 모두 **body 내부에 삽입할 마크업만** 출력합니다. `doctype`, `html`, `head`, `body`, `style`, `script` 태그는 생성하지 않습니다. Tailwind 모드는 클래스와 잔여 inline 스타일을 출력하며 CSS 빌드는 사용하는 프로젝트에서 처리합니다.
136
+ Both the library and CLI output **only the markup to insert inside a body**. They do not generate `doctype`, `html`, `head`, `body`, `style`, or `script` tags. Tailwind output includes classes and residual inline styles; the consuming project must build the corresponding CSS. `collectTailwindClasses()` returns a sorted list of unique rendered classes.
137
+
138
+ When rendering HTML, numeric Tailwind arbitrary values are rounded to at most two decimal places, with trailing zeros removed: `leading-[14.522727012634277px]` becomes `leading-[14.52px]`. Class collection uses the same formatting. The original IR and inline style values remain unchanged.
129
139
 
130
140
  ```sh
131
- node dist/cli/index.js export --input artifacts/live/file.json \
141
+ figma-json-tree export --input figma.json \
132
142
  --selector 'FRAME[id="41:5868"]' --format html \
133
- --out artifacts/live/hover-card.inline.html
143
+ --out hover-card.inline.html
134
144
 
135
- node dist/cli/index.js export --input artifacts/live/file.json \
145
+ figma-json-tree export --input figma.json \
136
146
  --selector 'FRAME[id="41:5868"]' --format html --styles tailwind \
137
- --out artifacts/live/hover-card.tailwind.html
147
+ --out hover-card.tailwind.html
138
148
 
139
- # 저장된 IR 또는 Tailwind IR 입력 가능
140
- node dist/cli/index.js export \
141
- --input artifacts/live/hover-card-frame-41-5868.tailwind-ir.json \
142
- --out artifacts/live/hover-card.from-tailwind-ir.html
149
+ # Saved standard IR and Tailwind IR are also supported
150
+ figma-json-tree export --input design.tailwind-ir.json --out design.html
143
151
  ```
144
152
 
145
- `--out`을 생략하면 HTML stdout으로 출력하며 덮어쓰기에는 `--force`가 필요합니다. 렌더링은 현재 IR의 지원 범위를 따릅니다. 벡터·이미지·효과의 완전한 재현, 폰트 다운로드, hover 동작 같은 인터랙션 생성은 포함하지 않습니다. [HTML API·제약·검증 방법](docs/html.md)을 참고하세요.
153
+ Omit `--out` to write HTML to stdout. Use `--force` to overwrite an existing file.
154
+
155
+ Rendering is limited to the properties supported by the current IR. It does not fully reproduce vectors, images, or effects, download fonts, or generate interactions such as hover behavior. See [HTML API, limitations, and verification](docs/html.md).
156
+
157
+ ## Development and verification
158
+
159
+ ```sh
160
+ git clone https://github.com/dosimpact/figma-json-tree.git
161
+ cd figma-json-tree
162
+ npm install
163
+ npm run check
164
+ ```
146
165
 
147
- ## 검증과 예제
166
+ Individual checks and examples:
148
167
 
149
168
  ```sh
150
- npm run lint # lint + 포맷 + import 정렬 검사
151
- npm run lint:fix # 안전한 lint 자동 수정 + 포맷 + import 정렬
152
- npm run format # 포맷만 자동 수정
169
+ npm run lint # Check lint rules, formatting, and import order
170
+ npm run lint:fix # Apply safe lint fixes, formatting, and import sorting
171
+ npm run format # Apply formatting only
153
172
  npm run typecheck
154
173
  npm test
155
174
  npm run build
156
175
  npm run test:package
157
- npm run test:live # FIGMA_TOKEN 필요, 실제 API 요청
158
- npm run test:html:live # artifacts/live의 실제 다운로드 데이터로 HTML 출력 검증
176
+ npm run test:live # Requires FIGMA_TOKEN; makes real API requests
177
+ npm run test:html:live # Uses downloaded Figma data in artifacts/live
159
178
 
160
179
  npx tsx examples/query.ts artifacts/live/file.json
161
180
  npx tsx examples/to-ir.ts artifacts/live/file.json 49:7390
162
181
  ```
163
182
 
164
- `npm run check`는 Biome 검사부터 타입 검사·테스트·빌드·패키지 소비 검증까지 실행합니다. Biome 공백 2칸, 작은따옴표, 불필요한 세미콜론 생략, 100 너비를 사용합니다. `.gitignore`의 산출물과 `package-lock.json`은 검사 대상에서 제외합니다. 상세 설정은 [biome.json](biome.json)에 있습니다.
183
+ `npm run check` runs Biome, type checking, tests, the build, and package consumption checks. Biome uses two-space indentation, single quotes, semicolons only where needed, and a line width of 100. Generated files covered by `.gitignore` and `package-lock.json` are excluded. See [biome.json](biome.json).
165
184
 
166
- 실제 검증의 기본 대상은 파일 `vHYqaZykgJgAjgUs1mxjp3`, 노드 `49:7390`입니다. `FIGMA_FILE_KEY`와 `FIGMA_NODE_ID`로 변경할 있습니다. JSON·IR·Tailwind CSS·보고서는 Git에서 제외된 `artifacts/live/`에 저장합니다. 실제 응답에서 `ToBe` 일치 노드가 없으면 0건을 기록하고 별도 fixture에서 양성 사례를 확인합니다.
185
+ Live API verification defaults to file `vHYqaZykgJgAjgUs1mxjp3` and node `49:7390`. Override them with `FIGMA_FILE_KEY` and `FIGMA_NODE_ID`. JSON, IR, Tailwind CSS, and reports are stored in the Git-ignored `artifacts/live/` directory. If the live response contains no names matching `ToBe`, the report records zero matches; a separate fixture verifies positive matches.
167
186
 
168
- 최초 구현의 실제 실행 결과는 [검증 기록](docs/verification.md) 정리했습니다.
187
+ The [verification record](docs/verification.md) documents the initial implementation's live results.
169
188
 
170
- `FIGMA_LIVE_REPLAY=1`은 저장한 파일·노드 응답으로 변환 검증을 재현합니다. CLI 다운로드는 모드에서도 실제 요청하며, 보고서는 replay 사용을 명시합니다. 기본 `test:live`는 응답을 다운로드합니다.
189
+ Set `FIGMA_LIVE_REPLAY=1` to repeat conversion checks using saved file and node responses. The CLI download check still makes a real request in this mode, and the report identifies replay usage. By default, `test:live` downloads fresh responses.
171
190
 
172
- 모듈 경계와 SOLID·SLAP 적용은 [설계 문서](docs/architecture.md) 정리했습니다.
191
+ See the [architecture documentation](docs/architecture.md) for module boundaries and the application of SOLID and SLAP (Single Level of Abstraction Principle). Linked reference documents are currently in Korean.
package/package.json CHANGED
@@ -1,7 +1,15 @@
1
1
  {
2
2
  "name": "figma-json-tree",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Query Figma JSON trees and convert subtrees to extensible design and Tailwind IR.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/dosimpact/figma-json-tree.git"
8
+ },
9
+ "homepage": "https://github.com/dosimpact/figma-json-tree#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/dosimpact/figma-json-tree/issues"
12
+ },
5
13
  "type": "module",
6
14
  "sideEffects": false,
7
15
  "engines": {