aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/core/parser.js
blob: 12c9728dcb78f65176121c18956cae3ad91a4aeb (plain)
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
import { globals } from '../../utils/window.js'
import { makeInstance } from '../../utils/adopter.js'

export default function parser () {

  // Reuse cached element if possible
  if ( !parser.nodes ) {

    let svg = makeInstance().size( 2, 0 )
    svg.node.cssText = [
      'opacity: 0',
      'position: absolute',
      'left: -100%',
      'top: -100%',
      'overflow: hidden'
    ].join( ';' )

    let path = svg.path().node

    parser.nodes = { svg, path }

  }

  if ( !parser.nodes.svg.node.parentNode ) {

    let b = globals.document.body || globals.document.documentElement
    parser.nodes.svg.addTo( b )

  }

  return parser.nodes

}