@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.
122 lines (118 loc) • 3.16 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/placeholders.ts
var placeholders_exports = {};
__export(placeholders_exports, {
applyPlaceholders: () => applyPlaceholders,
applyT: () => applyT,
createPlaceholders: () => createPlaceholders
});
module.exports = __toCommonJS(placeholders_exports);
// 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 _Theme {
static instance;
_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.getInstance();
// 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;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
applyPlaceholders,
applyT,
createPlaceholders
});