Skip to content

Commit 40ea61f

Browse files
committed
chore: release v0.1.0
1 parent 88d847b commit 40ea61f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+382
-0
lines changed

β€Ž.gitignoreβ€Ž

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.DS_Store
2+
node_modules
3+
4+
# local env files
5+
.env.local
6+
.env.*.local
7+
8+
# Log files
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
13+
# Editor directories and files
14+
.idea
15+
.vscode
16+
*.suo
17+
*.ntvs*
18+
*.njsproj
19+
*.sln
20+
*.sw?

β€ŽHeroPattern.vueβ€Ž

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<template>
2+
<div class="hero-pattern" :style="style">
3+
<slot />
4+
</div>
5+
</template>
6+
7+
<script>
8+
import { SVG_DATAURI } from '@dynamic/svg2datauri'
9+
10+
export default {
11+
name: 'HeroPattern',
12+
props: {
13+
// Pattern Name
14+
pattern: { type: String, default: 'line-in-motion' },
15+
// Given color is hexadecimal color value
16+
fillColor: {
17+
type: String,
18+
default: () => '#9c92ac',
19+
validator (val) {
20+
const regex = /#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})/g
21+
return regex.test(val)
22+
}
23+
},
24+
// Given color is hexadecimal color value
25+
backgroundColor: {
26+
type: String,
27+
default: () => '#dfdbe5',
28+
validator (val) {
29+
const regex = /#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})/g
30+
return regex.test(val)
31+
}
32+
},
33+
fillOpacity: {
34+
type: String,
35+
default: () => '0.4'
36+
},
37+
repeat: { type: String, default: 'repeat' }
38+
},
39+
data: () => ({
40+
svgDataUri: SVG_DATAURI
41+
}),
42+
computed: {
43+
style () {
44+
let svg = {}
45+
const idx = this.svgDataUri.findIndex(element => element.name.split('.').shift() === this.pattern)
46+
if (idx !== -1) {
47+
svg = this.svgDataUri[idx]
48+
const drop = (arr, n = 1) => arr.slice(n)
49+
const color = drop(Array.from(this.fillColor)).join('')
50+
const fillReg = /fill='(\w+|\S+)'/g
51+
const fillOpacityReg = /fill-opacity='(\w+|\S+)'/
52+
53+
const datauri = svg.datauri
54+
.replace(fillReg, `fill='%23${color}'`)
55+
.replace(fillOpacityReg, `fill-opacity='${this.fillOpacity}'`)
56+
57+
return {
58+
'background-color': this.backgroundColor,
59+
'background-image': `url("${datauri}")`,
60+
'background-repeat': this.repeat
61+
}
62+
}
63+
return {}
64+
}
65+
},
66+
mounted () {
67+
// this.getPattern()
68+
// console.log(SVG_DATAURI)
69+
},
70+
methods: {
71+
// async getPattern () {
72+
// const svg = await fs.readFile(path.join(__dirname, './assets/icons/line-in-motion'))
73+
// console.log(svg)
74+
// const uri = svgToMiniDataURI(svg)
75+
// console.log(uri)
76+
// },
77+
getRandomColor (hexs) {
78+
const shuffle = ([...arr]) => {
79+
let m = arr.length
80+
while (m) {
81+
let temp = null
82+
const i = Math.floor(Math.random() * m--)
83+
temp = arr[m]
84+
arr[m] = arr[i]
85+
arr[i] = temp
86+
}
87+
return arr
88+
}
89+
return shuffle(hexs).join('')
90+
}
91+
}
92+
}
93+
</script>
94+
95+
<style scoped>
96+
.hero-pattern {
97+
transition: all 0.5s ease-in-out;
98+
}
99+
</style>

β€ŽREADME.mdβ€Ž

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Vuepress Plugin HeroPattern
2+
3+
Register a global `<HeroPattern />` component for VuePress.
4+
5+
This component generate a seemless SVG background pattern.
6+
7+
> This plugin is a adaptor of [hero-pattern](http://www.heropatterns.com/) for VuePress
8+
9+
## See Demo on CodeSandbox
10+
11+
[![Edit vuepress-plugin-hero-pattern](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/musing-surf-twidv?fontsize=14&hidenavigation=1&theme=dark)
12+
13+
## Installation
14+
15+
```bash
16+
yarn add vuepress-plugin-hero-pattern -S
17+
or
18+
npm i vuepress-plugin-hero-pattern -S
19+
```
20+
21+
## Register the plugin
22+
23+
```js
24+
...
25+
module.exports = {
26+
...,
27+
plugins: {
28+
['hero-pattern']
29+
},
30+
...
31+
}
32+
...
33+
```
34+
35+
## Usage
36+
37+
> Only background image, you must give the width & height of the element
38+
39+
```vue
40+
<HeroPattern style="width: 240px; height: 80px;" />
41+
```
42+
43+
> With the custom slot, in the case, you can let the slot element control the pattern's height
44+
Γ·
45+
```vue
46+
<hero-pattern>
47+
<div style="padding: 64px; font-size: 2rem; color: white;">
48+
All Posts
49+
</div>
50+
</hero-pattern>
51+
```
52+
53+
## API
54+
55+
| Props | Description | Type | Default |
56+
| :---: | :---------: | :--: | :-----: |
57+
| pattern | 87 kinds of patterns that Hero Patterns supported, check [pattern list]() | String | `line-to-motion` |
58+
| fillColor | Controls the foreground color of the generated image. | String | `#9c92ac` |
59+
| fillOpacity | Controls the foreground opacity of the generated image. | String | `0.4` |
60+
| backgroundColor | Controls the background color of the generated image. | String | `#dfdbe5` |
61+
| repeat | Controls how the background repeated of the generated image. | String | `repeat` |
62+
63+
## Slot
64+
65+
`<HeroPattern />` component provide a custom slot, you can write some element on the generated pattern.
66+
67+
## License
68+
69+
MIT @ [xiaoluoboding](https://github.com/xiaoluoboding)
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

β€Žassets/icons/architect.svgβ€Ž

Lines changed: 1 addition & 0 deletions
Loading

β€Žassets/icons/autumn.svgβ€Ž

Lines changed: 1 addition & 0 deletions
Loading

β€Žassets/icons/aztec.svgβ€Ž

Lines changed: 1 addition & 0 deletions
Loading

β€Žassets/icons/bamboo.svgβ€Ž

Lines changed: 1 addition & 0 deletions
Loading

β€Žassets/icons/bank-note.svgβ€Ž

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
Β (0)