-
-
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.
- Loading branch information
1 parent
e753163
commit 3c54bd3
Showing
3 changed files
with
94 additions
and
90 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Enumeration of QR modes. | ||
*/ | ||
export enum QRMode { | ||
MODE_NUMBER = 1, // 1 << 0 is equivalent to 1 | ||
MODE_ALPHA_NUM = 2, // 1 << 1 is equivalent to 2 | ||
MODE_8BIT_BYTE = 4, // 1 << 2 is equivalent to 4 | ||
MODE_KANJI = 8, // 1 << 3 is equivalent to 8 | ||
} | ||
|
||
/** | ||
* Enumeration of QR error-correction levels. | ||
*/ | ||
export enum QRErrorCorrectLevel { | ||
L = 1, | ||
M = 0, | ||
Q = 3, | ||
H = 2, | ||
} | ||
|
||
/** | ||
* Enumeration of QR masking patterns. | ||
*/ | ||
export enum QRMaskPattern { | ||
PATTERN000 = 0, | ||
PATTERN001 = 1, | ||
PATTERN010 = 2, | ||
PATTERN011 = 3, | ||
PATTERN100 = 4, | ||
PATTERN101 = 5, | ||
PATTERN110 = 6, | ||
PATTERN111 = 7, | ||
} | ||
|
||
/** | ||
* Helper interface defining the structure of RS Blocks. | ||
*/ | ||
export interface RSBlock { | ||
totalCount: number | ||
dataCount: number | ||
errorCount: number | ||
} | ||
|
||
/** | ||
* Config for drawing/rendering the QRCode. | ||
*/ | ||
export interface QRCodeConfig { | ||
text: string | ||
width: number | ||
height: number | ||
colorDark: string | ||
colorLight: string | ||
correctLevel: QRErrorCorrectLevel | ||
useSVG: boolean | ||
} | ||
|
||
export type QRCodeOptions = Partial<QRCodeConfig> |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Helper function to determine if the current browser supports the Canvas API. | ||
*/ | ||
export function isSupportCanvas(): boolean { | ||
return typeof CanvasRenderingContext2D !== 'undefined' | ||
} | ||
|
||
/** | ||
* Helper function to detect Android versions (workarounds for older Android). | ||
*/ | ||
export function getAndroid(): number | false { | ||
const sAgent = navigator.userAgent.toLowerCase() | ||
|
||
if (sAgent.includes('android')) { | ||
// Try to grab the version number | ||
const match = sAgent.match(/android (\d\.\d)/i) | ||
if (match && match[1]) { | ||
return Number.parseFloat(match[1]) | ||
} | ||
|
||
return 1 // No version number found | ||
} | ||
|
||
return false | ||
} | ||
|
||
/** | ||
* Returns the length of text when encoded in UTF-8, plus BOM if needed. | ||
*/ | ||
export function getUTF8Length(sText: string): number { | ||
const replacedText = encodeURI(sText).toString().replace(/%[0-9a-f]{2}/gi, 'a') | ||
return replacedText.length + (replacedText.length !== sText.length ? 3 : 0) | ||
} |