metamorphosis
Advanced tools
Comparing version 0.2.1 to 0.2.2
{ | ||
"name": "metamorphosis", | ||
"description": "A css variable management library that helps create and organize variables into easily configurable themes.", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"type": "module", | ||
@@ -46,3 +46,3 @@ "module": "./dist/index.js", | ||
"dependencies": { | ||
"@alanscodelog/utils": "4.0.0-beta.5" | ||
"@alanscodelog/utils": "4.0.0-beta.9" | ||
}, | ||
@@ -63,18 +63,18 @@ "peerDependencies": { | ||
"@alanscodelog/commitlint-config": "^2.0.0", | ||
"@alanscodelog/eslint-config": "^4.0.3", | ||
"@alanscodelog/eslint-config": "^4.0.4", | ||
"@alanscodelog/semantic-release-config": "^3.0.0", | ||
"@alanscodelog/tsconfigs": "^3.1.3", | ||
"@types/node": "^20.4.1", | ||
"@typescript-eslint/eslint-plugin": "^5.61.0", | ||
"@typescript-eslint/parser": "^5.61.0", | ||
"@alanscodelog/tsconfigs": "^3.2.0", | ||
"@types/node": "^20.4.2", | ||
"@typescript-eslint/eslint-plugin": "^6.1.0", | ||
"@typescript-eslint/parser": "^6.1.0", | ||
"@vitest/coverage-c8": "^0.33.0", | ||
"@vue/eslint-config-typescript": "^11.0.3", | ||
"colorjs.io": "^0.4.5", | ||
"commitlint": "^17.6.6", | ||
"commitlint": "^17.6.7", | ||
"concurrently": "^8.2.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.44.0", | ||
"eslint": "^8.45.0", | ||
"eslint-import-resolver-typescript": "^3.5.5", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-jsdoc": "^46.4.3", | ||
"eslint-plugin-jsdoc": "^46.4.4", | ||
"eslint-plugin-simple-import-sort": "^10.0.0", | ||
@@ -90,3 +90,3 @@ "eslint-plugin-vue": "^9.15.1", | ||
"semantic-release": "^21.0.7", | ||
"tailwindcss": "^3.3.2", | ||
"tailwindcss": "^3.3.3", | ||
"ts-node": "^10.9.1", | ||
@@ -96,3 +96,5 @@ "tsc-alias": "^1.8.7", | ||
"typescript": "^5.1.6", | ||
"vite": "^4.4.2", | ||
"vite": "^4.4.4", | ||
"vite-plugin-dts": "^3.3.1", | ||
"vite-plugin-externalize-deps": "^0.7.0", | ||
"vite-tsconfig-paths": "^4.2.0", | ||
@@ -99,0 +101,0 @@ "vitest": "^0.33.0" |
export class Base { | ||
protected _dependants: Base[] = [] | ||
addDep(dep: any): void { | ||
this._dependants.push(dep) | ||
} | ||
removeDep(dep: any): void { | ||
@@ -12,2 +14,3 @@ const i = this._dependants.indexOf(dep) | ||
} | ||
protected _notify(): void { | ||
@@ -18,2 +21,3 @@ for (const dep of this._dependants) { | ||
} | ||
protected notify(..._any: any[]): void { | ||
@@ -20,0 +24,0 @@ throw new Error("Extending class must implement.") |
@@ -34,3 +34,5 @@ import type { MakePrimitive } from "@alanscodelog/utils" | ||
unit: (value: TUnit) => string | ||
value!: TUnit | ||
css: string = "" | ||
@@ -47,2 +49,3 @@ | ||
} | ||
set(value: MakePrimitive<TVal> | TUnit): void { | ||
@@ -52,2 +55,3 @@ this.value = (["number", "string", "boolean"].includes(typeof value) ? { _: value } : value) as TUnit | ||
} | ||
protected notify(): void { | ||
@@ -57,2 +61,3 @@ this.recompute() | ||
} | ||
protected recompute(): void { | ||
@@ -59,0 +64,0 @@ this.css = this.unit(this.value) |
@@ -65,7 +65,13 @@ import { isBlank } from "@alanscodelog/utils" | ||
name: string | ||
unit: (value: TUnit) => string | ||
values!: Value<TUnit> | ||
ready: boolean = false | ||
value: Record<string, any>[] = [] | ||
interpolated: Record<string, string> = {} | ||
options: InterpolatedVarsOptions<ControlVar<any, TUnit>> = { | ||
@@ -80,2 +86,3 @@ roundTo: 3, | ||
} | ||
constructor( | ||
@@ -97,2 +104,3 @@ name: string, | ||
} | ||
setOpts(value: Partial<InterpolatedVarsOptions<ControlVar<any, TUnit>>>): void { | ||
@@ -102,2 +110,3 @@ this.options = { ...this.options, ...value } | ||
} | ||
set(value: Value<TUnit>): void { | ||
@@ -128,2 +137,3 @@ // :/ https://github.com/microsoft/TypeScript/issues/50652 | ||
} | ||
protected notify(): void { | ||
@@ -133,2 +143,3 @@ this.recompute() | ||
} | ||
protected recompute(): void { | ||
@@ -135,0 +146,0 @@ const valRes: Record<string, any>[] = [] |
@@ -14,5 +14,9 @@ import { keys } from "@alanscodelog/utils" | ||
protected ready: boolean = false | ||
els: HTMLElement[] = [] | ||
css: Record<string, string> = {} | ||
value: TValues = {} as any | ||
options: { escapeChar: string } = { | ||
@@ -22,3 +26,5 @@ /** For replacing invalid css variable key characters. */ | ||
} | ||
protected _listeners: Record<string, (() => void) []> = { change: []} | ||
constructor(value: TValues, opts: Partial<Theme<TValues>["options"]> = {}) { | ||
@@ -31,2 +37,3 @@ super() | ||
} | ||
setOpts(value: Partial<Theme<TValues>["options"]> = {}): void { | ||
@@ -37,2 +44,3 @@ this.options = { ...this.options, ...value } | ||
} | ||
add(value: Record<string, ControlVar<any, any> | InterpolatedVars<any> >): void { | ||
@@ -43,2 +51,3 @@ for (const key of keys(value)) { | ||
} | ||
protected _add(key: string, value: InterpolatedVars<any> | ControlVar<any, any>): void { | ||
@@ -54,2 +63,3 @@ if (this.value[key]) throw new Error(`Key ${key} already exists in theme. Use set to change the value.`) | ||
} | ||
remove(key: string): void { | ||
@@ -66,2 +76,3 @@ if (!this.value[key]) return | ||
} | ||
set(key: string, value: InterpolatedVars<any> | ControlVar<any, any>): void { | ||
@@ -76,2 +87,3 @@ if (this.ready) { this.value[key]?.removeDep(this) } | ||
} | ||
protected notify({ recompute = true }: { recompute?: boolean } = {}): void { | ||
@@ -88,5 +100,7 @@ if (!this.ready) return | ||
} | ||
on(type: "change", cb: () => void): void { | ||
this._listeners[type].push(cb) | ||
} | ||
off(type: "change", cb: () => void): void { | ||
@@ -98,2 +112,3 @@ const i = this._listeners[type].findIndex(cb) | ||
} | ||
protected _generateCss( | ||
@@ -140,3 +155,5 @@ res: Record<string, string>, | ||
} | ||
protected _lastPropertiesSet: string[] = [] | ||
// todo move to utils? | ||
@@ -161,2 +178,3 @@ /** | ||
} | ||
/** | ||
@@ -171,2 +189,3 @@ * Attach to an element and automatically set and update the theme's properties on it. | ||
} | ||
detach(el: HTMLElement = document.documentElement): void { | ||
@@ -184,2 +203,3 @@ const existing = this.els.indexOf(el) | ||
} | ||
/** | ||
@@ -186,0 +206,0 @@ * Write theme variables to get autocomplete while developing. Only works from node. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
104618
37
+ Added@alanscodelog/utils@4.0.0-beta.9(transitive)
- Removed@alanscodelog/utils@4.0.0-beta.5(transitive)