@vialiq/web-components 0.4.0 → 0.6.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,780 @@
1
+ import { unsafeCSS, css, html } from 'lit';
2
+ import { customElement, property } from 'lit/decorators.js';
3
+ import { V as ValidityMixin } from '../validity-mixin-BjmXwgWk.js';
4
+ import { V as ViElement } from '../vi-element-C6GfDPs3.js';
5
+
6
+ const radioGroupStyles = "@charset \"UTF-8\";@layer reset,components,utilities;@layer components{.radio-group{border:none;margin:0;padding:0;display:flex;flex-direction:column;gap:var(--vi-radio-group-spacing-field-gap, var(--vi-spacing-xs, 8px));width:100%}.radio-group-legend{font-family:var(--vi-font-family-base, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif);font-size:var(--vi-radio-group-label-font-size, var(--vi-font-size-base, 16px));font-weight:var(--vi-font-weight-semibold, 600);color:var(--vi-radio-group-label-color, var(--vi-color-foreground, #111827));padding:0;margin:0;margin-block-end:var(--vi-radio-group-legend-margin-bottom, var(--vi-spacing-xs, 8px))}.radio-group-items{display:flex;gap:var(--vi-radio-group-gap, 8px)}.radio-group-items[orientation=vertical]{flex-direction:column}.radio-group-items[orientation=horizontal]{flex-direction:row;flex-wrap:wrap;gap:var(--vi-radio-group-gap-horizontal, 24px)}.radio-group-helper{display:block;font-family:var(--vi-font-family-base, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif);font-size:var(--vi-radio-group-helper-font-size, var(--vi-font-size-xs, 12px));color:var(--vi-radio-group-helper-color, var(--vi-text-helper, #9e9e9e))}.radio-group-validation{display:block;font-family:var(--vi-font-family-base, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif);font-size:var(--vi-radio-group-validation-font-size, var(--vi-font-size-xs, 12px));color:var(--vi-radio-group-validation-color, var(--vi-text-helper, #9e9e9e));margin-block-start:var(--vi-radio-group-validation-margin-top, var(--vi-spacing-xs, 8px))}.radio-group-validation.radio-group-validation--invalid{color:var(--vi-radio-group-error-color, var(--vi-color-error, #ef4444))}.radio-group-validation.radio-group-validation--valid{color:var(--vi-radio-group-success-color, var(--vi-color-success, #489167))}.radio-wrapper{display:inline-flex;align-items:center;gap:var(--vi-radio-label-gap, 8px);cursor:pointer;font-family:var(--vi-font-family-base, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif);font-size:var(--vi-radio-label-font-size, var(--vi-font-size-base, 16px));line-height:var(--vi-line-height-normal, 1.5);color:var(--vi-radio-label-color, var(--vi-color-foreground, #111827));position:relative;-webkit-user-select:none;user-select:none}.radio-input{position:absolute!important;clip-path:inset(50%)!important;overflow:hidden!important;width:1px!important;height:1px!important;margin:-1px!important;padding:0!important;border:0!important;white-space:nowrap!important}.radio-circle{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;width:var(--vi-radio-size, 18px);height:var(--vi-radio-size, 18px);border:var(--vi-border-width-base, 2px) solid var(--vi-radio-border-color, var(--vi-border-04, #bdbdbd));border-radius:50%;background-color:var(--vi-radio-background-color, var(--vi-color-background, #ffffff));transition:border-color .15s ease,box-shadow .15s ease;flex-shrink:0}.radio-dot{box-sizing:border-box;width:var(--vi-radio-dot-size, 8px);height:var(--vi-radio-dot-size, 8px);border-radius:50%;background-color:var(--vi-radio-dot-color, var(--vi-color-primary, #3676d0));transform:scale(0);opacity:0;transition:transform .15s cubic-bezier(.4,0,.2,1),opacity .15s ease}.radio-input:checked+.radio-circle{border-color:var(--vi-radio-border-color-checked, var(--vi-color-primary, #3676d0))}.radio-input:checked+.radio-circle .radio-dot{transform:scale(1);opacity:1}.radio-input:focus-visible+.radio-circle{outline:var(--vi-border-width-base, 2px) solid var(--vi-radio-focus-ring-color, var(--vi-color-primary, #3676d0));outline-offset:2px;box-shadow:0 0 0 3px var(--vi-radio-focus-ring-glow, var(--vi-color-blue-200, #cee6ff))}.radio-wrapper:hover:not(.radio-wrapper--disabled) .radio-circle{border-color:var(--vi-radio-border-color-hover, var(--vi-border-inverse-03, #757575))}.radio-wrapper:hover:not(.radio-wrapper--disabled) .radio-input:checked+.radio-circle{border-color:var(--vi-radio-border-color-checked-hover, var(--vi-color-primary, #3676d0))}.radio-wrapper--disabled{cursor:not-allowed;opacity:var(--vi-radio-disabled-opacity, .5)}.radio-wrapper--disabled .radio-circle{background-color:var(--vi-layer-disabled, #f3f4f6);border-color:var(--vi-border-02, #eeeeee)}.radio-wrapper--disabled .radio-dot{background-color:var(--vi-text-disabled, #9e9e9e)}@media(prefers-reduced-motion:reduce){.radio-circle,.radio-dot{transition:none}}}:host{display:block;outline:none}:host([disabled]){cursor:not-allowed;pointer-events:none}:host([status=invalid]){--vi-radio-group-label-color: var(--vi-color-error, #ef4444)}::slotted(*){font-family:inherit;font-size:inherit;color:inherit}:host([size=xs]){--vi-radio-group-label-font-size: var(--vi-font-size-xs, 12px);--vi-radio-group-legend-margin-bottom: 4px}:host([size=sm]){--vi-radio-group-label-font-size: var(--vi-font-size-sm, 14px);--vi-radio-group-legend-margin-bottom: 6px}:host([size=lg]){--vi-radio-group-label-font-size: var(--vi-font-size-lg, 18px);--vi-radio-group-legend-margin-bottom: 10px}";
7
+
8
+ function applyDecs2203RFactory() {
9
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
10
+ return function addInitializer(initializer) {
11
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
12
+ assertCallable(initializer, "An initializer");
13
+ initializers.push(initializer);
14
+ };
15
+ }
16
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
17
+ var kindStr;
18
+ switch(kind){
19
+ case 1:
20
+ kindStr = "accessor";
21
+ break;
22
+ case 2:
23
+ kindStr = "method";
24
+ break;
25
+ case 3:
26
+ kindStr = "getter";
27
+ break;
28
+ case 4:
29
+ kindStr = "setter";
30
+ break;
31
+ default:
32
+ kindStr = "field";
33
+ }
34
+ var ctx = {
35
+ kind: kindStr,
36
+ name: isPrivate ? "#" + name : name,
37
+ static: isStatic,
38
+ private: isPrivate,
39
+ metadata: metadata
40
+ };
41
+ var decoratorFinishedRef = {
42
+ v: false
43
+ };
44
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
45
+ var get, set;
46
+ if (kind === 0) {
47
+ if (isPrivate) {
48
+ get = desc.get;
49
+ set = desc.set;
50
+ } else {
51
+ get = function() {
52
+ return this[name];
53
+ };
54
+ set = function(v) {
55
+ this[name] = v;
56
+ };
57
+ }
58
+ } else if (kind === 2) {
59
+ get = function() {
60
+ return desc.value;
61
+ };
62
+ } else {
63
+ if (kind === 1 || kind === 3) {
64
+ get = function() {
65
+ return desc.get.call(this);
66
+ };
67
+ }
68
+ if (kind === 1 || kind === 4) {
69
+ set = function(v) {
70
+ desc.set.call(this, v);
71
+ };
72
+ }
73
+ }
74
+ ctx.access = get && set ? {
75
+ get: get,
76
+ set: set
77
+ } : get ? {
78
+ get: get
79
+ } : {
80
+ set: set
81
+ };
82
+ try {
83
+ return dec(value, ctx);
84
+ } finally{
85
+ decoratorFinishedRef.v = true;
86
+ }
87
+ }
88
+ function assertNotFinished(decoratorFinishedRef, fnName) {
89
+ if (decoratorFinishedRef.v) {
90
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
91
+ }
92
+ }
93
+ function assertCallable(fn, hint) {
94
+ if (typeof fn !== "function") {
95
+ throw new TypeError(hint + " must be a function");
96
+ }
97
+ }
98
+ function assertValidReturnValue(kind, value) {
99
+ var type = typeof value;
100
+ if (kind === 1) {
101
+ if (type !== "object" || value === null) {
102
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
103
+ }
104
+ if (value.get !== undefined) {
105
+ assertCallable(value.get, "accessor.get");
106
+ }
107
+ if (value.set !== undefined) {
108
+ assertCallable(value.set, "accessor.set");
109
+ }
110
+ if (value.init !== undefined) {
111
+ assertCallable(value.init, "accessor.init");
112
+ }
113
+ } else if (type !== "function") {
114
+ var hint;
115
+ if (kind === 0) {
116
+ hint = "field";
117
+ } else if (kind === 10) {
118
+ hint = "class";
119
+ } else {
120
+ hint = "method";
121
+ }
122
+ throw new TypeError(hint + " decorators must return a function or void 0");
123
+ }
124
+ }
125
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
126
+ var decs = decInfo[0];
127
+ var desc, init, value;
128
+ if (isPrivate) {
129
+ if (kind === 0 || kind === 1) {
130
+ desc = {
131
+ get: decInfo[3],
132
+ set: decInfo[4]
133
+ };
134
+ } else if (kind === 3) {
135
+ desc = {
136
+ get: decInfo[3]
137
+ };
138
+ } else if (kind === 4) {
139
+ desc = {
140
+ set: decInfo[3]
141
+ };
142
+ } else {
143
+ desc = {
144
+ value: decInfo[3]
145
+ };
146
+ }
147
+ } else if (kind !== 0) {
148
+ desc = Object.getOwnPropertyDescriptor(base, name);
149
+ }
150
+ if (kind === 1) {
151
+ value = {
152
+ get: desc.get,
153
+ set: desc.set
154
+ };
155
+ } else if (kind === 2) {
156
+ value = desc.value;
157
+ } else if (kind === 3) {
158
+ value = desc.get;
159
+ } else if (kind === 4) {
160
+ value = desc.set;
161
+ }
162
+ var newValue, get, set;
163
+ if (typeof decs === "function") {
164
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
165
+ if (newValue !== void 0) {
166
+ assertValidReturnValue(kind, newValue);
167
+ if (kind === 0) {
168
+ init = newValue;
169
+ } else if (kind === 1) {
170
+ init = newValue.init;
171
+ get = newValue.get || value.get;
172
+ set = newValue.set || value.set;
173
+ value = {
174
+ get: get,
175
+ set: set
176
+ };
177
+ } else {
178
+ value = newValue;
179
+ }
180
+ }
181
+ } else {
182
+ for(var i = decs.length - 1; i >= 0; i--){
183
+ var dec = decs[i];
184
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
185
+ if (newValue !== void 0) {
186
+ assertValidReturnValue(kind, newValue);
187
+ var newInit;
188
+ if (kind === 0) {
189
+ newInit = newValue;
190
+ } else if (kind === 1) {
191
+ newInit = newValue.init;
192
+ get = newValue.get || value.get;
193
+ set = newValue.set || value.set;
194
+ value = {
195
+ get: get,
196
+ set: set
197
+ };
198
+ } else {
199
+ value = newValue;
200
+ }
201
+ if (newInit !== void 0) {
202
+ if (init === void 0) {
203
+ init = newInit;
204
+ } else if (typeof init === "function") {
205
+ init = [
206
+ init,
207
+ newInit
208
+ ];
209
+ } else {
210
+ init.push(newInit);
211
+ }
212
+ }
213
+ }
214
+ }
215
+ }
216
+ if (kind === 0 || kind === 1) {
217
+ if (init === void 0) {
218
+ init = function(instance, init) {
219
+ return init;
220
+ };
221
+ } else if (typeof init !== "function") {
222
+ var ownInitializers = init;
223
+ init = function(instance, init) {
224
+ var value = init;
225
+ for(var i = 0; i < ownInitializers.length; i++){
226
+ value = ownInitializers[i].call(instance, value);
227
+ }
228
+ return value;
229
+ };
230
+ } else {
231
+ var originalInitializer = init;
232
+ init = function(instance, init) {
233
+ return originalInitializer.call(instance, init);
234
+ };
235
+ }
236
+ ret.push(init);
237
+ }
238
+ if (kind !== 0) {
239
+ if (kind === 1) {
240
+ desc.get = value.get;
241
+ desc.set = value.set;
242
+ } else if (kind === 2) {
243
+ desc.value = value;
244
+ } else if (kind === 3) {
245
+ desc.get = value;
246
+ } else if (kind === 4) {
247
+ desc.set = value;
248
+ }
249
+ if (isPrivate) {
250
+ if (kind === 1) {
251
+ ret.push(function(instance, args) {
252
+ return value.get.call(instance, args);
253
+ });
254
+ ret.push(function(instance, args) {
255
+ return value.set.call(instance, args);
256
+ });
257
+ } else if (kind === 2) {
258
+ ret.push(value);
259
+ } else {
260
+ ret.push(function(instance, args) {
261
+ return value.call(instance, args);
262
+ });
263
+ }
264
+ } else {
265
+ Object.defineProperty(base, name, desc);
266
+ }
267
+ }
268
+ }
269
+ function applyMemberDecs(Class, decInfos, metadata) {
270
+ var ret = [];
271
+ var protoInitializers;
272
+ var staticInitializers;
273
+ var existingProtoNonFields = new Map();
274
+ var existingStaticNonFields = new Map();
275
+ for(var i = 0; i < decInfos.length; i++){
276
+ var decInfo = decInfos[i];
277
+ if (!Array.isArray(decInfo)) continue;
278
+ var kind = decInfo[1];
279
+ var name = decInfo[2];
280
+ var isPrivate = decInfo.length > 3;
281
+ var isStatic = kind >= 5;
282
+ var base;
283
+ var initializers;
284
+ if (isStatic) {
285
+ base = Class;
286
+ kind = kind - 5;
287
+ staticInitializers = staticInitializers || [];
288
+ initializers = staticInitializers;
289
+ } else {
290
+ base = Class.prototype;
291
+ protoInitializers = protoInitializers || [];
292
+ initializers = protoInitializers;
293
+ }
294
+ if (kind !== 0 && !isPrivate) {
295
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
296
+ var existingKind = existingNonFields.get(name) || 0;
297
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
298
+ 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);
299
+ } else if (!existingKind && kind > 2) {
300
+ existingNonFields.set(name, kind);
301
+ } else {
302
+ existingNonFields.set(name, true);
303
+ }
304
+ }
305
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
306
+ }
307
+ pushInitializers(ret, protoInitializers);
308
+ pushInitializers(ret, staticInitializers);
309
+ return ret;
310
+ }
311
+ function pushInitializers(ret, initializers) {
312
+ if (initializers) {
313
+ ret.push(function(instance) {
314
+ for(var i = 0; i < initializers.length; i++){
315
+ initializers[i].call(instance);
316
+ }
317
+ return instance;
318
+ });
319
+ }
320
+ }
321
+ function applyClassDecs(targetClass, classDecs, metadata) {
322
+ if (classDecs.length > 0) {
323
+ var initializers = [];
324
+ var newClass = targetClass;
325
+ var name = targetClass.name;
326
+ for(var i = classDecs.length - 1; i >= 0; i--){
327
+ var decoratorFinishedRef = {
328
+ v: false
329
+ };
330
+ try {
331
+ var nextNewClass = classDecs[i](newClass, {
332
+ kind: "class",
333
+ name: name,
334
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
335
+ metadata
336
+ });
337
+ } finally{
338
+ decoratorFinishedRef.v = true;
339
+ }
340
+ if (nextNewClass !== undefined) {
341
+ assertValidReturnValue(10, nextNewClass);
342
+ newClass = nextNewClass;
343
+ }
344
+ }
345
+ return [
346
+ defineMetadata(newClass, metadata),
347
+ function() {
348
+ for(var i = 0; i < initializers.length; i++){
349
+ initializers[i].call(newClass);
350
+ }
351
+ }
352
+ ];
353
+ }
354
+ }
355
+ function defineMetadata(Class, metadata) {
356
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
357
+ configurable: true,
358
+ enumerable: true,
359
+ value: metadata
360
+ });
361
+ }
362
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
363
+ if (parentClass !== void 0) {
364
+ var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
365
+ }
366
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
367
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
368
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
369
+ return {
370
+ e: e,
371
+ get c () {
372
+ return applyClassDecs(targetClass, classDecs, metadata);
373
+ }
374
+ };
375
+ };
376
+ }
377
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
378
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
379
+ }
380
+ function _identity(x) {
381
+ return x;
382
+ }
383
+ var _dec, _initClass, _ValidityMixin, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, // ── ValidityMixin contract ───────────────────────────────────────────────
384
+ _init_status, _init_required, _init_validityMessage, // ── Public API ─────────────────────────────────────────────────────────────
385
+ /** Currently selected radio's value. */ _init_value, /** Shared name for all child radios. */ _init_name, /** Disables the entire group. */ _init_disabled, /** Layout direction of the radio group. */ _init_orientation, /** Size scale — controls spacing and propagates to child radios. */ _init_size, /** Allows clearing the selected radio button on double click. */ _init_allowDblclickClear, _initProto;
386
+ let _ViRadioGroup;
387
+ _dec = customElement('vi-radio-group'), _dec1 = property({
388
+ reflect: true
389
+ }), _dec2 = property({
390
+ type: Boolean,
391
+ reflect: true
392
+ }), _dec3 = property({
393
+ attribute: 'validity-message'
394
+ }), _dec4 = property({
395
+ reflect: true
396
+ }), _dec5 = property(), _dec6 = property({
397
+ type: Boolean,
398
+ reflect: true
399
+ }), _dec7 = property({
400
+ reflect: true
401
+ }), _dec8 = property({
402
+ type: String,
403
+ reflect: true
404
+ }), _dec9 = property({
405
+ type: Boolean,
406
+ attribute: 'allow-dblclick-clear',
407
+ reflect: true
408
+ });
409
+ new class extends _identity {
410
+ constructor(){
411
+ super(_ViRadioGroup), _initClass();
412
+ }
413
+ static{
414
+ class ViRadioGroup extends (_ValidityMixin = ValidityMixin(ViElement)) {
415
+ static{
416
+ ({ e: [_init_status, _init_required, _init_validityMessage, _init_value, _init_name, _init_disabled, _init_orientation, _init_size, _init_allowDblclickClear, _initProto], c: [_ViRadioGroup, _initClass] } = _apply_decs_2203_r(this, [
417
+ [
418
+ _dec1,
419
+ 1,
420
+ "status"
421
+ ],
422
+ [
423
+ _dec2,
424
+ 1,
425
+ "required"
426
+ ],
427
+ [
428
+ _dec3,
429
+ 1,
430
+ "validityMessage"
431
+ ],
432
+ [
433
+ _dec4,
434
+ 1,
435
+ "value"
436
+ ],
437
+ [
438
+ _dec5,
439
+ 1,
440
+ "name"
441
+ ],
442
+ [
443
+ _dec6,
444
+ 1,
445
+ "disabled"
446
+ ],
447
+ [
448
+ _dec7,
449
+ 1,
450
+ "orientation"
451
+ ],
452
+ [
453
+ _dec8,
454
+ 1,
455
+ "size"
456
+ ],
457
+ [
458
+ _dec9,
459
+ 1,
460
+ "allowDblclickClear"
461
+ ]
462
+ ], [
463
+ _dec
464
+ ], _ValidityMixin));
465
+ }
466
+ static formAssociated = true;
467
+ static styles = css`
468
+ ${unsafeCSS(radioGroupStyles)}
469
+ `;
470
+ _internals = (_initProto(this), this.attachInternals());
471
+ #___private_status_1 = _init_status(this, 'default');
472
+ get status() {
473
+ return this.#___private_status_1;
474
+ }
475
+ set status(_v) {
476
+ this.#___private_status_1 = _v;
477
+ }
478
+ #___private_required_2 = _init_required(this, false);
479
+ get required() {
480
+ return this.#___private_required_2;
481
+ }
482
+ set required(_v) {
483
+ this.#___private_required_2 = _v;
484
+ }
485
+ #___private_validityMessage_3 = _init_validityMessage(this, '');
486
+ get validityMessage() {
487
+ return this.#___private_validityMessage_3;
488
+ }
489
+ set validityMessage(_v) {
490
+ this.#___private_validityMessage_3 = _v;
491
+ }
492
+ #___private_value_4 = _init_value(this, '');
493
+ get value() {
494
+ return this.#___private_value_4;
495
+ }
496
+ set value(_v) {
497
+ this.#___private_value_4 = _v;
498
+ }
499
+ #___private_name_5 = _init_name(this, '');
500
+ get name() {
501
+ return this.#___private_name_5;
502
+ }
503
+ set name(_v) {
504
+ this.#___private_name_5 = _v;
505
+ }
506
+ #___private_disabled_6 = _init_disabled(this, false);
507
+ get disabled() {
508
+ return this.#___private_disabled_6;
509
+ }
510
+ set disabled(_v) {
511
+ this.#___private_disabled_6 = _v;
512
+ }
513
+ #___private_orientation_7 = _init_orientation(this, 'vertical');
514
+ get orientation() {
515
+ return this.#___private_orientation_7;
516
+ }
517
+ set orientation(_v) {
518
+ this.#___private_orientation_7 = _v;
519
+ }
520
+ #___private_size_8 = _init_size(this, 'md');
521
+ get size() {
522
+ return this.#___private_size_8;
523
+ }
524
+ set size(_v) {
525
+ this.#___private_size_8 = _v;
526
+ }
527
+ #___private_allowDblclickClear_9 = _init_allowDblclickClear(this, false);
528
+ get allowDblclickClear() {
529
+ return this.#___private_allowDblclickClear_9;
530
+ }
531
+ set allowDblclickClear(_v) {
532
+ this.#___private_allowDblclickClear_9 = _v;
533
+ }
534
+ _observer;
535
+ _initialValue = '';
536
+ connectedCallback() {
537
+ super.connectedCallback();
538
+ this._initialValue = this.getAttribute('value') ?? '';
539
+ // Set up MutationObserver to react to child vi-radio nodes added/removed dynamically
540
+ this._observer = new MutationObserver(()=>{
541
+ this._updateRadios();
542
+ });
543
+ this._observer.observe(this, {
544
+ childList: true,
545
+ subtree: true,
546
+ attributes: true,
547
+ attributeFilter: [
548
+ 'disabled'
549
+ ]
550
+ });
551
+ // Sync initial state of child radios
552
+ this._updateRadios();
553
+ // Listen for double-clicks on the host to support clearing
554
+ this.addEventListener('dblclick', this._onDblclick);
555
+ }
556
+ disconnectedCallback() {
557
+ super.disconnectedCallback();
558
+ if (this._observer) {
559
+ this._observer.disconnect();
560
+ }
561
+ this.removeEventListener('dblclick', this._onDblclick);
562
+ }
563
+ updated(changed) {
564
+ super.updated(changed);
565
+ if (changed.has('value')) {
566
+ this._internals.setFormValue(this.value);
567
+ }
568
+ if (changed.has('value') || changed.has('name') || changed.has('disabled') || changed.has('required') || changed.has('size')) {
569
+ this._updateRadios();
570
+ }
571
+ }
572
+ /** Resets the value and validation state when the parent form resets. */ formResetCallback() {
573
+ this.value = this._initialValue;
574
+ this.status = 'default';
575
+ this.validityMessage = '';
576
+ this._updateRadios();
577
+ }
578
+ /** Keeps disabled in sync when a containing fieldset/form is disabled. */ formDisabledCallback(disabled) {
579
+ this.disabled = disabled;
580
+ }
581
+ _testValidity() {
582
+ if (this.required && !this.value) {
583
+ const radios = this._getRadios();
584
+ if (radios.length > 0) {
585
+ const firstInput = radios[0].shadowRoot?.querySelector('input');
586
+ if (firstInput) {
587
+ const wasRequired = firstInput.required;
588
+ firstInput.required = true;
589
+ this.validityMessage = firstInput.validationMessage;
590
+ firstInput.required = wasRequired;
591
+ return {
592
+ valueMissing: true
593
+ };
594
+ }
595
+ }
596
+ const temp = document.createElement('input');
597
+ temp.type = 'radio';
598
+ temp.name = 'temp-radio-group';
599
+ temp.required = true;
600
+ this.appendChild(temp);
601
+ this.validityMessage = temp.validationMessage;
602
+ this.removeChild(temp);
603
+ return {
604
+ valueMissing: true
605
+ };
606
+ }
607
+ return {};
608
+ }
609
+ // ── Helper methods ─────────────────────────────────────────────────────────
610
+ _getRadios() {
611
+ return Array.from(this.querySelectorAll('vi-radio'));
612
+ }
613
+ _updateRadios() {
614
+ const radios = this._getRadios();
615
+ // 1. Propagate name, checked, and size attributes to children
616
+ radios.forEach((radio)=>{
617
+ if (this.name && radio.name !== this.name) {
618
+ radio.name = this.name;
619
+ }
620
+ if (this.size && radio.size !== this.size) {
621
+ radio.size = this.size;
622
+ }
623
+ const shouldBeChecked = this.value !== '' && radio.value === this.value;
624
+ if (radio.checked !== shouldBeChecked) {
625
+ radio.checked = shouldBeChecked;
626
+ }
627
+ // Let children recalculate their disabled states
628
+ radio.requestUpdate();
629
+ });
630
+ // 2. Roving tabindex active node determination:
631
+ // - The checked radio (if enabled)
632
+ // - The first enabled radio
633
+ // - Fallback to the first radio
634
+ let activeRadio = radios.find((r)=>r.checked && !r.disabled && !this.disabled);
635
+ if (!activeRadio) {
636
+ activeRadio = radios.find((r)=>!r.disabled && !this.disabled);
637
+ }
638
+ if (!activeRadio && radios.length > 0) {
639
+ activeRadio = radios[0];
640
+ }
641
+ radios.forEach((radio)=>{
642
+ const isRadioActive = radio === activeRadio;
643
+ radio.tabIndex = isRadioActive && !this.disabled && !radio.disabled ? 0 : -1;
644
+ });
645
+ }
646
+ // ── Event Handlers ─────────────────────────────────────────────────────────
647
+ _handleRadioChecked(e) {
648
+ const targetRadio = e.target;
649
+ if (this.disabled) return;
650
+ const oldValue = this.value;
651
+ this.value = targetRadio.value;
652
+ this._updateRadios();
653
+ if (this.value !== oldValue) {
654
+ this.dispatchEvent(new CustomEvent('vialiq-change', {
655
+ detail: {
656
+ value: this.value
657
+ },
658
+ bubbles: true,
659
+ composed: true
660
+ }));
661
+ }
662
+ }
663
+ _onKeydown(e) {
664
+ if (this.disabled) return;
665
+ const radios = this._getRadios().filter((r)=>!r.disabled);
666
+ if (radios.length === 0) return;
667
+ const eventTarget = e.target;
668
+ // Find index of the child radio that received the keydown event
669
+ const currentIndex = radios.findIndex((r)=>r === eventTarget || r.contains(eventTarget));
670
+ if (currentIndex === -1) return;
671
+ let nextIndex = currentIndex;
672
+ let shouldPreventDefault = false;
673
+ switch(e.key){
674
+ case 'ArrowDown':
675
+ case 'ArrowRight':
676
+ nextIndex = (currentIndex + 1) % radios.length;
677
+ shouldPreventDefault = true;
678
+ break;
679
+ case 'ArrowUp':
680
+ case 'ArrowLeft':
681
+ nextIndex = (currentIndex - 1 + radios.length) % radios.length;
682
+ shouldPreventDefault = true;
683
+ break;
684
+ case ' ':
685
+ nextIndex = currentIndex;
686
+ shouldPreventDefault = true;
687
+ break;
688
+ default:
689
+ return;
690
+ }
691
+ if (shouldPreventDefault) {
692
+ e.preventDefault();
693
+ }
694
+ const targetRadio = radios[nextIndex];
695
+ if (targetRadio) {
696
+ const oldValue = this.value;
697
+ this.value = targetRadio.value;
698
+ this._updateRadios();
699
+ targetRadio.focus();
700
+ if (this.value !== oldValue) {
701
+ this.dispatchEvent(new CustomEvent('vialiq-change', {
702
+ detail: {
703
+ value: this.value
704
+ },
705
+ bubbles: true,
706
+ composed: true
707
+ }));
708
+ }
709
+ }
710
+ }
711
+ _onDblclick = (e)=>{
712
+ if (this.disabled || !this.allowDblclickClear) return;
713
+ const targetRadio = e.target.closest('vi-radio');
714
+ if (!targetRadio || targetRadio.disabled) return;
715
+ if (targetRadio.checked && this.value === targetRadio.value) {
716
+ const oldValue = this.value;
717
+ this.value = '';
718
+ this._updateRadios();
719
+ if (this.value !== oldValue) {
720
+ this.dispatchEvent(new CustomEvent('vialiq-change', {
721
+ detail: {
722
+ value: this.value
723
+ },
724
+ bubbles: true,
725
+ composed: true
726
+ }));
727
+ }
728
+ }
729
+ };
730
+ // ── Render ─────────────────────────────────────────────────────────────────
731
+ get _validationMessage() {
732
+ if (!this.validityMessage) return html``;
733
+ const cls = this.status === 'invalid' ? 'radio-group-validation--invalid' : this.status === 'valid' ? 'radio-group-validation--valid' : '';
734
+ return html`
735
+ <span
736
+ id="validation-message"
737
+ class="radio-group-validation ${cls}"
738
+ part="validation"
739
+ role="alert"
740
+ aria-live="polite"
741
+ >
742
+ ${this.validityMessage}
743
+ </span>
744
+ `;
745
+ }
746
+ render() {
747
+ const { required, status, orientation } = this;
748
+ return html`
749
+ <fieldset
750
+ class="radio-group"
751
+ role="radiogroup"
752
+ aria-required=${required ? 'true' : 'false'}
753
+ aria-invalid=${status === 'invalid' ? 'true' : 'false'}
754
+ aria-describedby=${this.validityMessage ? 'validation-message' : undefined}
755
+ aria-errormessage=${status === 'invalid' && this.validityMessage ? 'validation-message' : undefined}
756
+ @vi-radio-checked=${this._handleRadioChecked}
757
+ @keydown=${this._onKeydown}
758
+ >
759
+ <legend class="radio-group-legend" part="legend">
760
+ <slot name="label"></slot>
761
+ </legend>
762
+ <div
763
+ class="radio-group-items"
764
+ part="items"
765
+ orientation=${orientation}
766
+ >
767
+ <slot></slot>
768
+ </div>
769
+ <div class="radio-group-helper" part="helper">
770
+ <slot name="helper"></slot>
771
+ </div>
772
+ ${this._validationMessage}
773
+ </fieldset>
774
+ `;
775
+ }
776
+ }
777
+ }
778
+ }();
779
+
780
+ export { _ViRadioGroup as ViRadioGroup };