periplo-ui 4.16.2 → 4.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/navigation/Tabs/Tabs.d.ts +2 -2
- package/dist/components/navigation/Tabs/Tabs.js +40 -6
- package/dist/components/navigation/Tabs/Tabs.js.map +1 -1
- package/dist/lib/useSlidingIndicator.d.ts +2 -1
- package/dist/lib/useSlidingIndicator.js +2 -1
- package/dist/lib/useSlidingIndicator.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,11 +7,11 @@ declare const TabsList: React.ForwardRefExoticComponent<Omit<TabsPrimitive.TabsL
|
|
|
7
7
|
underlined?: boolean;
|
|
8
8
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
9
9
|
declare const TabsTrigger: React.ForwardRefExoticComponent<Omit<TabsPrimitive.TabsTriggerProps & React.RefAttributes<HTMLButtonElement>, "ref"> & {
|
|
10
|
-
color?: ColorToken | string;
|
|
10
|
+
color?: ColorToken | (string & {});
|
|
11
11
|
} & React.RefAttributes<HTMLButtonElement>>;
|
|
12
12
|
declare const TabsLink: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "ref"> & {
|
|
13
13
|
active?: boolean;
|
|
14
|
-
color?: ColorToken | string;
|
|
14
|
+
color?: ColorToken | (string & {});
|
|
15
15
|
asChild?: boolean;
|
|
16
16
|
} & React.RefAttributes<HTMLAnchorElement>>;
|
|
17
17
|
declare const TabsContent: React.ForwardRefExoticComponent<Omit<TabsPrimitive.TabsContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cn, resolveColor } from "../../../lib/utils.js";
|
|
2
2
|
import { Typography } from "../../data-display/Typography/Typography.js";
|
|
3
|
+
import { SLIDING_INDICATOR_HORIZONTAL, slidingIndicatorProps, useSlidingIndicator } from "../../../lib/useSlidingIndicator.js";
|
|
3
4
|
import * as React$1 from "react";
|
|
4
5
|
import { Slot } from "@radix-ui/react-slot";
|
|
5
6
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -12,12 +13,45 @@ var TAB_SCROLLBAR_HIDDEN_CLASS = [
|
|
|
12
13
|
"[-ms-overflow-style:none]",
|
|
13
14
|
"[&::-webkit-scrollbar]:hidden"
|
|
14
15
|
].join(" ");
|
|
15
|
-
var TABS_TAB_ITEM_CLASSNAME = "focus-visible:ring-ring data-[state=active]:text-foreground relative inline-flex shrink-0 items-center justify-center rounded-lg px-3
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
var TABS_TAB_ITEM_CLASSNAME = "focus-visible:ring-ring data-[state=active]:text-foreground relative inline-flex shrink-0 items-center justify-center rounded-lg h-10 px-3 whitespace-nowrap text-neutral-400 ring-offset-1 transition-colors hover:bg-neutral-50 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50 data-[state=active]:hover:bg-transparent";
|
|
17
|
+
var TAB_INDICATOR_INSET = 2;
|
|
18
|
+
function measureTab(active) {
|
|
19
|
+
const range = document.createRange();
|
|
20
|
+
range.selectNodeContents(active);
|
|
21
|
+
const label = range.getBoundingClientRect();
|
|
22
|
+
const hasLabel = label.width > 0;
|
|
23
|
+
const labelLeft = hasLabel ? label.left - active.getBoundingClientRect().left : 0;
|
|
24
|
+
const labelWidth = hasLabel ? label.width : active.offsetWidth;
|
|
25
|
+
const raw = active.style.getPropertyValue("--tab-active-color");
|
|
26
|
+
return {
|
|
27
|
+
left: active.offsetLeft + labelLeft + TAB_INDICATOR_INSET,
|
|
28
|
+
width: Math.max(0, labelWidth - 4),
|
|
29
|
+
color: raw === "" ? void 0 : raw
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
var TAB_INDICATOR_OPTIONS = {
|
|
33
|
+
activeSelector: "[data-state=active]",
|
|
34
|
+
stateAttribute: "data-state",
|
|
35
|
+
measure: measureTab
|
|
36
|
+
};
|
|
37
|
+
var TabsList = React$1.forwardRef(({ className, fullWidth, underlined, children, style, ...props }, ref) => {
|
|
38
|
+
const listRef = React$1.useRef(null);
|
|
39
|
+
React$1.useImperativeHandle(ref, () => listRef.current, []);
|
|
40
|
+
const indicator = useSlidingIndicator(listRef, TAB_INDICATOR_OPTIONS);
|
|
41
|
+
return /* @__PURE__ */ jsx(TabsPrimitive.List, {
|
|
42
|
+
ref: listRef,
|
|
43
|
+
...slidingIndicatorProps(indicator),
|
|
44
|
+
className: cn(TAB_SCROLLBAR_HIDDEN_CLASS, "relative flex", fullWidth ? "w-full *:flex-1" : "gap-2", underlined && "border-b border-neutral-100", "after:absolute after:bottom-0 after:left-0 after:h-0.75 after:w-(--indicator-width) after:translate-x-(--indicator-left) after:bg-(--indicator-color)", SLIDING_INDICATOR_HORIZONTAL, className),
|
|
45
|
+
style: {
|
|
46
|
+
"--indicator-left": `${indicator?.left ?? 0}px`,
|
|
47
|
+
"--indicator-width": `${indicator?.width ?? 0}px`,
|
|
48
|
+
"--indicator-color": indicator?.color ?? resolveColor(void 0),
|
|
49
|
+
...style
|
|
50
|
+
},
|
|
51
|
+
...props,
|
|
52
|
+
children
|
|
53
|
+
});
|
|
54
|
+
});
|
|
21
55
|
TabsList.displayName = TabsPrimitive.List.displayName;
|
|
22
56
|
var TabsTrigger = React$1.forwardRef(({ className, children, color, style, ...props }, ref) => /* @__PURE__ */ jsx(TabsPrimitive.Trigger, {
|
|
23
57
|
asChild: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.js","names":["React"],"sources":["../../../../src/components/navigation/Tabs/Tabs.tsx"],"sourcesContent":["import { Slot } from '@radix-ui/react-slot'\nimport * as TabsPrimitive from '@radix-ui/react-tabs'\nimport * as React from 'react'\n\nimport { Typography } from '../../data-display/Typography'\n\nimport { cn, resolveColor, type ColorToken } from '@/lib/utils'\n\nconst Tabs = TabsPrimitive.Root\n\nconst TAB_SCROLLBAR_HIDDEN_CLASS = [\n 'overflow-x-auto',\n '[scrollbar-width:none]',\n '[-ms-overflow-style:none]',\n '[&::-webkit-scrollbar]:hidden',\n].join(' ')\n\nconst TABS_TAB_ITEM_CLASSNAME =\n 'focus-visible:ring-ring data-[state=active]:text-foreground relative inline-flex shrink-0 items-center justify-center rounded-lg px-3
|
|
1
|
+
{"version":3,"file":"Tabs.js","names":["React"],"sources":["../../../../src/components/navigation/Tabs/Tabs.tsx"],"sourcesContent":["import { Slot } from '@radix-ui/react-slot'\nimport * as TabsPrimitive from '@radix-ui/react-tabs'\nimport * as React from 'react'\n\nimport { Typography } from '../../data-display/Typography'\n\nimport { useSlidingIndicator, slidingIndicatorProps, SLIDING_INDICATOR_HORIZONTAL } from '@/lib/useSlidingIndicator'\nimport { cn, resolveColor, type ColorToken } from '@/lib/utils'\n\nconst Tabs = TabsPrimitive.Root\n\nconst TAB_SCROLLBAR_HIDDEN_CLASS = [\n 'overflow-x-auto',\n '[scrollbar-width:none]',\n '[-ms-overflow-style:none]',\n '[&::-webkit-scrollbar]:hidden',\n].join(' ')\n\nconst TABS_TAB_ITEM_CLASSNAME =\n 'focus-visible:ring-ring data-[state=active]:text-foreground relative inline-flex shrink-0 items-center justify-center rounded-lg h-10 px-3 whitespace-nowrap text-neutral-400 ring-offset-1 transition-colors hover:bg-neutral-50 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50 data-[state=active]:hover:bg-transparent'\n\nconst TAB_INDICATOR_INSET = 2\n\nfunction measureTab(active: HTMLElement) {\n const range = document.createRange()\n range.selectNodeContents(active)\n const label = range.getBoundingClientRect()\n const hasLabel = label.width > 0\n const labelLeft = hasLabel ? label.left - active.getBoundingClientRect().left : 0\n const labelWidth = hasLabel ? label.width : active.offsetWidth\n const raw = active.style.getPropertyValue('--tab-active-color')\n return {\n left: active.offsetLeft + labelLeft + TAB_INDICATOR_INSET,\n width: Math.max(0, labelWidth - TAB_INDICATOR_INSET * 2),\n color: raw === '' ? undefined : raw,\n }\n}\n\nconst TAB_INDICATOR_OPTIONS = {\n activeSelector: '[data-state=active]',\n stateAttribute: 'data-state',\n measure: measureTab,\n}\n\ntype TabsListProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.List> & {\n fullWidth?: boolean\n underlined?: boolean\n}\n\nconst TabsList = React.forwardRef<React.ComponentRef<typeof TabsPrimitive.List>, TabsListProps>(\n ({ className, fullWidth, underlined, children, style, ...props }, ref) => {\n const listRef = React.useRef<HTMLDivElement>(null)\n React.useImperativeHandle(ref, () => listRef.current as HTMLDivElement, [])\n const indicator = useSlidingIndicator(listRef, TAB_INDICATOR_OPTIONS)\n\n return (\n <TabsPrimitive.List\n ref={listRef}\n {...slidingIndicatorProps(indicator)}\n className={cn(\n TAB_SCROLLBAR_HIDDEN_CLASS,\n 'relative flex',\n fullWidth ? 'w-full *:flex-1' : 'gap-2',\n underlined && 'border-b border-neutral-100',\n 'after:absolute after:bottom-0 after:left-0 after:h-0.75 after:w-(--indicator-width) after:translate-x-(--indicator-left) after:bg-(--indicator-color)',\n SLIDING_INDICATOR_HORIZONTAL,\n className,\n )}\n style={\n {\n '--indicator-left': `${indicator?.left ?? 0}px`,\n '--indicator-width': `${indicator?.width ?? 0}px`,\n '--indicator-color': indicator?.color ?? resolveColor(undefined),\n ...style,\n } as React.CSSProperties\n }\n {...props}\n >\n {children}\n </TabsPrimitive.List>\n )\n },\n)\nTabsList.displayName = TabsPrimitive.List.displayName\n\ntype TabsTriggerProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger> & {\n color?: ColorToken | (string & {})\n}\n\nconst TabsTrigger = React.forwardRef<React.ComponentRef<typeof TabsPrimitive.Trigger>, TabsTriggerProps>(\n ({ className, children, color, style, ...props }, ref) => (\n <TabsPrimitive.Trigger\n asChild\n ref={ref}\n className={cn(TABS_TAB_ITEM_CLASSNAME, className)}\n style={\n {\n '--tab-active-color': resolveColor(color),\n ...style,\n } as React.CSSProperties\n }\n {...props}\n >\n <Typography variant=\"title-md\">{children}</Typography>\n </TabsPrimitive.Trigger>\n ),\n)\nTabsTrigger.displayName = TabsPrimitive.Trigger.displayName\n\ntype TabsLinkProps = React.ComponentPropsWithoutRef<'a'> & {\n active?: boolean\n color?: ColorToken | (string & {})\n asChild?: boolean\n}\n\nconst TabsLink = React.forwardRef<HTMLAnchorElement, TabsLinkProps>(\n ({ className, children, color, style, active = false, asChild, ...props }, ref) => {\n const Comp = asChild ? Slot : 'a'\n\n return (\n <Comp\n ref={ref}\n data-state={active ? 'active' : 'inactive'}\n aria-current={active ? 'page' : undefined}\n className={cn(TABS_TAB_ITEM_CLASSNAME, className)}\n style={\n {\n '--tab-active-color': resolveColor(color),\n ...style,\n } as React.CSSProperties\n }\n {...props}\n >\n {asChild ? children : <Typography variant=\"title-md\">{children}</Typography>}\n </Comp>\n )\n },\n)\nTabsLink.displayName = 'TabsLink'\n\nconst TabsContent = React.forwardRef<\n React.ComponentRef<typeof TabsPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>\n>(({ className, ...props }, ref) => (\n <TabsPrimitive.Content\n ref={ref}\n className={cn(\n 'focus-visible:ring-offset ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:outline-none',\n className,\n )}\n {...props}\n />\n))\nTabsContent.displayName = TabsPrimitive.Content.displayName\n\nexport { Tabs, TabsList, TabsTrigger, TabsLink, TabsContent }\n"],"mappings":";;;;;;;;AASA,IAAM,OAAO,cAAc;AAE3B,IAAM,6BAA6B;CACjC;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;AAEV,IAAM,0BACJ;AAEF,IAAM,sBAAsB;AAE5B,SAAS,WAAW,QAAqB;CACvC,MAAM,QAAQ,SAAS,YAAY;CACnC,MAAM,mBAAmB,MAAM;CAC/B,MAAM,QAAQ,MAAM,sBAAsB;CAC1C,MA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qB,CAAA;AAChC,CAAA,CAE3B;AACA,YAAY,cAAc,cAAc,QAAQ;AAQhD,IAAM,WAAWA,QAAM,YACpB,EAAE,WAAW,UAAU,OAAO,OAAO,SAAS,OAAO,SAAS,GAAG,SAAS,QAAQ;CAGjF,OACE,oBAHW,UAAU,OAAO,KAG5B;EACO;EACL,cAAY,SAAS,WAAW;EAChC,gBAAc,SAAS,SAAS,KAAA;EAChC,WAAW,GAAG,yBAAyB,SAAS;EAChD,OACE;GACE,sBAAsB,aAAa,KAAK;GACxC,GAAG;EACL;EAEF,GAAI;EAEH,UAAA,UAAU,WAAW,oBAAC,YAAD;GAAY,SAAQ;GAAY;EAAqB,CAAA;CACvE,CAAA;AAEV,CACF;AACA,SAAS,cAAc;AAEvB,IAAM,cAAcA,QAAM,YAGvB,EAAE,WAAW,GAAG,SAAS,QAC1B,oBAAC,cAAc,SAAf;CACO;CACL,WAAW,GACT,iIACA,SACF;CACA,GAAI;AACL,CAAA,CACF;AACD,YAAY,cAAc,cAAc,QAAQ"}
|
|
@@ -18,5 +18,6 @@ declare function slidingIndicatorProps(indicator: {
|
|
|
18
18
|
readonly 'data-indicator-slide': boolean | undefined;
|
|
19
19
|
};
|
|
20
20
|
declare const SLIDING_INDICATOR_VERTICAL = "before:opacity-0 before:ease-out-strong before:transition-opacity data-[indicator=visible]:before:opacity-100 data-[indicator-slide=true]:before:transition-[opacity,translate,height] motion-reduce:before:transition-none";
|
|
21
|
-
|
|
21
|
+
declare const SLIDING_INDICATOR_HORIZONTAL = "after:opacity-0 after:ease-out-strong after:transition-opacity data-[indicator=visible]:after:opacity-100 data-[indicator-slide=true]:after:transition-[opacity,translate,width] motion-reduce:after:transition-none";
|
|
22
|
+
export { useSlidingIndicator, slidingIndicatorProps, SLIDING_INDICATOR_VERTICAL, SLIDING_INDICATOR_HORIZONTAL };
|
|
22
23
|
export type { SlidingIndicator };
|
|
@@ -59,7 +59,8 @@ function slidingIndicatorProps(indicator) {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
var SLIDING_INDICATOR_VERTICAL = "before:opacity-0 before:ease-out-strong before:transition-opacity data-[indicator=visible]:before:opacity-100 data-[indicator-slide=true]:before:transition-[opacity,translate,height] motion-reduce:before:transition-none";
|
|
62
|
+
var SLIDING_INDICATOR_HORIZONTAL = "after:opacity-0 after:ease-out-strong after:transition-opacity data-[indicator=visible]:after:opacity-100 data-[indicator-slide=true]:after:transition-[opacity,translate,width] motion-reduce:after:transition-none";
|
|
62
63
|
//#endregion
|
|
63
|
-
export { SLIDING_INDICATOR_VERTICAL, slidingIndicatorProps, useSlidingIndicator };
|
|
64
|
+
export { SLIDING_INDICATOR_HORIZONTAL, SLIDING_INDICATOR_VERTICAL, slidingIndicatorProps, useSlidingIndicator };
|
|
64
65
|
|
|
65
66
|
//# sourceMappingURL=useSlidingIndicator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlidingIndicator.js","names":["React"],"sources":["../../src/lib/useSlidingIndicator.ts"],"sourcesContent":["import * as React from 'react'\n\ntype Measurement = Record<string, number | string | undefined>\n\ntype SlidingIndicator<M extends Measurement> = M & { visible: boolean; slide: boolean }\n\ntype SlidingIndicatorOptions<M extends Measurement> = {\n activeSelector: string\n stateAttribute: string\n measure: (active: HTMLElement) => M\n}\n\nfunction isSameMeasurement(current: Measurement, next: Measurement) {\n return Object.keys(next).every((key) => current[key] === next[key])\n}\n\nfunction useSlidingIndicator<M extends Measurement>(\n listRef: React.RefObject<HTMLElement | null>,\n { activeSelector, stateAttribute, measure }: SlidingIndicatorOptions<M>,\n) {\n const measureRef = React.useRef(measure)\n React.useEffect(() => {\n measureRef.current = measure\n })\n const [indicator, setIndicator] = React.useState<SlidingIndicator<M> | null>(null)\n\n React.useLayoutEffect(() => {\n const list = listRef.current\n if (!list) {\n return\n }\n\n const resizeObserver = new ResizeObserver(() => update())\n const observeChildren = () => Array.from(list.children).forEach((child) => resizeObserver.observe(child))\n\n const update = () => {\n observeChildren()\n const active = list.querySelector<HTMLElement>(activeSelector)\n setIndicator((prev) => {\n if (!active) {\n return prev?.visible ? { ...prev, visible: false, slide: false } : prev\n }\n const next = measureRef.current(active)\n if (prev?.visible && isSameMeasurement(prev, next)) {\n return prev\n }\n return { ...next, visible: true, slide: Boolean(prev?.visible) }\n })\n }\n\n update()\n const mutationObserver = new MutationObserver(update)\n mutationObserver.observe(list, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: [stateAttribute],\n })\n resizeObserver.observe(list)\n return () => {\n mutationObserver.disconnect()\n resizeObserver.disconnect()\n }\n }, [listRef, activeSelector, stateAttribute])\n\n return indicator\n}\n\nfunction slidingIndicatorProps(indicator: { visible: boolean; slide: boolean } | null) {\n return {\n 'data-indicator': indicator?.visible ? 'visible' : 'hidden',\n 'data-indicator-slide': indicator?.slide,\n } as const\n}\n\nconst SLIDING_INDICATOR_VERTICAL =\n 'before:opacity-0 before:ease-out-strong before:transition-opacity data-[indicator=visible]:before:opacity-100 data-[indicator-slide=true]:before:transition-[opacity,translate,height] motion-reduce:before:transition-none'\n\nexport { useSlidingIndicator, slidingIndicatorProps, SLIDING_INDICATOR_VERTICAL }\nexport type { SlidingIndicator }\n"],"mappings":";;AAYA,SAAS,kBAAkB,SAAsB,MAAmB;CAClE,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,OAAO,QAAQ,QAAQ,SAAS,KAAK,IAAI;AACpE;AAEA,SAAS,oBACP,SACA,EAAE,gBAAgB,gBAAgB,WAClC;CACA,MAAM,aAAaA,QAAM,OAAO,OAAO;CACvC,QAAM,gBAAgB;EACpB,WAAW,UAAU;CACvB,CAAC;CACD,MAAM,CAAC,WAAW,gBAAgBA,QAAM,SAAqC,IAAI;CAEjF,QAAM,sBAAsB;EAC1B,MAAM,OAAO,QAAQ;EACrB,IAAI,CAAC,MACH;EAGF,MAAM,iBAAiB,IAAI,qBAAqB,OAAO,CAAC;EACxD,MAAM,wBAAwB,MAAM,KAAK,KAAK,QAAQ,CAAC,CAAC,SAAS,UAAU,eAAe,QAAQ,KAAK,CAAC;EAExG,MAAM,eAAe;GACnB,gBAAgB;GAChB,MAAM,SAAS,KAAK,cAA2B,cAAc;GAC7D,cAAc,SAAS;IACrB,IAAI,CAAC,QACH,OAAO,MAAM,UAAU;KAAE,GAAG;KAAM,SAAS;KAAO,OAAO;IAAM,IAAI;IAErE,MAAM,OAAO,WAAW,QAAQ,MAAM;IACtC,IAAI,MAAM,WAAW,kBAAkB,MAAM,IAAI,GAC/C,OAAO;IAET,OAAO;KAAE,GAAG;KAAM,SAAS;KAAM,OAAO,QAAQ,MAAM,OAAO;IAAE;GACjE,CAAC;EACH;EAEA,OAAO;EACP,MAAM,mBAAmB,IAAI,iBAAiB,MAAM;EACpD,iBAAiB,QAAQ,MAAM;GAC7B,SAAS;GACT,WAAW;GACX,YAAY;GACZ,iBAAiB,CAAC,cAAc;EAClC,CAAC;EACD,eAAe,QAAQ,IAAI;EAC3B,aAAa;GACX,iBAAiB,WAAW;GAC5B,eAAe,WAAW;EAC5B;CACF,GAAG;EAAC;EAAS;EAAgB;CAAc,CAAC;CAE5C,OAAO;AACT;AAEA,SAAS,sBAAsB,WAAwD;CACrF,OAAO;EACL,kBAAkB,WAAW,UAAU,YAAY;EACnD,wBAAwB,WAAW;CACrC;AACF;AAEA,IAAM,6BACJ"}
|
|
1
|
+
{"version":3,"file":"useSlidingIndicator.js","names":["React"],"sources":["../../src/lib/useSlidingIndicator.ts"],"sourcesContent":["import * as React from 'react'\n\ntype Measurement = Record<string, number | string | undefined>\n\ntype SlidingIndicator<M extends Measurement> = M & { visible: boolean; slide: boolean }\n\ntype SlidingIndicatorOptions<M extends Measurement> = {\n activeSelector: string\n stateAttribute: string\n measure: (active: HTMLElement) => M\n}\n\nfunction isSameMeasurement(current: Measurement, next: Measurement) {\n return Object.keys(next).every((key) => current[key] === next[key])\n}\n\nfunction useSlidingIndicator<M extends Measurement>(\n listRef: React.RefObject<HTMLElement | null>,\n { activeSelector, stateAttribute, measure }: SlidingIndicatorOptions<M>,\n) {\n const measureRef = React.useRef(measure)\n React.useEffect(() => {\n measureRef.current = measure\n })\n const [indicator, setIndicator] = React.useState<SlidingIndicator<M> | null>(null)\n\n React.useLayoutEffect(() => {\n const list = listRef.current\n if (!list) {\n return\n }\n\n const resizeObserver = new ResizeObserver(() => update())\n const observeChildren = () => Array.from(list.children).forEach((child) => resizeObserver.observe(child))\n\n const update = () => {\n observeChildren()\n const active = list.querySelector<HTMLElement>(activeSelector)\n setIndicator((prev) => {\n if (!active) {\n return prev?.visible ? { ...prev, visible: false, slide: false } : prev\n }\n const next = measureRef.current(active)\n if (prev?.visible && isSameMeasurement(prev, next)) {\n return prev\n }\n return { ...next, visible: true, slide: Boolean(prev?.visible) }\n })\n }\n\n update()\n const mutationObserver = new MutationObserver(update)\n mutationObserver.observe(list, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: [stateAttribute],\n })\n resizeObserver.observe(list)\n return () => {\n mutationObserver.disconnect()\n resizeObserver.disconnect()\n }\n }, [listRef, activeSelector, stateAttribute])\n\n return indicator\n}\n\nfunction slidingIndicatorProps(indicator: { visible: boolean; slide: boolean } | null) {\n return {\n 'data-indicator': indicator?.visible ? 'visible' : 'hidden',\n 'data-indicator-slide': indicator?.slide,\n } as const\n}\n\nconst SLIDING_INDICATOR_VERTICAL =\n 'before:opacity-0 before:ease-out-strong before:transition-opacity data-[indicator=visible]:before:opacity-100 data-[indicator-slide=true]:before:transition-[opacity,translate,height] motion-reduce:before:transition-none'\n\nconst SLIDING_INDICATOR_HORIZONTAL =\n 'after:opacity-0 after:ease-out-strong after:transition-opacity data-[indicator=visible]:after:opacity-100 data-[indicator-slide=true]:after:transition-[opacity,translate,width] motion-reduce:after:transition-none'\n\nexport { useSlidingIndicator, slidingIndicatorProps, SLIDING_INDICATOR_VERTICAL, SLIDING_INDICATOR_HORIZONTAL }\nexport type { SlidingIndicator }\n"],"mappings":";;AAYA,SAAS,kBAAkB,SAAsB,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