Skip to content

Commit

Permalink
version: v3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoDaiGua-Ray committed Oct 17, 2024
1 parent 89a3cfd commit 441ab1f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 79 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## v3.0.2

### Fix

- 修复在 `nuxt` 中一些边界错误

## v3.0.1

### Fix

- 修复在 `nuxt` 中构建报错的问题

## v3.0.0

### Feat
Expand Down
87 changes: 10 additions & 77 deletions components/qrcode/core/awesome-qr.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ var __awaiter =
step((generator = generator.apply(thisArg, _arguments || [])).next())
})
}

import canvas from '../deps/skia-canvas-lib/lib/browser'
import { decompressFrames, parseGIF } from './gifuct-js'
const { Canvas } = canvas
import { decompressFrames, parseGIF } from './gifuct-js/index'
import { QRCodeModel, QRErrorCorrectLevel, QRUtil } from './qrcode'
import GIFEncoder from './gif.js/GIFEncoder'

const defaultScale = 0.4
const { Canvas } = canvas

function loadImage(url) {
if (!url) {
return undefined
Expand Down Expand Up @@ -73,54 +70,9 @@ function loadImage(url) {
img.src = url
})
}

export class AwesomeQR {
canvas
canvasContext
qrCode
options

static CorrectLevel = QRErrorCorrectLevel

static defaultComponentOptions = {
data: {
scale: 1,
},
timing: {
scale: 1,
protectors: false,
},
alignment: {
scale: 1,
protectors: false,
},
cornerAlignment: {
scale: 1,
protectors: true,
},
}

static defaultOptions = {
text: '',
size: 400,
margin: 20,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRErrorCorrectLevel.M,
backgroundImage: undefined,
backgroundDimming: 'rgba(0,0,0,0)',
logoImage: undefined,
logoScale: 0.2,
logoMargin: 4,
logoCornerRadius: 8,
whiteMargin: true,
components: AwesomeQR.defaultComponentOptions,
autoColor: true,
}

constructor(options) {
const _options = Object.assign({}, options)

Object.keys(AwesomeQR.defaultOptions).forEach((k) => {
if (!(k in _options)) {
Object.defineProperty(_options, k, {
Expand All @@ -130,7 +82,6 @@ export class AwesomeQR {
})
}
})

if (!_options.components) {
_options.components = AwesomeQR.defaultComponentOptions
} else if (typeof _options.components === 'object') {
Expand All @@ -143,17 +94,16 @@ export class AwesomeQR {
})
} else {
Object.defineProperty(_options.components, k, {
value: {
...AwesomeQR.defaultComponentOptions[k],
..._options.components[k],
},
value: Object.assign(
Object.assign({}, AwesomeQR.defaultComponentOptions[k]),
_options.components[k],
),
enumerable: true,
writable: true,
})
}
})
}

if (_options.dotScale !== null && _options.dotScale !== undefined) {
if (_options.dotScale <= 0 || _options.dotScale > 1) {
throw new Error('dotScale should be in range (0, 1].')
Expand All @@ -162,7 +112,6 @@ export class AwesomeQR {
_options.components.timing.scale = _options.dotScale
_options.components.alignment.scale = _options.dotScale
}

this.options = _options
this.canvas = new Canvas(options.size, options.size)
this.canvasContext = this.canvas.getContext('2d')
Expand All @@ -176,15 +125,12 @@ export class AwesomeQR {
this.qrCode.addData(this.options.text)
this.qrCode.make()
}

draw() {
return new Promise((resolve) => this._draw().then(resolve))
}

_clear() {
this.canvasContext.clearRect(0, 0, this.canvas.width, this.canvas.height)
}

static _prepareRoundedCornerClip(canvasContext, x, y, w, h, r) {
canvasContext.beginPath()
canvasContext.moveTo(x, y)
Expand All @@ -194,7 +140,6 @@ export class AwesomeQR {
canvasContext.arcTo(x, y, x + w, y, r)
canvasContext.closePath()
}

static _getAverageRGB(image) {
const blockSize = 5
const defaultRGB = {
Expand All @@ -210,26 +155,20 @@ export class AwesomeQR {
b: 0,
}
let count = 0

height = image.naturalHeight || image.height
width = image.naturalWidth || image.width

const canvas = new Canvas(width, height)
const context = canvas.getContext('2d')

if (!context) {
return defaultRGB
}

context.drawImage(image, 0, 0)

let data
try {
data = context.getImageData(0, 0, width, height)
} catch (e) {
return defaultRGB
}

while ((i += blockSize * 4) < data.data.length) {
if (
data.data[i] > 200 ||
Expand All @@ -242,14 +181,11 @@ export class AwesomeQR {
rgb.g += data.data[i + 1]
rgb.b += data.data[i + 2]
}

rgb.r = ~~(rgb.r / count)
rgb.g = ~~(rgb.g / count)
rgb.b = ~~(rgb.b / count)

return rgb
}

static _drawDot(
canvasContext,
centerX,
Expand All @@ -265,7 +201,6 @@ export class AwesomeQR {
dotScale * nSize,
)
}

static _drawAlignProtector(canvasContext, centerX, centerY, nSize) {
canvasContext.clearRect(
(centerX - 2) * nSize,
Expand All @@ -280,7 +215,6 @@ export class AwesomeQR {
5 * nSize,
)
}

static _drawAlign(
canvasContext,
centerX,
Expand Down Expand Up @@ -374,8 +308,7 @@ export class AwesomeQR {
}
canvasContext.fillStyle = oldFillStyle
}

async _draw() {
_draw() {
var _a,
_b,
_c,
Expand Down Expand Up @@ -903,7 +836,9 @@ export class AwesomeQR {
(bin, u8) => bin + String.fromCharCode(u8),
'',
)
return Promise.resolve(`data:image/gif;base64,${window.btoa(binary)}`)
return Promise.resolve(
`data:image/gif;base64,${globalThis.btoa(binary)}`,
)
}
return Promise.resolve(
Buffer.from(gifOutput.stream().toFlattenUint8Array()),
Expand Down Expand Up @@ -944,7 +879,6 @@ export class AwesomeQR {
})
}
}

AwesomeQR.CorrectLevel = QRErrorCorrectLevel
AwesomeQR.defaultComponentOptions = {
data: {
Expand Down Expand Up @@ -982,7 +916,6 @@ AwesomeQR.defaultOptions = {
logoBackgroundColor: '#ffffff',
backgroundColor: '#ffffff',
}

function isElement(obj) {
try {
//Using W3 DOM2 (works for FF, Opera and Chrome)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue3-next-qrcode",
"private": false,
"version": "3.0.0",
"version": "3.0.2",
"type": "module",
"license": "MIT",
"author": "Ray",
Expand Down Expand Up @@ -30,7 +30,7 @@
"js-binary-schema-parser": "^2.0.3"
},
"peerDependencies": {
"vue": "^3.0.0"
"vue": "^3.0.1"
},
"devDependencies": {
"@types/node": "^20.5.9",
Expand Down

0 comments on commit 441ab1f

Please sign in to comment.