morphing-scroll 2.2.21 → 2.3.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
@@ -73,7 +73,8 @@ Start using the `MorphScroll` component by defining the required `size` prop. Fo
73
73
  ##### **GENERAL SETTINGS**:
74
74
 
75
75
  <details><summary><b><code>className</code></b>: <em>Additional classes.</em></summary><br /><ul><div>
76
- <b>Type:</b> string<br />
76
+ <b>Type:</b><br />
77
+ string<br />
77
78
  <br />
78
79
  <b>Description:</b> <em><br />
79
80
  This parameter allows you to add additional classes to the component.</em><br />
@@ -91,7 +92,8 @@ This parameter allows you to add additional classes to the component.</em><br />
91
92
  <h2></h2>
92
93
 
93
94
  <details><summary><b><code>children</code></b>: <em>Custom user content.</em></summary><br /><ul><div>
94
- <b>Type:</b> React.ReactNode<br />
95
+ <b>Type:</b><br />
96
+ React.ReactNode<br />
95
97
  <br />
96
98
  <b>Description:</b> <em><br />
97
99
  This is where you can pass your list elements.<br />
@@ -111,9 +113,11 @@ Additionally, <code>MorphScroll</code> handles a passed <mark>null</mark> value
111
113
  ##### **SCROLL SETTINGS**:
112
114
 
113
115
  <details><summary><b><code>type</code></b>: <em>Type of progress element.</em></summary><br /><ul><div>
114
- <b>Type:</b> "scroll" | "slider" | "sliderMenu"<br />
116
+ <b>Type:</b><br />
117
+ "scroll" | "slider" | "sliderMenu"<br />
115
118
  <br />
116
- <b>Default:</b> "scroll"<br />
119
+ <b>Default:</b><br />
120
+ "scroll"<br />
117
121
  <br />
118
122
  <b>Description:</b> <em><br />
119
123
  This parameter defines how the provided <code>progressElement</code> behaves within <code>progressTrigger</code> and how you interact with it.<br />
@@ -139,9 +143,11 @@ This parameter defines how the provided <code>progressElement</code> behaves wit
139
143
  <h2></h2>
140
144
 
141
145
  <details><summary><b><code>direction</code></b>: <em>Scrolling direction.</em></summary><br /><ul><div>
142
- <b>Type:</b> "x" | "y" | "hybrid"<br />
146
+ <b>Type:</b><br />
147
+ "x" | "y" | "hybrid"<br />
143
148
  <br />
144
- <b>Default:</b> "y"<br />
149
+ <b>Default:</b><br />
150
+ "y"<br />
145
151
  <br />
146
152
  <b>Description:</b> <em><br />
147
153
  This parameter changes the scroll or slider type direction based on the provided value.<br />
@@ -162,13 +168,17 @@ You can set the value to horizontal, vertical or hybrid positions to customize t
162
168
  <h2></h2>
163
169
 
164
170
  <details><summary><b><code>scrollPosition</code></b>: <em>Scroll position and additional options.</em></summary><br /><ul><div>
165
- <b>Type:</b> {<br />
166
- value: number | "end" | (number | "end")[];<br />
167
- duration?: number;<br />
168
- updater?: boolean;<br />
171
+ <b>Type:</b><br />
172
+ {<br />
173
+ <ul>
174
+ value: number | "end" | (number | "end")[];<br />
175
+ duration?: number;<br />
176
+ updater?: boolean;<br />
177
+ </ul>
169
178
  }<br />
170
179
  <br />
171
- <b>Default:</b> { duration: 200; updater: false }<br />
180
+ <b>Default:</b><br />
181
+ { duration: 200; updater: false }<br />
172
182
  <br />
173
183
  <b>Description:</b> <em><br />
174
184
  This parameter allows you to set custom scroll values.<br />
@@ -204,7 +214,8 @@ This property is a helper for the <code>value</code> property. When setting the
204
214
  <h2></h2>
205
215
 
206
216
  <details><summary><b><code>onScrollValue</code></b>: <em>Callback for scroll value.</em></summary><br /><ul><div>
207
- <b>Type:</b> ( left: number, top: number ) => void<br />
217
+ <b>Type:</b><br />
218
+ ( left: number, top: number ) => void<br />
208
219
  <br />
209
220
  <b>Description:</b> <em><br />
210
221
  This parameter accepts a callback function that is triggered on every scroll event. The callback receives the current scroll top and left position as a number. The return value of the callback can be used to determine custom behavior based on the scroll value.</em><br />
@@ -226,7 +237,8 @@ This parameter accepts a callback function that is triggered on every scroll eve
226
237
  <h2></h2>
227
238
 
228
239
  <details><summary><b><code>isScrolling</code></b>: <em>Callback function for scroll status.</em></summary><br /><ul><div>
229
- <b>Type:</b> ( motion: boolean ) => void<br />
240
+ <b>Type:</b><br />
241
+ ( motion: boolean ) => void<br />
230
242
  <br />
231
243
  <b>Description:</b> <em><br />
232
244
  This parameter accepts a callback function that is triggered whenever the scroll status changes. The callback receives a boolean value, where <code>true</code> indicates that scrolling is in progress, and <code>false</code> indicates that scrolling has stopped. This can be useful for triggering additional actions, such as pausing animations or loading indicators based on the scroll state.</em><br />
@@ -251,7 +263,8 @@ This parameter accepts a callback function that is triggered whenever the scroll
251
263
  ##### **VISUAL SETTINGS**:
252
264
 
253
265
  <details><summary><b><code>size</code> REQUIRED</b>: <em>[width, height] dimension of <b>MorphScroll</b>.</em></summary><br /><ul><div>
254
- <b>Type:</b><br /> number | number[] | "auto"<br />
266
+ <b>Type:</b><br />
267
+ number | number[] | "auto"<br />
255
268
  <br />
256
269
  <b>Description:</b> <em><br />
257
270
  This parameter sets the width and height of the <code>MorphScroll</code>.<br />
@@ -279,7 +292,8 @@ This parameter sets the width and height of the <code>MorphScroll</code>.<br />
279
292
  number | "size" | "firstChild" | "none"<br />
280
293
  | (number | "size" | "firstChild" | "none")[]<br />
281
294
  <br />
282
- <b>Default:</b> If you don't provide any value, the default value will be taken from <code>size</code><br />
295
+ <b>Default:</b><br />
296
+ If you don't provide any value, the default value will be taken from <code>size</code><br />
283
297
  <br />
284
298
  <b>Description:</b> <em><br />
285
299
  This parameter defines the [width, height] of cells for each of your objects.<br />
@@ -320,7 +334,8 @@ This can be useful if you want to change the size of objects in your list dynami
320
334
  <h2></h2>
321
335
 
322
336
  <details><summary><b><code>crossCount</code></b>: <em>Number of cells in each direction.</em></summary><br /><ul><div>
323
- <b>Type:</b> number<br />
337
+ <b>Type:</b><br />
338
+ number<br />
324
339
  <br />
325
340
  <b>Description:</b> <em><br />
326
341
  This parameter defines the number of <b>columns</b> (<code>direction="y"</code>, <code>direction="hybrid"</code> + <code>elementsDirection="column"</code>) or <b>rows</b> (<code>direction="x"</code>, <code>direction="hybrid"</code> + <code>elementsDirection="row"</code>).<br />
@@ -346,7 +361,8 @@ This parameter defines the number of <b>columns</b> (<code>direction="y"</code>,
346
361
  <h2></h2>
347
362
 
348
363
  <details><summary><b><code>gap</code></b>: <em>Gap between cells.</em></summary><br /><ul><div>
349
- <b>Type:</b> number | number[]<br />
364
+ <b>Type:</b><br />
365
+ number | number[]<br />
350
366
  <br />
351
367
  <b>Description:</b> <em><br />
352
368
  This parameter allows you to set spacing in pixels between list items for rows and columns.<br />
@@ -369,7 +385,8 @@ It can be 1 number or an array of 2 numbers.</em><br />
369
385
  <h2></h2>
370
386
 
371
387
  <details><summary><b><code>wrapperMargin</code></b>: <em>Margin for the <b>.ms-objects-wrapper</b>.</em></summary><br /><ul><div>
372
- <b>Type:</b> number | number[]<br />
388
+ <b>Type:</b><br />
389
+ number | number[]<br />
373
390
  <br />
374
391
  <b>Description:</b> <em><br />
375
392
  This parameter defines the spacing between the list items and their wrapper, effectively increasing the width or height of the scrollable area.<br />
@@ -392,7 +409,9 @@ Can be 1 number or an array of 2 or 4 numbers in pixels.</em><br />
392
409
  <h2></h2>
393
410
 
394
411
  <details><summary><b><code>wrapperMinSize</code></b>: <em>Minimum height or width of the <b>.ms-objects-wrapper</b>.</em></summary><br /><ul><div>
395
- <b>Type:</b> number | "full" | (number | "full")[]<br /><br />
412
+ <b>Type:</b><br />
413
+ number | "full" | (number | "full")[]<br />
414
+ <br />
396
415
  <b>Description:</b> <em><br />
397
416
  This parameter defines the minimum height or width of the <b>.ms-objects-wrapper</b>, to which CSS properties like <code>min-height</code> or <code>min-width</code> will be applied.<br />
398
417
  <br />
@@ -439,7 +458,8 @@ Use 1 value to align one or both axes, or an array of 2 values to align both axe
439
458
  <h2></h2>
440
459
 
441
460
  <details><summary><b><code>elementsAlign</code></b>: <em>Aligns the objects inside <code>MorphScroll</code>.</em></summary><br /><ul><div>
442
- <b>Type:</b> "start" | "center" | "end"<br />
461
+ <b>Type:</b><br />
462
+ "start" | "center" | "end"<br />
443
463
  <br />
444
464
  <b>Example:</b>
445
465
 
@@ -456,9 +476,11 @@ Use 1 value to align one or both axes, or an array of 2 values to align both axe
456
476
  <h2></h2>
457
477
 
458
478
  <details><summary><b><code>elementsDirection</code></b>: <em>Direction of the provided elements.</em></summary><br /><ul><div>
459
- <b>Type:</b> "row" | "column"<br />
479
+ <b>Type:</b><br />
480
+ "row" | "column"<br />
460
481
  <br />
461
- <b>Default:</b> "row"<br />
482
+ <b>Default:</b><br />
483
+ "row"<br />
462
484
  <br />
463
485
  <b>Description:</b> <em><br />
464
486
  This parameter changes the order of the provided elements based on the provided value.</em><br />
@@ -478,19 +500,21 @@ This parameter changes the order of the provided elements based on the provided
478
500
  <h2></h2>
479
501
 
480
502
  <details><summary><b><code>edgeGradient</code></b>: <em>Gradient overlay at the edges of the scroll area.</em></summary><br /><ul><div>
481
- <b>Type:</b> boolean | { color?: string; size?: number }<br />
503
+ <b>Type:</b><br />
504
+ boolean | { color?: string; size?: number }<br />
482
505
  <br />
483
- <b>Default:</b> { size: 40 }<br />
506
+ <b>Default:</b><br />
507
+ { size: 40 }<br />
484
508
  <br />
485
509
  <b>Description:</b> <em><br />
486
510
  This parameter creates two edge elements responsible for darkening the edges of the scroll when it overflows.<br />
487
511
  <br />
488
- <code>color</code> :<br />
512
+ <code>color</code>:<br />
489
513
  The property accepts any valid color format.
490
514
  If you provide it, the library will generate a gradient transitioning from the custom color to transparent.
491
515
  If you provide just <mark>true</mark>, the edge elements will have no color, allowing for custom styling via CSS classes.<br />
492
516
  <br />
493
- <code>size</code> :<br />
517
+ <code>size</code>:<br />
494
518
  The property changes the height for horizontal and width for vertical <b>.ms-edge</b>.</em><br />
495
519
  <br />
496
520
  <b>Example:</b>
@@ -513,39 +537,52 @@ The property changes the height for horizontal and width for vertical <b>.ms-edg
513
537
  ##### **PROGRESSBAR**:
514
538
 
515
539
  <details><summary><b><code>progressTrigger</code></b>: <em>Triggers for the scroll progress.</em></summary><br /><ul><div>
516
- <b>Type:</b> {<br />
517
- wheel?: boolean;<br />
518
- content?: boolean;<br />
519
- progressElement?: boolean | React.ReactNode | React.ReactNode[];<br />
520
- arrows?: boolean | { size?: number; element?: React.ReactNode };<br />
540
+ <b>Type:</b><br />
541
+ {<br />
542
+ <ul>
543
+ wheel?: boolean | { changeDirection?: boolean; changeDirectionKey?: string };<br />
544
+ content?: boolean;<br />
545
+ progressElement?: boolean | React.ReactNode | React.ReactNode[];<br />
546
+ arrows?: boolean | { size?: number; element?: React.ReactNode };<br />
547
+ </ul>
521
548
  }<br />
522
549
  <br />
523
- <b>Default:</b> { wheel: true }<br />
550
+ <b>Default:</b><br />
551
+ { wheel: true }<br />
524
552
  <br />
525
553
  <b>Description:</b> <em><br />
526
554
  This is one of the most important properties, allowing you to define how users interact with the progress bar and customize its appearance.<br />
527
555
  <br />
528
- <code>wheel</code> :<br />
529
- This parameter determines whether the progress bar responds to mouse wheel scrolling.<br />
556
+ <code>wheel</code>:<br />
557
+ Determines whether the progress bar responds to mouse wheel scrolling.<br />
558
+ If you use <code>direction="hybrid"</code>, you can use:
559
+ <ul>
560
+ <li><code>changeDirection</code>: allows switching the scroll direction with the mouse wheel.</li>
561
+ <li><code>changeDirectionKey</code>: enables switching the scroll direction by pressing a specific key (default: <mark>"KeyX"</mark>).<br />
562
+ To disable this behavior, pass an empty string.<br />
563
+ <a href="https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_code_values">more about keys</a></li>
564
+ </ul>
530
565
  <br />
531
- <code>content</code> :<br />
566
+ <code>content</code>:<br />
532
567
  This parameter enables interaction by clicking and dragging anywhere within the scrollable content to move it.<br />
533
568
  <br />
534
- <code>progressElement</code> :<br />
569
+ <code>progressElement</code>:<br />
535
570
  This parameter determines how the scroll progress is managed.<br />
536
571
  <br />
537
572
  <ul>
538
- <li>When using <code>type="scroll"</code>, you can provide a custom scroll element. If it's not ready yet, simply set <mark>true</mark> instead — this will fall back to the browser’s default scrollbar.</li>
539
- <li>When using <code>type="slider"</code>, a <b>.ms-slider</b> element is automatically generated. It contains multiple <b>ms-slider-element</b> elements that visually represent the scroll progress. One of them will always have the <code>active</code> class depending on the current position.</li>
573
+ <li>When using <code>type="scroll"</code>, you can provide a custom scroll element. If it's not ready yet, simply set <mark>true</mark> instead — this will fall back to the browser’s default scrollbar.</li><br />
574
+ <li>When using <code>type="slider"</code>, a <b>.ms-slider</b> element is automatically generated. It contains multiple <b>ms-slider-element</b> elements that visually represent the scroll progress. One of them will always have the <code>active</code> class depending on the current position.</li><br />
540
575
  <li>When using <code>type="sliderMenu"</code>, everything is the same as with <mark>"slider"</mark> but you can pass an array of custom buttons to <code>progressElement</code>. These buttons act as a navigation menu, allowing users to jump to specific sections.</li>
541
576
  </ul>
542
577
  <br />
543
- <code>arrows</code> :<br />
578
+ <code>arrows</code>:<br />
544
579
  This parameter allows you to add custom arrows to the progress bar. You can either specify a <code>size</code> for the arrows and provide a custom element.<br />
545
580
  <br />
546
581
  ✦ Note:<br />
547
- <code>progressTrigger</code> can only create or provide your elements, but you must make the design for them yourself.</em><br />
548
- <br />
582
+ <ul>
583
+ <li><code>progressTrigger</code> can only create or provide elements, but you must make the design for them yourself.</li>
584
+ <li>The Library scroll element automatically receives <code>:focus</code> when you start scrolling with the mouse wheel.</li>
585
+ </ul></em><br />
549
586
  <b>Example:</b>
550
587
 
551
588
  ```tsx
@@ -565,9 +602,11 @@ This parameter allows you to add custom arrows to the progress bar. You can eith
565
602
  <h2></h2>
566
603
 
567
604
  <details><summary><b><code>progressReverse</code></b>: <em>Reverse the progress bar position.</em></summary><br /><ul><div>
568
- <b>Type:</b> boolean | boolean[]<br />
605
+ <b>Type:</b><br />
606
+ boolean | boolean[]<br />
569
607
  <br />
570
- <b>Default:</b> false<br />
608
+ <b>Default:</b><br />
609
+ false<br />
571
610
  <br />
572
611
  <b>Description:</b> <em><br />
573
612
  This parameter changes the position of the progress bar based on the direction property.<br />
@@ -593,9 +632,11 @@ This parameter changes the position of the progress bar based on the direction p
593
632
  <h2></h2>
594
633
 
595
634
  <details><summary><b><code>scrollBarOnHover</code></b>: <em>Hover visibility of the <b>progress bar</b>.</em></summary><br /><ul><div>
596
- <b>Type:</b> boolean<br />
635
+ <b>Type:</b><br />
636
+ boolean<br />
597
637
  <br />
598
- <b>Default:</b> false<br />
638
+ <b>Default:</b><br />
639
+ false<br />
599
640
  <br />
600
641
  <b>Description:</b> <em><br />
601
642
  This parameter controls the visibility of the progress bar regardless of the <code>type</code> value.<br />
@@ -618,11 +659,14 @@ When you use it, the <b>"hover"</b> class is applied to the <b>.ms-bar</b> when
618
659
  ##### **OPTIMIZATIONS**:
619
660
 
620
661
  <details><summary><b><code>render</code></b>: <em>Rendering strategy for performance optimization.</em></summary><br /><ul><div>
621
- <b>Type:</b> {<br />
662
+ <b>Type:</b><br />
663
+ {<br />
664
+ <ul>
622
665
  type: "lazy" | "virtual";<br />
623
666
  rootMargin?: number | number[];<br />
624
667
  stopLoadOnScroll?: boolean;<br />
625
- }<br />
668
+ </ul>
669
+ }<br />
626
670
  <br />
627
671
  <b>Description:</b> <em><br />
628
672
  This parameter adds a gradual rendering of the content as it enters the viewport.<br />
@@ -658,28 +702,33 @@ This property controls whether to stop loading content when scrolling.<br />
658
702
  <h2></h2>
659
703
 
660
704
  <details><summary><b><code>emptyElements</code></b>: <em>Handling of empty scroll elements.</em></summary><br /><ul><div>
661
- <b>Type:</b> {<br />
662
- mode: "clear" | "fallback" | { fallback: React.ReactNode };<br />
663
- clickTrigger?: { selector: string; delay?: number };<br />
705
+ <b>Type:</b><br />
706
+ {<br />
707
+ <ul>
708
+ mode: "clear" | "fallback" | { fallback: React.ReactNode };<br />
709
+ clickTrigger?: { selector: string; delay?: number };<br />
710
+ </ul>
664
711
  }<br />
665
712
  <br />
666
713
  <b>Description:</b> <em><br />
667
714
  This option will allow you to delete or replace empty list items during the first rendering, or to start this process by clicking.<br />
668
715
  <br />
669
- <code>mode</code> :<br />
716
+ <code>mode</code>:<br />
670
717
  <ul>
671
718
  <li><mark>"clear"</mark> – automatically removes empty elements.</li>
672
719
  <li><mark>"fallback"</mark> – replaces empty elements with the value from the <code>fallback</code> props.</li>
673
720
  <li><mark>{ fallback: React.ReactNode }</mark> – if you need a different element than in <code>fallback</code> to replace empty elements, you can use this option.</li>
674
721
  </ul>
675
722
  <br />
676
- <code>clickTrigger</code> :<br />
723
+ <code>clickTrigger</code>:<br />
677
724
  In case if elements are removed via a click action, use this option. It accepts an object with a <code>selector</code> ( such as a delete button’s class ) and <code>delay</code> ( in <b>ms</b> ) to wait before removing the elements.<br />
678
725
  <br />
679
726
  ✦ Note:<br />
680
727
  <ul>
681
- <li>The cleanup will start on the initial render, when the number of passed elements changes, on scroll and on click if you use <code>clickTrigger</code>.</li>
682
- <li>If you are using <code>clickTrigger</code> but there are no changes, you may need to increase the <code>delay</code> value, since the cleanup function is triggered when your item has not yet been deleted.</li>
728
+ <li>The cleanup runs on the initial render, when the number of elements changes, on scroll, and on click if you use <code>clickTrigger</code>.</li>
729
+ <li>If you use <code>clickTrigger</code>:<br />
730
+ - consider increasing <code>delay</code>, since the cleanup may run before removal.<br />
731
+ - the wrapper <code>ms-object-box</code> also gets the <code>remove</code> class, which you can use e.g. for fade-out animations.</li>
683
732
  </ul></em>
684
733
  <br />
685
734
  <b>Example:</b>
@@ -703,9 +752,11 @@ In case if elements are removed via a click action, use this option. It accepts
703
752
  <h2></h2>
704
753
 
705
754
  <details><summary><b><code>suspending</code></b>: <em>Adds React Suspense.</em></summary><br /><ul><div>
706
- <b>Type:</b> boolean<br />
755
+ <b>Type:</b><br />
756
+ boolean<br />
707
757
  <br />
708
- <b>Default:</b> false<br />
758
+ <b>Default:</b><br />
759
+ false<br />
709
760
  <br />
710
761
  <b>Description:</b> <em><br />
711
762
  This parameter adds React Suspense to the MorphScroll component for asynchronous rendering.</em><br />
@@ -723,7 +774,8 @@ This parameter adds React Suspense to the MorphScroll component for asynchronous
723
774
  <h2></h2>
724
775
 
725
776
  <details><summary><b><code>fallback</code></b>: <em>Fallback element.</em></summary><br /><ul><div>
726
- <b>Type:</b> React.ReactNode<br />
777
+ <b>Type:</b><br />
778
+ React.ReactNode<br />
727
779
  <br />
728
780
  <b>Description:</b> <em><br />
729
781
  This parameter sets the fallback element to display during loading or placeholder.<br />
@@ -757,7 +809,8 @@ It will be used when:
757
809
  <ul><div>
758
810
 
759
811
  <details><summary><b><code>className</code></b>: <em>Additional classes.</em></summary><br /><ul><div>
760
- <b>Type:</b> string<br />
812
+ <b>Type:</b><br />
813
+ string<br />
761
814
  <br />
762
815
  <b>Description:</b> <em><br />
763
816
  This parameter allows you to add additional classes to the component.</em><br />
@@ -773,7 +826,8 @@ This parameter allows you to add additional classes to the component.</em><br />
773
826
  <h2></h2>
774
827
 
775
828
  <details><summary><b><code>children</code></b>: <em>Custom user content.</em></summary><br /><ul><div>
776
- <b>Type:</b> React.ReactNode<br />
829
+ <b>Type:</b><br />
830
+ React.ReactNode<br />
777
831
  <br />
778
832
  <b>Description:</b> <em><br />
779
833
  This parameter allows you to add custom content to the component.</em><br />
@@ -789,7 +843,8 @@ This parameter allows you to add custom content to the component.</em><br />
789
843
  <h2></h2>
790
844
 
791
845
  <details><summary><b><code>style</code></b>: <em>Applies inline styles to the container.</em></summary><br /><ul><div>
792
- <b>Type:</b> React.CSSProperties<br />
846
+ <b>Type:</b><br />
847
+ React.CSSProperties<br />
793
848
  <br />
794
849
  <b>Example:</b>
795
850
 
@@ -802,9 +857,11 @@ This parameter allows you to add custom content to the component.</em><br />
802
857
  <h2></h2>
803
858
 
804
859
  <details><summary><b><code>measure</code></b>: <em>Defines the measurement strategy.</em></summary><br /><ul><div>
805
- <b>Type:</b> "inner" | "outer" | "all"<br />
860
+ <b>Type:</b><br />
861
+ "inner" | "outer" | "all"<br />
806
862
  <br />
807
- <b>Default:</b> "inner"<br />
863
+ <b>Default:</b><br />
864
+ "inner"<br />
808
865
  <br />
809
866
  <b>Description:</b><br />
810
867
  <em>This prop determines what is being measured by automatically applying inline styles that affect width and height.<br />
@@ -829,7 +886,8 @@ Be cautious when overriding styles via the <code>style</code> prop, as it may in
829
886
  <h2></h2>
830
887
 
831
888
  <details><summary><b><code>onResize</code></b>: <em>Callback triggered on size changes.</em></summary><br /><ul><div>
832
- <b>Type:</b> (rect: Partial<DOMRectReadOnly>) => void<br />
889
+ <b>Type:</b><br />
890
+ (rect: Partial<DOMRectReadOnly>) => void<br />
833
891
  <br />
834
892
  <b>Description:</b><br />
835
893
  <em>A callback function that is triggered whenever the observed element's dimensions change.<br />
@@ -868,7 +926,8 @@ The function receives an object containing the updated size properties.</em><br
868
926
  <ul><div>
869
927
 
870
928
  <details><summary><b><code>className</code></b>: <em>Additional classes.</em></summary><br /><ul><div>
871
- <b>Type:</b> string<br />
929
+ <b>Type:</b><br />
930
+ string<br />
872
931
  <br />
873
932
  <b>Description:</b> <em><br />
874
933
  This parameter allows you to add additional classes to the component.</em><br />
@@ -884,7 +943,8 @@ This parameter allows you to add additional classes to the component.</em><br />
884
943
  <h2></h2>
885
944
 
886
945
  <details><summary><b><code>children</code></b>: <em>Custom user content.</em></summary><br /><ul><div>
887
- <b>Type:</b> React.ReactNode<br />
946
+ <b>Type:</b><br />
947
+ React.ReactNode<br />
888
948
  <br />
889
949
  <b>Example:</b>
890
950
 
@@ -897,7 +957,8 @@ This parameter allows you to add additional classes to the component.</em><br />
897
957
  <h2></h2>
898
958
 
899
959
  <details><summary><b><code>style</code></b>: <em>Applies inline styles to the container.</em></summary><br /><ul><div>
900
- <b>Type:</b> React.CSSProperties<br />
960
+ <b>Type:</b><br />
961
+ React.CSSProperties<br />
901
962
  <br />
902
963
  <b>Example:</b>
903
964
 
@@ -912,9 +973,11 @@ This parameter allows you to add additional classes to the component.</em><br />
912
973
  <h2></h2>
913
974
 
914
975
  <details><summary><b><code>root</code></b>: <em>Defines the observation area.</em></summary><br /><ul><div>
915
- <b>Type:</b> Element | null<br />
976
+ <b>Type:</b><br />
977
+ Element | null<br />
916
978
  <br />
917
- <b>Default:</b> null (window)<br />
979
+ <b>Default:</b><br />
980
+ null (window)<br />
918
981
  <br />
919
982
  <b>Description:</b> <em><br />
920
983
  Specifies the element that serves as the bounding box for the intersection observation.
@@ -933,7 +996,8 @@ If provided, it must be an ancestor of the observed element.</em><br />
933
996
  <h2></h2>
934
997
 
935
998
  <details><summary><b><code>rootMargin</code></b>: <em>Sets the margin around the root element.</em></summary><br /><ul><div>
936
- <b>Type:</b> number | number[]<br />
999
+ <b>Type:</b><br />
1000
+ number | number[]<br />
937
1001
  <br />
938
1002
  <b>Description:</b> <em><br />
939
1003
  Defines an offset around the root element, expanding or shrinking the observed area.<br />
@@ -952,9 +1016,11 @@ It can be a single number or an array of 2 <b>[ top-bottom, left-right ]</b> or
952
1016
  <h2></h2>
953
1017
 
954
1018
  <details><summary><b><code>threshold</code></b>: <em>Defines when the callback <code>onIntersection</code> and content visibility should be triggered.</em></summary><br /><ul><div>
955
- <b>Type:</b> number | number[]<br />
1019
+ <b>Type:</b><br />
1020
+ number | number[]<br />
956
1021
  <br />
957
- <b>Default:</b> 0<br />
1022
+ <b>Default:</b><br />
1023
+ 0<br />
958
1024
  <br />
959
1025
  <b>Description:</b> <em><br />
960
1026
  Specifies at what percentage of the observed element’s visibility the callback should be executed.<br />
@@ -976,9 +1042,11 @@ Specifies at what percentage of the observed element’s visibility the callback
976
1042
  <h2></h2>
977
1043
 
978
1044
  <details><summary><b><code>visibleContent</code></b>: <em>Makes all elements always visible.</em></summary><br /><ul><div>
979
- <b>Type:</b> boolean<br />
1045
+ <b>Type:</b><br />
1046
+ boolean<br />
980
1047
  <br />
981
- <b>Default:</b> false<br />
1048
+ <b>Default:</b><br />
1049
+ false<br />
982
1050
  <br />
983
1051
  <b>Description:</b> <em><br />
984
1052
  If set to <mark>true</mark>, the tracked elements will always be visible, regardless of their actual intersection status.<br />
@@ -995,7 +1063,8 @@ This is useful for testing purposes or when using the <code>onIntersection</code
995
1063
  <h2></h2>
996
1064
 
997
1065
  <details><summary><b><code>onIntersection</code></b>: <em>Callback function triggered when the element becomes visible.</em></summary><br /><ul><div>
998
- <b>Type:</b> (entry: IntersectionObserverEntry) => void<br />
1066
+ <b>Type:</b><br />
1067
+ (entry: IntersectionObserverEntry) => void<br />
999
1068
  <br />
1000
1069
  <b>Description:</b> <em><br />
1001
1070
  A callback function that is called when the observed element enters or leaves the viewport or the area defined by the <code>root</code> property. This can be used to load new list items for <code>MorphScroll</code>.<br />
package/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");const t=(e,t=!1,r)=>{let n=[];if(n=Array.isArray(e)?2===e.length?[e[1],e[0],e[1],e[0]]:[...e]:[e,e,e,e],t&&(n=[n[1],n[0],n[3],n[2]]),r){const e=[];for(let t=0;r>t;t++)e.push(n[t%4]);n=e}return n},r=({className:r,children:n,style:o,root:l,threshold:s,rootMargin:i,visibleContent:c=!1,onIntersection:a})=>{const[u,d]=e.useState(!1),m=e.useRef(null),p=e.useMemo((()=>{if(!i)return"";const e=t(i);return`${e[0]}px ${e[1]}px ${e[2]}px ${e[3]}px`}),[i]),f=e.useCallback((([e])=>{d(e.isIntersecting),a&&a({time:e.time,rootBounds:e.rootBounds,boundingClientRect:e.boundingClientRect,intersectionRect:e.intersectionRect,isIntersecting:e.isIntersecting,intersectionRatio:e.intersectionRatio,target:e.target})}),[a]);return e.useEffect((()=>{const e=new IntersectionObserver(f,{root:l,threshold:s,rootMargin:p});return m.current&&e.observe(m.current),()=>{e.disconnect()}}),[f,l,s,p]),e.createElement("div",{"intersection-tracker":"",className:r,ref:m,style:o},c||u?n:null)};r.displayName="IntersectionTracker";const n=({className:t,children:r,style:n,measure:o="inner",onResize:l})=>{const s=e.useRef(null);e.useEffect((()=>{const e=s.current;if(!e)return;const t=new ResizeObserver((e=>{for(const t of e)l&&l(t.contentRect)}));return t.observe(e),()=>{t.unobserve(e),t.disconnect()}}),[o,l]);const i={width:"max-content",height:"max-content"},c={inner:Object.assign({},i),outer:Object.assign({},{width:"100%",height:"100%"}),all:Object.assign({minWidth:"100%",minHeight:"100%"},i)};return e.createElement("div",{"resize-tracker":"",className:t,ref:s,style:Object.assign(Object.assign({willChange:"width, height"},c[o]),n)},r)};function o(t,r){const n=e.useMemo((()=>function(e,t){let r=null,n=null;const o=(...o)=>{"requestFrame"===t?(null!==n&&cancelAnimationFrame(n),n=requestAnimationFrame((()=>{e(...o),n=null}))):(null!==r&&clearTimeout(r),r=setTimeout((()=>{e(...o),r=null}),t))};return o.cancel=()=>{null!==r&&(clearTimeout(r),r=null),null!==n&&(cancelAnimationFrame(n),n=null)},o}(t,r)),[r,t]);return e.useEffect((()=>()=>{n.cancel()}),[n]),n}n.displayName="ResizeTracker";let l=1;const s=({type:t,direction:r,progressReverse:n,size:o,progressTrigger:l,scrollBarOnHover:s,scrollBarEvent:i,thumbSize:c,thumbSpace:a,objLengthPerSize:u,sliderCheckLocal:d,duration:m})=>{const p="sliderMenu"!==t?{onMouseDown:i,onTouchStart:i}:{},f=e.useMemo((()=>{if("scroll"===t||!r)return;const n=["hybrid","y"].includes(r)?"y":"x",s="x"===n?o[0]:o[1];return Array.from({length:u},((r,o)=>e.createElement("div",{key:o,className:"ms-slider-element",style:Object.assign({},"sliderMenu"===t&&{cursor:"pointer"}),onClick:"sliderMenu"===t?()=>{i(s*o,n,m,d)}:void 0},Array.isArray(null==l?void 0:l.progressElement)?l.progressElement[o]:null==l?void 0:l.progressElement)))}),[u,r,o,t,i,null==l?void 0:l.progressElement]);return e.createElement(e.Fragment,null,"scroll"===t?e.createElement("div",{className:"ms-bar",style:Object.assign(Object.assign(Object.assign({position:"absolute",width:"fit-content"},"x"===r?Object.assign({transformOrigin:"left top",height:o[0]+"px"},n?{top:0,transform:"rotate(-90deg) translateX(-100%)"}:{transform:"rotate(-90deg)"}):Object.assign({top:0,height:"100%"},n?{left:0}:{right:0})),0!=!(null==l?void 0:l.progressElement)&&{pointerEvents:"none"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"})},e.createElement("div",Object.assign({className:"ms-thumb","data-direction":["hybrid","y"].includes(r)?"y":r},p,{style:Object.assign(Object.assign({height:c+"px",willChange:"transform, height",transform:`translateY(${a}px)`},(null==l?void 0:l.progressElement)&&{cursor:"grab"}),{transition:"height 0.05s ease-in-out"})}),null==l?void 0:l.progressElement)):u>1&&(null==l?void 0:l.progressElement)&&e.createElement("div",Object.assign({className:"ms-slider","data-direction":["hybrid","y"].includes(r)?"y":r},p,{style:Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex"},"slider"===t&&{cursor:"grab"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"}),"x"===r?Object.assign({transformOrigin:"left top",left:"50%",transform:"translateX(-50%)"},n?{top:0}:{bottom:0}):Object.assign({flexDirection:"column",top:"50%",transform:"translateY(-50%)"},n?{left:0}:{right:0}))}),f))};s.displayName="ScrollBar";var i=e.memo(s);const c=({edgeGradient:t,visibility:r,edgeType:n})=>{if(!t)return null;const o=Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",pointerEvents:"none",transition:"opacity 0.1s ease-in-out"},t.color&&{background:t.color&&`linear-gradient(${"right"===n||"left"===n?"90deg, ":""}${t.color}, transparent)`}),"right"===n||"left"===n?{height:"100%",width:t.size+"px",top:0}:{width:"100%",height:t.size+"px",left:0}),n?{[n]:0}:{}),"right"===n?{transform:"scaleX(-1)"}:"bottom"===n?{transform:"scaleY(-1)"}:{});return e.createElement("div",{className:"ms-edge"+(n?" "+n:""),style:Object.assign(Object.assign({},o),{opacity:r?1:0})})};c.displayName="Edge";var a=e.memo(c);const u=({activity:t,arrows:r,arrowType:n,handleArrow:o,size:l})=>{const s=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",width:r.size+"px"},n?{[n]:0}:{}),"top"===n&&{transform:"rotate(-90deg) translateX(-100%)",transformOrigin:"left top"}),"bottom"===n&&{transform:"rotate(90deg) translateX(-100%)",transformOrigin:"left bottom"}),"left"===n&&{transform:"scaleX(-1)"}),["top","bottom"].includes(n)?{height:l+"px"}:{height:"100%",top:0});return e.createElement("div",{className:`ms-arrow-box ${n}${t?" active":""}`,style:Object.assign({},s),onClick:()=>o(n)},r.element)};u.displayName="Arrow";var d=e.memo(u);function m(e,t){return e>t?Math.floor(e/t):1}function p(e,t=0,r=1/0){return Math.max(t,Math.min(Math.round(e),r))}const f=(e,t,r)=>{if(!t)return;const n=t.querySelectorAll("."+("scroll"===e?"ms-thumb":"ms-slider"));n.length>0&&(r.current=n)},h=e=>e?"start"===e?"flex-start":"center"===e?"center":"flex-end":void 0;function g(e,t,r=0,n=0){return o=>{var l,s,i,c;const a={width:(null!==(l=o.width)&&void 0!==l?l:0)-r,height:(null!==(s=o.height)&&void 0!==s?s:0)-n};(null===(i=e.current)||void 0===i?void 0:i.width)===a.width&&(null===(c=e.current)||void 0===c?void 0:c.height)===a.height||(e.current=a,t())}}function v(t){const r=[],n=t=>{if(null===t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)r.push(t+"");else if("string"==typeof t)r.push(t);else if("function"==typeof t)r.push("<function>");else if(e.isValidElement(t))r.push("<react-node>");else if(Array.isArray(t))t.forEach(n);else if("object"==typeof t){const e=Object.entries(t).sort((([e],[t])=>e.localeCompare(t)));for(const[,t]of e)n(t)}else void 0===t&&r.push("<undefined>")};return n(t),r.join("/")}function y(e){var t,r,n;const o={x:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientX:e.mouseEvent.clientX,y:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientY:e.mouseEvent.clientY,leftover:null!==(r=null===(t=e.prevCoordsRef.current)||void 0===t?void 0:t.leftover)&&void 0!==r?r:0},l=null!==(n=e.prevCoordsRef.current)&&void 0!==n?n:o,s={x:o.x-l.x,y:o.y-l.y};e.prevCoordsRef.current=o;const i=t=>{if(!e.scrollElementRef||!e.objectsWrapperRef)return;let r=0;const n="x"===t?"movementX"in e.mouseEvent?e.mouseEvent.movementX:s.x:"movementY"in e.mouseEvent?e.mouseEvent.movementY:s.y,o=e.scrollElementRef;if("thumb"===e.clicked){const s=e.objectsWrapperRef,i=getComputedStyle(s),c="x"===t?o.clientWidth:o.clientHeight,a="x"===t?s.clientWidth+parseFloat(i.marginLeft)+parseFloat(i.marginRight):s.clientHeight+parseFloat(i.marginTop)+parseFloat(i.marginBottom),u=c-e.thumbSize,d=a-c;if(0>=u||0>=d)return;const m=n*(d/u)+l.leftover,p=Math.trunc(m),f=m-p;e.prevCoordsRef.current.leftover=f,r=p}else r=-n;"x"===t?(o.scrollLeft+=r,e.scrollStateRef.targetScrollX=o.scrollLeft):(o.scrollTop+=r,e.scrollStateRef.targetScrollY=o.scrollTop)},c=t=>{const r=e.objectsWrapperRef;if(!r)return;const n="slider"===e.type&&"wrapp"===e.clicked?-1:1,o=s[t]*n,l="x"===t?e.sizeLocal[0]:e.sizeLocal[1],i="x"===t?r.offsetWidth:r.offsetHeight,c="x"===t?e.scrollElementRef.scrollLeft:e.scrollElementRef.scrollTop;e.numForSliderRef.current+=Math.abs(o),e.numForSliderRef.current>6&&!e.isScrollingRef.current&&(o>0&&i>c+l?e.smoothScroll(c+l,t,e.duration):0>o&&c>0&&e.smoothScroll(c-l,t,e.duration),e.numForSliderRef.current=0)},a=t=>{"thumb"===e.clicked?i(t):"wrapp"===e.clicked?"slider"===e.type?c(t):i(t):"slider"===e.clicked&&c(t)};"hybrid"===e.direction?"wrapp"===e.clicked?(a("x"),a("y")):e.axisFromAtr&&a(e.axisFromAtr):a(e.direction||"y")}function b(e){if(e.controller.abort(),document.body.style.removeProperty("cursor"),["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),e.clickedObject.current="none",e.scrollBarOnHover){let t=e.mouseEvent.target,r=!1;for(;t&&t!==document.body;){if(t===e.scrollContentRef){r=!0;break}t=t.parentNode}r||e.mouseOnRefHandle(e.mouseEvent)}e.prevCoordsRef.current=null,e.triggerUpdate()}const x=e=>{e&&("grab"===e.style.cursor?(e.style.cursor="grabbing",e.classList.add("active")):"grabbing"===e.style.cursor&&(e.style.cursor="grab",e.classList.remove("active")))},E="wrap-id",j=new Map,O=(e,t,r)=>{w(e);const n=setTimeout((()=>{t(),j.delete(e)}),r);j.set(e,n)},w=e=>{const t=j.get(e);t&&(clearTimeout(t),j.delete(e))},R=({type:r="scroll",className:s,size:c,objectsSize:u,direction:w="y",gap:R,wrapperMargin:S,wrapperMinSize:M,progressReverse:k=!1,progressTrigger:T={wheel:!0},scrollBarOnHover:z=!1,suspending:A=!1,fallback:C,scrollPosition:L,edgeGradient:F,children:N,onScrollValue:I,elementsAlign:$,elementsDirection:W="row",wrapperAlign:X,isScrolling:B,render:H,emptyElements:Y,crossCount:q})=>{var P,D,V,_,K,G,U;const J=o((()=>{Mt()}),40),Q=o((()=>{gt()}),34),Z=function(){const t=e.useRef(null);return null===t.current&&(t.current=""+l++),t.current}();if(!c)throw Error(`Prop "size" is not provided\nMorphScroll〈♦${Z}〉`);Object.keys(T).length;const[ee,te]=e.useState(0),re=()=>{te((e=>"number"==typeof e&&1e3>e?e+1:0))},ne=e.useRef(null),oe=e.useRef(null),le=e.useRef(null),se=e.useRef(null),ie=e.useRef([]),ce=e.useRef(null),ae=e.useRef("none"),ue=e.useRef({loaded:[],empty:[]}),de=e.useRef({targetScrollY:0,targetScrollX:0,animating:!1,animationFrameId:0}),me=e.useRef(!1),pe=e.useRef(0),fe=e.useRef(null);function he(){return e.useRef({width:0,height:0})}const ge=he(),ve=he(),ye=he(),[be,xe,Ee,je,Oe,we,Re,Se]=function(...e){return e.map(v)}(null==L?void 0:L.value,H,c,u,Y,M,X,R),Me=e.useMemo((()=>{var e,t;return{value:"number"==typeof(null==L?void 0:L.value)||"string"==typeof(null==L?void 0:L.value)?[L.value,L.value]:null!==(e=null==L?void 0:L.value)&&void 0!==e?e:[null],duration:null!==(t=null==L?void 0:L.duration)&&void 0!==t?t:200}}),[be,null==L?void 0:L.duration]),ke={color:null,size:40},Te=e.useMemo((()=>"object"==typeof F?Object.assign(Object.assign({},ke),F):ke),[F]),ze=e.useMemo((()=>Object.assign(Object.assign({},ke),"object"==typeof T.arrows?T.arrows:{})),[T.arrows]),Ae=e.useCallback((t=>{if(null==t)return[];if(e.isValidElement(t)){const r=t;return r.type===e.Fragment?e.Children.toArray(r.props.children).flatMap(Ae):[r]}return[t]}),[]),Ce=e.useMemo((()=>e.Children.toArray(N).flatMap(Ae).map((t=>e.isValidElement(t)&&t.key?t.key+"":null)).filter((e=>null!==e)).filter((e=>{var t;return"clear"!==(null==Y?void 0:Y.mode)||!(null===(t=ue.current.empty)||void 0===t?void 0:t.includes(e))}))),[N,Oe,null===(P=ue.current.empty)||void 0===P?void 0:P.join()]),[Le,Fe,Ne,Ie]=S?t(S):[0,0,0,0],$e=Le+Ne,We=Ie+Fe,[Xe,Be]=e.useMemo((()=>{var e,t;return"number"==typeof R?[R,R]:Array.isArray(R)?[null!==(e=R[1])&&void 0!==e?e:0,null!==(t=R[0])&&void 0!==t?t:0]:[0,0]}),[R]),He=e.useMemo((()=>t((null==H?void 0:H.rootMargin)||0,"x"===w)),[xe,w]),[Ye,qe]=He?[He[2],He[0]]:[0,0],Pe=e.useMemo((()=>{const[e,t]=Array.isArray(c)?c:"number"==typeof c?[c,c]:[ge.current.width,ge.current.height];if(!T.arrows||!ze.size)return[e,t,e,t];const r=2*ze.size;let n=e,o=t;return"x"===w?n=e-r:"y"===w?o=t-r:"hybrid"===w&&(n=e-r,o=t-r),[n,o,e,t]}),[Ee,ze.size,ge.current]),De="x"===w?Pe[0]:Pe[1],Ve=e.useMemo((()=>u?Array.isArray(u)?u:t(u,!0,2):[null,null]),[je]),_e=e.useMemo((()=>{const e=(e,t)=>"number"==typeof e?e:"firstChild"===e?t:0;return[e(Ve[0]&&"none"!==Ve[0]&&"size"!==Ve[0]?Ve[0]:"y"===w&&"none"!==Ve[0]||"size"===Ve[0]?Pe[0]:0,ye.current.width),e(Ve[1]&&"none"!==Ve[1]&&"size"!==Ve[1]?Ve[1]:"x"===w&&"none"!==Ve[1]||"size"===Ve[1]?Pe[1]:0,ye.current.height)]}),[je,Ee,ye.current,Pe.join()]),Ke=e.useMemo((()=>{const e="x"===w,t="row"===W,r="column"===W,n=e?Pe[1]:Pe[0],o=e?_e[1]+Be:_e[0]+Xe,l="hybrid"===w?o*(Ce.length+1)-o:n,s=Math.floor(l/o)||1,i=q&&s>=q?"hybrid"===w?Math.ceil(s/q):q:s,c=i>1&&i<Ce.length?Math.ceil(Ce.length/i):i>Ce.length?1:Ce.length,a=q&&q<Ce.length,u=e=>Number.isFinite(e)&&e>0?e:1;if("hybrid"===w){const e=a?t?q:i:t?Ce.length:1,n=a?r?q:i:r?Ce.length:1;return[u(e),u(n)]}return[u(i),u(c)]}),[Ce.length,w,_e.join(),Pe.join(),Xe,We,$e,q]),Ge=e.useMemo((()=>{const e=Ke[0]?Ke[0]*Be-Be:0,t="x"===w?Ke[1]:Ke[0];return _e[0]?(_e[0]+Be)*t-Be:(null==H?void 0:H.type)?ye.current.width+e:ve.current.width}),[_e[0],Ke.join(),Be,ve.current.width,ye.current,xe]),Ue=e.useMemo((()=>{const e=1>Ke[1]?1:Ke[0]*Xe-Xe;return _e[1]?"x"===w?(_e[1]+Xe)*Ke[0]-Xe:(_e[1]+Xe)*Ke[1]-Xe:(null==H?void 0:H.type)?ye.current.height+e:ve.current.height}),[_e[1],Ke.join(),Xe,ve.current.height,ye.current,xe]),Je=e.useMemo((()=>Ue+$e),[Ue,$e]),Qe=e.useMemo((()=>Ge+We),[Ge,We]),Ze="x"===w?Qe:Je,et="x"===w?(null===(D=le.current)||void 0===D?void 0:D.scrollLeft)||0:(null===(V=le.current)||void 0===V?void 0:V.scrollTop)||0,tt=et>1&&!0,rt=Ze>Math.round(et+De);let nt=!1,ot=!1;"hybrid"===w&&(nt=((null===(_=le.current)||void 0===_?void 0:_.scrollLeft)||0)>1&&!0,ot=Math.round(((null===(K=le.current)||void 0===K?void 0:K.scrollLeft)||0)+Pe[0])<Qe);const lt=e.useMemo((()=>{if(!T.progressElement||!Ze)return 0;const e=Math.round(De/Ze*De);return!Number.isFinite(e)||0>e?0:e}),[De,Ze,T.progressElement]),st=e.useMemo((()=>{if(!T.progressElement)return 0;const e=Math.round(Pe[0]/Qe*Pe[0]);return!Number.isFinite(e)||0>e?0:e}),[Pe[0],Qe,T.progressElement]),it=e.useMemo((()=>De?Ze-De:Ze),[Ze,De]),ct=e.useMemo((()=>Pe[0]?Qe-Pe[0]:Qe),[Qe,Pe[0]]),at=e.useCallback((()=>{if(!(null==H?void 0:H.type)||1>=Ke[0])return[];const e=Array.from({length:Ce.length},((e,t)=>t)),t=Array.from({length:Ke[0]},(()=>[])),r="x"===w&&"column"===W||"x"!==w&&"row"===W;return e.forEach((e=>{const n=r?e%Ke[0]:Math.floor(e/Ke[1]);t[n]&&t[n].push(e)})),t}),[Ce.length,Ke.join(),xe,W,w]),ut=e.useMemo((()=>{if(!(null==H?void 0:H.type))return[{elementTop:0,elementBottom:0,left:0,right:0}];let e=[],t=0;if($){const r=Array.from({length:Ce.length},((e,t)=>t)),n=Math.abs(Math.floor(Ce.length/Ke[0])*Ke[0]-Ce.length);e=n?r.slice(-n):[],"center"===$?t=(_e[0]+Be)*(Ke[0]-n)/2:"end"===$&&(t=(_e[0]+Be)*(Ke[0]-n))}return Ce.map(((r,n)=>{const o=function(e,t){for(let r=0;r<t.length;r++){const n=t[r].indexOf(e);if(-1!==n)return["x"===w?n:r,["hybrid","y"].includes(w)?n:r]}return[0,0]}(n,at()),l=e.length>0&&e.includes(n)?t:0,s=function(e){const t="x"===w?l:0;return e>0?t+(_e[1]+Xe)*e:t}(Ke[0]>1||["hybrid","x"].includes(w)?o[1]:n),i=_e[1]?s+_e[1]:s,c=function(e){const t="x"===w?0:l;return e>0?t+(_e[0]+Be)*e:t}(1===Ke[0]&&"x"===w?n:o[0]);return{elementTop:s,elementBottom:i,left:c,right:c+_e[0]}}))}),[N,_e.join(),R,xe,Ke[0],W]),dt=e.useMemo((()=>(null==Pe?void 0:Pe.length)&&X?function(e,t,r,n){const[o,l="start"]="string"==typeof e?[e,e]:e,s={display:"flex"};return t[0]>r&&(s.justifyContent=h(o)),t[1]>n&&(s.alignItems=h(l)),s}(X,Pe,Qe,Je):{}),[X,Pe.join(),Je,Qe]),mt=e.useMemo((()=>[m(Qe,Pe[0]),m(Je,Pe[1])]),[Qe,Je,Pe.join()]),pt=e.useMemo((()=>"x"===w?mt[0]:mt[1]),[w,mt[0],mt[1]]),ft=e.useCallback((e=>{if(!z)return;const t=()=>((e,t,r,n)=>{e&&e.querySelectorAll(".ms-bar").forEach(((e,t)=>{const o=e;["mouseleave","mouseup","touchend"].includes(r.type)?(o.style.opacity="0",o.classList.remove("hover"),o.classList.add("leave"),n(`mouseOnRef${t}-anim`,(()=>o.classList.remove("leave")),200)):(o.style.opacity="1",o.classList.add("hover"))}))})(oe.current,0,e,O);"mouseleave"===e.type?!["thumb","slider","wrapp"].includes(ae.current)&&t():t()}),[z,r,ae.current,oe.current]),ht=e.useCallback((e=>{le.current&&(({arrowType:e,scrollElement:t,wrapSize:r,scrollSize:n,smoothScroll:o,duration:l})=>{const s=r[0],i=r[1],c=t.scrollTop,a=t.scrollLeft,u=["top","bottom"].includes(e)?i:s,d=(e,t)=>o(p(e,0,u),t,l);"top"===e&&c>0?d(c-n[1],"y"):"left"===e&&a>0&&d(a-n[0],"x"),"bottom"===e&&c+n[1]!==i?d(c+n[1],"y"):"right"===e&&a+n[0]!==s&&d(a+n[0],"x")})({arrowType:e,scrollElement:le.current,wrapSize:[Qe,Je],scrollSize:Pe,smoothScroll:Ot,duration:Me.duration})}),[le.current,Pe.join(),Qe,Je,Me.duration]),gt=e.useCallback((()=>{f(r,ne.current,ie);const e=le.current;oe.current&&e&&0!==ie.current.length&&((e,t,r,n)=>{!function(){var o,l,s,i;const c=null!==(l=null===(o=t[0])||void 0===o?void 0:o.querySelectorAll(".ms-slider-element"))&&void 0!==l?l:[],a=null!==(i=null===(s=t[1])||void 0===s?void 0:s.querySelectorAll(".ms-slider-element"))&&void 0!==i?i:[];function u(e,t,r,n){const o="x"===n?r.scrollLeft:r.scrollTop;e.forEach(((e,r)=>{const l="x"===n?t[0]:t[1];o>=l*r&&l*(r+1)>o?e.classList.add("active"):e.classList.remove("active")}))}c.length>0&&u(c,r,e,n),a.length>0&&u(a,r,e,"x")}()})(e,ie.current,Pe,w)}),[Pe.join(),w,le,oe,ie,r]),vt=e.useCallback((()=>{const e=le.current;e&&(null==I||I(e.scrollLeft,e.scrollTop),me.current=!0,null==B||B(!0),O("handleScroll-anim",(()=>{me.current=!1,null==B||B(!1),(null==H?void 0:H.type)?re():J()}),200),"slider"===r&&Q(),(null==H?void 0:H.type)||J(),re())}),[w,I,B,xe,r,Q]),yt=p(et/it*(De-lt),0,De-lt),bt=p(((null===(G=le.current)||void 0===G?void 0:G.scrollLeft)||0)/ct*(Pe[0]-Pe[0]/Qe*Pe[0]),0,Pe[0]-st),xt=o(g(ge,re),40),Et=o(g(ve,re,We,$e),40),jt=o(g(ye,re),40),Ot=e.useCallback(((e,t,r,n)=>{const o=le.current;return o?function(e,t,r,n,o){let l;if(!t&&!n)return null;const s=performance.now(),i=t.scrollTop,c=t.scrollLeft,a=u=>{const d=Math.min((u-s)/r,1);"y"===e?t.scrollTop=i+(n-i)*d:"x"===e&&(t.scrollLeft=c+(n-c)*d),1>d?l=requestAnimationFrame(a):null==o||o()};return l=requestAnimationFrame(a),()=>cancelAnimationFrame(l)}(t,o,r,e,n):null}),[le]),wt=e.useCallback(((e,t="mousedown",n)=>{const o=e||("scroll"===r?"thumb":"slider");if("wrapp"===e&&!T.content||["thumb","slider"].includes(o)&&!T.progressElement)return;f(r,ne.current,ie);let l=null;n&&(l=n.getAttribute("data-direction")),function(e){const t=new AbortController,{signal:r}=t;e.clickedObject.current=e.clicked,e.triggerUpdate(),"mousedown"===e.eventType?(["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),document.addEventListener("mousemove",(t=>y(Object.assign(Object.assign({},e),{mouseEvent:t}))),{signal:r}),document.addEventListener("mouseup",(r=>b(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})):"touchstart"===e.eventType&&(document.addEventListener("touchmove",(t=>{t.preventDefault(),y(Object.assign(Object.assign({},e),{mouseEvent:t}))}),{signal:r,passive:!1}),document.addEventListener("touchend",(r=>b(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})),document.body.style.cursor="grabbing"}({eventType:t,scrollElementRef:le.current,objectsWrapperRef:se.current,scrollBar:n||null,clickedObject:ae,scrollContentRef:oe.current,scrollStateRef:de.current,type:r,scrollBarOnHover:z,mouseOnEl:x,mouseOnRefHandle:ft,triggerUpdate:re,direction:w,smoothScroll:Ot,sizeLocal:[Pe[0],Pe[1]],clicked:o,numForSliderRef:pe,isScrollingRef:me,prevCoordsRef:fe,thumbSize:"x"===l?st:lt,axisFromAtr:l,duration:Me.duration})}),[r,T.content,T.progressElement,Pe.join(),lt,st,Me.duration]),Rt=e.useCallback((e=>{wt(null,e.type,e.target)}),[wt]),St=e.useCallback((()=>{wt("wrapp")}),[wt]),Mt=e.useCallback((()=>{ne.current&&((e,t,r,n)=>{const{allIds:o,emptyKeysRaw:l}=(()=>{const t=[],r=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e instanceof Element&&e.hasAttribute(E)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let o=n.nextNode();for(;o;){const e=o,l=e.getAttribute(E);l&&(t.push(l),0===e.children.length&&r.push(l)),o=n.nextNode()}return{allIds:t,emptyKeysRaw:r}})(),s=new Set(t.current.loaded);o.forEach((e=>s.add(e)));let i=null;if(t.current.empty){const e=new Set(t.current.empty);l.forEach((t=>e.add(t))),i=Array.from(e)}t.current={loaded:"lazy"===n?Array.from(s):o.map((e=>e)),empty:i},r()})(ne.current,ue,re,null==H?void 0:H.type)}),[xe]),kt=e.useCallback((e=>{(null==Y?void 0:Y.clickTrigger)&&((e,t,r,n)=>{e.target.closest(r.selector)&&t("emptyKeys-anim",(()=>{n()}),r.delay||0)})(e,O,Y.clickTrigger,Mt)}),[Oe]),Tt=e.useCallback(((e,t,r)=>{if(ce.current){if(ce.current!==Ce[0])return void(ce.current=Ce[0])}else ce.current=Ce[0];const n=Ot(t,e,Me.duration);n&&r.push(n)}),[Ce[0],Me.duration]),zt=e.useMemo((()=>{const e=Object.assign(Object.assign(Object.assign(Object.assign({margin:S?`${Le}px ${Fe}px ${Ne}px ${Ie}px`:"",height:Ve[1]&&"none"!==Ve[1]?Ue+"px":"fit-content",width:Ve[0]&&"none"!==Ve[0]?Ge+"px":"fit-content"},T.content&&{cursor:"grab"}),R&&!(null==H?void 0:H.type)&&{gap:`${Xe}px ${Be}px`}),M&&function(e,t,r,n,o){const l=(e,t)=>"full"===e?("x"===t?r[0]:r[1])-("x"===t?n:o):e;if("hybrid"!==t&&!Array.isArray(e)){const r=l(e,t)+"px";return"x"===t?{minWidth:r}:{minHeight:r}}let s,i;return Array.isArray(e)?[s,i]=e:s=i=e,{minWidth:l(s,"x")+"px",minHeight:l(i,"y")+"px"}}(M,w,Pe,We,$e)),X&&{flexShrink:0});if(null==H?void 0:H.type)return Object.assign(Object.assign({},e),{position:"relative"});const t=Ve[1]?"wrap":void 0,r=1===Ke[0]?"y"===w?"column":"row":W;return Object.assign(Object.assign({},e),{display:"flex",flexDirection:r,flexWrap:t,justifyContent:h($)})}),[S,[Le,Fe,Ne,Ie,We,$e].join(),Ve[1],Ue,Ge,T.content,Se,[Xe,Be].join(),null==H?void 0:H.type,we,w,Pe.join(),Re,Ke[0],W,$]);e.useEffect((()=>{(Y||(null==H?void 0:H.type))&&(Y||null===ue.current.empty||(ue.current.empty=null),J())}),[Oe,null==H?void 0:H.type,xe,me.current,Ce.length]),e.useEffect((()=>(((null==H?void 0:H.type)||B)&&(B&&B(!1),re()),gt(),()=>{de.current.animationFrameId&&cancelAnimationFrame(de.current.animationFrameId),(()=>{for(const e of j.values())clearTimeout(e);j.clear()})()})),[]),e.useEffect((()=>{const e=le.current;if(!e)return;const t=T.wheel?t=>function(e,t,r,n){e.preventDefault(),r.animating||(r.targetScrollX=t.scrollLeft,r.targetScrollY=t.scrollTop),"x"===n?r.targetScrollX=p(r.targetScrollX+e.deltaY,0,t.scrollWidth-t.clientWidth+2):r.targetScrollY=p(r.targetScrollY+e.deltaY,0,t.scrollHeight-t.clientHeight+2),r.animating||(r.animating=!0,r.animationFrameId=requestAnimationFrame((function e(){let o=0;"x"===n?(t.scrollLeft+=.4*(r.targetScrollX-t.scrollLeft),o=Math.abs(t.scrollLeft-r.targetScrollX)):(t.scrollTop+=.4*(r.targetScrollY-t.scrollTop),o=Math.abs(t.scrollTop-r.targetScrollY)),o>2.5?r.animationFrameId=requestAnimationFrame(e):(r.animating=!1,null!==r.animationFrameId&&(cancelAnimationFrame(r.animationFrameId),r.animationFrameId=null))})))}(t,e,de.current,w):e=>e.preventDefault();return e.addEventListener("wheel",t,{passive:!1}),()=>{e.removeEventListener("wheel",t)}}),[w,T.wheel]),e.useEffect((()=>{if(!Me.value)return;const e=[];return("hybrid"===w?["x","y"]:[w]).forEach((t=>{const r="x"===t?0:1;"end"===Me.value[r]&&Tt(t,"x"===t?ct:it,e)})),()=>{e.forEach((e=>e()))}}),[Me.value.join(),be,it,ct,Qe,Je]),e.useEffect((()=>{if(!Me.value)return;const e=[];return("hybrid"===w?["x","y"]:[w]).forEach((t=>{const r="x"===t?0:1;"number"==typeof Me.value[r]&&Tt(t,Me.value[r],e)})),()=>{e.forEach((e=>e()))}}),[be,null==L?void 0:L.updater]);const At=e.useCallback(((t,r,n,o)=>{var l;const s=Object.assign({width:_e[0]?_e[0]+"px":void 0,height:_e[1]?_e[1]+"px":void 0},(null==H?void 0:H.type)&&Object.assign({position:"absolute",top:r+"px",left:n+"px"},!_e[0]&&1===Ke[0]&&{transform:"translateX(-50%)"})),i=A?e.createElement(e.Suspense,{fallback:C},o):o,c=(null===(l=null==Y?void 0:Y.clickTrigger)||void 0===l?void 0:l.selector)&&kt;return e.createElement("div",Object.assign({key:t},H||Y?{[E]:""+t}:{},{className:"ms-object-box",style:s,onClick:c}),i)}),[A,!!C,_e.join(),le.current,xe,Oe,Ke[0]]),Ct=e.createElement("div",{className:"ms-objects-wrapper",ref:se,onMouseDown:St,style:zt},Ce.map(((t,r)=>{var o,l,s;const i=e.Children.toArray(N).find((r=>e.isValidElement(r)&&r.key===t)),c=(null==H?void 0:H.stopLoadOnScroll)&&me.current&&!ue.current.loaded.includes(""+t)?C:(null===(o=ue.current.empty)||void 0===o?void 0:o.includes(t))?"object"==typeof(null==Y?void 0:Y.mode)?Y.mode.fallback:C:i,a="number"==typeof Ve[0]&&"number"==typeof Ve[1]||"firstChild"!==Ve[0]&&"firstChild"!==Ve[1]||0!==r?c:e.createElement(n,{onResize:jt},c);if(!(null==H?void 0:H.type))return At(t,0,0,a);{const{elementTop:e,elementBottom:n,left:o,right:i}=ut[r],c="x"===w?Ye:qe,u=De+c>("x"===w?o:e)-et&&("x"===w?i:n)-et>0-c,d="hybrid"!==w||Pe[0]+Ye>o-((null===(l=le.current)||void 0===l?void 0:l.scrollLeft)||0)&&i-((null===(s=le.current)||void 0===s?void 0:s.scrollLeft)||0)>0-Ye;if(u&&d)return At(t,e,o,a)}}))),Lt=[{positionType:"x"===w?"left":"top",visibility:tt},{positionType:"x"===w?"right":"bottom",visibility:rt},..."hybrid"===w?[{positionType:"left",visibility:nt},{positionType:"right",visibility:ot}]:[]],Ft=e.createElement("div",{"morph-scroll":`〈♦${Z}〉`,className:s,ref:ne,style:{width:Pe[2]+"px",height:Pe[3]+"px"}},e.createElement("div",{className:"ms-content",ref:oe,onMouseEnter:ft,onMouseLeave:ft,onTouchStart:ft,onTouchEnd:ft,style:Object.assign({position:"relative",width:Pe[0]+"px",height:Pe[1]+"px"},T.arrows&&ze.size&&("x"===w?{left:ze.size+"px"}:"y"===w?{top:ze.size+"px"}:{top:ze.size+"px",left:ze.size+"px"}))},e.createElement("div",{className:"ms-element",ref:le,onScroll:vt,style:Object.assign(Object.assign(Object.assign({width:"100%",height:"100%"},dt),{overflow:null!==(U={x:Qe>Pe[0]?"scroll hidden":"hidden",y:Je>Pe[1]?"hidden scroll":"hidden",hybrid:`${Qe>Pe[0]?"scroll":"hidden"} ${Je>Pe[1]?"scroll":"hidden"}`,hide:"hidden"}[T.wheel||T.content?w:"hide"])&&void 0!==U?U:"hidden"}),"scroll"!==r||"boolean"!=typeof T.progressElement||!1===T.progressElement?{scrollbarWidth:"none"}:{})},_e[0]&&_e[1]?Ct:e.createElement(n,{onResize:Et,style:Object.assign({},dt)},Ct)),F&&Lt.map((({positionType:t,visibility:r})=>e.createElement(a,{key:"edge-"+t,edgeGradient:Te,visibility:r,edgeType:t}))),T.progressElement&&!0!==T.progressElement&&[{shouldRender:Ze>lt,direction:w,thumbSize:lt,thumbSpace:yt,objLengthPerSize:pt,progressReverseIndex:0},{shouldRender:"hybrid"===w&&Qe>st,direction:"x",thumbSize:st,thumbSpace:bt,objLengthPerSize:mt[0],progressReverseIndex:1}].filter((({shouldRender:e})=>e)).map((t=>e.createElement(i,{key:t.direction,type:r,direction:t.direction,progressReverse:"boolean"==typeof k?k:k[t.progressReverseIndex],size:Pe,progressTrigger:T,scrollBarOnHover:z,scrollBarEvent:"sliderMenu"===r?Ot:Rt,thumbSize:t.thumbSize,thumbSpace:t.thumbSpace,objLengthPerSize:t.objLengthPerSize,sliderCheckLocal:gt,duration:Me.duration})))),T.arrows&&Lt.map((({positionType:t,visibility:r})=>e.createElement(d,{key:"arrow-"+t,activity:r,arrows:ze,arrowType:t,handleArrow:ht,size:"hybrid"===w?Pe[0]+2*ze.size:Pe[0]}))));return"auto"===c?e.createElement(n,{measure:"outer",onResize:xt},Ft):Ft};R.displayName="MorphScroll";const S={MorphScroll:R,ResizeTracker:n,IntersectionTracker:r};exports.IntersectionTracker=r,exports.MorphScroll=R,exports.ResizeTracker=n,exports.default=S;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");const t=(e,t=!1,r)=>{let n=[];if(n=Array.isArray(e)?2===e.length?[e[1],e[0],e[1],e[0]]:[...e]:[e,e,e,e],t&&(n=[n[1],n[0],n[3],n[2]]),r){const e=[];for(let t=0;r>t;t++)e.push(n[t%4]);n=e}return n},r=({className:r,children:n,style:o,root:l,threshold:s,rootMargin:i,visibleContent:c=!1,onIntersection:a})=>{const[u,d]=e.useState(!1),m=e.useRef(null),p=e.useMemo((()=>{if(!i)return"";const e=t(i);return`${e[0]}px ${e[1]}px ${e[2]}px ${e[3]}px`}),[i]),h=e.useCallback((([e])=>{d(e.isIntersecting),a&&a({time:e.time,rootBounds:e.rootBounds,boundingClientRect:e.boundingClientRect,intersectionRect:e.intersectionRect,isIntersecting:e.isIntersecting,intersectionRatio:e.intersectionRatio,target:e.target})}),[a]);return e.useEffect((()=>{const e=new IntersectionObserver(h,{root:l,threshold:s,rootMargin:p});return m.current&&e.observe(m.current),()=>{e.disconnect()}}),[h,l,s,p]),e.createElement("div",{"intersection-tracker":"",className:r,ref:m,style:o},c||u?n:null)};r.displayName="IntersectionTracker";const n=({className:t,children:r,style:n,measure:o="inner",onResize:l})=>{const s=e.useRef(null);e.useEffect((()=>{const e=s.current;if(!e)return;const t=new ResizeObserver((e=>{for(const t of e)l&&l(t.contentRect)}));return t.observe(e),()=>{t.unobserve(e),t.disconnect()}}),[o,l]);const i={width:"max-content",height:"max-content"},c={inner:Object.assign({},i),outer:Object.assign({},{width:"100%",height:"100%"}),all:Object.assign({minWidth:"100%",minHeight:"100%"},i)};return e.createElement("div",{"resize-tracker":"",className:t,ref:s,style:Object.assign(Object.assign({willChange:"width, height"},c[o]),n)},r)};function o(t,r){const n=e.useMemo((()=>function(e,t){let r=null,n=null;const o=(...o)=>{"requestFrame"===t?(null!==n&&cancelAnimationFrame(n),n=requestAnimationFrame((()=>{e(...o),n=null}))):(null!==r&&clearTimeout(r),r=setTimeout((()=>{e(...o),r=null}),t))};return o.cancel=()=>{null!==r&&(clearTimeout(r),r=null),null!==n&&(cancelAnimationFrame(n),n=null)},o}(t,r)),[r,t]);return e.useEffect((()=>()=>{n.cancel()}),[n]),n}n.displayName="ResizeTracker";let l=1;const s=({type:t,direction:r,progressReverse:n,size:o,progressTrigger:l,scrollBarOnHover:s,scrollBarEvent:i,thumbSize:c,thumbSpace:a,objLengthPerSize:u,sliderCheckLocal:d,duration:m})=>{const p="sliderMenu"!==t?{onMouseDown:i,onTouchStart:i}:{},h=e.useMemo((()=>{if("scroll"===t||!r)return;const n=["hybrid","y"].includes(r)?"y":"x",s="x"===n?o[0]:o[1];return Array.from({length:u},((r,o)=>e.createElement("div",{key:o,className:"ms-slider-element",style:Object.assign({},"sliderMenu"===t&&{cursor:"pointer"}),onClick:"sliderMenu"===t?()=>{i(s*o,n,m,d)}:void 0},Array.isArray(null==l?void 0:l.progressElement)?l.progressElement[o]:null==l?void 0:l.progressElement)))}),[u,r,o,t,i,null==l?void 0:l.progressElement,m,d]);return e.createElement(e.Fragment,null,"scroll"===t?e.createElement("div",{className:"ms-bar",style:Object.assign(Object.assign(Object.assign({position:"absolute",width:"fit-content"},"x"===r?Object.assign({transformOrigin:"left top",height:o[0]+"px"},n?{top:0,transform:"rotate(-90deg) translateX(-100%)"}:{transform:"rotate(-90deg)"}):Object.assign({top:0,height:"100%"},n?{left:0}:{right:0})),0!=!(null==l?void 0:l.progressElement)&&{pointerEvents:"none"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"})},e.createElement("div",Object.assign({className:"ms-thumb","data-direction":["hybrid","y"].includes(r)?"y":r},p,{style:Object.assign(Object.assign({height:c+"px",willChange:"transform, height",transform:`translateY(${a}px)`},(null==l?void 0:l.progressElement)&&{cursor:"grab"}),{transition:"height 0.05s ease-in-out"})}),null==l?void 0:l.progressElement)):u>1&&(null==l?void 0:l.progressElement)&&e.createElement("div",Object.assign({className:"ms-slider","data-direction":["hybrid","y"].includes(r)?"y":r},p,{style:Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex"},"slider"===t&&{cursor:"grab"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"}),"x"===r?Object.assign({transformOrigin:"left top",left:"50%",transform:"translateX(-50%)"},n?{top:0}:{bottom:0}):Object.assign({flexDirection:"column",top:"50%",transform:"translateY(-50%)"},n?{left:0}:{right:0}))}),h))};s.displayName="ScrollBar";var i=e.memo(s);const c=({edgeGradient:t,visibility:r,edgeType:n})=>{if(!t)return null;const o=Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",pointerEvents:"none",transition:"opacity 0.1s ease-in-out"},t.color&&{background:t.color&&`linear-gradient(${"right"===n||"left"===n?"90deg, ":""}${t.color}, transparent)`}),"right"===n||"left"===n?{height:"100%",width:t.size+"px",top:0}:{width:"100%",height:t.size+"px",left:0}),n?{[n]:0}:{}),"right"===n?{transform:"scaleX(-1)"}:"bottom"===n?{transform:"scaleY(-1)"}:{});return e.createElement("div",{className:"ms-edge"+(n?" "+n:""),style:Object.assign(Object.assign({},o),{opacity:r?1:0})})};c.displayName="Edge";var a=e.memo(c);const u=({activity:t,arrows:r,arrowType:n,handleArrow:o,size:l})=>{const s=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",width:r.size+"px"},n?{[n]:0}:{}),"top"===n&&{transform:"rotate(-90deg) translateX(-100%)",transformOrigin:"left top"}),"bottom"===n&&{transform:"rotate(90deg) translateX(-100%)",transformOrigin:"left bottom"}),"left"===n&&{transform:"scaleX(-1)"}),["top","bottom"].includes(n)?{height:l+"px"}:{height:"100%",top:0});return e.createElement("div",{className:`ms-arrow-box ${n}${t?" active":""}`,style:Object.assign({},s),onClick:()=>o(n)},r.element)};u.displayName="Arrow";var d=e.memo(u);function m(e,t){return e>t?Math.floor(e/t):1}function p(e,t=0,r=1/0){return Math.max(t,Math.min(Math.round(e),r))}const h=(e,t,r)=>{if(!t)return;const n=t.querySelectorAll("."+("scroll"===e?"ms-thumb":"ms-slider"));n.length>0&&(r.current=n)},f=e=>e?"start"===e?"flex-start":"center"===e?"center":"flex-end":void 0;function g(e,t,r=0,n=0){return o=>{var l,s,i,c;const a={width:(null!==(l=o.width)&&void 0!==l?l:0)-r,height:(null!==(s=o.height)&&void 0!==s?s:0)-n};(null===(i=e.current)||void 0===i?void 0:i.width)===a.width&&(null===(c=e.current)||void 0===c?void 0:c.height)===a.height||(e.current=a,t())}}function y(t){const r=[],n=t=>{if(null===t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)r.push(t+"");else if("string"==typeof t)r.push(t);else if("function"==typeof t)r.push("<function>");else if(e.isValidElement(t))r.push("<react-node>");else if(Array.isArray(t))t.forEach(n);else if("object"==typeof t){const e=Object.entries(t).sort((([e],[t])=>e.localeCompare(t)));for(const[,t]of e)n(t)}else void 0===t&&r.push("<undefined>")};return n(t),r.join("/")}function v(e){var t,r,n;const o={x:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientX:e.mouseEvent.clientX,y:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientY:e.mouseEvent.clientY,leftover:null!==(r=null===(t=e.prevCoordsRef.current)||void 0===t?void 0:t.leftover)&&void 0!==r?r:0},l=null!==(n=e.prevCoordsRef.current)&&void 0!==n?n:o,s={x:o.x-l.x,y:o.y-l.y};e.prevCoordsRef.current=o;const i=t=>{if(!e.scrollElementRef||!e.objectsWrapperRef)return;let r=0;const n="x"===t?"movementX"in e.mouseEvent?e.mouseEvent.movementX:s.x:"movementY"in e.mouseEvent?e.mouseEvent.movementY:s.y,o=e.scrollElementRef;if("thumb"===e.clicked){const s=e.objectsWrapperRef,i=getComputedStyle(s),c="x"===t?o.clientWidth:o.clientHeight,a="x"===t?s.clientWidth+parseFloat(i.marginLeft)+parseFloat(i.marginRight):s.clientHeight+parseFloat(i.marginTop)+parseFloat(i.marginBottom),u=c-e.thumbSize,d=a-c;if(0>=u||0>=d)return;const m=n*(d/u)+l.leftover,p=Math.trunc(m),h=m-p;e.prevCoordsRef.current.leftover=h,r=p}else r=-n;"x"===t?(o.scrollLeft+=r,e.scrollStateRef.targetScrollX=o.scrollLeft):(o.scrollTop+=r,e.scrollStateRef.targetScrollY=o.scrollTop)},c=t=>{const r=e.objectsWrapperRef;if(!r)return;const n="slider"===e.type&&"wrapp"===e.clicked?-1:1,o=s[t]*n,l="x"===t?e.sizeLocal[0]:e.sizeLocal[1],i="x"===t?r.offsetWidth:r.offsetHeight,c="x"===t?e.scrollElementRef.scrollLeft:e.scrollElementRef.scrollTop;e.numForSliderRef.current+=Math.abs(o),e.numForSliderRef.current>6&&!e.isScrollingRef.current&&(o>0&&i>c+l?e.smoothScroll(c+l,t,e.duration):0>o&&c>0&&e.smoothScroll(c-l,t,e.duration),e.numForSliderRef.current=0)},a=t=>{"thumb"===e.clicked?i(t):"wrapp"===e.clicked?"slider"===e.type?c(t):i(t):"slider"===e.clicked&&c(t)};"hybrid"===e.direction?"wrapp"===e.clicked?(a("x"),a("y")):e.axisFromAtr&&a(e.axisFromAtr):a(e.direction||"y")}function b(e){if(e.controller.abort(),document.body.style.removeProperty("cursor"),["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),e.clickedObject.current="none",e.scrollBarOnHover){let t=e.mouseEvent.target,r=!1;for(;t&&t!==document.body;){if(t===e.scrollContentRef){r=!0;break}t=t.parentNode}r||e.mouseOnRefHandle(e.mouseEvent)}e.prevCoordsRef.current=null,e.triggerUpdate()}const x=e=>{e&&("grab"===e.style.cursor?(e.style.cursor="grabbing",e.classList.add("active")):"grabbing"===e.style.cursor&&(e.style.cursor="grab",e.classList.remove("active")))},E="wrap-id",j=new Map,w=(e,t,r)=>{O(e);const n=setTimeout((()=>{t(),j.delete(e)}),r);j.set(e,n)},O=e=>{const t=j.get(e);t&&(clearTimeout(t),j.delete(e))},S=({className:r,children:s,type:c="scroll",direction:u="y",scrollPosition:O,onScrollValue:S,isScrolling:R,size:M,objectsSize:k,crossCount:T,gap:z,wrapperMargin:A,wrapperMinSize:C,wrapperAlign:L,elementsAlign:F,elementsDirection:N="row",edgeGradient:I,progressTrigger:$={wheel:!0},progressReverse:X=!1,scrollBarOnHover:W=!1,render:B,emptyElements:H,suspending:Y=!1,fallback:P})=>{var q,D,K,V,_,U;const G=o((()=>{kt()}),40),J=o((()=>{Mt()}),34),Q=function(){const t=e.useRef(null);return null===t.current&&(t.current=""+l++),t.current}();if(!M)throw Error(`Prop "size" is not provided\nMorphScroll〈♦${Q}〉`);Object.keys($).length;const[Z,ee]=e.useState(0),te=()=>{ee((e=>"number"==typeof e&&1e3>e?e+1:0))},re=e.useRef(null),ne=e.useRef(null),oe=e.useRef(null),le=e.useRef(null),se=e.useRef([]),ie=e.useRef(null),ce=e.useRef("none"),ae=e.useRef({loaded:[],empty:[]}),ue=e.useRef({targetScrollY:0,targetScrollX:0,animating:!1,animationFrameId:0}),de=e.useRef(!1),me=e.useRef(0),pe=e.useRef(null),he=e.useRef(!1);function fe(){return e.useRef({width:0,height:0})}const ge=fe(),ye=fe(),ve=fe(),[be,xe,Ee,je,we,Oe,Se,Re,Me,ke]=function(...e){return e.map(y)}(null==O?void 0:O.value,B,M,k,H,C,L,z,$,ae.current.empty),Te=e.useMemo((()=>{var e,t;return{value:"number"==typeof(null==O?void 0:O.value)||"string"==typeof(null==O?void 0:O.value)?[O.value,O.value]:null!==(e=null==O?void 0:O.value)&&void 0!==e?e:[null],duration:null!==(t=null==O?void 0:O.duration)&&void 0!==t?t:200}}),[be,null==O?void 0:O.duration]),ze={color:null,size:40},Ae=e.useMemo((()=>"object"==typeof I?Object.assign(Object.assign({},ze),I):ze),[I]),Ce=e.useMemo((()=>Object.assign(Object.assign({},ze),"object"==typeof $.arrows?$.arrows:{})),[Me]),Le=e.useCallback((t=>{if(null==t)return[];if(e.isValidElement(t)){const r=t;return r.type===e.Fragment?e.Children.toArray(r.props.children).flatMap(Le):[r]}return[t]}),[]),Fe=e.useMemo((()=>e.Children.toArray(s).flatMap(Le).map((t=>e.isValidElement(t)&&t.key?t.key+"":null)).filter((e=>null!==e)).filter((e=>{var t;return"clear"!==(null==H?void 0:H.mode)||!(null===(t=ae.current.empty)||void 0===t?void 0:t.includes(e))}))),[s,Le,we,ke]),[Ne,Ie,$e,Xe]=A?t(A):[0,0,0,0],We=Ne+$e,Be=Xe+Ie,[He,Ye]=e.useMemo((()=>{var e,t;return"number"==typeof z?[z,z]:Array.isArray(z)?[null!==(e=z[1])&&void 0!==e?e:0,null!==(t=z[0])&&void 0!==t?t:0]:[0,0]}),[z]),Pe=e.useMemo((()=>t((null==B?void 0:B.rootMargin)||0,"x"===u)),[xe,u]),[qe,De]=Pe?[Pe[2],Pe[0]]:[0,0],Ke=e.useMemo((()=>{const[e,t]=Array.isArray(M)?M:"number"==typeof M?[M,M]:[ge.current.width,ge.current.height];if(!$.arrows||!Ce.size)return[e,t,e,t];const r=2*Ce.size;let n=e,o=t;return"x"===u?n=e-r:"y"===u?o=t-r:"hybrid"===u&&(n=e-r,o=t-r),[n,o,e,t]}),[Ee,Me,u,Ce.size,ge.current.height,ge.current.width]),Ve="x"===u?Ke[0]:Ke[1],_e=e.useMemo((()=>k?Array.isArray(k)?k:t(k,!0,2):[null,null]),[je]),Ue=e.useMemo((()=>{const e=(e,t)=>"number"==typeof e?e:"firstChild"===e?t:0;return[e(_e[0]&&"none"!==_e[0]&&"size"!==_e[0]?_e[0]:"y"===u&&"none"!==_e[0]||"size"===_e[0]?Ke[0]:0,ve.current.width),e(_e[1]&&"none"!==_e[1]&&"size"!==_e[1]?_e[1]:"x"===u&&"none"!==_e[1]||"size"===_e[1]?Ke[1]:0,ve.current.height)]}),[_e,u,ve.current.width,ve.current.height,Ke.join()]),Ge=e.useMemo((()=>{const e="x"===u,t="row"===N,r="column"===N,n=e?Ke[1]:Ke[0],o=e?Ue[1]+Ye:Ue[0]+He,l="hybrid"===u?o*(Fe.length+1)-o:n,s=Math.floor(l/o)||1,i=T&&s>=T?"hybrid"===u?Math.ceil(s/T):T:s,c=i>1&&i<Fe.length?Math.ceil(Fe.length/i):i>Fe.length?1:Fe.length,a=T&&T<Fe.length,d=e=>Number.isFinite(e)&&e>0?e:1;if("hybrid"===u){const e=a?t?T:i:t?Fe.length:1,n=a?r?T:i:r?Fe.length:1;return[d(e),d(n)]}return[d(i),d(c)]}),[N,Ye,He,Ue.join(),Fe.length,u,Ke.join(),T]),Je=e.useMemo((()=>{const e=Ge[0]?Ge[0]*Ye-Ye:0,t="x"===u?Ge[1]:Ge[0];return Ue[0]?(Ue[0]+Ye)*t-Ye:(null==B?void 0:B.type)?ve.current.width+e:ye.current.width}),[u,Ue[0],Ge.join(),Ye,ye.current.width,ve.current.width,null==B?void 0:B.type]),Qe=e.useMemo((()=>{const e=1>Ge[1]?1:Ge[0]*He-He;return Ue[1]?"x"===u?(Ue[1]+He)*Ge[0]-He:(Ue[1]+He)*Ge[1]-He:(null==B?void 0:B.type)?ve.current.height+e:ye.current.height}),[u,Ue[1],Ge.join(),He,ye.current.height,ve.current.height,null==B?void 0:B.type]),Ze=e.useMemo((()=>Qe+We),[Qe,We]),et=e.useMemo((()=>Je+Be),[Je,Be]),tt="x"===u?et:Ze,rt="x"===u?(null===(q=oe.current)||void 0===q?void 0:q.scrollLeft)||0:(null===(D=oe.current)||void 0===D?void 0:D.scrollTop)||0,nt=rt>1&&!0,ot=tt>Math.round(rt+Ve);let lt=!1,st=!1;"hybrid"===u&&(lt=((null===(K=oe.current)||void 0===K?void 0:K.scrollLeft)||0)>1&&!0,st=Math.round(((null===(V=oe.current)||void 0===V?void 0:V.scrollLeft)||0)+Ke[0])<et);const it=e.useMemo((()=>{if(!$.progressElement||!tt)return 0;const e=Math.round(Ve/tt*Ve);return!Number.isFinite(e)||0>e?0:e}),[Ve,tt,$.progressElement]),ct=e.useMemo((()=>{if(!$.progressElement)return 0;const e=Math.round(Ke[0]/et*Ke[0]);return!Number.isFinite(e)||0>e?0:e}),[Ke[0],et,$.progressElement]),at=e.useMemo((()=>Ve?tt-Ve:tt),[tt,Ve]),ut=e.useMemo((()=>Ke[0]?et-Ke[0]:et),[et,Ke[0]]),dt=e.useCallback((()=>{if(!(null==B?void 0:B.type)||1>=Ge[0])return[];const e=Array.from({length:Fe.length},((e,t)=>t)),t=Array.from({length:Ge[0]},(()=>[])),r="x"===u&&"column"===N||"x"!==u&&"row"===N;return e.forEach((e=>{const n=r?e%Ge[0]:Math.floor(e/Ge[1]);t[n]&&t[n].push(e)})),t}),[Fe.length,Ge.join(),null==B?void 0:B.type,N,u]),mt=e.useMemo((()=>{if(!(null==B?void 0:B.type))return[{elementTop:0,elementBottom:0,left:0,right:0}];let e=[],t=0;if(F){const r=Array.from({length:Fe.length},((e,t)=>t)),n=Math.abs(Math.floor(Fe.length/Ge[0])*Ge[0]-Fe.length);e=n?r.slice(-n):[],"center"===F?t=(Ue[0]+Ye)*(Ge[0]-n)/2:"end"===F&&(t=(Ue[0]+Ye)*(Ge[0]-n))}return Fe.map(((r,n)=>{const o=function(e,t){for(let r=0;r<t.length;r++){const n=t[r].indexOf(e);if(-1!==n)return["x"===u?n:r,["hybrid","y"].includes(u)?n:r]}return[0,0]}(n,dt()),l=e.length>0&&e.includes(n)?t:0,s=function(e){const t="x"===u?l:0;return e>0?t+(Ue[1]+He)*e:t}(Ge[0]>1||["hybrid","x"].includes(u)?o[1]:n),i=Ue[1]?s+Ue[1]:s,c=function(e){const t="x"===u?0:l;return e>0?t+(Ue[0]+Ye)*e:t}(1===Ge[0]&&"x"===u?n:o[0]);return{elementTop:s,elementBottom:i,left:c,right:c+Ue[0]}}))}),[u,Ge[0],Ue.join(),He,Ye,null==B?void 0:B.type,N,F,dt,Fe.join()]),pt=e.useMemo((()=>(null==Ke?void 0:Ke.length)&&L?function(e,t,r,n){const[o,l="start"]="string"==typeof e?[e,e]:e,s={display:"flex"};return t[0]>r&&(s.justifyContent=f(o)),t[1]>n&&(s.alignItems=f(l)),s}(L,Ke,et,Ze):{}),[L,Ke.join(),Ze,et]),ht=e.useMemo((()=>[m(et,Ke[0]),m(Ze,Ke[1])]),[et,Ze,Ke.join()]),ft=e.useMemo((()=>"x"===u?ht[0]:ht[1]),[u,ht[0],ht[1]]),gt=o(g(ge,te),40),yt=o(g(ye,te,Be,We),40),vt=o(g(ve,te),40),bt=e.useCallback(((e,t,r,n)=>{const o=oe.current;return o?function(e,t,r,n,o){let l;if(!t&&!n)return null;const s=performance.now(),i=t.scrollTop,c=t.scrollLeft,a=u=>{const d=Math.min((u-s)/r,1);"y"===e?t.scrollTop=i+(n-i)*d:"x"===e&&(t.scrollLeft=c+(n-c)*d),1>d?l=requestAnimationFrame(a):null==o||o()};return l=requestAnimationFrame(a),()=>cancelAnimationFrame(l)}(t,o,r,e,n):null}),[]),xt=e.useCallback(((e,t,r)=>{if(ie.current){if(ie.current!==Fe[0])return void(ie.current=Fe[0])}else ie.current=Fe[0];const n=bt(t,e,Te.duration);n&&r.push(n)}),[Fe[0],Te.duration,bt]),Et=e.useMemo((()=>{const e=Object.assign(Object.assign(Object.assign(Object.assign({margin:A?`${Ne}px ${Ie}px ${$e}px ${Xe}px`:"",height:_e[1]&&"none"!==_e[1]?Qe+"px":"fit-content",width:_e[0]&&"none"!==_e[0]?Je+"px":"fit-content"},$.content&&{cursor:"grab"}),z&&!(null==B?void 0:B.type)&&{gap:`${He}px ${Ye}px`}),C&&function(e,t,r,n,o){const l=(e,t)=>"full"===e?("x"===t?r[0]:r[1])-("x"===t?n:o):e;if("hybrid"!==t&&!Array.isArray(e)){const r=l(e,t)+"px";return"x"===t?{minWidth:r}:{minHeight:r}}let s,i;return Array.isArray(e)?[s,i]=e:s=i=e,{minWidth:l(s,"x")+"px",minHeight:l(i,"y")+"px"}}(C,u,Ke,Be,We)),L&&{flexShrink:0});if(null==B?void 0:B.type)return Object.assign(Object.assign({},e),{position:"relative"});const t=_e[1]?"wrap":void 0,r=1===Ge[0]?"y"===u?"column":"row":N;return Object.assign(Object.assign({},e),{display:"flex",flexDirection:r,flexWrap:t,justifyContent:f(F)})}),[A,Se,Oe,[Ne,Ie,$e,Xe,Be,We,He,Ye].join(),Ke.join(),Re,_e[1],Qe,Je,$.content,Re,null==B?void 0:B.type,u,Ge[0],N,F]),jt=e.useCallback((e=>{if(!W)return;const t=()=>((e,t,r,n)=>{e&&e.querySelectorAll(".ms-bar").forEach(((e,t)=>{const o=e;["mouseleave","mouseup","touchend"].includes(r.type)?(o.style.opacity="0",o.classList.remove("hover"),o.classList.add("leave"),n(`mouseOnRef${t}-anim`,(()=>o.classList.remove("leave")),200)):(o.style.opacity="1",o.classList.add("hover"))}))})(ne.current,0,e,w);"mouseleave"===e.type?!["thumb","slider","wrapp"].includes(ce.current)&&t():t()}),[W]),wt=e.useCallback(((e,t="mousedown",r)=>{const n=e||("scroll"===c?"thumb":"slider");if("wrapp"===e&&!$.content||["thumb","slider"].includes(n)&&!$.progressElement)return;h(c,re.current,se);let o=null;r&&(o=r.getAttribute("data-direction")),function(e){const t=new AbortController,{signal:r}=t;e.clickedObject.current=e.clicked,e.triggerUpdate(),"mousedown"===e.eventType?(["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),document.addEventListener("mousemove",(t=>v(Object.assign(Object.assign({},e),{mouseEvent:t}))),{signal:r}),document.addEventListener("mouseup",(r=>b(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})):"touchstart"===e.eventType&&(document.addEventListener("touchmove",(t=>{t.preventDefault(),v(Object.assign(Object.assign({},e),{mouseEvent:t}))}),{signal:r,passive:!1}),document.addEventListener("touchend",(r=>b(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})),document.body.style.cursor="grabbing"}({eventType:t,scrollElementRef:oe.current,objectsWrapperRef:le.current,scrollBar:r||null,clickedObject:ce,scrollContentRef:ne.current,scrollStateRef:ue.current,type:c,scrollBarOnHover:W,mouseOnEl:x,mouseOnRefHandle:jt,triggerUpdate:te,direction:u,smoothScroll:bt,sizeLocal:[Ke[0],Ke[1]],clicked:n,numForSliderRef:me,isScrollingRef:de,prevCoordsRef:pe,thumbSize:"x"===o?ct:it,axisFromAtr:o,duration:Te.duration})}),[u,c,$.content,$.progressElement,Ke.join(),it,ct,Te.duration,bt,jt,W]),Ot=e.useCallback((e=>{wt(null,e.type,e.target)}),[wt]),St=e.useCallback((()=>{wt("wrapp")}),[wt]),Rt=e.useCallback((e=>{oe.current&&(({arrowType:e,scrollElement:t,wrapSize:r,scrollSize:n,smoothScroll:o,duration:l})=>{const s=r[0],i=r[1],c=t.scrollTop,a=t.scrollLeft,u=["top","bottom"].includes(e)?i:s,d=(e,t)=>o(p(e,0,u),t,l);"top"===e&&c>0?d(c-n[1],"y"):"left"===e&&a>0&&d(a-n[0],"x"),"bottom"===e&&c+n[1]!==i?d(c+n[1],"y"):"right"===e&&a+n[0]!==s&&d(a+n[0],"x")})({arrowType:e,scrollElement:oe.current,wrapSize:[et,Ze],scrollSize:Ke,smoothScroll:bt,duration:Te.duration})}),[Ke.join(),et,Ze,Te.duration,bt]),Mt=e.useCallback((()=>{h(c,re.current,se);const e=oe.current;ne.current&&e&&0!==se.current.length&&((e,t,r,n)=>{!function(){var o,l,s,i;const c=null!==(l=null===(o=t[0])||void 0===o?void 0:o.querySelectorAll(".ms-slider-element"))&&void 0!==l?l:[],a=null!==(i=null===(s=t[1])||void 0===s?void 0:s.querySelectorAll(".ms-slider-element"))&&void 0!==i?i:[];function u(e,t,r,n){const o="x"===n?r.scrollLeft:r.scrollTop;e.forEach(((e,r)=>{const l="x"===n?t[0]:t[1];o>=l*r&&l*(r+1)>o?e.classList.add("active"):e.classList.remove("active")}))}c.length>0&&u(c,r,e,n),a.length>0&&u(a,r,e,"x")}()})(e,se.current,Ke,u)}),[Ke.join(),u,oe,ne,c]),kt=e.useCallback((()=>{re.current&&((e,t,r,n)=>{const{allIds:o,emptyKeysRaw:l}=(()=>{const t=[],r=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e instanceof Element&&e.hasAttribute(E)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let o=n.nextNode();for(;o;){const e=o,l=e.getAttribute(E);l&&(t.push(l),0===e.children.length&&r.push(l)),o=n.nextNode()}return{allIds:t,emptyKeysRaw:r}})(),s=new Set(t.current.loaded);o.forEach((e=>s.add(e)));let i=null;if(t.current.empty){const e=new Set(t.current.empty);l.forEach((t=>e.add(t))),i=Array.from(e)}t.current={loaded:"lazy"===n?Array.from(s):o.map((e=>e)),empty:i},r()})(re.current,ae,te,null==B?void 0:B.type)}),[xe]),Tt=e.useCallback((e=>{(null==H?void 0:H.clickTrigger)&&((e,t,r,n)=>{const o=e.target;if(!o.closest(r.selector))return;const l=o.closest(`[${E}]`);l&&l.classList.add("remove"),t("emptyKeys-anim",(()=>{l&&l.classList.remove("remove"),n()}),r.delay||0)})(e,w,H.clickTrigger,kt)}),[we,kt]),zt=e.useCallback((()=>{const e=oe.current;e&&(null==S||S(e.scrollLeft,e.scrollTop),de.current=!0,null==R||R(!0),w("handleScroll-anim",(()=>{de.current=!1,null==R||R(!1),(null==B?void 0:B.type)?te():G()}),200),"slider"===c&&J(),(null==B?void 0:B.type)||G(),te())}),[S,R,c,null==B?void 0:B.type,J,kt]),At=p(rt/at*(Ve-it),0,Ve-it),Ct=p(((null===(_=oe.current)||void 0===_?void 0:_.scrollLeft)||0)/ut*(Ke[0]-Ke[0]/et*Ke[0]),0,Ke[0]-ct),Lt=e.useCallback((e=>{const t="object"==typeof $.wheel&&$.wheel.changeDirectionKey?$.wheel.changeDirectionKey:"KeyX";e.code!==t||"hybrid"!==u||he.current||(e.stopPropagation(),he.current=!0,te())}),[u,JSON.stringify($.wheel)]),Ft=e.useCallback((e=>{he.current&&(e.stopPropagation(),he.current=!1,te())}),[]);e.useEffect((()=>{(H||(null==B?void 0:B.type))&&(H||null===ae.current.empty||(ae.current.empty=null),G())}),[we,null==B?void 0:B.type,de.current,Fe.join(),kt]),e.useEffect((()=>{const e=ue.current.animationFrameId;return((null==B?void 0:B.type)||R)&&R&&(R(!1),te()),Mt(),()=>{e&&cancelAnimationFrame(e),(()=>{for(const e of j.values())clearTimeout(e);j.clear()})()}}),[]),e.useEffect((()=>{const e=oe.current;if(!e)return;const t=e=>e.preventDefault(),r="hybrid"===u&&"object"==typeof $.wheel&&$.wheel.changeDirection?"x":u,n="hybrid"===u&&Qe+We<=Ke[1]||he.current?["hybrid","y"].includes(r)?"x":"y":r,o=$.wheel?e=>{t(e),function(e,t,r){const n=e.target.closest(".ms-element");n.matches(":focus")||n.focus(),t.animating||(t.targetScrollX=n.scrollLeft,t.targetScrollY=n.scrollTop),"x"===r?t.targetScrollX=p(t.targetScrollX+e.deltaY,0,n.scrollWidth-n.clientWidth+2):t.targetScrollY=p(t.targetScrollY+e.deltaY,0,n.scrollHeight-n.clientHeight+2),t.animating||(t.animating=!0,t.animationFrameId=requestAnimationFrame((function e(){let o=0;"x"===r?(n.scrollLeft+=.4*(t.targetScrollX-n.scrollLeft),o=Math.abs(n.scrollLeft-t.targetScrollX)):(n.scrollTop+=.4*(t.targetScrollY-n.scrollTop),o=Math.abs(n.scrollTop-t.targetScrollY)),o>2.5?t.animationFrameId=requestAnimationFrame(e):(t.animating=!1,null!==t.animationFrameId&&(cancelAnimationFrame(t.animationFrameId),t.animationFrameId=null))})))}(e,ue.current,n)}:t;return e.addEventListener("wheel",o,{passive:!1}),()=>{e.removeEventListener("wheel",o)}}),[u,JSON.stringify($.wheel),Qe,Ke[1],We,he.current]),e.useEffect((()=>{if(!Te.value)return;const e=[];return("hybrid"===u?["x","y"]:[u]).forEach((t=>{const r="x"===t?0:1;"end"===Te.value[r]&&xt(t,"x"===t?ut:at,e)})),()=>{e.forEach((e=>e()))}}),[u,Te.value.join(),be,at,ut,et,Ze]),e.useEffect((()=>{if(!Te.value)return;const e=[];return("hybrid"===u?["x","y"]:[u]).forEach((t=>{const r="x"===t?0:1;"number"==typeof Te.value[r]&&xt(t,Te.value[r],e)})),()=>{e.forEach((e=>e()))}}),[be,null==O?void 0:O.updater,u,xt,Te.value.join()]);const Nt=e.useCallback(((t,r,n,o)=>{var l;const s=Object.assign({width:Ue[0]?Ue[0]+"px":void 0,height:Ue[1]?Ue[1]+"px":void 0},(null==B?void 0:B.type)&&Object.assign({position:"absolute",top:r+"px",left:n+"px"},!Ue[0]&&1===Ge[0]&&{transform:"translateX(-50%)"})),i=Y?e.createElement(e.Suspense,{fallback:P},o):o,c=(null===(l=null==H?void 0:H.clickTrigger)||void 0===l?void 0:l.selector)&&Tt;return e.createElement("div",Object.assign({key:t},B||H?{[E]:""+t}:{},{className:"ms-object-box",style:s,onClick:c}),i)}),[Y,!!P,Ue.join(),xe,we,Ge[0],Tt]),It=e.createElement("div",{className:"ms-objects-wrapper",ref:le,onMouseDown:St,style:Et},Fe.map(((t,r)=>{var o,l,i;const c=e.Children.toArray(s).find((r=>e.isValidElement(r)&&r.key===t)),a=(null==B?void 0:B.stopLoadOnScroll)&&de.current&&!ae.current.loaded.includes(""+t)?P:(null===(o=ae.current.empty)||void 0===o?void 0:o.includes(t))?"object"==typeof(null==H?void 0:H.mode)?H.mode.fallback:P:c,d="number"==typeof _e[0]&&"number"==typeof _e[1]||"firstChild"!==_e[0]&&"firstChild"!==_e[1]||0!==r?a:e.createElement(n,{onResize:vt},a);if(!(null==B?void 0:B.type))return Nt(t,0,0,d);{const{elementTop:e,elementBottom:n,left:o,right:s}=mt[r],c="x"===u?qe:De,a=Ve+c>("x"===u?o:e)-rt&&("x"===u?s:n)-rt>0-c,m="hybrid"!==u||Ke[0]+qe>o-((null===(l=oe.current)||void 0===l?void 0:l.scrollLeft)||0)&&s-((null===(i=oe.current)||void 0===i?void 0:i.scrollLeft)||0)>0-qe;if(a&&m)return Nt(t,e,o,d)}}))),$t=[{positionType:"x"===u?"left":"top",visibility:nt},{positionType:"x"===u?"right":"bottom",visibility:ot},..."hybrid"===u?[{positionType:"left",visibility:lt},{positionType:"right",visibility:st}]:[]],Xt=e.createElement("div",{"morph-scroll":`〈♦${Q}〉`,className:r,ref:re,style:{width:Ke[2]+"px",height:Ke[3]+"px"}},e.createElement("div",{className:"ms-content",ref:ne,onMouseEnter:jt,onMouseLeave:jt,onTouchStart:jt,onTouchEnd:jt,style:Object.assign({position:"relative",width:Ke[0]+"px",height:Ke[1]+"px"},$.arrows&&Ce.size&&("x"===u?{left:Ce.size+"px"}:"y"===u?{top:Ce.size+"px"}:{top:Ce.size+"px",left:Ce.size+"px"}))},e.createElement("div",{className:"ms-element",ref:oe,onScroll:zt,onKeyDown:Lt,onKeyUp:Ft,style:Object.assign(Object.assign(Object.assign({width:"100%",height:"100%",outline:"none"},pt),{overflow:null!==(U={x:et>Ke[0]?"scroll hidden":"hidden",y:Ze>Ke[1]?"hidden scroll":"hidden",hybrid:`${et>Ke[0]?"scroll":"hidden"} ${Ze>Ke[1]?"scroll":"hidden"}`,hide:"hidden"}[$.wheel||$.content?u:"hide"])&&void 0!==U?U:"hidden"}),"scroll"!==c||"boolean"!=typeof $.progressElement||!1===$.progressElement?{scrollbarWidth:"none"}:{})},Ue[0]&&Ue[1]?It:e.createElement(n,{onResize:yt,style:Object.assign({},pt)},It)),I&&$t.map((({positionType:t,visibility:r})=>e.createElement(a,{key:"edge-"+t,edgeGradient:Ae,visibility:r,edgeType:t}))),$.progressElement&&!0!==$.progressElement&&[{shouldRender:tt>it,direction:u,thumbSize:it,thumbSpace:At,objLengthPerSize:ft,progressReverseIndex:0},{shouldRender:"hybrid"===u&&et>ct,direction:"x",thumbSize:ct,thumbSpace:Ct,objLengthPerSize:ht[0],progressReverseIndex:1}].filter((({shouldRender:e})=>e)).map((t=>e.createElement(i,{key:t.direction,type:c,direction:t.direction,progressReverse:"boolean"==typeof X?X:X[t.progressReverseIndex],size:Ke,progressTrigger:$,scrollBarOnHover:W,scrollBarEvent:"sliderMenu"===c?bt:Ot,thumbSize:t.thumbSize,thumbSpace:t.thumbSpace,objLengthPerSize:t.objLengthPerSize,sliderCheckLocal:Mt,duration:Te.duration})))),$.arrows&&$t.map((({positionType:t,visibility:r})=>e.createElement(d,{key:"arrow-"+t,activity:r,arrows:Ce,arrowType:t,handleArrow:Rt,size:"hybrid"===u?Ke[0]+2*Ce.size:Ke[0]}))));return"auto"===M?e.createElement(n,{measure:"outer",onResize:gt},Xt):Xt};S.displayName="MorphScroll";const R={MorphScroll:S,ResizeTracker:n,IntersectionTracker:r};exports.IntersectionTracker=r,exports.MorphScroll=S,exports.ResizeTracker=n,exports.default=R;
package/esm/index.js CHANGED
@@ -1 +1 @@
1
- import e,{useMemo as t,useEffect as r,useRef as n}from"react";const o=(e,t=!1,r)=>{let n=[];if(n=Array.isArray(e)?2===e.length?[e[1],e[0],e[1],e[0]]:[...e]:[e,e,e,e],t&&(n=[n[1],n[0],n[3],n[2]]),r){const e=[];for(let t=0;r>t;t++)e.push(n[t%4]);n=e}return n},l=({className:t,children:r,style:n,root:l,threshold:s,rootMargin:i,visibleContent:c=!1,onIntersection:a})=>{const[u,d]=e.useState(!1),m=e.useRef(null),p=e.useMemo((()=>{if(!i)return"";const e=o(i);return`${e[0]}px ${e[1]}px ${e[2]}px ${e[3]}px`}),[i]),f=e.useCallback((([e])=>{d(e.isIntersecting),a&&a({time:e.time,rootBounds:e.rootBounds,boundingClientRect:e.boundingClientRect,intersectionRect:e.intersectionRect,isIntersecting:e.isIntersecting,intersectionRatio:e.intersectionRatio,target:e.target})}),[a]);return e.useEffect((()=>{const e=new IntersectionObserver(f,{root:l,threshold:s,rootMargin:p});return m.current&&e.observe(m.current),()=>{e.disconnect()}}),[f,l,s,p]),e.createElement("div",{"intersection-tracker":"",className:t,ref:m,style:n},c||u?r:null)};l.displayName="IntersectionTracker";const s=({className:t,children:r,style:n,measure:o="inner",onResize:l})=>{const s=e.useRef(null);e.useEffect((()=>{const e=s.current;if(!e)return;const t=new ResizeObserver((e=>{for(const t of e)l&&l(t.contentRect)}));return t.observe(e),()=>{t.unobserve(e),t.disconnect()}}),[o,l]);const i={width:"max-content",height:"max-content"},c={inner:Object.assign({},i),outer:Object.assign({},{width:"100%",height:"100%"}),all:Object.assign({minWidth:"100%",minHeight:"100%"},i)};return e.createElement("div",{"resize-tracker":"",className:t,ref:s,style:Object.assign(Object.assign({willChange:"width, height"},c[o]),n)},r)};function i(e,n){const o=t((()=>function(e,t){let r=null,n=null;const o=(...o)=>{"requestFrame"===t?(null!==n&&cancelAnimationFrame(n),n=requestAnimationFrame((()=>{e(...o),n=null}))):(null!==r&&clearTimeout(r),r=setTimeout((()=>{e(...o),r=null}),t))};return o.cancel=()=>{null!==r&&(clearTimeout(r),r=null),null!==n&&(cancelAnimationFrame(n),n=null)},o}(e,n)),[n,e]);return r((()=>()=>{o.cancel()}),[o]),o}s.displayName="ResizeTracker";let c=1;const a=({type:t,direction:r,progressReverse:n,size:o,progressTrigger:l,scrollBarOnHover:s,scrollBarEvent:i,thumbSize:c,thumbSpace:a,objLengthPerSize:u,sliderCheckLocal:d,duration:m})=>{const p="sliderMenu"!==t?{onMouseDown:i,onTouchStart:i}:{},f=e.useMemo((()=>{if("scroll"===t||!r)return;const n=["hybrid","y"].includes(r)?"y":"x",s="x"===n?o[0]:o[1];return Array.from({length:u},((r,o)=>e.createElement("div",{key:o,className:"ms-slider-element",style:Object.assign({},"sliderMenu"===t&&{cursor:"pointer"}),onClick:"sliderMenu"===t?()=>{i(s*o,n,m,d)}:void 0},Array.isArray(null==l?void 0:l.progressElement)?l.progressElement[o]:null==l?void 0:l.progressElement)))}),[u,r,o,t,i,null==l?void 0:l.progressElement]);return e.createElement(e.Fragment,null,"scroll"===t?e.createElement("div",{className:"ms-bar",style:Object.assign(Object.assign(Object.assign({position:"absolute",width:"fit-content"},"x"===r?Object.assign({transformOrigin:"left top",height:o[0]+"px"},n?{top:0,transform:"rotate(-90deg) translateX(-100%)"}:{transform:"rotate(-90deg)"}):Object.assign({top:0,height:"100%"},n?{left:0}:{right:0})),0!=!(null==l?void 0:l.progressElement)&&{pointerEvents:"none"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"})},e.createElement("div",Object.assign({className:"ms-thumb","data-direction":["hybrid","y"].includes(r)?"y":r},p,{style:Object.assign(Object.assign({height:c+"px",willChange:"transform, height",transform:`translateY(${a}px)`},(null==l?void 0:l.progressElement)&&{cursor:"grab"}),{transition:"height 0.05s ease-in-out"})}),null==l?void 0:l.progressElement)):u>1&&(null==l?void 0:l.progressElement)&&e.createElement("div",Object.assign({className:"ms-slider","data-direction":["hybrid","y"].includes(r)?"y":r},p,{style:Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex"},"slider"===t&&{cursor:"grab"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"}),"x"===r?Object.assign({transformOrigin:"left top",left:"50%",transform:"translateX(-50%)"},n?{top:0}:{bottom:0}):Object.assign({flexDirection:"column",top:"50%",transform:"translateY(-50%)"},n?{left:0}:{right:0}))}),f))};a.displayName="ScrollBar";var u=e.memo(a);const d=({edgeGradient:t,visibility:r,edgeType:n})=>{if(!t)return null;const o=Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",pointerEvents:"none",transition:"opacity 0.1s ease-in-out"},t.color&&{background:t.color&&`linear-gradient(${"right"===n||"left"===n?"90deg, ":""}${t.color}, transparent)`}),"right"===n||"left"===n?{height:"100%",width:t.size+"px",top:0}:{width:"100%",height:t.size+"px",left:0}),n?{[n]:0}:{}),"right"===n?{transform:"scaleX(-1)"}:"bottom"===n?{transform:"scaleY(-1)"}:{});return e.createElement("div",{className:"ms-edge"+(n?" "+n:""),style:Object.assign(Object.assign({},o),{opacity:r?1:0})})};d.displayName="Edge";var m=e.memo(d);const p=({activity:t,arrows:r,arrowType:n,handleArrow:o,size:l})=>{const s=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",width:r.size+"px"},n?{[n]:0}:{}),"top"===n&&{transform:"rotate(-90deg) translateX(-100%)",transformOrigin:"left top"}),"bottom"===n&&{transform:"rotate(90deg) translateX(-100%)",transformOrigin:"left bottom"}),"left"===n&&{transform:"scaleX(-1)"}),["top","bottom"].includes(n)?{height:l+"px"}:{height:"100%",top:0});return e.createElement("div",{className:`ms-arrow-box ${n}${t?" active":""}`,style:Object.assign({},s),onClick:()=>o(n)},r.element)};p.displayName="Arrow";var f=e.memo(p);function h(e,t){return e>t?Math.floor(e/t):1}function g(e,t=0,r=1/0){return Math.max(t,Math.min(Math.round(e),r))}const v=(e,t,r)=>{if(!t)return;const n=t.querySelectorAll("."+("scroll"===e?"ms-thumb":"ms-slider"));n.length>0&&(r.current=n)},y=e=>e?"start"===e?"flex-start":"center"===e?"center":"flex-end":void 0;function b(e,t,r=0,n=0){return o=>{var l,s,i,c;const a={width:(null!==(l=o.width)&&void 0!==l?l:0)-r,height:(null!==(s=o.height)&&void 0!==s?s:0)-n};(null===(i=e.current)||void 0===i?void 0:i.width)===a.width&&(null===(c=e.current)||void 0===c?void 0:c.height)===a.height||(e.current=a,t())}}function x(t){const r=[],n=t=>{if(null===t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)r.push(t+"");else if("string"==typeof t)r.push(t);else if("function"==typeof t)r.push("<function>");else if(e.isValidElement(t))r.push("<react-node>");else if(Array.isArray(t))t.forEach(n);else if("object"==typeof t){const e=Object.entries(t).sort((([e],[t])=>e.localeCompare(t)));for(const[,t]of e)n(t)}else void 0===t&&r.push("<undefined>")};return n(t),r.join("/")}function E(e){var t,r,n;const o={x:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientX:e.mouseEvent.clientX,y:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientY:e.mouseEvent.clientY,leftover:null!==(r=null===(t=e.prevCoordsRef.current)||void 0===t?void 0:t.leftover)&&void 0!==r?r:0},l=null!==(n=e.prevCoordsRef.current)&&void 0!==n?n:o,s={x:o.x-l.x,y:o.y-l.y};e.prevCoordsRef.current=o;const i=t=>{if(!e.scrollElementRef||!e.objectsWrapperRef)return;let r=0;const n="x"===t?"movementX"in e.mouseEvent?e.mouseEvent.movementX:s.x:"movementY"in e.mouseEvent?e.mouseEvent.movementY:s.y,o=e.scrollElementRef;if("thumb"===e.clicked){const s=e.objectsWrapperRef,i=getComputedStyle(s),c="x"===t?o.clientWidth:o.clientHeight,a="x"===t?s.clientWidth+parseFloat(i.marginLeft)+parseFloat(i.marginRight):s.clientHeight+parseFloat(i.marginTop)+parseFloat(i.marginBottom),u=c-e.thumbSize,d=a-c;if(0>=u||0>=d)return;const m=n*(d/u)+l.leftover,p=Math.trunc(m),f=m-p;e.prevCoordsRef.current.leftover=f,r=p}else r=-n;"x"===t?(o.scrollLeft+=r,e.scrollStateRef.targetScrollX=o.scrollLeft):(o.scrollTop+=r,e.scrollStateRef.targetScrollY=o.scrollTop)},c=t=>{const r=e.objectsWrapperRef;if(!r)return;const n="slider"===e.type&&"wrapp"===e.clicked?-1:1,o=s[t]*n,l="x"===t?e.sizeLocal[0]:e.sizeLocal[1],i="x"===t?r.offsetWidth:r.offsetHeight,c="x"===t?e.scrollElementRef.scrollLeft:e.scrollElementRef.scrollTop;e.numForSliderRef.current+=Math.abs(o),e.numForSliderRef.current>6&&!e.isScrollingRef.current&&(o>0&&i>c+l?e.smoothScroll(c+l,t,e.duration):0>o&&c>0&&e.smoothScroll(c-l,t,e.duration),e.numForSliderRef.current=0)},a=t=>{"thumb"===e.clicked?i(t):"wrapp"===e.clicked?"slider"===e.type?c(t):i(t):"slider"===e.clicked&&c(t)};"hybrid"===e.direction?"wrapp"===e.clicked?(a("x"),a("y")):e.axisFromAtr&&a(e.axisFromAtr):a(e.direction||"y")}function j(e){if(e.controller.abort(),document.body.style.removeProperty("cursor"),["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),e.clickedObject.current="none",e.scrollBarOnHover){let t=e.mouseEvent.target,r=!1;for(;t&&t!==document.body;){if(t===e.scrollContentRef){r=!0;break}t=t.parentNode}r||e.mouseOnRefHandle(e.mouseEvent)}e.prevCoordsRef.current=null,e.triggerUpdate()}const O=e=>{e&&("grab"===e.style.cursor?(e.style.cursor="grabbing",e.classList.add("active")):"grabbing"===e.style.cursor&&(e.style.cursor="grab",e.classList.remove("active")))},w="wrap-id",S=new Map,R=(e,t,r)=>{M(e);const n=setTimeout((()=>{t(),S.delete(e)}),r);S.set(e,n)},M=e=>{const t=S.get(e);t&&(clearTimeout(t),S.delete(e))},k=({type:t="scroll",className:r,size:l,objectsSize:a,direction:d="y",gap:p,wrapperMargin:M,wrapperMinSize:k,progressReverse:T=!1,progressTrigger:z={wheel:!0},scrollBarOnHover:A=!1,suspending:C=!1,fallback:L,scrollPosition:F,edgeGradient:N,children:I,onScrollValue:$,elementsAlign:W,elementsDirection:X="row",wrapperAlign:B,isScrolling:H,render:Y,emptyElements:q,crossCount:P})=>{var D,V,K,G,U,_,J;const Q=i((()=>{kt()}),40),Z=i((()=>{vt()}),34),ee=function(){const e=n(null);return null===e.current&&(e.current=""+c++),e.current}();if(!l)throw Error(`Prop "size" is not provided\nMorphScroll〈♦${ee}〉`);Object.keys(z).length;const[te,re]=e.useState(0),ne=()=>{re((e=>"number"==typeof e&&1e3>e?e+1:0))},oe=e.useRef(null),le=e.useRef(null),se=e.useRef(null),ie=e.useRef(null),ce=e.useRef([]),ae=e.useRef(null),ue=e.useRef("none"),de=e.useRef({loaded:[],empty:[]}),me=e.useRef({targetScrollY:0,targetScrollX:0,animating:!1,animationFrameId:0}),pe=e.useRef(!1),fe=e.useRef(0),he=e.useRef(null);function ge(){return e.useRef({width:0,height:0})}const ve=ge(),ye=ge(),be=ge(),[xe,Ee,je,Oe,we,Se,Re,Me]=function(...e){return e.map(x)}(null==F?void 0:F.value,Y,l,a,q,k,B,p),ke=e.useMemo((()=>{var e,t;return{value:"number"==typeof(null==F?void 0:F.value)||"string"==typeof(null==F?void 0:F.value)?[F.value,F.value]:null!==(e=null==F?void 0:F.value)&&void 0!==e?e:[null],duration:null!==(t=null==F?void 0:F.duration)&&void 0!==t?t:200}}),[xe,null==F?void 0:F.duration]),Te={color:null,size:40},ze=e.useMemo((()=>"object"==typeof N?Object.assign(Object.assign({},Te),N):Te),[N]),Ae=e.useMemo((()=>Object.assign(Object.assign({},Te),"object"==typeof z.arrows?z.arrows:{})),[z.arrows]),Ce=e.useCallback((t=>{if(null==t)return[];if(e.isValidElement(t)){const r=t;return r.type===e.Fragment?e.Children.toArray(r.props.children).flatMap(Ce):[r]}return[t]}),[]),Le=e.useMemo((()=>e.Children.toArray(I).flatMap(Ce).map((t=>e.isValidElement(t)&&t.key?t.key+"":null)).filter((e=>null!==e)).filter((e=>{var t;return"clear"!==(null==q?void 0:q.mode)||!(null===(t=de.current.empty)||void 0===t?void 0:t.includes(e))}))),[I,we,null===(D=de.current.empty)||void 0===D?void 0:D.join()]),[Fe,Ne,Ie,$e]=M?o(M):[0,0,0,0],We=Fe+Ie,Xe=$e+Ne,[Be,He]=e.useMemo((()=>{var e,t;return"number"==typeof p?[p,p]:Array.isArray(p)?[null!==(e=p[1])&&void 0!==e?e:0,null!==(t=p[0])&&void 0!==t?t:0]:[0,0]}),[p]),Ye=e.useMemo((()=>o((null==Y?void 0:Y.rootMargin)||0,"x"===d)),[Ee,d]),[qe,Pe]=Ye?[Ye[2],Ye[0]]:[0,0],De=e.useMemo((()=>{const[e,t]=Array.isArray(l)?l:"number"==typeof l?[l,l]:[ve.current.width,ve.current.height];if(!z.arrows||!Ae.size)return[e,t,e,t];const r=2*Ae.size;let n=e,o=t;return"x"===d?n=e-r:"y"===d?o=t-r:"hybrid"===d&&(n=e-r,o=t-r),[n,o,e,t]}),[je,Ae.size,ve.current]),Ve="x"===d?De[0]:De[1],Ke=e.useMemo((()=>a?Array.isArray(a)?a:o(a,!0,2):[null,null]),[Oe]),Ge=e.useMemo((()=>{const e=(e,t)=>"number"==typeof e?e:"firstChild"===e?t:0;return[e(Ke[0]&&"none"!==Ke[0]&&"size"!==Ke[0]?Ke[0]:"y"===d&&"none"!==Ke[0]||"size"===Ke[0]?De[0]:0,be.current.width),e(Ke[1]&&"none"!==Ke[1]&&"size"!==Ke[1]?Ke[1]:"x"===d&&"none"!==Ke[1]||"size"===Ke[1]?De[1]:0,be.current.height)]}),[Oe,je,be.current,De.join()]),Ue=e.useMemo((()=>{const e="x"===d,t="row"===X,r="column"===X,n=e?De[1]:De[0],o=e?Ge[1]+He:Ge[0]+Be,l="hybrid"===d?o*(Le.length+1)-o:n,s=Math.floor(l/o)||1,i=P&&s>=P?"hybrid"===d?Math.ceil(s/P):P:s,c=i>1&&i<Le.length?Math.ceil(Le.length/i):i>Le.length?1:Le.length,a=P&&P<Le.length,u=e=>Number.isFinite(e)&&e>0?e:1;if("hybrid"===d){const e=a?t?P:i:t?Le.length:1,n=a?r?P:i:r?Le.length:1;return[u(e),u(n)]}return[u(i),u(c)]}),[Le.length,d,Ge.join(),De.join(),Be,Xe,We,P]),_e=e.useMemo((()=>{const e=Ue[0]?Ue[0]*He-He:0,t="x"===d?Ue[1]:Ue[0];return Ge[0]?(Ge[0]+He)*t-He:(null==Y?void 0:Y.type)?be.current.width+e:ye.current.width}),[Ge[0],Ue.join(),He,ye.current.width,be.current,Ee]),Je=e.useMemo((()=>{const e=1>Ue[1]?1:Ue[0]*Be-Be;return Ge[1]?"x"===d?(Ge[1]+Be)*Ue[0]-Be:(Ge[1]+Be)*Ue[1]-Be:(null==Y?void 0:Y.type)?be.current.height+e:ye.current.height}),[Ge[1],Ue.join(),Be,ye.current.height,be.current,Ee]),Qe=e.useMemo((()=>Je+We),[Je,We]),Ze=e.useMemo((()=>_e+Xe),[_e,Xe]),et="x"===d?Ze:Qe,tt="x"===d?(null===(V=se.current)||void 0===V?void 0:V.scrollLeft)||0:(null===(K=se.current)||void 0===K?void 0:K.scrollTop)||0,rt=tt>1&&!0,nt=et>Math.round(tt+Ve);let ot=!1,lt=!1;"hybrid"===d&&(ot=((null===(G=se.current)||void 0===G?void 0:G.scrollLeft)||0)>1&&!0,lt=Math.round(((null===(U=se.current)||void 0===U?void 0:U.scrollLeft)||0)+De[0])<Ze);const st=e.useMemo((()=>{if(!z.progressElement||!et)return 0;const e=Math.round(Ve/et*Ve);return!Number.isFinite(e)||0>e?0:e}),[Ve,et,z.progressElement]),it=e.useMemo((()=>{if(!z.progressElement)return 0;const e=Math.round(De[0]/Ze*De[0]);return!Number.isFinite(e)||0>e?0:e}),[De[0],Ze,z.progressElement]),ct=e.useMemo((()=>Ve?et-Ve:et),[et,Ve]),at=e.useMemo((()=>De[0]?Ze-De[0]:Ze),[Ze,De[0]]),ut=e.useCallback((()=>{if(!(null==Y?void 0:Y.type)||1>=Ue[0])return[];const e=Array.from({length:Le.length},((e,t)=>t)),t=Array.from({length:Ue[0]},(()=>[])),r="x"===d&&"column"===X||"x"!==d&&"row"===X;return e.forEach((e=>{const n=r?e%Ue[0]:Math.floor(e/Ue[1]);t[n]&&t[n].push(e)})),t}),[Le.length,Ue.join(),Ee,X,d]),dt=e.useMemo((()=>{if(!(null==Y?void 0:Y.type))return[{elementTop:0,elementBottom:0,left:0,right:0}];let e=[],t=0;if(W){const r=Array.from({length:Le.length},((e,t)=>t)),n=Math.abs(Math.floor(Le.length/Ue[0])*Ue[0]-Le.length);e=n?r.slice(-n):[],"center"===W?t=(Ge[0]+He)*(Ue[0]-n)/2:"end"===W&&(t=(Ge[0]+He)*(Ue[0]-n))}return Le.map(((r,n)=>{const o=function(e,t){for(let r=0;r<t.length;r++){const n=t[r].indexOf(e);if(-1!==n)return["x"===d?n:r,["hybrid","y"].includes(d)?n:r]}return[0,0]}(n,ut()),l=e.length>0&&e.includes(n)?t:0,s=function(e){const t="x"===d?l:0;return e>0?t+(Ge[1]+Be)*e:t}(Ue[0]>1||["hybrid","x"].includes(d)?o[1]:n),i=Ge[1]?s+Ge[1]:s,c=function(e){const t="x"===d?0:l;return e>0?t+(Ge[0]+He)*e:t}(1===Ue[0]&&"x"===d?n:o[0]);return{elementTop:s,elementBottom:i,left:c,right:c+Ge[0]}}))}),[I,Ge.join(),p,Ee,Ue[0],X]),mt=e.useMemo((()=>(null==De?void 0:De.length)&&B?function(e,t,r,n){const[o,l="start"]="string"==typeof e?[e,e]:e,s={display:"flex"};return t[0]>r&&(s.justifyContent=y(o)),t[1]>n&&(s.alignItems=y(l)),s}(B,De,Ze,Qe):{}),[B,De.join(),Qe,Ze]),pt=e.useMemo((()=>[h(Ze,De[0]),h(Qe,De[1])]),[Ze,Qe,De.join()]),ft=e.useMemo((()=>"x"===d?pt[0]:pt[1]),[d,pt[0],pt[1]]),ht=e.useCallback((e=>{if(!A)return;const t=()=>((e,t,r,n)=>{e&&e.querySelectorAll(".ms-bar").forEach(((e,t)=>{const o=e;["mouseleave","mouseup","touchend"].includes(r.type)?(o.style.opacity="0",o.classList.remove("hover"),o.classList.add("leave"),n(`mouseOnRef${t}-anim`,(()=>o.classList.remove("leave")),200)):(o.style.opacity="1",o.classList.add("hover"))}))})(le.current,0,e,R);"mouseleave"===e.type?!["thumb","slider","wrapp"].includes(ue.current)&&t():t()}),[A,t,ue.current,le.current]),gt=e.useCallback((e=>{se.current&&(({arrowType:e,scrollElement:t,wrapSize:r,scrollSize:n,smoothScroll:o,duration:l})=>{const s=r[0],i=r[1],c=t.scrollTop,a=t.scrollLeft,u=["top","bottom"].includes(e)?i:s,d=(e,t)=>o(g(e,0,u),t,l);"top"===e&&c>0?d(c-n[1],"y"):"left"===e&&a>0&&d(a-n[0],"x"),"bottom"===e&&c+n[1]!==i?d(c+n[1],"y"):"right"===e&&a+n[0]!==s&&d(a+n[0],"x")})({arrowType:e,scrollElement:se.current,wrapSize:[Ze,Qe],scrollSize:De,smoothScroll:wt,duration:ke.duration})}),[se.current,De.join(),Ze,Qe,ke.duration]),vt=e.useCallback((()=>{v(t,oe.current,ce);const e=se.current;le.current&&e&&0!==ce.current.length&&((e,t,r,n)=>{!function(){var o,l,s,i;const c=null!==(l=null===(o=t[0])||void 0===o?void 0:o.querySelectorAll(".ms-slider-element"))&&void 0!==l?l:[],a=null!==(i=null===(s=t[1])||void 0===s?void 0:s.querySelectorAll(".ms-slider-element"))&&void 0!==i?i:[];function u(e,t,r,n){const o="x"===n?r.scrollLeft:r.scrollTop;e.forEach(((e,r)=>{const l="x"===n?t[0]:t[1];o>=l*r&&l*(r+1)>o?e.classList.add("active"):e.classList.remove("active")}))}c.length>0&&u(c,r,e,n),a.length>0&&u(a,r,e,"x")}()})(e,ce.current,De,d)}),[De.join(),d,se,le,ce,t]),yt=e.useCallback((()=>{const e=se.current;e&&(null==$||$(e.scrollLeft,e.scrollTop),pe.current=!0,null==H||H(!0),R("handleScroll-anim",(()=>{pe.current=!1,null==H||H(!1),(null==Y?void 0:Y.type)?ne():Q()}),200),"slider"===t&&Z(),(null==Y?void 0:Y.type)||Q(),ne())}),[d,$,H,Ee,t,Z]),bt=g(tt/ct*(Ve-st),0,Ve-st),xt=g(((null===(_=se.current)||void 0===_?void 0:_.scrollLeft)||0)/at*(De[0]-De[0]/Ze*De[0]),0,De[0]-it),Et=i(b(ve,ne),40),jt=i(b(ye,ne,Xe,We),40),Ot=i(b(be,ne),40),wt=e.useCallback(((e,t,r,n)=>{const o=se.current;return o?function(e,t,r,n,o){let l;if(!t&&!n)return null;const s=performance.now(),i=t.scrollTop,c=t.scrollLeft,a=u=>{const d=Math.min((u-s)/r,1);"y"===e?t.scrollTop=i+(n-i)*d:"x"===e&&(t.scrollLeft=c+(n-c)*d),1>d?l=requestAnimationFrame(a):null==o||o()};return l=requestAnimationFrame(a),()=>cancelAnimationFrame(l)}(t,o,r,e,n):null}),[se]),St=e.useCallback(((e,r="mousedown",n)=>{const o=e||("scroll"===t?"thumb":"slider");if("wrapp"===e&&!z.content||["thumb","slider"].includes(o)&&!z.progressElement)return;v(t,oe.current,ce);let l=null;n&&(l=n.getAttribute("data-direction")),function(e){const t=new AbortController,{signal:r}=t;e.clickedObject.current=e.clicked,e.triggerUpdate(),"mousedown"===e.eventType?(["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),document.addEventListener("mousemove",(t=>E(Object.assign(Object.assign({},e),{mouseEvent:t}))),{signal:r}),document.addEventListener("mouseup",(r=>j(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})):"touchstart"===e.eventType&&(document.addEventListener("touchmove",(t=>{t.preventDefault(),E(Object.assign(Object.assign({},e),{mouseEvent:t}))}),{signal:r,passive:!1}),document.addEventListener("touchend",(r=>j(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})),document.body.style.cursor="grabbing"}({eventType:r,scrollElementRef:se.current,objectsWrapperRef:ie.current,scrollBar:n||null,clickedObject:ue,scrollContentRef:le.current,scrollStateRef:me.current,type:t,scrollBarOnHover:A,mouseOnEl:O,mouseOnRefHandle:ht,triggerUpdate:ne,direction:d,smoothScroll:wt,sizeLocal:[De[0],De[1]],clicked:o,numForSliderRef:fe,isScrollingRef:pe,prevCoordsRef:he,thumbSize:"x"===l?it:st,axisFromAtr:l,duration:ke.duration})}),[t,z.content,z.progressElement,De.join(),st,it,ke.duration]),Rt=e.useCallback((e=>{St(null,e.type,e.target)}),[St]),Mt=e.useCallback((()=>{St("wrapp")}),[St]),kt=e.useCallback((()=>{oe.current&&((e,t,r,n)=>{const{allIds:o,emptyKeysRaw:l}=(()=>{const t=[],r=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e instanceof Element&&e.hasAttribute(w)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let o=n.nextNode();for(;o;){const e=o,l=e.getAttribute(w);l&&(t.push(l),0===e.children.length&&r.push(l)),o=n.nextNode()}return{allIds:t,emptyKeysRaw:r}})(),s=new Set(t.current.loaded);o.forEach((e=>s.add(e)));let i=null;if(t.current.empty){const e=new Set(t.current.empty);l.forEach((t=>e.add(t))),i=Array.from(e)}t.current={loaded:"lazy"===n?Array.from(s):o.map((e=>e)),empty:i},r()})(oe.current,de,ne,null==Y?void 0:Y.type)}),[Ee]),Tt=e.useCallback((e=>{(null==q?void 0:q.clickTrigger)&&((e,t,r,n)=>{e.target.closest(r.selector)&&t("emptyKeys-anim",(()=>{n()}),r.delay||0)})(e,R,q.clickTrigger,kt)}),[we]),zt=e.useCallback(((e,t,r)=>{if(ae.current){if(ae.current!==Le[0])return void(ae.current=Le[0])}else ae.current=Le[0];const n=wt(t,e,ke.duration);n&&r.push(n)}),[Le[0],ke.duration]),At=e.useMemo((()=>{const e=Object.assign(Object.assign(Object.assign(Object.assign({margin:M?`${Fe}px ${Ne}px ${Ie}px ${$e}px`:"",height:Ke[1]&&"none"!==Ke[1]?Je+"px":"fit-content",width:Ke[0]&&"none"!==Ke[0]?_e+"px":"fit-content"},z.content&&{cursor:"grab"}),p&&!(null==Y?void 0:Y.type)&&{gap:`${Be}px ${He}px`}),k&&function(e,t,r,n,o){const l=(e,t)=>"full"===e?("x"===t?r[0]:r[1])-("x"===t?n:o):e;if("hybrid"!==t&&!Array.isArray(e)){const r=l(e,t)+"px";return"x"===t?{minWidth:r}:{minHeight:r}}let s,i;return Array.isArray(e)?[s,i]=e:s=i=e,{minWidth:l(s,"x")+"px",minHeight:l(i,"y")+"px"}}(k,d,De,Xe,We)),B&&{flexShrink:0});if(null==Y?void 0:Y.type)return Object.assign(Object.assign({},e),{position:"relative"});const t=Ke[1]?"wrap":void 0,r=1===Ue[0]?"y"===d?"column":"row":X;return Object.assign(Object.assign({},e),{display:"flex",flexDirection:r,flexWrap:t,justifyContent:y(W)})}),[M,[Fe,Ne,Ie,$e,Xe,We].join(),Ke[1],Je,_e,z.content,Me,[Be,He].join(),null==Y?void 0:Y.type,Se,d,De.join(),Re,Ue[0],X,W]);e.useEffect((()=>{(q||(null==Y?void 0:Y.type))&&(q||null===de.current.empty||(de.current.empty=null),Q())}),[we,null==Y?void 0:Y.type,Ee,pe.current,Le.length]),e.useEffect((()=>(((null==Y?void 0:Y.type)||H)&&(H&&H(!1),ne()),vt(),()=>{me.current.animationFrameId&&cancelAnimationFrame(me.current.animationFrameId),(()=>{for(const e of S.values())clearTimeout(e);S.clear()})()})),[]),e.useEffect((()=>{const e=se.current;if(!e)return;const t=z.wheel?t=>function(e,t,r,n){e.preventDefault(),r.animating||(r.targetScrollX=t.scrollLeft,r.targetScrollY=t.scrollTop),"x"===n?r.targetScrollX=g(r.targetScrollX+e.deltaY,0,t.scrollWidth-t.clientWidth+2):r.targetScrollY=g(r.targetScrollY+e.deltaY,0,t.scrollHeight-t.clientHeight+2),r.animating||(r.animating=!0,r.animationFrameId=requestAnimationFrame((function e(){let o=0;"x"===n?(t.scrollLeft+=.4*(r.targetScrollX-t.scrollLeft),o=Math.abs(t.scrollLeft-r.targetScrollX)):(t.scrollTop+=.4*(r.targetScrollY-t.scrollTop),o=Math.abs(t.scrollTop-r.targetScrollY)),o>2.5?r.animationFrameId=requestAnimationFrame(e):(r.animating=!1,null!==r.animationFrameId&&(cancelAnimationFrame(r.animationFrameId),r.animationFrameId=null))})))}(t,e,me.current,d):e=>e.preventDefault();return e.addEventListener("wheel",t,{passive:!1}),()=>{e.removeEventListener("wheel",t)}}),[d,z.wheel]),e.useEffect((()=>{if(!ke.value)return;const e=[];return("hybrid"===d?["x","y"]:[d]).forEach((t=>{const r="x"===t?0:1;"end"===ke.value[r]&&zt(t,"x"===t?at:ct,e)})),()=>{e.forEach((e=>e()))}}),[ke.value.join(),xe,ct,at,Ze,Qe]),e.useEffect((()=>{if(!ke.value)return;const e=[];return("hybrid"===d?["x","y"]:[d]).forEach((t=>{const r="x"===t?0:1;"number"==typeof ke.value[r]&&zt(t,ke.value[r],e)})),()=>{e.forEach((e=>e()))}}),[xe,null==F?void 0:F.updater]);const Ct=e.useCallback(((t,r,n,o)=>{var l;const s=Object.assign({width:Ge[0]?Ge[0]+"px":void 0,height:Ge[1]?Ge[1]+"px":void 0},(null==Y?void 0:Y.type)&&Object.assign({position:"absolute",top:r+"px",left:n+"px"},!Ge[0]&&1===Ue[0]&&{transform:"translateX(-50%)"})),i=C?e.createElement(e.Suspense,{fallback:L},o):o,c=(null===(l=null==q?void 0:q.clickTrigger)||void 0===l?void 0:l.selector)&&Tt;return e.createElement("div",Object.assign({key:t},Y||q?{[w]:""+t}:{},{className:"ms-object-box",style:s,onClick:c}),i)}),[C,!!L,Ge.join(),se.current,Ee,we,Ue[0]]),Lt=e.createElement("div",{className:"ms-objects-wrapper",ref:ie,onMouseDown:Mt,style:At},Le.map(((t,r)=>{var n,o,l;const i=e.Children.toArray(I).find((r=>e.isValidElement(r)&&r.key===t)),c=(null==Y?void 0:Y.stopLoadOnScroll)&&pe.current&&!de.current.loaded.includes(""+t)?L:(null===(n=de.current.empty)||void 0===n?void 0:n.includes(t))?"object"==typeof(null==q?void 0:q.mode)?q.mode.fallback:L:i,a="number"==typeof Ke[0]&&"number"==typeof Ke[1]||"firstChild"!==Ke[0]&&"firstChild"!==Ke[1]||0!==r?c:e.createElement(s,{onResize:Ot},c);if(!(null==Y?void 0:Y.type))return Ct(t,0,0,a);{const{elementTop:e,elementBottom:n,left:s,right:i}=dt[r],c="x"===d?qe:Pe,u=Ve+c>("x"===d?s:e)-tt&&("x"===d?i:n)-tt>0-c,m="hybrid"!==d||De[0]+qe>s-((null===(o=se.current)||void 0===o?void 0:o.scrollLeft)||0)&&i-((null===(l=se.current)||void 0===l?void 0:l.scrollLeft)||0)>0-qe;if(u&&m)return Ct(t,e,s,a)}}))),Ft=[{positionType:"x"===d?"left":"top",visibility:rt},{positionType:"x"===d?"right":"bottom",visibility:nt},..."hybrid"===d?[{positionType:"left",visibility:ot},{positionType:"right",visibility:lt}]:[]],Nt=e.createElement("div",{"morph-scroll":`〈♦${ee}〉`,className:r,ref:oe,style:{width:De[2]+"px",height:De[3]+"px"}},e.createElement("div",{className:"ms-content",ref:le,onMouseEnter:ht,onMouseLeave:ht,onTouchStart:ht,onTouchEnd:ht,style:Object.assign({position:"relative",width:De[0]+"px",height:De[1]+"px"},z.arrows&&Ae.size&&("x"===d?{left:Ae.size+"px"}:"y"===d?{top:Ae.size+"px"}:{top:Ae.size+"px",left:Ae.size+"px"}))},e.createElement("div",{className:"ms-element",ref:se,onScroll:yt,style:Object.assign(Object.assign(Object.assign({width:"100%",height:"100%"},mt),{overflow:null!==(J={x:Ze>De[0]?"scroll hidden":"hidden",y:Qe>De[1]?"hidden scroll":"hidden",hybrid:`${Ze>De[0]?"scroll":"hidden"} ${Qe>De[1]?"scroll":"hidden"}`,hide:"hidden"}[z.wheel||z.content?d:"hide"])&&void 0!==J?J:"hidden"}),"scroll"!==t||"boolean"!=typeof z.progressElement||!1===z.progressElement?{scrollbarWidth:"none"}:{})},Ge[0]&&Ge[1]?Lt:e.createElement(s,{onResize:jt,style:Object.assign({},mt)},Lt)),N&&Ft.map((({positionType:t,visibility:r})=>e.createElement(m,{key:"edge-"+t,edgeGradient:ze,visibility:r,edgeType:t}))),z.progressElement&&!0!==z.progressElement&&[{shouldRender:et>st,direction:d,thumbSize:st,thumbSpace:bt,objLengthPerSize:ft,progressReverseIndex:0},{shouldRender:"hybrid"===d&&Ze>it,direction:"x",thumbSize:it,thumbSpace:xt,objLengthPerSize:pt[0],progressReverseIndex:1}].filter((({shouldRender:e})=>e)).map((r=>e.createElement(u,{key:r.direction,type:t,direction:r.direction,progressReverse:"boolean"==typeof T?T:T[r.progressReverseIndex],size:De,progressTrigger:z,scrollBarOnHover:A,scrollBarEvent:"sliderMenu"===t?wt:Rt,thumbSize:r.thumbSize,thumbSpace:r.thumbSpace,objLengthPerSize:r.objLengthPerSize,sliderCheckLocal:vt,duration:ke.duration})))),z.arrows&&Ft.map((({positionType:t,visibility:r})=>e.createElement(f,{key:"arrow-"+t,activity:r,arrows:Ae,arrowType:t,handleArrow:gt,size:"hybrid"===d?De[0]+2*Ae.size:De[0]}))));return"auto"===l?e.createElement(s,{measure:"outer",onResize:Et},Nt):Nt};k.displayName="MorphScroll";const T={MorphScroll:k,ResizeTracker:s,IntersectionTracker:l};export{l as IntersectionTracker,k as MorphScroll,s as ResizeTracker,T as default};
1
+ import e,{useMemo as t,useEffect as r,useRef as n}from"react";const o=(e,t=!1,r)=>{let n=[];if(n=Array.isArray(e)?2===e.length?[e[1],e[0],e[1],e[0]]:[...e]:[e,e,e,e],t&&(n=[n[1],n[0],n[3],n[2]]),r){const e=[];for(let t=0;r>t;t++)e.push(n[t%4]);n=e}return n},l=({className:t,children:r,style:n,root:l,threshold:i,rootMargin:s,visibleContent:c=!1,onIntersection:a})=>{const[u,d]=e.useState(!1),m=e.useRef(null),p=e.useMemo((()=>{if(!s)return"";const e=o(s);return`${e[0]}px ${e[1]}px ${e[2]}px ${e[3]}px`}),[s]),h=e.useCallback((([e])=>{d(e.isIntersecting),a&&a({time:e.time,rootBounds:e.rootBounds,boundingClientRect:e.boundingClientRect,intersectionRect:e.intersectionRect,isIntersecting:e.isIntersecting,intersectionRatio:e.intersectionRatio,target:e.target})}),[a]);return e.useEffect((()=>{const e=new IntersectionObserver(h,{root:l,threshold:i,rootMargin:p});return m.current&&e.observe(m.current),()=>{e.disconnect()}}),[h,l,i,p]),e.createElement("div",{"intersection-tracker":"",className:t,ref:m,style:n},c||u?r:null)};l.displayName="IntersectionTracker";const i=({className:t,children:r,style:n,measure:o="inner",onResize:l})=>{const i=e.useRef(null);e.useEffect((()=>{const e=i.current;if(!e)return;const t=new ResizeObserver((e=>{for(const t of e)l&&l(t.contentRect)}));return t.observe(e),()=>{t.unobserve(e),t.disconnect()}}),[o,l]);const s={width:"max-content",height:"max-content"},c={inner:Object.assign({},s),outer:Object.assign({},{width:"100%",height:"100%"}),all:Object.assign({minWidth:"100%",minHeight:"100%"},s)};return e.createElement("div",{"resize-tracker":"",className:t,ref:i,style:Object.assign(Object.assign({willChange:"width, height"},c[o]),n)},r)};function s(e,n){const o=t((()=>function(e,t){let r=null,n=null;const o=(...o)=>{"requestFrame"===t?(null!==n&&cancelAnimationFrame(n),n=requestAnimationFrame((()=>{e(...o),n=null}))):(null!==r&&clearTimeout(r),r=setTimeout((()=>{e(...o),r=null}),t))};return o.cancel=()=>{null!==r&&(clearTimeout(r),r=null),null!==n&&(cancelAnimationFrame(n),n=null)},o}(e,n)),[n,e]);return r((()=>()=>{o.cancel()}),[o]),o}i.displayName="ResizeTracker";let c=1;const a=({type:t,direction:r,progressReverse:n,size:o,progressTrigger:l,scrollBarOnHover:i,scrollBarEvent:s,thumbSize:c,thumbSpace:a,objLengthPerSize:u,sliderCheckLocal:d,duration:m})=>{const p="sliderMenu"!==t?{onMouseDown:s,onTouchStart:s}:{},h=e.useMemo((()=>{if("scroll"===t||!r)return;const n=["hybrid","y"].includes(r)?"y":"x",i="x"===n?o[0]:o[1];return Array.from({length:u},((r,o)=>e.createElement("div",{key:o,className:"ms-slider-element",style:Object.assign({},"sliderMenu"===t&&{cursor:"pointer"}),onClick:"sliderMenu"===t?()=>{s(i*o,n,m,d)}:void 0},Array.isArray(null==l?void 0:l.progressElement)?l.progressElement[o]:null==l?void 0:l.progressElement)))}),[u,r,o,t,s,null==l?void 0:l.progressElement,m,d]);return e.createElement(e.Fragment,null,"scroll"===t?e.createElement("div",{className:"ms-bar",style:Object.assign(Object.assign(Object.assign({position:"absolute",width:"fit-content"},"x"===r?Object.assign({transformOrigin:"left top",height:o[0]+"px"},n?{top:0,transform:"rotate(-90deg) translateX(-100%)"}:{transform:"rotate(-90deg)"}):Object.assign({top:0,height:"100%"},n?{left:0}:{right:0})),0!=!(null==l?void 0:l.progressElement)&&{pointerEvents:"none"}),i&&{opacity:0,transition:"opacity 0.1s ease-in-out"})},e.createElement("div",Object.assign({className:"ms-thumb","data-direction":["hybrid","y"].includes(r)?"y":r},p,{style:Object.assign(Object.assign({height:c+"px",willChange:"transform, height",transform:`translateY(${a}px)`},(null==l?void 0:l.progressElement)&&{cursor:"grab"}),{transition:"height 0.05s ease-in-out"})}),null==l?void 0:l.progressElement)):u>1&&(null==l?void 0:l.progressElement)&&e.createElement("div",Object.assign({className:"ms-slider","data-direction":["hybrid","y"].includes(r)?"y":r},p,{style:Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex"},"slider"===t&&{cursor:"grab"}),i&&{opacity:0,transition:"opacity 0.1s ease-in-out"}),"x"===r?Object.assign({transformOrigin:"left top",left:"50%",transform:"translateX(-50%)"},n?{top:0}:{bottom:0}):Object.assign({flexDirection:"column",top:"50%",transform:"translateY(-50%)"},n?{left:0}:{right:0}))}),h))};a.displayName="ScrollBar";var u=e.memo(a);const d=({edgeGradient:t,visibility:r,edgeType:n})=>{if(!t)return null;const o=Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",pointerEvents:"none",transition:"opacity 0.1s ease-in-out"},t.color&&{background:t.color&&`linear-gradient(${"right"===n||"left"===n?"90deg, ":""}${t.color}, transparent)`}),"right"===n||"left"===n?{height:"100%",width:t.size+"px",top:0}:{width:"100%",height:t.size+"px",left:0}),n?{[n]:0}:{}),"right"===n?{transform:"scaleX(-1)"}:"bottom"===n?{transform:"scaleY(-1)"}:{});return e.createElement("div",{className:"ms-edge"+(n?" "+n:""),style:Object.assign(Object.assign({},o),{opacity:r?1:0})})};d.displayName="Edge";var m=e.memo(d);const p=({activity:t,arrows:r,arrowType:n,handleArrow:o,size:l})=>{const i=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",width:r.size+"px"},n?{[n]:0}:{}),"top"===n&&{transform:"rotate(-90deg) translateX(-100%)",transformOrigin:"left top"}),"bottom"===n&&{transform:"rotate(90deg) translateX(-100%)",transformOrigin:"left bottom"}),"left"===n&&{transform:"scaleX(-1)"}),["top","bottom"].includes(n)?{height:l+"px"}:{height:"100%",top:0});return e.createElement("div",{className:`ms-arrow-box ${n}${t?" active":""}`,style:Object.assign({},i),onClick:()=>o(n)},r.element)};p.displayName="Arrow";var h=e.memo(p);function f(e,t){return e>t?Math.floor(e/t):1}function g(e,t=0,r=1/0){return Math.max(t,Math.min(Math.round(e),r))}const y=(e,t,r)=>{if(!t)return;const n=t.querySelectorAll("."+("scroll"===e?"ms-thumb":"ms-slider"));n.length>0&&(r.current=n)},v=e=>e?"start"===e?"flex-start":"center"===e?"center":"flex-end":void 0;function b(e,t,r=0,n=0){return o=>{var l,i,s,c;const a={width:(null!==(l=o.width)&&void 0!==l?l:0)-r,height:(null!==(i=o.height)&&void 0!==i?i:0)-n};(null===(s=e.current)||void 0===s?void 0:s.width)===a.width&&(null===(c=e.current)||void 0===c?void 0:c.height)===a.height||(e.current=a,t())}}function x(t){const r=[],n=t=>{if(null===t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)r.push(t+"");else if("string"==typeof t)r.push(t);else if("function"==typeof t)r.push("<function>");else if(e.isValidElement(t))r.push("<react-node>");else if(Array.isArray(t))t.forEach(n);else if("object"==typeof t){const e=Object.entries(t).sort((([e],[t])=>e.localeCompare(t)));for(const[,t]of e)n(t)}else void 0===t&&r.push("<undefined>")};return n(t),r.join("/")}function E(e){var t,r,n;const o={x:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientX:e.mouseEvent.clientX,y:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientY:e.mouseEvent.clientY,leftover:null!==(r=null===(t=e.prevCoordsRef.current)||void 0===t?void 0:t.leftover)&&void 0!==r?r:0},l=null!==(n=e.prevCoordsRef.current)&&void 0!==n?n:o,i={x:o.x-l.x,y:o.y-l.y};e.prevCoordsRef.current=o;const s=t=>{if(!e.scrollElementRef||!e.objectsWrapperRef)return;let r=0;const n="x"===t?"movementX"in e.mouseEvent?e.mouseEvent.movementX:i.x:"movementY"in e.mouseEvent?e.mouseEvent.movementY:i.y,o=e.scrollElementRef;if("thumb"===e.clicked){const i=e.objectsWrapperRef,s=getComputedStyle(i),c="x"===t?o.clientWidth:o.clientHeight,a="x"===t?i.clientWidth+parseFloat(s.marginLeft)+parseFloat(s.marginRight):i.clientHeight+parseFloat(s.marginTop)+parseFloat(s.marginBottom),u=c-e.thumbSize,d=a-c;if(0>=u||0>=d)return;const m=n*(d/u)+l.leftover,p=Math.trunc(m),h=m-p;e.prevCoordsRef.current.leftover=h,r=p}else r=-n;"x"===t?(o.scrollLeft+=r,e.scrollStateRef.targetScrollX=o.scrollLeft):(o.scrollTop+=r,e.scrollStateRef.targetScrollY=o.scrollTop)},c=t=>{const r=e.objectsWrapperRef;if(!r)return;const n="slider"===e.type&&"wrapp"===e.clicked?-1:1,o=i[t]*n,l="x"===t?e.sizeLocal[0]:e.sizeLocal[1],s="x"===t?r.offsetWidth:r.offsetHeight,c="x"===t?e.scrollElementRef.scrollLeft:e.scrollElementRef.scrollTop;e.numForSliderRef.current+=Math.abs(o),e.numForSliderRef.current>6&&!e.isScrollingRef.current&&(o>0&&s>c+l?e.smoothScroll(c+l,t,e.duration):0>o&&c>0&&e.smoothScroll(c-l,t,e.duration),e.numForSliderRef.current=0)},a=t=>{"thumb"===e.clicked?s(t):"wrapp"===e.clicked?"slider"===e.type?c(t):s(t):"slider"===e.clicked&&c(t)};"hybrid"===e.direction?"wrapp"===e.clicked?(a("x"),a("y")):e.axisFromAtr&&a(e.axisFromAtr):a(e.direction||"y")}function j(e){if(e.controller.abort(),document.body.style.removeProperty("cursor"),["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),e.clickedObject.current="none",e.scrollBarOnHover){let t=e.mouseEvent.target,r=!1;for(;t&&t!==document.body;){if(t===e.scrollContentRef){r=!0;break}t=t.parentNode}r||e.mouseOnRefHandle(e.mouseEvent)}e.prevCoordsRef.current=null,e.triggerUpdate()}const w=e=>{e&&("grab"===e.style.cursor?(e.style.cursor="grabbing",e.classList.add("active")):"grabbing"===e.style.cursor&&(e.style.cursor="grab",e.classList.remove("active")))},O="wrap-id",S=new Map,R=(e,t,r)=>{M(e);const n=setTimeout((()=>{t(),S.delete(e)}),r);S.set(e,n)},M=e=>{const t=S.get(e);t&&(clearTimeout(t),S.delete(e))},k=({className:t,children:r,type:l="scroll",direction:a="y",scrollPosition:d,onScrollValue:p,isScrolling:M,size:k,objectsSize:T,crossCount:z,gap:A,wrapperMargin:C,wrapperMinSize:L,wrapperAlign:F,elementsAlign:N,elementsDirection:I="row",edgeGradient:$,progressTrigger:X={wheel:!0},progressReverse:W=!1,scrollBarOnHover:B=!1,render:H,emptyElements:Y,suspending:P=!1,fallback:D})=>{var q,K,V,U,G,_;const J=s((()=>{Tt()}),40),Q=s((()=>{kt()}),34),Z=function(){const e=n(null);return null===e.current&&(e.current=""+c++),e.current}();if(!k)throw Error(`Prop "size" is not provided\nMorphScroll〈♦${Z}〉`);Object.keys(X).length;const[ee,te]=e.useState(0),re=()=>{te((e=>"number"==typeof e&&1e3>e?e+1:0))},ne=e.useRef(null),oe=e.useRef(null),le=e.useRef(null),ie=e.useRef(null),se=e.useRef([]),ce=e.useRef(null),ae=e.useRef("none"),ue=e.useRef({loaded:[],empty:[]}),de=e.useRef({targetScrollY:0,targetScrollX:0,animating:!1,animationFrameId:0}),me=e.useRef(!1),pe=e.useRef(0),he=e.useRef(null),fe=e.useRef(!1);function ge(){return e.useRef({width:0,height:0})}const ye=ge(),ve=ge(),be=ge(),[xe,Ee,je,we,Oe,Se,Re,Me,ke,Te]=function(...e){return e.map(x)}(null==d?void 0:d.value,H,k,T,Y,L,F,A,X,ue.current.empty),ze=e.useMemo((()=>{var e,t;return{value:"number"==typeof(null==d?void 0:d.value)||"string"==typeof(null==d?void 0:d.value)?[d.value,d.value]:null!==(e=null==d?void 0:d.value)&&void 0!==e?e:[null],duration:null!==(t=null==d?void 0:d.duration)&&void 0!==t?t:200}}),[xe,null==d?void 0:d.duration]),Ae={color:null,size:40},Ce=e.useMemo((()=>"object"==typeof $?Object.assign(Object.assign({},Ae),$):Ae),[$]),Le=e.useMemo((()=>Object.assign(Object.assign({},Ae),"object"==typeof X.arrows?X.arrows:{})),[ke]),Fe=e.useCallback((t=>{if(null==t)return[];if(e.isValidElement(t)){const r=t;return r.type===e.Fragment?e.Children.toArray(r.props.children).flatMap(Fe):[r]}return[t]}),[]),Ne=e.useMemo((()=>e.Children.toArray(r).flatMap(Fe).map((t=>e.isValidElement(t)&&t.key?t.key+"":null)).filter((e=>null!==e)).filter((e=>{var t;return"clear"!==(null==Y?void 0:Y.mode)||!(null===(t=ue.current.empty)||void 0===t?void 0:t.includes(e))}))),[r,Fe,Oe,Te]),[Ie,$e,Xe,We]=C?o(C):[0,0,0,0],Be=Ie+Xe,He=We+$e,[Ye,Pe]=e.useMemo((()=>{var e,t;return"number"==typeof A?[A,A]:Array.isArray(A)?[null!==(e=A[1])&&void 0!==e?e:0,null!==(t=A[0])&&void 0!==t?t:0]:[0,0]}),[A]),De=e.useMemo((()=>o((null==H?void 0:H.rootMargin)||0,"x"===a)),[Ee,a]),[qe,Ke]=De?[De[2],De[0]]:[0,0],Ve=e.useMemo((()=>{const[e,t]=Array.isArray(k)?k:"number"==typeof k?[k,k]:[ye.current.width,ye.current.height];if(!X.arrows||!Le.size)return[e,t,e,t];const r=2*Le.size;let n=e,o=t;return"x"===a?n=e-r:"y"===a?o=t-r:"hybrid"===a&&(n=e-r,o=t-r),[n,o,e,t]}),[je,ke,a,Le.size,ye.current.height,ye.current.width]),Ue="x"===a?Ve[0]:Ve[1],Ge=e.useMemo((()=>T?Array.isArray(T)?T:o(T,!0,2):[null,null]),[we]),_e=e.useMemo((()=>{const e=(e,t)=>"number"==typeof e?e:"firstChild"===e?t:0;return[e(Ge[0]&&"none"!==Ge[0]&&"size"!==Ge[0]?Ge[0]:"y"===a&&"none"!==Ge[0]||"size"===Ge[0]?Ve[0]:0,be.current.width),e(Ge[1]&&"none"!==Ge[1]&&"size"!==Ge[1]?Ge[1]:"x"===a&&"none"!==Ge[1]||"size"===Ge[1]?Ve[1]:0,be.current.height)]}),[Ge,a,be.current.width,be.current.height,Ve.join()]),Je=e.useMemo((()=>{const e="x"===a,t="row"===I,r="column"===I,n=e?Ve[1]:Ve[0],o=e?_e[1]+Pe:_e[0]+Ye,l="hybrid"===a?o*(Ne.length+1)-o:n,i=Math.floor(l/o)||1,s=z&&i>=z?"hybrid"===a?Math.ceil(i/z):z:i,c=s>1&&s<Ne.length?Math.ceil(Ne.length/s):s>Ne.length?1:Ne.length,u=z&&z<Ne.length,d=e=>Number.isFinite(e)&&e>0?e:1;if("hybrid"===a){const e=u?t?z:s:t?Ne.length:1,n=u?r?z:s:r?Ne.length:1;return[d(e),d(n)]}return[d(s),d(c)]}),[I,Pe,Ye,_e.join(),Ne.length,a,Ve.join(),z]),Qe=e.useMemo((()=>{const e=Je[0]?Je[0]*Pe-Pe:0,t="x"===a?Je[1]:Je[0];return _e[0]?(_e[0]+Pe)*t-Pe:(null==H?void 0:H.type)?be.current.width+e:ve.current.width}),[a,_e[0],Je.join(),Pe,ve.current.width,be.current.width,null==H?void 0:H.type]),Ze=e.useMemo((()=>{const e=1>Je[1]?1:Je[0]*Ye-Ye;return _e[1]?"x"===a?(_e[1]+Ye)*Je[0]-Ye:(_e[1]+Ye)*Je[1]-Ye:(null==H?void 0:H.type)?be.current.height+e:ve.current.height}),[a,_e[1],Je.join(),Ye,ve.current.height,be.current.height,null==H?void 0:H.type]),et=e.useMemo((()=>Ze+Be),[Ze,Be]),tt=e.useMemo((()=>Qe+He),[Qe,He]),rt="x"===a?tt:et,nt="x"===a?(null===(q=le.current)||void 0===q?void 0:q.scrollLeft)||0:(null===(K=le.current)||void 0===K?void 0:K.scrollTop)||0,ot=nt>1&&!0,lt=rt>Math.round(nt+Ue);let it=!1,st=!1;"hybrid"===a&&(it=((null===(V=le.current)||void 0===V?void 0:V.scrollLeft)||0)>1&&!0,st=Math.round(((null===(U=le.current)||void 0===U?void 0:U.scrollLeft)||0)+Ve[0])<tt);const ct=e.useMemo((()=>{if(!X.progressElement||!rt)return 0;const e=Math.round(Ue/rt*Ue);return!Number.isFinite(e)||0>e?0:e}),[Ue,rt,X.progressElement]),at=e.useMemo((()=>{if(!X.progressElement)return 0;const e=Math.round(Ve[0]/tt*Ve[0]);return!Number.isFinite(e)||0>e?0:e}),[Ve[0],tt,X.progressElement]),ut=e.useMemo((()=>Ue?rt-Ue:rt),[rt,Ue]),dt=e.useMemo((()=>Ve[0]?tt-Ve[0]:tt),[tt,Ve[0]]),mt=e.useCallback((()=>{if(!(null==H?void 0:H.type)||1>=Je[0])return[];const e=Array.from({length:Ne.length},((e,t)=>t)),t=Array.from({length:Je[0]},(()=>[])),r="x"===a&&"column"===I||"x"!==a&&"row"===I;return e.forEach((e=>{const n=r?e%Je[0]:Math.floor(e/Je[1]);t[n]&&t[n].push(e)})),t}),[Ne.length,Je.join(),null==H?void 0:H.type,I,a]),pt=e.useMemo((()=>{if(!(null==H?void 0:H.type))return[{elementTop:0,elementBottom:0,left:0,right:0}];let e=[],t=0;if(N){const r=Array.from({length:Ne.length},((e,t)=>t)),n=Math.abs(Math.floor(Ne.length/Je[0])*Je[0]-Ne.length);e=n?r.slice(-n):[],"center"===N?t=(_e[0]+Pe)*(Je[0]-n)/2:"end"===N&&(t=(_e[0]+Pe)*(Je[0]-n))}return Ne.map(((r,n)=>{const o=function(e,t){for(let r=0;r<t.length;r++){const n=t[r].indexOf(e);if(-1!==n)return["x"===a?n:r,["hybrid","y"].includes(a)?n:r]}return[0,0]}(n,mt()),l=e.length>0&&e.includes(n)?t:0,i=function(e){const t="x"===a?l:0;return e>0?t+(_e[1]+Ye)*e:t}(Je[0]>1||["hybrid","x"].includes(a)?o[1]:n),s=_e[1]?i+_e[1]:i,c=function(e){const t="x"===a?0:l;return e>0?t+(_e[0]+Pe)*e:t}(1===Je[0]&&"x"===a?n:o[0]);return{elementTop:i,elementBottom:s,left:c,right:c+_e[0]}}))}),[a,Je[0],_e.join(),Ye,Pe,null==H?void 0:H.type,I,N,mt,Ne.join()]),ht=e.useMemo((()=>(null==Ve?void 0:Ve.length)&&F?function(e,t,r,n){const[o,l="start"]="string"==typeof e?[e,e]:e,i={display:"flex"};return t[0]>r&&(i.justifyContent=v(o)),t[1]>n&&(i.alignItems=v(l)),i}(F,Ve,tt,et):{}),[F,Ve.join(),et,tt]),ft=e.useMemo((()=>[f(tt,Ve[0]),f(et,Ve[1])]),[tt,et,Ve.join()]),gt=e.useMemo((()=>"x"===a?ft[0]:ft[1]),[a,ft[0],ft[1]]),yt=s(b(ye,re),40),vt=s(b(ve,re,He,Be),40),bt=s(b(be,re),40),xt=e.useCallback(((e,t,r,n)=>{const o=le.current;return o?function(e,t,r,n,o){let l;if(!t&&!n)return null;const i=performance.now(),s=t.scrollTop,c=t.scrollLeft,a=u=>{const d=Math.min((u-i)/r,1);"y"===e?t.scrollTop=s+(n-s)*d:"x"===e&&(t.scrollLeft=c+(n-c)*d),1>d?l=requestAnimationFrame(a):null==o||o()};return l=requestAnimationFrame(a),()=>cancelAnimationFrame(l)}(t,o,r,e,n):null}),[]),Et=e.useCallback(((e,t,r)=>{if(ce.current){if(ce.current!==Ne[0])return void(ce.current=Ne[0])}else ce.current=Ne[0];const n=xt(t,e,ze.duration);n&&r.push(n)}),[Ne[0],ze.duration,xt]),jt=e.useMemo((()=>{const e=Object.assign(Object.assign(Object.assign(Object.assign({margin:C?`${Ie}px ${$e}px ${Xe}px ${We}px`:"",height:Ge[1]&&"none"!==Ge[1]?Ze+"px":"fit-content",width:Ge[0]&&"none"!==Ge[0]?Qe+"px":"fit-content"},X.content&&{cursor:"grab"}),A&&!(null==H?void 0:H.type)&&{gap:`${Ye}px ${Pe}px`}),L&&function(e,t,r,n,o){const l=(e,t)=>"full"===e?("x"===t?r[0]:r[1])-("x"===t?n:o):e;if("hybrid"!==t&&!Array.isArray(e)){const r=l(e,t)+"px";return"x"===t?{minWidth:r}:{minHeight:r}}let i,s;return Array.isArray(e)?[i,s]=e:i=s=e,{minWidth:l(i,"x")+"px",minHeight:l(s,"y")+"px"}}(L,a,Ve,He,Be)),F&&{flexShrink:0});if(null==H?void 0:H.type)return Object.assign(Object.assign({},e),{position:"relative"});const t=Ge[1]?"wrap":void 0,r=1===Je[0]?"y"===a?"column":"row":I;return Object.assign(Object.assign({},e),{display:"flex",flexDirection:r,flexWrap:t,justifyContent:v(N)})}),[C,Re,Se,[Ie,$e,Xe,We,He,Be,Ye,Pe].join(),Ve.join(),Me,Ge[1],Ze,Qe,X.content,Me,null==H?void 0:H.type,a,Je[0],I,N]),wt=e.useCallback((e=>{if(!B)return;const t=()=>((e,t,r,n)=>{e&&e.querySelectorAll(".ms-bar").forEach(((e,t)=>{const o=e;["mouseleave","mouseup","touchend"].includes(r.type)?(o.style.opacity="0",o.classList.remove("hover"),o.classList.add("leave"),n(`mouseOnRef${t}-anim`,(()=>o.classList.remove("leave")),200)):(o.style.opacity="1",o.classList.add("hover"))}))})(oe.current,0,e,R);"mouseleave"===e.type?!["thumb","slider","wrapp"].includes(ae.current)&&t():t()}),[B]),Ot=e.useCallback(((e,t="mousedown",r)=>{const n=e||("scroll"===l?"thumb":"slider");if("wrapp"===e&&!X.content||["thumb","slider"].includes(n)&&!X.progressElement)return;y(l,ne.current,se);let o=null;r&&(o=r.getAttribute("data-direction")),function(e){const t=new AbortController,{signal:r}=t;e.clickedObject.current=e.clicked,e.triggerUpdate(),"mousedown"===e.eventType?(["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),document.addEventListener("mousemove",(t=>E(Object.assign(Object.assign({},e),{mouseEvent:t}))),{signal:r}),document.addEventListener("mouseup",(r=>j(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})):"touchstart"===e.eventType&&(document.addEventListener("touchmove",(t=>{t.preventDefault(),E(Object.assign(Object.assign({},e),{mouseEvent:t}))}),{signal:r,passive:!1}),document.addEventListener("touchend",(r=>j(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})),document.body.style.cursor="grabbing"}({eventType:t,scrollElementRef:le.current,objectsWrapperRef:ie.current,scrollBar:r||null,clickedObject:ae,scrollContentRef:oe.current,scrollStateRef:de.current,type:l,scrollBarOnHover:B,mouseOnEl:w,mouseOnRefHandle:wt,triggerUpdate:re,direction:a,smoothScroll:xt,sizeLocal:[Ve[0],Ve[1]],clicked:n,numForSliderRef:pe,isScrollingRef:me,prevCoordsRef:he,thumbSize:"x"===o?at:ct,axisFromAtr:o,duration:ze.duration})}),[a,l,X.content,X.progressElement,Ve.join(),ct,at,ze.duration,xt,wt,B]),St=e.useCallback((e=>{Ot(null,e.type,e.target)}),[Ot]),Rt=e.useCallback((()=>{Ot("wrapp")}),[Ot]),Mt=e.useCallback((e=>{le.current&&(({arrowType:e,scrollElement:t,wrapSize:r,scrollSize:n,smoothScroll:o,duration:l})=>{const i=r[0],s=r[1],c=t.scrollTop,a=t.scrollLeft,u=["top","bottom"].includes(e)?s:i,d=(e,t)=>o(g(e,0,u),t,l);"top"===e&&c>0?d(c-n[1],"y"):"left"===e&&a>0&&d(a-n[0],"x"),"bottom"===e&&c+n[1]!==s?d(c+n[1],"y"):"right"===e&&a+n[0]!==i&&d(a+n[0],"x")})({arrowType:e,scrollElement:le.current,wrapSize:[tt,et],scrollSize:Ve,smoothScroll:xt,duration:ze.duration})}),[Ve.join(),tt,et,ze.duration,xt]),kt=e.useCallback((()=>{y(l,ne.current,se);const e=le.current;oe.current&&e&&0!==se.current.length&&((e,t,r,n)=>{!function(){var o,l,i,s;const c=null!==(l=null===(o=t[0])||void 0===o?void 0:o.querySelectorAll(".ms-slider-element"))&&void 0!==l?l:[],a=null!==(s=null===(i=t[1])||void 0===i?void 0:i.querySelectorAll(".ms-slider-element"))&&void 0!==s?s:[];function u(e,t,r,n){const o="x"===n?r.scrollLeft:r.scrollTop;e.forEach(((e,r)=>{const l="x"===n?t[0]:t[1];o>=l*r&&l*(r+1)>o?e.classList.add("active"):e.classList.remove("active")}))}c.length>0&&u(c,r,e,n),a.length>0&&u(a,r,e,"x")}()})(e,se.current,Ve,a)}),[Ve.join(),a,le,oe,l]),Tt=e.useCallback((()=>{ne.current&&((e,t,r,n)=>{const{allIds:o,emptyKeysRaw:l}=(()=>{const t=[],r=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e instanceof Element&&e.hasAttribute(O)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let o=n.nextNode();for(;o;){const e=o,l=e.getAttribute(O);l&&(t.push(l),0===e.children.length&&r.push(l)),o=n.nextNode()}return{allIds:t,emptyKeysRaw:r}})(),i=new Set(t.current.loaded);o.forEach((e=>i.add(e)));let s=null;if(t.current.empty){const e=new Set(t.current.empty);l.forEach((t=>e.add(t))),s=Array.from(e)}t.current={loaded:"lazy"===n?Array.from(i):o.map((e=>e)),empty:s},r()})(ne.current,ue,re,null==H?void 0:H.type)}),[Ee]),zt=e.useCallback((e=>{(null==Y?void 0:Y.clickTrigger)&&((e,t,r,n)=>{const o=e.target;if(!o.closest(r.selector))return;const l=o.closest(`[${O}]`);l&&l.classList.add("remove"),t("emptyKeys-anim",(()=>{l&&l.classList.remove("remove"),n()}),r.delay||0)})(e,R,Y.clickTrigger,Tt)}),[Oe,Tt]),At=e.useCallback((()=>{const e=le.current;e&&(null==p||p(e.scrollLeft,e.scrollTop),me.current=!0,null==M||M(!0),R("handleScroll-anim",(()=>{me.current=!1,null==M||M(!1),(null==H?void 0:H.type)?re():J()}),200),"slider"===l&&Q(),(null==H?void 0:H.type)||J(),re())}),[p,M,l,null==H?void 0:H.type,Q,Tt]),Ct=g(nt/ut*(Ue-ct),0,Ue-ct),Lt=g(((null===(G=le.current)||void 0===G?void 0:G.scrollLeft)||0)/dt*(Ve[0]-Ve[0]/tt*Ve[0]),0,Ve[0]-at),Ft=e.useCallback((e=>{const t="object"==typeof X.wheel&&X.wheel.changeDirectionKey?X.wheel.changeDirectionKey:"KeyX";e.code!==t||"hybrid"!==a||fe.current||(e.stopPropagation(),fe.current=!0,re())}),[a,JSON.stringify(X.wheel)]),Nt=e.useCallback((e=>{fe.current&&(e.stopPropagation(),fe.current=!1,re())}),[]);e.useEffect((()=>{(Y||(null==H?void 0:H.type))&&(Y||null===ue.current.empty||(ue.current.empty=null),J())}),[Oe,null==H?void 0:H.type,me.current,Ne.join(),Tt]),e.useEffect((()=>{const e=de.current.animationFrameId;return((null==H?void 0:H.type)||M)&&M&&(M(!1),re()),kt(),()=>{e&&cancelAnimationFrame(e),(()=>{for(const e of S.values())clearTimeout(e);S.clear()})()}}),[]),e.useEffect((()=>{const e=le.current;if(!e)return;const t=e=>e.preventDefault(),r="hybrid"===a&&"object"==typeof X.wheel&&X.wheel.changeDirection?"x":a,n="hybrid"===a&&Ze+Be<=Ve[1]||fe.current?["hybrid","y"].includes(r)?"x":"y":r,o=X.wheel?e=>{t(e),function(e,t,r){const n=e.target.closest(".ms-element");n.matches(":focus")||n.focus(),t.animating||(t.targetScrollX=n.scrollLeft,t.targetScrollY=n.scrollTop),"x"===r?t.targetScrollX=g(t.targetScrollX+e.deltaY,0,n.scrollWidth-n.clientWidth+2):t.targetScrollY=g(t.targetScrollY+e.deltaY,0,n.scrollHeight-n.clientHeight+2),t.animating||(t.animating=!0,t.animationFrameId=requestAnimationFrame((function e(){let o=0;"x"===r?(n.scrollLeft+=.4*(t.targetScrollX-n.scrollLeft),o=Math.abs(n.scrollLeft-t.targetScrollX)):(n.scrollTop+=.4*(t.targetScrollY-n.scrollTop),o=Math.abs(n.scrollTop-t.targetScrollY)),o>2.5?t.animationFrameId=requestAnimationFrame(e):(t.animating=!1,null!==t.animationFrameId&&(cancelAnimationFrame(t.animationFrameId),t.animationFrameId=null))})))}(e,de.current,n)}:t;return e.addEventListener("wheel",o,{passive:!1}),()=>{e.removeEventListener("wheel",o)}}),[a,JSON.stringify(X.wheel),Ze,Ve[1],Be,fe.current]),e.useEffect((()=>{if(!ze.value)return;const e=[];return("hybrid"===a?["x","y"]:[a]).forEach((t=>{const r="x"===t?0:1;"end"===ze.value[r]&&Et(t,"x"===t?dt:ut,e)})),()=>{e.forEach((e=>e()))}}),[a,ze.value.join(),xe,ut,dt,tt,et]),e.useEffect((()=>{if(!ze.value)return;const e=[];return("hybrid"===a?["x","y"]:[a]).forEach((t=>{const r="x"===t?0:1;"number"==typeof ze.value[r]&&Et(t,ze.value[r],e)})),()=>{e.forEach((e=>e()))}}),[xe,null==d?void 0:d.updater,a,Et,ze.value.join()]);const It=e.useCallback(((t,r,n,o)=>{var l;const i=Object.assign({width:_e[0]?_e[0]+"px":void 0,height:_e[1]?_e[1]+"px":void 0},(null==H?void 0:H.type)&&Object.assign({position:"absolute",top:r+"px",left:n+"px"},!_e[0]&&1===Je[0]&&{transform:"translateX(-50%)"})),s=P?e.createElement(e.Suspense,{fallback:D},o):o,c=(null===(l=null==Y?void 0:Y.clickTrigger)||void 0===l?void 0:l.selector)&&zt;return e.createElement("div",Object.assign({key:t},H||Y?{[O]:""+t}:{},{className:"ms-object-box",style:i,onClick:c}),s)}),[P,!!D,_e.join(),Ee,Oe,Je[0],zt]),$t=e.createElement("div",{className:"ms-objects-wrapper",ref:ie,onMouseDown:Rt,style:jt},Ne.map(((t,n)=>{var o,l,s;const c=e.Children.toArray(r).find((r=>e.isValidElement(r)&&r.key===t)),u=(null==H?void 0:H.stopLoadOnScroll)&&me.current&&!ue.current.loaded.includes(""+t)?D:(null===(o=ue.current.empty)||void 0===o?void 0:o.includes(t))?"object"==typeof(null==Y?void 0:Y.mode)?Y.mode.fallback:D:c,d="number"==typeof Ge[0]&&"number"==typeof Ge[1]||"firstChild"!==Ge[0]&&"firstChild"!==Ge[1]||0!==n?u:e.createElement(i,{onResize:bt},u);if(!(null==H?void 0:H.type))return It(t,0,0,d);{const{elementTop:e,elementBottom:r,left:o,right:i}=pt[n],c="x"===a?qe:Ke,u=Ue+c>("x"===a?o:e)-nt&&("x"===a?i:r)-nt>0-c,m="hybrid"!==a||Ve[0]+qe>o-((null===(l=le.current)||void 0===l?void 0:l.scrollLeft)||0)&&i-((null===(s=le.current)||void 0===s?void 0:s.scrollLeft)||0)>0-qe;if(u&&m)return It(t,e,o,d)}}))),Xt=[{positionType:"x"===a?"left":"top",visibility:ot},{positionType:"x"===a?"right":"bottom",visibility:lt},..."hybrid"===a?[{positionType:"left",visibility:it},{positionType:"right",visibility:st}]:[]],Wt=e.createElement("div",{"morph-scroll":`〈♦${Z}〉`,className:t,ref:ne,style:{width:Ve[2]+"px",height:Ve[3]+"px"}},e.createElement("div",{className:"ms-content",ref:oe,onMouseEnter:wt,onMouseLeave:wt,onTouchStart:wt,onTouchEnd:wt,style:Object.assign({position:"relative",width:Ve[0]+"px",height:Ve[1]+"px"},X.arrows&&Le.size&&("x"===a?{left:Le.size+"px"}:"y"===a?{top:Le.size+"px"}:{top:Le.size+"px",left:Le.size+"px"}))},e.createElement("div",{className:"ms-element",ref:le,onScroll:At,onKeyDown:Ft,onKeyUp:Nt,style:Object.assign(Object.assign(Object.assign({width:"100%",height:"100%",outline:"none"},ht),{overflow:null!==(_={x:tt>Ve[0]?"scroll hidden":"hidden",y:et>Ve[1]?"hidden scroll":"hidden",hybrid:`${tt>Ve[0]?"scroll":"hidden"} ${et>Ve[1]?"scroll":"hidden"}`,hide:"hidden"}[X.wheel||X.content?a:"hide"])&&void 0!==_?_:"hidden"}),"scroll"!==l||"boolean"!=typeof X.progressElement||!1===X.progressElement?{scrollbarWidth:"none"}:{})},_e[0]&&_e[1]?$t:e.createElement(i,{onResize:vt,style:Object.assign({},ht)},$t)),$&&Xt.map((({positionType:t,visibility:r})=>e.createElement(m,{key:"edge-"+t,edgeGradient:Ce,visibility:r,edgeType:t}))),X.progressElement&&!0!==X.progressElement&&[{shouldRender:rt>ct,direction:a,thumbSize:ct,thumbSpace:Ct,objLengthPerSize:gt,progressReverseIndex:0},{shouldRender:"hybrid"===a&&tt>at,direction:"x",thumbSize:at,thumbSpace:Lt,objLengthPerSize:ft[0],progressReverseIndex:1}].filter((({shouldRender:e})=>e)).map((t=>e.createElement(u,{key:t.direction,type:l,direction:t.direction,progressReverse:"boolean"==typeof W?W:W[t.progressReverseIndex],size:Ve,progressTrigger:X,scrollBarOnHover:B,scrollBarEvent:"sliderMenu"===l?xt:St,thumbSize:t.thumbSize,thumbSpace:t.thumbSpace,objLengthPerSize:t.objLengthPerSize,sliderCheckLocal:kt,duration:ze.duration})))),X.arrows&&Xt.map((({positionType:t,visibility:r})=>e.createElement(h,{key:"arrow-"+t,activity:r,arrows:Le,arrowType:t,handleArrow:Mt,size:"hybrid"===a?Ve[0]+2*Le.size:Ve[0]}))));return"auto"===k?e.createElement(i,{measure:"outer",onResize:yt},Wt):Wt};k.displayName="MorphScroll";const T={MorphScroll:k,ResizeTracker:i,IntersectionTracker:l};export{l as IntersectionTracker,k as MorphScroll,i as ResizeTracker,T as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "morphing-scroll",
3
- "version": "2.2.21",
3
+ "version": "2.3.0",
4
4
  "description": "React library for custom object scrolling and scrollbar styling",
5
5
  "author": "Georg Schilin",
6
6
  "license": "MIT",
@@ -316,7 +316,6 @@ type MorphScrollT = {
316
316
  * @note
317
317
  * - *`progressElement` can be thumb or slider, use props `type`*
318
318
  * - *If `progressElement` is true and `type` is "scroll", the default browser scroll element will be used*
319
- * - *`arrows` can be designed with their className or you can provide a custom element*
320
319
  *
321
320
  * @example
322
321
  * ```tsx
@@ -328,7 +327,9 @@ type MorphScrollT = {
328
327
  * ```
329
328
  */
330
329
  progressTrigger: {
331
- wheel?: boolean;
330
+ wheel?:
331
+ | boolean
332
+ | { changeDirection?: boolean; changeDirectionKey?: string };
332
333
  content?: boolean;
333
334
  progressElement?: boolean | React.ReactNode;
334
335
  arrows?: boolean | { size?: number; element?: React.ReactNode };