Detalhes do pacote

ember-svg-jar

voltidev131.5kMIT2.6.3

Best way to use SVG images in Ember applications

ember-addon

readme (leia-me)

Logo

Best way to use SVG images in Ember apps.

🎮 View Live Demo · 🐞 Report Bug · 🍩 Request Feature · 🤔 Ask Question

Build Status Ember Observer Score

Table of Contents

🍩 Features

Here's some of useful features:

  • Visual workflow to find and use SVGs the fastest way possible
  • Automatic SVG optimization (it can cut file size by half or more)
  • Easy to use helper {{svg-jar "asset-name"}}
  • Support for both inline and symbol embedding methods
  • Copy SVG as CSS background
  • Zero configuration

👋 Getting started

Installation

$ ember install ember-svg-jar

Start in 3 easy steps

  • 1️⃣ Drop some SVG images to the public directory (e.g. material-design-icons)

  • 2️⃣ Open the asset viewer and select any icon you like

  • 3️⃣ Copy the helper code from the viewer and paste it to your template

🎮 Usage

Place your SVG images to the public directory (e.g. ./public/images/my-icon.svg). Then copy the helper code for your image from the asset viewer or just write it by hand like this: {{svg-jar "my-icon"}}.

The viewer is available at: http://localhost:4200/ember-svg-jar/index.html

If your rootURL is not /, then to use the asset viewer you will need to add rootURL to the addon config.

Helper

Use the svg-jar helper to embed SVG images to your application's templates.

For the default inline embedding strategy you can write:

{{svg-jar 'my-cool-icon' class='icon' width='24px'}}

The helper takes an asset ID and optional attributes that will be added to the created SVG element. The example above will create an SVG like this:

<svg class='icon' width='24px'>...</svg>

For the symbol strategy you will need to add # to the asset ID like this:

{{svg-jar '#my-cool-icon'}}

In this case the result can look like this:

<svg><use xlink:href='#my-cool-icon'></use></svg>

Accessibility

Pass title, desc, and role as properties to the helper in order to include accessible elements or attributes. aria-labelledby will be automatically added and point to title and/or desc if they are included.

Writing this:

{{svg-jar 'my-cool-icon' role='img' title='Icon' desc='A very cool icon'}}

Will create an SVG that looks like this:

<svg role="img" aria-labelledby="title desc">
  <title id="title">Icon</title>
  <desc id="desc">A very cool icon<desc>
</svg>

Assets from Node modules

By default ember-svg-jar looks for SVGs in the public directory. To get SVGs from node_modules packages or any other directory you will need to add them to ember-cli-build.js like this:

var app = new EmberApp(defaults, {
  svgJar: {
    sourceDirs: [
      'node_modules/material-design-icons/file/svg/design',
      'node_modules/material-design-icons/action/svg/design',
      'public/images/icons',
    ],
  },
});

Click here for more configuration options

Usage in an addon

Using ember-svg-jar in an addon is the same as in an app, except that in the package.json of the addon, it should be listed as one of the dependencies and not devDependencies.

🔧 Configuration

The addon should be useful without any configuration. But it wants to be very configurable when it's time to adjust it for your needs.

❓ FAQ

Q: Will the asset viewer affect my production build size?
A: No, it won't at all. The asset viewer is included in development mode only.

Q: Can it find SVG icons outside of the public directory, e.g. from node_modules?
A: Yes, it can import SVGs from any directory defined in the sourceDirs array.

Q: Why the SVG files deployed into the dist/assets folder without being fingerprinted?
A: This is done with the default ember cli behaviour. For more information see SVG Fingerprinting.

Q: Why does this matter?

Q: Why would you switch from Font Awesome to SVG?

  • original Font Awesome is about 149 KB as TTF and 88.3 KB as WOFF
  • it includes 634 icons and you need just some of them usually
  • 20 Font Awesome icons in SVGJar will be about 4.3 KB (you save 84 KB or 145 KB as TTF)
  • 50 Font Awesome icons in SVGJar will be about 9 KB

You can get Font Awesome icons as individual SVG files from font-awesome-svg.

👓 Compatibility

Latest ember-svg-jar currently supports:

  • Ember.js v3.20 or above
  • Ember CLI v3.20 or above
  • Node.js v12 or above

💟 Contributors

Contributions of any kind welcome! See the Contributing guide for details.

Thanks goes to these wonderful people:


Ivan Volti

James Herdman

Edward Faulkner

Tobias Bieniek

Robert Wagner

Peter Wagenet

Ryan Cook

Mirko Akov

Ewan McDougall

Mark Catley

John Griffin

Ivan Lučin

James Shih

djsegal

Jan Buschtöns

Sivasubramanyam A

Alex DiLiberto

Brian Runnells

Jen Weber

Frédéric Soumaré

David Laird

Daan van Etten

Tom Carter

Ivan Gromov

Ruslan Hrabovyi

Alex LaFroscia

Laura Knight

Alberto Cantú Gómez

Sergey Astapov

🆓 License

This project is distributed under the MIT license.


GitHub @voltidev  ·  Twitter @voltidev

changelog (log de mudanças)

SVGJar Change Log

v2.4.4

  • [FIX] Simplify inline strategy so multiple versions of ember-svg-jar do not overwrite index.js
  • [FEATURE] Speed up requiring index.js file
  • [FIX] Fix file missing error on embroider when using custom rootURL

v2.4.3

  • [FIX] Proper fixes for embroider
  • [FIX] Use uniqueId for recurring title and desc

v2.4.2

  • [FIX] first embroider fixes

v2.4.1

  • [FIX] fix asset viewer integration

v2.4.0

v2.3.4

Note that this release likely does not work with Ember v4+. The released version of ember-cli-fastboot has an unaddressed problems with modern Ember (see https://github.com/ember-fastboot/ember-cli-fastboot/issues/829). If you find this not to be the case for you, please open an issue with this project so that I can remove this notice. My assurance that these versions don't work is entirely based upon the ember-try-scenario matrix failing for these versions.

  • [FIX] Resolve Ember.assign deprecation

v2.3.3

v2.3.2

Do not use

v2.3.1

  • [ENHANCEMENT] Extract references from symbol to svg-level <defs/> tag
  • [ENHANCEMENT] Add validations.throwOnFailure option
  • [ENHANCEMENT] Add a11y options
  • [INTERNAL] Fix htmlSafe import
  • [INTERNAL] CI uses Github Actions
  • [INTERNAL] Numerous dependency updates
  • [INTERNAL] Add Embroider tests

v2.3.0

Bad release. Hiccups on my first publish of this package. Sorry :( @jherdman

v2.2.1

  • [FIX] Move development dependencies into devDependencies @Turbo87

Full changelog

v2.2.0

  • [ENHANCEMENT] Improved Assets Viewer. It got faster for big SVG collections and has better UI.
  • [INTERNAL] Cleanup some code.

Full changelog

v2.1.0

  • [ENHANCEMENT] Disable removeTitle, removeViewBox, and removeDesc SVGO plugins by default to preserve the original behaviour and stay a zero-configuration addon.
  • [INTERNAL] Get rid of viewer.embed option.
  • [INTERNAL] Improve SVGJar options validation.

Full changelog

v2.0.0

  • [BREAKING ENHANCEMENT] Upgrade SVGO from 0.6.6 to 1.3.0. It's a breaking change to fix security issues of SVGO 0.6.6. In SVGO 1.3.0 most plugins are now active by default (e.g. removeTitle, removeViewBox). This can cause undesired changes in optimized SVG images. In ember-svg-jar v2.1.0 it's not the case anymore for removeTitle, removeViewBox, and removeDesc plugins. Read this document to know what exactly changed. To see changes of default SVGO plugins check out this diff.
  • [CLEANUP] Upgrade ember-cli to 3.11.0, including related packages

Full changelog

v1.2.2

Full changelog

v1.2.1

Full changelog

v1.2.0

  • [internal] Ability to specify which version of svgo to use for optimizer
  • [INTERNAL] Drop Node 4 support
  • [INTERNAL] Update dependencies & cleanup code

Full changelog

v1.1.0

Full changelog

v1.0.0

  • [FEATURE] ember-svg-jar can now be used by addons as a dependency @ef4
  • [FEATURE] Ability to suppress asset validation warnings
  • [CLEANUP] The addon is now fully consumable as a Git dependency, without any build step
  • [CLEANUP] Upgrade to ember-cli 3.0.0 @Dhaulagiri
  • [CLEANUP] Making addon compatible with the latest Ember CLI ember-cli@3.2
  • [FIX] Workaround for broccoli-asset-rev bug (fixes #54)

Full changelog

v0.12.0

Full changelog

v0.11.0

Full changelog

v0.10.3

Full changelog

v0.10.1

Full changelog

v0.10.0

  • [CLEANUP] Fix treeForAddon deprecation warning #27 @ef4
  • [BUGFIX] Fix a problem with .DS_Store #20 @mupkoo
  • [CLEANUP] Upgrade ember-cli to 2.12.1 and related packages
  • [CLEANUP] Refactor node.js related modules

Full changelog

v0.9.3

  • [INTERNAL] The viewer builder skips emtpy SVG
  • [INTERNAL] Upgrade broccoli-svg-optimizer

Full changelog

v0.9.2

  • [ENHANCEMENT] Ability to import svgJar helper to use outside of templates @djsegal
  • [CLEANUP] Refactor helper's code and tests

Full changelog

v0.9.1

  • [FEATURE] Helper supports size attribute {{svg-jar "asset-name" size=2}}
  • [ENHANCEMENT] The viewer now shows asset base size as 24x20px in details
  • [ENHANCEMENT] The viewer allows to copy optimized asset code to clipboard
  • [CLEANUP] Add node tests to cover all broccoli stuff & improve code

Full changelog

v0.9.0

  • [FEATURE] The viewer allows downloading selected assets
  • [FEATURE] The viewer allows copying selected assets' code to the clipboard
  • [FEATURE] The viewer now shows original and optimized file sizes
  • [BREAKING ENHANCEMENT] stripPath is now true by default

This release contains a potentially breaking change. In previous versions of the addon stripPath was set to false by default. It means that some of your asset IDs could look like {{svg-jar "icons/filled/twitter"}}. When stripPath is true the same helper will look like this {{svg-jar "twitter"}}.

If you prefer the old behavior, just add the code below to the ember-cli-build.js:

let app = new EmberApp(defaults, {
  svgJar: {
    stripPath: false,
  },
});

Full changelog

v0.8.3

  • [BUGFIX] Custom helper attrs shouldn't affect the inline assets store
  • [DOC] Add CHANGELOG.md

Full changelog

v0.8.2

  • [FEATURE] svg-jar helper can now bind any passed attributes to created SVG elements
  • [CLEANUP] Upgrade ember-cli to 2.7.0
  • [CLEANUP] Add more tests & clean up the helper's code

Full changelog

v0.8.1

  • [BUGFIX] The viewer correctly shows SVGs with undefined height & width

Full changelog

v0.8.0

  • [FEATURE] Add support for old Ember versions
  • [ENHANCEMENT] Add sidebar links to the viewer

Full changelog

v0.7.0

  • [ENHANCEMENT] Apply stripPath before idGen
  • [CLEANUP] Unify access to strategy specific options
  • [DOC] Add documentation for all configuration options

Full changelog

v0.6.1

  • [CLEANUP] Add acceptance tests
  • [DOC] Improve readme

Full changelog

v0.6.0

  • [CLEANUP] Improve assets validation
  • [CLEANUP] Switch to ES6 for broccoli modules
  • [CLEANUP] Add ESLint and cleanup the code
  • [CLEANUP] Remove compiled files of the viewer from the repo
  • [INTERNAL] Upgrade broccoli-symbolizer

Full changelog

v0.5.0

  • [FEATURE] Add stripPath option
  • [FEATURE] Add assets validation to ensure unique asset IDs
  • [FEATURE] Make the optimizer a strategy specific option
  • [ENHANCEMENT] Strip .svg extension by default
  • [ENHANCEMENT] Allow the dot character . in inline strategy IDs

Full changelog

v0.4.2 - v0.1.0

Full changelog