Skip to content

Commit

Permalink
feat: @watermark-design/node first major version
Browse files Browse the repository at this point in the history
  • Loading branch information
zhensherlock committed Nov 4, 2023
1 parent 3438bde commit 1d11b7d
Show file tree
Hide file tree
Showing 19 changed files with 574 additions and 65 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-squids-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@watermark-design/node': major
---

first major version
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<p align="center">
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/watermark-design/watermark/deploy.yml?branch=main">
<img alt="GitHub" src="https://img.shields.io/github/license/watermark-design/watermark">
<a href="https://discord.gg/89xaVqpV"><img src="https://img.shields.io/discord/1143015541175496777" alt="Join the chat"></a>
<a href="https://discord.gg/V5msNXCE"><img src="https://img.shields.io/discord/1170204572254474300" alt="Join the chat"></a>
</p>

# Watermark
Expand All @@ -21,7 +21,7 @@ Works with both Vue 2 , Vue 3 And React.

### Vue

<a href="https://npmjs.com/package/@watermark-design/vue"><img src="https://badgen.net/npm/v/@watermark-design/vue" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/vue">
<a href="https://npmjs.com/package/@watermark-design/vue"><img src="https://badgen.net/npm/v/@watermark-design/vue" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/vue"> <img alt="npm download week" src="https://img.shields.io/npm/dw/@watermark-design/vue">

```ts
import WatermarkDesign from '@watermark-design/vue';
Expand All @@ -36,7 +36,7 @@ app.use(WatermarkDesign);

### React

<a href="https://npmjs.com/package/@watermark-design/react"><img src="https://badgen.net/npm/v/@watermark-design/react" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/react">
<a href="https://npmjs.com/package/@watermark-design/react"><img src="https://badgen.net/npm/v/@watermark-design/react" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/react"> <img alt="npm download week" src="https://img.shields.io/npm/dw/@watermark-design/react">

```ts
import { Watermark } from '@watermark-design/react';
Expand All @@ -50,7 +50,7 @@ import { Watermark } from '@watermark-design/react';

### Dom

<a href="https://npmjs.com/package/@watermark-design/dom"><img src="https://badgen.net/npm/v/@watermark-design/dom" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/dom">
<a href="https://npmjs.com/package/@watermark-design/dom"><img src="https://badgen.net/npm/v/@watermark-design/dom" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/dom"> <img alt="npm download week" src="https://img.shields.io/npm/dw/@watermark-design/dom">

```ts
import { Watermark } from '@watermark-design/dom';
Expand Down
8 changes: 4 additions & 4 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<p align="center">
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/watermark-design/watermark/deploy.yml?branch=main">
<img alt="GitHub" src="https://img.shields.io/github/license/watermark-design/watermark">
<a href="https://discord.gg/89xaVqpV"><img src="https://img.shields.io/discord/1143015541175496777" alt="Join the chat"></a>
<a href="https://discord.gg/V5msNXCE"><img src="https://img.shields.io/discord/1170204572254474300" alt="Join the chat"></a>
</p>

# watermark-design
Expand All @@ -17,7 +17,7 @@

### Vue

<a href="https://npmjs.com/package/@watermark-design/vue"><img src="https://badgen.net/npm/v/@watermark-design/vue" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/vue">
<a href="https://npmjs.com/package/@watermark-design/vue"><img src="https://badgen.net/npm/v/@watermark-design/vue" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/vue"> <img alt="npm download week" src="https://img.shields.io/npm/dw/@watermark-design/vue">

```ts
import WatermarkDesign from '@watermark-design/vue';
Expand All @@ -32,7 +32,7 @@ app.use(WatermarkDesign);

### React

<a href="https://npmjs.com/package/@watermark-design/react"><img src="https://badgen.net/npm/v/@watermark-design/react" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/react">
<a href="https://npmjs.com/package/@watermark-design/react"><img src="https://badgen.net/npm/v/@watermark-design/react" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/react"> <img alt="npm download week" src="https://img.shields.io/npm/dw/@watermark-design/react">

```ts
import { Watermark } from '@watermark-design/react';
Expand All @@ -46,7 +46,7 @@ import { Watermark } from '@watermark-design/react';

### Dom

<a href="https://npmjs.com/package/@watermark-design/dom"><img src="https://badgen.net/npm/v/@watermark-design/dom" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/dom">
<a href="https://npmjs.com/package/@watermark-design/dom"><img src="https://badgen.net/npm/v/@watermark-design/dom" alt="npm package"></a> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/dom"> <img alt="npm download week" src="https://img.shields.io/npm/dw/@watermark-design/dom">

```ts
import { Watermark } from '@watermark-design/dom';
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"dev": "pnpm -r --aggregate-output --filter=./playground dev",
"dev2.6": "pnpm -r --aggregate-output --filter=./playground-vue2.6 dev",
"dev2.7": "pnpm -r --aggregate-output --filter=./playground-vue2.7 dev",
"build": "pnpm -r --aggregate-output --filter=./packages/* build",
"dev-node": "pnpm -r --aggregate-output --filter=./playground-node dev",
"build": "pnpm -r --aggregate-output --filter=./packages/node build",
"clear": "rimraf 'packages/*/{dist,node_modules}' && rimraf node_modules",
"docs:dev": "pnpm -r --aggregate-output --filter=./docs dev",
"docs:build": "pnpm -r --aggregate-output --filter=./docs build",
Expand All @@ -40,6 +41,7 @@
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-eslint": "^9.0.5",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-strip": "^3.0.4",
"@rollup/plugin-terser": "^0.4.4",
Expand Down
Empty file added packages/node/CHANGELOG.md
Empty file.
21 changes: 21 additions & 0 deletions packages/node/LICENSE
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.
32 changes: 32 additions & 0 deletions packages/node/README.md
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).
23 changes: 23 additions & 0 deletions packages/node/babel.config.js
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 };
59 changes: 59 additions & 0 deletions packages/node/package.json
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"
}
}
62 changes: 62 additions & 0 deletions packages/node/rollup.config.js
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'],
},
];
37 changes: 37 additions & 0 deletions packages/node/src/blind.ts
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;
};
1 change: 1 addition & 0 deletions packages/node/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as blind from './blind';
10 changes: 10 additions & 0 deletions packages/node/tsconfig.json
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"]
}
2 changes: 1 addition & 1 deletion packages/style/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@watermark-design/style">
<img alt="npm download week" src="https://img.shields.io/npm/dw/@watermark-design/style">
<img alt="GitHub" src="https://img.shields.io/github/license/watermark-design/watermark">
<a href="https://discord.gg/89xaVqpV"><img src="https://img.shields.io/discord/1143015541175496777" alt="Join the chat"></a>
<a href="https://discord.gg/V5msNXCE"><img src="https://img.shields.io/discord/1170204572254474300" alt="Join the chat"></a>
</p>

# `@watermark-design/style`
Expand Down
12 changes: 12 additions & 0 deletions playground-node/node/main.ts
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);
});
17 changes: 17 additions & 0 deletions playground-node/package.json
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"
}
}
Loading

0 comments on commit 1d11b7d

Please sign in to comment.