Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 919a7cc
Showing
25 changed files
with
26,701 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"ignorePatterns": ["node_modules/", "*.js"], | ||
"plugins": ["@typescript-eslint", "prettier", "tsdoc"], | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier", | ||
"prettier/@typescript-eslint" | ||
], | ||
"rules": { | ||
"no-console": ["warn", { "allow": ["error"] }], | ||
"object-shorthand": ["error", "always"], | ||
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }], | ||
"eol-last": ["error", "always"], | ||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"prettier/prettier": ["error"], | ||
"tsdoc/syntax": "warn" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Logs | ||
.DS_Store | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
coverage | ||
.nyc_output | ||
node_modules/ | ||
|
||
dist/ | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
yarn-error.log* | ||
|
||
coverage | ||
.nyc_output | ||
|
||
api/ | ||
config/ | ||
src/ | ||
test/ | ||
tmp/ | ||
.eslint* | ||
.prettier* | ||
ava.config.js | ||
tsconfig.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"semi": false, | ||
"trailingComma": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
Version 2, December 2004 | ||
|
||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> | ||
|
||
Everyone is permitted to copy and distribute verbatim or modified | ||
copies of this license document, and changing it is allowed as long | ||
as the name is changed. | ||
|
||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
|
||
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# svg-autocrop | ||
|
||
A tool for cutting out redundant transparent space from SVG images. It returns the original SVG without any changes besides a `viewBox` attribute updated/added to be as small as possible to fit all of the opaque content. | ||
|
||
## Functions | ||
|
||
### autocrop | ||
|
||
Automatically crops the SVG's viewBox so it doesn't contain redundant transparent content. For performance reasons, it's much preferable to batch requests by passing in an array of images rather than making many frequent requests with single ones. That way all of the SVGs in the array are put on the same page and screenshotted at the same time. | ||
|
||
**Overloads:** | ||
<details> | ||
<summary><code class="language-typescript">(input: string, options?: <a href="#Options">Options</a>): Promise<string></code></summary> | ||
|
||
```typescript | ||
async function autocrop(input: string, options?: Options): Promise<string> | ||
``` | ||
|
||
**Parameters:** | ||
|
||
Name | Type | Description | | ||
------ | ------ | ------ | | ||
`input` | string | A string with the input SVG | | ||
`options?` | [Options](#Options) | Settings for the function | | ||
|
||
**Returns:** A promise containing the SVG with the viewBox cropped | ||
</details> | ||
|
||
<details> | ||
<summary><code class="language-typescript">(input: string[], options?: <a href="#Options">Options</a>): Promise<string[]></code></summary> | ||
|
||
```typescript | ||
async function autocrop(input: string[], options?: Options): Promise<string[]> | ||
``` | ||
|
||
**Parameters:** | ||
|
||
Name | Type | Description | | ||
------ | ------ | ------ | | ||
`input` | string[] | A string array with the input SVGs | | ||
`options?` | [Options](#Options) | Settings for the function | | ||
|
||
**Returns:** A promise containing the SVGs with the viewBoxes cropped | ||
</details> | ||
|
||
___ | ||
|
||
### startBrowser | ||
|
||
Starts the Chrome instance. Used to achieve extra performance by keeping a single browser instance instead of creating a new one for each request. The browser will keep running until the [closeBrowser](#closebrowser) function is invoked or the process emits the `exit` event. In some environments like Jest invoking [closeBrowser](#closebrowser) might be necessary to prevent memory leaks as the process doesn't close the browser on its own when exiting. | ||
|
||
```typescript | ||
const startBrowser: () => Promise<ChildProcess> | ||
``` | ||
|
||
**Returns:** A promise containing the instance of the spawned child process | ||
|
||
___ | ||
|
||
### closeBrowser | ||
|
||
Closes the Chrome instance that was started using the [startBrowser](#startbrowser) function. | ||
|
||
```typescript | ||
const closeBrowser: () => void | ||
``` | ||
|
||
## Inferfaces | ||
|
||
### Options | ||
|
||
Options for the main [autocrop](#autocrop) function | ||
|
||
```typescript | ||
interface Options { | ||
size?: number | ||
scale?: number | ||
} | ||
``` | ||
|
||
**Properties:** | ||
|
||
• **scale** - How much to scale the viewbox after cropping. Used to prevent opaque parts of the image from being cut and/or to put extra whitespace around it. *Default:* `1.05` | ||
|
||
• **size** - Height and width of a single bitmap in pixels. The higher the size the better the precision, but the slower the performance. *Default:* `100` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## API Report File for "@mzdunek/svg-autocrop" | ||
|
||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
```ts | ||
|
||
import { ChildProcess } from 'child_process'; | ||
|
||
// @beta | ||
function autocrop(input: string[], options?: Options): Promise<string[]>; | ||
|
||
// @beta | ||
function autocrop(input: string, options?: Options): Promise<string>; | ||
|
||
export { autocrop } | ||
|
||
export default autocrop; | ||
|
||
// @beta | ||
export function closeBrowser(): void; | ||
|
||
// @beta | ||
export interface Options { | ||
scale?: number; | ||
size?: number; | ||
} | ||
|
||
// @beta | ||
export function startBrowser(): Promise<ChildProcess>; | ||
|
||
|
||
// (No @packageDocumentation comment for this package) | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
"extensions": [ | ||
"ts" | ||
], | ||
"require": [ | ||
"ts-node/register" | ||
] | ||
} |
Oops, something went wrong.