@salt-ds/embla-carousel 0.1.4 → 0.1.6

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 (88) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/css/salt-embla-carousel.css +42 -22
  3. package/dist-cjs/Carousel.js +30 -9
  4. package/dist-cjs/Carousel.js.map +1 -1
  5. package/dist-cjs/CarouselAutoplayIndicator.js.map +1 -1
  6. package/dist-cjs/CarouselAutoplayIndicatorSVG.js.map +1 -1
  7. package/dist-cjs/CarouselCard.css.js +1 -1
  8. package/dist-cjs/CarouselCard.js +18 -8
  9. package/dist-cjs/CarouselCard.js.map +1 -1
  10. package/dist-cjs/CarouselContext.js.map +1 -1
  11. package/dist-cjs/CarouselNextButton.js +4 -1
  12. package/dist-cjs/CarouselNextButton.js.map +1 -1
  13. package/dist-cjs/CarouselPreviousButton.js +4 -1
  14. package/dist-cjs/CarouselPreviousButton.js.map +1 -1
  15. package/dist-cjs/CarouselProgressLabel.js +11 -33
  16. package/dist-cjs/CarouselProgressLabel.js.map +1 -1
  17. package/dist-cjs/CarouselSlides.css.js +1 -1
  18. package/dist-cjs/CarouselSlides.js +119 -23
  19. package/dist-cjs/CarouselSlides.js.map +1 -1
  20. package/dist-cjs/CarouselTab.css.js +1 -1
  21. package/dist-cjs/CarouselTab.js +1 -5
  22. package/dist-cjs/CarouselTab.js.map +1 -1
  23. package/dist-cjs/CarouselTabList.css.js +1 -1
  24. package/dist-cjs/CarouselTabList.js +41 -27
  25. package/dist-cjs/CarouselTabList.js.map +1 -1
  26. package/dist-cjs/createCustomSettle.js.map +1 -1
  27. package/dist-cjs/getSlideDescription.js +32 -0
  28. package/dist-cjs/getSlideDescription.js.map +1 -0
  29. package/dist-cjs/getVisibleSlideDescription.js +26 -0
  30. package/dist-cjs/getVisibleSlideDescription.js.map +1 -0
  31. package/dist-cjs/getVisibleSlideIndexes.js +33 -0
  32. package/dist-cjs/getVisibleSlideIndexes.js.map +1 -0
  33. package/dist-cjs/index.js +0 -3
  34. package/dist-cjs/index.js.map +1 -1
  35. package/dist-cjs/usePrevNextButtons.js +3 -1
  36. package/dist-cjs/usePrevNextButtons.js.map +1 -1
  37. package/dist-es/Carousel.js +32 -11
  38. package/dist-es/Carousel.js.map +1 -1
  39. package/dist-es/CarouselAutoplayIndicator.js.map +1 -1
  40. package/dist-es/CarouselAutoplayIndicatorSVG.js.map +1 -1
  41. package/dist-es/CarouselCard.css.js +1 -1
  42. package/dist-es/CarouselCard.js +18 -8
  43. package/dist-es/CarouselCard.js.map +1 -1
  44. package/dist-es/CarouselContext.js.map +1 -1
  45. package/dist-es/CarouselNextButton.js +4 -1
  46. package/dist-es/CarouselNextButton.js.map +1 -1
  47. package/dist-es/CarouselPreviousButton.js +4 -1
  48. package/dist-es/CarouselPreviousButton.js.map +1 -1
  49. package/dist-es/CarouselProgressLabel.js +12 -34
  50. package/dist-es/CarouselProgressLabel.js.map +1 -1
  51. package/dist-es/CarouselSlides.css.js +1 -1
  52. package/dist-es/CarouselSlides.js +121 -25
  53. package/dist-es/CarouselSlides.js.map +1 -1
  54. package/dist-es/CarouselTab.css.js +1 -1
  55. package/dist-es/CarouselTab.js +1 -5
  56. package/dist-es/CarouselTab.js.map +1 -1
  57. package/dist-es/CarouselTabList.css.js +1 -1
  58. package/dist-es/CarouselTabList.js +42 -28
  59. package/dist-es/CarouselTabList.js.map +1 -1
  60. package/dist-es/createCustomSettle.js.map +1 -1
  61. package/dist-es/getSlideDescription.js +30 -0
  62. package/dist-es/getSlideDescription.js.map +1 -0
  63. package/dist-es/getVisibleSlideDescription.js +24 -0
  64. package/dist-es/getVisibleSlideDescription.js.map +1 -0
  65. package/dist-es/getVisibleSlideIndexes.js +30 -0
  66. package/dist-es/getVisibleSlideIndexes.js.map +1 -0
  67. package/dist-es/index.js +0 -1
  68. package/dist-es/index.js.map +1 -1
  69. package/dist-es/usePrevNextButtons.js +3 -1
  70. package/dist-es/usePrevNextButtons.js.map +1 -1
  71. package/dist-types/Carousel.d.ts +7 -1
  72. package/dist-types/CarouselContext.d.ts +31 -0
  73. package/dist-types/CarouselTab.d.ts +0 -6
  74. package/dist-types/CarouselTabList.d.ts +4 -0
  75. package/dist-types/getSlideDescription.d.ts +7 -0
  76. package/dist-types/getVisibleSlideDescription.d.ts +7 -0
  77. package/dist-types/getVisibleSlideIndexes.d.ts +8 -0
  78. package/dist-types/index.d.ts +0 -1
  79. package/package.json +2 -2
  80. package/dist-cjs/CarouselAnnouncementPlugin.js +0 -52
  81. package/dist-cjs/CarouselAnnouncementPlugin.js.map +0 -1
  82. package/dist-cjs/CarouselProgressLabel.css.js +0 -6
  83. package/dist-cjs/CarouselProgressLabel.css.js.map +0 -1
  84. package/dist-es/CarouselAnnouncementPlugin.js +0 -49
  85. package/dist-es/CarouselAnnouncementPlugin.js.map +0 -1
  86. package/dist-es/CarouselProgressLabel.css.js +0 -4
  87. package/dist-es/CarouselProgressLabel.css.js.map +0 -1
  88. package/dist-types/CarouselAnnouncementPlugin.d.ts +0 -24
@@ -4,11 +4,13 @@ import { useCarouselContext } from './CarouselContext.js';
4
4
  const usePrevNextButtons = () => {
5
5
  const [prevBtnDisabled, setPrevBtnDisabled] = useState(true);
6
6
  const [nextBtnDisabled, setNextBtnDisabled] = useState(true);
7
- const { emblaApi } = useCarouselContext();
7
+ const { emblaApi, setAnnouncementState } = useCarouselContext();
8
8
  const handlePrevButtonClick = () => {
9
+ setAnnouncementState("navigation");
9
10
  emblaApi == null ? void 0 : emblaApi.scrollPrev();
10
11
  };
11
12
  const handleNextButtonClick = () => {
13
+ setAnnouncementState("navigation");
12
14
  emblaApi == null ? void 0 : emblaApi.scrollNext();
13
15
  };
14
16
  useEffect(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"usePrevNextButtons.js","sources":["../src/usePrevNextButtons.tsx"],"sourcesContent":["import type { EmblaCarouselType } from \"embla-carousel\";\nimport { useEffect, useState } from \"react\";\nimport { useCarouselContext } from \"./CarouselContext\";\n\ntype UsePrevNextButtonsType = {\n /**\n * Indicates whether the previous button is disabled.\n */\n prevBtnDisabled: boolean;\n /**\n * Indicates whether the next button is disabled.\n */\n nextBtnDisabled: boolean;\n /**\n * Handles the click event for the previous button.\n */\n onPrevButtonClick: () => void;\n /**\n * Handles the click event for the next button.\n */\n onNextButtonClick: () => void;\n};\n\nexport const usePrevNextButtons = (): UsePrevNextButtonsType => {\n const [prevBtnDisabled, setPrevBtnDisabled] = useState(true);\n const [nextBtnDisabled, setNextBtnDisabled] = useState(true);\n\n const { emblaApi } = useCarouselContext();\n\n const handlePrevButtonClick = () => {\n emblaApi?.scrollPrev();\n };\n\n const handleNextButtonClick = () => {\n emblaApi?.scrollNext();\n };\n\n useEffect(() => {\n const handleSelect = (emblaApi: EmblaCarouselType) => {\n setPrevBtnDisabled(!emblaApi.canScrollPrev());\n setNextBtnDisabled(!emblaApi.canScrollNext());\n };\n\n if (!emblaApi) {\n return;\n }\n handleSelect(emblaApi);\n emblaApi\n .on(\"init\", handleSelect)\n .on(\"reInit\", handleSelect)\n .on(\"select\", handleSelect);\n // Cleanup listener on component unmount\n return () => {\n emblaApi\n .off(\"init\", handleSelect)\n .off(\"reInit\", handleSelect)\n .off(\"select\", handleSelect);\n };\n }, [emblaApi]);\n\n return {\n prevBtnDisabled,\n nextBtnDisabled,\n onPrevButtonClick: handlePrevButtonClick,\n onNextButtonClick: handleNextButtonClick,\n };\n};\n"],"names":["emblaApi"],"mappings":";;;AAuBO,MAAM,qBAAqB,MAA8B;AAC9D,EAAA,MAAM,CAAC,eAAA,EAAiB,kBAAkB,CAAA,GAAI,SAAS,IAAI,CAAA;AAC3D,EAAA,MAAM,CAAC,eAAA,EAAiB,kBAAkB,CAAA,GAAI,SAAS,IAAI,CAAA;AAE3D,EAAM,MAAA,EAAE,QAAS,EAAA,GAAI,kBAAmB,EAAA;AAExC,EAAA,MAAM,wBAAwB,MAAM;AAClC,IAAU,QAAA,IAAA,IAAA,GAAA,MAAA,GAAA,QAAA,CAAA,UAAA,EAAA;AAAA,GACZ;AAEA,EAAA,MAAM,wBAAwB,MAAM;AAClC,IAAU,QAAA,IAAA,IAAA,GAAA,MAAA,GAAA,QAAA,CAAA,UAAA,EAAA;AAAA,GACZ;AAEA,EAAA,SAAA,CAAU,MAAM;AACd,IAAM,MAAA,YAAA,GAAe,CAACA,SAAgC,KAAA;AACpD,MAAmB,kBAAA,CAAA,CAACA,SAAS,CAAA,aAAA,EAAe,CAAA;AAC5C,MAAmB,kBAAA,CAAA,CAACA,SAAS,CAAA,aAAA,EAAe,CAAA;AAAA,KAC9C;AAEA,IAAA,IAAI,CAAC,QAAU,EAAA;AACb,MAAA;AAAA;AAEF,IAAA,YAAA,CAAa,QAAQ,CAAA;AACrB,IACG,QAAA,CAAA,EAAA,CAAG,MAAQ,EAAA,YAAY,CACvB,CAAA,EAAA,CAAG,UAAU,YAAY,CAAA,CACzB,EAAG,CAAA,QAAA,EAAU,YAAY,CAAA;AAE5B,IAAA,OAAO,MAAM;AACX,MACG,QAAA,CAAA,GAAA,CAAI,MAAQ,EAAA,YAAY,CACxB,CAAA,GAAA,CAAI,UAAU,YAAY,CAAA,CAC1B,GAAI,CAAA,QAAA,EAAU,YAAY,CAAA;AAAA,KAC/B;AAAA,GACF,EAAG,CAAC,QAAQ,CAAC,CAAA;AAEb,EAAO,OAAA;AAAA,IACL,eAAA;AAAA,IACA,eAAA;AAAA,IACA,iBAAmB,EAAA,qBAAA;AAAA,IACnB,iBAAmB,EAAA;AAAA,GACrB;AACF;;;;"}
1
+ {"version":3,"file":"usePrevNextButtons.js","sources":["../src/usePrevNextButtons.tsx"],"sourcesContent":["import type { EmblaCarouselType } from \"embla-carousel\";\nimport { useEffect, useState } from \"react\";\nimport { useCarouselContext } from \"./CarouselContext\";\n\ntype UsePrevNextButtonsType = {\n /**\n * Indicates whether the previous button is disabled.\n */\n prevBtnDisabled: boolean;\n /**\n * Indicates whether the next button is disabled.\n */\n nextBtnDisabled: boolean;\n /**\n * Handles the click event for the previous button.\n */\n onPrevButtonClick: () => void;\n /**\n * Handles the click event for the next button.\n */\n onNextButtonClick: () => void;\n};\n\nexport const usePrevNextButtons = (): UsePrevNextButtonsType => {\n const [prevBtnDisabled, setPrevBtnDisabled] = useState(true);\n const [nextBtnDisabled, setNextBtnDisabled] = useState(true);\n\n const { emblaApi, setAnnouncementState } = useCarouselContext();\n\n const handlePrevButtonClick = () => {\n setAnnouncementState(\"navigation\");\n emblaApi?.scrollPrev();\n };\n\n const handleNextButtonClick = () => {\n setAnnouncementState(\"navigation\");\n emblaApi?.scrollNext();\n };\n\n useEffect(() => {\n const handleSelect = (emblaApi: EmblaCarouselType) => {\n setPrevBtnDisabled(!emblaApi.canScrollPrev());\n setNextBtnDisabled(!emblaApi.canScrollNext());\n };\n\n if (!emblaApi) {\n return;\n }\n handleSelect(emblaApi);\n emblaApi\n .on(\"init\", handleSelect)\n .on(\"reInit\", handleSelect)\n .on(\"select\", handleSelect);\n // Cleanup listener on component unmount\n return () => {\n emblaApi\n .off(\"init\", handleSelect)\n .off(\"reInit\", handleSelect)\n .off(\"select\", handleSelect);\n };\n }, [emblaApi]);\n\n return {\n prevBtnDisabled,\n nextBtnDisabled,\n onPrevButtonClick: handlePrevButtonClick,\n onNextButtonClick: handleNextButtonClick,\n };\n};\n"],"names":["emblaApi"],"mappings":";;;AAuBO,MAAM,qBAAqB,MAA8B;AAC9D,EAAA,MAAM,CAAC,eAAA,EAAiB,kBAAkB,CAAA,GAAI,SAAS,IAAI,CAAA;AAC3D,EAAA,MAAM,CAAC,eAAA,EAAiB,kBAAkB,CAAA,GAAI,SAAS,IAAI,CAAA;AAE3D,EAAA,MAAM,EAAE,QAAA,EAAU,oBAAA,EAAqB,GAAI,kBAAA,EAAmB;AAE9D,EAAA,MAAM,wBAAwB,MAAM;AAClC,IAAA,oBAAA,CAAqB,YAAY,CAAA;AACjC,IAAA,QAAA,IAAA,IAAA,GAAA,MAAA,GAAA,QAAA,CAAU,UAAA,EAAA;AAAA,EACZ,CAAA;AAEA,EAAA,MAAM,wBAAwB,MAAM;AAClC,IAAA,oBAAA,CAAqB,YAAY,CAAA;AACjC,IAAA,QAAA,IAAA,IAAA,GAAA,MAAA,GAAA,QAAA,CAAU,UAAA,EAAA;AAAA,EACZ,CAAA;AAEA,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAM,YAAA,GAAe,CAACA,SAAAA,KAAgC;AACpD,MAAA,kBAAA,CAAmB,CAACA,SAAAA,CAAS,aAAA,EAAe,CAAA;AAC5C,MAAA,kBAAA,CAAmB,CAACA,SAAAA,CAAS,aAAA,EAAe,CAAA;AAAA,IAC9C,CAAA;AAEA,IAAA,IAAI,CAAC,QAAA,EAAU;AACb,MAAA;AAAA,IACF;AACA,IAAA,YAAA,CAAa,QAAQ,CAAA;AACrB,IAAA,QAAA,CACG,EAAA,CAAG,MAAA,EAAQ,YAAY,CAAA,CACvB,EAAA,CAAG,UAAU,YAAY,CAAA,CACzB,EAAA,CAAG,QAAA,EAAU,YAAY,CAAA;AAE5B,IAAA,OAAO,MAAM;AACX,MAAA,QAAA,CACG,GAAA,CAAI,MAAA,EAAQ,YAAY,CAAA,CACxB,GAAA,CAAI,UAAU,YAAY,CAAA,CAC1B,GAAA,CAAI,QAAA,EAAU,YAAY,CAAA;AAAA,IAC/B,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAEb,EAAA,OAAO;AAAA,IACL,eAAA;AAAA,IACA,eAAA;AAAA,IACA,iBAAA,EAAmB,qBAAA;AAAA,IACnB,iBAAA,EAAmB;AAAA,GACrB;AACF;;;;"}
@@ -20,8 +20,14 @@ export interface CarouselProps extends ComponentPropsWithoutRef<"section"> {
20
20
  * These options are passed directly to the Embla Carousel instance.
21
21
  */
22
22
  emblaPlugins?: CarouselPlugin;
23
- /** Get embla API instance, use this to manage the state of the Carousel */
23
+ /**
24
+ * Get embla API instance, use this to manage the state of the Carousel
25
+ **/
24
26
  getEmblaApi?: (embla: CarouselEmblaApiType) => void;
27
+ /**
28
+ * Disable screenreader announcing slide updates, defaults to false.
29
+ */
30
+ disableSlideAnnouncements?: boolean;
25
31
  }
26
32
  export declare const Carousel: import("react").ForwardRefExoticComponent<CarouselProps & import("react").RefAttributes<HTMLElement>>;
27
33
  export {};
@@ -1,4 +1,7 @@
1
+ import { type Dispatch, type SetStateAction } from "react";
1
2
  import type { CarouselEmblaApiType, CarouselEmblaRefType } from "./Carousel";
3
+ export type CarouselAriaVariant = "group" | "tabpanel";
4
+ export type CarouselAnnouncementTrigger = "tab" | "navigation" | "drag" | "focus";
2
5
  /**
3
6
  * Type definition for the Carousel context.
4
7
  * Provides access to the Embla Carousel API and reference.
@@ -14,6 +17,34 @@ interface CarouselContextType {
14
17
  * Used to directly interact with the carousel DOM element.
15
18
  */
16
19
  emblaRef?: CarouselEmblaRefType;
20
+ /**
21
+ * Aria variant for the Carousel.
22
+ * When used with a `CarouselTabList` the screenreader will be presented as a `tablist` of tabpanels.
23
+ * When used without a `CarouselTabList` the screenreader will be presented as a `group` of slides.
24
+ */
25
+ ariaVariant: CarouselAriaVariant;
26
+ /**
27
+ * Function to set the aria variant for the Carousel.
28
+ */
29
+ setAriaVariant: Dispatch<SetStateAction<CarouselAriaVariant>>;
30
+ /**
31
+ * Disable screenreader announcing slide updates, defaults to false.
32
+ */
33
+ disableSlideAnnouncements?: boolean;
34
+ /**
35
+ * Id for the carousel
36
+ */
37
+ carouselId: string | undefined;
38
+ /**
39
+ * Announcement state, determines whether change is communicated to screenreader.
40
+ * @param trigger
41
+ */
42
+ announcementState: CarouselAnnouncementTrigger | undefined;
43
+ /**
44
+ * Set announcement state, determines whether change is communicated to screenreader.
45
+ * @param trigger
46
+ */
47
+ setAnnouncementState: (trigger: CarouselAnnouncementTrigger | undefined) => void;
17
48
  }
18
49
  export declare const CarouselContext: import("react").Context<CarouselContextType | undefined>;
19
50
  export declare const useCarouselContext: () => CarouselContextType;
@@ -13,12 +13,6 @@ type UseCarouselTabProps = {
13
13
  * An array of scroll snap positions for the carousel slides.
14
14
  */
15
15
  scrollSnaps: number[];
16
- /**
17
- * Handler function for clicking a tab button to navigate to a specific slide.
18
- *
19
- * @param index - The index of the slide to navigate to.
20
- */
21
- onClick: (index: number) => void;
22
16
  };
23
17
  export declare const useCarouselTab: (emblaApi: EmblaCarouselType | undefined) => UseCarouselTabProps;
24
18
  /**
@@ -1,5 +1,6 @@
1
1
  import { type RenderPropsType } from "@salt-ds/core";
2
2
  import { type HTMLAttributes } from "react";
3
+ import { type CarouselTabProps } from "./CarouselTab";
3
4
  /**
4
5
  * Props for the CarouselTabList component.
5
6
  */
@@ -9,4 +10,7 @@ export interface CarouselTabListProps extends HTMLAttributes<HTMLDivElement> {
9
10
  */
10
11
  render?: RenderPropsType["render"];
11
12
  }
13
+ export interface CarouselTabRendererProps extends CarouselTabProps {
14
+ render?: CarouselTabListProps["render"];
15
+ }
12
16
  export declare const CarouselTabList: import("react").ForwardRefExoticComponent<CarouselTabListProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,7 @@
1
+ import type { EmblaCarouselType } from "embla-carousel";
2
+ /** Get a description of the slide.
3
+ * @param emblaApi
4
+ * @param slideIndex
5
+ * @returns A slide description if defined or an empty string
6
+ */
7
+ export declare const getSlideDescription: (emblaApi: EmblaCarouselType | undefined, slideNumber: number) => string;
@@ -0,0 +1,7 @@
1
+ import type { EmblaCarouselType } from "embla-carousel";
2
+ /** Get a description of the visible slide(s).
3
+ * @param emblaApi
4
+ * @param slideIndex
5
+ * @returns An array of descriptions for the visible slides
6
+ */
7
+ export declare const getVisibleSlideDescription: (emblaApi: EmblaCarouselType | undefined, scrollSnapIndex: number) => string;
@@ -0,0 +1,8 @@
1
+ import type { EmblaCarouselType } from "embla-carousel";
2
+ export declare const getSlideNumberRange: (startSlideNumber: number, endSlideNumber: number) => number[];
3
+ /** Get the visible slide indexes
4
+ * @param emblaApi
5
+ * @param scrollSnap
6
+ * @returns An array of visible slide indexes
7
+ */
8
+ export declare const getVisibleSlideIndexes: (emblaApi: EmblaCarouselType | undefined, scrollSnapIndex: number) => number[];
@@ -1,5 +1,4 @@
1
1
  export * from "./Carousel";
2
- export * from "./CarouselAnnouncementPlugin";
3
2
  export * from "./CarouselAutoplayIndicator";
4
3
  export * from "./CarouselCard";
5
4
  export * from "./CarouselContext";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salt-ds/embla-carousel",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,7 +20,7 @@
20
20
  "*.css"
21
21
  ],
22
22
  "dependencies": {
23
- "@salt-ds/core": "^1.47.5",
23
+ "@salt-ds/core": "^1.49.0",
24
24
  "clsx": "^2.0.0"
25
25
  },
26
26
  "devDependencies": {
@@ -1,52 +0,0 @@
1
- 'use strict';
2
-
3
- var core = require('@salt-ds/core');
4
- var react = require('react');
5
-
6
- const getSlideLabel = (emblaApi) => {
7
- var _a;
8
- const slideCount = (emblaApi == null ? void 0 : emblaApi.slideNodes().length) ?? 0;
9
- const slideIndexInView = ((_a = emblaApi == null ? void 0 : emblaApi.slidesInView()) == null ? void 0 : _a[0]) ?? 0;
10
- const slideElement = emblaApi == null ? void 0 : emblaApi.slideNodes()[slideIndexInView];
11
- let description = slideElement == null ? void 0 : slideElement.getAttribute("aria-label");
12
- if (!description) {
13
- const labelledById = slideElement == null ? void 0 : slideElement.getAttribute("aria-labelledby");
14
- const { ownerDocument } = emblaApi.internalEngine();
15
- if (labelledById) {
16
- const labelledByElement = ownerDocument.getElementById(labelledById);
17
- description = (labelledByElement == null ? void 0 : labelledByElement.textContent) || "No description available";
18
- } else {
19
- description = "No description available";
20
- }
21
- }
22
- return `slide ${slideIndexInView + 1} of ${slideCount}. ${description}`;
23
- };
24
- function CarouselAnnouncement(userOptions = {}) {
25
- let emblaApi;
26
- const { announce } = core.useAriaAnnouncer();
27
- const handleSettle = react.useCallback(
28
- (emblaApi2) => {
29
- const slideLabel = getSlideLabel(emblaApi2);
30
- announce(slideLabel);
31
- },
32
- [announce]
33
- );
34
- function init(emblaApiInstance) {
35
- emblaApi = emblaApiInstance;
36
- emblaApi.on("settle", handleSettle);
37
- }
38
- function destroy() {
39
- emblaApi.off("settle", handleSettle);
40
- }
41
- const self = {
42
- name: "announcement",
43
- options: userOptions,
44
- init,
45
- destroy
46
- };
47
- return self;
48
- }
49
-
50
- exports.CarouselAnnouncement = CarouselAnnouncement;
51
- exports.getSlideLabel = getSlideLabel;
52
- //# sourceMappingURL=CarouselAnnouncementPlugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CarouselAnnouncementPlugin.js","sources":["../src/CarouselAnnouncementPlugin.ts"],"sourcesContent":["import { useAriaAnnouncer } from \"@salt-ds/core\";\nimport type {\n CreateOptionsType,\n CreatePluginType,\n EmblaCarouselType,\n} from \"embla-carousel\";\nimport { useCallback } from \"react\";\n\ndeclare module \"embla-carousel\" {\n interface EmblaPluginsType {\n announcement: CarouselAnnouncementType;\n }\n}\n\n/**\n * Type definition for the parameters of the getSlideLabel function.\n * @returns A string that describes the slide, including its index and total count.\n */\nexport type GetSlideLabelProps = (emblaApi: EmblaCarouselType) => string;\n\n/** * Generates a label for a carousel slide based on ARIA attributes.\n * This function retrieves the slide's ARIA label or text content and formats it into a descriptive string.\n * @param slideElement\n * @param slideIndex\n * @param slideCount\n * @returns A string description of the slide, including its position and ARIA label or text content.\n */\nexport const getSlideLabel: GetSlideLabelProps = (emblaApi): string => {\n const slideCount = emblaApi?.slideNodes().length ?? 0;\n const slideIndexInView = emblaApi?.slidesInView()?.[0] ?? 0;\n const slideElement = emblaApi?.slideNodes()[slideIndexInView];\n\n let description = slideElement?.getAttribute(\"aria-label\");\n if (!description) {\n const labelledById = slideElement?.getAttribute(\"aria-labelledby\");\n const { ownerDocument } = emblaApi.internalEngine();\n if (labelledById) {\n const labelledByElement = ownerDocument.getElementById(labelledById);\n description =\n labelledByElement?.textContent || \"No description available\";\n } else {\n description = \"No description available\";\n }\n }\n return `slide ${slideIndexInView + 1} of ${slideCount}. ${description}`;\n};\n\n// biome-ignore lint/complexity/noBannedTypes: Replicated from embla docs/code\ntype OptionsType = CreateOptionsType<{}>;\n// biome-ignore lint/complexity/noBannedTypes: Replicated from embla docs/code\nexport type CarouselAnnouncementType = CreatePluginType<{}, OptionsType>;\n\nexport type CarouselAnnouncementOptionsType =\n CarouselAnnouncementType[\"options\"];\n\nexport function CarouselAnnouncement(\n userOptions: CarouselAnnouncementOptionsType = {},\n): CarouselAnnouncementType {\n let emblaApi: EmblaCarouselType;\n\n const { announce } = useAriaAnnouncer();\n\n const handleSettle = useCallback(\n (emblaApi: EmblaCarouselType) => {\n const slideLabel = getSlideLabel(emblaApi);\n announce(slideLabel);\n },\n [announce],\n );\n\n function init(emblaApiInstance: EmblaCarouselType): void {\n emblaApi = emblaApiInstance;\n emblaApi.on(\"settle\", handleSettle);\n }\n\n function destroy(): void {\n emblaApi.off(\"settle\", handleSettle);\n }\n\n const self: CarouselAnnouncementType = {\n name: \"announcement\",\n options: userOptions,\n init,\n destroy,\n };\n return self;\n}\n"],"names":["useAriaAnnouncer","useCallback","emblaApi"],"mappings":";;;;;AA2Ba,MAAA,aAAA,GAAoC,CAAC,QAAqB,KAAA;AA3BvE,EAAA,IAAA,EAAA;AA4BE,EAAM,MAAA,UAAA,GAAA,CAAa,QAAU,IAAA,IAAA,GAAA,MAAA,GAAA,QAAA,CAAA,UAAA,EAAA,CAAa,MAAU,KAAA,CAAA;AACpD,EAAA,MAAM,gBAAmB,GAAA,CAAA,CAAA,EAAA,GAAA,QAAA,IAAA,IAAA,GAAA,MAAA,GAAA,QAAA,CAAU,YAAV,EAAA,KAAA,IAAA,GAAA,MAAA,GAAA,EAAA,CAA2B,CAAM,CAAA,KAAA,CAAA;AAC1D,EAAM,MAAA,YAAA,GAAe,qCAAU,UAAa,EAAA,CAAA,gBAAA,CAAA;AAE5C,EAAI,IAAA,WAAA,GAAc,6CAAc,YAAa,CAAA,YAAA,CAAA;AAC7C,EAAA,IAAI,CAAC,WAAa,EAAA;AAChB,IAAM,MAAA,YAAA,GAAe,6CAAc,YAAa,CAAA,iBAAA,CAAA;AAChD,IAAA,MAAM,EAAE,aAAA,EAAkB,GAAA,QAAA,CAAS,cAAe,EAAA;AAClD,IAAA,IAAI,YAAc,EAAA;AAChB,MAAM,MAAA,iBAAA,GAAoB,aAAc,CAAA,cAAA,CAAe,YAAY,CAAA;AACnE,MAAA,WAAA,GAAA,CACE,uDAAmB,WAAe,KAAA,0BAAA;AAAA,KAC/B,MAAA;AACL,MAAc,WAAA,GAAA,0BAAA;AAAA;AAChB;AAEF,EAAA,OAAO,SAAS,gBAAmB,GAAA,CAAC,CAAO,IAAA,EAAA,UAAU,KAAK,WAAW,CAAA,CAAA;AACvE;AAUgB,SAAA,oBAAA,CACd,WAA+C,GAAA,EACrB,EAAA;AAC1B,EAAI,IAAA,QAAA;AAEJ,EAAM,MAAA,EAAE,QAAS,EAAA,GAAIA,qBAAiB,EAAA;AAEtC,EAAA,MAAM,YAAe,GAAAC,iBAAA;AAAA,IACnB,CAACC,SAAgC,KAAA;AAC/B,MAAM,MAAA,UAAA,GAAa,cAAcA,SAAQ,CAAA;AACzC,MAAA,QAAA,CAAS,UAAU,CAAA;AAAA,KACrB;AAAA,IACA,CAAC,QAAQ;AAAA,GACX;AAEA,EAAA,SAAS,KAAK,gBAA2C,EAAA;AACvD,IAAW,QAAA,GAAA,gBAAA;AACX,IAAS,QAAA,CAAA,EAAA,CAAG,UAAU,YAAY,CAAA;AAAA;AAGpC,EAAA,SAAS,OAAgB,GAAA;AACvB,IAAS,QAAA,CAAA,GAAA,CAAI,UAAU,YAAY,CAAA;AAAA;AAGrC,EAAA,MAAM,IAAiC,GAAA;AAAA,IACrC,IAAM,EAAA,cAAA;AAAA,IACN,OAAS,EAAA,WAAA;AAAA,IACT,IAAA;AAAA,IACA;AAAA,GACF;AACA,EAAO,OAAA,IAAA;AACT;;;;;"}
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- var css_248z = ".saltCarouselTabList.saltText {\n font-weight: var(--salt-text-fontWeight-strong);\n}\n";
4
-
5
- module.exports = css_248z;
6
- //# sourceMappingURL=CarouselProgressLabel.css.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CarouselProgressLabel.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -1,49 +0,0 @@
1
- import { useAriaAnnouncer } from '@salt-ds/core';
2
- import { useCallback } from 'react';
3
-
4
- const getSlideLabel = (emblaApi) => {
5
- var _a;
6
- const slideCount = (emblaApi == null ? void 0 : emblaApi.slideNodes().length) ?? 0;
7
- const slideIndexInView = ((_a = emblaApi == null ? void 0 : emblaApi.slidesInView()) == null ? void 0 : _a[0]) ?? 0;
8
- const slideElement = emblaApi == null ? void 0 : emblaApi.slideNodes()[slideIndexInView];
9
- let description = slideElement == null ? void 0 : slideElement.getAttribute("aria-label");
10
- if (!description) {
11
- const labelledById = slideElement == null ? void 0 : slideElement.getAttribute("aria-labelledby");
12
- const { ownerDocument } = emblaApi.internalEngine();
13
- if (labelledById) {
14
- const labelledByElement = ownerDocument.getElementById(labelledById);
15
- description = (labelledByElement == null ? void 0 : labelledByElement.textContent) || "No description available";
16
- } else {
17
- description = "No description available";
18
- }
19
- }
20
- return `slide ${slideIndexInView + 1} of ${slideCount}. ${description}`;
21
- };
22
- function CarouselAnnouncement(userOptions = {}) {
23
- let emblaApi;
24
- const { announce } = useAriaAnnouncer();
25
- const handleSettle = useCallback(
26
- (emblaApi2) => {
27
- const slideLabel = getSlideLabel(emblaApi2);
28
- announce(slideLabel);
29
- },
30
- [announce]
31
- );
32
- function init(emblaApiInstance) {
33
- emblaApi = emblaApiInstance;
34
- emblaApi.on("settle", handleSettle);
35
- }
36
- function destroy() {
37
- emblaApi.off("settle", handleSettle);
38
- }
39
- const self = {
40
- name: "announcement",
41
- options: userOptions,
42
- init,
43
- destroy
44
- };
45
- return self;
46
- }
47
-
48
- export { CarouselAnnouncement, getSlideLabel };
49
- //# sourceMappingURL=CarouselAnnouncementPlugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CarouselAnnouncementPlugin.js","sources":["../src/CarouselAnnouncementPlugin.ts"],"sourcesContent":["import { useAriaAnnouncer } from \"@salt-ds/core\";\nimport type {\n CreateOptionsType,\n CreatePluginType,\n EmblaCarouselType,\n} from \"embla-carousel\";\nimport { useCallback } from \"react\";\n\ndeclare module \"embla-carousel\" {\n interface EmblaPluginsType {\n announcement: CarouselAnnouncementType;\n }\n}\n\n/**\n * Type definition for the parameters of the getSlideLabel function.\n * @returns A string that describes the slide, including its index and total count.\n */\nexport type GetSlideLabelProps = (emblaApi: EmblaCarouselType) => string;\n\n/** * Generates a label for a carousel slide based on ARIA attributes.\n * This function retrieves the slide's ARIA label or text content and formats it into a descriptive string.\n * @param slideElement\n * @param slideIndex\n * @param slideCount\n * @returns A string description of the slide, including its position and ARIA label or text content.\n */\nexport const getSlideLabel: GetSlideLabelProps = (emblaApi): string => {\n const slideCount = emblaApi?.slideNodes().length ?? 0;\n const slideIndexInView = emblaApi?.slidesInView()?.[0] ?? 0;\n const slideElement = emblaApi?.slideNodes()[slideIndexInView];\n\n let description = slideElement?.getAttribute(\"aria-label\");\n if (!description) {\n const labelledById = slideElement?.getAttribute(\"aria-labelledby\");\n const { ownerDocument } = emblaApi.internalEngine();\n if (labelledById) {\n const labelledByElement = ownerDocument.getElementById(labelledById);\n description =\n labelledByElement?.textContent || \"No description available\";\n } else {\n description = \"No description available\";\n }\n }\n return `slide ${slideIndexInView + 1} of ${slideCount}. ${description}`;\n};\n\n// biome-ignore lint/complexity/noBannedTypes: Replicated from embla docs/code\ntype OptionsType = CreateOptionsType<{}>;\n// biome-ignore lint/complexity/noBannedTypes: Replicated from embla docs/code\nexport type CarouselAnnouncementType = CreatePluginType<{}, OptionsType>;\n\nexport type CarouselAnnouncementOptionsType =\n CarouselAnnouncementType[\"options\"];\n\nexport function CarouselAnnouncement(\n userOptions: CarouselAnnouncementOptionsType = {},\n): CarouselAnnouncementType {\n let emblaApi: EmblaCarouselType;\n\n const { announce } = useAriaAnnouncer();\n\n const handleSettle = useCallback(\n (emblaApi: EmblaCarouselType) => {\n const slideLabel = getSlideLabel(emblaApi);\n announce(slideLabel);\n },\n [announce],\n );\n\n function init(emblaApiInstance: EmblaCarouselType): void {\n emblaApi = emblaApiInstance;\n emblaApi.on(\"settle\", handleSettle);\n }\n\n function destroy(): void {\n emblaApi.off(\"settle\", handleSettle);\n }\n\n const self: CarouselAnnouncementType = {\n name: \"announcement\",\n options: userOptions,\n init,\n destroy,\n };\n return self;\n}\n"],"names":["emblaApi"],"mappings":";;;AA2Ba,MAAA,aAAA,GAAoC,CAAC,QAAqB,KAAA;AA3BvE,EAAA,IAAA,EAAA;AA4BE,EAAM,MAAA,UAAA,GAAA,CAAa,QAAU,IAAA,IAAA,GAAA,MAAA,GAAA,QAAA,CAAA,UAAA,EAAA,CAAa,MAAU,KAAA,CAAA;AACpD,EAAA,MAAM,gBAAmB,GAAA,CAAA,CAAA,EAAA,GAAA,QAAA,IAAA,IAAA,GAAA,MAAA,GAAA,QAAA,CAAU,YAAV,EAAA,KAAA,IAAA,GAAA,MAAA,GAAA,EAAA,CAA2B,CAAM,CAAA,KAAA,CAAA;AAC1D,EAAM,MAAA,YAAA,GAAe,qCAAU,UAAa,EAAA,CAAA,gBAAA,CAAA;AAE5C,EAAI,IAAA,WAAA,GAAc,6CAAc,YAAa,CAAA,YAAA,CAAA;AAC7C,EAAA,IAAI,CAAC,WAAa,EAAA;AAChB,IAAM,MAAA,YAAA,GAAe,6CAAc,YAAa,CAAA,iBAAA,CAAA;AAChD,IAAA,MAAM,EAAE,aAAA,EAAkB,GAAA,QAAA,CAAS,cAAe,EAAA;AAClD,IAAA,IAAI,YAAc,EAAA;AAChB,MAAM,MAAA,iBAAA,GAAoB,aAAc,CAAA,cAAA,CAAe,YAAY,CAAA;AACnE,MAAA,WAAA,GAAA,CACE,uDAAmB,WAAe,KAAA,0BAAA;AAAA,KAC/B,MAAA;AACL,MAAc,WAAA,GAAA,0BAAA;AAAA;AAChB;AAEF,EAAA,OAAO,SAAS,gBAAmB,GAAA,CAAC,CAAO,IAAA,EAAA,UAAU,KAAK,WAAW,CAAA,CAAA;AACvE;AAUgB,SAAA,oBAAA,CACd,WAA+C,GAAA,EACrB,EAAA;AAC1B,EAAI,IAAA,QAAA;AAEJ,EAAM,MAAA,EAAE,QAAS,EAAA,GAAI,gBAAiB,EAAA;AAEtC,EAAA,MAAM,YAAe,GAAA,WAAA;AAAA,IACnB,CAACA,SAAgC,KAAA;AAC/B,MAAM,MAAA,UAAA,GAAa,cAAcA,SAAQ,CAAA;AACzC,MAAA,QAAA,CAAS,UAAU,CAAA;AAAA,KACrB;AAAA,IACA,CAAC,QAAQ;AAAA,GACX;AAEA,EAAA,SAAS,KAAK,gBAA2C,EAAA;AACvD,IAAW,QAAA,GAAA,gBAAA;AACX,IAAS,QAAA,CAAA,EAAA,CAAG,UAAU,YAAY,CAAA;AAAA;AAGpC,EAAA,SAAS,OAAgB,GAAA;AACvB,IAAS,QAAA,CAAA,GAAA,CAAI,UAAU,YAAY,CAAA;AAAA;AAGrC,EAAA,MAAM,IAAiC,GAAA;AAAA,IACrC,IAAM,EAAA,cAAA;AAAA,IACN,OAAS,EAAA,WAAA;AAAA,IACT,IAAA;AAAA,IACA;AAAA,GACF;AACA,EAAO,OAAA,IAAA;AACT;;;;"}
@@ -1,4 +0,0 @@
1
- var css_248z = ".saltCarouselTabList.saltText {\n font-weight: var(--salt-text-fontWeight-strong);\n}\n";
2
-
3
- export { css_248z as default };
4
- //# sourceMappingURL=CarouselProgressLabel.css.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CarouselProgressLabel.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,24 +0,0 @@
1
- import type { CreateOptionsType, CreatePluginType, EmblaCarouselType } from "embla-carousel";
2
- declare module "embla-carousel" {
3
- interface EmblaPluginsType {
4
- announcement: CarouselAnnouncementType;
5
- }
6
- }
7
- /**
8
- * Type definition for the parameters of the getSlideLabel function.
9
- * @returns A string that describes the slide, including its index and total count.
10
- */
11
- export type GetSlideLabelProps = (emblaApi: EmblaCarouselType) => string;
12
- /** * Generates a label for a carousel slide based on ARIA attributes.
13
- * This function retrieves the slide's ARIA label or text content and formats it into a descriptive string.
14
- * @param slideElement
15
- * @param slideIndex
16
- * @param slideCount
17
- * @returns A string description of the slide, including its position and ARIA label or text content.
18
- */
19
- export declare const getSlideLabel: GetSlideLabelProps;
20
- type OptionsType = CreateOptionsType<{}>;
21
- export type CarouselAnnouncementType = CreatePluginType<{}, OptionsType>;
22
- export type CarouselAnnouncementOptionsType = CarouselAnnouncementType["options"];
23
- export declare function CarouselAnnouncement(userOptions?: CarouselAnnouncementOptionsType): CarouselAnnouncementType;
24
- export {};