@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.
- package/dist/pkg/format.js +1 -1
- package/dist/pkg/headless.js +301 -62
- package/package.json +1 -1
- package/src/components/macros/Button.tsx +2 -10
- package/src/components/macros/Cycle.tsx +6 -12
- package/src/components/macros/Dialog.tsx +2 -8
- package/src/components/macros/PassageDisplay.tsx +17 -10
- package/src/hooks/use-action.ts +15 -0
- package/src/index.tsx +2 -2
- package/src/markup/render.tsx +3 -2
- package/src/markup/svg-names.ts +69 -0
- package/src/observe/observable-text.ts +61 -7
- package/src/observe/svg-instances.ts +210 -0
- package/src/saves/save-manager.ts +25 -9
- package/src/store.ts +16 -2
- package/src/story-init.ts +6 -1
- package/src/utils/element-visibility.ts +27 -10
|
@@ -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
|
-
|
|
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(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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 (
|
|
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.
|