@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/tabs.js CHANGED
@@ -1,94 +1,104 @@
1
- (function () {
2
- function initTabs(tabGroup, groupIdx) {
3
- const items = tabGroup.querySelectorAll('.pp-tabs__item');
4
- const targetAttr = 'data-tab-target';
5
-
6
- // Ensure tablist role
7
- if (!tabGroup.getAttribute('role')) tabGroup.setAttribute('role', 'tablist');
8
-
9
- // Wire up tab roles and aria-controls
10
- items.forEach((item, i) => {
11
- item.setAttribute('role', 'tab');
12
- if (!item.id) item.id = `pp-tab-${groupIdx}-${i}`;
13
-
14
- const targetId = item.getAttribute(targetAttr);
15
- if (targetId) {
16
- item.setAttribute('aria-controls', targetId);
17
- const panel = document.querySelector(`[data-tab-panel="${targetId}"]`);
18
- if (panel) {
19
- if (!panel.id) panel.id = targetId;
20
- panel.setAttribute('role', 'tabpanel');
21
- panel.setAttribute('aria-labelledby', item.id);
22
- }
23
- }
24
- });
25
-
26
- function activate(item) {
27
- items.forEach((i) => {
28
- i.classList.remove('is-active');
29
- i.setAttribute('aria-selected', 'false');
30
- i.setAttribute('tabindex', '-1');
31
- });
32
-
33
- item.classList.add('is-active');
34
- item.setAttribute('aria-selected', 'true');
35
- item.setAttribute('tabindex', '0');
36
-
37
- // Show/hide associated panels if present
38
- const targetId = item.getAttribute(targetAttr);
39
- if (targetId) {
40
- document.querySelectorAll('[data-tab-panel]').forEach((panel) => {
41
- const isVisible = panel.getAttribute('data-tab-panel') === targetId;
42
- panel.hidden = !isVisible;
43
- panel.setAttribute('aria-hidden', String(!isVisible));
44
- });
45
- }
46
-
47
- tabGroup.dispatchEvent(new CustomEvent('pp-tabs:change', {
48
- bubbles: true,
49
- detail: { value: item.dataset.tabTarget, label: item.textContent.trim() },
50
- }));
51
- }
52
-
53
- // Click
54
- items.forEach((item) => {
55
- item.addEventListener('click', () => activate(item));
56
- });
57
-
58
- // Keyboard: left/right arrow navigation
59
- tabGroup.addEventListener('keydown', (e) => {
60
- const current = [...items].findIndex((i) => i === document.activeElement);
61
- if (current === -1) return;
62
-
63
- if (e.key === 'ArrowRight') {
64
- e.preventDefault();
65
- const next = items[(current + 1) % items.length];
66
- activate(next);
67
- next.focus();
68
- }
69
- if (e.key === 'ArrowLeft') {
70
- e.preventDefault();
71
- const prev = items[(current - 1 + items.length) % items.length];
72
- activate(prev);
73
- prev.focus();
74
- }
75
- if (e.key === 'Home') {
76
- e.preventDefault();
77
- activate(items[0]);
78
- items[0].focus();
79
- }
80
- if (e.key === 'End') {
81
- e.preventDefault();
82
- activate(items[items.length - 1]);
83
- items[items.length - 1].focus();
84
- }
85
- });
86
-
87
- // Set initial tabindex
88
- items.forEach((item) => {
89
- item.setAttribute('tabindex', item.classList.contains('is-active') ? '0' : '-1');
90
- });
91
- }
92
-
93
- document.querySelectorAll('.pp-tabs').forEach((el, i) => initTabs(el, i));
94
- })();
1
+ (function () {
2
+ const registry = {};
3
+
4
+ function initTabs(tabGroup, groupIdx) {
5
+ const items = [...tabGroup.querySelectorAll('.pp-tabs__item')];
6
+ const targetAttr = 'data-tab-target';
7
+
8
+ if (!tabGroup.getAttribute('role')) tabGroup.setAttribute('role', 'tablist');
9
+
10
+ items.forEach((item, i) => {
11
+ item.setAttribute('role', 'tab');
12
+ if (!item.id) item.id = `pp-tab-${groupIdx}-${i}`;
13
+
14
+ const targetId = item.getAttribute(targetAttr);
15
+ if (targetId) {
16
+ item.setAttribute('aria-controls', targetId);
17
+ const panel = document.querySelector(`[data-tab-panel="${targetId}"]`);
18
+ if (panel) {
19
+ if (!panel.id) panel.id = targetId;
20
+ panel.setAttribute('role', 'tabpanel');
21
+ panel.setAttribute('aria-labelledby', item.id);
22
+ }
23
+ }
24
+ });
25
+
26
+ function activate(item) {
27
+ items.forEach((i) => {
28
+ i.classList.remove('is-active');
29
+ i.setAttribute('aria-selected', 'false');
30
+ i.setAttribute('tabindex', '-1');
31
+ });
32
+
33
+ item.classList.add('is-active');
34
+ item.setAttribute('aria-selected', 'true');
35
+ item.setAttribute('tabindex', '0');
36
+
37
+ const targetId = item.getAttribute(targetAttr);
38
+ if (targetId) {
39
+ document.querySelectorAll('[data-tab-panel]').forEach((panel) => {
40
+ const isVisible = panel.getAttribute('data-tab-panel') === targetId;
41
+ panel.hidden = !isVisible;
42
+ panel.setAttribute('aria-hidden', String(!isVisible));
43
+ });
44
+ }
45
+
46
+ const detail = { value: item.dataset.tabTarget, label: item.textContent.trim(), index: items.indexOf(item) };
47
+ tabGroup.dispatchEvent(new CustomEvent('pp:tabs:change', { bubbles: true, detail }));
48
+ }
49
+
50
+ items.forEach((item) => {
51
+ item.addEventListener('click', () => activate(item));
52
+ });
53
+
54
+ tabGroup.addEventListener('keydown', (e) => {
55
+ const current = items.findIndex((i) => i === document.activeElement);
56
+ if (current === -1) return;
57
+
58
+ if (e.key === 'ArrowRight') {
59
+ e.preventDefault();
60
+ const next = items[(current + 1) % items.length];
61
+ activate(next); next.focus();
62
+ }
63
+ if (e.key === 'ArrowLeft') {
64
+ e.preventDefault();
65
+ const prev = items[(current - 1 + items.length) % items.length];
66
+ activate(prev); prev.focus();
67
+ }
68
+ if (e.key === 'Home') {
69
+ e.preventDefault();
70
+ activate(items[0]); items[0].focus();
71
+ }
72
+ if (e.key === 'End') {
73
+ e.preventDefault();
74
+ activate(items[items.length - 1]); items[items.length - 1].focus();
75
+ }
76
+ });
77
+
78
+ items.forEach((item) => {
79
+ item.setAttribute('tabindex', item.classList.contains('is-active') ? '0' : '-1');
80
+ });
81
+
82
+ return {
83
+ activate(index) {
84
+ const item = items[index];
85
+ if (item) { activate(item); item.focus(); }
86
+ },
87
+ };
88
+ }
89
+
90
+ document.querySelectorAll('.pp-tabs').forEach((el, i) => {
91
+ const id = el.id || `pp-tabs-${i}`;
92
+ if (!el.id) el.id = id;
93
+ const api = initTabs(el, i);
94
+ if (api) registry[id] = api;
95
+ });
96
+
97
+ window.ppTabs = {
98
+ get(ref) {
99
+ if (typeof ref === 'string') return registry[ref];
100
+ if (ref instanceof Element) return registry[ref.id];
101
+ return null;
102
+ },
103
+ };
104
+ })();
@@ -0,0 +1,47 @@
1
+ (function () {
2
+ const STORAGE_KEY = 'pp-theme';
3
+ const ROOT = document.documentElement;
4
+
5
+ function applyTheme(theme) {
6
+ if (theme === 'dark') {
7
+ ROOT.classList.add('dark');
8
+ } else {
9
+ ROOT.classList.remove('dark');
10
+ }
11
+ try { localStorage.setItem(STORAGE_KEY, theme); } catch (_) {}
12
+
13
+ document.dispatchEvent(new CustomEvent('pp:theme:change', {
14
+ bubbles: false,
15
+ detail: { theme },
16
+ }));
17
+ }
18
+
19
+ window.ppTheme = {
20
+ set(theme) {
21
+ applyTheme(theme === 'dark' ? 'dark' : 'light');
22
+ },
23
+
24
+ get() {
25
+ return ROOT.classList.contains('dark') ? 'dark' : 'light';
26
+ },
27
+
28
+ toggle() {
29
+ applyTheme(ROOT.classList.contains('dark') ? 'light' : 'dark');
30
+ },
31
+ };
32
+
33
+ // Restore from localStorage on load
34
+ (function init() {
35
+ let saved;
36
+ try { saved = localStorage.getItem(STORAGE_KEY); } catch (_) {}
37
+ if (saved === 'dark' || saved === 'light') {
38
+ applyTheme(saved);
39
+ }
40
+ })();
41
+
42
+ // Auto-wire [data-theme-toggle] buttons
43
+ document.addEventListener('click', (e) => {
44
+ const btn = e.target.closest('[data-theme-toggle]');
45
+ if (btn) ppTheme.toggle();
46
+ });
47
+ })();
@@ -0,0 +1,79 @@
1
+ (function () {
2
+ const ICON_SVG = {
3
+ info: '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>',
4
+ success: '<svg viewBox="0 0 24 24"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>',
5
+ warning: '<svg viewBox="0 0 24 24"><path d="m10.29 3.86-8.61 14.88A2 2 0 0 0 3.4 22h17.2a2 2 0 0 0 1.72-3l-8.6-15a2 2 0 0 0-3.43 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',
6
+ error: '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>',
7
+ neutral: '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>',
8
+ };
9
+
10
+ function getOrCreateContainer(position) {
11
+ const cls = `pp-toast-container--${position}`;
12
+ let container = document.querySelector(`.pp-toast-container.${cls}`);
13
+ if (!container) {
14
+ container = document.createElement('div');
15
+ container.className = `pp-toast-container ${cls}`;
16
+ container.setAttribute('aria-live', 'polite');
17
+ container.setAttribute('aria-atomic', 'false');
18
+ document.body.appendChild(container);
19
+ }
20
+ return container;
21
+ }
22
+
23
+ function dismiss(toastEl) {
24
+ if (toastEl._dismissed) return;
25
+ toastEl._dismissed = true;
26
+ toastEl.classList.add('is-dismissing');
27
+ toastEl.dispatchEvent(new CustomEvent('pp:toast:dismiss', { bubbles: true }));
28
+ toastEl.addEventListener('animationend', () => toastEl.remove(), { once: true });
29
+ setTimeout(() => toastEl.remove(), 300);
30
+ }
31
+
32
+ window.ppToast = {
33
+ show({ message = '', title = '', variant = 'neutral', duration = 4000, position = 'top-right' } = {}) {
34
+ const container = getOrCreateContainer(position);
35
+
36
+ const toast = document.createElement('div');
37
+ toast.className = `pp-toast pp-toast--${variant}`;
38
+ toast.setAttribute('role', 'status');
39
+
40
+ const icon = ICON_SVG[variant] || ICON_SVG.neutral;
41
+
42
+ toast.innerHTML = `
43
+ <span class="pp-toast__icon" aria-hidden="true">${icon}</span>
44
+ <div class="pp-toast__body">
45
+ ${title ? `<div class="pp-toast__title">${title}</div>` : ''}
46
+ <div class="pp-toast__message">${message}</div>
47
+ </div>
48
+ <button class="pp-toast__dismiss" aria-label="Dismiss">
49
+ <svg viewBox="0 0 24 24"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
50
+ </button>
51
+ ${duration > 0 ? `<span class="pp-toast__progress" style="--pp-toast-duration:${duration}ms"></span>` : ''}
52
+ `.trim();
53
+
54
+ toast.querySelector('.pp-toast__dismiss').addEventListener('click', () => dismiss(toast));
55
+
56
+ container.appendChild(toast);
57
+
58
+ toast.dispatchEvent(new CustomEvent('pp:toast:show', {
59
+ bubbles: true,
60
+ detail: { message, title, variant, duration },
61
+ }));
62
+
63
+ if (duration > 0) {
64
+ setTimeout(() => dismiss(toast), duration);
65
+ }
66
+
67
+ return { dismiss: () => dismiss(toast) };
68
+ },
69
+ };
70
+
71
+ // Auto-wire any [data-toast-dismiss] buttons in static markup
72
+ document.addEventListener('click', (e) => {
73
+ const btn = e.target.closest('[data-toast-dismiss]');
74
+ if (btn) {
75
+ const toast = btn.closest('.pp-toast');
76
+ if (toast) dismiss(toast);
77
+ }
78
+ });
79
+ })();
@@ -1,132 +1,132 @@
1
- // PeppertinoCSS — Validation
2
-
3
- (function () {
4
- function getField(input) { return input.closest('.pp-field'); }
5
- function getMessageEl(field) { return field ? field.querySelector('.pp-field__message') : null; }
6
- function getHintEl(field) { return field ? field.querySelector('.pp-field__hint') : null; }
7
-
8
- function buildDescribedBy(field) {
9
- const ids = [];
10
- const hint = getHintEl(field);
11
- const msg = getMessageEl(field);
12
- if (hint && hint.id) ids.push(hint.id);
13
- if (msg && msg.id) ids.push(msg.id);
14
- return ids.join(' ');
15
- }
16
-
17
- function ensureIds(field, input) {
18
- const base = input.id || `pp-field-${Math.random().toString(36).slice(2, 7)}`;
19
- const hint = getHintEl(field);
20
- const msg = getMessageEl(field);
21
- if (hint && !hint.id) hint.id = `${base}-hint`;
22
- if (msg && !msg.id) msg.id = `${base}-msg`;
23
- }
24
-
25
- function setError(input, message) {
26
- const field = getField(input);
27
- if (!field) return;
28
- ensureIds(field, input);
29
- field.classList.remove('pp-field--success', 'pp-field--warning', 'pp-field--validating');
30
- field.classList.add('pp-field--error');
31
- input.setAttribute('aria-invalid', 'true');
32
- let msg = getMessageEl(field);
33
- if (!msg) {
34
- msg = document.createElement('span');
35
- msg.className = 'pp-field__message';
36
- msg.id = `${input.id || 'field'}-msg`;
37
- msg.setAttribute('role', 'alert');
38
- field.appendChild(msg);
39
- }
40
- msg.textContent = message;
41
- input.setAttribute('aria-describedby', buildDescribedBy(field));
42
- field.dispatchEvent(new CustomEvent('pp-field:error', { bubbles: true, detail: { input, message } }));
43
- }
44
-
45
- function clearError(input) {
46
- const field = getField(input);
47
- if (!field) return;
48
- field.classList.remove('pp-field--error', 'pp-field--validating');
49
- input.setAttribute('aria-invalid', 'false');
50
- const msg = getMessageEl(field);
51
- if (msg) msg.textContent = '';
52
- input.setAttribute('aria-describedby', buildDescribedBy(field));
53
- field.dispatchEvent(new CustomEvent('pp-field:clear', { bubbles: true, detail: { input } }));
54
- }
55
-
56
- function setSuccess(input, message) {
57
- const field = getField(input);
58
- if (!field) return;
59
- ensureIds(field, input);
60
- field.classList.remove('pp-field--error', 'pp-field--warning', 'pp-field--validating');
61
- field.classList.add('pp-field--success');
62
- input.setAttribute('aria-invalid', 'false');
63
- let msg = getMessageEl(field);
64
- if (message) {
65
- if (!msg) {
66
- msg = document.createElement('span');
67
- msg.className = 'pp-field__message';
68
- msg.id = `${input.id || 'field'}-msg`;
69
- field.appendChild(msg);
70
- }
71
- msg.textContent = message;
72
- }
73
- input.setAttribute('aria-describedby', buildDescribedBy(field));
74
- }
75
-
76
- function setValidating(input) {
77
- const field = getField(input);
78
- if (!field) return;
79
- field.classList.remove('pp-field--error', 'pp-field--success', 'pp-field--warning');
80
- field.classList.add('pp-field--validating');
81
- input.removeAttribute('aria-invalid');
82
- }
83
-
84
- function setSummary(errors, summaryEl) {
85
- if (!summaryEl) return;
86
- const list = summaryEl.querySelector('.pp-validation-summary__list');
87
- if (!list) return;
88
- list.innerHTML = '';
89
- if (!errors || errors.length === 0) {
90
- summaryEl.classList.remove('is-visible');
91
- summaryEl.setAttribute('aria-hidden', 'true');
92
- return;
93
- }
94
- errors.forEach(({ input, message }) => {
95
- const inputEl = typeof input === 'string' ? document.getElementById(input) : input;
96
- const li = document.createElement('li');
97
- li.className = 'pp-validation-summary__item';
98
- if (inputEl && inputEl.id) {
99
- const a = document.createElement('a');
100
- a.href = `#${inputEl.id}`;
101
- a.textContent = message;
102
- a.addEventListener('click', (e) => {
103
- e.preventDefault();
104
- inputEl.focus();
105
- inputEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
106
- });
107
- li.appendChild(a);
108
- } else {
109
- li.textContent = message;
110
- }
111
- list.appendChild(li);
112
- });
113
- summaryEl.classList.add('is-visible');
114
- summaryEl.setAttribute('aria-hidden', 'false');
115
- summaryEl.setAttribute('tabindex', '-1');
116
- summaryEl.focus();
117
- }
118
-
119
- document.querySelectorAll('.pp-field').forEach((field) => {
120
- const input = field.querySelector('.pp-field__input, .pp-field__textarea');
121
- if (!input) return;
122
- ensureIds(field, input);
123
- const refs = buildDescribedBy(field);
124
- if (refs) {
125
- const existing = input.getAttribute('aria-describedby') || '';
126
- const merged = [...new Set([...existing.split(' '), ...refs.split(' ')].filter(Boolean))].join(' ');
127
- input.setAttribute('aria-describedby', merged);
128
- }
129
- });
130
-
131
- window.ppValidation = { setError, clearError, setSuccess, setValidating, setSummary };
132
- })();
1
+ // PeppertinoCSS — Validation
2
+
3
+ (function () {
4
+ function getField(input) { return input.closest('.pp-field'); }
5
+ function getMessageEl(field) { return field ? field.querySelector('.pp-field__message') : null; }
6
+ function getHintEl(field) { return field ? field.querySelector('.pp-field__hint') : null; }
7
+
8
+ function buildDescribedBy(field) {
9
+ const ids = [];
10
+ const hint = getHintEl(field);
11
+ const msg = getMessageEl(field);
12
+ if (hint && hint.id) ids.push(hint.id);
13
+ if (msg && msg.id) ids.push(msg.id);
14
+ return ids.join(' ');
15
+ }
16
+
17
+ function ensureIds(field, input) {
18
+ const base = input.id || `pp-field-${Math.random().toString(36).slice(2, 7)}`;
19
+ const hint = getHintEl(field);
20
+ const msg = getMessageEl(field);
21
+ if (hint && !hint.id) hint.id = `${base}-hint`;
22
+ if (msg && !msg.id) msg.id = `${base}-msg`;
23
+ }
24
+
25
+ function setError(input, message) {
26
+ const field = getField(input);
27
+ if (!field) return;
28
+ ensureIds(field, input);
29
+ field.classList.remove('pp-field--success', 'pp-field--warning', 'pp-field--validating');
30
+ field.classList.add('pp-field--error');
31
+ input.setAttribute('aria-invalid', 'true');
32
+ let msg = getMessageEl(field);
33
+ if (!msg) {
34
+ msg = document.createElement('span');
35
+ msg.className = 'pp-field__message';
36
+ msg.id = `${input.id || 'field'}-msg`;
37
+ msg.setAttribute('role', 'alert');
38
+ field.appendChild(msg);
39
+ }
40
+ msg.textContent = message;
41
+ input.setAttribute('aria-describedby', buildDescribedBy(field));
42
+ field.dispatchEvent(new CustomEvent('pp-field:error', { bubbles: true, detail: { input, message } }));
43
+ }
44
+
45
+ function clearError(input) {
46
+ const field = getField(input);
47
+ if (!field) return;
48
+ field.classList.remove('pp-field--error', 'pp-field--validating');
49
+ input.setAttribute('aria-invalid', 'false');
50
+ const msg = getMessageEl(field);
51
+ if (msg) msg.textContent = '';
52
+ input.setAttribute('aria-describedby', buildDescribedBy(field));
53
+ field.dispatchEvent(new CustomEvent('pp-field:clear', { bubbles: true, detail: { input } }));
54
+ }
55
+
56
+ function setSuccess(input, message) {
57
+ const field = getField(input);
58
+ if (!field) return;
59
+ ensureIds(field, input);
60
+ field.classList.remove('pp-field--error', 'pp-field--warning', 'pp-field--validating');
61
+ field.classList.add('pp-field--success');
62
+ input.setAttribute('aria-invalid', 'false');
63
+ let msg = getMessageEl(field);
64
+ if (message) {
65
+ if (!msg) {
66
+ msg = document.createElement('span');
67
+ msg.className = 'pp-field__message';
68
+ msg.id = `${input.id || 'field'}-msg`;
69
+ field.appendChild(msg);
70
+ }
71
+ msg.textContent = message;
72
+ }
73
+ input.setAttribute('aria-describedby', buildDescribedBy(field));
74
+ }
75
+
76
+ function setValidating(input) {
77
+ const field = getField(input);
78
+ if (!field) return;
79
+ field.classList.remove('pp-field--error', 'pp-field--success', 'pp-field--warning');
80
+ field.classList.add('pp-field--validating');
81
+ input.removeAttribute('aria-invalid');
82
+ }
83
+
84
+ function setSummary(errors, summaryEl) {
85
+ if (!summaryEl) return;
86
+ const list = summaryEl.querySelector('.pp-validation-summary__list');
87
+ if (!list) return;
88
+ list.innerHTML = '';
89
+ if (!errors || errors.length === 0) {
90
+ summaryEl.classList.remove('is-visible');
91
+ summaryEl.setAttribute('aria-hidden', 'true');
92
+ return;
93
+ }
94
+ errors.forEach(({ input, message }) => {
95
+ const inputEl = typeof input === 'string' ? document.getElementById(input) : input;
96
+ const li = document.createElement('li');
97
+ li.className = 'pp-validation-summary__item';
98
+ if (inputEl && inputEl.id) {
99
+ const a = document.createElement('a');
100
+ a.href = `#${inputEl.id}`;
101
+ a.textContent = message;
102
+ a.addEventListener('click', (e) => {
103
+ e.preventDefault();
104
+ inputEl.focus();
105
+ inputEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
106
+ });
107
+ li.appendChild(a);
108
+ } else {
109
+ li.textContent = message;
110
+ }
111
+ list.appendChild(li);
112
+ });
113
+ summaryEl.classList.add('is-visible');
114
+ summaryEl.setAttribute('aria-hidden', 'false');
115
+ summaryEl.setAttribute('tabindex', '-1');
116
+ summaryEl.focus();
117
+ }
118
+
119
+ document.querySelectorAll('.pp-field').forEach((field) => {
120
+ const input = field.querySelector('.pp-field__input, .pp-field__textarea');
121
+ if (!input) return;
122
+ ensureIds(field, input);
123
+ const refs = buildDescribedBy(field);
124
+ if (refs) {
125
+ const existing = input.getAttribute('aria-describedby') || '';
126
+ const merged = [...new Set([...existing.split(' '), ...refs.split(' ')].filter(Boolean))].join(' ');
127
+ input.setAttribute('aria-describedby', merged);
128
+ }
129
+ });
130
+
131
+ window.ppValidation = { setError, clearError, setSuccess, setValidating, setSummary };
132
+ })();