Skip to content

Commit

Permalink
feat: move GAP into theme options
Browse files Browse the repository at this point in the history
  • Loading branch information
SSShooter committed Nov 3, 2024
1 parent b6e88ce commit 60d0a0c
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Features:
- Bulk operations supported
- Undo / Redo
- Efficient shortcuts
- Easily Styling your node with CSS
- Easily Styling your node with CSS variables

<details>
<summary>Table of Contents</summary>
Expand Down
4 changes: 1 addition & 3 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ export const RIGHT = 1
export const SIDE = 2
export const DOWN = 3

// TODO: move to options
export const GAP = 30 // must sync with --gap in index.less

export const THEME: Theme = {
name: 'Latte',
palette: ['#dd7878', '#ea76cb', '#8839ef', '#e64553', '#fe640b', '#df8e1d', '#40a02b', '#209fb5', '#1e66f5', '#7287fd'],
cssVar: {
'--gap': '30px',
'--main-color': '#444446',
'--main-bgcolor': '#ffffff',
'--color': '#777777',
Expand Down
3 changes: 1 addition & 2 deletions src/index.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.mind-elixir {
--gap: 30px; // child node horizontal gap, it will be updated at instance initialization

// May overwrited by js
--gap: 30px; // child node horizontal gap
--root-radius: 30px;
--main-radius: 20px;
--root-color: #ffffff;
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './index.less'
import './iconfont/iconfont.js'
import { LEFT, RIGHT, SIDE, GAP, DARK_THEME, THEME } from './const'
import { LEFT, RIGHT, SIDE, DARK_THEME, THEME } from './const'
import { generateUUID } from './utils/index'
import initMouseEvent from './mouse'
import Bus from './utils/pubsub'
Expand Down Expand Up @@ -52,7 +52,6 @@ function MindElixir(

ele.className += ' mind-elixir'
ele.innerHTML = ''
ele.style.setProperty('--gap', GAP + 'px')
this.mindElixirBox = ele as HTMLElement
this.disposable = []
this.before = before || {}
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type Theme = {
name: string
palette: string[]
cssVar: Partial<{
'--gap': string
'--main-color': string
'--main-bgcolor': string
'--color': string
Expand Down
3 changes: 2 additions & 1 deletion src/utils/generateBranch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { MindElixirInstance } from '..'
import { GAP } from '../const'

export type MainLineParams = {
pT: number
Expand Down Expand Up @@ -50,6 +49,8 @@ export function main({ pT, pL, pW, pH, cT, cL, cW, cH, direction, containerHeigh
}

export function sub(this: MindElixirInstance, { pT, pL, pW, pH, cT, cL, cW, cH, direction, isFirst }: SubLineParams) {
const GAP = parseInt(this.mindElixirBox.style.getPropertyValue('--gap')) // cache?
// const GAP = 30
let y1 = 0
let end = 0
if (isFirst) {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/theme.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { THEME } from '../const'
import type { MindElixirInstance } from '../types/index'
import type { Theme } from '../types/index'

const changeTheme = function (this: MindElixirInstance, theme: Theme, shouldRefresh = true) {
theme.cssVar = { ...THEME.cssVar, ...theme.cssVar }
this.theme = theme
const cssVar = this.theme.cssVar
const keys = Object.keys(cssVar)
this.mindElixirBox.style.cssText = ''
for (let i = 0; i < keys.length; i++) {
const key = keys[i] as keyof typeof cssVar
this.mindElixirBox.style.setProperty(key, cssVar[key] as string)
}
if (!theme.cssVar['--gap']) {
this.mindElixirBox.style.setProperty('--gap', '30px')
}
shouldRefresh && this.refresh()
}

Expand Down

0 comments on commit 60d0a0c

Please sign in to comment.