@marianmeres/stuic 2.21.1 → 2.22.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.
@@ -1,5 +1,6 @@
1
1
  import { mount, unmount } from "svelte";
2
2
  import { twMerge } from "../../utils/tw-merge.js";
3
+ import { addAnchorName, removeAnchorName } from "../../utils/anchor-name.js";
3
4
  import PopoverContent from "./PopoverContent.svelte";
4
5
  //
5
6
  import "./index.css";
@@ -162,7 +163,8 @@ export function popover(anchorEl, fn) {
162
163
  let currentOptions = {};
163
164
  // Initialize anchor element - anchor-name is always set
164
165
  // In forceFallback mode, the CSS is just ignored
165
- anchorEl.style.cssText += `anchor-name: ${anchorName};`;
166
+ // Use addAnchorName to support multiple anchor names on same element (e.g., popover + tooltip)
167
+ addAnchorName(anchorEl, anchorName);
166
168
  anchorEl.setAttribute("aria-haspopup", "dialog");
167
169
  anchorEl.setAttribute("aria-expanded", "false");
168
170
  anchorEl.setAttribute("aria-controls", id);
@@ -446,6 +448,8 @@ export function popover(anchorEl, fn) {
446
448
  anchorEl.removeEventListener("mouseleave", scheduleHide);
447
449
  anchorEl.removeEventListener("focus", scheduleShow);
448
450
  anchorEl.removeEventListener("blur", scheduleHide);
451
+ // Remove anchor name (preserves other anchor names on element)
452
+ removeAnchorName(anchorEl, anchorName);
449
453
  // Cleanup popover on unmount
450
454
  if (mountedComponent) {
451
455
  unmount(mountedComponent);
@@ -1,4 +1,5 @@
1
1
  import { twMerge } from "../../utils/tw-merge.js";
2
+ import { addAnchorName, removeAnchorName } from "../../utils/anchor-name.js";
2
3
  //
3
4
  import "./index.css";
4
5
  const TIMEOUT = 200;
@@ -103,7 +104,8 @@ export function tooltip(anchorEl, fn) {
103
104
  const id = `tooltip-${rnd}`;
104
105
  const anchorName = `--anchor-${rnd}`;
105
106
  // node once init
106
- anchorEl.style.cssText += `anchor-name: ${anchorName};`;
107
+ // Use addAnchorName to support multiple anchor names on same element (e.g., popover + tooltip)
108
+ addAnchorName(anchorEl, anchorName);
107
109
  anchorEl.setAttribute("aria-describedby", id);
108
110
  anchorEl.setAttribute("aria-expanded", "false");
109
111
  const debug = (...args) => {
@@ -230,6 +232,8 @@ export function tooltip(anchorEl, fn) {
230
232
  anchorEl.removeEventListener("mouseleave", schedule_hide);
231
233
  anchorEl.removeEventListener("focus", schedule_show);
232
234
  anchorEl.removeEventListener("blur", schedule_hide);
235
+ // Remove anchor name (preserves other anchor names on element)
236
+ removeAnchorName(anchorEl, anchorName);
233
237
  // might not have been initialized
234
238
  tooltipEl?.removeEventListener("mouseenter", schedule_show);
235
239
  tooltipEl?.removeEventListener("mouseleave", schedule_hide);
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Utilities for managing CSS anchor-name property when multiple actions
3
+ * (like popover and tooltip) need to anchor to the same element.
4
+ *
5
+ * CSS anchor-name accepts a comma-separated list of names, allowing multiple
6
+ * anchor references on a single element.
7
+ */
8
+ /**
9
+ * Adds an anchor name to an element without overwriting existing ones.
10
+ *
11
+ * @param el - The element to add the anchor name to
12
+ * @param name - The anchor name to add (e.g., "--anchor-popover-xyz")
13
+ */
14
+ export declare function addAnchorName(el: HTMLElement, name: string): void;
15
+ /**
16
+ * Removes an anchor name from an element, preserving other anchor names.
17
+ *
18
+ * @param el - The element to remove the anchor name from
19
+ * @param name - The anchor name to remove
20
+ */
21
+ export declare function removeAnchorName(el: HTMLElement, name: string): void;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Utilities for managing CSS anchor-name property when multiple actions
3
+ * (like popover and tooltip) need to anchor to the same element.
4
+ *
5
+ * CSS anchor-name accepts a comma-separated list of names, allowing multiple
6
+ * anchor references on a single element.
7
+ */
8
+ /**
9
+ * Adds an anchor name to an element without overwriting existing ones.
10
+ *
11
+ * @param el - The element to add the anchor name to
12
+ * @param name - The anchor name to add (e.g., "--anchor-popover-xyz")
13
+ */
14
+ export function addAnchorName(el, name) {
15
+ const current = el.style.getPropertyValue("anchor-name").trim();
16
+ if (current) {
17
+ // Append to existing list (avoid duplicates)
18
+ const names = current.split(",").map((n) => n.trim());
19
+ if (!names.includes(name)) {
20
+ el.style.setProperty("anchor-name", `${current}, ${name}`);
21
+ }
22
+ }
23
+ else {
24
+ el.style.setProperty("anchor-name", name);
25
+ }
26
+ }
27
+ /**
28
+ * Removes an anchor name from an element, preserving other anchor names.
29
+ *
30
+ * @param el - The element to remove the anchor name from
31
+ * @param name - The anchor name to remove
32
+ */
33
+ export function removeAnchorName(el, name) {
34
+ const current = el.style.getPropertyValue("anchor-name").trim();
35
+ if (current) {
36
+ const names = current
37
+ .split(",")
38
+ .map((n) => n.trim())
39
+ .filter((n) => n !== name);
40
+ if (names.length > 0) {
41
+ el.style.setProperty("anchor-name", names.join(", "));
42
+ }
43
+ else {
44
+ el.style.removeProperty("anchor-name");
45
+ }
46
+ }
47
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "2.21.1",
3
+ "version": "2.22.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",