@brytdesigns/web-component-core 1.1.7 → 3.0.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/main/animation/awaitAllAnimations.js +28 -32
- package/dist/main/animation/awaitAllAnimations.js.map +1 -1
- package/dist/main/animation/content.js +156 -0
- package/dist/main/animation/content.js.map +1 -0
- package/dist/main/animation/controlsToPromise.js +6 -5
- package/dist/main/animation/controlsToPromise.js.map +1 -1
- package/dist/main/animation/getTransitionConfig.js +52 -51
- package/dist/main/animation/getTransitionConfig.js.map +1 -1
- package/dist/main/animation/index.d.ts +61 -1
- package/dist/main/animation/index.js +5 -5
- package/dist/main/focusTrap/index.d.ts +1 -1
- package/dist/main/focusTrap/index.js +10 -14
- package/dist/main/focusTrap/index.js.map +1 -1
- package/dist/main/hooks/index.d.ts +14 -9
- package/dist/main/hooks/index.js +5 -6
- package/dist/main/hooks/internal/getValueFromPath.js +9 -10
- package/dist/main/hooks/internal/getValueFromPath.js.map +1 -1
- package/dist/main/hooks/makePathContextHooks.js +58 -68
- package/dist/main/hooks/makePathContextHooks.js.map +1 -1
- package/dist/main/hooks/makePathDataArrayComponent.js +61 -67
- package/dist/main/hooks/makePathDataArrayComponent.js.map +1 -1
- package/dist/main/hooks/makePathDataArrayItemComponent.js +17 -21
- package/dist/main/hooks/makePathDataArrayItemComponent.js.map +1 -1
- package/dist/main/hooks/makePathDataComponent.js +31 -33
- package/dist/main/hooks/makePathDataComponent.js.map +1 -1
- package/dist/main/index.d.ts +304 -27
- package/dist/main/index.js +28 -7
- package/dist/main/promise/abortablePromise.js +10 -15
- package/dist/main/promise/abortablePromise.js.map +1 -1
- package/dist/main/promise/index.js +2 -3
- package/dist/main/utils/a11y.js +133 -0
- package/dist/main/utils/a11y.js.map +1 -0
- package/dist/main/utils/body-scroll-lock.js +40 -18
- package/dist/main/utils/body-scroll-lock.js.map +1 -1
- package/dist/main/utils/checkLoaded.js +4 -4
- package/dist/main/utils/checkLoaded.js.map +1 -1
- package/dist/main/utils/createRemoteContext.js +85 -0
- package/dist/main/utils/createRemoteContext.js.map +1 -0
- package/dist/main/utils/disclosure.js +52 -0
- package/dist/main/utils/disclosure.js.map +1 -0
- package/dist/main/utils/formatValue.js +14 -18
- package/dist/main/utils/formatValue.js.map +1 -1
- package/dist/main/utils/getContextFromProvider.js +15 -10
- package/dist/main/utils/getContextFromProvider.js.map +1 -1
- package/dist/main/utils/getTemplateContent.js +6 -7
- package/dist/main/utils/getTemplateContent.js.map +1 -1
- package/dist/main/utils/guarded-effect.js +72 -0
- package/dist/main/utils/guarded-effect.js.map +1 -0
- package/dist/main/utils/index.d.ts +237 -20
- package/dist/main/utils/index.js +15 -12
- package/dist/main/utils/invokeOnLoaded.js +13 -13
- package/dist/main/utils/invokeOnLoaded.js.map +1 -1
- package/dist/main/utils/isCustomElement.js +4 -3
- package/dist/main/utils/isCustomElement.js.map +1 -1
- package/dist/main/utils/nested-overlays.js +36 -0
- package/dist/main/utils/nested-overlays.js.map +1 -0
- package/dist/main/utils/solid-element.js +48 -88
- package/dist/main/utils/solid-element.js.map +1 -1
- package/dist/main/utils/toHyphenated.js +4 -3
- package/dist/main/utils/toHyphenated.js.map +1 -1
- package/package.json +16 -15
- package/dist/esm/animation/index.js +0 -97
- package/dist/esm/animation/index.js.map +0 -1
- package/dist/esm/focusTrap/index.js +0 -18
- package/dist/esm/focusTrap/index.js.map +0 -1
- package/dist/esm/hooks/index.js +0 -235
- package/dist/esm/hooks/index.js.map +0 -1
- package/dist/esm/index.js +0 -547
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/promise/index.js +0 -20
- package/dist/esm/promise/index.js.map +0 -1
- package/dist/esm/utils/index.js +0 -236
- package/dist/esm/utils/index.js.map +0 -1
- package/dist/main/animation/index.js.map +0 -1
- package/dist/main/hooks/index.js.map +0 -1
- package/dist/main/hooks/internal/index.js +0 -3
- package/dist/main/hooks/internal/index.js.map +0 -1
- package/dist/main/hooks/internal/types.js +0 -3
- package/dist/main/hooks/internal/types.js.map +0 -1
- package/dist/main/index.js.map +0 -1
- package/dist/main/promise/index.js.map +0 -1
- package/dist/main/utils/createWithElementContext.js +0 -64
- package/dist/main/utils/createWithElementContext.js.map +0 -1
- package/dist/main/utils/index.js.map +0 -1
|
@@ -1,36 +1,32 @@
|
|
|
1
|
+
//#region src/animation/awaitAllAnimations.ts
|
|
1
2
|
function awaitAllAnimations(promises) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
updateResults(null, i);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
3
|
+
return new Promise((resolve, _) => {
|
|
4
|
+
const results = [];
|
|
5
|
+
let remaining = promises.length;
|
|
6
|
+
if (remaining === 0) {
|
|
7
|
+
resolve([]);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
function updateResults(value, index) {
|
|
11
|
+
results[index] = value;
|
|
12
|
+
remaining -= 1;
|
|
13
|
+
if (remaining === 0) resolve(results);
|
|
14
|
+
}
|
|
15
|
+
promises.forEach((p, i) => {
|
|
16
|
+
try {
|
|
17
|
+
if (p?.state === "idle") updateResults(null, i);
|
|
18
|
+
else p.then(() => {
|
|
19
|
+
updateResults(null, i);
|
|
20
|
+
});
|
|
21
|
+
} catch (e) {
|
|
22
|
+
p.then(() => {
|
|
23
|
+
updateResults(null, i);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
32
28
|
}
|
|
33
|
-
|
|
29
|
+
//#endregion
|
|
34
30
|
export { awaitAllAnimations };
|
|
35
|
-
|
|
31
|
+
|
|
36
32
|
//# sourceMappingURL=awaitAllAnimations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"awaitAllAnimations.js","names":[],"sources":["../../../src/animation/awaitAllAnimations.ts"],"sourcesContent":["import type { AnimationPlaybackControlsWithThen } from \"motion\";\n\nexport function awaitAllAnimations(\n\tpromises: AnimationPlaybackControlsWithThen[],\n) {\n\treturn new Promise((resolve, _) => {\n\t\tconst results: any[] = [];\n\t\tlet remaining = promises.length;\n\t\tif (remaining === 0) {\n\t\t\tresolve([]); // zero‐length edge case\n\t\t\treturn;\n\t\t}\n\n\t\tfunction updateResults<T>(value: T, index: number) {\n\t\t\tresults[index] = value;\n\t\t\tremaining -= 1;\n\t\t\tif (remaining === 0) {\n\t\t\t\tresolve(results);\n\t\t\t}\n\t\t}\n\n\t\tpromises.forEach((p, i) => {\n\t\t\ttry {\n\t\t\t\tif (p?.state === \"idle\") {\n\t\t\t\t\tupdateResults(null, i);\n\t\t\t\t} else {\n\t\t\t\t\tp.then(() => {\n\t\t\t\t\t\tupdateResults(null, i);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tp.then(() => {\n\t\t\t\t\tupdateResults(null, i);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t});\n}\n"],"mappings":";AAEA,SAAgB,mBACf,UACC;CACD,OAAO,IAAI,SAAS,SAAS,MAAM;EAClC,MAAM,UAAiB,CAAC;EACxB,IAAI,YAAY,SAAS;EACzB,IAAI,cAAc,GAAG;GACpB,QAAQ,CAAC,CAAC;GACV;EACD;EAEA,SAAS,cAAiB,OAAU,OAAe;GAClD,QAAQ,SAAS;GACjB,aAAa;GACb,IAAI,cAAc,GACjB,QAAQ,OAAO;EAEjB;EAEA,SAAS,SAAS,GAAG,MAAM;GAC1B,IAAI;IACH,IAAI,GAAG,UAAU,QAChB,cAAc,MAAM,CAAC;SAErB,EAAE,WAAW;KACZ,cAAc,MAAM,CAAC;IACtB,CAAC;GAEH,SAAS,GAAG;IACX,EAAE,WAAW;KACZ,cAAc,MAAM,CAAC;IACtB,CAAC;GACF;EACD,CAAC;CACF,CAAC;AACF"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { animate } from "motion";
|
|
2
|
+
//#region src/animation/content.ts
|
|
3
|
+
/**
|
|
4
|
+
* Open/close helpers for disclosure content (`accordion-content` and
|
|
5
|
+
* `collapsible-content`), which animates its height and vertical padding
|
|
6
|
+
* between zero and its natural size.
|
|
7
|
+
*/
|
|
8
|
+
var CONTENT_DURATION = .35;
|
|
9
|
+
/**
|
|
10
|
+
* Whether the visitor has asked their device to reduce motion. Read on every
|
|
11
|
+
* open and close, so changing the setting applies without a reload.
|
|
12
|
+
*/
|
|
13
|
+
function shouldReduceMotion() {
|
|
14
|
+
return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
15
|
+
}
|
|
16
|
+
var REDUCED_MOTION_DURATION = .001;
|
|
17
|
+
var contentTransition = () => ({ duration: shouldReduceMotion() ? REDUCED_MOTION_DURATION : CONTENT_DURATION });
|
|
18
|
+
var never = () => false;
|
|
19
|
+
var setChildrenOpacity = (element, opacity) => {
|
|
20
|
+
for (const child of Array.from(element.children)) child.style.opacity = opacity;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The open size to animate `max-height` towards, plus the padding to restore.
|
|
24
|
+
*
|
|
25
|
+
* `height` is the border-box height, but `max-height` caps the **content**
|
|
26
|
+
* box unless the element is `box-sizing: border-box`. Animating towards the
|
|
27
|
+
* border-box height under the default `content-box` overshoots by the
|
|
28
|
+
* padding, so the content is fully revealed well before the animation ends and
|
|
29
|
+
* the tail of the easing does nothing — a 20px/20px panel reached full size at
|
|
30
|
+
* roughly 60% of its duration.
|
|
31
|
+
*
|
|
32
|
+
* So the target is whatever `max-height` will actually mean on this element.
|
|
33
|
+
*/
|
|
34
|
+
var measureContent = (element) => {
|
|
35
|
+
element.style.maxHeight = "max-content";
|
|
36
|
+
const height = element.getBoundingClientRect().height;
|
|
37
|
+
element.style.maxHeight = "0";
|
|
38
|
+
const style = getComputedStyle(element);
|
|
39
|
+
const paddingTop = parseInt(style.paddingTop, 10) || 0;
|
|
40
|
+
const paddingBottom = parseInt(style.paddingBottom, 10) || 0;
|
|
41
|
+
return {
|
|
42
|
+
target: style.boxSizing === "border-box" ? height : height - paddingTop - paddingBottom,
|
|
43
|
+
paddingTop,
|
|
44
|
+
paddingBottom
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Whether the browser supports `hidden="until-found"`, which keeps a closed
|
|
49
|
+
* content's text reachable by find-in-page and text-fragment links.
|
|
50
|
+
*/
|
|
51
|
+
function supportsHiddenUntilFound() {
|
|
52
|
+
return "onbeforematch" in HTMLElement.prototype;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Puts the content in its open end state, without animating.
|
|
56
|
+
*
|
|
57
|
+
* `flow-root` rather than `block`, so the panel is always a block formatting
|
|
58
|
+
* context and always contains its children's margins.
|
|
59
|
+
*
|
|
60
|
+
* Without it the box model changed underneath the animation. The measurement
|
|
61
|
+
* runs before `overflow: hidden` is applied, so a child margin collapsed out
|
|
62
|
+
* of the panel and the target came back short; the animation then set
|
|
63
|
+
* `overflow: hidden`, which *makes* the panel a BFC, so the same content
|
|
64
|
+
* suddenly needed more room than the target allowed and stayed clipped — and
|
|
65
|
+
* snapped into place when `overflow` was removed at the end. A `<p>` with
|
|
66
|
+
* default margins inside a plain `<div>` measured 24px and rendered 56px.
|
|
67
|
+
*
|
|
68
|
+
* `flow-root` is the modern way to ask for a BFC without clipping, which is
|
|
69
|
+
* exactly what is wanted here: `overflow: hidden` during the animation now
|
|
70
|
+
* changes nothing about the box, only what is painted outside it.
|
|
71
|
+
*/
|
|
72
|
+
function showContent(element) {
|
|
73
|
+
element.removeAttribute("hidden");
|
|
74
|
+
element.style.cssText = `
|
|
75
|
+
display: flow-root;
|
|
76
|
+
opacity: 1;
|
|
77
|
+
visibility: visible;
|
|
78
|
+
`;
|
|
79
|
+
element.style.maxHeight = "max-content";
|
|
80
|
+
setChildrenOpacity(element, "1");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Puts the content in its closed end state, without animating.
|
|
84
|
+
*
|
|
85
|
+
* Where supported, the content is closed with `hidden="until-found"` rather
|
|
86
|
+
* than `display: none`, so find-in-page can still match its text. The inline
|
|
87
|
+
* styles zero the box, which `until-found` alone leaves its padding, and keep
|
|
88
|
+
* it a block: `until-found` hides content through `content-visibility`, which
|
|
89
|
+
* does not apply to an inline box, and custom elements are inline by default.
|
|
90
|
+
*/
|
|
91
|
+
function hideContent(element) {
|
|
92
|
+
if (supportsHiddenUntilFound()) {
|
|
93
|
+
element.setAttribute("hidden", "until-found");
|
|
94
|
+
element.style.cssText = `
|
|
95
|
+
display: flow-root;
|
|
96
|
+
overflow: hidden;
|
|
97
|
+
max-height: 0px;
|
|
98
|
+
padding-top: 0px;
|
|
99
|
+
padding-bottom: 0px;
|
|
100
|
+
`;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
element.style.cssText = `
|
|
104
|
+
display: none;
|
|
105
|
+
opacity: 0;
|
|
106
|
+
visibility: hidden;
|
|
107
|
+
max-height: 0px;
|
|
108
|
+
`;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Calls `callback` when find-in-page or a text-fragment link matches text
|
|
112
|
+
* inside the closed content. It fires before the browser removes `hidden` and
|
|
113
|
+
* scrolls to the match, so layout changes made synchronously in `callback`
|
|
114
|
+
* are settled by the time the browser scrolls. Returns a cleanup function.
|
|
115
|
+
*/
|
|
116
|
+
function onContentRevealed(element, callback) {
|
|
117
|
+
element.addEventListener("beforematch", callback);
|
|
118
|
+
return () => element.removeEventListener("beforematch", callback);
|
|
119
|
+
}
|
|
120
|
+
/** Animates the content open from zero height. */
|
|
121
|
+
function expandContent(element, isStale = never) {
|
|
122
|
+
showContent(element);
|
|
123
|
+
const { target, paddingTop, paddingBottom } = measureContent(element);
|
|
124
|
+
element.style.overflow = "hidden";
|
|
125
|
+
const animation = animate(element, {
|
|
126
|
+
maxHeight: ["0px", `${target}px`],
|
|
127
|
+
paddingTop: ["0px", `${paddingTop}px`],
|
|
128
|
+
paddingBottom: ["0px", `${paddingBottom}px`]
|
|
129
|
+
}, contentTransition());
|
|
130
|
+
animation.then(() => {
|
|
131
|
+
if (isStale()) return;
|
|
132
|
+
element.style.maxHeight = "max-content";
|
|
133
|
+
element.style.removeProperty("overflow");
|
|
134
|
+
});
|
|
135
|
+
return animation;
|
|
136
|
+
}
|
|
137
|
+
/** Animates the content closed to zero height. */
|
|
138
|
+
function collapseContent(element, isStale = never) {
|
|
139
|
+
const { target, paddingTop, paddingBottom } = measureContent(element);
|
|
140
|
+
element.style.overflow = "hidden";
|
|
141
|
+
setChildrenOpacity(element, "0");
|
|
142
|
+
const animation = animate(element, {
|
|
143
|
+
maxHeight: [`${target}px`, "0px"],
|
|
144
|
+
paddingTop: [`${paddingTop}px`, "0px"],
|
|
145
|
+
paddingBottom: [`${paddingBottom}px`, "0px"]
|
|
146
|
+
}, contentTransition());
|
|
147
|
+
animation.then(() => {
|
|
148
|
+
if (isStale()) return;
|
|
149
|
+
hideContent(element);
|
|
150
|
+
});
|
|
151
|
+
return animation;
|
|
152
|
+
}
|
|
153
|
+
//#endregion
|
|
154
|
+
export { collapseContent, expandContent, hideContent, onContentRevealed, shouldReduceMotion, showContent, supportsHiddenUntilFound };
|
|
155
|
+
|
|
156
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","names":[],"sources":["../../../src/animation/content.ts"],"sourcesContent":["import { animate } from \"motion\";\n\n/**\n * Open/close helpers for disclosure content (`accordion-content` and\n * `collapsible-content`), which animates its height and vertical padding\n * between zero and its natural size.\n */\n\nconst CONTENT_DURATION = 0.35;\n\n/**\n * Whether the visitor has asked their device to reduce motion. Read on every\n * open and close, so changing the setting applies without a reload.\n */\nexport function shouldReduceMotion() {\n\treturn (\n\t\ttypeof window.matchMedia === \"function\" &&\n\t\twindow.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n\t);\n}\n\n// Under reduced motion the animation still runs, so everything awaiting it\n// (end states, queues, is-animating) settles as usual, but over a single\n// frame. Not zero: with `duration: 0`, Motion resolves the animation before\n// it writes the final keyframe, so the final keyframe overwrites the end\n// state applied on completion (open content stays capped at its measured\n// height).\nconst REDUCED_MOTION_DURATION = 0.001;\n\nconst contentTransition = () => ({\n\tduration: shouldReduceMotion() ? REDUCED_MOTION_DURATION : CONTENT_DURATION,\n});\n\n/**\n * Whether the direction this animation was started for has since been left.\n *\n * Toggling mid-animation re-runs the caller's effect, whose cleanup calls\n * `animation.complete()` — which resolves the promise, so the `.then` below\n * fires as a microtask *after* the new direction has already applied its\n * styles, and would undo them. Callers flip their own flag in that cleanup;\n * the default is for callers that never re-enter.\n */\ntype IsStale = () => boolean;\n\nconst never: IsStale = () => false;\n\nconst setChildrenOpacity = (element: HTMLElement, opacity: \"0\" | \"1\") => {\n\tfor (const child of Array.from(element.children) as HTMLElement[]) {\n\t\tchild.style.opacity = opacity;\n\t}\n};\n\n/**\n * The open size to animate `max-height` towards, plus the padding to restore.\n *\n * `height` is the border-box height, but `max-height` caps the **content**\n * box unless the element is `box-sizing: border-box`. Animating towards the\n * border-box height under the default `content-box` overshoots by the\n * padding, so the content is fully revealed well before the animation ends and\n * the tail of the easing does nothing — a 20px/20px panel reached full size at\n * roughly 60% of its duration.\n *\n * So the target is whatever `max-height` will actually mean on this element.\n */\nconst measureContent = (element: HTMLElement) => {\n\telement.style.maxHeight = \"max-content\";\n\tconst height = element.getBoundingClientRect().height;\n\telement.style.maxHeight = \"0\";\n\tconst style = getComputedStyle(element);\n\tconst paddingTop = parseInt(style.paddingTop, 10) || 0;\n\tconst paddingBottom = parseInt(style.paddingBottom, 10) || 0;\n\tconst capsBorderBox = style.boxSizing === \"border-box\";\n\treturn {\n\t\ttarget: capsBorderBox ? height : height - paddingTop - paddingBottom,\n\t\tpaddingTop,\n\t\tpaddingBottom,\n\t};\n};\n\n/**\n * Whether the browser supports `hidden=\"until-found\"`, which keeps a closed\n * content's text reachable by find-in-page and text-fragment links.\n */\nexport function supportsHiddenUntilFound() {\n\treturn \"onbeforematch\" in HTMLElement.prototype;\n}\n\n/**\n * Puts the content in its open end state, without animating.\n *\n * `flow-root` rather than `block`, so the panel is always a block formatting\n * context and always contains its children's margins.\n *\n * Without it the box model changed underneath the animation. The measurement\n * runs before `overflow: hidden` is applied, so a child margin collapsed out\n * of the panel and the target came back short; the animation then set\n * `overflow: hidden`, which *makes* the panel a BFC, so the same content\n * suddenly needed more room than the target allowed and stayed clipped — and\n * snapped into place when `overflow` was removed at the end. A `<p>` with\n * default margins inside a plain `<div>` measured 24px and rendered 56px.\n *\n * `flow-root` is the modern way to ask for a BFC without clipping, which is\n * exactly what is wanted here: `overflow: hidden` during the animation now\n * changes nothing about the box, only what is painted outside it.\n */\nexport function showContent(element: HTMLElement) {\n\telement.removeAttribute(\"hidden\");\n\telement.style.cssText = `\n display: flow-root;\n opacity: 1;\n visibility: visible;\n `;\n\telement.style.maxHeight = \"max-content\";\n\tsetChildrenOpacity(element, \"1\");\n}\n\n/**\n * Puts the content in its closed end state, without animating.\n *\n * Where supported, the content is closed with `hidden=\"until-found\"` rather\n * than `display: none`, so find-in-page can still match its text. The inline\n * styles zero the box, which `until-found` alone leaves its padding, and keep\n * it a block: `until-found` hides content through `content-visibility`, which\n * does not apply to an inline box, and custom elements are inline by default.\n */\nexport function hideContent(element: HTMLElement) {\n\tif (supportsHiddenUntilFound()) {\n\t\telement.setAttribute(\"hidden\", \"until-found\");\n\t\telement.style.cssText = `\n display: flow-root;\n overflow: hidden;\n max-height: 0px;\n padding-top: 0px;\n padding-bottom: 0px;\n `;\n\t\treturn;\n\t}\n\telement.style.cssText = `\n display: none;\n opacity: 0;\n visibility: hidden;\n max-height: 0px;\n `;\n}\n\n/**\n * Calls `callback` when find-in-page or a text-fragment link matches text\n * inside the closed content. It fires before the browser removes `hidden` and\n * scrolls to the match, so layout changes made synchronously in `callback`\n * are settled by the time the browser scrolls. Returns a cleanup function.\n */\nexport function onContentRevealed(element: HTMLElement, callback: () => void) {\n\telement.addEventListener(\"beforematch\", callback);\n\treturn () => element.removeEventListener(\"beforematch\", callback);\n}\n\n/** Animates the content open from zero height. */\nexport function expandContent(element: HTMLElement, isStale: IsStale = never) {\n\tshowContent(element);\n\n\tconst { target, paddingTop, paddingBottom } = measureContent(element);\n\n\t// Clip the children to the growing box; removed once open.\n\telement.style.overflow = \"hidden\";\n\n\tconst animation = animate(\n\t\telement,\n\t\t{\n\t\t\tmaxHeight: [\"0px\", `${target}px`],\n\t\t\tpaddingTop: [\"0px\", `${paddingTop}px`],\n\t\t\tpaddingBottom: [\"0px\", `${paddingBottom}px`],\n\t\t},\n\t\tcontentTransition(),\n\t);\n\n\tanimation.then(() => {\n\t\tif (isStale()) return;\n\t\telement.style.maxHeight = \"max-content\";\n\t\telement.style.removeProperty(\"overflow\");\n\t});\n\n\treturn animation;\n}\n\n/** Animates the content closed to zero height. */\nexport function collapseContent(\n\telement: HTMLElement,\n\tisStale: IsStale = never,\n) {\n\tconst { target, paddingTop, paddingBottom } = measureContent(element);\n\n\telement.style.overflow = \"hidden\";\n\n\tsetChildrenOpacity(element, \"0\");\n\n\tconst animation = animate(\n\t\telement,\n\t\t{\n\t\t\tmaxHeight: [`${target}px`, \"0px\"],\n\t\t\tpaddingTop: [`${paddingTop}px`, \"0px\"],\n\t\t\tpaddingBottom: [`${paddingBottom}px`, \"0px\"],\n\t\t},\n\t\tcontentTransition(),\n\t);\n\n\tanimation.then(() => {\n\t\tif (isStale()) return;\n\t\thideContent(element);\n\t});\n\n\treturn animation;\n}\n"],"mappings":";;;;;;;AAQA,IAAM,mBAAmB;;;;;AAMzB,SAAgB,qBAAqB;CACpC,OACC,OAAO,OAAO,eAAe,cAC7B,OAAO,WAAW,kCAAkC,CAAC,CAAC;AAExD;AAQA,IAAM,0BAA0B;AAEhC,IAAM,2BAA2B,EAChC,UAAU,mBAAmB,IAAI,0BAA0B,iBAC5D;AAaA,IAAM,cAAuB;AAE7B,IAAM,sBAAsB,SAAsB,YAAuB;CACxE,KAAK,MAAM,SAAS,MAAM,KAAK,QAAQ,QAAQ,GAC9C,MAAM,MAAM,UAAU;AAExB;;;;;;;;;;;;;AAcA,IAAM,kBAAkB,YAAyB;CAChD,QAAQ,MAAM,YAAY;CAC1B,MAAM,SAAS,QAAQ,sBAAsB,CAAC,CAAC;CAC/C,QAAQ,MAAM,YAAY;CAC1B,MAAM,QAAQ,iBAAiB,OAAO;CACtC,MAAM,aAAa,SAAS,MAAM,YAAY,EAAE,KAAK;CACrD,MAAM,gBAAgB,SAAS,MAAM,eAAe,EAAE,KAAK;CAE3D,OAAO;EACN,QAFqB,MAAM,cAAc,eAEjB,SAAS,SAAS,aAAa;EACvD;EACA;CACD;AACD;;;;;AAMA,SAAgB,2BAA2B;CAC1C,OAAO,mBAAmB,YAAY;AACvC;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,YAAY,SAAsB;CACjD,QAAQ,gBAAgB,QAAQ;CAChC,QAAQ,MAAM,UAAU;;;;;CAKxB,QAAQ,MAAM,YAAY;CAC1B,mBAAmB,SAAS,GAAG;AAChC;;;;;;;;;;AAWA,SAAgB,YAAY,SAAsB;CACjD,IAAI,yBAAyB,GAAG;EAC/B,QAAQ,aAAa,UAAU,aAAa;EAC5C,QAAQ,MAAM,UAAU;;;;;;;EAOxB;CACD;CACA,QAAQ,MAAM,UAAU;;;;;;AAMzB;;;;;;;AAQA,SAAgB,kBAAkB,SAAsB,UAAsB;CAC7E,QAAQ,iBAAiB,eAAe,QAAQ;CAChD,aAAa,QAAQ,oBAAoB,eAAe,QAAQ;AACjE;;AAGA,SAAgB,cAAc,SAAsB,UAAmB,OAAO;CAC7E,YAAY,OAAO;CAEnB,MAAM,EAAE,QAAQ,YAAY,kBAAkB,eAAe,OAAO;CAGpE,QAAQ,MAAM,WAAW;CAEzB,MAAM,YAAY,QACjB,SACA;EACC,WAAW,CAAC,OAAO,GAAG,OAAO,GAAG;EAChC,YAAY,CAAC,OAAO,GAAG,WAAW,GAAG;EACrC,eAAe,CAAC,OAAO,GAAG,cAAc,GAAG;CAC5C,GACA,kBAAkB,CACnB;CAEA,UAAU,WAAW;EACpB,IAAI,QAAQ,GAAG;EACf,QAAQ,MAAM,YAAY;EAC1B,QAAQ,MAAM,eAAe,UAAU;CACxC,CAAC;CAED,OAAO;AACR;;AAGA,SAAgB,gBACf,SACA,UAAmB,OAClB;CACD,MAAM,EAAE,QAAQ,YAAY,kBAAkB,eAAe,OAAO;CAEpE,QAAQ,MAAM,WAAW;CAEzB,mBAAmB,SAAS,GAAG;CAE/B,MAAM,YAAY,QACjB,SACA;EACC,WAAW,CAAC,GAAG,OAAO,KAAK,KAAK;EAChC,YAAY,CAAC,GAAG,WAAW,KAAK,KAAK;EACrC,eAAe,CAAC,GAAG,cAAc,KAAK,KAAK;CAC5C,GACA,kBAAkB,CACnB;CAEA,UAAU,WAAW;EACpB,IAAI,QAAQ,GAAG;EACf,YAAY,OAAO;CACpB,CAAC;CAED,OAAO;AACR"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
//#region src/animation/controlsToPromise.ts
|
|
1
2
|
async function controlsToPromise(controls) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
return new Promise((resolve) => {
|
|
4
|
+
controls.then(() => resolve(null));
|
|
5
|
+
});
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
+
//#endregion
|
|
7
8
|
export { controlsToPromise };
|
|
8
|
-
|
|
9
|
+
|
|
9
10
|
//# sourceMappingURL=controlsToPromise.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"controlsToPromise.js","names":[],"sources":["../../../src/animation/controlsToPromise.ts"],"sourcesContent":["import type { AnimationPlaybackControlsWithThen } from \"motion\";\n\nexport async function controlsToPromise(\n\tcontrols: AnimationPlaybackControlsWithThen,\n) {\n\treturn new Promise((resolve) => {\n\t\tcontrols.then(() => resolve(null));\n\t});\n}\n"],"mappings":";AAEA,eAAsB,kBACrB,UACC;CACD,OAAO,IAAI,SAAS,YAAY;EAC/B,SAAS,WAAW,QAAQ,IAAI,CAAC;CAClC,CAAC;AACF"}
|
|
@@ -1,55 +1,56 @@
|
|
|
1
|
+
//#region src/animation/getTransitionConfig.ts
|
|
1
2
|
function getTransitionConfig(style) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
3
|
+
const properties = {
|
|
4
|
+
bounce: style.getPropertyValue("--motion--bounce"),
|
|
5
|
+
bounceDamping: style.getPropertyValue("--motion--bounce-damping"),
|
|
6
|
+
bounceStiffness: style.getPropertyValue("--motion--bounce-stiffness"),
|
|
7
|
+
duration: style.getPropertyValue("--motion--duration"),
|
|
8
|
+
damping: style.getPropertyValue("--motion--damping"),
|
|
9
|
+
delay: style.getPropertyValue("--motion--delay"),
|
|
10
|
+
ease: style.getPropertyValue("--motion--ease"),
|
|
11
|
+
elapsed: style.getPropertyValue("--motion--elapsed"),
|
|
12
|
+
mass: style.getPropertyValue("--motion--mass"),
|
|
13
|
+
max: style.getPropertyValue("--motion--max"),
|
|
14
|
+
min: style.getPropertyValue("--motion--min"),
|
|
15
|
+
power: style.getPropertyValue("--motion--power"),
|
|
16
|
+
repeat: style.getPropertyValue("--motion--repeat"),
|
|
17
|
+
repeatDelay: style.getPropertyValue("--motion--repeat-delay"),
|
|
18
|
+
repeatType: style.getPropertyValue("--motion--repeat-type"),
|
|
19
|
+
restDelta: style.getPropertyValue("--motion--rest-delta"),
|
|
20
|
+
restSpeed: style.getPropertyValue("--motion--rest-speed"),
|
|
21
|
+
startTime: style.getPropertyValue("--motion--start-time"),
|
|
22
|
+
timeConstant: style.getPropertyValue("--motion--time-constant"),
|
|
23
|
+
times: style.getPropertyValue("--motion--times"),
|
|
24
|
+
type: style.getPropertyValue("--motion--type"),
|
|
25
|
+
velocity: style.getPropertyValue("--motion--velocity"),
|
|
26
|
+
visualDuration: style.getPropertyValue("--motion--visual-duration")
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
bounce: properties.bounce ? parseFloat(properties.bounce) : void 0,
|
|
30
|
+
bounceDamping: properties.bounceDamping ? parseFloat(properties.bounceDamping) : void 0,
|
|
31
|
+
bounceStiffness: properties.bounceStiffness ? parseFloat(properties.bounceStiffness) : void 0,
|
|
32
|
+
duration: properties.duration ? parseFloat(properties.duration) : void 0,
|
|
33
|
+
damping: properties.damping ? parseFloat(properties.damping) : void 0,
|
|
34
|
+
delay: properties.delay ? parseFloat(properties.delay) : void 0,
|
|
35
|
+
ease: properties.ease ? properties.ease : void 0,
|
|
36
|
+
elapsed: properties.elapsed ? parseFloat(properties.elapsed) : void 0,
|
|
37
|
+
mass: properties.mass ? parseFloat(properties.mass) : void 0,
|
|
38
|
+
max: properties.max ? parseFloat(properties.max) : void 0,
|
|
39
|
+
min: properties.min ? parseFloat(properties.min) : void 0,
|
|
40
|
+
power: properties.power ? parseFloat(properties.power) : void 0,
|
|
41
|
+
repeat: properties.repeat ? parseInt(properties.repeat) : void 0,
|
|
42
|
+
repeatDelay: properties.repeatDelay ? parseFloat(properties.repeatDelay) : void 0,
|
|
43
|
+
repeatType: properties.repeatType ? properties.repeatType : void 0,
|
|
44
|
+
restDelta: properties.restDelta ? parseFloat(properties.restDelta) : void 0,
|
|
45
|
+
restSpeed: properties.restSpeed ? parseFloat(properties.restSpeed) : void 0,
|
|
46
|
+
startTime: properties.startTime ? parseFloat(properties.startTime) : void 0,
|
|
47
|
+
timeConstant: properties.timeConstant ? parseFloat(properties.timeConstant) : void 0,
|
|
48
|
+
type: properties.type ? properties.type : void 0,
|
|
49
|
+
velocity: properties.velocity ? parseFloat(properties.velocity) : void 0,
|
|
50
|
+
visualDuration: properties.visualDuration ? parseFloat(properties.visualDuration) : void 0
|
|
51
|
+
};
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
//#endregion
|
|
53
54
|
export { getTransitionConfig };
|
|
54
|
-
|
|
55
|
+
|
|
55
56
|
//# sourceMappingURL=getTransitionConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"getTransitionConfig.js","names":[],"sources":["../../../src/animation/getTransitionConfig.ts"],"sourcesContent":["import type {\n\tAnimationGeneratorType,\n\tEasing,\n\tRepeatType,\n\tTransition,\n} from \"motion\";\n\nexport function getTransitionConfig(style: CSSStyleDeclaration) {\n\tconst properties = {\n\t\tbounce: style.getPropertyValue(\"--motion--bounce\"),\n\t\tbounceDamping: style.getPropertyValue(\"--motion--bounce-damping\"),\n\t\tbounceStiffness: style.getPropertyValue(\"--motion--bounce-stiffness\"),\n\t\tduration: style.getPropertyValue(\"--motion--duration\"),\n\t\tdamping: style.getPropertyValue(\"--motion--damping\"),\n\t\tdelay: style.getPropertyValue(\"--motion--delay\"),\n\t\tease: style.getPropertyValue(\"--motion--ease\"),\n\t\telapsed: style.getPropertyValue(\"--motion--elapsed\"),\n\t\tmass: style.getPropertyValue(\"--motion--mass\"),\n\t\tmax: style.getPropertyValue(\"--motion--max\"),\n\t\tmin: style.getPropertyValue(\"--motion--min\"),\n\t\tpower: style.getPropertyValue(\"--motion--power\"),\n\t\trepeat: style.getPropertyValue(\"--motion--repeat\"),\n\t\trepeatDelay: style.getPropertyValue(\"--motion--repeat-delay\"),\n\t\trepeatType: style.getPropertyValue(\"--motion--repeat-type\"),\n\t\trestDelta: style.getPropertyValue(\"--motion--rest-delta\"),\n\t\trestSpeed: style.getPropertyValue(\"--motion--rest-speed\"),\n\t\tstartTime: style.getPropertyValue(\"--motion--start-time\"),\n\t\ttimeConstant: style.getPropertyValue(\"--motion--time-constant\"),\n\t\ttimes: style.getPropertyValue(\"--motion--times\"),\n\t\ttype: style.getPropertyValue(\"--motion--type\"),\n\t\tvelocity: style.getPropertyValue(\"--motion--velocity\"),\n\t\tvisualDuration: style.getPropertyValue(\"--motion--visual-duration\"),\n\t};\n\treturn {\n\t\tbounce: properties.bounce ? parseFloat(properties.bounce) : undefined,\n\t\tbounceDamping: properties.bounceDamping\n\t\t\t? parseFloat(properties.bounceDamping)\n\t\t\t: undefined,\n\t\tbounceStiffness: properties.bounceStiffness\n\t\t\t? parseFloat(properties.bounceStiffness)\n\t\t\t: undefined,\n\t\tduration: properties.duration ? parseFloat(properties.duration) : undefined,\n\t\tdamping: properties.damping ? parseFloat(properties.damping) : undefined,\n\t\tdelay: properties.delay ? parseFloat(properties.delay) : undefined,\n\t\tease: (properties.ease ? properties.ease : undefined) as Easing,\n\t\telapsed: properties.elapsed ? parseFloat(properties.elapsed) : undefined,\n\t\tmass: properties.mass ? parseFloat(properties.mass) : undefined,\n\t\tmax: properties.max ? parseFloat(properties.max) : undefined,\n\t\tmin: properties.min ? parseFloat(properties.min) : undefined,\n\t\tpower: properties.power ? parseFloat(properties.power) : undefined,\n\t\trepeat: properties.repeat ? parseInt(properties.repeat) : undefined,\n\t\trepeatDelay: properties.repeatDelay\n\t\t\t? parseFloat(properties.repeatDelay)\n\t\t\t: undefined,\n\t\trepeatType: (properties.repeatType\n\t\t\t? properties.repeatType\n\t\t\t: undefined) as RepeatType,\n\t\trestDelta: properties.restDelta\n\t\t\t? parseFloat(properties.restDelta)\n\t\t\t: undefined,\n\t\trestSpeed: properties.restSpeed\n\t\t\t? parseFloat(properties.restSpeed)\n\t\t\t: undefined,\n\t\tstartTime: properties.startTime\n\t\t\t? parseFloat(properties.startTime)\n\t\t\t: undefined,\n\t\ttimeConstant: properties.timeConstant\n\t\t\t? parseFloat(properties.timeConstant)\n\t\t\t: undefined,\n\t\ttype: (properties.type\n\t\t\t? properties.type\n\t\t\t: undefined) as AnimationGeneratorType,\n\t\tvelocity: properties.velocity ? parseFloat(properties.velocity) : undefined,\n\t\tvisualDuration: properties.visualDuration\n\t\t\t? parseFloat(properties.visualDuration)\n\t\t\t: undefined,\n\t} satisfies Transition;\n}\n"],"mappings":";AAOA,SAAgB,oBAAoB,OAA4B;CAC/D,MAAM,aAAa;EAClB,QAAQ,MAAM,iBAAiB,kBAAkB;EACjD,eAAe,MAAM,iBAAiB,0BAA0B;EAChE,iBAAiB,MAAM,iBAAiB,4BAA4B;EACpE,UAAU,MAAM,iBAAiB,oBAAoB;EACrD,SAAS,MAAM,iBAAiB,mBAAmB;EACnD,OAAO,MAAM,iBAAiB,iBAAiB;EAC/C,MAAM,MAAM,iBAAiB,gBAAgB;EAC7C,SAAS,MAAM,iBAAiB,mBAAmB;EACnD,MAAM,MAAM,iBAAiB,gBAAgB;EAC7C,KAAK,MAAM,iBAAiB,eAAe;EAC3C,KAAK,MAAM,iBAAiB,eAAe;EAC3C,OAAO,MAAM,iBAAiB,iBAAiB;EAC/C,QAAQ,MAAM,iBAAiB,kBAAkB;EACjD,aAAa,MAAM,iBAAiB,wBAAwB;EAC5D,YAAY,MAAM,iBAAiB,uBAAuB;EAC1D,WAAW,MAAM,iBAAiB,sBAAsB;EACxD,WAAW,MAAM,iBAAiB,sBAAsB;EACxD,WAAW,MAAM,iBAAiB,sBAAsB;EACxD,cAAc,MAAM,iBAAiB,yBAAyB;EAC9D,OAAO,MAAM,iBAAiB,iBAAiB;EAC/C,MAAM,MAAM,iBAAiB,gBAAgB;EAC7C,UAAU,MAAM,iBAAiB,oBAAoB;EACrD,gBAAgB,MAAM,iBAAiB,2BAA2B;CACnE;CACA,OAAO;EACN,QAAQ,WAAW,SAAS,WAAW,WAAW,MAAM,IAAI,KAAA;EAC5D,eAAe,WAAW,gBACvB,WAAW,WAAW,aAAa,IACnC,KAAA;EACH,iBAAiB,WAAW,kBACzB,WAAW,WAAW,eAAe,IACrC,KAAA;EACH,UAAU,WAAW,WAAW,WAAW,WAAW,QAAQ,IAAI,KAAA;EAClE,SAAS,WAAW,UAAU,WAAW,WAAW,OAAO,IAAI,KAAA;EAC/D,OAAO,WAAW,QAAQ,WAAW,WAAW,KAAK,IAAI,KAAA;EACzD,MAAO,WAAW,OAAO,WAAW,OAAO,KAAA;EAC3C,SAAS,WAAW,UAAU,WAAW,WAAW,OAAO,IAAI,KAAA;EAC/D,MAAM,WAAW,OAAO,WAAW,WAAW,IAAI,IAAI,KAAA;EACtD,KAAK,WAAW,MAAM,WAAW,WAAW,GAAG,IAAI,KAAA;EACnD,KAAK,WAAW,MAAM,WAAW,WAAW,GAAG,IAAI,KAAA;EACnD,OAAO,WAAW,QAAQ,WAAW,WAAW,KAAK,IAAI,KAAA;EACzD,QAAQ,WAAW,SAAS,SAAS,WAAW,MAAM,IAAI,KAAA;EAC1D,aAAa,WAAW,cACrB,WAAW,WAAW,WAAW,IACjC,KAAA;EACH,YAAa,WAAW,aACrB,WAAW,aACX,KAAA;EACH,WAAW,WAAW,YACnB,WAAW,WAAW,SAAS,IAC/B,KAAA;EACH,WAAW,WAAW,YACnB,WAAW,WAAW,SAAS,IAC/B,KAAA;EACH,WAAW,WAAW,YACnB,WAAW,WAAW,SAAS,IAC/B,KAAA;EACH,cAAc,WAAW,eACtB,WAAW,WAAW,YAAY,IAClC,KAAA;EACH,MAAO,WAAW,OACf,WAAW,OACX,KAAA;EACH,UAAU,WAAW,WAAW,WAAW,WAAW,QAAQ,IAAI,KAAA;EAClE,gBAAgB,WAAW,iBACxB,WAAW,WAAW,cAAc,IACpC,KAAA;CACJ;AACD"}
|
|
@@ -2,8 +2,68 @@
|
|
|
2
2
|
|
|
3
3
|
import { AnimationGeneratorType, AnimationPlaybackControlsWithThen, Easing, RepeatType } from 'motion';
|
|
4
4
|
|
|
5
|
-
export declare function controlsToPromise(controls: AnimationPlaybackControlsWithThen): Promise<unknown>;
|
|
6
5
|
export declare function awaitAllAnimations(promises: AnimationPlaybackControlsWithThen[]): Promise<unknown>;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the visitor has asked their device to reduce motion. Read on every
|
|
8
|
+
* open and close, so changing the setting applies without a reload.
|
|
9
|
+
*/
|
|
10
|
+
export declare function shouldReduceMotion(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the direction this animation was started for has since been left.
|
|
13
|
+
*
|
|
14
|
+
* Toggling mid-animation re-runs the caller's effect, whose cleanup calls
|
|
15
|
+
* `animation.complete()` — which resolves the promise, so the `.then` below
|
|
16
|
+
* fires as a microtask *after* the new direction has already applied its
|
|
17
|
+
* styles, and would undo them. Callers flip their own flag in that cleanup;
|
|
18
|
+
* the default is for callers that never re-enter.
|
|
19
|
+
*/
|
|
20
|
+
export type IsStale = () => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the browser supports `hidden="until-found"`, which keeps a closed
|
|
23
|
+
* content's text reachable by find-in-page and text-fragment links.
|
|
24
|
+
*/
|
|
25
|
+
export declare function supportsHiddenUntilFound(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Puts the content in its open end state, without animating.
|
|
28
|
+
*
|
|
29
|
+
* `flow-root` rather than `block`, so the panel is always a block formatting
|
|
30
|
+
* context and always contains its children's margins.
|
|
31
|
+
*
|
|
32
|
+
* Without it the box model changed underneath the animation. The measurement
|
|
33
|
+
* runs before `overflow: hidden` is applied, so a child margin collapsed out
|
|
34
|
+
* of the panel and the target came back short; the animation then set
|
|
35
|
+
* `overflow: hidden`, which *makes* the panel a BFC, so the same content
|
|
36
|
+
* suddenly needed more room than the target allowed and stayed clipped — and
|
|
37
|
+
* snapped into place when `overflow` was removed at the end. A `<p>` with
|
|
38
|
+
* default margins inside a plain `<div>` measured 24px and rendered 56px.
|
|
39
|
+
*
|
|
40
|
+
* `flow-root` is the modern way to ask for a BFC without clipping, which is
|
|
41
|
+
* exactly what is wanted here: `overflow: hidden` during the animation now
|
|
42
|
+
* changes nothing about the box, only what is painted outside it.
|
|
43
|
+
*/
|
|
44
|
+
export declare function showContent(element: HTMLElement): void;
|
|
45
|
+
/**
|
|
46
|
+
* Puts the content in its closed end state, without animating.
|
|
47
|
+
*
|
|
48
|
+
* Where supported, the content is closed with `hidden="until-found"` rather
|
|
49
|
+
* than `display: none`, so find-in-page can still match its text. The inline
|
|
50
|
+
* styles zero the box, which `until-found` alone leaves its padding, and keep
|
|
51
|
+
* it a block: `until-found` hides content through `content-visibility`, which
|
|
52
|
+
* does not apply to an inline box, and custom elements are inline by default.
|
|
53
|
+
*/
|
|
54
|
+
export declare function hideContent(element: HTMLElement): void;
|
|
55
|
+
/**
|
|
56
|
+
* Calls `callback` when find-in-page or a text-fragment link matches text
|
|
57
|
+
* inside the closed content. It fires before the browser removes `hidden` and
|
|
58
|
+
* scrolls to the match, so layout changes made synchronously in `callback`
|
|
59
|
+
* are settled by the time the browser scrolls. Returns a cleanup function.
|
|
60
|
+
*/
|
|
61
|
+
export declare function onContentRevealed(element: HTMLElement, callback: () => void): () => void;
|
|
62
|
+
/** Animates the content open from zero height. */
|
|
63
|
+
export declare function expandContent(element: HTMLElement, isStale?: IsStale): import("motion").AnimationPlaybackControlsWithThen;
|
|
64
|
+
/** Animates the content closed to zero height. */
|
|
65
|
+
export declare function collapseContent(element: HTMLElement, isStale?: IsStale): import("motion").AnimationPlaybackControlsWithThen;
|
|
66
|
+
export declare function controlsToPromise(controls: AnimationPlaybackControlsWithThen): Promise<unknown>;
|
|
7
67
|
export declare function getTransitionConfig(style: CSSStyleDeclaration): {
|
|
8
68
|
bounce: number | undefined;
|
|
9
69
|
bounceDamping: number | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { awaitAllAnimations } from "./awaitAllAnimations.js";
|
|
2
|
+
import { collapseContent, expandContent, hideContent, onContentRevealed, shouldReduceMotion, showContent, supportsHiddenUntilFound } from "./content.js";
|
|
3
|
+
import { controlsToPromise } from "./controlsToPromise.js";
|
|
4
|
+
import { getTransitionConfig } from "./getTransitionConfig.js";
|
|
5
|
+
export { awaitAllAnimations, collapseContent, controlsToPromise, expandContent, getTransitionConfig, hideContent, onContentRevealed, shouldReduceMotion, showContent, supportsHiddenUntilFound };
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
import { FocusTrap, Options } from 'focus-trap';
|
|
4
4
|
import { Accessor } from 'solid-js';
|
|
5
5
|
|
|
6
|
-
export declare const createFocusTrap: (element: HTMLElement, options?: Accessor<Options>) =>
|
|
6
|
+
export declare const createFocusTrap: (element: HTMLElement, options?: Accessor<Options>) => import("solid-js").SourceAccessor<FocusTrap>;
|
|
7
7
|
|
|
8
8
|
export {};
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { createFocusTrap as createFocusTrap$1 } from
|
|
2
|
-
import { createMemo } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (!o.trapStack) {
|
|
10
|
-
o.trapStack = trapStack;
|
|
11
|
-
}
|
|
12
|
-
return createFocusTrap$1(element, o);
|
|
1
|
+
import { createFocusTrap as createFocusTrap$1 } from "focus-trap";
|
|
2
|
+
import { createMemo } from "solid-js";
|
|
3
|
+
//#region src/focusTrap/index.ts
|
|
4
|
+
var trapStack = [];
|
|
5
|
+
var createFocusTrap = (element, options) => createMemo(() => {
|
|
6
|
+
const o = options?.() || { trapStack };
|
|
7
|
+
if (!o.trapStack) o.trapStack = trapStack;
|
|
8
|
+
return createFocusTrap$1(element, o);
|
|
13
9
|
});
|
|
14
|
-
|
|
10
|
+
//#endregion
|
|
15
11
|
export { createFocusTrap };
|
|
16
|
-
|
|
12
|
+
|
|
17
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/focusTrap/index.ts"],"sourcesContent":["import {\n\tcreateFocusTrap as _createFocusTrap,\n\ttype FocusTrap,\n\ttype Options,\n} from \"focus-trap\";\nimport { type Accessor, createMemo } from \"solid-js\";\n\nconst trapStack: Array<FocusTrap> = [];\n\nexport const createFocusTrap = (\n\telement: HTMLElement,\n\toptions?: Accessor<Options>,\n) =>\n\tcreateMemo(() => {\n\t\tconst o = options?.() || {\n\t\t\ttrapStack,\n\t\t};\n\t\tif (!o.trapStack) {\n\t\t\to.trapStack = trapStack;\n\t\t}\n\t\treturn _createFocusTrap(element, o);\n\t});\n"],"mappings":";;;AAOA,IAAM,YAA8B,CAAC;AAErC,IAAa,mBACZ,SACA,YAEA,iBAAiB;CAChB,MAAM,IAAI,UAAU,KAAK,EACxB,UACD;CACA,IAAI,CAAC,EAAE,WACN,EAAE,YAAY;CAEf,OAAO,kBAAiB,SAAS,CAAC;AACnC,CAAC"}
|
|
@@ -3,15 +3,20 @@
|
|
|
3
3
|
import { ICustomElement, provide as _provide } from 'component-register';
|
|
4
4
|
import { Accessor } from 'solid-js';
|
|
5
5
|
|
|
6
|
-
export type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export type Format = "currency" | "number" | "boolean" | "invert_boolean" | string;
|
|
7
|
+
/**
|
|
8
|
+
* `component-register` types `options.element` as a bare `ICustomElement`, but
|
|
9
|
+
* at runtime it is always also an `HTMLElement`. Every component in this repo
|
|
10
|
+
* needs the DOM half.
|
|
11
|
+
*/
|
|
10
12
|
export type CorrectComponentOptions = {
|
|
11
13
|
element: HTMLElement & ICustomElement;
|
|
12
14
|
};
|
|
13
15
|
export type CorrectComponentType<T> = (props: T, options: CorrectComponentOptions) => unknown;
|
|
14
|
-
export type
|
|
16
|
+
export type Path<T> = T extends readonly (infer U)[] ? `${number}` | `${number}.${Path<U>}` : T extends object ? {
|
|
17
|
+
[K in keyof T & (string | number)]: T[K] extends object | any[] ? `${K}` | `${K}.${Path<T[K]>}` : `${K}`;
|
|
18
|
+
}[keyof T & (string | number)] : never;
|
|
19
|
+
export type PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? PathValue<T[Key], Rest> : Key extends `${number}` ? T extends readonly (infer U)[] ? PathValue<U, Rest> : undefined : undefined : P extends keyof T ? T[P] : P extends `${number}` ? T extends readonly (infer U)[] ? U : undefined : undefined;
|
|
15
20
|
export type WalkableNode = Parameters<typeof _provide>[2];
|
|
16
21
|
export declare const makeFullPropertyPathContext: <RootData = any>() => {
|
|
17
22
|
provide: ({ element, path, }: {
|
|
@@ -39,10 +44,6 @@ export type BaseOptions<RootData = any, Props = any> = {
|
|
|
39
44
|
name: string;
|
|
40
45
|
Component?: CorrectComponentType<Props>;
|
|
41
46
|
};
|
|
42
|
-
export declare const makePathDataComponent: <RootData = any, Props = any>({ useRootData, hooks, name, }: BaseOptions<RootData>) => CorrectComponentType<{
|
|
43
|
-
propertyName: Path<RootData>;
|
|
44
|
-
format?: Format;
|
|
45
|
-
} & Props>;
|
|
46
47
|
export declare const makePathDataArrayComponent: <RootData = any, Props = any>({ useRootData, hooks, name, arrayItemName, }: BaseOptions<RootData> & {
|
|
47
48
|
arrayItemName: string;
|
|
48
49
|
}) => CorrectComponentType<{
|
|
@@ -52,5 +53,9 @@ export declare const makePathDataArrayComponent: <RootData = any, Props = any>({
|
|
|
52
53
|
export declare const makePathDataArrayItemComponent: <RootData = any, Props extends {
|
|
53
54
|
itemIndex: Path<RootData>;
|
|
54
55
|
} = any>({ hooks, name, }: BaseOptions<RootData, Props>) => CorrectComponentType<Props>;
|
|
56
|
+
export declare const makePathDataComponent: <RootData = any, Props = any>({ useRootData, hooks, name, }: BaseOptions<RootData>) => CorrectComponentType<{
|
|
57
|
+
propertyName: Path<RootData>;
|
|
58
|
+
format?: Format;
|
|
59
|
+
} & Props>;
|
|
55
60
|
|
|
56
61
|
export {};
|
package/dist/main/hooks/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { makeFullPropertyPathContext } from "./makePathContextHooks.js";
|
|
2
|
+
import { makePathDataArrayComponent } from "./makePathDataArrayComponent.js";
|
|
3
|
+
import { makePathDataArrayItemComponent } from "./makePathDataArrayItemComponent.js";
|
|
4
|
+
import { makePathDataComponent } from "./makePathDataComponent.js";
|
|
5
|
+
export { makeFullPropertyPathContext, makePathDataArrayComponent, makePathDataArrayItemComponent, makePathDataComponent };
|