mirror of
https://github.com/documenso/documenso.git
synced 2026-07-10 04:55:02 +10:00
7ea664214a
## Description Add envelopes V2 embedded support --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
import { colord } from 'colord';
|
|
import { toKebabCase } from 'remeda';
|
|
|
|
import type { TCssVarsSchema } from '@documenso/lib/types/css-vars';
|
|
|
|
export const toNativeCssVars = (vars: TCssVarsSchema) => {
|
|
const cssVars: Record<string, string> = {};
|
|
|
|
const { radius, ...colorVars } = vars;
|
|
|
|
for (const [key, value] of Object.entries(colorVars)) {
|
|
if (value) {
|
|
const color = colord(value);
|
|
const { h, s, l } = color.toHsl();
|
|
|
|
cssVars[`--${toKebabCase(key)}`] = `${h} ${s} ${l}`;
|
|
}
|
|
}
|
|
|
|
if (radius) {
|
|
cssVars[`--radius`] = `${radius}`;
|
|
}
|
|
|
|
return cssVars;
|
|
};
|
|
|
|
export const injectCss = (options: { css?: string; cssVars?: TCssVarsSchema }) => {
|
|
const { css, cssVars } = options;
|
|
|
|
if (css) {
|
|
const style = document.createElement('style');
|
|
style.innerHTML = css;
|
|
|
|
document.head.appendChild(style);
|
|
}
|
|
|
|
if (cssVars) {
|
|
const nativeVars = toNativeCssVars(cssVars);
|
|
|
|
for (const [key, value] of Object.entries(nativeVars)) {
|
|
document.documentElement.style.setProperty(key, value);
|
|
}
|
|
}
|
|
};
|