@auriel/peppertino 0.5.0 → 0.6.1

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 (134) hide show
  1. package/CHANGELOG.txt +249 -224
  2. package/LICENSE +21 -21
  3. package/MIGRATION.md +52 -52
  4. package/README.md +811 -764
  5. package/agents/peppertino/SKILL.md +84 -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 +83 -0
  14. package/agents/peppertino/components-ai-search.md +10 -0
  15. package/agents/peppertino/components-display.md +19 -0
  16. package/agents/peppertino/components-inputs.md +15 -0
  17. package/agents/peppertino/components-navigation.md +12 -0
  18. package/agents/peppertino/dark-mode.md +152 -0
  19. package/agents/peppertino/footer.md +109 -0
  20. package/agents/peppertino/forms-fieldset.md +85 -0
  21. package/agents/peppertino/forms-form-instructions.md +94 -0
  22. package/agents/peppertino/forms-label.md +110 -0
  23. package/agents/peppertino/forms-text-field.md +134 -0
  24. package/agents/peppertino/forms-validation.md +153 -0
  25. package/agents/peppertino/gradient.md +41 -0
  26. package/agents/peppertino/header.md +105 -0
  27. package/agents/peppertino/modal.md +123 -0
  28. package/agents/peppertino/section.md +56 -0
  29. package/agents/peppertino/select.md +110 -0
  30. package/agents/peppertino/switch.md +72 -0
  31. package/agents/peppertino/table.md +69 -0
  32. package/agents/peppertino/tabs.md +115 -0
  33. package/agents/peppertino/toast.md +96 -0
  34. package/agents/peppertino/tooltip.md +111 -0
  35. package/agents/peppertino/typography.md +118 -0
  36. package/agents/peppertino/utilities.md +194 -0
  37. package/agents/skill.md +65 -0
  38. package/build.js +53 -53
  39. package/dist/accordion.js +1 -1
  40. package/dist/accordion.js.map +2 -2
  41. package/dist/alert.js.map +1 -1
  42. package/dist/carousel.js.map +1 -1
  43. package/dist/header.js.map +1 -1
  44. package/dist/main.css +2566 -1008
  45. package/dist/main.css.map +1 -1
  46. package/dist/main.min.css +1 -0
  47. package/dist/modal.js.map +1 -1
  48. package/dist/peppertino.js +1 -1
  49. package/dist/peppertino.js.map +2 -2
  50. package/dist/select.js.map +1 -1
  51. package/dist/switch.js.map +1 -1
  52. package/dist/tabs.js.map +1 -1
  53. package/dist/theme.js.map +1 -1
  54. package/dist/toast.js.map +1 -1
  55. package/dist/validation.js.map +1 -1
  56. package/icon.svg +4 -0
  57. package/index.html +2177 -2098
  58. package/package.json +28 -28
  59. package/scripts/hex-to-hsl.mjs +75 -75
  60. package/scripts/lint-bem.mjs +53 -53
  61. package/scripts/lint-colors.mjs +87 -87
  62. package/site.webmanifest +18 -0
  63. package/src/js/accordion.js +105 -103
  64. package/src/js/alert.js +28 -28
  65. package/src/js/carousel.js +153 -153
  66. package/src/js/header.js +85 -85
  67. package/src/js/modal.js +138 -138
  68. package/src/js/peppertino.js +15 -15
  69. package/src/js/select.js +101 -101
  70. package/src/js/switch.js +28 -28
  71. package/src/js/tabs.js +104 -104
  72. package/src/js/theme.js +47 -47
  73. package/src/js/toast.js +79 -79
  74. package/src/js/validation.js +132 -132
  75. package/src/scss/accordion.scss +190 -156
  76. package/src/scss/activity.scss +17 -0
  77. package/src/scss/alert.scss +203 -203
  78. package/src/scss/badge.scss +90 -90
  79. package/src/scss/base.scss +511 -506
  80. package/src/scss/button.scss +119 -119
  81. package/src/scss/card.scss +121 -121
  82. package/src/scss/carousel.scss +303 -303
  83. package/src/scss/code-block.scss +22 -0
  84. package/src/scss/counter.scss +5 -0
  85. package/src/scss/dark-mode.scss +514 -514
  86. package/src/scss/duration.scss +26 -0
  87. package/src/scss/folder.scss +27 -0
  88. package/src/scss/footer.scss +224 -224
  89. package/src/scss/forms/fieldset.scss +127 -127
  90. package/src/scss/forms/form-instructions.scss +133 -133
  91. package/src/scss/forms/label.scss +115 -115
  92. package/src/scss/forms/text-field.scss +240 -240
  93. package/src/scss/forms/validation.scss +215 -215
  94. package/src/scss/forms.scss +8 -8
  95. package/src/scss/gradient.scss +11 -11
  96. package/src/scss/gravity-letters.scss +7 -0
  97. package/src/scss/header.scss +257 -238
  98. package/src/scss/helpers/color.scss +9 -0
  99. package/src/scss/helpers/flex.scss +14 -0
  100. package/src/scss/helpers/index.scss +6 -0
  101. package/src/scss/helpers/layout.scss +14 -0
  102. package/src/scss/helpers/spacing.scss +14 -0
  103. package/src/scss/helpers/typography.scss +11 -0
  104. package/src/scss/helpers/visibility.scss +9 -0
  105. package/src/scss/main.scss +49 -24
  106. package/src/scss/modal.scss +188 -188
  107. package/src/scss/model-picker.scss +5 -0
  108. package/src/scss/notification.scss +5 -0
  109. package/src/scss/orb.scss +7 -0
  110. package/src/scss/otp.scss +5 -0
  111. package/src/scss/pill-nav.scss +10 -0
  112. package/src/scss/prompt.scss +28 -0
  113. package/src/scss/rail.scss +7 -0
  114. package/src/scss/reactions.scss +5 -0
  115. package/src/scss/reset.scss +84 -84
  116. package/src/scss/response.scss +11 -0
  117. package/src/scss/reveal.scss +5 -0
  118. package/src/scss/scroll-progress.scss +4 -0
  119. package/src/scss/search-results.scss +13 -0
  120. package/src/scss/section.scss +87 -79
  121. package/src/scss/select.scss +210 -210
  122. package/src/scss/sidebar.scss +8 -0
  123. package/src/scss/status.scss +5 -0
  124. package/src/scss/step-list.scss +13 -0
  125. package/src/scss/switch.scss +121 -121
  126. package/src/scss/table.scss +89 -89
  127. package/src/scss/tabs.scss +156 -156
  128. package/src/scss/task-list.scss +18 -0
  129. package/src/scss/theme-picker.scss +5 -0
  130. package/src/scss/toast.scss +170 -170
  131. package/src/scss/tooltip.scss +126 -126
  132. package/src/scss/typography.scss +58 -58
  133. package/src/scss/utilities.scss +243 -243
  134. package/src/scss/voice-note.scss +5 -0
@@ -1,103 +1,105 @@
1
- (function () {
2
- const registry = {};
3
-
4
- document.querySelectorAll('.pp-accordion').forEach((accordion, accordionIdx) => {
5
- const allowMultiple = accordion.hasAttribute('data-allow-multiple');
6
- const id = accordion.id || `pp-accordion-${accordionIdx}`;
7
- if (!accordion.id) accordion.id = id;
8
-
9
- const triggers = [...accordion.querySelectorAll('.pp-accordion__trigger')];
10
-
11
- triggers.forEach((trigger, i) => {
12
- const panelId = trigger.getAttribute('aria-controls');
13
- const panel = panelId
14
- ? document.getElementById(panelId)
15
- : trigger.nextElementSibling;
16
-
17
- if (!panel) return;
18
-
19
- const isOpen = trigger.getAttribute('aria-expanded') === 'true';
20
- panel.setAttribute('aria-hidden', isOpen ? 'false' : 'true');
21
- if (isOpen) panel.classList.add('is-open');
22
-
23
- trigger.addEventListener('click', () => {
24
- const expanded = trigger.getAttribute('aria-expanded') === 'true';
25
-
26
- if (!allowMultiple) {
27
- triggers.forEach((t) => {
28
- if (t === trigger) return;
29
- t.setAttribute('aria-expanded', 'false');
30
- const p = t.getAttribute('aria-controls')
31
- ? document.getElementById(t.getAttribute('aria-controls'))
32
- : t.nextElementSibling;
33
- if (p) {
34
- p.setAttribute('aria-hidden', 'true');
35
- p.classList.remove('is-open');
36
- }
37
- });
38
- }
39
-
40
- const next = !expanded;
41
- trigger.setAttribute('aria-expanded', String(next));
42
- panel.setAttribute('aria-hidden', String(!next));
43
- panel.classList.toggle('is-open', next);
44
-
45
- accordion.dispatchEvent(new CustomEvent(next ? 'pp:accordion:open' : 'pp:accordion:close', {
46
- bubbles: true,
47
- detail: { index: i, trigger, panel },
48
- }));
49
- });
50
-
51
- trigger.addEventListener('keydown', (e) => {
52
- const idx = triggers.indexOf(trigger);
53
- if (e.key === 'ArrowDown') {
54
- e.preventDefault();
55
- triggers[(idx + 1) % triggers.length].focus();
56
- } else if (e.key === 'ArrowUp') {
57
- e.preventDefault();
58
- triggers[(idx - 1 + triggers.length) % triggers.length].focus();
59
- } else if (e.key === 'Home') {
60
- e.preventDefault();
61
- triggers[0].focus();
62
- } else if (e.key === 'End') {
63
- e.preventDefault();
64
- triggers[triggers.length - 1].focus();
65
- }
66
- });
67
- });
68
-
69
- function setItem(index, open) {
70
- const trigger = triggers[index];
71
- if (!trigger) return;
72
- const panelId = trigger.getAttribute('aria-controls');
73
- const panel = panelId ? document.getElementById(panelId) : trigger.nextElementSibling;
74
- if (!panel) return;
75
- trigger.setAttribute('aria-expanded', String(open));
76
- panel.setAttribute('aria-hidden', String(!open));
77
- panel.classList.toggle('is-open', open);
78
- accordion.dispatchEvent(new CustomEvent(open ? 'pp:accordion:open' : 'pp:accordion:close', {
79
- bubbles: true,
80
- detail: { index, trigger, panel },
81
- }));
82
- }
83
-
84
- const api = {
85
- open: (index) => setItem(index, true),
86
- close: (index) => setItem(index, false),
87
- toggleAll() {
88
- const anyOpen = triggers.some((t) => t.getAttribute('aria-expanded') === 'true');
89
- triggers.forEach((_, i) => setItem(i, !anyOpen));
90
- },
91
- };
92
-
93
- registry[id] = api;
94
- });
95
-
96
- window.ppAccordion = {
97
- get(ref) {
98
- if (typeof ref === 'string') return registry[ref];
99
- if (ref instanceof Element) return registry[ref.id];
100
- return null;
101
- },
102
- };
103
- })();
1
+ (function () {
2
+ const registry = {};
3
+
4
+ document.querySelectorAll('.pp-accordion').forEach((accordion, accordionIdx) => {
5
+ const allowMultiple = accordion.hasAttribute('data-allow-multiple');
6
+ const id = accordion.id || `pp-accordion-${accordionIdx}`;
7
+ if (!accordion.id) accordion.id = id;
8
+
9
+ // Native summary elements already toggle their details without a shim.
10
+ const triggers = [...accordion.querySelectorAll('.pp-accordion__trigger')]
11
+ .filter((trigger) => !trigger.matches('summary'));
12
+
13
+ triggers.forEach((trigger, i) => {
14
+ const panelId = trigger.getAttribute('aria-controls');
15
+ const panel = panelId
16
+ ? document.getElementById(panelId)
17
+ : trigger.nextElementSibling;
18
+
19
+ if (!panel) return;
20
+
21
+ const isOpen = trigger.getAttribute('aria-expanded') === 'true';
22
+ panel.setAttribute('aria-hidden', isOpen ? 'false' : 'true');
23
+ if (isOpen) panel.classList.add('is-open');
24
+
25
+ trigger.addEventListener('click', () => {
26
+ const expanded = trigger.getAttribute('aria-expanded') === 'true';
27
+
28
+ if (!allowMultiple) {
29
+ triggers.forEach((t) => {
30
+ if (t === trigger) return;
31
+ t.setAttribute('aria-expanded', 'false');
32
+ const p = t.getAttribute('aria-controls')
33
+ ? document.getElementById(t.getAttribute('aria-controls'))
34
+ : t.nextElementSibling;
35
+ if (p) {
36
+ p.setAttribute('aria-hidden', 'true');
37
+ p.classList.remove('is-open');
38
+ }
39
+ });
40
+ }
41
+
42
+ const next = !expanded;
43
+ trigger.setAttribute('aria-expanded', String(next));
44
+ panel.setAttribute('aria-hidden', String(!next));
45
+ panel.classList.toggle('is-open', next);
46
+
47
+ accordion.dispatchEvent(new CustomEvent(next ? 'pp:accordion:open' : 'pp:accordion:close', {
48
+ bubbles: true,
49
+ detail: { index: i, trigger, panel },
50
+ }));
51
+ });
52
+
53
+ trigger.addEventListener('keydown', (e) => {
54
+ const idx = triggers.indexOf(trigger);
55
+ if (e.key === 'ArrowDown') {
56
+ e.preventDefault();
57
+ triggers[(idx + 1) % triggers.length].focus();
58
+ } else if (e.key === 'ArrowUp') {
59
+ e.preventDefault();
60
+ triggers[(idx - 1 + triggers.length) % triggers.length].focus();
61
+ } else if (e.key === 'Home') {
62
+ e.preventDefault();
63
+ triggers[0].focus();
64
+ } else if (e.key === 'End') {
65
+ e.preventDefault();
66
+ triggers[triggers.length - 1].focus();
67
+ }
68
+ });
69
+ });
70
+
71
+ function setItem(index, open) {
72
+ const trigger = triggers[index];
73
+ if (!trigger) return;
74
+ const panelId = trigger.getAttribute('aria-controls');
75
+ const panel = panelId ? document.getElementById(panelId) : trigger.nextElementSibling;
76
+ if (!panel) return;
77
+ trigger.setAttribute('aria-expanded', String(open));
78
+ panel.setAttribute('aria-hidden', String(!open));
79
+ panel.classList.toggle('is-open', open);
80
+ accordion.dispatchEvent(new CustomEvent(open ? 'pp:accordion:open' : 'pp:accordion:close', {
81
+ bubbles: true,
82
+ detail: { index, trigger, panel },
83
+ }));
84
+ }
85
+
86
+ const api = {
87
+ open: (index) => setItem(index, true),
88
+ close: (index) => setItem(index, false),
89
+ toggleAll() {
90
+ const anyOpen = triggers.some((t) => t.getAttribute('aria-expanded') === 'true');
91
+ triggers.forEach((_, i) => setItem(i, !anyOpen));
92
+ },
93
+ };
94
+
95
+ registry[id] = api;
96
+ });
97
+
98
+ window.ppAccordion = {
99
+ get(ref) {
100
+ if (typeof ref === 'string') return registry[ref];
101
+ if (ref instanceof Element) return registry[ref.id];
102
+ return null;
103
+ },
104
+ };
105
+ })();
package/src/js/alert.js CHANGED
@@ -1,28 +1,28 @@
1
- (function () {
2
- function dismiss(alertEl) {
3
- if (alertEl._dismissed) return;
4
- alertEl._dismissed = true;
5
- alertEl.classList.add('is-dismissing');
6
- alertEl.dispatchEvent(new CustomEvent('pp:alert:dismiss', { bubbles: true }));
7
- alertEl.addEventListener('animationend', () => alertEl.remove(), { once: true });
8
- setTimeout(() => alertEl.remove(), 250);
9
- }
10
-
11
- window.ppAlert = {
12
- dismiss(idOrEl) {
13
- const el = typeof idOrEl === 'string'
14
- ? document.getElementById(idOrEl)
15
- : idOrEl;
16
- if (el) dismiss(el);
17
- },
18
- };
19
-
20
- // Auto-wire [data-alert-dismiss] buttons
21
- document.addEventListener('click', (e) => {
22
- const btn = e.target.closest('[data-alert-dismiss]');
23
- if (btn) {
24
- const alert = btn.closest('.pp-alert');
25
- if (alert) dismiss(alert);
26
- }
27
- });
28
- })();
1
+ (function () {
2
+ function dismiss(alertEl) {
3
+ if (alertEl._dismissed) return;
4
+ alertEl._dismissed = true;
5
+ alertEl.classList.add('is-dismissing');
6
+ alertEl.dispatchEvent(new CustomEvent('pp:alert:dismiss', { bubbles: true }));
7
+ alertEl.addEventListener('animationend', () => alertEl.remove(), { once: true });
8
+ setTimeout(() => alertEl.remove(), 250);
9
+ }
10
+
11
+ window.ppAlert = {
12
+ dismiss(idOrEl) {
13
+ const el = typeof idOrEl === 'string'
14
+ ? document.getElementById(idOrEl)
15
+ : idOrEl;
16
+ if (el) dismiss(el);
17
+ },
18
+ };
19
+
20
+ // Auto-wire [data-alert-dismiss] buttons
21
+ document.addEventListener('click', (e) => {
22
+ const btn = e.target.closest('[data-alert-dismiss]');
23
+ if (btn) {
24
+ const alert = btn.closest('.pp-alert');
25
+ if (alert) dismiss(alert);
26
+ }
27
+ });
28
+ })();
@@ -1,153 +1,153 @@
1
- // PeppertinoCSS — Carousel
2
-
3
- (function () {
4
- function initCarousel(root, rootIdx) {
5
- const track = root.querySelector('.pp-carousel__track');
6
- const slides = [...root.querySelectorAll('.pp-carousel__slide')];
7
- const dots = [...root.querySelectorAll('.pp-carousel__dot')];
8
- const prevBtn = root.querySelector('.pp-carousel__prev');
9
- const nextBtn = root.querySelector('.pp-carousel__next');
10
- const autoplayBtn = root.querySelector('.pp-carousel__autoplay');
11
-
12
- if (!track || !slides.length) return;
13
-
14
- const total = slides.length;
15
- let current = 0;
16
-
17
- if (!root.getAttribute('role')) root.setAttribute('role', 'region');
18
- if (!root.getAttribute('aria-roledescription')) root.setAttribute('aria-roledescription', 'carousel');
19
- if (!root.getAttribute('aria-label') && !root.getAttribute('aria-labelledby')) {
20
- root.setAttribute('aria-label', root.dataset.label || `Carousel ${rootIdx + 1}`);
21
- }
22
-
23
- track.setAttribute('aria-live', 'off');
24
-
25
- slides.forEach((slide, i) => {
26
- slide.setAttribute('role', 'group');
27
- if (!slide.getAttribute('aria-roledescription')) slide.setAttribute('aria-roledescription', 'slide');
28
- if (!slide.getAttribute('aria-label')) slide.setAttribute('aria-label', `${i + 1} of ${total}`);
29
- });
30
-
31
- let announcer = root.querySelector('.pp-carousel__announcer');
32
- if (!announcer) {
33
- announcer = document.createElement('div');
34
- announcer.className = 'pp-carousel__announcer';
35
- root.appendChild(announcer);
36
- }
37
- announcer.setAttribute('aria-live', 'polite');
38
- announcer.setAttribute('aria-atomic', 'true');
39
-
40
- dots.forEach((dot, i) => {
41
- if (!dot.id) dot.id = `pp-carousel-${rootIdx}-dot-${i}`;
42
- if (!dot.getAttribute('aria-label')) dot.setAttribute('aria-label', `Go to slide ${i + 1}`);
43
- });
44
-
45
- if (prevBtn && !prevBtn.getAttribute('aria-label')) prevBtn.setAttribute('aria-label', 'Previous slide');
46
- if (nextBtn && !nextBtn.getAttribute('aria-label')) nextBtn.setAttribute('aria-label', 'Next slide');
47
-
48
- function syncUI(idx) {
49
- current = idx;
50
-
51
- slides.forEach((slide, i) => slide.setAttribute('aria-hidden', String(i !== idx)));
52
-
53
- dots.forEach((dot, i) => {
54
- dot.classList.toggle('is-active', i === idx);
55
- dot.setAttribute('aria-current', String(i === idx));
56
- dot.setAttribute('tabindex', i === idx ? '0' : '-1');
57
- });
58
-
59
- if (prevBtn) {
60
- prevBtn.disabled = idx === 0;
61
- prevBtn.setAttribute('aria-disabled', String(idx === 0));
62
- }
63
- if (nextBtn) {
64
- nextBtn.disabled = idx === total - 1;
65
- nextBtn.setAttribute('aria-disabled', String(idx === total - 1));
66
- }
67
-
68
- const label = slides[idx].getAttribute('aria-label') || `Slide ${idx + 1}`;
69
- announcer.textContent = '';
70
- requestAnimationFrame(() => { announcer.textContent = label; });
71
-
72
- root.dispatchEvent(new CustomEvent('pp:carousel:change', {
73
- bubbles: true,
74
- detail: { index: idx, total, label },
75
- }));
76
- }
77
-
78
- const observer = new IntersectionObserver(
79
- (entries) => {
80
- entries.forEach((entry) => {
81
- if (entry.isIntersecting) {
82
- const idx = slides.indexOf(entry.target);
83
- if (idx !== -1 && idx !== current) syncUI(idx);
84
- }
85
- });
86
- },
87
- { root: track, threshold: 0.5 }
88
- );
89
- slides.forEach((slide) => observer.observe(slide));
90
-
91
- function goTo(idx) {
92
- const clamped = Math.max(0, Math.min(total - 1, idx));
93
- slides[clamped].scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });
94
- syncUI(clamped);
95
- }
96
-
97
- if (prevBtn) prevBtn.addEventListener('click', () => goTo(current - 1));
98
- if (nextBtn) nextBtn.addEventListener('click', () => goTo(current + 1));
99
-
100
- dots.forEach((dot, i) => {
101
- dot.addEventListener('click', () => goTo(i));
102
- dot.addEventListener('keydown', (e) => {
103
- if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
104
- e.preventDefault(); goTo((i + 1) % total); dots[(i + 1) % total].focus();
105
- }
106
- if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
107
- e.preventDefault(); goTo((i - 1 + total) % total); dots[(i - 1 + total) % total].focus();
108
- }
109
- if (e.key === 'Home') { e.preventDefault(); goTo(0); dots[0].focus(); }
110
- if (e.key === 'End') { e.preventDefault(); goTo(total - 1); dots[total - 1].focus(); }
111
- });
112
- });
113
-
114
- if (autoplayBtn) {
115
- autoplayBtn.addEventListener('click', () => {
116
- const playing = root.classList.contains('pp-carousel--playing');
117
- root.classList.toggle('pp-carousel--playing', !playing);
118
- root.classList.toggle('pp-carousel--paused', playing);
119
- autoplayBtn.setAttribute('aria-pressed', String(!playing));
120
- autoplayBtn.setAttribute('aria-label', playing ? 'Start autoplay' : 'Pause autoplay');
121
- root.dispatchEvent(new CustomEvent('pp-carousel:autoplay', { bubbles: true, detail: { playing: !playing } }));
122
- });
123
- }
124
-
125
- track.setAttribute('tabindex', '0');
126
- track.addEventListener('keydown', (e) => {
127
- if (e.key === 'ArrowRight') { e.preventDefault(); goTo(current + 1); }
128
- if (e.key === 'ArrowLeft') { e.preventDefault(); goTo(current - 1); }
129
- if (e.key === 'Home') { e.preventDefault(); goTo(0); }
130
- if (e.key === 'End') { e.preventDefault(); goTo(total - 1); }
131
- });
132
-
133
- syncUI(0);
134
-
135
- return { goTo, current: () => current, total };
136
- }
137
-
138
- const instances = {};
139
- document.querySelectorAll('.pp-carousel').forEach((el, i) => {
140
- const id = el.id || `pp-carousel-${i}`;
141
- const api = initCarousel(el, i);
142
- if (api) instances[id] = api;
143
- });
144
-
145
- window.ppCarousel = {
146
- get(ref) {
147
- if (typeof ref === 'string') return instances[ref];
148
- if (ref instanceof Element) return instances[ref.id] || Object.values(instances).find((_, k) => document.getElementById(Object.keys(instances)[k]) === ref);
149
- return null;
150
- },
151
- instances,
152
- };
153
- })();
1
+ // PeppertinoCSS — Carousel
2
+
3
+ (function () {
4
+ function initCarousel(root, rootIdx) {
5
+ const track = root.querySelector('.pp-carousel__track');
6
+ const slides = [...root.querySelectorAll('.pp-carousel__slide')];
7
+ const dots = [...root.querySelectorAll('.pp-carousel__dot')];
8
+ const prevBtn = root.querySelector('.pp-carousel__prev');
9
+ const nextBtn = root.querySelector('.pp-carousel__next');
10
+ const autoplayBtn = root.querySelector('.pp-carousel__autoplay');
11
+
12
+ if (!track || !slides.length) return;
13
+
14
+ const total = slides.length;
15
+ let current = 0;
16
+
17
+ if (!root.getAttribute('role')) root.setAttribute('role', 'region');
18
+ if (!root.getAttribute('aria-roledescription')) root.setAttribute('aria-roledescription', 'carousel');
19
+ if (!root.getAttribute('aria-label') && !root.getAttribute('aria-labelledby')) {
20
+ root.setAttribute('aria-label', root.dataset.label || `Carousel ${rootIdx + 1}`);
21
+ }
22
+
23
+ track.setAttribute('aria-live', 'off');
24
+
25
+ slides.forEach((slide, i) => {
26
+ slide.setAttribute('role', 'group');
27
+ if (!slide.getAttribute('aria-roledescription')) slide.setAttribute('aria-roledescription', 'slide');
28
+ if (!slide.getAttribute('aria-label')) slide.setAttribute('aria-label', `${i + 1} of ${total}`);
29
+ });
30
+
31
+ let announcer = root.querySelector('.pp-carousel__announcer');
32
+ if (!announcer) {
33
+ announcer = document.createElement('div');
34
+ announcer.className = 'pp-carousel__announcer';
35
+ root.appendChild(announcer);
36
+ }
37
+ announcer.setAttribute('aria-live', 'polite');
38
+ announcer.setAttribute('aria-atomic', 'true');
39
+
40
+ dots.forEach((dot, i) => {
41
+ if (!dot.id) dot.id = `pp-carousel-${rootIdx}-dot-${i}`;
42
+ if (!dot.getAttribute('aria-label')) dot.setAttribute('aria-label', `Go to slide ${i + 1}`);
43
+ });
44
+
45
+ if (prevBtn && !prevBtn.getAttribute('aria-label')) prevBtn.setAttribute('aria-label', 'Previous slide');
46
+ if (nextBtn && !nextBtn.getAttribute('aria-label')) nextBtn.setAttribute('aria-label', 'Next slide');
47
+
48
+ function syncUI(idx) {
49
+ current = idx;
50
+
51
+ slides.forEach((slide, i) => slide.setAttribute('aria-hidden', String(i !== idx)));
52
+
53
+ dots.forEach((dot, i) => {
54
+ dot.classList.toggle('is-active', i === idx);
55
+ dot.setAttribute('aria-current', String(i === idx));
56
+ dot.setAttribute('tabindex', i === idx ? '0' : '-1');
57
+ });
58
+
59
+ if (prevBtn) {
60
+ prevBtn.disabled = idx === 0;
61
+ prevBtn.setAttribute('aria-disabled', String(idx === 0));
62
+ }
63
+ if (nextBtn) {
64
+ nextBtn.disabled = idx === total - 1;
65
+ nextBtn.setAttribute('aria-disabled', String(idx === total - 1));
66
+ }
67
+
68
+ const label = slides[idx].getAttribute('aria-label') || `Slide ${idx + 1}`;
69
+ announcer.textContent = '';
70
+ requestAnimationFrame(() => { announcer.textContent = label; });
71
+
72
+ root.dispatchEvent(new CustomEvent('pp:carousel:change', {
73
+ bubbles: true,
74
+ detail: { index: idx, total, label },
75
+ }));
76
+ }
77
+
78
+ const observer = new IntersectionObserver(
79
+ (entries) => {
80
+ entries.forEach((entry) => {
81
+ if (entry.isIntersecting) {
82
+ const idx = slides.indexOf(entry.target);
83
+ if (idx !== -1 && idx !== current) syncUI(idx);
84
+ }
85
+ });
86
+ },
87
+ { root: track, threshold: 0.5 }
88
+ );
89
+ slides.forEach((slide) => observer.observe(slide));
90
+
91
+ function goTo(idx) {
92
+ const clamped = Math.max(0, Math.min(total - 1, idx));
93
+ slides[clamped].scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });
94
+ syncUI(clamped);
95
+ }
96
+
97
+ if (prevBtn) prevBtn.addEventListener('click', () => goTo(current - 1));
98
+ if (nextBtn) nextBtn.addEventListener('click', () => goTo(current + 1));
99
+
100
+ dots.forEach((dot, i) => {
101
+ dot.addEventListener('click', () => goTo(i));
102
+ dot.addEventListener('keydown', (e) => {
103
+ if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
104
+ e.preventDefault(); goTo((i + 1) % total); dots[(i + 1) % total].focus();
105
+ }
106
+ if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
107
+ e.preventDefault(); goTo((i - 1 + total) % total); dots[(i - 1 + total) % total].focus();
108
+ }
109
+ if (e.key === 'Home') { e.preventDefault(); goTo(0); dots[0].focus(); }
110
+ if (e.key === 'End') { e.preventDefault(); goTo(total - 1); dots[total - 1].focus(); }
111
+ });
112
+ });
113
+
114
+ if (autoplayBtn) {
115
+ autoplayBtn.addEventListener('click', () => {
116
+ const playing = root.classList.contains('pp-carousel--playing');
117
+ root.classList.toggle('pp-carousel--playing', !playing);
118
+ root.classList.toggle('pp-carousel--paused', playing);
119
+ autoplayBtn.setAttribute('aria-pressed', String(!playing));
120
+ autoplayBtn.setAttribute('aria-label', playing ? 'Start autoplay' : 'Pause autoplay');
121
+ root.dispatchEvent(new CustomEvent('pp-carousel:autoplay', { bubbles: true, detail: { playing: !playing } }));
122
+ });
123
+ }
124
+
125
+ track.setAttribute('tabindex', '0');
126
+ track.addEventListener('keydown', (e) => {
127
+ if (e.key === 'ArrowRight') { e.preventDefault(); goTo(current + 1); }
128
+ if (e.key === 'ArrowLeft') { e.preventDefault(); goTo(current - 1); }
129
+ if (e.key === 'Home') { e.preventDefault(); goTo(0); }
130
+ if (e.key === 'End') { e.preventDefault(); goTo(total - 1); }
131
+ });
132
+
133
+ syncUI(0);
134
+
135
+ return { goTo, current: () => current, total };
136
+ }
137
+
138
+ const instances = {};
139
+ document.querySelectorAll('.pp-carousel').forEach((el, i) => {
140
+ const id = el.id || `pp-carousel-${i}`;
141
+ const api = initCarousel(el, i);
142
+ if (api) instances[id] = api;
143
+ });
144
+
145
+ window.ppCarousel = {
146
+ get(ref) {
147
+ if (typeof ref === 'string') return instances[ref];
148
+ if (ref instanceof Element) return instances[ref.id] || Object.values(instances).find((_, k) => document.getElementById(Object.keys(instances)[k]) === ref);
149
+ return null;
150
+ },
151
+ instances,
152
+ };
153
+ })();