@kuma-ui/sheet
Version:
🐻 Kuma UI is a utility-first, zero-runtime CSS-in-JS library that offers an outstanding developer experience and optimized performance.
103 lines (99 loc) • 2.15 kB
JavaScript
import {
__publicField
} from "./chunk-NHABU752.mjs";
// src/placeholders.ts
var applyT = (input, placeholders) => {
return applyPlaceholders(input, placeholders);
};
var applyPlaceholders = (input, placeholders) => {
const regex = /\bt\s*\(\s*["']([^"']+)["']\s*\)/g;
return input.replace(regex, (match, placeholder) => {
if (typeof placeholder === "string" && placeholder in placeholders) {
return placeholders[placeholder];
}
return match;
});
};
var createPlaceholders = (theme2) => {
const result = {};
for (const token of tokens) {
const tokenValue = theme2[token];
if (tokenValue) {
for (const key in tokenValue) {
result[key] = tokenValue[key];
}
}
}
return result;
};
// src/theme.ts
var defaultBreakpoints = Object.freeze({
sm: "576px",
md: "768px",
lg: "992px",
xl: "1200px"
});
var tokens = [
"colors",
"fonts",
"fontSizes",
"fontWeights",
"lineHeights",
"letterSpacings",
"spacings",
"sizes",
"radii",
"zIndices",
"breakpoints"
];
var _Theme = class {
_userTheme = {
...globalThis.__KUMA_USER_THEME__,
breakpoints: globalThis.__KUMA_USER_THEME__?.breakpoints ?? defaultBreakpoints
};
_placeholders = {};
constructor() {
}
static getInstance() {
if (!_Theme.instance) {
_Theme.instance = new _Theme();
}
return _Theme.instance;
}
setUserTheme(userTheme) {
if (Object.keys(userTheme.breakpoints || {}).length === 0) {
delete userTheme.breakpoints;
}
this._userTheme = {
...this._userTheme,
...userTheme
};
this._placeholders = createPlaceholders(this._userTheme);
}
getUserTheme() {
return this._userTheme;
}
getPlaceholders() {
return this._placeholders;
}
getVariants(componentName) {
return this._userTheme.components?.[componentName] || {};
}
reset() {
this._userTheme = {
breakpoints: defaultBreakpoints
};
}
};
var Theme = _Theme;
__publicField(Theme, "instance");
var theme = Theme.getInstance();
export {
defaultBreakpoints,
tokens,
Theme,
theme,
applyT,
applyPlaceholders,
createPlaceholders
};