forked from soldair/node-qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from slidoapp/refactor/esm
- Loading branch information
Showing
75 changed files
with
725 additions
and
633 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
/* global QRCode */ | ||
QRCode.toSJIS = require('./to-sjis') | ||
|
||
import { toSJIS } from './to-sjis.js' | ||
|
||
QRCode.toSJIS = toSJIS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,70 @@ | ||
// Copyright 2017 Vincenzo Greco | ||
// Copyright 2024 Cisco Systems, Inc. | ||
// Licensed under MIT-style license (see LICENSE.txt file). | ||
|
||
/** | ||
* Helper class to handle QR Code symbol modules | ||
* | ||
* @param {Number} size Symbol size | ||
*/ | ||
function BitMatrix (size) { | ||
if (!size || size < 1) { | ||
throw new Error('BitMatrix size must be defined and greater than 0') | ||
} | ||
export default class BitMatrix { | ||
/** | ||
* @param {Number} size Symbol size | ||
*/ | ||
constructor (size) { | ||
if (!size || size < 1) { | ||
throw new Error('BitMatrix size must be defined and greater than 0') | ||
} | ||
|
||
this.size = size | ||
this.data = new Uint8Array(size * size) | ||
this.reservedBit = new Uint8Array(size * size) | ||
} | ||
this.size = size | ||
this.data = new Uint8Array(size * size) | ||
this.reservedBit = new Uint8Array(size * size) | ||
} | ||
|
||
/** | ||
* Set bit value at specified location | ||
* If reserved flag is set, this bit will be ignored during masking process | ||
* | ||
* @param {Number} row | ||
* @param {Number} col | ||
* @param {Boolean} value | ||
* @param {Boolean} reserved | ||
*/ | ||
BitMatrix.prototype.set = function (row, col, value, reserved) { | ||
const index = row * this.size + col | ||
this.data[index] = value | ||
if (reserved) this.reservedBit[index] = true | ||
} | ||
/** | ||
* Set bit value at specified location | ||
* If reserved flag is set, this bit will be ignored during masking process | ||
* | ||
* @param {Number} row | ||
* @param {Number} col | ||
* @param {Boolean} value | ||
* @param {Boolean} reserved | ||
*/ | ||
set (row, col, value, reserved) { | ||
const index = row * this.size + col | ||
this.data[index] = value | ||
if (reserved) this.reservedBit[index] = true | ||
} | ||
|
||
/** | ||
* Returns bit value at specified location | ||
* | ||
* @param {Number} row | ||
* @param {Number} col | ||
* @return {Boolean} | ||
*/ | ||
BitMatrix.prototype.get = function (row, col) { | ||
return this.data[row * this.size + col] | ||
} | ||
/** | ||
* Returns bit value at specified location | ||
* | ||
* @param {Number} row | ||
* @param {Number} col | ||
* @return {Boolean} | ||
*/ | ||
get (row, col) { | ||
return this.data[row * this.size + col] | ||
} | ||
|
||
/** | ||
* Applies xor operator at specified location | ||
* (used during masking process) | ||
* | ||
* @param {Number} row | ||
* @param {Number} col | ||
* @param {Boolean} value | ||
*/ | ||
BitMatrix.prototype.xor = function (row, col, value) { | ||
this.data[row * this.size + col] ^= value | ||
} | ||
/** | ||
* Applies xor operator at specified location | ||
* (used during masking process) | ||
* | ||
* @param {Number} row | ||
* @param {Number} col | ||
* @param {Boolean} value | ||
*/ | ||
xor (row, col, value) { | ||
this.data[row * this.size + col] ^= value | ||
} | ||
|
||
/** | ||
* Check if bit at specified location is reserved | ||
* | ||
* @param {Number} row | ||
* @param {Number} col | ||
* @return {Boolean} | ||
*/ | ||
BitMatrix.prototype.isReserved = function (row, col) { | ||
return this.reservedBit[row * this.size + col] | ||
/** | ||
* Check if bit at specified location is reserved | ||
* | ||
* @param {Number} row | ||
* @param {Number} col | ||
* @return {Boolean} | ||
*/ | ||
isReserved (row, col) { | ||
return this.reservedBit[row * this.size + col] | ||
} | ||
} | ||
|
||
module.exports = BitMatrix |
Oops, something went wrong.