@dorsk/tsumikit 0.14.0 → 0.16.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/README.md CHANGED
@@ -129,6 +129,10 @@ triggers, and `SegmentedControl`. Each renders an exact
129
129
  original ghost icon-button default. Use `control` on `Button` or `Popover` when
130
130
  the roomier shared `--control-height` composer contract is required.
131
131
 
132
+ Button and Popover share the same semantic tones. For a confirmed positive
133
+ action, `tone="success"` gives neutral controls a success tint; combine it with
134
+ `variant="primary"` for a filled success action without consumer CSS.
135
+
132
136
  ## Built on the platform
133
137
 
134
138
  Interactive components lean on modern web features rather than reimplementing
@@ -6,8 +6,8 @@
6
6
  variant?: 'default' | 'primary' | 'ghost' | 'danger';
7
7
  // Semantic state tint layered on top of the variant: tints text/border and
8
8
  // adds a subtle fill on hover. For stateful controls — an "on"/active toggle
9
- // (`accent`), or cost/severity states (`info`, `warn`).
10
- tone?: 'none' | 'accent' | 'info' | 'warn' | 'danger';
9
+ // (`accent`), positive actions (`success`), or cost/severity states.
10
+ tone?: 'none' | 'accent' | 'success' | 'info' | 'warn' | 'danger';
11
11
  size?: 'sm' | 'md' | 'lg';
12
12
  control?: boolean;
13
13
  block?: boolean;
@@ -66,6 +66,7 @@
66
66
  class:btn-icon={icon}
67
67
  class:btn-chip={chip}
68
68
  class:btn-tone-accent={tone === 'accent'}
69
+ class:btn-tone-success={tone === 'success'}
69
70
  class:btn-tone-info={tone === 'info'}
70
71
  class:btn-tone-warn={tone === 'warn'}
71
72
  class:btn-tone-danger={tone === 'danger'}
@@ -156,6 +157,9 @@
156
157
  .btn-tone-accent {
157
158
  --btn-tone: var(--accent);
158
159
  }
160
+ .btn-tone-success {
161
+ --btn-tone: var(--ok);
162
+ }
159
163
  .btn-tone-info {
160
164
  --btn-tone: var(--info);
161
165
  }
@@ -166,6 +170,7 @@
166
170
  --btn-tone: var(--danger);
167
171
  }
168
172
  .btn-tone-accent,
173
+ .btn-tone-success,
169
174
  .btn-tone-info,
170
175
  .btn-tone-warn,
171
176
  .btn-tone-danger {
@@ -173,6 +178,7 @@
173
178
  border-color: color-mix(in srgb, var(--btn-tone) 50%, var(--border));
174
179
  }
175
180
  .btn-tone-accent:hover:not(:disabled),
181
+ .btn-tone-success:hover:not(:disabled),
176
182
  .btn-tone-info:hover:not(:disabled),
177
183
  .btn-tone-warn:hover:not(:disabled),
178
184
  .btn-tone-danger:hover:not(:disabled) {
@@ -234,6 +240,26 @@
234
240
  border-color: var(--accent);
235
241
  filter: brightness(1.08);
236
242
  }
243
+ .btn-control.btn-tone-success {
244
+ color: var(--ok);
245
+ border-color: color-mix(in srgb, var(--ok) 50%, var(--border));
246
+ }
247
+ .btn-control.btn-tone-success:hover:not(:disabled) {
248
+ background: color-mix(in srgb, var(--ok) 14%, transparent);
249
+ border-color: var(--ok);
250
+ }
251
+ /* A positive primary action uses success as its fill, not merely as the
252
+ neutral tint. This follows the control override so both heights match. */
253
+ .btn-primary.btn-tone-success {
254
+ background: var(--ok);
255
+ border-color: var(--ok);
256
+ color: var(--text-on-success);
257
+ }
258
+ .btn-primary.btn-tone-success:hover:not(:disabled) {
259
+ background: var(--ok);
260
+ border-color: var(--ok);
261
+ filter: brightness(1.08);
262
+ }
237
263
 
238
264
  /* Icon-only buttons (IconButton). Square box = consistent 2.25rem tap target. */
239
265
  .btn-icon {
@@ -2,7 +2,7 @@ import type { Snippet } from 'svelte';
2
2
  import type { HTMLButtonAttributes } from 'svelte/elements';
3
3
  type ButtonProps = HTMLButtonAttributes & {
4
4
  variant?: 'default' | 'primary' | 'ghost' | 'danger';
5
- tone?: 'none' | 'accent' | 'info' | 'warn' | 'danger';
5
+ tone?: 'none' | 'accent' | 'success' | 'info' | 'warn' | 'danger';
6
6
  size?: 'sm' | 'md' | 'lg';
7
7
  control?: boolean;
8
8
  block?: boolean;
@@ -13,7 +13,7 @@
13
13
 
14
14
  type Placement = 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end';
15
15
  type TriggerVariant = 'default' | 'primary' | 'ghost' | 'danger';
16
- type TriggerTone = 'none' | 'accent' | 'info' | 'warn' | 'danger';
16
+ type TriggerTone = 'none' | 'accent' | 'success' | 'info' | 'warn' | 'danger';
17
17
  type TriggerSize = 'sm' | 'md' | 'lg';
18
18
 
19
19
  let {
@@ -101,6 +101,7 @@
101
101
  class:trigger-control={control}
102
102
  class:trigger-block={block}
103
103
  class:trigger-tone-accent={tone === 'accent'}
104
+ class:trigger-tone-success={tone === 'success'}
104
105
  class:trigger-tone-info={tone === 'info'}
105
106
  class:trigger-tone-warn={tone === 'warn'}
106
107
  class:trigger-tone-danger={tone === 'danger'}
@@ -212,6 +213,9 @@
212
213
  .pop-trigger.trigger-tone-accent {
213
214
  --pop-trigger-tone: var(--accent);
214
215
  }
216
+ .pop-trigger.trigger-tone-success {
217
+ --pop-trigger-tone: var(--ok);
218
+ }
215
219
  .pop-trigger.trigger-tone-info {
216
220
  --pop-trigger-tone: var(--info);
217
221
  }
@@ -222,6 +226,7 @@
222
226
  --pop-trigger-tone: var(--danger);
223
227
  }
224
228
  .pop-trigger.trigger-tone-accent,
229
+ .pop-trigger.trigger-tone-success,
225
230
  .pop-trigger.trigger-tone-info,
226
231
  .pop-trigger.trigger-tone-warn,
227
232
  .pop-trigger.trigger-tone-danger {
@@ -229,12 +234,23 @@
229
234
  border-color: color-mix(in srgb, var(--pop-trigger-tone) 50%, var(--border));
230
235
  }
231
236
  .pop-trigger.trigger-tone-accent:hover:not(:disabled),
237
+ .pop-trigger.trigger-tone-success:hover:not(:disabled),
232
238
  .pop-trigger.trigger-tone-info:hover:not(:disabled),
233
239
  .pop-trigger.trigger-tone-warn:hover:not(:disabled),
234
240
  .pop-trigger.trigger-tone-danger:hover:not(:disabled) {
235
241
  background: color-mix(in srgb, var(--pop-trigger-tone) 14%, transparent);
236
242
  border-color: var(--pop-trigger-tone);
237
243
  }
244
+ .pop-trigger.trigger-primary.trigger-tone-success {
245
+ background: var(--ok);
246
+ border-color: var(--ok);
247
+ color: var(--text-on-success);
248
+ }
249
+ .pop-trigger.trigger-primary.trigger-tone-success:hover:not(:disabled) {
250
+ background: var(--ok);
251
+ border-color: var(--ok);
252
+ filter: brightness(1.08);
253
+ }
238
254
  .pop-trigger:disabled {
239
255
  opacity: 0.45;
240
256
  cursor: not-allowed;
@@ -1,7 +1,7 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  type Placement = 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end';
3
3
  type TriggerVariant = 'default' | 'primary' | 'ghost' | 'danger';
4
- type TriggerTone = 'none' | 'accent' | 'info' | 'warn' | 'danger';
4
+ type TriggerTone = 'none' | 'accent' | 'success' | 'info' | 'warn' | 'danger';
5
5
  type TriggerSize = 'sm' | 'md' | 'lg';
6
6
  type $$ComponentProps = {
7
7
  placement?: Placement;
@@ -32,6 +32,7 @@
32
32
  value,
33
33
  mode = 'datetime',
34
34
  utc = false,
35
+ precision = false,
35
36
  details = true,
36
37
  selectable = false,
37
38
  mono = false,
@@ -49,6 +50,9 @@
49
50
  * (zoneless). Handy for calendar-date fields, where a local midnight-UTC
50
51
  * value would otherwise show the wrong day. */
51
52
  utc?: boolean;
53
+ /** Relative mode only: render two units ("1d 15h", "1h 55m") instead of a
54
+ * single rounded unit. Default false. */
55
+ precision?: boolean;
52
56
  /** Click to open the details popover (UTC / local / relative / zone /
53
57
  * epoch). Default true. When false, renders as a bare inline <time>. */
54
58
  details?: boolean;
@@ -83,7 +87,7 @@
83
87
  });
84
88
 
85
89
  const date = $derived(toDate(value));
86
- const label = $derived(formatTimestamp(value, current, now, utc));
90
+ const label = $derived(formatTimestamp(value, current, now, utc, precision));
87
91
  // datetime= wants a valid ISO string; omit it entirely on bad input.
88
92
  const machine = $derived(date ? toISO(date) : undefined);
89
93
  const showPopover = $derived(details || selectable);
@@ -105,7 +109,7 @@
105
109
  ? [
106
110
  { k: 'UTC', v: toISO(date) },
107
111
  { k: 'Local', v: toLocale(date, 'datetime') },
108
- { k: 'Relative', v: relativeTime(date, now) },
112
+ { k: 'Relative', v: relativeTime(date, now, true) },
109
113
  { k: 'Time zone', v: localTimeZone() },
110
114
  { k: 'Unix', v: String(toEpochSeconds(date)) }
111
115
  ]
@@ -12,6 +12,9 @@ type $$ComponentProps = {
12
12
  * (zoneless). Handy for calendar-date fields, where a local midnight-UTC
13
13
  * value would otherwise show the wrong day. */
14
14
  utc?: boolean;
15
+ /** Relative mode only: render two units ("1d 15h", "1h 55m") instead of a
16
+ * single rounded unit. Default false. */
17
+ precision?: boolean;
15
18
  /** Click to open the details popover (UTC / local / relative / zone /
16
19
  * epoch). Default true. When false, renders as a bare inline <time>. */
17
20
  details?: boolean;
@@ -73,6 +73,9 @@
73
73
  --text-muted: var(--c-text-muted);
74
74
  --text-faint: var(--c-text-faint);
75
75
  --text-on-accent: var(--c-accent-ink);
76
+ /* Adaptive ink for filled positive actions: dark canvas ink on bright greens,
77
+ light canvas ink on the darker greens used by light themes. */
78
+ --text-on-success: var(--bg);
76
79
 
77
80
  --accent: var(--c-accent);
78
81
  --accent-dim: var(--c-accent-dim);
@@ -28,11 +28,17 @@ export declare function localTimeZone(): string;
28
28
  * "3m ago", "2h ago", "5d ago" — past-relative, coarsening as it ages and
29
29
  * falling back to a locale date once past ~30 days. Future instants read
30
30
  * "in 3m" etc. `now` is injectable so callers (and tests) control the clock.
31
+ *
32
+ * The single-unit form **rounds to the nearest** unit (not truncating), so an
33
+ * instant 1d 15h away reads "in 2d" rather than the misleading "in 1d", and the
34
+ * rounding carries across boundaries (23h40m → "1d"). Pass `precision` for the
35
+ * two-unit form — "1d 15h", "1h 55m" — which keeps the coarse unit exact and
36
+ * shows the remainder instead of rounding it away.
31
37
  */
32
- export declare function relativeTime(value: TimeInput | null | undefined, now?: number): string;
38
+ export declare function relativeTime(value: TimeInput | null | undefined, now?: number, precision?: boolean): string;
33
39
  /**
34
40
  * Render a date in the chosen inline mode. `utc` selects UTC over the viewer's
35
41
  * zone for the date/time/datetime modes (ignored by `iso`, always UTC, and
36
42
  * `relative`, zoneless). Returns '' for unparseable input.
37
43
  */
38
- export declare function formatTimestamp(value: TimeInput | null | undefined, mode: TimestampMode, now?: number, utc?: boolean): string;
44
+ export declare function formatTimestamp(value: TimeInput | null | undefined, mode: TimestampMode, now?: number, utc?: boolean, precision?: boolean): string;
package/dist/timestamp.js CHANGED
@@ -49,12 +49,21 @@ export function toEpochSeconds(d) {
49
49
  export function localTimeZone() {
50
50
  return Intl.DateTimeFormat().resolvedOptions().timeZone;
51
51
  }
52
+ const MIN = 60;
53
+ const HOUR = 60 * MIN;
54
+ const DAY = 24 * HOUR;
52
55
  /**
53
56
  * "3m ago", "2h ago", "5d ago" — past-relative, coarsening as it ages and
54
57
  * falling back to a locale date once past ~30 days. Future instants read
55
58
  * "in 3m" etc. `now` is injectable so callers (and tests) control the clock.
59
+ *
60
+ * The single-unit form **rounds to the nearest** unit (not truncating), so an
61
+ * instant 1d 15h away reads "in 2d" rather than the misleading "in 1d", and the
62
+ * rounding carries across boundaries (23h40m → "1d"). Pass `precision` for the
63
+ * two-unit form — "1d 15h", "1h 55m" — which keeps the coarse unit exact and
64
+ * shows the remainder instead of rounding it away.
56
65
  */
57
- export function relativeTime(value, now = Date.now()) {
66
+ export function relativeTime(value, now = Date.now(), precision = false) {
58
67
  const d = toDate(value);
59
68
  if (!d)
60
69
  return '';
@@ -62,15 +71,32 @@ export function relativeTime(value, now = Date.now()) {
62
71
  const future = deltaMs < 0;
63
72
  const secs = Math.floor(Math.abs(deltaMs) / 1000);
64
73
  const suffix = (s) => (future ? `in ${s}` : `${s} ago`);
65
- if (secs < 60)
74
+ if (secs < MIN)
66
75
  return suffix(`${secs}s`);
67
- const mins = Math.floor(secs / 60);
76
+ if (secs >= 30 * DAY)
77
+ return d.toLocaleDateString();
78
+ if (precision) {
79
+ if (secs < HOUR) {
80
+ const m = Math.floor(secs / MIN);
81
+ const s = secs % MIN;
82
+ return suffix(s ? `${m}m ${s}s` : `${m}m`);
83
+ }
84
+ if (secs < DAY) {
85
+ const h = Math.floor(secs / HOUR);
86
+ const m = Math.floor((secs % HOUR) / MIN);
87
+ return suffix(m ? `${h}h ${m}m` : `${h}h`);
88
+ }
89
+ const days = Math.floor(secs / DAY);
90
+ const h = Math.floor((secs % DAY) / HOUR);
91
+ return suffix(h ? `${days}d ${h}h` : `${days}d`);
92
+ }
93
+ const mins = Math.round(secs / MIN);
68
94
  if (mins < 60)
69
95
  return suffix(`${mins}m`);
70
- const hrs = Math.floor(mins / 60);
96
+ const hrs = Math.round(secs / HOUR);
71
97
  if (hrs < 24)
72
98
  return suffix(`${hrs}h`);
73
- const days = Math.floor(hrs / 24);
99
+ const days = Math.round(secs / DAY);
74
100
  if (days < 30)
75
101
  return suffix(`${days}d`);
76
102
  return d.toLocaleDateString();
@@ -80,7 +106,7 @@ export function relativeTime(value, now = Date.now()) {
80
106
  * zone for the date/time/datetime modes (ignored by `iso`, always UTC, and
81
107
  * `relative`, zoneless). Returns '' for unparseable input.
82
108
  */
83
- export function formatTimestamp(value, mode, now, utc = false) {
109
+ export function formatTimestamp(value, mode, now, utc = false, precision = false) {
84
110
  const d = toDate(value);
85
111
  if (!d)
86
112
  return '';
@@ -92,6 +118,6 @@ export function formatTimestamp(value, mode, now, utc = false) {
92
118
  case 'datetime':
93
119
  return toLocale(d, mode, utc);
94
120
  case 'relative':
95
- return relativeTime(d, now);
121
+ return relativeTime(d, now, precision);
96
122
  }
97
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dorsk/tsumikit",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "Minimal, dependency-free Svelte 5 + pure-CSS UI kit. Token-driven atoms, molecules & layouts with theming out of the box.",
5
5
  "type": "module",
6
6
  "license": "MIT",