Compare commits

..

No commits in common. 'master' and 'v0.3.0' have entirely different histories.

@ -1,108 +0,0 @@
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,3 +1 @@
shamefully-hoist=true
strict-peer-dependencies=true
auto-install-peers=true
package-lock=false

@ -23,10 +23,10 @@ A tool for decoding qrcode.
## Guide
Use `pnpm` to install.
Use `npm` to install.
```bash
$ pnpm install --save qrcode-decoder
$ npm install --save qrcode-decoder
```
Using in webpack:
@ -38,7 +38,7 @@ import QrcodeDecoder from 'qrcode-decoder';
Using in browser:
```html
<script src="https://unpkg.com/qrcode-decoder@0.3.1/dist/index.min.js"></script>
<script src="https://unpkg.com/qrcode-decoder"></script>
```
## Demo
@ -96,31 +96,31 @@ Stops the current `qr` from searching for a QRCode.
Install dependencies:
```bash
$ pnpm install
$ npm install
```
Build code:
```bash
$ pnpm run build
$ npm run build
```
Run unit test:
```bash
$ pnpm test
$ npm test
```
Modify version in `package.json`, run `release` script:
```bash
$ pnpm run release
$ npm run release
```
Publish
```bash
$ pnpm publish
$ npm publish
```
## License

@ -23,10 +23,10 @@
## 使用者指南
通过 pnpm 下载安装代码
通过 npm 下载安装代码
```bash
$ pnpm install --save qrcode-decoder
$ npm install --save qrcode-decoder
```
如果你是 webpack 等环境
@ -38,7 +38,7 @@ import QrcodeDecoder from 'qrcode-decoder';
如果你是浏览器环境
```html
<script src="https://unpkg.com/qrcode-decoder@0.3.1/dist/index.min.js"></script>
<script src="https://unpkg.com/qrcode-decoder"></script>
```
## 示例
@ -96,31 +96,31 @@ qr.decodeFromCamera(videoElem).then((res) => {
首次运行需要先安装依赖
```bash
$ pnpm install
$ npm install
```
一键打包生成生产代码
```bash
$ pnpm run build
$ npm run build
```
运行单元测试,浏览器环境需要手动测试,位于`test/browser`
```bash
$ pnpm test
$ npm test
```
修改 package.json 中的版本号,修改 README.md 中的版本号,修改 CHANGELOG.md然后发布新版
```bash
$ pnpm run release
$ npm run release
```
将新版本发布到 pnpm
将新版本发布到 npm
```bash
$ pnpm publish
$ npm publish
```
## License

@ -2,4 +2,4 @@
Rewrite unit test.
- [x] Rewrite unit test.
- [] Rewrite unit test.

@ -1,26 +0,0 @@
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();
});
});

@ -20,7 +20,7 @@
var vConsole = new VConsole();
console.log('Hello world');
function main() {
var qr = new QrcodeDecoder.default();
var qr = new QrcodeDecoder();
var video = document.querySelector('#video');
var start = document.querySelector('#start');
var stop = document.querySelector('#stop');

@ -30,7 +30,7 @@
<script type="module">
var vConsole = new VConsole();
function main() {
var qr = new QrcodeDecoder.default();
var qr = new QrcodeDecoder();
var btn1 = document.querySelector('button#decode1');
var btn2 = document.querySelector('button#decode2');

@ -22,7 +22,7 @@
var result = document.querySelector('#result');
var start = document.querySelector('#start');
var stop = document.querySelector('#stop');
var qr = new QrcodeDecoder.default();
var qr = new QrcodeDecoder();
start.onclick = startScan;

@ -1,11 +1,5 @@
const isDebug = process.env.DEBUG === 'true';
module.exports = {
verbose: true,
silent: !isDebug,
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testTimeout: 60000,
transform: {
'^.+\\.tsx?$': 'ts-jest',

@ -1,17 +1,12 @@
{
"name": "qrcode-decoder",
"version": "0.3.4",
"version": "0.3.0",
"description": "Tool for decoding qrcode",
"main": "dist/index.js",
"browser": "dist/index.min.js",
"unpkg": "dist/index.min.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"packageManager": "pnpm@7.11.0",
"scripts": {
"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'",
"build": "ts-node -P scripts/tsconfig.json scripts/bundle.ts umd,esm,aio && npm run copy-file",
"prettier": "prettier --check '**/*.{ts,tsx,md}' --config .prettierrc",
"prettier:fix": "prettier --write '**/*.{ts,tsx,md}' --config .prettierrc",
"test": "jest",
@ -28,7 +23,7 @@
},
"lint-staged": {
"*.{ts,tsx,md}": [
"pnpm run prettier:fix",
"npm run prettier:fix",
"git add ."
]
},
@ -79,7 +74,7 @@
"ts-node": "^8.4.1",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.4.3"
"typescript": "^3.7.5"
},
"license": "MIT",
"repository": {

File diff suppressed because it is too large Load Diff

@ -59,25 +59,6 @@ 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() {
const bundle = await rollup.rollup({
input: path.join(process.cwd(), 'src/index.ts'),
@ -119,14 +100,6 @@ async function bundle() {
await bundleUmd();
}
if (outputs.indexOf('commonjs') === -1) {
logBundle(`Skipping commonjs`);
} else {
logBundle(`Creating commonjs`);
await bundleCommonjs();
}
if (outputs.indexOf('aio') === -1) {
logBundle(`Skipping umd aio`);
} else {

@ -1,13 +1,12 @@
import jsQR, { QRCode, Options } from 'jsqr';
export type CodeResult = QRCode | null;
import { Options } from 'jsqr';
import jsQR from 'jsqr';
const videoSize = {
width: { min: 360, ideal: 720, max: 1080 },
height: { min: 360, ideal: 720, max: 1080 },
};
export class QrcodeDecoder {
class QrcodeDecoder {
timerCapture: null | NodeJS.Timeout;
canvasElem: null | HTMLCanvasElement;
gCtx: null | CanvasRenderingContext2D;
@ -101,10 +100,7 @@ export class QrcodeDecoder {
* inversionAttempts - (attemptBoth (default), dontInvert, onlyInvert, or invertFirst)
* refer to jsqr options: https://github.com/cozmo/jsQR
*/
async _captureToCanvas(
videoElem: HTMLVideoElement,
options: Options,
): Promise<CodeResult> {
async _captureToCanvas(videoElem: HTMLVideoElement, options: Options) {
if (this.timerCapture) {
clearTimeout(this.timerCapture);
}
@ -146,7 +142,7 @@ export class QrcodeDecoder {
const result = await proms();
return result as CodeResult;
return result;
}
/**
@ -159,10 +155,7 @@ export class QrcodeDecoder {
* inversionAttempts - (attemptBoth (default), dontInvert, onlyInvert, or invertFirst)
* refer to jsqr options: https://github.com/cozmo/jsQR
*/
async decodeFromCamera(
videoElem: HTMLVideoElement,
options: any = {},
): Promise<CodeResult> {
async decodeFromCamera(videoElem: HTMLVideoElement, options: any = {}) {
const opts = {
...this.defaultOption,
...options,
@ -204,8 +197,6 @@ export class QrcodeDecoder {
const code = await this.decodeFromVideo(videoElem, opts);
return code;
}
return null;
}
/**
@ -216,10 +207,7 @@ export class QrcodeDecoder {
* inversionAttempts - (attemptBoth (default), dontInvert, onlyInvert, or invertFirst)
* refer to jsqr options: https://github.com/cozmo/jsQR
*/
async decodeFromVideo(
videoElem: HTMLVideoElement,
options = {},
): Promise<CodeResult> {
async decodeFromVideo(videoElem: HTMLVideoElement, options = {}) {
const opts = {
...this.defaultOption,
...options,
@ -241,16 +229,20 @@ export class QrcodeDecoder {
* refer to jsqr options: https://github.com/cozmo/jsQR
*/
async decodeFromImage(
img: HTMLImageElement | string,
img: HTMLImageElement,
options: { crossOrigin?: string } = {},
): Promise<CodeResult> {
) {
let imgDom: HTMLImageElement | null = null;
const opts = {
...this.defaultOption,
...options,
};
if (typeof img === 'string') {
if (+img.nodeType > 0) {
if (!img.src) {
throw new Error('The ImageElement must contain a src');
}
imgDom = img;
} else if (typeof img === 'string') {
imgDom = document.createElement('img');
if (options.crossOrigin) {
imgDom.crossOrigin = options.crossOrigin;
@ -261,11 +253,6 @@ export class QrcodeDecoder {
imgDom!.onload = () => resolve(true);
});
await proms();
} else if (+img.nodeType > 0) {
if (!img.src) {
throw new Error('The ImageElement must contain a src');
}
imgDom = img;
}
let code = null;
@ -292,7 +279,7 @@ export class QrcodeDecoder {
return code;
}
return null;
return false;
}
/**

@ -11,10 +11,7 @@
"experimentalDecorators": true,
"preserveConstEnums": true,
"importHelpers": false,
"lib": [
"esnext",
"dom"
],
"lib": ["esnext", "dom"],
"module": "ESNext",
"moduleResolution": "node",
"sourceMap": false,

Loading…
Cancel
Save