21 Commits

Author SHA1 Message Date
chris48s
8a98824e5e use SVG2 hrefs (#10918)
* use SVG2 hrefs

* add note to badge-maker changelog
2025-03-03 17:58:48 +00:00
LitoMore
d51b47a9fd fix badge style when logo only (#10794)
* fix badge style when logo only

* simply logo-only condition

* Update variable name

* Update and add snapshots

* Fixes

* Update test and snapshot

* fix tests
2025-01-26 16:10:03 +00:00
chris48s
152b8e9a64 fix badge-maker package tests (#10809) 2025-01-18 19:16:59 +00:00
valkyrie_pilot
9ab1a906b2 Add option for IDs to have a prefix (#10576)
* Add option for IDs to have a prefix

* Switch to suffixes to protect ID values

* Document idSuffix

* Fix validation error message consistency

* Fix ID suffix regex test

* Add tests

* snapshot tests for idSuffix covering all 5 badge styles

* tweak docs

* update typescript definitions

* badge-maker 4.1.0 release

---------

Co-authored-by: chris48s <git@chris-shaw.dev>
2024-10-13 16:47:50 +00:00
chris48s
779c1ffaad fix incorrect colorsForBackground detection (#6939)
* pass an actual color to colorsForBackground (closes #6936)

* improve test coverage for non-default font color
2021-08-22 16:59:25 +01:00
Paul Melnikow
cdd68fee7f Make for-the-badge letter spacing more predictable, and rewrite layout logic (#5754)
* Rewrite for-the-badge renderer
* Update snapshots
* Remove pixel grid alignment in for-the-badge
* abstract XML stringification to XmlElement class

Co-authored-by: chris48s <chris48s@users.noreply.github.com>
Co-authored-by: chris48s <chris.shaw480@gmail.com>
2021-05-26 20:55:28 +01:00
Paul Melnikow
af3f720113 Improve appearance of for-the-badge and social badges by measuring correct font (#5696)
Even before #2311, Shields has measured all badge text using 11px Verdana, which is the correct font for plastic, flat, and flat-square.

However the for-the-badge style uses 10px Verdana and bold 10px Verdana, and the social badge uses bold 11px _Helvetica_. This causes these badges to be wider or narrower than they should be, and the text to be stretched accordingly.

Since the for-the-badge style relies on synthetic letter spacing (we just multiply the computed length in code) there is room to massage this further. Our test badges all look as good or better than before, so I think it should not block merging this, however we might need to get it right before the downstream problem in squint goes away. (There's also #4691 which this doesn't attempt to address.)

Fixes #4275
2020-10-15 20:06:46 -04:00
Paul Melnikow
cd70bf5246 Prettify the SVG snapshots (and a couple cleanups) (#5714)
I’m running into some strange issues working on badge-maker in #5696, where the images look good but the snapshots have changed in unexpected ways. I’m finding them a little tricky to debug.

This saves the prettified snapshots instead, which I think will make them easier to compare and debug. They may have to be updated when we upgrade prettier.

I also inlined a few things in the test file.
2020-10-15 19:40:14 -04:00
Pierre-Yves B
471f3f4ad1 Use black font when background color is too light (#5467)
* Use black font when background color is too light

* Tweak dark color

* Extract magic brightness numbers to constants

* Fix snapshot tests

* Switch threshold to 0.69
2020-09-07 19:07:28 +02:00
Evelyn Hathaway
c1ded757c7 feat: add accessible text alternative in when a graphic and link (#5289)
Co-authored-by: chris48s <chris48s@users.noreply.github.com>
2020-07-13 20:07:26 +01:00
Makarenko Anton
6ca2fa0c89 Fix rendering in Firefox on Windows (#5038)
Close #4813
2020-05-04 20:01:15 -04:00
chris48s
17374873ad fix link width params (#4991)
closes #4989

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2020-05-01 20:55:57 +00:00
chris48s
3ba05cb184 📦 version 3 (#4756)
* Validate input to BadgeFactory.create() (#3875)

* validate input to create()

* remove deprecated properties (#3881)

* remove BadgeFactory class (#3884)

* Template literal templates (#4459)

- Remove use of the doT template library and move to generating SVG output using javascript template literals.
- Drop SVGO and mostly manually implement the optimisations.
- Add a bunch more tests

Co-authored-by: Paul Melnikow <github@paulmelnikow.com>

* drop raster support in package CLI (#4523)

* drop raster support in package CLI
* update docs

* rename gh-badges package to badge-maker

* rename gh-badges dir to badge-maker

* update relative imports and other refs to in parent dir

'gh-badges' --> 'badge-maker'

* update snyk service tests

This change is only tangentially related

We've used the shields repo as an example for these tests so
moving files around in our repo has a knock-on effect on them

* add missing type hints to dev style page

* write the changelog/migration guide for v3

* use extension in README CLI example

* update CLI help

whoops - missed this in #4523

* bump version

* update for self-hosting users

* README updates

* drop .format param from CLI, always output SVG

* Change text[] to label and message, Remove JSON output

- Change text[] to label and message
- Fix message only badge
- Remove JSON output format
- Update the docs

* update package-lock

* rename 'template' to 'style'

* handle invalid styles in coalesceBadge

* ensure makeBadge is passed a string for template in coalesceBadge()

issue #4925

* fix (logo/no label text/label color specified) case

issue #4926

* add example of (logo/no label text/label color specified) to style debug page

* update type defs

* padding fix for FTB style

Co-authored-by: Paul Melnikow <github@paulmelnikow.com>
2020-04-23 20:05:48 +01:00
Paul Melnikow
ae2499bf53 Generate JSON badges without using a template [GithubSearch] (#3395)
Warm up for #2428.
2019-04-29 23:26:52 -04:00
Pierre-Yves B
9a869e24ba Added link test expectations (#3376) 2019-04-29 18:52:58 +01:00
Pierre-Yves B
25f8541e5b JSON format modernisation and _shields_test removal (#3272)
* Modernised JSON format and removed _shields_test style

* Added logoWidth and labelColor fields to JSON response

* Reinstated and updated comment

* Extended expectBadge to accept Joi schemas for all fields
2019-04-07 18:57:55 +01:00
Paul Melnikow
51897b3c7e Precompute text width using a lookup table (#2311)
This simplifies and further optimizes text-width computation by computing the entire width table in advance, and serializing it in the style of QuickTextMeasurer (#1390). This entirely removes the need for PDFKit at runtime. This has the advantage of fixing #1305 – more generally: producing the same result everywhere – without having to deploy a copy of Verdana.

The lifting is delegated to these three libraries, which are housed in a monorepo: https://github.com/metabolize/anafanafo

I'd be happy to move it into the badges org if folks want to collaborate on maintaining them.

QuickTextMeasurer took kerning pairs into account, whereas this implementation does not. I was thinking kerning would be a necessary refinement, though this seems to work well enough.

I dropped in a binary-search package to traverse the data structure, in part to conserve space. This causes a moderate performance regression, though there is ample room for improving on that: https://github.com/badges/shields/pull/2311#issuecomment-439182704
2018-11-15 17:27:21 -05:00
chris48s
04290e890b delete snapshots with no corresponding test (#2111) 2018-09-24 21:19:13 +01:00
Danial
317e19ea2a Add support for simple-icons, colored icons with ?logoColor (#1810)
* add simple-icons

* handle undefined

* support logoColor param

* our icon > simple-icon

* dont crash 

* return false → undefined

* update test

* add test

* support logoColor on our logos

* cache as base64, pre-load-simple-icons, logo-helper

* add ?logoColor information

* and simple-icons reference, link to github master branch for our logos

* update simple-icons

update to 1.7.1

* Revert "and simple-icons reference, link to github master branch for our logos"

This reverts commit 5e99d5f8db.

* add link to simple-icons

* Add snapshot test

* support dash in place of space for logo name
2018-08-02 09:07:23 +12:00
Danial
b216bcc17e Hide left hand of badge if no label (#1585)
* hide left side if no text

* fix whitespace at start of template

* for-the-badge done

* center text

* add logo support

* update snapshot test

* make first - in static badge optional

* add no label support to non static badges

* Add test for label

* update to not allow use of false/0/null

* fixup
2018-07-27 08:27:32 +12:00
Paul Melnikow
ae848f38f4 Add snapshot tests for SVG and JSON (#1557)
These tests should fail if something is accidentally changed that affects the SVG or JSON files. In the case of deliberate changes, we can update the snapshots.
2018-03-11 09:07:03 -07:00