Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2 SDF icons support #21

Merged
merged 13 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -22,10 +22,10 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: yarn
run: npm install
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: build
run: yarn run build
run: npm run build
- name: test
run: yarn test
run: npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
*.tgz
.DS_Store
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
}
}
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
- SVG and PNG icon inputs
- Multiple pixel ratio support
- Uses `sharp` for rendering (compatibility with newer Node.js versions and architectures)
- Supports SDF icons

## Install

```bash
yarn add @unvt/sprite-one
```

or

```bash
npm install @unvt/sprite-one
```
Expand All @@ -20,7 +15,7 @@ npm install @unvt/sprite-one

- CLI

```zsh
```bash
$ sprite-one -h
Usage: sprite-one [options] <sprite_filename>

Expand All @@ -30,6 +25,7 @@ Options:
-v, --version output the version number
-i, --icon <icons...> A folder path which stores SVG icons. Multiple folders can be set.
-r, --ratio <ratios...> pixel ratio to generate sprite. default is 1.
--sdf generate sprite with SDF (Signed Distance Field). (default: false)
-h, --help display help for command
```

Expand All @@ -54,14 +50,24 @@ If the `@2x` version doesn't exist, the default icon will be used and scaled up

Note that while this feature is supported for SVG icons, this is usually unneccesary because SVG, as a vector format, can be scaled without problems.

### SDF icons support

SDF icons can be generated by using the `--sdf` option. This allows users to apply [icon-color](https://maplibre.org/maplibre-style-spec/layers/#paint-symbol-icon-color) and [icon-halo-color](https://maplibre.org/maplibre-style-spec/layers/#paint-symbol-icon-halo-color) properties in Maplibre style to able to change the colour dynamically.

```javascript
import { generateSprite } from '@unvt/sprite-one'

generateSprite('../out', '../input', [1], true).then(() => {})
```

## Develop

via `bin/index.ts`

```bash
git clone https://github.com/unvt/sprite-one.git
cd sprite-one
yarn
npm install
npx ts-node src/bin/index.ts ../../tmp/out --icon ../../tmp/maki/icons
npx ts-node src/bin/index.ts ../../tmp/out --icon ../../tmp/maki/icons --ratio=2
npx ts-node src/bin/index.ts ../../tmp/out --icon ../../tmp/maki/icons --icon ../../tmp/maki/icons2 --ratio=1 --ratio=2
Expand Down
Loading