@skeletonlabs/skeleton 1.11.0-dev.fa91c649 → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/components/Accordion/Accordion.svelte +15 -3
  2. package/dist/components/Accordion/Accordion.svelte.d.ts +17 -23
  3. package/dist/components/Accordion/AccordionItem.svelte +8 -3
  4. package/dist/components/Accordion/AccordionItem.svelte.d.ts +15 -25
  5. package/dist/components/AppRail/AppRailTile.svelte +1 -1
  6. package/dist/components/Autocomplete/Autocomplete.svelte +17 -7
  7. package/dist/components/Autocomplete/Autocomplete.svelte.d.ts +17 -27
  8. package/dist/components/Avatar/Avatar.svelte +1 -1
  9. package/dist/components/ConicGradient/ConicGradient.svelte +1 -1
  10. package/dist/components/InputChip/InputChip.svelte +25 -4
  11. package/dist/components/InputChip/InputChip.svelte.d.ts +22 -27
  12. package/dist/components/Paginator/Paginator.svelte +18 -16
  13. package/dist/components/Paginator/Paginator.svelte.d.ts +2 -2
  14. package/dist/components/Paginator/types.d.ts +2 -2
  15. package/dist/components/Ratings/Ratings.svelte +1 -1
  16. package/dist/components/Stepper/Step.svelte +11 -2
  17. package/dist/components/Stepper/Step.svelte.d.ts +15 -12
  18. package/dist/components/Stepper/Stepper.svelte +21 -3
  19. package/dist/components/Stepper/Stepper.svelte.d.ts +17 -27
  20. package/dist/components/Tab/TabGroup.svelte +1 -1
  21. package/dist/components/Table/Table.svelte +1 -1
  22. package/dist/index.d.ts +10 -9
  23. package/dist/index.js +10 -12
  24. package/dist/internal/transitions.d.ts +10 -0
  25. package/dist/internal/transitions.js +11 -0
  26. package/dist/transitions/crossfade.d.ts +1 -0
  27. package/dist/transitions/crossfade.js +21 -0
  28. package/dist/types.d.ts +8 -0
  29. package/dist/types.js +1 -0
  30. package/dist/utilities/Drawer/Drawer.svelte +33 -12
  31. package/dist/utilities/Drawer/Drawer.svelte.d.ts +4 -2
  32. package/dist/utilities/Drawer/stores.d.ts +20 -1
  33. package/dist/utilities/Drawer/stores.js +27 -2
  34. package/dist/utilities/Drawer/types.d.ts +2 -0
  35. package/dist/utilities/Modal/Modal.svelte +21 -23
  36. package/dist/utilities/Modal/Modal.svelte.d.ts +17 -37
  37. package/dist/utilities/Modal/stores.d.ts +20 -1
  38. package/dist/utilities/Modal/stores.js +27 -1
  39. package/dist/utilities/PrefersReducedMotion/PrefersReducedMotion.d.ts +7 -0
  40. package/dist/utilities/PrefersReducedMotion/PrefersReducedMotion.js +26 -0
  41. package/dist/utilities/TableOfContents/TableOfContents.svelte +56 -0
  42. package/dist/utilities/TableOfContents/TableOfContents.svelte.d.ts +34 -0
  43. package/dist/utilities/TableOfContents/crawler.d.ts +14 -0
  44. package/dist/utilities/TableOfContents/crawler.js +76 -0
  45. package/dist/utilities/TableOfContents/stores.d.ts +6 -0
  46. package/dist/utilities/TableOfContents/stores.js +5 -0
  47. package/dist/utilities/TableOfContents/types.d.ts +5 -0
  48. package/dist/utilities/TableOfContents/types.js +2 -0
  49. package/dist/utilities/Toast/Toast.svelte +24 -23
  50. package/dist/utilities/Toast/Toast.svelte.d.ts +17 -24
  51. package/dist/utilities/Toast/stores.d.ts +23 -5
  52. package/dist/utilities/Toast/stores.js +56 -29
  53. package/dist/utilities/index.d.ts +18 -0
  54. package/dist/utilities/index.js +25 -0
  55. package/package.json +3 -16
  56. package/dist/components/TableOfContents/TableOfContents.svelte +0 -111
  57. package/dist/components/TableOfContents/TableOfContents.svelte.d.ts +0 -44
  58. package/dist/styles/all.css +0 -30
  59. package/dist/styles/elements/alerts.css +0 -17
  60. package/dist/styles/elements/badges.css +0 -31
  61. package/dist/styles/elements/breadcrumbs.css +0 -36
  62. package/dist/styles/elements/buttons.css +0 -109
  63. package/dist/styles/elements/cards.css +0 -32
  64. package/dist/styles/elements/chips.css +0 -22
  65. package/dist/styles/elements/codeblocks.css +0 -16
  66. package/dist/styles/elements/forms.css +0 -283
  67. package/dist/styles/elements/lists.css +0 -51
  68. package/dist/styles/elements/logo-clouds.css +0 -29
  69. package/dist/styles/elements/modals.css +0 -15
  70. package/dist/styles/elements/placeholders.css +0 -17
  71. package/dist/styles/elements/popups.css +0 -16
  72. package/dist/styles/elements/tables.css +0 -102
  73. package/dist/styles/partials/core.css +0 -66
  74. package/dist/styles/partials/elements.css +0 -20
  75. package/dist/styles/partials/tailwind.css +0 -16
  76. package/dist/styles/partials/typography-next.css +0 -99
  77. package/dist/styles/partials/typography-prose.css +0 -49
  78. package/dist/styles/partials/typography.css +0 -99
  79. package/dist/styles/partials/variants.css +0 -204
  80. package/dist/styles/skeleton-minimal.css +0 -30
  81. package/dist/styles/skeleton.css +0 -30
  82. package/dist/tailwind/core.cjs +0 -37
  83. package/dist/tailwind/core.d.cts +0 -5
  84. package/dist/tailwind/generated/intellisense-classes.cjs +0 -1
  85. package/dist/tailwind/generated/intellisense-classes.d.cts +0 -2729
  86. package/dist/tailwind/intellisense.cjs +0 -21
  87. package/dist/tailwind/intellisense.d.cts +0 -5
  88. package/dist/tailwind/settings.cjs +0 -20
  89. package/dist/tailwind/settings.d.cts +0 -6
  90. package/dist/tailwind/skeleton.cjs +0 -19
  91. package/dist/tailwind/skeleton.d.cts +0 -7
  92. package/dist/tailwind/theme/colors.cjs +0 -18
  93. package/dist/tailwind/theme/colors.d.cts +0 -2
  94. package/dist/tailwind/tokens/backgrounds.cjs +0 -39
  95. package/dist/tailwind/tokens/backgrounds.d.cts +0 -2
  96. package/dist/tailwind/tokens/border-radius.cjs +0 -21
  97. package/dist/tailwind/tokens/border-radius.d.cts +0 -33
  98. package/dist/tailwind/tokens/borders.cjs +0 -20
  99. package/dist/tailwind/tokens/borders.d.cts +0 -6
  100. package/dist/tailwind/tokens/fills.cjs +0 -20
  101. package/dist/tailwind/tokens/fills.d.cts +0 -15
  102. package/dist/tailwind/tokens/rings.cjs +0 -50
  103. package/dist/tailwind/tokens/rings.d.cts +0 -22
  104. package/dist/tailwind/tokens/text.cjs +0 -31
  105. package/dist/tailwind/tokens/text.d.cts +0 -21
  106. package/dist/themes/theme-crimson.css +0 -100
  107. package/dist/themes/theme-gold-nouveau.css +0 -143
  108. package/dist/themes/theme-hamlindigo.css +0 -109
  109. package/dist/themes/theme-modern.css +0 -134
  110. package/dist/themes/theme-rocket.css +0 -120
  111. package/dist/themes/theme-sahara.css +0 -133
  112. package/dist/themes/theme-seafoam.css +0 -128
  113. package/dist/themes/theme-seasonal.css +0 -114
  114. package/dist/themes/theme-skeleton.css +0 -119
  115. package/dist/themes/theme-test.css +0 -96
  116. package/dist/themes/theme-vintage.css +0 -131
  117. package/dist/utilities/DataTable/DataTable.d.ts +0 -19
  118. package/dist/utilities/DataTable/DataTable.js +0 -137
  119. package/dist/utilities/DataTable/types.d.ts +0 -33
  120. package/dist/utilities/DataTable/types.js +0 -2
  121. /package/dist/{utilities/DataTable → components/Table}/actions.d.ts +0 -0
  122. /package/dist/{utilities/DataTable → components/Table}/actions.js +0 -0
@@ -1,14 +1,14 @@
1
- <script>import { createEventDispatcher } from "svelte";
2
- import { fade, fly } from "svelte/transition";
1
+ <script context="module">import { fly, fade } from "svelte/transition";
2
+ import { prefersReducedMotionStore } from "../../index.js";
3
+ import { dynamicTransition } from "../../internal/transitions.js";
4
+ </script>
5
+
6
+ <script generics="TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition">import { createEventDispatcher } from "svelte";
3
7
  const dispatch = createEventDispatcher();
4
- import { modalStore } from "./stores.js";
5
8
  import { focusTrap } from "../../actions/FocusTrap/focusTrap.js";
9
+ import { getModalStore } from "./stores.js";
6
10
  export let position = "items-center";
7
11
  export let components = {};
8
- export let duration = 150;
9
- export let flyOpacity = 0;
10
- export let flyX = 0;
11
- export let flyY = 100;
12
12
  export let background = "bg-surface-100-800-token";
13
13
  export let width = "w-modal";
14
14
  export let height = "h-auto";
@@ -26,6 +26,11 @@ export let regionBackdrop = "bg-surface-backdrop-token";
26
26
  export let regionHeader = "text-2xl font-bold";
27
27
  export let regionBody = "max-h-[200px] overflow-hidden";
28
28
  export let regionFooter = "flex justify-end space-x-2";
29
+ export let transitions = !$prefersReducedMotionStore;
30
+ export let transitionIn = fly;
31
+ export let transitionInParams = { duration: 150, opacity: 0, x: 0, y: 100 };
32
+ export let transitionOut = fly;
33
+ export let transitionOutParams = { duration: 150, opacity: 0, x: 0, y: 100 };
29
34
  const cBackdrop = "fixed top-0 left-0 right-0 bottom-0 overflow-y-auto";
30
35
  const cTransitionLayer = "w-full h-fit min-h-full p-4 overflow-y-auto flex justify-center";
31
36
  const cModal = "block overflow-y-auto";
@@ -38,6 +43,7 @@ const buttonTextDefaults = {
38
43
  };
39
44
  let currentComponent;
40
45
  let registeredInteractionWithBackdrop = false;
46
+ const modalStore = getModalStore();
41
47
  modalStore.subscribe((modals) => {
42
48
  if (!modals.length)
43
49
  return;
@@ -102,11 +108,6 @@ $:
102
108
  parent = {
103
109
  position,
104
110
  // ---
105
- duration,
106
- flyOpacity,
107
- flyX,
108
- flyY,
109
- // ---
110
111
  background,
111
112
  width,
112
113
  height,
@@ -135,7 +136,7 @@ $:
135
136
  {#if $modalStore.length > 0}
136
137
  {#key $modalStore}
137
138
  <!-- Backdrop -->
138
- <!-- TODO: Remove for V2 -->
139
+ <!-- FIXME: resolve a11y warnings -->
139
140
  <!-- svelte-ignore a11y-no-static-element-interactions -->
140
141
  <div
141
142
  class="modal-backdrop {classesBackdrop}"
@@ -144,21 +145,18 @@ $:
144
145
  on:mouseup={onBackdropInteractionEnd}
145
146
  on:touchstart|passive
146
147
  on:touchend|passive
147
- transition:fade|global={{ duration }}
148
+ transition:dynamicTransition|global={{ transition: fade, params: { duration: 150 }, enabled: transitions }}
148
149
  use:focusTrap={true}
149
150
  >
150
151
  <!-- Transition Layer -->
151
- <div class="modal-transition {classesTransitionLayer}" transition:fly|global={{ duration, opacity: flyOpacity, x: flyX, y: flyY }}>
152
+ <div
153
+ class="modal-transition {classesTransitionLayer}"
154
+ in:dynamicTransition|global={{ transition: transitionIn, params: transitionInParams, enabled: transitions }}
155
+ out:dynamicTransition|global={{ transition: transitionOut, params: transitionOutParams, enabled: transitions }}
156
+ >
152
157
  {#if $modalStore[0].type !== 'component'}
153
158
  <!-- Modal: Presets -->
154
- <div
155
- class="modal {classesModal}"
156
- data-testid="modal"
157
- role="dialog"
158
- aria-modal="true"
159
- aria-label={$modalStore[0].title ?? ''}
160
- transition:fly|global={{ duration, opacity: 0, y: 100 }}
161
- >
159
+ <div class="modal {classesModal}" data-testid="modal" role="dialog" aria-modal="true" aria-label={$modalStore[0].title ?? ''}>
162
160
  <!-- Header -->
163
161
  {#if $modalStore[0]?.title}
164
162
  <header class="modal-header {regionHeader}">{@html $modalStore[0].title}</header>
@@ -1,68 +1,48 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import { fly } from 'svelte/transition';
3
+ import { type Transition, type TransitionParams } from '../../index.js';
4
+ type FlyTransition = typeof fly;
2
5
  import type { ModalComponent } from './types.js';
3
- declare const __propDef: {
4
- props: {
6
+ declare class __sveltets_Render<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> {
7
+ props(): {
5
8
  [x: string]: any;
6
- /** Set the modal position within the backdrop container*/
7
9
  position?: string | undefined;
8
- /** Register a list of reusable component modals.*/
9
10
  components?: Record<string, ModalComponent> | undefined;
10
- /** The open/close animation duration. Set '0' (zero) to disable.*/
11
- duration?: number | undefined;
12
- /** Set the fly transition opacity.*/
13
- flyOpacity?: number | undefined;
14
- /** Set the fly transition X axis value.*/
15
- flyX?: number | undefined;
16
- /** Set the fly transition Y axis value.*/
17
- flyY?: number | undefined;
18
- /** Provide classes to style the modal background.*/
19
11
  background?: string | undefined;
20
- /** Provide classes to style the modal width.*/
21
12
  width?: string | undefined;
22
- /** Provide classes to style the modal height.*/
23
13
  height?: string | undefined;
24
- /** Provide classes to style the modal padding.*/
25
14
  padding?: string | undefined;
26
- /** Provide classes to style the modal spacing.*/
27
15
  spacing?: string | undefined;
28
- /** Provide classes to style the modal border radius.*/
29
16
  rounded?: string | undefined;
30
- /** Provide classes to style modal box shadow.*/
31
17
  shadow?: string | undefined;
32
- /** Provide a class to override the z-index*/
33
18
  zIndex?: string | undefined;
34
- /** Provide classes for neutral buttons, such as Cancel.*/
35
19
  buttonNeutral?: string | undefined;
36
- /** Provide classes for positive actions, such as Confirm or Submit.*/
37
20
  buttonPositive?: string | undefined;
38
- /** Override the text for the Cancel button.*/
39
21
  buttonTextCancel?: string | undefined;
40
- /** Override the text for the Confirm button.*/
41
22
  buttonTextConfirm?: string | undefined;
42
- /** Override the text for the Submit button.*/
43
23
  buttonTextSubmit?: string | undefined;
44
- /** Provide classes to style the backdrop.*/
45
24
  regionBackdrop?: string | undefined;
46
- /** Provide arbitrary classes to modal header region.*/
47
25
  regionHeader?: string | undefined;
48
- /** Provide arbitrary classes to modal body region.*/
49
26
  regionBody?: string | undefined;
50
- /** Provide arbitrary classes to modal footer region.*/
51
27
  regionFooter?: string | undefined;
28
+ transitions?: boolean | undefined;
29
+ transitionIn?: TransitionIn | undefined;
30
+ transitionInParams?: TransitionParams<TransitionIn> | undefined;
31
+ transitionOut?: TransitionOut | undefined;
32
+ transitionOutParams?: TransitionParams<TransitionOut> | undefined;
52
33
  };
53
- events: {
34
+ events(): {
54
35
  touchstart: TouchEvent;
55
36
  touchend: TouchEvent;
56
- /** {{ event }} backdrop - Fires on backdrop interaction.*/
57
37
  backdrop: CustomEvent<MouseEvent>;
58
38
  } & {
59
39
  [evt: string]: CustomEvent<any>;
60
40
  };
61
- slots: {};
62
- };
63
- export type ModalProps = typeof __propDef.props;
64
- export type ModalEvents = typeof __propDef.events;
65
- export type ModalSlots = typeof __propDef.slots;
66
- export default class Modal extends SvelteComponentTyped<ModalProps, ModalEvents, ModalSlots> {
41
+ slots(): {};
42
+ }
43
+ export type ModalProps<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> = ReturnType<__sveltets_Render<TransitionIn, TransitionOut>['props']>;
44
+ export type ModalEvents<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> = ReturnType<__sveltets_Render<TransitionIn, TransitionOut>['events']>;
45
+ export type ModalSlots<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> = ReturnType<__sveltets_Render<TransitionIn, TransitionOut>['slots']>;
46
+ export default class Modal<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> extends SvelteComponentTyped<ModalProps<TransitionIn, TransitionOut>, ModalEvents<TransitionIn, TransitionOut>, ModalSlots<TransitionIn, TransitionOut>> {
67
47
  }
68
48
  export {};
@@ -1,6 +1,24 @@
1
1
  /// <reference types="svelte" />
2
2
  import type { ModalSettings } from './types.js';
3
- export declare const modalStore: {
3
+ /**
4
+ * Retrieves the `modalStore`.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { getmodalStore } from "@skeletonlabs/skeleton";
9
+ *
10
+ * const modalStore = getModalStore();
11
+ *
12
+ * modalStore.trigger({ type: "alert", title: "Welcome!" });
13
+ * ```
14
+ */
15
+ export declare function getModalStore(): ModalStore;
16
+ /**
17
+ * Initializes the `modalStore`.
18
+ */
19
+ export declare function initializeModalStore(): ModalStore;
20
+ type ModalStore = ReturnType<typeof modalService>;
21
+ declare function modalService(): {
4
22
  subscribe: (this: void, run: import("svelte/store").Subscriber<ModalSettings[]>, invalidate?: import("svelte/store").Invalidator<ModalSettings[]> | undefined) => import("svelte/store").Unsubscriber;
5
23
  set: (this: void, value: ModalSettings[]) => void;
6
24
  update: (this: void, updater: import("svelte/store").Updater<ModalSettings[]>) => void;
@@ -11,3 +29,4 @@ export declare const modalStore: {
11
29
  /** Remove all items from queue. */
12
30
  clear: () => void;
13
31
  };
32
+ export {};
@@ -1,5 +1,32 @@
1
1
  // Modal Store Queue
2
2
  import { writable } from 'svelte/store';
3
+ import { getContext, setContext } from 'svelte';
4
+ const MODAL_STORE_KEY = 'modalStore';
5
+ /**
6
+ * Retrieves the `modalStore`.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { getmodalStore } from "@skeletonlabs/skeleton";
11
+ *
12
+ * const modalStore = getModalStore();
13
+ *
14
+ * modalStore.trigger({ type: "alert", title: "Welcome!" });
15
+ * ```
16
+ */
17
+ export function getModalStore() {
18
+ const modalStore = getContext(MODAL_STORE_KEY);
19
+ if (!modalStore)
20
+ throw new Error('modalStore is not initialized. Please ensure that `initializeStores()` is invoked in the root layout file of this app!');
21
+ return modalStore;
22
+ }
23
+ /**
24
+ * Initializes the `modalStore`.
25
+ */
26
+ export function initializeModalStore() {
27
+ const modalStore = modalService();
28
+ return setContext(MODAL_STORE_KEY, modalStore);
29
+ }
3
30
  function modalService() {
4
31
  const { subscribe, set, update } = writable([]);
5
32
  return {
@@ -21,4 +48,3 @@ function modalService() {
21
48
  clear: () => set([])
22
49
  };
23
50
  }
24
- export const modalStore = modalService();
@@ -0,0 +1,7 @@
1
+ /// <reference types="svelte" />
2
+ /**
3
+ * Indicates that the user has enabled reduced motion on their device.
4
+ *
5
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion
6
+ */
7
+ export declare const prefersReducedMotionStore: import("svelte/store").Readable<boolean>;
@@ -0,0 +1,26 @@
1
+ import { readable } from 'svelte/store';
2
+ import { BROWSER } from 'esm-env';
3
+ /** Prefers reduced motion */
4
+ const reducedMotionQuery = '(prefers-reduced-motion: reduce)';
5
+ function prefersReducedMotion() {
6
+ if (!BROWSER)
7
+ return false;
8
+ return window.matchMedia(reducedMotionQuery).matches;
9
+ }
10
+ /**
11
+ * Indicates that the user has enabled reduced motion on their device.
12
+ *
13
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion
14
+ */
15
+ export const prefersReducedMotionStore = readable(prefersReducedMotion(), (set) => {
16
+ if (BROWSER) {
17
+ const setReducedMotion = (event) => {
18
+ set(event.matches);
19
+ };
20
+ const mediaQueryList = window.matchMedia(reducedMotionQuery);
21
+ mediaQueryList.addEventListener('change', setReducedMotion);
22
+ return () => {
23
+ mediaQueryList.removeEventListener('change', setReducedMotion);
24
+ };
25
+ }
26
+ });
@@ -0,0 +1,56 @@
1
+ <script>import { fade } from "svelte/transition";
2
+ import { tocStore, tocActiveId } from "./stores.js";
3
+ export let inactive = "opacity-60 hover:opacity-100";
4
+ export let active = "text-primary-500";
5
+ export let activeId = "";
6
+ export let indentStyles = {
7
+ h2: "",
8
+ h3: "ml-4",
9
+ h4: "ml-8",
10
+ h5: "ml-12",
11
+ h6: "ml-16"
12
+ };
13
+ export let regionLead = "font-bold";
14
+ export let regionList = "";
15
+ export let regionListItem = "";
16
+ export let regionAnchor = "";
17
+ const cBase = "space-y-4";
18
+ const cList = "space-y-2";
19
+ const cListItem = "block";
20
+ const cAnchor = "";
21
+ $:
22
+ reactiveActiveId = $tocActiveId ? $tocActiveId : activeId.replace("#", "");
23
+ $:
24
+ classesBase = `${cBase} ${$$props.class ?? ""}`;
25
+ $:
26
+ classesList = `${cList} ${regionList}`;
27
+ $:
28
+ classesListItem = `${cListItem} ${regionListItem}`;
29
+ $:
30
+ classesAnchor = `${cAnchor} ${regionAnchor}`;
31
+ </script>
32
+
33
+ {#if $tocStore.length}
34
+ <nav class="toc {classesBase}" data-testid="toc" transition:fade|local={{ duration: 100 }}>
35
+ <!-- Slot: Default (title) -->
36
+ <div class={regionLead}>
37
+ <slot>Table of Contents</slot>
38
+ </div>
39
+ <!-- List -->
40
+ <ul class="toc-list {classesList}">
41
+ {#each $tocStore as tocHeading}
42
+ <li class="toc-list-item {classesListItem} {indentStyles[tocHeading.element]}">
43
+ <a
44
+ href="#{tocHeading.id}"
45
+ class="toc-anchor {classesAnchor} {tocHeading.id === reactiveActiveId ? active : inactive}"
46
+ on:click={() => {
47
+ reactiveActiveId = tocHeading.id;
48
+ }}
49
+ >
50
+ {tocHeading.text}
51
+ </a>
52
+ </li>
53
+ {/each}
54
+ </ul>
55
+ </nav>
56
+ {/if}
@@ -0,0 +1,34 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ /** Provide classes to set the inactive anchor styles.*/
6
+ inactive?: string | undefined;
7
+ /** Provide classes to set the active anchor styles.*/
8
+ active?: string | undefined;
9
+ /** Set the active permalink ID on load.*/
10
+ activeId?: string | undefined;
11
+ /** Set indentation per each queried element.*/
12
+ indentStyles?: Record<string, string> | undefined;
13
+ /** Provide arbitrary classes to the lead regions, used for titles.*/
14
+ regionLead?: string | undefined;
15
+ /** Provide arbitrary classes to style the list element.*/
16
+ regionList?: string | undefined;
17
+ /** Provide arbitrary classes to style the list item elements.*/
18
+ regionListItem?: string | undefined;
19
+ /** Provide arbitrary classes to style the anchor elements.*/
20
+ regionAnchor?: string | undefined;
21
+ };
22
+ events: {
23
+ [evt: string]: CustomEvent<any>;
24
+ };
25
+ slots: {
26
+ default: {};
27
+ };
28
+ };
29
+ export type TableOfContentsProps = typeof __propDef.props;
30
+ export type TableOfContentsEvents = typeof __propDef.events;
31
+ export type TableOfContentsSlots = typeof __propDef.slots;
32
+ export default class TableOfContents extends SvelteComponentTyped<TableOfContentsProps, TableOfContentsEvents, TableOfContentsSlots> {
33
+ }
34
+ export {};
@@ -0,0 +1,14 @@
1
+ interface TOCCrawlerArgs {
2
+ /** Set generate mode to automatically set heading IDs. */
3
+ mode?: 'generate' | undefined;
4
+ /** Provide query list of elements. Defaults h2-h6. */
5
+ queryElements?: string;
6
+ scrollTarget?: string;
7
+ /** Reload the action when this key value changes. */
8
+ key?: unknown;
9
+ }
10
+ export declare function tocCrawler(node: HTMLElement, args?: TOCCrawlerArgs): {
11
+ update(newArgs: TOCCrawlerArgs): void;
12
+ destroy(): void;
13
+ };
14
+ export {};
@@ -0,0 +1,76 @@
1
+ // Action: Table of Contents Crawler
2
+ import { tocStore, tocActiveId } from './stores.js';
3
+ export function tocCrawler(node, args) {
4
+ let queryElements = 'h2, h3, h4, h5, h6';
5
+ let scrollTarget = 'body';
6
+ let headings;
7
+ let permalinks = [];
8
+ function init() {
9
+ // Reset headings
10
+ headings = node.querySelectorAll(queryElements);
11
+ // Reset the permalinks array:
12
+ permalinks = [];
13
+ // Set accepted list of query elements
14
+ if (args?.queryElements)
15
+ queryElements = args.queryElements;
16
+ // Set the desired scroll target to monitor
17
+ if (args?.scrollTarget)
18
+ scrollTarget = args.scrollTarget;
19
+ // Query and process the headings
20
+ queryHeadings();
21
+ }
22
+ function queryHeadings() {
23
+ headings?.forEach((elemHeading) => {
24
+ // If heading has ignore attribute, skip it
25
+ if (elemHeading.hasAttribute('data-toc-ignore'))
26
+ return;
27
+ // If generate mode and heading ID not present, assign one
28
+ if (args?.mode === 'generate' && !elemHeading.id) {
29
+ const newHeadingId = elemHeading.firstChild?.textContent
30
+ ?.trim()
31
+ .replaceAll(/[^a-zA-Z0-9 ]/g, '')
32
+ .replaceAll(' ', '-')
33
+ .toLowerCase();
34
+ elemHeading.id = newHeadingId || '';
35
+ }
36
+ // Push heading data to the permalink array
37
+ permalinks.push({
38
+ element: elemHeading.nodeName.toLowerCase(),
39
+ id: elemHeading.id,
40
+ text: elemHeading.firstChild?.textContent?.trim() || ''
41
+ });
42
+ });
43
+ // Set the store with the permalink array
44
+ tocStore.set(permalinks);
45
+ }
46
+ // Listens to scroll event, determines top-most heading, provides that to the `tocActiveId` store
47
+ function onWindowScroll(e) {
48
+ if (!headings?.length)
49
+ return;
50
+ const targetElem = e.target;
51
+ if (!(targetElem instanceof HTMLElement))
52
+ throw new Error('scrollTarget is not an HTMLElement');
53
+ const scrollableTop = targetElem.getBoundingClientRect().top || 0;
54
+ const headingSizeThreshold = 40; // px
55
+ for (const elemHeading of headings) {
56
+ const headerBoundTop = elemHeading.getBoundingClientRect().top;
57
+ const offsetTop = headerBoundTop - scrollableTop + headingSizeThreshold;
58
+ if (offsetTop >= 0)
59
+ return tocActiveId.set(elemHeading.id);
60
+ }
61
+ }
62
+ // Lifecycle
63
+ init();
64
+ if (scrollTarget)
65
+ document.querySelector(scrollTarget)?.addEventListener('scroll', onWindowScroll);
66
+ return {
67
+ update(newArgs) {
68
+ args = newArgs;
69
+ init();
70
+ },
71
+ destroy() {
72
+ if (scrollTarget)
73
+ document.querySelector(scrollTarget)?.removeEventListener('scroll', onWindowScroll);
74
+ }
75
+ };
76
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="svelte" />
2
+ import type { TOCHeadingLink } from './types.js';
3
+ /** Contains the set of table of contents link data. */
4
+ export declare const tocStore: import("svelte/store").Writable<TOCHeadingLink[]>;
5
+ /** Contains the ID of the top-most visible heading when scrolling. */
6
+ export declare const tocActiveId: import("svelte/store").Writable<string>;
@@ -0,0 +1,5 @@
1
+ import { writable } from 'svelte/store';
2
+ /** Contains the set of table of contents link data. */
3
+ export const tocStore = writable([]);
4
+ /** Contains the ID of the top-most visible heading when scrolling. */
5
+ export const tocActiveId = writable(undefined);
@@ -0,0 +1,5 @@
1
+ export interface TOCHeadingLink {
2
+ element: string;
3
+ id: string;
4
+ text: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ // Table of Content Types
2
+ export {};
@@ -1,10 +1,13 @@
1
- <script>import { crossfade } from "svelte/transition";
2
- import { cubicInOut } from "svelte/easing";
3
- import { flip } from "svelte/animate";
4
- import { toastStore } from "./stores.js";
1
+ <script context="module">import { fly } from "svelte/transition";
2
+ import { prefersReducedMotionStore } from "../../index.js";
3
+ import { dynamicTransition } from "../../internal/transitions.js";
4
+ </script>
5
+
6
+ <script generics="TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition">import { flip } from "svelte/animate";
7
+ import { getToastStore } from "./stores.js";
8
+ const toastStore = getToastStore();
5
9
  export let position = "b";
6
10
  export let max = 3;
7
- export let duration = 250;
8
11
  export let background = "variant-filled-secondary";
9
12
  export let width = "max-w-[640px]";
10
13
  export let color = "";
@@ -16,6 +19,11 @@ export let zIndex = "z-[888]";
16
19
  export let buttonAction = "btn variant-filled";
17
20
  export let buttonDismiss = "btn-icon btn-icon-sm variant-filled";
18
21
  export let buttonDismissLabel = "\u2715";
22
+ export let transitions = !$prefersReducedMotionStore;
23
+ export let transitionIn = fly;
24
+ export let transitionInParams = { duration: 250 };
25
+ export let transitionOut = fly;
26
+ export let transitionOutParams = { duration: 250 };
19
27
  const cWrapper = "flex fixed top-0 left-0 right-0 bottom-0 pointer-events-none";
20
28
  const cSnackbar = "flex flex-col gap-y-2";
21
29
  const cToast = "flex justify-between items-center pointer-events-auto";
@@ -89,21 +97,6 @@ $:
89
97
  classesToast = `${cToast} ${width} ${color} ${padding} ${spacing} ${rounded} ${shadow}`;
90
98
  $:
91
99
  filteredToasts = Array.from($toastStore).slice(0, max);
92
- const [send, receive] = crossfade({
93
- duration: (d) => Math.sqrt(d * duration),
94
- fallback(node) {
95
- const style = getComputedStyle(node);
96
- const transform = style.transform === "none" ? "" : style.transform;
97
- return {
98
- duration,
99
- easing: cubicInOut,
100
- css: (t, u) => `
101
- transform: ${transform} scale(${t}) translate(${u * animAxis.x}%, ${u * animAxis.y}%);
102
- opacity: ${t}
103
- `
104
- };
105
- }
106
- });
107
100
  </script>
108
101
 
109
102
  {#if $toastStore.length}
@@ -113,9 +106,17 @@ const [send, receive] = crossfade({
113
106
  <div class="snackbar {classesSnackbar}">
114
107
  {#each filteredToasts as t, i (t)}
115
108
  <div
116
- animate:flip={{ duration }}
117
- in:receive|global={{ key: t.id }}
118
- out:send|global={{ key: t.id }}
109
+ animate:flip={{ duration: transitions ? 250 : 0 }}
110
+ in:dynamicTransition|global={{
111
+ transition: transitionIn,
112
+ params: { x: animAxis.x, y: animAxis.y, ...transitionInParams },
113
+ enabled: transitions
114
+ }}
115
+ out:dynamicTransition|global={{
116
+ transition: transitionOut,
117
+ params: { x: animAxis.x, y: animAxis.y, ...transitionOutParams },
118
+ enabled: transitions
119
+ }}
119
120
  on:mouseenter={() => onMouseEnter(i)}
120
121
  on:mouseleave={() => onMouseLeave(i)}
121
122
  role={t.hideDismiss ? 'alert' : 'alertdialog'}
@@ -1,44 +1,37 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- declare const __propDef: {
3
- props: {
2
+ import { fly } from 'svelte/transition';
3
+ import { type Transition, type TransitionParams } from '../../index.js';
4
+ type FlyTransition = typeof fly;
5
+ declare class __sveltets_Render<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> {
6
+ props(): {
4
7
  [x: string]: any;
5
- /** Set the toast position.*/
6
8
  position?: "b" | "br" | "tr" | "t" | "l" | "r" | "tl" | "bl" | undefined;
7
- /** Maximum toasts that can show at once.*/
8
9
  max?: number | undefined;
9
- /** The duration of the fly in/out animation.*/
10
- duration?: number | undefined;
11
- /** Provide classes to set the background color.*/
12
10
  background?: string | undefined;
13
- /** Provide classes to set width styles.*/
14
11
  width?: string | undefined;
15
- /** Provide classes to set the text color.*/
16
12
  color?: string | undefined;
17
- /** Provide classes to set the padding.*/
18
13
  padding?: string | undefined;
19
- /** Provide classes to set toast horizontal spacing.*/
20
14
  spacing?: string | undefined;
21
- /** Provide classes to set the border radius styles.*/
22
15
  rounded?: string | undefined;
23
- /** Provide classes to set the border box shadow.*/
24
16
  shadow?: string | undefined;
25
- /** Provide a class to override the z-index*/
26
17
  zIndex?: string | undefined;
27
- /** Provide styles for the action button.*/
28
18
  buttonAction?: string | undefined;
29
- /** Provide styles for the dismiss button.*/
30
19
  buttonDismiss?: string | undefined;
31
- /** The button label text.*/
32
20
  buttonDismissLabel?: string | undefined;
21
+ transitions?: boolean | undefined;
22
+ transitionIn?: TransitionIn | undefined;
23
+ transitionInParams?: TransitionParams<TransitionIn> | undefined;
24
+ transitionOut?: TransitionOut | undefined;
25
+ transitionOutParams?: TransitionParams<TransitionOut> | undefined;
33
26
  };
34
- events: {
27
+ events(): {} & {
35
28
  [evt: string]: CustomEvent<any>;
36
29
  };
37
- slots: {};
38
- };
39
- export type ToastProps = typeof __propDef.props;
40
- export type ToastEvents = typeof __propDef.events;
41
- export type ToastSlots = typeof __propDef.slots;
42
- export default class Toast extends SvelteComponentTyped<ToastProps, ToastEvents, ToastSlots> {
30
+ slots(): {};
31
+ }
32
+ export type ToastProps<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> = ReturnType<__sveltets_Render<TransitionIn, TransitionOut>['props']>;
33
+ export type ToastEvents<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> = ReturnType<__sveltets_Render<TransitionIn, TransitionOut>['events']>;
34
+ export type ToastSlots<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> = ReturnType<__sveltets_Render<TransitionIn, TransitionOut>['slots']>;
35
+ export default class Toast<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> extends SvelteComponentTyped<ToastProps<TransitionIn, TransitionOut>, ToastEvents<TransitionIn, TransitionOut>, ToastSlots<TransitionIn, TransitionOut>> {
43
36
  }
44
37
  export {};