svelte-ant-design 0.7.0 → 0.8.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
@@ -18,7 +18,7 @@ Ant Design.
18
18
 
19
19
  ## Status
20
20
 
21
- Version `0.7.0`. Available components: `Button`, `Checkbox` (with `CheckboxGroup`), `Input` (with `InputTextArea`, `InputPassword`, `InputSearch` and `InputOTP`), `Radio` (with `RadioButton` and `RadioGroup`), `Select` (with `SelectOption` and `SelectOptGroup`), `Switch`, `Tooltip`. More components are planned.
21
+ Version `0.8.0`. Available components: `Button`, `Checkbox` (with `CheckboxGroup`), `Grid` (`Row`, `Col` and `Breakpoints`), `Input` (with `InputTextArea`, `InputPassword`, `InputSearch` and `InputOTP`), `Radio` (with `RadioButton` and `RadioGroup`), `Select` (with `SelectOption` and `SelectOptGroup`), `Switch`, `Tooltip`. More components are planned.
22
22
 
23
23
  ## Browser support
24
24
 
@@ -59,6 +59,7 @@ Vite in `tests/packaging`; other bundlers are not covered.
59
59
 
60
60
  See the [Button](https://prostreyd.github.io/ant-design-svelte/components/button/),
61
61
  [Checkbox](https://prostreyd.github.io/ant-design-svelte/components/checkbox/),
62
+ [Grid](https://prostreyd.github.io/ant-design-svelte/components/grid/),
62
63
  [Input](https://prostreyd.github.io/ant-design-svelte/components/input/),
63
64
  [Radio](https://prostreyd.github.io/ant-design-svelte/components/radio/),
64
65
  [Select](https://prostreyd.github.io/ant-design-svelte/components/select/),
@@ -66,6 +67,7 @@ See the [Button](https://prostreyd.github.io/ant-design-svelte/components/button
66
67
  [Tooltip](https://prostreyd.github.io/ant-design-svelte/components/tooltip/) pages of the documentation site for
67
68
  examples and the API tables, or [`src/lib/Button/README.md`](./src/lib/Button/README.md),
68
69
  [`src/lib/Checkbox/README.md`](./src/lib/Checkbox/README.md),
70
+ [`src/lib/Grid/README.md`](./src/lib/Grid/README.md),
69
71
  [`src/lib/Input/README.md`](./src/lib/Input/README.md),
70
72
  [`src/lib/Radio/README.md`](./src/lib/Radio/README.md),
71
73
  [`src/lib/Select/README.md`](./src/lib/Select/README.md),
@@ -0,0 +1,43 @@
1
+ import type { Breakpoint } from './types.js';
2
+ export type BreakpointsOptions = {
3
+ /**
4
+ * The breakpoint to report where the screen cannot be asked (on the server). The flags are those of a screen exactly
5
+ * as wide as this breakpoint starts. Default `'xs'`.
6
+ */
7
+ fallback?: Breakpoint;
8
+ };
9
+ /**
10
+ * Which breakpoints the screen matches now, as plain properties that a template or a `$derived` can read:
11
+ *
12
+ * ```svelte
13
+ * <script>
14
+ * const screens = new Breakpoints();
15
+ * </script>
16
+ * {#if screens.md}...{/if}
17
+ * ```
18
+ *
19
+ * `xs` is true below 576 px; every other flag is true from its minimum width up (so at 1000 px `sm`, `md` and `lg` are
20
+ * true), and `current` is the largest one that matches. The values are read from the screen when the object is created,
21
+ * so they are right on the first render in a browser. On the server they follow `options.fallback`. The listeners exist
22
+ * only while something reactive reads the values.
23
+ */
24
+ export declare class Breakpoints {
25
+ #private;
26
+ constructor(options?: BreakpointsOptions);
27
+ /** Below 576 px. */
28
+ get xs(): boolean;
29
+ /** From 576 px up. */
30
+ get sm(): boolean;
31
+ /** From 768 px up. */
32
+ get md(): boolean;
33
+ /** From 992 px up. */
34
+ get lg(): boolean;
35
+ /** From 1200 px up. */
36
+ get xl(): boolean;
37
+ /** From 1600 px up. */
38
+ get xxl(): boolean;
39
+ /** From 1920 px up. */
40
+ get xxxl(): boolean;
41
+ /** The largest breakpoint that matches (`'xs'` below 576 px). */
42
+ get current(): Breakpoint;
43
+ }
@@ -0,0 +1,99 @@
1
+ import { createSubscriber } from 'svelte/reactivity';
2
+ import { resolveOption } from '../internal/options.js';
3
+ import { BREAKPOINT_NAMES, BREAKPOINTS } from './constants.js';
4
+ /**
5
+ * The media query of each breakpoint. `xs` is the complement of `sm` (below 576 px), the others are "from their
6
+ * minimum width up", so at any width `xs` is true or `sm` is, never both and never neither, even at 575.5 px.
7
+ */
8
+ const QUERIES = Object.freeze({
9
+ xs: `not all and (min-width: ${BREAKPOINTS.sm}px)`,
10
+ sm: `(min-width: ${BREAKPOINTS.sm}px)`,
11
+ md: `(min-width: ${BREAKPOINTS.md}px)`,
12
+ lg: `(min-width: ${BREAKPOINTS.lg}px)`,
13
+ xl: `(min-width: ${BREAKPOINTS.xl}px)`,
14
+ xxl: `(min-width: ${BREAKPOINTS.xxl}px)`,
15
+ xxxl: `(min-width: ${BREAKPOINTS.xxxl}px)`
16
+ });
17
+ /** Whether a screen exactly `width` px wide matches the breakpoint. */
18
+ function matchesWidth(breakpoint, width) {
19
+ return breakpoint === 'xs' ? width < BREAKPOINTS.sm : width >= BREAKPOINTS[breakpoint];
20
+ }
21
+ /**
22
+ * Which breakpoints the screen matches now, as plain properties that a template or a `$derived` can read:
23
+ *
24
+ * ```svelte
25
+ * <script>
26
+ * const screens = new Breakpoints();
27
+ * </script>
28
+ * {#if screens.md}...{/if}
29
+ * ```
30
+ *
31
+ * `xs` is true below 576 px; every other flag is true from its minimum width up (so at 1000 px `sm`, `md` and `lg` are
32
+ * true), and `current` is the largest one that matches. The values are read from the screen when the object is created,
33
+ * so they are right on the first render in a browser. On the server they follow `options.fallback`. The listeners exist
34
+ * only while something reactive reads the values.
35
+ */
36
+ export class Breakpoints {
37
+ #fallback;
38
+ #lists;
39
+ #subscribe;
40
+ constructor(options = {}) {
41
+ this.#fallback = resolveOption('Breakpoints', 'fallback', options.fallback ?? 'xs', BREAKPOINT_NAMES, 'xs');
42
+ this.#lists =
43
+ typeof window !== 'undefined' && typeof window.matchMedia === 'function'
44
+ ? Object.fromEntries(BREAKPOINT_NAMES.map((name) => [name, window.matchMedia(QUERIES[name])]))
45
+ : undefined;
46
+ this.#subscribe = createSubscriber((update) => {
47
+ const lists = this.#lists;
48
+ if (!lists)
49
+ return;
50
+ for (const name of BREAKPOINT_NAMES)
51
+ lists[name].addEventListener('change', update);
52
+ return () => {
53
+ for (const name of BREAKPOINT_NAMES)
54
+ lists[name].removeEventListener('change', update);
55
+ };
56
+ });
57
+ }
58
+ #matches(breakpoint) {
59
+ this.#subscribe();
60
+ const list = this.#lists?.[breakpoint];
61
+ return list ? list.matches : matchesWidth(breakpoint, BREAKPOINTS[this.#fallback]);
62
+ }
63
+ /** Below 576 px. */
64
+ get xs() {
65
+ return this.#matches('xs');
66
+ }
67
+ /** From 576 px up. */
68
+ get sm() {
69
+ return this.#matches('sm');
70
+ }
71
+ /** From 768 px up. */
72
+ get md() {
73
+ return this.#matches('md');
74
+ }
75
+ /** From 992 px up. */
76
+ get lg() {
77
+ return this.#matches('lg');
78
+ }
79
+ /** From 1200 px up. */
80
+ get xl() {
81
+ return this.#matches('xl');
82
+ }
83
+ /** From 1600 px up. */
84
+ get xxl() {
85
+ return this.#matches('xxl');
86
+ }
87
+ /** From 1920 px up. */
88
+ get xxxl() {
89
+ return this.#matches('xxxl');
90
+ }
91
+ /** The largest breakpoint that matches (`'xs'` below 576 px). */
92
+ get current() {
93
+ let current = 'xs';
94
+ for (const name of BREAKPOINT_NAMES)
95
+ if (name !== 'xs' && this.#matches(name))
96
+ current = name;
97
+ return current;
98
+ }
99
+ }
@@ -0,0 +1,300 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLAttributes } from 'svelte/elements';
4
+ import { classList, styleText } from '../internal/semantic.js';
5
+ import { colVars } from './layout.js';
6
+ import type { ColSize } from './types.js';
7
+
8
+ type ColProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'style'> & {
9
+ /** How many of the 24 columns to take. `0` hides the column. Unset: the column keeps its content width. */
10
+ span?: number;
11
+ /** Empty columns before this one. */
12
+ offset?: number;
13
+ /** Columns to shift it towards the inline end, visually only (the DOM order does not change). */
14
+ push?: number;
15
+ /** Columns to shift it towards the inline start, visually only (the DOM order does not change). */
16
+ pull?: number;
17
+ /** The flex `order`, visually only (the DOM order does not change). */
18
+ order?: number;
19
+ /** A raw flex value: a number `n` is `n n auto`; a string is used as written (digits only: `n 1 0px`). */
20
+ flex?: string | number;
21
+ /** From 0 px up (the base of all widths). A number is a `span`. */
22
+ xs?: number | ColSize;
23
+ /** From 576 px up. A number is a `span`. */
24
+ sm?: number | ColSize;
25
+ /** From 768 px up. A number is a `span`. */
26
+ md?: number | ColSize;
27
+ /** From 992 px up. A number is a `span`. */
28
+ lg?: number | ColSize;
29
+ /** From 1200 px up. A number is a `span`. */
30
+ xl?: number | ColSize;
31
+ /** From 1600 px up. A number is a `span`. */
32
+ xxl?: number | ColSize;
33
+ /** From 1920 px up. A number is a `span`. */
34
+ xxxl?: number | ColSize;
35
+ /** Additional CSS class appended to the component classes. */
36
+ class?: string;
37
+ /** Inline style of the root; it is written after the component's own, so it wins on the same property. */
38
+ style?: string;
39
+ /** The content of the column. */
40
+ children?: Snippet;
41
+ };
42
+
43
+ let {
44
+ span,
45
+ offset,
46
+ push,
47
+ pull,
48
+ order,
49
+ flex,
50
+ xs,
51
+ sm,
52
+ md,
53
+ lg,
54
+ xl,
55
+ xxl,
56
+ xxxl,
57
+ class: customClass,
58
+ style,
59
+ children,
60
+ ...rest
61
+ }: ColProps = $props();
62
+
63
+ // Each given value is checked here (outside its contract it throws in development and is ignored in production)
64
+ // and written as a custom property; the `@media` rules below pick the one that fits the screen.
65
+ const vars = $derived(
66
+ colVars({ span, offset, push, pull, order, flex }, { xs, sm, md, lg, xl, xxl, xxxl })
67
+ );
68
+ const classes = $derived(classList('ads-col', customClass));
69
+ const inlineStyle = $derived(styleText(vars, style));
70
+ </script>
71
+
72
+ <div {...rest} class={classes} style={inlineStyle}>
73
+ {@render children?.()}
74
+ </div>
75
+
76
+ <style>
77
+ /*
78
+ * The component writes the values it was given as `--ads-col-<name>-<breakpoint>` (see layout.ts). A value that was
79
+ * not given stays "invalid" in the chains below, and a declaration that uses an invalid variable is dropped when the
80
+ * style is computed, so a column without `span` keeps its content width (`flex: 0 1 auto`). The `@media` rules at
81
+ * the end switch the resolved variables. The gutter `--_row-gx` comes from the Row the column stands in.
82
+ *
83
+ * Custom properties inherit, so the public ones are reset here: a Col inside a Col must not take the span of the outer
84
+ * one. An inline value, which the component writes, wins over this reset.
85
+ */
86
+ .ads-col {
87
+ --ads-col-span-xs: initial;
88
+ --ads-col-span-sm: initial;
89
+ --ads-col-span-md: initial;
90
+ --ads-col-span-lg: initial;
91
+ --ads-col-span-xl: initial;
92
+ --ads-col-span-xxl: initial;
93
+ --ads-col-span-xxxl: initial;
94
+ --ads-col-offset-xs: initial;
95
+ --ads-col-offset-sm: initial;
96
+ --ads-col-offset-md: initial;
97
+ --ads-col-offset-lg: initial;
98
+ --ads-col-offset-xl: initial;
99
+ --ads-col-offset-xxl: initial;
100
+ --ads-col-offset-xxxl: initial;
101
+ --ads-col-push-xs: initial;
102
+ --ads-col-push-sm: initial;
103
+ --ads-col-push-md: initial;
104
+ --ads-col-push-lg: initial;
105
+ --ads-col-push-xl: initial;
106
+ --ads-col-push-xxl: initial;
107
+ --ads-col-push-xxxl: initial;
108
+ --ads-col-pull-xs: initial;
109
+ --ads-col-pull-sm: initial;
110
+ --ads-col-pull-md: initial;
111
+ --ads-col-pull-lg: initial;
112
+ --ads-col-pull-xl: initial;
113
+ --ads-col-pull-xxl: initial;
114
+ --ads-col-pull-xxxl: initial;
115
+ --ads-col-order-xs: initial;
116
+ --ads-col-order-sm: initial;
117
+ --ads-col-order-md: initial;
118
+ --ads-col-order-lg: initial;
119
+ --ads-col-order-xl: initial;
120
+ --ads-col-order-xxl: initial;
121
+ --ads-col-order-xxxl: initial;
122
+ --ads-col-flex-xs: initial;
123
+ --ads-col-flex-sm: initial;
124
+ --ads-col-flex-md: initial;
125
+ --ads-col-flex-lg: initial;
126
+ --ads-col-flex-xl: initial;
127
+ --ads-col-flex-xxl: initial;
128
+ --ads-col-flex-xxxl: initial;
129
+ --ads-col-mw-xs: initial;
130
+ --ads-col-mw-sm: initial;
131
+ --ads-col-mw-md: initial;
132
+ --ads-col-mw-lg: initial;
133
+ --ads-col-mw-xl: initial;
134
+ --ads-col-mw-xxl: initial;
135
+ --ads-col-mw-xxxl: initial;
136
+ --ads-col-d-xs: initial;
137
+ --ads-col-d-sm: initial;
138
+ --ads-col-d-md: initial;
139
+ --ads-col-d-lg: initial;
140
+ --ads-col-d-xl: initial;
141
+ --ads-col-d-xxl: initial;
142
+ --ads-col-d-xxxl: initial;
143
+
144
+ --_span-xs: var(--ads-col-span-xs);
145
+ --_span-sm: var(--ads-col-span-sm, var(--_span-xs));
146
+ --_span-md: var(--ads-col-span-md, var(--_span-sm));
147
+ --_span-lg: var(--ads-col-span-lg, var(--_span-md));
148
+ --_span-xl: var(--ads-col-span-xl, var(--_span-lg));
149
+ --_span-xxl: var(--ads-col-span-xxl, var(--_span-xl));
150
+ --_span-xxxl: var(--ads-col-span-xxxl, var(--_span-xxl));
151
+ --_off-xs: var(--ads-col-offset-xs, 0);
152
+ --_off-sm: var(--ads-col-offset-sm, var(--_off-xs));
153
+ --_off-md: var(--ads-col-offset-md, var(--_off-sm));
154
+ --_off-lg: var(--ads-col-offset-lg, var(--_off-md));
155
+ --_off-xl: var(--ads-col-offset-xl, var(--_off-lg));
156
+ --_off-xxl: var(--ads-col-offset-xxl, var(--_off-xl));
157
+ --_off-xxxl: var(--ads-col-offset-xxxl, var(--_off-xxl));
158
+ --_push-xs: var(--ads-col-push-xs, 0);
159
+ --_push-sm: var(--ads-col-push-sm, var(--_push-xs));
160
+ --_push-md: var(--ads-col-push-md, var(--_push-sm));
161
+ --_push-lg: var(--ads-col-push-lg, var(--_push-md));
162
+ --_push-xl: var(--ads-col-push-xl, var(--_push-lg));
163
+ --_push-xxl: var(--ads-col-push-xxl, var(--_push-xl));
164
+ --_push-xxxl: var(--ads-col-push-xxxl, var(--_push-xxl));
165
+ --_pull-xs: var(--ads-col-pull-xs, 0);
166
+ --_pull-sm: var(--ads-col-pull-sm, var(--_pull-xs));
167
+ --_pull-md: var(--ads-col-pull-md, var(--_pull-sm));
168
+ --_pull-lg: var(--ads-col-pull-lg, var(--_pull-md));
169
+ --_pull-xl: var(--ads-col-pull-xl, var(--_pull-lg));
170
+ --_pull-xxl: var(--ads-col-pull-xxl, var(--_pull-xl));
171
+ --_pull-xxxl: var(--ads-col-pull-xxxl, var(--_pull-xxl));
172
+ --_order-xs: var(--ads-col-order-xs, 0);
173
+ --_order-sm: var(--ads-col-order-sm, var(--_order-xs));
174
+ --_order-md: var(--ads-col-order-md, var(--_order-sm));
175
+ --_order-lg: var(--ads-col-order-lg, var(--_order-md));
176
+ --_order-xl: var(--ads-col-order-xl, var(--_order-lg));
177
+ --_order-xxl: var(--ads-col-order-xxl, var(--_order-xl));
178
+ --_order-xxxl: var(--ads-col-order-xxxl, var(--_order-xxl));
179
+ --_flex-xs: var(--ads-col-flex-xs);
180
+ --_flex-sm: var(--ads-col-flex-sm, var(--_flex-xs));
181
+ --_flex-md: var(--ads-col-flex-md, var(--_flex-sm));
182
+ --_flex-lg: var(--ads-col-flex-lg, var(--_flex-md));
183
+ --_flex-xl: var(--ads-col-flex-xl, var(--_flex-lg));
184
+ --_flex-xxl: var(--ads-col-flex-xxl, var(--_flex-xl));
185
+ --_flex-xxxl: var(--ads-col-flex-xxxl, var(--_flex-xxl));
186
+ --_mw-xs: var(--ads-col-mw-xs);
187
+ --_mw-sm: var(--ads-col-mw-sm, var(--_mw-xs));
188
+ --_mw-md: var(--ads-col-mw-md, var(--_mw-sm));
189
+ --_mw-lg: var(--ads-col-mw-lg, var(--_mw-md));
190
+ --_mw-xl: var(--ads-col-mw-xl, var(--_mw-lg));
191
+ --_mw-xxl: var(--ads-col-mw-xxl, var(--_mw-xl));
192
+ --_mw-xxxl: var(--ads-col-mw-xxxl, var(--_mw-xxl));
193
+ --_d-xs: var(--ads-col-d-xs, block);
194
+ --_d-sm: var(--ads-col-d-sm, var(--_d-xs));
195
+ --_d-md: var(--ads-col-d-md, var(--_d-sm));
196
+ --_d-lg: var(--ads-col-d-lg, var(--_d-md));
197
+ --_d-xl: var(--ads-col-d-xl, var(--_d-lg));
198
+ --_d-xxl: var(--ads-col-d-xxl, var(--_d-xl));
199
+ --_d-xxxl: var(--ads-col-d-xxxl, var(--_d-xxl));
200
+
201
+ --_span: var(--_span-xs);
202
+ --_off: var(--_off-xs);
203
+ --_push: var(--_push-xs);
204
+ --_pull: var(--_pull-xs);
205
+ --_order: var(--_order-xs);
206
+ --_flex: var(--_flex-xs);
207
+ --_mw: var(--_mw-xs);
208
+ --_d: var(--_d-xs);
209
+
210
+ --_gx: var(--_row-gx, 0px);
211
+ /* The width of `span` columns: the span's share of the 24 columns, counting the gaps between them. */
212
+ --_w: calc((100% + var(--_gx)) * var(--_span) / 24 - var(--_gx));
213
+
214
+ position: relative;
215
+ display: var(--_d);
216
+ flex: var(--_flex, 0 0 var(--_w));
217
+ max-width: var(--_mw, var(--_w, 100%));
218
+ order: var(--_order);
219
+ margin-inline-start: calc((100% + var(--_gx)) * var(--_off) / 24);
220
+ inset-inline-start: calc((100% + var(--_gx)) * (var(--_push) - var(--_pull)) / 24);
221
+ }
222
+
223
+ @media (min-width: 576px) {
224
+ .ads-col {
225
+ --_span: var(--_span-sm);
226
+ --_off: var(--_off-sm);
227
+ --_push: var(--_push-sm);
228
+ --_pull: var(--_pull-sm);
229
+ --_order: var(--_order-sm);
230
+ --_flex: var(--_flex-sm);
231
+ --_mw: var(--_mw-sm);
232
+ --_d: var(--_d-sm);
233
+ }
234
+ }
235
+
236
+ @media (min-width: 768px) {
237
+ .ads-col {
238
+ --_span: var(--_span-md);
239
+ --_off: var(--_off-md);
240
+ --_push: var(--_push-md);
241
+ --_pull: var(--_pull-md);
242
+ --_order: var(--_order-md);
243
+ --_flex: var(--_flex-md);
244
+ --_mw: var(--_mw-md);
245
+ --_d: var(--_d-md);
246
+ }
247
+ }
248
+
249
+ @media (min-width: 992px) {
250
+ .ads-col {
251
+ --_span: var(--_span-lg);
252
+ --_off: var(--_off-lg);
253
+ --_push: var(--_push-lg);
254
+ --_pull: var(--_pull-lg);
255
+ --_order: var(--_order-lg);
256
+ --_flex: var(--_flex-lg);
257
+ --_mw: var(--_mw-lg);
258
+ --_d: var(--_d-lg);
259
+ }
260
+ }
261
+
262
+ @media (min-width: 1200px) {
263
+ .ads-col {
264
+ --_span: var(--_span-xl);
265
+ --_off: var(--_off-xl);
266
+ --_push: var(--_push-xl);
267
+ --_pull: var(--_pull-xl);
268
+ --_order: var(--_order-xl);
269
+ --_flex: var(--_flex-xl);
270
+ --_mw: var(--_mw-xl);
271
+ --_d: var(--_d-xl);
272
+ }
273
+ }
274
+
275
+ @media (min-width: 1600px) {
276
+ .ads-col {
277
+ --_span: var(--_span-xxl);
278
+ --_off: var(--_off-xxl);
279
+ --_push: var(--_push-xxl);
280
+ --_pull: var(--_pull-xxl);
281
+ --_order: var(--_order-xxl);
282
+ --_flex: var(--_flex-xxl);
283
+ --_mw: var(--_mw-xxl);
284
+ --_d: var(--_d-xxl);
285
+ }
286
+ }
287
+
288
+ @media (min-width: 1920px) {
289
+ .ads-col {
290
+ --_span: var(--_span-xxxl);
291
+ --_off: var(--_off-xxxl);
292
+ --_push: var(--_push-xxxl);
293
+ --_pull: var(--_pull-xxxl);
294
+ --_order: var(--_order-xxxl);
295
+ --_flex: var(--_flex-xxxl);
296
+ --_mw: var(--_mw-xxxl);
297
+ --_d: var(--_d-xxxl);
298
+ }
299
+ }
300
+ </style>
@@ -0,0 +1,40 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import type { ColSize } from './types.js';
4
+ type ColProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'style'> & {
5
+ /** How many of the 24 columns to take. `0` hides the column. Unset: the column keeps its content width. */
6
+ span?: number;
7
+ /** Empty columns before this one. */
8
+ offset?: number;
9
+ /** Columns to shift it towards the inline end, visually only (the DOM order does not change). */
10
+ push?: number;
11
+ /** Columns to shift it towards the inline start, visually only (the DOM order does not change). */
12
+ pull?: number;
13
+ /** The flex `order`, visually only (the DOM order does not change). */
14
+ order?: number;
15
+ /** A raw flex value: a number `n` is `n n auto`; a string is used as written (digits only: `n 1 0px`). */
16
+ flex?: string | number;
17
+ /** From 0 px up (the base of all widths). A number is a `span`. */
18
+ xs?: number | ColSize;
19
+ /** From 576 px up. A number is a `span`. */
20
+ sm?: number | ColSize;
21
+ /** From 768 px up. A number is a `span`. */
22
+ md?: number | ColSize;
23
+ /** From 992 px up. A number is a `span`. */
24
+ lg?: number | ColSize;
25
+ /** From 1200 px up. A number is a `span`. */
26
+ xl?: number | ColSize;
27
+ /** From 1600 px up. A number is a `span`. */
28
+ xxl?: number | ColSize;
29
+ /** From 1920 px up. A number is a `span`. */
30
+ xxxl?: number | ColSize;
31
+ /** Additional CSS class appended to the component classes. */
32
+ class?: string;
33
+ /** Inline style of the root; it is written after the component's own, so it wins on the same property. */
34
+ style?: string;
35
+ /** The content of the column. */
36
+ children?: Snippet;
37
+ };
38
+ declare const Col: import("svelte").Component<ColProps, {}, "">;
39
+ type Col = ReturnType<typeof Col>;
40
+ export default Col;
@@ -0,0 +1,75 @@
1
+ # Grid
2
+
3
+ A 24-column layout with Ant Design-inspired names and a Svelte 5 API. A `Row` lays out its `Col` children; a column takes
4
+ `span` of the 24 and moves to the next line as a whole when it does not fit. `Breakpoints` tells your code which breakpoints
5
+ the screen matches.
6
+
7
+ The API is inspired by Ant Design (MIT); the implementation is original for Svelte.
8
+
9
+ ## Usage
10
+
11
+ ```svelte
12
+ <script lang="ts">
13
+ import { Col, Row } from 'svelte-ant-design';
14
+ </script>
15
+
16
+ <Row gutter={16}>
17
+ <Col span={8}>one</Col>
18
+ <Col span={8}>two</Col>
19
+ <Col span={8}>three</Col>
20
+ </Row>
21
+ ```
22
+
23
+ The grid draws nothing, so it needs no design tokens.
24
+
25
+ ## Row
26
+
27
+ | Prop | Type | Default |
28
+ |---|---|---|
29
+ | `align` | `'top' \| 'middle' \| 'bottom' \| 'stretch'` or an object per breakpoint | `'top'` |
30
+ | `justify` | `'start' \| 'end' \| 'center' \| 'space-around' \| 'space-between' \| 'space-evenly'` or an object per breakpoint | `'start'` |
31
+ | `gutter` | number (px), CSS length string, object per breakpoint, or `[horizontal, vertical]` | `0` |
32
+ | `wrap` | `boolean` | `true` |
33
+
34
+ ## Col
35
+
36
+ | Prop | Type | Default |
37
+ |---|---|---|
38
+ | `span` | `number` (`0` hides the column) | unset |
39
+ | `offset`, `push`, `pull`, `order` | `number` | `0` |
40
+ | `flex` | `string \| number` | unset |
41
+ | `xs`, `sm`, `md`, `lg`, `xl`, `xxl`, `xxxl` | `number` (a span) or `{ span, offset, push, pull, order, flex }` | unset |
42
+
43
+ The breakpoints are 576, 768, 992, 1200, 1600 and 1920 px (`BREAKPOINTS` is exported). `xs` is the base of every width; a
44
+ breakpoint that is not given keeps the value of the next smaller one, and each key (`span`, `offset`, ...) cascades on its own.
45
+
46
+ ## Breakpoints
47
+
48
+ ```svelte
49
+ <script lang="ts">
50
+ import { Breakpoints } from 'svelte-ant-design';
51
+
52
+ const screens = new Breakpoints(); // options: { fallback: 'lg' } for a server render
53
+ </script>
54
+
55
+ {#if screens.md}...{/if}
56
+ {screens.current}
57
+ ```
58
+
59
+ `xs` is true below 576 px; every other flag is true from its width up. The values are right on the first render in a browser.
60
+
61
+ ## How it differs from Ant Design
62
+
63
+ - `gutter` is a flex `gap`. A `Row` is exactly as wide as its parent, so it never makes a page scroll sideways (the Ant Design
64
+ `Row` is wider than its parent by the gutter). The boxes of the content are in the same places.
65
+ - The responsive values are resolved in CSS, so the server and the browser render the same page and nothing flashes on
66
+ hydration. The breakpoints are fixed; a theme cannot change them.
67
+ - `Breakpoints` is a class, not a hook, and it is right on the first render.
68
+ - There is no `classNames` or `styles`: none of the three Ant Design libraries has them for the grid.
69
+
70
+ ## Accessibility
71
+
72
+ Row and Col are plain `<div>`s with no role, name or state. The reading order is the DOM order: `order`, `push` and `pull`
73
+ change only how the columns are drawn, so write the columns in the order they should be read.
74
+
75
+ See [`specs/grid.md`](../../../specs/grid.md) for the full contract.
@@ -0,0 +1,191 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLAttributes } from 'svelte/elements';
4
+ import { classList, styleText } from '../internal/semantic.js';
5
+ import { rowVars } from './layout.js';
6
+ import type { Gutter, Responsive, RowAlign, RowJustify } from './types.js';
7
+
8
+ type RowProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'style'> & {
9
+ /** Vertical alignment of the columns of a line, or one value per breakpoint. Default `'top'`. */
10
+ align?: RowAlign | Responsive<RowAlign>;
11
+ /** Horizontal arrangement of the columns of a line, or one value per breakpoint. Default `'start'`. */
12
+ justify?: RowJustify | Responsive<RowJustify>;
13
+ /**
14
+ * Space between the columns: pixels, a CSS length string, or one of them per breakpoint. A pair is
15
+ * `[horizontal, vertical]`. Default `0`.
16
+ */
17
+ gutter?: Gutter | [Gutter, Gutter];
18
+ /** Whether columns that do not fit move to the next line (`false`: they stay on one line and shrink). */
19
+ wrap?: boolean;
20
+ /** Additional CSS class appended to the component classes. */
21
+ class?: string;
22
+ /** Inline style of the root; it is written after the component's own, so it wins on the same property. */
23
+ style?: string;
24
+ /** The columns (`Col`). */
25
+ children?: Snippet;
26
+ };
27
+
28
+ // `align` (`top`), `justify` (`start`) and `gutter` (`0`) have no default here: a value that is not given is not written,
29
+ // and the stylesheet supplies the default, so a plain Row carries no inline style.
30
+ let {
31
+ align,
32
+ justify,
33
+ gutter,
34
+ wrap = true,
35
+ class: customClass,
36
+ style,
37
+ children,
38
+ ...rest
39
+ }: RowProps = $props();
40
+
41
+ // Each given value is checked here (outside its contract it throws in development and is ignored in production)
42
+ // and written as a custom property; the `@media` rules below pick the one that fits the screen.
43
+ const vars = $derived(rowVars({ align, justify, gutter }));
44
+ const classes = $derived(classList('ads-row', !wrap && 'ads-row-nowrap', customClass));
45
+ const inlineStyle = $derived(styleText(vars, style));
46
+ </script>
47
+
48
+ <div {...rest} class={classes} style={inlineStyle}>
49
+ {@render children?.()}
50
+ </div>
51
+
52
+ <style>
53
+ /*
54
+ * The component writes the values it was given as `--ads-row-<name>-<breakpoint>` (see layout.ts). The chains below
55
+ * give every breakpoint the value of the next smaller one when it has none of its own, and the `@media` rules at
56
+ * the end switch the resolved variables (`--_row-gx` is read by the columns). Nothing is measured in JavaScript.
57
+ *
58
+ * Custom properties inherit, so the public ones are reset here: a Row inside a Row (or a Col) must not take the
59
+ * gutter of the outer one. An inline value, which the component writes, wins over this reset.
60
+ */
61
+ .ads-row {
62
+ --ads-row-gx-xs: initial;
63
+ --ads-row-gx-sm: initial;
64
+ --ads-row-gx-md: initial;
65
+ --ads-row-gx-lg: initial;
66
+ --ads-row-gx-xl: initial;
67
+ --ads-row-gx-xxl: initial;
68
+ --ads-row-gx-xxxl: initial;
69
+ --ads-row-gy-xs: initial;
70
+ --ads-row-gy-sm: initial;
71
+ --ads-row-gy-md: initial;
72
+ --ads-row-gy-lg: initial;
73
+ --ads-row-gy-xl: initial;
74
+ --ads-row-gy-xxl: initial;
75
+ --ads-row-gy-xxxl: initial;
76
+ --ads-row-align-xs: initial;
77
+ --ads-row-align-sm: initial;
78
+ --ads-row-align-md: initial;
79
+ --ads-row-align-lg: initial;
80
+ --ads-row-align-xl: initial;
81
+ --ads-row-align-xxl: initial;
82
+ --ads-row-align-xxxl: initial;
83
+ --ads-row-justify-xs: initial;
84
+ --ads-row-justify-sm: initial;
85
+ --ads-row-justify-md: initial;
86
+ --ads-row-justify-lg: initial;
87
+ --ads-row-justify-xl: initial;
88
+ --ads-row-justify-xxl: initial;
89
+ --ads-row-justify-xxxl: initial;
90
+
91
+ --_gx-xs: var(--ads-row-gx-xs, 0px);
92
+ --_gx-sm: var(--ads-row-gx-sm, var(--_gx-xs));
93
+ --_gx-md: var(--ads-row-gx-md, var(--_gx-sm));
94
+ --_gx-lg: var(--ads-row-gx-lg, var(--_gx-md));
95
+ --_gx-xl: var(--ads-row-gx-xl, var(--_gx-lg));
96
+ --_gx-xxl: var(--ads-row-gx-xxl, var(--_gx-xl));
97
+ --_gx-xxxl: var(--ads-row-gx-xxxl, var(--_gx-xxl));
98
+ --_gy-xs: var(--ads-row-gy-xs, 0px);
99
+ --_gy-sm: var(--ads-row-gy-sm, var(--_gy-xs));
100
+ --_gy-md: var(--ads-row-gy-md, var(--_gy-sm));
101
+ --_gy-lg: var(--ads-row-gy-lg, var(--_gy-md));
102
+ --_gy-xl: var(--ads-row-gy-xl, var(--_gy-lg));
103
+ --_gy-xxl: var(--ads-row-gy-xxl, var(--_gy-xl));
104
+ --_gy-xxxl: var(--ads-row-gy-xxxl, var(--_gy-xxl));
105
+ --_al-xs: var(--ads-row-align-xs, flex-start);
106
+ --_al-sm: var(--ads-row-align-sm, var(--_al-xs));
107
+ --_al-md: var(--ads-row-align-md, var(--_al-sm));
108
+ --_al-lg: var(--ads-row-align-lg, var(--_al-md));
109
+ --_al-xl: var(--ads-row-align-xl, var(--_al-lg));
110
+ --_al-xxl: var(--ads-row-align-xxl, var(--_al-xl));
111
+ --_al-xxxl: var(--ads-row-align-xxxl, var(--_al-xxl));
112
+ --_ju-xs: var(--ads-row-justify-xs, flex-start);
113
+ --_ju-sm: var(--ads-row-justify-sm, var(--_ju-xs));
114
+ --_ju-md: var(--ads-row-justify-md, var(--_ju-sm));
115
+ --_ju-lg: var(--ads-row-justify-lg, var(--_ju-md));
116
+ --_ju-xl: var(--ads-row-justify-xl, var(--_ju-lg));
117
+ --_ju-xxl: var(--ads-row-justify-xxl, var(--_ju-xl));
118
+ --_ju-xxxl: var(--ads-row-justify-xxxl, var(--_ju-xxl));
119
+
120
+ --_row-gx: var(--_gx-xs);
121
+ --_gy: var(--_gy-xs);
122
+ --_al: var(--_al-xs);
123
+ --_ju: var(--_ju-xs);
124
+
125
+ display: flex;
126
+ flex-flow: row wrap;
127
+ column-gap: var(--_row-gx);
128
+ row-gap: var(--_gy);
129
+ align-items: var(--_al);
130
+ justify-content: var(--_ju);
131
+ min-width: 0;
132
+ }
133
+
134
+ .ads-row-nowrap {
135
+ flex-wrap: nowrap;
136
+ }
137
+
138
+ @media (min-width: 576px) {
139
+ .ads-row {
140
+ --_row-gx: var(--_gx-sm);
141
+ --_gy: var(--_gy-sm);
142
+ --_al: var(--_al-sm);
143
+ --_ju: var(--_ju-sm);
144
+ }
145
+ }
146
+
147
+ @media (min-width: 768px) {
148
+ .ads-row {
149
+ --_row-gx: var(--_gx-md);
150
+ --_gy: var(--_gy-md);
151
+ --_al: var(--_al-md);
152
+ --_ju: var(--_ju-md);
153
+ }
154
+ }
155
+
156
+ @media (min-width: 992px) {
157
+ .ads-row {
158
+ --_row-gx: var(--_gx-lg);
159
+ --_gy: var(--_gy-lg);
160
+ --_al: var(--_al-lg);
161
+ --_ju: var(--_ju-lg);
162
+ }
163
+ }
164
+
165
+ @media (min-width: 1200px) {
166
+ .ads-row {
167
+ --_row-gx: var(--_gx-xl);
168
+ --_gy: var(--_gy-xl);
169
+ --_al: var(--_al-xl);
170
+ --_ju: var(--_ju-xl);
171
+ }
172
+ }
173
+
174
+ @media (min-width: 1600px) {
175
+ .ads-row {
176
+ --_row-gx: var(--_gx-xxl);
177
+ --_gy: var(--_gy-xxl);
178
+ --_al: var(--_al-xxl);
179
+ --_ju: var(--_ju-xxl);
180
+ }
181
+ }
182
+
183
+ @media (min-width: 1920px) {
184
+ .ads-row {
185
+ --_row-gx: var(--_gx-xxxl);
186
+ --_gy: var(--_gy-xxxl);
187
+ --_al: var(--_al-xxxl);
188
+ --_ju: var(--_ju-xxxl);
189
+ }
190
+ }
191
+ </style>
@@ -0,0 +1,25 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import type { Gutter, Responsive, RowAlign, RowJustify } from './types.js';
4
+ type RowProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'style'> & {
5
+ /** Vertical alignment of the columns of a line, or one value per breakpoint. Default `'top'`. */
6
+ align?: RowAlign | Responsive<RowAlign>;
7
+ /** Horizontal arrangement of the columns of a line, or one value per breakpoint. Default `'start'`. */
8
+ justify?: RowJustify | Responsive<RowJustify>;
9
+ /**
10
+ * Space between the columns: pixels, a CSS length string, or one of them per breakpoint. A pair is
11
+ * `[horizontal, vertical]`. Default `0`.
12
+ */
13
+ gutter?: Gutter | [Gutter, Gutter];
14
+ /** Whether columns that do not fit move to the next line (`false`: they stay on one line and shrink). */
15
+ wrap?: boolean;
16
+ /** Additional CSS class appended to the component classes. */
17
+ class?: string;
18
+ /** Inline style of the root; it is written after the component's own, so it wins on the same property. */
19
+ style?: string;
20
+ /** The columns (`Col`). */
21
+ children?: Snippet;
22
+ };
23
+ declare const Row: import("svelte").Component<RowProps, {}, "">;
24
+ type Row = ReturnType<typeof Row>;
25
+ export default Row;
@@ -0,0 +1,8 @@
1
+ import type { Breakpoint } from './types.js';
2
+ /** The breakpoints, from the smallest. */
3
+ export declare const BREAKPOINT_NAMES: readonly ["xs", "sm", "md", "lg", "xl", "xxl", "xxxl"];
4
+ /**
5
+ * The minimum screen width of each breakpoint, in pixels (the Bootstrap 4 widths that Ant Design uses).
6
+ * The `@media (min-width: ...)` rules of `Row.svelte` and `Col.svelte` use the same numbers; a test compares them.
7
+ */
8
+ export declare const BREAKPOINTS: Readonly<Record<Breakpoint, number>>;
@@ -0,0 +1,15 @@
1
+ /** The breakpoints, from the smallest. */
2
+ export const BREAKPOINT_NAMES = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl', 'xxxl'];
3
+ /**
4
+ * The minimum screen width of each breakpoint, in pixels (the Bootstrap 4 widths that Ant Design uses).
5
+ * The `@media (min-width: ...)` rules of `Row.svelte` and `Col.svelte` use the same numbers; a test compares them.
6
+ */
7
+ export const BREAKPOINTS = Object.freeze({
8
+ xs: 0,
9
+ sm: 576,
10
+ md: 768,
11
+ lg: 992,
12
+ xl: 1200,
13
+ xxl: 1600,
14
+ xxxl: 1920
15
+ });
@@ -0,0 +1,38 @@
1
+ import type { Breakpoint, ColSize, Gutter, Responsive, RowAlign, RowJustify } from './types.js';
2
+ /** Custom properties by name, as `styleText` takes them. */
3
+ export type CssVars = Record<string, string>;
4
+ export declare const ROW_ALIGNS: readonly ["top", "middle", "bottom", "stretch"];
5
+ export declare const ROW_JUSTIFIES: readonly ["start", "end", "center", "space-around", "space-between", "space-evenly"];
6
+ /** A finite number, optionally not below `min` and optionally an integer; `undefined` (and a message) otherwise. */
7
+ export declare function checkNumber(component: string, prop: string, value: unknown, { min, integer }?: {
8
+ min?: number;
9
+ integer?: boolean;
10
+ }): number | undefined;
11
+ /**
12
+ * A CSS length that is safe to put into the width formulas of the columns. A number is pixels. A string must be a
13
+ * length (`2rem`, `5vw`, `10%`, `0`) or a `calc()`, `min()`, `max()`, `clamp()` or `var()` expression with balanced
14
+ * parentheses; anything else (an unitless `'16'`, a word) is dropped, because one invalid value would make every column
15
+ * of the Row lose its width. A dropped string is not an error: the gutter is `0`.
16
+ */
17
+ export declare function gutterLength(component: string, value: unknown): string | undefined;
18
+ /** The custom properties of a Row: `--ads-row-{gx,gy,align,justify}-<breakpoint>` for each value given. */
19
+ export declare function rowVars(options: {
20
+ align?: RowAlign | Responsive<RowAlign>;
21
+ justify?: RowJustify | Responsive<RowJustify>;
22
+ gutter?: Gutter | [Gutter, Gutter];
23
+ }): CssVars;
24
+ /**
25
+ * The CSS `flex` value of the `flex` prop. A number `n` is `n n auto`; a string of digits is `n 1 0px`; a single length
26
+ * or percentage (`100px`, `30%`) is a fixed width, `0 0 <length>` (the public demos of Ant Design show this, although
27
+ * their table says "applied as written"); any other string (`auto`, `none`, `1 1 200px`) is used as written.
28
+ * `undefined` (and a message) for what is neither a number nor a string.
29
+ */
30
+ export declare function flexValue(component: string, value: unknown): string | undefined;
31
+ /**
32
+ * The custom properties of a Col: `--ads-col-{span,offset,push,pull,order,flex}-<breakpoint>` for each value given, plus
33
+ * `--ads-col-d-<breakpoint>` (`none` for a span of `0`, `block` otherwise) and `--ads-col-mw-<breakpoint>` (`100%` where
34
+ * a `flex` is given, so that the flex value is not capped by the width of a `span`).
35
+ *
36
+ * The plain props are the base, the same as `xs`; an `xs` value of the same name wins over the plain one.
37
+ */
38
+ export declare function colVars(base: ColSize, sizes: Partial<Record<Breakpoint, number | ColSize | undefined>>): CssVars;
@@ -0,0 +1,241 @@
1
+ /**
2
+ * Turns the props of `Row` and `Col` into CSS custom properties.
3
+ *
4
+ * The components do not look at the screen. They write the values they were given, one custom property per breakpoint,
5
+ * and the static `@media (min-width: ...)` rules of the component pick the one that applies (the cascade is written in
6
+ * CSS: a breakpoint with no value takes the one of the next smaller). So the server and the client render the same
7
+ * markup, and nothing is measured or listened to in JavaScript.
8
+ */
9
+ import { isProduction } from '../internal/env.js';
10
+ import { resolveOption } from '../internal/options.js';
11
+ import { BREAKPOINT_NAMES } from './constants.js';
12
+ export const ROW_ALIGNS = ['top', 'middle', 'bottom', 'stretch'];
13
+ export const ROW_JUSTIFIES = [
14
+ 'start',
15
+ 'end',
16
+ 'center',
17
+ 'space-around',
18
+ 'space-between',
19
+ 'space-evenly'
20
+ ];
21
+ // `start` and `end` are written as `flex-start` and `flex-end`: the plain keywords came to flex containers later
22
+ // than the oldest browsers the library supports.
23
+ const ALIGN_CSS = {
24
+ top: 'flex-start',
25
+ middle: 'center',
26
+ bottom: 'flex-end',
27
+ stretch: 'stretch'
28
+ };
29
+ const JUSTIFY_CSS = {
30
+ start: 'flex-start',
31
+ end: 'flex-end',
32
+ center: 'center',
33
+ 'space-around': 'space-around',
34
+ 'space-between': 'space-between',
35
+ 'space-evenly': 'space-evenly'
36
+ };
37
+ /** A value outside the contract throws while developing and is ignored in a production build. */
38
+ function outsideContract(message) {
39
+ if (!isProduction())
40
+ throw new RangeError(message);
41
+ return undefined;
42
+ }
43
+ function isBreakpoint(key) {
44
+ return BREAKPOINT_NAMES.includes(key);
45
+ }
46
+ function isRecord(value) {
47
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
48
+ }
49
+ /**
50
+ * The given breakpoints of an object, in order. An unknown key is outside the contract (it is almost always a typo).
51
+ * A key whose value is `undefined` counts as not given.
52
+ */
53
+ function givenBreakpoints(component, prop, value) {
54
+ const given = [];
55
+ for (const key of Object.keys(value)) {
56
+ if (!isBreakpoint(key)) {
57
+ outsideContract(`${component} ${prop}: "${key}" is not a breakpoint; use ${BREAKPOINT_NAMES.join(', ')}.`);
58
+ continue;
59
+ }
60
+ const entry = value[key];
61
+ if (entry !== undefined)
62
+ given.push([key, entry]);
63
+ }
64
+ return given;
65
+ }
66
+ /** A finite number, optionally not below `min` and optionally an integer; `undefined` (and a message) otherwise. */
67
+ export function checkNumber(component, prop, value, { min = Number.NEGATIVE_INFINITY, integer = false } = {}) {
68
+ if (typeof value === 'number' && Number.isFinite(value) && value >= min && (!integer || Number.isInteger(value))) {
69
+ return value;
70
+ }
71
+ const rule = [integer ? 'an integer' : 'a finite number', min > Number.NEGATIVE_INFINITY ? `not below ${min}` : '']
72
+ .filter(Boolean)
73
+ .join(' ');
74
+ return outsideContract(`${component} ${prop} must be ${rule}.`);
75
+ }
76
+ const LENGTH = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[a-z]+|%)$/i;
77
+ const FUNCTION = /^(?:calc|min|max|clamp|var)\(.+\)$/i;
78
+ /**
79
+ * A CSS length that is safe to put into the width formulas of the columns. A number is pixels. A string must be a
80
+ * length (`2rem`, `5vw`, `10%`, `0`) or a `calc()`, `min()`, `max()`, `clamp()` or `var()` expression with balanced
81
+ * parentheses; anything else (an unitless `'16'`, a word) is dropped, because one invalid value would make every column
82
+ * of the Row lose its width. A dropped string is not an error: the gutter is `0`.
83
+ */
84
+ export function gutterLength(component, value) {
85
+ if (typeof value === 'number') {
86
+ const pixels = checkNumber(component, 'gutter', value, { min: 0 });
87
+ return pixels === undefined ? undefined : `${pixels}px`;
88
+ }
89
+ if (typeof value !== 'string')
90
+ return outsideContract(`${component} gutter must be a number or a CSS length string.`);
91
+ const text = value.trim();
92
+ if (text === '0')
93
+ return '0px';
94
+ if (LENGTH.test(text))
95
+ return text;
96
+ if (FUNCTION.test(text) && balanced(text))
97
+ return text;
98
+ return undefined;
99
+ }
100
+ function balanced(text) {
101
+ let depth = 0;
102
+ for (const char of text) {
103
+ if (char === '(')
104
+ depth += 1;
105
+ else if (char === ')')
106
+ depth -= 1;
107
+ if (depth < 0)
108
+ return false;
109
+ }
110
+ return depth === 0;
111
+ }
112
+ /** One gutter as a length per breakpoint: a plain value is the base (`xs`), an object has its own keys. */
113
+ function gutterByBreakpoint(component, value) {
114
+ if (value === undefined)
115
+ return [];
116
+ if (isRecord(value)) {
117
+ const lengths = [];
118
+ for (const [breakpoint, entry] of givenBreakpoints(component, 'gutter', value)) {
119
+ const length = gutterLength(component, entry);
120
+ if (length !== undefined)
121
+ lengths.push([breakpoint, length]);
122
+ }
123
+ return lengths;
124
+ }
125
+ const length = gutterLength(component, value);
126
+ return length === undefined ? [] : [['xs', length]];
127
+ }
128
+ /** A value of an enum prop as one per breakpoint, each checked and turned into its CSS keyword. */
129
+ function enumByBreakpoint(component, prop, value, allowed, fallback, css) {
130
+ if (value === undefined)
131
+ return [];
132
+ if (isRecord(value)) {
133
+ return givenBreakpoints(component, prop, value).map(([breakpoint, entry]) => [
134
+ breakpoint,
135
+ css[resolveOption(component, prop, entry, allowed, fallback)]
136
+ ]);
137
+ }
138
+ return [['xs', css[resolveOption(component, prop, value, allowed, fallback)]]];
139
+ }
140
+ /** The custom properties of a Row: `--ads-row-{gx,gy,align,justify}-<breakpoint>` for each value given. */
141
+ export function rowVars(options) {
142
+ const vars = {};
143
+ const write = (name, entries) => {
144
+ for (const [breakpoint, value] of entries)
145
+ vars[`--ads-row-${name}-${breakpoint}`] = value;
146
+ };
147
+ const [horizontal, vertical] = Array.isArray(options.gutter) ? options.gutter : [options.gutter, undefined];
148
+ write('gx', gutterByBreakpoint('Row', horizontal));
149
+ write('gy', gutterByBreakpoint('Row', vertical));
150
+ write('align', enumByBreakpoint('Row', 'align', options.align, ROW_ALIGNS, 'top', ALIGN_CSS));
151
+ write('justify', enumByBreakpoint('Row', 'justify', options.justify, ROW_JUSTIFIES, 'start', JUSTIFY_CSS));
152
+ return vars;
153
+ }
154
+ const DIGITS = /^\d+$/;
155
+ /**
156
+ * The CSS `flex` value of the `flex` prop. A number `n` is `n n auto`; a string of digits is `n 1 0px`; a single length
157
+ * or percentage (`100px`, `30%`) is a fixed width, `0 0 <length>` (the public demos of Ant Design show this, although
158
+ * their table says "applied as written"); any other string (`auto`, `none`, `1 1 200px`) is used as written.
159
+ * `undefined` (and a message) for what is neither a number nor a string.
160
+ */
161
+ export function flexValue(component, value) {
162
+ if (typeof value === 'number') {
163
+ const grow = checkNumber(component, 'flex', value, { min: 0 });
164
+ return grow === undefined ? undefined : `${grow} ${grow} auto`;
165
+ }
166
+ if (typeof value === 'string') {
167
+ const text = value.trim();
168
+ if (text === '')
169
+ return undefined;
170
+ if (DIGITS.test(text))
171
+ return `${text} 1 0px`;
172
+ if (LENGTH.test(text))
173
+ return `0 0 ${text}`;
174
+ return text;
175
+ }
176
+ return outsideContract(`${component} flex must be a number or a string.`);
177
+ }
178
+ /** What a breakpoint prop (`xs`, ..., `xxxl`) is: a `span`, or an object of the same props as the plain ones. */
179
+ function sizeOf(component, prop, value) {
180
+ if (typeof value === 'number')
181
+ return { span: value };
182
+ if (isRecord(value))
183
+ return value;
184
+ return outsideContract(`${component} ${prop} must be a number or an object of Col props.`);
185
+ }
186
+ /** The numeric props of a column, with the least value each accepts. */
187
+ const NUMERIC = [
188
+ { key: 'span', name: 'span', min: 0 },
189
+ { key: 'offset', name: 'offset', min: 0 },
190
+ { key: 'push', name: 'push', min: 0 },
191
+ { key: 'pull', name: 'pull', min: 0 },
192
+ { key: 'order', name: 'order', integer: true }
193
+ ];
194
+ /**
195
+ * The custom properties of a Col: `--ads-col-{span,offset,push,pull,order,flex}-<breakpoint>` for each value given, plus
196
+ * `--ads-col-d-<breakpoint>` (`none` for a span of `0`, `block` otherwise) and `--ads-col-mw-<breakpoint>` (`100%` where
197
+ * a `flex` is given, so that the flex value is not capped by the width of a `span`).
198
+ *
199
+ * The plain props are the base, the same as `xs`; an `xs` value of the same name wins over the plain one.
200
+ */
201
+ export function colVars(base, sizes) {
202
+ const vars = {};
203
+ const layers = [];
204
+ if (Object.values(base).some((value) => value !== undefined))
205
+ layers.push(['xs', base]);
206
+ for (const [breakpoint, entry] of givenBreakpoints('Col', 'sizes', sizes)) {
207
+ const size = sizeOf('Col', breakpoint, entry);
208
+ if (size)
209
+ layers.push([breakpoint, size]);
210
+ }
211
+ // Two layers can address the same breakpoint (the plain props and `xs`): later keys win, each key on its own.
212
+ const merged = new Map();
213
+ for (const [breakpoint, size] of layers) {
214
+ const kept = merged.get(breakpoint) ?? {};
215
+ for (const [key, value] of Object.entries(size)) {
216
+ if (value !== undefined)
217
+ kept[key] = value;
218
+ }
219
+ merged.set(breakpoint, kept);
220
+ }
221
+ for (const [breakpoint, size] of merged) {
222
+ for (const { key, name, min, integer } of NUMERIC) {
223
+ if (size[key] === undefined)
224
+ continue;
225
+ const value = checkNumber('Col', name, size[key], { min, integer });
226
+ if (value === undefined)
227
+ continue;
228
+ vars[`--ads-col-${name}-${breakpoint}`] = String(value);
229
+ if (key === 'span')
230
+ vars[`--ads-col-d-${breakpoint}`] = value === 0 ? 'none' : 'block';
231
+ }
232
+ if (size.flex !== undefined) {
233
+ const flex = flexValue('Col', size.flex);
234
+ if (flex !== undefined) {
235
+ vars[`--ads-col-flex-${breakpoint}`] = flex;
236
+ vars[`--ads-col-mw-${breakpoint}`] = '100%';
237
+ }
238
+ }
239
+ }
240
+ return vars;
241
+ }
@@ -0,0 +1,27 @@
1
+ /** The screen-width steps of the grid, from the smallest. */
2
+ export type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | 'xxxl';
3
+ /** A value per breakpoint. A value at a breakpoint applies from that width up (until the next given one). */
4
+ export type Responsive<T> = Partial<Record<Breakpoint, T>>;
5
+ /** Vertical alignment of the columns of a line. */
6
+ export type RowAlign = 'top' | 'middle' | 'bottom' | 'stretch';
7
+ /** Horizontal arrangement of the columns of a line. */
8
+ export type RowJustify = 'start' | 'end' | 'center' | 'space-around' | 'space-between' | 'space-evenly';
9
+ /** One gutter: pixels (a number) or a CSS length (a string such as `'2rem'`). */
10
+ export type GutterValue = number | string;
11
+ /** A gutter, fixed or per breakpoint. */
12
+ export type Gutter = GutterValue | Responsive<GutterValue>;
13
+ /** What a column can take at one breakpoint. */
14
+ export type ColSize = {
15
+ /** Columns of the 24 to take; `0` hides the column. */
16
+ span?: number;
17
+ /** Empty columns before this one. */
18
+ offset?: number;
19
+ /** Columns to shift it towards the inline end, visually only. */
20
+ push?: number;
21
+ /** Columns to shift it towards the inline start, visually only. */
22
+ pull?: number;
23
+ /** The flex `order`. */
24
+ order?: number;
25
+ /** A raw flex value: a number `n` is `n n auto`, a string is used as written. */
26
+ flex?: string | number;
27
+ };
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "0.7.0";
1
+ export declare const VERSION = "0.8.0";
2
2
  export { default as Button } from './Button/Button.svelte';
3
3
  export { default as Switch } from './Switch/Switch.svelte';
4
4
  export { default as Checkbox } from './Checkbox/Checkbox.svelte';
@@ -10,6 +10,12 @@ export { default as Select } from './Select/Select.svelte';
10
10
  export { default as SelectOption } from './Select/SelectOption.svelte';
11
11
  export { default as SelectOptGroup } from './Select/SelectOptGroup.svelte';
12
12
  export { default as Tooltip } from './Tooltip/Tooltip.svelte';
13
+ export { default as Row } from './Grid/Row.svelte';
14
+ export { default as Col } from './Grid/Col.svelte';
15
+ export { Breakpoints } from './Grid/Breakpoints.js';
16
+ export type { BreakpointsOptions } from './Grid/Breakpoints.js';
17
+ export { BREAKPOINTS } from './Grid/constants.js';
18
+ export type { Breakpoint, ColSize, Gutter, GutterValue, Responsive, RowAlign, RowJustify } from './Grid/types.js';
13
19
  export { default as Input } from './Input/Input.svelte';
14
20
  export { default as InputOTP } from './Input/InputOTP.svelte';
15
21
  export { default as InputPassword } from './Input/InputPassword.svelte';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Public API of the library. Components are re-exported from here.
2
- export const VERSION = '0.7.0';
2
+ export const VERSION = '0.8.0';
3
3
  export { default as Button } from './Button/Button.svelte';
4
4
  export { default as Switch } from './Switch/Switch.svelte';
5
5
  export { default as Checkbox } from './Checkbox/Checkbox.svelte';
@@ -11,6 +11,10 @@ export { default as Select } from './Select/Select.svelte';
11
11
  export { default as SelectOption } from './Select/SelectOption.svelte';
12
12
  export { default as SelectOptGroup } from './Select/SelectOptGroup.svelte';
13
13
  export { default as Tooltip } from './Tooltip/Tooltip.svelte';
14
+ export { default as Row } from './Grid/Row.svelte';
15
+ export { default as Col } from './Grid/Col.svelte';
16
+ export { Breakpoints } from './Grid/Breakpoints.js';
17
+ export { BREAKPOINTS } from './Grid/constants.js';
14
18
  export { default as Input } from './Input/Input.svelte';
15
19
  export { default as InputOTP } from './Input/InputOTP.svelte';
16
20
  export { default as InputPassword } from './Input/InputPassword.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-ant-design",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "An independent UI component library for Svelte 5, inspired by Ant Design.",
5
5
  "license": "MIT",
6
6
  "repository": {