1.4.11 • Published 9 months ago

@blockquote-web-components/blockquote-directive-svg-to-data-image v1.4.11

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

blockquoteDirectiveSvgToDataImage

Lit

This directive receives an <svg> HTML element from a Template Result and returns it as data URI (data:image/svg+xml).

svg-templates

Demo

Open in StackBlitz

Usage

Simple SVG

get _svgTag() {
  return html` <svg
    xmlns="htt://www.w3.org/2000/svg"
    viewBox="0 0 100 100"
    height="100px"
    width="100px"
  >
    <!-- ... (SVG content) ... -->
  </svg>`;
}

render() {
  return html`
    <div
      aria-hidden="true"
      style="background-image: url('${blockquoteDirectiveSvgToDataImage(this._svgTag)}');"
    ></div>
  `;
}

Complex SVG

get _bgTpl() {
  return svg` <circle fill="${this.bgFill}" cx="100" cy="100" r="100"></circle> `;
}

get _shapeTpl() {
  return svg`
    <g fill="#fff">
      <!-- ... (SVG content) ... -->
    </g>
  `;
}

get _svgTag() {
  return html`<svg
    id="${Math.random().toString(36).substring(2, 10)}"
    xmlns="http://www.w3.org/2000/svg"
    width="200"
    height="200"
    focusable="false"
    role="presentation"
    viewBox="0 0 200 200"
  >
    ${this._bgTpl} ${this._shapeTpl}
  </svg>`;
}

render() {
  return html`
    <div
      aria-hidden="true"
      style="background-image:var(--bgUrl, url('${blockquoteDirectiveSvgToDataImage(this._svgTag)}'));"
    ></div>
  `;
}

src/BlockquoteDirectiveSvgToDataImage.js:

Variables

NameDescriptionType
blockquoteDirectiveSvgToDataImage

Exports

KindNameDeclarationModulePackage
jsREADMEREADMEsrc/BlockquoteDirectiveSvgToDataImage.js
jsblockquoteDirectiveSvgToDataImageblockquoteDirectiveSvgToDataImagesrc/BlockquoteDirectiveSvgToDataImage.js

src/index.js:

Exports

KindNameDeclarationModulePackage
jsblockquoteDirectiveSvgToDataImageblockquoteDirectiveSvgToDataImage./BlockquoteDirectiveSvgToDataImage.js
1.4.11

9 months ago

1.4.10

9 months ago

1.4.9

9 months ago

1.4.6

10 months ago

1.4.8

10 months ago

1.4.7

10 months ago

1.4.5

12 months ago

1.4.4

1 year ago

1.4.3

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.1

2 years ago

1.1.0

3 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago