@dorsk/tsumikit 0.2.6 → 0.2.7
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.
|
@@ -7,30 +7,65 @@
|
|
|
7
7
|
// gutter. `maxCols` optionally caps how many columns the grid will ever show:
|
|
8
8
|
// it raises the effective per-column minimum to the width N columns would
|
|
9
9
|
// need, so auto-fit can never pack more than N across.
|
|
10
|
+
//
|
|
11
|
+
// `max` caps each column's width: instead of growing to fill the row (the
|
|
12
|
+
// default `1fr`), columns top out at `max` and the grid left-packs them
|
|
13
|
+
// (auto-fill + justify-content:start) so a 3-item and a 4-item section both
|
|
14
|
+
// show uniform fixed-width columns rather than stretching to fill. `align`
|
|
15
|
+
// controls cross-axis alignment of items within their row; it defaults to
|
|
16
|
+
// `start` so cards don't stretch to the tallest sibling.
|
|
10
17
|
import type { Snippet } from 'svelte';
|
|
11
18
|
|
|
12
19
|
let {
|
|
13
20
|
as = 'div',
|
|
14
21
|
min = '14rem',
|
|
22
|
+
max,
|
|
15
23
|
gap = 'var(--sp-4)',
|
|
16
24
|
maxCols,
|
|
25
|
+
align = 'start',
|
|
26
|
+
justify,
|
|
17
27
|
class: klass = '',
|
|
18
28
|
children,
|
|
19
29
|
...rest
|
|
20
30
|
}: {
|
|
21
31
|
as?: 'div' | 'section' | 'ul' | 'ol';
|
|
22
32
|
min?: string;
|
|
33
|
+
/** Maximum column width. When set, columns stop growing at this width and
|
|
34
|
+
* the grid left-packs uniform tracks instead of stretching to fill. */
|
|
35
|
+
max?: string;
|
|
23
36
|
gap?: string;
|
|
24
37
|
maxCols?: number;
|
|
38
|
+
/** Cross-axis alignment of items in their row (align-items). Defaults to `start`. */
|
|
39
|
+
align?: 'start' | 'center' | 'end' | 'stretch';
|
|
40
|
+
/** Inline (main-axis) distribution of tracks (justify-content). Defaults to
|
|
41
|
+
* `start` when `max` is set, otherwise the grid's natural `stretch`. */
|
|
42
|
+
justify?: 'start' | 'center' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch';
|
|
25
43
|
class?: string;
|
|
26
44
|
children?: Snippet;
|
|
27
45
|
[key: string]: unknown;
|
|
28
46
|
} = $props();
|
|
29
47
|
|
|
48
|
+
// Columns grow to fill (`1fr`) by default; when `max` is given they cap there.
|
|
49
|
+
let track = $derived(max != null ? max : '1fr');
|
|
50
|
+
// auto-fill keeps capped tracks from stretching to fill the row; auto-fit
|
|
51
|
+
// (the default) collapses empty tracks so columns expand to use the space.
|
|
52
|
+
let mode = $derived(max != null ? 'auto-fill' : 'auto-fit');
|
|
53
|
+
// Left-pack capped grids by default so columns don't drift to fill the row.
|
|
54
|
+
let justifyValue = $derived(justify ?? (max != null ? 'start' : null));
|
|
55
|
+
|
|
30
56
|
let style = $derived(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
57
|
+
[
|
|
58
|
+
`--ag-min: ${min}`,
|
|
59
|
+
`--ag-track: ${track}`,
|
|
60
|
+
`--ag-mode: ${mode}`,
|
|
61
|
+
maxCols != null ? `--ag-gap: ${gap}` : null,
|
|
62
|
+
maxCols != null ? `--ag-cols: ${maxCols}` : null,
|
|
63
|
+
`gap: ${gap}`,
|
|
64
|
+
`align-items: ${align}`,
|
|
65
|
+
justifyValue ? `justify-content: ${justifyValue}` : null
|
|
66
|
+
]
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
.join('; ')
|
|
34
69
|
);
|
|
35
70
|
</script>
|
|
36
71
|
|
|
@@ -47,7 +82,7 @@
|
|
|
47
82
|
<style>
|
|
48
83
|
.autogrid-c {
|
|
49
84
|
display: grid;
|
|
50
|
-
grid-template-columns: repeat(
|
|
85
|
+
grid-template-columns: repeat(var(--ag-mode), minmax(min(100%, var(--ag-min)), var(--ag-track)));
|
|
51
86
|
}
|
|
52
87
|
|
|
53
88
|
/* Cap at N columns: the per-column floor becomes the larger of `min` and the
|
|
@@ -56,10 +91,10 @@
|
|
|
56
91
|
overflowing when the container is narrower than a single `min` track. */
|
|
57
92
|
.autogrid-c.capped {
|
|
58
93
|
grid-template-columns: repeat(
|
|
59
|
-
|
|
94
|
+
var(--ag-mode),
|
|
60
95
|
minmax(
|
|
61
96
|
min(100%, max(var(--ag-min), (100% - (var(--ag-cols) - 1) * var(--ag-gap)) / var(--ag-cols))),
|
|
62
|
-
|
|
97
|
+
var(--ag-track)
|
|
63
98
|
)
|
|
64
99
|
);
|
|
65
100
|
}
|
|
@@ -2,8 +2,16 @@ import type { Snippet } from 'svelte';
|
|
|
2
2
|
type $$ComponentProps = {
|
|
3
3
|
as?: 'div' | 'section' | 'ul' | 'ol';
|
|
4
4
|
min?: string;
|
|
5
|
+
/** Maximum column width. When set, columns stop growing at this width and
|
|
6
|
+
* the grid left-packs uniform tracks instead of stretching to fill. */
|
|
7
|
+
max?: string;
|
|
5
8
|
gap?: string;
|
|
6
9
|
maxCols?: number;
|
|
10
|
+
/** Cross-axis alignment of items in their row (align-items). Defaults to `start`. */
|
|
11
|
+
align?: 'start' | 'center' | 'end' | 'stretch';
|
|
12
|
+
/** Inline (main-axis) distribution of tracks (justify-content). Defaults to
|
|
13
|
+
* `start` when `max` is set, otherwise the grid's natural `stretch`. */
|
|
14
|
+
justify?: 'start' | 'center' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch';
|
|
7
15
|
class?: string;
|
|
8
16
|
children?: Snippet;
|
|
9
17
|
[key: string]: unknown;
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
// Centered, max-width content column with token gutters that respect safe-area
|
|
3
3
|
// insets. `size` overrides the default --content-max; `pad` toggles vertical
|
|
4
|
-
// padding.
|
|
4
|
+
// padding. `fullWidth` releases the max-width constraint and lets the content
|
|
5
|
+
// bleed to the full viewport width even when nested inside a centered ancestor
|
|
6
|
+
// (the `margin-inline: calc(50% - 50vw)` trick), for edge-to-edge sections.
|
|
7
|
+
// Polymorphic via `as` so it can be a <main>, <section>, etc.
|
|
5
8
|
import type { Snippet } from 'svelte';
|
|
6
9
|
|
|
7
10
|
let {
|
|
8
11
|
as = 'div',
|
|
9
12
|
size,
|
|
10
13
|
pad = false,
|
|
14
|
+
fullWidth = false,
|
|
11
15
|
class: klass = '',
|
|
12
16
|
children,
|
|
13
17
|
...rest
|
|
14
18
|
}: {
|
|
15
19
|
as?: 'div' | 'main' | 'section' | 'article';
|
|
16
|
-
/** Max width (any CSS length). Defaults to --content-max. */
|
|
20
|
+
/** Max width (any CSS length). Defaults to --content-max. Ignored when `fullWidth`. */
|
|
17
21
|
size?: string;
|
|
18
22
|
pad?: boolean;
|
|
23
|
+
/** Break out to the full viewport width, ignoring `size`/--content-max. */
|
|
24
|
+
fullWidth?: boolean;
|
|
19
25
|
class?: string;
|
|
20
26
|
children?: Snippet;
|
|
21
27
|
[key: string]: unknown;
|
|
@@ -26,7 +32,8 @@
|
|
|
26
32
|
this={as}
|
|
27
33
|
class="container ct {klass}"
|
|
28
34
|
class:pad
|
|
29
|
-
|
|
35
|
+
class:full={fullWidth}
|
|
36
|
+
style={!fullWidth && size ? `max-width: ${size}` : undefined}
|
|
30
37
|
{...rest}
|
|
31
38
|
>
|
|
32
39
|
{@render children?.()}
|
|
@@ -37,4 +44,13 @@
|
|
|
37
44
|
padding-top: var(--sp-6);
|
|
38
45
|
padding-bottom: var(--sp-12);
|
|
39
46
|
}
|
|
47
|
+
|
|
48
|
+
/* Break out of any centered ancestor to span the full viewport width.
|
|
49
|
+
`margin-inline: calc(50% - 50vw)` pulls each edge out to the viewport,
|
|
50
|
+
keeping the element in normal flow (no transform/overflow side-effects). */
|
|
51
|
+
.ct.full {
|
|
52
|
+
max-width: none;
|
|
53
|
+
width: 100vw;
|
|
54
|
+
margin-inline: calc(50% - 50vw);
|
|
55
|
+
}
|
|
40
56
|
</style>
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
type $$ComponentProps = {
|
|
3
3
|
as?: 'div' | 'main' | 'section' | 'article';
|
|
4
|
-
/** Max width (any CSS length). Defaults to --content-max. */
|
|
4
|
+
/** Max width (any CSS length). Defaults to --content-max. Ignored when `fullWidth`. */
|
|
5
5
|
size?: string;
|
|
6
6
|
pad?: boolean;
|
|
7
|
+
/** Break out to the full viewport width, ignoring `size`/--content-max. */
|
|
8
|
+
fullWidth?: boolean;
|
|
7
9
|
class?: string;
|
|
8
10
|
children?: Snippet;
|
|
9
11
|
[key: string]: unknown;
|
package/package.json
CHANGED