@funstack/ui 0.1.0-alpha.7 → 0.1.0-alpha.9

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 (76) hide show
  1. package/dist/combobox/combobox-popup.mjs +1 -1
  2. package/dist/combobox/combobox-popup.mjs.map +1 -1
  3. package/dist/csp/csp-provider.d.mts +25 -0
  4. package/dist/csp/csp-provider.d.mts.map +1 -0
  5. package/dist/csp/csp-provider.mjs +24 -0
  6. package/dist/csp/csp-provider.mjs.map +1 -0
  7. package/dist/csp/index.d.mts +3 -0
  8. package/dist/csp/index.mjs +3 -0
  9. package/dist/csp/style-hashes.d.mts +19 -0
  10. package/dist/csp/style-hashes.d.mts.map +1 -0
  11. package/dist/csp/style-hashes.mjs +21 -0
  12. package/dist/csp/style-hashes.mjs.map +1 -0
  13. package/dist/index.d.mts +7 -3
  14. package/dist/index.mjs +3 -1
  15. package/dist/internal/anchor-position.d.mts +11 -3
  16. package/dist/internal/anchor-position.d.mts.map +1 -1
  17. package/dist/internal/anchor-position.mjs +180 -6
  18. package/dist/internal/anchor-position.mjs.map +1 -1
  19. package/dist/internal/csp-context.mjs +8 -0
  20. package/dist/internal/csp-context.mjs.map +1 -0
  21. package/dist/internal/tooltip-warm.mjs +29 -0
  22. package/dist/internal/tooltip-warm.mjs.map +1 -0
  23. package/dist/internal/use-popover-popup.mjs +22 -4
  24. package/dist/internal/use-popover-popup.mjs.map +1 -1
  25. package/dist/internal/use-resolved-placement.mjs +146 -0
  26. package/dist/internal/use-resolved-placement.mjs.map +1 -0
  27. package/dist/menu/index.d.mts +5 -1
  28. package/dist/menu/index.d.mts.map +1 -1
  29. package/dist/menu/index.mjs +5 -1
  30. package/dist/menu/index.mjs.map +1 -1
  31. package/dist/menu/menu-context-trigger.d.mts +46 -0
  32. package/dist/menu/menu-context-trigger.d.mts.map +1 -0
  33. package/dist/menu/menu-context-trigger.mjs +405 -0
  34. package/dist/menu/menu-context-trigger.mjs.map +1 -0
  35. package/dist/menu/menu-context.mjs +44 -1
  36. package/dist/menu/menu-context.mjs.map +1 -1
  37. package/dist/menu/menu-dom.mjs +42 -2
  38. package/dist/menu/menu-dom.mjs.map +1 -1
  39. package/dist/menu/menu-popup.d.mts +36 -8
  40. package/dist/menu/menu-popup.d.mts.map +1 -1
  41. package/dist/menu/menu-popup.mjs +214 -22
  42. package/dist/menu/menu-popup.mjs.map +1 -1
  43. package/dist/menu/menu-root.d.mts +5 -0
  44. package/dist/menu/menu-root.d.mts.map +1 -1
  45. package/dist/menu/menu-root.mjs +56 -6
  46. package/dist/menu/menu-root.mjs.map +1 -1
  47. package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
  48. package/dist/menu/menu-submenu-trigger.mjs +27 -11
  49. package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
  50. package/dist/popover/popover-popup.d.mts +21 -7
  51. package/dist/popover/popover-popup.d.mts.map +1 -1
  52. package/dist/popover/popover-popup.mjs +16 -6
  53. package/dist/popover/popover-popup.mjs.map +1 -1
  54. package/dist/tooltip/index.d.mts +8 -5
  55. package/dist/tooltip/index.d.mts.map +1 -1
  56. package/dist/tooltip/index.mjs +6 -3
  57. package/dist/tooltip/index.mjs.map +1 -1
  58. package/dist/tooltip/tooltip-arrow.d.mts +30 -0
  59. package/dist/tooltip/tooltip-arrow.d.mts.map +1 -0
  60. package/dist/tooltip/tooltip-arrow.mjs +45 -0
  61. package/dist/tooltip/tooltip-arrow.mjs.map +1 -0
  62. package/dist/tooltip/tooltip-context.d.mts +7 -0
  63. package/dist/tooltip/tooltip-context.d.mts.map +1 -1
  64. package/dist/tooltip/tooltip-context.mjs +2 -1
  65. package/dist/tooltip/tooltip-context.mjs.map +1 -1
  66. package/dist/tooltip/tooltip-popup.d.mts +21 -6
  67. package/dist/tooltip/tooltip-popup.d.mts.map +1 -1
  68. package/dist/tooltip/tooltip-popup.mjs +28 -6
  69. package/dist/tooltip/tooltip-popup.mjs.map +1 -1
  70. package/dist/tooltip/tooltip-trigger.d.mts +9 -2
  71. package/dist/tooltip/tooltip-trigger.d.mts.map +1 -1
  72. package/dist/tooltip/tooltip-trigger.mjs +21 -5
  73. package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
  74. package/dist/tooltip/use-tooltip-interaction.mjs +26 -2
  75. package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
  76. package/package.json +2 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip-arrow.mjs","names":[],"sources":["../../src/tooltip/tooltip-arrow.tsx"],"sourcesContent":["\"use client\";\nimport { use } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { TooltipPopupContext } from \"./tooltip-context.js\";\nimport type { TooltipAlign, TooltipSide } from \"./tooltip-context.js\";\n\nexport interface TooltipArrowState {\n /** The Popup's side: resolved while shown (after any flip), requested otherwise. */\n readonly side: TooltipSide | null;\n readonly align: TooltipAlign;\n}\n\nexport interface TooltipArrowProps extends Omit<\n ComponentPropsWithRef<\"span\">,\n \"aria-hidden\" | \"className\" | \"style\" | \"children\"\n> {\n className?: StateValue<string | undefined, TooltipArrowState>;\n style?: StateValue<CSSProperties | undefined, TooltipArrowState>;\n children?: StateValue<ReactNode, TooltipArrowState>;\n render?: RenderProp<ComponentPropsWithRef<\"span\">, TooltipArrowState>;\n}\n\n/**\n * A decorative `<span aria-hidden=\"true\">` inside `Tooltip.Popup` that draws nothing itself: it\n * echoes the Popup's `data-side` / `data-align`, which are the **resolved** placement while the\n * tooltip is shown (design 7.4), so CSS keyed on `[data-side]` puts it on the edge that faces the\n * trigger, after a `position-try-fallbacks` flip as well.\n *\n * Owned keys (conventions 1.2): `aria-hidden`, and `data-side` / `data-align` unless the Popup's\n * `side` is `null`.\n */\nexport function TooltipArrow({ className, style, children, render, ...rest }: TooltipArrowProps) {\n const placement = use(TooltipPopupContext);\n if (placement === null) {\n throw new Error(\"Tooltip.Arrow must be rendered inside a Tooltip.Popup.\");\n }\n const { side, align } = placement;\n const state: TooltipArrowState = { side, align };\n\n const libraryProps: ComponentPropsWithRef<\"span\"> & DataAttributes = {\n \"aria-hidden\": true,\n ...(side !== null && { \"data-side\": side, \"data-align\": align }),\n };\n\n return useRender<ComponentPropsWithRef<\"span\">, TooltipArrowState>({\n defaultElement: \"span\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n });\n}\n\nTooltipArrow.displayName = \"TooltipArrow\";\n"],"mappings":";;;;;;;;;;;;;;AAkCA,SAAgB,aAAa,EAAE,WAAW,OAAO,UAAU,QAAQ,GAAG,QAA2B;CAC/F,MAAM,YAAY,IAAI,mBAAmB;CACzC,IAAI,cAAc,MAChB,MAAM,IAAI,MAAM,wDAAwD;CAE1E,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,QAA2B;EAAE;EAAM;CAAM;CAE/C,MAAM,eAA+D;EACnE,eAAe;EACf,GAAI,SAAS,QAAQ;GAAE,aAAa;GAAM,cAAc;EAAM;CAChE;CAEA,OAAO,UAA4D;EACjE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;CACF,CAAC;AACH;AAEA,aAAa,cAAc"}
@@ -1,4 +1,11 @@
1
+ import { AnchorAlign, AnchorSide } from "../internal/anchor-position.mjs";
1
2
  //#region src/tooltip/tooltip-context.d.ts
3
+ /**
4
+ * `inline-start` / `inline-end` follow the popup's `direction` (wave 11; conventions 13.1). While
5
+ * shown, the state carries the resolved physical side.
6
+ */
7
+ export type TooltipSide = AnchorSide;
8
+ export type TooltipAlign = AnchorAlign;
2
9
  /** Which accessibility relation the tooltip provides for its trigger (design section 5.1). */
3
10
  export type TooltipProvides = "description" | "name";
4
11
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-context.d.mts","names":[],"sources":["../../src/tooltip/tooltip-context.ts"],"mappings":";;YAIY"}
1
+ {"version":3,"file":"tooltip-context.d.mts","names":[],"sources":["../../src/tooltip/tooltip-context.ts"],"mappings":";;;;;;YAQY,cAAc;YACd,eAAe;;YAGf"}
@@ -2,12 +2,13 @@
2
2
  import { createContext, use } from "react";
3
3
  //#region src/tooltip/tooltip-context.ts
4
4
  const TooltipContext = createContext(null);
5
+ const TooltipPopupContext = createContext(null);
5
6
  function useTooltipContext(part) {
6
7
  const context = use(TooltipContext);
7
8
  if (context === null) throw new Error(`${part} must be rendered inside a Tooltip.Root.`);
8
9
  return context;
9
10
  }
10
11
  //#endregion
11
- export { TooltipContext, useTooltipContext };
12
+ export { TooltipContext, TooltipPopupContext, useTooltipContext };
12
13
 
13
14
  //# sourceMappingURL=tooltip-context.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-context.mjs","names":[],"sources":["../../src/tooltip/tooltip-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\n\n/** Which accessibility relation the tooltip provides for its trigger (design section 5.1). */\nexport type TooltipProvides = \"description\" | \"name\";\n\nexport interface TooltipContextValue {\n /** Id of the Popup; the Trigger references it through `aria-describedby` / `aria-labelledby`. */\n readonly popupId: string;\n readonly disabled: boolean;\n /** Written onto the Trigger as `interest-delay-start` / `-end` on the native path. */\n readonly delay: number;\n readonly closeDelay: number;\n readonly provides: TooltipProvides;\n /** Trigger and Popup register their elements through callback refs (design 12.2). */\n readonly setTriggerElement: (element: HTMLElement | null) => void;\n readonly setPopupElement: (element: HTMLElement | null) => void;\n /**\n * The Trigger reports whether it renders `interestfor`, so the Root's interaction effect re-runs\n * (and re-detects the native path) when `experimental_interestFor` changes after mount.\n */\n readonly setInterestForRequested: (requested: boolean) => void;\n}\n\nexport const TooltipContext = createContext<TooltipContextValue | null>(null);\n\nexport function useTooltipContext(part: string): TooltipContextValue {\n const context = use(TooltipContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Tooltip.Root.`);\n }\n return context;\n}\n"],"mappings":";;;AAwBA,MAAa,iBAAiB,cAA0C,IAAI;AAE5E,SAAgB,kBAAkB,MAAmC;CACnE,MAAM,UAAU,IAAI,cAAc;CAClC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,yCAAyC;CAEnE,OAAO;AACT"}
1
+ {"version":3,"file":"tooltip-context.mjs","names":[],"sources":["../../src/tooltip/tooltip-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/anchor-position.js\";\n\n/**\n * `inline-start` / `inline-end` follow the popup's `direction` (wave 11; conventions 13.1). While\n * shown, the state carries the resolved physical side.\n */\nexport type TooltipSide = AnchorSide;\nexport type TooltipAlign = AnchorAlign;\n\n/** Which accessibility relation the tooltip provides for its trigger (design section 5.1). */\nexport type TooltipProvides = \"description\" | \"name\";\n\nexport interface TooltipContextValue {\n /** Id of the Popup; the Trigger references it through `aria-describedby` / `aria-labelledby`. */\n readonly popupId: string;\n readonly disabled: boolean;\n /** Written onto the Trigger as `interest-delay-start` / `-end` on the native path. */\n readonly delay: number;\n readonly closeDelay: number;\n readonly provides: TooltipProvides;\n /** Trigger and Popup register their elements through callback refs (design 12.2). */\n readonly setTriggerElement: (element: HTMLElement | null) => void;\n readonly setPopupElement: (element: HTMLElement | null) => void;\n /**\n * The Trigger reports whether it renders `interestfor`, so the Root's interaction effect re-runs\n * (and re-detects the native path) when `experimental_interestFor` changes after mount.\n */\n readonly setInterestForRequested: (requested: boolean) => void;\n}\n\nexport const TooltipContext = createContext<TooltipContextValue | null>(null);\n\n/** What `Tooltip.Popup` tells its `Tooltip.Arrow`: the placement it renders (design 12.2). */\nexport interface TooltipPopupContextValue {\n /** The resolved side while shown, else the requested one; `null` with `side={null}`. */\n readonly side: TooltipSide | null;\n readonly align: TooltipAlign;\n}\n\nexport const TooltipPopupContext = createContext<TooltipPopupContextValue | null>(null);\n\nexport function useTooltipContext(part: string): TooltipContextValue {\n const context = use(TooltipContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Tooltip.Root.`);\n }\n return context;\n}\n"],"mappings":";;;AAgCA,MAAa,iBAAiB,cAA0C,IAAI;AAS5E,MAAa,sBAAsB,cAA+C,IAAI;AAEtF,SAAgB,kBAAkB,MAAmC;CACnE,MAAM,UAAU,IAAI,cAAc;CAClC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,yCAAyC;CAEnE,OAAO;AACT"}
@@ -1,21 +1,31 @@
1
1
  import { RenderProp, StateValue } from "../internal/types.mjs";
2
+ import { TooltipAlign, TooltipSide } from "./tooltip-context.mjs";
2
3
  import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
3
4
  //#region src/tooltip/tooltip-popup.d.ts
4
- export type TooltipSide = "top" | "bottom" | "left" | "right";
5
- export type TooltipAlign = "start" | "center" | "end";
6
5
  export interface TooltipPopupState {
7
6
  readonly disabled: boolean;
7
+ /**
8
+ * While shown: the physical side the browser placed the popup on (`"top"` / `"bottom"` /
9
+ * `"left"` / `"right"`, after any fallback flip). Otherwise the `side` prop. `null` with
10
+ * `side={null}`.
11
+ */
8
12
  readonly side: TooltipSide | null;
13
+ /** While shown: the resolved alignment; otherwise the `align` prop. */
9
14
  readonly align: TooltipAlign;
10
15
  }
11
16
  export interface TooltipPopupProps extends Omit<ComponentPropsWithRef<"div">, "id" | "popover" | "role" | "className" | "style" | "children"> {
12
17
  /**
13
18
  * Placement relative to the trigger through inline `position-area`, with
14
- * `position-try-fallbacks` flipping it when it does not fit. Default `"top"`. `null` emits no
15
- * inline positioning (and no `data-side` / `data-align`), so a stylesheet owns placement.
19
+ * `position-try-fallbacks` flipping it when it does not fit. Default `"top"`. `"inline-start"` /
20
+ * `"inline-end"` follow the popup's direction. `null` emits no inline positioning (and no
21
+ * `data-side` / `data-align`), so a stylesheet owns placement.
16
22
  */
17
23
  side?: TooltipSide | null;
18
- /** Alignment along the side. Default `"center"`. Ignored when `side` is `null`. */
24
+ /**
25
+ * Alignment along the side. Default `"center"`. On a top / bottom side `start` / `end` are
26
+ * inline-relative (mirrored under `direction: rtl`); on the other sides they are the top /
27
+ * bottom edges. Ignored when `side` is `null`.
28
+ */
19
29
  align?: TooltipAlign;
20
30
  /**
21
31
  * Experimental (Chrome 151+, Firefox 153+; Safari 27.0 treats it as `"manual"`). Renders
@@ -38,12 +48,17 @@ export interface TooltipPopupProps extends Omit<ComponentPropsWithRef<"div">, "i
38
48
  * anchored to the trigger implicitly (`interestfor` or `showPopover({ source })`). Open state is
39
49
  * browser-owned: style it with `:popover-open` and animate it with `@starting-style` in CSS.
40
50
  *
51
+ * `data-side` / `data-align` are where the browser placed the popup while it is shown (the
52
+ * `position-try-fallbacks` option it applied, read from the computed `position-area`;
53
+ * conventions 13.2) and the requested values otherwise; `Tooltip.Arrow` echoes them.
54
+ *
41
55
  * Owned keys (conventions 1.2): `id`, `popover`, `role`, `data-disabled`, and `data-side` /
42
56
  * `data-align` unless `side` is `null`.
43
57
  */
44
- export declare function TooltipPopup({ side, align, experimental_hint, className, style, children, render, ...rest }: TooltipPopupProps): ReactNode;
58
+ export declare function TooltipPopup({ side: sideProp, align: alignProp, experimental_hint, className, style, children, render, ...rest }: TooltipPopupProps): import("react").JSX.Element;
45
59
  export declare namespace TooltipPopup {
46
60
  var displayName: string;
47
61
  }
48
62
  //#endregion
63
+ export type { TooltipAlign, TooltipSide };
49
64
  //# sourceMappingURL=tooltip-popup.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-popup.d.mts","names":[],"sources":["../../src/tooltip/tooltip-popup.tsx"],"mappings":";;;YASY;YACA;iBAEK;WACN;WACA,MAAM;WACN,OAAO;;iBAGD,0BAA0B,KACzC;;;;;;EAQA,OAAO;;EAEP,QAAQ;;;;;;;EAOR;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;;;;EAK9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,8BAA8B;;;;;;;;;;wBAWpC,eACd,MACA,OACA,mBACA,WACA,OACA,UACA,WACG,QACF,oBAAiB;yBATJ"}
1
+ {"version":3,"file":"tooltip-popup.d.mts","names":[],"sources":["../../src/tooltip/tooltip-popup.tsx"],"mappings":";;;;iBAeiB;WACN;;;;;;WAMA,MAAM;;WAEN,OAAO;;iBAGD,0BAA0B,KACzC;;;;;;;EASA,OAAO;;;;;;EAMP,QAAQ;;;;;;;EAOR;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;;;;EAK9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;wBAepC,eACd,MAAM,UACN,OAAO,WACP,mBACA,WACA,OACA,UACA,WACG,QACF,oCAAiB,IAAA;yBATJ"}
@@ -1,25 +1,43 @@
1
1
  "use client";
2
2
  import { dataAttr } from "../internal/data-attr.mjs";
3
+ import { mergeRefs } from "../internal/merge-props.mjs";
3
4
  import { resolveStateValue } from "../internal/render-element.mjs";
4
5
  import { useRender } from "../internal/use-render.mjs";
6
+ import { TooltipPopupContext, useTooltipContext } from "./tooltip-context.mjs";
5
7
  import { POSITION_TRY_FALLBACKS, positionArea } from "../internal/anchor-position.mjs";
6
- import { useTooltipContext } from "./tooltip-context.mjs";
8
+ import { useResolvedPlacement } from "../internal/use-resolved-placement.mjs";
9
+ import { useMemo } from "react";
10
+ import { jsx } from "react/jsx-runtime";
7
11
  //#region src/tooltip/tooltip-popup.tsx
8
12
  /**
9
13
  * The tooltip content: a `div` with `popover` and `role="tooltip"`, shown in the top layer and
10
14
  * anchored to the trigger implicitly (`interestfor` or `showPopover({ source })`). Open state is
11
15
  * browser-owned: style it with `:popover-open` and animate it with `@starting-style` in CSS.
12
16
  *
17
+ * `data-side` / `data-align` are where the browser placed the popup while it is shown (the
18
+ * `position-try-fallbacks` option it applied, read from the computed `position-area`;
19
+ * conventions 13.2) and the requested values otherwise; `Tooltip.Arrow` echoes them.
20
+ *
13
21
  * Owned keys (conventions 1.2): `id`, `popover`, `role`, `data-disabled`, and `data-side` /
14
22
  * `data-align` unless `side` is `null`.
15
23
  */
16
- function TooltipPopup({ side = "top", align = "center", experimental_hint = false, className, style, children, render, ...rest }) {
24
+ function TooltipPopup({ side: sideProp = "top", align: alignProp = "center", experimental_hint = false, className, style, children, render, ...rest }) {
17
25
  const ctx = useTooltipContext("Tooltip.Popup");
26
+ const placement = useResolvedPlacement({
27
+ side: sideProp,
28
+ align: alignProp
29
+ });
30
+ const { side, align } = placement;
18
31
  const state = {
19
32
  disabled: ctx.disabled,
20
33
  side,
21
34
  align
22
35
  };
36
+ const arrow = useMemo(() => ({
37
+ side,
38
+ align
39
+ }), [side, align]);
40
+ const ref = useMemo(() => mergeRefs(ctx.setPopupElement, placement.ref), [ctx.setPopupElement, placement.ref]);
23
41
  const libraryProps = {
24
42
  id: ctx.popupId,
25
43
  popover: experimental_hint ? "hint" : "manual",
@@ -30,20 +48,24 @@ function TooltipPopup({ side = "top", align = "center", experimental_hint = fals
30
48
  "data-align": align
31
49
  }
32
50
  };
33
- return useRender({
51
+ const element = useRender({
34
52
  defaultElement: "div",
35
53
  render,
36
54
  state,
37
55
  className,
38
- style: side === null ? style : (s) => ({
39
- positionArea: positionArea(side, align),
56
+ style: sideProp === null ? style : (s) => ({
57
+ positionArea: positionArea(sideProp, alignProp),
40
58
  positionTryFallbacks: POSITION_TRY_FALLBACKS,
41
59
  ...resolveStateValue(style, s)
42
60
  }),
43
61
  children,
44
62
  props: rest,
45
63
  libraryProps,
46
- ref: ctx.setPopupElement
64
+ ref
65
+ });
66
+ return /* @__PURE__ */ jsx(TooltipPopupContext, {
67
+ value: arrow,
68
+ children: element
47
69
  });
48
70
  }
49
71
  TooltipPopup.displayName = "TooltipPopup";
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-popup.mjs","names":[],"sources":["../../src/tooltip/tooltip-popup.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { POSITION_TRY_FALLBACKS, positionArea } from \"../internal/anchor-position.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useTooltipContext } from \"./tooltip-context.js\";\n\nexport type TooltipSide = \"top\" | \"bottom\" | \"left\" | \"right\";\nexport type TooltipAlign = \"start\" | \"center\" | \"end\";\n\nexport interface TooltipPopupState {\n readonly disabled: boolean;\n readonly side: TooltipSide | null;\n readonly align: TooltipAlign;\n}\n\nexport interface TooltipPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"popover\" | \"role\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Placement relative to the trigger through inline `position-area`, with\n * `position-try-fallbacks` flipping it when it does not fit. Default `\"top\"`. `null` emits no\n * inline positioning (and no `data-side` / `data-align`), so a stylesheet owns placement.\n */\n side?: TooltipSide | null;\n /** Alignment along the side. Default `\"center\"`. Ignored when `side` is `null`. */\n align?: TooltipAlign;\n /**\n * Experimental (Chrome 151+, Firefox 153+; Safari 27.0 treats it as `\"manual\"`). Renders\n * `popover=\"hint\"` instead of `popover=\"manual\"`: native light dismiss, and the tooltip can\n * open over an `auto` popover (a menu) without closing it. The JS Escape / pointerdown handling\n * stays in place for engines that do not know `hint`. Default `false`.\n */\n experimental_hint?: boolean;\n className?: StateValue<string | undefined, TooltipPopupState>;\n style?: StateValue<CSSProperties | undefined, TooltipPopupState>;\n /**\n * Rendered at mount (hidden by the popover's `display: none`), not at open time. Tooltip\n * content should be static; if it must suspend, put the `<Suspense>` boundary inside the Popup.\n */\n children?: StateValue<ReactNode, TooltipPopupState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, TooltipPopupState>;\n}\n\n/**\n * The tooltip content: a `div` with `popover` and `role=\"tooltip\"`, shown in the top layer and\n * anchored to the trigger implicitly (`interestfor` or `showPopover({ source })`). Open state is\n * browser-owned: style it with `:popover-open` and animate it with `@starting-style` in CSS.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `data-disabled`, and `data-side` /\n * `data-align` unless `side` is `null`.\n */\nexport function TooltipPopup({\n side = \"top\",\n align = \"center\",\n experimental_hint = false,\n className,\n style,\n children,\n render,\n ...rest\n}: TooltipPopupProps) {\n const ctx = useTooltipContext(\"Tooltip.Popup\");\n const state: TooltipPopupState = { disabled: ctx.disabled, side, align };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: ctx.popupId,\n popover: experimental_hint ? \"hint\" : \"manual\",\n role: \"tooltip\",\n \"data-disabled\": dataAttr(ctx.disabled),\n // Not owned with `side={null}`: the stylesheet (or a render element) may set them.\n ...(side !== null && { \"data-side\": side, \"data-align\": align }),\n };\n\n return useRender<ComponentPropsWithRef<\"div\">, TooltipPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The inline placement sits under the consumer's style: the consumer wins (design 3).\n style:\n side === null\n ? style\n : (s) => ({\n positionArea: positionArea(side, align),\n positionTryFallbacks: POSITION_TRY_FALLBACKS,\n ...resolveStateValue(style, s),\n }),\n children,\n props: rest,\n libraryProps,\n ref: ctx.setPopupElement,\n });\n}\n\nTooltipPopup.displayName = \"TooltipPopup\";\n"],"mappings":";;;;;;;;;;;;;;;AAuDA,SAAgB,aAAa,EAC3B,OAAO,OACP,QAAQ,UACR,oBAAoB,OACpB,WACA,OACA,UACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,kBAAkB,eAAe;CAC7C,MAAM,QAA2B;EAAE,UAAU,IAAI;EAAU;EAAM;CAAM;CAEvE,MAAM,eAA8D;EAClE,IAAI,IAAI;EACR,SAAS,oBAAoB,SAAS;EACtC,MAAM;EACN,iBAAiB,SAAS,IAAI,QAAQ;EAEtC,GAAI,SAAS,QAAQ;GAAE,aAAa;GAAM,cAAc;EAAM;CAChE;CAEA,OAAO,UAA2D;EAChE,gBAAgB;EAChB;EACA;EACA;EAEA,OACE,SAAS,OACL,SACC,OAAO;GACN,cAAc,aAAa,MAAM,KAAK;GACtC,sBAAsB;GACtB,GAAG,kBAAkB,OAAO,CAAC;EAC/B;EACN;EACA,OAAO;EACP;EACA,KAAK,IAAI;CACX,CAAC;AACH;AAEA,aAAa,cAAc"}
1
+ {"version":3,"file":"tooltip-popup.mjs","names":[],"sources":["../../src/tooltip/tooltip-popup.tsx"],"sourcesContent":["\"use client\";\nimport { useMemo } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { POSITION_TRY_FALLBACKS, positionArea } from \"../internal/anchor-position.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { mergeRefs } from \"../internal/merge-props.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useResolvedPlacement } from \"../internal/use-resolved-placement.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { TooltipPopupContext, useTooltipContext } from \"./tooltip-context.js\";\nimport type { TooltipAlign, TooltipPopupContextValue, TooltipSide } from \"./tooltip-context.js\";\n\nexport type { TooltipAlign, TooltipSide } from \"./tooltip-context.js\";\n\nexport interface TooltipPopupState {\n readonly disabled: boolean;\n /**\n * While shown: the physical side the browser placed the popup on (`\"top\"` / `\"bottom\"` /\n * `\"left\"` / `\"right\"`, after any fallback flip). Otherwise the `side` prop. `null` with\n * `side={null}`.\n */\n readonly side: TooltipSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: TooltipAlign;\n}\n\nexport interface TooltipPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"popover\" | \"role\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Placement relative to the trigger through inline `position-area`, with\n * `position-try-fallbacks` flipping it when it does not fit. Default `\"top\"`. `\"inline-start\"` /\n * `\"inline-end\"` follow the popup's direction. `null` emits no inline positioning (and no\n * `data-side` / `data-align`), so a stylesheet owns placement.\n */\n side?: TooltipSide | null;\n /**\n * Alignment along the side. Default `\"center\"`. On a top / bottom side `start` / `end` are\n * inline-relative (mirrored under `direction: rtl`); on the other sides they are the top /\n * bottom edges. Ignored when `side` is `null`.\n */\n align?: TooltipAlign;\n /**\n * Experimental (Chrome 151+, Firefox 153+; Safari 27.0 treats it as `\"manual\"`). Renders\n * `popover=\"hint\"` instead of `popover=\"manual\"`: native light dismiss, and the tooltip can\n * open over an `auto` popover (a menu) without closing it. The JS Escape / pointerdown handling\n * stays in place for engines that do not know `hint`. Default `false`.\n */\n experimental_hint?: boolean;\n className?: StateValue<string | undefined, TooltipPopupState>;\n style?: StateValue<CSSProperties | undefined, TooltipPopupState>;\n /**\n * Rendered at mount (hidden by the popover's `display: none`), not at open time. Tooltip\n * content should be static; if it must suspend, put the `<Suspense>` boundary inside the Popup.\n */\n children?: StateValue<ReactNode, TooltipPopupState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, TooltipPopupState>;\n}\n\n/**\n * The tooltip content: a `div` with `popover` and `role=\"tooltip\"`, shown in the top layer and\n * anchored to the trigger implicitly (`interestfor` or `showPopover({ source })`). Open state is\n * browser-owned: style it with `:popover-open` and animate it with `@starting-style` in CSS.\n *\n * `data-side` / `data-align` are where the browser placed the popup while it is shown (the\n * `position-try-fallbacks` option it applied, read from the computed `position-area`;\n * conventions 13.2) and the requested values otherwise; `Tooltip.Arrow` echoes them.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `data-disabled`, and `data-side` /\n * `data-align` unless `side` is `null`.\n */\nexport function TooltipPopup({\n side: sideProp = \"top\",\n align: alignProp = \"center\",\n experimental_hint = false,\n className,\n style,\n children,\n render,\n ...rest\n}: TooltipPopupProps) {\n const ctx = useTooltipContext(\"Tooltip.Popup\");\n const placement = useResolvedPlacement({ side: sideProp, align: alignProp });\n const { side, align } = placement;\n const state: TooltipPopupState = { disabled: ctx.disabled, side, align };\n const arrow = useMemo<TooltipPopupContextValue>(() => ({ side, align }), [side, align]);\n const ref = useMemo(\n () => mergeRefs(ctx.setPopupElement, placement.ref),\n [ctx.setPopupElement, placement.ref],\n );\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: ctx.popupId,\n popover: experimental_hint ? \"hint\" : \"manual\",\n role: \"tooltip\",\n \"data-disabled\": dataAttr(ctx.disabled),\n // Not owned with `side={null}`: the stylesheet (or a render element) may set them.\n ...(side !== null && { \"data-side\": side, \"data-align\": align }),\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, TooltipPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The inline placement is the requested one (the browser keeps choosing from it) and sits\n // under the consumer's style: the consumer wins (design 3).\n style:\n sideProp === null\n ? style\n : (s) => ({\n positionArea: positionArea(sideProp, alignProp),\n positionTryFallbacks: POSITION_TRY_FALLBACKS,\n ...resolveStateValue(style, s),\n }),\n children,\n props: rest,\n libraryProps,\n ref,\n });\n\n return <TooltipPopupContext value={arrow}>{element}</TooltipPopupContext>;\n}\n\nTooltipPopup.displayName = \"TooltipPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyEA,SAAgB,aAAa,EAC3B,MAAM,WAAW,OACjB,OAAO,YAAY,UACnB,oBAAoB,OACpB,WACA,OACA,UACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,kBAAkB,eAAe;CAC7C,MAAM,YAAY,qBAAqB;EAAE,MAAM;EAAU,OAAO;CAAU,CAAC;CAC3E,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,QAA2B;EAAE,UAAU,IAAI;EAAU;EAAM;CAAM;CACvE,MAAM,QAAQ,eAAyC;EAAE;EAAM;CAAM,IAAI,CAAC,MAAM,KAAK,CAAC;CACtF,MAAM,MAAM,cACJ,UAAU,IAAI,iBAAiB,UAAU,GAAG,GAClD,CAAC,IAAI,iBAAiB,UAAU,GAAG,CACrC;CAEA,MAAM,eAA8D;EAClE,IAAI,IAAI;EACR,SAAS,oBAAoB,SAAS;EACtC,MAAM;EACN,iBAAiB,SAAS,IAAI,QAAQ;EAEtC,GAAI,SAAS,QAAQ;GAAE,aAAa;GAAM,cAAc;EAAM;CAChE;CAEA,MAAM,UAAU,UAA2D;EACzE,gBAAgB;EAChB;EACA;EACA;EAGA,OACE,aAAa,OACT,SACC,OAAO;GACN,cAAc,aAAa,UAAU,SAAS;GAC9C,sBAAsB;GACtB,GAAG,kBAAkB,OAAO,CAAC;EAC/B;EACN;EACA,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,oBAAC,qBAAD;EAAqB,OAAO;EAAQ,UAAA;CAA6B,CAAA;AAC1E;AAEA,aAAa,cAAc"}
@@ -10,6 +10,12 @@ export interface TooltipTriggerProps extends Omit<ComponentPropsWithRef<"button"
10
10
  * browser owns hover, focus, Escape and long-press; the library's JS trigger path is skipped
11
11
  * where the rendered element implements `interestForElement`. No effect in other engines (the
12
12
  * attribute is ignored and the JS path runs). Pair with `Tooltip.Popup experimental_hint`.
13
+ * Skip-delay on this path comes from a shipped rule: the Trigger renders the
14
+ * `data-fsui-tooltip-trigger` marker, an `interest-delay-start` of
15
+ * `calc(<delay>ms * (1 - var(--fsui-tooltip-warm, 0)))` and a hoisted
16
+ * `<style href="@funstack/ui/tooltip-warm">` (nonce from `<CSPProvider>`), rendered beside the
17
+ * element so a `render` element with its own children keeps it. When that stylesheet is
18
+ * missing (a CSP blocks it), the tooltip opens after its `delay` and only skip-delay is lost.
13
19
  * Default `false`.
14
20
  */
15
21
  experimental_interestFor?: boolean;
@@ -28,9 +34,10 @@ export interface TooltipTriggerProps extends Omit<ComponentPropsWithRef<"button"
28
34
  *
29
35
  * Owned keys (conventions 1.2): `aria-describedby` (with `provides="description"`) or
30
36
  * `aria-labelledby` (with `provides="name"`), both token-merged with the consumer's ids;
31
- * `data-disabled`; and `interestfor` when `experimental_interestFor` is on.
37
+ * `data-disabled`; and `interestfor` and `data-fsui-tooltip-trigger` when
38
+ * `experimental_interestFor` is on.
32
39
  */
33
- export declare function TooltipTrigger({ experimental_interestFor, className, style, children, render, ...rest }: TooltipTriggerProps): ReactNode;
40
+ export declare function TooltipTrigger({ experimental_interestFor, className, style, children, render, ...rest }: TooltipTriggerProps): import("react").JSX.Element;
34
41
  export declare namespace TooltipTrigger {
35
42
  var displayName: string;
36
43
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-trigger.d.mts","names":[],"sources":["../../src/tooltip/tooltip-trigger.tsx"],"mappings":";;;iBASiB;WACN;;iBAGM,4BAA4B,KAC3C;;;;;;;;EAUA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;wBAevC,iBACd,0BACA,WACA,OACA,UACA,WACG,QACF,sBAAmB;yBAPN"}
1
+ {"version":3,"file":"tooltip-trigger.d.mts","names":[],"sources":["../../src/tooltip/tooltip-trigger.tsx"],"mappings":";;;iBAiBiB;WACN;;iBAGM,4BAA4B,KAC3C;;;;;;;;;;;;;;EAgBA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;wBAgBvC,iBACd,0BACA,WACA,OACA,UACA,WACG,QACF,sCAAmB,IAAA;yBAPN"}
@@ -3,7 +3,11 @@ import { dataAttr } from "../internal/data-attr.mjs";
3
3
  import { rendersButton, resolveStateValue } from "../internal/render-element.mjs";
4
4
  import { useRender } from "../internal/use-render.mjs";
5
5
  import { useTooltipContext } from "./tooltip-context.mjs";
6
- import { useLayoutEffect } from "react";
6
+ import { FSUI_PRECEDENCE } from "../internal/anchor-position.mjs";
7
+ import { CSPContext } from "../internal/csp-context.mjs";
8
+ import { TOOLTIP_WARM_HREF, TOOLTIP_WARM_RULES, warmDelay } from "../internal/tooltip-warm.mjs";
9
+ import { use, useLayoutEffect } from "react";
10
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
11
  //#region src/tooltip/tooltip-trigger.tsx
8
12
  /**
9
13
  * The element the user hovers or focuses: a `<button type="button">` by default. `render` may
@@ -15,12 +19,14 @@ import { useLayoutEffect } from "react";
15
19
  *
16
20
  * Owned keys (conventions 1.2): `aria-describedby` (with `provides="description"`) or
17
21
  * `aria-labelledby` (with `provides="name"`), both token-merged with the consumer's ids;
18
- * `data-disabled`; and `interestfor` when `experimental_interestFor` is on.
22
+ * `data-disabled`; and `interestfor` and `data-fsui-tooltip-trigger` when
23
+ * `experimental_interestFor` is on.
19
24
  */
20
25
  function TooltipTrigger({ experimental_interestFor = false, className, style, children, render, ...rest }) {
21
26
  const ctx = useTooltipContext("Tooltip.Trigger");
22
27
  const { disabled, popupId, provides, setInterestForRequested } = ctx;
23
28
  const native = experimental_interestFor && !disabled;
29
+ const csp = use(CSPContext);
24
30
  useLayoutEffect(() => {
25
31
  setInterestForRequested(native);
26
32
  }, [native, setInterestForRequested]);
@@ -28,15 +34,24 @@ function TooltipTrigger({ experimental_interestFor = false, className, style, ch
28
34
  const libraryProps = {
29
35
  ...provides === "name" ? { "aria-labelledby": popupId } : { "aria-describedby": popupId },
30
36
  "data-disabled": dataAttr(disabled),
31
- ...experimental_interestFor && { interestfor: native ? popupId : void 0 }
37
+ ...experimental_interestFor && {
38
+ interestfor: native ? popupId : void 0,
39
+ ["data-fsui-tooltip-trigger"]: native ? "" : void 0
40
+ }
32
41
  };
33
- return useRender({
42
+ const warmRules = native ? /* @__PURE__ */ jsx("style", {
43
+ href: TOOLTIP_WARM_HREF,
44
+ precedence: FSUI_PRECEDENCE,
45
+ nonce: csp?.nonce,
46
+ children: TOOLTIP_WARM_RULES
47
+ }) : null;
48
+ const element = useRender({
34
49
  defaultElement: "button",
35
50
  render,
36
51
  state,
37
52
  className,
38
53
  style: native ? (s) => ({
39
- interestDelayStart: `${ctx.delay}ms`,
54
+ interestDelayStart: warmDelay(ctx.delay),
40
55
  interestDelayEnd: `${ctx.closeDelay}ms`,
41
56
  ...resolveStateValue(style, s)
42
57
  }) : style,
@@ -48,6 +63,7 @@ function TooltipTrigger({ experimental_interestFor = false, className, style, ch
48
63
  libraryProps,
49
64
  ref: ctx.setTriggerElement
50
65
  });
66
+ return /* @__PURE__ */ jsxs(Fragment, { children: [warmRules, element] });
51
67
  }
52
68
  TooltipTrigger.displayName = "TooltipTrigger";
53
69
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-trigger.mjs","names":[],"sources":["../../src/tooltip/tooltip-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { rendersButton, resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useTooltipContext } from \"./tooltip-context.js\";\n\nexport interface TooltipTriggerState {\n readonly disabled: boolean;\n}\n\nexport interface TooltipTriggerProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"className\" | \"style\" | \"children\"\n> {\n /**\n * Experimental (Chromium 142+). Renders `interestfor` and `interest-delay-start/end` so the\n * browser owns hover, focus, Escape and long-press; the library's JS trigger path is skipped\n * where the rendered element implements `interestForElement`. No effect in other engines (the\n * attribute is ignored and the JS path runs). Pair with `Tooltip.Popup experimental_hint`.\n * Default `false`.\n */\n experimental_interestFor?: boolean;\n className?: StateValue<string | undefined, TooltipTriggerState>;\n style?: StateValue<CSSProperties | undefined, TooltipTriggerState>;\n children?: StateValue<ReactNode, TooltipTriggerState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, TooltipTriggerState>;\n}\n\n/**\n * The element the user hovers or focuses: a `<button type=\"button\">` by default. `render` may\n * substitute a link or a custom button; the element must be focusable (a dev warning fires when\n * it is not). A natively `disabled` button never opens a tooltip; use `aria-disabled` instead.\n *\n * The library attaches its hover / focus listeners with `addEventListener` from `Tooltip.Root`,\n * so every `on*` prop passes through untouched.\n *\n * Owned keys (conventions 1.2): `aria-describedby` (with `provides=\"description\"`) or\n * `aria-labelledby` (with `provides=\"name\"`), both token-merged with the consumer's ids;\n * `data-disabled`; and `interestfor` when `experimental_interestFor` is on.\n */\nexport function TooltipTrigger({\n experimental_interestFor = false,\n className,\n style,\n children,\n render,\n ...rest\n}: TooltipTriggerProps) {\n const ctx = useTooltipContext(\"Tooltip.Trigger\");\n const { disabled, popupId, provides, setInterestForRequested } = ctx;\n const native = experimental_interestFor && !disabled;\n\n useLayoutEffect(() => {\n setInterestForRequested(native);\n }, [native, setInterestForRequested]);\n\n const state: TooltipTriggerState = { disabled };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n // Only the relation in use is owned; the other one passes through untouched.\n ...(provides === \"name\" ? { \"aria-labelledby\": popupId } : { \"aria-describedby\": popupId }),\n \"data-disabled\": dataAttr(disabled),\n // Owned while the flag is on: a disabled tooltip removes the attribute, so the browser\n // cannot open it either. Unflagged, the key is omitted (conventions 1.2).\n ...(experimental_interestFor && { interestfor: native ? popupId : undefined }),\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, TooltipTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n // The native delays sit under the consumer's style: the consumer wins.\n style: native\n ? (s) => ({\n interestDelayStart: `${ctx.delay}ms`,\n interestDelayEnd: `${ctx.closeDelay}ms`,\n ...resolveStateValue(style, s),\n })\n : style,\n children,\n // `type=\"button\"` only on a real button (the consumer may override it); a link or a\n // component element does not get it.\n props: rendersButton(render) ? { type: \"button\", ...rest } : rest,\n libraryProps,\n ref: ctx.setTriggerElement,\n });\n}\n\nTooltipTrigger.displayName = \"TooltipTrigger\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,eAAe,EAC7B,2BAA2B,OAC3B,WACA,OACA,UACA,QACA,GAAG,QACmB;CACtB,MAAM,MAAM,kBAAkB,iBAAiB;CAC/C,MAAM,EAAE,UAAU,SAAS,UAAU,4BAA4B;CACjE,MAAM,SAAS,4BAA4B,CAAC;CAE5C,sBAAsB;EACpB,wBAAwB,MAAM;CAChC,GAAG,CAAC,QAAQ,uBAAuB,CAAC;CAEpC,MAAM,QAA6B,EAAE,SAAS;CAE9C,MAAM,eAAiE;EAErE,GAAI,aAAa,SAAS,EAAE,mBAAmB,QAAQ,IAAI,EAAE,oBAAoB,QAAQ;EACzF,iBAAiB,SAAS,QAAQ;EAGlC,GAAI,4BAA4B,EAAE,aAAa,SAAS,UAAU,KAAA,EAAU;CAC9E;CAEA,OAAO,UAAgE;EACrE,gBAAgB;EAChB;EACA;EACA;EAEA,OAAO,UACF,OAAO;GACN,oBAAoB,GAAG,IAAI,MAAM;GACjC,kBAAkB,GAAG,IAAI,WAAW;GACpC,GAAG,kBAAkB,OAAO,CAAC;EAC/B,KACA;EACJ;EAGA,OAAO,cAAc,MAAM,IAAI;GAAE,MAAM;GAAU,GAAG;EAAK,IAAI;EAC7D;EACA,KAAK,IAAI;CACX,CAAC;AACH;AAEA,eAAe,cAAc"}
1
+ {"version":3,"file":"tooltip-trigger.mjs","names":[],"sources":["../../src/tooltip/tooltip-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { use, useLayoutEffect } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { CSPContext } from \"../internal/csp-context.js\";\nimport { FSUI_PRECEDENCE } from \"../internal/anchor-position.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport {\n TOOLTIP_TRIGGER_MARKER,\n TOOLTIP_WARM_HREF,\n TOOLTIP_WARM_RULES,\n warmDelay,\n} from \"../internal/tooltip-warm.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { rendersButton, resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useTooltipContext } from \"./tooltip-context.js\";\n\nexport interface TooltipTriggerState {\n readonly disabled: boolean;\n}\n\nexport interface TooltipTriggerProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"className\" | \"style\" | \"children\"\n> {\n /**\n * Experimental (Chromium 142+). Renders `interestfor` and `interest-delay-start/end` so the\n * browser owns hover, focus, Escape and long-press; the library's JS trigger path is skipped\n * where the rendered element implements `interestForElement`. No effect in other engines (the\n * attribute is ignored and the JS path runs). Pair with `Tooltip.Popup experimental_hint`.\n * Skip-delay on this path comes from a shipped rule: the Trigger renders the\n * `data-fsui-tooltip-trigger` marker, an `interest-delay-start` of\n * `calc(<delay>ms * (1 - var(--fsui-tooltip-warm, 0)))` and a hoisted\n * `<style href=\"@funstack/ui/tooltip-warm\">` (nonce from `<CSPProvider>`), rendered beside the\n * element so a `render` element with its own children keeps it. When that stylesheet is\n * missing (a CSP blocks it), the tooltip opens after its `delay` and only skip-delay is lost.\n * Default `false`.\n */\n experimental_interestFor?: boolean;\n className?: StateValue<string | undefined, TooltipTriggerState>;\n style?: StateValue<CSSProperties | undefined, TooltipTriggerState>;\n children?: StateValue<ReactNode, TooltipTriggerState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, TooltipTriggerState>;\n}\n\n/**\n * The element the user hovers or focuses: a `<button type=\"button\">` by default. `render` may\n * substitute a link or a custom button; the element must be focusable (a dev warning fires when\n * it is not). A natively `disabled` button never opens a tooltip; use `aria-disabled` instead.\n *\n * The library attaches its hover / focus listeners with `addEventListener` from `Tooltip.Root`,\n * so every `on*` prop passes through untouched.\n *\n * Owned keys (conventions 1.2): `aria-describedby` (with `provides=\"description\"`) or\n * `aria-labelledby` (with `provides=\"name\"`), both token-merged with the consumer's ids;\n * `data-disabled`; and `interestfor` and `data-fsui-tooltip-trigger` when\n * `experimental_interestFor` is on.\n */\nexport function TooltipTrigger({\n experimental_interestFor = false,\n className,\n style,\n children,\n render,\n ...rest\n}: TooltipTriggerProps) {\n const ctx = useTooltipContext(\"Tooltip.Trigger\");\n const { disabled, popupId, provides, setInterestForRequested } = ctx;\n const native = experimental_interestFor && !disabled;\n const csp = use(CSPContext);\n\n useLayoutEffect(() => {\n setInterestForRequested(native);\n }, [native, setInterestForRequested]);\n\n const state: TooltipTriggerState = { disabled };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n // Only the relation in use is owned; the other one passes through untouched.\n ...(provides === \"name\" ? { \"aria-labelledby\": popupId } : { \"aria-describedby\": popupId }),\n \"data-disabled\": dataAttr(disabled),\n // Owned while the flag is on: a disabled tooltip removes the attribute, so the browser\n // cannot open it either. Unflagged, the key is omitted (conventions 1.2).\n ...(experimental_interestFor && {\n interestfor: native ? popupId : undefined,\n // What the shipped skip-delay rule matches (design 6); nothing else carries it.\n [TOOLTIP_TRIGGER_MARKER]: native ? \"\" : undefined,\n }),\n };\n\n // Skip-delay on the native path (design 6, conventions 12): the browser reads the delay from\n // the computed style when the hover starts, and only a rule can see that another tooltip is\n // showing. Hoisted into <head> by React (during SSR too) and deduplicated; nothing lands in\n // place. Rendered beside the element, not in its children: a `render` element with its own\n // children (`render={<a href>Text</a>}`) wins over `children` and would drop it.\n const warmRules = native ? (\n <style href={TOOLTIP_WARM_HREF} precedence={FSUI_PRECEDENCE} nonce={csp?.nonce}>\n {TOOLTIP_WARM_RULES}\n </style>\n ) : null;\n\n const element = useRender<ComponentPropsWithRef<\"button\">, TooltipTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n // The native delays sit under the consumer's style: the consumer wins. The open delay is 0\n // while another tooltip is showing (`--fsui-tooltip-warm`, design 6).\n style: native\n ? (s) => ({\n interestDelayStart: warmDelay(ctx.delay),\n interestDelayEnd: `${ctx.closeDelay}ms`,\n ...resolveStateValue(style, s),\n })\n : style,\n children,\n // `type=\"button\"` only on a real button (the consumer may override it); a link or a\n // component element does not get it.\n props: rendersButton(render) ? { type: \"button\", ...rest } : rest,\n libraryProps,\n ref: ctx.setTriggerElement,\n });\n return (\n <>\n {warmRules}\n {element}\n </>\n );\n}\n\nTooltipTrigger.displayName = \"TooltipTrigger\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,eAAe,EAC7B,2BAA2B,OAC3B,WACA,OACA,UACA,QACA,GAAG,QACmB;CACtB,MAAM,MAAM,kBAAkB,iBAAiB;CAC/C,MAAM,EAAE,UAAU,SAAS,UAAU,4BAA4B;CACjE,MAAM,SAAS,4BAA4B,CAAC;CAC5C,MAAM,MAAM,IAAI,UAAU;CAE1B,sBAAsB;EACpB,wBAAwB,MAAM;CAChC,GAAG,CAAC,QAAQ,uBAAuB,CAAC;CAEpC,MAAM,QAA6B,EAAE,SAAS;CAE9C,MAAM,eAAiE;EAErE,GAAI,aAAa,SAAS,EAAE,mBAAmB,QAAQ,IAAI,EAAE,oBAAoB,QAAQ;EACzF,iBAAiB,SAAS,QAAQ;EAGlC,GAAI,4BAA4B;GAC9B,aAAa,SAAS,UAAU,KAAA;IAEN,8BAAA,SAAS,KAAK,KAAA;EAC1C;CACF;CAOA,MAAM,YAAY,SAChB,oBAAC,SAAD;EAAO,MAAM;EAAmB,YAAY;EAAiB,OAAO,KAAK;EACtE,UAAA;CACI,CAAA,IACL;CAEJ,MAAM,UAAU,UAAgE;EAC9E,gBAAgB;EAChB;EACA;EACA;EAGA,OAAO,UACF,OAAO;GACN,oBAAoB,UAAU,IAAI,KAAK;GACvC,kBAAkB,GAAG,IAAI,WAAW;GACpC,GAAG,kBAAkB,OAAO,CAAC;EAC/B,KACA;EACJ;EAGA,OAAO,cAAc,MAAM,IAAI;GAAE,MAAM;GAAU,GAAG;EAAK,IAAI;EAC7D;EACA,KAAK,IAAI;CACX,CAAC;CACD,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,WACA,OACD,EAAA,CAAA;AAEN;AAEA,eAAe,cAAc"}
@@ -14,6 +14,10 @@ import { useEffect, useEffectEvent } from "react";
14
14
  * `showPopover()` (the `toggle` event is queued as a task, so waiting for it would leave a window
15
15
  * in which an Escape or pointerdown does nothing) and detached when `toggle` reports a close,
16
16
  * including closes the library did not perform (native light dismiss of `popover="hint"`).
17
+ *
18
+ * Skip-delay (design 6, wave 11): while another tooltip is showing anywhere in the document
19
+ * (`[role="tooltip"]:popover-open`, FUNSTACK's or not), a hover or keyboard focus hides it and
20
+ * opens this one at once. Stateless: the DOM is read at the start of each hover or focus.
17
21
  */
18
22
  function useTooltipInteraction(trigger, popup, options) {
19
23
  const getDelays = useEffectEvent(() => ({
@@ -52,6 +56,16 @@ function useTooltipInteraction(trigger, popup, options) {
52
56
  clear();
53
57
  hide();
54
58
  };
59
+ const showSoon = () => {
60
+ const other = isOpen(popup) ? null : otherOpenTooltip(doc, popup);
61
+ if (other === null) {
62
+ showLater();
63
+ return;
64
+ }
65
+ clear();
66
+ other.hidePopover();
67
+ show();
68
+ };
55
69
  const onKeyDown = (event) => {
56
70
  if (event.key !== "Escape") return;
57
71
  clear();
@@ -72,10 +86,10 @@ function useTooltipInteraction(trigger, popup, options) {
72
86
  listenDocument(isOpen(popup));
73
87
  };
74
88
  const onTriggerEnter = (event) => {
75
- if (event.pointerType !== "touch") showLater();
89
+ if (event.pointerType !== "touch") showSoon();
76
90
  };
77
91
  const onTriggerFocus = () => {
78
- if (trigger.matches(":focus-visible")) showLater();
92
+ if (trigger.matches(":focus-visible")) showSoon();
79
93
  };
80
94
  const onTriggerKeyDown = (event) => {
81
95
  if (event.key === "Escape") clear();
@@ -109,6 +123,16 @@ function useTooltipInteraction(trigger, popup, options) {
109
123
  interestForRequested
110
124
  ]);
111
125
  }
126
+ /**
127
+ * A tooltip popover other than `popup` that is showing in the document, or `null` (the warm
128
+ * condition of design 6, the same one the native path's `:root:has()` rule reads). Walks the
129
+ * tooltip popovers and asks each for `:popover-open` rather than one `querySelector`, which the
130
+ * jsdom shim could not answer.
131
+ */
132
+ function otherOpenTooltip(doc, popup) {
133
+ for (const element of doc.querySelectorAll("[role=\"tooltip\"][popover]")) if (element !== popup && isOpen(element)) return element;
134
+ return null;
135
+ }
112
136
  /** The popover's top-layer state, read from the DOM. A removed popover is never open. */
113
137
  function isOpen(popup) {
114
138
  return popup.isConnected && popup.matches(":popover-open");
@@ -1 +1 @@
1
- {"version":3,"file":"use-tooltip-interaction.mjs","names":[],"sources":["../../src/tooltip/use-tooltip-interaction.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useEffectEvent } from \"react\";\nimport { createDelayedPair } from \"../internal/use-delayed-pair.js\";\n\nexport interface TooltipInteractionOptions {\n readonly delay: number;\n readonly closeDelay: number;\n readonly disabled: boolean;\n /** The Trigger renders `interestfor` (flag on and not disabled). Re-runs the detection. */\n readonly interestForRequested: boolean;\n}\n\n/**\n * The cross-engine JS path of design section 2.2: hover / keyboard focus with delays,\n * `showPopover({ source })`, Escape and pointerdown-anywhere. Listeners go through\n * `addEventListener` (conventions 7.4) so they can be feature-detected away: where the trigger\n * renders `interestfor` and the element implements `interestForElement`, the browser owns the\n * whole interaction and nothing is attached.\n *\n * Open state is browser-owned (conventions 3.5): every decision reads\n * `popup.matches(\":popover-open\")`, never a copy. The document listeners are attached right after\n * `showPopover()` (the `toggle` event is queued as a task, so waiting for it would leave a window\n * in which an Escape or pointerdown does nothing) and detached when `toggle` reports a close,\n * including closes the library did not perform (native light dismiss of `popover=\"hint\"`).\n */\nexport function useTooltipInteraction(\n trigger: HTMLElement | null,\n popup: HTMLElement | null,\n options: TooltipInteractionOptions,\n): void {\n const getDelays = useEffectEvent(() => ({\n delay: options.delay,\n closeDelay: options.closeDelay,\n }));\n const { disabled, interestForRequested } = options;\n\n useEffect(() => {\n if (popup === null) return;\n // Disabling while open hides the popup on both paths (design section 13, Disabled row). On the\n // JS path the previous run's cleanup already did; on the native path nothing else would, and\n // removing `interestfor` does not close an open popover.\n if (disabled) {\n if (isOpen(popup)) popup.hidePopover();\n return;\n }\n if (trigger === null) return;\n // Native path (conventions 8): only when the flag put `interestfor` on the element, and per\n // element, so a `render`ed `<span>` (no `interestForElement`) keeps the JS path. Nothing is\n // attached here, Escape included: the browser's interest handling and the `hint` close watcher\n // decide, so in Chromium an Escape that closes the tooltip may also close an enclosing modal\n // `<dialog>` (the library cannot `preventDefault()` a keydown it never sees).\n if (\n interestForRequested &&\n trigger.hasAttribute(\"interestfor\") &&\n \"interestForElement\" in trigger\n ) {\n return;\n }\n\n const doc = trigger.ownerDocument;\n // One pending open or close at a time (the timer helper shared with Menu's hover intent).\n const timers = createDelayedPair();\n const clear = timers.cancel;\n const show = () => {\n if (isOpen(popup) || !popup.isConnected || !trigger.isConnected) return;\n popup.showPopover({ source: trigger });\n listenDocument(true);\n };\n const hide = () => {\n // A removed popover is already hidden (`isOpen` is false), so this never throws.\n if (!isOpen(popup)) return;\n popup.hidePopover();\n listenDocument(false);\n };\n const showLater = () => {\n timers.open(getDelays().delay, show);\n };\n const hideLater = () => {\n timers.close(getDelays().closeDelay, hide);\n };\n const hideNow = () => {\n clear();\n hide();\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key !== \"Escape\") return;\n clear();\n // Escape while closed passes through untouched.\n if (!isOpen(popup)) return;\n hide();\n // This Escape was the tooltip's: an enclosing modal `<dialog>` or `popover=\"auto\"` menu\n // stays open (the close request sees a canceled keydown). A second Escape reaches them.\n event.preventDefault();\n };\n function listenDocument(listen: boolean) {\n if (listen) {\n doc.addEventListener(\"keydown\", onKeyDown);\n doc.addEventListener(\"pointerdown\", hideNow, true);\n } else {\n doc.removeEventListener(\"keydown\", onKeyDown);\n doc.removeEventListener(\"pointerdown\", hideNow, true);\n }\n }\n // Follows opens and closes the library did not perform; reads the DOM, not `newState`, so a\n // toggle task that is stale by the time it runs cannot detach the listeners of an open popup.\n const onToggle = () => {\n listenDocument(isOpen(popup));\n };\n const onTriggerEnter = (event: PointerEvent) => {\n // No hover on touch; the ARIA relation still works for screen-reader focus (design 5.3).\n if (event.pointerType !== \"touch\") showLater();\n };\n const onTriggerFocus = () => {\n // Pointer focus (a click) does not open; keyboard focus does (design 5.2).\n if (trigger.matches(\":focus-visible\")) showLater();\n };\n // The document listeners exist only while the popup is open, so before that the trigger\n // itself cancels a pending open: a click or Escape before `delay` elapses must not open the\n // tooltip afterwards. Once open, the document listeners do the hiding.\n const onTriggerKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") clear();\n };\n\n trigger.addEventListener(\"pointerenter\", onTriggerEnter);\n trigger.addEventListener(\"pointerleave\", hideLater);\n trigger.addEventListener(\"pointerdown\", clear);\n trigger.addEventListener(\"keydown\", onTriggerKeyDown);\n trigger.addEventListener(\"focus\", onTriggerFocus);\n trigger.addEventListener(\"blur\", hideLater);\n popup.addEventListener(\"pointerenter\", clear);\n popup.addEventListener(\"pointerleave\", hideLater);\n popup.addEventListener(\"toggle\", onToggle);\n\n return () => {\n hideNow();\n listenDocument(false);\n trigger.removeEventListener(\"pointerenter\", onTriggerEnter);\n trigger.removeEventListener(\"pointerleave\", hideLater);\n trigger.removeEventListener(\"pointerdown\", clear);\n trigger.removeEventListener(\"keydown\", onTriggerKeyDown);\n trigger.removeEventListener(\"focus\", onTriggerFocus);\n trigger.removeEventListener(\"blur\", hideLater);\n popup.removeEventListener(\"pointerenter\", clear);\n popup.removeEventListener(\"pointerleave\", hideLater);\n popup.removeEventListener(\"toggle\", onToggle);\n };\n }, [trigger, popup, disabled, interestForRequested]);\n}\n\n/** The popover's top-layer state, read from the DOM. A removed popover is never open. */\nfunction isOpen(popup: HTMLElement): boolean {\n return popup.isConnected && popup.matches(\":popover-open\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,SAAgB,sBACd,SACA,OACA,SACM;CACN,MAAM,YAAY,sBAAsB;EACtC,OAAO,QAAQ;EACf,YAAY,QAAQ;CACtB,EAAE;CACF,MAAM,EAAE,UAAU,yBAAyB;CAE3C,gBAAgB;EACd,IAAI,UAAU,MAAM;EAIpB,IAAI,UAAU;GACZ,IAAI,OAAO,KAAK,GAAG,MAAM,YAAY;GACrC;EACF;EACA,IAAI,YAAY,MAAM;EAMtB,IACE,wBACA,QAAQ,aAAa,aAAa,KAClC,wBAAwB,SAExB;EAGF,MAAM,MAAM,QAAQ;EAEpB,MAAM,SAAS,kBAAkB;EACjC,MAAM,QAAQ,OAAO;EACrB,MAAM,aAAa;GACjB,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,eAAe,CAAC,QAAQ,aAAa;GACjE,MAAM,YAAY,EAAE,QAAQ,QAAQ,CAAC;GACrC,eAAe,IAAI;EACrB;EACA,MAAM,aAAa;GAEjB,IAAI,CAAC,OAAO,KAAK,GAAG;GACpB,MAAM,YAAY;GAClB,eAAe,KAAK;EACtB;EACA,MAAM,kBAAkB;GACtB,OAAO,KAAK,UAAU,CAAC,CAAC,OAAO,IAAI;EACrC;EACA,MAAM,kBAAkB;GACtB,OAAO,MAAM,UAAU,CAAC,CAAC,YAAY,IAAI;EAC3C;EACA,MAAM,gBAAgB;GACpB,MAAM;GACN,KAAK;EACP;EAEA,MAAM,aAAa,UAAyB;GAC1C,IAAI,MAAM,QAAQ,UAAU;GAC5B,MAAM;GAEN,IAAI,CAAC,OAAO,KAAK,GAAG;GACpB,KAAK;GAGL,MAAM,eAAe;EACvB;EACA,SAAS,eAAe,QAAiB;GACvC,IAAI,QAAQ;IACV,IAAI,iBAAiB,WAAW,SAAS;IACzC,IAAI,iBAAiB,eAAe,SAAS,IAAI;GACnD,OAAO;IACL,IAAI,oBAAoB,WAAW,SAAS;IAC5C,IAAI,oBAAoB,eAAe,SAAS,IAAI;GACtD;EACF;EAGA,MAAM,iBAAiB;GACrB,eAAe,OAAO,KAAK,CAAC;EAC9B;EACA,MAAM,kBAAkB,UAAwB;GAE9C,IAAI,MAAM,gBAAgB,SAAS,UAAU;EAC/C;EACA,MAAM,uBAAuB;GAE3B,IAAI,QAAQ,QAAQ,gBAAgB,GAAG,UAAU;EACnD;EAIA,MAAM,oBAAoB,UAAyB;GACjD,IAAI,MAAM,QAAQ,UAAU,MAAM;EACpC;EAEA,QAAQ,iBAAiB,gBAAgB,cAAc;EACvD,QAAQ,iBAAiB,gBAAgB,SAAS;EAClD,QAAQ,iBAAiB,eAAe,KAAK;EAC7C,QAAQ,iBAAiB,WAAW,gBAAgB;EACpD,QAAQ,iBAAiB,SAAS,cAAc;EAChD,QAAQ,iBAAiB,QAAQ,SAAS;EAC1C,MAAM,iBAAiB,gBAAgB,KAAK;EAC5C,MAAM,iBAAiB,gBAAgB,SAAS;EAChD,MAAM,iBAAiB,UAAU,QAAQ;EAEzC,aAAa;GACX,QAAQ;GACR,eAAe,KAAK;GACpB,QAAQ,oBAAoB,gBAAgB,cAAc;GAC1D,QAAQ,oBAAoB,gBAAgB,SAAS;GACrD,QAAQ,oBAAoB,eAAe,KAAK;GAChD,QAAQ,oBAAoB,WAAW,gBAAgB;GACvD,QAAQ,oBAAoB,SAAS,cAAc;GACnD,QAAQ,oBAAoB,QAAQ,SAAS;GAC7C,MAAM,oBAAoB,gBAAgB,KAAK;GAC/C,MAAM,oBAAoB,gBAAgB,SAAS;GACnD,MAAM,oBAAoB,UAAU,QAAQ;EAC9C;CACF,GAAG;EAAC;EAAS;EAAO;EAAU;CAAoB,CAAC;AACrD;;AAGA,SAAS,OAAO,OAA6B;CAC3C,OAAO,MAAM,eAAe,MAAM,QAAQ,eAAe;AAC3D"}
1
+ {"version":3,"file":"use-tooltip-interaction.mjs","names":[],"sources":["../../src/tooltip/use-tooltip-interaction.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useEffectEvent } from \"react\";\nimport { createDelayedPair } from \"../internal/use-delayed-pair.js\";\n\nexport interface TooltipInteractionOptions {\n readonly delay: number;\n readonly closeDelay: number;\n readonly disabled: boolean;\n /** The Trigger renders `interestfor` (flag on and not disabled). Re-runs the detection. */\n readonly interestForRequested: boolean;\n}\n\n/**\n * The cross-engine JS path of design section 2.2: hover / keyboard focus with delays,\n * `showPopover({ source })`, Escape and pointerdown-anywhere. Listeners go through\n * `addEventListener` (conventions 7.4) so they can be feature-detected away: where the trigger\n * renders `interestfor` and the element implements `interestForElement`, the browser owns the\n * whole interaction and nothing is attached.\n *\n * Open state is browser-owned (conventions 3.5): every decision reads\n * `popup.matches(\":popover-open\")`, never a copy. The document listeners are attached right after\n * `showPopover()` (the `toggle` event is queued as a task, so waiting for it would leave a window\n * in which an Escape or pointerdown does nothing) and detached when `toggle` reports a close,\n * including closes the library did not perform (native light dismiss of `popover=\"hint\"`).\n *\n * Skip-delay (design 6, wave 11): while another tooltip is showing anywhere in the document\n * (`[role=\"tooltip\"]:popover-open`, FUNSTACK's or not), a hover or keyboard focus hides it and\n * opens this one at once. Stateless: the DOM is read at the start of each hover or focus.\n */\nexport function useTooltipInteraction(\n trigger: HTMLElement | null,\n popup: HTMLElement | null,\n options: TooltipInteractionOptions,\n): void {\n const getDelays = useEffectEvent(() => ({\n delay: options.delay,\n closeDelay: options.closeDelay,\n }));\n const { disabled, interestForRequested } = options;\n\n useEffect(() => {\n if (popup === null) return;\n // Disabling while open hides the popup on both paths (design section 13, Disabled row). On the\n // JS path the previous run's cleanup already did; on the native path nothing else would, and\n // removing `interestfor` does not close an open popover.\n if (disabled) {\n if (isOpen(popup)) popup.hidePopover();\n return;\n }\n if (trigger === null) return;\n // Native path (conventions 8): only when the flag put `interestfor` on the element, and per\n // element, so a `render`ed `<span>` (no `interestForElement`) keeps the JS path. Nothing is\n // attached here, Escape included: the browser's interest handling and the `hint` close watcher\n // decide, so in Chromium an Escape that closes the tooltip may also close an enclosing modal\n // `<dialog>` (the library cannot `preventDefault()` a keydown it never sees).\n if (\n interestForRequested &&\n trigger.hasAttribute(\"interestfor\") &&\n \"interestForElement\" in trigger\n ) {\n return;\n }\n\n const doc = trigger.ownerDocument;\n // One pending open or close at a time (the timer helper shared with Menu's hover intent).\n const timers = createDelayedPair();\n const clear = timers.cancel;\n const show = () => {\n if (isOpen(popup) || !popup.isConnected || !trigger.isConnected) return;\n popup.showPopover({ source: trigger });\n listenDocument(true);\n };\n const hide = () => {\n // A removed popover is already hidden (`isOpen` is false), so this never throws.\n if (!isOpen(popup)) return;\n popup.hidePopover();\n listenDocument(false);\n };\n const showLater = () => {\n timers.open(getDelays().delay, show);\n };\n const hideLater = () => {\n timers.close(getDelays().closeDelay, hide);\n };\n const hideNow = () => {\n clear();\n hide();\n };\n // Another tooltip is showing: hide it and open now, else wait `delay` (design 6). The other\n // Root sees its `toggle` and detaches; its pending close timer finds it closed.\n const showSoon = () => {\n const other = isOpen(popup) ? null : otherOpenTooltip(doc, popup);\n if (other === null) {\n showLater();\n return;\n }\n clear();\n other.hidePopover();\n show();\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key !== \"Escape\") return;\n clear();\n // Escape while closed passes through untouched.\n if (!isOpen(popup)) return;\n hide();\n // This Escape was the tooltip's: an enclosing modal `<dialog>` or `popover=\"auto\"` menu\n // stays open (the close request sees a canceled keydown). A second Escape reaches them.\n event.preventDefault();\n };\n function listenDocument(listen: boolean) {\n if (listen) {\n doc.addEventListener(\"keydown\", onKeyDown);\n doc.addEventListener(\"pointerdown\", hideNow, true);\n } else {\n doc.removeEventListener(\"keydown\", onKeyDown);\n doc.removeEventListener(\"pointerdown\", hideNow, true);\n }\n }\n // Follows opens and closes the library did not perform; reads the DOM, not `newState`, so a\n // toggle task that is stale by the time it runs cannot detach the listeners of an open popup.\n const onToggle = () => {\n listenDocument(isOpen(popup));\n };\n const onTriggerEnter = (event: PointerEvent) => {\n // No hover on touch; the ARIA relation still works for screen-reader focus (design 5.3).\n if (event.pointerType !== \"touch\") showSoon();\n };\n const onTriggerFocus = () => {\n // Pointer focus (a click) does not open; keyboard focus does (design 5.2).\n if (trigger.matches(\":focus-visible\")) showSoon();\n };\n // The document listeners exist only while the popup is open, so before that the trigger\n // itself cancels a pending open: a click or Escape before `delay` elapses must not open the\n // tooltip afterwards. Once open, the document listeners do the hiding.\n const onTriggerKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") clear();\n };\n\n trigger.addEventListener(\"pointerenter\", onTriggerEnter);\n trigger.addEventListener(\"pointerleave\", hideLater);\n trigger.addEventListener(\"pointerdown\", clear);\n trigger.addEventListener(\"keydown\", onTriggerKeyDown);\n trigger.addEventListener(\"focus\", onTriggerFocus);\n trigger.addEventListener(\"blur\", hideLater);\n popup.addEventListener(\"pointerenter\", clear);\n popup.addEventListener(\"pointerleave\", hideLater);\n popup.addEventListener(\"toggle\", onToggle);\n\n return () => {\n hideNow();\n listenDocument(false);\n trigger.removeEventListener(\"pointerenter\", onTriggerEnter);\n trigger.removeEventListener(\"pointerleave\", hideLater);\n trigger.removeEventListener(\"pointerdown\", clear);\n trigger.removeEventListener(\"keydown\", onTriggerKeyDown);\n trigger.removeEventListener(\"focus\", onTriggerFocus);\n trigger.removeEventListener(\"blur\", hideLater);\n popup.removeEventListener(\"pointerenter\", clear);\n popup.removeEventListener(\"pointerleave\", hideLater);\n popup.removeEventListener(\"toggle\", onToggle);\n };\n }, [trigger, popup, disabled, interestForRequested]);\n}\n\n/**\n * A tooltip popover other than `popup` that is showing in the document, or `null` (the warm\n * condition of design 6, the same one the native path's `:root:has()` rule reads). Walks the\n * tooltip popovers and asks each for `:popover-open` rather than one `querySelector`, which the\n * jsdom shim could not answer.\n */\nfunction otherOpenTooltip(doc: Document, popup: HTMLElement): HTMLElement | null {\n for (const element of doc.querySelectorAll<HTMLElement>('[role=\"tooltip\"][popover]')) {\n if (element !== popup && isOpen(element)) return element;\n }\n return null;\n}\n\n/** The popover's top-layer state, read from the DOM. A removed popover is never open. */\nfunction isOpen(popup: HTMLElement): boolean {\n return popup.isConnected && popup.matches(\":popover-open\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,sBACd,SACA,OACA,SACM;CACN,MAAM,YAAY,sBAAsB;EACtC,OAAO,QAAQ;EACf,YAAY,QAAQ;CACtB,EAAE;CACF,MAAM,EAAE,UAAU,yBAAyB;CAE3C,gBAAgB;EACd,IAAI,UAAU,MAAM;EAIpB,IAAI,UAAU;GACZ,IAAI,OAAO,KAAK,GAAG,MAAM,YAAY;GACrC;EACF;EACA,IAAI,YAAY,MAAM;EAMtB,IACE,wBACA,QAAQ,aAAa,aAAa,KAClC,wBAAwB,SAExB;EAGF,MAAM,MAAM,QAAQ;EAEpB,MAAM,SAAS,kBAAkB;EACjC,MAAM,QAAQ,OAAO;EACrB,MAAM,aAAa;GACjB,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,eAAe,CAAC,QAAQ,aAAa;GACjE,MAAM,YAAY,EAAE,QAAQ,QAAQ,CAAC;GACrC,eAAe,IAAI;EACrB;EACA,MAAM,aAAa;GAEjB,IAAI,CAAC,OAAO,KAAK,GAAG;GACpB,MAAM,YAAY;GAClB,eAAe,KAAK;EACtB;EACA,MAAM,kBAAkB;GACtB,OAAO,KAAK,UAAU,CAAC,CAAC,OAAO,IAAI;EACrC;EACA,MAAM,kBAAkB;GACtB,OAAO,MAAM,UAAU,CAAC,CAAC,YAAY,IAAI;EAC3C;EACA,MAAM,gBAAgB;GACpB,MAAM;GACN,KAAK;EACP;EAGA,MAAM,iBAAiB;GACrB,MAAM,QAAQ,OAAO,KAAK,IAAI,OAAO,iBAAiB,KAAK,KAAK;GAChE,IAAI,UAAU,MAAM;IAClB,UAAU;IACV;GACF;GACA,MAAM;GACN,MAAM,YAAY;GAClB,KAAK;EACP;EAEA,MAAM,aAAa,UAAyB;GAC1C,IAAI,MAAM,QAAQ,UAAU;GAC5B,MAAM;GAEN,IAAI,CAAC,OAAO,KAAK,GAAG;GACpB,KAAK;GAGL,MAAM,eAAe;EACvB;EACA,SAAS,eAAe,QAAiB;GACvC,IAAI,QAAQ;IACV,IAAI,iBAAiB,WAAW,SAAS;IACzC,IAAI,iBAAiB,eAAe,SAAS,IAAI;GACnD,OAAO;IACL,IAAI,oBAAoB,WAAW,SAAS;IAC5C,IAAI,oBAAoB,eAAe,SAAS,IAAI;GACtD;EACF;EAGA,MAAM,iBAAiB;GACrB,eAAe,OAAO,KAAK,CAAC;EAC9B;EACA,MAAM,kBAAkB,UAAwB;GAE9C,IAAI,MAAM,gBAAgB,SAAS,SAAS;EAC9C;EACA,MAAM,uBAAuB;GAE3B,IAAI,QAAQ,QAAQ,gBAAgB,GAAG,SAAS;EAClD;EAIA,MAAM,oBAAoB,UAAyB;GACjD,IAAI,MAAM,QAAQ,UAAU,MAAM;EACpC;EAEA,QAAQ,iBAAiB,gBAAgB,cAAc;EACvD,QAAQ,iBAAiB,gBAAgB,SAAS;EAClD,QAAQ,iBAAiB,eAAe,KAAK;EAC7C,QAAQ,iBAAiB,WAAW,gBAAgB;EACpD,QAAQ,iBAAiB,SAAS,cAAc;EAChD,QAAQ,iBAAiB,QAAQ,SAAS;EAC1C,MAAM,iBAAiB,gBAAgB,KAAK;EAC5C,MAAM,iBAAiB,gBAAgB,SAAS;EAChD,MAAM,iBAAiB,UAAU,QAAQ;EAEzC,aAAa;GACX,QAAQ;GACR,eAAe,KAAK;GACpB,QAAQ,oBAAoB,gBAAgB,cAAc;GAC1D,QAAQ,oBAAoB,gBAAgB,SAAS;GACrD,QAAQ,oBAAoB,eAAe,KAAK;GAChD,QAAQ,oBAAoB,WAAW,gBAAgB;GACvD,QAAQ,oBAAoB,SAAS,cAAc;GACnD,QAAQ,oBAAoB,QAAQ,SAAS;GAC7C,MAAM,oBAAoB,gBAAgB,KAAK;GAC/C,MAAM,oBAAoB,gBAAgB,SAAS;GACnD,MAAM,oBAAoB,UAAU,QAAQ;EAC9C;CACF,GAAG;EAAC;EAAS;EAAO;EAAU;CAAoB,CAAC;AACrD;;;;;;;AAQA,SAAS,iBAAiB,KAAe,OAAwC;CAC/E,KAAK,MAAM,WAAW,IAAI,iBAA8B,6BAA2B,GACjF,IAAI,YAAY,SAAS,OAAO,OAAO,GAAG,OAAO;CAEnD,OAAO;AACT;;AAGA,SAAS,OAAO,OAA6B;CAC3C,OAAO,MAAM,eAAe,MAAM,QAAQ,eAAe;AAC3D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funstack/ui",
3
- "version": "0.1.0-alpha.7",
3
+ "version": "0.1.0-alpha.9",
4
4
  "description": "Headless UI library for React — the first Async React-native UI library",
5
5
  "keywords": [
6
6
  "components",
@@ -34,6 +34,7 @@
34
34
  "./checkbox": "./dist/checkbox/index.mjs",
35
35
  "./checkbox-group": "./dist/checkbox-group/index.mjs",
36
36
  "./combobox": "./dist/combobox/index.mjs",
37
+ "./csp": "./dist/csp/index.mjs",
37
38
  "./dialog": "./dist/dialog/index.mjs",
38
39
  "./field": "./dist/field/index.mjs",
39
40
  "./form": "./dist/form/index.mjs",