@acnb/core
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

acnb-core

API for creating cnblog theme.

Install

npm i @acnb/core

API

createTheme

Returns a theme instance that provides a theme context.

import { createTheme } from '@acnb/core'

const theme = createTheme()

defineOptions

Returns a generic configuration object.

import { defineOptions } from '@acnb/core'

const useBackgroundOptions = defineOptions('bodyBackground', {
  enable: false,
  value: '',
  opacity: 0.85,
  repeat: false,
})

Cnblog theme users can add the following configuration:

const opts = {
  bodyBackground: {
    enable: false,
    value: '',
    opacity: 0.85,
    repeat: false,
  },
}

Using configuration aliases:

import { defineOptions } from '@acnb/core'

const useBackgroundOptions = defineOptions(['bodyBackground', 'background'], {
  enable: false,
  value: '',
  opacity: 0.85,
  repeat: false,
})

Plugin System

// plugin.js
import { defineOptions } from '@acnb/core'

export const backgroundPlugin = (theme, devOptions, pluginOptions) => {
  const useBackgroundOptions = defineOptions('bodyBackground', {
    enable: false,
    value: '',
    opacity: 0.85,
    repeat: false,
  })

  const { enable, value, opacity, repeat } = useBackgroundOptions(devOptions)

  if (!enable) return

  const { opacitySelector } = Object.assign(
    {},
    {
      opacitySelector: '#main,#navigator',
    },
    pluginOptions
  )

  setBackground(value, repeat)
  setOpacity(opacity, opacitySelector)
}
// theme/index.js
import { createTheme } from '@acnb/core'
import { backgroundPlugin } from './plugin'

const theme = createTheme()

theme.use(
  backgroundPlugin,
  {
    // Set the default configuration of the theme
    enable: true,
    value: '#ffb3cc',
    opacity: 0.85,
  },
  {
    // Set the default configuration of the plugin
    opacitySelector: '#main',
  }
)

Dependents (3)

Package Sidebar

Install

npm i @acnb/core

Weekly Downloads

1

Version

1.0.8

License

MIT

Unpacked Size

7.02 kB

Total Files

5

Last publish

Collaborators

  • guangzan