@esportsplus/ui 0.62.0 → 0.63.0

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.
@@ -1,603 +0,0 @@
1
- import * as reactivity_u0 from '@esportsplus/reactivity';
2
- import { computed, effect, onCleanup, read } from '@esportsplus/reactivity';
3
- import * as template_u1 from '@esportsplus/template';
4
- import { component } from '@esportsplus/template';
5
- import amex from '@esportsplus/ui/svg/amex.svg';
6
- import card from '@esportsplus/ui/svg/card.svg';
7
- import checkSvg from '@esportsplus/ui/svg/check.svg';
8
- import chip from '@esportsplus/ui/svg/chip.svg';
9
- import discover from '@esportsplus/ui/svg/discover.svg';
10
- import lock from '@esportsplus/ui/svg/lock.svg';
11
- import mastercard from '@esportsplus/ui/svg/mastercard.svg';
12
- import visa from '@esportsplus/ui/svg/visa.svg';
13
- import faces from '../button/faces.js';
14
- import icon from '../icon/index.js';
15
- import input from '../input/index.js';
16
- import '../button/scss/index.scss';
17
- import './scss/index.scss';
18
- const template_02im3v18 = template_u1.template(`<div class='cc-shell cc-shell--cvc'><div class='cc-shell-header'><label class='cc-label'>`, true);
19
- const template_02im3v1c = template_u1.template(`<span class='cc-error'>`, true);
20
- const template_02im3v1e = template_u1.template(`<div class='cc-shell cc-shell--expiry'><div class='cc-shell-header'><label class='cc-label'>`, true);
21
- const template_02im3v1j = template_u1.template(`<div class='cc-shell cc-shell--name'><div class='cc-shell-header'><label class='cc-label'>`, true);
22
- const template_02im3v1o = template_u1.template(`<div class='cc-shell cc-shell--number'><div class='cc-shell-header'><label class='cc-label'>`, true);
23
- const template_02im3v1t = template_u1.template(`<div><div class='cc-shell-header'><label class='cc-label'>`, true);
24
- const template_02im3v1y = template_u1.template(`<span aria-hidden='true' class='cc-brand cc-brand--large'>`, true);
25
- const template_02im3v110 = template_u1.template(`<span>`, true);
26
- const template_02im3v112 = template_u1.template(`<span aria-hidden='true' class='cc-brand cc-brand--small'>`, true);
27
- const template_02im3v115 = template_u1.template(`<span aria-hidden='true'>`, true);
28
- const template_02im3v118 = template_u1.template(`<form aria-label='Card details' novalidate><div aria-hidden='true' class='cc-preview'><div><div class='cc-face cc-face--front'><span></span><div class='cc-face-top'><!--$--></div><div></div><div class='cc-face-bottom'><div><span class='cc-caption'>Card holder</span><span class='cc-holder-value'></span></div><div><span class='cc-caption'>Expires</span><span class='cc-expires-value'></span></div></div></div><div class='cc-face cc-face--back'><div class='cc-stripe'></div><div class='cc-signature'><div class='cc-signature-value'></div><span class='cc-caption'>CVC</span></div><p class='cc-disclaimer'>Not a real card. Nothing you type leaves this page.</p></div></div></div><div class='cc-fields'><!--$--><div class='cc-row'><!--$--></div></div><div class='cc-actions'><button type='submit'></button><!--$--><span aria-live='polite' class='button-status' role='status'></span><span aria-live='polite' class='cc-live'>`, true);
29
- const template_02im3v11w = template_u1.template(`<div class='cc-control'><!--$--><span>`, true);
30
- const template_02im3v120 = template_u1.template(`<!--$-->Details look valid`);
31
- const template_02im3v123 = template_u1.template(`<p class='cc-note'><!--$-->`, true);
32
- class ReactiveObject_02im3v10 extends reactivity_u0.ReactiveObject {
33
- #cvc = this[reactivity_u0.SIGNAL]('');
34
- #expiry = this[reactivity_u0.SIGNAL]('');
35
- #name = this[reactivity_u0.SIGNAL]('');
36
- #number = this[reactivity_u0.SIGNAL]('');
37
- constructor() {
38
- super(null);
39
- }
40
- get cvc() {
41
- return reactivity_u0.read(this.#cvc);
42
- }
43
- set cvc(_v0) {
44
- reactivity_u0.write(this.#cvc, _v0);
45
- }
46
- get expiry() {
47
- return reactivity_u0.read(this.#expiry);
48
- }
49
- set expiry(_v1) {
50
- reactivity_u0.write(this.#expiry, _v1);
51
- }
52
- get name() {
53
- return reactivity_u0.read(this.#name);
54
- }
55
- set name(_v2) {
56
- reactivity_u0.write(this.#name, _v2);
57
- }
58
- get number() {
59
- return reactivity_u0.read(this.#number);
60
- }
61
- set number(_v3) {
62
- reactivity_u0.write(this.#number, _v3);
63
- }
64
- }
65
- class ReactiveObject_02im3v11 extends reactivity_u0.ReactiveObject {
66
- #active = this[reactivity_u0.SIGNAL](false);
67
- #error = this[reactivity_u0.SIGNAL]('');
68
- constructor() {
69
- super(null);
70
- }
71
- get active() {
72
- return reactivity_u0.read(this.#active);
73
- }
74
- set active(_v0) {
75
- reactivity_u0.write(this.#active, _v0);
76
- }
77
- get error() {
78
- return reactivity_u0.read(this.#error);
79
- }
80
- set error(_v1) {
81
- reactivity_u0.write(this.#error, _v1);
82
- }
83
- }
84
- class ReactiveObject_02im3v12 extends reactivity_u0.ReactiveObject {
85
- #active = this[reactivity_u0.SIGNAL](false);
86
- #error = this[reactivity_u0.SIGNAL]('');
87
- constructor() {
88
- super(null);
89
- }
90
- get active() {
91
- return reactivity_u0.read(this.#active);
92
- }
93
- set active(_v0) {
94
- reactivity_u0.write(this.#active, _v0);
95
- }
96
- get error() {
97
- return reactivity_u0.read(this.#error);
98
- }
99
- set error(_v1) {
100
- reactivity_u0.write(this.#error, _v1);
101
- }
102
- }
103
- class ReactiveObject_02im3v13 extends reactivity_u0.ReactiveObject {
104
- #active = this[reactivity_u0.SIGNAL](false);
105
- #error = this[reactivity_u0.SIGNAL]('');
106
- constructor() {
107
- super(null);
108
- }
109
- get active() {
110
- return reactivity_u0.read(this.#active);
111
- }
112
- set active(_v0) {
113
- reactivity_u0.write(this.#active, _v0);
114
- }
115
- get error() {
116
- return reactivity_u0.read(this.#error);
117
- }
118
- set error(_v1) {
119
- reactivity_u0.write(this.#error, _v1);
120
- }
121
- }
122
- class ReactiveObject_02im3v14 extends reactivity_u0.ReactiveObject {
123
- #active = this[reactivity_u0.SIGNAL](false);
124
- #error = this[reactivity_u0.SIGNAL]('');
125
- constructor() {
126
- super(null);
127
- }
128
- get active() {
129
- return reactivity_u0.read(this.#active);
130
- }
131
- set active(_v0) {
132
- reactivity_u0.write(this.#active, _v0);
133
- }
134
- get error() {
135
- return reactivity_u0.read(this.#error);
136
- }
137
- set error(_v1) {
138
- reactivity_u0.write(this.#error, _v1);
139
- }
140
- }
141
- class ReactiveObject_02im3v15 extends reactivity_u0.ReactiveObject {
142
- #confirmed = this[reactivity_u0.SIGNAL](false);
143
- #ring = this[reactivity_u0.SIGNAL](false);
144
- constructor() {
145
- super(null);
146
- }
147
- get confirmed() {
148
- return reactivity_u0.read(this.#confirmed);
149
- }
150
- set confirmed(_v0) {
151
- reactivity_u0.write(this.#confirmed, _v0);
152
- }
153
- get ring() {
154
- return reactivity_u0.read(this.#ring);
155
- }
156
- set ring(_v1) {
157
- reactivity_u0.write(this.#ring, _v1);
158
- }
159
- }
160
- class ReactiveObject_02im3v16 extends reactivity_u0.ReactiveObject {
161
- #height;
162
- #left;
163
- #top;
164
- #width;
165
- constructor(_p0, _p1, _p2, _p3) {
166
- super(null);
167
- this.#height = this[reactivity_u0.SIGNAL](_p0);
168
- this.#left = this[reactivity_u0.SIGNAL](_p1);
169
- this.#top = this[reactivity_u0.SIGNAL](_p2);
170
- this.#width = this[reactivity_u0.SIGNAL](_p3);
171
- }
172
- get height() {
173
- return reactivity_u0.read(this.#height);
174
- }
175
- set height(_v0) {
176
- reactivity_u0.write(this.#height, _v0);
177
- }
178
- get left() {
179
- return reactivity_u0.read(this.#left);
180
- }
181
- set left(_v1) {
182
- reactivity_u0.write(this.#left, _v1);
183
- }
184
- get top() {
185
- return reactivity_u0.read(this.#top);
186
- }
187
- set top(_v2) {
188
- reactivity_u0.write(this.#top, _v2);
189
- }
190
- get width() {
191
- return reactivity_u0.read(this.#width);
192
- }
193
- set width(_v3) {
194
- reactivity_u0.write(this.#width, _v3);
195
- }
196
- }
197
- const BRANDS = {
198
- amex: { cvc: 4, gaps: [4, 10], icon: amex, lengths: [15], name: 'American Express', test: /^3[47]/ },
199
- discover: { cvc: 3, gaps: [4, 8, 12, 16], icon: discover, lengths: [16, 19], name: 'Discover', test: /^(6011|65|64[4-9])/ },
200
- mastercard: { cvc: 3, gaps: [4, 8, 12], icon: mastercard, lengths: [16], name: 'Mastercard', test: /^(5[1-5]|2[2-7])/ },
201
- unknown: { cvc: 3, gaps: [4, 8, 12, 16], icon: card, lengths: [16, 12, 13, 14, 15], name: 'Card', test: /^/ },
202
- visa: { cvc: 3, gaps: [4, 8, 12, 16], icon: visa, lengths: [16, 13, 19], name: 'Visa', test: /^4/ }
203
- };
204
- const CC_FIELD = Symbol.for('@esportsplus/ui/cc.field');
205
- const CC_SUBMIT = Symbol.for('@esportsplus/ui/cc.submit');
206
- const CONFIRM_FOR = 2000;
207
- const DIGIT = /\d/;
208
- const FIELDS = ['number', 'expiry', 'cvc', 'name'];
209
- const INVALID_MONTH_START = /^[2-9]/;
210
- const NON_DIGIT = /\D/;
211
- const NON_DIGITS = /\D/g;
212
- const ORDER = ['visa', 'mastercard', 'amex', 'discover'];
213
- let uid = 0;
214
- function caret(value, count) {
215
- if (count <= 0) {
216
- return 0;
217
- }
218
- let seen = 0;
219
- for (let i = 0, n = value.length; i < n; i++) {
220
- if (DIGIT.test(value[i]) && ++seen === count) {
221
- return i + 1;
222
- }
223
- }
224
- return value.length;
225
- }
226
- function detect(value) {
227
- let digits = digitsOf(value);
228
- return ORDER.find((brand) => BRANDS[brand].test.test(digits)) ?? 'unknown';
229
- }
230
- function digitsOf(value) {
231
- return value.replace(NON_DIGITS, '');
232
- }
233
- function expiry(digits) {
234
- return digits.length > 2 ? `${digits.slice(0, 2)}/${digits.slice(2)}` : digits;
235
- }
236
- function group(digits, gaps) {
237
- let out = '';
238
- for (let i = 0, n = digits.length; i < n; i++) {
239
- if (gaps.includes(i)) {
240
- out += ' ';
241
- }
242
- out += digits[i];
243
- }
244
- return out;
245
- }
246
- function luhn(digits) {
247
- let sum = 0;
248
- for (let i = 0, n = digits.length; i < n; i++) {
249
- let d = Number(digits[n - 1 - i]);
250
- if (i % 2) {
251
- d *= 2;
252
- if (d > 9) {
253
- d -= 9;
254
- }
255
- }
256
- sum += d;
257
- }
258
- return sum % 10 === 0;
259
- }
260
- function mark(brand, size) {
261
- return (size === "large" ? (() => {
262
- let root_02im3v1x = template_02im3v1y();
263
- template_u1.slot(root_02im3v1x, Object.keys(BRANDS).map((b) => {
264
- let root_02im3v1z = template_02im3v110();
265
- template_u1.slot(root_02im3v1z, icon({ class: 'cc-brand-icon' }, BRANDS[b].icon), 1);
266
- template_u1.setClass(root_02im3v1z, ["cc-brand-mark", () => brand() === b && '--active']);
267
- return root_02im3v1z;
268
- }), 1);
269
- return root_02im3v1x;
270
- })() : size === "small" ? (() => {
271
- let root_02im3v111 = template_02im3v112();
272
- template_u1.slot(root_02im3v111, Object.keys(BRANDS).map((b) => {
273
- let root_02im3v113 = template_02im3v110();
274
- template_u1.slot(root_02im3v113, icon({ class: 'cc-brand-icon' }, BRANDS[b].icon), 1);
275
- template_u1.setClass(root_02im3v113, ["cc-brand-mark", () => brand() === b && '--active']);
276
- return root_02im3v113;
277
- }), 1);
278
- return root_02im3v111;
279
- })() : (() => {
280
- let root_02im3v114 = template_02im3v115();
281
- template_u1.slot(root_02im3v114, Object.keys(BRANDS).map((b) => {
282
- let root_02im3v116 = template_02im3v110();
283
- template_u1.slot(root_02im3v116, icon({ class: 'cc-brand-icon' }, BRANDS[b].icon), 1);
284
- template_u1.setClass(root_02im3v116, ["cc-brand-mark", () => brand() === b && '--active']);
285
- return root_02im3v116;
286
- }), 1);
287
- template_u1.setClass(root_02im3v114, ["cc-brand", "cc-brand--" + (size)]);
288
- return root_02im3v114;
289
- })());
290
- }
291
- function reformat(element, max, format, pad) {
292
- let at = element.selectionStart ?? element.value.length, before = digitsOf(element.value.slice(0, at)).length, digits = digitsOf(element.value).slice(0, max);
293
- if (pad) {
294
- let padded = pad(digits);
295
- before += padded.length - digits.length;
296
- digits = padded;
297
- }
298
- let value = format(digits);
299
- element.value = value;
300
- if (document.activeElement === element) {
301
- let position = caret(value, Math.min(before, digits.length));
302
- element.setSelectionRange(position, position);
303
- }
304
- return value;
305
- }
306
- function skip(e) {
307
- let element = e.currentTarget, at = element.selectionStart;
308
- if (at === null || at !== element.selectionEnd) {
309
- return;
310
- }
311
- if (e.key === 'Backspace' && at > 0 && NON_DIGIT.test(element.value[at - 1])) {
312
- element.setSelectionRange(at - 1, at - 1);
313
- }
314
- if (e.key === 'Delete' && at < element.value.length && NON_DIGIT.test(element.value[at])) {
315
- element.setSelectionRange(at + 1, at + 1);
316
- }
317
- }
318
- function validate(field, values, final) {
319
- let spec = BRANDS[detect(values.number)], value = values[field], digits = digitsOf(value);
320
- if (!value.trim()) {
321
- return final ? 'Required' : '';
322
- }
323
- if (field === 'number') {
324
- if (!spec.lengths.includes(digits.length)) {
325
- return 'Too short';
326
- }
327
- if (!luhn(digits)) {
328
- return 'Not a valid number';
329
- }
330
- }
331
- if (field === 'expiry') {
332
- if (digits.length < 4) {
333
- return 'Use MM/YY';
334
- }
335
- let month = Number(digits.slice(0, 2)), now = new Date(), year = 2000 + Number(digits.slice(2));
336
- if (month < 1 || month > 12) {
337
- return 'Invalid month';
338
- }
339
- if (year < now.getFullYear() || (year === now.getFullYear() && month < now.getMonth() + 1)) {
340
- return 'Card expired';
341
- }
342
- }
343
- if (field === 'cvc' && digits.length < spec.cvc) {
344
- return 'Too short';
345
- }
346
- return '';
347
- }
348
- export default component(function ({ note = '', onvalid, state = new ReactiveObject_02im3v10(), submit = 'Check details', ...attributes }) {
349
- let detected = computed(() => detect(state.number)), fields = {
350
- cvc: new ReactiveObject_02im3v11(),
351
- expiry: new ReactiveObject_02im3v12(),
352
- name: new ReactiveObject_02im3v13(),
353
- number: new ReactiveObject_02im3v14()
354
- }, id = `cc-${++uid}`, local = new ReactiveObject_02im3v15(), outline = new ReactiveObject_02im3v16(undefined, undefined, undefined, undefined), parts = { ...this?.attributes?.[CC_FIELD], ...attributes[CC_FIELD] }, regions = {}, slots = new reactivity_u0.ReactiveArray(), timer;
355
- let errors = Object.fromEntries(FIELDS.map((field) => [field, computed(() => !!fields[field].error)]));
356
- function brand() {
357
- return read(detected);
358
- }
359
- function check(e) {
360
- e.preventDefault();
361
- let bad;
362
- for (let i = 0, n = FIELDS.length; i < n; i++) {
363
- let error = validate(FIELDS[i], state, true);
364
- fields[FIELDS[i]].error = error;
365
- if (error && !bad) {
366
- bad = FIELDS[i];
367
- }
368
- }
369
- if (bad) {
370
- e.currentTarget.elements.namedItem(bad).focus();
371
- return;
372
- }
373
- local.confirmed = true;
374
- onvalid?.({ brand: brand(), expiry: state.expiry, last4: digitsOf(state.number).slice(-4), name: state.name.trim() });
375
- clearTimeout(timer);
376
- timer = setTimeout(() => {
377
- local.confirmed = false;
378
- }, CONFIRM_FOR);
379
- }
380
- function control(field, own) {
381
- return input.call({ attributes: parts }, {
382
- ...own,
383
- 'aria-describedby': () => fields[field].error && `${id}-${field}-error`,
384
- 'aria-invalid': () => fields[field].error ? 'true' : 'false',
385
- class: `cc-field cc-field--${field}`,
386
- id: `${id}-${field}`,
387
- name: field,
388
- onblur: () => {
389
- fields[field].error = validate(field, state, false);
390
- },
391
- state: fields[field],
392
- value: () => state[field]
393
- });
394
- }
395
- function focused() {
396
- return FIELDS.find((field) => fields[field].active) ?? '';
397
- }
398
- function frame(field) {
399
- let region = field && field !== 'cvc' ? regions[field] : undefined;
400
- if (!region) {
401
- local.ring = false;
402
- return;
403
- }
404
- outline.height = `${region.offsetHeight + 12}px`;
405
- outline.left = `${region.offsetLeft - 8}px`;
406
- outline.top = `${region.offsetTop - 6}px`;
407
- outline.width = `${region.offsetWidth + 16}px`;
408
- local.ring = true;
409
- }
410
- function set(field, value) {
411
- state[field] = value;
412
- fields[field].error = '';
413
- local.confirmed = false;
414
- }
415
- function shell(field, label, content) {
416
- return (field === "cvc" ? (() => {
417
- let root_02im3v17 = template_02im3v18(), element_02im3v19 = root_02im3v17.firstElementChild.firstElementChild, element_02im3v1a = root_02im3v17.firstElementChild;
418
- template_u1.slot(element_02im3v19, label, 1);
419
- new template_u1.EffectSlot(element_02im3v1a, () => read(errors[field]) && (() => {
420
- let root_02im3v1b = template_02im3v1c();
421
- new template_u1.EffectSlot(root_02im3v1b, () => fields[field].error, 1);
422
- template_u1.setProperty(root_02im3v1b, 'id', "" + (id) + "-" + (field) + "-error");
423
- return root_02im3v1b;
424
- })(), 1);
425
- template_u1.slot(root_02im3v17, content, 1);
426
- template_u1.setProperty(element_02im3v19, 'for', "" + (id) + "-cvc");
427
- return root_02im3v17;
428
- })() : field === "expiry" ? (() => {
429
- let root_02im3v1d = template_02im3v1e(), element_02im3v1f = root_02im3v1d.firstElementChild.firstElementChild, element_02im3v1g = root_02im3v1d.firstElementChild;
430
- template_u1.slot(element_02im3v1f, label, 1);
431
- new template_u1.EffectSlot(element_02im3v1g, () => read(errors[field]) && (() => {
432
- let root_02im3v1h = template_02im3v1c();
433
- new template_u1.EffectSlot(root_02im3v1h, () => fields[field].error, 1);
434
- template_u1.setProperty(root_02im3v1h, 'id', "" + (id) + "-" + (field) + "-error");
435
- return root_02im3v1h;
436
- })(), 1);
437
- template_u1.slot(root_02im3v1d, content, 1);
438
- template_u1.setProperty(element_02im3v1f, 'for', "" + (id) + "-expiry");
439
- return root_02im3v1d;
440
- })() : field === "name" ? (() => {
441
- let root_02im3v1i = template_02im3v1j(), element_02im3v1k = root_02im3v1i.firstElementChild.firstElementChild, element_02im3v1l = root_02im3v1i.firstElementChild;
442
- template_u1.slot(element_02im3v1k, label, 1);
443
- new template_u1.EffectSlot(element_02im3v1l, () => read(errors[field]) && (() => {
444
- let root_02im3v1m = template_02im3v1c();
445
- new template_u1.EffectSlot(root_02im3v1m, () => fields[field].error, 1);
446
- template_u1.setProperty(root_02im3v1m, 'id', "" + (id) + "-" + (field) + "-error");
447
- return root_02im3v1m;
448
- })(), 1);
449
- template_u1.slot(root_02im3v1i, content, 1);
450
- template_u1.setProperty(element_02im3v1k, 'for', "" + (id) + "-name");
451
- return root_02im3v1i;
452
- })() : field === "number" ? (() => {
453
- let root_02im3v1n = template_02im3v1o(), element_02im3v1p = root_02im3v1n.firstElementChild.firstElementChild, element_02im3v1q = root_02im3v1n.firstElementChild;
454
- template_u1.slot(element_02im3v1p, label, 1);
455
- new template_u1.EffectSlot(element_02im3v1q, () => read(errors[field]) && (() => {
456
- let root_02im3v1r = template_02im3v1c();
457
- new template_u1.EffectSlot(root_02im3v1r, () => fields[field].error, 1);
458
- template_u1.setProperty(root_02im3v1r, 'id', "" + (id) + "-" + (field) + "-error");
459
- return root_02im3v1r;
460
- })(), 1);
461
- template_u1.slot(root_02im3v1n, content, 1);
462
- template_u1.setProperty(element_02im3v1p, 'for', "" + (id) + "-number");
463
- return root_02im3v1n;
464
- })() : (() => {
465
- let root_02im3v1s = template_02im3v1t(), element_02im3v1u = root_02im3v1s.firstElementChild.firstElementChild, element_02im3v1v = root_02im3v1s.firstElementChild;
466
- template_u1.slot(element_02im3v1u, label, 1);
467
- new template_u1.EffectSlot(element_02im3v1v, () => read(errors[field]) && (() => {
468
- let root_02im3v1w = template_02im3v1c();
469
- new template_u1.EffectSlot(root_02im3v1w, () => fields[field].error, 1);
470
- template_u1.setProperty(root_02im3v1w, 'id', "" + (id) + "-" + (field) + "-error");
471
- return root_02im3v1w;
472
- })(), 1);
473
- template_u1.slot(root_02im3v1s, content, 1);
474
- template_u1.setProperty(element_02im3v1u, 'for', "" + (id) + "-" + (field));
475
- template_u1.setClass(root_02im3v1s, ["cc-shell", "cc-shell--" + (field)]);
476
- return root_02im3v1s;
477
- })());
478
- }
479
- effect(() => digitsOf(state.number), (digits) => {
480
- let initial = slots.$length === 0, spec = BRANDS[detect(digits)], length = Math.max(spec.lengths[0], digits.length);
481
- for (let i = 0; i < length; i++) {
482
- let char = digits[i] ?? '•', gap = spec.gaps.includes(i), slot = slots[i];
483
- if (!slot) {
484
- slots.push(reactivity_u0.reactive({ char, gap, roll: initial ? 0 : 1 }));
485
- continue;
486
- }
487
- slot.gap = gap;
488
- if (slot.char !== char) {
489
- slot.char = char;
490
- slot.roll = slot.roll === 1 ? 2 : 1;
491
- }
492
- }
493
- if (slots.$length > length) {
494
- slots.splice(length);
495
- }
496
- });
497
- effect(focused, frame);
498
- onCleanup(() => clearTimeout(timer));
499
- {
500
- let root_02im3v117 = template_02im3v118(), element_02im3v119 = root_02im3v117.firstElementChild, element_02im3v11a = element_02im3v119.firstElementChild, element_02im3v11b = element_02im3v11a.firstElementChild, element_02im3v11c = element_02im3v11b.firstElementChild, element_02im3v11d = element_02im3v11c.nextElementSibling, element_02im3v11e = element_02im3v11d.firstChild, element_02im3v11f = element_02im3v11d.nextElementSibling, element_02im3v11g = element_02im3v11f.nextElementSibling.firstElementChild, element_02im3v11h = element_02im3v11g.firstElementChild.nextElementSibling, element_02im3v11i = element_02im3v11g.nextElementSibling, element_02im3v11j = element_02im3v11i.firstElementChild.nextElementSibling, element_02im3v11k = element_02im3v11b.nextElementSibling.firstElementChild.nextElementSibling.firstElementChild, element_02im3v11l = element_02im3v119.nextElementSibling, element_02im3v11m = element_02im3v11l.firstChild, element_02im3v11n = element_02im3v11l.firstElementChild.firstChild, element_02im3v11o = element_02im3v11l.firstElementChild, element_02im3v11p = element_02im3v11l.nextElementSibling, element_02im3v11q = element_02im3v11p.firstElementChild, element_02im3v11r = element_02im3v11p.firstChild.nextSibling, element_02im3v11s = element_02im3v11q.nextElementSibling, element_02im3v11t = element_02im3v11s.nextElementSibling;
501
- template_u1.slot(element_02im3v11e, icon({ class: 'cc-chip' }, chip));
502
- template_u1.slot(element_02im3v11d, mark(brand, 'large'), 1);
503
- element_02im3v11f.appendChild(new template_u1.ArraySlot(slots, (slot) => {
504
- let root_02im3v11u = template_02im3v110();
505
- new template_u1.EffectSlot(root_02im3v11u, () => slot.char, 1);
506
- template_u1.setClass(root_02im3v11u, ["cc-digit", () => slot.gap && 'cc-digit--gap', () => slot.char === '•' && 'cc-digit--placeholder', () => slot.roll && `cc-digit--roll-${slot.roll}`]);
507
- return root_02im3v11u;
508
- }, true).fragment);
509
- new template_u1.EffectSlot(element_02im3v11h, () => state.name.trim() || 'Your name', 1);
510
- new template_u1.EffectSlot(element_02im3v11j, () => state.expiry || 'MM/YY', 1);
511
- new template_u1.EffectSlot(element_02im3v11k, () => state.cvc || (brand() === 'amex' ? '••••' : '•••'), 1);
512
- template_u1.slot(element_02im3v11m, shell('number', 'Card number', (() => {
513
- let root_02im3v11v = template_02im3v11w(), element_02im3v11x = root_02im3v11v.firstChild, element_02im3v11y = root_02im3v11v.firstElementChild;
514
- template_u1.slot(element_02im3v11x, control('number', {
515
- autocomplete: 'cc-number',
516
- inputmode: 'numeric',
517
- oninput: (e) => {
518
- let element = e.currentTarget, spec = BRANDS[detect(element.value)];
519
- set('number', reformat(element, Math.max(...spec.lengths), (d) => group(d, spec.gaps)));
520
- if (state.cvc.length > spec.cvc) {
521
- state.cvc = state.cvc.slice(0, spec.cvc);
522
- }
523
- },
524
- onkeydown: skip,
525
- placeholder: '1234 5678 9012 3456'
526
- }));
527
- template_u1.slot(element_02im3v11y, mark(brand, 'small'), 1);
528
- template_u1.setClass(element_02im3v11y, ["cc-control-brand", () => brand() !== 'unknown' && 'cc-control-brand--known']);
529
- return root_02im3v11v;
530
- })()));
531
- template_u1.slot(element_02im3v11n, shell('expiry', 'Expiry', control('expiry', {
532
- autocomplete: 'cc-exp',
533
- inputmode: 'numeric',
534
- oninput: (e) => {
535
- set('expiry', reformat(e.currentTarget, 4, expiry, (d) => INVALID_MONTH_START.test(d) ? `0${d}`.slice(0, 4) : d));
536
- },
537
- onkeydown: skip,
538
- placeholder: 'MM/YY'
539
- })));
540
- template_u1.slot(element_02im3v11o, shell('cvc', 'CVC', control('cvc', {
541
- autocomplete: 'cc-csc',
542
- inputmode: 'numeric',
543
- oninput: (e) => {
544
- set('cvc', reformat(e.currentTarget, BRANDS[brand()].cvc, (d) => d));
545
- },
546
- placeholder: () => brand() === 'amex' ? '1234' : '123'
547
- })), 1);
548
- template_u1.slot(element_02im3v11l, shell('name', 'Name on card', control('name', {
549
- autocapitalize: 'words',
550
- autocomplete: 'cc-name',
551
- maxlength: 40,
552
- oninput: (e) => {
553
- set('name', e.currentTarget.value);
554
- },
555
- placeholder: 'Ada Lovelace',
556
- spellcheck: false
557
- })), 1);
558
- template_u1.slot(element_02im3v11q, faces(() => local.confirmed ? 'valid' : 'idle', [
559
- { content: submit, key: 'idle' },
560
- { content: (() => {
561
- let root_02im3v11z = template_02im3v120(), element_02im3v121 = root_02im3v11z.firstChild;
562
- template_u1.slot(element_02im3v121, icon({ 'aria-hidden': 'true', class: 'button-icon button-icon--draw' }, checkSvg));
563
- return root_02im3v11z;
564
- })(), key: 'valid' }
565
- ]), 1);
566
- template_u1.slot(element_02im3v11r, !!note && (() => {
567
- let root_02im3v122 = template_02im3v123(), element_02im3v124 = root_02im3v122.firstChild;
568
- template_u1.slot(element_02im3v124, icon({ 'aria-hidden': 'true', class: 'cc-note-icon' }, lock));
569
- template_u1.slot(root_02im3v122, note, 1);
570
- return root_02im3v122;
571
- })());
572
- new template_u1.EffectSlot(element_02im3v11s, () => local.confirmed && 'Card details look valid', 1);
573
- new template_u1.EffectSlot(element_02im3v11t, () => brand() !== 'unknown' && `${BRANDS[brand()].name} card`, 1);
574
- let attributes_02im3v125 = this?.attributes?.[CC_SUBMIT];
575
- template_u1.setProperties(element_02im3v11q, attributes_02im3v125, true);
576
- let attributes_02im3v126 = attributes[CC_SUBMIT];
577
- template_u1.setProperties(element_02im3v11q, attributes_02im3v126, true);
578
- template_u1.setClass(element_02im3v11q, ["button button--feedback cc-submit", attributes_02im3v125?.class, attributes_02im3v126?.class]);
579
- template_u1.setStyle(element_02im3v11q, ["", attributes_02im3v125?.style, attributes_02im3v126?.style]);
580
- template_u1.onconnect(element_02im3v11i, (element) => { regions.expiry = element; });
581
- template_u1.setClass(element_02im3v11i, ["cc-expires"]);
582
- template_u1.onconnect(element_02im3v11g, (element) => { regions.name = element; });
583
- template_u1.setClass(element_02im3v11g, ["cc-holder"]);
584
- template_u1.onconnect(element_02im3v11f, (element) => { regions.number = element; });
585
- template_u1.setClass(element_02im3v11f, ["cc-number"]);
586
- template_u1.setClass(element_02im3v11c, ["cc-ring", () => local.ring && '--active']);
587
- template_u1.setStyle(element_02im3v11c, ["", () => ({
588
- height: outline.height,
589
- left: outline.left,
590
- top: outline.top,
591
- width: outline.width
592
- })]);
593
- template_u1.setClass(element_02im3v11a, ["cc-card", () => focused() === 'cvc' && 'cc-card--flipped']);
594
- let attributes_02im3v127 = this?.attributes;
595
- template_u1.setProperties(root_02im3v117, attributes_02im3v127, true);
596
- let attributes_02im3v128 = attributes;
597
- template_u1.setProperties(root_02im3v117, attributes_02im3v128, true);
598
- template_u1.direct(root_02im3v117, 'submit', check);
599
- template_u1.setClass(root_02im3v117, ["cc", attributes_02im3v127?.class, attributes_02im3v128?.class]);
600
- template_u1.setStyle(root_02im3v117, ["", attributes_02im3v127?.style, attributes_02im3v128?.style]);
601
- return root_02im3v117;
602
- }
603
- }, { field: CC_FIELD, submit: CC_SUBMIT });