@vialiq/web-components 0.1.2 → 0.2.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.
@@ -0,0 +1,937 @@
1
+ import { unsafeCSS, css, html } from 'lit';
2
+ import { customElement, property } from 'lit/decorators.js';
3
+ import { F as FocusableMixin } from '../focusable-mixin-CmxOyPX5.js';
4
+ import { V as ViElement } from '../vi-element-C6GfDPs3.js';
5
+ import { ifDefined } from 'lit/directives/if-defined.js';
6
+
7
+ /**
8
+ * ValidityMixin
9
+ *
10
+ * Adds the standard form validation API (`checkValidity`, `reportValidity`,
11
+ * `setCustomValidity`) to any form-associated Lit element.
12
+ *
13
+ * Backed by the native `ElementInternals` API so the component participates
14
+ * in `HTMLFormElement` constraint validation, `.elements`, and browser
15
+ * validation UI — exactly like a native `<input>`.
16
+ *
17
+ * ─────────────────────────────────────────────────────────────────────────
18
+ * MINIMUM SUBCLASS REQUIREMENTS
19
+ * ─────────────────────────────────────────────────────────────────────────
20
+ *
21
+ * 1. Declare static formAssociated = true;
22
+ * Makes the browser register this element as a form participant.
23
+ *
24
+ * 2. Attach ElementInternals:
25
+ * protected readonly _internals = this.attachInternals();
26
+ * Must be a field initializer (runs after super() in the constructor).
27
+ *
28
+ * 3. Declare reactive properties (MUST be @property so Lit tracks changes):
29
+ * @property({ reflect: true }) accessor status: ControlStatus = 'default';
30
+ * @property({ type: Boolean, reflect: true }) accessor required = false;
31
+ * @property() accessor validityMessage = '';
32
+ * @property() accessor value = '';
33
+ *
34
+ * 4. Sync value to internals on every value change:
35
+ * override updated(changed: PropertyValues): void {
36
+ * super.updated(changed);
37
+ * if (changed.has('value')) {
38
+ * this._internals.setFormValue(this.value);
39
+ * }
40
+ * }
41
+ *
42
+ * 5. Handle form reset:
43
+ * formResetCallback(): void {
44
+ * this.value = this.getAttribute('value') ?? '';
45
+ * this.status = 'default';
46
+ * this.validityMessage = '';
47
+ * }
48
+ *
49
+ * 6. Handle fieldset/form disable:
50
+ * formDisabledCallback(disabled: boolean): void {
51
+ * this.disabled = disabled;
52
+ * }
53
+ *
54
+ * ─────────────────────────────────────────────────────────────────────────
55
+ * OVERRIDE _testValidity() FOR CUSTOM CONSTRAINTS
56
+ * ─────────────────────────────────────────────────────────────────────────
57
+ *
58
+ * protected override _testValidity(): Partial<ValidityStateFlags> {
59
+ * if (this.required && !this.value) return { valueMissing: true };
60
+ * return {};
61
+ * }
62
+ *
63
+ * Chain constraints for components with multiple rules (e.g. vi-input[type="number"]):
64
+ *
65
+ * protected override _testValidity(): Partial<ValidityStateFlags> {
66
+ * if (this.required && !this.value) return { valueMissing: true };
67
+ * if (this.minlength && this.value.length < this.minlength)
68
+ * return { tooShort: true };
69
+ * if (this.maxlength && this.value.length > this.maxlength)
70
+ * return { tooLong: true };
71
+ * return {};
72
+ * }
73
+ *
74
+ * ─────────────────────────────────────────────────────────────────────────
75
+ * FULL USAGE EXAMPLE — vi-input
76
+ * ─────────────────────────────────────────────────────────────────────────
77
+ *
78
+ * import { property } from 'lit/decorators.js';
79
+ * import { ValidityMixin } from '../base/validity-mixin.js';
80
+ * import { FocusableMixin } from '../base/focusable-mixin.js';
81
+ * import { ViElement } from '../base/vi-element.js';
82
+ *
83
+ * @customElement('vi-input')
84
+ * export class ViInput extends ValidityMixin(FocusableMixin(ViElement)) {
85
+ * static override formAssociated = true;
86
+ * protected readonly _internals = this.attachInternals();
87
+ *
88
+ * @property({ reflect: true }) accessor status: ControlStatus = 'default';
89
+ * @property({ type: Boolean, reflect: true }) accessor required = false;
90
+ * @property() accessor validityMessage = '';
91
+ * @property() accessor value = '';
92
+ *
93
+ * protected override _testValidity(): Partial<ValidityStateFlags> {
94
+ * if (this.required && !this.value) return { valueMissing: true };
95
+ * return {};
96
+ * }
97
+ *
98
+ * override updated(changed: PropertyValues): void {
99
+ * super.updated(changed);
100
+ * if (changed.has('value')) this._internals.setFormValue(this.value);
101
+ * }
102
+ *
103
+ * formResetCallback(): void {
104
+ * this.value = this.getAttribute('value') ?? '';
105
+ * this.status = 'default';
106
+ * this.validityMessage = '';
107
+ * }
108
+ *
109
+ * formDisabledCallback(disabled: boolean): void {
110
+ * this.disabled = disabled;
111
+ * }
112
+ * }
113
+ *
114
+ * ─────────────────────────────────────────────────────────────────────────
115
+ * INVALID EVENT BEHAVIOUR
116
+ * ─────────────────────────────────────────────────────────────────────────
117
+ *
118
+ * checkValidity() fires a cancelable 'invalid' event when validation fails.
119
+ * The event does NOT bubble (matches native form element behaviour).
120
+ * Consumer can suppress the default UI by calling event.preventDefault().
121
+ *
122
+ * Example:
123
+ * myInput.addEventListener('invalid', (e) => {
124
+ * e.preventDefault(); // suppress browser tooltip
125
+ * showMyCustomError(myInput.validityMessage);
126
+ * });
127
+ *
128
+ * ─────────────────────────────────────────────────────────────────────────
129
+ * MIXIN COMPOSITION ORDER
130
+ * ─────────────────────────────────────────────────────────────────────────
131
+ *
132
+ * ValidityMixin should wrap FocusableMixin (outermost):
133
+ * ValidityMixin(FocusableMixin(ViElement))
134
+ *
135
+ * Reason: ValidityMixin only adds methods (checkValidity etc.). It does not
136
+ * touch shadowRootOptions or focus delegation, so order has no side-effects.
137
+ * Convention is: functionality mixins wrap infrastructure mixins.
138
+ */ function ValidityMixin(Base) {
139
+ class ValidityMixinClass extends Base {
140
+ /**
141
+ * Base implementation — always valid.
142
+ * Subclass overrides this to return flags like { valueMissing: true }.
143
+ */ _testValidity() {
144
+ return {};
145
+ }
146
+ checkValidity() {
147
+ const flags = this._testValidity();
148
+ const isValid = !Object.values(flags).some(Boolean);
149
+ // Sync to ElementInternals so native form API (formElement.checkValidity,
150
+ // :invalid CSS pseudo-class, browser tooltip) reflects the same state.
151
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
152
+ const internals = this._internals;
153
+ if (internals) {
154
+ if (isValid) {
155
+ internals.setValidity({}, '');
156
+ } else {
157
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
158
+ const msg = this.validityMessage || 'Invalid value';
159
+ internals.setValidity(flags, msg);
160
+ }
161
+ }
162
+ if (isValid) {
163
+ // Only clear status if it was previously set to 'invalid' by the constraint
164
+ // API. Do not override an explicit 'valid' set by the parent/framework.
165
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
166
+ if (this.status === 'invalid') {
167
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
+ this.status = 'default';
169
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
170
+ this.validityMessage = '';
171
+ }
172
+ } else {
173
+ // Fire cancelable 'invalid' — mirrors native form element behaviour.
174
+ // Cancelable so consumers can suppress browser tooltip and show their own.
175
+ // bubbles: false — matches native <input> 'invalid' event.
176
+ // composed: false — stays within the document, does not cross shadow boundaries.
177
+ const proceed = this.dispatchEvent(new Event('invalid', {
178
+ bubbles: false,
179
+ cancelable: true,
180
+ composed: false
181
+ }));
182
+ if (proceed) {
183
+ // Only set status='invalid' if the event was not cancelled.
184
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
185
+ this.status = 'invalid';
186
+ }
187
+ }
188
+ return isValid;
189
+ }
190
+ reportValidity() {
191
+ // Prefer ElementInternals.reportValidity() — it triggers native browser UI
192
+ // (tooltip near the field). Falls back to checkValidity() if internals not set.
193
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
194
+ const internals = this._internals;
195
+ if (internals) {
196
+ // Must sync validity state first so the browser has something to show.
197
+ this.checkValidity();
198
+ return internals.reportValidity();
199
+ }
200
+ return this.checkValidity();
201
+ }
202
+ setCustomValidity(message) {
203
+ const hasError = Boolean(message);
204
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
205
+ this.status = hasError ? 'invalid' : 'default';
206
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
207
+ this.validityMessage = message;
208
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
209
+ const internals = this._internals;
210
+ if (internals) {
211
+ internals.setValidity(hasError ? {
212
+ customError: true
213
+ } : {}, hasError ? message : '');
214
+ }
215
+ }
216
+ }
217
+ // Cast required: TypeScript cannot reconcile LitElement's private fields
218
+ // with the anonymous class return type. Same pattern as FocusableMixin.
219
+ return ValidityMixinClass;
220
+ }
221
+
222
+ /**
223
+ * ifNonEmpty — conditional attribute directive
224
+ *
225
+ * A wrapper around Lit's `ifDefined` that additionally removes the attribute
226
+ * when the value is an empty string. Use this for every optional string
227
+ * attribute on inner native elements where `""` and "absent" have different
228
+ * meaning for browsers and screen readers.
229
+ *
230
+ * Problem with raw `ifDefined`:
231
+ * - `ifDefined(undefined)` → removes the attribute ✅
232
+ * - `ifDefined(null)` → removes the attribute ✅
233
+ * - `ifDefined('')` → sets attribute to "" ❌
234
+ *
235
+ * With `ifNonEmpty`:
236
+ * - `ifNonEmpty(undefined)` → removes the attribute ✅
237
+ * - `ifNonEmpty(null)` → removes the attribute ✅
238
+ * - `ifNonEmpty('')` → removes the attribute ✅
239
+ * - `ifNonEmpty('hello')` → sets attribute to "hello" ✅
240
+ *
241
+ * Why it matters — real screen reader / browser bugs caused by `=""`:
242
+ * - `placeholder=""` → JAWS/NVDA still announce it as an empty placeholder
243
+ * - `aria-label=""` → NVDA reads "blank" instead of deriving the name elsewhere
244
+ * - `aria-describedby=""`→ browsers may still look for id="" element
245
+ * - `title=""` → browsers show an empty tooltip on hover in some engines
246
+ *
247
+ * ---
248
+ *
249
+ * USAGE
250
+ *
251
+ * Import in any shadow template that has optional string attributes:
252
+ *
253
+ * import { ifNonEmpty } from '../base/if-non-empty.js';
254
+ *
255
+ * In the template:
256
+ *
257
+ * // ✅ Use ifNonEmpty for optional string attributes on inner native elements
258
+ * <input
259
+ * placeholder=${ifNonEmpty(this.placeholder)}
260
+ * aria-label=${ifNonEmpty(this.label)}
261
+ * aria-describedby=${ifNonEmpty(this._descriptionId)}
262
+ * />
263
+ *
264
+ * // ❌ Do NOT use for boolean attributes — Lit has ?attr=${bool} for that
265
+ * // ❌ Do NOT use for property bindings — Lit has .prop=${val} for that
266
+ * // ❌ Do NOT use for event bindings — Lit has @event=${handler} for that
267
+ *
268
+ * ---
269
+ *
270
+ * WHEN TO USE vs NOT USE
271
+ *
272
+ * Use ifNonEmpty when:
273
+ * - The attribute is optional (component has a prop that defaults to '')
274
+ * - The inner native element is a standard HTML element (input, button, a, etc.)
275
+ * - The attribute has accessibility or UI meaning when absent vs present
276
+ *
277
+ * Skip ifNonEmpty when:
278
+ * - The attribute is always required (e.g. type="button" is never absent)
279
+ * - You need the attribute to literally be "" (rare, document when intentional)
280
+ * - The binding is to a custom element property — use .prop=${val} instead
281
+ */ const ifNonEmpty = (value)=>ifDefined(value === '' ? undefined : value ?? undefined);
282
+
283
+ const inputStyles = "@charset \"UTF-8\";@layer reset,components,utilities;@layer components{.input-field{display:flex;flex-direction:column;gap:var(--vi-input-spacing-field-gap, var(--vi-spacing-xs, 8px));width:100%}.input-control{appearance:none;-webkit-appearance:none;display:block;width:100%;box-sizing:border-box;min-height:var(--vi-input-sizing-min-height, 40px);border:var(--vi-border-width-thin, 1px) solid var(--vi-input-border-color, var(--vi-color-grey-300, #e0e0e0));border-radius:var(--vi-input-shape-border-radius, var(--vi-border-radius-lg, 8px));padding:var(--vi-input-spacing-padding-block, var(--vi-spacing-xs, 8px)) var(--vi-input-spacing-padding-inline, var(--vi-spacing-sm, 16px));font-family:var(--vi-font-family-base, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif);font-size:var(--vi-input-typography-font-size, var(--vi-font-size-base, 16px));font-weight:var(--vi-font-weight-normal, 400);line-height:var(--vi-input-typography-line-height, var(--vi-line-height-normal, 1.5));color:var(--vi-input-text-color, var(--vi-color-foreground, #111827));background-color:var(--vi-input-background-color, var(--vi-color-background, #ffffff));transition:border-color .15s ease,box-shadow .15s ease}.input-control:hover:not(:focus-visible){border-color:var(--vi-input-border-color-hover, var(--vi-color-grey-500, #9e9e9e))}.input-control:focus-visible,.input-control:focus{outline:var(--vi-border-width-base, 2px) solid var(--vi-input-focus-ring-color, var(--vi-color-primary, #3676d0));outline-offset:0;box-shadow:0 0 0 3px var(--vi-input-focus-ring-glow, var(--vi-color-blue-200, #cee6ff))}.input-control::placeholder{color:var(--vi-input-placeholder-color, var(--vi-color-grey-500, #9e9e9e))}.input-helper{font-size:var(--vi-input-helper-size, var(--vi-font-size-xs, 12px));line-height:var(--vi-input-helper-leading, var(--vi-line-height-normal, 1.5));color:var(--vi-input-helper-color, var(--vi-color-grey-500, #9e9e9e))}.input-error{font-size:var(--vi-input-error-size, var(--vi-font-size-xs, 12px));line-height:var(--vi-input-error-leading, var(--vi-line-height-normal, 1.5));color:var(--vi-input-error-color, var(--vi-color-error, #ef4444))}@media(prefers-reduced-motion:reduce){.input-control{transition:none}}}:host{display:block;outline:none}:host([disabled]){opacity:.6;cursor:not-allowed;pointer-events:none}:host([status=invalid]){--vi-input-border-color: var(--vi-color-error, #ef4444);--vi-input-border-color-hover: var(--vi-color-red-700, #db231b);--vi-input-focus-ring-color: var(--vi-color-error, #ef4444);--vi-input-focus-ring-glow: var(--vi-color-red-100, #ffccce);--vi-input-label-color: var(--vi-color-error, #ef4444)}:host([status=valid]){--vi-input-border-color: var(--vi-color-success, #489167);--vi-input-border-color-hover: var(--vi-color-green-700, #265a3d);--vi-input-focus-ring-color: var(--vi-color-success, #489167);--vi-input-focus-ring-glow: var(--vi-color-green-100, #e6f0eb)}.input-validation{font-family:var(--vi-font-family-base, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif);font-size:var(--vi-font-size-xs, 12px);line-height:var(--vi-line-height-normal, 1.5);letter-spacing:var(--vi-letter-spacing-wider, .05em);color:var(--vi-input-helper-color, var(--vi-color-grey-500, #9e9e9e))}.input-validation--invalid{color:var(--vi-input-error-color, var(--vi-color-error, #ef4444))}.input-validation--valid{color:var(--vi-input-success-color, var(--vi-color-success, #489167))}::slotted([slot=helper]){font-family:var(--vi-font-family-base, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif);font-size:var(--vi-font-size-xs, 12px);line-height:var(--vi-line-height-normal, 1.5);letter-spacing:var(--vi-letter-spacing-wider, .05em);color:var(--vi-input-helper-color, var(--vi-color-grey-500, #9e9e9e))}";
284
+
285
+ function applyDecs2203RFactory() {
286
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
287
+ return function addInitializer(initializer) {
288
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
289
+ assertCallable(initializer, "An initializer");
290
+ initializers.push(initializer);
291
+ };
292
+ }
293
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
294
+ var kindStr;
295
+ switch(kind){
296
+ case 1:
297
+ kindStr = "accessor";
298
+ break;
299
+ case 2:
300
+ kindStr = "method";
301
+ break;
302
+ case 3:
303
+ kindStr = "getter";
304
+ break;
305
+ case 4:
306
+ kindStr = "setter";
307
+ break;
308
+ default:
309
+ kindStr = "field";
310
+ }
311
+ var ctx = {
312
+ kind: kindStr,
313
+ name: isPrivate ? "#" + name : name,
314
+ static: isStatic,
315
+ private: isPrivate,
316
+ metadata: metadata
317
+ };
318
+ var decoratorFinishedRef = {
319
+ v: false
320
+ };
321
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
322
+ var get, set;
323
+ if (kind === 0) {
324
+ if (isPrivate) {
325
+ get = desc.get;
326
+ set = desc.set;
327
+ } else {
328
+ get = function() {
329
+ return this[name];
330
+ };
331
+ set = function(v) {
332
+ this[name] = v;
333
+ };
334
+ }
335
+ } else if (kind === 2) {
336
+ get = function() {
337
+ return desc.value;
338
+ };
339
+ } else {
340
+ if (kind === 1 || kind === 3) {
341
+ get = function() {
342
+ return desc.get.call(this);
343
+ };
344
+ }
345
+ if (kind === 1 || kind === 4) {
346
+ set = function(v) {
347
+ desc.set.call(this, v);
348
+ };
349
+ }
350
+ }
351
+ ctx.access = get && set ? {
352
+ get: get,
353
+ set: set
354
+ } : get ? {
355
+ get: get
356
+ } : {
357
+ set: set
358
+ };
359
+ try {
360
+ return dec(value, ctx);
361
+ } finally{
362
+ decoratorFinishedRef.v = true;
363
+ }
364
+ }
365
+ function assertNotFinished(decoratorFinishedRef, fnName) {
366
+ if (decoratorFinishedRef.v) {
367
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
368
+ }
369
+ }
370
+ function assertCallable(fn, hint) {
371
+ if (typeof fn !== "function") {
372
+ throw new TypeError(hint + " must be a function");
373
+ }
374
+ }
375
+ function assertValidReturnValue(kind, value) {
376
+ var type = typeof value;
377
+ if (kind === 1) {
378
+ if (type !== "object" || value === null) {
379
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
380
+ }
381
+ if (value.get !== undefined) {
382
+ assertCallable(value.get, "accessor.get");
383
+ }
384
+ if (value.set !== undefined) {
385
+ assertCallable(value.set, "accessor.set");
386
+ }
387
+ if (value.init !== undefined) {
388
+ assertCallable(value.init, "accessor.init");
389
+ }
390
+ } else if (type !== "function") {
391
+ var hint;
392
+ if (kind === 0) {
393
+ hint = "field";
394
+ } else if (kind === 10) {
395
+ hint = "class";
396
+ } else {
397
+ hint = "method";
398
+ }
399
+ throw new TypeError(hint + " decorators must return a function or void 0");
400
+ }
401
+ }
402
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
403
+ var decs = decInfo[0];
404
+ var desc, init, value;
405
+ if (isPrivate) {
406
+ if (kind === 0 || kind === 1) {
407
+ desc = {
408
+ get: decInfo[3],
409
+ set: decInfo[4]
410
+ };
411
+ } else if (kind === 3) {
412
+ desc = {
413
+ get: decInfo[3]
414
+ };
415
+ } else if (kind === 4) {
416
+ desc = {
417
+ set: decInfo[3]
418
+ };
419
+ } else {
420
+ desc = {
421
+ value: decInfo[3]
422
+ };
423
+ }
424
+ } else if (kind !== 0) {
425
+ desc = Object.getOwnPropertyDescriptor(base, name);
426
+ }
427
+ if (kind === 1) {
428
+ value = {
429
+ get: desc.get,
430
+ set: desc.set
431
+ };
432
+ } else if (kind === 2) {
433
+ value = desc.value;
434
+ } else if (kind === 3) {
435
+ value = desc.get;
436
+ } else if (kind === 4) {
437
+ value = desc.set;
438
+ }
439
+ var newValue, get, set;
440
+ if (typeof decs === "function") {
441
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
442
+ if (newValue !== void 0) {
443
+ assertValidReturnValue(kind, newValue);
444
+ if (kind === 0) {
445
+ init = newValue;
446
+ } else if (kind === 1) {
447
+ init = newValue.init;
448
+ get = newValue.get || value.get;
449
+ set = newValue.set || value.set;
450
+ value = {
451
+ get: get,
452
+ set: set
453
+ };
454
+ } else {
455
+ value = newValue;
456
+ }
457
+ }
458
+ } else {
459
+ for(var i = decs.length - 1; i >= 0; i--){
460
+ var dec = decs[i];
461
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
462
+ if (newValue !== void 0) {
463
+ assertValidReturnValue(kind, newValue);
464
+ var newInit;
465
+ if (kind === 0) {
466
+ newInit = newValue;
467
+ } else if (kind === 1) {
468
+ newInit = newValue.init;
469
+ get = newValue.get || value.get;
470
+ set = newValue.set || value.set;
471
+ value = {
472
+ get: get,
473
+ set: set
474
+ };
475
+ } else {
476
+ value = newValue;
477
+ }
478
+ if (newInit !== void 0) {
479
+ if (init === void 0) {
480
+ init = newInit;
481
+ } else if (typeof init === "function") {
482
+ init = [
483
+ init,
484
+ newInit
485
+ ];
486
+ } else {
487
+ init.push(newInit);
488
+ }
489
+ }
490
+ }
491
+ }
492
+ }
493
+ if (kind === 0 || kind === 1) {
494
+ if (init === void 0) {
495
+ init = function(instance, init) {
496
+ return init;
497
+ };
498
+ } else if (typeof init !== "function") {
499
+ var ownInitializers = init;
500
+ init = function(instance, init) {
501
+ var value = init;
502
+ for(var i = 0; i < ownInitializers.length; i++){
503
+ value = ownInitializers[i].call(instance, value);
504
+ }
505
+ return value;
506
+ };
507
+ } else {
508
+ var originalInitializer = init;
509
+ init = function(instance, init) {
510
+ return originalInitializer.call(instance, init);
511
+ };
512
+ }
513
+ ret.push(init);
514
+ }
515
+ if (kind !== 0) {
516
+ if (kind === 1) {
517
+ desc.get = value.get;
518
+ desc.set = value.set;
519
+ } else if (kind === 2) {
520
+ desc.value = value;
521
+ } else if (kind === 3) {
522
+ desc.get = value;
523
+ } else if (kind === 4) {
524
+ desc.set = value;
525
+ }
526
+ if (isPrivate) {
527
+ if (kind === 1) {
528
+ ret.push(function(instance, args) {
529
+ return value.get.call(instance, args);
530
+ });
531
+ ret.push(function(instance, args) {
532
+ return value.set.call(instance, args);
533
+ });
534
+ } else if (kind === 2) {
535
+ ret.push(value);
536
+ } else {
537
+ ret.push(function(instance, args) {
538
+ return value.call(instance, args);
539
+ });
540
+ }
541
+ } else {
542
+ Object.defineProperty(base, name, desc);
543
+ }
544
+ }
545
+ }
546
+ function applyMemberDecs(Class, decInfos, metadata) {
547
+ var ret = [];
548
+ var protoInitializers;
549
+ var staticInitializers;
550
+ var existingProtoNonFields = new Map();
551
+ var existingStaticNonFields = new Map();
552
+ for(var i = 0; i < decInfos.length; i++){
553
+ var decInfo = decInfos[i];
554
+ if (!Array.isArray(decInfo)) continue;
555
+ var kind = decInfo[1];
556
+ var name = decInfo[2];
557
+ var isPrivate = decInfo.length > 3;
558
+ var isStatic = kind >= 5;
559
+ var base;
560
+ var initializers;
561
+ if (isStatic) {
562
+ base = Class;
563
+ kind = kind - 5;
564
+ staticInitializers = staticInitializers || [];
565
+ initializers = staticInitializers;
566
+ } else {
567
+ base = Class.prototype;
568
+ protoInitializers = protoInitializers || [];
569
+ initializers = protoInitializers;
570
+ }
571
+ if (kind !== 0 && !isPrivate) {
572
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
573
+ var existingKind = existingNonFields.get(name) || 0;
574
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
575
+ throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
576
+ } else if (!existingKind && kind > 2) {
577
+ existingNonFields.set(name, kind);
578
+ } else {
579
+ existingNonFields.set(name, true);
580
+ }
581
+ }
582
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
583
+ }
584
+ pushInitializers(ret, protoInitializers);
585
+ pushInitializers(ret, staticInitializers);
586
+ return ret;
587
+ }
588
+ function pushInitializers(ret, initializers) {
589
+ if (initializers) {
590
+ ret.push(function(instance) {
591
+ for(var i = 0; i < initializers.length; i++){
592
+ initializers[i].call(instance);
593
+ }
594
+ return instance;
595
+ });
596
+ }
597
+ }
598
+ function applyClassDecs(targetClass, classDecs, metadata) {
599
+ if (classDecs.length > 0) {
600
+ var initializers = [];
601
+ var newClass = targetClass;
602
+ var name = targetClass.name;
603
+ for(var i = classDecs.length - 1; i >= 0; i--){
604
+ var decoratorFinishedRef = {
605
+ v: false
606
+ };
607
+ try {
608
+ var nextNewClass = classDecs[i](newClass, {
609
+ kind: "class",
610
+ name: name,
611
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
612
+ metadata
613
+ });
614
+ } finally{
615
+ decoratorFinishedRef.v = true;
616
+ }
617
+ if (nextNewClass !== undefined) {
618
+ assertValidReturnValue(10, nextNewClass);
619
+ newClass = nextNewClass;
620
+ }
621
+ }
622
+ return [
623
+ defineMetadata(newClass, metadata),
624
+ function() {
625
+ for(var i = 0; i < initializers.length; i++){
626
+ initializers[i].call(newClass);
627
+ }
628
+ }
629
+ ];
630
+ }
631
+ }
632
+ function defineMetadata(Class, metadata) {
633
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
634
+ configurable: true,
635
+ enumerable: true,
636
+ value: metadata
637
+ });
638
+ }
639
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
640
+ if (parentClass !== void 0) {
641
+ var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
642
+ }
643
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
644
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
645
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
646
+ return {
647
+ e: e,
648
+ get c () {
649
+ return applyClassDecs(targetClass, classDecs, metadata);
650
+ }
651
+ };
652
+ };
653
+ }
654
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
655
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
656
+ }
657
+ function _identity(x) {
658
+ return x;
659
+ }
660
+ var _dec, _initClass, _ValidityMixin, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, // ── ValidityMixin contract — must be declared as @property —————————————
661
+ _init_status, _init_required, _init_validityMessage, // ── Public API ─────────────────────────────────────────────────────────────
662
+ /** Input type. Controls the keyboard/picker on mobile and browser validation hints. */ _init_type, /** Native input placeholder text. */ _init_placeholder, /** Form field name. Submitted with the form when set. */ _init_name, /** Current value. Synced to ElementInternals for form participation. */ _init_value, /** When true, disables the input and removes it from the tab order. */ _init_disabled, /** When true, the value cannot be edited but is still submitted. */ _init_readonly, _initProto;
663
+ let _ViInput;
664
+ _dec = customElement('vi-input'), _dec1 = property({
665
+ reflect: true
666
+ }), _dec2 = property({
667
+ type: Boolean,
668
+ reflect: true
669
+ }), _dec3 = property(), _dec4 = property({
670
+ type: String,
671
+ reflect: true
672
+ }), _dec5 = property(), _dec6 = property(), _dec7 = property(), _dec8 = property({
673
+ type: Boolean,
674
+ reflect: true
675
+ }), _dec9 = property({
676
+ type: Boolean,
677
+ reflect: true
678
+ });
679
+ new class extends _identity {
680
+ constructor(){
681
+ super(_ViInput), _initClass();
682
+ }
683
+ static{
684
+ class ViInput extends (_ValidityMixin = ValidityMixin(FocusableMixin(ViElement))) {
685
+ static{
686
+ ({ e: [_init_status, _init_required, _init_validityMessage, _init_type, _init_placeholder, _init_name, _init_value, _init_disabled, _init_readonly, _initProto], c: [_ViInput, _initClass] } = _apply_decs_2203_r(this, [
687
+ [
688
+ _dec1,
689
+ 1,
690
+ "status"
691
+ ],
692
+ [
693
+ _dec2,
694
+ 1,
695
+ "required"
696
+ ],
697
+ [
698
+ _dec3,
699
+ 1,
700
+ "validityMessage"
701
+ ],
702
+ [
703
+ _dec4,
704
+ 1,
705
+ "type"
706
+ ],
707
+ [
708
+ _dec5,
709
+ 1,
710
+ "placeholder"
711
+ ],
712
+ [
713
+ _dec6,
714
+ 1,
715
+ "name"
716
+ ],
717
+ [
718
+ _dec7,
719
+ 1,
720
+ "value"
721
+ ],
722
+ [
723
+ _dec8,
724
+ 1,
725
+ "disabled"
726
+ ],
727
+ [
728
+ _dec9,
729
+ 1,
730
+ "readonly"
731
+ ]
732
+ ], [
733
+ _dec
734
+ ], _ValidityMixin));
735
+ }
736
+ static formAssociated = true;
737
+ static styles = css`
738
+ ${unsafeCSS(inputStyles)}
739
+ `;
740
+ _internals = (_initProto(this), this.attachInternals());
741
+ get _focusableElement() {
742
+ return this.shadowRoot?.querySelector('input') ?? null;
743
+ }
744
+ #___private_status_1 = _init_status(this, 'default');
745
+ get status() {
746
+ return this.#___private_status_1;
747
+ }
748
+ set status(_v) {
749
+ this.#___private_status_1 = _v;
750
+ }
751
+ #___private_required_2 = _init_required(this, false);
752
+ get required() {
753
+ return this.#___private_required_2;
754
+ }
755
+ set required(_v) {
756
+ this.#___private_required_2 = _v;
757
+ }
758
+ #___private_validityMessage_3 = _init_validityMessage(this, '');
759
+ get validityMessage() {
760
+ return this.#___private_validityMessage_3;
761
+ }
762
+ set validityMessage(_v) {
763
+ this.#___private_validityMessage_3 = _v;
764
+ }
765
+ #___private_type_4 = _init_type(this, 'text');
766
+ get type() {
767
+ return this.#___private_type_4;
768
+ }
769
+ set type(_v) {
770
+ this.#___private_type_4 = _v;
771
+ }
772
+ #___private_placeholder_5 = _init_placeholder(this, '');
773
+ get placeholder() {
774
+ return this.#___private_placeholder_5;
775
+ }
776
+ set placeholder(_v) {
777
+ this.#___private_placeholder_5 = _v;
778
+ }
779
+ #___private_name_6 = _init_name(this, '');
780
+ get name() {
781
+ return this.#___private_name_6;
782
+ }
783
+ set name(_v) {
784
+ this.#___private_name_6 = _v;
785
+ }
786
+ #___private_value_7 = _init_value(this, '');
787
+ get value() {
788
+ return this.#___private_value_7;
789
+ }
790
+ set value(_v) {
791
+ this.#___private_value_7 = _v;
792
+ }
793
+ #___private_disabled_8 = _init_disabled(this, false);
794
+ get disabled() {
795
+ return this.#___private_disabled_8;
796
+ }
797
+ set disabled(_v) {
798
+ this.#___private_disabled_8 = _v;
799
+ }
800
+ #___private_readonly_9 = _init_readonly(this, false);
801
+ get readonly() {
802
+ return this.#___private_readonly_9;
803
+ }
804
+ set readonly(_v) {
805
+ this.#___private_readonly_9 = _v;
806
+ }
807
+ // ── ValidityMixin hook ─────────────────────────────────────────────────────
808
+ // _testValidity is declared protected in ValidityInterface, but TypeScript's
809
+ // mixin intersection type does not always surface protected members for
810
+ // `override` checking. The method is still an override at runtime.
811
+ _testValidity() {
812
+ if (this._internals.validity.customError) {
813
+ return {
814
+ customError: true
815
+ };
816
+ }
817
+ const input = this._focusableElement;
818
+ if (input) {
819
+ if (input.value !== this.value) {
820
+ input.value = this.value;
821
+ }
822
+ const validity = input.validity;
823
+ if (!validity.valid) {
824
+ this.validityMessage = input.validationMessage;
825
+ return {
826
+ badInput: validity.badInput,
827
+ customError: validity.customError,
828
+ patternMismatch: validity.patternMismatch,
829
+ rangeOverflow: validity.rangeOverflow,
830
+ rangeUnderflow: validity.rangeUnderflow,
831
+ stepMismatch: validity.stepMismatch,
832
+ tooLong: validity.tooLong,
833
+ tooShort: validity.tooShort,
834
+ typeMismatch: validity.typeMismatch,
835
+ valueMissing: validity.valueMissing
836
+ };
837
+ }
838
+ } else if (this.required && !this.value) {
839
+ this.validityMessage = 'Please fill out this field.';
840
+ return {
841
+ valueMissing: true
842
+ };
843
+ }
844
+ return {};
845
+ }
846
+ // ── Lifecycle ──────────────────────────────────────────────────────────────
847
+ updated(changed) {
848
+ super.updated(changed);
849
+ if (changed.has('value')) {
850
+ this._internals.setFormValue(this.value);
851
+ }
852
+ if (changed.has('disabled')) {
853
+ this._setHostFocusable(!this.disabled);
854
+ }
855
+ }
856
+ /** Resets value and validation state when the associated form resets. */ formResetCallback() {
857
+ this.value = this.getAttribute('value') ?? '';
858
+ this.status = 'default';
859
+ this.validityMessage = '';
860
+ }
861
+ /** Keeps disabled in sync when a containing fieldset or form is disabled. */ formDisabledCallback(disabled) {
862
+ this.disabled = disabled;
863
+ }
864
+ // ── Event handlers ─────────────────────────────────────────────────────────
865
+ _onInput(e) {
866
+ e.stopPropagation();
867
+ const input = e.target;
868
+ this.value = input.value;
869
+ this.dispatchEvent(new CustomEvent('vialiq-input', {
870
+ detail: {
871
+ value: this.value
872
+ },
873
+ bubbles: true,
874
+ composed: true
875
+ }));
876
+ }
877
+ _onChange(e) {
878
+ e.stopPropagation();
879
+ const input = e.target;
880
+ this.value = input.value;
881
+ this.dispatchEvent(new CustomEvent('vialiq-change', {
882
+ detail: {
883
+ value: this.value
884
+ },
885
+ bubbles: true,
886
+ composed: true
887
+ }));
888
+ }
889
+ // ── Render ─────────────────────────────────────────────────────────────────
890
+ get _helperContent() {
891
+ return html`<span id="helper-text" class="input-helper" part="helper"
892
+ ><slot name="helper"></slot
893
+ ></span>`;
894
+ }
895
+ get _validationMessage() {
896
+ if (!this.validityMessage) return html``;
897
+ const cls = this.status === 'invalid' ? 'input-validation--invalid' : this.status === 'valid' ? 'input-validation--valid' : '';
898
+ return html`<span
899
+ id="validation-message"
900
+ class="input-validation ${cls}"
901
+ part="validation"
902
+ role="alert"
903
+ aria-live="polite"
904
+ >${this.validityMessage}</span
905
+ >`;
906
+ }
907
+ render() {
908
+ const { type, placeholder, name, value, disabled, required, readonly } = this;
909
+ return html`
910
+ <div class="input-field" part="field">
911
+ <input
912
+ class="input-control"
913
+ part="input"
914
+ tabindex="0"
915
+ type=${type}
916
+ .value=${value}
917
+ ?disabled=${disabled}
918
+ ?readonly=${readonly}
919
+ ?required=${required}
920
+ aria-required=${ifNonEmpty(required ? 'true' : '')}
921
+ aria-invalid=${this.status === 'invalid' ? 'true' : 'false'}
922
+ aria-describedby=${this.validityMessage ? 'helper-text validation-message' : 'helper-text'}
923
+ aria-errormessage=${ifNonEmpty(this.status === 'invalid' && this.validityMessage ? 'validation-message' : '')}
924
+ placeholder=${ifNonEmpty(placeholder)}
925
+ name=${ifNonEmpty(name)}
926
+ @input=${this._onInput}
927
+ @change=${this._onChange}
928
+ />
929
+ ${this._helperContent} ${this._validationMessage}
930
+ </div>
931
+ `;
932
+ }
933
+ }
934
+ }
935
+ }();
936
+
937
+ export { _ViInput as ViInput };