initial commit

Signed-off-by: Mitch Hijlkema <mitch@hijlkema.codes>
This commit is contained in:
2023-08-24 14:04:43 +02:00
parent 844188ee58
commit a6d98a9d84
42 changed files with 8124 additions and 20 deletions

View File

@@ -0,0 +1,64 @@
import { CSSResult, css, unsafeCSS } from 'lit';
export class VariableHelper {
private property: string | undefined;
private variableName: string | undefined;
private groupModifier: string | undefined;
private defaultValue: string | CSSResult = '/*! */';
private isPrivate = false;
public asPrivate(isPrivate = true) {
this.isPrivate = isPrivate;
return this;
}
public withDefaultValue(value: string | CSSResult) {
this.defaultValue = value;
return this;
}
public withProperty(property: string) {
this.property = property;
return this;
}
public withVariableName(name: string) {
this.variableName = name;
return this;
}
public withGroupModifier(modifier: string, ...modifiers: string[]) {
this.groupModifier = [modifier, ...modifiers].join('--');
return this;
}
toCss() {
if (!this.property) {
return css`
${unsafeCSS(this.buildVariableName())}
`;
}
return css`
${unsafeCSS(this.property)}: ${unsafeCSS(this.buildVariableName())};
`;
}
private buildVariableName() {
const variableName = [];
if (this.groupModifier) {
variableName.push(this.groupModifier);
}
if (this.variableName) {
variableName.push(this.variableName);
}
return `var(--${this.isPrivate ? '_' : ''}${variableName.join('--')}, ${
this.defaultValue
})`;
}
}