@aesthetic/core
Version:
Aesthetic is a powerful type-safe, framework agnostic, CSS-in-JS library for styling components.
101 lines (87 loc) • 3.01 kB
JavaScript
// Bundled with Packemon: https://packemon.dev
// Platform: browser, Support: stable, Format: esm
import { lightTheme, darkTheme } from '@aesthetic/system/test';
export { darkTheme, design, lightTheme } from '@aesthetic/system/test';
import { hyphenate, objectLoop } from '@aesthetic/utils';
/* eslint-disable no-param-reassign */
function resetAestheticState(aesthetic) {
// @ts-expect-error Allow access
aesthetic.activeDirection = undefined; // @ts-expect-error Allow access
aesthetic.activeTheme = undefined; // @ts-expect-error Allow access
aesthetic.listeners.clear(); // @ts-expect-error Allow access
aesthetic.globalSheetRegistry.clear(); // @ts-expect-error Allow access
aesthetic.themeRegistry.reset();
aesthetic.configure({
customProperties: {},
defaultUnit: 'px',
deterministicClasses: false,
directionConverter: null,
rootVariables: false,
vendorPrefixer: null
});
}
function getAestheticState(aesthetic) {
return {
// @ts-expect-error Allow access
activeDirection: aesthetic.activeDirection,
// @ts-expect-error Allow access
activeTheme: aesthetic.activeTheme,
// @ts-expect-error Allow access
globalSheetRegistry: aesthetic.globalSheetRegistry,
// @ts-expect-error Allow access
listeners: aesthetic.listeners,
// @ts-expect-error Allow access
options: aesthetic.options,
// @ts-expect-error Allow access
themeRegistry: aesthetic.themeRegistry
};
}
function setupAesthetic(aesthetic) {
aesthetic.registerTheme('day', lightTheme);
aesthetic.registerTheme('night', darkTheme);
}
function teardownAesthetic(aesthetic) {
lightTheme.name = '';
darkTheme.name = '';
resetAestheticState(aesthetic);
}
function createTestEngine() {
const noop = () => {};
const renderVariable = name => `variable:${hyphenate(name)}`;
const renderRule = (rule, options = {}) => {
let result = String(options.debugName ?? 'class');
objectLoop(rule['@variables'], (value, name) => {
result += ` ${renderVariable(name)}`;
});
return {
result,
variants: Object.keys(rule['@variants'] ?? {}).map(variant => {
const types = variant.split('+').map(v => v.trim());
return {
result: types.map(v => `variant:${v}`).join(' '),
types
};
})
};
};
const engine = {
direction: 'ltr',
name: 'test',
prefersColorScheme: () => false,
prefersContrastLevel: () => false,
renderDeclaration: prop => `property:${hyphenate(prop)}`,
renderFontFace: () => 'font-face',
renderImport: () => 'import',
renderKeyframes: (keyframes, name) => `keyframes:${hyphenate(name ?? 'unknown')}`,
renderRule,
renderRuleGrouped: renderRule,
renderVariable,
ruleCount: 0,
setDirection: noop,
setRootVariables: noop,
setTheme: noop
};
return engine;
}
export { createTestEngine, getAestheticState, resetAestheticState, setupAesthetic, teardownAesthetic };
//# sourceMappingURL=test.js.map