@zikojs/framer-motion 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ZAKARIA ELALAOUI
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/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # @zikojs/motion
2
+
3
+ A lightweight adapter that adds ZikoJS UIElement support to Motion / Framer Motion.
4
+
5
+ The Motion API remains the same. The only difference is that `UIElement` and `UIElement[]` can now be used directly as animation targets.
6
+
7
+ ## install
8
+
9
+ ```bash
10
+ npm i @zikojs/motion
11
+ ```
12
+ Usage
13
+
14
+ Instead of manually accessing the underlying DOM element:
15
+
16
+ ```js
17
+ import { animate } from "framer-motion";
18
+
19
+ animate(box.element, { x: 100 }, { duration: 1 });
20
+ ```
21
+
22
+ you can pass the `UIElement` directly:
23
+
24
+ ```js
25
+ import { animate } from "@zikojs/motion";
26
+
27
+ animate(box, { x: 100 }, { duration: 1 });
28
+ ```
29
+
30
+ ## Features
31
+
32
+ - ***ðŸŽŊ UIElement targets*** : Use ZikoJS UIElement directly as a motion target.
33
+ - ***ðŸ“Ķ UIElement arrays*** : Animate UIElement[] without manually accessing .element.
34
+ - ***🔀 Mixed targets*** : Combine UIElement and HTMLElement targets.
35
+ - ***ðŸ§Đ Same motion API*** : No new syntax or alternative animation API.
36
+ - ***🔌 Drop-in adapter*** : Works as a thin layer on top of motion.
37
+ - ***🌐 Native DOM support*** : Existing HTMLElement targets continue to work.
38
+ - ***ðŸŠķ Lightweight*** : Only adapts targets; motion handles the animation itself.
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@zikojs/framer-motion",
3
+ "version": "0.1.0",
4
+ "description": "framer-motion adapter for zikojs",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "author": "zakaria elaloui",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/zikojs/addons.git",
13
+ "directory": "packages/framer-motion"
14
+ },
15
+ "keywords": [
16
+ "zikojs",
17
+ "ziko",
18
+ "framer-motion",
19
+ "animation"
20
+ ],
21
+ "exports": {
22
+ ".": {
23
+ "import": "./src/index.js",
24
+ "types": "./src/index.d.ts"
25
+ }
26
+ },
27
+ "files": [
28
+ "src",
29
+ "dist",
30
+ "LICENCE"
31
+ ],
32
+ "license": "MIT",
33
+ "devDependencies": {
34
+ "@rollup/plugin-commonjs": "^29.0.3",
35
+ "@rollup/plugin-node-resolve": "^16.0.3",
36
+ "@rollup/plugin-terser": "^1.0.0",
37
+ "cross-env": "^10.1.0",
38
+ "rollup": "^4.63.1"
39
+ },
40
+ "dependencies": {
41
+ "framer-motion": "^3.15.0",
42
+ "ziko": "2.0.0-beta.9"
43
+ },
44
+ "scripts": {
45
+ "test": "echo \"Error: no test specified\" && exit 1",
46
+ "dev": "cross-env NODE_ENV=development rollup --config rollup.config.js",
47
+ "watch": "cross-env NODE_ENV=development rollup --config rollup.config.js -w",
48
+ "build": "cross-env NODE_ENV=production rollup --config rollup.config.js"
49
+ }
50
+ }
package/src/index.js ADDED
@@ -0,0 +1,45 @@
1
+ import { motion as originalMotion } from "framer-motion";
2
+ import { UIElement } from "ziko/dom";
3
+
4
+ const resolveTarget = (target) => (target instanceof UIElement ? target?.element : target);
5
+
6
+ /**
7
+ * Wraps a motion component or HTML tag to unpack Ziko UIElement instances in props/ref
8
+ */
9
+ const wrapComponent = (Component) => {
10
+ return (props) => {
11
+ const resolvedProps = { ...props };
12
+
13
+ // Resolve target element inside ref if passed as UIElement
14
+ if (resolvedProps.ref && resolvedProps.ref instanceof UIElement) {
15
+ resolvedProps.ref = resolveTarget(resolvedProps.ref);
16
+ }
17
+
18
+ return Component(resolvedProps);
19
+ };
20
+ };
21
+
22
+ // Proxy to dynamically capture motion.div, motion.span, motion(Component), etc.
23
+ export const motion = new Proxy(originalMotion, {
24
+ get(target, prop) {
25
+ const orig = target[prop];
26
+ return typeof orig === "function" ? wrapComponent(orig) : orig;
27
+ },
28
+ apply(target, thisArg, argArray) {
29
+ const Component = target(...argArray);
30
+ return wrapComponent(Component);
31
+ }
32
+ });
33
+
34
+ /**
35
+ * Adapter for Motion core animation utilities (e.g. animate)
36
+ */
37
+ export function animate(target, keyframes, options) {
38
+ const resolved = Array.isArray(target)
39
+ ? target.map(resolveTarget)
40
+ : resolveTarget(target);
41
+
42
+ return originalMotion.animate
43
+ ? originalMotion.animate(resolved, keyframes, options)
44
+ : null;
45
+ }