-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring full support for row- and cell-params (#11)
- Loading branch information
Showing
4 changed files
with
106 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { parse } from 'qs'; | ||
import type { CSSProperties } from 'vue'; | ||
|
||
const YES = ['1', 'yes', 'y', 'true']; | ||
const LEFT = ['l', 'left']; | ||
const RIGHT = ['r', 'right']; | ||
const TOP_LEFT = ['la', 'tl', 'c4', 'nw', 'top-left', 'topleft']; | ||
const TOP_RIGHT = ['ra', 'tr', 'c1', 'ne', 'top-right', 'topright']; | ||
const BOTTOM_LEFT = ['le', 'bl', 'c3', 'sw', 'bottom-left', 'bottomleft']; | ||
const BOTTOM_RIGHT = ['re', 'br', 'c2', 'se', 'bottom-right', 'bottomright']; | ||
|
||
export default function styleFromParams(text: string | undefined): CSSProperties { | ||
const style = {} as CSSProperties; | ||
const params = parse(text ?? '', { delimiter: ',' }) as Record<string, string>; | ||
|
||
if (params.bg) { | ||
style.backgroundColor = params.bg; | ||
} else if (params.background) { | ||
style.backgroundColor = params.background; | ||
} else if (params.bgcolor) { | ||
style.backgroundColor = params.bgcolor; | ||
} | ||
|
||
if (params.color) { | ||
style.color = params.color; | ||
} else if (params.colour) { | ||
style.color = params.colour; | ||
} | ||
|
||
if (YES.includes(params.b ?? params.bold)) { | ||
style.fontWeight = 'bold'; | ||
} | ||
|
||
if (YES.includes(params.i ?? params.it ?? params.italic)) { | ||
style.fontStyle = 'italic'; | ||
} | ||
|
||
if ([...LEFT, ...TOP_LEFT].includes(params.align)) { | ||
style['--bs-map-cell-halign'] = 'left'; | ||
} else if ([...RIGHT, ...TOP_RIGHT].includes(params.align)) { | ||
style['--bs-map-cell-halign'] = 'right'; | ||
} | ||
|
||
if ([...TOP_LEFT, ...TOP_RIGHT].includes(params.align)) { | ||
style['--bs-map-cell-valign'] = 'top'; | ||
} else if ([...BOTTOM_LEFT, ...BOTTOM_RIGHT].includes(params.align)) { | ||
style['--bs-map-cell-valign'] = 'bottom'; | ||
} | ||
|
||
return style; | ||
} |