-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: @watermark-design/node first major version
- Loading branch information
1 parent
3438bde
commit 1d11b7d
Showing
19 changed files
with
574 additions
and
65 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,5 @@ | ||
--- | ||
'@watermark-design/node': major | ||
--- | ||
|
||
first major version |
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
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
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
Empty file.
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Watermark Design | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,32 @@ | ||
<p align="center"> | ||
<a href="https://watermark-design.github.io/watermark/" target="_blank" rel="noopener noreferrer"> | ||
<img height="100" src="https://watermark-design.github.io/watermark/full-logo.png" alt="watermark design"> | ||
</a> | ||
</p> | ||
<p align="center"> | ||
<a href="https://npmjs.com/package/@watermark-design/shared"><img src="https://badgen.net/npm/v/@watermark-design/node" alt="npm package"></a> | ||
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/watermark-design/watermark/deploy.yml?branch=main"> | ||
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/node"> | ||
<img alt="npm download week" src="https://img.shields.io/npm/dw/@watermark-design/node"> | ||
<img alt="GitHub" src="https://img.shields.io/github/license/watermark-design/watermark"> | ||
<a href="https://discord.gg/V5msNXCE"><img src="https://img.shields.io/discord/1170204572254474300" alt="Join the chat"></a> | ||
</p> | ||
|
||
# `@watermark-design/node` | ||
|
||
The utils used internally by the Watermark Design. It includes common type checking, error assertions, component types/declarations/parameters, and more. | ||
|
||
## Installing | ||
|
||
```bash | ||
# or pnpm or yarn | ||
npm install @watermark-design/node | ||
``` | ||
|
||
## Documentation | ||
|
||
To learn more, check [its documentation](https://watermark-design.github.io/watermark/). | ||
|
||
## License | ||
|
||
[MIT](LICENSE). |
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,23 @@ | ||
const presets = [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
// useBuiltIns: 'usage', | ||
corejs: { version: 3 }, | ||
targets: [ | ||
'> 1%', | ||
'Firefox ESR', | ||
'last 4 versions', | ||
'maintained node versions', | ||
'not dead', | ||
'safari >= 7', | ||
], | ||
}, | ||
], | ||
]; | ||
|
||
const plugins = [ | ||
// '@babel/plugin-transform-runtime' | ||
]; | ||
|
||
module.exports = { presets, plugins }; |
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,59 @@ | ||
{ | ||
"name": "@watermark-design/node", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"description": "watermark-design node", | ||
"author": "zhensherlock", | ||
"homepage": "https://github.com/watermark-design/watermark/tree/master/packages/node#readme", | ||
"keywords": [ | ||
"Watermark", | ||
"Watermark Design", | ||
"watermark", | ||
"watermark design", | ||
"水印", | ||
"水印组件" | ||
], | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/", | ||
"access": "public" | ||
}, | ||
"license": "MIT", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"webpack": "dist/index.cjs.js", | ||
"types": "dist/types/main.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/types/main.d.ts", | ||
"import": "./dist/index.esm.js", | ||
"require": "./dist/index.cjs.js" | ||
}, | ||
"./*": "./*", | ||
"./dist/*": "./dist/*", | ||
"./package.json": "./package.json" | ||
}, | ||
"files": [ | ||
"dist", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/watermark-design/watermark.git" | ||
}, | ||
"scripts": { | ||
"clean:dist": "rimraf dist", | ||
"build": "npm run clean:dist && rollup -c --bundleConfigAsCjs --environment NODE_ENV:production" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/watermark-design/watermark/issues" | ||
}, | ||
"dependencies": { | ||
"canvas": "^2.11.2", | ||
"node-fetch": "^3.3.2" | ||
}, | ||
"peerDependencies": { | ||
"canvas": "^2.11.2", | ||
"node-fetch": "^3.3.2" | ||
} | ||
} |
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,62 @@ | ||
import filesize from 'rollup-plugin-filesize'; | ||
import { babel } from '@rollup/plugin-babel'; | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import eslint from '@rollup/plugin-eslint'; | ||
import terser from '@rollup/plugin-terser'; | ||
import typescript from '@rollup/plugin-typescript'; | ||
import strip from '@rollup/plugin-strip'; | ||
|
||
const output = [ | ||
{ | ||
format: 'esm', | ||
file: 'dist/index.esm.js', | ||
sourcemap: true, | ||
inlineDynamicImports: true, | ||
}, | ||
{ | ||
format: 'cjs', | ||
file: 'dist/index.cjs.js', | ||
sourcemap: true, | ||
inlineDynamicImports: true, | ||
}, | ||
// prod | ||
{ | ||
format: 'esm', | ||
file: 'dist/index.esm.prod.js', | ||
sourcemap: true, | ||
plugins: [terser()], | ||
inlineDynamicImports: true, | ||
}, | ||
{ | ||
format: 'cjs', | ||
file: 'dist/index.cjs.prod.js', | ||
sourcemap: true, | ||
plugins: [terser()], | ||
inlineDynamicImports: true, | ||
}, | ||
]; | ||
|
||
export default [ | ||
{ | ||
input: 'src/main.ts', | ||
output, | ||
plugins: [ | ||
eslint({ | ||
throwOnError: true, | ||
throwOnWarning: true, | ||
include: ['src/**'], | ||
exclude: ['node_modules/**', 'src/style/**'], | ||
}), | ||
resolve(), | ||
strip(), | ||
typescript(), | ||
commonjs(), | ||
babel({ | ||
exclude: /node_modules/, | ||
}), | ||
filesize(), | ||
], | ||
external: ['node-fetch', 'canvas'], | ||
}, | ||
]; |
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,37 @@ | ||
import { createCanvas, loadImage } from 'canvas'; | ||
import fetch from 'node-fetch'; | ||
|
||
export interface DecodeBlindWatermarkOptions { | ||
url: string; | ||
fillColor: string; | ||
compositeOperation: string; | ||
mode: string; | ||
} | ||
|
||
export const decodeBlindWatermark = async (props: DecodeBlindWatermarkOptions) => { | ||
const options = Object.assign( | ||
{ | ||
url: '', | ||
fillColor: '#000', | ||
compositeOperation: 'color-burn', | ||
mode: 'canvas', | ||
}, | ||
props | ||
); | ||
if (!options.url) { | ||
return; | ||
} | ||
const response = await fetch(options.url); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
let resultImage = ''; | ||
await loadImage(Buffer.from(arrayBuffer)).then((img) => { | ||
const canvas = createCanvas(img.width, img.height); | ||
const ctx = canvas.getContext('2d'); | ||
ctx.drawImage(img, 0, 0, img.width, img.height); | ||
ctx.globalCompositeOperation = options.compositeOperation as any; | ||
ctx.fillStyle = options.fillColor; | ||
ctx.fillRect(0, 0, img.width, img.height); | ||
resultImage = canvas.toDataURL(); | ||
}); | ||
return resultImage; | ||
}; |
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 @@ | ||
export * as blind from './blind'; |
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,10 @@ | ||
{ | ||
"extends": "../../tsconfig.root.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "dist/types", | ||
"declaration": true, | ||
"sourceMap": true | ||
}, | ||
"include": ["src"] | ||
} |
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
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,12 @@ | ||
import * as watermark from '../../packages/node/src/main'; | ||
|
||
watermark.blind | ||
.decodeBlindWatermark({ | ||
url: 'https://cdn.jsdelivr.net/gh/zhensherlock/oss@main/uPic/blind-watermark-test-bxEJgQ.png', | ||
fillColor: '#000', | ||
compositeOperation: 'color-burn', | ||
mode: 'canvas', | ||
}) | ||
.then((res) => { | ||
console.log(res); | ||
}); |
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,17 @@ | ||
{ | ||
"name": "@watermark-design/playground-node", | ||
"version": "1.0.0", | ||
"private": true, | ||
"type": "module", | ||
"description": "watermark design playground-node", | ||
"scripts": { | ||
"dev": "ts-node ./node/main.ts" | ||
}, | ||
"keywords": [], | ||
"author": "zhensherlock", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@watermark-design/node": "workspace:^", | ||
"ts-node": "^10.9.1" | ||
} | ||
} |
Oops, something went wrong.