MCPcopy Create free account
hub / github.com/Kong/insomnia / getThemeBlockCSS

Function getThemeBlockCSS

packages/insomnia/src/ui/plugins/misc.ts:123–202  ·  view source on GitHub ↗
(block?: ThemeBlock)

Source from the content-addressed store, hash-verified

121};
122
123function getThemeBlockCSS(block?: ThemeBlock) {
124 if (!block) {
125 return '';
126 }
127
128 const indent = '\t';
129 let css = '';
130
131 const addColorVar = (variable: string, value?: string) => {
132 if (!value) {
133 return;
134 }
135
136 try {
137 const parsedColor = Color(value);
138 const rgb = parsedColor.rgb();
139 addVar(variable, rgb.string());
140 addVar(`${variable}-rgb`, rgb.array().join(', '));
141 } catch {
142 console.log('[theme] Failed to parse theme color', value);
143 }
144 };
145
146 const addVar = (variable: string, value?: string) => {
147 if (!value) {
148 return;
149 }
150
151 css += `${indent}--${variable}: ${value};\n`;
152 };
153
154 const addComment = (comment: string) => {
155 css += `${indent}/* ${comment} */\n`;
156 };
157
158 const addNewLine = () => {
159 css += '\n';
160 };
161
162 if (block.background) {
163 const { background } = block;
164 addComment('Background');
165 addColorVar('color-bg', background.default);
166 addColorVar('color-success', background.success);
167 addColorVar('color-notice', background.notice);
168 addColorVar('color-warning', background.warning);
169 addColorVar('color-danger', background.danger);
170 addColorVar('color-surprise', background.surprise);
171 addColorVar('color-info', background.info);
172 addNewLine();
173 }
174
175 if (block.foreground) {
176 const { foreground } = block;
177 addComment('Foreground');
178 addColorVar('color-font', foreground.default);
179 addColorVar('color-font-success', foreground.success);
180 addColorVar('color-font-notice', foreground.notice);

Callers 1

generateThemeCSSFunction · 0.85

Calls 3

addCommentFunction · 0.85
addColorVarFunction · 0.85
addNewLineFunction · 0.85

Tested by

no test coverage detected