@rohal12/spindle 0.64.25 → 0.64.27

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.
@@ -47,19 +47,33 @@ const SVG_NOT_TEXT = new Set([
47
47
  'marker',
48
48
  ]);
49
49
 
50
+ /** Detached/headless DOMs may have no computed value; CSSOM still resolves
51
+ * duplicate inline declarations and priorities correctly.
52
+ */
53
+ function styleValue(el: Element, name: 'display' | 'visibility'): string {
54
+ return (
55
+ (el.ownerDocument.defaultView ?? globalThis.window)?.getComputedStyle?.(el)[
56
+ name
57
+ ] ||
58
+ (el as HTMLElement).style?.[name] ||
59
+ ''
60
+ );
61
+ }
62
+
50
63
  /**
51
64
  * Whether the element hides its whole subtree, including stylesheet rules.
52
65
  * This needs computed styles but no layout, so it also works headlessly.
66
+ * A symbol referenced by SVG use is rendered only as an instance root.
53
67
  */
54
- export function isHidden(el: Element): boolean {
68
+ export function isHidden(el: Element, svgInstanceRoot = false): boolean {
55
69
  return (
56
70
  el.hasAttribute('hidden') ||
57
71
  el.getAttribute('aria-hidden') === 'true' ||
58
- /(^|;)\s*display\s*:\s*none\b/i.test(el.getAttribute('style') ?? '') ||
59
- el.ownerDocument.defaultView?.getComputedStyle(el).display === 'none' ||
72
+ styleValue(el, 'display') === 'none' ||
60
73
  NOT_TEXT.has(el.localName.toLowerCase()) ||
61
74
  (el.namespaceURI === 'http://www.w3.org/2000/svg' &&
62
- SVG_NOT_TEXT.has(el.localName.toLowerCase())) ||
75
+ SVG_NOT_TEXT.has(el.localName.toLowerCase()) &&
76
+ !(svgInstanceRoot && el.localName.toLowerCase() === 'symbol')) ||
63
77
  (el.parentElement?.tagName === 'DETAILS' &&
64
78
  !el.parentElement.hasAttribute('open') &&
65
79
  el !==
@@ -95,13 +109,16 @@ function inClosedDetails(el: Element, root?: Element): boolean {
95
109
  * `<details>`. An optional root bounds ancestor checks, so observations can
96
110
  * read StoryContext inside its deliberately hidden host.
97
111
  */
98
- export function isRendered(el: Element, root?: Element): boolean {
99
- const style = (e: Element) =>
100
- e.ownerDocument.defaultView?.getComputedStyle(e);
101
- const visibility = style(el)?.visibility;
102
- if (visibility === 'hidden' || visibility === 'collapse') return false;
112
+ export function isRendered(
113
+ el: Element,
114
+ root?: Element,
115
+ checkVisibility = true,
116
+ ): boolean {
117
+ const visibility = styleValue(el, 'visibility');
118
+ if (checkVisibility && (visibility === 'hidden' || visibility === 'collapse'))
119
+ return false;
103
120
  for (let e: Element | null = el; e; e = composedParent(e)) {
104
- if (style(e)?.display === 'none') return false;
121
+ if (styleValue(e, 'display') === 'none') return false;
105
122
  if (e === root) break;
106
123
  const parent = e.parentElement;
107
124
  // Connected light DOM may have no place in its host's rendered tree.