mirror of
https://github.com/yugasun/qrcode-decoder.git
synced 2026-08-13 21:12:02 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fa47676df | ||
|
|
0b7edb39df | ||
|
|
8afbcdad33 | ||
|
|
0f2e84268c | ||
|
|
33f115036f | ||
|
|
17ced673e4 | ||
|
|
c236e43f21 | ||
|
|
e6fb08352f | ||
|
|
b9d89e0545 | ||
|
|
aeee33ee6c |
@@ -0,0 +1,108 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
env:
|
||||||
|
NODE_OPTIONS: --max-old-space-size=6144
|
||||||
|
# install playwright binary manually (because pnpm only runs install script once)
|
||||||
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- master
|
||||||
|
- release/*
|
||||||
|
- feat/*
|
||||||
|
- fix/*
|
||||||
|
- perf/*
|
||||||
|
- v1
|
||||||
|
- v2
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
timeout-minutes: 20
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
node_version: [16]
|
||||||
|
fail-fast: false
|
||||||
|
|
||||||
|
name: "Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }}"
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm
|
||||||
|
uses: pnpm/action-setup@v2.2.2
|
||||||
|
|
||||||
|
- name: Set node version to ${{ matrix.node_version }}
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node_version }}
|
||||||
|
cache: "pnpm"
|
||||||
|
|
||||||
|
- name: Install deps
|
||||||
|
run: pnpm install
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: pnpm run build
|
||||||
|
|
||||||
|
test:
|
||||||
|
timeout-minutes: 10
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: "Lint: node-16, ubuntu-latest"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Install pnpm
|
||||||
|
uses: pnpm/action-setup@v2.2.2
|
||||||
|
|
||||||
|
- name: Set node version to 16
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
cache: "pnpm"
|
||||||
|
|
||||||
|
- name: Install deps
|
||||||
|
run: pnpm install
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: pnpm run build
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: pnpm run test
|
||||||
|
|
||||||
|
lint:
|
||||||
|
timeout-minutes: 10
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: "Lint: node-16, ubuntu-latest"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Install pnpm
|
||||||
|
uses: pnpm/action-setup@v2.2.2
|
||||||
|
|
||||||
|
- name: Set node version to 16
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
cache: "pnpm"
|
||||||
|
|
||||||
|
- name: Install deps
|
||||||
|
run: pnpm install
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: pnpm run build
|
||||||
|
|
||||||
|
- name: Check formatting
|
||||||
|
run: pnpm run prettier
|
||||||
@@ -1 +1,3 @@
|
|||||||
package-lock=false
|
shamefully-hoist=true
|
||||||
|
strict-peer-dependencies=true
|
||||||
|
auto-install-peers=true
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ A tool for decoding qrcode.
|
|||||||
|
|
||||||
## Guide
|
## Guide
|
||||||
|
|
||||||
Use `npm` to install.
|
Use `pnpm` to install.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm install --save qrcode-decoder
|
$ pnpm install --save qrcode-decoder
|
||||||
```
|
```
|
||||||
|
|
||||||
Using in webpack:
|
Using in webpack:
|
||||||
@@ -38,7 +38,7 @@ import QrcodeDecoder from 'qrcode-decoder';
|
|||||||
Using in browser:
|
Using in browser:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="https://unpkg.com/qrcode-decoder"></script>
|
<script src="https://unpkg.com/qrcode-decoder@0.3.1/dist/index.min.js"></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
@@ -96,31 +96,31 @@ Stops the current `qr` from searching for a QRCode.
|
|||||||
Install dependencies:
|
Install dependencies:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm install
|
$ pnpm install
|
||||||
```
|
```
|
||||||
|
|
||||||
Build code:
|
Build code:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm run build
|
$ pnpm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
Run unit test:
|
Run unit test:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm test
|
$ pnpm test
|
||||||
```
|
```
|
||||||
|
|
||||||
Modify version in `package.json`, run `release` script:
|
Modify version in `package.json`, run `release` script:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm run release
|
$ pnpm run release
|
||||||
```
|
```
|
||||||
|
|
||||||
Publish
|
Publish
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm publish
|
$ pnpm publish
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
+9
-9
@@ -23,10 +23,10 @@
|
|||||||
|
|
||||||
## 使用者指南
|
## 使用者指南
|
||||||
|
|
||||||
通过 npm 下载安装代码
|
通过 pnpm 下载安装代码
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm install --save qrcode-decoder
|
$ pnpm install --save qrcode-decoder
|
||||||
```
|
```
|
||||||
|
|
||||||
如果你是 webpack 等环境
|
如果你是 webpack 等环境
|
||||||
@@ -38,7 +38,7 @@ import QrcodeDecoder from 'qrcode-decoder';
|
|||||||
如果你是浏览器环境
|
如果你是浏览器环境
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="https://unpkg.com/qrcode-decoder"></script>
|
<script src="https://unpkg.com/qrcode-decoder@0.3.1/dist/index.min.js"></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
## 示例
|
## 示例
|
||||||
@@ -96,31 +96,31 @@ qr.decodeFromCamera(videoElem).then((res) => {
|
|||||||
首次运行需要先安装依赖
|
首次运行需要先安装依赖
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm install
|
$ pnpm install
|
||||||
```
|
```
|
||||||
|
|
||||||
一键打包生成生产代码
|
一键打包生成生产代码
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm run build
|
$ pnpm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
运行单元测试,浏览器环境需要手动测试,位于`test/browser`
|
运行单元测试,浏览器环境需要手动测试,位于`test/browser`
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm test
|
$ pnpm test
|
||||||
```
|
```
|
||||||
|
|
||||||
修改 package.json 中的版本号,修改 README.md 中的版本号,修改 CHANGELOG.md,然后发布新版
|
修改 package.json 中的版本号,修改 README.md 中的版本号,修改 CHANGELOG.md,然后发布新版
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm run release
|
$ pnpm run release
|
||||||
```
|
```
|
||||||
|
|
||||||
将新版本发布到 npm
|
将新版本发布到 pnpm
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm publish
|
$ pnpm publish
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import QrcodeDecoder from '../';
|
||||||
|
|
||||||
|
describe('QrcodeDecoder', () => {
|
||||||
|
test('use', async () => {
|
||||||
|
const res = await import('../dist');
|
||||||
|
|
||||||
|
expect(res.default).toEqual(QrcodeDecoder);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('new QrcodeDecoder()', async () => {
|
||||||
|
const qr = new QrcodeDecoder();
|
||||||
|
|
||||||
|
expect(qr).toBeDefined();
|
||||||
|
expect(qr.videoConstraints).toEqual({
|
||||||
|
video: {
|
||||||
|
width: { min: 360, ideal: 720, max: 1080 },
|
||||||
|
height: { min: 360, ideal: 720, max: 1080 },
|
||||||
|
facingMode: { exact: 'environment' },
|
||||||
|
},
|
||||||
|
audio: false,
|
||||||
|
});
|
||||||
|
expect(qr.decodeFromImage).toBeDefined();
|
||||||
|
expect(qr.decodeFromCamera).toBeDefined();
|
||||||
|
expect(qr.decodeFromVideo).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
|
const isDebug = process.env.DEBUG === 'true';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
verbose: true,
|
verbose: true,
|
||||||
|
silent: !isDebug,
|
||||||
|
transform: {
|
||||||
|
'^.+\\.tsx?$': 'ts-jest',
|
||||||
|
},
|
||||||
testTimeout: 60000,
|
testTimeout: 60000,
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.tsx?$': 'ts-jest',
|
'^.+\\.tsx?$': 'ts-jest',
|
||||||
|
|||||||
+8
-3
@@ -1,12 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "qrcode-decoder",
|
"name": "qrcode-decoder",
|
||||||
"version": "0.3.0",
|
"version": "0.3.3",
|
||||||
"description": "Tool for decoding qrcode",
|
"description": "Tool for decoding qrcode",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"browser": "dist/index.min.js",
|
||||||
|
"unpkg": "dist/index.min.js",
|
||||||
"module": "dist/index.esm.js",
|
"module": "dist/index.esm.js",
|
||||||
|
"types": "dist/index.d.ts",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
|
"packageManager": "pnpm@7.11.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ts-node -P scripts/tsconfig.json scripts/bundle.ts umd,esm,aio && npm run copy-file",
|
"build": "ts-node -P scripts/tsconfig.json scripts/bundle.ts commonjs,esm,aio && pnpm run dts && pnpm run copy-file",
|
||||||
|
"dts": "tsc src/index.ts --declaration --emitDeclarationOnly --outDir './dist'",
|
||||||
"prettier": "prettier --check '**/*.{ts,tsx,md}' --config .prettierrc",
|
"prettier": "prettier --check '**/*.{ts,tsx,md}' --config .prettierrc",
|
||||||
"prettier:fix": "prettier --write '**/*.{ts,tsx,md}' --config .prettierrc",
|
"prettier:fix": "prettier --write '**/*.{ts,tsx,md}' --config .prettierrc",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
@@ -23,7 +28,7 @@
|
|||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.{ts,tsx,md}": [
|
"*.{ts,tsx,md}": [
|
||||||
"npm run prettier:fix",
|
"pnpm run prettier:fix",
|
||||||
"git add ."
|
"git add ."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Generated
+7446
File diff suppressed because it is too large
Load Diff
@@ -59,6 +59,25 @@ async function bundleUmd() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function bundleCommonjs() {
|
||||||
|
const bundle = await rollup.rollup({
|
||||||
|
input: path.join(process.cwd(), 'src/index.ts'),
|
||||||
|
plugins: [...plugins],
|
||||||
|
external: ['jsqr'],
|
||||||
|
});
|
||||||
|
await bundle.write({
|
||||||
|
file: 'dist/index.js',
|
||||||
|
exports: 'named',
|
||||||
|
name: 'QrcodeDecoder',
|
||||||
|
format: 'commonjs',
|
||||||
|
sourcemap: false,
|
||||||
|
globals: {
|
||||||
|
jsqr: 'jsqr',
|
||||||
|
tslib: 'tslib',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function bundleAio() {
|
async function bundleAio() {
|
||||||
const bundle = await rollup.rollup({
|
const bundle = await rollup.rollup({
|
||||||
input: path.join(process.cwd(), 'src/index.ts'),
|
input: path.join(process.cwd(), 'src/index.ts'),
|
||||||
@@ -100,6 +119,14 @@ async function bundle() {
|
|||||||
await bundleUmd();
|
await bundleUmd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (outputs.indexOf('commonjs') === -1) {
|
||||||
|
logBundle(`Skipping commonjs`);
|
||||||
|
} else {
|
||||||
|
logBundle(`Creating commonjs`);
|
||||||
|
|
||||||
|
await bundleCommonjs();
|
||||||
|
}
|
||||||
|
|
||||||
if (outputs.indexOf('aio') === -1) {
|
if (outputs.indexOf('aio') === -1) {
|
||||||
logBundle(`Skipping umd aio`);
|
logBundle(`Skipping umd aio`);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+8
-7
@@ -229,7 +229,7 @@ class QrcodeDecoder {
|
|||||||
* refer to jsqr options: https://github.com/cozmo/jsQR
|
* refer to jsqr options: https://github.com/cozmo/jsQR
|
||||||
*/
|
*/
|
||||||
async decodeFromImage(
|
async decodeFromImage(
|
||||||
img: HTMLImageElement,
|
img: HTMLImageElement | string,
|
||||||
options: { crossOrigin?: string } = {},
|
options: { crossOrigin?: string } = {},
|
||||||
) {
|
) {
|
||||||
let imgDom: HTMLImageElement | null = null;
|
let imgDom: HTMLImageElement | null = null;
|
||||||
@@ -237,12 +237,8 @@ class QrcodeDecoder {
|
|||||||
...this.defaultOption,
|
...this.defaultOption,
|
||||||
...options,
|
...options,
|
||||||
};
|
};
|
||||||
if (+img.nodeType > 0) {
|
|
||||||
if (!img.src) {
|
if (typeof img === 'string') {
|
||||||
throw new Error('The ImageElement must contain a src');
|
|
||||||
}
|
|
||||||
imgDom = img;
|
|
||||||
} else if (typeof img === 'string') {
|
|
||||||
imgDom = document.createElement('img');
|
imgDom = document.createElement('img');
|
||||||
if (options.crossOrigin) {
|
if (options.crossOrigin) {
|
||||||
imgDom.crossOrigin = options.crossOrigin;
|
imgDom.crossOrigin = options.crossOrigin;
|
||||||
@@ -253,6 +249,11 @@ class QrcodeDecoder {
|
|||||||
imgDom!.onload = () => resolve(true);
|
imgDom!.onload = () => resolve(true);
|
||||||
});
|
});
|
||||||
await proms();
|
await proms();
|
||||||
|
} else if (+img.nodeType > 0) {
|
||||||
|
if (!img.src) {
|
||||||
|
throw new Error('The ImageElement must contain a src');
|
||||||
|
}
|
||||||
|
imgDom = img;
|
||||||
}
|
}
|
||||||
|
|
||||||
let code = null;
|
let code = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user