@auriel/peppertino 0.4.0 → 0.5.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 (63) hide show
  1. package/CHANGELOG.txt +88 -0
  2. package/MIGRATION.md +52 -0
  3. package/README.md +184 -42
  4. package/dist/accordion.js +41 -4
  5. package/dist/accordion.js.map +2 -2
  6. package/dist/alert.js +26 -0
  7. package/dist/alert.js.map +7 -0
  8. package/dist/carousel.js +4 -0
  9. package/dist/carousel.js.map +2 -2
  10. package/dist/header.js +1 -0
  11. package/dist/header.js.map +2 -2
  12. package/dist/main.css +1047 -338
  13. package/dist/main.css.map +1 -1
  14. package/dist/modal.js +2 -0
  15. package/dist/modal.js.map +2 -2
  16. package/dist/peppertino.js +244 -15
  17. package/dist/peppertino.js.map +3 -3
  18. package/dist/select.js +2 -4
  19. package/dist/select.js.map +2 -2
  20. package/dist/switch.js +29 -0
  21. package/dist/switch.js.map +7 -0
  22. package/dist/tabs.js +27 -7
  23. package/dist/tabs.js.map +2 -2
  24. package/dist/theme.js +47 -0
  25. package/dist/theme.js.map +7 -0
  26. package/dist/toast.js +69 -0
  27. package/dist/toast.js.map +7 -0
  28. package/index.html +241 -45
  29. package/package.json +6 -4
  30. package/scripts/hex-to-hsl.mjs +75 -0
  31. package/scripts/lint-bem.mjs +53 -0
  32. package/scripts/lint-colors.mjs +87 -0
  33. package/src/js/accordion.js +48 -6
  34. package/src/js/alert.js +28 -0
  35. package/src/js/carousel.js +5 -0
  36. package/src/js/header.js +1 -0
  37. package/src/js/modal.js +4 -0
  38. package/src/js/peppertino.js +4 -0
  39. package/src/js/select.js +2 -4
  40. package/src/js/switch.js +28 -0
  41. package/src/js/tabs.js +31 -21
  42. package/src/js/theme.js +47 -0
  43. package/src/js/toast.js +79 -0
  44. package/src/scss/accordion.scss +8 -8
  45. package/src/scss/alert.scss +30 -31
  46. package/src/scss/badge.scss +90 -0
  47. package/src/scss/base.scss +267 -66
  48. package/src/scss/button.scss +44 -46
  49. package/src/scss/carousel.scss +18 -28
  50. package/src/scss/dark-mode.scss +135 -95
  51. package/src/scss/footer.scss +12 -12
  52. package/src/scss/forms/fieldset.scss +8 -8
  53. package/src/scss/forms/form-instructions.scss +8 -8
  54. package/src/scss/forms/text-field.scss +13 -13
  55. package/src/scss/forms/validation.scss +11 -11
  56. package/src/scss/gradient.scss +2 -2
  57. package/src/scss/main.scss +4 -0
  58. package/src/scss/modal.scss +2 -2
  59. package/src/scss/select.scss +3 -3
  60. package/src/scss/switch.scss +121 -0
  61. package/src/scss/tabs.scss +26 -26
  62. package/src/scss/toast.scss +170 -0
  63. package/src/scss/tooltip.scss +126 -0
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env bun
2
+ // Fails if any SCSS component file contains literal color values that should
3
+ // be CSS custom properties. Structural white/black overlays are allowed.
4
+ // Usage: bun run scripts/lint-colors.mjs
5
+
6
+ import { readdir, readFile } from 'fs/promises';
7
+ import { join, relative } from 'path';
8
+
9
+ const EXEMPT = new Set(['base.scss', 'dark-mode.scss']);
10
+
11
+ // Patterns that are ALLOWED in component files (structural design choices):
12
+ // - Pure white/black with opacity: rgb(255...), rgb(0...), rgba(#fff,...), rgba(0,0,0,...)
13
+ // - Transparent keyword
14
+ const ALLOWED_PATTERNS = [
15
+ /rgba?\(255[^)]*\)/, // white with alpha
16
+ /rgba?\(0,\s*0,\s*0[^)]*\)/, // black with alpha
17
+ /rgba?\(#fff[^)]*\)/, // #fff with alpha
18
+ /rgba?\(#000[^)]*\)/, // #000 with alpha
19
+ /rgb\(255\s+255\s+255[^)]*\)/, // modern white syntax
20
+ /rgb\(0\s+0\s+0[^)]*\)/, // modern black syntax
21
+ /^#fff$/i, // pure white
22
+ /^#000$/i, // pure black
23
+ ];
24
+
25
+ // Patterns that are BANNED (should use CSS vars instead):
26
+ const BANNED = [
27
+ { pattern: /rgba?\(\s*\$color[-_\w]+\s*,/g, desc: 'rgba() with SCSS color variable — use hsl(var(--pp-*-h) ... / alpha)' },
28
+ { pattern: /rgba?\(\s*\$gradient[-_\w]*\s*,/g, desc: 'rgba() with SCSS gradient variable — use hsl(var(--pp-gradient-*-h) ... / alpha)' },
29
+ { pattern: /#[0-9a-fA-F]{6}(?!\s*[}|;,\n]?\s*!|[0-9a-fA-F])/g, desc: '6-digit hex color — use var(--pp-*)' },
30
+ ];
31
+
32
+ // Allowed 6-digit hexes (structural white/black variants):
33
+ const ALLOWED_HEX = new Set(['#ffffff', '#000000', '#ffb3b3']);
34
+
35
+ async function scanDir(dir) {
36
+ const entries = await readdir(dir, { withFileTypes: true });
37
+ const files = [];
38
+ for (const entry of entries) {
39
+ if (entry.isDirectory()) {
40
+ files.push(...await scanDir(join(dir, entry.name)));
41
+ } else if (entry.name.endsWith('.scss') && !EXEMPT.has(entry.name)) {
42
+ files.push(join(dir, entry.name));
43
+ }
44
+ }
45
+ return files;
46
+ }
47
+
48
+ const scssDir = join(import.meta.dir, '..', 'src', 'scss');
49
+ const files = await scanDir(scssDir);
50
+
51
+ let totalViolations = 0;
52
+
53
+ for (const file of files) {
54
+ const src = await readFile(file, 'utf8');
55
+ const lines = src.split('\n');
56
+ const relPath = relative(join(import.meta.dir, '..'), file);
57
+
58
+ lines.forEach((line, i) => {
59
+ const lineNum = i + 1;
60
+ const trimmed = line.trim();
61
+ if (trimmed.startsWith('//')) return; // skip comments
62
+
63
+ for (const { pattern, desc } of BANNED) {
64
+ const regex = new RegExp(pattern.source, pattern.flags);
65
+ let match;
66
+ while ((match = regex.exec(line)) !== null) {
67
+ const hit = match[0].toLowerCase();
68
+ // Skip if it matches an allowed pattern
69
+ if (ALLOWED_PATTERNS.some((p) => p.test(match[0]))) continue;
70
+ if (ALLOWED_HEX.has(hit)) continue;
71
+ // Skip obvious structural #fff patterns
72
+ if (hit === '#fff' || hit === '#000') continue;
73
+
74
+ console.error(` ${relPath}:${lineNum} ${desc}`);
75
+ console.error(` → ${line.trim()}`);
76
+ totalViolations++;
77
+ }
78
+ }
79
+ });
80
+ }
81
+
82
+ if (totalViolations > 0) {
83
+ console.error(`\n✖ lint-colors: ${totalViolations} violation(s) found. Replace with var(--pp-*) tokens.\n`);
84
+ process.exit(1);
85
+ } else {
86
+ console.log('✔ lint-colors: No literal color tokens found in component files.');
87
+ }
@@ -1,8 +1,14 @@
1
1
  (function () {
2
- document.querySelectorAll('.pp-accordion').forEach((accordion) => {
2
+ const registry = {};
3
+
4
+ document.querySelectorAll('.pp-accordion').forEach((accordion, accordionIdx) => {
3
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')];
4
10
 
5
- accordion.querySelectorAll('.pp-accordion__trigger').forEach((trigger) => {
11
+ triggers.forEach((trigger, i) => {
6
12
  const panelId = trigger.getAttribute('aria-controls');
7
13
  const panel = panelId
8
14
  ? document.getElementById(panelId)
@@ -10,7 +16,6 @@
10
16
 
11
17
  if (!panel) return;
12
18
 
13
- // Ensure ARIA state matches DOM on init
14
19
  const isOpen = trigger.getAttribute('aria-expanded') === 'true';
15
20
  panel.setAttribute('aria-hidden', isOpen ? 'false' : 'true');
16
21
  if (isOpen) panel.classList.add('is-open');
@@ -19,7 +24,7 @@
19
24
  const expanded = trigger.getAttribute('aria-expanded') === 'true';
20
25
 
21
26
  if (!allowMultiple) {
22
- accordion.querySelectorAll('.pp-accordion__trigger').forEach((t) => {
27
+ triggers.forEach((t) => {
23
28
  if (t === trigger) return;
24
29
  t.setAttribute('aria-expanded', 'false');
25
30
  const p = t.getAttribute('aria-controls')
@@ -36,11 +41,14 @@
36
41
  trigger.setAttribute('aria-expanded', String(next));
37
42
  panel.setAttribute('aria-hidden', String(!next));
38
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
+ }));
39
49
  });
40
50
 
41
- // Keyboard: Home/End focus management within accordion
42
51
  trigger.addEventListener('keydown', (e) => {
43
- const triggers = [...accordion.querySelectorAll('.pp-accordion__trigger')];
44
52
  const idx = triggers.indexOf(trigger);
45
53
  if (e.key === 'ArrowDown') {
46
54
  e.preventDefault();
@@ -57,5 +65,39 @@
57
65
  }
58
66
  });
59
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;
60
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
+ };
61
103
  })();
@@ -0,0 +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
+ })();
@@ -68,6 +68,11 @@
68
68
  const label = slides[idx].getAttribute('aria-label') || `Slide ${idx + 1}`;
69
69
  announcer.textContent = '';
70
70
  requestAnimationFrame(() => { announcer.textContent = label; });
71
+
72
+ root.dispatchEvent(new CustomEvent('pp:carousel:change', {
73
+ bubbles: true,
74
+ detail: { index: idx, total, label },
75
+ }));
71
76
  }
72
77
 
73
78
  const observer = new IntersectionObserver(
package/src/js/header.js CHANGED
@@ -39,6 +39,7 @@
39
39
  const isOpen = nav.classList.toggle('is-open');
40
40
  toggle.setAttribute('aria-expanded', String(isOpen));
41
41
  nav.setAttribute('aria-hidden', String(!isOpen));
42
+ header.dispatchEvent(new CustomEvent(isOpen ? 'pp:header:open' : 'pp:header:close', { bubbles: true }));
42
43
  });
43
44
 
44
45
  // Close drawer on outside click
package/src/js/modal.js CHANGED
@@ -67,6 +67,8 @@
67
67
 
68
68
  backdrop._trapFocus = (e) => trapFocus(e, backdrop);
69
69
  backdrop.addEventListener('keydown', backdrop._trapFocus);
70
+
71
+ backdrop.dispatchEvent(new CustomEvent('pp:modal:open', { bubbles: true }));
70
72
  }
71
73
 
72
74
  function closeModal(id) {
@@ -86,6 +88,8 @@
86
88
  delete backdrop._trapFocus;
87
89
  }
88
90
 
91
+ backdrop.dispatchEvent(new CustomEvent('pp:modal:close', { bubbles: true }));
92
+
89
93
  // Restore focus to the element that opened the modal
90
94
  if (lastFocused && typeof lastFocused.focus === 'function') {
91
95
  lastFocused.focus();
@@ -3,9 +3,13 @@
3
3
  // Each component is a self-contained IIFE in its own file — import only what you need.
4
4
 
5
5
  import './accordion.js';
6
+ import './alert.js';
6
7
  import './carousel.js';
7
8
  import './header.js';
8
9
  import './modal.js';
9
10
  import './select.js';
11
+ import './switch.js';
10
12
  import './tabs.js';
13
+ import './theme.js';
14
+ import './toast.js';
11
15
  import './validation.js';
package/src/js/select.js CHANGED
@@ -67,10 +67,8 @@
67
67
  const nativeSelect = wrapper.querySelector('select[data-pp-select]');
68
68
  if (nativeSelect) nativeSelect.value = opt.dataset.value ?? opt.textContent.trim();
69
69
 
70
- wrapper.dispatchEvent(new CustomEvent('pp-select:change', {
71
- bubbles: true,
72
- detail: { value: opt.dataset.value, label: opt.textContent.trim() },
73
- }));
70
+ const detail = { value: opt.dataset.value, label: opt.textContent.trim() };
71
+ wrapper.dispatchEvent(new CustomEvent('pp:select:change', { bubbles: true, detail }));
74
72
 
75
73
  close();
76
74
  trigger.focus();
@@ -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
+ })();
package/src/js/tabs.js CHANGED
@@ -1,12 +1,12 @@
1
1
  (function () {
2
+ const registry = {};
3
+
2
4
  function initTabs(tabGroup, groupIdx) {
3
- const items = tabGroup.querySelectorAll('.pp-tabs__item');
5
+ const items = [...tabGroup.querySelectorAll('.pp-tabs__item')];
4
6
  const targetAttr = 'data-tab-target';
5
7
 
6
- // Ensure tablist role
7
8
  if (!tabGroup.getAttribute('role')) tabGroup.setAttribute('role', 'tablist');
8
9
 
9
- // Wire up tab roles and aria-controls
10
10
  items.forEach((item, i) => {
11
11
  item.setAttribute('role', 'tab');
12
12
  if (!item.id) item.id = `pp-tab-${groupIdx}-${i}`;
@@ -34,7 +34,6 @@
34
34
  item.setAttribute('aria-selected', 'true');
35
35
  item.setAttribute('tabindex', '0');
36
36
 
37
- // Show/hide associated panels if present
38
37
  const targetId = item.getAttribute(targetAttr);
39
38
  if (targetId) {
40
39
  document.querySelectorAll('[data-tab-panel]').forEach((panel) => {
@@ -44,51 +43,62 @@
44
43
  });
45
44
  }
46
45
 
47
- tabGroup.dispatchEvent(new CustomEvent('pp-tabs:change', {
48
- bubbles: true,
49
- detail: { value: item.dataset.tabTarget, label: item.textContent.trim() },
50
- }));
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 }));
51
48
  }
52
49
 
53
- // Click
54
50
  items.forEach((item) => {
55
51
  item.addEventListener('click', () => activate(item));
56
52
  });
57
53
 
58
- // Keyboard: left/right arrow navigation
59
54
  tabGroup.addEventListener('keydown', (e) => {
60
- const current = [...items].findIndex((i) => i === document.activeElement);
55
+ const current = items.findIndex((i) => i === document.activeElement);
61
56
  if (current === -1) return;
62
57
 
63
58
  if (e.key === 'ArrowRight') {
64
59
  e.preventDefault();
65
60
  const next = items[(current + 1) % items.length];
66
- activate(next);
67
- next.focus();
61
+ activate(next); next.focus();
68
62
  }
69
63
  if (e.key === 'ArrowLeft') {
70
64
  e.preventDefault();
71
65
  const prev = items[(current - 1 + items.length) % items.length];
72
- activate(prev);
73
- prev.focus();
66
+ activate(prev); prev.focus();
74
67
  }
75
68
  if (e.key === 'Home') {
76
69
  e.preventDefault();
77
- activate(items[0]);
78
- items[0].focus();
70
+ activate(items[0]); items[0].focus();
79
71
  }
80
72
  if (e.key === 'End') {
81
73
  e.preventDefault();
82
- activate(items[items.length - 1]);
83
- items[items.length - 1].focus();
74
+ activate(items[items.length - 1]); items[items.length - 1].focus();
84
75
  }
85
76
  });
86
77
 
87
- // Set initial tabindex
88
78
  items.forEach((item) => {
89
79
  item.setAttribute('tabindex', item.classList.contains('is-active') ? '0' : '-1');
90
80
  });
81
+
82
+ return {
83
+ activate(index) {
84
+ const item = items[index];
85
+ if (item) { activate(item); item.focus(); }
86
+ },
87
+ };
91
88
  }
92
89
 
93
- document.querySelectorAll('.pp-tabs').forEach((el, i) => initTabs(el, i));
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
+ };
94
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
+ })();
@@ -115,24 +115,24 @@
115
115
 
116
116
  // ─── Variant: dark ────────────────────────────────────────────────────────────
117
117
  .pp-accordion--dark {
118
- background: $color-neutral-900;
119
- border-color: $color-neutral-700;
118
+ background: var(--pp-neutral-900);
119
+ border-color: var(--pp-neutral-700);
120
120
 
121
121
  .pp-accordion__item {
122
- border-color: $color-neutral-700;
122
+ border-color: var(--pp-neutral-700);
123
123
  }
124
124
 
125
125
  .pp-accordion__trigger {
126
126
  color: rgba(#fff, 0.85);
127
127
 
128
128
  &:hover {
129
- background: $color-neutral-800;
129
+ background: var(--pp-neutral-800);
130
130
  color: #fff;
131
131
  }
132
132
 
133
133
  &[aria-expanded='true'] {
134
- color: $color-primary-light;
135
- background: $color-neutral-800;
134
+ color: var(--pp-primary-light);
135
+ background: var(--pp-neutral-800);
136
136
  }
137
137
  }
138
138
 
@@ -144,13 +144,13 @@
144
144
  // ─── Variant: primary accent trigger ─────────────────────────────────────────
145
145
  .pp-accordion--primary {
146
146
  .pp-accordion__trigger[aria-expanded='true'] {
147
- background: $color-primary;
147
+ background: var(--pp-primary);
148
148
  color: #fff;
149
149
  }
150
150
 
151
151
  .pp-accordion__item:has(.pp-accordion__trigger[aria-expanded='true']) {
152
152
  .pp-accordion__panel {
153
- background: rgba($color-primary, 0.04);
153
+ background: hsl(var(--pp-primary-h) var(--pp-primary-s) var(--pp-primary-l) / 0.04);
154
154
  }
155
155
  }
156
156
  }