@brytdesigns/web-component-parallax 1.2.20 → 3.1.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/components/index.js +3 -8
- package/dist/main/components/parallax-animation/index.js +188 -199
- package/dist/main/components/parallax-animation/index.js.map +1 -1
- package/dist/main/components/parallax-container/index.js +11 -17
- package/dist/main/components/parallax-container/index.js.map +1 -1
- package/dist/main/components/parallax-sticky-layer/index.js +13 -24
- package/dist/main/components/parallax-sticky-layer/index.js.map +1 -1
- package/dist/main/hooks/index.js +3 -4
- package/dist/main/hooks/useParallax.js +59 -76
- package/dist/main/hooks/useParallax.js.map +1 -1
- package/dist/main/hooks/useParallaxStickyLayer.js +103 -116
- package/dist/main/hooks/useParallaxStickyLayer.js.map +1 -1
- package/dist/main/index.d.ts +27 -22
- package/dist/main/index.js +17 -24
- package/dist/main/index.js.map +1 -1
- package/dist/main/utils.js +11 -37
- package/dist/main/utils.js.map +1 -1
- package/package.json +8 -9
- package/dist/esm/index.js +0 -507
- package/dist/esm/index.js.map +0 -1
- package/dist/main/components/index.js.map +0 -1
- package/dist/main/hooks/index.js.map +0 -1
|
@@ -1,84 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { createContext, provide
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { createGuardedEffect, createRemoteContext, getContextFromProvider } from "@brytdesigns/web-component-core/utils";
|
|
2
|
+
import { motionValue, scroll } from "motion";
|
|
3
|
+
import { createStore, merge, omit, onCleanup } from "solid-js";
|
|
4
|
+
import { consume, createContext, provide } from "component-register";
|
|
5
|
+
//#region src/hooks/useParallax.ts
|
|
7
6
|
function initializeParallaxContext(props) {
|
|
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
|
-
scrollY.destroy();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
return mergeProps(_state, {
|
|
51
|
-
scrollYProgress,
|
|
52
|
-
scrollY,
|
|
53
|
-
info
|
|
54
|
-
});
|
|
7
|
+
const _state = omit(props, "root");
|
|
8
|
+
const scrollYProgress = motionValue(-1);
|
|
9
|
+
const scrollY = motionValue(-1);
|
|
10
|
+
const [info, setInfo] = createStore({
|
|
11
|
+
offset: [-1, -1],
|
|
12
|
+
scrollLength: -1
|
|
13
|
+
});
|
|
14
|
+
createGuardedEffect(() => _state.maxPages, (pages) => {
|
|
15
|
+
props.root.style.height = `${pages * 100}vh`;
|
|
16
|
+
props.root.style.width = `100%`;
|
|
17
|
+
props.root.style.position = "relative";
|
|
18
|
+
if (!props.root.style.display) props.root.style.display = "block";
|
|
19
|
+
const remove = scroll((_, info) => {
|
|
20
|
+
const { y } = info;
|
|
21
|
+
scrollYProgress.set(y.progress);
|
|
22
|
+
scrollY.set(y.current);
|
|
23
|
+
setInfo((draft) => {
|
|
24
|
+
draft.offset[0] = y.offset?.at(0) || 0;
|
|
25
|
+
draft.offset[1] = y.offset?.at(1) || 0;
|
|
26
|
+
draft.scrollLength = y.scrollLength;
|
|
27
|
+
});
|
|
28
|
+
}, {
|
|
29
|
+
target: props.root,
|
|
30
|
+
axis: "y",
|
|
31
|
+
offset: ["start start", "end end"]
|
|
32
|
+
});
|
|
33
|
+
return () => {
|
|
34
|
+
if (remove) remove();
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
onCleanup(() => {
|
|
38
|
+
scrollYProgress.destroy();
|
|
39
|
+
scrollY.destroy();
|
|
40
|
+
});
|
|
41
|
+
return merge(_state, {
|
|
42
|
+
scrollYProgress,
|
|
43
|
+
scrollY,
|
|
44
|
+
info
|
|
45
|
+
});
|
|
55
46
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
var ParallaxContextState = createContext(initializeParallaxContext);
|
|
48
|
+
var provideParallaxContext = (initialState, element) => {
|
|
49
|
+
const props = merge(initialState, { root: element });
|
|
50
|
+
return provide(ParallaxContextState, props, element);
|
|
60
51
|
};
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
var useParallaxContext = (context) => {
|
|
53
|
+
return context;
|
|
63
54
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"ParallaxContext not found! Please ensure to wrap your custom element with parallax-container element."
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
return useParallaxContext(context);
|
|
55
|
+
var useParallax = (element) => {
|
|
56
|
+
const context = consume(ParallaxContextState, element);
|
|
57
|
+
if (!context) throw new Error("ParallaxContext not found! Please ensure to wrap your custom element with parallax-container element.");
|
|
58
|
+
return useParallaxContext(context);
|
|
72
59
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
ParallaxContextState,
|
|
77
|
-
element
|
|
78
|
-
);
|
|
79
|
-
return useParallaxContext(context);
|
|
60
|
+
var useParallaxAt = createRemoteContext(ParallaxContextState);
|
|
61
|
+
var getParallaxContext = (element) => {
|
|
62
|
+
return useParallaxContext(getContextFromProvider(ParallaxContextState, element));
|
|
80
63
|
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { getParallaxContext, provideParallaxContext, useParallax, useParallaxAt, useParallaxContext };
|
|
81
66
|
|
|
82
|
-
export { getParallaxContext, provideParallaxContext, useParallax, useParallaxContext, withParallaxElementContext };
|
|
83
|
-
//# sourceMappingURL=useParallax.js.map
|
|
84
67
|
//# sourceMappingURL=useParallax.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"useParallax.js","names":[],"sources":["../../../src/hooks/useParallax.ts"],"sourcesContent":["import {\n\tcreateGuardedEffect,\n\tcreateRemoteContext,\n\tgetContextFromProvider,\n} from \"@brytdesigns/web-component-core/utils\";\nimport {\n\tconsume,\n\tcreateContext,\n\ttype ICustomElement,\n\tprovide,\n} from \"component-register\";\nimport { motionValue, scroll } from \"motion\";\nimport { createStore, merge, omit, onCleanup } from \"solid-js\";\n\ntype CreateContextOptions = {\n\troot: HTMLElement & ICustomElement;\n\tmaxPages: number;\n};\n\ntype WalkableNode = Parameters<typeof provide>[2];\n\ntype ParallaxContext = ReturnType<typeof initializeParallaxContext>;\n\nfunction initializeParallaxContext(props: CreateContextOptions) {\n\t// `omit` returns only the rest; `root` is read straight off `props`.\n\tconst _state = omit(props, \"root\");\n\n\tconst scrollYProgress = motionValue(-1);\n\tconst scrollY = motionValue(-1);\n\tconst [info, setInfo] = createStore({\n\t\toffset: [-1, -1],\n\t\tscrollLength: -1,\n\t});\n\n\tcreateGuardedEffect(\n\t\t() => _state.maxPages,\n\t\t(pages) => {\n\t\t\tprops.root.style.height = `${pages * 100}vh`;\n\t\t\tprops.root.style.width = `100%`;\n\t\t\tprops.root.style.position = \"relative\";\n\t\t\tif (!props.root.style.display) {\n\t\t\t\tprops.root.style.display = \"block\";\n\t\t\t}\n\n\t\t\tconst remove = scroll(\n\t\t\t\t(_, info) => {\n\t\t\t\t\tconst { y } = info;\n\n\t\t\t\t\tscrollYProgress.set(y.progress);\n\t\t\t\t\tscrollY.set(y.current);\n\t\t\t\t\t// No `batch` in v2 — writes stage and flush together by default.\n\t\t\t\t\t// v2 store setters are draft-first: mutate in place, no paths.\n\t\t\t\t\tsetInfo((draft) => {\n\t\t\t\t\t\tdraft.offset[0] = y.offset?.at(0) || 0;\n\t\t\t\t\t\tdraft.offset[1] = y.offset?.at(1) || 0;\n\t\t\t\t\t\tdraft.scrollLength = y.scrollLength;\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttarget: props.root,\n\t\t\t\t\taxis: \"y\",\n\t\t\t\t\toffset: [\"start start\", \"end end\"],\n\t\t\t\t},\n\t\t\t);\n\n\t\t\treturn () => {\n\t\t\t\tif (remove) {\n\t\t\t\t\tremove();\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t);\n\n\t// Context scope, not the effect's cleanup. These two are created here and\n\t// never recreated, but `destroy()` used to run every time `maxPages`\n\t// changed and the effect re-ran — and `destroy()` calls `clearListeners()`,\n\t// which drops every subscriber including each `parallax-sticky-layer`'s.\n\t// Layers happen to re-subscribe because their own effect also depends on\n\t// `maxPages`, so this worked by ordering rather than by design.\n\tonCleanup(() => {\n\t\tscrollYProgress.destroy();\n\t\tscrollY.destroy();\n\t});\n\n\treturn merge(_state, {\n\t\tscrollYProgress,\n\t\tscrollY,\n\t\tinfo,\n\t});\n}\n\nconst ParallaxContextState = createContext(initializeParallaxContext);\n\nexport const provideParallaxContext = (\n\tinitialState: Omit<CreateContextOptions, \"root\">,\n\telement: WalkableNode,\n): ParallaxContext => {\n\tconst props = merge(initialState, { root: element });\n\treturn provide(ParallaxContextState, props, element);\n};\n\nexport const useParallaxContext = (context: ParallaxContext) => {\n\treturn context;\n};\n\nexport const useParallax = (element: HTMLElement & ICustomElement) => {\n\tconst context: ParallaxContext = consume(ParallaxContextState, element);\n\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t\"ParallaxContext not found! Please ensure to wrap your custom element with parallax-container element.\",\n\t\t);\n\t}\n\n\treturn useParallaxContext(context);\n};\n\nexport const useParallaxAt =\n\tcreateRemoteContext<ParallaxContext>(ParallaxContextState);\n\nexport const getParallaxContext = (element: Element) => {\n\tconst context = getContextFromProvider<Parallax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sB,YAA6B;CAC/D,OAAO;AACR;AAEA,IAAa,eAAe,YAA0C;CACrE,MAAM,UAA2B,QAAQ,sBAAsB,OAAO;CAEtE,IAAI,CAAC,SACJ,MAAM,IAAI,MACT,uGACD;CAGD,OAAO,mBAAmB,OAAO;AAClC;AAEA,IAAa,gBACZ,oBAAqC,oBAAoB;AAE1D,IAAa,sBAAsB,YAAqB;CAKvD,OAAO,mBAJS,uBACf,sBACA,OAEyB,CAAO;AAClC"}
|
|
@@ -1,124 +1,111 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { awaitAllAnimations } from
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
1
|
+
import { useParallax } from "./useParallax.js";
|
|
2
|
+
import { isInRange, normalizeTuple } from "../utils.js";
|
|
3
|
+
import { createGuardedEffect, createRemoteContext, getContextFromProvider } from "@brytdesigns/web-component-core/utils";
|
|
4
|
+
import { awaitAllAnimations } from "@brytdesigns/web-component-core/animation";
|
|
5
|
+
import { animate, frame, motionValue, transform, transformValue } from "motion";
|
|
6
|
+
import { merge, omit, onCleanup } from "solid-js";
|
|
7
|
+
import { consume, createContext, provide } from "component-register";
|
|
8
|
+
import { abortablePromise } from "@brytdesigns/web-component-core/promise";
|
|
9
|
+
//#region src/hooks/useParallaxStickyLayer.ts
|
|
10
10
|
function initializeParallaxStickyLayerContext(props) {
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
11
|
+
omit(props, "root", "start", "end");
|
|
12
|
+
const parallax = useParallax(props.root);
|
|
13
|
+
const progress = motionValue(-1);
|
|
14
|
+
const inRange = motionValue(false);
|
|
15
|
+
const belowRange = motionValue(false);
|
|
16
|
+
const aboveRange = motionValue(false);
|
|
17
|
+
const position = transformValue(() => inRange.get() ? "sticky" : "absolute");
|
|
18
|
+
const transform$1 = transformValue(() => {
|
|
19
|
+
const isInRange = inRange.get();
|
|
20
|
+
const isBelowRange = belowRange.get();
|
|
21
|
+
const isAboveRange = aboveRange.get();
|
|
22
|
+
if (isInRange) return "none";
|
|
23
|
+
if (isBelowRange) return `translate(0px, ${(props.start - 1) * 100}vh)`;
|
|
24
|
+
if (isAboveRange) return `translate(0px, ${(props.end - 1) * 100}vh)`;
|
|
25
|
+
});
|
|
26
|
+
const animations = motionValue([]);
|
|
27
|
+
const styles = transformValue(() => ({
|
|
28
|
+
position: position.get(),
|
|
29
|
+
transform: transform$1.get()
|
|
30
|
+
}));
|
|
31
|
+
props.root.style.top = "0px";
|
|
32
|
+
props.root.style.right = "0px";
|
|
33
|
+
props.root.style.bottom = "0px";
|
|
34
|
+
props.root.style.left = "0px";
|
|
35
|
+
props.root.style.height = `100dvh`;
|
|
36
|
+
props.root.style.overflowX = "hidden";
|
|
37
|
+
props.root.style.maxWidth = "100%";
|
|
38
|
+
if (window.getComputedStyle(props.root).display === "inline") props.root.style.display = "block";
|
|
39
|
+
createGuardedEffect(() => ({
|
|
40
|
+
start: props.start,
|
|
41
|
+
end: props.end,
|
|
42
|
+
maxPages: parallax.maxPages
|
|
43
|
+
}), ({ start, end, maxPages }) => {
|
|
44
|
+
const normalizedRange = normalizeTuple([start, end], maxPages);
|
|
45
|
+
const [normStart, normEnd] = normalizedRange;
|
|
46
|
+
const transformer = transform(normalizedRange, [0, 1]);
|
|
47
|
+
const unsubscribe = parallax.scrollYProgress.on("change", (value) => {
|
|
48
|
+
inRange.set(isInRange({
|
|
49
|
+
range: normalizedRange,
|
|
50
|
+
value
|
|
51
|
+
}));
|
|
52
|
+
belowRange.set(value <= normStart);
|
|
53
|
+
aboveRange.set(value >= normEnd);
|
|
54
|
+
progress.set(transformer(value));
|
|
55
|
+
});
|
|
56
|
+
return () => {
|
|
57
|
+
unsubscribe();
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
function updateStyles() {
|
|
61
|
+
const s = styles.get();
|
|
62
|
+
props.root.style.position = s.position;
|
|
63
|
+
props.root.style.transform = s.transform;
|
|
64
|
+
}
|
|
65
|
+
function renderStyles() {
|
|
66
|
+
frame.render(updateStyles);
|
|
67
|
+
}
|
|
68
|
+
function waitForAnimations() {
|
|
69
|
+
const a = animations.get();
|
|
70
|
+
const controller = new AbortController();
|
|
71
|
+
abortablePromise(awaitAllAnimations(a), controller.signal).then(() => {
|
|
72
|
+
animations.set([]);
|
|
73
|
+
renderStyles();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const unsubStyles = styles.on("change", (_) => {
|
|
77
|
+
if (progress.get() === 1 || progress.get() === 0) return waitForAnimations();
|
|
78
|
+
animations.set([]);
|
|
79
|
+
renderStyles();
|
|
80
|
+
});
|
|
81
|
+
function _animate(...args) {
|
|
82
|
+
const animation = animate(...args);
|
|
83
|
+
animations.set([...animations.get(), animation]);
|
|
84
|
+
return animation;
|
|
85
|
+
}
|
|
86
|
+
onCleanup(() => {
|
|
87
|
+
unsubStyles();
|
|
88
|
+
});
|
|
89
|
+
return [progress, { animate: _animate }];
|
|
90
90
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const props = mergeProps(initialState, { root: element });
|
|
96
|
-
return provide(ParallaxStickyLayerContextState, props, element);
|
|
91
|
+
var ParallaxStickyLayerContextState = createContext(initializeParallaxStickyLayerContext);
|
|
92
|
+
var provideParallaxStickyLayerContext = (initialState, element) => {
|
|
93
|
+
const props = merge(initialState, { root: element });
|
|
94
|
+
return provide(ParallaxStickyLayerContextState, props, element);
|
|
97
95
|
};
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
var useParallaxStickyLayerContext = (context) => {
|
|
97
|
+
return context;
|
|
100
98
|
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
);
|
|
106
|
-
if (!context) {
|
|
107
|
-
throw console.error(
|
|
108
|
-
"ParallaxContext not found! Please ensure to wrap your custom element with parallax-container element."
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
return useParallaxStickyLayerContext(context);
|
|
99
|
+
var useParallaxStickyLayer = (element) => {
|
|
100
|
+
const context = consume(ParallaxStickyLayerContextState, element);
|
|
101
|
+
if (!context) throw new Error("ParallaxContext not found! Please ensure to wrap your custom element with parallax-container element.");
|
|
102
|
+
return useParallaxStickyLayerContext(context);
|
|
112
103
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
ParallaxStickyLayerContextState,
|
|
117
|
-
element
|
|
118
|
-
);
|
|
119
|
-
return useParallaxStickyLayerContext(context);
|
|
104
|
+
var useParallaxStickyLayerAt = createRemoteContext(ParallaxStickyLayerContextState);
|
|
105
|
+
var getParallaxStickyLayerContext = (element) => {
|
|
106
|
+
return useParallaxStickyLayerContext(getContextFromProvider(ParallaxStickyLayerContextState, element));
|
|
120
107
|
};
|
|
108
|
+
//#endregion
|
|
109
|
+
export { getParallaxStickyLayerContext, provideParallaxStickyLayerContext, useParallaxStickyLayer, useParallaxStickyLayerAt, useParallaxStickyLayerContext };
|
|
121
110
|
|
|
122
|
-
export { getParallaxStickyLayerContext, provideParallaxStickyLayerContext, useParallaxStickyLayer, useParallaxStickyLayerContext, withParallaxStickyLayerContext };
|
|
123
|
-
//# sourceMappingURL=useParallaxStickyLayer.js.map
|
|
124
111
|
//# sourceMappingURL=useParallaxStickyLayer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"useParallaxStickyLayer.js","names":[],"sources":["../../../src/hooks/useParallaxStickyLayer.ts"],"sourcesContent":["import { awaitAllAnimations } from \"@brytdesigns/web-component-core/animation\";\nimport { abortablePromise } from \"@brytdesigns/web-component-core/promise\";\nimport {\n\tcreateGuardedEffect,\n\tcreateRemoteContext,\n\tgetContextFromProvider,\n} from \"@brytdesigns/web-component-core/utils\";\nimport {\n\tconsume,\n\tcreateContext,\n\ttype ICustomElement,\n\tprovide,\n} from \"component-register\";\nimport {\n\ttype AnimationPlaybackControlsWithThen,\n\tanimate,\n\tframe,\n\tmotionValue,\n\ttransform as mTransform,\n\ttransformValue,\n} from \"motion\";\nimport { merge, omit, onCleanup } from \"solid-js\";\nimport { isInRange, normalizeTuple } from \"../utils\";\nimport { useParallax } from \"./useParallax\";\n\ntype CreateContextOptions = {\n\troot: HTMLElement & ICustomElement;\n\tstart: number;\n\tend: number;\n};\n\ntype WalkableNode = Parameters<typeof provide>[2];\n\ntype ParallaxStickyLayerContext = ReturnType<\n\ttypeof initializeParallaxStickyLayerContext\n>;\n\nfunction initializeParallaxStickyLayerContext(props: CreateContextOptions) {\n\t// `omit` returns only the rest; picked keys come straight off `props`.\n\tconst _state = omit(props, \"root\", \"start\", \"end\");\n\tconst parallax = useParallax(props.root);\n\n\tconst progress = motionValue(-1);\n\tconst inRange = motionValue(false);\n\tconst belowRange = motionValue(false);\n\tconst aboveRange = motionValue(false);\n\n\tconst position = transformValue(() =>\n\t\tinRange.get() ? \"sticky\" : \"absolute\",\n\t);\n\tconst transform = transformValue(() => {\n\t\tconst isInRange = inRange.get();\n\t\tconst isBelowRange = belowRange.get();\n\t\tconst isAboveRange = aboveRange.get();\n\t\tif (isInRange) return \"none\";\n\t\tif (isBelowRange) return `translate(0px, ${(props.start - 1) * 100}vh)`;\n\t\tif (isAboveRange) return `translate(0px, ${(props.end - 1) * 100}vh)`;\n\t});\n\tconst animations = motionValue<AnimationPlaybackControlsWithThen[]>([]);\n\n\tconst styles = transformValue(() => ({\n\t\tposition: position.get(),\n\t\ttransform: transform.get(),\n\t}));\n\n\tprops.root.style.top = \"0px\";\n\tprops.root.style.right = \"0px\";\n\tprops.root.style.bottom = \"0px\";\n\tprops.root.style.left = \"0px\";\n\tprops.root.style.height = `100dvh`;\n\tprops.root.style.overflowX = \"hidden\";\n\tprops.root.style.maxWidth = \"100%\";\n\tif (window.getComputedStyle(props.root).display === \"inline\") {\n\t\tprops.root.style.display = \"block\";\n\t}\n\n\tcreateGuardedEffect(\n\t\t() => ({ start: props.start, end: props.end, maxPages: parallax.maxPages }),\n\t\t({ start, end, maxPages }) => {\n\t\t\tconst range = [start, end];\n\t\t\tconst normalizedRange = normalizeTuple(range as any, maxPages);\n\t\t\tconst [normStart, normEnd] = normalizedRange;\n\t\t\tconst transformer = mTransform(normalizedRange as any, [0, 1]);\n\n\t\t\tconst unsubscribe = parallax.scrollYProgress.on(\"change\", (value) => {\n\t\t\t\tinRange.set(isInRange({ range: normalizedRange as any, value }));\n\t\t\t\tbelowRange.set(value <= normStart);\n\t\t\t\taboveRange.set(value >= normEnd);\n\t\t\t\tprogress.set(transformer(value));\n\t\t\t});\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t);\n\n\tfunction updateStyles() {\n\t\tconst s = styles.get();\n\t\tprops.root.style.position = s.position;\n\t\tprops.root.style.transform = s.transform;\n\t}\n\n\tfunction renderStyles() {\n\t\tframe.render(updateStyles);\n\t}\n\n\tfunction waitForAnimations() {\n\t\tconst a = animations.get();\n\t\tconst controller = new AbortController();\n\t\tabortablePromise(awaitAllAnimations(a), controller.signal).then(() => {\n\t\t\tanimations.set([]);\n\t\t\trenderStyles();\n\t\t});\n\t}\n\n\tconst unsubStyles = styles.on(\"change\", (_) => {\n\t\tif (progress.get() === 1 || progress.get() === 0)\n\t\t\treturn waitForAnimations();\n\t\tanimations.set([]);\n\t\trenderStyles();\n\t});\n\n\tfunction _animate(...args: Parameters<typeof animate>) {\n\t\tconst animation = animate(...args);\n\t\tanimations.set([...animations.get(), animation]);\n\t\treturn animation;\n\t}\n\n\tonCleanup(() => {\n\t\tunsubStyles();\n\t});\n\n\treturn [progress, { animate: _animate }] as const;\n}\n\nconst ParallaxStickyLayerContextState = createContext(\n\tinitializeParallaxStickyLayerContext,\n);\n\nexport const provideParallaxStickyLayerContext = (\n\tinitialState: Omit<CreateContextOptions, \"root\">,\n\telement: WalkableNode,\n): ParallaxStickyLayerContext => {\n\tconst props = merge(initialState, { root: element });\n\treturn provide(ParallaxStickyLayerContextState, props, element);\n};\n\nexport const useParallaxStickyLayerContext = (\n\tcontext: ParallaxStickyLayerContext,\n) => {\n\treturn context;\n};\n\nexport const useParallaxStickyLayer = (\n\telement: HTMLElement & ICustomElement,\n) => {\n\tconst context: ParallaxStickyLayerContext = consume(\n\t\tParallaxStickyLayerContextState,\n\t\telement,\n\t);\n\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t\"ParallaxContext not found! Please ensure to wrap your custom element with parallax-container element.\",\n\t\t);\n\t}\n\n\treturn useParallaxStickyLayerContext(context);\n};\n\nexport const useParallaxStickyLayerAt =\n\tcreateRemoteContext<ParallaxStickyLayerContext>(\n\t\tParallaxStickyLayerContextState,\n\t);\n\nexport const getParallaxStickyLayerContext = (element: Element) => {\n\tconst context = getContextFromProvider<ParallaxStickyLayerContext>(\n\t\tParallaxStickyLayerContextState,\n\t\telement,\n\t);\n\treturn useParallaxStickyLayerContext(context);\n};\n"],"mappings":";;;;;;;;;AAqCA,SAAS,qCAAqC,OAA6B;CAE3D,KAAK,OAAO,QAAQ,SAAS,KAAK;CACjD,MAAM,WAAW,YAAY,MAAM,IAAI;CAEvC,MAAM,WAAW,YAAY,EAAE;CAC/B,MAAM,UAAU,YAAY,KAAK;CACjC,MAAM,aAAa,YAAY,KAAK;CACpC,MAAM,aAAa,YAAY,KAAK;CAEpC,MAAM,WAAW,qBAChB,QAAQ,IAAI,IAAI,WAAW,UAC5B;CACA,MAAM,cAAY,qBAAqB;EACtC,MAAM,YAAY,QAAQ,IAAI;EAC9B,MAAM,eAAe,WAAW,IAAI;EACpC,MAAM,eAAe,WAAW,IAAI;EACpC,IAAI,WAAW,OAAO;EACtB,IAAI,cAAc,OAAO,mBAAmB,MAAM,QAAQ,KAAK,IAAI;EACnE,IAAI,cAAc,OAAO,mBAAmB,MAAM,MAAM,KAAK,IAAI;CAClE,CAAC;CACD,MAAM,aAAa,YAAiD,CAAC,CAAC;CAEtE,MAAM,SAAS,sBAAsB;EACpC,UAAU,SAAS,IAAI;EACvB,WAAW,YAAU,IAAI;CAC1B,EAAE;CAEF,MAAM,KAAK,MAAM,MAAM;CACvB,MAAM,KAAK,MAAM,QAAQ;CACzB,MAAM,KAAK,MAAM,SAAS;CAC1B,MAAM,KAAK,MAAM,OAAO;CACxB,MAAM,KAAK,MAAM,SAAS;CAC1B,MAAM,KAAK,MAAM,YAAY;CAC7B,MAAM,KAAK,MAAM,WAAW;CAC5B,IAAI,OAAO,iBAAiB,MAAM,IAAI,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AG,SAAS,CAAC;EAC/C,OAAO;CACR;CAEA,gBAAgB;EACf,YAAY;CACb,CAAC;CAED,OAAO,CAAC,UAAU,EAAE,SAAS,SAAS,CAAC;AACxC;AAEA,IAAM,kCAAkC,cACvC,oCACD;AAEA,IAAa,qCACZ,cACA,YACgC;CAChC,MAAM,QAAQ,MAAM,cAAc,EAAE,MAAM,QAAQ,CAAC;CACnD,OAAO,QAAQ,iCAAiC,OAAO,OAAO;AAC/D;AAEA,IAAa,iCACZ,YACI;CACJ,OAAO;AACR;AAEA,IAAa,0BACZ,YACI;CACJ,MAAM,UAAsC,QAC3C,iCACA,OACD;CAEA,IAAI,CAAC,SACJ,MAAM,IAAI,MACT,uGACD;CAGD,OAAO,8BAA8B,OAAO;AAC7C;AAEA,IAAa,2BACZ,oBACC,+BACD;AAED,IAAa,iCAAiC,YAAqB;CAKlE,OAAO,8BAJS,uBACf,iCACA,OAEoC,CAAO;AAC7C"}
|
package/dist/main/index.d.ts
CHANGED
|
@@ -3,23 +3,17 @@
|
|
|
3
3
|
import { ICustomElement } from 'component-register';
|
|
4
4
|
import { AnimationPlaybackControlsWithThen } from 'motion';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* `component-register` types `options.element` as a bare `ICustomElement`, but
|
|
8
|
+
* at runtime it is always also an `HTMLElement`. Every component in this repo
|
|
9
|
+
* needs the DOM half.
|
|
10
|
+
*/
|
|
6
11
|
export type CorrectComponentOptions = {
|
|
7
12
|
element: HTMLElement & ICustomElement;
|
|
8
13
|
};
|
|
9
14
|
export type CorrectComponentType<T> = (props: T, options: CorrectComponentOptions) => unknown;
|
|
10
|
-
export type Props = {
|
|
11
|
-
maxPages: number;
|
|
12
|
-
};
|
|
13
|
-
declare const Name = "parallax-container";
|
|
14
|
-
declare const Component: CorrectComponentType<Props>;
|
|
15
|
-
type Props$1 = {
|
|
16
|
-
start: number;
|
|
17
|
-
end: number;
|
|
18
|
-
};
|
|
19
|
-
declare const Name$1 = "parallax-sticky-layer";
|
|
20
|
-
declare const Component$1: CorrectComponentType<Props$1>;
|
|
21
15
|
export type AnimatableArray = Array<string | number> | null;
|
|
22
|
-
type Props
|
|
16
|
+
export type Props = {
|
|
23
17
|
breakpoints: string[];
|
|
24
18
|
range: number[] | number[][];
|
|
25
19
|
y: AnimatableArray | AnimatableArray[];
|
|
@@ -30,7 +24,7 @@ type Props$2 = {
|
|
|
30
24
|
backgroundColor: AnimatableArray | AnimatableArray[];
|
|
31
25
|
borderRadius: AnimatableArray | AnimatableArray[];
|
|
32
26
|
};
|
|
33
|
-
declare const Name
|
|
27
|
+
declare const Name = "parallax-animation";
|
|
34
28
|
declare const PROPS: {
|
|
35
29
|
breakpoints: string[];
|
|
36
30
|
range: number[];
|
|
@@ -43,6 +37,17 @@ declare const PROPS: {
|
|
|
43
37
|
backgroundColor: null;
|
|
44
38
|
borderRadius: null;
|
|
45
39
|
};
|
|
40
|
+
declare const Component: CorrectComponentType<Props>;
|
|
41
|
+
type Props$1 = {
|
|
42
|
+
maxPages: number;
|
|
43
|
+
};
|
|
44
|
+
declare const Name$1 = "parallax-container";
|
|
45
|
+
declare const Component$1: CorrectComponentType<Props$1>;
|
|
46
|
+
type Props$2 = {
|
|
47
|
+
start: number;
|
|
48
|
+
end: number;
|
|
49
|
+
};
|
|
50
|
+
declare const Name$2 = "parallax-sticky-layer";
|
|
46
51
|
declare const Component$2: CorrectComponentType<Props$2>;
|
|
47
52
|
export declare const useParallax: (element: HTMLElement & ICustomElement) => {
|
|
48
53
|
maxPages: number;
|
|
@@ -53,7 +58,7 @@ export declare const useParallax: (element: HTMLElement & ICustomElement) => {
|
|
|
53
58
|
scrollLength: number;
|
|
54
59
|
};
|
|
55
60
|
};
|
|
56
|
-
export declare const
|
|
61
|
+
export declare const useParallaxAt: (target: () => string | undefined, host: HTMLElement) => import("solid-js").SourceAccessor<{
|
|
57
62
|
maxPages: number;
|
|
58
63
|
scrollYProgress: import("motion").MotionValue<number>;
|
|
59
64
|
scrollY: import("motion").MotionValue<number>;
|
|
@@ -61,7 +66,7 @@ export declare const withParallaxElementContext: <D extends unknown>(target: str
|
|
|
61
66
|
offset: number[];
|
|
62
67
|
scrollLength: number;
|
|
63
68
|
};
|
|
64
|
-
}
|
|
69
|
+
}>;
|
|
65
70
|
export declare const getParallaxContext: (element: Element) => {
|
|
66
71
|
maxPages: number;
|
|
67
72
|
scrollYProgress: import("motion").MotionValue<number>;
|
|
@@ -77,24 +82,24 @@ export declare const useParallaxStickyLayer: (element: HTMLElement & ICustomElem
|
|
|
77
82
|
readonly animate: (object: {} | {}[], keyframes: import("motion").ObjectTarget<{}>, options?: import("motion").AnimationOptions | undefined) => AnimationPlaybackControlsWithThen;
|
|
78
83
|
}
|
|
79
84
|
];
|
|
80
|
-
export declare const
|
|
85
|
+
export declare const useParallaxStickyLayerAt: (target: () => string | undefined, host: HTMLElement) => import("solid-js").SourceAccessor<readonly [
|
|
81
86
|
import("motion").MotionValue<number>,
|
|
82
87
|
{
|
|
83
88
|
readonly animate: (object: {} | {}[], keyframes: import("motion").ObjectTarget<{}>, options?: import("motion").AnimationOptions | undefined) => AnimationPlaybackControlsWithThen;
|
|
84
89
|
}
|
|
85
|
-
]
|
|
90
|
+
]>;
|
|
86
91
|
export declare const getParallaxStickyLayerContext: (element: Element) => readonly [
|
|
87
92
|
import("motion").MotionValue<number>,
|
|
88
93
|
{
|
|
89
94
|
readonly animate: (object: {} | {}[], keyframes: import("motion").ObjectTarget<{}>, options?: import("motion").AnimationOptions | undefined) => AnimationPlaybackControlsWithThen;
|
|
90
95
|
}
|
|
91
96
|
];
|
|
92
|
-
export type ParallaxContainerProps = Props;
|
|
93
|
-
export type ParallaxStickyLayerProps = Props
|
|
94
|
-
export type ParallaxAnimationProps =
|
|
97
|
+
export type ParallaxContainerProps = Props$1;
|
|
98
|
+
export type ParallaxStickyLayerProps = ParallaxStickyLayer.Props;
|
|
99
|
+
export type ParallaxAnimationProps = Props;
|
|
95
100
|
|
|
96
|
-
declare namespace
|
|
97
|
-
export { Component$2 as Component, Name$2 as Name,
|
|
101
|
+
declare namespace ParallaxStickyLayer {
|
|
102
|
+
export { Component$2 as Component, Name$2 as Name, Props$2 as Props };
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
export {};
|
package/dist/main/index.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { getParallaxContext, useParallax, useParallaxAt } from "./hooks/useParallax.js";
|
|
2
|
+
import { getParallaxStickyLayerContext, useParallaxStickyLayer, useParallaxStickyLayerAt } from "./hooks/useParallaxStickyLayer.js";
|
|
3
|
+
import "./hooks/index.js";
|
|
4
|
+
import { Component, Name, PROPS } from "./components/parallax-animation/index.js";
|
|
5
|
+
import { Component as Component$1, Name as Name$1 } from "./components/parallax-container/index.js";
|
|
6
|
+
import { Component as Component$2, Name as Name$2 } from "./components/parallax-sticky-layer/index.js";
|
|
7
|
+
import "./components/index.js";
|
|
8
|
+
import { customShadowlessElement } from "@brytdesigns/web-component-core/utils";
|
|
9
|
+
//#region src/index.ts
|
|
10
|
+
customShadowlessElement(Name$1, { maxPages: 2 }, Component$1);
|
|
11
|
+
customShadowlessElement(Name$2, {
|
|
12
|
+
start: 1,
|
|
13
|
+
end: 2
|
|
14
|
+
}, Component$2);
|
|
15
|
+
customShadowlessElement(Name, PROPS, Component);
|
|
16
|
+
//#endregion
|
|
17
|
+
export { getParallaxContext, getParallaxStickyLayerContext, useParallax, useParallaxAt, useParallaxStickyLayer, useParallaxStickyLayerAt };
|
|
4
18
|
|
|
5
|
-
customShadowlessElement(
|
|
6
|
-
ParallaxContainer.Name,
|
|
7
|
-
{
|
|
8
|
-
maxPages: 2
|
|
9
|
-
},
|
|
10
|
-
correctElementType(ParallaxContainer.Component)
|
|
11
|
-
);
|
|
12
|
-
customShadowlessElement(
|
|
13
|
-
ParallaxStickyLayer.Name,
|
|
14
|
-
{
|
|
15
|
-
start: 1,
|
|
16
|
-
end: 2
|
|
17
|
-
},
|
|
18
|
-
correctElementType(ParallaxStickyLayer.Component)
|
|
19
|
-
);
|
|
20
|
-
customShadowlessElement(
|
|
21
|
-
ParallaxAnimation.Name,
|
|
22
|
-
ParallaxAnimation.PROPS,
|
|
23
|
-
correctElementType(ParallaxAnimation.Component)
|
|
24
|
-
);
|
|
25
|
-
//# sourceMappingURL=index.js.map
|
|
26
19
|
//# sourceMappingURL=index.js.map
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { customShadowlessElement } from \"@brytdesigns/web-component-core/utils\";\n\nimport {\n\tParallaxAnimation,\n\tParallaxContainer,\n\tParallaxStickyLayer,\n} from \"./components/index.js\";\n\nexport type ParallaxContainerProps = ParallaxContainer.Props;\nexport type ParallaxStickyLayerProps = ParallaxStickyLayer.Props;\nexport type ParallaxAnimationProps = ParallaxAnimation.Props;\n\ncustomShadowlessElement(\n\tParallaxContainer.Name,\n\t{\n\t\tmaxPages: 2,\n\t},\n\tParallaxContainer.Component,\n);\n\ncustomShadowlessElement(\n\tParallaxStickyLayer.Name,\n\t{\n\t\tstart: 1,\n\t\tend: 2,\n\t},\n\tParallaxStickyLayer.Component,\n);\n\ncustomShadowlessElement(\n\tParallaxAnimation.Name,\n\tParallaxAnimation.PROPS,\n\tParallaxAnimation.Component,\n);\n\nexport {\n\tgetParallaxContext,\n\tgetParallaxStickyLayerContext,\n\tuseParallax,\n\tuseParallaxAt,\n\tuseParallaxStickyLayer,\n\tuseParallaxStickyLayerAt,\n} from \"./hooks/index.js\";\n"],"mappings":";;;;;;;;;AAYA,wBACC,QACA,EACC,UAAU,EACX,GACA,WACD;AAEA,wBACC,QACA;CACC,OAAO;CACP,KAAK;AACN,GACA,WACD;AAEA,wBACC,MACA,OACA,SACD"}
|