Skip to content

Commit 3d79adb

Browse files
committed
feat: first commit
0 parents  commit 3d79adb

13 files changed

+4451
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.svg]
15+
insert_final_newline = false

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.gitignore

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
extends: '@inabagumi',
3+
parserOptions: {
4+
project: 'tsconfig.json'
5+
},
6+
root: true
7+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/dist/
2+
/node_modules/

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.gitignore

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020-present Haneru Developers
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# blurhash-loader
2+
3+
A blurhash loader module for webpack.
4+
5+
## License
6+
7+
[MIT](LICENSE)

package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"author": {
3+
"email": "contact@haneru.dev",
4+
"name": "Haneru Developers",
5+
"url": "https://haneru.dev/"
6+
},
7+
"bugs": {
8+
"email": "security@haneru.dev",
9+
"url": "https://github.com/inabagumi/blurhash-loader/issues"
10+
},
11+
"dependencies": {
12+
"@jimp/custom": "^0.16.1",
13+
"@jimp/gif": "^0.16.1",
14+
"@jimp/jpeg": "^0.16.1",
15+
"@jimp/png": "^0.16.1",
16+
"blurhash": "^1.1.3",
17+
"loader-utils": "^2.0.0"
18+
},
19+
"description": "A blurhash loader module for webpack.",
20+
"devDependencies": {
21+
"@inabagumi/eslint-config": "^6.0.1",
22+
"@inabagumi/prettier-config": "^1.1.2",
23+
"@types/loader-utils": "^2.0.1",
24+
"@types/webpack": "^4.41.22",
25+
"eslint": "^7.11.0",
26+
"microbundle": "^0.12.4",
27+
"prettier": "^2.1.2"
28+
},
29+
"homepage": "https://github.com/inabagumi/blurhash-loader",
30+
"license": "MIT",
31+
"name": "blurhash-loader",
32+
"repository": {
33+
"type": "git",
34+
"url": "https://github.com/inabagumi/blurhash-loader.git"
35+
},
36+
"source": "src/index.ts",
37+
"main": "dist/blurhash-loader.js",
38+
"module": "dist/blurhash-loader.module.js",
39+
"scripts": {
40+
"build": "microbundle --no-compress --format es,cjs --no-sourcemap --strict",
41+
"format": "prettier --write .",
42+
"format-check": "prettier --check .",
43+
"lint": "eslint ."
44+
},
45+
"version": "0.1.0"
46+
}

prettier.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@inabagumi/prettier-config')

src/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { encode } from 'blurhash'
2+
import { getOptions } from 'loader-utils'
3+
import { loader } from 'webpack'
4+
import Jimp from './jimp'
5+
6+
type LoaderOptions = {
7+
componentX?: number
8+
componentY?: number
9+
}
10+
11+
function loader(this: loader.LoaderContext, content: Buffer): void {
12+
if (this.cacheable) this.cacheable()
13+
14+
const callback = this.async()
15+
const options = getOptions(this) as Readonly<LoaderOptions>
16+
17+
Jimp.read(content)
18+
.then(({ bitmap }) => {
19+
const pixels = new Uint8ClampedArray(bitmap.data)
20+
const blurhash = encode(
21+
pixels,
22+
bitmap.width,
23+
bitmap.height,
24+
options.componentX || 4,
25+
options.componentY || 3
26+
)
27+
28+
callback(null, `export default '${blurhash}'`)
29+
})
30+
.catch((error) => {
31+
callback(error, null)
32+
})
33+
}
34+
35+
export default loader

0 commit comments

Comments
 (0)