@finsweet/webflow-apps-utils 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/providers/GlobalProvider.stories.d.ts +5 -0
  4. package/dist/providers/GlobalProvider.stories.js +419 -0
  5. package/dist/providers/GlobalProviderDemo.svelte +266 -0
  6. package/dist/providers/GlobalProviderDemo.svelte.d.ts +3 -0
  7. package/dist/providers/configuratorUtils.d.ts +11 -14
  8. package/dist/providers/configuratorUtils.js +68 -115
  9. package/dist/providers/index.d.ts +1 -1
  10. package/dist/providers/index.js +1 -1
  11. package/dist/router/Router.stories.d.ts +6 -0
  12. package/dist/router/Router.stories.js +564 -0
  13. package/dist/router/examples/RouterExample.svelte +271 -0
  14. package/dist/router/examples/RouterExample.svelte.d.ts +18 -0
  15. package/dist/router/examples/index.d.ts +4 -0
  16. package/dist/router/examples/index.js +4 -0
  17. package/dist/router/examples/pages/AboutPage.svelte +568 -0
  18. package/dist/router/examples/pages/AboutPage.svelte.d.ts +13 -0
  19. package/dist/router/examples/pages/HomePage.svelte +200 -0
  20. package/dist/router/examples/pages/HomePage.svelte.d.ts +14 -0
  21. package/dist/router/examples/pages/NotFoundPage.svelte +307 -0
  22. package/dist/router/examples/pages/NotFoundPage.svelte.d.ts +17 -0
  23. package/dist/router/hooks.svelte.d.ts +2 -2
  24. package/dist/router/index.d.ts +3 -0
  25. package/dist/router/index.js +3 -0
  26. package/dist/router/{Link.svelte → providers/Link.svelte} +1 -1
  27. package/dist/router/{Route.svelte → providers/Route.svelte} +1 -1
  28. package/dist/router/{Route.svelte.d.ts → providers/Route.svelte.d.ts} +1 -1
  29. package/dist/router/{Router.svelte → providers/RouterProvider.svelte} +22 -5
  30. package/dist/router/{Router.svelte.d.ts → providers/RouterProvider.svelte.d.ts} +8 -4
  31. package/dist/router/providers/index.d.ts +3 -0
  32. package/dist/router/providers/index.js +3 -0
  33. package/dist/router/{index.svelte.d.ts → router.svelte.d.ts} +1 -3
  34. package/dist/router/{index.svelte.js → router.svelte.js} +1 -4
  35. package/dist/stores/forms/Form.stories.d.ts +5 -0
  36. package/dist/stores/forms/Form.stories.js +342 -0
  37. package/dist/stores/forms/FormDemo.svelte +545 -0
  38. package/dist/stores/forms/FormDemo.svelte.d.ts +18 -0
  39. package/dist/stores/forms.d.ts +41 -4
  40. package/dist/stores/forms.js +86 -32
  41. package/dist/types/customCode.d.ts +1 -1
  42. package/dist/types/window.d.ts +1 -0
  43. package/dist/ui/components/button/Button.svelte +1 -1
  44. package/dist/ui/components/copy-text/CopyText.stories.d.ts +70 -0
  45. package/dist/ui/components/copy-text/CopyText.stories.js +241 -0
  46. package/dist/ui/components/copy-text/CopyText.svelte +247 -0
  47. package/dist/ui/components/copy-text/CopyText.svelte.d.ts +4 -0
  48. package/dist/ui/components/copy-text/index.d.ts +2 -0
  49. package/dist/ui/components/copy-text/index.js +1 -0
  50. package/dist/ui/components/copy-text/types.d.ts +52 -0
  51. package/dist/ui/components/copy-text/types.js +1 -0
  52. package/dist/ui/components/index.d.ts +1 -0
  53. package/dist/ui/components/index.js +1 -0
  54. package/dist/ui/components/input/Input.stories.d.ts +9 -0
  55. package/dist/ui/components/input/Input.stories.js +78 -0
  56. package/dist/ui/components/input/Input.svelte +39 -3
  57. package/dist/ui/components/input/types.d.ts +6 -0
  58. package/dist/ui/components/layout/Layout.svelte +45 -64
  59. package/dist/ui/components/layout/Layout.svelte.d.ts +26 -3
  60. package/dist/ui/components/layout/examples/ExampleLayout.svelte +32 -27
  61. package/dist/ui/components/layout/index.d.ts +1 -1
  62. package/dist/ui/components/layout/test-helpers/TestLayoutWithFooter.svelte +20 -0
  63. package/dist/ui/components/layout/test-helpers/TestLayoutWithFooter.svelte.d.ts +7 -0
  64. package/dist/ui/components/layout/types.d.ts +1 -10
  65. package/dist/ui/components/notification/Notification.stories.svelte +12 -1
  66. package/dist/ui/components/notification/Notification.svelte +10 -5
  67. package/dist/ui/components/notification/Notification.svelte.d.ts +1 -1
  68. package/dist/ui/components/notification/types.d.ts +1 -1
  69. package/dist/ui/components/section/Section.svelte +8 -4
  70. package/dist/ui/components/section/types.d.ts +8 -0
  71. package/dist/ui/components/text/Text.stories.svelte +67 -1
  72. package/dist/ui/components/text/Text.svelte +209 -8
  73. package/dist/ui/components/text/types.d.ts +4 -0
  74. package/dist/ui/index.css +6 -2
  75. package/dist/utils/animations/factory.d.ts +7 -0
  76. package/dist/utils/animations/factory.js +101 -0
  77. package/dist/utils/animations/index.d.ts +7 -0
  78. package/dist/utils/animations/index.js +62 -0
  79. package/dist/utils/animations/types.d.ts +39 -0
  80. package/dist/utils/animations/types.js +1 -0
  81. package/dist/utils/custom-code/configs.d.ts +22 -0
  82. package/dist/utils/custom-code/configs.js +40 -0
  83. package/dist/utils/custom-code/index.d.ts +1 -0
  84. package/dist/utils/custom-code/index.js +1 -0
  85. package/dist/utils/diff-mapper/DiffMapper.stories.d.ts +5 -0
  86. package/dist/utils/diff-mapper/DiffMapper.stories.js +185 -0
  87. package/dist/utils/diff-mapper/DiffMapperDemo.svelte +351 -0
  88. package/dist/utils/diff-mapper/DiffMapperDemo.svelte.d.ts +18 -0
  89. package/dist/utils/diff-mapper/deepDiffMapper.d.ts +31 -0
  90. package/dist/utils/diff-mapper/deepDiffMapper.js +264 -0
  91. package/dist/utils/diff-mapper/index.d.ts +1 -0
  92. package/dist/utils/diff-mapper/index.js +1 -0
  93. package/dist/utils/helpers/capitalizeFirstLetter.d.ts +4 -0
  94. package/dist/utils/helpers/capitalizeFirstLetter.js +9 -0
  95. package/dist/utils/helpers/getTimeNow.d.ts +4 -0
  96. package/dist/utils/helpers/getTimeNow.js +8 -0
  97. package/dist/utils/helpers/index.d.ts +4 -0
  98. package/dist/utils/helpers/index.js +4 -0
  99. package/dist/utils/helpers/minifyCode.d.ts +10 -0
  100. package/dist/utils/helpers/minifyCode.js +73 -0
  101. package/dist/utils/helpers/objectsToModuleExports.d.ts +1 -1
  102. package/dist/utils/helpers/objectsToModuleExports.js +1 -0
  103. package/dist/utils/helpers/toHumanReadableList.d.ts +4 -0
  104. package/dist/utils/helpers/toHumanReadableList.js +11 -0
  105. package/dist/utils/index.d.ts +2 -0
  106. package/dist/utils/index.js +2 -0
  107. package/dist/utils/webflow-canvas/getAllChildren.d.ts +16 -0
  108. package/dist/utils/webflow-canvas/getAllChildren.js +65 -0
  109. package/dist/utils/webflow-canvas/getElementClassList.d.ts +9 -0
  110. package/dist/utils/webflow-canvas/getElementClassList.js +19 -0
  111. package/dist/utils/webflow-canvas/index.d.ts +2 -0
  112. package/dist/utils/webflow-canvas/index.js +2 -0
  113. package/package.json +6 -1
  114. package/dist/providers/GlobalProvider.mdx +0 -322
  115. package/dist/router/README.md +0 -397
  116. /package/dist/router/{Link.svelte.d.ts → providers/Link.svelte.d.ts} +0 -0
@@ -32,6 +32,7 @@
32
32
 
33
33
  // Tooltip configuration - pass any tooltip props
34
34
  tooltip,
35
+ tooltipTarget = 'icon',
35
36
 
36
37
  // Popup configuration - for action popups (reset, delete, etc.)
37
38
  popup,
@@ -87,6 +88,7 @@
87
88
  disabled: popup?.disabled ?? false,
88
89
  title: popup?.title ?? 'Remove',
89
90
  subtitle: popup?.subtitle ?? 'Alt + click',
91
+ onclick: popup?.onclick ?? null,
90
92
  description: popup?.description ?? 'This action will remove the current selection.',
91
93
  icon: popup?.icon ?? DeleteIcon,
92
94
  active: popup?.active ?? false
@@ -114,6 +116,8 @@
114
116
  wrapperElement.dispatchEvent(new CustomEvent('popupAction', actionEvent));
115
117
  }
116
118
 
119
+ popup?.onclick?.();
120
+
117
121
  isPopupHidden = true;
118
122
  }
119
123
 
@@ -280,11 +284,26 @@
280
284
  !disabled &&
281
285
  (isPopupHidden || !hasPopup)
282
286
  );
287
+
288
+ // Validate tooltipTarget - if 'icon' is specified, icon must be present and not loading
289
+ let isValidTooltipTarget = $derived(
290
+ tooltipTarget === 'text' || (tooltipTarget === 'icon' && !!icon && !loading)
291
+ );
292
+
293
+ // Determine if tooltip should show on text (default behavior or when explicitly set to 'text')
294
+ let shouldShowTooltipOnText = $derived(
295
+ shouldShowTooltip && isValidTooltipTarget && tooltipTarget === 'text'
296
+ );
297
+
298
+ // Determine if tooltip should show on icon (when explicitly set to 'icon' and icon is present)
299
+ let shouldShowTooltipOnIcon = $derived(
300
+ shouldShowTooltip && isValidTooltipTarget && tooltipTarget === 'icon' && !!icon && !loading
301
+ );
283
302
  </script>
284
303
 
285
304
  {#if label || tooltip || icon || children}
286
- {#if !hasPopup && shouldShowTooltip}
287
- <!-- Simple text with tooltip -->
305
+ {#if !hasPopup && shouldShowTooltipOnText}
306
+ <!-- Simple text with tooltip on text -->
288
307
  <Tooltip {...tooltip}>
289
308
  {#snippet target()}
290
309
  <div
@@ -314,8 +333,14 @@
314
333
  <div class="loading" style="flex-shrink: 0;">
315
334
  <Loader size={16} />
316
335
  </div>
317
- {:else if icon}
336
+ {:else if icon && !shouldShowTooltipOnIcon}
318
337
  <IconComponent style="flex-shrink: 0;" />
338
+ {:else if icon && shouldShowTooltipOnIcon}
339
+ <Tooltip {...tooltip}>
340
+ {#snippet target()}
341
+ <IconComponent style="flex-shrink: 0;" />
342
+ {/snippet}
343
+ </Tooltip>
319
344
  {/if}
320
345
  {/if}
321
346
  <div class={textClasses()} style={textStyles()}>
@@ -336,8 +361,14 @@
336
361
  <div class="loading">
337
362
  <Loader size={16} />
338
363
  </div>
339
- {:else if icon}
364
+ {:else if icon && !shouldShowTooltipOnIcon}
340
365
  <IconComponent />
366
+ {:else if icon && shouldShowTooltipOnIcon}
367
+ <Tooltip {...tooltip}>
368
+ {#snippet target()}
369
+ <IconComponent />
370
+ {/snippet}
371
+ </Tooltip>
341
372
  {/if}
342
373
  {/if}
343
374
 
@@ -358,6 +389,85 @@
358
389
  </div>
359
390
  {/snippet}
360
391
  </Tooltip>
392
+ {:else if !hasPopup && shouldShowTooltipOnIcon}
393
+ <!-- Simple text with tooltip on icon -->
394
+ <div
395
+ class={labelClasses()}
396
+ data-component="Text"
397
+ {...isInteractive ? { tabindex: 0 } : {}}
398
+ role={isInteractive ? 'button' : undefined}
399
+ onclick={handleClick}
400
+ {title}
401
+ style={labelStyles()}
402
+ {...restProps}
403
+ >
404
+ {#if label?.trim() || icon || children}
405
+ {#if ellipsisOnWidth && (icon || loading)}
406
+ <!-- handling ellipsis with icons -->
407
+ <div
408
+ class="text-with-icon"
409
+ style="display: flex; align-items: center; gap: 4px; width: {ellipsisOnWidth}; justify-content: {textAlign ===
410
+ 'center'
411
+ ? 'center'
412
+ : textAlign === 'right'
413
+ ? 'flex-end'
414
+ : 'flex-start'};"
415
+ >
416
+ {#if icon || loading}
417
+ {#if loading}
418
+ <div class="loading" style="flex-shrink: 0;">
419
+ <Loader size={16} />
420
+ </div>
421
+ {:else if icon}
422
+ <Tooltip {...tooltip}>
423
+ {#snippet target()}
424
+ <IconComponent style="flex-shrink: 0;" />
425
+ {/snippet}
426
+ </Tooltip>
427
+ {/if}
428
+ {/if}
429
+ <div class={textClasses()} style={textStyles()}>
430
+ {#if children}
431
+ {@render children()}
432
+ {:else if raw}
433
+ {@html label}
434
+ {:else}
435
+ {label}
436
+ {/if}
437
+ </div>
438
+ </div>
439
+ {:else}
440
+ <!-- Normal text handling -->
441
+ <div class={textClasses()} style={textStyles()}>
442
+ {#if icon || loading}
443
+ {#if loading}
444
+ <div class="loading">
445
+ <Loader size={16} />
446
+ </div>
447
+ {:else if icon}
448
+ <Tooltip {...tooltip}>
449
+ {#snippet target()}
450
+ <IconComponent />
451
+ {/snippet}
452
+ </Tooltip>
453
+ {/if}
454
+ {/if}
455
+
456
+ {#if children}
457
+ {@render children()}
458
+ {:else if raw}
459
+ {@html label}
460
+ {:else}
461
+ {label}
462
+ {/if}
463
+ </div>
464
+ {/if}
465
+ {/if}
466
+
467
+ {#if pill}
468
+ {@render pill()}
469
+ {/if}
470
+ </div>
361
471
  {:else if !hasPopup}
362
472
  <!-- Simple text without tooltip -->
363
473
  <div
@@ -451,8 +561,8 @@
451
561
  >
452
562
  {#snippet target()}
453
563
  <span class="dropdown-label item {popupConfig.active ? 'active' : ''}">
454
- {#if shouldShowTooltip}
455
- <!-- Text with popup and tooltip -->
564
+ {#if shouldShowTooltipOnText}
565
+ <!-- Text with popup and tooltip on text -->
456
566
  <Tooltip {...tooltip}>
457
567
  {#snippet target()}
458
568
  <div
@@ -482,8 +592,14 @@
482
592
  <div class="loading" style="flex-shrink: 0;">
483
593
  <Loader size={16} />
484
594
  </div>
485
- {:else if icon}
595
+ {:else if icon && !shouldShowTooltipOnIcon}
486
596
  <IconComponent style="flex-shrink: 0;" />
597
+ {:else if icon && shouldShowTooltipOnIcon}
598
+ <Tooltip {...tooltip}>
599
+ {#snippet target()}
600
+ <IconComponent style="flex-shrink: 0;" />
601
+ {/snippet}
602
+ </Tooltip>
487
603
  {/if}
488
604
  {/if}
489
605
  <div class={textClasses()} style={textStyles()}>
@@ -504,8 +620,14 @@
504
620
  <div class="loading">
505
621
  <Loader size={16} />
506
622
  </div>
507
- {:else if icon}
623
+ {:else if icon && !shouldShowTooltipOnIcon}
508
624
  <IconComponent />
625
+ {:else if icon && shouldShowTooltipOnIcon}
626
+ <Tooltip {...tooltip}>
627
+ {#snippet target()}
628
+ <IconComponent />
629
+ {/snippet}
630
+ </Tooltip>
509
631
  {/if}
510
632
  {/if}
511
633
 
@@ -526,6 +648,85 @@
526
648
  </div>
527
649
  {/snippet}
528
650
  </Tooltip>
651
+ {:else if shouldShowTooltipOnIcon}
652
+ <!-- Text with popup and tooltip on icon -->
653
+ <div
654
+ class={labelClasses()}
655
+ data-component="Text"
656
+ {...isInteractive ? { tabindex: 0 } : {}}
657
+ role={isInteractive ? 'button' : undefined}
658
+ onclick={handleClick}
659
+ {title}
660
+ style={labelStyles()}
661
+ {...restProps}
662
+ >
663
+ {#if label?.trim() || icon || children}
664
+ {#if ellipsisOnWidth && (icon || loading)}
665
+ <!-- handling ellipsis with icons -->
666
+ <div
667
+ class="text-with-icon"
668
+ style="display: flex; align-items: center; gap: 4px; width: {ellipsisOnWidth}; justify-content: {textAlign ===
669
+ 'center'
670
+ ? 'center'
671
+ : textAlign === 'right'
672
+ ? 'flex-end'
673
+ : 'flex-start'};"
674
+ >
675
+ {#if icon || loading}
676
+ {#if loading}
677
+ <div class="loading" style="flex-shrink: 0;">
678
+ <Loader size={16} />
679
+ </div>
680
+ {:else if icon}
681
+ <Tooltip {...tooltip}>
682
+ {#snippet target()}
683
+ <IconComponent style="flex-shrink: 0;" />
684
+ {/snippet}
685
+ </Tooltip>
686
+ {/if}
687
+ {/if}
688
+ <div class={textClasses()} style={textStyles()}>
689
+ {#if children}
690
+ {@render children()}
691
+ {:else if raw}
692
+ {@html label}
693
+ {:else}
694
+ {label}
695
+ {/if}
696
+ </div>
697
+ </div>
698
+ {:else}
699
+ <!-- Normal text handling -->
700
+ <div class={textClasses()} style={textStyles()}>
701
+ {#if icon || loading}
702
+ {#if loading}
703
+ <div class="loading">
704
+ <Loader size={16} />
705
+ </div>
706
+ {:else if icon}
707
+ <Tooltip {...tooltip}>
708
+ {#snippet target()}
709
+ <IconComponent />
710
+ {/snippet}
711
+ </Tooltip>
712
+ {/if}
713
+ {/if}
714
+
715
+ {#if children}
716
+ {@render children()}
717
+ {:else if raw}
718
+ {@html label}
719
+ {:else}
720
+ {label}
721
+ {/if}
722
+ </div>
723
+ {/if}
724
+ {/if}
725
+
726
+ {#if pill}
727
+ {@render pill()}
728
+ {/if}
729
+ </div>
529
730
  {:else}
530
731
  <!-- Text with popup without tooltip -->
531
732
  <div
@@ -21,6 +21,8 @@ export interface PopupConfig {
21
21
  icon?: Component | null;
22
22
  /** Whether the popup trigger is currently active */
23
23
  active?: boolean;
24
+ /** Event handler for popup action */
25
+ onclick?: () => void;
24
26
  }
25
27
  export interface TextProps {
26
28
  label?: string;
@@ -37,6 +39,8 @@ export interface TextProps {
37
39
  height?: string;
38
40
  ellipsisOnWidth?: string;
39
41
  tooltip?: Partial<TooltipProps>;
42
+ /** Specifies whether to show tooltip on the text or icon. Requires icon prop when set to 'icon' */
43
+ tooltipTarget?: 'text' | 'icon';
40
44
  popup?: PopupConfig;
41
45
  icon?: Component | null;
42
46
  loading?: boolean;
package/dist/ui/index.css CHANGED
@@ -4,7 +4,7 @@
4
4
  /* custom scrollbar related */
5
5
  --sb-track-color: #1e1e1e;
6
6
  --sb-thumb-color: #373737;
7
- --sb-size: 6px;
7
+ --sb-size: 8px;
8
8
 
9
9
  /* Webflow colors */
10
10
  --background1: #292929;
@@ -264,9 +264,13 @@ label {
264
264
  .disabled,
265
265
  .login-required {
266
266
  cursor: not-allowed !important;
267
- opacity: 0.75 !important;
267
+ opacity: 0.8 !important;
268
268
  }
269
269
 
270
+ /* Used for disabled sections */
271
+ .not-allowed {
272
+ cursor: not-allowed !important;
273
+ }
270
274
  /* OverlayScrollbars Global Theme */
271
275
  :root {
272
276
  /* OverlayScrollbars theme variables using design system colors */
@@ -0,0 +1,7 @@
1
+ import type { AnimationFunctions, AnimationProps } from './types';
2
+ /**
3
+ * Creates a new Animation.
4
+ * @param props The animaiton props.
5
+ * @returns A new `in` and `out` Animation functions.
6
+ */
7
+ export declare const createAnimation: ({ initialStyles, keyframes }: AnimationProps) => AnimationFunctions;
@@ -0,0 +1,101 @@
1
+ import { animate, stagger as staggerDelay } from 'motion';
2
+ /**
3
+ * Creates a new Animation.
4
+ * @param props The animaiton props.
5
+ * @returns A new `in` and `out` Animation functions.
6
+ */
7
+ export const createAnimation = ({ initialStyles, keyframes }) => {
8
+ const isBrowser = typeof window !== 'undefined';
9
+ /**
10
+ * Prepares the {@link animateIn} elements by setting the initial styles and rendering them to the DOM.
11
+ * @param elements The elements to prepare.
12
+ * @param options.target If defined, the element will be appended to the target.
13
+ * @param options.insertAfter A child of the target. If defined, the element will be appended right after this anchor element.
14
+ */
15
+ const prepareIn = (elements, options = {}) => {
16
+ const { target, insertAfter, display = '' } = options;
17
+ if (!Array.isArray(elements))
18
+ elements = [elements];
19
+ for (const element of elements) {
20
+ element.style.display = display;
21
+ Object.assign(element.style, initialStyles);
22
+ if (target && insertAfter !== undefined) {
23
+ if (insertAfter)
24
+ target.insertBefore(element, insertAfter.nextSibling);
25
+ else {
26
+ if (isBrowser && target instanceof HTMLElement) {
27
+ target.insertBefore(element, target.firstChild);
28
+ }
29
+ }
30
+ }
31
+ else if (target)
32
+ target.appendChild(element);
33
+ }
34
+ };
35
+ /**
36
+ * In animation.
37
+ * @param elements The elements to animate.
38
+ * @param options.target If defined, the element will be appended to the target.
39
+ * @param options.insertAfter A child of the target. If defined, the element will be appended right after this anchor element.
40
+ * @param options.prepared Defines if the animation has been prepared beforehand, useful to avoid performing double preparation.
41
+ * @param options.stagger If defined, the animation will be staggered using this time value.
42
+ * @param options.animationOptions The main options of the animation. Reference: {@link [Motion One](https://motion.dev/dom/animate#options)}.
43
+ * @returns An awaitable promise.
44
+ */
45
+ const animateIn = async (elements, options = {}) => {
46
+ //TODO: probably display can be used also?
47
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
48
+ const { prepared, stagger, display, duration, ...animationOptions } = options;
49
+ const durationInSeconds = duration ? duration / 1000 : undefined;
50
+ if (!prepared)
51
+ prepareIn(elements, options);
52
+ const { finished } = animate(elements, keyframes, {
53
+ ...animationOptions,
54
+ delay: stagger ? staggerDelay(stagger / 1000) : undefined,
55
+ duration: durationInSeconds
56
+ });
57
+ return await finished;
58
+ };
59
+ /**
60
+ * Out animation.
61
+ * @param elements The elements to animate.
62
+ * @param options.remove If defined, the element will be removed from the DOM after the animation ends.
63
+ * @param options.stagger If defined, the animation will be staggered using this time value.
64
+ * @param options.animationOptions The main options of the animation. Reference: {@link [Motion One](https://motion.dev/dom/animate#options)}.
65
+ * @returns An awaitable promise.
66
+ */
67
+ const animateOut = async (elements, options = {}) => {
68
+ const { remove, stagger, target, insertAfter, display = 'none', duration, ...animationOptions } = options;
69
+ const durationInSeconds = duration ? duration / 1000 : undefined;
70
+ if (!Array.isArray(elements))
71
+ elements = [elements];
72
+ elements = elements.filter((element) => document.body.contains(element));
73
+ if (!elements.length)
74
+ return;
75
+ const { finished } = animate(elements, keyframes, {
76
+ ...animationOptions,
77
+ duration: durationInSeconds,
78
+ delay: stagger ? staggerDelay(stagger / 1000) : undefined,
79
+ direction: 'reverse'
80
+ });
81
+ await finished;
82
+ for (const element of elements) {
83
+ if (target && insertAfter !== undefined) {
84
+ if (insertAfter)
85
+ target.insertBefore(element, insertAfter.nextSibling);
86
+ else {
87
+ if (isBrowser && target instanceof HTMLElement) {
88
+ target.insertBefore(element, target.firstChild);
89
+ }
90
+ }
91
+ }
92
+ else if (target)
93
+ target.appendChild(element);
94
+ if (remove)
95
+ element.remove();
96
+ else
97
+ element.style.display = display;
98
+ }
99
+ };
100
+ return { prepareIn, animateIn, animateOut };
101
+ };
@@ -0,0 +1,7 @@
1
+ import type { AnimationsObject } from './types';
2
+ export * from './types';
3
+ export declare const easings: readonly ["linear", "ease", "ease-in", "ease-out", "ease-in-out"];
4
+ /**
5
+ * Contains all animation functions.
6
+ */
7
+ export declare const animations: AnimationsObject;
@@ -0,0 +1,62 @@
1
+ import { createAnimation } from './factory';
2
+ export * from './types';
3
+ // Constants
4
+ export const easings = ['linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out'];
5
+ /**
6
+ * Contains all animation functions.
7
+ */
8
+ export const animations = {
9
+ /**
10
+ * Fade
11
+ */
12
+ fade: createAnimation({ keyframes: { opacity: [0, 1] }, initialStyles: { opacity: '0' } }),
13
+ /**
14
+ * Slide Up
15
+ */
16
+ 'slide-up': createAnimation({
17
+ keyframes: { y: [100, 0], opacity: [0, 1] },
18
+ initialStyles: { transform: 'translateY(100px)', opacity: '0' }
19
+ }),
20
+ /**
21
+ * Slide Down
22
+ */
23
+ 'slide-down': createAnimation({
24
+ keyframes: { y: [-100, 0], opacity: [0, 1] },
25
+ initialStyles: { transform: 'translateY(-100px)', opacity: '0' }
26
+ }),
27
+ /**
28
+ * Slide Right
29
+ */
30
+ 'slide-right': createAnimation({
31
+ keyframes: { x: [-100, 0], opacity: [0, 1] },
32
+ initialStyles: { transform: 'translateX(-100px)', opacity: '0' }
33
+ }),
34
+ /**
35
+ * Slide Left
36
+ */
37
+ 'slide-left': createAnimation({
38
+ keyframes: { x: [100, 0], opacity: [0, 1] },
39
+ initialStyles: { transform: 'translateX(100px)', opacity: '0' }
40
+ }),
41
+ /**
42
+ * Grow
43
+ */
44
+ grow: createAnimation({
45
+ keyframes: { scale: [0, 1], opacity: [0, 1] },
46
+ initialStyles: { transform: 'scale(0)', opacity: '0' }
47
+ }),
48
+ /**
49
+ * Shrink
50
+ */
51
+ shrink: createAnimation({
52
+ keyframes: { scale: [1.25, 1], opacity: [0, 1] },
53
+ initialStyles: { transform: 'scale(1.25)', opacity: '0' }
54
+ }),
55
+ /**
56
+ * Spin
57
+ */
58
+ spin: createAnimation({
59
+ keyframes: { rotate: [900, 0], opacity: [0, 1] },
60
+ initialStyles: { transform: 'rotate(900deg)', opacity: '0' }
61
+ })
62
+ };
@@ -0,0 +1,39 @@
1
+ import type { AnimationOptions, MotionKeyframesDefinition } from 'motion';
2
+ import type { easings } from '.';
3
+ export interface AnimationProps {
4
+ keyframes: MotionKeyframesDefinition;
5
+ initialStyles: {
6
+ [key: string]: string;
7
+ };
8
+ }
9
+ type FilteredAnimationOptions = Pick<AnimationOptions, 'duration' | 'easing'> & {
10
+ stagger?: number;
11
+ };
12
+ type AnimationPrepare<T> = (element: HTMLElement | HTMLElement[], options?: T) => void;
13
+ type AnimationBase<T> = (element: HTMLElement | HTMLElement[], options?: T & FilteredAnimationOptions) => Promise<void>;
14
+ type PrepareProps = {
15
+ target?: Element;
16
+ insertAfter?: Node | null;
17
+ display?: string;
18
+ };
19
+ type AnimationInProps = PrepareProps & {
20
+ prepared?: true;
21
+ };
22
+ type AnimationOutProps = PrepareProps & {
23
+ remove?: boolean;
24
+ };
25
+ type PrepareIn = AnimationPrepare<PrepareProps>;
26
+ type AnimationIn = AnimationBase<AnimationInProps>;
27
+ type AnimationOut = AnimationBase<AnimationOutProps>;
28
+ export type AnimationFunctions = {
29
+ prepareIn: PrepareIn;
30
+ animateIn: AnimationIn;
31
+ animateOut: AnimationOut;
32
+ };
33
+ export type Animation = AnimationFunctions & {
34
+ options?: FilteredAnimationOptions;
35
+ };
36
+ export type AnimationsObject = Readonly<Record<'fade' | 'slide-up' | 'slide-down' | 'slide-right' | 'slide-left' | 'grow' | 'shrink' | 'spin', AnimationFunctions>>;
37
+ export type Easings = typeof easings;
38
+ export type AnimationOptionsCustom = Readonly<Record<'fade' | 'slide-up' | 'slide-down' | 'slide-right' | 'slide-left' | 'grow' | 'shrink' | 'spin', string>>;
39
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Store for Custom Code stored Component configs
3
+ */
4
+ export declare const componentConfigsStore: import("svelte/store").Writable<null>;
5
+ export type CustomCodeConfigsStore = {
6
+ component: string;
7
+ instance: string[];
8
+ }[];
9
+ /**
10
+ * Store for Custom Code stored Component configs instances
11
+ */
12
+ export declare const customCodeConfigsStore: import("svelte/store").Writable<CustomCodeConfigsStore>;
13
+ /**
14
+ * Get configs from custom code.
15
+ */
16
+ export declare const getProjectConfigs: () => Promise<any>;
17
+ /**
18
+ * Fetches configs stored in custom code for a given component.
19
+ * @param component
20
+ * @returns
21
+ */
22
+ export declare const getComponentConfigs: (component: string) => Promise<any>;
@@ -0,0 +1,40 @@
1
+ import { writable } from 'svelte/store';
2
+ import { getLogger } from '../logger';
3
+ import { getCustomCode } from './api';
4
+ const logger = getLogger('utils');
5
+ const DISPLAY_NAME = 'finsweetcomponentsconfig';
6
+ /**
7
+ * Store for Custom Code stored Component configs
8
+ */
9
+ export const componentConfigsStore = writable(null);
10
+ /**
11
+ * Store for Custom Code stored Component configs instances
12
+ */
13
+ export const customCodeConfigsStore = writable([]);
14
+ /**
15
+ * Get configs from custom code.
16
+ */
17
+ export const getProjectConfigs = async () => {
18
+ const [customCodeBlock] = await getCustomCode(DISPLAY_NAME);
19
+ if (!customCodeBlock || !customCodeBlock.hostedLocation) {
20
+ return null;
21
+ }
22
+ // activate loading state to block iife scripts
23
+ window.isLoadingCustomCodeConfigs = true;
24
+ const configs = await import(/* @vite-ignore */ customCodeBlock.hostedLocation);
25
+ window.isLoadingCustomCodeConfigs = false;
26
+ customCodeConfigsStore.set(configs);
27
+ logger.log({}, 'Project custom code configs', configs);
28
+ return configs;
29
+ };
30
+ /**
31
+ * Fetches configs stored in custom code for a given component.
32
+ * @param component
33
+ * @returns
34
+ */
35
+ export const getComponentConfigs = async (component) => {
36
+ const customCodeBlock = await getProjectConfigs();
37
+ if (!customCodeBlock || Object.keys(customCodeBlock[component]).length === 0)
38
+ return null;
39
+ return customCodeBlock[component];
40
+ };
@@ -1 +1,2 @@
1
1
  export * from './api';
2
+ export * from './configs';
@@ -1 +1,2 @@
1
1
  export * from './api';
2
+ export * from './configs';
@@ -0,0 +1,5 @@
1
+ import type { Meta, StoryObj } from '@storybook/sveltekit';
2
+ declare const meta: Meta;
3
+ export default meta;
4
+ type Story = StoryObj<typeof meta>;
5
+ export declare const Interactive: Story;