@auriel/peppertino 0.5.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.
- package/CHANGELOG.txt +242 -224
- package/LICENSE +21 -21
- package/MIGRATION.md +52 -52
- package/README.md +773 -764
- package/agents/peppertino/SKILL.md +76 -0
- package/agents/peppertino/accordion.md +134 -0
- package/agents/peppertino/alert.md +116 -0
- package/agents/peppertino/badge.md +74 -0
- package/agents/peppertino/base.md +252 -0
- package/agents/peppertino/button.md +65 -0
- package/agents/peppertino/card.md +82 -0
- package/agents/peppertino/carousel.md +147 -0
- package/agents/peppertino/catalog.md +81 -0
- package/agents/peppertino/dark-mode.md +152 -0
- package/agents/peppertino/footer.md +109 -0
- package/agents/peppertino/forms-fieldset.md +85 -0
- package/agents/peppertino/forms-form-instructions.md +94 -0
- package/agents/peppertino/forms-label.md +110 -0
- package/agents/peppertino/forms-text-field.md +134 -0
- package/agents/peppertino/forms-validation.md +153 -0
- package/agents/peppertino/gradient.md +41 -0
- package/agents/peppertino/header.md +105 -0
- package/agents/peppertino/modal.md +123 -0
- package/agents/peppertino/section.md +56 -0
- package/agents/peppertino/select.md +110 -0
- package/agents/peppertino/switch.md +72 -0
- package/agents/peppertino/table.md +69 -0
- package/agents/peppertino/tabs.md +115 -0
- package/agents/peppertino/toast.md +96 -0
- package/agents/peppertino/tooltip.md +111 -0
- package/agents/peppertino/typography.md +118 -0
- package/agents/peppertino/utilities.md +194 -0
- package/agents/skill.md +65 -0
- package/build.js +53 -53
- package/dist/accordion.js +1 -1
- package/dist/accordion.js.map +2 -2
- package/dist/alert.js.map +1 -1
- package/dist/carousel.js.map +1 -1
- package/dist/header.js.map +1 -1
- package/dist/main.css +2566 -1008
- package/dist/main.css.map +1 -1
- package/dist/main.min.css +1 -0
- package/dist/modal.js.map +1 -1
- package/dist/peppertino.js +1 -1
- package/dist/peppertino.js.map +2 -2
- package/dist/select.js.map +1 -1
- package/dist/switch.js.map +1 -1
- package/dist/tabs.js.map +1 -1
- package/dist/theme.js.map +1 -1
- package/dist/toast.js.map +1 -1
- package/dist/validation.js.map +1 -1
- package/icon.svg +4 -0
- package/index.html +2172 -2098
- package/package.json +28 -28
- package/scripts/hex-to-hsl.mjs +75 -75
- package/scripts/lint-bem.mjs +53 -53
- package/scripts/lint-colors.mjs +87 -87
- package/site.webmanifest +18 -0
- package/src/js/accordion.js +105 -103
- package/src/js/alert.js +28 -28
- package/src/js/carousel.js +153 -153
- package/src/js/header.js +85 -85
- package/src/js/modal.js +138 -138
- package/src/js/peppertino.js +15 -15
- package/src/js/select.js +101 -101
- package/src/js/switch.js +28 -28
- package/src/js/tabs.js +104 -104
- package/src/js/theme.js +47 -47
- package/src/js/toast.js +79 -79
- package/src/js/validation.js +132 -132
- package/src/scss/accordion.scss +190 -156
- package/src/scss/activity.scss +17 -0
- package/src/scss/alert.scss +203 -203
- package/src/scss/badge.scss +90 -90
- package/src/scss/base.scss +511 -506
- package/src/scss/button.scss +119 -119
- package/src/scss/card.scss +121 -121
- package/src/scss/carousel.scss +303 -303
- package/src/scss/code-block.scss +22 -0
- package/src/scss/counter.scss +5 -0
- package/src/scss/dark-mode.scss +514 -514
- package/src/scss/duration.scss +26 -0
- package/src/scss/folder.scss +27 -0
- package/src/scss/footer.scss +224 -224
- package/src/scss/forms/fieldset.scss +127 -127
- package/src/scss/forms/form-instructions.scss +133 -133
- package/src/scss/forms/label.scss +115 -115
- package/src/scss/forms/text-field.scss +240 -240
- package/src/scss/forms/validation.scss +215 -215
- package/src/scss/forms.scss +8 -8
- package/src/scss/gradient.scss +11 -11
- package/src/scss/gravity-letters.scss +7 -0
- package/src/scss/header.scss +257 -238
- package/src/scss/helpers/color.scss +9 -0
- package/src/scss/helpers/flex.scss +14 -0
- package/src/scss/helpers/index.scss +6 -0
- package/src/scss/helpers/layout.scss +14 -0
- package/src/scss/helpers/spacing.scss +14 -0
- package/src/scss/helpers/typography.scss +11 -0
- package/src/scss/helpers/visibility.scss +9 -0
- package/src/scss/main.scss +49 -24
- package/src/scss/modal.scss +188 -188
- package/src/scss/model-picker.scss +5 -0
- package/src/scss/notification.scss +5 -0
- package/src/scss/orb.scss +7 -0
- package/src/scss/otp.scss +5 -0
- package/src/scss/pill-nav.scss +10 -0
- package/src/scss/prompt.scss +28 -0
- package/src/scss/rail.scss +7 -0
- package/src/scss/reactions.scss +5 -0
- package/src/scss/reset.scss +84 -84
- package/src/scss/response.scss +11 -0
- package/src/scss/reveal.scss +5 -0
- package/src/scss/scroll-progress.scss +4 -0
- package/src/scss/search-results.scss +13 -0
- package/src/scss/section.scss +87 -79
- package/src/scss/select.scss +210 -210
- package/src/scss/sidebar.scss +8 -0
- package/src/scss/status.scss +5 -0
- package/src/scss/step-list.scss +13 -0
- package/src/scss/switch.scss +121 -121
- package/src/scss/table.scss +89 -89
- package/src/scss/tabs.scss +156 -156
- package/src/scss/task-list.scss +18 -0
- package/src/scss/theme-picker.scss +5 -0
- package/src/scss/toast.scss +170 -170
- package/src/scss/tooltip.scss +126 -126
- package/src/scss/typography.scss +58 -58
- package/src/scss/utilities.scss +243 -243
- package/src/scss/voice-note.scss +5 -0
package/src/js/accordion.js
CHANGED
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return
|
|
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
|
+
})();
|
package/src/js/carousel.js
CHANGED
|
@@ -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
|
+
})();
|