@hyvor/design 2.1.14 → 2.1.16

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.
@@ -26,8 +26,15 @@
26
26
  speed = 34
27
27
  }: Props = $props();
28
28
 
29
- // render twice for marquee effect
30
- const track = $derived(marquee ? [...logos, ...logos] : logos);
29
+ let containerWidth = $state(0);
30
+ let setWidths = $state<number[]>([]);
31
+ const setWidth = $derived(setWidths[0] ?? 0);
32
+
33
+ const copies = $derived.by(() => {
34
+ if (!setWidth || !containerWidth) return 2;
35
+ const needed = Math.ceil((containerWidth * 2) / setWidth);
36
+ return Math.min(20, Math.max(2, needed % 2 === 0 ? needed : needed + 1));
37
+ });
31
38
  </script>
32
39
 
33
40
  {#snippet logoImg(logo: Logo, hidden = false)}
@@ -65,23 +72,27 @@
65
72
  </div>
66
73
 
67
74
  {#if marquee}
68
- <div class="marquee hds-container-max">
69
- <div class="marquee-track">
70
- {#each track as logo, i}
71
- {@const hidden = i >= logos.length}
72
- {#if logo.href}
73
- <a
74
- href={logo.href}
75
- target="_blank"
76
- rel="noopener"
77
- class="logo-link"
78
- tabindex={hidden ? -1 : undefined}
79
- >
80
- {@render logoImg(logo, hidden)}
81
- </a>
82
- {:else}
83
- {@render logoImg(logo, hidden)}
84
- {/if}
75
+ <div class="marquee hds-container-max" bind:clientWidth={containerWidth}>
76
+ <div class="marquee-track" style:--ls-copies={copies}>
77
+ {#each Array.from({ length: copies }) as _, setIndex (setIndex)}
78
+ {@const hidden = setIndex > 0}
79
+ <div class="marquee-set" bind:clientWidth={setWidths[setIndex]} aria-hidden={hidden}>
80
+ {#each logos as logo}
81
+ {#if logo.href}
82
+ <a
83
+ href={logo.href}
84
+ target="_blank"
85
+ rel="noopener"
86
+ class="logo-link"
87
+ tabindex={hidden ? -1 : undefined}
88
+ >
89
+ {@render logoImg(logo, hidden)}
90
+ </a>
91
+ {:else}
92
+ {@render logoImg(logo, hidden)}
93
+ {/if}
94
+ {/each}
95
+ </div>
85
96
  {/each}
86
97
  </div>
87
98
  </div>
@@ -134,9 +145,18 @@
134
145
  .marquee-track {
135
146
  display: flex;
136
147
  align-items: center;
137
- gap: 52px;
138
148
  width: max-content;
139
- animation: marquee-scroll var(--ls-speed) linear infinite;
149
+ /* keep a constant per-set speed regardless of how many sets we repeat */
150
+ animation: marquee-scroll calc(var(--ls-speed) * var(--ls-copies, 2) / 2) linear infinite;
151
+ }
152
+
153
+ .marquee-set {
154
+ display: flex;
155
+ align-items: center;
156
+ flex: none;
157
+ gap: 52px;
158
+ /* trailing gap so every set is an identical width and -50% lands cleanly */
159
+ padding-right: 52px;
140
160
  }
141
161
 
142
162
  .marquee:hover .marquee-track {
@@ -148,7 +168,6 @@
148
168
  transform: translateX(0);
149
169
  }
150
170
  to {
151
- /* one full set-width, since the track is two identical sets back to back */
152
171
  transform: translateX(-50%);
153
172
  }
154
173
  }
@@ -186,13 +205,18 @@
186
205
 
187
206
  .marquee-track {
188
207
  animation: none;
208
+ width: 100%;
209
+ padding: 0 15px;
210
+ }
211
+
212
+ .marquee-set {
189
213
  flex-wrap: wrap;
190
214
  justify-content: center;
191
215
  width: 100%;
192
- padding: 0 15px;
216
+ padding-right: 0;
193
217
  }
194
218
 
195
- .marquee-track :global(.logo[aria-hidden='true']) {
219
+ .marquee-set:not(:first-child) {
196
220
  display: none;
197
221
  }
198
222
  }