@brytdesigns/web-component-parallax 1.2.19 → 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.
@@ -1,84 +1,67 @@
1
- import { splitProps, createEffect, batch, onCleanup, mergeProps } from 'solid-js';
2
- import { createStore } from 'solid-js/store';
3
- import { createWithElementContext, getContextFromProvider } from '@brytdesigns/web-component-core/utils';
4
- import { createContext, provide, consume } from 'component-register';
5
- import { motionValue, scroll } from 'motion';
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
- const [_internal, _state] = splitProps(props, ["root"]);
9
- const scrollYProgress = motionValue(-1);
10
- const scrollY = motionValue(-1);
11
- const [info, setInfo] = createStore({
12
- offset: [-1, -1],
13
- scrollLength: -1
14
- });
15
- window.addEventListener("resize", () => {
16
- });
17
- createEffect(() => {
18
- const pages = _state.maxPages;
19
- _internal.root.style.height = `${pages * 100}vh`;
20
- _internal.root.style.width = `100%`;
21
- _internal.root.style.position = "relative";
22
- if (!_internal.root.style.display) {
23
- _internal.root.style.display = "block";
24
- }
25
- const remove = scroll(
26
- (_, info2) => {
27
- const { y } = info2;
28
- scrollYProgress.set(y.progress);
29
- scrollY.set(y.current);
30
- batch(() => {
31
- setInfo("offset", 0, y.offset?.at(0) || 0);
32
- setInfo("offset", 1, y.offset?.at(1) || 0);
33
- setInfo("scrollLength", y.scrollLength);
34
- });
35
- },
36
- {
37
- target: _internal.root,
38
- axis: "y",
39
- offset: ["start start", "end end"]
40
- }
41
- );
42
- onCleanup(() => {
43
- if (remove) {
44
- remove();
45
- }
46
- scrollYProgress.destroy();
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
- const ParallaxContextState = createContext(initializeParallaxContext);
57
- const provideParallaxContext = (initialState, element) => {
58
- const props = mergeProps(initialState, { root: element });
59
- return provide(ParallaxContextState, props, element);
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
- const useParallaxContext = (context) => {
62
- return context;
52
+ var useParallaxContext = (context) => {
53
+ return context;
63
54
  };
64
- const useParallax = (element) => {
65
- const context = consume(ParallaxContextState, element);
66
- if (!context) {
67
- throw console.error(
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
- const withParallaxElementContext = createWithElementContext(ParallaxContextState);
74
- const getParallaxContext = (element) => {
75
- const context = getContextFromProvider(
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,"sources":["../../../src/hooks/useParallax.ts"],"names":["info"],"mappings":";;;;;;AA6BA,SAAS,0BAA0B,KAA6B,EAAA;AAC9D,EAAM,MAAA,CAAC,WAAW,MAAM,CAAA,GAAI,WAAW,KAAO,EAAA,CAAC,MAAM,CAAC,CAAA;AAEtD,EAAM,MAAA,eAAA,GAAkB,YAAY,EAAE,CAAA;AACtC,EAAM,MAAA,OAAA,GAAU,YAAY,EAAE,CAAA;AAC9B,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAI,WAAY,CAAA;AAAA,IAClC,MAAA,EAAQ,CAAC,EAAA,EAAI,EAAE,CAAA;AAAA,IACf,YAAc,EAAA;AAAA,GACf,CAAA;AAED,EAAO,MAAA,CAAA,gBAAA,CAAiB,UAAU,MAAM;AAAA,GAAE,CAAA;AAE1C,EAAA,YAAA,CAAa,MAAM;AACjB,IAAA,MAAM,QAAQ,MAAO,CAAA,QAAA;AAErB,IAAA,SAAA,CAAU,IAAK,CAAA,KAAA,CAAM,MAAS,GAAA,CAAA,EAAG,QAAQ,GAAG,CAAA,EAAA,CAAA;AAC5C,IAAU,SAAA,CAAA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;AACH;AAEA,MAAM,oBAAA,GAAuB,cAAc,yBAAyB,CAAA;AAEvD,MAAA,sBAAA,GAAyB,CACpC,YAAA,EACA,OACoB,KAAA;AACpB,EAAA,MAAM,QAAQ,UAAW,CAAA,YAAA,EAAc,EAAE,IAAA,EAAM,SAAS,CAAA;AACxD,EAAO,OAAA,OAAA,CAAQ,oBAAsB,EAAA,KAAA,EAAO,OAAO,CAAA;AACrD;AAEa,MAAA,kBAAA,GAAqB,CAAC,OAA6B,KAAA;AAC9D,EAAO,OAAA,OAAA;AACT;AAEa,MAAA,WAAA,GAAc,CAAC,OAA0C,KAAA;AACpE,EAAM,MAAA,OAAA,GAA2B,OAAQ,CAAA,oBAAA,EAAsB,OAAO,CAAA;AAEtE,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAA,MAAM,OAAQ,CAAA,KAAA;AAAA,MACZ;AAAA,KACF;AAAA;AAGF,EAAA,OAAO,mBAAmB,OAAO,CAAA;AACnC;AAEa,MAAA,0BAAA,GAA6B,yBAGxC,oBAAoB;AAET,MAAA,kBAAA,GAAqB,CAAC,OAAqB,KAAA;AACtD,EAAA,MAAM,OAAU,GAAA,sBAAA;AAAA,IACd,oBAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO,mBAAmB,OAAO,CAAA;AACnC","file":"useParallax.js","sourcesContent":["import {\n onCleanup,\n createEffect,\n splitProps,\n mergeProps,\n batch,\n} from \"solid-js\";\nimport { createStore } from \"solid-js/store\";\nimport {\n getContextFromProvider,\n createWithElementContext,\n} from \"@brytdesigns/web-component-core/utils\";\nimport {\n type ICustomElement,\n createContext,\n provide,\n consume,\n} from \"component-register\";\nimport { scroll, motionValue } from \"motion\";\n\ntype CreateContextOptions = {\n root: HTMLElement & ICustomElement;\n maxPages: number;\n};\n\ntype WalkableNode = Parameters<typeof provide>[2];\n\ntype ParallaxContext = ReturnType<typeof initializeParallaxContext>;\n\nfunction initializeParallaxContext(props: CreateContextOptions) {\n const [_internal, _state] = splitProps(props, [\"root\"]);\n\n const scrollYProgress = motionValue(-1);\n const scrollY = motionValue(-1);\n const [info, setInfo] = createStore({\n offset: [-1, -1],\n scrollLength: -1,\n });\n\n window.addEventListener(\"resize\", () => {});\n\n createEffect(() => {\n const pages = _state.maxPages;\n\n _internal.root.style.height = `${pages * 100}vh`;\n _internal.root.style.width = `100%`;\n _internal.root.style.position = \"relative\";\n if (!_internal.root.style.display) {\n _internal.root.style.display = \"block\";\n }\n\n const remove = scroll(\n (_, info) => {\n const { y } = info;\n\n scrollYProgress.set(y.progress);\n scrollY.set(y.current);\n batch(() => {\n setInfo(\"offset\", 0, y.offset?.at(0) || 0);\n setInfo(\"offset\", 1, y.offset?.at(1) || 0);\n setInfo(\"scrollLength\", y.scrollLength);\n });\n },\n {\n target: _internal.root,\n axis: \"y\",\n offset: [\"start start\", \"end end\"],\n },\n );\n\n onCleanup(() => {\n if (remove) {\n remove();\n }\n scrollYProgress.destroy();\n scrollY.destroy();\n });\n });\n\n return mergeProps(_state, {\n scrollYProgress,\n scrollY,\n info,\n });\n}\n\nconst ParallaxContextState = createContext(initializeParallaxContext);\n\nexport const provideParallaxContext = (\n initialState: Omit<CreateContextOptions, \"root\">,\n element: WalkableNode,\n): ParallaxContext => {\n const props = mergeProps(initialState, { root: element });\n return provide(ParallaxContextState, props, element);\n};\n\nexport const useParallaxContext = (context: ParallaxContext) => {\n return context;\n};\n\nexport const useParallax = (element: HTMLElement & ICustomElement) => {\n const context: ParallaxContext = consume(ParallaxContextState, element);\n\n if (!context) {\n throw console.error(\n \"ParallaxContext not found! Please ensure to wrap your custom element with parallax-container element.\",\n );\n }\n\n return useParallaxContext(context);\n};\n\nexport const withParallaxElementContext = createWithElementContext<\n typeof ParallaxContextState,\n ParallaxContext\n>(ParallaxContextState);\n\nexport const getParallaxContext = (element: Element) => {\n const context = getContextFromProvider<ParallaxContext>(\n ParallaxContextState,\n element,\n );\n return useParallaxContext(context);\n};\n"]}
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<ParallaxContext>(\n\t\tParallaxContextState,\n\t\telement,\n\t);\n\treturn useParallaxContext(context);\n};\n"],"mappings":";;;;;AAuBA,SAAS,0BAA0B,OAA6B;CAE/D,MAAM,SAAS,KAAK,OAAO,MAAM;CAEjC,MAAM,kBAAkB,YAAY,EAAE;CACtC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IAAa,gBACZ,oBAAqC,oBAAoB;AAE1D,IAAa,sBAAsB,YAAqB;CAKvD,OAAO,mBAJS,uBACf,sBACA,OAEyB,CAAO;AAClC"}
@@ -1,124 +1,111 @@
1
- import { splitProps, createEffect, onCleanup, mergeProps } from 'solid-js';
2
- import { createContext, provide, consume } from 'component-register';
3
- import { motionValue, transformValue, transform, frame, animate } from 'motion';
4
- import { awaitAllAnimations } from '@brytdesigns/web-component-core/animation';
5
- import { abortablePromise } from '@brytdesigns/web-component-core/promise';
6
- import { createWithElementContext, getContextFromProvider } from '@brytdesigns/web-component-core/utils';
7
- import { useParallax } from './useParallax';
8
- import { normalizeTuple, isInRange } from '../utils';
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
- const [_internal, _state] = splitProps(props, ["root", "start", "end"]);
12
- const parallax = useParallax(_internal.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(
18
- () => inRange.get() ? "sticky" : "absolute"
19
- );
20
- const transform$1 = transformValue(() => {
21
- const isInRange2 = inRange.get();
22
- const isBelowRange = belowRange.get();
23
- const isAboveRange = aboveRange.get();
24
- if (isInRange2) return "none";
25
- if (isBelowRange) return `translate(0px, ${(_internal.start - 1) * 100}vh)`;
26
- if (isAboveRange) return `translate(0px, ${(_internal.end - 1) * 100}vh)`;
27
- });
28
- const animations = motionValue([]);
29
- const styles = transformValue(() => ({
30
- position: position.get(),
31
- transform: transform$1.get()
32
- }));
33
- _internal.root.style.top = "0px";
34
- _internal.root.style.right = "0px";
35
- _internal.root.style.bottom = "0px";
36
- _internal.root.style.left = "0px";
37
- _internal.root.style.height = `100dvh`;
38
- _internal.root.style.overflowX = "hidden";
39
- _internal.root.style.maxWidth = "100%";
40
- if (window.getComputedStyle(_internal.root).display === "inline") {
41
- _internal.root.style.display = "block";
42
- }
43
- createEffect(() => {
44
- const range = [_internal.start, _internal.end];
45
- const maxPages = parallax.maxPages;
46
- const normalizedRange = normalizeTuple(range, maxPages);
47
- const [normStart, normEnd] = normalizedRange;
48
- const transformer = transform(normalizedRange, [0, 1]);
49
- const unsubscribe = parallax.scrollYProgress.on("change", (value) => {
50
- inRange.set(isInRange({ range: normalizedRange, value }));
51
- belowRange.set(value <= normStart);
52
- aboveRange.set(value >= normEnd);
53
- progress.set(transformer(value));
54
- });
55
- return onCleanup(() => {
56
- unsubscribe();
57
- });
58
- });
59
- function updateStyles() {
60
- const s = styles.get();
61
- _internal.root.style.position = s.position;
62
- _internal.root.style.transform = s.transform;
63
- }
64
- function renderStyles() {
65
- frame.render(updateStyles);
66
- }
67
- function waitForAnimations() {
68
- const a = animations.get();
69
- const controller = new AbortController();
70
- abortablePromise(awaitAllAnimations(a), controller.signal).then(() => {
71
- animations.set([]);
72
- renderStyles();
73
- });
74
- }
75
- const unsubStyles = styles.on("change", (_) => {
76
- if (progress.get() === 1 || progress.get() === 0)
77
- 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 }];
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
- const ParallaxStickyLayerContextState = createContext(
92
- initializeParallaxStickyLayerContext
93
- );
94
- const provideParallaxStickyLayerContext = (initialState, element) => {
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
- const useParallaxStickyLayerContext = (context) => {
99
- return context;
96
+ var useParallaxStickyLayerContext = (context) => {
97
+ return context;
100
98
  };
101
- const useParallaxStickyLayer = (element) => {
102
- const context = consume(
103
- ParallaxStickyLayerContextState,
104
- element
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
- const withParallaxStickyLayerContext = createWithElementContext(ParallaxStickyLayerContextState);
114
- const getParallaxStickyLayerContext = (element) => {
115
- const context = getContextFromProvider(
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,"sources":["../../../src/hooks/useParallaxStickyLayer.ts"],"names":["transform","isInRange","mTransform"],"mappings":";;;;;;;;;AAqCA,SAAS,qCAAqC,KAA6B,EAAA;AAC1E,EAAM,MAAA,CAAC,SAAW,EAAA,MAAM,CAAI,GAAA,UAAA,CAAW,OAAO,CAAC,MAAA,EAAQ,OAAS,EAAA,KAAK,CAAC,CAAA;AACtE,EAAM,MAAA,QAAA,GAAW,WAAY,CAAA,SAAA,CAAU,IAAI,CAAA;AAE3C,EAAM,MAAA,QAAA,GAAW,YAAY,EAAE,CAAA;AAC/B,EAAM,MAAA,OAAA,GAAU,YAAY,KAAK,CAAA;AACjC,EAAM,MAAA,UAAA,GAAa,YAAY,KAAK,CAAA;AACpC,EAAM,MAAA,UAAA,GAAa,YAAY,KAAK,CAAA;AAEpC,EAAA,MAAM,QAAW,GAAA,cAAA;AAAA,IAAe,MAC/B,OAAA,CAAQ,GAAI,EAAA,GAAI,QAAW,GAAA;AAAA,GAC5B;AACA,EAAM,MAAAA,WAAA,GAAY,eAAe,MAAM;AACtC,IAAMC,MAAAA,UAAAA,GAAY,QAAQ,GAAI,EAAA;AAC9B,IAAM,MAAA,YAAA,GAAe,WAAW,GAAI,EAAA;AACpC,IAAM,MAAA,YAAA,GAAe,WAAW,GAAI,EAAA;AACpC,IAAA,IAAIA,YAAkB,OAAA,MAAA;AACtB,IAAA,IAAI,cAAqB,OAAA,CAAA,eAAA,EAAA,CAAmB,SAAU,CAAA,KAAA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AAEa,MAAA,8BAAA,GAAiC,yBAG5C,+BAA+B;AAEpB,MAAA,6BAAA,GAAgC,CAAC,OAAqB,KAAA;AAClE,EAAA,MAAM,OAAU,GAAA,sBAAA;AAAA,IACf,+BAAA;AAAA,IACA;AAAA,GACD;AACA,EAAA,OAAO,8BAA8B,OAAO,CAAA;AAC7C","file":"useParallaxStickyLayer.js","sourcesContent":["import { onCleanup, createEffect, splitProps, mergeProps } from \"solid-js\";\nimport {\n\ttype ICustomElement,\n\tcreateContext,\n\tprovide,\n\tconsume,\n} from \"component-register\";\nimport {\n\tmotionValue,\n\ttransformValue,\n\ttransform as mTransform,\n\tframe,\n\tanimate,\n\ttype AnimationPlaybackControlsWithThen,\n} from \"motion\";\nimport { awaitAllAnimations } from \"@brytdesigns/web-component-core/animation\";\nimport { abortablePromise } from \"@brytdesigns/web-component-core/promise\";\nimport {\n\tgetContextFromProvider,\n\tcreateWithElementContext,\n} from \"@brytdesigns/web-component-core/utils\";\n\nimport { useParallax } from \"./useParallax\";\nimport { normalizeTuple, isInRange } from \"../utils\";\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\tconst [_internal, _state] = splitProps(props, [\"root\", \"start\", \"end\"]);\n\tconst parallax = useParallax(_internal.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, ${(_internal.start - 1) * 100}vh)`;\n\t\tif (isAboveRange) return `translate(0px, ${(_internal.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\t_internal.root.style.top = \"0px\";\n\t_internal.root.style.right = \"0px\";\n\t_internal.root.style.bottom = \"0px\";\n\t_internal.root.style.left = \"0px\";\n\t_internal.root.style.height = `100dvh`;\n\t_internal.root.style.overflowX = \"hidden\";\n\t_internal.root.style.maxWidth = \"100%\";\n\tif (window.getComputedStyle(_internal.root).display === \"inline\") {\n\t\t_internal.root.style.display = \"block\";\n\t}\n\n\tcreateEffect(() => {\n\t\tconst range = [_internal.start, _internal.end];\n\t\tconst maxPages = parallax.maxPages;\n\t\tconst normalizedRange = normalizeTuple(range as any, maxPages);\n\t\tconst [normStart, normEnd] = normalizedRange;\n\t\tconst transformer = mTransform(normalizedRange as any, [0, 1]);\n\n\t\tconst unsubscribe = parallax.scrollYProgress.on(\"change\", (value) => {\n\t\t\tinRange.set(isInRange({ range: normalizedRange as any, value }));\n\t\t\tbelowRange.set(value <= normStart);\n\t\t\taboveRange.set(value >= normEnd);\n\t\t\tprogress.set(transformer(value));\n\t\t});\n\n\t\treturn onCleanup(() => {\n\t\t\tunsubscribe();\n\t\t});\n\t});\n\n\tfunction updateStyles() {\n\t\tconst s = styles.get();\n\t\t_internal.root.style.position = s.position;\n\t\t_internal.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 = mergeProps(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 console.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 withParallaxStickyLayerContext = createWithElementContext<\n\ttypeof ParallaxStickyLayerContextState,\n\tParallaxStickyLayerContext\n>(ParallaxStickyLayerContextState);\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"]}
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,IAA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AAW,IAAI;EACzB,MAAM,aAAa,IAAI,gBAAgB;EACvC,iBAAiB,mBAAmB,CAAC,GAAG,WAAW,MAAM,CAAC,CAAC,WAAW;GACrE,WAAW,IAAI,CAAC,CAAC;GACjB,aAAa;EACd,CAAC;CACF;CAEA,MAAM,cAAc,OAAO,GAAG,WAAW,MAAM;EAC9C,IAAI,SAAS,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,GAC9C,OAAO,kBAAkB;EAC1B,WAAW,IAAI,CAAC,CAAC;EACjB,aAAa;CACd,CAAC;CAED,SAAS,SAAS,GAAG,MAAkC;EACtD,MAAM,YAAY,QAAQ,GAAG,IAAI;EACjC,WAAW,IAAI,CAAC,GAAG,WAAW,IAAI,GAAG,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"}
@@ -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$2 = {
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$2 = "parallax-animation";
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 withParallaxElementContext: <D extends unknown>(target: string | import("solid-js").Accessor<string> | import("solid-js").Accessor<() => Element>, dependencies: import("solid-js").Accessor<D> | undefined, cb: (context: {
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
- }, dependencies: D) => void | (() => void)) => void;
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 withParallaxStickyLayerContext: <D extends unknown>(target: string | import("solid-js").Accessor<string> | import("solid-js").Accessor<() => Element>, dependencies: import("solid-js").Accessor<D> | undefined, cb: (context: readonly [
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
- ], dependencies: D) => void | (() => void)) => void;
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$1;
94
- export type ParallaxAnimationProps = ParallaxAnimation.Props;
97
+ export type ParallaxContainerProps = Props$1;
98
+ export type ParallaxStickyLayerProps = ParallaxStickyLayer.Props;
99
+ export type ParallaxAnimationProps = Props;
95
100
 
96
- declare namespace ParallaxAnimation {
97
- export { Component$2 as Component, Name$2 as Name, PROPS, Props$2 as Props };
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 {};
@@ -1,26 +1,19 @@
1
- import { customShadowlessElement, correctElementType } from '@brytdesigns/web-component-core/utils';
2
- import { ParallaxContainer, ParallaxStickyLayer, ParallaxAnimation } from './components/index.js';
3
- export { getParallaxContext, getParallaxStickyLayerContext, useParallax, useParallaxStickyLayer, withParallaxElementContext, withParallaxStickyLayerContext } from './hooks/index.js';
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAeA,uBAAA;AAAA,EACE,iBAAkB,CAAA,IAAA;AAAA,EAClB;AAAA,IACE,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,kBAAA,CAAmB,kBAAkB,SAAS;AAChD,CAAA;AAEA,uBAAA;AAAA,EACE,mBAAoB,CAAA,IAAA;AAAA,EACpB;AAAA,IACE,KAAO,EAAA,CAAA;AAAA,IACP,GAAK,EAAA;AAAA,GACP;AAAA,EACA,kBAAA,CAAmB,oBAAoB,SAAS;AAClD,CAAA;AAEA,uBAAA;AAAA,EACE,iBAAkB,CAAA,IAAA;AAAA,EAClB,iBAAkB,CAAA,KAAA;AAAA,EAClB,kBAAA,CAAmB,kBAAkB,SAAS;AAChD,CAAA","file":"index.js","sourcesContent":["import {\n customShadowlessElement,\n correctElementType,\n} from \"@brytdesigns/web-component-core/utils\";\n\nimport {\n ParallaxContainer,\n ParallaxStickyLayer,\n ParallaxAnimation,\n} from \"./components/index.js\";\n\nexport type ParallaxContainerProps = ParallaxContainer.Props;\nexport type ParallaxStickyLayerProps = ParallaxStickyLayer.Props;\nexport type ParallaxAnimationProps = ParallaxAnimation.Props;\n\ncustomShadowlessElement(\n ParallaxContainer.Name,\n {\n maxPages: 2,\n },\n correctElementType(ParallaxContainer.Component),\n);\n\ncustomShadowlessElement(\n ParallaxStickyLayer.Name,\n {\n start: 1,\n end: 2,\n },\n correctElementType(ParallaxStickyLayer.Component),\n);\n\ncustomShadowlessElement(\n ParallaxAnimation.Name,\n ParallaxAnimation.PROPS,\n correctElementType(ParallaxAnimation.Component),\n);\n\nexport {\n useParallax,\n getParallaxContext,\n useParallaxStickyLayer,\n getParallaxStickyLayerContext,\n withParallaxElementContext,\n withParallaxStickyLayerContext,\n} from \"./hooks/index.js\";\n"]}
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"}