@taybart/corvid 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/dom.d.ts +1 -0
- package/dist/index.js +14 -0
- package/dist/qr/index.d.ts +41 -0
- package/dist/qr/qr-generator.d.ts +71 -0
- package/dist/qr/qr-utils.d.ts +28 -0
- package/dist/qr.js +2078 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -116,3 +116,14 @@ style.onDarkMode((isDark) => {
|
|
|
116
116
|
console.log(`is dark mode: ${isDark} and background is ${style.cssVar('--color-bg')`)
|
|
117
117
|
})
|
|
118
118
|
```
|
|
119
|
+
|
|
120
|
+
### QR
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import { QR } '@taybart/corvid/qr'
|
|
124
|
+
|
|
125
|
+
QR.render({
|
|
126
|
+
text: 'https://example.com',
|
|
127
|
+
size: 200,
|
|
128
|
+
}, document.getElementById('qr'))
|
|
129
|
+
```
|
package/dist/dom.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { logger } from './utils';
|
|
|
7
7
|
* onDomContentLoaded callback
|
|
8
8
|
*/
|
|
9
9
|
export declare function ready(cb: () => void): void;
|
|
10
|
+
export declare function on(event: string, cb: (ev: Event) => void): () => void;
|
|
10
11
|
export declare function onKey(key: string, cb: (ev: {
|
|
11
12
|
ctrl: boolean;
|
|
12
13
|
alt: boolean;
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ __webpack_require__.d(dom_namespaceObject, {
|
|
|
43
43
|
el: ()=>dom_el,
|
|
44
44
|
els: ()=>els,
|
|
45
45
|
interpolate: ()=>interpolate,
|
|
46
|
+
on: ()=>on,
|
|
46
47
|
onKey: ()=>onKey,
|
|
47
48
|
ready: ()=>ready
|
|
48
49
|
});
|
|
@@ -158,16 +159,23 @@ function genID(len = 15, alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefg
|
|
|
158
159
|
].map((value)=>alphabet[Math.floor(value / 255 * alphabet.length)]).join('');
|
|
159
160
|
}
|
|
160
161
|
const clipboard = {
|
|
162
|
+
check () {
|
|
163
|
+
if (!navigator.clipboard) throw new Error('Clipboard API not supported, or context is not https');
|
|
164
|
+
},
|
|
161
165
|
async copy (text) {
|
|
166
|
+
this.check();
|
|
162
167
|
await navigator.clipboard.writeText(text);
|
|
163
168
|
},
|
|
164
169
|
async copyArbitrary (data) {
|
|
170
|
+
this.check();
|
|
165
171
|
await navigator.clipboard.write(data);
|
|
166
172
|
},
|
|
167
173
|
async read () {
|
|
174
|
+
this.check();
|
|
168
175
|
return await navigator.clipboard.readText();
|
|
169
176
|
},
|
|
170
177
|
async readArbitrary () {
|
|
178
|
+
this.check();
|
|
171
179
|
return await navigator.clipboard.read();
|
|
172
180
|
},
|
|
173
181
|
listen (query, cb) {
|
|
@@ -242,6 +250,12 @@ function dom_define_property(obj, key, value) {
|
|
|
242
250
|
function ready(cb) {
|
|
243
251
|
window.addEventListener('DOMContentLoaded', cb);
|
|
244
252
|
}
|
|
253
|
+
function on(event, cb) {
|
|
254
|
+
document.addEventListener(event, cb);
|
|
255
|
+
return ()=>{
|
|
256
|
+
document.removeEventListener(event, cb);
|
|
257
|
+
};
|
|
258
|
+
}
|
|
245
259
|
function onKey(key, cb, verbose = false) {
|
|
246
260
|
const log = new logger(verbose ? utils_logLevel.debug : utils_logLevel.none, 'onKey');
|
|
247
261
|
log.debug(`adding ${key} keydown listener`);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface QRCodeConfig {
|
|
2
|
+
text: string;
|
|
3
|
+
size?: number;
|
|
4
|
+
fill?: string | GradientFill;
|
|
5
|
+
background?: string | null;
|
|
6
|
+
ecLevel?: 'L' | 'M' | 'Q' | 'H';
|
|
7
|
+
minVersion?: number;
|
|
8
|
+
maxVersion?: number;
|
|
9
|
+
radius?: number;
|
|
10
|
+
quiet?: number;
|
|
11
|
+
left?: number;
|
|
12
|
+
top?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface GradientFill {
|
|
15
|
+
type: 'linear-gradient' | 'radial-gradient';
|
|
16
|
+
position: number[];
|
|
17
|
+
colorStops: [number, string][];
|
|
18
|
+
}
|
|
19
|
+
export interface QRCode {
|
|
20
|
+
text: string;
|
|
21
|
+
level: string;
|
|
22
|
+
version: number;
|
|
23
|
+
moduleCount: number;
|
|
24
|
+
isDark: (row: number, col: number) => boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare class QR {
|
|
27
|
+
static render(config: QRCodeConfig, element: HTMLElement | HTMLCanvasElement): void;
|
|
28
|
+
private static getDefaultSettings;
|
|
29
|
+
private static createQRCode;
|
|
30
|
+
private static createMinQRCode;
|
|
31
|
+
private static drawBackground;
|
|
32
|
+
private static drawModuleRoundedDark;
|
|
33
|
+
private static drawModuleRoundedLight;
|
|
34
|
+
private static drawModuleRounded;
|
|
35
|
+
private static drawModules;
|
|
36
|
+
private static setFill;
|
|
37
|
+
private static drawOnCanvas;
|
|
38
|
+
private static createCanvas;
|
|
39
|
+
private static renderToCanvas;
|
|
40
|
+
}
|
|
41
|
+
export default QR;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export declare class QRCodeGenerator {
|
|
2
|
+
private typeNumber;
|
|
3
|
+
private errorCorrectLevel;
|
|
4
|
+
private modules;
|
|
5
|
+
private moduleCount;
|
|
6
|
+
private dataCache;
|
|
7
|
+
private dataList;
|
|
8
|
+
constructor(typeNumber: number, errorCorrectLevel: string);
|
|
9
|
+
addData(data: string): void;
|
|
10
|
+
isDark(row: number, col: number): boolean;
|
|
11
|
+
getModuleCount(): number;
|
|
12
|
+
make(): void;
|
|
13
|
+
private makeImpl;
|
|
14
|
+
private createModules;
|
|
15
|
+
private setupPositionProbePattern;
|
|
16
|
+
private getBestMaskPattern;
|
|
17
|
+
private setupTimingPattern;
|
|
18
|
+
private setupPositionAdjustPattern;
|
|
19
|
+
private setupTypeNumber;
|
|
20
|
+
private setupTypeInfo;
|
|
21
|
+
private mapData;
|
|
22
|
+
private createBytes;
|
|
23
|
+
private getErrorCorrectPolynomial;
|
|
24
|
+
private createData;
|
|
25
|
+
static stringToBytes(s: string): number[];
|
|
26
|
+
}
|
|
27
|
+
export declare class QR8BitByte {
|
|
28
|
+
private mode;
|
|
29
|
+
private data;
|
|
30
|
+
private bytes;
|
|
31
|
+
constructor(data: string);
|
|
32
|
+
getMode(): number;
|
|
33
|
+
getLength(): number;
|
|
34
|
+
write(buffer: QRBitBuffer): void;
|
|
35
|
+
}
|
|
36
|
+
export declare class QRBitBuffer {
|
|
37
|
+
private buffer;
|
|
38
|
+
private length;
|
|
39
|
+
getBuffer(): number[];
|
|
40
|
+
getAt(index: number): boolean;
|
|
41
|
+
put(num: number, length: number): void;
|
|
42
|
+
getLengthInBits(): number;
|
|
43
|
+
putBit(bit: boolean): void;
|
|
44
|
+
}
|
|
45
|
+
export declare class QRPolynomial {
|
|
46
|
+
private num;
|
|
47
|
+
constructor(num: number[], shift: number);
|
|
48
|
+
getAt(index: number): number;
|
|
49
|
+
getLength(): number;
|
|
50
|
+
multiply(e: QRPolynomial): QRPolynomial;
|
|
51
|
+
mod(e: QRPolynomial): QRPolynomial;
|
|
52
|
+
}
|
|
53
|
+
export declare const QRMode: {
|
|
54
|
+
readonly MODE_8BIT_BYTE: number;
|
|
55
|
+
};
|
|
56
|
+
export declare const QRErrorCorrectLevel: {
|
|
57
|
+
readonly L: 1;
|
|
58
|
+
readonly M: 0;
|
|
59
|
+
readonly Q: 3;
|
|
60
|
+
readonly H: 2;
|
|
61
|
+
};
|
|
62
|
+
export declare const QRMaskPattern: {
|
|
63
|
+
readonly PATTERN000: 0;
|
|
64
|
+
readonly PATTERN001: 1;
|
|
65
|
+
readonly PATTERN010: 2;
|
|
66
|
+
readonly PATTERN011: 3;
|
|
67
|
+
readonly PATTERN100: 4;
|
|
68
|
+
readonly PATTERN101: 5;
|
|
69
|
+
readonly PATTERN110: 6;
|
|
70
|
+
readonly PATTERN111: 7;
|
|
71
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare class QRUtil {
|
|
2
|
+
private static PATTERN_POSITION_TABLE;
|
|
3
|
+
private static G15;
|
|
4
|
+
private static G18;
|
|
5
|
+
private static G15_MASK;
|
|
6
|
+
private static getBCHDigit;
|
|
7
|
+
static getBCHTypeInfo(data: number): number;
|
|
8
|
+
static getBCHTypeNumber(data: number): number;
|
|
9
|
+
static getPatternPosition(typeNumber: number): number[];
|
|
10
|
+
static getMaskFunction(maskPattern: number): (i: number, j: number) => boolean;
|
|
11
|
+
static getErrorCorrectPolynomial(errorCorrectLength: number): any;
|
|
12
|
+
static getLengthInBits(mode: number, type: number): number;
|
|
13
|
+
static getLostPoint(qrcode: any): number;
|
|
14
|
+
}
|
|
15
|
+
export declare class QRMath {
|
|
16
|
+
private static EXP_TABLE;
|
|
17
|
+
private static LOG_TABLE;
|
|
18
|
+
static glog(n: number): number;
|
|
19
|
+
static gexp(n: number): number;
|
|
20
|
+
}
|
|
21
|
+
export declare class QRRSBlock {
|
|
22
|
+
private static RS_BLOCK_TABLE;
|
|
23
|
+
totalCount: number;
|
|
24
|
+
dataCount: number;
|
|
25
|
+
constructor(totalCount: number, dataCount: number);
|
|
26
|
+
private static getRsBlockTable;
|
|
27
|
+
static getRSBlocks(typeNumber: number, errorCorrectLevel: number): QRRSBlock[];
|
|
28
|
+
}
|