Skip to content

Commit ddd2e68

Browse files
author
thuongtruong109
committed
fix(pkg): width size
1 parent 07c59c9 commit ddd2e68

File tree

11 files changed

+55
-66
lines changed

11 files changed

+55
-66
lines changed

.config/eslint.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export default tseslint.config([
99
sonarjs.configs.recommended,
1010
{
1111
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
12-
ignores: ["coverage/**", "dist/**", "examples/**"],
1312
plugins: { js },
1413
languageOptions: { globals: { ...globals.browser, ...globals.node } },
1514
rules: {
@@ -18,5 +17,5 @@ export default tseslint.config([
1817
"sonarjs/no-commented-code": "off",
1918
},
2019
},
21-
globalIgnores(["dist/**/*"]),
20+
globalIgnores(["dist/**/*", "api/**/*"]),
2221
]);

.config/lefthook.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
# Lefthook configuration for git hooks
2-
# Documentation: https://lefthook.dev/configuration/
3-
41
pre-commit:
52
parallel: true
63
jobs:
74
- name: eslint
85
glob: "*.{js,ts,jsx,tsx}"
9-
run: bun run eslint --config .config/eslint.config.ts {staged_files}
10-
6+
run: bun run lint {staged_files}
7+
118
- name: biome
129
glob: "*.{js,ts,jsx,tsx,json}"
13-
run: biome check --no-errors-on-unmatched --files-ignore-unknown=true {staged_files}
10+
run: bun run biome {staged_files}
1411

1512
commit-msg:
1613
jobs:
1714
- name: commitlint
18-
run: commitlint --config .config/commitlint.config.ts --edit {1}
19-
20-
pre-push:
21-
parallel: true
22-
jobs:
23-
- name: lint-check
24-
run: bun run lint
25-
26-
- name: biome-check
27-
run: bun run biome
28-
29-
- name: build
30-
run: bun run build
15+
run: bunx commitlint --config .config/commitlint.config.ts --edit {1}

README.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
![CI status](https://img.shields.io/github/actions/workflow/status/thuongtruong109/flashot/ci.yml?branch=main&label=ci&logo=github&style=flat&colorA=080f12&colorB=1fa669)
99
[![Npm version](https://img.shields.io/npm/v/flashot?style=flat&label=version&colorA=080f12&colorB=1fa669&logo=npm)](https://npmjs.com/package/flashot)
10-
[![Npm downloads](https://img.shields.io/npm/dm/flashot?style=flat&colorA=080f12&colorB=1fa669)](https://npmjs.com/package/flashot)
11-
![Code size](https://img.shields.io/github/languages/code-size/thuongtruong109/flashot?style=flat&colorA=080f12&colorB=1fa669)
12-
[![JSDocs](https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669)](https://www.jsdocs.io/package/vite-unbundled)
10+
[![Npm downloads](https://img.shields.io/npm/dm/flashot?style=flat&logo=jsr&colorA=080f12&colorB=1fa669)](https://npmjs.com/package/flashot)
11+
[![JSDocs](https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&logo=javascript&colorA=080f12&colorB=1fa669)](https://www.jsdocs.io/package/vite-unbundled)
12+
![Code size](https://img.shields.io/github/languages/code-size/thuongtruong109/flashot?style=flat&logo=bun&colorA=080f12&colorB=1fa669)
1313
[![License](https://img.shields.io/github/license/thuongtruong109/flashot.svg?style=flat&colorA=080f12&colorB=1fa669)](https://github.com/antfu/vite-unbundled/blob/main/LICENSE)
14+
[![Sponsor](https://img.shields.io/badge/sponsor-1fa669?logo=githubsponsors&labelColor=080f12)](https://github.com/sponsors/thuongtruong109)
1415

1516
Flashot is the **blazing-fast image generation tool** for code snippets, designed for flawless experience and speed.
1617

@@ -48,9 +49,11 @@ import { writeFile } from "node:fs/promises";
4849
import { c2i } from "flashot";
4950

5051
const buffer = await c2i('console.log("hello, world!");');
51-
await writeFile("image.png", buffer);
52+
await writeFile("output.png", buffer); // Export the image
5253
```
5354

55+
Then you can use the `buffer` to display the image or send it in a response.
56+
5457
## ⚙️ API Options (default is not needed)
5558

5659
```js
@@ -60,7 +63,7 @@ const defaultOptions = {
6063
font: "https://fonts.bunny.net/ubuntu-sans-mono/files/ubuntu-sans-mono-latin-400-normal.woff2", // custom font
6164
width: 800, // default is auto
6265
height: 400, // default is auto
63-
backgroundColor: "transparent", // default is theme's background
66+
bg: "transparent", // default is theme's background
6467
gap: 1, // gap between lines (default is 1)
6568
style: {
6669
borderRadius: 10, // default is 8
@@ -72,31 +75,28 @@ const defaultOptions = {
7275
const buffer = await c2i('console.log("hello, world!");', defaultOptions);
7376
```
7477

75-
| Option | Description | Default |
76-
| -------- | ---------------------------------------------------------------------------------------- | -------------------- |
77-
| `lang` | Code language ([supported](https://shiki.style/languages)) | `"typescript"` |
78-
| `theme` | Rendering theme ([supported](https://shiki.style/themes)) | `"github-dark"` |
79-
| `style` | Additional container styles ([docs](https://takumi.kane.tw/docs/deep-dives/stylesheets)) | `{}` |
80-
| `font` | Font for rendering (URL or ArrayBuffer) | System default |
81-
| `width` | Image width | `(columns + 2) * 10` |
82-
| `height` | Image height | `(lines + 2) * 20` |
83-
84-
## 🚀 Features
85-
86-
- **[Bun](https://bun.sh)** - Fast all-in-one JavaScript runtime and toolkit
87-
- **[TypeScript](https://www.typescriptlang.org/)** - Type-safe development with strict mode enabled
88-
- **[Vite](https://vitejs.dev/)** - Lightning-fast build tool with optimized bundling
89-
- **[Vitest](https://vitest.dev/)** - Blazing fast unit testing framework
90-
- **[shiki](https://github.com/shikijs/shiki)** and **[takumi](https://github.com/kane50613/takumi)**
91-
- **Dual Module Support** - ESM and CommonJS output with proper type definitions
92-
- **[Biome](https://biomejs.dev/)** - Fast formatter and linter for consistent code style
93-
- **[ESLint](https://eslint.org/)** - Advanced linting with TypeScript and SonarJS rules
94-
- **Git Hooks** - Automated quality checks via Lefthook and Commitlint
95-
- **Watch Mode** - Hot rebuild during development
96-
- **Test Coverage** - Built-in coverage reporting with v8
97-
- **UI Testing** - Interactive test UI with `@vitest/ui`
98-
- **Pre-commit Hooks** - Automatic linting and formatting on commit
99-
- **Pre-push Validation** - Full build and test suite before pushing
78+
| Option | Description | Default |
79+
| -------- | ---------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
80+
| `lang` | Code language ([supported](https://shiki.style/languages)) | `"js"` |
81+
| `theme` | Rendering theme ([supported](https://shiki.style/themes)) | `"dracula"` |
82+
| `font` | Font for rendering (URL or ArrayBuffer) | [`ubuntu`](https://fonts.bunny.net/ubuntu-sans-mono/files/ubuntu-sans-mono-latin-400-normal.woff2) |
83+
| `width` | Image width | System default |
84+
| `height` | Image height | System default |
85+
| `bg` | Background color | Theme's background |
86+
| `gap` | Gap between lines | `1` |
87+
| `style` | Additional container styles ([docs](https://takumi.kane.tw/docs/deep-dives/stylesheets)) | `{ borderRadius: 8, padding: 25 }` |
88+
89+
## 📚 Technologies
90+
91+
-**[Bun](https://bun.sh)** - Fast all-in-one JavaScript runtime and toolkit
92+
- 🏗️ **[TypeScript](https://www.typescriptlang.org/)** - Type-safe development with strict mode enabled
93+
- 📦 **[Vite](https://vitejs.dev/)** - Lightning-fast build tool with optimized bundling
94+
- 🔋 **[Vitest](https://vitest.dev/)** - Blazing fast unit testing & interactive test UI framework
95+
- 🪓 **[shiki](https://github.com/shikijs/shiki)** and **[takumi](https://github.com/kane50613/takumi)**
96+
- 📝 **[Biome](https://biomejs.dev/)** - Fast formatter and linter for consistent code style
97+
- 🚀 **Dual Module Support** - ESM and CommonJS output with proper type definitions
98+
- 🔥 **[ESLint](https://eslint.org/)** - Advanced linting with TypeScript and SonarJS rules
99+
- 🧩 **[Lefthook](https://github.com/evilmartians/lefthook)** and **[Commitlint](https://commitlint.js.org/)** - Automated Git hooks for linting and formatting
100100

101101
## 🧪 Code Coverage
102102

examples/image.png

-5.67 KB
Binary file not shown.

examples/index.js renamed to examples/starter-js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import { writeFile } from "node:fs/promises";
22
import { c2i } from "flashot";
33

44
const buffer = await c2i('console.log("hello, world!");');
5-
await writeFile("image.png", buffer);
5+
await writeFile("output.png", buffer);

examples/starter-js/output.png

5.92 KB
Loading

examples/package-lock.json renamed to examples/starter-js/package-lock.json

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/package.json renamed to examples/starter-js/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "flashot-code-to-image-demo",
2+
"name": "flashot-starter-js",
33
"version": "1.0.0",
44
"main": "index.js",
55
"scripts": {
@@ -10,6 +10,6 @@
1010
"license": "ISC",
1111
"description": "",
1212
"dependencies": {
13-
"flashot": "^1.0.1"
13+
"flashot": "^1.2.0"
1414
}
1515
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"biome": "biome check .",
3131
"biome:fix": "biome check --write .",
3232
"check": "bun run lint && bun run biome",
33-
"check:fix": "bun run lint:fix && bun run biome:fix"
33+
"check:fix": "bun run lint:fix && bun run biome:fix",
34+
"pre": "bun lefthook run pre-commit && bun lefthook run pre-push"
3435
},
3536
"files": [
3637
"dist"

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ export async function c2i(code: string, options?: ThemeOptions) {
5555
style: {
5656
minWidth: em(0.5 * token.content.length),
5757
minHeight: 0,
58-
backgroundColor: "transparent",
58+
// backgroundColor: "transparent",
5959
padding: 0,
6060
},
6161
})
62-
: text(token.content, { color: token.color })
62+
: text(token.content, { color: token.color }),
6363
),
64-
})
64+
}),
6565
),
6666
});
6767

@@ -78,7 +78,7 @@ export async function c2i(code: string, options?: ThemeOptions) {
7878

7979
const res = await renderer.renderAsync(root, {
8080
format: "Png" as OutputFormat | undefined,
81-
width: mergedOptions.width || (columns + 2) * 10,
81+
width: mergedOptions.width || (columns + 4) * 10,
8282
height:
8383
(mergedOptions.height || (lines + 2) * 23.7) +
8484
(Number(mergedOptions.style.padding) - 25) * 15,

0 commit comments

Comments
 (0)