Skip to content

Commit deca96f

Browse files
committed
chore: init code
0 parents  commit deca96f

30 files changed

+5566
-0
lines changed

.editorconfig

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

.eslintrc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"plugins": ["@typescript-eslint"],
4+
"parserOptions": {
5+
"ecmaVersion": 6,
6+
"sourceType": "module"
7+
},
8+
"extends": [
9+
"eslint:recommended",
10+
"plugin:@typescript-eslint/eslint-recommended",
11+
"plugin:@typescript-eslint/recommended"
12+
],
13+
"env": {
14+
"browser": true
15+
},
16+
"globals": {
17+
"process": true
18+
},
19+
"rules": {
20+
"linebreak-style": 0,
21+
"no-console": 0,
22+
"no-debugger": 0,
23+
"no-useless-escape": "off",
24+
"@typescript-eslint/no-explicit-any": 0,
25+
"@typescript-eslint/no-empty-interface": 0,
26+
"@typescript-eslint/no-this-alias": 0,
27+
"@typescript-eslint/ban-ts-comment": 0,
28+
"@typescript-eslint/explicit-module-boundary-types": 0,
29+
"@typescript-eslint/no-non-null-assertion": 0,
30+
"@typescript-eslint/ban-types": [1, {
31+
"types": {
32+
"Function": false,
33+
"{}": false
34+
},
35+
"extendDefaults": true
36+
}],
37+
"no-constant-condition": ["error", {
38+
"checkLoops": false
39+
}],
40+
"semi": [1, "never"],
41+
"quotes": [1, "single", {
42+
"allowTemplateLiterals": true
43+
}]
44+
},
45+
"ignorePatterns": ["node_modules", "dist", "index.html"]
46+
}

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
!.vscode/extensions.json
17+
.idea
18+
.DS_Store
19+
*.suo
20+
*.ntvs*
21+
*.njsproj
22+
*.sln
23+
*.sw?

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"printWidth": 80,
5+
"trailingComma": "none",
6+
"arrowParens": "avoid",
7+
"endOfLine": "lf"
8+
}

.vscode/settings.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"cSpell.words": [
4+
"esbenp",
5+
"linebreak",
6+
"arrowParens",
7+
"jsbarcode",
8+
"zxing"
9+
],
10+
"cSpell.ignorePaths": [
11+
"dist",
12+
"node_modules",
13+
"yarn.lock"
14+
],
15+
"typescript.tsdk": "node_modules/typescript/lib",
16+
"editor.codeActionsOnSave": {
17+
"source.fixAll.eslint": true
18+
},
19+
"[typescript]": {
20+
"editor.defaultFormatter": "esbenp.prettier-vscode"
21+
},
22+
"svg.preview.background": "custom",
23+
"eslint.workingDirectories": [
24+
"./packages"
25+
]
26+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021-present, hufe
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
13+
all 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
21+
THE SOFTWARE.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<h1 align="center">canvas-editor-plugin</h1>
2+
3+
<p align="center">plugins for canvas-editor</p>
4+
5+
## plugin list
6+
7+
- @hufe921/canvas-editor-plugin-barcode1d
8+
9+
- @hufe921/canvas-editor-plugin-barcode2d

lerna.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"packages": [
3+
"packages/*"
4+
],
5+
"version": "0.0.1",
6+
"npmClient": "yarn",
7+
"command": {
8+
"ignoreChanges": [
9+
"*.md",
10+
"example/**"
11+
]
12+
},
13+
"bootstrap": {
14+
"npmClientArgs": [
15+
"--no-package-lock"
16+
]
17+
}
18+
}

package.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"private": true,
3+
"name": "canvas-editor-plugin",
4+
"author": "Hufe",
5+
"license": "MIT",
6+
"version": "0.0.1",
7+
"description": "plugins for canvas-editor",
8+
"type": "module",
9+
"publishConfig": {
10+
"registry": "https://registry.npmjs.org/",
11+
"access": "public"
12+
},
13+
"homepage": "https://github.com/Hufe921/canvas-editor-plugin",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/Hufe921/canvas-editor-plugin.git"
17+
},
18+
"keywords": [
19+
"canvas-editor",
20+
"plugin"
21+
],
22+
"workspaces": [
23+
"packages/*"
24+
],
25+
"scripts": {
26+
"clean": "lerna clean --yes && rm -rf ./packages/**/package-lock.json",
27+
"build": "lerna run build",
28+
"test": "lerna run test",
29+
"dev": "lerna run dev",
30+
"type:check": "lerna run type:check",
31+
"lint": "eslint \"packages/*/src/**/*.ts\"",
32+
"prerelease": "yarn build",
33+
"release:publish": "lerna publish from-git --yes",
34+
"release:package": "lerna publish from-package --yes",
35+
"postinstall": "simple-git-hooks"
36+
},
37+
"devDependencies": {
38+
"@types/node": "^18.12.1",
39+
"@typescript-eslint/eslint-plugin": "5.61.0",
40+
"@typescript-eslint/parser": "5.61.0",
41+
"eslint": "8.44.0",
42+
"lerna": "^7.1.1",
43+
"simple-git-hooks": "^2.8.1",
44+
"typescript": "^5.0.2"
45+
},
46+
"simple-git-hooks": {
47+
"pre-commit": "npm run lint && npm run type:check",
48+
"commit-msg": "node scripts/verifyCommit.js"
49+
}
50+
}

packages/barcode1d/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021-present, hufe
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
13+
all 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
21+
THE SOFTWARE.

packages/barcode1d/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<h1 align="center">canvas-editor-plugin-barcode1d</h1>
2+
3+
<p align="center">barcode1d plugin for canvas-editor</p>
4+
5+
## usage
6+
7+
```bash
8+
npm i @hufe921/canvas-editor-plugin-barcode1d --save
9+
```
10+
11+
```javascript
12+
import Editor from "@hufe921/canvas-editor"
13+
import barcode1DPlugin from "@hufe921/canvas-editor-plugin-barcode1d"
14+
15+
const instance = new Editor()
16+
instance.use(barcode1DPlugin)
17+
18+
instance.executeInsertBarcode1D(
19+
content: string,
20+
width: number,
21+
height: number,
22+
options?: JsBarcode.Options
23+
)
24+
```

packages/barcode1d/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<title>canvas-editor-plugin-barcode1d</title>
9+
</head>
10+
11+
<body>
12+
<div id="app">
13+
<button>TEST</button>
14+
<div id="editor"></div>
15+
</div>
16+
<script type="module" src="/src/main.ts"></script>
17+
</body>
18+
19+
</html>

packages/barcode1d/package.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@hufe921/canvas-editor-plugin-barcode1d",
3+
"author": "Hufe",
4+
"license": "MIT",
5+
"version": "0.0.1",
6+
"description": "barcode1d plugin for canvas-editor",
7+
"type": "module",
8+
"publishConfig": {
9+
"registry": "https://registry.npmjs.org/",
10+
"access": "public"
11+
},
12+
"files": [
13+
"dist",
14+
"README.md",
15+
"LICENSE",
16+
"package.json"
17+
],
18+
"typings": "./dist/src/barcode1d/index.d.ts",
19+
"main": "./dist/barcode1d.umd.cjs",
20+
"module": "./dist/barcode1d.js",
21+
"repository": {
22+
"type": "git",
23+
"url": "https://github.com/Hufe921/canvas-editor-plugin.git"
24+
},
25+
"keywords": [
26+
"canvas-editor",
27+
"barcode1d"
28+
],
29+
"scripts": {
30+
"dev": "vite",
31+
"build": "vite build --mode lib",
32+
"release": "node scripts/release.js",
33+
"type:check": "tsc --noEmit"
34+
},
35+
"peerDependencies": {
36+
"@hufe921/canvas-editor": ">=0.9.37"
37+
},
38+
"devDependencies": {
39+
"@hufe921/canvas-editor": "0.9.37",
40+
"@rollup/plugin-typescript": "^10.0.1",
41+
"@types/node": "^16.11.12",
42+
"@typescript-eslint/eslint-plugin": "4.33.0",
43+
"@typescript-eslint/parser": "4.33.0",
44+
"eslint": "7.32.0",
45+
"simple-git-hooks": "^2.8.1",
46+
"typescript": "^5.0.2",
47+
"vite": "^4.3.9"
48+
},
49+
"dependencies": {
50+
"jsbarcode": "^3.11.5"
51+
}
52+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Editor, Command, ElementType } from '@hufe921/canvas-editor'
2+
import JsBarcode from 'jsbarcode'
3+
4+
function convertSvgElementToBase64(svgElement: HTMLElement | SVGSVGElement) {
5+
return `data:image/svg+xml;base64,${btoa(
6+
decodeURIComponent(svgElement.outerHTML)
7+
)}`
8+
}
9+
10+
export type CommandWithBarcode1D = Command & {
11+
executeInsertBarcode1D(
12+
content: string,
13+
width: number,
14+
height: number,
15+
options?: JsBarcode.Options
16+
): void
17+
}
18+
19+
export default function barcodePlugin(editor: Editor) {
20+
const command = <CommandWithBarcode1D>editor.command
21+
22+
// 条形码
23+
command.executeInsertBarcode1D = (
24+
content: string,
25+
width: number,
26+
height: number,
27+
options?: JsBarcode.Options
28+
) => {
29+
const svgElement = document.createElement('svg')
30+
// 解析一维码
31+
JsBarcode(svgElement, content, options)
32+
// 插入
33+
command.executeInsertElementList([
34+
{
35+
type: ElementType.IMAGE,
36+
value: convertSvgElementToBase64(svgElement),
37+
width,
38+
height
39+
}
40+
])
41+
}
42+
}

0 commit comments

Comments
 (0)