@klodd/ds 5.6.0 → 5.7.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/SKILL.md CHANGED
@@ -6,10 +6,11 @@ description: Design memory for the @klodd/ds shared design system used by the tw
6
6
  # @klodd/ds — Design Memory
7
7
 
8
8
  ## Status
9
- Senast audit: 2026-05-20. Pågående arbete enligt `audits/00-summary.md`:
10
- - Sprint 1: dead-code-städning + topbar-bump (~435 rader)
11
- - Sprint 2: component-token-konsolidering, ADR 0024-backfill, light-theme-removal
12
- - Sprint 3: base.css-extraktion till paketets base-lager
9
+ Designsystem-auditen (2026-05-20, se `audits/00-summary.md`) slutförd -
10
+ alla tre sprintar klara:
11
+ - Sprint 1: dead-code-städning + topbar-bump (5.4.3)
12
+ - Sprint 2: component-token-konsolidering, ADR 0024-backfill, light-theme-removal (5.5.0)
13
+ - Sprint 3: base.css-extraktion till paketets base/interactions.css (5.6.0)
13
14
 
14
15
  ## Vad detta är
15
16
  Gemensamt designsystem på npm (`@klodd/ds@5.x`). Tre-lagers tokens,
package/js/sheet.js ADDED
@@ -0,0 +1,96 @@
1
+ /*--------------------------------------------------------------
2
+ sheet.js - bottom-sheet open/close for <dialog class="sheet">.
3
+
4
+ Native <dialog> skoter ESC, focus-trap och inert-bakgrund. Denna
5
+ modul lagger till:
6
+ - openSheet(id) / closeSheet(dlg), exponerade som globals
7
+ window.__sheetOpen / window.__sheetClose
8
+ - click-delegation: [data-sheet]-trigger oppnar sheet, klick pa
9
+ backdrop eller [data-sheet-close] stanger
10
+ - drag-state-reset: nollar inline transform/transition som
11
+ sheet-drag.js kan lamna kvar om en sheet stangs mitt i en drag
12
+
13
+ Laddas fore app-lokal JS som anropar window.__sheetOpen.
14
+ --------------------------------------------------------------*/
15
+ (function () {
16
+ // Defensiv state-reset mot drag-physics-laeckage. sheet-drag.js
17
+ // satter inline style.transform + style.transition under drag och
18
+ // cleanar via transitionend-event. Om dialogen stangs innan
19
+ // transitionen avslutas (ESC, backdrop-klick, programmatic close
20
+ // eller form-submit mid-animation) eldas transitionend ALDRIG och
21
+ // inline-style laecker till nasta showModal() - sheet hamnar dar
22
+ // drag avbrots (ofta utanfor viewport eller halvvags upp). Reset i
23
+ // open + close + close-event-listener ger clean state oavsett hur
24
+ // dialogen stangts.
25
+ function resetDragState(dlg) {
26
+ dlg.style.transform = '';
27
+ dlg.style.transition = '';
28
+ }
29
+ function openSheet(id) {
30
+ const dlg = document.querySelector('dialog.sheet[data-sheet-id="' + id + '"]');
31
+ if (!dlg) return null;
32
+ resetDragState(dlg);
33
+ if (typeof dlg.showModal === 'function' && !dlg.open) {
34
+ dlg.showModal();
35
+ } else {
36
+ // Fallback for browsers utan <dialog>.
37
+ dlg.setAttribute('open', '');
38
+ }
39
+ // Auto-focus + select-all pa input markerad med
40
+ // data-sheet-autofocus. setTimeout 50ms sa showModal-animationen
41
+ // hunnit borja innan focus-grabben (annars hoppar caret).
42
+ const focusEl = dlg.querySelector('[data-sheet-autofocus]');
43
+ if (focusEl) {
44
+ setTimeout(function () {
45
+ try {
46
+ focusEl.focus({ preventScroll: true });
47
+ if (typeof focusEl.select === 'function') focusEl.select();
48
+ } catch (_) { /* ignore */ }
49
+ }, 50);
50
+ }
51
+ return dlg;
52
+ }
53
+ function closeSheet(dlg) {
54
+ if (!dlg) return;
55
+ resetDragState(dlg);
56
+ if (typeof dlg.close === 'function' && dlg.open) {
57
+ dlg.close();
58
+ } else {
59
+ dlg.removeAttribute('open');
60
+ }
61
+ }
62
+ // Exponera for andra moduler (sheet-drag, optimistic-UI).
63
+ window.__sheetOpen = openSheet;
64
+ window.__sheetClose = closeSheet;
65
+
66
+ // ESC-stangning + native dialog.close() gar inte via closeSheet
67
+ // ovan. Lyssna pa close-event i capture-phase (close-event har
68
+ // bubbles: false per spec, sa capture ar enda sattet att fanga det
69
+ // med delegation pa document-niva). Reset drag-geometri sa nasta
70
+ // open startar med clean inline-style.
71
+ document.addEventListener('close', function (e) {
72
+ if (e.target instanceof HTMLDialogElement && e.target.classList.contains('sheet')) {
73
+ resetDragState(e.target);
74
+ }
75
+ }, true);
76
+
77
+ document.addEventListener('click', function (e) {
78
+ const trigger = e.target.closest('[data-sheet]');
79
+ if (trigger) {
80
+ openSheet(trigger.dataset.sheet);
81
+ e.preventDefault();
82
+ return;
83
+ }
84
+ // Backdrop-click: e.target ar dialog-elementet sjalvt (klick
85
+ // utanfor content-omradet, pa backdrop som <dialog> renderar).
86
+ if (e.target.tagName === 'DIALOG' && e.target.classList.contains('sheet')) {
87
+ closeSheet(e.target);
88
+ return;
89
+ }
90
+ // Avbryt-knapp inne i sheet.
91
+ if (e.target.closest('[data-sheet-close]')) {
92
+ const dlg = e.target.closest('dialog.sheet');
93
+ closeSheet(dlg);
94
+ }
95
+ });
96
+ })();
package/js/toast.js ADDED
@@ -0,0 +1,31 @@
1
+ /*--------------------------------------------------------------
2
+ toast.js - transient feedback-meddelanden.
3
+
4
+ window.showToast(message, type, duration)
5
+ type 'info' (default) | 'success' | 'error' | 'warning'
6
+ duration ms innan auto-removal (default 3000)
7
+
8
+ Skapar ett .toast-element och stackar det i #toast-region. Kraver:
9
+ - ett element med id="toast-region" i DOM (mountpoint)
10
+ - .toast / .toast--out / .toast--{success,error,warning} CSS
11
+ (paketets components/feedback.css + .toast-region/.toast--out
12
+ i app-doman-CSS)
13
+
14
+ Laddas fore app-lokal JS som anropar window.showToast.
15
+ --------------------------------------------------------------*/
16
+ (function () {
17
+ window.showToast = function (message, type, duration) {
18
+ type = type || 'info';
19
+ duration = duration || 3000;
20
+ const region = document.getElementById('toast-region');
21
+ if (!region) return;
22
+ const el = document.createElement('div');
23
+ el.className = 'toast' + (type !== 'info' ? ' toast--' + type : '');
24
+ el.textContent = message;
25
+ region.appendChild(el);
26
+ setTimeout(function () {
27
+ el.classList.add('toast--out');
28
+ el.addEventListener('animationend', function () { el.remove(); }, { once: true });
29
+ }, duration);
30
+ };
31
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@klodd/ds",
3
- "version": "5.6.0",
3
+ "version": "5.7.0",
4
4
  "description": "Klodd shared design system - tokens, components, JS",
5
5
  "main": "css/index.css",
6
6
  "bin": {