Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sonofmagic/dom-styler

dom-styler
https://github.com/sonofmagic/dom-styler

Last synced: about 1 month ago
JSON representation

dom-styler

Awesome Lists containing this project

README

        

# dom-styler

> dom-styler,manage your dom style easily!

## Usage

```ts
import {
DomStyler,
createDocumentElementStyler,
createDomStyler
} from 'dom-styler'

const manager = new DomStyler(dom)
// same to
const manager1 = createDomStyler(dom)
// default document.documentElement
const docManager = createDocumentElementStyler()

const themeJson = {
width: '100px',
height: {
value: '100vh',
priority: 'important'
},
color: (value, priority) => {
return {
value: newValue,
priority: newPriority
}
}
}
// also you can set themeJson as an array
const key = 'custom-theme'
manager.setVariables(themeJson)
manager.setSingleVariable(property, value, priority)
manager.removeProperty(property)
manager.getPropertyValue(property)
manager.saveTheme(themeJson, key)
manager.sync()
```

## APIS

```ts
export declare type VariablesItem = {
value?: string
priority?: string
}
export declare type VariablesParamValue =
| string
| VariablesItem
| ((variables: VariablesItem) => VariablesItem)
export declare type VariablesParamMap = Record
export declare type SetVariablesParams = VariablesParamMap[] | VariablesParamMap

export declare class DomStyler {
root: HTMLElement
style: CSSStyleDeclaration
constructor(dom?: HTMLElement)
private handleParam
setVariables(param: SetVariablesParams): void
setSingleVariable(property: string, value?: string, priority?: string): void
removeProperty(property: string): string
item(index: number): string
getPropertyValue(property: string): string
getPropertyPriority(property: string): string
sync(cacheKey?: string): any
saveTheme(theme: Record, cacheKey?: string): void
}
export declare const createDocumentElementStyler: () => DomStyler
export declare const createDomStyler: (dom: HTMLElement) => DomStyler
```