-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
-
309
-
310
-
311
-
312
-
313
-
314
-
315
-
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
-
324
-
325
-
326
-
327
-
328
-
329
-
330
-
331
-
332
-
333
-
334
-
335
-
336
-
337
-
338
-
339
-
340
-
341
-
342
-
343
-
344
-
345
-
346
-
347
-
348
-
349
-
350
-
351
-
352
-
353
-
354
-
355
-
356
-
357
-
358
-
359
-
360
-
361
-
362
-
363
-
364
-
365
-
366
-
367
-
368
-
369
-
370
-
371
-
372
-
373
-
374
-
375
-
376
-
377
-
378
-
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
-
390
-
391
-
392
-
393
-
394
-
395
-
396
-
397
-
398
-
399
-
400
-
401
-
402
-
403
-
404
-
405
-
406
-
407
-
408
-
409
-
410
-
411
-
412
-
413
-
414
-
415
-
416
-
417
-
418
-
419
-
420
-
421
-
422
-
423
-
424
-
425
-
426
-
427
-
428
-
429
-
430
-
431
-
432
-
433
-
434
-
435
-
436
-
437
-
438
-
439
-
440
-
441
-
442
-
443
-
444
-
445
-
446
-
447
-
448
-
449
-
450
-
451
-
452
-
453
-
454
-
455
-
456
-
457
-
458
-
459
-
460
-
461
-
462
-
463
-
464
-
465
-
466
-
467
-
468
-
469
-
470
-
471
-
472
-
473
-
474
-
475
-
476
-
477
-
478
-
479
-
480
-
481
-
482
-
483
-
484
-
485
-
486
-
487
-
488
-
489
-
490
-
491
-
492
-
493
-
494
-
495
-
496
-
497
-
498
-
499
-
500
-
501
-
502
-
503
-
504
-
505
-
506
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Figspec</title>
<link rel="stylesheet" href="./style.css" />
<script type="module" src="./index.ts"></script>
</head>
<body>
<main>
<hgroup>
<h1>Figspec</h1>
<h2>Unofficial Figma design viewer</h2>
</hgroup>
<p>
Figspec is an unofficial Figma design viewer primarily developed for
embedding usage.
</p>
<ul>
<li>
<a href="#demo">Live demo</a>
</li>
<li>
<a href="#install">Install</a>
</li>
<li>
<a href="#usage">Usage</a>
</li>
<li>
<a href="#api">API</a>
</li>
<li>
<a href="#examples">Examples</a>
</li>
<li>
<a href="https://github.com/pocka/figspec">Source code (GitHub)</a>
</li>
</ul>
<section id="demo">
<h2>Live demo</h2>
<p>
This is a working demo of
<code><figspec-frame-viewer/></code> displaying a frame of
sample Figma design.
</p>
<figspec-frame-viewer
id="frame_demo"
link="https://www.figma.com/file/Klm6pxIZSaJFiOMX5FpTul9F/storybook-addon-designs-sample?type=design&node-id=64%3A1&mode=design&t=qv0I0EDmOnHF0knC-1"
></figspec-frame-viewer>
</section>
<section id="install">
<h2>Install</h2>
<p>Install <code>@figspec/components</code> package from NPM.</p>
<pre><code>npm i @figspec/components</code></pre>
</section>
<section id="usage">
<h2>Usage</h2>
<p>
This package registers two custom elements:
<code><figspec-frame-viewer/></code> and
<code><figspec-file-viewer/></code>. As the names describe, the
frame viewer displays a specific Figma Frame and the file viewer
displays an entire Figma file.
</p>
<p>
Once you installed the package, import the package entrypoint from
your JavaScript file, which registers the two custom elements.
</p>
<pre><code><b>import</b> <u>"@figspec/components"</u>;</code></pre>
<p>Now, you can use the custom elements in your HTML/DOM.</p>
<pre><code><<b>body</b>>
<<b>figspec-frame-viewer</b> nodes=<u>"..."</u> rendered-image=<u>"..."</u>></<b>figspec-frame-viewer</b>>
</<b>body</b>></code></pre>
</section>
<section id="api">
<h2>API</h2>
<h3 id="api_common">Common</h3>
<p>
These APIs are available both in
<code><figspec-frame-viewer /></code> and in
<code><figspec-file-viewer /></code>.
</p>
<h4>Properties</h4>
<table>
<thead>
<tr>
<th>Name</th>
<th>Data type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>link</code>
</td>
<td><code>string</code></td>
<td></td>
<td>
An URL for the Figma frame or containing file. A footer will
appear if this property is not empty.
</td>
</tr>
<tr>
<td>
<code>panX</code>
</td>
<td><code>number</code></td>
<td><code>0</code></td>
<td>
Current value of viewport translate for X axis, in pixel.
Scaling applies after the translate.
</td>
</tr>
<tr>
<td>
<code>panY</code>
</td>
<td><code>number</code></td>
<td><code>0</code></td>
<td>
Current value of viewport translate for Y axis, in pixel.
Scaling applies after the translate.
</td>
</tr>
<tr>
<td>
<code>scale</code>
</td>
<td><code>number</code></td>
<td><code>1.0</code></td>
<td>
Current value of viewport scaling (zoom), where 1.0 = 100%;
</td>
</tr>
<tr>
<td>
<code>zoomSpeed</code>
</td>
<td><code>number</code></td>
<td><code>500</code></td>
<td>
How fast viewport zooms when user performs <kbd>Ctrl</kbd> +
wheel scroll or pinch in-out gesture. You can specify between 1
to 1,000.
</td>
</tr>
<tr>
<td>
<code>panSpeed</code>
</td>
<td><code>number</code></td>
<td><code>500</code></td>
<td>
How fast viewport translates when user performs wheel scroll.
This does not affect to the speed of drag with middle button
(wheel button) pressed. You can specify between 1 to 1,000.
</td>
</tr>
<tr>
<td>
<code>selectedNode</code>
</td>
<td>
<code
><a
href="https://github.com/pocka/figspec/blob/master/src/FigspecViewer/utils.ts#L4"
>SizedNode</a
>
| null</code
>
</td>
<td><code>null</code></td>
<td>Selected node object.</td>
</tr>
<tr>
<td>
<code>zoomMargin</code>
</td>
<td><code>number</code></td>
<td><code>50</code></td>
<td>
The minimum margin for the preview canvas in px. Preview element
uses this value for default zoom value (scale).
</td>
</tr>
</tbody>
</table>
<h4>Attributes</h4>
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>link</code>
</td>
<td>
A corresponding attribute for the <code>link</code> property.
</td>
</tr>
<tr>
<td>
<code>zoom-speed</code>
</td>
<td>
A corresponding attribute for the
<code>zoomSpeed</code> property.
</td>
</tr>
<tr>
<td>
<code>pan-speed</code>
</td>
<td>
A corresponding attribute for the
<code>panSpeed</code> property.
</td>
</tr>
<tr>
<td>
<code>zoom-margin</code>
</td>
<td>
A corresponding attribute for the
<code>zoomMargin</code> property.
</td>
</tr>
</tbody>
</table>
<h4>Events</h4>
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>scalechange</code>
</td>
<td>
Fired when a user performs zoom-in or zoom-out on the preview.
</td>
</tr>
<tr>
<td>
<code>positionchange</code>
</td>
<td>Fired when a user performs pan on the preview.</td>
</tr>
<tr>
<td>
<code>nodeselect</code>
</td>
<td>Fired when a user selects or unselects a node.</td>
</tr>
</tbody>
</table>
<h3 id="api_figspec_frame_viewer"><figspec-frame-viewer /></h3>
<h4>Properties</h4>
<table>
<thead>
<tr>
<th>Name</th>
<th>Data type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>nodes</code>
</td>
<td>
<code
><a
href="https://jemgold.github.io/figma-js/interfaces/filenodesresponse.html"
>FileNodesResponse</a
>
| null</code
>
</td>
<td><code>null</code></td>
<td>
Required. A response of the
<a
href="https://www.figma.com/developers/api#get-file-nodes-endpoint"
>
"GET file nodes"
</a>
API.
</td>
</tr>
<tr>
<td>
<code>renderedImage</code>
</td>
<td><code>string | null</code></td>
<td><code>null</code></td>
<td>
Required. An URL for the frame image rendered by
<a
href="https://www.figma.com/developers/api#get-images-endpoint"
>"GET image"</a
>
API.
</td>
</tr>
<tr>
<td>
<code>documentNode</code>
</td>
<td>
<code
><a
href="https://github.com/pocka/figspec/blob/master/src/FigspecViewer/utils.ts#L4"
>SizedNode</a
>
| null</code
>
</td>
<td><code>null</code></td>
<td>Readonly. A root drawable node.</td>
</tr>
</tbody>
</table>
<h4>Attributes</h4>
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>nodes</code>
</td>
<td>
A corresponding attribute for the <code>nodes</code> property.
Parsed as a JSON string.
</td>
</tr>
<tr>
<td>
<code>rendered-image</code>
</td>
<td>
A corresponding attribute for the
<code>renderedImage</code> property.
</td>
</tr>
</tbody>
</table>
<h3 id="api_figspec_file_viewer"><figspec-file-viewer /></h3>
<h4>Properties</h4>
<table>
<thead>
<tr>
<th>Name</th>
<th>Data type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>documentNode</code>
</td>
<td>
<code
><a
href="https://jemgold.github.io/figma-js/interfaces/fileresponse.html"
>FileResponse</a
>
| null</code
>
</td>
<td><code>null</code></td>
<td>
Required. A response of the
<a
href="https://www.figma.com/developers/api#get-files-endpoint"
>
"GET file"
</a>
API.
</td>
</tr>
<tr>
<td>
<code>renderedImages</code>
</td>
<td>
<code>{ [nodeId: string]: string } | null</code>
</td>
<td>
<code>null</code>
</td>
<td>
Required. A record of rendered images, where key is an ID of the
node and value is an URI of the image.
<code>images</code> property in the response of
<a
href="https://www.figma.com/developers/api#get-images-endpoint"
>"GET image"</a
>
API.
</td>
</tr>
<tr>
<td>
<code>selectedPage</code>
</td>
<td>
<code
><a
href="https://jemgold.github.io/figma-js/interfaces/canvas.html"
>Canvas</a
>
| null</code
>
</td>
<td>
<code>null</code>
</td>
<td>Currently selected page object.</td>
</tr>
</tbody>
</table>
<h4>Attributes</h4>
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>document-node</code>
</td>
<td>
A corresponding attribute for the
<code>documentNode</code> property. Parsed as a JSON string.
</td>
</tr>
<tr>
<td>
<code>rendered-images</code>
</td>
<td>
A corresponding attribute for the
<code>renderedImages</code> property. Parsed as a JSON string.
</td>
</tr>
</tbody>
</table>
</section>
<section id="examples">
<h2>Examples</h2>
<div>
<ul>
<li>
<a href="./examples/file.html" target="example_frame">
File viewer
</a>
</li>
<li>
<a href="./examples/custom-speed.html" target="example_frame">
Custom pan&zoom speed
</a>
</li>
<li>
<a
href="./examples/parameter-missing-error.html"
target="example_frame"
>
Parameter missing error
</a>
</li>
<li>
<a href="./examples/events.html" target="example_frame">
Events (see browser console)
</a>
</li>
</ul>
<iframe name="example_frame" src="./examples/file.html"></iframe>
</div>
</section>
</main>
</body>
</html>