@brytdesigns/web-component-parallax 1.2.20 → 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,46 +1,20 @@
1
+ //#region src/utils.ts
1
2
  function normalizeTuple(range, max) {
2
- if (max <= 1) {
3
- throw new Error("The maximum value must be greater than 1.");
4
- }
5
- const [start, end] = range;
6
- const normalizedStart = (start - 1) / (max - 1);
7
- const normalizedEnd = (end - 1) / (max - 1);
8
- return [normalizedStart, normalizedEnd];
3
+ if (max <= 1) throw new Error("The maximum value must be greater than 1.");
4
+ const [start, end] = range;
5
+ return [(start - 1) / (max - 1), (end - 1) / (max - 1)];
9
6
  }
10
- function isInRange({
11
- range: [start, end],
12
- value
13
- }) {
14
- return start <= value && end >= value;
15
- }
16
- function getLastMatchingMediaQueryIndex(queries) {
17
- let lastMatchIndex = -1;
18
- for (let i = 0; i < queries.length; i++) {
19
- const query = queries[i];
20
- if (typeof query !== "string") continue;
21
- if (window.matchMedia(query).matches) {
22
- lastMatchIndex = i;
23
- }
24
- }
25
- return lastMatchIndex;
7
+ function isInRange({ range: [start, end], value }) {
8
+ return start <= value && end >= value;
26
9
  }
27
10
  function getActiveBreakpoints(queries) {
28
- return queries.map((query) => window.matchMedia(query).matches);
11
+ return queries.map((query) => window.matchMedia(query).matches);
29
12
  }
30
13
  function getLastTruthyIndex(values) {
31
- for (let i = values.length - 1; i >= 0; i--) {
32
- if (values[i]) return i;
33
- }
34
- return -1;
35
- }
36
- function getLastValidValue(arr, index) {
37
- if (arr[index] != null) return arr[index];
38
- for (let i = index - 1; i >= 0; i--) {
39
- if (arr[i] != null) return arr[i];
40
- }
41
- return null;
14
+ for (let i = values.length - 1; i >= 0; i--) if (values[i]) return i;
15
+ return -1;
42
16
  }
17
+ //#endregion
18
+ export { getActiveBreakpoints, getLastTruthyIndex, isInRange, normalizeTuple };
43
19
 
44
- export { getActiveBreakpoints, getLastMatchingMediaQueryIndex, getLastTruthyIndex, getLastValidValue, isInRange, normalizeTuple };
45
- //# sourceMappingURL=utils.js.map
46
20
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils.ts"],"names":[],"mappings":"AAAO,SAAS,cAAA,CAAe,OAAyB,GAAa,EAAA;AACnE,EAAA,IAAI,OAAO,CAAG,EAAA;AACZ,IAAM,MAAA,IAAI,MAAM,2CAA2C,CAAA;AAAA;AAG7D,EAAM,MAAA,CAAC,KAAO,EAAA,GAAG,CAAI,GAAA,KAAA;AACrB,EAAM,MAAA,eAAA,GAAA,CAAmB,KAAQ,GAAA,CAAA,KAAM,GAAM,GAAA,CAAA,CAAA;AAC7C,EAAM,MAAA,aAAA,GAAA,CAAiB,GAAM,GAAA,CAAA,KAAM,GAAM,GAAA,CAAA,CAAA;AAEzC,EAAO,OAAA,CAAC,iBAAiB,aAAa,CAAA;AACxC;AAEO,SAAS,SAAU,CAAA;AAAA,EACxB,KAAA,EAAO,CAAC,KAAA,EAAO,GAAG,CAAA;AAAA,EAClB;AACF,CAGG,EAAA;AACD,EAAO,OAAA,KAAA,IAAS,SAAS,GAAO,IAAA,KAAA;AAClC;AAEO,SAAS,+BAA+B,OAA2B,EAAA;AACxE,EAAA,IAAI,cAAiB,GAAA,EAAA;AAErB,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,OAAA,CAAQ,QAAQ,CAAK,EAAA,EAAA;AACvC,IAAM,MAAA,KAAA,GAAQ,QAAQ,CAAC,CAAA;AACvB,IAAI,IAAA,OAAO,UAAU,QAAU,EAAA;AAC/B,IAAA,IAAI,MAAO,CAAA,UAAA,CAAW,KAAK,CAAA,CAAE,OAAS,EAAA;AACpC,MAAiB,cAAA,GAAA,CAAA;AAAA;AACnB;AAGF,EAAO,OAAA,cAAA;AACT;AAEO,SAAS,qBAAqB,OAA8B,EAAA;AACjE,EAAO,OAAA,OAAA,CAAQ,IAAI,CAAC,KAAA,KAAU,OAAO,UAAW,CAAA,KAAK,EAAE,OAAO,CAAA;AAChE;AAEO,SAAS,mBAAmB,MAA2B,EAAA;AAC5D,EAAA,KAAA,IAAS,IAAI,MAAO,CAAA,MAAA,GAAS,CAAG,EAAA,CAAA,IAAK,GAAG,CAAK,EAAA,EAAA;AAC3C,IAAI,IAAA,MAAA,CAAO,CAAC,CAAA,EAAU,OAAA,CAAA;AAAA;AAExB,EAAO,OAAA,EAAA;AACT;AACO,SAAS,iBAAA,CACd,KACA,KACU,EAAA;AACV,EAAA,IAAI,IAAI,KAAK,CAAA,IAAK,IAAM,EAAA,OAAO,IAAI,KAAK,CAAA;AAExC,EAAA,KAAA,IAAS,CAAI,GAAA,KAAA,GAAQ,CAAG,EAAA,CAAA,IAAK,GAAG,CAAK,EAAA,EAAA;AACnC,IAAA,IAAI,IAAI,CAAC,CAAA,IAAK,IAAM,EAAA,OAAO,IAAI,CAAC,CAAA;AAAA;AAGlC,EAAO,OAAA,IAAA;AACT","file":"utils.js","sourcesContent":["export function normalizeTuple(range: [number, number], max: number) {\n if (max <= 1) {\n throw new Error(\"The maximum value must be greater than 1.\");\n }\n\n const [start, end] = range;\n const normalizedStart = (start - 1) / (max - 1);\n const normalizedEnd = (end - 1) / (max - 1);\n\n return [normalizedStart, normalizedEnd] as const;\n}\n\nexport function isInRange({\n range: [start, end],\n value,\n}: {\n range: [number, number];\n value: number;\n}) {\n return start <= value && end >= value;\n}\n\nexport function getLastMatchingMediaQueryIndex(queries: string[]): number {\n let lastMatchIndex = -1;\n\n for (let i = 0; i < queries.length; i++) {\n const query = queries[i];\n if (typeof query !== \"string\") continue;\n if (window.matchMedia(query).matches) {\n lastMatchIndex = i;\n }\n }\n\n return lastMatchIndex;\n}\n\nexport function getActiveBreakpoints(queries: string[]): boolean[] {\n return queries.map((query) => window.matchMedia(query).matches);\n}\n\nexport function getLastTruthyIndex(values: boolean[]): number {\n for (let i = values.length - 1; i >= 0; i--) {\n if (values[i]) return i;\n }\n return -1;\n}\nexport function getLastValidValue<T>(\n arr: (T | null)[],\n index: number,\n): T | null {\n if (arr[index] != null) return arr[index]!;\n\n for (let i = index - 1; i >= 0; i--) {\n if (arr[i] != null) return arr[i]!;\n }\n\n return null;\n}\n"]}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["export function normalizeTuple(range: [number, number], max: number) {\n\tif (max <= 1) {\n\t\tthrow new Error(\"The maximum value must be greater than 1.\");\n\t}\n\n\tconst [start, end] = range;\n\tconst normalizedStart = (start - 1) / (max - 1);\n\tconst normalizedEnd = (end - 1) / (max - 1);\n\n\treturn [normalizedStart, normalizedEnd] as const;\n}\n\nexport function isInRange({\n\trange: [start, end],\n\tvalue,\n}: {\n\trange: [number, number];\n\tvalue: number;\n}) {\n\treturn start <= value && end >= value;\n}\n\nexport function getLastMatchingMediaQueryIndex(queries: string[]): number {\n\tlet lastMatchIndex = -1;\n\n\tfor (let i = 0; i < queries.length; i++) {\n\t\tconst query = queries[i];\n\t\tif (typeof query !== \"string\") continue;\n\t\tif (window.matchMedia(query).matches) {\n\t\t\tlastMatchIndex = i;\n\t\t}\n\t}\n\n\treturn lastMatchIndex;\n}\n\nexport function getActiveBreakpoints(queries: string[]): boolean[] {\n\treturn queries.map((query) => window.matchMedia(query).matches);\n}\n\nexport function getLastTruthyIndex(values: boolean[]): number {\n\tfor (let i = values.length - 1; i >= 0; i--) {\n\t\tif (values[i]) return i;\n\t}\n\treturn -1;\n}\nexport function getLastValidValue<T>(\n\tarr: (T | null)[],\n\tindex: number,\n): T | null {\n\tif (arr[index] != null) return arr[index]!;\n\n\tfor (let i = index - 1; i >= 0; i--) {\n\t\tif (arr[i] != null) return arr[i]!;\n\t}\n\n\treturn null;\n}\n"],"mappings":";AAAA,SAAgB,eAAe,OAAyB,KAAa;CACpE,IAAI,OAAO,GACV,MAAM,IAAI,MAAM,2CAA2C;CAG5D,MAAM,CAAC,OAAO,OAAO;CAIrB,OAAO,EAHkB,QAAQ,MAAM,MAAM,KACtB,MAAM,MAAM,MAAM,EAEH;AACvC;AAEA,SAAgB,UAAU,EACzB,OAAO,CAAC,OAAO,MACf,SAIE;CACF,OAAO,SAAS,SAAS,OAAO;AACjC;AAgBA,SAAgB,qBAAqB,SAA8B;CAClE,OAAO,QAAQ,KAAK,UAAU,OAAO,WAAW,KAAK,CAAC,CAAC,OAAO;AAC/D;AAEA,SAAgB,mBAAmB,QAA2B;CAC7D,KAAK,IAAI,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KACvC,IAAI,OAAO,IAAI,OAAO;CAEvB,OAAO;AACR"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brytdesigns/web-component-parallax",
3
- "version": "1.2.20",
3
+ "version": "3.0.0",
4
4
  "description": "Headless parallax animation web component",
5
5
  "main": "./dist/main/index.js",
6
6
  "module": "./dist/main/index.js",
@@ -9,7 +9,7 @@
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./dist/main/index.d.ts",
12
- "module": "./dist/main/index.js"
12
+ "default": "./dist/main/index.js"
13
13
  }
14
14
  },
15
15
  "files": [
@@ -19,18 +19,17 @@
19
19
  "author": "Bryt Designs",
20
20
  "license": "ISC",
21
21
  "dependencies": {
22
+ "@brytdesigns/web-component-core": "3.0.0",
22
23
  "component-register": "0.8.7",
23
- "motion": "^12.40.0",
24
- "solid-element": "^1.9.1",
25
- "solid-js": "^1.9.9",
26
- "@brytdesigns/web-component-core": "1.1.7"
24
+ "motion": "^12.43.0",
25
+ "solid-js": "2.0.0-rc.14"
27
26
  },
28
27
  "devDependencies": {
29
- "dts-bundle-generator": "^9.5.1",
30
- "tsup": "^8.4.0"
28
+ "@repo/vite-config": "0.0.0",
29
+ "vite": "^8.2.2"
31
30
  },
32
31
  "scripts": {
33
- "build": "tsup --clean",
32
+ "build": "vite build",
34
33
  "typecheck": "tsc --noEmit"
35
34
  }
36
35
  }
package/dist/esm/index.js DELETED
@@ -1,507 +0,0 @@
1
- import { createWithElementContext, customShadowlessElement, correctElementType, getContextFromProvider } from '@brytdesigns/web-component-core/utils';
2
- import { splitProps, createEffect, batch, onCleanup, mergeProps, createMemo } from 'solid-js';
3
- import { createStore } from 'solid-js/store';
4
- import { createContext, consume, provide } from 'component-register';
5
- import { motionValue, scroll, transformValue, transform, frame, animate, styleEffect } from 'motion';
6
- import { awaitAllAnimations } from '@brytdesigns/web-component-core/animation';
7
- import { abortablePromise } from '@brytdesigns/web-component-core/promise';
8
-
9
- var __defProp = Object.defineProperty;
10
- var __export = (target, all) => {
11
- for (var name in all)
12
- __defProp(target, name, { get: all[name], enumerable: true });
13
- };
14
-
15
- // src/components/parallax-container/index.ts
16
- var parallax_container_exports = {};
17
- __export(parallax_container_exports, {
18
- Component: () => Component,
19
- Name: () => Name
20
- });
21
- function initializeParallaxContext(props) {
22
- const [_internal, _state] = splitProps(props, ["root"]);
23
- const scrollYProgress = motionValue(-1);
24
- const scrollY = motionValue(-1);
25
- const [info, setInfo] = createStore({
26
- offset: [-1, -1],
27
- scrollLength: -1
28
- });
29
- window.addEventListener("resize", () => {
30
- });
31
- createEffect(() => {
32
- const pages = _state.maxPages;
33
- _internal.root.style.height = `${pages * 100}vh`;
34
- _internal.root.style.width = `100%`;
35
- _internal.root.style.position = "relative";
36
- if (!_internal.root.style.display) {
37
- _internal.root.style.display = "block";
38
- }
39
- const remove = scroll(
40
- (_, info2) => {
41
- const { y } = info2;
42
- scrollYProgress.set(y.progress);
43
- scrollY.set(y.current);
44
- batch(() => {
45
- setInfo("offset", 0, y.offset?.at(0) || 0);
46
- setInfo("offset", 1, y.offset?.at(1) || 0);
47
- setInfo("scrollLength", y.scrollLength);
48
- });
49
- },
50
- {
51
- target: _internal.root,
52
- axis: "y",
53
- offset: ["start start", "end end"]
54
- }
55
- );
56
- onCleanup(() => {
57
- if (remove) {
58
- remove();
59
- }
60
- scrollYProgress.destroy();
61
- scrollY.destroy();
62
- });
63
- });
64
- return mergeProps(_state, {
65
- scrollYProgress,
66
- scrollY,
67
- info
68
- });
69
- }
70
- var ParallaxContextState = createContext(initializeParallaxContext);
71
- var provideParallaxContext = (initialState, element) => {
72
- const props = mergeProps(initialState, { root: element });
73
- return provide(ParallaxContextState, props, element);
74
- };
75
- var useParallaxContext = (context) => {
76
- return context;
77
- };
78
- var useParallax = (element) => {
79
- const context = consume(ParallaxContextState, element);
80
- if (!context) {
81
- throw console.error(
82
- "ParallaxContext not found! Please ensure to wrap your custom element with parallax-container element."
83
- );
84
- }
85
- return useParallaxContext(context);
86
- };
87
- var withParallaxElementContext = createWithElementContext(ParallaxContextState);
88
- var getParallaxContext = (element) => {
89
- const context = getContextFromProvider(
90
- ParallaxContextState,
91
- element
92
- );
93
- return useParallaxContext(context);
94
- };
95
-
96
- // src/utils.ts
97
- function normalizeTuple(range, max) {
98
- if (max <= 1) {
99
- throw new Error("The maximum value must be greater than 1.");
100
- }
101
- const [start, end] = range;
102
- const normalizedStart = (start - 1) / (max - 1);
103
- const normalizedEnd = (end - 1) / (max - 1);
104
- return [normalizedStart, normalizedEnd];
105
- }
106
- function isInRange({
107
- range: [start, end],
108
- value
109
- }) {
110
- return start <= value && end >= value;
111
- }
112
- function getActiveBreakpoints(queries) {
113
- return queries.map((query) => window.matchMedia(query).matches);
114
- }
115
- function getLastTruthyIndex(values) {
116
- for (let i = values.length - 1; i >= 0; i--) {
117
- if (values[i]) return i;
118
- }
119
- return -1;
120
- }
121
-
122
- // src/hooks/useParallaxStickyLayer.ts
123
- function initializeParallaxStickyLayerContext(props) {
124
- const [_internal, _state] = splitProps(props, ["root", "start", "end"]);
125
- const parallax = useParallax(_internal.root);
126
- const progress = motionValue(-1);
127
- const inRange = motionValue(false);
128
- const belowRange = motionValue(false);
129
- const aboveRange = motionValue(false);
130
- const position = transformValue(
131
- () => inRange.get() ? "sticky" : "absolute"
132
- );
133
- const transform$1 = transformValue(() => {
134
- const isInRange2 = inRange.get();
135
- const isBelowRange = belowRange.get();
136
- const isAboveRange = aboveRange.get();
137
- if (isInRange2) return "none";
138
- if (isBelowRange) return `translate(0px, ${(_internal.start - 1) * 100}vh)`;
139
- if (isAboveRange) return `translate(0px, ${(_internal.end - 1) * 100}vh)`;
140
- });
141
- const animations = motionValue([]);
142
- const styles = transformValue(() => ({
143
- position: position.get(),
144
- transform: transform$1.get()
145
- }));
146
- _internal.root.style.top = "0px";
147
- _internal.root.style.right = "0px";
148
- _internal.root.style.bottom = "0px";
149
- _internal.root.style.left = "0px";
150
- _internal.root.style.height = `100dvh`;
151
- _internal.root.style.overflowX = "hidden";
152
- _internal.root.style.maxWidth = "100%";
153
- if (window.getComputedStyle(_internal.root).display === "inline") {
154
- _internal.root.style.display = "block";
155
- }
156
- createEffect(() => {
157
- const range = [_internal.start, _internal.end];
158
- const maxPages = parallax.maxPages;
159
- const normalizedRange = normalizeTuple(range, maxPages);
160
- const [normStart, normEnd] = normalizedRange;
161
- const transformer = transform(normalizedRange, [0, 1]);
162
- const unsubscribe = parallax.scrollYProgress.on("change", (value) => {
163
- inRange.set(isInRange({ range: normalizedRange, value }));
164
- belowRange.set(value <= normStart);
165
- aboveRange.set(value >= normEnd);
166
- progress.set(transformer(value));
167
- });
168
- return onCleanup(() => {
169
- unsubscribe();
170
- });
171
- });
172
- function updateStyles() {
173
- const s = styles.get();
174
- _internal.root.style.position = s.position;
175
- _internal.root.style.transform = s.transform;
176
- }
177
- function renderStyles() {
178
- frame.render(updateStyles);
179
- }
180
- function waitForAnimations() {
181
- const a = animations.get();
182
- const controller = new AbortController();
183
- abortablePromise(awaitAllAnimations(a), controller.signal).then(() => {
184
- animations.set([]);
185
- renderStyles();
186
- });
187
- }
188
- const unsubStyles = styles.on("change", (_) => {
189
- if (progress.get() === 1 || progress.get() === 0)
190
- return waitForAnimations();
191
- animations.set([]);
192
- renderStyles();
193
- });
194
- function _animate(...args) {
195
- const animation = animate(...args);
196
- animations.set([...animations.get(), animation]);
197
- return animation;
198
- }
199
- onCleanup(() => {
200
- unsubStyles();
201
- });
202
- return [progress, { animate: _animate }];
203
- }
204
- var ParallaxStickyLayerContextState = createContext(
205
- initializeParallaxStickyLayerContext
206
- );
207
- var provideParallaxStickyLayerContext = (initialState, element) => {
208
- const props = mergeProps(initialState, { root: element });
209
- return provide(ParallaxStickyLayerContextState, props, element);
210
- };
211
- var useParallaxStickyLayerContext = (context) => {
212
- return context;
213
- };
214
- var useParallaxStickyLayer = (element) => {
215
- const context = consume(
216
- ParallaxStickyLayerContextState,
217
- element
218
- );
219
- if (!context) {
220
- throw console.error(
221
- "ParallaxContext not found! Please ensure to wrap your custom element with parallax-container element."
222
- );
223
- }
224
- return useParallaxStickyLayerContext(context);
225
- };
226
- var withParallaxStickyLayerContext = createWithElementContext(ParallaxStickyLayerContextState);
227
- var getParallaxStickyLayerContext = (element) => {
228
- const context = getContextFromProvider(
229
- ParallaxStickyLayerContextState,
230
- element
231
- );
232
- return useParallaxStickyLayerContext(context);
233
- };
234
-
235
- // src/components/parallax-container/index.ts
236
- var Name = `parallax-container`;
237
- var Component = (props, { element }) => {
238
- if (!props.maxPages)
239
- return console.warn(
240
- `${Name}: requires max-pages attribute to be set!`,
241
- element
242
- );
243
- if (props.maxPages < 1)
244
- return console.warn(
245
- `${Name}: max-pages must be greater than or equal to 1!`,
246
- element
247
- );
248
- provideParallaxContext(props, element);
249
- };
250
-
251
- // src/components/parallax-sticky-layer/index.ts
252
- var parallax_sticky_layer_exports = {};
253
- __export(parallax_sticky_layer_exports, {
254
- Component: () => Component2,
255
- Name: () => Name2
256
- });
257
- var Name2 = `parallax-sticky-layer`;
258
- var Component2 = (props, { element }) => {
259
- if (!props.start)
260
- return console.warn(
261
- `${Name2}: requires start attribute to be set!`,
262
- element
263
- );
264
- if (!props.end)
265
- return console.warn(`${Name2}: requires end attribute to be set!`, element);
266
- if (props.end <= props.start)
267
- return console.warn(
268
- `${Name2}: the start attribute must be less than the end attribute!`,
269
- element
270
- );
271
- if (props.start < 1 || props.end < 1)
272
- return console.warn(
273
- `${Name2}: The start and end attributes must be greater than or equal to 1!`,
274
- element
275
- );
276
- provideParallaxStickyLayerContext(props, element);
277
- };
278
-
279
- // src/components/parallax-animation/index.ts
280
- var parallax_animation_exports = {};
281
- __export(parallax_animation_exports, {
282
- Component: () => Component3,
283
- Name: () => Name3,
284
- PROPS: () => PROPS
285
- });
286
- function keysFromObject(object) {
287
- return Object.keys(object);
288
- }
289
- var Name3 = `parallax-animation`;
290
- var PROPS = {
291
- breakpoints: [""],
292
- range: [0, 1],
293
- y: null,
294
- x: null,
295
- scale: null,
296
- rotate: null,
297
- opacity: null,
298
- color: null,
299
- backgroundColor: null,
300
- borderRadius: null
301
- };
302
- var PROP_DEFAULTS = {
303
- y: "0%",
304
- x: "0%",
305
- scale: 1,
306
- rotate: 0,
307
- opacity: null,
308
- color: null,
309
- backgroundColor: null,
310
- borderRadius: null
311
- };
312
- var KEYS = Object.keys(PROPS);
313
- var isNestedAnimatableArray = (values) => {
314
- return Array.isArray(values) && (Array.isArray(values[0]) || values[0] === null);
315
- };
316
- var flattenAnimatableArray = (value, index = 0) => {
317
- if (isNestedAnimatableArray(value)) {
318
- return value[index];
319
- }
320
- return value;
321
- };
322
- var Component3 = (props, { element }) => {
323
- if (Object.keys(props).some(
324
- (key) => KEYS.includes(key) && !Array.isArray(Reflect.get(props, key))
325
- ))
326
- return console.warn(
327
- `parallax-animate: At least one of ${KEYS.join(",")} properties is required and must be an array of values!`,
328
- element
329
- );
330
- const messages = Object.entries(props).reduce((messages2, [key, value]) => {
331
- if (!KEYS.includes(key)) return messages2;
332
- if (value && value.length !== props.range.length) {
333
- return messages2.concat(
334
- `${key} attribute must have the same length as range attribute!`
335
- );
336
- }
337
- return messages2;
338
- }, []);
339
- if (messages.length)
340
- return console.warn(
341
- element,
342
- `
343
- parallax-animate: Please fix the following issues:
344
- ${messages.join("\n")}`
345
- );
346
- const [progress, { animate: animate2 }] = useParallaxStickyLayer(element);
347
- const [activeBreakpoints, setActiveBreakpoints] = createStore(
348
- getActiveBreakpoints(props.breakpoints)
349
- );
350
- const activeBreakpointIndex = createMemo(
351
- () => getLastTruthyIndex(activeBreakpoints)
352
- );
353
- const [_, importantProps] = splitProps(props, ["breakpoints"]);
354
- const animateableProps = mergeProps(importantProps, {});
355
- const activeProps = createMemo(() => {
356
- const index = activeBreakpointIndex();
357
- if (index === -1) {
358
- const { breakpoints, ...active2 } = PROPS;
359
- return active2;
360
- }
361
- const keys = keysFromObject(animateableProps);
362
- const active = keys.reduce((active2, key) => {
363
- const value = animateableProps[key];
364
- if (isNestedAnimatableArray(value)) {
365
- const flattenedValue = flattenAnimatableArray(value, index);
366
- return {
367
- ...active2,
368
- [key]: flattenedValue
369
- };
370
- }
371
- return {
372
- ...active2,
373
- [key]: value
374
- };
375
- }, {});
376
- return active;
377
- });
378
- createEffect(() => {
379
- const breakpoints = props.breakpoints;
380
- const controller = new AbortController();
381
- for (let i = 0; i < breakpoints.length; i++) {
382
- const query = breakpoints[i];
383
- if (!query) continue;
384
- const mediaQuery = window.matchMedia(query);
385
- mediaQuery.addEventListener(
386
- "change",
387
- (e) => setActiveBreakpoints(i, e.matches),
388
- { signal: controller.signal }
389
- );
390
- }
391
- return onCleanup(() => {
392
- controller.abort();
393
- });
394
- });
395
- element.style.willChange = "transform";
396
- if (window.getComputedStyle(element).getPropertyValue("display") === "inline") {
397
- element.style.display = "block";
398
- }
399
- createEffect(() => {
400
- const active = activeProps();
401
- const { range, ...props2 } = active;
402
- const valueSubscribers = [];
403
- let disposed = false;
404
- const progressValue = Object.keys(PROP_DEFAULTS).reduce(
405
- (values, key) => {
406
- const fallback = Reflect.get(PROP_DEFAULTS, key);
407
- const valueRange = Reflect.get(props2, key);
408
- if (valueRange?.length === range.length) {
409
- const transform2 = transform(range, valueRange);
410
- const value = motionValue(transform2(progress.get()));
411
- const unsub2 = progress.on("change", (latest) => {
412
- value.set(transform2(latest));
413
- });
414
- valueSubscribers.push(unsub2);
415
- values[key] = value;
416
- } else values[key] = fallback;
417
- return values;
418
- },
419
- {}
420
- );
421
- const animated = Object.keys(progressValue).reduce(
422
- (obj, key) => {
423
- const v = progressValue[key];
424
- Reflect.set(
425
- obj,
426
- key,
427
- motionValue(typeof v === "object" && v !== null ? v.get() : v)
428
- );
429
- return obj;
430
- },
431
- {}
432
- );
433
- const transform$1 = transformValue(
434
- () => `translate(${animated.x?.get()}, ${animated.y?.get()}) scale(${animated.scale?.get()}) rotate(${animated.rotate?.get()}deg)`
435
- );
436
- function animateValues() {
437
- if (disposed) return;
438
- const sequence = Object.keys(animated).map((key) => {
439
- const subject = animated[key];
440
- const v = progressValue[key]?.get?.();
441
- if (!subject) return null;
442
- if (typeof v === "undefined" || v === null) return null;
443
- if (typeof v !== "string" && typeof v !== "number") return null;
444
- return [animated[key], v, { at: "<" }];
445
- }).filter((v) => v !== null);
446
- if (sequence.length === 0) return;
447
- animate2(sequence);
448
- }
449
- function scheduleAnimation() {
450
- frame.update(animateValues);
451
- }
452
- const unsub = progress.on("change", (_2) => {
453
- scheduleAnimation();
454
- });
455
- const styledValues = Object.keys(animated).filter(
456
- (key) => key !== "y" && key !== "x" && key !== "rotate" && key !== "scale"
457
- ).reduce((obj, key) => {
458
- Reflect.set(obj, key, animated[key]);
459
- return obj;
460
- }, {});
461
- const unstyle = styleEffect(element, {
462
- transform: transform$1,
463
- ...styledValues
464
- });
465
- return onCleanup(() => {
466
- disposed = true;
467
- unstyle();
468
- unsub();
469
- valueSubscribers.forEach((unsub2) => {
470
- unsub2();
471
- });
472
- Object.values(animated).forEach((value) => {
473
- value.destroy();
474
- });
475
- Object.values(progressValue).forEach((value) => {
476
- value?.destroy?.();
477
- });
478
- transform$1.destroy();
479
- });
480
- });
481
- };
482
-
483
- // src/index.ts
484
- customShadowlessElement(
485
- parallax_container_exports.Name,
486
- {
487
- maxPages: 2
488
- },
489
- correctElementType(parallax_container_exports.Component)
490
- );
491
- customShadowlessElement(
492
- parallax_sticky_layer_exports.Name,
493
- {
494
- start: 1,
495
- end: 2
496
- },
497
- correctElementType(parallax_sticky_layer_exports.Component)
498
- );
499
- customShadowlessElement(
500
- parallax_animation_exports.Name,
501
- parallax_animation_exports.PROPS,
502
- correctElementType(parallax_animation_exports.Component)
503
- );
504
-
505
- export { getParallaxContext, getParallaxStickyLayerContext, useParallax, useParallaxStickyLayer, withParallaxElementContext, withParallaxStickyLayerContext };
506
- //# sourceMappingURL=index.js.map
507
- //# sourceMappingURL=index.js.map