@taybart/corvid 0.1.5 → 0.1.7

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 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;
@@ -20,7 +21,7 @@ type elOpts = {
20
21
  query?: string;
21
22
  type?: string;
22
23
  content?: any;
23
- class?: string;
24
+ class?: string | string[];
24
25
  style?: Object;
25
26
  id?: string;
26
27
  parent?: HTMLElement | el;
@@ -45,8 +46,8 @@ export declare class el {
45
46
  /*** Style ***/
46
47
  style(update: Object | string, stringify?: boolean): this | undefined;
47
48
  hasClass(className: string): boolean;
48
- addClass(className: string): this;
49
- removeClass(className: string): this;
49
+ addClass(className: string | string[]): this;
50
+ removeClass(className: string | string[]): this;
50
51
  /*** Templates ***/
51
52
  render(vars?: {}): string;
52
53
  appendTemplate(template: el, vars: any): void;
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`);
@@ -331,12 +345,14 @@ class dom_el {
331
345
  }
332
346
  addClass(className) {
333
347
  if (!this.el) throw new Error(`no element from query: ${this.query}`);
334
- this.el.classList.add(className);
348
+ if ('string' == typeof className) this.el.classList.add(className);
349
+ else for (const sc of className)this.el.classList.add(sc);
335
350
  return this;
336
351
  }
337
352
  removeClass(className) {
338
353
  if (!this.el) throw new Error(`no element from query: ${this.query}`);
339
- this.el.classList.remove(className);
354
+ if ('string' == typeof className) this.el.classList.remove(className);
355
+ else for (const sc of className)this.el.classList.remove(sc);
340
356
  return this;
341
357
  }
342
358
  render(vars = {}) {
@@ -365,6 +381,7 @@ class dom_el {
365
381
  }
366
382
  removeListeners(event) {
367
383
  if (!this.el) throw new Error(`no element from query: ${this.query}`);
384
+ if (!this.listeners[event]) return this;
368
385
  for (const cb of this.listeners[event])this.el.removeEventListener(event, cb);
369
386
  this.listeners[event] = [];
370
387
  return this;
@@ -404,7 +421,8 @@ class dom_el {
404
421
  this.log.debug(`setting id: ${id}`);
405
422
  this.el.id = id;
406
423
  }
407
- if (styleClass) this.el.classList.add(styleClass);
424
+ if (styleClass) if ('string' == typeof styleClass) this.el.classList.add(styleClass);
425
+ else for (const sc of styleClass)this.el.classList.add(sc);
408
426
  if (style) this.style(style);
409
427
  if (content) {
410
428
  this.log.debug(`setting content: ${content}`);
@@ -469,14 +487,16 @@ class request {
469
487
  this.opts.body = body;
470
488
  return this;
471
489
  }
472
- async do({ path, override } = {}) {
490
+ async do({ path, params: passedParams, override } = {}) {
473
491
  if (this.opts.auth) this.opts.headers.Authorization = `Bearer ${this.opts.auth}`;
474
492
  if (!override) override = {};
475
493
  const body = override.body || this.opts.body;
476
494
  let url = this.opts.url;
477
495
  if (path) url = `${this.opts.url}${path}`;
478
- const params = override.params || this.opts.params;
479
- if (params) url = `${url}?${params.toString()}`;
496
+ let reqParams;
497
+ if (override.params || this.opts.params) reqParams = new network_params(override.params || this.opts.params);
498
+ if (passedParams) reqParams = reqParams ? new network_params(reqParams).set(passedParams) : new network_params(passedParams);
499
+ if (reqParams) url = `${url}?${reqParams.toString()}`;
480
500
  this.log.debug(`${this.opts.method} ${url}`);
481
501
  const res = await fetch(url, {
482
502
  method: this.opts.method,
package/dist/network.d.ts CHANGED
@@ -12,7 +12,7 @@ export type requestOpts = {
12
12
  url?: string;
13
13
  type?: 'json';
14
14
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
15
- params?: typeof params;
15
+ params?: Object | params;
16
16
  headers?: Record<string, string>;
17
17
  auth?: string;
18
18
  body?: Object;
@@ -26,11 +26,12 @@ export declare class request {
26
26
  auth(token: string): this;
27
27
  basicAuth(username: string, password: string): this;
28
28
  body(body: Object): this;
29
- do({ path, override, }?: {
29
+ do({ path, params: passedParams, override, }?: {
30
30
  path?: string;
31
+ params?: Object;
31
32
  override?: {
32
33
  success?: number;
33
- params?: any;
34
+ params?: Object;
34
35
  body?: Object;
35
36
  };
36
37
  }): Promise<any>;
@@ -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
+ }