@oila/0account 3.4.3 → 3.4.5

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.
Files changed (94) hide show
  1. package/LICENSE +1 -1
  2. package/dist/cjs/index-1e526aba.js +1645 -0
  3. package/dist/cjs/index-1e526aba.js.map +1 -0
  4. package/dist/cjs/index.cjs.js +4 -0
  5. package/dist/cjs/index.cjs.js.map +1 -0
  6. package/dist/cjs/loader.cjs.js +15 -0
  7. package/dist/cjs/loader.cjs.js.map +1 -0
  8. package/dist/cjs/qr-code_2.cjs.entry.js +2472 -0
  9. package/dist/cjs/qr-code_2.cjs.entry.js.map +1 -0
  10. package/dist/cjs/zero-account.cjs.js +25 -0
  11. package/dist/cjs/zero-account.cjs.js.map +1 -0
  12. package/dist/collection/collection-manifest.json +13 -0
  13. package/dist/collection/components/zero-account/enums.js +18 -0
  14. package/dist/collection/components/zero-account/enums.js.map +1 -0
  15. package/dist/collection/components/zero-account/logo.js +6 -0
  16. package/dist/collection/components/zero-account/logo.js.map +1 -0
  17. package/dist/collection/components/zero-account/qrcode.js +111 -0
  18. package/dist/collection/components/zero-account/qrcode.js.map +1 -0
  19. package/dist/collection/components/zero-account/websocket.js +174 -0
  20. package/dist/collection/components/zero-account/websocket.js.map +1 -0
  21. package/dist/collection/components/zero-account/zero-account.css +287 -0
  22. package/dist/collection/components/zero-account/zero-account.e2e.js +26 -0
  23. package/dist/collection/components/zero-account/zero-account.e2e.js.map +1 -0
  24. package/dist/collection/components/zero-account/zero-account.js +457 -0
  25. package/dist/collection/components/zero-account/zero-account.js.map +1 -0
  26. package/dist/collection/components/zero-account/zero-account.spec.js +35 -0
  27. package/dist/collection/components/zero-account/zero-account.spec.js.map +1 -0
  28. package/dist/collection/index.js +2 -0
  29. package/dist/collection/index.js.map +1 -0
  30. package/dist/collection/utils/qrcode/qrcode.js +1007 -0
  31. package/dist/collection/utils/request.js +38 -0
  32. package/dist/collection/utils/request.js.map +1 -0
  33. package/dist/collection/utils/url.js +43 -0
  34. package/dist/collection/utils/utils.js +16 -0
  35. package/dist/collection/utils/utils.js.map +1 -0
  36. package/dist/collection/utils/utils.spec.js +10 -0
  37. package/dist/collection/utils/utils.spec.js.map +1 -0
  38. package/dist/components/index.d.ts +27 -0
  39. package/dist/components/index.js +3 -0
  40. package/dist/components/index.js.map +1 -0
  41. package/dist/components/qr-code.d.ts +11 -0
  42. package/dist/components/qr-code.js +8 -0
  43. package/dist/components/qr-code.js.map +1 -0
  44. package/dist/components/qrcode.js +1073 -0
  45. package/dist/components/qrcode.js.map +1 -0
  46. package/dist/components/zero-account.d.ts +11 -0
  47. package/dist/components/zero-account.js +1460 -0
  48. package/dist/components/zero-account.js.map +1 -0
  49. package/dist/esm/index-09024c20.js +1616 -0
  50. package/dist/esm/index-09024c20.js.map +1 -0
  51. package/dist/esm/index.js +3 -0
  52. package/dist/esm/index.js.map +1 -0
  53. package/dist/esm/loader.js +11 -0
  54. package/dist/esm/loader.js.map +1 -0
  55. package/dist/esm/polyfills/core-js.js +11 -0
  56. package/dist/esm/polyfills/dom.js +79 -0
  57. package/dist/esm/polyfills/es5-html-element.js +1 -0
  58. package/dist/esm/polyfills/index.js +34 -0
  59. package/dist/esm/polyfills/system.js +6 -0
  60. package/dist/esm/qr-code_2.entry.js +2467 -0
  61. package/dist/esm/qr-code_2.entry.js.map +1 -0
  62. package/dist/esm/zero-account.js +20 -0
  63. package/dist/esm/zero-account.js.map +1 -0
  64. package/dist/index.cjs.js +1 -0
  65. package/dist/index.js +1 -0
  66. package/dist/types/components/zero-account/enums.d.ts +14 -0
  67. package/dist/types/components/zero-account/logo.d.ts +5 -0
  68. package/dist/types/components/zero-account/qrcode.d.ts +8 -0
  69. package/dist/types/components/zero-account/websocket.d.ts +31 -0
  70. package/dist/types/components/zero-account/zero-account.d.ts +45 -0
  71. package/dist/types/components.d.ts +88 -0
  72. package/dist/types/index.d.ts +1 -0
  73. package/dist/types/stencil-public-runtime.d.ts +1640 -0
  74. package/dist/types/utils/request.d.ts +10 -0
  75. package/dist/types/utils/utils.d.ts +7 -0
  76. package/dist/zero-account/index.esm.js +2 -0
  77. package/dist/zero-account/index.esm.js.map +1 -0
  78. package/dist/zero-account/p-21f4994d.js +3 -0
  79. package/dist/zero-account/p-21f4994d.js.map +1 -0
  80. package/dist/zero-account/p-9a90a04d.entry.js +2 -0
  81. package/dist/zero-account/p-9a90a04d.entry.js.map +1 -0
  82. package/dist/zero-account/zero-account.esm.js +2 -0
  83. package/dist/zero-account/zero-account.esm.js.map +1 -0
  84. package/loader/cdn.js +3 -0
  85. package/loader/index.cjs.js +3 -0
  86. package/loader/index.d.ts +21 -0
  87. package/loader/index.es2017.js +3 -0
  88. package/loader/index.js +4 -0
  89. package/loader/package.json +11 -0
  90. package/package.json +33 -40
  91. package/readme.md +75 -0
  92. package/0account.d.ts +0 -24
  93. package/README.md +0 -3
  94. package/dist/0account.js +0 -1
@@ -0,0 +1,457 @@
1
+ import { h, Host } from "@stencil/core";
2
+ import { UAParser } from "ua-parser-js";
3
+ import { v4 as uuidv4 } from "uuid";
4
+ import { Environment, ErrorCorrectionLevel, ThemePreset } from "./enums";
5
+ import { Logger } from "../../utils/utils";
6
+ import * as utilsURL from "../../utils/url";
7
+ import Logo from "./logo";
8
+ import { WS } from "./websocket";
9
+ const maxInterval = 59 * 60 * 1000;
10
+ const minInterval = 10 * 1000;
11
+ const DEFAULT_CALLBACK_URL = window.location.origin + '/zero/auth';
12
+ const ANIMATION_DURATION = 3000;
13
+ export class ZeroAccount {
14
+ constructor() {
15
+ this.refreshQR = (ignoreAnimate = false) => {
16
+ const update = () => {
17
+ this.restartTimer();
18
+ this.updateURL();
19
+ };
20
+ if (ignoreAnimate)
21
+ return update();
22
+ this.isAnimating = true;
23
+ this.animationTimer = window.setTimeout(() => {
24
+ update();
25
+ this.isAnimating = false;
26
+ }, ANIMATION_DURATION);
27
+ };
28
+ this.hideOnEsc = (e) => {
29
+ if ((e.key === 'Escape' || e.key === 'Esc')) {
30
+ this.modalOpen = false;
31
+ }
32
+ };
33
+ this.log = (...args) => this.logger.log(...args);
34
+ this.appId = undefined;
35
+ this.updateInterval = 3 * 60 * 1000;
36
+ this.callbackURL = DEFAULT_CALLBACK_URL;
37
+ this.modal = true;
38
+ this.selector = null;
39
+ this.level = ErrorCorrectionLevel.M;
40
+ this.primaryColor = '#3C444F';
41
+ this.secondaryColor = undefined;
42
+ this.instructionsText = undefined;
43
+ this.hideInstructions = false;
44
+ this.environment = Environment.production;
45
+ this.enableWithCredentials = false;
46
+ this.themePreset = ThemePreset.light;
47
+ this.autoStartApp = true;
48
+ this.modalOpen = false;
49
+ this.isAnimating = false;
50
+ this.url = '';
51
+ }
52
+ getUpdateInterval() {
53
+ // make sure the provided value is within bounds
54
+ return Math.min(Math.max(this.updateInterval, minInterval), maxInterval);
55
+ }
56
+ toggleModal() {
57
+ this.modalOpen = !this.modalOpen;
58
+ if (this.modalOpen)
59
+ this.refreshQR(true);
60
+ if ((this.modalOpen && this.autoStartApp) || this.isMobile())
61
+ this.openApp();
62
+ }
63
+ _closeModal() {
64
+ this.modalOpen = false;
65
+ this.stopTimer();
66
+ }
67
+ closeModal(e) {
68
+ if (e.target !== this.modalEl && e.target !== this.closeButtonEl) {
69
+ return e.stopPropagation();
70
+ }
71
+ this._closeModal();
72
+ }
73
+ openApp() {
74
+ if (this.modalOpen) {
75
+ window.location.href = this.url;
76
+ }
77
+ }
78
+ render() {
79
+ const logoColor = this.themePreset === ThemePreset.light ? '#7263FA' : '#FFFFF9';
80
+ const qrColor = this.themePreset === ThemePreset.light ? '#000' : '#FFFFF9';
81
+ return (h(Host, null, h("slot", null), this.host.childNodes.length === 0 &&
82
+ h("button", { class: `button ${this.themePreset}`, onClick: () => this.toggleModal() }, h(Logo, { className: 'button__logo', color: logoColor }), "use 0account"), h("div", { ref: el => this.modalEl = el, onClick: (e) => this.closeModal(e), class: `modal ${this.themePreset} ${this.isAnimating ? 'modal-animated' : ''} ${this.modalOpen ? '' : 'modal--hidden'}` }, h("div", { class: 'modal__content' }, h("div", { ref: el => this.closeButtonEl = el, class: 'modal__close-button' }), h("div", { class: 'modal__qrcode__container' }, h("qr-code", { url: this.url, class: `modal__qrcode`, level: this.level, color: qrColor }), h("div", { class: 'circle__overlay' }, h("div", { class: 'circle' }), h("div", { class: 'circle circle--medium' }), h("div", { class: 'circle circle--large' })), h(Logo, { className: 'modal__logo', color: logoColor })), h("div", { class: 'modal__buttons' }, h("button", { onClick: () => this.openApp(), class: 'modal__button' }, "Open the desktop app"), h("a", { href: '#', class: 'modal__link' }, "Download the app"))))));
83
+ }
84
+ // called only once
85
+ componentWillLoad() {
86
+ this.logger = new Logger(this.environment);
87
+ this.uaParser = new UAParser();
88
+ this.ws = new WS(this.appId, {
89
+ updateInterval: this.getUpdateInterval(),
90
+ callbackURL: this.callbackURL,
91
+ uaParser: this.uaParser,
92
+ env: this.environment,
93
+ log: this.log,
94
+ });
95
+ // make sure we initQR
96
+ this.refreshQR(true);
97
+ document.addEventListener('keydown', this.hideOnEsc);
98
+ }
99
+ updateURL() {
100
+ const expires = new Date().getTime() + this.getUpdateInterval();
101
+ const uuid = uuidv4();
102
+ this.ws.updateUUID(uuid);
103
+ const params = utilsURL.appendToParams('', {
104
+ appId: this.appId,
105
+ uuid: uuid,
106
+ expires: expires,
107
+ });
108
+ if (this.isMobile()) {
109
+ this.url = 'https://launch.0account.com/auth?' + params;
110
+ }
111
+ else {
112
+ this.url = 'zero-account://auth?' + params;
113
+ }
114
+ }
115
+ isMobile() {
116
+ const device = this.uaParser.getDevice();
117
+ return device.type === 'tablet' || device.type === 'mobile';
118
+ }
119
+ connectedCallback() {
120
+ this.startTimer();
121
+ }
122
+ disconnectedCallback() {
123
+ this.stopTimer();
124
+ document.removeEventListener('keydown', this.hideOnEsc);
125
+ }
126
+ restartTimer() {
127
+ this.stopTimer();
128
+ this.startTimer();
129
+ }
130
+ startTimer() {
131
+ this.timer = window.setInterval(this.refreshQR, this.getUpdateInterval());
132
+ }
133
+ stopTimer() {
134
+ window.clearInterval(this.timer);
135
+ window.clearTimeout(this.animationTimer);
136
+ this.isAnimating = false;
137
+ }
138
+ static get is() { return "zero-account"; }
139
+ static get encapsulation() { return "shadow"; }
140
+ static get originalStyleUrls() {
141
+ return {
142
+ "$": ["zero-account.css"]
143
+ };
144
+ }
145
+ static get styleUrls() {
146
+ return {
147
+ "$": ["zero-account.css"]
148
+ };
149
+ }
150
+ static get properties() {
151
+ return {
152
+ "appId": {
153
+ "type": "string",
154
+ "mutable": false,
155
+ "complexType": {
156
+ "original": "string",
157
+ "resolved": "string",
158
+ "references": {}
159
+ },
160
+ "required": true,
161
+ "optional": false,
162
+ "docs": {
163
+ "tags": [],
164
+ "text": ""
165
+ },
166
+ "attribute": "app-id",
167
+ "reflect": false
168
+ },
169
+ "updateInterval": {
170
+ "type": "number",
171
+ "mutable": false,
172
+ "complexType": {
173
+ "original": "number",
174
+ "resolved": "number",
175
+ "references": {}
176
+ },
177
+ "required": false,
178
+ "optional": true,
179
+ "docs": {
180
+ "tags": [],
181
+ "text": ""
182
+ },
183
+ "attribute": "update-interval",
184
+ "reflect": false,
185
+ "defaultValue": "3 * 60 * 1000"
186
+ },
187
+ "callbackURL": {
188
+ "type": "string",
189
+ "mutable": false,
190
+ "complexType": {
191
+ "original": "string",
192
+ "resolved": "string",
193
+ "references": {}
194
+ },
195
+ "required": false,
196
+ "optional": false,
197
+ "docs": {
198
+ "tags": [],
199
+ "text": ""
200
+ },
201
+ "attribute": "callback-u-r-l",
202
+ "reflect": false,
203
+ "defaultValue": "DEFAULT_CALLBACK_URL"
204
+ },
205
+ "modal": {
206
+ "type": "boolean",
207
+ "mutable": false,
208
+ "complexType": {
209
+ "original": "boolean",
210
+ "resolved": "boolean",
211
+ "references": {}
212
+ },
213
+ "required": false,
214
+ "optional": true,
215
+ "docs": {
216
+ "tags": [],
217
+ "text": ""
218
+ },
219
+ "attribute": "modal",
220
+ "reflect": false,
221
+ "defaultValue": "true"
222
+ },
223
+ "selector": {
224
+ "type": "string",
225
+ "mutable": false,
226
+ "complexType": {
227
+ "original": "string",
228
+ "resolved": "string",
229
+ "references": {}
230
+ },
231
+ "required": false,
232
+ "optional": true,
233
+ "docs": {
234
+ "tags": [],
235
+ "text": ""
236
+ },
237
+ "attribute": "selector",
238
+ "reflect": false,
239
+ "defaultValue": "null"
240
+ },
241
+ "level": {
242
+ "type": "string",
243
+ "mutable": false,
244
+ "complexType": {
245
+ "original": "ErrorCorrectionLevel",
246
+ "resolved": "ErrorCorrectionLevel.H | ErrorCorrectionLevel.L | ErrorCorrectionLevel.M | ErrorCorrectionLevel.Q",
247
+ "references": {
248
+ "ErrorCorrectionLevel": {
249
+ "location": "import",
250
+ "path": "./enums",
251
+ "id": "src/components/zero-account/enums.ts::ErrorCorrectionLevel"
252
+ }
253
+ }
254
+ },
255
+ "required": false,
256
+ "optional": true,
257
+ "docs": {
258
+ "tags": [],
259
+ "text": ""
260
+ },
261
+ "attribute": "level",
262
+ "reflect": false,
263
+ "defaultValue": "ErrorCorrectionLevel.M"
264
+ },
265
+ "primaryColor": {
266
+ "type": "string",
267
+ "mutable": false,
268
+ "complexType": {
269
+ "original": "string",
270
+ "resolved": "string",
271
+ "references": {}
272
+ },
273
+ "required": false,
274
+ "optional": false,
275
+ "docs": {
276
+ "tags": [],
277
+ "text": ""
278
+ },
279
+ "attribute": "primary-color",
280
+ "reflect": false,
281
+ "defaultValue": "'#3C444F'"
282
+ },
283
+ "secondaryColor": {
284
+ "type": "string",
285
+ "mutable": false,
286
+ "complexType": {
287
+ "original": "string",
288
+ "resolved": "string",
289
+ "references": {}
290
+ },
291
+ "required": false,
292
+ "optional": false,
293
+ "docs": {
294
+ "tags": [],
295
+ "text": ""
296
+ },
297
+ "attribute": "secondary-color",
298
+ "reflect": false
299
+ },
300
+ "instructionsText": {
301
+ "type": "string",
302
+ "mutable": false,
303
+ "complexType": {
304
+ "original": "string",
305
+ "resolved": "string",
306
+ "references": {}
307
+ },
308
+ "required": false,
309
+ "optional": false,
310
+ "docs": {
311
+ "tags": [],
312
+ "text": ""
313
+ },
314
+ "attribute": "instructions-text",
315
+ "reflect": false
316
+ },
317
+ "hideInstructions": {
318
+ "type": "boolean",
319
+ "mutable": false,
320
+ "complexType": {
321
+ "original": "boolean",
322
+ "resolved": "boolean",
323
+ "references": {}
324
+ },
325
+ "required": false,
326
+ "optional": false,
327
+ "docs": {
328
+ "tags": [],
329
+ "text": ""
330
+ },
331
+ "attribute": "hide-instructions",
332
+ "reflect": false,
333
+ "defaultValue": "false"
334
+ },
335
+ "environment": {
336
+ "type": "string",
337
+ "mutable": false,
338
+ "complexType": {
339
+ "original": "Environment",
340
+ "resolved": "Environment.production | Environment.staging",
341
+ "references": {
342
+ "Environment": {
343
+ "location": "import",
344
+ "path": "./enums",
345
+ "id": "src/components/zero-account/enums.ts::Environment"
346
+ }
347
+ }
348
+ },
349
+ "required": false,
350
+ "optional": true,
351
+ "docs": {
352
+ "tags": [],
353
+ "text": ""
354
+ },
355
+ "attribute": "environment",
356
+ "reflect": false,
357
+ "defaultValue": "Environment.production"
358
+ },
359
+ "enableWithCredentials": {
360
+ "type": "boolean",
361
+ "mutable": false,
362
+ "complexType": {
363
+ "original": "boolean",
364
+ "resolved": "boolean",
365
+ "references": {}
366
+ },
367
+ "required": false,
368
+ "optional": true,
369
+ "docs": {
370
+ "tags": [],
371
+ "text": ""
372
+ },
373
+ "attribute": "enable-with-credentials",
374
+ "reflect": false,
375
+ "defaultValue": "false"
376
+ },
377
+ "themePreset": {
378
+ "type": "string",
379
+ "mutable": false,
380
+ "complexType": {
381
+ "original": "ThemePreset",
382
+ "resolved": "ThemePreset.dark | ThemePreset.light",
383
+ "references": {
384
+ "ThemePreset": {
385
+ "location": "import",
386
+ "path": "./enums",
387
+ "id": "src/components/zero-account/enums.ts::ThemePreset"
388
+ }
389
+ }
390
+ },
391
+ "required": false,
392
+ "optional": true,
393
+ "docs": {
394
+ "tags": [],
395
+ "text": ""
396
+ },
397
+ "attribute": "theme-preset",
398
+ "reflect": false,
399
+ "defaultValue": "ThemePreset.light"
400
+ },
401
+ "autoStartApp": {
402
+ "type": "boolean",
403
+ "mutable": false,
404
+ "complexType": {
405
+ "original": "boolean",
406
+ "resolved": "boolean",
407
+ "references": {}
408
+ },
409
+ "required": false,
410
+ "optional": true,
411
+ "docs": {
412
+ "tags": [],
413
+ "text": ""
414
+ },
415
+ "attribute": "auto-start-app",
416
+ "reflect": false,
417
+ "defaultValue": "true"
418
+ }
419
+ };
420
+ }
421
+ static get states() {
422
+ return {
423
+ "modalOpen": {},
424
+ "isAnimating": {},
425
+ "url": {}
426
+ };
427
+ }
428
+ static get elementRef() { return "host"; }
429
+ static get listeners() {
430
+ return [{
431
+ "name": "0account-toggle-modal",
432
+ "method": "toggleModal",
433
+ "target": "document",
434
+ "capture": false,
435
+ "passive": false
436
+ }, {
437
+ "name": "0account-close-modal",
438
+ "method": "_closeModal",
439
+ "target": "document",
440
+ "capture": false,
441
+ "passive": false
442
+ }, {
443
+ "name": "0account-authenticated",
444
+ "method": "_closeModal",
445
+ "target": "document",
446
+ "capture": false,
447
+ "passive": false
448
+ }, {
449
+ "name": "0account-open-app",
450
+ "method": "openApp",
451
+ "target": "document",
452
+ "capture": false,
453
+ "passive": false
454
+ }];
455
+ }
456
+ }
457
+ //# sourceMappingURL=zero-account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zero-account.js","sourceRoot":"","sources":["../../../src/components/zero-account/zero-account.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,WAAW,E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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGF","sourcesContent":["import { Element, Component, h, Host, Prop, Listen, State } from '@stencil/core';\nimport { UAParser } from 'ua-parser-js';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { Environment, ErrorCorrectionLevel, ThemePreset } from './enums';\nimport { Logger } from '../../utils/utils';\nimport * as utilsURL from '../../utils/url';\nimport Logo from './logo';\nimport { WS } from './websocket';\n\nconst maxInterval = 59 * 60 * 1000;\nconst minInterval = 10 * 1000;\n\nconst DEFAULT_CALLBACK_URL = window.location.origin + '/zero/auth';\nconst ANIMATION_DURATION = 3000\n\n@Component({\n tag: 'zero-account',\n styleUrl: 'zero-account.css',\n shadow: true,\n})\nexport class ZeroAccount {\n @Prop() appId!: string;\n @Prop() updateInterval?: number = 3 * 60 * 1000;\n @Prop() callbackURL: string = DEFAULT_CALLBACK_URL;\n @Prop() modal?: boolean = true;\n @Prop() selector?: string = null;\n @Prop() level?: ErrorCorrectionLevel = ErrorCorrectionLevel.M;\n @Prop() primaryColor: string = '#3C444F';\n @Prop() secondaryColor: string;\n @Prop() instructionsText: string;\n @Prop() hideInstructions: boolean = false;\n @Prop() environment?: Environment = Environment.production;\n @Prop() enableWithCredentials?: boolean = false;\n @Prop() themePreset?: ThemePreset = ThemePreset.light;\n @Prop() autoStartApp? = true;\n\n private logger: Logger;\n private uaParser: UAParser;\n private ws: WS;\n\n private timer: number;\n private animationTimer: number;\n\n @Element() host: HTMLElement;\n private modalEl: HTMLDivElement;\n private closeButtonEl: HTMLDivElement;\n\n @State() modalOpen = false;\n @State() isAnimating = false;\n @State() url = '';\n\n private getUpdateInterval() {\n // make sure the provided value is within bounds\n return Math.min(Math.max(this.updateInterval, minInterval), maxInterval);\n }\n private refreshQR = (ignoreAnimate = false)=> {\n const update = () => {\n this.restartTimer();\n this.updateURL()\n }\n if (ignoreAnimate) return update();\n\n this.isAnimating = true\n this.animationTimer = window.setTimeout(()=>{\n update()\n this.isAnimating = false\n }, ANIMATION_DURATION)\n }\n\n @Listen('0account-toggle-modal', { target: 'document' })\n toggleModal() {\n this.modalOpen = !this.modalOpen;\n if (this.modalOpen) this.refreshQR(true)\n if ((this.modalOpen && this.autoStartApp) || this.isMobile()) this.openApp()\n }\n\n @Listen('0account-close-modal', { target: 'document' })\n @Listen('0account-authenticated', { target: 'document' })\n private _closeModal() {\n this.modalOpen = false;\n this.stopTimer()\n }\n\n private closeModal(e: MouseEvent) {\n if (e.target !== this.modalEl && e.target !== this.closeButtonEl) {\n return e.stopPropagation();\n }\n this._closeModal()\n }\n\n @Listen('0account-open-app', { target: 'document' })\n openApp() {\n if (this.modalOpen) {\n window.location.href = this.url\n }\n }\n\n render() {\n const logoColor = this.themePreset === ThemePreset.light ? '#7263FA': '#FFFFF9'\n const qrColor = this.themePreset === ThemePreset.light ? '#000': '#FFFFF9'\n return (\n <Host>\n <slot />\n {this.host.childNodes.length === 0 &&\n <button class={`button ${this.themePreset}`} onClick={()=>this.toggleModal()}>\n <Logo className='button__logo' color={logoColor} />\n use 0account\n </button>\n }\n <div\n ref={el => this.modalEl = el}\n onClick={(e) => this.closeModal(e)}\n class={`modal ${this.themePreset} ${this.isAnimating ? 'modal-animated': ''} ${this.modalOpen ? '' : 'modal--hidden'}`}>\n <div class='modal__content'>\n <div ref={el => this.closeButtonEl = el} class='modal__close-button'></div>\n <div class='modal__qrcode__container'>\n <qr-code url={this.url} class={`modal__qrcode`} level={this.level} color={qrColor}/>\n <div class='circle__overlay'>\n <div class='circle'></div>\n <div class='circle circle--medium'></div>\n <div class='circle circle--large'></div>\n </div>\n <Logo className='modal__logo' color={logoColor} />\n </div>\n <div class='modal__buttons'>\n <button onClick={()=>this.openApp()} class='modal__button'>Open the desktop app</button>\n <a href='#' class='modal__link'>Download the app</a>\n </div>\n </div>\n </div>\n </Host>\n );\n }\n\n private hideOnEsc = (e) => {\n if ((e.key === 'Escape' || e.key === 'Esc')) {\n this.modalOpen = false;\n }\n };\n\n // called only once\n componentWillLoad() {\n this.logger = new Logger(this.environment);\n this.uaParser = new UAParser();\n this.ws = new WS(this.appId, {\n updateInterval: this.getUpdateInterval(),\n callbackURL: this.callbackURL,\n uaParser: this.uaParser,\n env: this.environment,\n log: this.log,\n })\n\n // make sure we initQR\n this.refreshQR(true)\n document.addEventListener('keydown', this.hideOnEsc);\n }\n\n private updateURL() {\n const expires = new Date().getTime() + this.getUpdateInterval();\n const uuid = uuidv4();\n this.ws.updateUUID(uuid);\n const params = utilsURL.appendToParams('', {\n appId: this.appId,\n uuid: uuid,\n expires: expires,\n })\n\n if (this.isMobile()) {\n this.url = 'https://launch.0account.com/auth?' + params;\n } else {\n this.url = 'zero-account://auth?' + params;\n }\n }\n\n isMobile() {\n const device = this.uaParser.getDevice()\n return device.type === 'tablet' || device.type === 'mobile'\n }\n\n connectedCallback() {\n this.startTimer()\n }\n\n disconnectedCallback() {\n this.stopTimer()\n document.removeEventListener('keydown', this.hideOnEsc);\n }\n\n private restartTimer() {\n this.stopTimer()\n this.startTimer()\n }\n\n private startTimer() {\n this.timer = window.setInterval(this.refreshQR, this.getUpdateInterval());\n }\n\n private stopTimer() {\n window.clearInterval(this.timer);\n window.clearTimeout(this.animationTimer);\n this.isAnimating = false\n }\n\n private log = (...args) => this.logger.log(...args);\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { newSpecPage } from "@stencil/core/testing";
2
+ import { ZeroAccount } from "./zero-account";
3
+ describe('zero-account', () => {
4
+ it('renders', async () => {
5
+ const { root } = await newSpecPage({
6
+ components: [ZeroAccount],
7
+ html: '<zero-account></zero-account>',
8
+ });
9
+ expect(root).toEqualHtml(`
10
+ <zero-account>
11
+ <mock:shadow-root>
12
+ <div>
13
+ Hello, World! I'm
14
+ </div>
15
+ </mock:shadow-root>
16
+ </zero-account>
17
+ `);
18
+ });
19
+ it('renders with values', async () => {
20
+ const { root } = await newSpecPage({
21
+ components: [ZeroAccount],
22
+ html: `<zero-account first="Stencil" last="'Don't call me a framework' JS"></zero-account>`,
23
+ });
24
+ expect(root).toEqualHtml(`
25
+ <zero-account first="Stencil" last="'Don't call me a framework' JS">
26
+ <mock:shadow-root>
27
+ <div>
28
+ Hello, World! I'm Stencil 'Don't call me a framework' JS
29
+ </div>
30
+ </mock:shadow-root>
31
+ </zero-account>
32
+ `);
33
+ });
34
+ });
35
+ //# sourceMappingURL=zero-account.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zero-account.spec.js","sourceRoot":"","sources":["../../../src/components/zero-account/zero-account.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;EAC5B,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;IACvB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,WAAW,CAAC;MACjC,UAAU,EAAE,CAAC,WAAW,CAAC;MACzB,IAAI,EAAE,+BAA+B;KACtC,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC;;;;;;;;KAQxB,CAAC,CAAC;EACL,CAAC,CAAC,CAAC;EAEH,EAAE,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;IACnC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,WAAW,CAAC;MACjC,UAAU,EAAE,CAAC,WAAW,CAAC;MACzB,IAAI,EAAE,qFAAqF;KAC5F,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC;;;;;;;;KAQxB,CAAC,CAAC;EACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { newSpecPage } from '@stencil/core/testing';\nimport { ZeroAccount } from './zero-account';\n\ndescribe('zero-account', () => {\n it('renders', async () => {\n const { root } = await newSpecPage({\n components: [ZeroAccount],\n html: '<zero-account></zero-account>',\n });\n expect(root).toEqualHtml(`\n <zero-account>\n <mock:shadow-root>\n <div>\n Hello, World! I'm\n </div>\n </mock:shadow-root>\n </zero-account>\n `);\n });\n\n it('renders with values', async () => {\n const { root } = await newSpecPage({\n components: [ZeroAccount],\n html: `<zero-account first=\"Stencil\" last=\"'Don't call me a framework' JS\"></zero-account>`,\n });\n expect(root).toEqualHtml(`\n <zero-account first=\"Stencil\" last=\"'Don't call me a framework' JS\">\n <mock:shadow-root>\n <div>\n Hello, World! I'm Stencil 'Don't call me a framework' JS\n </div>\n </mock:shadow-root>\n </zero-account>\n `);\n });\n});\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './components';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC","sourcesContent":["export * from './components';\n"]}