noph-ui 0.46.1 → 0.48.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 (74) hide show
  1. package/README.md +3 -1
  2. package/dist/button/ButtonGroup.svelte +1 -3
  3. package/dist/carousel/Carousel.svelte +410 -0
  4. package/dist/carousel/Carousel.svelte.d.ts +4 -0
  5. package/dist/carousel/CarouselItem.svelte +300 -0
  6. package/dist/carousel/CarouselItem.svelte.d.ts +5 -0
  7. package/dist/carousel/carouselMorph.d.ts +13 -0
  8. package/dist/carousel/carouselMorph.js +100 -0
  9. package/dist/carousel/carouselStrategy.d.ts +61 -0
  10. package/dist/carousel/carouselStrategy.js +344 -0
  11. package/dist/carousel/context.d.ts +2 -0
  12. package/dist/carousel/context.js +2 -0
  13. package/dist/carousel/index.d.ts +3 -0
  14. package/dist/carousel/index.js +3 -0
  15. package/dist/carousel/types.d.ts +31 -0
  16. package/dist/carousel/types.js +1 -0
  17. package/dist/date-picker/DockedDatePicker.svelte +2 -3
  18. package/dist/date-picker/DockedDateTimePicker.svelte +2 -3
  19. package/dist/date-picker/dateUtils.d.ts +2 -13
  20. package/dist/date-picker/dateUtils.js +4 -66
  21. package/dist/date-picker/formatters.d.ts +4 -0
  22. package/dist/date-picker/formatters.js +26 -0
  23. package/dist/date-picker/timeUtils.d.ts +34 -0
  24. package/dist/date-picker/timeUtils.js +139 -0
  25. package/dist/fab/FabMenu.svelte +1 -2
  26. package/dist/form-reset.d.ts +2 -1
  27. package/dist/form-reset.js +2 -2
  28. package/dist/icons/KeyboardIcon.svelte +5 -0
  29. package/dist/icons/KeyboardIcon.svelte.d.ts +26 -0
  30. package/dist/icons/ScheduleIcon.svelte +5 -0
  31. package/dist/icons/ScheduleIcon.svelte.d.ts +26 -0
  32. package/dist/icons/index.d.ts +2 -0
  33. package/dist/icons/index.js +2 -0
  34. package/dist/index.d.ts +2 -0
  35. package/dist/index.js +2 -0
  36. package/dist/keyboard-nav.d.ts +3 -1
  37. package/dist/keyboard-nav.js +9 -4
  38. package/dist/media.d.ts +4 -0
  39. package/dist/media.js +4 -0
  40. package/dist/menu/Menu.svelte +2 -1
  41. package/dist/progress/CircularProgress.svelte +9 -9
  42. package/dist/progress/LinearProgress.svelte +1 -2
  43. package/dist/ripple/Ripple.svelte +7 -8
  44. package/dist/search/Search.svelte +7 -6
  45. package/dist/select/Select.svelte +9 -10
  46. package/dist/select/VirtualList.svelte +12 -13
  47. package/dist/slider/Slider.svelte +5 -6
  48. package/dist/tabs/Tabs.svelte +21 -14
  49. package/dist/time-picker/ClockDial.svelte +528 -0
  50. package/dist/time-picker/ClockDial.svelte.d.ts +4 -0
  51. package/dist/time-picker/DockedTimePicker.svelte +378 -0
  52. package/dist/time-picker/DockedTimePicker.svelte.d.ts +7 -0
  53. package/dist/time-picker/PeriodSelector.svelte +156 -0
  54. package/dist/time-picker/PeriodSelector.svelte.d.ts +4 -0
  55. package/dist/time-picker/TimeInputs.svelte +233 -0
  56. package/dist/time-picker/TimeInputs.svelte.d.ts +4 -0
  57. package/dist/time-picker/TimePickerDialog.svelte +229 -0
  58. package/dist/time-picker/TimePickerDialog.svelte.d.ts +7 -0
  59. package/dist/time-picker/TimePickerPanel.svelte +203 -0
  60. package/dist/time-picker/TimePickerPanel.svelte.d.ts +4 -0
  61. package/dist/time-picker/TimeSelectors.svelte +157 -0
  62. package/dist/time-picker/TimeSelectors.svelte.d.ts +4 -0
  63. package/dist/time-picker/index.d.ts +4 -0
  64. package/dist/time-picker/index.js +4 -0
  65. package/dist/time-picker/timePickerState.svelte.d.ts +27 -0
  66. package/dist/time-picker/timePickerState.svelte.js +63 -0
  67. package/dist/time-picker/types.d.ts +148 -0
  68. package/dist/time-picker/types.js +1 -0
  69. package/dist/tooltip/Tooltip.svelte +2 -4
  70. package/dist/types.d.ts +2 -0
  71. package/dist/types.js +2 -0
  72. package/dist/validity.d.ts +2 -0
  73. package/dist/validity.js +4 -0
  74. package/package.json +1 -1
package/README.md CHANGED
@@ -73,7 +73,8 @@ Live demos and usage examples for every component are available on [noph.dev](ht
73
73
  [Select](https://noph.dev/components/select) ·
74
74
  [Slider](https://noph.dev/components/slider) ·
75
75
  [Switch](https://noph.dev/components/switch) ·
76
- [Text fields](https://noph.dev/components/text-field)
76
+ [Text fields](https://noph.dev/components/text-field) ·
77
+ [TimePicker](https://noph.dev/components/time-picker)
77
78
 
78
79
  **Navigation**
79
80
  [Menus](https://noph.dev/components/menu) ·
@@ -94,6 +95,7 @@ Live demos and usage examples for every component are available on [noph.dev](ht
94
95
 
95
96
  **Containment**
96
97
  [Cards](https://noph.dev/components/card) ·
98
+ [Carousel](https://noph.dev/components/carousel) ·
97
99
  [Divider](https://noph.dev/components/divider) ·
98
100
  [Sheets](https://noph.dev/components/sheet) ·
99
101
  [Lists](https://noph.dev/components/list)
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
+ import { reducedMotion } from '../media.js'
2
3
  import { onMount } from 'svelte'
3
- import { MediaQuery } from 'svelte/reactivity'
4
4
  import { expandedWidths, parseMotion, resolveItem } from './buttonGroup.js'
5
5
  import type { ButtonGroupProps } from './types.js'
6
6
 
@@ -13,8 +13,6 @@
13
13
  ...attributes
14
14
  }: ButtonGroupProps = $props()
15
15
 
16
- const reducedMotion = new MediaQuery('(prefers-reduced-motion: reduce)', false)
17
-
18
16
  const settleRatio = 0.75
19
17
 
20
18
  type Timing = { duration: number; easing: string }
@@ -0,0 +1,410 @@
1
+ <script lang="ts">
2
+ import { arrowKeyNav } from '../keyboard-nav.js'
3
+ import { reducedMotion } from '../media.js'
4
+ import type { Attachment } from 'svelte/attachments'
5
+ import { carouselMorph, scrollTimelines } from './carouselMorph.js'
6
+ import { setCarouselContext } from './context.js'
7
+ import type { CarouselContext, CarouselItemElement, CarouselProps } from './types.js'
8
+
9
+ let {
10
+ variant = 'multi-browse',
11
+ alignment = 'start',
12
+ orientation,
13
+ snap,
14
+ label,
15
+ itemLabel = (text, position, total) => `${text}, ${position} of ${total}`,
16
+ children,
17
+ scroller = $bindable(),
18
+ element = $bindable(),
19
+ onkeydown: userKeydown,
20
+ ...attributes
21
+ }: CarouselProps = $props()
22
+
23
+ const uid = $props.id()
24
+ let track = $state<HTMLDivElement>()
25
+ let metrics = $state<HTMLDivElement>()
26
+ let snapPoints = $state<HTMLDivElement>()
27
+ let items = $state.raw<CarouselItemElement[]>([])
28
+
29
+ const axis = $derived(orientation ?? (variant === 'full-screen' ? 'vertical' : 'horizontal'))
30
+ const vertical = $derived(axis === 'vertical')
31
+ const snapping = $derived(snap ?? variant !== 'uncontained')
32
+
33
+ const keylined = $derived(variant === 'multi-browse' || variant === 'hero' ? variant : undefined)
34
+ const morphing = $derived(!!keylined && scrollTimelines && !reducedMotion.current)
35
+
36
+ const cropping = $derived(variant === 'uncontained' && !reducedMotion.current)
37
+
38
+ const collectItems: Attachment<HTMLElement> = (node) => {
39
+ const read = () => {
40
+ const found = [...node.querySelectorAll<CarouselItemElement>('.np-carousel-item')]
41
+ const same =
42
+ found.length === items.length && found.every((item, index) => item === items[index])
43
+ if (!same) items = found
44
+ }
45
+ read()
46
+ let queued = false
47
+ const observer = new MutationObserver(() => {
48
+ if (queued) return
49
+ queued = true
50
+ queueMicrotask(() => {
51
+ queued = false
52
+ read()
53
+ })
54
+ })
55
+ observer.observe(node, { childList: true, subtree: true })
56
+ return () => observer.disconnect()
57
+ }
58
+
59
+ const morph = $derived(
60
+ morphing && keylined
61
+ ? carouselMorph({ variant: keylined, alignment, vertical, items, track, metrics, uid })
62
+ : undefined,
63
+ )
64
+
65
+ const arrowHandler = $derived(arrowKeyNav('.np-carousel-item', axis, { wrap: false }))
66
+
67
+ const handleKeydown = (
68
+ event: KeyboardEvent & { currentTarget: EventTarget & HTMLDivElement },
69
+ ) => {
70
+ userKeydown?.(event)
71
+ if (!event.defaultPrevented) arrowHandler(event)
72
+ }
73
+
74
+ const places = $derived(new Map(items.map((item, index) => [item, index + 1])))
75
+
76
+ const handleFocusIn = (event: FocusEvent) => {
77
+ const item = (event.target as HTMLElement | null)?.closest<HTMLElement>('.np-carousel-item')
78
+ if (!item) return
79
+ const behavior = reducedMotion.current ? 'auto' : 'smooth'
80
+ const place = places.get(item as CarouselItemElement) ?? 0
81
+ const notch =
82
+ place > 0 ? (snapPoints?.children[place - 1] as HTMLElement | undefined) : undefined
83
+ if (notch) notch.scrollIntoView({ block: 'start', inline: 'start', behavior })
84
+ else item.scrollIntoView({ block: 'nearest', inline: 'nearest', behavior })
85
+ }
86
+
87
+ const carouselContext: CarouselContext = {
88
+ get items() {
89
+ return items
90
+ },
91
+ set items(next) {
92
+ items = next
93
+ },
94
+ position: (item) => places.get(item) ?? 0,
95
+ get itemLabel() {
96
+ return itemLabel
97
+ },
98
+ set itemLabel(next) {
99
+ itemLabel = next
100
+ },
101
+ }
102
+ setCarouselContext(carouselContext)
103
+ </script>
104
+
105
+ <div
106
+ {...attributes}
107
+ bind:this={element}
108
+ role={attributes.role ?? 'group'}
109
+ aria-roledescription={attributes['aria-roledescription'] ?? 'carousel'}
110
+ aria-label={label ?? attributes['aria-label']}
111
+ class={[
112
+ 'np-carousel',
113
+ `np-carousel-${variant}`,
114
+ `np-carousel-${axis}`,
115
+ snapping && 'np-carousel-snap',
116
+ cropping && 'np-carousel-cropping',
117
+ attributes.class,
118
+ ]}
119
+ onkeydown={handleKeydown}
120
+ onfocusin={handleFocusIn}
121
+ >
122
+ {#if keylined}
123
+ <div bind:this={metrics} class="np-carousel-metrics" aria-hidden="true">
124
+ <span class="np-carousel-metric-item"></span>
125
+ <span class="np-carousel-metric-small"></span>
126
+ </div>
127
+ {/if}
128
+ <div bind:this={scroller} class="np-carousel-scroller" {@attach morph}>
129
+ {#if morphing}
130
+ <div bind:this={snapPoints} class="np-carousel-snap-points" aria-hidden="true">
131
+ {#each items as item (item)}
132
+ <span></span>
133
+ {/each}
134
+ </div>
135
+ {/if}
136
+ <div bind:this={track} class="np-carousel-track" {@attach collectItems}>
137
+ {@render children?.()}
138
+ </div>
139
+ </div>
140
+ </div>
141
+
142
+ <style>
143
+ .np-carousel {
144
+ position: relative;
145
+ container-type: inline-size;
146
+ --_pad: 0px;
147
+ --_gap: var(--np-carousel-item-spacing, 0.5rem);
148
+ --_cross: var(--np-carousel-cross-padding, 0.5rem);
149
+ }
150
+
151
+ @media (prefers-reduced-motion: no-preference) {
152
+ .np-carousel {
153
+ --_pad: var(--np-carousel-padding, 1rem);
154
+ }
155
+ }
156
+
157
+ .np-carousel-scroller {
158
+ display: flex;
159
+ position: relative;
160
+ overflow-anchor: none;
161
+ scrollbar-width: var(--np-carousel-scrollbar-width, none);
162
+ }
163
+
164
+ .np-carousel-horizontal .np-carousel-scroller {
165
+ overflow-x: auto;
166
+ overflow-y: clip;
167
+ touch-action: pan-x pinch-zoom;
168
+ overscroll-behavior-inline: contain;
169
+ scroll-padding-inline-start: var(--_pad);
170
+ }
171
+
172
+ .np-carousel-vertical .np-carousel-scroller {
173
+ flex-direction: column;
174
+ overflow-x: clip;
175
+ overflow-y: auto;
176
+ touch-action: pan-y pinch-zoom;
177
+ block-size: var(--np-carousel-length, 100%);
178
+ scroll-padding-block-start: var(--_pad);
179
+ }
180
+
181
+ .np-carousel-snap.np-carousel-horizontal .np-carousel-scroller {
182
+ scroll-snap-type: x var(--np-carousel-snap-strictness, mandatory);
183
+ }
184
+
185
+ .np-carousel-snap.np-carousel-vertical .np-carousel-scroller {
186
+ scroll-snap-type: y var(--np-carousel-snap-strictness, mandatory);
187
+ }
188
+
189
+ .np-carousel-track {
190
+ display: flex;
191
+ flex: none;
192
+ align-items: center;
193
+ gap: var(--_gap);
194
+ padding-inline: var(--_pad);
195
+ padding-block: var(--_cross);
196
+ }
197
+
198
+ .np-carousel-vertical .np-carousel-track {
199
+ flex-direction: column;
200
+ padding-block: var(--_pad);
201
+ padding-inline: var(--_cross);
202
+ }
203
+
204
+ .np-carousel-vertical .np-carousel-track :global(.np-carousel-item-aspect) {
205
+ inline-size: var(--np-carousel-item-width, 12.5rem);
206
+ block-size: auto;
207
+ }
208
+
209
+ .np-carousel-full-screen {
210
+ --np-carousel-padding: 0px;
211
+ --_gap: 0px;
212
+ --_cross: 0px;
213
+ --np-carousel-item-container-shape: 0px;
214
+ --np-carousel-snap-stop: always;
215
+ }
216
+
217
+ .np-carousel-full-screen .np-carousel-track {
218
+ block-size: 100%;
219
+ }
220
+
221
+ .np-carousel-full-screen .np-carousel-track :global(.np-carousel-item) {
222
+ inline-size: 100%;
223
+ block-size: 100%;
224
+ flex: none;
225
+ }
226
+
227
+ .np-carousel-full-screen.np-carousel-vertical .np-carousel-scroller {
228
+ overscroll-behavior-block: contain;
229
+ }
230
+
231
+ :global(.np-carousel-morphing) .np-carousel-track {
232
+ overflow: clip;
233
+ overflow-clip-margin: var(--_cross);
234
+ }
235
+
236
+ :global(.np-carousel-morphing-inline) .np-carousel-track {
237
+ inline-size: var(--_track);
238
+ }
239
+
240
+ :global(.np-carousel-morphing-block) .np-carousel-track {
241
+ block-size: var(--_track);
242
+ }
243
+
244
+ :global(.np-carousel-morphing-inline) .np-carousel-track :global(.np-carousel-item) {
245
+ flex: 0 0 var(--_item, auto);
246
+ inline-size: var(--_item, auto);
247
+ }
248
+
249
+ :global(.np-carousel-morphing-block) .np-carousel-track :global(.np-carousel-item) {
250
+ flex: 0 0 var(--_item, auto);
251
+ block-size: var(--_item, auto);
252
+ }
253
+ @property --np-carousel-clip {
254
+ syntax: '<length>';
255
+ inherits: true;
256
+ initial-value: 0px;
257
+ }
258
+ @property --_out {
259
+ syntax: '<number>';
260
+ inherits: false;
261
+ initial-value: 0;
262
+ }
263
+
264
+ @property --_in {
265
+ syntax: '<number>';
266
+ inherits: false;
267
+ initial-value: 0;
268
+ }
269
+
270
+ @keyframes np-carousel-edge-out {
271
+ from {
272
+ --_out: 0;
273
+ }
274
+ to {
275
+ --_out: 1;
276
+ }
277
+ }
278
+
279
+ @keyframes np-carousel-edge-in {
280
+ from {
281
+ --_in: 1;
282
+ }
283
+ to {
284
+ --_in: 0;
285
+ }
286
+ }
287
+
288
+ @supports (animation-timeline: view()) {
289
+ .np-carousel-cropping .np-carousel-track :global(.np-carousel-item) {
290
+ animation:
291
+ np-carousel-edge-out linear both,
292
+ np-carousel-edge-in linear both;
293
+ animation-range: exit, entry;
294
+ --_crop-start: calc((1 - var(--_visible, 0.3333)) * var(--_out) * 100%);
295
+ --_crop-end: calc((1 - var(--_visible, 0.3333)) * var(--_in) * 100%);
296
+ --_shift: calc(var(--_visible, 0.3333) * (var(--_out) - var(--_in)) * 100%);
297
+ }
298
+
299
+ .np-carousel-cropping.np-carousel-horizontal .np-carousel-track :global(.np-carousel-item) {
300
+ animation-timeline: view(inline), view(inline);
301
+ clip-path: inset(
302
+ 0 var(--_crop-end) 0 var(--_crop-start) round
303
+ var(--np-carousel-item-container-shape, var(--np-shape-corner-extra-large))
304
+ );
305
+ --np-carousel-parallax: var(--_shift) 0;
306
+ }
307
+
308
+ .np-carousel-cropping.np-carousel-horizontal
309
+ .np-carousel-track:dir(rtl)
310
+ :global(.np-carousel-item) {
311
+ clip-path: inset(
312
+ 0 var(--_crop-start) 0 var(--_crop-end) round
313
+ var(--np-carousel-item-container-shape, var(--np-shape-corner-extra-large))
314
+ );
315
+ --_shift: calc(var(--_visible, 0.3333) * (var(--_in) - var(--_out)) * 100%);
316
+ }
317
+
318
+ .np-carousel-cropping.np-carousel-vertical .np-carousel-track :global(.np-carousel-item) {
319
+ animation-timeline: view(block), view(block);
320
+ clip-path: inset(
321
+ var(--_crop-start) 0 var(--_crop-end) 0 round
322
+ var(--np-carousel-item-container-shape, var(--np-shape-corner-extra-large))
323
+ );
324
+ --np-carousel-parallax: 0 var(--_shift);
325
+ }
326
+
327
+ .np-carousel-cropping .np-carousel-track :global(.np-carousel-item-label) {
328
+ inset-inline-start: var(--_crop-start);
329
+ inset-inline-end: var(--_crop-end);
330
+ }
331
+ }
332
+
333
+ @supports (animation-timeline: scroll(nearest inline)) {
334
+ :global(.np-carousel-morphing) .np-carousel-track :global(.np-carousel-item) {
335
+ animation: var(--_morph, none) linear both;
336
+ }
337
+
338
+ :global(.np-carousel-morphing-inline) .np-carousel-track :global(.np-carousel-item) {
339
+ animation-timeline: scroll(nearest inline);
340
+ }
341
+
342
+ :global(.np-carousel-morphing-block) .np-carousel-track :global(.np-carousel-item) {
343
+ animation-timeline: scroll(nearest block);
344
+ }
345
+ }
346
+
347
+ .np-carousel-snap-points > span {
348
+ position: absolute;
349
+ inset-block: 0;
350
+ inline-size: 1px;
351
+ pointer-events: none;
352
+ visibility: hidden;
353
+ }
354
+
355
+ .np-carousel-horizontal .np-carousel-snap-points > span {
356
+ inset-inline-start: calc(var(--_pad) + var(--_at, 0px));
357
+ }
358
+
359
+ .np-carousel-vertical .np-carousel-snap-points > span {
360
+ inset-block-start: calc(var(--_pad) + var(--_at, 0px));
361
+ inset-inline: 0;
362
+ block-size: 1px;
363
+ }
364
+
365
+ .np-carousel-snap .np-carousel-snap-points > span {
366
+ scroll-snap-align: start;
367
+ }
368
+
369
+ .np-carousel-snap .np-carousel-track :global(.np-carousel-item) {
370
+ scroll-snap-align: start;
371
+ }
372
+
373
+ :global(.np-carousel-morphing) .np-carousel-track :global(.np-carousel-item) {
374
+ scroll-snap-align: none;
375
+ }
376
+
377
+ .np-carousel-metrics {
378
+ position: absolute;
379
+ inset-block-start: 0;
380
+ inset-inline-start: 0;
381
+ block-size: 0;
382
+ visibility: hidden;
383
+ pointer-events: none;
384
+ }
385
+
386
+ .np-carousel-metrics > * {
387
+ display: block;
388
+ block-size: 0;
389
+ }
390
+
391
+ .np-carousel-metric-item {
392
+ inline-size: var(--np-carousel-item-width, 12.5rem);
393
+ }
394
+
395
+ .np-carousel-vertical .np-carousel-metric-item {
396
+ inline-size: auto;
397
+ block-size: var(--np-carousel-item-height, 12.5rem);
398
+ }
399
+
400
+ .np-carousel-metric-small {
401
+ inline-size: 0;
402
+ min-inline-size: var(--np-carousel-small-item-min-width, 2.5rem);
403
+ max-inline-size: var(--np-carousel-small-item-max-width, 3.5rem);
404
+ }
405
+
406
+ .np-carousel-vertical .np-carousel-metric-small {
407
+ min-block-size: var(--np-carousel-small-item-min-width, 2.5rem);
408
+ max-block-size: var(--np-carousel-small-item-max-width, 3.5rem);
409
+ }
410
+ </style>
@@ -0,0 +1,4 @@
1
+ import type { CarouselProps } from './types.ts';
2
+ declare const Carousel: import("svelte").Component<CarouselProps, {}, "scroller" | "element">;
3
+ type Carousel = ReturnType<typeof Carousel>;
4
+ export default Carousel;