@sebgroup/green-core 1.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js ADDED
@@ -0,0 +1,1065 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result)
9
+ __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ var __accessCheck = (obj, member, msg2) => {
13
+ if (!member.has(obj))
14
+ throw TypeError("Cannot " + msg2);
15
+ };
16
+ var __privateGet = (obj, member, getter) => {
17
+ __accessCheck(obj, member, "read from private field");
18
+ return getter ? getter.call(obj) : member.get(obj);
19
+ };
20
+ var __privateAdd = (obj, member, value) => {
21
+ if (member.has(obj))
22
+ throw TypeError("Cannot add the same private member more than once");
23
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
24
+ };
25
+ var __privateSet = (obj, member, value, setter) => {
26
+ __accessCheck(obj, member, "write to private field");
27
+ setter ? setter.call(obj, value) : member.set(obj, value);
28
+ return value;
29
+ };
30
+ var __privateMethod = (obj, member, method) => {
31
+ __accessCheck(obj, member, "access private method");
32
+ return method;
33
+ };
34
+
35
+ // libs/core/src/components/dropdown/dropdown.ts
36
+ import { property as property5 } from "lit/decorators.js";
37
+ import { unsafeHTML } from "lit/directives/unsafe-html.js";
38
+ import { when as when2 } from "lit/directives/when.js";
39
+ import { ifDefined } from "lit/directives/if-defined.js";
40
+ import { createRef as createRef2, ref as ref2 } from "lit/directives/ref.js";
41
+ import { msg, str, updateWhenLocaleChanges } from "@lit/localize";
42
+ import "reflect-metadata";
43
+
44
+ // libs/core/src/utils/helpers/constrain-slots.ts
45
+ function constrainSlots(self) {
46
+ self.updateComplete.then(() => {
47
+ const slots = self.shadowRoot?.querySelectorAll("slot[gds-allow]");
48
+ if (!slots)
49
+ return;
50
+ for (const node of Array.from(self.childNodes)) {
51
+ if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim() === "") {
52
+ node.parentNode?.removeChild(node);
53
+ }
54
+ }
55
+ const constrain = (slot) => {
56
+ const allowed = slot.getAttribute("gds-allow")?.split(" ") || [];
57
+ for (const node of Array.from(slot.assignedNodes())) {
58
+ if (!allowed.includes(node.nodeName.toLowerCase())) {
59
+ node.parentNode?.removeChild(node);
60
+ }
61
+ }
62
+ };
63
+ slots.forEach((slot) => {
64
+ constrain(slot);
65
+ slot.addEventListener("slotchange", () => constrain(slot));
66
+ });
67
+ });
68
+ }
69
+
70
+ // libs/core/src/utils/helpers/id.ts
71
+ var randomId = () => "gds-" + Math.random().toString(36).substring(2, 9);
72
+
73
+ // libs/core/src/utils/decorators/watch.ts
74
+ function watch(propertyName, options) {
75
+ const resolvedOptions = {
76
+ waitUntilFirstUpdate: false,
77
+ ...options
78
+ };
79
+ return (proto, propertyKey, descriptor) => {
80
+ const { update } = proto;
81
+ const watchedProperties = Array.isArray(propertyName) ? propertyName : [propertyName];
82
+ proto.update = function(changedProps) {
83
+ watchedProperties.forEach((property6) => {
84
+ const key = property6;
85
+ if (changedProps.has(key)) {
86
+ const oldValue = changedProps.get(key);
87
+ const newValue = this[key];
88
+ if (oldValue !== newValue) {
89
+ if (!resolvedOptions.waitUntilFirstUpdate || this.hasUpdated) {
90
+ descriptor.value?.call(this, oldValue, newValue);
91
+ }
92
+ }
93
+ }
94
+ });
95
+ update.call(this, changedProps);
96
+ };
97
+ };
98
+ }
99
+
100
+ // libs/core/src/utils/decorators/observe-light-dom.ts
101
+ function observeLightDOM() {
102
+ return (proto, _propertyKey, descriptor) => {
103
+ const observerConfig = { attributes: true, childList: true, subtree: false };
104
+ let observer;
105
+ const connectedCallback = proto.connectedCallback;
106
+ const disconnectedCallback = proto.disconnectedCallback;
107
+ proto.connectedCallback = function() {
108
+ connectedCallback?.call(this);
109
+ const callback = (_mutationList, _observer) => {
110
+ descriptor.value?.call(this);
111
+ };
112
+ observer = new MutationObserver(callback);
113
+ observer.observe(this, observerConfig);
114
+ };
115
+ proto.disconnectedCallback = function() {
116
+ disconnectedCallback?.call(this);
117
+ observer.disconnect();
118
+ };
119
+ };
120
+ }
121
+
122
+ // libs/core/src/utils/helpers/custom-element-scoping.ts
123
+ import { html as litHtml } from "lit";
124
+ import { customElement } from "lit/decorators.js";
125
+ var VER_SUFFIX = "-gdsvsuffix";
126
+ var elementLookupTable = /* @__PURE__ */ new Map();
127
+ var gdsCustomElement = (tagName) => {
128
+ if (globalThis.GDS_DISABLE_VERSIONED_ELEMENTS) {
129
+ return customElement(tagName);
130
+ }
131
+ const versionedTagName = tagName + VER_SUFFIX;
132
+ elementLookupTable.set(tagName, versionedTagName);
133
+ return customElement(versionedTagName);
134
+ };
135
+ var templateCache = /* @__PURE__ */ new WeakMap();
136
+ function applyElementScoping(strings, ...values) {
137
+ let modstrings = templateCache.get(strings);
138
+ if (!modstrings) {
139
+ modstrings = replaceTags(strings);
140
+ modstrings.raw = replaceTags(strings.raw);
141
+ templateCache.set(strings, modstrings);
142
+ }
143
+ return [modstrings, ...values];
144
+ }
145
+ var replaceTags = (inStr) => inStr.map((s) => {
146
+ for (const [key, value] of elementLookupTable.entries()) {
147
+ s = s.split(key).join(value);
148
+ }
149
+ return s;
150
+ });
151
+ function htmlTemplateTagFactory(extendedTag) {
152
+ return (strings, ...values) => {
153
+ if (globalThis.GDS_DISABLE_VERSIONED_ELEMENTS) {
154
+ return extendedTag(strings, ...values);
155
+ }
156
+ const [modstrings, ...modvalues] = applyElementScoping(strings, ...values);
157
+ return extendedTag(modstrings, ...modvalues);
158
+ };
159
+ }
160
+ var html = htmlTemplateTagFactory(litHtml);
161
+ function getScopedTagName(tagName) {
162
+ return elementLookupTable.get(tagName) ?? tagName;
163
+ }
164
+ function getUnscopedTagName(tagName) {
165
+ return [...elementLookupTable.entries()].find(
166
+ ([, value]) => value === tagName
167
+ )?.[0];
168
+ }
169
+
170
+ // libs/core/src/primitives/listbox/listbox.ts
171
+ import { LitElement as LitElement2 } from "lit";
172
+ import { property as property2 } from "lit/decorators.js";
173
+ import { createRef, ref } from "lit/directives/ref.js";
174
+
175
+ // libs/core/src/utils/helpers/transitional-styles.ts
176
+ var TransitionalStyles = class {
177
+ constructor() {
178
+ this.sheets = /* @__PURE__ */ new Map();
179
+ this.elements = /* @__PURE__ */ new Map();
180
+ }
181
+ static get instance() {
182
+ if (!globalThis.__gdsTransitionalStyles)
183
+ globalThis.__gdsTransitionalStyles = new TransitionalStyles();
184
+ return globalThis.__gdsTransitionalStyles;
185
+ }
186
+ apply(element, styleKey) {
187
+ const sheet = this.sheets.get(styleKey);
188
+ if (!sheet || !element.shadowRoot)
189
+ return;
190
+ this.elements.set(styleKey, element);
191
+ this.applyToElement(styleKey, sheet);
192
+ }
193
+ applyToElement(styleKey, sheet) {
194
+ const element = this.elements.get(styleKey);
195
+ if (!element || !element.shadowRoot)
196
+ return;
197
+ element.shadowRoot.adoptedStyleSheets = [sheet];
198
+ }
199
+ register(name, styles) {
200
+ const sheet = new CSSStyleSheet();
201
+ sheet.replaceSync(styles);
202
+ this.sheets.set(name, sheet);
203
+ this.applyToElement(name, sheet);
204
+ }
205
+ };
206
+
207
+ // libs/core/src/primitives/listbox/option.ts
208
+ import { LitElement, html as html2 } from "lit";
209
+ import { property } from "lit/decorators.js";
210
+ import { when } from "lit/directives/when.js";
211
+ import { classMap } from "lit/directives/class-map.js";
212
+
213
+ // libs/core/src/primitives/listbox/option.styles.ts
214
+ import { css } from "lit";
215
+ var style = css`
216
+ :host {
217
+ padding: 0.5 1rem;
218
+ cursor: pointer;
219
+ }
220
+
221
+ :host(:hover) {
222
+ background-color: grey;
223
+ }
224
+ `;
225
+ var option_styles_default = style;
226
+
227
+ // libs/core/src/primitives/listbox/option.ts
228
+ import "reflect-metadata";
229
+ var _hidden, _emitSelect, emitSelect_fn;
230
+ var GdsOption = class extends LitElement {
231
+ constructor() {
232
+ super();
233
+ __privateAdd(this, _emitSelect);
234
+ __privateAdd(this, _hidden, false);
235
+ this.selected = false;
236
+ this.isPlaceholder = false;
237
+ this.onblur = (e) => {
238
+ this.setAttribute("tabindex", "-1");
239
+ this.dispatchEvent(
240
+ new FocusEvent("gds-blur", {
241
+ bubbles: true,
242
+ composed: true,
243
+ relatedTarget: e.relatedTarget
244
+ })
245
+ );
246
+ };
247
+ this.onfocus = (e) => {
248
+ this.dispatchEvent(
249
+ new FocusEvent("gds-focus", {
250
+ bubbles: true,
251
+ composed: true,
252
+ relatedTarget: e.relatedTarget
253
+ })
254
+ );
255
+ };
256
+ this.addEventListener("click", __privateMethod(this, _emitSelect, emitSelect_fn));
257
+ this.addEventListener("keydown", (e) => {
258
+ if (e.key !== "Enter" && e.key !== " ")
259
+ return;
260
+ e.preventDefault();
261
+ __privateMethod(this, _emitSelect, emitSelect_fn).call(this);
262
+ });
263
+ }
264
+ get hidden() {
265
+ return __privateGet(this, _hidden);
266
+ }
267
+ set hidden(value) {
268
+ if (this.isPlaceholder)
269
+ return;
270
+ __privateSet(this, _hidden, value === "true" || value === true);
271
+ this.setAttribute("aria-hidden", value.toString());
272
+ }
273
+ connectedCallback() {
274
+ super.connectedCallback();
275
+ this.setAttribute("role", "option");
276
+ if (this.isPlaceholder) {
277
+ __privateSet(this, _hidden, true);
278
+ this.setAttribute("aria-hidden", "true");
279
+ }
280
+ this.updateComplete.then(
281
+ () => TransitionalStyles.instance.apply(this, "gds-option")
282
+ );
283
+ }
284
+ get parentElement() {
285
+ return super.parentElement;
286
+ }
287
+ handlePlaceholderStatusChange() {
288
+ if (this.isPlaceholder) {
289
+ __privateSet(this, _hidden, true);
290
+ this.setAttribute("aria-hidden", "true");
291
+ } else {
292
+ __privateSet(this, _hidden, false);
293
+ this.setAttribute("aria-hidden", "false");
294
+ }
295
+ }
296
+ /**
297
+ * Focuses the option.
298
+ *
299
+ * @param options - Focus options
300
+ */
301
+ focus(options) {
302
+ this.setAttribute("tabindex", "0");
303
+ super.focus(options);
304
+ if (document.activeElement !== this) {
305
+ const iv = setInterval(() => {
306
+ if (document.activeElement === this)
307
+ clearInterval(iv);
308
+ super.focus(options);
309
+ }, 10);
310
+ }
311
+ }
312
+ render() {
313
+ const isMultiple = this.parentElement.multiple;
314
+ const checkbox = html2`<span
315
+ class="checkbox ${classMap({ checked: this.selected })}"
316
+ ></span>`;
317
+ if (!isMultiple) {
318
+ if (this.selected)
319
+ this.setAttribute("highlighted", "");
320
+ else
321
+ this.removeAttribute("highlighted");
322
+ }
323
+ return html2`${when(isMultiple, () => checkbox)}<slot></slot>`;
324
+ }
325
+ };
326
+ _hidden = new WeakMap();
327
+ _emitSelect = new WeakSet();
328
+ emitSelect_fn = function() {
329
+ this.dispatchEvent(
330
+ new CustomEvent("gds-select", {
331
+ bubbles: true,
332
+ composed: true,
333
+ detail: {
334
+ value: this.value
335
+ }
336
+ })
337
+ );
338
+ };
339
+ GdsOption.styles = option_styles_default;
340
+ __decorateClass([
341
+ property()
342
+ ], GdsOption.prototype, "value", 2);
343
+ __decorateClass([
344
+ property({
345
+ attribute: "aria-hidden",
346
+ reflect: true
347
+ })
348
+ ], GdsOption.prototype, "hidden", 1);
349
+ __decorateClass([
350
+ property({
351
+ attribute: "aria-selected",
352
+ reflect: true
353
+ })
354
+ ], GdsOption.prototype, "selected", 2);
355
+ __decorateClass([
356
+ property({ type: Boolean, reflect: true })
357
+ ], GdsOption.prototype, "isPlaceholder", 2);
358
+ __decorateClass([
359
+ watch("isplaceholder")
360
+ ], GdsOption.prototype, "handlePlaceholderStatusChange", 1);
361
+ GdsOption = __decorateClass([
362
+ gdsCustomElement("gds-option")
363
+ ], GdsOption);
364
+
365
+ // libs/core/src/primitives/listbox/listbox.ts
366
+ import "reflect-metadata";
367
+
368
+ // libs/core/src/primitives/listbox/listbox.styles.ts
369
+ import { css as css2 } from "lit";
370
+ var style2 = css2`
371
+ :host {
372
+ display: flex;
373
+ flex-direction: column;
374
+ }
375
+ `;
376
+ var listbox_styles_default = style2;
377
+
378
+ // libs/core/src/primitives/listbox/listbox.ts
379
+ var _slotRef, _handleSelect, _keyboardNavigationHandler;
380
+ var GdsListbox = class extends LitElement2 {
381
+ constructor() {
382
+ super();
383
+ this.multiple = false;
384
+ __privateAdd(this, _slotRef, createRef());
385
+ __privateAdd(this, _handleSelect, (e) => {
386
+ const option = e.target;
387
+ if (this.multiple)
388
+ option.selected = !option.selected;
389
+ else {
390
+ option.selected = true;
391
+ Array.from(this.options).forEach((el) => {
392
+ if (el !== option)
393
+ el.selected = false;
394
+ });
395
+ }
396
+ ;
397
+ this.ariaActiveDescendantElement = option;
398
+ this.dispatchEvent(
399
+ new CustomEvent("change", {
400
+ bubbles: false,
401
+ composed: false
402
+ })
403
+ );
404
+ });
405
+ __privateAdd(this, _keyboardNavigationHandler, (e) => {
406
+ if (!(e.target instanceof GdsOption))
407
+ return;
408
+ let handled = false;
409
+ if (e.key === "ArrowDown") {
410
+ const nextOptionIndex = this.visibleOptionElements.indexOf(e.target) + 1;
411
+ const nextItem = this.visibleOptionElements[nextOptionIndex];
412
+ nextItem?.focus();
413
+ handled = true;
414
+ } else if (e.key === "ArrowUp") {
415
+ const prevOptionIndex = this.visibleOptionElements.indexOf(e.target) - 1;
416
+ const prevItem = this.visibleOptionElements[prevOptionIndex];
417
+ prevItem?.focus();
418
+ handled = true;
419
+ } else if (e.key === "Home") {
420
+ this.visibleOptionElements[0]?.focus();
421
+ handled = true;
422
+ } else if (e.key === "End") {
423
+ this.visibleOptionElements[this.visibleOptionElements.length - 1]?.focus();
424
+ handled = true;
425
+ } else {
426
+ const key = e.key.toLowerCase();
427
+ if (key.length !== 1) {
428
+ return;
429
+ }
430
+ const isLetter = key >= "a" && key <= "z";
431
+ const isNumber = key >= "0" && key <= "9";
432
+ if (isLetter || isNumber) {
433
+ const firstMatch = this.visibleOptionElements.find((el) => {
434
+ const text = el.textContent?.trim().toLowerCase();
435
+ return text?.startsWith(key);
436
+ });
437
+ firstMatch?.focus();
438
+ handled = true;
439
+ }
440
+ }
441
+ if (handled) {
442
+ e.preventDefault();
443
+ e.stopPropagation();
444
+ }
445
+ });
446
+ }
447
+ /**
448
+ * Returns a list of all `gds-option` elements in the listbox.
449
+ */
450
+ get options() {
451
+ let slot = __privateGet(this, _slotRef).value;
452
+ if (!slot)
453
+ return [];
454
+ while (slot.assignedElements().length > 0 && slot.assignedElements()[0].nodeName === "SLOT") {
455
+ slot = slot.assignedElements()[0];
456
+ }
457
+ return slot.assignedElements().filter(
458
+ (o) => !o.hasAttribute("isplaceholder")
459
+ ) || [];
460
+ }
461
+ /**
462
+ * Returns a list of all visible `gds-option` elements in the listbox.
463
+ */
464
+ get visibleOptionElements() {
465
+ return this.options.filter((el) => !el.hidden);
466
+ }
467
+ /**
468
+ * Returns a list of all visible `gds-option` elements in the listbox.
469
+ */
470
+ get visibleSelectedOptionElements() {
471
+ return this.options.filter((el) => el.selected && !el.hidden);
472
+ }
473
+ /**
474
+ * Returns a list of all selected `gds-option` elements in the listbox.
475
+ */
476
+ get selection() {
477
+ return this.options.filter((el) => el.selected);
478
+ }
479
+ set selection(values) {
480
+ this.options.forEach((el) => {
481
+ el.selected = values.includes(el.value) || values.includes(el);
482
+ });
483
+ }
484
+ connectedCallback() {
485
+ super.connectedCallback();
486
+ this.setAttribute("role", "listbox");
487
+ TransitionalStyles.instance.apply(this, "gds-listbox");
488
+ this.addEventListener("keydown", __privateGet(this, _keyboardNavigationHandler));
489
+ this.addEventListener("gds-select", __privateGet(this, _handleSelect));
490
+ }
491
+ /**
492
+ * Focuses the first selected option in the listbox.
493
+ * If no option is selected, the first visible option is focused.
494
+ */
495
+ focus() {
496
+ ;
497
+ (this.visibleSelectedOptionElements[0] || this.visibleOptionElements[0])?.focus();
498
+ }
499
+ render() {
500
+ return html`<slot ${ref(__privateGet(this, _slotRef))}></slot>`;
501
+ }
502
+ _rerenderOptions() {
503
+ this.options.forEach((el) => {
504
+ el.requestUpdate();
505
+ });
506
+ }
507
+ };
508
+ _slotRef = new WeakMap();
509
+ _handleSelect = new WeakMap();
510
+ _keyboardNavigationHandler = new WeakMap();
511
+ GdsListbox.styles = listbox_styles_default;
512
+ __decorateClass([
513
+ property2({
514
+ type: Boolean,
515
+ reflect: true,
516
+ attribute: "aria-multiselectable",
517
+ converter: {
518
+ fromAttribute: Boolean,
519
+ toAttribute: (value) => value.toString()
520
+ }
521
+ })
522
+ ], GdsListbox.prototype, "multiple", 2);
523
+ __decorateClass([
524
+ watch("multiple")
525
+ ], GdsListbox.prototype, "_rerenderOptions", 1);
526
+ GdsListbox = __decorateClass([
527
+ gdsCustomElement("gds-listbox")
528
+ ], GdsListbox);
529
+
530
+ // libs/core/src/primitives/popover/popover.ts
531
+ import { LitElement as LitElement3, html as html3, unsafeCSS as unsafeCSS3 } from "lit";
532
+ import { property as property3 } from "lit/decorators.js";
533
+ import { computePosition, autoUpdate, offset, flip } from "@floating-ui/dom";
534
+
535
+ // libs/core/src/primitives/popover/popover.styles.ts
536
+ import { css as css3 } from "lit";
537
+ var style3 = css3`
538
+ :host {
539
+ position: absolute;
540
+ background-color: white;
541
+ box-shadow: 0 1rem 1rem 1rem rgba(0, 0, 0, 0.1);
542
+ }
543
+ `;
544
+ var popover_styles_default = style3;
545
+
546
+ // libs/core/src/primitives/popover/popover.ts
547
+ var _autoPositionCleanup, _registerTriggerEvents, registerTriggerEvents_fn, _unregisterTriggerEvents, unregisterTriggerEvents_fn, _triggerKeyDownListener, _setOpen, setOpen_fn;
548
+ var GdsPopover = class extends LitElement3 {
549
+ constructor() {
550
+ super(...arguments);
551
+ __privateAdd(this, _registerTriggerEvents);
552
+ __privateAdd(this, _unregisterTriggerEvents);
553
+ __privateAdd(this, _setOpen);
554
+ this.open = false;
555
+ this.trigger = void 0;
556
+ __privateAdd(this, _autoPositionCleanup, void 0);
557
+ /**
558
+ * ArrowDown on the trigger element will trigger the popover by default, and escape will close it.
559
+ */
560
+ __privateAdd(this, _triggerKeyDownListener, (e) => {
561
+ if (e.key === "ArrowDown") {
562
+ e.preventDefault();
563
+ __privateMethod(this, _setOpen, setOpen_fn).call(this, true);
564
+ const firstSlottedChild = this.shadowRoot?.querySelector("slot")?.assignedElements()[0];
565
+ this.updateComplete.then(() => {
566
+ firstSlottedChild?.focus();
567
+ });
568
+ }
569
+ if (e.key === "Escape") {
570
+ __privateMethod(this, _setOpen, setOpen_fn).call(this, false);
571
+ }
572
+ });
573
+ }
574
+ _handleTriggerChanged() {
575
+ __privateMethod(this, _registerTriggerEvents, registerTriggerEvents_fn).call(this);
576
+ }
577
+ connectedCallback() {
578
+ super.connectedCallback();
579
+ TransitionalStyles.instance.apply(this, "gds-popover");
580
+ __privateMethod(this, _registerTriggerEvents, registerTriggerEvents_fn).call(this);
581
+ this._updateHidden();
582
+ this.addEventListener("keydown", (e) => {
583
+ if (e.key === "Escape") {
584
+ __privateMethod(this, _setOpen, setOpen_fn).call(this, false);
585
+ }
586
+ });
587
+ }
588
+ disconnectedCallback() {
589
+ super.disconnectedCallback();
590
+ __privateMethod(this, _unregisterTriggerEvents, unregisterTriggerEvents_fn).call(this);
591
+ }
592
+ render() {
593
+ return html3` <slot></slot> `;
594
+ }
595
+ _updateHidden() {
596
+ this.setAttribute("aria-hidden", String(!this.open));
597
+ this.hidden = !this.open;
598
+ }
599
+ };
600
+ _autoPositionCleanup = new WeakMap();
601
+ _registerTriggerEvents = new WeakSet();
602
+ registerTriggerEvents_fn = function() {
603
+ if (!this.trigger)
604
+ return;
605
+ this.trigger.addEventListener("keydown", __privateGet(this, _triggerKeyDownListener));
606
+ const referenceEl = this.trigger;
607
+ __privateSet(this, _autoPositionCleanup, autoUpdate(referenceEl, this, () => {
608
+ computePosition(referenceEl, this, {
609
+ placement: "bottom-start",
610
+ middleware: [offset(8), flip()]
611
+ }).then(({ x, y }) => {
612
+ Object.assign(this.style, {
613
+ left: `${x}px`,
614
+ top: `${y}px`
615
+ });
616
+ });
617
+ }));
618
+ };
619
+ _unregisterTriggerEvents = new WeakSet();
620
+ unregisterTriggerEvents_fn = function() {
621
+ var _a;
622
+ this.trigger?.removeEventListener("keydown", __privateGet(this, _triggerKeyDownListener));
623
+ (_a = __privateGet(this, _autoPositionCleanup)) == null ? void 0 : _a.call(this);
624
+ };
625
+ _triggerKeyDownListener = new WeakMap();
626
+ _setOpen = new WeakSet();
627
+ setOpen_fn = function(open) {
628
+ this.open = open;
629
+ this.dispatchEvent(
630
+ new CustomEvent("gds-ui-state", {
631
+ detail: { open },
632
+ bubbles: true,
633
+ composed: false
634
+ })
635
+ );
636
+ };
637
+ GdsPopover.styles = unsafeCSS3(popover_styles_default);
638
+ __decorateClass([
639
+ property3({ type: Boolean, reflect: true })
640
+ ], GdsPopover.prototype, "open", 2);
641
+ __decorateClass([
642
+ property3()
643
+ ], GdsPopover.prototype, "trigger", 2);
644
+ __decorateClass([
645
+ watch("trigger")
646
+ ], GdsPopover.prototype, "_handleTriggerChanged", 1);
647
+ __decorateClass([
648
+ watch("open")
649
+ ], GdsPopover.prototype, "_updateHidden", 1);
650
+ GdsPopover = __decorateClass([
651
+ gdsCustomElement("gds-popover")
652
+ ], GdsPopover);
653
+
654
+ // libs/core/src/components/form-control.ts
655
+ import { LitElement as LitElement4 } from "lit";
656
+ import { property as property4 } from "lit/decorators.js";
657
+ var _internals, _handleFormReset;
658
+ var GdsFormControlElement = class extends LitElement4 {
659
+ constructor() {
660
+ super();
661
+ __privateAdd(this, _internals, void 0);
662
+ this.invalid = false;
663
+ this.name = "";
664
+ /**
665
+ * Event handler for the form reset event.
666
+ */
667
+ __privateAdd(this, _handleFormReset, () => {
668
+ this.value = void 0;
669
+ });
670
+ __privateSet(this, _internals, this.attachInternals());
671
+ }
672
+ get form() {
673
+ return __privateGet(this, _internals).form;
674
+ }
675
+ get type() {
676
+ return getUnscopedTagName(this.localName) || "gds-form-control";
677
+ }
678
+ get validity() {
679
+ return __privateGet(this, _internals).validity;
680
+ }
681
+ get validationMessage() {
682
+ return __privateGet(this, _internals).validationMessage;
683
+ }
684
+ get willValidate() {
685
+ return __privateGet(this, _internals).willValidate;
686
+ }
687
+ checkValidity() {
688
+ return __privateGet(this, _internals).checkValidity();
689
+ }
690
+ reportValidity() {
691
+ return __privateGet(this, _internals).reportValidity();
692
+ }
693
+ connectedCallback() {
694
+ super.connectedCallback();
695
+ __privateGet(this, _internals).form?.addEventListener("reset", __privateGet(this, _handleFormReset));
696
+ }
697
+ disconnectedCallback() {
698
+ super.disconnectedCallback();
699
+ __privateGet(this, _internals).form?.removeEventListener("reset", __privateGet(this, _handleFormReset));
700
+ }
701
+ __handleValidityChange() {
702
+ __privateGet(this, _internals).setValidity(
703
+ {
704
+ badInput: false,
705
+ customError: this.invalid,
706
+ patternMismatch: false,
707
+ rangeOverflow: false,
708
+ rangeUnderflow: false,
709
+ stepMismatch: false,
710
+ tooLong: false,
711
+ tooShort: false,
712
+ typeMismatch: false,
713
+ valueMissing: false
714
+ },
715
+ this.validationMessage || "Error message"
716
+ );
717
+ }
718
+ __handleValueChange() {
719
+ __privateGet(this, _internals).setFormValue(this.value);
720
+ }
721
+ };
722
+ _internals = new WeakMap();
723
+ _handleFormReset = new WeakMap();
724
+ GdsFormControlElement.formAssociated = true;
725
+ __decorateClass([
726
+ property4({
727
+ type: Boolean,
728
+ reflect: true,
729
+ attribute: "aria-invalid",
730
+ converter: {
731
+ fromAttribute: Boolean,
732
+ toAttribute: (value) => value?.toString()
733
+ }
734
+ })
735
+ ], GdsFormControlElement.prototype, "invalid", 2);
736
+ __decorateClass([
737
+ property4()
738
+ ], GdsFormControlElement.prototype, "value", 2);
739
+ __decorateClass([
740
+ property4({ reflect: true })
741
+ ], GdsFormControlElement.prototype, "name", 2);
742
+ __decorateClass([
743
+ watch("invalid")
744
+ ], GdsFormControlElement.prototype, "__handleValidityChange", 1);
745
+ __decorateClass([
746
+ watch("value")
747
+ ], GdsFormControlElement.prototype, "__handleValueChange", 1);
748
+
749
+ // libs/core/src/components/dropdown/dropdown.styles.ts
750
+ import { css as css4 } from "lit";
751
+ var style4 = css4`
752
+ button {
753
+ appearance: none;
754
+ display: block;
755
+ background-color: black;
756
+ border-radius: 2rem;
757
+ border: none;
758
+ color: white;
759
+ padding: 0.7rem 2rem;
760
+ margin: 0.5rem 0;
761
+ }
762
+ `;
763
+ var dropdown_styles_default = style4;
764
+
765
+ // libs/core/src/components/dropdown/dropdown.ts
766
+ var _listboxRef, _triggerRef, _searchInputRef, _optionElements, _listboxId, _triggerId, _handleSearchFieldKeyUp, _handleSearchFieldKeyDown, _handleOptionFocusChange, _registerPopoverTrigger, registerPopoverTrigger_fn, _handleSelectionChange, handleSelectionChange_fn, _registerAutoCloseListener, registerAutoCloseListener_fn, _unregisterAutoCloseListener, unregisterAutoCloseListener_fn, _autoCloseListener;
767
+ var GdsDropdown = class extends GdsFormControlElement {
768
+ constructor() {
769
+ super();
770
+ /**
771
+ * Registers the trigger button of the dropdown to the popover.
772
+ *
773
+ * @param el The popover element.
774
+ */
775
+ __privateAdd(this, _registerPopoverTrigger);
776
+ /**
777
+ * Selects an option in the dropdown.
778
+ *
779
+ * @fires change
780
+ */
781
+ __privateAdd(this, _handleSelectionChange);
782
+ __privateAdd(this, _registerAutoCloseListener);
783
+ __privateAdd(this, _unregisterAutoCloseListener);
784
+ this.label = "";
785
+ this.open = false;
786
+ this.searchable = false;
787
+ this.multiple = false;
788
+ // Private members
789
+ __privateAdd(this, _listboxRef, createRef2());
790
+ __privateAdd(this, _triggerRef, createRef2());
791
+ __privateAdd(this, _searchInputRef, createRef2());
792
+ __privateAdd(this, _optionElements, void 0);
793
+ __privateAdd(this, _listboxId, randomId());
794
+ __privateAdd(this, _triggerId, randomId());
795
+ /**
796
+ * Event handler for filtering the options in the dropdown.
797
+ *
798
+ * @param e The keyboard event.
799
+ */
800
+ __privateAdd(this, _handleSearchFieldKeyUp, (e) => {
801
+ const input = e.target;
802
+ const options = Array.from(__privateGet(this, _optionElements));
803
+ options.forEach((o) => o.hidden = false);
804
+ if (!input.value)
805
+ return;
806
+ const filteredOptions = options.filter(
807
+ (o) => !o.innerHTML.toLowerCase().includes(input.value.toLowerCase())
808
+ );
809
+ filteredOptions.forEach((o) => o.hidden = true);
810
+ });
811
+ /**
812
+ * Check for ArrowDown in the search field.
813
+ * If found, focus should be moved to the listbox.
814
+ */
815
+ __privateAdd(this, _handleSearchFieldKeyDown, (e) => {
816
+ if (e.key === "ArrowDown") {
817
+ __privateGet(this, _listboxRef).value?.focus();
818
+ return;
819
+ }
820
+ });
821
+ __privateAdd(this, _handleOptionFocusChange, (e) => {
822
+ const triggerButton = __privateGet(this, _triggerRef).value;
823
+ if (triggerButton)
824
+ triggerButton.ariaActiveDescendantElement = e.target;
825
+ });
826
+ /**
827
+ * A listener to close the dropdown when clicking outside of it,
828
+ * or when any other element recieves a keyup event.
829
+ */
830
+ __privateAdd(this, _autoCloseListener, (e) => {
831
+ const isClickOutside = e instanceof MouseEvent && e.target instanceof Node && !this.contains(e.target);
832
+ const isFocusOutside = e instanceof FocusEvent && e.relatedTarget && !this.contains(e.relatedTarget);
833
+ if (isClickOutside || isFocusOutside)
834
+ this.open = false;
835
+ });
836
+ constrainSlots(this);
837
+ updateWhenLocaleChanges(this);
838
+ __privateSet(this, _optionElements, this.getElementsByTagName(
839
+ getScopedTagName("gds-option")
840
+ ));
841
+ }
842
+ connectedCallback() {
843
+ super.connectedCallback();
844
+ TransitionalStyles.instance.apply(this, "gds-dropdown");
845
+ this.updateComplete.then(() => {
846
+ this._handleLightDOMChange();
847
+ this._handleValueChange();
848
+ });
849
+ }
850
+ /**
851
+ * Get the options of the dropdown.
852
+ */
853
+ get options() {
854
+ return Array.from(__privateGet(this, _optionElements)).filter(
855
+ (o) => !o.hasAttribute("isplaceholder")
856
+ );
857
+ }
858
+ /**
859
+ * Return the first option with a isPlaceholder attribute.
860
+ * If no placeholder is found, this will be undefined.
861
+ */
862
+ get placeholder() {
863
+ return Array.from(__privateGet(this, _optionElements)).find(
864
+ (o) => o.hasAttribute("isplaceholder")
865
+ );
866
+ }
867
+ /**
868
+ * Returns the display value as a string.
869
+ * If the dropdown is in multiple mode, this will be a comma separated list of the selected values.
870
+ */
871
+ get displayValue() {
872
+ let displayValue;
873
+ if (Array.isArray(this.value)) {
874
+ this.value.length > 2 ? displayValue = msg(str`${this.value.length} selected`) : displayValue = this.value.reduce(
875
+ (acc, cur) => acc + this.options.find((v) => v.value === cur)?.innerHTML + ", ",
876
+ ""
877
+ ).slice(0, -2);
878
+ } else {
879
+ displayValue = this.options.find((v) => v.selected)?.innerHTML;
880
+ }
881
+ return displayValue || this.placeholder?.innerHTML || "";
882
+ }
883
+ render() {
884
+ return html`
885
+ ${when2(
886
+ this.label,
887
+ () => html`<label for="${__privateGet(this, _triggerId)}">${this.label}</label>`
888
+ )}
889
+
890
+ <span class="form-info"><slot name="sub-label"></slot></span>
891
+
892
+ <button
893
+ id="${__privateGet(this, _triggerId)}"
894
+ @click="${() => this.open = !this.open}"
895
+ aria-haspopup="listbox"
896
+ role="combobox"
897
+ aria-owns="${__privateGet(this, _listboxId)}"
898
+ aria-controls="${__privateGet(this, _listboxId)}"
899
+ aria-expanded="${this.open}"
900
+ ${ref2(__privateGet(this, _triggerRef))}
901
+ >
902
+ <slot name="trigger">
903
+ <span>${unsafeHTML(this.displayValue)}</span>
904
+ </slot>
905
+ </button>
906
+
907
+ <span class="form-info"><slot name="message"></slot></span>
908
+
909
+ <gds-popover
910
+ .open=${this.open}
911
+ @gds-ui-state=${(e) => this.open = e.detail.open}
912
+ ${ref2(__privateMethod(this, _registerPopoverTrigger, registerPopoverTrigger_fn))}
913
+ >
914
+ ${when2(
915
+ this.searchable,
916
+ () => html`<input
917
+ type="text"
918
+ aria-label="${msg("Filter available options")}"
919
+ placeholder="${msg("Search")}"
920
+ ${ref2(__privateGet(this, _searchInputRef))}
921
+ @keydown=${__privateGet(this, _handleSearchFieldKeyDown)}
922
+ @keyup=${__privateGet(this, _handleSearchFieldKeyUp)}
923
+ />`
924
+ )}
925
+
926
+ <gds-listbox
927
+ id="${__privateGet(this, _listboxId)}"
928
+ .multiple="${ifDefined(this.multiple)}"
929
+ ${ref2(__privateGet(this, _listboxRef))}
930
+ @change="${__privateMethod(this, _handleSelectionChange, handleSelectionChange_fn)}"
931
+ @gds-focus="${__privateGet(this, _handleOptionFocusChange)}"
932
+ >
933
+ <slot gds-allow="gds-option"></slot>
934
+ </gds-listbox>
935
+ </gds-popover>
936
+ `;
937
+ }
938
+ _handleLightDOMChange() {
939
+ this.requestUpdate();
940
+ if (this.multiple)
941
+ return;
942
+ if (!this.value) {
943
+ if (this.placeholder)
944
+ this.value = this.placeholder.value;
945
+ else
946
+ this.value = this.options[0]?.value;
947
+ } else if (!this.placeholder && this.options.find((o) => o.value === this.value) === void 0) {
948
+ this.options[0] && (this.options[0].selected = true);
949
+ this.value = this.options[0]?.value;
950
+ }
951
+ }
952
+ _handleValueChange() {
953
+ const listbox = __privateGet(this, _listboxRef).value;
954
+ if (listbox) {
955
+ if (Array.isArray(this.value))
956
+ listbox.selection = this.value;
957
+ else
958
+ listbox.selection = [this.value];
959
+ }
960
+ }
961
+ _onOpenChange() {
962
+ const open = this.open;
963
+ if (open)
964
+ __privateMethod(this, _registerAutoCloseListener, registerAutoCloseListener_fn).call(this);
965
+ else {
966
+ __privateMethod(this, _unregisterAutoCloseListener, unregisterAutoCloseListener_fn).call(this);
967
+ __privateGet(this, _searchInputRef).value && (__privateGet(this, _searchInputRef).value.value = "");
968
+ Array.from(__privateGet(this, _optionElements)).forEach((o) => o.hidden = false);
969
+ }
970
+ this.dispatchEvent(
971
+ new CustomEvent("gds-ui-state", {
972
+ detail: { open },
973
+ bubbles: true,
974
+ composed: true
975
+ })
976
+ );
977
+ }
978
+ };
979
+ _listboxRef = new WeakMap();
980
+ _triggerRef = new WeakMap();
981
+ _searchInputRef = new WeakMap();
982
+ _optionElements = new WeakMap();
983
+ _listboxId = new WeakMap();
984
+ _triggerId = new WeakMap();
985
+ _handleSearchFieldKeyUp = new WeakMap();
986
+ _handleSearchFieldKeyDown = new WeakMap();
987
+ _handleOptionFocusChange = new WeakMap();
988
+ _registerPopoverTrigger = new WeakSet();
989
+ registerPopoverTrigger_fn = function(el) {
990
+ if (el) {
991
+ const popover = el;
992
+ popover.trigger = __privateGet(this, _triggerRef).value;
993
+ }
994
+ };
995
+ _handleSelectionChange = new WeakSet();
996
+ handleSelectionChange_fn = function() {
997
+ const listbox = __privateGet(this, _listboxRef).value;
998
+ if (!listbox)
999
+ return;
1000
+ if (this.multiple)
1001
+ this.value = listbox.selection.map((s) => s.value);
1002
+ else {
1003
+ this.value = listbox.selection[0]?.value;
1004
+ this.open = false;
1005
+ setTimeout(() => __privateGet(this, _triggerRef).value?.focus(), 0);
1006
+ }
1007
+ this.dispatchEvent(
1008
+ new CustomEvent("change", {
1009
+ detail: { value: this.value },
1010
+ bubbles: true,
1011
+ composed: true
1012
+ })
1013
+ );
1014
+ };
1015
+ _registerAutoCloseListener = new WeakSet();
1016
+ registerAutoCloseListener_fn = function() {
1017
+ window.addEventListener("click", __privateGet(this, _autoCloseListener));
1018
+ this.addEventListener("blur", __privateGet(this, _autoCloseListener));
1019
+ this.addEventListener("gds-blur", __privateGet(this, _autoCloseListener));
1020
+ };
1021
+ _unregisterAutoCloseListener = new WeakSet();
1022
+ unregisterAutoCloseListener_fn = function() {
1023
+ window.removeEventListener("click", __privateGet(this, _autoCloseListener));
1024
+ this.removeEventListener("blur", __privateGet(this, _autoCloseListener));
1025
+ this.removeEventListener("gds-blur", __privateGet(this, _autoCloseListener));
1026
+ };
1027
+ _autoCloseListener = new WeakMap();
1028
+ GdsDropdown.styles = dropdown_styles_default;
1029
+ GdsDropdown.shadowRootOptions = {
1030
+ mode: "open",
1031
+ delegatesFocus: true
1032
+ };
1033
+ __decorateClass([
1034
+ property5()
1035
+ ], GdsDropdown.prototype, "label", 2);
1036
+ __decorateClass([
1037
+ property5({ type: Boolean, reflect: true })
1038
+ ], GdsDropdown.prototype, "open", 2);
1039
+ __decorateClass([
1040
+ property5({ type: Boolean, reflect: true })
1041
+ ], GdsDropdown.prototype, "searchable", 2);
1042
+ __decorateClass([
1043
+ property5({ type: Boolean, reflect: true })
1044
+ ], GdsDropdown.prototype, "multiple", 2);
1045
+ __decorateClass([
1046
+ observeLightDOM()
1047
+ ], GdsDropdown.prototype, "_handleLightDOMChange", 1);
1048
+ __decorateClass([
1049
+ watch("value")
1050
+ ], GdsDropdown.prototype, "_handleValueChange", 1);
1051
+ __decorateClass([
1052
+ watch("open")
1053
+ ], GdsDropdown.prototype, "_onOpenChange", 1);
1054
+ GdsDropdown = __decorateClass([
1055
+ gdsCustomElement("gds-dropdown")
1056
+ ], GdsDropdown);
1057
+ export {
1058
+ GdsDropdown,
1059
+ GdsOption,
1060
+ gdsCustomElement,
1061
+ getScopedTagName,
1062
+ getUnscopedTagName,
1063
+ html,
1064
+ htmlTemplateTagFactory
1065
+ };