MCPcopy Index your code
hub / github.com/figma/plugin-samples / styleToTokenDataMap

Function styleToTokenDataMap

styles-to-variables/code.js:65–91  ·  view source on GitHub ↗
(into, current)

Source from the content-addressed store, hash-verified

63}
64
65function styleToTokenDataMap(into, current) {
66 const paints = current.paints.filter(
67 ({ visible, type }) => visible && type === "SOLID"
68 );
69 if (paints.length === 1) {
70 const {
71 blendMode,
72 color: { r, g, b },
73 opacity,
74 type,
75 } = paints[0];
76 const hex = rgbToHex({ r, g, b });
77 if (blendMode === "NORMAL") {
78 const uniqueId = [hex, opacity].join("-");
79 into[uniqueId] = into[uniqueId] || {
80 color: { r, g, b },
81 hex,
82 opacity,
83 tokens: [],
84 };
85 into[uniqueId].tokens.push(current.name);
86 } else {
87 // do something different i guess
88 }
89 }
90 return into;
91}
92
93function rgbToHex({ r, g, b }) {
94 const toHex = (value) => {

Callers

nothing calls this directly

Calls 1

rgbToHexFunction · 0.70

Tested by

no test coverage detected