File size: 1,138 Bytes
4d70170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const icons = require.context(
  '@akryum/md-icons-svg/svg/',
  true,
  /materialicons\/24px\.svg$/,
)

export default {
  install() {
    const sprites = ['']
    let spriteIndex = 0
    // Load all the SVG symbols
    icons.keys().forEach((key, index) => {
      let result = icons(key)
      const [, iconName] = /(\w+)\/materialicons/.exec(key)
      // eslint-disable-next-line regexp/no-super-linear-backtracking
      const [, content] = /<svg.+?>(.*)<\/svg>/.exec(result)
      result = `<svg xmlns="http://www.w3.org/2000/svg" id="ic_${iconName}_standard" viewBox="0 0 24 24">${content}</svg>`
      sprites[spriteIndex] += result
      if ((index + 1) % 40 === 0) {
        sprites.push('')
        spriteIndex++
      }
    })
    for (const html of sprites) {
      const iconsWrapper = document.createElement('div')
      iconsWrapper.style.display = 'none'
      iconsWrapper.innerHTML = html
      document.body.insertBefore(iconsWrapper, document.body.firstChild)
    }
  },
}

export function generateHtmlIcon(icon: string) {
  return `<div class="vue-ui-icon"><svg><use href="#ic_${icon}_standard"></use></svg></div>`
}