@auriel/peppertino 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.
Files changed (139) hide show
  1. package/CHANGELOG.txt +242 -136
  2. package/LICENSE +21 -21
  3. package/MIGRATION.md +52 -0
  4. package/README.md +773 -622
  5. package/agents/peppertino/SKILL.md +76 -0
  6. package/agents/peppertino/accordion.md +134 -0
  7. package/agents/peppertino/alert.md +116 -0
  8. package/agents/peppertino/badge.md +74 -0
  9. package/agents/peppertino/base.md +252 -0
  10. package/agents/peppertino/button.md +65 -0
  11. package/agents/peppertino/card.md +82 -0
  12. package/agents/peppertino/carousel.md +147 -0
  13. package/agents/peppertino/catalog.md +81 -0
  14. package/agents/peppertino/dark-mode.md +152 -0
  15. package/agents/peppertino/footer.md +109 -0
  16. package/agents/peppertino/forms-fieldset.md +85 -0
  17. package/agents/peppertino/forms-form-instructions.md +94 -0
  18. package/agents/peppertino/forms-label.md +110 -0
  19. package/agents/peppertino/forms-text-field.md +134 -0
  20. package/agents/peppertino/forms-validation.md +153 -0
  21. package/agents/peppertino/gradient.md +41 -0
  22. package/agents/peppertino/header.md +105 -0
  23. package/agents/peppertino/modal.md +123 -0
  24. package/agents/peppertino/section.md +56 -0
  25. package/agents/peppertino/select.md +110 -0
  26. package/agents/peppertino/switch.md +72 -0
  27. package/agents/peppertino/table.md +69 -0
  28. package/agents/peppertino/tabs.md +115 -0
  29. package/agents/peppertino/toast.md +96 -0
  30. package/agents/peppertino/tooltip.md +111 -0
  31. package/agents/peppertino/typography.md +118 -0
  32. package/agents/peppertino/utilities.md +194 -0
  33. package/agents/skill.md +65 -0
  34. package/build.js +53 -53
  35. package/dist/accordion.js +41 -4
  36. package/dist/accordion.js.map +2 -2
  37. package/dist/alert.js +26 -0
  38. package/dist/alert.js.map +7 -0
  39. package/dist/carousel.js +4 -0
  40. package/dist/carousel.js.map +2 -2
  41. package/dist/header.js +1 -0
  42. package/dist/header.js.map +2 -2
  43. package/dist/main.css +3610 -1343
  44. package/dist/main.css.map +1 -1
  45. package/dist/main.min.css +1 -0
  46. package/dist/modal.js +2 -0
  47. package/dist/modal.js.map +2 -2
  48. package/dist/peppertino.js +244 -15
  49. package/dist/peppertino.js.map +3 -3
  50. package/dist/select.js +2 -4
  51. package/dist/select.js.map +2 -2
  52. package/dist/switch.js +29 -0
  53. package/dist/switch.js.map +7 -0
  54. package/dist/tabs.js +27 -7
  55. package/dist/tabs.js.map +2 -2
  56. package/dist/theme.js +47 -0
  57. package/dist/theme.js.map +7 -0
  58. package/dist/toast.js +69 -0
  59. package/dist/toast.js.map +7 -0
  60. package/dist/validation.js.map +1 -1
  61. package/icon.svg +4 -0
  62. package/index.html +2172 -1902
  63. package/package.json +28 -26
  64. package/scripts/hex-to-hsl.mjs +75 -0
  65. package/scripts/lint-bem.mjs +53 -0
  66. package/scripts/lint-colors.mjs +87 -0
  67. package/site.webmanifest +18 -0
  68. package/src/js/accordion.js +105 -61
  69. package/src/js/alert.js +28 -0
  70. package/src/js/carousel.js +153 -148
  71. package/src/js/header.js +85 -84
  72. package/src/js/modal.js +138 -134
  73. package/src/js/peppertino.js +15 -11
  74. package/src/js/select.js +101 -103
  75. package/src/js/switch.js +28 -0
  76. package/src/js/tabs.js +104 -94
  77. package/src/js/theme.js +47 -0
  78. package/src/js/toast.js +79 -0
  79. package/src/js/validation.js +132 -132
  80. package/src/scss/accordion.scss +190 -156
  81. package/src/scss/activity.scss +17 -0
  82. package/src/scss/alert.scss +203 -204
  83. package/src/scss/badge.scss +90 -0
  84. package/src/scss/base.scss +511 -305
  85. package/src/scss/button.scss +119 -121
  86. package/src/scss/card.scss +121 -121
  87. package/src/scss/carousel.scss +303 -313
  88. package/src/scss/code-block.scss +22 -0
  89. package/src/scss/counter.scss +5 -0
  90. package/src/scss/dark-mode.scss +514 -474
  91. package/src/scss/duration.scss +26 -0
  92. package/src/scss/folder.scss +27 -0
  93. package/src/scss/footer.scss +224 -224
  94. package/src/scss/forms/fieldset.scss +127 -127
  95. package/src/scss/forms/form-instructions.scss +133 -133
  96. package/src/scss/forms/label.scss +115 -115
  97. package/src/scss/forms/text-field.scss +240 -240
  98. package/src/scss/forms/validation.scss +215 -215
  99. package/src/scss/forms.scss +8 -8
  100. package/src/scss/gradient.scss +11 -11
  101. package/src/scss/gravity-letters.scss +7 -0
  102. package/src/scss/header.scss +257 -238
  103. package/src/scss/helpers/color.scss +9 -0
  104. package/src/scss/helpers/flex.scss +14 -0
  105. package/src/scss/helpers/index.scss +6 -0
  106. package/src/scss/helpers/layout.scss +14 -0
  107. package/src/scss/helpers/spacing.scss +14 -0
  108. package/src/scss/helpers/typography.scss +11 -0
  109. package/src/scss/helpers/visibility.scss +9 -0
  110. package/src/scss/main.scss +49 -20
  111. package/src/scss/modal.scss +188 -188
  112. package/src/scss/model-picker.scss +5 -0
  113. package/src/scss/notification.scss +5 -0
  114. package/src/scss/orb.scss +7 -0
  115. package/src/scss/otp.scss +5 -0
  116. package/src/scss/pill-nav.scss +10 -0
  117. package/src/scss/prompt.scss +28 -0
  118. package/src/scss/rail.scss +7 -0
  119. package/src/scss/reactions.scss +5 -0
  120. package/src/scss/reset.scss +84 -84
  121. package/src/scss/response.scss +11 -0
  122. package/src/scss/reveal.scss +5 -0
  123. package/src/scss/scroll-progress.scss +4 -0
  124. package/src/scss/search-results.scss +13 -0
  125. package/src/scss/section.scss +87 -79
  126. package/src/scss/select.scss +210 -210
  127. package/src/scss/sidebar.scss +8 -0
  128. package/src/scss/status.scss +5 -0
  129. package/src/scss/step-list.scss +13 -0
  130. package/src/scss/switch.scss +121 -0
  131. package/src/scss/table.scss +89 -89
  132. package/src/scss/tabs.scss +156 -156
  133. package/src/scss/task-list.scss +18 -0
  134. package/src/scss/theme-picker.scss +5 -0
  135. package/src/scss/toast.scss +170 -0
  136. package/src/scss/tooltip.scss +126 -0
  137. package/src/scss/typography.scss +58 -58
  138. package/src/scss/utilities.scss +243 -243
  139. package/src/scss/voice-note.scss +5 -0
package/src/js/modal.js CHANGED
@@ -1,134 +1,138 @@
1
- (function () {
2
- const FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
3
- let lastFocused = null;
4
-
5
- document.querySelectorAll('.pp-modal-backdrop').forEach((backdrop) => {
6
- backdrop.classList.add('is-animated');
7
- backdrop.setAttribute('aria-hidden', 'true');
8
-
9
- // Role and modal semantics (skip if native <dialog>)
10
- if (!(backdrop instanceof HTMLDialogElement)) {
11
- backdrop.setAttribute('role', 'dialog');
12
- backdrop.setAttribute('aria-modal', 'true');
13
- }
14
-
15
- // Wire aria-labelledby to the modal title if present
16
- const modal = backdrop.querySelector('.pp-modal');
17
- const title = modal?.querySelector('.pp-modal__title');
18
- if (title) {
19
- if (!title.id) title.id = `pp-modal-title-${backdrop.id}`;
20
- backdrop.setAttribute('aria-labelledby', title.id);
21
- }
22
-
23
- // Wire aria-describedby to description if present
24
- const desc = modal?.querySelector('.pp-modal__description');
25
- if (desc) {
26
- if (!desc.id) desc.id = `pp-modal-desc-${backdrop.id}`;
27
- backdrop.setAttribute('aria-describedby', desc.id);
28
- }
29
- });
30
-
31
- function getFocusable(backdrop) {
32
- return [...backdrop.querySelectorAll(FOCUSABLE)];
33
- }
34
-
35
- function trapFocus(e, backdrop) {
36
- const focusable = getFocusable(backdrop);
37
- if (!focusable.length) return;
38
- const first = focusable[0];
39
- const last = focusable[focusable.length - 1];
40
-
41
- if (e.key === 'Tab') {
42
- if (e.shiftKey) {
43
- if (document.activeElement === first) { e.preventDefault(); last.focus(); }
44
- } else {
45
- if (document.activeElement === last) { e.preventDefault(); first.focus(); }
46
- }
47
- }
48
- }
49
-
50
- function openModal(id) {
51
- const backdrop = document.getElementById(id);
52
- if (!backdrop) return;
53
-
54
- lastFocused = document.activeElement;
55
-
56
- if (backdrop instanceof HTMLDialogElement) {
57
- backdrop.showModal();
58
- } else {
59
- backdrop.classList.add('is-open');
60
- }
61
-
62
- backdrop.removeAttribute('aria-hidden');
63
- backdrop.setAttribute('aria-hidden', 'false');
64
-
65
- const focusable = getFocusable(backdrop);
66
- if (focusable.length) focusable[0].focus();
67
-
68
- backdrop._trapFocus = (e) => trapFocus(e, backdrop);
69
- backdrop.addEventListener('keydown', backdrop._trapFocus);
70
- }
71
-
72
- function closeModal(id) {
73
- const backdrop = document.getElementById(id);
74
- if (!backdrop) return;
75
-
76
- if (backdrop instanceof HTMLDialogElement) {
77
- backdrop.close();
78
- } else {
79
- backdrop.classList.remove('is-open');
80
- }
81
-
82
- backdrop.setAttribute('aria-hidden', 'true');
83
-
84
- if (backdrop._trapFocus) {
85
- backdrop.removeEventListener('keydown', backdrop._trapFocus);
86
- delete backdrop._trapFocus;
87
- }
88
-
89
- // Restore focus to the element that opened the modal
90
- if (lastFocused && typeof lastFocused.focus === 'function') {
91
- lastFocused.focus();
92
- lastFocused = null;
93
- }
94
- }
95
-
96
- function closeAll() {
97
- document.querySelectorAll('.pp-modal-backdrop').forEach((b) => {
98
- if (b instanceof HTMLDialogElement) b.close();
99
- else b.classList.remove('is-open');
100
- b.setAttribute('aria-hidden', 'true');
101
- if (b._trapFocus) {
102
- b.removeEventListener('keydown', b._trapFocus);
103
- delete b._trapFocus;
104
- }
105
- });
106
- if (lastFocused && typeof lastFocused.focus === 'function') {
107
- lastFocused.focus();
108
- lastFocused = null;
109
- }
110
- }
111
-
112
- // Close on backdrop click outside .pp-modal
113
- document.querySelectorAll('.pp-modal-backdrop').forEach((backdrop) => {
114
- backdrop.addEventListener('click', (e) => {
115
- if (e.target === backdrop) closeModal(backdrop.id);
116
- });
117
- });
118
-
119
- // Escape key
120
- document.addEventListener('keydown', (e) => {
121
- if (e.key === 'Escape') closeAll();
122
- });
123
-
124
- // data-modal-open / data-modal-close triggers
125
- document.querySelectorAll('[data-modal-open]').forEach((el) => {
126
- el.addEventListener('click', () => openModal(el.dataset.modalOpen));
127
- });
128
-
129
- document.querySelectorAll('[data-modal-close]').forEach((el) => {
130
- el.addEventListener('click', () => closeModal(el.dataset.modalClose));
131
- });
132
-
133
- window.ppModal = { open: openModal, close: closeModal, closeAll };
134
- })();
1
+ (function () {
2
+ const FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
3
+ let lastFocused = null;
4
+
5
+ document.querySelectorAll('.pp-modal-backdrop').forEach((backdrop) => {
6
+ backdrop.classList.add('is-animated');
7
+ backdrop.setAttribute('aria-hidden', 'true');
8
+
9
+ // Role and modal semantics (skip if native <dialog>)
10
+ if (!(backdrop instanceof HTMLDialogElement)) {
11
+ backdrop.setAttribute('role', 'dialog');
12
+ backdrop.setAttribute('aria-modal', 'true');
13
+ }
14
+
15
+ // Wire aria-labelledby to the modal title if present
16
+ const modal = backdrop.querySelector('.pp-modal');
17
+ const title = modal?.querySelector('.pp-modal__title');
18
+ if (title) {
19
+ if (!title.id) title.id = `pp-modal-title-${backdrop.id}`;
20
+ backdrop.setAttribute('aria-labelledby', title.id);
21
+ }
22
+
23
+ // Wire aria-describedby to description if present
24
+ const desc = modal?.querySelector('.pp-modal__description');
25
+ if (desc) {
26
+ if (!desc.id) desc.id = `pp-modal-desc-${backdrop.id}`;
27
+ backdrop.setAttribute('aria-describedby', desc.id);
28
+ }
29
+ });
30
+
31
+ function getFocusable(backdrop) {
32
+ return [...backdrop.querySelectorAll(FOCUSABLE)];
33
+ }
34
+
35
+ function trapFocus(e, backdrop) {
36
+ const focusable = getFocusable(backdrop);
37
+ if (!focusable.length) return;
38
+ const first = focusable[0];
39
+ const last = focusable[focusable.length - 1];
40
+
41
+ if (e.key === 'Tab') {
42
+ if (e.shiftKey) {
43
+ if (document.activeElement === first) { e.preventDefault(); last.focus(); }
44
+ } else {
45
+ if (document.activeElement === last) { e.preventDefault(); first.focus(); }
46
+ }
47
+ }
48
+ }
49
+
50
+ function openModal(id) {
51
+ const backdrop = document.getElementById(id);
52
+ if (!backdrop) return;
53
+
54
+ lastFocused = document.activeElement;
55
+
56
+ if (backdrop instanceof HTMLDialogElement) {
57
+ backdrop.showModal();
58
+ } else {
59
+ backdrop.classList.add('is-open');
60
+ }
61
+
62
+ backdrop.removeAttribute('aria-hidden');
63
+ backdrop.setAttribute('aria-hidden', 'false');
64
+
65
+ const focusable = getFocusable(backdrop);
66
+ if (focusable.length) focusable[0].focus();
67
+
68
+ backdrop._trapFocus = (e) => trapFocus(e, backdrop);
69
+ backdrop.addEventListener('keydown', backdrop._trapFocus);
70
+
71
+ backdrop.dispatchEvent(new CustomEvent('pp:modal:open', { bubbles: true }));
72
+ }
73
+
74
+ function closeModal(id) {
75
+ const backdrop = document.getElementById(id);
76
+ if (!backdrop) return;
77
+
78
+ if (backdrop instanceof HTMLDialogElement) {
79
+ backdrop.close();
80
+ } else {
81
+ backdrop.classList.remove('is-open');
82
+ }
83
+
84
+ backdrop.setAttribute('aria-hidden', 'true');
85
+
86
+ if (backdrop._trapFocus) {
87
+ backdrop.removeEventListener('keydown', backdrop._trapFocus);
88
+ delete backdrop._trapFocus;
89
+ }
90
+
91
+ backdrop.dispatchEvent(new CustomEvent('pp:modal:close', { bubbles: true }));
92
+
93
+ // Restore focus to the element that opened the modal
94
+ if (lastFocused && typeof lastFocused.focus === 'function') {
95
+ lastFocused.focus();
96
+ lastFocused = null;
97
+ }
98
+ }
99
+
100
+ function closeAll() {
101
+ document.querySelectorAll('.pp-modal-backdrop').forEach((b) => {
102
+ if (b instanceof HTMLDialogElement) b.close();
103
+ else b.classList.remove('is-open');
104
+ b.setAttribute('aria-hidden', 'true');
105
+ if (b._trapFocus) {
106
+ b.removeEventListener('keydown', b._trapFocus);
107
+ delete b._trapFocus;
108
+ }
109
+ });
110
+ if (lastFocused && typeof lastFocused.focus === 'function') {
111
+ lastFocused.focus();
112
+ lastFocused = null;
113
+ }
114
+ }
115
+
116
+ // Close on backdrop click outside .pp-modal
117
+ document.querySelectorAll('.pp-modal-backdrop').forEach((backdrop) => {
118
+ backdrop.addEventListener('click', (e) => {
119
+ if (e.target === backdrop) closeModal(backdrop.id);
120
+ });
121
+ });
122
+
123
+ // Escape key
124
+ document.addEventListener('keydown', (e) => {
125
+ if (e.key === 'Escape') closeAll();
126
+ });
127
+
128
+ // data-modal-open / data-modal-close triggers
129
+ document.querySelectorAll('[data-modal-open]').forEach((el) => {
130
+ el.addEventListener('click', () => openModal(el.dataset.modalOpen));
131
+ });
132
+
133
+ document.querySelectorAll('[data-modal-close]').forEach((el) => {
134
+ el.addEventListener('click', () => closeModal(el.dataset.modalClose));
135
+ });
136
+
137
+ window.ppModal = { open: openModal, close: closeModal, closeAll };
138
+ })();
@@ -1,11 +1,15 @@
1
- // PeppertinoCSS — aggregator
2
- // Imports all JS components so users can include a single <script> tag.
3
- // Each component is a self-contained IIFE in its own file — import only what you need.
4
-
5
- import './accordion.js';
6
- import './carousel.js';
7
- import './header.js';
8
- import './modal.js';
9
- import './select.js';
10
- import './tabs.js';
11
- import './validation.js';
1
+ // PeppertinoCSS — aggregator
2
+ // Imports all JS components so users can include a single <script> tag.
3
+ // Each component is a self-contained IIFE in its own file — import only what you need.
4
+
5
+ import './accordion.js';
6
+ import './alert.js';
7
+ import './carousel.js';
8
+ import './header.js';
9
+ import './modal.js';
10
+ import './select.js';
11
+ import './switch.js';
12
+ import './tabs.js';
13
+ import './theme.js';
14
+ import './toast.js';
15
+ import './validation.js';
package/src/js/select.js CHANGED
@@ -1,103 +1,101 @@
1
- (function () {
2
- function initSelect(wrapper, idx) {
3
- const trigger = wrapper.querySelector('.pp-select__trigger');
4
- const panel = wrapper.querySelector('.pp-select__panel');
5
- const options = wrapper.querySelectorAll('.pp-select__option');
6
- const valueEl = wrapper.querySelector('.pp-select__value');
7
-
8
- if (!trigger || !panel) return;
9
-
10
- // IDs for aria-controls / aria-activedescendant
11
- const panelId = panel.id || `pp-select-panel-${idx}`;
12
- panel.id = panelId;
13
-
14
- options.forEach((opt, i) => {
15
- if (!opt.id) opt.id = `pp-select-opt-${idx}-${i}`;
16
- opt.setAttribute('role', 'option');
17
- opt.setAttribute('aria-selected', opt.classList.contains('is-selected') ? 'true' : 'false');
18
- });
19
-
20
- panel.setAttribute('role', 'listbox');
21
- trigger.setAttribute('role', 'combobox');
22
- trigger.setAttribute('aria-haspopup', 'listbox');
23
- trigger.setAttribute('aria-expanded', 'false');
24
- trigger.setAttribute('aria-controls', panelId);
25
-
26
- // Set initial aria-activedescendant to the selected option
27
- const selected = wrapper.querySelector('.pp-select__option.is-selected');
28
- if (selected) trigger.setAttribute('aria-activedescendant', selected.id);
29
-
30
- function open() {
31
- wrapper.classList.add('is-open');
32
- trigger.setAttribute('aria-expanded', 'true');
33
- panel.removeAttribute('hidden');
34
- }
35
-
36
- function close() {
37
- wrapper.classList.remove('is-open');
38
- trigger.setAttribute('aria-expanded', 'false');
39
- panel.setAttribute('hidden', '');
40
- }
41
-
42
- function toggle() {
43
- wrapper.classList.contains('is-open') ? close() : open();
44
- }
45
-
46
- // Initial state — JS takes over from :focus-within
47
- panel.setAttribute('hidden', '');
48
-
49
- trigger.addEventListener('click', (e) => {
50
- e.stopPropagation();
51
- toggle();
52
- });
53
-
54
- // Option selection
55
- options.forEach((opt) => {
56
- opt.addEventListener('click', () => {
57
- options.forEach((o) => {
58
- o.classList.remove('is-selected');
59
- o.setAttribute('aria-selected', 'false');
60
- });
61
- opt.classList.add('is-selected');
62
- opt.setAttribute('aria-selected', 'true');
63
- trigger.setAttribute('aria-activedescendant', opt.id);
64
-
65
- if (valueEl) valueEl.textContent = opt.textContent.trim();
66
-
67
- const nativeSelect = wrapper.querySelector('select[data-pp-select]');
68
- if (nativeSelect) nativeSelect.value = opt.dataset.value ?? opt.textContent.trim();
69
-
70
- wrapper.dispatchEvent(new CustomEvent('pp-select:change', {
71
- bubbles: true,
72
- detail: { value: opt.dataset.value, label: opt.textContent.trim() },
73
- }));
74
-
75
- close();
76
- trigger.focus();
77
- });
78
- });
79
-
80
- // Keyboard navigation
81
- trigger.addEventListener('keydown', (e) => {
82
- if (e.key === 'ArrowDown') { e.preventDefault(); open(); options[0]?.focus(); }
83
- if (e.key === 'Escape') close();
84
- });
85
-
86
- panel.addEventListener('keydown', (e) => {
87
- const focusable = [...options];
88
- const idx = focusable.indexOf(document.activeElement);
89
-
90
- if (e.key === 'ArrowDown') { e.preventDefault(); focusable[idx + 1]?.focus(); }
91
- if (e.key === 'ArrowUp') { e.preventDefault(); idx > 0 ? focusable[idx - 1]?.focus() : trigger.focus(); }
92
- if (e.key === 'Escape') { close(); trigger.focus(); }
93
- if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); document.activeElement?.click(); }
94
- });
95
-
96
- // Close on outside click
97
- document.addEventListener('click', (e) => {
98
- if (!wrapper.contains(e.target)) close();
99
- });
100
- }
101
-
102
- document.querySelectorAll('.pp-select').forEach((el, i) => initSelect(el, i));
103
- })();
1
+ (function () {
2
+ function initSelect(wrapper, idx) {
3
+ const trigger = wrapper.querySelector('.pp-select__trigger');
4
+ const panel = wrapper.querySelector('.pp-select__panel');
5
+ const options = wrapper.querySelectorAll('.pp-select__option');
6
+ const valueEl = wrapper.querySelector('.pp-select__value');
7
+
8
+ if (!trigger || !panel) return;
9
+
10
+ // IDs for aria-controls / aria-activedescendant
11
+ const panelId = panel.id || `pp-select-panel-${idx}`;
12
+ panel.id = panelId;
13
+
14
+ options.forEach((opt, i) => {
15
+ if (!opt.id) opt.id = `pp-select-opt-${idx}-${i}`;
16
+ opt.setAttribute('role', 'option');
17
+ opt.setAttribute('aria-selected', opt.classList.contains('is-selected') ? 'true' : 'false');
18
+ });
19
+
20
+ panel.setAttribute('role', 'listbox');
21
+ trigger.setAttribute('role', 'combobox');
22
+ trigger.setAttribute('aria-haspopup', 'listbox');
23
+ trigger.setAttribute('aria-expanded', 'false');
24
+ trigger.setAttribute('aria-controls', panelId);
25
+
26
+ // Set initial aria-activedescendant to the selected option
27
+ const selected = wrapper.querySelector('.pp-select__option.is-selected');
28
+ if (selected) trigger.setAttribute('aria-activedescendant', selected.id);
29
+
30
+ function open() {
31
+ wrapper.classList.add('is-open');
32
+ trigger.setAttribute('aria-expanded', 'true');
33
+ panel.removeAttribute('hidden');
34
+ }
35
+
36
+ function close() {
37
+ wrapper.classList.remove('is-open');
38
+ trigger.setAttribute('aria-expanded', 'false');
39
+ panel.setAttribute('hidden', '');
40
+ }
41
+
42
+ function toggle() {
43
+ wrapper.classList.contains('is-open') ? close() : open();
44
+ }
45
+
46
+ // Initial state — JS takes over from :focus-within
47
+ panel.setAttribute('hidden', '');
48
+
49
+ trigger.addEventListener('click', (e) => {
50
+ e.stopPropagation();
51
+ toggle();
52
+ });
53
+
54
+ // Option selection
55
+ options.forEach((opt) => {
56
+ opt.addEventListener('click', () => {
57
+ options.forEach((o) => {
58
+ o.classList.remove('is-selected');
59
+ o.setAttribute('aria-selected', 'false');
60
+ });
61
+ opt.classList.add('is-selected');
62
+ opt.setAttribute('aria-selected', 'true');
63
+ trigger.setAttribute('aria-activedescendant', opt.id);
64
+
65
+ if (valueEl) valueEl.textContent = opt.textContent.trim();
66
+
67
+ const nativeSelect = wrapper.querySelector('select[data-pp-select]');
68
+ if (nativeSelect) nativeSelect.value = opt.dataset.value ?? opt.textContent.trim();
69
+
70
+ const detail = { value: opt.dataset.value, label: opt.textContent.trim() };
71
+ wrapper.dispatchEvent(new CustomEvent('pp:select:change', { bubbles: true, detail }));
72
+
73
+ close();
74
+ trigger.focus();
75
+ });
76
+ });
77
+
78
+ // Keyboard navigation
79
+ trigger.addEventListener('keydown', (e) => {
80
+ if (e.key === 'ArrowDown') { e.preventDefault(); open(); options[0]?.focus(); }
81
+ if (e.key === 'Escape') close();
82
+ });
83
+
84
+ panel.addEventListener('keydown', (e) => {
85
+ const focusable = [...options];
86
+ const idx = focusable.indexOf(document.activeElement);
87
+
88
+ if (e.key === 'ArrowDown') { e.preventDefault(); focusable[idx + 1]?.focus(); }
89
+ if (e.key === 'ArrowUp') { e.preventDefault(); idx > 0 ? focusable[idx - 1]?.focus() : trigger.focus(); }
90
+ if (e.key === 'Escape') { close(); trigger.focus(); }
91
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); document.activeElement?.click(); }
92
+ });
93
+
94
+ // Close on outside click
95
+ document.addEventListener('click', (e) => {
96
+ if (!wrapper.contains(e.target)) close();
97
+ });
98
+ }
99
+
100
+ document.querySelectorAll('.pp-select').forEach((el, i) => initSelect(el, i));
101
+ })();
@@ -0,0 +1,28 @@
1
+ (function () {
2
+ function initSwitch(el) {
3
+ if (el.dataset.ppSwitchInit) return;
4
+ el.dataset.ppSwitchInit = '1';
5
+
6
+ function toggle() {
7
+ if (el.disabled || el.getAttribute('aria-disabled') === 'true') return;
8
+ const checked = el.getAttribute('aria-checked') === 'true';
9
+ const next = !checked;
10
+ el.setAttribute('aria-checked', String(next));
11
+ el.dispatchEvent(new CustomEvent('pp:switch:change', {
12
+ bubbles: true,
13
+ detail: { checked: next },
14
+ }));
15
+ }
16
+
17
+ el.addEventListener('click', toggle);
18
+ el.addEventListener('keydown', (e) => {
19
+ if (e.key === ' ') { e.preventDefault(); toggle(); }
20
+ });
21
+
22
+ // Ensure role is set
23
+ if (!el.getAttribute('role')) el.setAttribute('role', 'switch');
24
+ if (!el.getAttribute('aria-checked')) el.setAttribute('aria-checked', 'false');
25
+ }
26
+
27
+ document.querySelectorAll('[role="switch"], .pp-switch').forEach(initSwitch);
28
+ })();