openfig-mcp 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.
- package/README.md +3 -18
- package/bin/openfig-mcp.mjs +71 -71
- package/package.json +1 -1
- package/src/convert.mjs +484 -484
- package/src/html.mjs +110 -110
- package/src/index.mjs +8 -8
- package/src/render.mjs +85 -85
- package/src/server.mjs +246 -246
- package/src/tokens.mjs +157 -157
- package/src/vendor/svg-builder.mjs +1661 -1661
package/src/tokens.mjs
CHANGED
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
// Design tokens: Figma styles (fill/text/effect/grid) and Figma Variables (collections + modes).
|
|
2
|
-
import { cssColor, gid, idOf, r2, slug, fontWeight } from './util.mjs';
|
|
3
|
-
|
|
4
|
-
const STYLE_PREFIX = { FILL: 'color', TEXT: 'text', EFFECT: 'shadow', GRID: 'grid' };
|
|
5
|
-
|
|
6
|
-
export function styleTokenName(st) { return `--${STYLE_PREFIX[st.styleType] || slug(st.styleType)}-${slug(st.name)}`; }
|
|
7
|
-
export function textStyleClass(st) { return `ts-${slug(st.name)}`; }
|
|
8
|
-
|
|
9
|
-
export function variableTokenName(doc, v) {
|
|
10
|
-
const set = doc.variableSet(v.variableSetID);
|
|
11
|
-
const base = slug(v.name.replace(/\//g, '-'));
|
|
12
|
-
return `--${set ? slug(set.name) + '-' : ''}${base}`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Plain-value CSS for a text style / text node font properties (no color). */
|
|
16
|
-
export function typographyCss(n) {
|
|
17
|
-
const f = n.fontName || {};
|
|
18
|
-
const css = { 'font-family': `'${f.family}', sans-serif`, 'font-weight': fontWeight(f.style) };
|
|
19
|
-
if (/italic/i.test(f.style || '')) css['font-style'] = 'italic';
|
|
20
|
-
if (n.fontSize) css['font-size'] = `${r2(n.fontSize)}px`;
|
|
21
|
-
const lh = n.lineHeight;
|
|
22
|
-
if (lh) {
|
|
23
|
-
if (lh.units === 'PIXELS') css['line-height'] = `${r2(lh.value)}px`;
|
|
24
|
-
else if (lh.units === 'PERCENT') {
|
|
25
|
-
if (lh.value !== 100) css['line-height'] = r2(lh.value / 100);
|
|
26
|
-
else {
|
|
27
|
-
// Figma "Auto" = the font's own line height, which Figma records per font in derivedTextData
|
|
28
|
-
const meta = (n.derivedTextData?.fontMetaData || []).find(m => m.key?.family === f.family && (m.key?.style === f.style || !f.style)) || n.derivedTextData?.fontMetaData?.[0];
|
|
29
|
-
css['line-height'] = meta?.fontLineHeight ? r2(meta.fontLineHeight) : 'normal';
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else if (lh.units === 'RAW') css['line-height'] = r2(lh.value);
|
|
33
|
-
}
|
|
34
|
-
const ls = n.letterSpacing;
|
|
35
|
-
if (ls?.value) css['letter-spacing'] = ls.units === 'PERCENT' ? `${r2(ls.value / 100)}em` : `${r2(ls.value)}px`;
|
|
36
|
-
if (n.textCase && n.textCase !== 'ORIGINAL') css['text-transform'] = { UPPER: 'uppercase', LOWER: 'lowercase', TITLE: 'capitalize' }[n.textCase] || undefined;
|
|
37
|
-
if (n.textDecoration && n.textDecoration !== 'NONE') css['text-decoration'] = n.textDecoration === 'STRIKETHROUGH' ? 'line-through' : 'underline';
|
|
38
|
-
return css;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function variableValueCss(doc, data, resolvedType, seen = new Set()) {
|
|
42
|
-
const val = data?.value;
|
|
43
|
-
if (!val) return null;
|
|
44
|
-
if (val.alias) {
|
|
45
|
-
const target = doc.variable(val.alias);
|
|
46
|
-
if (!target || seen.has(idOf(target))) return null;
|
|
47
|
-
return `var(${variableTokenName(doc, target)})`;
|
|
48
|
-
}
|
|
49
|
-
const t = resolvedType || data.resolvedDataType || data.dataType;
|
|
50
|
-
if (val.colorValue) return cssColor(val.colorValue);
|
|
51
|
-
if (val.floatValue !== undefined) return t === 'FLOAT' || t === 'NUMBER' ? `${r2(val.floatValue)}` : `${r2(val.floatValue)}`;
|
|
52
|
-
if (val.textValue !== undefined) return JSON.stringify(val.textValue);
|
|
53
|
-
if (val.boolValue !== undefined) return String(val.boolValue);
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Tracks which tokens a conversion touched, and emits tokens.css / JSON.
|
|
59
|
-
*/
|
|
60
|
-
export class TokenRegistry {
|
|
61
|
-
constructor(doc) { this.doc = doc; this.used = new Map(); this.usedVars = new Map(); }
|
|
62
|
-
|
|
63
|
-
styleVar(st) { const name = styleTokenName(st); this.used.set(name, st); return name; }
|
|
64
|
-
textClass(st) { this.used.set(styleTokenName(st), st); return textStyleClass(st); }
|
|
65
|
-
variableVar(v) { const name = variableTokenName(this.doc, v); this.usedVars.set(name, v); return name; }
|
|
66
|
-
|
|
67
|
-
/** VariableData that aliases a variable -> `var(--x)` or null. */
|
|
68
|
-
aliasVar(data) {
|
|
69
|
-
const alias = data?.value?.alias;
|
|
70
|
-
if (!alias) return null;
|
|
71
|
-
const v = this.doc.variable(alias);
|
|
72
|
-
if (!v) return null;
|
|
73
|
-
return `var(${this.variableVar(v)})`;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Every token in the file (or only the used ones). */
|
|
77
|
-
collect({ onlyUsed = false } = {}) {
|
|
78
|
-
const doc = this.doc;
|
|
79
|
-
const styles = onlyUsed ? [...this.used.values()] : doc.styles.filter(s => !doc.isInternal(s) || true);
|
|
80
|
-
const uniq = new Map();
|
|
81
|
-
for (const st of styles) uniq.set(styleTokenName(st), st);
|
|
82
|
-
const colors = [], typography = [], shadows = [], other = [];
|
|
83
|
-
for (const [name, st] of uniq) {
|
|
84
|
-
if (st.styleType === 'FILL') {
|
|
85
|
-
const paints = (st.fillPaints || []).filter(p => p.visible !== false);
|
|
86
|
-
const value = paints.length === 1 && paints[0].type === 'SOLID' ? cssColor(paints[0].color, paints[0].opacity ?? 1) : paints.map(p => p.type === 'SOLID' ? cssColor(p.color, p.opacity ?? 1) : `/* ${p.type} */`).join(', ');
|
|
87
|
-
colors.push({ name, figmaName: st.name, value, description: st.styleDescription || undefined });
|
|
88
|
-
} else if (st.styleType === 'TEXT') {
|
|
89
|
-
typography.push({ name, className: textStyleClass(st), figmaName: st.name, value: typographyCss(st) });
|
|
90
|
-
} else if (st.styleType === 'EFFECT') {
|
|
91
|
-
shadows.push({ name, figmaName: st.name, value: effectsCss(st.effects || [])['box-shadow'] || null, effects: st.effects?.map(e => e.type) });
|
|
92
|
-
} else other.push({ name, figmaName: st.name, type: st.styleType });
|
|
93
|
-
}
|
|
94
|
-
// Variables
|
|
95
|
-
const vars = onlyUsed ? [...this.usedVars.values()] : doc.variables;
|
|
96
|
-
const collections = new Map();
|
|
97
|
-
for (const v of vars) {
|
|
98
|
-
const set = doc.variableSet(v.variableSetID);
|
|
99
|
-
const key = set ? idOf(set) : '(none)';
|
|
100
|
-
if (!collections.has(key)) {
|
|
101
|
-
const modes = (set?.variableSetModes || []).slice().sort((a, b) => (a.sortPosition < b.sortPosition ? -1 : 1));
|
|
102
|
-
collections.set(key, { name: set?.name || '(no collection)', modes: modes.map(m => ({ id: gid(m.id), name: m.name })), variables: [] });
|
|
103
|
-
}
|
|
104
|
-
const col = collections.get(key);
|
|
105
|
-
const values = {};
|
|
106
|
-
for (const e of v.variableDataValues?.entries || []) {
|
|
107
|
-
const mode = col.modes.find(m => m.id === gid(e.modeID));
|
|
108
|
-
values[mode?.name || gid(e.modeID)] = variableValueCss(doc, e.variableData, v.variableResolvedType);
|
|
109
|
-
}
|
|
110
|
-
col.variables.push({ name: variableTokenName(doc, v), figmaName: v.name, type: v.variableResolvedType, values, scopes: v.variableScopes || undefined, codeSyntax: v.variableTokenName || undefined });
|
|
111
|
-
}
|
|
112
|
-
return { colors, typography, shadows, other, variables: [...collections.values()] };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** CSS custom properties + typography utility classes (+ one block per extra variable mode). */
|
|
116
|
-
toCss(opts) {
|
|
117
|
-
const t = this.collect(opts);
|
|
118
|
-
const lines = [':root {'];
|
|
119
|
-
for (const c of t.colors) lines.push(` ${c.name}: ${c.value}; /* ${c.figmaName} */`);
|
|
120
|
-
for (const s of t.shadows) if (s.value) lines.push(` ${s.name}: ${s.value}; /* ${s.figmaName} */`);
|
|
121
|
-
const extraModes = [];
|
|
122
|
-
for (const col of t.variables) {
|
|
123
|
-
const def = col.modes[0]?.name;
|
|
124
|
-
for (const v of col.variables) {
|
|
125
|
-
const val = v.values[def] ?? Object.values(v.values)[0];
|
|
126
|
-
if (val != null) lines.push(` ${v.name}: ${v.type === 'FLOAT' && /^-?[\d.]+$/.test(val) && !/opacity|weight|z-?index|ratio/i.test(v.figmaName) ? val + 'px' : val}; /* ${col.name} / ${v.figmaName} */`);
|
|
127
|
-
}
|
|
128
|
-
for (const m of col.modes.slice(1)) extraModes.push({ col, mode: m });
|
|
129
|
-
}
|
|
130
|
-
lines.push('}');
|
|
131
|
-
for (const { col, mode } of extraModes) {
|
|
132
|
-
lines.push(`\n/* ${col.name} — mode "${mode.name}" */\n[data-${slug(col.name) || 'mode'}="${slug(mode.name)}"] {`);
|
|
133
|
-
for (const v of col.variables) { const val = v.values[mode.name]; if (val != null) lines.push(` ${v.name}: ${v.type === 'FLOAT' && /^-?[\d.]+$/.test(val) && !/opacity|weight|z-?index|ratio/i.test(v.figmaName) ? val + 'px' : val};`); }
|
|
134
|
-
lines.push('}');
|
|
135
|
-
}
|
|
136
|
-
for (const ty of t.typography) {
|
|
137
|
-
lines.push(`\n/* Text style: ${ty.figmaName} */\n.${ty.className} { ${Object.entries(ty.value).map(([k, v]) => `${k}: ${v}`).join('; ')}; }`);
|
|
138
|
-
}
|
|
139
|
-
return lines.join('\n') + '\n';
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** Figma effects -> CSS (box-shadow / filter / backdrop-filter). */
|
|
144
|
-
export function effectsCss(effects, reg) {
|
|
145
|
-
const shadows = [], css = {};
|
|
146
|
-
for (const e of effects || []) {
|
|
147
|
-
if (e.visible === false) continue;
|
|
148
|
-
if (e.type === 'DROP_SHADOW' || e.type === 'INNER_SHADOW') {
|
|
149
|
-
const col = (reg && e.colorVar && reg.aliasVar(e.colorVar)) || cssColor(e.color);
|
|
150
|
-
shadows.push(`${e.type === 'INNER_SHADOW' ? 'inset ' : ''}${r2(e.offset?.x || 0)}px ${r2(e.offset?.y || 0)}px ${r2(e.radius || 0)}px ${r2(e.spread || 0)}px ${col}`);
|
|
151
|
-
} else if (e.type === 'FOREGROUND_BLUR') css.filter = `blur(${r2((e.radius || 0) / 2)}px)`;
|
|
152
|
-
else if (e.type === 'BACKGROUND_BLUR') css['backdrop-filter'] = `blur(${r2((e.radius || 0) / 2)}px)`;
|
|
153
|
-
else css[`/* effect */`] = `${e.type} (not expressible in CSS)`;
|
|
154
|
-
}
|
|
155
|
-
if (shadows.length) css['box-shadow'] = shadows.join(', ');
|
|
156
|
-
return css;
|
|
157
|
-
}
|
|
1
|
+
// Design tokens: Figma styles (fill/text/effect/grid) and Figma Variables (collections + modes).
|
|
2
|
+
import { cssColor, gid, idOf, r2, slug, fontWeight } from './util.mjs';
|
|
3
|
+
|
|
4
|
+
const STYLE_PREFIX = { FILL: 'color', TEXT: 'text', EFFECT: 'shadow', GRID: 'grid' };
|
|
5
|
+
|
|
6
|
+
export function styleTokenName(st) { return `--${STYLE_PREFIX[st.styleType] || slug(st.styleType)}-${slug(st.name)}`; }
|
|
7
|
+
export function textStyleClass(st) { return `ts-${slug(st.name)}`; }
|
|
8
|
+
|
|
9
|
+
export function variableTokenName(doc, v) {
|
|
10
|
+
const set = doc.variableSet(v.variableSetID);
|
|
11
|
+
const base = slug(v.name.replace(/\//g, '-'));
|
|
12
|
+
return `--${set ? slug(set.name) + '-' : ''}${base}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Plain-value CSS for a text style / text node font properties (no color). */
|
|
16
|
+
export function typographyCss(n) {
|
|
17
|
+
const f = n.fontName || {};
|
|
18
|
+
const css = { 'font-family': `'${f.family}', sans-serif`, 'font-weight': fontWeight(f.style) };
|
|
19
|
+
if (/italic/i.test(f.style || '')) css['font-style'] = 'italic';
|
|
20
|
+
if (n.fontSize) css['font-size'] = `${r2(n.fontSize)}px`;
|
|
21
|
+
const lh = n.lineHeight;
|
|
22
|
+
if (lh) {
|
|
23
|
+
if (lh.units === 'PIXELS') css['line-height'] = `${r2(lh.value)}px`;
|
|
24
|
+
else if (lh.units === 'PERCENT') {
|
|
25
|
+
if (lh.value !== 100) css['line-height'] = r2(lh.value / 100);
|
|
26
|
+
else {
|
|
27
|
+
// Figma "Auto" = the font's own line height, which Figma records per font in derivedTextData
|
|
28
|
+
const meta = (n.derivedTextData?.fontMetaData || []).find(m => m.key?.family === f.family && (m.key?.style === f.style || !f.style)) || n.derivedTextData?.fontMetaData?.[0];
|
|
29
|
+
css['line-height'] = meta?.fontLineHeight ? r2(meta.fontLineHeight) : 'normal';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (lh.units === 'RAW') css['line-height'] = r2(lh.value);
|
|
33
|
+
}
|
|
34
|
+
const ls = n.letterSpacing;
|
|
35
|
+
if (ls?.value) css['letter-spacing'] = ls.units === 'PERCENT' ? `${r2(ls.value / 100)}em` : `${r2(ls.value)}px`;
|
|
36
|
+
if (n.textCase && n.textCase !== 'ORIGINAL') css['text-transform'] = { UPPER: 'uppercase', LOWER: 'lowercase', TITLE: 'capitalize' }[n.textCase] || undefined;
|
|
37
|
+
if (n.textDecoration && n.textDecoration !== 'NONE') css['text-decoration'] = n.textDecoration === 'STRIKETHROUGH' ? 'line-through' : 'underline';
|
|
38
|
+
return css;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function variableValueCss(doc, data, resolvedType, seen = new Set()) {
|
|
42
|
+
const val = data?.value;
|
|
43
|
+
if (!val) return null;
|
|
44
|
+
if (val.alias) {
|
|
45
|
+
const target = doc.variable(val.alias);
|
|
46
|
+
if (!target || seen.has(idOf(target))) return null;
|
|
47
|
+
return `var(${variableTokenName(doc, target)})`;
|
|
48
|
+
}
|
|
49
|
+
const t = resolvedType || data.resolvedDataType || data.dataType;
|
|
50
|
+
if (val.colorValue) return cssColor(val.colorValue);
|
|
51
|
+
if (val.floatValue !== undefined) return t === 'FLOAT' || t === 'NUMBER' ? `${r2(val.floatValue)}` : `${r2(val.floatValue)}`;
|
|
52
|
+
if (val.textValue !== undefined) return JSON.stringify(val.textValue);
|
|
53
|
+
if (val.boolValue !== undefined) return String(val.boolValue);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Tracks which tokens a conversion touched, and emits tokens.css / JSON.
|
|
59
|
+
*/
|
|
60
|
+
export class TokenRegistry {
|
|
61
|
+
constructor(doc) { this.doc = doc; this.used = new Map(); this.usedVars = new Map(); }
|
|
62
|
+
|
|
63
|
+
styleVar(st) { const name = styleTokenName(st); this.used.set(name, st); return name; }
|
|
64
|
+
textClass(st) { this.used.set(styleTokenName(st), st); return textStyleClass(st); }
|
|
65
|
+
variableVar(v) { const name = variableTokenName(this.doc, v); this.usedVars.set(name, v); return name; }
|
|
66
|
+
|
|
67
|
+
/** VariableData that aliases a variable -> `var(--x)` or null. */
|
|
68
|
+
aliasVar(data) {
|
|
69
|
+
const alias = data?.value?.alias;
|
|
70
|
+
if (!alias) return null;
|
|
71
|
+
const v = this.doc.variable(alias);
|
|
72
|
+
if (!v) return null;
|
|
73
|
+
return `var(${this.variableVar(v)})`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Every token in the file (or only the used ones). */
|
|
77
|
+
collect({ onlyUsed = false } = {}) {
|
|
78
|
+
const doc = this.doc;
|
|
79
|
+
const styles = onlyUsed ? [...this.used.values()] : doc.styles.filter(s => !doc.isInternal(s) || true);
|
|
80
|
+
const uniq = new Map();
|
|
81
|
+
for (const st of styles) uniq.set(styleTokenName(st), st);
|
|
82
|
+
const colors = [], typography = [], shadows = [], other = [];
|
|
83
|
+
for (const [name, st] of uniq) {
|
|
84
|
+
if (st.styleType === 'FILL') {
|
|
85
|
+
const paints = (st.fillPaints || []).filter(p => p.visible !== false);
|
|
86
|
+
const value = paints.length === 1 && paints[0].type === 'SOLID' ? cssColor(paints[0].color, paints[0].opacity ?? 1) : paints.map(p => p.type === 'SOLID' ? cssColor(p.color, p.opacity ?? 1) : `/* ${p.type} */`).join(', ');
|
|
87
|
+
colors.push({ name, figmaName: st.name, value, description: st.styleDescription || undefined });
|
|
88
|
+
} else if (st.styleType === 'TEXT') {
|
|
89
|
+
typography.push({ name, className: textStyleClass(st), figmaName: st.name, value: typographyCss(st) });
|
|
90
|
+
} else if (st.styleType === 'EFFECT') {
|
|
91
|
+
shadows.push({ name, figmaName: st.name, value: effectsCss(st.effects || [])['box-shadow'] || null, effects: st.effects?.map(e => e.type) });
|
|
92
|
+
} else other.push({ name, figmaName: st.name, type: st.styleType });
|
|
93
|
+
}
|
|
94
|
+
// Variables
|
|
95
|
+
const vars = onlyUsed ? [...this.usedVars.values()] : doc.variables;
|
|
96
|
+
const collections = new Map();
|
|
97
|
+
for (const v of vars) {
|
|
98
|
+
const set = doc.variableSet(v.variableSetID);
|
|
99
|
+
const key = set ? idOf(set) : '(none)';
|
|
100
|
+
if (!collections.has(key)) {
|
|
101
|
+
const modes = (set?.variableSetModes || []).slice().sort((a, b) => (a.sortPosition < b.sortPosition ? -1 : 1));
|
|
102
|
+
collections.set(key, { name: set?.name || '(no collection)', modes: modes.map(m => ({ id: gid(m.id), name: m.name })), variables: [] });
|
|
103
|
+
}
|
|
104
|
+
const col = collections.get(key);
|
|
105
|
+
const values = {};
|
|
106
|
+
for (const e of v.variableDataValues?.entries || []) {
|
|
107
|
+
const mode = col.modes.find(m => m.id === gid(e.modeID));
|
|
108
|
+
values[mode?.name || gid(e.modeID)] = variableValueCss(doc, e.variableData, v.variableResolvedType);
|
|
109
|
+
}
|
|
110
|
+
col.variables.push({ name: variableTokenName(doc, v), figmaName: v.name, type: v.variableResolvedType, values, scopes: v.variableScopes || undefined, codeSyntax: v.variableTokenName || undefined });
|
|
111
|
+
}
|
|
112
|
+
return { colors, typography, shadows, other, variables: [...collections.values()] };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** CSS custom properties + typography utility classes (+ one block per extra variable mode). */
|
|
116
|
+
toCss(opts) {
|
|
117
|
+
const t = this.collect(opts);
|
|
118
|
+
const lines = [':root {'];
|
|
119
|
+
for (const c of t.colors) lines.push(` ${c.name}: ${c.value}; /* ${c.figmaName} */`);
|
|
120
|
+
for (const s of t.shadows) if (s.value) lines.push(` ${s.name}: ${s.value}; /* ${s.figmaName} */`);
|
|
121
|
+
const extraModes = [];
|
|
122
|
+
for (const col of t.variables) {
|
|
123
|
+
const def = col.modes[0]?.name;
|
|
124
|
+
for (const v of col.variables) {
|
|
125
|
+
const val = v.values[def] ?? Object.values(v.values)[0];
|
|
126
|
+
if (val != null) lines.push(` ${v.name}: ${v.type === 'FLOAT' && /^-?[\d.]+$/.test(val) && !/opacity|weight|z-?index|ratio/i.test(v.figmaName) ? val + 'px' : val}; /* ${col.name} / ${v.figmaName} */`);
|
|
127
|
+
}
|
|
128
|
+
for (const m of col.modes.slice(1)) extraModes.push({ col, mode: m });
|
|
129
|
+
}
|
|
130
|
+
lines.push('}');
|
|
131
|
+
for (const { col, mode } of extraModes) {
|
|
132
|
+
lines.push(`\n/* ${col.name} — mode "${mode.name}" */\n[data-${slug(col.name) || 'mode'}="${slug(mode.name)}"] {`);
|
|
133
|
+
for (const v of col.variables) { const val = v.values[mode.name]; if (val != null) lines.push(` ${v.name}: ${v.type === 'FLOAT' && /^-?[\d.]+$/.test(val) && !/opacity|weight|z-?index|ratio/i.test(v.figmaName) ? val + 'px' : val};`); }
|
|
134
|
+
lines.push('}');
|
|
135
|
+
}
|
|
136
|
+
for (const ty of t.typography) {
|
|
137
|
+
lines.push(`\n/* Text style: ${ty.figmaName} */\n.${ty.className} { ${Object.entries(ty.value).map(([k, v]) => `${k}: ${v}`).join('; ')}; }`);
|
|
138
|
+
}
|
|
139
|
+
return lines.join('\n') + '\n';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Figma effects -> CSS (box-shadow / filter / backdrop-filter). */
|
|
144
|
+
export function effectsCss(effects, reg) {
|
|
145
|
+
const shadows = [], css = {};
|
|
146
|
+
for (const e of effects || []) {
|
|
147
|
+
if (e.visible === false) continue;
|
|
148
|
+
if (e.type === 'DROP_SHADOW' || e.type === 'INNER_SHADOW') {
|
|
149
|
+
const col = (reg && e.colorVar && reg.aliasVar(e.colorVar)) || cssColor(e.color);
|
|
150
|
+
shadows.push(`${e.type === 'INNER_SHADOW' ? 'inset ' : ''}${r2(e.offset?.x || 0)}px ${r2(e.offset?.y || 0)}px ${r2(e.radius || 0)}px ${r2(e.spread || 0)}px ${col}`);
|
|
151
|
+
} else if (e.type === 'FOREGROUND_BLUR') css.filter = `blur(${r2((e.radius || 0) / 2)}px)`;
|
|
152
|
+
else if (e.type === 'BACKGROUND_BLUR') css['backdrop-filter'] = `blur(${r2((e.radius || 0) / 2)}px)`;
|
|
153
|
+
else css[`/* effect */`] = `${e.type} (not expressible in CSS)`;
|
|
154
|
+
}
|
|
155
|
+
if (shadows.length) css['box-shadow'] = shadows.join(', ');
|
|
156
|
+
return css;
|
|
157
|
+
}
|