1.4.0 • Published 2 months ago

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

Weekly downloads
-
License
MIT
Repository
-
Last release
2 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.0

2 months ago

1.3.0

2 months ago

1.2.9

4 months ago

1.2.8

4 months ago

1.2.7

4 months ago

1.2.6

4 months ago

1.2.5

4 months ago

1.2.4

4 months ago

1.2.3

5 months ago

1.2.2

6 months ago

1.2.1

6 months ago

1.2.0

6 months ago

1.1.9

10 months ago

1.1.8

11 months ago

1.1.7

11 months ago

1.1.6

11 months ago

1.1.5

11 months ago

1.1.4

11 months ago

1.1.11

7 months ago

1.1.10

9 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago