@levita-js/react 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jérôme André
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,85 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let levita_js = require("levita-js");
3
+ let react = require("react");
4
+ let react_jsx_runtime = require("react/jsx-runtime");
5
+
6
+ //#region src/index.tsx
7
+ /**
8
+ * React wrapper for the Levita 3D tilt effect.
9
+ *
10
+ * Accepts all `LevitaOptions` as props alongside standard `<div>` attributes.
11
+ * The Levita instance is created on mount and destroyed on unmount.
12
+ * Changing any tilt prop recreates the instance.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * import { Tilt } from '@levita-js/react';
17
+ * import 'levita-js/style.css';
18
+ *
19
+ * <Tilt glare shadow max={20}>
20
+ * <h1>Hello</h1>
21
+ * </Tilt>
22
+ * ```
23
+ */
24
+ const Tilt = (0, react.forwardRef)(({ max, perspective, scale, speed, easing, reverse, axis, reset, glare, maxGlare, shadow, gyroscope, disabled, eventsEl, children, ...rest }, ref) => {
25
+ const elRef = (0, react.useRef)(null);
26
+ const instanceRef = (0, react.useRef)(null);
27
+ (0, react.useImperativeHandle)(ref, () => ({
28
+ get element() {
29
+ return elRef.current;
30
+ },
31
+ get instance() {
32
+ return instanceRef.current;
33
+ },
34
+ requestPermission: async () => {
35
+ return await instanceRef.current?.requestPermission() ?? false;
36
+ }
37
+ }));
38
+ (0, react.useEffect)(() => {
39
+ if (!elRef.current) return;
40
+ const options = (0, levita_js.buildOptions)({
41
+ max,
42
+ perspective,
43
+ scale,
44
+ speed,
45
+ easing,
46
+ reverse,
47
+ axis,
48
+ reset,
49
+ glare,
50
+ maxGlare,
51
+ shadow,
52
+ gyroscope,
53
+ disabled,
54
+ eventsEl
55
+ });
56
+ instanceRef.current = new levita_js.Levita(elRef.current, options);
57
+ return () => {
58
+ instanceRef.current?.destroy();
59
+ instanceRef.current = null;
60
+ };
61
+ }, [
62
+ max,
63
+ perspective,
64
+ scale,
65
+ speed,
66
+ easing,
67
+ reverse,
68
+ axis,
69
+ reset,
70
+ glare,
71
+ maxGlare,
72
+ shadow,
73
+ gyroscope,
74
+ disabled,
75
+ eventsEl
76
+ ]);
77
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
78
+ ref: elRef,
79
+ ...rest,
80
+ children
81
+ });
82
+ });
83
+
84
+ //#endregion
85
+ exports.Tilt = Tilt;
@@ -0,0 +1,39 @@
1
+ import * as react from "react";
2
+ import { HTMLAttributes, ReactNode } from "react";
3
+ import { Levita, LevitaOptions } from "levita-js";
4
+
5
+ //#region src/index.d.ts
6
+ /** Props accepted by the `<Tilt>` component. */
7
+ interface TiltProps extends Partial<LevitaOptions>, Omit<HTMLAttributes<HTMLDivElement>, "onAnimationEnd"> {
8
+ children?: ReactNode;
9
+ }
10
+ /** Imperative handle exposed via `ref` on the `<Tilt>` component. */
11
+ interface TiltRef {
12
+ /** The underlying DOM element. */
13
+ element: HTMLDivElement | null;
14
+ /** The Levita instance driving the tilt effect. */
15
+ instance: Levita | null;
16
+ /** Request accelerometer permission (must be called from a user gesture on iOS). */
17
+ requestPermission: () => Promise<boolean>;
18
+ }
19
+ /**
20
+ * React wrapper for the Levita 3D tilt effect.
21
+ *
22
+ * Accepts all `LevitaOptions` as props alongside standard `<div>` attributes.
23
+ * The Levita instance is created on mount and destroyed on unmount.
24
+ * Changing any tilt prop recreates the instance.
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * import { Tilt } from '@levita-js/react';
29
+ * import 'levita-js/style.css';
30
+ *
31
+ * <Tilt glare shadow max={20}>
32
+ * <h1>Hello</h1>
33
+ * </Tilt>
34
+ * ```
35
+ */
36
+ declare const Tilt: react.ForwardRefExoticComponent<TiltProps & react.RefAttributes<TiltRef>>;
37
+ //#endregion
38
+ export { Tilt, TiltProps, TiltRef };
39
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;UAYiB,SAAA,SACR,OAAA,CAAQ,aAAA,GACf,IAAA,CAAK,cAAA,CAAe,cAAA;EACrB,QAAA,GAAW,SAAA;AAAA;;UAIK,OAAA;EALK;EAOrB,OAAA,EAAS,cAAA;EANE;EAQX,QAAA,EAAU,MAAA;EATT;EAWD,iBAAA,QAAyB,OAAA;AAAA;;;;;;;;;;AAN1B;;;;;;;;cA0Ba,IAAA,EAAI,KAAA,CAAA,yBAAA,CAAA,SAAA,GAAA,KAAA,CAAA,aAAA,CAAA,OAAA"}
@@ -0,0 +1,39 @@
1
+ import { Levita, LevitaOptions } from "levita-js";
2
+ import * as react from "react";
3
+ import { HTMLAttributes, ReactNode } from "react";
4
+
5
+ //#region src/index.d.ts
6
+ /** Props accepted by the `<Tilt>` component. */
7
+ interface TiltProps extends Partial<LevitaOptions>, Omit<HTMLAttributes<HTMLDivElement>, "onAnimationEnd"> {
8
+ children?: ReactNode;
9
+ }
10
+ /** Imperative handle exposed via `ref` on the `<Tilt>` component. */
11
+ interface TiltRef {
12
+ /** The underlying DOM element. */
13
+ element: HTMLDivElement | null;
14
+ /** The Levita instance driving the tilt effect. */
15
+ instance: Levita | null;
16
+ /** Request accelerometer permission (must be called from a user gesture on iOS). */
17
+ requestPermission: () => Promise<boolean>;
18
+ }
19
+ /**
20
+ * React wrapper for the Levita 3D tilt effect.
21
+ *
22
+ * Accepts all `LevitaOptions` as props alongside standard `<div>` attributes.
23
+ * The Levita instance is created on mount and destroyed on unmount.
24
+ * Changing any tilt prop recreates the instance.
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * import { Tilt } from '@levita-js/react';
29
+ * import 'levita-js/style.css';
30
+ *
31
+ * <Tilt glare shadow max={20}>
32
+ * <h1>Hello</h1>
33
+ * </Tilt>
34
+ * ```
35
+ */
36
+ declare const Tilt: react.ForwardRefExoticComponent<TiltProps & react.RefAttributes<TiltRef>>;
37
+ //#endregion
38
+ export { Tilt, TiltProps, TiltRef };
39
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;UAYiB,SAAA,SACR,OAAA,CAAQ,aAAA,GACf,IAAA,CAAK,cAAA,CAAe,cAAA;EACrB,QAAA,GAAW,SAAA;AAAA;;UAIK,OAAA;EALK;EAOrB,OAAA,EAAS,cAAA;EANE;EAQX,QAAA,EAAU,MAAA;EATT;EAWD,iBAAA,QAAyB,OAAA;AAAA;;;;;;;;;;AAN1B;;;;;;;;cA0Ba,IAAA,EAAI,KAAA,CAAA,yBAAA,CAAA,SAAA,GAAA,KAAA,CAAA,aAAA,CAAA,OAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,85 @@
1
+ import { Levita, buildOptions } from "levita-js";
2
+ import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+
5
+ //#region src/index.tsx
6
+ /**
7
+ * React wrapper for the Levita 3D tilt effect.
8
+ *
9
+ * Accepts all `LevitaOptions` as props alongside standard `<div>` attributes.
10
+ * The Levita instance is created on mount and destroyed on unmount.
11
+ * Changing any tilt prop recreates the instance.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * import { Tilt } from '@levita-js/react';
16
+ * import 'levita-js/style.css';
17
+ *
18
+ * <Tilt glare shadow max={20}>
19
+ * <h1>Hello</h1>
20
+ * </Tilt>
21
+ * ```
22
+ */
23
+ const Tilt = forwardRef(({ max, perspective, scale, speed, easing, reverse, axis, reset, glare, maxGlare, shadow, gyroscope, disabled, eventsEl, children, ...rest }, ref) => {
24
+ const elRef = useRef(null);
25
+ const instanceRef = useRef(null);
26
+ useImperativeHandle(ref, () => ({
27
+ get element() {
28
+ return elRef.current;
29
+ },
30
+ get instance() {
31
+ return instanceRef.current;
32
+ },
33
+ requestPermission: async () => {
34
+ return await instanceRef.current?.requestPermission() ?? false;
35
+ }
36
+ }));
37
+ useEffect(() => {
38
+ if (!elRef.current) return;
39
+ const options = buildOptions({
40
+ max,
41
+ perspective,
42
+ scale,
43
+ speed,
44
+ easing,
45
+ reverse,
46
+ axis,
47
+ reset,
48
+ glare,
49
+ maxGlare,
50
+ shadow,
51
+ gyroscope,
52
+ disabled,
53
+ eventsEl
54
+ });
55
+ instanceRef.current = new Levita(elRef.current, options);
56
+ return () => {
57
+ instanceRef.current?.destroy();
58
+ instanceRef.current = null;
59
+ };
60
+ }, [
61
+ max,
62
+ perspective,
63
+ scale,
64
+ speed,
65
+ easing,
66
+ reverse,
67
+ axis,
68
+ reset,
69
+ glare,
70
+ maxGlare,
71
+ shadow,
72
+ gyroscope,
73
+ disabled,
74
+ eventsEl
75
+ ]);
76
+ return /* @__PURE__ */ jsx("div", {
77
+ ref: elRef,
78
+ ...rest,
79
+ children
80
+ });
81
+ });
82
+
83
+ //#endregion
84
+ export { Tilt };
85
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["import type { LevitaOptions } from \"levita-js\";\nimport { buildOptions, Levita } from \"levita-js\";\nimport {\n\tforwardRef,\n\ttype HTMLAttributes,\n\ttype ReactNode,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n} from \"react\";\n\n/** Props accepted by the `<Tilt>` component. */\nexport interface TiltProps\n\textends Partial<LevitaOptions>,\n\t\tOmit<HTMLAttributes<HTMLDivElement>, \"onAnimationEnd\"> {\n\tchildren?: ReactNode;\n}\n\n/** Imperative handle exposed via `ref` on the `<Tilt>` component. */\nexport interface TiltRef {\n\t/** The underlying DOM element. */\n\telement: HTMLDivElement | null;\n\t/** The Levita instance driving the tilt effect. */\n\tinstance: Levita | null;\n\t/** Request accelerometer permission (must be called from a user gesture on iOS). */\n\trequestPermission: () => Promise<boolean>;\n}\n\n/**\n * React wrapper for the Levita 3D tilt effect.\n *\n * Accepts all `LevitaOptions` as props alongside standard `<div>` attributes.\n * The Levita instance is created on mount and destroyed on unmount.\n * Changing any tilt prop recreates the instance.\n *\n * @example\n * ```tsx\n * import { Tilt } from '@levita-js/react';\n * import 'levita-js/style.css';\n *\n * <Tilt glare shadow max={20}>\n * <h1>Hello</h1>\n * </Tilt>\n * ```\n */\nexport const Tilt = forwardRef<TiltRef, TiltProps>(\n\t(\n\t\t{\n\t\t\tmax,\n\t\t\tperspective,\n\t\t\tscale,\n\t\t\tspeed,\n\t\t\teasing,\n\t\t\treverse,\n\t\t\taxis,\n\t\t\treset,\n\t\t\tglare,\n\t\t\tmaxGlare,\n\t\t\tshadow,\n\t\t\tgyroscope,\n\t\t\tdisabled,\n\t\t\teventsEl,\n\t\t\tchildren,\n\t\t\t...rest\n\t\t},\n\t\tref,\n\t) => {\n\t\tconst elRef = useRef<HTMLDivElement>(null);\n\t\tconst instanceRef = useRef<Levita | null>(null);\n\n\t\tuseImperativeHandle(ref, () => ({\n\t\t\tget element() {\n\t\t\t\treturn elRef.current;\n\t\t\t},\n\t\t\tget instance() {\n\t\t\t\treturn instanceRef.current;\n\t\t\t},\n\t\t\trequestPermission: async () => {\n\t\t\t\treturn (await instanceRef.current?.requestPermission()) ?? false;\n\t\t\t},\n\t\t}));\n\n\t\tuseEffect(() => {\n\t\t\tif (!elRef.current) return;\n\n\t\t\tconst options = buildOptions({\n\t\t\t\tmax,\n\t\t\t\tperspective,\n\t\t\t\tscale,\n\t\t\t\tspeed,\n\t\t\t\teasing,\n\t\t\t\treverse,\n\t\t\t\taxis,\n\t\t\t\treset,\n\t\t\t\tglare,\n\t\t\t\tmaxGlare,\n\t\t\t\tshadow,\n\t\t\t\tgyroscope,\n\t\t\t\tdisabled,\n\t\t\t\teventsEl,\n\t\t\t});\n\n\t\t\tinstanceRef.current = new Levita(elRef.current, options);\n\n\t\t\treturn () => {\n\t\t\t\tinstanceRef.current?.destroy();\n\t\t\t\tinstanceRef.current = null;\n\t\t\t};\n\t\t}, [\n\t\t\tmax,\n\t\t\tperspective,\n\t\t\tscale,\n\t\t\tspeed,\n\t\t\teasing,\n\t\t\treverse,\n\t\t\taxis,\n\t\t\treset,\n\t\t\tglare,\n\t\t\tmaxGlare,\n\t\t\tshadow,\n\t\t\tgyroscope,\n\t\t\tdisabled,\n\t\t\teventsEl,\n\t\t]);\n\t\treturn (\n\t\t\t<div ref={elRef} {...rest}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t},\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,OAAO,YAElB,EACC,KACA,aACA,OACA,OACA,QACA,SACA,MACA,OACA,OACA,UACA,QACA,WACA,UACA,UACA,UACA,GAAG,QAEJ,QACI;CACJ,MAAM,QAAQ,OAAuB,KAAK;CAC1C,MAAM,cAAc,OAAsB,KAAK;AAE/C,qBAAoB,YAAY;EAC/B,IAAI,UAAU;AACb,UAAO,MAAM;;EAEd,IAAI,WAAW;AACd,UAAO,YAAY;;EAEpB,mBAAmB,YAAY;AAC9B,UAAQ,MAAM,YAAY,SAAS,mBAAmB,IAAK;;EAE5D,EAAE;AAEH,iBAAgB;AACf,MAAI,CAAC,MAAM,QAAS;EAEpB,MAAM,UAAU,aAAa;GAC5B;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,CAAC;AAEF,cAAY,UAAU,IAAI,OAAO,MAAM,SAAS,QAAQ;AAExD,eAAa;AACZ,eAAY,SAAS,SAAS;AAC9B,eAAY,UAAU;;IAErB;EACF;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,CAAC;AACF,QACC,oBAAC;EAAI,KAAK;EAAO,GAAI;EACnB;GACI;EAGR"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@levita-js/react",
3
+ "version": "0.1.1",
4
+ "description": "React wrapper for Levita 3D tilt & parallax",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.mts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.mts",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "sideEffects": false,
25
+ "peerDependencies": {
26
+ "react": ">=18",
27
+ "react-dom": ">=18"
28
+ },
29
+ "dependencies": {
30
+ "levita-js": "0.1.1"
31
+ },
32
+ "devDependencies": {
33
+ "@testing-library/react": "^16.3.2",
34
+ "@types/react": "^19.0.0",
35
+ "@types/react-dom": "^19.0.0",
36
+ "react": "^19.1.0",
37
+ "react-dom": "^19.1.0",
38
+ "tsdown": "^0.20.3"
39
+ },
40
+ "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/jeromearsene/levita.git",
44
+ "directory": "packages/react"
45
+ },
46
+ "homepage": "https://github.com/jeromearsene/levita#readme",
47
+ "scripts": {
48
+ "build": "tsdown"
49
+ }
50
+ }