├── .babelrc
├── .editorconfig
├── .eslintignore
├── .eslintrc
├── .gitignore
├── .npmignore
├── .prettierrc
├── README.md
├── docz
├── doczrc.js
├── package-lock.json
├── package.json
├── postinstall.sh
├── public
│ ├── sky-square.jpg
│ ├── sky-wide.jpg
│ ├── tailwind.min.css
│ └── zurich.jpg
├── src
│ ├── images.js
│ ├── pages
│ │ ├── GettingStarted
│ │ │ ├── Simple.tsx
│ │ │ ├── curve.mdx
│ │ │ └── intro.mdx
│ │ ├── Player
│ │ │ ├── Player.tsx
│ │ │ ├── PlayerFull.tsx
│ │ │ ├── PlayerMini.tsx
│ │ │ └── player.mdx
│ │ ├── Progress
│ │ │ └── progress.mdx-
│ │ ├── Tests
│ │ │ └── toggle.mdx-
│ │ ├── Travel
│ │ │ ├── Travel.tsx
│ │ │ ├── tavel.mdx
│ │ │ └── travel.css
│ │ ├── api
│ │ │ ├── useFade.mdx
│ │ │ ├── useMorphKeys.mdx
│ │ │ └── useMorphList.mdx
│ │ ├── demos
│ │ │ └── docs.mdx
│ │ ├── options.mdx
│ │ └── styling
│ │ │ ├── styling.js
│ │ │ └── styling.mdx
│ └── utilities.css
└── tsconfig.json
├── examples
├── react-morph-simple.gif
└── react-morph.gif
├── lib
├── Morph.d.ts
├── Morph.js
├── Morph.js.map
├── easings.d.ts
├── easings.js
├── easings.js.map
├── index.d.ts
├── index.js
├── index.js.map
├── morphTransition.d.ts
├── morphTransition.js
├── morphTransition.js.map
├── presets.d.ts
├── presets.js
├── presets.js.map
├── useFade.d.ts
├── useFade.js
├── useFade.js.map
├── useMorph.d.ts
├── useMorph.js
├── useMorph.js.map
├── useMorphKeys.d.ts
├── useMorphKeys.js
├── useMorphKeys.js.map
├── useMorphList.d.ts
├── useMorphList.js
├── useMorphList.js.map
├── useMorphs.d.ts
├── useMorphs.js
├── useMorphs.js.map
├── util.d.ts
├── util.js
└── util.js.map
├── package-lock.json
├── package.json
├── src
├── Morph.tsx
├── bck_Morph.jsx
├── easings.ts
├── index.ts
├── morphTransition.ts
├── presets.ts
├── types.d.ts
├── useFade.ts
├── useMorph.ts
├── useMorphList.ts
├── useMorphs.ts
└── util.ts
└── tsconfig.json
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [["@babel/env"]],
3 | "plugins": [
4 | ["transform-class-properties"],
5 | ["transform-regenerator"],
6 | ["transform-object-rest-spread", { "useBuiltIns": true }]
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | indent_style = space
2 | indent_size = 2
3 |
4 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | lib
2 | **/node_modules
3 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | parserOptions: { parser: "@typescript-eslint/parser" },
3 | "extends":
4 | [
5 | "airbnb-base",
6 | "plugin:@typescript-eslint/recommended",
7 | "prettier",
8 | "prettier/@typescript-eslint",
9 | ],
10 | }
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Directory for instrumented libs generated by jscoverage/JSCover
7 | lib-cov
8 |
9 | # Coverage directory used by tools like istanbul
10 | coverage
11 |
12 | # Dependency directories
13 | node_modules/
14 | jspm_packages/
15 |
16 | # Typescript v1 declaration files
17 | typings/
18 |
19 | # Optional npm cache directory
20 | .npm
21 |
22 | # Optional eslint cache
23 | .eslintcache
24 |
25 | # Optional REPL history
26 | .node_repl_history
27 |
28 | # Output of 'npm pack'
29 | *.tgz
30 |
31 | # Yarn Integrity file
32 | .yarn-integrity
33 |
34 | # dotenv environment variables file
35 | .env
36 | .cache
37 |
38 | .DS_Store
39 |
40 | .docz
41 | docz/.docz
42 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .babelrc
2 | examples
3 | docz
4 | src
5 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "trailingComma": "all"
4 | }
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Morph ️🦋
2 |
3 | #### Morphing UI transitions made simple
4 |
5 | [](https://www.npmjs.com/package/react-morph)
6 |
7 |
8 |
9 | Magically animates one element into another just by tagging the first and last state.
10 |
11 | ## Getting Started 🐛
12 |
13 | ```sh
14 | npm install react-morph
15 | # or
16 | yarn add react-morph
17 | ```
18 |
19 | Import the `useMorph` hook.
20 |
21 | ```js
22 | const morph = useMorph(options);
23 | ```
24 |
25 | Then spread the props to the elements you want to morph.
26 |
27 | ```jsx
28 |
29 | ```
30 |
31 | ```jsx
32 |
33 | ```
34 |
35 | > Make sure you have just **ONE element rendered at same time**.
36 |
37 | ## Simple Example 🦋
38 |
39 | 1. Create two states as you normally would (HTML + CSS).
40 | 2. Call `useMorph` hook.
41 | 3. Spread the elements you want to morph with `{...morph}`
42 | 4. Add and remove the element from the DOM
43 |
44 | ```js
45 | import React from 'react';
46 | import { useMorph } from 'react-morph';
47 | ```
48 |
49 | ```jsx
50 | () => {
51 | // Handle toggle state as you normally would.
52 | const [toggle, setToggle] = useState(true);
53 | const morph = useMorph();
54 |
55 | return (
56 |
57 |
setToggle(!toggle)}>Let's morph!
58 |
59 |
60 | {toggle ? (
61 |
62 | ) : (
63 |
64 | )}
65 |
66 | );
67 | };
68 | ```
69 |
70 | ## [Documentation](https://brunnolou.github.io/react-morph)
71 |
72 | Please check the [documentation](https://brunnolou.github.io/react-morph).
73 |
74 | ## Features 🌟
75 |
76 | - Simplicity
77 | - No hardcoded absolute positions
78 | - All GPU accelerated props
79 | - No layout or paint browser rendering
80 |
81 | ## Live Demos
82 |
83 | - [Hello world](https://codesandbox.io/s/yqyymqn8z1)
84 | - [Apple App Store](https://codesandbox.io/s/7ywk4o0xmj)
85 |
--------------------------------------------------------------------------------
/docz/doczrc.js:
--------------------------------------------------------------------------------
1 | import { css } from 'docz-plugin-css';
2 |
3 | export default {
4 | title: 'React Morph - Docs',
5 | base: '/react-morph/',
6 | typescript: true,
7 | files: './**/*.{md,markdown,mdx}',
8 | public: './public',
9 | menu: [
10 | { name: 'Getting Started' },
11 | { name: 'Styling' },
12 | { name: 'Api' },
13 | ],
14 | codeSandbox: false,
15 | plugins: [css({ preprocessor: 'postcss' })],
16 | themeConfig: {
17 | styles: {
18 | container: {
19 | width: ['100%', '100%', 1920],
20 | padding: ['20px', '0 40px 40px'],
21 | },
22 | },
23 | ordering: 'ascending',
24 | colors: {
25 | primary: '#00C0FF',
26 | },
27 | },
28 | };
29 |
--------------------------------------------------------------------------------
/docz/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-morph-docz",
3 | "version": "0.4.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "postinstall": "./postinstall.sh",
8 | "watch-lib": "onchange '../lib/**/*.js' -- npm run postinstall",
9 | "dev": "docz dev && npm run watch-lib",
10 | "deploy": "gh-pages -d .docz/dist",
11 | "build": "docz build"
12 | },
13 | "keywords": [],
14 | "dependencies": {
15 | "@types/react-router-dom": "^4.3.2",
16 | "@types/styled-components": "^4.1.14",
17 | "docz-plugin-css": "^0.11.0",
18 | "react": "^16.8.6",
19 | "react-dom": "^16.8.6",
20 | "react-router-dom": "^5.0.0",
21 | "styled-components": "^4.2.0"
22 | },
23 | "devDependencies": {
24 | "@types/react": "^16.8.13",
25 | "@types/react-dom": "^16.8.3",
26 | "docz": "^1.0.0",
27 | "docz-theme-default": "^1.0.0",
28 | "onchange": "^5.2.0"
29 | },
30 | "homepage": "https://brunnolou.github.io/react-morph",
31 | "repository": {
32 | "type": "git",
33 | "url": "git+https://github.com/brunnolou/react-morph.git"
34 | },
35 | "contributors": [
36 | "Bruno Lourenço"
37 | ],
38 | "license": "MIT",
39 | "bugs": {
40 | "url": "https://github.com/brunnolou/react-morph/issues"
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/docz/postinstall.sh:
--------------------------------------------------------------------------------
1 | mkdir -p ./node_modules/react-morph
2 | cp ../package.json ./node_modules/react-morph
3 | cp -r ../lib/* ./node_modules/react-morph
4 |
--------------------------------------------------------------------------------
/docz/public/sky-square.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brunnolou/react-morph/f277f639213bc32d46bc918e79deb989d8d52e6b/docz/public/sky-square.jpg
--------------------------------------------------------------------------------
/docz/public/sky-wide.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brunnolou/react-morph/f277f639213bc32d46bc918e79deb989d8d52e6b/docz/public/sky-wide.jpg
--------------------------------------------------------------------------------
/docz/public/zurich.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brunnolou/react-morph/f277f639213bc32d46bc918e79deb989d8d52e6b/docz/public/zurich.jpg
--------------------------------------------------------------------------------
/docz/src/pages/GettingStarted/Simple.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { useMorph } from 'react-morph/';
3 |
4 | const logo =
5 | 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA4NDEuOSA1OTUuMyI+ICAgIDxnIGZpbGw9IiM2MURBRkIiPiAgICAgICAgPHBhdGggZD0iTTY2Ni4zIDI5Ni41YzAtMzIuNS00MC43LTYzLjMtMTAzLjEtODIuNCAxNC40LTYzLjYgOC0xMTQuMi0yMC4yLTEzMC40LTYuNS0zLjgtMTQuMS01LjYtMjIuNC01LjZ2MjIuM2M0LjYgMCA4LjMuOSAxMS40IDIuNiAxMy42IDcuOCAxOS41IDM3LjUgMTQuOSA3NS43LTEuMSA5LjQtMi45IDE5LjMtNS4xIDI5LjQtMTkuNi00LjgtNDEtOC41LTYzLjUtMTAuOS0xMy41LTE4LjUtMjcuNS0zNS4zLTQxLjYtNTAgMzIuNi0zMC4zIDYzLjItNDYuOSA4NC00Ni45Vjc4Yy0yNy41IDAtNjMuNSAxOS42LTk5Ljk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TMuMS0xOS4zLTYuNS0yOC0xMC4yek0zMTAgNDkwYy0xMy42LTcuOC0xOS41LTM3LjUtMTQuOS03NS43IDEuMS05LjQgMi45LTE5LjMgNS4xLTI5LjQgMTkuNiA0LjggNDEgOC41IDYzLjUgMTAuOSAxMy41IDE4LjUgMjcuNSAzNS4zIDQxLjYgNTAtMzIuNiAzMC4zLTYzLjIgNDYuOS04NCA0Ni45LTQuNS0uMS04LjMtMS0xMS4zLTIuN3ptMjM3LjItNzYuMmM0LjcgMzguMi0xLjEgNjcuOS0xNC42IDc1LjgtMyAxLjgtNi45IDIuNi0xMS41IDIuNi0yMC43IDAtNTEuNC0xNi41LTg0LTQ2LjYgMTQtMTQuNyAyOC0zMS40IDQxLjMtNDkuOSAyMi42LTIuNCA0NC02LjEgNjMuNi0xMSAyLjMgMTAuMSA0LjEgMTkuOCA1LjIgMjkuMXptMzguNS02Ni43Yy04LjYgMy43LTE4IDctMjcuNyAxMC4xLTUuNy0xOS42LTEzLjItNDAtMjIuNS02MC45IDkuMi0yMC44IDE2LjYtNDEuMSAyMi4yLTYwLjYgOS45IDMuMSAxOS4zIDYuNSAyOC4xIDEwLjIgMzUuNCAxNS4xIDU4LjMgMzQuOSA1OC4zIDUwLjYtLjEgMTUuNy0yMyAzNS42LTU4LjQgNTAuNnpNMzIwLjggNzguNHoiLz4gICAgICAgIDxjaXJjbGUgY3g9IjQyMC45IiBjeT0iMjk2LjUiIHI9IjQ1LjciLz4gICAgICAgIDxwYXRoIGQ9Ik01MjAuNSA3OC4xeiIvPiAgICA8L2c+PC9zdmc+';
6 |
7 | function Simple() {
8 | const morph = useMorph();
9 | const [toggle, setToggle] = useState(false);
10 |
11 | return (
12 |
13 |
setToggle(!toggle)}>Let's morph!
14 |
15 |
16 | {toggle ? (
17 |
18 | ) : (
19 |
20 | )}
21 |
22 | );
23 | }
24 |
25 | export default Simple;
26 |
--------------------------------------------------------------------------------
/docz/src/pages/GettingStarted/curve.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Curves & Easings
3 | route: /curves-easings
4 | ---
5 |
6 | import { Playground } from 'docz';
7 | import { useState } from 'react';
8 | import { useMorph } from 'react-morph/index';
9 | import { easeInSin, easeOutSin, easeIn, easeOut } from 'react-morph/easings';
10 | import { butterfly, larva } from '../../images';
11 | import {
12 | circIn,
13 | circOut,
14 | circInOut,
15 | reversed,
16 | createMirroredEasing,
17 | } from '@popmotion/easing';
18 |
19 | # Curves & Easings
20 |
21 | ## Curves
22 |
23 | It's possible to create a curve instead of a linear translation between morph states.
24 |
25 | In order to achieve that you need to set different easings between `X` and `Y` values.
26 |
27 | ```js
28 | useMorph({
29 | easings: {
30 | translateX: easeOutSin,
31 | translateY: easeInSin,
32 | },
33 | });
34 | ```
35 |
36 | ## Demo
37 |
38 | {
39 | () => {
40 | // Handle toggle state as you normally would.
41 | const [toggle, setToggle] = useState(false);
42 | const morph = useMorph({
43 | isReversed: !toggle,
44 | easings: {
45 | translateX: easeOutSin,
46 | translateY: easeInSin,
47 | },
48 | });
49 | return (
50 |
51 |
setToggle(!toggle)}>Let's morph!
52 |
53 |
54 | {toggle &&
}
55 |
56 |
57 |
58 |
59 |
60 |
61 | {!toggle && (
62 |
68 | )}
69 |
70 |
71 | )}}
72 |
73 |
74 |
75 | ## Easings
76 |
77 | The valid CSS property keys are: `translateX`, `translateY`, `scaleX`, and `scaleY`.
78 |
79 | The value should be an easing function that **doesn't clamp** the values.
80 |
81 | React Morph provides some "safe" easing functions. You can import them like these:
82 |
83 | ```js
84 | import { easeInSin, easeOutSin, easeIn, easeOut } from 'react-morph/easings';
85 | ```
86 |
87 | ### Fine-tuning
88 |
89 | Different ease functions will result in different curve shapes.
90 | Depending on the easing and spring values you might need to fine-tune other spring properties like `restDisplacementThreshold` or `overshootClamping`
91 |
92 | ```js
93 | useMorph({
94 | spring: {
95 | restDisplacementThreshold: 0.0001,
96 | overshootClamping: true,
97 | },
98 | });
99 | ```
100 |
--------------------------------------------------------------------------------
/docz/src/pages/GettingStarted/intro.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Getting Started
3 | route: /
4 | ---
5 |
6 | import { Playground } from 'docz';
7 | import { useState } from 'react';
8 | import { useMorph } from 'react-morph/';
9 | import { butterfly, larva } from '../../images';
10 |
11 | # React Morph ️🦋
12 |
13 | #### Morphing UI transitions made simple
14 |
15 | Magically animates one element into another just by tagging the first and last state.
16 |
17 | ## Getting Started 🐛
18 |
19 | Import the `useMorph` hook.
20 |
21 | ```js
22 | import { useMorph } from 'react-morph';
23 | ```
24 |
25 | Call the hook in you function component.
26 |
27 | ```js
28 | const morph = useMorph(options);
29 | ```
30 |
31 | Then spread the props to the elements you want to morph.
32 |
33 | ```jsx
34 |
35 | ```
36 |
37 | ```jsx
38 |
39 | ```
40 |
41 | You should handle the state as you normally would for mounting and unmounting the elements.
42 |
43 | > Make sure you have just **ONE element rendered at same time**.
44 |
45 |
46 | {() => {
47 | // Handle toggle state as you normally would.
48 | const [toggle, setToggle] = useState(true)
49 | const morph = useMorph();
50 |
51 | return (
52 |
53 |
setToggle(!toggle)}>Let's morph!
54 |
55 |
56 | {toggle &&
}
57 |
58 |
59 |
60 | {!toggle &&
}
61 |
62 | )
63 | }
64 | }
65 |
66 |
67 | ## Controling the state
68 |
69 | React morph doesn't handle the state for you. There is no play or stop method.
70 |
71 | Also, it won't hide or show the elements for you. It's up to you how you want to handle it.
72 |
73 | The animation will be triggered as soon as the new element with the same `{...morph}` enters the DOM.
74 |
75 | That's why you cannot have the two state elements at the same time.
76 |
77 | The elements can use `useState`
78 |
79 | ```js
80 | {
81 | toggle ? (
82 |
83 | ) : (
84 |
85 | );
86 | }
87 | ```
88 |
89 | But also you can use `react-router`
90 |
--------------------------------------------------------------------------------
/docz/src/pages/Player/Player.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { useMorphKeys } from 'react-morph';
3 | import PlayerFull from './PlayerFull';
4 | import PlayerMini from './PlayerMini';
5 |
6 | const Player = () => {
7 | const morphs = useMorphKeys(['container', 'title', 'subtitle', 'image']);
8 |
9 | const [toggle, setToggle] = useState(false);
10 |
11 | return (
12 |
13 |
14 |
15 | {!toggle ? (
16 |
setToggle(!toggle)} />
17 | ) : (
18 | setToggle(!toggle)} />
19 | )}
20 |
21 |
22 | );
23 | };
24 |
25 | export default Player;
26 |
--------------------------------------------------------------------------------
/docz/src/pages/Player/PlayerFull.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 |
3 | const PlayerFull = ({ morphs = {}, ...props }) => {
4 | return (
5 |
6 |
7 |
8 |
9 |
15 |
16 |
17 |
18 |
19 |
23 | A Sky Full of Stars
24 |
25 |
29 | Ghost Stories
30 |
31 |
32 |
42 |
43 |
44 |
54 |
64 |
74 |
84 |
94 |
95 |
96 |
97 |
98 |
99 |
0:40
100 |
4:20
101 |
102 |
109 |
110 |
111 |
112 | );
113 | };
114 |
115 | export default PlayerFull;
116 |
--------------------------------------------------------------------------------
/docz/src/pages/Player/PlayerMini.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 |
3 | const PlayerFull = ({ morphs, ...props }) => {
4 | return (
5 |
10 |
11 |
12 |
19 |
20 |
21 |
22 |
23 |
27 | A Sky Full of Stars
28 |
29 |
33 | Ghost Stories
34 |
35 |
36 |
37 |
38 |
39 |
40 | );
41 | };
42 |
43 | export default PlayerFull;
44 |
--------------------------------------------------------------------------------
/docz/src/pages/Player/player.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Player
3 | route: /demos/player
4 | menu: Demos
5 | ---
6 |
7 | import { useState } from 'react';
8 | import { useMorph, useMorphs } from 'react-morph';
9 | import { Playground } from 'docz';
10 | import '../../utilities.css';
11 | import '../../../public/tailwind.min.css';
12 | import PlayerFull from './PlayerFull';
13 | import PlayerMini from './PlayerMini';
14 | import Player from './Player.tsx';
15 |
16 | # Player Demo
17 |
18 |
19 | {() => {
20 | const morphs = useMorphs(['container', 'title', 'subtitle', 'image']);
21 |
22 | const [toggle, setToggle] = useState(false);
23 |
24 | return (
25 |
26 | {!toggle ? (
27 |
setToggle(!toggle)} />
28 | ) : (
29 | setToggle(!toggle)} />
30 | )}
31 |
32 |
33 | )}}
34 |
35 |
36 |
37 | Design by: @shuvro_008
38 | https://tailwindcomponents.com/component/tailwind-css-audio-player
39 |
40 |
--------------------------------------------------------------------------------
/docz/src/pages/Progress/progress.mdx-:
--------------------------------------------------------------------------------
1 | ---
2 | name: Progress
3 | route: /advanced/progress
4 | menu: Advanced
5 | ---
6 |
7 | import { Playground } from 'docz';
8 | import { useState } from 'react';
9 | import { useMorph } from 'react-morph/';
10 | import { butterfly, larva } from '../../images';
11 |
12 | # Controling progress
13 |
14 |
15 | {() => {
16 | // Handle toggle state as you normally would.
17 | const [toggle, setToggle] = useState(true)
18 | const [progress, setProgress] = useState(0)
19 |
20 | const morph = useMorph({ progress: Number(progress / 100) });
21 |
22 | return (
23 |
24 |
25 |
26 | {setToggle(!toggle); setProgress(progress)}}>Let's morph!
27 |
28 |
29 | setProgress(value)}
33 | step="0.01"
34 |
35 | />
36 | {progress}%
37 |
38 |
39 |
40 | {toggle &&
}
41 |
42 |
43 |
44 |
45 | {!toggle &&
}
46 |
47 | )
48 | }
49 |
50 | }
51 |
52 |
53 |
--------------------------------------------------------------------------------
/docz/src/pages/Tests/toggle.mdx-:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brunnolou/react-morph/f277f639213bc32d46bc918e79deb989d8d52e6b/docz/src/pages/Tests/toggle.mdx-
--------------------------------------------------------------------------------
/docz/src/pages/Travel/Travel.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import './travel.css';
3 | import { useMorph, useMorphs, useFade } from 'react-morph/';
4 | import { createEaseIn } from 'react-morph/easings';
5 | import presets from 'react-morph/presets';
6 |
7 | const strongerEase = createEaseIn(2);
8 |
9 | const faces = [
10 | {
11 | username: 'brunnolou',
12 | src: 'https://avatars1.githubusercontent.com/u/2729225?s=460&v=4',
13 | },
14 | {
15 | username: 'lucalanca',
16 | src: 'https://avatars3.githubusercontent.com/u/389459?s=460&v=4',
17 | },
18 | {
19 | username: 'florianginetta',
20 | src: 'https://avatars3.githubusercontent.com/u/30113109?s=460&v=4',
21 | },
22 | {
23 | username: 'lejoe',
24 | src: 'https://avatars3.githubusercontent.com/u/1759?s=460&v=4',
25 | },
26 | ];
27 |
28 | const spring = presets.noWobble;
29 |
30 | const Travel = () => {
31 | const [toggle, go] = useState(false);
32 | const contentPlaceholderMorph = useMorph({
33 | spring,
34 | zIndex: 1,
35 | isReversed: !toggle,
36 | easings: strongerEase,
37 | });
38 | const coverMorph = useMorph({ spring, zIndex: 2 });
39 | const sepFade = useFade({ spring, isInitial: !toggle, zIndex: 4 });
40 | const titleMorph = useMorph({ spring, zIndex: 4 });
41 | const leftMorph = useMorph({ spring, zIndex: 4 });
42 | const rightMorph = useMorph({ spring, zIndex: 4 });
43 | const facesMorphs = useMorphs(faces, { spring, zIndex: 3 });
44 | const facesFades = faces.map(() =>
45 | useFade({ spring, isInitial: toggle, zIndex: 4 }),
46 | );
47 |
48 | return (
49 |
50 |
go(!toggle)}>Toggle
51 | {!toggle && (
52 |
go(true)}>
53 |
54 |
55 | Zurich
56 |
57 |
58 |
64 |
65 |
66 |
67 | Grossmünster
68 |
69 |
70 | 47.3769° N, 8.5417° E
71 |
72 |
73 |
74 | )}
75 |
76 | {!toggle && (
77 |
78 |
82 |
83 |
84 |
85 |
86 | Panorama Grossmünster limmat river
87 |
88 |
89 |
90 |
91 | {faces.map(({ src, username }, index) => (
92 |
93 |
99 |
100 | ))}
101 |
102 |
103 |
104 | )}
105 |
106 | {toggle && (
107 |
go(false)}>
108 |
115 |
116 |
117 |
118 |
119 | Grossmünster
120 |
121 |
122 | 47.3769° N, 8.5417° E
123 |
124 |
125 |
126 |
127 | Zurich
128 |
129 |
130 |
131 |
132 |
136 |
137 |
138 | {faces.map(({ src, username }, index) => (
139 |
140 |
141 |
147 |
148 |
149 |
150 | {username}
151 |
152 |
153 | ))}
154 |
155 |
156 |
157 | )}
158 |
159 | );
160 | };
161 |
162 | export default Travel;
163 |
--------------------------------------------------------------------------------
/docz/src/pages/Travel/tavel.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Travel
3 | route: /demos/travel
4 | menu: Demos
5 | ---
6 |
7 | import { Playground } from 'docz';
8 | import { useState } from 'react';
9 | import { useMorph } from 'react-morph/';
10 | import Travel from './Travel';
11 |
12 | # Travel demo
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/docz/src/pages/Travel/travel.css:
--------------------------------------------------------------------------------
1 | .accelerated {
2 | transform: translate3d(0, 0, 0);
3 | will-change: transform;
4 | }
5 |
6 | * {
7 | box-sizing: border-box;
8 | margin: 0;
9 | padding: 0;
10 | }
11 |
12 | a {
13 | cursor: pointer;
14 | }
15 |
16 | img {
17 | max-width: 100%;
18 | }
19 |
20 | body,
21 | html {
22 | height: 100%;
23 | min-height: 100%;
24 | }
25 |
26 | .body {
27 | background-image: linear-gradient(#ced8dd, #9bb1c1);
28 | color: #666;
29 | width: 100%;
30 | min-height: 700px;
31 | padding: 3rem;
32 | }
33 |
34 | p {
35 | margin: 12px 0;
36 | font-size: 14px;
37 | }
38 |
39 | .container {
40 | display: flex;
41 | justify-content: center;
42 | align-items: center;
43 | flex-direction: column;
44 | }
45 |
46 | .card {
47 | position: relative;
48 | z-index: 2;
49 | display: flex;
50 | flex-direction: column;
51 | justify-content: space-between;
52 | width: 100%;
53 | max-width: 17rem;
54 | height: 18rem;
55 | text-align: center;
56 | color: #fff;
57 | padding: 1rem;
58 | margin: 15rem 1rem 0;
59 | }
60 |
61 | .card-content-placeholder,
62 | .card-image {
63 | position: absolute;
64 | top: 0;
65 | left: 0;
66 | right: 0;
67 | bottom: 0;
68 | z-index: -1;
69 | background-size: auto 100%;
70 | background-position: center;
71 | box-shadow: 0 15px 40px -10px rgba(0, 0, 0, 0.9);
72 | border-radius: 0.5rem;
73 | }
74 | .card-content-placeholder {
75 | background: white;
76 | }
77 |
78 | .details-title,
79 | .card-title {
80 | display: inline-block;
81 | font-weight: 100;
82 | margin: 0;
83 | color: #fff;
84 | }
85 |
86 | .card-content-placeholder {
87 | z-index: -2;
88 | border-radius: 0.25rem;
89 | background: #fff;
90 | box-shadow: 0 15px 40px -10px rgba(0, 0, 0, 0.1);
91 | }
92 |
93 | .card-content {
94 | position: relative;
95 | z-index: 1;
96 | border-radius: 0.25rem;
97 | display: inline-flex;
98 | flex-direction: column;
99 | justify-content: space-between;
100 | width: 100%;
101 | max-width: 19rem;
102 | height: 12rem;
103 | margin: -4rem 1rem 1rem;
104 | padding: 1rem;
105 | font-size: 14px;
106 | text-align: left;
107 | }
108 |
109 | .card-footer {
110 | display: flex;
111 | justify-content: space-between;
112 | }
113 |
114 | .details {
115 | position: relative;
116 | top: 0;
117 | z-index: 1;
118 | display: flex;
119 | flex-direction: column;
120 | justify-content: center;
121 | max-width: 60rem;
122 | width: 100%;
123 | }
124 |
125 | .details-image {
126 | position: relative;
127 | z-index: 2;
128 | background-size: cover;
129 | background-position: center;
130 |
131 | width: 100%;
132 | height: 24rem;
133 | }
134 |
135 | .details-title {
136 | z-index: 3;
137 | display: block;
138 | text-align: center;
139 | font-weight: 100;
140 | margin-top: -6rem;
141 | }
142 |
143 | .title-large {
144 | font-size: 50px;
145 | }
146 |
147 | .details-content {
148 | position: relative;
149 | z-index: 1;
150 | padding: 1rem;
151 | }
152 |
153 | .details-toolbar {
154 | position: absolute;
155 | top: 0;
156 | left: 0;
157 | width: 100%;
158 | padding: 1rem;
159 | z-index: 3;
160 | }
161 |
162 | .details-content-placeholder {
163 | background: #fff;
164 | position: absolute;
165 | top: 0;
166 | left: 0;
167 | right: 0;
168 | bottom: 0;
169 | z-index: -1;
170 | }
171 |
172 | .users {
173 | display: flex;
174 | margin: 1rem -3rem -1rem;
175 | padding: 1rem 2rem 0;
176 | }
177 |
178 | .separator {
179 | padding: 1rem;
180 | border-bottom: 1px solid #eee;
181 | margin: 0 -2rem -1rem;
182 | }
183 |
184 | .users-item {
185 | display: block;
186 | margin-right: -0.5rem;
187 | text-align: left;
188 | display: flex;
189 | justify-content: flex-start;
190 | align-items: center;
191 | }
192 |
193 | .users-image {
194 | display: block;
195 | width: 2rem;
196 | height: 2rem;
197 | border-radius: 2rem;
198 | box-shadow: 0 2px 5px -2px rgba(0, 0, 0, 0.9);
199 | }
200 |
201 | .users-image--lg {
202 | width: 4rem;
203 | height: 4rem;
204 | }
205 |
206 | .p1 {
207 | padding: 1rem;
208 | }
209 | .m1 {
210 | margin: 1rem;
211 | }
212 |
213 | .t-center {
214 | text-align: center;
215 | }
216 | .t-left {
217 | text-align: left;
218 | }
219 |
220 | .c-white {
221 | color: #fff;
222 | }
223 |
224 | .l-inline-block {
225 | position: relative;
226 | display: inline-block;
227 | }
228 |
229 | .l-flex {
230 | display: flex;
231 | justify-content: center;
232 | }
233 |
234 | .text-container {
235 | display: flex;
236 | flex-wrap: wrap;
237 | width: 320px;
238 | margin: 0 auto;
239 | cursor: pointer;
240 | }
241 |
242 | .text-container > span {
243 | margin: 0 0.1em;
244 | }
245 |
246 | .text-container--small {
247 | justify-content: center;
248 | font-size: 30px;
249 | font-weight: bold;
250 | width: 200px;
251 | }
252 |
--------------------------------------------------------------------------------
/docz/src/pages/api/useFade.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: useFade
3 | route: /api/fade
4 | menu: Api
5 | ---
6 |
7 | import { Playground } from 'docz';
8 | import { useState } from 'react';
9 | import { useFade } from 'react-morph/';
10 | import { butterfly, larva } from '../../images';
11 |
12 | # Fade in Fade out
13 |
14 | ## Intro
15 |
16 | When creating complex morph animation some elements can simply fade in or fade out.
17 | This would make more pleasent animations since there will be less cognitive load to
18 | process all the movements.
19 |
20 | Import the `useFade` hook.
21 |
22 | ```js
23 | import { useFade } from 'react-morph';
24 | ```
25 |
26 | Call the hook in you function component.
27 |
28 | ```js
29 | const fade = useFade(options);
30 | ```
31 |
32 | Then spread the props to the elements you want to fade.
33 |
34 | ```jsx
35 |
36 | ```
37 |
38 | ## Simple fade
39 |
40 |
41 | {() => {
42 | // Handle toggle state as you normally would.
43 | const [toggle, setToggle] = useState(false)
44 | const spring = { damping: 5, stiffness: 10 };
45 | const fadeIn = useFade({ spring, isInitial: toggle, delaysRatio: 1 });
46 | const fadeOut = useFade({ spring, isInitial: !toggle });
47 |
48 | return (
49 |
50 |
setToggle(!toggle)}>Let's fade!
51 |
52 |
53 |
54 | {toggle ? (
55 |
56 | ) : (
57 |
58 | )}
59 |
60 | )}}
61 |
62 |
63 |
64 | > **⚠️ Warning: **
65 | >
66 | > Differentl than `useMorph`:
67 | >
68 | > - Don't spread the same fade into multiple elements.
69 | > - Create one for the initial state and another for the final state
70 |
71 | ## Disable initial fade
72 |
73 | Usually when you create a complex morph with some fades, we just want to fade in/out when toggle.
74 | In order to disable the initial fade in on page load you can toggle the option `isInitial`.
75 |
76 | Normally you will set the `isInitial` option on the initial state and disable it to the final state.
77 |
78 | ```js
79 | useFade({ isInitial: toggle });
80 | ```
81 |
82 | ## Delay
83 |
84 | By default `useFade` delays the fade in and speeds up the fade out.
85 | This is expecially useful to use with `useMorph`.
86 |
87 | To update this behaviour you can set the option `delaysRatio`.
88 | The default value is `0.1`. To disable the delay set `delaysRatio` to `1`.
89 |
--------------------------------------------------------------------------------
/docz/src/pages/api/useMorphKeys.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: useMorphKeys
3 | route: /api/useMorphKeys
4 | menu: Api
5 | ---
6 |
7 | # `useMorphKeys`
8 |
9 | ```js
10 | import { useMorphKeys } from 'react-morph';
11 | ```
12 |
13 | ### `useMorphKeys(string[], options: MorphOptions)`
14 |
15 | Return an **object** with multiple morphs with the given keys.
16 | Also, each morph will receive an incremental `zIndex` option prop.
17 |
18 | ```js
19 | const Index = () => {
20 | const morphs = useMorphKeys(['key1', 'key2']);
21 | // morphs = { key1: …, key2: … }
22 |
23 | return (
24 |
25 | {toggle && }
26 | {!toggle && }
27 |
28 | );
29 | };
30 |
31 | const Item = ({ morphs }) => (
32 |
35 | );
36 |
37 | const Details = ({ morphs }) => (
38 |
39 |
Foo
40 |
41 | );
42 | ```
43 |
--------------------------------------------------------------------------------
/docz/src/pages/api/useMorphList.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: useMorphList
3 | route: /api/useMorphList
4 | menu: Api
5 | ---
6 |
7 | # `useMorphList`
8 |
9 | ```js
10 | import { useMorphList } from 'react-morph';
11 | ```
12 |
13 | ### `useMorphList(any[] | number, options: MorphOptions)`
14 |
15 | Return an **array** with multiple morphs with the same length of the given array or the length of the given number.
16 | Also, each morph will receive an incremental `zIndex` option prop.
17 |
18 | ```js
19 | const myItems = [{ name: 'Foo' }, { name: 'bar' }];
20 | const morphs = useMorphList(myItems);
21 |
22 |
23 | {myItems.map((user, index) => (
24 |
25 | {isExpanded && {user.name} }
26 | {isExpanded && {user.name} }
27 |
28 | ))}
29 | ;
30 | ```
31 |
--------------------------------------------------------------------------------
/docz/src/pages/demos/docs.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Examples
3 | route: /demos/examples
4 | menu: Demos
5 | ---
6 |
7 | import { Playground } from 'docz';
8 |
9 | # Live Demos
10 |
11 | ## [Hello world](https://codesandbox.io/s/yqyymqn8z1)
12 |
13 |
25 |
26 | ## [Apple App Store](https://codesandbox.io/s/7ywk4o0xmj)
27 |
28 | React Router page animation.
29 |
30 |
42 |
43 | ## [Player](https://codesandbox.io/s/jpnq33q47w)
44 |
45 | React Router page animation.
46 |
47 |
59 |
--------------------------------------------------------------------------------
/docz/src/pages/options.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Options
3 | route: /api/options
4 | menu: Api
5 | ---
6 |
7 | # Options
8 |
9 | ## Default options
10 |
11 | ```js
12 | {
13 | keepFrom: false,
14 | type: 'morph',
15 | getMargins: false,
16 | portalElement: document.body, // Where cloned elements will be placed.
17 | spring: {
18 | damping: 26,
19 | mass: 1,
20 | stiffness: 180,
21 | },
22 | easings: linear // OR: { translateX: easeOutSin, translateY: easeInSin },
23 | isReversed: false, // Used for reversing the easings curves.
24 | }
25 | ```
26 |
27 | ## Spring
28 |
29 | ```js
30 | {
31 | // The spring stiffness coefficient.
32 | stiffness?: number;
33 | // Defines how the spring’s motion should be damped due to the forces of friction.
34 | damping?: number;
35 | // The mass of the object attached to the end of the spring.
36 | mass?: number;
37 | // Whether or not the spring allows "overdamping" (a damping ratio > 1). Defaults to false.
38 | allowsOverdamping?: boolean;
39 | // False when overshooting is allowed, true when it is not. Defaults to false.
40 | overshootClamping?: boolean;
41 | // When spring's velocity is below `restVelocityThreshold`, it is at rest. Defaults to .001.
42 | restVelocityThreshold?: number;
43 | // When the spring's displacement (current value) is below `restDisplacementThreshold`, it is at rest. Defaults to .001.
44 | restDisplacementThreshold?: number;
45 | }
46 | ```
47 |
48 | Spring physics values from [wobble](https://github.com/skevy/wobble#configuration) micro-library.
49 |
--------------------------------------------------------------------------------
/docz/src/pages/styling/styling.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | export const H1Block = () => (
4 |
9 | This is an h1
10 |
11 | );
12 |
13 | export const H1Inline = () => (
14 |
20 | This is an h1
21 |
22 | );
23 |
--------------------------------------------------------------------------------
/docz/src/pages/styling/styling.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Styling
3 | route: /styling
4 | ---
5 |
6 | import { Playground } from 'docz';
7 | import { H1Block, H1Inline } from './styling';
8 |
9 | # Styling
10 |
11 | You can style your components with whatever you like.
12 | You can use **inline styles**, **CSS** class names or a **CSS-in-JS** solution like Styled Components.
13 |
14 | ### Caveats
15 |
16 | Since React Morph rely on `getBoundingClientRect` there's a few things you should know.
17 |
18 | ## Whitespace
19 |
20 | You need to remove extra whitespace, to match the real element's width.
21 | For example, `block` elements like an `h1` don't have intuitive size:
22 |
23 |
24 | {() => {
25 | return (
26 |
31 | This is an h1
32 |
33 | );
34 | }}
35 |
36 |
37 | To solve this we can style it with `display: inline-block`:
38 |
39 |
40 | {() => {
41 | return (
42 |
48 | This is an h1
49 |
50 | );
51 | }}
52 |
53 |
54 | Another way is by wrapping with flexbox `display: flex`:
55 |
56 |
57 | {() => {
58 | return (
59 |
66 |
71 | This is an h1
72 |
73 |
78 | This is another one
79 |
80 |
81 | );
82 | }}
83 |
84 |
85 | ## Margins
86 |
87 | Margins also create extra white space.
88 | You can wrap the element and add the margin to it.
89 |
90 | ```js
91 | // Don't
92 |
93 | …
94 |
95 | ```
96 |
97 | ```js
98 | // Do
99 |
102 | ```
103 |
104 | Or you can make sure to **match the margins in both states**.
105 |
106 | ```js
107 | // Do
108 | {
109 | toggle ? (
110 |
111 | ) : (
112 |
113 | );
114 | }
115 | ```
116 |
117 | ### Other
118 |
119 | List items could be miscalculated; a simple solution is: `list-style: none;`.
120 |
--------------------------------------------------------------------------------
/docz/src/utilities.css:
--------------------------------------------------------------------------------
1 | .object-cover {
2 | object-fit: cover;
3 | }
4 |
--------------------------------------------------------------------------------
/docz/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "target": "es2017",
5 | "module": "es2015",
6 | "moduleResolution": "node",
7 | "inlineSourceMap": true,
8 | "allowSyntheticDefaultImports": true,
9 | "esModuleInterop": true,
10 |
11 | "jsx": "react",
12 | "strict": true /* Enable all strict type-checking options. */,
13 |
14 | /* Strict Type-Checking Options */
15 | "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
16 | "strictNullChecks": true /* Enable strict null checks. */,
17 | "strictFunctionTypes": true /* Enable strict checking of function types. */,
18 | "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
19 | "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
20 | "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
21 |
22 | /* Additional Checks */
23 | "noUnusedLocals": true /* Report errors on unused locals. */,
24 | "noUnusedParameters": false /* Report errors on unused parameters. */,
25 | "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
26 | "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
27 |
28 | /* Debugging Options */
29 | "traceResolution": false /* Report module resolution log messages. */,
30 | "listEmittedFiles": false /* Print names of generated files part of the compilation. */,
31 | "listFiles": false /* Print names of files part of the compilation. */,
32 | "pretty": true /* Stylize errors and messages using color and context. */,
33 |
34 | /* Experimental Options */
35 | // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
36 | // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
37 |
38 | "lib": ["es2017", "dom"]
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/examples/react-morph-simple.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brunnolou/react-morph/f277f639213bc32d46bc918e79deb989d8d52e6b/examples/react-morph-simple.gif
--------------------------------------------------------------------------------
/examples/react-morph.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brunnolou/react-morph/f277f639213bc32d46bc918e79deb989d8d52e6b/examples/react-morph.gif
--------------------------------------------------------------------------------
/lib/Morph.d.ts:
--------------------------------------------------------------------------------
1 | declare const Morph: ({ children, ...props }: {
2 | [x: string]: any;
3 | children: any;
4 | }) => any;
5 | export default Morph;
6 |
--------------------------------------------------------------------------------
/lib/Morph.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __rest = (this && this.__rest) || function (s, e) {
3 | var t = {};
4 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5 | t[p] = s[p];
6 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
7 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
8 | t[p[i]] = s[p[i]];
9 | return t;
10 | };
11 | Object.defineProperty(exports, "__esModule", { value: true });
12 | var React = require("react");
13 | var useMorph_1 = require("./useMorph");
14 | var useFadeIn = function () {
15 | return function () { return ({}); };
16 | };
17 | var useHide = function () {
18 | return function () { return ({}); };
19 | };
20 | var Morph = function (_a) {
21 | var children = _a.children, props = __rest(_a, ["children"]);
22 | var morph = useMorph_1.default();
23 | var fadeIn = useFadeIn();
24 | var hide = useHide();
25 | return React.Children.only(children({
26 | from: morph,
27 | to: morph,
28 | fadeIn: fadeIn,
29 | fadeOut: fadeIn,
30 | hide: hide,
31 | }));
32 | };
33 | exports.default = Morph;
34 | //# sourceMappingURL=Morph.js.map
--------------------------------------------------------------------------------
/lib/Morph.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"Morph.js","sourceRoot":"","sources":["../src/Morph.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA+B;AAC/B,uCAAkC;AAElC,IAAM,SAAS,GAAG;IAChB,OAAO,cAAM,OAAA,CAAC,EAAE,CAAC,EAAJ,CAAI,CAAC;AACpB,CAAC,CAAC;AAEF,IAAM,OAAO,GAAG;IACd,OAAO,cAAM,OAAA,CAAC,EAAE,CAAC,EAAJ,CAAI,CAAC;AACpB,CAAC,CAAC;AAEF,IAAM,KAAK,GAAG,UAAC,EAAsB;IAApB,IAAA,sBAAQ,EAAE,gCAAQ;IACjC,IAAM,KAAK,GAAG,kBAAQ,EAAE,CAAC;IACzB,IAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,IAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IAEvB,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,CACxB,QAAQ,CAAC;QACP,IAAI,EAAE,KAAK;QACX,EAAE,EAAE,KAAK;QAET,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,MAAM;QAEf,IAAI,EAAE,IAAI;KACX,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,KAAK,CAAC"}
--------------------------------------------------------------------------------
/lib/easings.d.ts:
--------------------------------------------------------------------------------
1 | import { Easing } from 'types';
2 | export declare const createEaseIn: (power: number) => (t: number) => number;
3 | export declare const createEaseOut: (power: number) => (t: number) => number;
4 | export declare const createEaseInOut: (p: any) => (t: any) => number;
5 | export declare const createReversed: (easing: Easing) => (t: number) => number;
6 | export declare const easeInSin: (t: number) => number;
7 | export declare const easeOutSin: (t: number) => number;
8 | export declare const easeInOutSin: (t: number) => number;
9 | export declare const easeIn: (t: number) => number;
10 | export declare const easeOut: (t: number) => number;
11 | export declare const easeInOut: (t: any) => number;
12 | export declare const linear: (x: number) => number;
13 |
--------------------------------------------------------------------------------
/lib/easings.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | // Credits to: https://gist.github.com/gre/1650294
4 | exports.createEaseIn = function (power) { return function (t) {
5 | return Math.pow(t, power);
6 | }; };
7 | exports.createEaseOut = function (power) { return function (t) {
8 | return 1 - Math.abs(Math.pow(t - 1, power));
9 | }; };
10 | exports.createEaseInOut = function (p) { return function (t) {
11 | return t < 0.5 ? exports.createEaseIn(p)(t * 2) / 2 : exports.createEaseOut(p)(t * 2 - 1) / 2 + 0.5;
12 | }; };
13 | exports.createReversed = function (easing) { return function (t) { return 1 - easing(1 - t); }; };
14 | exports.easeInSin = function (t) {
15 | return 1 + Math.sin((Math.PI / 2) * t - Math.PI / 2);
16 | };
17 | exports.easeOutSin = function (t) { return Math.sin((Math.PI / 2) * t); };
18 | exports.easeInOutSin = function (t) {
19 | return (1 + Math.sin(Math.PI * t - Math.PI / 2)) / 2;
20 | };
21 | exports.easeIn = exports.createEaseIn(2);
22 | exports.easeOut = exports.createEaseOut(2);
23 | exports.easeInOut = exports.createEaseInOut(2);
24 | exports.linear = function (x) { return x; };
25 | //# sourceMappingURL=easings.js.map
--------------------------------------------------------------------------------
/lib/easings.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"easings.js","sourceRoot":"","sources":["../src/easings.ts"],"names":[],"mappings":";;AAEA,kDAAkD;AAErC,QAAA,YAAY,GAAG,UAAC,KAAa,IAAK,OAAA,UAAC,CAAS;IACvD,OAAA,IAAI,CAAC,GAAG,CAAC,CAAC,E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AG,CAAC,CAAC,CAAC,GAAG,CAAC;AAA7C,CAA6C,CAAC;AAEnC,QAAA,MAAM,GAAG,oBAAY,CAAC,CAAC,CAAC,CAAC;AACzB,QAAA,OAAO,GAAG,qBAAa,CAAC,CAAC,CAAC,CAAC;AAC3B,QAAA,SAAS,GAAG,uBAAe,CAAC,CAAC,CAAC,CAAC;AAE/B,QAAA,MAAM,GAAG,UAAC,CAAS,IAAK,OAAA,CAAC,EAAD,CAAC,CAAC"}
--------------------------------------------------------------------------------
/lib/index.d.ts:
--------------------------------------------------------------------------------
1 | export { default as useMorph } from './useMorph';
2 | export { default as useMorphs } from './useMorphs';
3 | export { default as useMorphKeys } from './useMorphs';
4 | export { default as useMorphList } from './useMorphList';
5 | export { default as useFade } from './useFade';
6 | export { default as presets } from './presets';
7 |
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | var useMorph_1 = require("./useMorph");
4 | exports.useMorph = useMorph_1.default;
5 | var useMorphs_1 = require("./useMorphs");
6 | exports.useMorphs = useMorphs_1.default;
7 | var useMorphs_2 = require("./useMorphs");
8 | exports.useMorphKeys = useMorphs_2.default;
9 | var useMorphList_1 = require("./useMorphList");
10 | exports.useMorphList = useMorphList_1.default;
11 | var useFade_1 = require("./useFade");
12 | exports.useFade = useFade_1.default;
13 | var presets_1 = require("./presets");
14 | exports.presets = presets_1.default;
15 | //# sourceMappingURL=index.js.map
--------------------------------------------------------------------------------
/lib/index.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,uCAAiD;AAAxC,8BAAA,OAAO,CAAY;AAC5B,yCAAmD;AAA1C,gCAAA,OAAO,CAAa;AAC7B,yCAAsD;AAA7C,mCAAA,OAAO,CAAgB;AAChC,+CAAyD;AAAhD,sCAAA,OAAO,CAAgB;AAChC,qCAA+C;AAAtC,4BAAA,OAAO,CAAW;AAC3B,qCAA+C;AAAtC,4BAAA,OAAO,CAAW"}
--------------------------------------------------------------------------------
/lib/morphTransition.d.ts:
--------------------------------------------------------------------------------
1 | import { SpringListenerFn } from 'wobble';
2 | import { MorphOptions } from './types';
3 | declare type Options = {
4 | from: HTMLElement;
5 | to: HTMLElement;
6 | rectFrom: CSSStyleDeclaration;
7 | rectTo: CSSStyleDeclaration;
8 | fromValue?: number;
9 | initialVelocity?: number;
10 | onUpdate?: SpringListenerFn;
11 | onStart?: SpringListenerFn;
12 | onStop?: SpringListenerFn;
13 | willBack?: boolean;
14 | options: MorphOptions;
15 | };
16 | export default function morphTransition({ from, to, rectFrom, rectTo, fromValue, initialVelocity, onUpdate, onStart, onStop, willBack, options, }: Options): {
17 | cleanup: () => void;
18 | setProgress: (progress: number) => void;
19 | };
20 | export {};
21 |
--------------------------------------------------------------------------------
/lib/morphTransition.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __assign = (this && this.__assign) || function () {
3 | __assign = Object.assign || function(t) {
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
5 | s = arguments[i];
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 | t[p] = s[p];
8 | }
9 | return t;
10 | };
11 | return __assign.apply(this, arguments);
12 | };
13 | Object.defineProperty(exports, "__esModule", { value: true });
14 | var wobble_1 = require("wobble");
15 | var popcorn_1 = require("@popmotion/popcorn");
16 | var util_1 = require("./util");
17 | var resetTranslate = {
18 | translateX: 0,
19 | translateY: 0,
20 | scaleX: 1,
21 | scaleY: 1,
22 | };
23 | var ease = popcorn_1.cubicBezier(0.9, 0.9, 0.37, 0.98);
24 | var easeRev = popcorn_1.reversed(ease);
25 | var easeInOut = popcorn_1.cubicBezier(0.5, 0.5, 0, 1);
26 | var delaysRatio = 0.1;
27 | var halfClampEnd = util_1.clamp(1 - delaysRatio, 1);
28 | var halfClampStart = util_1.clamp(0, delaysRatio);
29 | var easeFast = function (x) {
30 | return easeInOut(Number(popcorn_1.interpolate([1 - delaysRatio, 1], [0, 1])(halfClampEnd(x))));
31 | };
32 | var easeSlow = function (x) {
33 | return easeInOut(Number(popcorn_1.interpolate([0, delaysRatio], [0, 1])(halfClampStart(x))));
34 | };
35 | function morphTransition(_a) {
36 | var from = _a.from, to = _a.to, rectFrom = _a.rectFrom, rectTo = _a.rectTo, _b = _a.fromValue, fromValue = _b === void 0 ? 0 : _b, initialVelocity = _a.initialVelocity, _c = _a.onUpdate, onUpdate = _c === void 0 ? function () { } : _c, _d = _a.onStart, onStart = _d === void 0 ? function () { } : _d, _e = _a.onStop, onStop = _e === void 0 ? function () { } : _e, willBack = _a.willBack, options = _a.options;
37 | var spring = new wobble_1.Spring(__assign({ fromValue: fromValue,
38 | initialVelocity: initialVelocity, toValue: 1 }, options.spring));
39 | var fromDiffStyle = util_1.diffRect(rectFrom, rectTo);
40 | var toDiffStyle = util_1.diffRect(rectTo, rectFrom);
41 | var fromContainer = util_1.cloneElement(from, options);
42 | var toContainer = util_1.cloneElement(to, options);
43 | // hideInnerMorph(toContainer);
44 | // hideInnerMorph(fromContainer);
45 | to.style.visibility = 'hidden';
46 | to.style.pointerEvents = 'none';
47 | from.style.visibility = 'hidden';
48 | from.style.pointerEvents = 'none';
49 | util_1.applyOverlayStyle(toContainer, rectTo);
50 | util_1.applyOverlayStyle(fromContainer, rectFrom);
51 | var toFLIP = util_1.interpolateObject(fromDiffStyle, resetTranslate, options);
52 | var fromFLIP = util_1.interpolateObject(resetTranslate, toDiffStyle, options);
53 | var toFade = util_1.lerp(0, 1, true);
54 | var fromFade = util_1.lerp(1, 0, true);
55 | var isDeleted = false;
56 | var onProgress = function (p) {
57 | switch (options.type) {
58 | case 'morph':
59 | default:
60 | toContainer.style.opacity = String(toFade(ease(p)));
61 | fromContainer.style.opacity = String(fromFade(easeRev(p)));
62 | toContainer.style.transform = util_1.getTransformString(toFLIP(p));
63 | fromContainer.style.transform = util_1.getTransformString(fromFLIP(p));
64 | }
65 | };
66 | spring
67 | .onStart(onStart)
68 | .onUpdate(function (s) {
69 | var p = s.currentValue;
70 | onProgress(p);
71 | onUpdate(s);
72 | })
73 | .onStop(function (s) {
74 | if (s.currentValue === 0 || s.currentValue === 1) {
75 | onStop(s);
76 | cleanup();
77 | }
78 | });
79 | if (typeof options.progress === 'undefined') {
80 | spring.start();
81 | }
82 | else {
83 | onProgress(options.progress);
84 | }
85 | var setProgress = function (progress) {
86 | onProgress(progress);
87 | if (progress === 0 || progress === 1) {
88 | onStop(null);
89 | // cleanup();
90 | }
91 | };
92 | var cleanup = function () {
93 | if (isDeleted)
94 | return;
95 | if (options.portalElement) {
96 | options.portalElement.removeChild(toContainer);
97 | options.portalElement.removeChild(fromContainer);
98 | }
99 | to.style.visibility = ''; // show original to
100 | to.style.pointerEvents = ''; // show original to
101 | if (!willBack) {
102 | // show original from
103 | from.style.pointerEvents = '';
104 | from.style.visibility = '';
105 | }
106 | isDeleted = true;
107 | };
108 | return { cleanup: cleanup, setProgress: setProgress };
109 | }
110 | exports.default = morphTransition;
111 | //# sourceMappingURL=morphTransition.js.map
--------------------------------------------------------------------------------
/lib/morphTransition.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"morphTransition.js","sourceRoot":"","sources":["../src/morphTransition.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iCAAkD;AAClD,8CAAwE;AAExE,+BAQgB;AAGhB,IAAM,cAAc,GAAG;IACrB,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;CACV,CAAC;AAEF,IAAM,IAAI,GAAG,qBAAW,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC/C,IAAM,OAAO,GAAG,kBAAQ,CAAC,IAAI,CAAC,CAAC;AAC/B,IAAM,SAAS,GAAG,qBAAW,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAE9C,IA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;YACrB,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,EAAE,CAAC;YAC9B,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,EAAE,CAAC;SAC5B;QACD,SAAS,GAAG,IAAI,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO,EAAE,OAAO,SAAA,EAAE,WAAW,aAAA,EAAE,CAAC;AAClC,CAAC;AAtGD,kCAsGC"}
--------------------------------------------------------------------------------
/lib/presets.d.ts:
--------------------------------------------------------------------------------
1 | export declare const noWobble: {
2 | stiffness: number;
3 | damping: number;
4 | };
5 | export declare const gentle: {
6 | stiffness: number;
7 | damping: number;
8 | };
9 | export declare const wobbly: {
10 | stiffness: number;
11 | damping: number;
12 | };
13 | export declare const stiff: {
14 | stiffness: number;
15 | damping: number;
16 | };
17 | export declare const slowMo: {
18 | stiffness: number;
19 | damping: number;
20 | };
21 | declare const _default: {
22 | noWobble: {
23 | stiffness: number;
24 | damping: number;
25 | };
26 | gentle: {
27 | stiffness: number;
28 | damping: number;
29 | };
30 | wobbly: {
31 | stiffness: number;
32 | damping: number;
33 | };
34 | stiff: {
35 | stiffness: number;
36 | damping: number;
37 | };
38 | slowMo: {
39 | stiffness: number;
40 | damping: number;
41 | };
42 | };
43 | export default _default;
44 |
--------------------------------------------------------------------------------
/lib/presets.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | // credits to react-motion
4 | exports.noWobble = { stiffness: 170, damping: 26 };
5 | exports.gentle = { stiffness: 120, damping: 14 };
6 | exports.wobbly = { stiffness: 180, damping: 12 };
7 | exports.stiff = { stiffness: 210, damping: 20 };
8 | exports.slowMo = { stiffness: 5, damping: 30 };
9 | exports.default = {
10 | noWobble: exports.noWobble,
11 | gentle: exports.gentle,
12 | wobbly: exports.wobbly,
13 | stiff: exports.stiff,
14 | slowMo: exports.slowMo,
15 | };
16 | //# sourceMappingURL=presets.js.map
--------------------------------------------------------------------------------
/lib/presets.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"presets.js","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":";;AAAA,0BAA0B;AACb,QAAA,QAAQ,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAC3C,QAAA,MAAM,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACzC,QAAA,MAAM,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACzC,QAAA,KAAK,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACxC,QAAA,MAAM,GAAG,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEpD,kBAAe;IACb,QAAQ,kBAAA;IACR,MAAM,gBAAA;IACN,MAAM,gBAAA;IACN,KAAK,eAAA;IACL,MAAM,gBAAA;CACP,CAAC"}
--------------------------------------------------------------------------------
/lib/useFade.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import { FadeOptions } from './types';
3 | export default function useFade(opts?: FadeOptions): {
4 | ({ style, ...extra }?: {
5 | style?: {};
6 | }): {
7 | style: {
8 | alignContent?: string;
9 | alignItems?: string;
10 | alignSelf?: string;
11 | animationDelay?: string;
12 | animationDirection?: string;
13 | animationDuration?: string;
14 | animationFillMode?: string;
15 | animationIterationCount?: string | number;
16 | animationName?: string;
17 | animationPlayState?: string;
18 | animationTimingFunction?: string;
19 | appearance?: import("csstype").AppearanceProperty;
20 | backdropFilter?: string;
21 | backfaceVisibility?: import("csstype").BackfaceVisibilityProperty;
22 | backgroundAttachment?: string;
23 | backgroundBlendMode?: string;
24 | backgroundClip?: string;
25 | backgroundColor?: string;
26 | backgroundImage?: string;
27 | backgroundOrigin?: string;
28 | backgroundPosition?: string | number;
29 | backgroundPositionX?: string | number;
30 | backgroundPositionY?: string | number;
31 | backgroundRepeat?: string;
32 | backgroundSize?: string | number;
33 | blockOverflow?: string;
34 | blockSize?: string | number;
35 | borderBlockColor?: string;
36 | borderBlockEndColor?: string;
37 | borderBlockEndStyle?: import("csstype").BorderBlockEndStyleProperty;
38 | borderBlockEndWidth?: string | number;
39 | borderBlockStartColor?: string;
40 | borderBlockStartStyle?: import("csstype").BorderBlockEndStyleProperty;
41 | borderBlockStartWidth?: string | number;
42 | borderBlockStyle?: import("csstype").BorderBlockEndStyleProperty;
43 | borderBlockWidth?: string | number;
44 | borderBottomColor?: string;
45 | borderBottomLeftRadius?: string | number;
46 | borderBottomRightRadius?: string | number;
47 | borderBottomStyle?: import("csstype").BorderBlockEndStyleProperty;
48 | borderBottomWidth?: string | number;
49 | borderCollapse?: import("csstype").BorderCollapseProperty;
50 | borderEndEndRadius?: string | number;
51 | borderEndStartRadius?: string | number;
52 | borderImageOutset?: string | number;
53 | borderImageRepeat?: string;
54 | borderImageSlice?: string | number;
55 | borderImageSource?: string;
56 | borderImageWidth?: string | number;
57 | borderInlineColor?: string;
58 | borderInlineEndColor?: string;
59 | borderInlineEndStyle?: import("csstype").BorderBlockEndStyleProperty;
60 | borderInlineEndWidth?: string | number;
61 | borderInlineStartColor?: string;
62 | borderInlineStartStyle?: import("csstype").BorderBlockEndStyleProperty;
63 | borderInlineStartWidth?: string | number;
64 | borderInlineStyle?: import("csstype").BorderBlockEndStyleProperty;
65 | borderInlineWidth?: string | number;
66 | borderLeftColor?: string;
67 | borderLeftStyle?: import("csstype").BorderBlockEndStyleProperty;
68 | borderLeftWidth?: string | number;
69 | borderRightColor?: string;
70 | borderRightStyle?: import("csstype").BorderBlockEndStyleProperty;
71 | borderRightWidth?: string | number;
72 | borderSpacing?: string | number;
73 | borderStartEndRadius?: string | number;
74 | borderStartStartRadius?: string | number;
75 | borderTopColor?: string;
76 | borderTopLeftRadius?: string | number;
77 | borderTopRightRadius?: string | number;
78 | borderTopStyle?: import("csstype").BorderBlockEndStyleProperty;
79 | borderTopWidth?: string | number;
80 | bottom?: string | number;
81 | boxDecorationBreak?: import("csstype").BoxDecorationBreakProperty;
82 | boxShadow?: string;
83 | boxSizing?: import("csstype").BoxSizingProperty;
84 | breakAfter?: import("csstype").BreakAfterProperty;
85 | breakBefore?: import("csstype").BreakAfterProperty;
86 | breakInside?: import("csstype").BreakInsideProperty;
87 | captionSide?: import("csstype").CaptionSideProperty;
88 | caretColor?: string;
89 | clear?: import("csstype").ClearProperty;
90 | clipPath?: string;
91 | color?: string;
92 | colorAdjust?: import("csstype").ColorAdjustProperty;
93 | columnCount?: import("csstype").ColumnCountProperty;
94 | columnFill?: import("csstype").ColumnFillProperty;
95 | columnGap?: string | number;
96 | columnRuleColor?: string;
97 | columnRuleStyle?: string;
98 | columnRuleWidth?: string | number;
99 | columnSpan?: import("csstype").ColumnSpanProperty;
100 | columnWidth?: string | number;
101 | contain?: string;
102 | content?: string;
103 | counterIncrement?: string;
104 | counterReset?: string;
105 | cursor?: string;
106 | direction?: import("csstype").DirectionProperty;
107 | display?: string;
108 | emptyCells?: import("csstype").EmptyCellsProperty;
109 | filter?: string;
110 | flexBasis?: string | number;
111 | flexDirection?: import("csstype").FlexDirectionProperty;
112 | flexGrow?: import("csstype").GlobalsNumber;
113 | flexShrink?: import("csstype").GlobalsNumber;
114 | flexWrap?: import("csstype").FlexWrapProperty;
115 | float?: import("csstype").FloatProperty;
116 | fontFamily?: string;
117 | fontFeatureSettings?: string;
118 | fontKerning?: import("csstype").FontKerningProperty;
119 | fontLanguageOverride?: string;
120 | fontOpticalSizing?: import("csstype").FontOpticalSizingProperty;
121 | fontSize?: string | number;
122 | fontSizeAdjust?: import("csstype").FontSizeAdjustProperty;
123 | fontStretch?: string;
124 | fontStyle?: string;
125 | fontSynthesis?: string;
126 | fontVariant?: string;
127 | fontVariantCaps?: import("csstype").FontVariantCapsProperty;
128 | fontVariantEastAsian?: string;
129 | fontVariantLigatures?: string;
130 | fontVariantNumeric?: string;
131 | fontVariantPosition?: import("csstype").FontVariantPositionProperty;
132 | fontVariationSettings?: string;
133 | fontWeight?: import("csstype").FontWeightProperty;
134 | gridAutoColumns?: string | number;
135 | gridAutoFlow?: string;
136 | gridAutoRows?: string | number;
137 | gridColumnEnd?: string | number;
138 | gridColumnStart?: string | number;
139 | gridRowEnd?: string | number;
140 | gridRowStart?: string | number;
141 | gridTemplateAreas?: string;
142 | gridTemplateColumns?: string | number;
143 | gridTemplateRows?: string | number;
144 | hangingPunctuation?: string;
145 | height?: string | number;
146 | hyphens?: import("csstype").HyphensProperty;
147 | imageOrientation?: string;
148 | imageRendering?: import("csstype").ImageRenderingProperty;
149 | imageResolution?: string;
150 | initialLetter?: string | number;
151 | inlineSize?: string | number;
152 | insetBlockEnd?: string | number;
153 | insetBlockStart?: string | number;
154 | insetInlineEnd?: string | number;
155 | insetInlineStart?: string | number;
156 | isolation?: import("csstype").IsolationProperty;
157 | justifyContent?: string;
158 | justifyItems?: string;
159 | justifySelf?: string;
160 | left?: string | number;
161 | letterSpacing?: string | number;
162 | lineBreak?: import("csstype").LineBreakProperty;
163 | lineHeight?: string | number;
164 | lineHeightStep?: string | number;
165 | listStyleImage?: string;
166 | listStylePosition?: import("csstype").ListStylePositionProperty;
167 | listStyleType?: string;
168 | marginBlock?: string | number;
169 | marginBlockEnd?: string | number;
170 | marginBlockStart?: string | number;
171 | marginBottom?: string | number;
172 | marginInline?: string | number;
173 | marginInlineEnd?: string | number;
174 | marginInlineStart?: string | number;
175 | marginLeft?: string | number;
176 | marginRight?: string | number;
177 | marginTop?: string | number;
178 | maskBorderMode?: import("csstype").MaskBorderModeProperty;
179 | maskBorderOutset?: string | number;
180 | maskBorderRepeat?: string;
181 | maskBorderSlice?: string | number;
182 | maskBorderSource?: string;
183 | maskBorderWidth?: string | number;
184 | maskClip?: string;
185 | maskComposite?: string;
186 | maskImage?: string;
187 | maskMode?: string;
188 | maskOrigin?: string;
189 | maskPosition?: string | number;
190 | maskRepeat?: string;
191 | maskSize?: string | number;
192 | maskType?: import("csstype").MaskBorderModeProperty;
193 | maxBlockSize?: string | number;
194 | maxHeight?: string | number;
195 | maxInlineSize?: string | number;
196 | maxLines?: import("csstype").FontSizeAdjustProperty;
197 | maxWidth?: string | number;
198 | minBlockSize?: string | number;
199 | minHeight?: string | number;
200 | minInlineSize?: string | number;
201 | minWidth?: string | number;
202 | mixBlendMode?: import("csstype").MixBlendModeProperty;
203 | motionDistance?: string | number;
204 | motionPath?: string;
205 | motionRotation?: string;
206 | objectFit?: import("csstype").ObjectFitProperty;
207 | objectPosition?: string | number;
208 | offsetAnchor?: string | number;
209 | offsetDistance?: string | number;
210 | offsetPath?: string;
211 | offsetPosition?: string | number;
212 | offsetRotate?: string;
213 | offsetRotation?: string;
214 | opacity?: import("csstype").GlobalsNumber;
215 | order?: import("csstype").GlobalsNumber;
216 | orphans?: import("csstype").GlobalsNumber;
217 | outlineColor?: string;
218 | outlineOffset?: string | number;
219 | outlineStyle?: string;
220 | outlineWidth?: string | number;
221 | overflow?: string;
222 | overflowAnchor?: import("csstype").FontOpticalSizingProperty;
223 | overflowBlock?: string;
224 | overflowClipBox?: import("csstype").OverflowClipBoxProperty;
225 | overflowInline?: string;
226 | overflowWrap?: import("csstype").OverflowWrapProperty;
227 | overflowX?: import("csstype").OverflowXProperty;
228 | overflowY?: import("csstype").OverflowXProperty;
229 | overscrollBehavior?: string;
230 | overscrollBehaviorX?: import("csstype").OverscrollBehaviorXProperty;
231 | overscrollBehaviorY?: import("csstype").OverscrollBehaviorXProperty;
232 | paddingBlock?: string | number;
233 | paddingBlockEnd?: string | number;
234 | paddingBlockStart?: string | number;
235 | paddingBottom?: string | number;
236 | paddingInline?: string | number;
237 | paddingInlineEnd?: string | number;
238 | paddingInlineStart?: string | number;
239 | paddingLeft?: string | number;
240 | paddingRight?: string | number;
241 | paddingTop?: string | number;
242 | pageBreakAfter?: import("csstype").PageBreakAfterProperty;
243 | pageBreakBefore?: import("csstype").PageBreakAfterProperty;
244 | pageBreakInside?: import("csstype").PageBreakInsideProperty;
245 | paintOrder?: string;
246 | perspective?: string | number;
247 | perspectiveOrigin?: string | number;
248 | placeContent?: string;
249 | pointerEvents?: import("csstype").PointerEventsProperty;
250 | position?: import("csstype").PositionProperty;
251 | quotes?: string;
252 | resize?: import("csstype").ResizeProperty;
253 | right?: string | number;
254 | rotate?: string;
255 | rowGap?: string | number;
256 | rubyAlign?: import("csstype").RubyAlignProperty;
257 | rubyMerge?: import("csstype").RubyMergeProperty;
258 | rubyPosition?: import("csstype").RubyPositionProperty;
259 | scale?: string | number;
260 | scrollBehavior?: import("csstype").ScrollBehaviorProperty;
261 | scrollMargin?: string | number;
262 | scrollMarginBlock?: string | number;
263 | scrollMarginBlockEnd?: string | number;
264 | scrollMarginBlockStart?: string | number;
265 | scrollMarginBottom?: string | number;
266 | scrollMarginInlineEnd?: string | number;
267 | scrollMarginInlineStart?: string | number;
268 | scrollMarginLeft?: string | number;
269 | scrollMarginRight?: string | number;
270 | scrollMarginTop?: string | number;
271 | scrollPadding?: string | number;
272 | scrollPaddingBlock?: string | number;
273 | scrollPaddingBlockEnd?: string | number;
274 | scrollPaddingBlockStart?: string | number;
275 | scrollPaddingBottom?: string | number;
276 | scrollPaddingInline?: string | number;
277 | scrollPaddingInlineEnd?: string | number;
278 | scrollPaddingInlineStart?: string | number;
279 | scrollPaddingLeft?: string | number;
280 | scrollPaddingRight?: string | number;
281 | scrollPaddingTop?: string | number;
282 | scrollSnapAlign?: string;
283 | scrollSnapType?: string;
284 | scrollbarColor?: string;
285 | scrollbarWidth?: import("csstype").ScrollbarWidthProperty;
286 | shapeImageThreshold?: import("csstype").GlobalsNumber;
287 | shapeMargin?: string | number;
288 | shapeOutside?: string;
289 | tabSize?: string | number;
290 | tableLayout?: import("csstype").TableLayoutProperty;
291 | textAlign?: import("csstype").TextAlignProperty;
292 | textAlignLast?: import("csstype").TextAlignLastProperty;
293 | textCombineUpright?: string;
294 | textDecorationColor?: string;
295 | textDecorationLine?: string;
296 | textDecorationSkip?: string;
297 | textDecorationSkipInk?: import("csstype").FontOpticalSizingProperty;
298 | textDecorationStyle?: import("csstype").TextDecorationStyleProperty;
299 | textEmphasisColor?: string;
300 | textEmphasisPosition?: string;
301 | textEmphasisStyle?: string;
302 | textIndent?: string | number;
303 | textJustify?: import("csstype").TextJustifyProperty;
304 | textOrientation?: import("csstype").TextOrientationProperty;
305 | textOverflow?: string;
306 | textRendering?: import("csstype").TextRenderingProperty;
307 | textShadow?: string;
308 | textSizeAdjust?: string;
309 | textTransform?: import("csstype").TextTransformProperty;
310 | textUnderlinePosition?: string;
311 | top?: string | number;
312 | touchAction?: string;
313 | transform?: string;
314 | transformBox?: import("csstype").TransformBoxProperty;
315 | transformOrigin?: string | number;
316 | transformStyle?: import("csstype").TransformStyleProperty;
317 | transitionDelay?: string;
318 | transitionDuration?: string;
319 | transitionProperty?: string;
320 | transitionTimingFunction?: string;
321 | translate?: string | number;
322 | unicodeBidi?: import("csstype").UnicodeBidiProperty;
323 | userSelect?: import("csstype").UserSelectProperty;
324 | verticalAlign?: string | number;
325 | visibility?: import("csstype").VisibilityProperty;
326 | whiteSpace?: import("csstype").WhiteSpaceProperty;
327 | widows?: import("csstype").GlobalsNumber;
328 | width?: string | number;
329 | willChange?: string;
330 | wordBreak?: import("csstype").WordBreakProperty;
331 | wordSpacing?: string | number;
332 | wordWrap?: import("csstype").WordWrapProperty;
333 | writingMode?: import("csstype").WritingModeProperty;
334 | zIndex?: import("csstype").ColumnCountProperty;
335 | zoom?: string | number;
336 | all?: import("csstype").Globals;
337 | animation?: string | number;
338 | background?: string | number;
339 | border?: string | number;
340 | borderBlock?: string | number;
341 | borderBlockEnd?: string | number;
342 | borderBlockStart?: string | number;
343 | borderBottom?: string | number;
344 | borderColor?: string;
345 | borderImage?: string | number;
346 | borderInline?: string | number;
347 | borderInlineEnd?: string | number;
348 | borderInlineStart?: string | number;
349 | borderLeft?: string | number;
350 | borderRadius?: string | number;
351 | borderRight?: string | number;
352 | borderStyle?: string;
353 | borderTop?: string | number;
354 | borderWidth?: string | number;
355 | columnRule?: string | number;
356 | columns?: string | number;
357 | flex?: string | number;
358 | flexFlow?: string;
359 | font?: string;
360 | gap?: string | number;
361 | grid?: string;
362 | gridArea?: string | number;
363 | gridColumn?: string | number;
364 | gridRow?: string | number;
365 | gridTemplate?: string;
366 | lineClamp?: import("csstype").FontSizeAdjustProperty;
367 | listStyle?: string;
368 | margin?: string | number;
369 | mask?: string | number;
370 | maskBorder?: string | number;
371 | motion?: string | number;
372 | offset?: string | number;
373 | outline?: string | number;
374 | padding?: string | number;
375 | placeItems?: string;
376 | placeSelf?: string;
377 | textDecoration?: string;
378 | textEmphasis?: string;
379 | transition?: string;
380 | MozAnimationDelay?: string;
381 | MozAnimationDirection?: string;
382 | MozAnimationDuration?: string;
383 | MozAnimationFillMode?: string;
384 | MozAnimationIterationCount?: string | number;
385 | MozAnimationName?: string;
386 | MozAnimationPlayState?: string;
387 | MozAnimationTimingFunction?: string;
388 | MozAppearance?: import("csstype").MozAppearanceProperty;
389 | MozBackfaceVisibility?: import("csstype").BackfaceVisibilityProperty;
390 | MozBorderBottomColors?: string;
391 | MozBorderEndColor?: string;
392 | MozBorderEndStyle?: import("csstype").BorderBlockEndStyleProperty;
393 | MozBorderEndWidth?: string | number;
394 | MozBorderLeftColors?: string;
395 | MozBorderRightColors?: string;
396 | MozBorderStartColor?: string;
397 | MozBorderStartStyle?: import("csstype").BorderBlockEndStyleProperty;
398 | MozBorderTopColors?: string;
399 | MozBoxSizing?: import("csstype").BoxSizingProperty;
400 | MozColumnCount?: import("csstype").ColumnCountProperty;
401 | MozColumnFill?: import("csstype").ColumnFillProperty;
402 | MozColumnGap?: string | number;
403 | MozColumnRuleColor?: string;
404 | MozColumnRuleStyle?: string;
405 | MozColumnRuleWidth?: string | number;
406 | MozColumnWidth?: string | number;
407 | MozContextProperties?: string;
408 | MozFloatEdge?: import("csstype").MozFloatEdgeProperty;
409 | MozFontFeatureSettings?: string;
410 | MozFontLanguageOverride?: string;
411 | MozForceBrokenImageIcon?: import("csstype").GlobalsNumber;
412 | MozHyphens?: import("csstype").HyphensProperty;
413 | MozImageRegion?: string;
414 | MozMarginEnd?: string | number;
415 | MozMarginStart?: string | number;
416 | MozOrient?: import("csstype").MozOrientProperty;
417 | MozOutlineRadiusBottomleft?: string | number;
418 | MozOutlineRadiusBottomright?: string | number;
419 | MozOutlineRadiusTopleft?: string | number;
420 | MozOutlineRadiusTopright?: string | number;
421 | MozPaddingEnd?: string | number;
422 | MozPaddingStart?: string | number;
423 | MozPerspective?: string | number;
424 | MozPerspectiveOrigin?: string | number;
425 | MozStackSizing?: import("csstype").MozStackSizingProperty;
426 | MozTabSize?: string | number;
427 | MozTextSizeAdjust?: string;
428 | MozTransformOrigin?: string | number;
429 | MozTransformStyle?: import("csstype").TransformStyleProperty;
430 | MozTransitionDelay?: string;
431 | MozTransitionDuration?: string;
432 | MozTransitionProperty?: string;
433 | MozTransitionTimingFunction?: string;
434 | MozUserFocus?: import("csstype").MozUserFocusProperty;
435 | MozUserModify?: import("csstype").MozUserModifyProperty;
436 | MozUserSelect?: import("csstype").UserSelectProperty;
437 | MozWindowDragging?: import("csstype").MozWindowDraggingProperty;
438 | MozWindowShadow?: import("csstype").MozWindowShadowProperty;
439 | msAccelerator?: import("csstype").MsAcceleratorProperty;
440 | msAlignSelf?: string;
441 | msBlockProgression?: import("csstype").MsBlockProgressionProperty;
442 | msContentZoomChaining?: import("csstype").MsContentZoomChainingProperty;
443 | msContentZoomLimitMax?: string;
444 | msContentZoomLimitMin?: string;
445 | msContentZoomSnapPoints?: string;
446 | msContentZoomSnapType?: import("csstype").MsContentZoomSnapTypeProperty;
447 | msContentZooming?: import("csstype").MsContentZoomingProperty;
448 | msFilter?: string;
449 | msFlexDirection?: import("csstype").FlexDirectionProperty;
450 | msFlexPositive?: import("csstype").GlobalsNumber;
451 | msFlowFrom?: string;
452 | msFlowInto?: string;
453 | msGridColumns?: string | number;
454 | msGridRows?: string | number;
455 | msHighContrastAdjust?: import("csstype").FontOpticalSizingProperty;
456 | msHyphenateLimitChars?: string | number;
457 | msHyphenateLimitLines?: import("csstype").MsHyphenateLimitLinesProperty;
458 | msHyphenateLimitZone?: string | number;
459 | msHyphens?: import("csstype").HyphensProperty;
460 | msImeAlign?: import("csstype").MsImeAlignProperty;
461 | msLineBreak?: import("csstype").LineBreakProperty;
462 | msOrder?: import("csstype").GlobalsNumber;
463 | msOverflowStyle?: import("csstype").MsOverflowStyleProperty;
464 | msOverflowX?: import("csstype").OverflowXProperty;
465 | msOverflowY?: import("csstype").OverflowXProperty;
466 | msScrollChaining?: import("csstype").MsContentZoomChainingProperty;
467 | msScrollLimitXMax?: string | number;
468 | msScrollLimitXMin?: string | number;
469 | msScrollLimitYMax?: string | number;
470 | msScrollLimitYMin?: string | number;
471 | msScrollRails?: import("csstype").MsScrollRailsProperty;
472 | msScrollSnapPointsX?: string;
473 | msScrollSnapPointsY?: string;
474 | msScrollSnapType?: import("csstype").MsContentZoomSnapTypeProperty;
475 | msScrollTranslation?: import("csstype").MsScrollTranslationProperty;
476 | msTextAutospace?: import("csstype").MsTextAutospaceProperty;
477 | msTextCombineHorizontal?: string;
478 | msTextOverflow?: string;
479 | msTextSizeAdjust?: string;
480 | msTouchAction?: string;
481 | msTouchSelect?: import("csstype").MsTouchSelectProperty;
482 | msTransform?: string;
483 | msTransformOrigin?: string | number;
484 | msUserSelect?: import("csstype").MsUserSelectProperty;
485 | msWordBreak?: import("csstype").WordBreakProperty;
486 | msWrapFlow?: import("csstype").MsWrapFlowProperty;
487 | msWrapMargin?: string | number;
488 | msWrapThrough?: import("csstype").MsWrapThroughProperty;
489 | msWritingMode?: import("csstype").WritingModeProperty;
490 | OObjectFit?: import("csstype").ObjectFitProperty;
491 | OObjectPosition?: string | number;
492 | OTabSize?: string | number;
493 | OTextOverflow?: string;
494 | OTransformOrigin?: string | number;
495 | WebkitAlignContent?: string;
496 | WebkitAlignItems?: string;
497 | WebkitAlignSelf?: string;
498 | WebkitAnimationDelay?: string;
499 | WebkitAnimationDirection?: string;
500 | WebkitAnimationDuration?: string;
501 | WebkitAnimationFillMode?: string;
502 | WebkitAnimationIterationCount?: string | number;
503 | WebkitAnimationName?: string;
504 | WebkitAnimationPlayState?: string;
505 | WebkitAnimationTimingFunction?: string;
506 | WebkitAppearance?: import("csstype").WebkitAppearanceProperty;
507 | WebkitBackdropFilter?: string;
508 | WebkitBackfaceVisibility?: import("csstype").BackfaceVisibilityProperty;
509 | WebkitBackgroundClip?: string;
510 | WebkitBackgroundOrigin?: string;
511 | WebkitBackgroundSize?: string | number;
512 | WebkitBorderBeforeColor?: string;
513 | WebkitBorderBeforeStyle?: string;
514 | WebkitBorderBeforeWidth?: string | number;
515 | WebkitBorderBottomLeftRadius?: string | number;
516 | WebkitBorderBottomRightRadius?: string | number;
517 | WebkitBorderImageSlice?: string | number;
518 | WebkitBorderTopLeftRadius?: string | number;
519 | WebkitBorderTopRightRadius?: string | number;
520 | WebkitBoxDecorationBreak?: import("csstype").BoxDecorationBreakProperty;
521 | WebkitBoxReflect?: string | number;
522 | WebkitBoxShadow?: string;
523 | WebkitBoxSizing?: import("csstype").BoxSizingProperty;
524 | WebkitClipPath?: string;
525 | WebkitColorAdjust?: import("csstype").ColorAdjustProperty;
526 | WebkitColumnCount?: import("csstype").ColumnCountProperty;
527 | WebkitColumnGap?: string | number;
528 | WebkitColumnRuleColor?: string;
529 | WebkitColumnRuleStyle?: string;
530 | WebkitColumnRuleWidth?: string | number;
531 | WebkitColumnSpan?: import("csstype").ColumnSpanProperty;
532 | WebkitColumnWidth?: string | number;
533 | WebkitFilter?: string;
534 | WebkitFlexBasis?: string | number;
535 | WebkitFlexDirection?: import("csstype").FlexDirectionProperty;
536 | WebkitFlexGrow?: import("csstype").GlobalsNumber;
537 | WebkitFlexShrink?: import("csstype").GlobalsNumber;
538 | WebkitFlexWrap?: import("csstype").FlexWrapProperty;
539 | WebkitFontFeatureSettings?: string;
540 | WebkitFontKerning?: import("csstype").FontKerningProperty;
541 | WebkitFontVariantLigatures?: string;
542 | WebkitHyphens?: import("csstype").HyphensProperty;
543 | WebkitJustifyContent?: string;
544 | WebkitLineBreak?: import("csstype").LineBreakProperty;
545 | WebkitMarginEnd?: string | number;
546 | WebkitMarginStart?: string | number;
547 | WebkitMaskAttachment?: string;
548 | WebkitMaskClip?: string;
549 | WebkitMaskComposite?: string;
550 | WebkitMaskImage?: string;
551 | WebkitMaskOrigin?: string;
552 | WebkitMaskPosition?: string | number;
553 | WebkitMaskPositionX?: string | number;
554 | WebkitMaskPositionY?: string | number;
555 | WebkitMaskRepeat?: string;
556 | WebkitMaskRepeatX?: import("csstype").WebkitMaskRepeatXProperty;
557 | WebkitMaskRepeatY?: import("csstype").WebkitMaskRepeatXProperty;
558 | WebkitMaskSize?: string | number;
559 | WebkitMaxInlineSize?: string | number;
560 | WebkitOrder?: import("csstype").GlobalsNumber;
561 | WebkitOverflowScrolling?: import("csstype").WebkitOverflowScrollingProperty;
562 | WebkitPaddingEnd?: string | number;
563 | WebkitPaddingStart?: string | number;
564 | WebkitPerspective?: string | number;
565 | WebkitPerspectiveOrigin?: string | number;
566 | WebkitScrollSnapType?: string;
567 | WebkitShapeMargin?: string | number;
568 | WebkitTapHighlightColor?: string;
569 | WebkitTextCombine?: string;
570 | WebkitTextDecorationColor?: string;
571 | WebkitTextDecorationLine?: string;
572 | WebkitTextDecorationSkip?: string;
573 | WebkitTextDecorationStyle?: import("csstype").TextDecorationStyleProperty;
574 | WebkitTextEmphasisColor?: string;
575 | WebkitTextEmphasisPosition?: string;
576 | WebkitTextEmphasisStyle?: string;
577 | WebkitTextFillColor?: string;
578 | WebkitTextOrientation?: import("csstype").TextOrientationProperty;
579 | WebkitTextSizeAdjust?: string;
580 | WebkitTextStrokeColor?: string;
581 | WebkitTextStrokeWidth?: string | number;
582 | WebkitTouchCallout?: import("csstype").WebkitTouchCalloutProperty;
583 | WebkitTransform?: string;
584 | WebkitTransformOrigin?: string | number;
585 | WebkitTransformStyle?: import("csstype").TransformStyleProperty;
586 | WebkitTransitionDelay?: string;
587 | WebkitTransitionDuration?: string;
588 | WebkitTransitionProperty?: string;
589 | WebkitTransitionTimingFunction?: string;
590 | WebkitUserModify?: import("csstype").WebkitUserModifyProperty;
591 | WebkitUserSelect?: import("csstype").UserSelectProperty;
592 | WebkitWritingMode?: import("csstype").WritingModeProperty;
593 | MozAnimation?: string | number;
594 | MozBorderImage?: string | number;
595 | MozColumnRule?: string | number;
596 | MozColumns?: string | number;
597 | MozTransition?: string;
598 | msContentZoomLimit?: string;
599 | msContentZoomSnap?: string;
600 | msFlex?: string | number;
601 | msScrollLimit?: string;
602 | msScrollSnapX?: string;
603 | msScrollSnapY?: string;
604 | OBorderImage?: string | number;
605 | WebkitAnimation?: string | number;
606 | WebkitBorderBefore?: string | number;
607 | WebkitBorderImage?: string | number;
608 | WebkitBorderRadius?: string | number;
609 | WebkitColumnRule?: string | number;
610 | WebkitColumns?: string | number;
611 | WebkitFlex?: string | number;
612 | WebkitFlexFlow?: string;
613 | WebkitLineClamp?: import("csstype").FontSizeAdjustProperty;
614 | WebkitMask?: string | number;
615 | WebkitTextEmphasis?: string;
616 | WebkitTextStroke?: string | number;
617 | WebkitTransition?: string;
618 | boxAlign?: import("csstype").BoxAlignProperty;
619 | boxDirection?: import("csstype").BoxDirectionProperty;
620 | boxFlex?: import("csstype").GlobalsNumber;
621 | boxFlexGroup?: import("csstype").GlobalsNumber;
622 | boxLines?: import("csstype").BoxLinesProperty;
623 | boxOrdinalGroup?: import("csstype").GlobalsNumber;
624 | boxOrient?: import("csstype").BoxOrientProperty;
625 | boxPack?: import("csstype").BoxPackProperty;
626 | clip?: string;
627 | fontVariantAlternates?: string;
628 | gridColumnGap?: string | number;
629 | gridGap?: string | number;
630 | gridRowGap?: string | number;
631 | imeMode?: import("csstype").ImeModeProperty;
632 | offsetBlockEnd?: string | number;
633 | offsetBlockStart?: string | number;
634 | offsetInlineEnd?: string | number;
635 | offsetInlineStart?: string | number;
636 | scrollSnapCoordinate?: string | number;
637 | scrollSnapDestination?: string | number;
638 | scrollSnapPointsX?: string;
639 | scrollSnapPointsY?: string;
640 | scrollSnapTypeX?: import("csstype").MsContentZoomSnapTypeProperty;
641 | scrollSnapTypeY?: import("csstype").MsContentZoomSnapTypeProperty;
642 | textCombineHorizontal?: string;
643 | KhtmlBoxAlign?: import("csstype").BoxAlignProperty;
644 | KhtmlBoxDirection?: import("csstype").BoxDirectionProperty;
645 | KhtmlBoxFlex?: import("csstype").GlobalsNumber;
646 | KhtmlBoxFlexGroup?: import("csstype").GlobalsNumber;
647 | KhtmlBoxLines?: import("csstype").BoxLinesProperty;
648 | KhtmlBoxOrdinalGroup?: import("csstype").GlobalsNumber;
649 | KhtmlBoxOrient?: import("csstype").BoxOrientProperty;
650 | KhtmlBoxPack?: import("csstype").BoxPackProperty;
651 | MozBackgroundClip?: string;
652 | MozBackgroundInlinePolicy?: import("csstype").BoxDecorationBreakProperty;
653 | MozBackgroundOrigin?: string;
654 | MozBackgroundSize?: string | number;
655 | MozBinding?: string;
656 | MozBorderRadius?: string | number;
657 | MozBorderRadiusBottomleft?: string | number;
658 | MozBorderRadiusBottomright?: string | number;
659 | MozBorderRadiusTopleft?: string | number;
660 | MozBorderRadiusTopright?: string | number;
661 | MozBoxAlign?: import("csstype").BoxAlignProperty;
662 | MozBoxDirection?: import("csstype").BoxDirectionProperty;
663 | MozBoxFlex?: import("csstype").GlobalsNumber;
664 | MozBoxOrdinalGroup?: import("csstype").GlobalsNumber;
665 | MozBoxOrient?: import("csstype").BoxOrientProperty;
666 | MozBoxPack?: import("csstype").BoxPackProperty;
667 | MozBoxShadow?: string;
668 | MozOpacity?: import("csstype").GlobalsNumber;
669 | MozOutline?: string | number;
670 | MozOutlineColor?: string;
671 | MozOutlineRadius?: string | number;
672 | MozOutlineStyle?: string;
673 | MozOutlineWidth?: string | number;
674 | MozResize?: import("csstype").ResizeProperty;
675 | MozTextAlignLast?: import("csstype").TextAlignLastProperty;
676 | MozTextBlink?: import("csstype").MozTextBlinkProperty;
677 | MozTextDecorationColor?: string;
678 | MozTextDecorationLine?: string;
679 | MozTextDecorationStyle?: import("csstype").TextDecorationStyleProperty;
680 | MozUserInput?: import("csstype").MozUserInputProperty;
681 | msImeMode?: import("csstype").ImeModeProperty;
682 | msScrollbar3dlightColor?: string;
683 | msScrollbarArrowColor?: string;
684 | msScrollbarBaseColor?: string;
685 | msScrollbarDarkshadowColor?: string;
686 | msScrollbarFaceColor?: string;
687 | msScrollbarHighlightColor?: string;
688 | msScrollbarShadowColor?: string;
689 | msScrollbarTrackColor?: string;
690 | OAnimation?: string | number;
691 | OAnimationDelay?: string;
692 | OAnimationDirection?: string;
693 | OAnimationDuration?: string;
694 | OAnimationFillMode?: string;
695 | OAnimationIterationCount?: string | number;
696 | OAnimationName?: string;
697 | OAnimationPlayState?: string;
698 | OAnimationTimingFunction?: string;
699 | OBackgroundSize?: string | number;
700 | OTransform?: string;
701 | OTransition?: string;
702 | OTransitionDelay?: string;
703 | OTransitionDuration?: string;
704 | OTransitionProperty?: string;
705 | OTransitionTimingFunction?: string;
706 | WebkitBoxAlign?: import("csstype").BoxAlignProperty;
707 | WebkitBoxDirection?: import("csstype").BoxDirectionProperty;
708 | WebkitBoxFlex?: import("csstype").GlobalsNumber;
709 | WebkitBoxFlexGroup?: import("csstype").GlobalsNumber;
710 | WebkitBoxLines?: import("csstype").BoxLinesProperty;
711 | WebkitBoxOrdinalGroup?: import("csstype").GlobalsNumber;
712 | WebkitBoxOrient?: import("csstype").BoxOrientProperty;
713 | WebkitBoxPack?: import("csstype").BoxPackProperty;
714 | WebkitScrollSnapPointsX?: string;
715 | WebkitScrollSnapPointsY?: string;
716 | alignmentBaseline?: import("csstype").AlignmentBaselineProperty;
717 | baselineShift?: string | number;
718 | clipRule?: import("csstype").ClipRuleProperty;
719 | colorInterpolation?: import("csstype").ColorInterpolationProperty;
720 | colorRendering?: import("csstype").ColorRenderingProperty;
721 | dominantBaseline?: import("csstype").DominantBaselineProperty;
722 | fill?: string;
723 | fillOpacity?: import("csstype").GlobalsNumber;
724 | fillRule?: import("csstype").ClipRuleProperty;
725 | floodColor?: string;
726 | floodOpacity?: import("csstype").GlobalsNumber;
727 | glyphOrientationVertical?: string | number;
728 | lightingColor?: string;
729 | marker?: string;
730 | markerEnd?: string;
731 | markerMid?: string;
732 | markerStart?: string;
733 | shapeRendering?: import("csstype").ShapeRenderingProperty;
734 | stopColor?: string;
735 | stopOpacity?: import("csstype").GlobalsNumber;
736 | stroke?: string;
737 | strokeDasharray?: string | number;
738 | strokeDashoffset?: string | number;
739 | strokeLinecap?: import("csstype").StrokeLinecapProperty;
740 | strokeLinejoin?: import("csstype").StrokeLinejoinProperty;
741 | strokeMiterlimit?: import("csstype").GlobalsNumber;
742 | strokeOpacity?: import("csstype").GlobalsNumber;
743 | strokeWidth?: string | number;
744 | textAnchor?: import("csstype").TextAnchorProperty;
745 | vectorEffect?: import("csstype").VectorEffectProperty;
746 | };
747 | ref: (n: any) => void;
748 | };
749 | ref: (n: any) => void;
750 | style: import("react").CSSProperties;
751 | };
752 |
--------------------------------------------------------------------------------
/lib/useFade.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __assign = (this && this.__assign) || function () {
3 | __assign = Object.assign || function(t) {
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
5 | s = arguments[i];
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 | t[p] = s[p];
8 | }
9 | return t;
10 | };
11 | return __assign.apply(this, arguments);
12 | };
13 | var __rest = (this && this.__rest) || function (s, e) {
14 | var t = {};
15 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16 | t[p] = s[p];
17 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
18 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
19 | t[p[i]] = s[p[i]];
20 | return t;
21 | };
22 | Object.defineProperty(exports, "__esModule", { value: true });
23 | var react_1 = require("react");
24 | var wobble_1 = require("wobble");
25 | var util_1 = require("./util");
26 | var easing_1 = require("@popmotion/easing");
27 | var popcorn_1 = require("@popmotion/popcorn");
28 | var globalAny = global;
29 | var defaultsOptions = {
30 | keepFrom: false,
31 | type: 'morph',
32 | getMargins: false,
33 | portalElement: globalAny.document && globalAny.document.body,
34 | spring: {
35 | damping: 26,
36 | mass: 1,
37 | stiffness: 180,
38 | overshootClamping: true,
39 | },
40 | easings: easing_1.linear,
41 | delaysRatio: 0.1,
42 | isInitial: false,
43 | };
44 | function useFade(opts) {
45 | if (opts === void 0) { opts = defaultsOptions; }
46 | var options = __assign({}, defaultsOptions, opts);
47 | var getMargins = options.getMargins, isInitial = options.isInitial, delaysRatio = options.delaysRatio;
48 | var prevNodeRef = react_1.useRef();
49 | var cloneContainerRef = react_1.useRef();
50 | var isMountedRef = react_1.useRef();
51 | var cleanup = function () {
52 | if (!cloneContainerRef.current)
53 | return;
54 | prevNodeRef.current.style.visibility = null;
55 | options.portalElement.removeChild(cloneContainerRef.current);
56 | cloneContainerRef.current = null;
57 | };
58 | var halfClampEnd = popcorn_1.clamp(1 - delaysRatio, 1);
59 | var easeFast = function (x) {
60 | return easing_1.easeInOut(Number(popcorn_1.interpolate([1 - delaysRatio, 1], [0, 1])(halfClampEnd(x))));
61 | };
62 | var spring = new wobble_1.Spring(__assign({ fromValue: Number(isInitial), toValue: Number(!isInitial) }, options.spring));
63 | spring
64 | .onUpdate(function (s) {
65 | if (!cloneContainerRef.current)
66 | return;
67 | cloneContainerRef.current.style.opacity = String(easeFast(s.currentValue));
68 | })
69 | .onStop(cleanup);
70 | var getRef = react_1.useCallback(function (n) {
71 | var node = n || prevNodeRef.current;
72 | var hasNode = !!node;
73 | if (hasNode && isMountedRef.current) {
74 | node.style.visibility = 'visible';
75 | var rect = util_1.getRect(node, { getMargins: getMargins });
76 | if (!cloneContainerRef.current)
77 | cloneContainerRef.current = util_1.cloneElement(node, options);
78 | node.style.visibility = 'hidden';
79 | prevNodeRef.current = node;
80 | util_1.applyOverlayStyle(cloneContainerRef.current, __assign({}, rect));
81 | }
82 | var toValue = Number(!!n);
83 | if (spring.currentValue === toValue)
84 | cleanup();
85 | spring.updateConfig({ toValue: toValue }).start();
86 | }, []);
87 | isMountedRef.current = true;
88 | var style = { visibility: 'hidden' };
89 | var props = {
90 | ref: getRef,
91 | style: style,
92 | };
93 | var propsFn = function (_a) {
94 | if (_a === void 0) { _a = {}; }
95 | var _b = _a.style, style = _b === void 0 ? {} : _b, extra = __rest(_a, ["style"]);
96 | return (__assign({}, props, { style: __assign({}, props.style, style) }));
97 | };
98 | propsFn.ref = getRef;
99 | propsFn.style = style;
100 | return propsFn;
101 | }
102 | exports.default = useFade;
103 | //# sourceMappingURL=useFade.js.map
--------------------------------------------------------------------------------
/lib/useFade.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"useFade.js","sourceRoot":"","sources":["../src/useFade.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAuD;AACvD,iCAAgC;AAEhC,+BAAkE;AAElE,4CAA+D;AAC/D,8CAAwD;AAExD,IAAM,SAAS,GAAQ,MAAM,CAAC;AAE9B,IAAM,eAAe,GAAG;IACtB,QAAQ,EAAE,KAAK;IACf,IAAI,EAAE,OAAO;IACb,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,SAAS,CAAC,QAAQ,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI;IAC5D,MAAM,EAAE;QACN,OAAO,EAAE,EAAE;QACX,IAAI,EAAE,CAAC;QACP,SAAS,EAAE,GAAG;QACd,iBAAiB,EAAE,IAAI;KACxB;IACD,OAAO,EAAE,eAAM;IACf,WAAW,EAAE,GAAG;IAChB,SAAS,EAAE,KAAK;CACjB,CAAC;AAEF,SAAwB,OAAO,CAAC,IAAmC;IAAnC,qBAAA,EAAA,sBAAmC;IACjE,IAAM,OAAO,gBAAQ,eAAe,EAA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KAAK,CAAC,KAAK,EAAK,KAAK,KACjC,CAAA;KAAA,CAAC;IAEH,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC;IACrB,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;IAEtB,OAAO,OAAO,CAAC;AACjB,CAAC;AAnFD,0BAmFC"}
--------------------------------------------------------------------------------
/lib/useMorph.d.ts:
--------------------------------------------------------------------------------
1 | import { MorphOptions, Morph } from './types';
2 | export default function useMorph(opts?: MorphOptions): Morph;
3 |
--------------------------------------------------------------------------------
/lib/useMorph.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __assign = (this && this.__assign) || function () {
3 | __assign = Object.assign || function(t) {
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
5 | s = arguments[i];
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 | t[p] = s[p];
8 | }
9 | return t;
10 | };
11 | return __assign.apply(this, arguments);
12 | };
13 | var __rest = (this && this.__rest) || function (s, e) {
14 | var t = {};
15 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16 | t[p] = s[p];
17 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
18 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
19 | t[p[i]] = s[p[i]];
20 | return t;
21 | };
22 | Object.defineProperty(exports, "__esModule", { value: true });
23 | var react_1 = require("react");
24 | var easing_1 = require("@popmotion/easing");
25 | var morphTransition_1 = require("./morphTransition");
26 | var util_1 = require("./util");
27 | var globalAny = global;
28 | var defaultsOptions = {
29 | keepFrom: false,
30 | type: 'morph',
31 | getMargins: false,
32 | portalElement: globalAny.document && globalAny.document.body,
33 | spring: {
34 | damping: 26,
35 | mass: 1,
36 | stiffness: 180,
37 | },
38 | easings: easing_1.linear,
39 | isReversed: false,
40 | withMethods: false,
41 | };
42 | function useMorph(opts) {
43 | if (opts === void 0) { opts = defaultsOptions; }
44 | var options = __assign({}, defaultsOptions, opts);
45 | var getMargins = options.getMargins, keepFrom = options.keepFrom, _a = options.spring, damping = _a.damping, mass = _a.mass, stiffness = _a.stiffness, isReversed = options.isReversed;
46 | var backAnimationRef = react_1.useRef();
47 | var prevToRef = react_1.useRef();
48 | var prevToRectRef = react_1.useRef();
49 | var prevSpringRef = react_1.useRef();
50 | var cleanupFromRef = react_1.useRef();
51 | var setProgressRef = react_1.useRef();
52 | var isAnimating = false;
53 | var cleanup;
54 | function resize() {
55 | if (!prevToRef.current)
56 | return;
57 | prevToRectRef.current = util_1.getRect(prevToRef.current, { getMargins: getMargins });
58 | }
59 | // Window on resize effect.
60 | react_1.useEffect(function () {
61 | if (!prevToRef.current)
62 | return;
63 | window.addEventListener('resize', resize);
64 | return function () { return window.removeEventListener('resize', resize); };
65 | }, []);
66 | var animate = function (_a) {
67 | var from = _a.from, to = _a.to, rectFrom = _a.rectFrom, rectTo = _a.rectTo, willBack = _a.willBack;
68 | if (!to)
69 | return;
70 | to.style.visibility = 'visible';
71 | if (!from)
72 | return;
73 | isAnimating = true;
74 | var prevSpring = prevSpringRef.current;
75 | switch (options.type) {
76 | case 'fade':
77 | case 'morph':
78 | default:
79 | var morph = morphTransition_1.default({
80 | from: from,
81 | to: to,
82 | rectFrom: rectFrom,
83 | rectTo: rectTo,
84 | fromValue: prevSpring !== undefined && prevSpring.currentValue !== 1
85 | ? 1 - prevSpring.currentValue
86 | : 0,
87 | initialVelocity: prevSpring !== undefined && prevSpring.currentVelocity !== 0
88 | ? prevSpring.currentVelocity * -1
89 | : 0,
90 | onUpdate: function (s) {
91 | prevSpringRef.current = s;
92 | },
93 | willBack: willBack,
94 | options: options,
95 | });
96 | cleanup = morph.cleanup;
97 | setProgressRef.current = morph.setProgress;
98 | cleanupFromRef.current = cleanup;
99 | }
100 | return function () {
101 | if (isAnimating)
102 | cleanup();
103 | };
104 | };
105 | react_1.useEffect(function () {
106 | if (!setProgressRef.current)
107 | return;
108 | setProgressRef.current(options.progress);
109 | }, [options.progress]);
110 | var getRef = react_1.useCallback(function (to) {
111 | var from = prevToRef.current;
112 | var cleanupFrom = cleanupFromRef.current;
113 | if (from === to)
114 | return;
115 | var willUnmount = !to;
116 | var willAnimate = !!to && !!from;
117 | var willBack = keepFrom && willAnimate;
118 | var isBackwards = keepFrom && willUnmount && !!from;
119 | if (cleanupFrom)
120 | cleanupFrom();
121 | if (isBackwards) {
122 | animate(backAnimationRef.current);
123 | return;
124 | }
125 | if (willUnmount) {
126 | if (cleanup)
127 | cleanup();
128 | return;
129 | }
130 | var rectFrom = prevToRectRef.current;
131 | var rectTo = util_1.getRect(to, { getMargins: getMargins });
132 | animate({ from: from, rectFrom: rectFrom, to: to, rectTo: rectTo, willBack: willBack });
133 | backAnimationRef.current = {
134 | from: to,
135 | rectFrom: rectTo,
136 | to: from,
137 | rectTo: rectFrom,
138 | };
139 | if (!willBack) {
140 | prevToRef.current = to;
141 | prevToRectRef.current = rectTo;
142 | }
143 | }, [keepFrom, damping, mass, stiffness, isReversed]);
144 | var style = { visibility: 'hidden' };
145 | var props = {
146 | ref: getRef,
147 | style: style,
148 | };
149 | var propsFn = function (_a) {
150 | if (_a === void 0) { _a = {}; }
151 | var _b = _a.style, style = _b === void 0 ? {} : _b, extra = __rest(_a, ["style"]);
152 | return (__assign({}, props, { style: __assign({}, props.style, style) }));
153 | };
154 | propsFn.ref = getRef;
155 | propsFn.style = style;
156 | if (options.withMethods) {
157 | propsFn.resize = resize;
158 | }
159 | return propsFn;
160 | }
161 | exports.default = useMorph;
162 | //# sourceMappingURL=useMorph.js.map
--------------------------------------------------------------------------------
/lib/useMorph.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"useMorph.js","sourceRoot":"","sources":["../src/useMorph.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAuD;AAEvD,4CAA2C;AAE3C,qDAAgD;AAChD,+BAAiC;AAGjC,IAAM,SAAS,GAAQ,MAAM,CAAC;AAU9B,IAAM,eAAe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,EAAE,MAAM;YAChB,EAAE,EAAE,IAAI;YACR,MAAM,EAAE,QAAQ;SACjB,CAAC;QAEF,IAAI,CAAC,QAAQ,EAAE;YACb,SAAS,CAAC,OAAO,GAAG,EAAE,CAAC;YACvB,aAAa,CAAC,OAAO,GAAG,MAAM,CAAC;SAChC;IACH,CAAC,EACD,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,CACjD,CAAC;IAEF,IAAM,KAAK,GAAwB,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;IAE5D,IAAM,KAAK,GAAG;QACZ,GAAG,EAAE,MAAM;QACX,KAAK,OAAA;KACN,CAAC;IAEF,IAAM,OAAO,GAAU,UAAC,EAA6B;QAA7B,mBAAA,EAAA,OAA6B;QAA3B,IAAA,aAAU,EAAV,+BAAU,EAAE,6BAAQ;QAAY,OAAA,cACrD,KAAK,IACR,KAAK,eAAO,KAAK,CAAC,KAAK,EAAK,KAAK,KACjC,CAAA;KAAA,CAAC;IAEH,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC;IACrB,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;IAEtB,IAAI,OAAO,CAAC,WAAW,EAAE;QACvB,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;KACzB;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAxJD,2BAwJC"}
--------------------------------------------------------------------------------
/lib/useMorphKeys.d.ts:
--------------------------------------------------------------------------------
1 | import { MorphOptions, Morph } from './types';
2 | declare function useMorphs(keys: [A, B, C, D, E, F, G, H], options?: MorphOptions): {
3 | [key in A | B | C | D | E | F | G | H]: Morph;
4 | };
5 | declare function useMorphs (keys: [A, B, C, D, E, F, G], options?: MorphOptions): {
6 | [key in A | B | C | D | E | F | G]: Morph;
7 | };
8 | declare function useMorphs (keys: [A, B, C, D, E, F], options?: MorphOptions): {
9 | [key in A | B | C | D | E | F]: Morph;
10 | };
11 | declare function useMorphs (keys: [A, B, C, D, E], options?: MorphOptions): {
12 | [key in A | B | C | D | E]: Morph;
13 | };
14 | declare function useMorphs (keys: [A, B, C, D], options?: MorphOptions): {
15 | [key in A | B | C | D]: Morph;
16 | };
17 | declare function useMorphs (keys: [A, B, C], options?: MorphOptions): {
18 | [key in A | B | C]: Morph;
19 | };
20 | declare function useMorphs (keys: [A, B], options?: MorphOptions): {
21 | [key in A | B]: Morph;
22 | };
23 | export default useMorphs;
24 |
--------------------------------------------------------------------------------
/lib/useMorphKeys.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __assign = (this && this.__assign) || function () {
3 | __assign = Object.assign || function(t) {
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
5 | s = arguments[i];
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 | t[p] = s[p];
8 | }
9 | return t;
10 | };
11 | return __assign.apply(this, arguments);
12 | };
13 | Object.defineProperty(exports, "__esModule", { value: true });
14 | var useMorph_1 = require("./useMorph");
15 | function useMorphs(keys, options) {
16 | if (options === void 0) { options = {}; }
17 | var morphObject = keys.reduce(function (acc, key, i) {
18 | var _a;
19 | return __assign({}, acc, (_a = {}, _a[key] = useMorph_1.default(__assign({ zIndex: i }, options)), _a));
20 | }, {});
21 | return morphObject;
22 | }
23 | exports.default = useMorphs;
24 | //# sourceMappingURL=useMorphKeys.js.map
--------------------------------------------------------------------------------
/lib/useMorphKeys.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"useMorphKeys.js","sourceRoot":"","sources":["../src/useMorphKeys.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,uCAAkC;AA6ElC,SAAS,SAAS,CAAC,IAAI,EAAE,OAAY;IAAZ,wBAAA,EAAA,YAAY;IACnC,IAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,UAAC,GAAU,EAAE,GAAW,EAAE,CAAS;;QACjE,oBAAY,GAAG,eAAG,GAAG,IAAG,kBAAQ,YAAG,MAAM,EAAE,CAAC,IAAK,OAAO,EAAG,OAAG;IAChE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,kBAAe,SAAS,CAAC"}
--------------------------------------------------------------------------------
/lib/useMorphList.d.ts:
--------------------------------------------------------------------------------
1 | import { MorphOptions } from './types';
2 | declare type OptionsMapperFn = (items: any[]) => MorphOptions;
3 | declare const useMorphList: (items: number | any[], options?: MorphOptions | OptionsMapperFn) => import("./types").Morph[];
4 | export default useMorphList;
5 |
--------------------------------------------------------------------------------
/lib/useMorphList.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __assign = (this && this.__assign) || function () {
3 | __assign = Object.assign || function(t) {
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
5 | s = arguments[i];
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 | t[p] = s[p];
8 | }
9 | return t;
10 | };
11 | return __assign.apply(this, arguments);
12 | };
13 | Object.defineProperty(exports, "__esModule", { value: true });
14 | var useMorph_1 = require("./useMorph");
15 | var useMorphList = function (items, options) {
16 | if (options === void 0) { options = {}; }
17 | var list = items;
18 | if (typeof list === 'number')
19 | list = Array(list).fill(0);
20 | var optionsFn = typeof options === 'function' ? options : function () { return options; };
21 | return list
22 | .map(optionsFn)
23 | .map(function (options, i) {
24 | return useMorph_1.default(__assign({ zIndex: i }, options));
25 | });
26 | };
27 | exports.default = useMorphList;
28 | //# sourceMappingURL=useMorphList.js.map
--------------------------------------------------------------------------------
/lib/useMorphList.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"useMorphList.js","sourceRoot":"","sources":["../src/useMorphList.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,uCAAkC;AAKlC,IAAM,YAAY,GAAG,UACnB,KAAqB,EACrB,OAA4C;IAA5C,wBAAA,EAAA,YAA4C;IAE5C,IAAI,IAAI,GAAG,KAAK,CAAC;IAEjB,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEzD,IAAM,SAAS,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAM,OAAA,OAAO,EAAP,CAAO,CAAC;IAE1E,OAAO,IAAI;SACR,GAAG,CAAC,SAAS,CAAC;SACd,GAAG,CAAC,UAAC,OAAqB,EAAE,CAAS;QACpC,OAAA,kBAAQ,YAAG,MAAM,EAAE,CAAC,IAAK,OAAO,EAAG;IAAnC,CAAmC,CACpC,CAAC;AACN,CAAC,CAAC;AAEF,kBAAe,YAAY,CAAC"}
--------------------------------------------------------------------------------
/lib/useMorphs.d.ts:
--------------------------------------------------------------------------------
1 | import { MorphOptions, Morph } from './types';
2 | declare function useMorphs (keys: [A, B, C, D, E, F, G, H], options?: MorphOptions): {
3 | [key in A | B | C | D | E | F | G | H]: Morph;
4 | };
5 | declare function useMorphs (keys: [A, B, C, D, E, F, G], options?: MorphOptions): {
6 | [key in A | B | C | D | E | F | G]: Morph;
7 | };
8 | declare function useMorphs (keys: [A, B, C, D, E, F], options?: MorphOptions): {
9 | [key in A | B | C | D | E | F]: Morph;
10 | };
11 | declare function useMorphs (keys: [A, B, C, D, E], options?: MorphOptions): {
12 | [key in A | B | C | D | E]: Morph;
13 | };
14 | declare function useMorphs (keys: [A, B, C, D], options?: MorphOptions): {
15 | [key in A | B | C | D]: Morph;
16 | };
17 | declare function useMorphs (keys: [A, B, C], options?: MorphOptions): {
18 | [key in A | B | C]: Morph;
19 | };
20 | declare function useMorphs (keys: [A, B], options?: MorphOptions): {
21 | [key in A | B]: Morph;
22 | };
23 | export default useMorphs;
24 |
--------------------------------------------------------------------------------
/lib/useMorphs.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __assign = (this && this.__assign) || function () {
3 | __assign = Object.assign || function(t) {
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
5 | s = arguments[i];
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 | t[p] = s[p];
8 | }
9 | return t;
10 | };
11 | return __assign.apply(this, arguments);
12 | };
13 | Object.defineProperty(exports, "__esModule", { value: true });
14 | var useMorph_1 = require("./useMorph");
15 | function useMorphs(keys, options) {
16 | if (options === void 0) { options = {}; }
17 | var morphObject = keys.reduce(function (acc, key, i) {
18 | var _a;
19 | return __assign({}, acc, (_a = {}, _a[key] = useMorph_1.default(__assign({ zIndex: i }, options)), _a));
20 | }, {});
21 | return morphObject;
22 | }
23 | exports.default = useMorphs;
24 | //# sourceMappingURL=useMorphs.js.map
--------------------------------------------------------------------------------
/lib/useMorphs.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"useMorphs.js","sourceRoot":"","sources":["../src/useMorphs.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,uCAAkC;AA6ElC,SAAS,SAAS,CAAC,IAAI,EAAE,OAAY;IAAZ,wBAAA,EAAA,YAAY;IACnC,IAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,UAAC,GAAU,EAAE,GAAW,EAAE,CAAS;;QACjE,oBAAY,GAAG,eAAG,GAAG,IAAG,kBAAQ,YAAG,MAAM,EAAE,CAAC,IAAK,OAAO,EAAG,OAAG;IAChE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,kBAAe,SAAS,CAAC"}
--------------------------------------------------------------------------------
/lib/util.d.ts:
--------------------------------------------------------------------------------
1 | import { MorphOptions, NumberObject } from './types';
2 | export declare const getRects: (node: HTMLElement) => {
3 | left: string;
4 | top: string;
5 | width: string;
6 | height: string;
7 | };
8 | export declare const applyOverlayStyle: (node: HTMLElement, styles?: {}) => void;
9 | export declare const diffRect: (a: CSSStyleDeclaration, b: CSSStyleDeclaration) => {
10 | translateY: number;
11 | translateX: number;
12 | scaleY: number;
13 | scaleX: number;
14 | };
15 | export declare const getTransformString: ({ translateY, translateX, scaleY, scaleX }: NumberObject, removeScale?: boolean) => string;
16 | export declare const getRect: (elm: HTMLElement, { getMargins }?: {
17 | getMargins?: boolean;
18 | }) => CSSStyleDeclaration;
19 | export declare const getValueFromProgress: (from: number, to: number, progress: number) => number;
20 | export declare const interpolateObject: (from: NumberObject, to: NumberObject, { easings, isReversed }: MorphOptions) => (t: number) => {};
21 | export declare const cloneElement: (element: HTMLElement, { portalElement, zIndex }: MorphOptions) => HTMLDivElement;
22 | export declare const clamp: (min: number, max: number) => (x: number) => number;
23 | export declare const clampProgress: (x: number) => number;
24 | export declare const lerp: (from: number, to: number, isClamped: Boolean) => (t: number) => number;
25 | declare const _default: {
26 | interpolateObject: (from: NumberObject, to: NumberObject, { easings, isReversed }: MorphOptions) => (t: number) => {};
27 | };
28 | export default _default;
29 |
--------------------------------------------------------------------------------
/lib/util.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __assign = (this && this.__assign) || function () {
3 | __assign = Object.assign || function(t) {
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
5 | s = arguments[i];
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 | t[p] = s[p];
8 | }
9 | return t;
10 | };
11 | return __assign.apply(this, arguments);
12 | };
13 | Object.defineProperty(exports, "__esModule", { value: true });
14 | var easings_1 = require("./easings");
15 | var px = function (x) { return x + "px"; };
16 | exports.getRects = function (node) {
17 | var _a = node.getBoundingClientRect(), left = _a.left, top = _a.top, width = _a.width, height = _a.height;
18 | return { left: px(left), top: px(top), width: px(width), height: px(height) };
19 | };
20 | exports.applyOverlayStyle = function (node, styles) {
21 | if (styles === void 0) { styles = {}; }
22 | Object.assign(node.style, __assign({ position: 'absolute',
23 | // border: '2px solid red',
24 | 'transform-origin': 'top left' }, styles));
25 | };
26 | exports.diffRect = function (a, b) { return ({
27 | translateY: parseInt(a.top || '0', 10) - parseInt(b.top || '0', 10),
28 | translateX: parseInt(a.left || '0', 10) - parseInt(b.left || '0', 10),
29 | scaleY: parseInt(a.height || '0', 10) / parseInt(b.height || '0', 10),
30 | scaleX: parseInt(a.width || '0', 10) / parseInt(b.width || '0', 10),
31 | }); };
32 | exports.getTransformString = function (_a, removeScale) {
33 | var translateY = _a.translateY, translateX = _a.translateX, scaleY = _a.scaleY, scaleX = _a.scaleX;
34 | if (removeScale === void 0) { removeScale = false; }
35 | return "\n translateY(" + px(translateY) + ")\n\ttranslateX(" + px(translateX) + ")\n\t" + (!removeScale
36 | ? "\n\t scaleY(" + scaleY + ")\n\t scaleX(" + scaleX + ")\n\t"
37 | : '') + "\n";
38 | };
39 | exports.getRect = function (elm, _a) {
40 | var _b = (_a === void 0 ? {} : _a).getMargins, getMargins = _b === void 0 ? false : _b;
41 | var box = elm.getBoundingClientRect();
42 | var styles = getComputedStyle(elm);
43 | return {
44 | top: px(box.top +
45 | window.scrollY -
46 | (getMargins ? parseInt(styles.marginTop || '0', 10) : 0)),
47 | left: px(box.left +
48 | window.scrollX -
49 | (getMargins ? parseInt(styles.marginLeft || '0', 10) : 0)),
50 | width: px(box.width +
51 | (getMargins
52 | ? parseInt(styles.marginLeft || '0', 10) +
53 | parseInt(styles.marginRight || '0', 10)
54 | : 0)),
55 | height: px(box.height +
56 | (getMargins
57 | ? parseInt(styles.marginTop || '0', 10) +
58 | parseInt(styles.marginBottom || '0', 10)
59 | : 0)),
60 | };
61 | };
62 | exports.getValueFromProgress = function (from, to, progress) { return -progress * from + progress * to + from; };
63 | exports.interpolateObject = function (from, to, _a) {
64 | if (from === void 0) { from = {}; }
65 | if (to === void 0) { to = {}; }
66 | var _b = _a.easings, easings = _b === void 0 ? easings_1.linear : _b, isReversed = _a.isReversed;
67 | return function (t) { return (__assign({}, Object.keys(from).reduce(function (acc, key) {
68 | var _a;
69 | var shouldRev = isReversed ? easings_1.createReversed : function (x) { return x; };
70 | var easeFn = shouldRev(typeof easings === 'function' ? easings : easings[key] || easings_1.linear);
71 | return __assign((_a = {}, _a[key] = exports.getValueFromProgress(from[key], to[key], easeFn(t)), _a), acc);
72 | }, {}))); };
73 | };
74 | exports.cloneElement = function (element, _a) {
75 | var portalElement = _a.portalElement, _b = _a.zIndex, zIndex = _b === void 0 ? 0 : _b;
76 | var cloneContainer = document.createElement('div');
77 | var clone = element.cloneNode(true);
78 | cloneContainer.classList.add('rm-cloned');
79 | // cloneContainer.style.pointerEvents = "none";
80 | cloneContainer.style.zIndex = String(1 + zIndex);
81 | cloneContainer.appendChild(clone);
82 | portalElement.appendChild(cloneContainer);
83 | return cloneContainer;
84 | };
85 | exports.clamp = function (min, max) { return function (x) {
86 | return Math.min(Math.max(x, min), max);
87 | }; };
88 | exports.clampProgress = exports.clamp(0, 1);
89 | exports.lerp = function (from, to, isClamped) { return function (t) { return exports.getValueFromProgress(from, to, isClamped ? exports.clampProgress(t) : t); }; };
90 | exports.default = {
91 | interpolateObject: exports.interpolateObject,
92 | };
93 | //# sourceMappingURL=util.js.map
--------------------------------------------------------------------------------
/lib/util.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,qCAAmD;AAEnD,IAAM,EAAE,GAAG,UAAC,CAAS,IAAK,OAAG,CAAC,OAAI,EAAR,CAAQ,CAAC;AAEtB,QAAA,QAAQ,GAAG,UAAC,IAAiB;IAClC,IAAA,iCAA2D,EAAzD,cAAI,EAAE,YAAG,EAAE,gBAAK,EAAE,kBAAuC,CAAC;IAClE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;AAChF,CAAC,CAAC;AAEW,QAAA,iBAAiB,GAAG,UAAC,IAAiB,EAAE,MAAW;IAAX,uBAAA,EAAA,WAAW;IAC9D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,aACtB,QAAQ,EAAE,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W,QAAA,KAAK,GAAG,UAAC,GAAW,EAAE,GAAW,IAAK,OAAA,UAAC,CAAS;IAC3D,OAAA,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC;AAA/B,CAA+B,EADkB,CAClB,CAAC;AACrB,QAAA,aAAa,GAAG,aAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5B,QAAA,IAAI,GAAG,UAAC,IAAY,EAAE,EAAU,EAAE,SAAkB,IAAK,OAAA,UACpE,CAAS,IACN,OAAA,4BAAoB,CAAC,IAAI,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,qBAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAhE,CAAgE,EAFC,CAED,CAAC;AAEtE,kBAAe;IACb,iBAAiB,2BAAA;CAClB,CAAC"}
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-morph",
3 | "version": "0.4.0",
4 | "description": "Ui transitions made simple",
5 | "main": "lib",
6 | "types": "lib/index.d.ts",
7 | "scripts": {
8 | "preversion": "npm run test && npm run build",
9 | "prepublishOnly": "npm run build",
10 | "build": "tsc",
11 | "dev": "tsc --watch",
12 | "test": "eslint src"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "git+https://github.com/brunnolou/react-morph.git"
17 | },
18 | "contributors": [
19 | "Bruno Lourenço"
20 | ],
21 | "license": "MIT",
22 | "bugs": {
23 | "url": "https://github.com/brunnolou/react-morph/issues"
24 | },
25 | "homepage": "https://brunnolou.github.io/react-morph",
26 | "dependencies": {
27 | "@popmotion/popcorn": ">=0.3.1",
28 | "wobble": ">=1.5.1"
29 | },
30 | "peerDependencies": {
31 | "@types/react": ">=16.8.0",
32 | "react": ">=16.8.0"
33 | },
34 | "devDependencies": {
35 | "@typescript-eslint/eslint-plugin": "^1.4.1",
36 | "@typescript-eslint/parser": "^1.4.1",
37 | "ajv-keywords": "^2.1.1",
38 | "babel-cli": "^6.26.0",
39 | "babel-eslint": "^10.0.1",
40 | "babel-plugin-transform-class-properties": "^6.24.1",
41 | "babel-plugin-transform-object-rest-spread": "^6.26.0",
42 | "babel-plugin-transform-regenerator": "^6.26.0",
43 | "babel-preset-react-app": "^7.0.2",
44 | "eslint": "^5.14.1",
45 | "eslint-config-airbnb": "^16.1.0",
46 | "eslint-config-airbnb-base": "^12.1.0",
47 | "eslint-config-prettier": "^4.0.0",
48 | "eslint-config-react-app": "^2.1.0",
49 | "eslint-config-skeleton": "^0.1.4",
50 | "eslint-plugin-flowtype": "^2.44.0",
51 | "eslint-plugin-import": "^2.8.0",
52 | "eslint-plugin-jsx-a11y": "^6.0.3",
53 | "eslint-plugin-prettier": "^3.0.1",
54 | "eslint-plugin-react": "^7.6.1",
55 | "imagesloaded": "^4.1.4",
56 | "prettier": "^1.9.2",
57 | "prettier-eslint": "^8.8.2",
58 | "react": ">=16.8.0",
59 | "styled-components": "^4.1.3",
60 | "typescript": "^3.3.3333",
61 | "uglify-js": "^3.2.2"
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/Morph.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import useMorph from './useMorph';
3 |
4 | const useFadeIn = () => {
5 | return () => ({});
6 | };
7 |
8 | const useHide = () => {
9 | return () => ({});
10 | };
11 |
12 | const Morph = ({ children, ...props }) => {
13 | const morph = useMorph();
14 | const fadeIn = useFadeIn();
15 | const hide = useHide();
16 |
17 | return React.Children.only(
18 | children({
19 | from: morph,
20 | to: morph,
21 |
22 | fadeIn: fadeIn,
23 | fadeOut: fadeIn,
24 |
25 | hide: hide,
26 | }),
27 | );
28 | };
29 |
30 | export default Morph;
31 |
--------------------------------------------------------------------------------
/src/bck_Morph.jsx:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import propTypes from 'prop-types';
3 | import keyframe from 'keyframe';
4 | import raf from 'raf';
5 | import css from 'stylefire/css';
6 | import { linear } from 'popmotion/lib/easing';
7 | import keyframes from 'popmotion/lib/animations/keyframes';
8 | import spring from 'popmotion/lib/animations/spring';
9 | import tween from 'popmotion/lib/animations/tween';
10 | import value from 'popmotion/lib/reactions/value';
11 | import { pipe } from 'popmotion/lib/transformers';
12 | import { interpolateObject } from './util';
13 |
14 | const getBox = (elm, { getMargins = false } = {}) => {
15 | const box = elm.getBoundingClientRect();
16 | const styles = getComputedStyle(elm);
17 |
18 | return {
19 | top:
20 | box.top +
21 | window.scrollY -
22 | (getMargins ? parseInt(styles.marginTop, 10) : 0),
23 | left:
24 | box.left +
25 | window.scrollX -
26 | (getMargins ? parseInt(styles.marginLeft, 10) : 0),
27 | width:
28 | box.width +
29 | (getMargins
30 | ? parseInt(styles.marginLeft, 10) + parseInt(styles.marginRight, 10)
31 | : 0),
32 | height:
33 | box.height +
34 | (getMargins
35 | ? parseInt(styles.marginTop, 10) + parseInt(styles.marginBottom, 10)
36 | : 0),
37 | };
38 | };
39 |
40 | const fadeOutTween = ({ element, options = {} }) =>
41 | tween({
42 | from: 1,
43 | to: 0,
44 | ease: linear,
45 | ...options,
46 | }).start(v => {
47 | const node = element;
48 | node.style.opacity = v;
49 | if (v === 1) node.style.pointerEvents = 'all';
50 | });
51 |
52 | const fadeInTween = ({ element, options = {} }) => {
53 | const styler = css(element);
54 | return keyframes({
55 | values: [{ opacity: 0 }, { opacity: 1 }],
56 | easings: linear,
57 | times: [0.8, 1],
58 | ...options,
59 | })
60 | .start(style => {
61 | const node = element;
62 |
63 | styler.set(style);
64 |
65 | if (style.opacity === 1) node.style.pointerEvents = 'all';
66 | })
67 | .pause();
68 | };
69 |
70 | const hideTween = ({ element }) => ({
71 | seek: pipe(Math.round, t => {
72 | const node = element;
73 |
74 | node.style.visibility = t > 0 ? 'hidden' : 'visible';
75 | }),
76 | });
77 |
78 | const hide = styler => t =>
79 | styler.set({
80 | opacity: t,
81 | visibility: t > 0 ? 'visible' : 'hidden',
82 | });
83 |
84 | const diffRect = (a, b) => ({
85 | translateY: a.top - b.top,
86 | translateX: a.left - b.left,
87 | scaleY: a.height / b.height,
88 | scaleX: a.width / b.width,
89 | });
90 |
91 | class Morph extends Component {
92 | static propTypes = {
93 | // eslint-disable-next-line
94 | portalElement: propTypes.object,
95 | children: propTypes.func.isRequired,
96 | spring: propTypes.shape({
97 | restDelta: propTypes.number,
98 | restSpeed: propTypes.number,
99 | stiffness: propTypes.number.isRequired,
100 | mass: propTypes.number,
101 | damping: propTypes.number.isRequired,
102 | }),
103 | };
104 |
105 | static defaultProps = {
106 | portalElement: global.document && global.document.body,
107 | spring: {
108 | restDelta: 0.001,
109 | restSpeed: 0.001,
110 | damping: 26,
111 | mass: 1,
112 | stiffness: 170,
113 | },
114 | };
115 |
116 | state = {
117 | state: 'from',
118 | };
119 |
120 | componentWillUnmount() {
121 | // Remove clones.
122 | this.elementsCloned.forEach(node =>
123 | this.props.portalElement.removeChild(node),
124 | );
125 | }
126 |
127 | elementFrom = {};
128 | elementTo = {};
129 |
130 | elementsCloned = [];
131 |
132 | hideElements = [];
133 | fadeInElements = [];
134 | fadeOutElements = [];
135 |
136 | isPlaying = false;
137 | timeline = [];
138 |
139 | hide = options => ({
140 | ref: node => {
141 | const element = node;
142 | this.hideElements.push({ element, options });
143 | },
144 | });
145 |
146 | progress = value(0, this.seek);
147 |
148 | fadeIn = options => ({
149 | ref: node => {
150 | const element = node;
151 | if (!element) return;
152 |
153 | element.style.willChange = 'opacity';
154 | element.style.pointerEvents = 'none';
155 | element.style.opacity = 0;
156 | this.fadeInElements.push({ element, options });
157 | },
158 | });
159 |
160 | fadeOut = options => ({
161 | ref: node => {
162 | const element = node;
163 | if (!element) return;
164 |
165 | element.style.willChange = 'opacity';
166 | this.fadeOutElements.push({ element, options });
167 | },
168 | });
169 |
170 | from = (key, options) => ({
171 | ref: node => {
172 | const element = node;
173 | if (!element || this.elementFrom[key]) return;
174 |
175 | element.style.willChange = 'transform';
176 | this.elementFrom[key] = { element, options };
177 | },
178 | });
179 |
180 | to = (key, options) => ({
181 | ref: node => {
182 | const element = node;
183 | if (!element || this.elementTo[key]) return;
184 |
185 | element.style.visibility = 'hidden';
186 | element.style.opacity = 0;
187 | element.style.willChange = 'transform';
188 | this.elementTo[key] = { element, options };
189 | },
190 | });
191 |
192 | go = (to, options = {}) => {
193 | if (!this.timeline.length) {
194 | this.init(to);
195 | return;
196 | }
197 |
198 | spring({
199 | from: this.progress.get(),
200 | to,
201 | ...this.props.spring,
202 | ...options,
203 | }).start(x => {
204 | this.progress.update(x);
205 | this.seek(x);
206 | });
207 | };
208 |
209 | seek = t => {
210 | if (t === 1 || t === 0) {
211 | this.setState({ state: t ? 'to' : 'from' });
212 | }
213 |
214 | this.timeline.forEach(x => x.seek(t));
215 | };
216 |
217 | /* eslint-disable max-statements */
218 | morph = key => {
219 | const {
220 | element: original,
221 | options: {
222 | zIndex,
223 | getMargins = true,
224 | easing: optEasing = x => x,
225 | ...options
226 | } = {},
227 | } = this.elementFrom[key];
228 | const { element: target } = this.elementTo[key];
229 |
230 | const originalRect = getBox(original, { getMargins });
231 | const targetRect = getBox(target, { getMargins });
232 | const originalCloneContainer = document.createElement('div');
233 | const originalClone = original.cloneNode(true);
234 |
235 | originalCloneContainer.appendChild(originalClone);
236 |
237 | const originalStyler = css(original);
238 | const cloneStyler = css(originalCloneContainer);
239 | const targetStyler = css(target);
240 |
241 | cloneStyler.set({
242 | position: 'absolute',
243 | transformOrigin: 'top left',
244 | pointerEvents: 'none',
245 | ...originalRect,
246 | ...options,
247 | zIndex,
248 | });
249 | targetStyler.set({
250 | 'transform-origin': 'top left',
251 | visibility: 'visible',
252 | });
253 |
254 | this.props.portalElement.appendChild(originalCloneContainer);
255 | this.elementsCloned = [...this.elementsCloned, originalCloneContainer];
256 |
257 | const diffStyle = diffRect(targetRect, originalRect);
258 |
259 | const cloneTranslateIn = interpolateObject(
260 | { translateX: 0, translateY: 0, scaleX: 1, scaleY: 1 },
261 | diffStyle,
262 | );
263 |
264 | const diffTargetStyles = diffRect(originalRect, targetRect);
265 | const targetTranslateFLIP = interpolateObject(diffTargetStyles, {
266 | translateX: 0,
267 | translateY: 0,
268 | scaleX: 1,
269 | scaleY: 1,
270 | });
271 |
272 | this.timeline.push(
273 | // In and out track.
274 | {
275 | seek: keyframe({
276 | 0.01: t => {
277 | hide(originalStyler)(1 - t);
278 | },
279 | 30: () => {},
280 | 100: t => {
281 | hide(cloneStyler)(1 - t);
282 | },
283 | }),
284 | },
285 | // Full track.
286 | {
287 | seek: keyframe({
288 | 100: t => {
289 | pipe(optEasing, cloneTranslateIn, cloneStyler.set)(t);
290 | pipe(optEasing, targetTranslateFLIP, targetStyler.set)(t);
291 | },
292 | }),
293 | },
294 | // Half way track.
295 | {
296 | seek: keyframe({
297 | 0.01: t => {
298 | hide(cloneStyler)(t);
299 | },
300 | 30: t => hide(targetStyler)(t),
301 | }),
302 | },
303 | );
304 |
305 | this.isPlaying = true;
306 | };
307 |
308 | init = to => {
309 | if (this.timeline.length) return;
310 |
311 | Object.keys(this.elementFrom).forEach(this.morph);
312 |
313 | const fadeOuts = this.fadeOutElements.map(fadeOutTween);
314 | const fadeIns = this.fadeInElements.map(fadeInTween);
315 | const hidesIns = this.hideElements.map(hideTween);
316 |
317 | this.timeline = [...fadeOuts, ...fadeIns, ...hidesIns, ...this.timeline];
318 |
319 | raf(() => this.go(to));
320 | };
321 |
322 | render() {
323 | const renderedChildren = this.props.children({
324 | from: this.from,
325 | to: this.to,
326 |
327 | fadeIn: this.fadeIn,
328 | fadeOut: this.fadeOut,
329 |
330 | back: this.back,
331 | seek: this.seek,
332 | go: this.go,
333 |
334 | progress: this.progress,
335 | state: this.state.state,
336 |
337 | hide: this.hide,
338 | init: this.init,
339 | });
340 |
341 | return renderedChildren && React.Children.only(renderedChildren);
342 | }
343 | }
344 |
345 | export default Morph;
346 |
--------------------------------------------------------------------------------
/src/easings.ts:
--------------------------------------------------------------------------------
1 | import { Easing } from 'types';
2 |
3 | // Credits to: https://gist.github.com/gre/1650294
4 |
5 | export const createEaseIn = (power: number) => (t: number) =>
6 | Math.pow(t, power);
7 | export const createEaseOut = (power: number) => (t: number) =>
8 | 1 - Math.abs(Math.pow(t - 1, power));
9 | export const createEaseInOut = p => t =>
10 | t < 0.5 ? createEaseIn(p)(t * 2) / 2 : createEaseOut(p)(t * 2 - 1) / 2 + 0.5;
11 |
12 | export const createReversed = (easing: Easing) => (t: number) => 1 - easing(1 - t);
13 |
14 | export const easeInSin = (t: number) =>
15 | 1 + Math.sin((Math.PI / 2) * t - Math.PI / 2);
16 | export const easeOutSin = (t: number) => Math.sin((Math.PI / 2) * t);
17 | export const easeInOutSin = (t: number) =>
18 | (1 + Math.sin(Math.PI * t - Math.PI / 2)) / 2;
19 |
20 | export const easeIn = createEaseIn(2);
21 | export const easeOut = createEaseOut(2);
22 | export const easeInOut = createEaseInOut(2);
23 |
24 | export const linear = (x: number) => x;
25 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | export { default as useMorph } from './useMorph';
2 | export { default as useMorphs } from './useMorphs';
3 | export { default as useMorphKeys } from './useMorphs';
4 | export { default as useMorphList } from './useMorphList';
5 | export { default as useFade } from './useFade';
6 | export { default as presets } from './presets';
7 |
--------------------------------------------------------------------------------
/src/morphTransition.ts:
--------------------------------------------------------------------------------
1 | import { Spring, SpringListenerFn } from 'wobble';
2 | import { cubicBezier, interpolate, reversed } from '@popmotion/popcorn';
3 |
4 | import {
5 | interpolateObject,
6 | applyOverlayStyle,
7 | diffRect,
8 | getTransformString,
9 | cloneElement,
10 | lerp,
11 | clamp,
12 | } from './util';
13 | import { MorphOptions } from './types';
14 |
15 | const resetTranslate = {
16 | translateX: 0,
17 | translateY: 0,
18 | scaleX: 1,
19 | scaleY: 1,
20 | };
21 |
22 | const ease = cubicBezier(0.9, 0.9, 0.37, 0.98);
23 | const easeRev = reversed(ease);
24 | const easeInOut = cubicBezier(0.5, 0.5, 0, 1);
25 |
26 | const delaysRatio = 0.1;
27 | const halfClampEnd = clamp(1 - delaysRatio, 1);
28 | const halfClampStart = clamp(0, delaysRatio);
29 | const easeFast = (x: number) =>
30 | easeInOut(
31 | Number(interpolate([1 - delaysRatio, 1], [0, 1])(halfClampEnd(x))),
32 | );
33 | const easeSlow = (x: number) =>
34 | easeInOut(Number(interpolate([0, delaysRatio], [0, 1])(halfClampStart(x))));
35 |
36 | type Options = {
37 | from: HTMLElement;
38 | to: HTMLElement;
39 | rectFrom: CSSStyleDeclaration;
40 | rectTo: CSSStyleDeclaration;
41 | fromValue?: number;
42 | initialVelocity?: number;
43 | onUpdate?: SpringListenerFn;
44 | onStart?: SpringListenerFn;
45 | onStop?: SpringListenerFn;
46 | willBack?: boolean;
47 | options: MorphOptions;
48 | };
49 |
50 | export default function morphTransition({
51 | from,
52 | to,
53 | rectFrom,
54 | rectTo,
55 | fromValue = 0,
56 | initialVelocity,
57 | onUpdate = () => {},
58 | onStart = () => {},
59 | onStop = () => {},
60 | willBack,
61 | options,
62 | }: Options) {
63 | const spring = new Spring({
64 | fromValue,
65 | initialVelocity,
66 | toValue: 1,
67 | ...options.spring,
68 | });
69 |
70 | const fromDiffStyle = diffRect(rectFrom, rectTo);
71 | const toDiffStyle = diffRect(rectTo, rectFrom);
72 |
73 | const fromContainer = cloneElement(from, options);
74 | const toContainer = cloneElement(to, options);
75 |
76 | // hideInnerMorph(toContainer);
77 | // hideInnerMorph(fromContainer);
78 |
79 | to.style.visibility = 'hidden';
80 | to.style.pointerEvents = 'none';
81 | from.style.visibility = 'hidden';
82 | from.style.pointerEvents = 'none';
83 |
84 | applyOverlayStyle(toContainer, rectTo);
85 | applyOverlayStyle(fromContainer, rectFrom);
86 |
87 | const toFLIP = interpolateObject(fromDiffStyle, resetTranslate, options);
88 | const fromFLIP = interpolateObject(resetTranslate, toDiffStyle, options);
89 |
90 | const toFade = lerp(0, 1, true);
91 | const fromFade = lerp(1, 0, true);
92 |
93 | let isDeleted = false;
94 |
95 | const onProgress = (p: number) => {
96 | switch (options.type) {
97 | case 'morph':
98 | default:
99 | toContainer.style.opacity = String(toFade(ease(p)));
100 | fromContainer.style.opacity = String(fromFade(easeRev(p)));
101 | toContainer.style.transform = getTransformString(toFLIP(p));
102 | fromContainer.style.transform = getTransformString(fromFLIP(p));
103 | }
104 | };
105 |
106 | spring
107 | .onStart(onStart)
108 | .onUpdate(s => {
109 | const p = s.currentValue;
110 | onProgress(p);
111 | onUpdate(s);
112 | })
113 | .onStop(s => {
114 | if (s.currentValue === 0 || s.currentValue === 1) {
115 | onStop(s);
116 | cleanup();
117 | }
118 | });
119 |
120 | if (typeof options.progress === 'undefined') {
121 | spring.start();
122 | } else {
123 | onProgress(options.progress);
124 | }
125 |
126 | const setProgress = (progress: number) => {
127 | onProgress(progress);
128 | if (progress === 0 || progress === 1) {
129 | onStop(null);
130 | // cleanup();
131 | }
132 | };
133 |
134 | const cleanup = () => {
135 | if (isDeleted) return;
136 | if (options.portalElement) {
137 | options.portalElement.removeChild(toContainer);
138 | options.portalElement.removeChild(fromContainer);
139 | }
140 | to.style.visibility = ''; // show original to
141 | to.style.pointerEvents = ''; // show original to
142 |
143 | if (!willBack) {
144 | // show original from
145 | from.style.pointerEvents = '';
146 | from.style.visibility = '';
147 | }
148 | isDeleted = true;
149 | };
150 |
151 | return { cleanup, setProgress };
152 | }
153 |
--------------------------------------------------------------------------------
/src/presets.ts:
--------------------------------------------------------------------------------
1 | // credits to react-motion
2 | export const noWobble = { stiffness: 170, damping: 26 };
3 | export const gentle = { stiffness: 120, damping: 14 };
4 | export const wobbly = { stiffness: 180, damping: 12 };
5 | export const stiff = { stiffness: 210, damping: 20 };
6 | export const slowMo = { stiffness: 5, damping: 30 };
7 |
8 | export default {
9 | noWobble,
10 | gentle,
11 | wobbly,
12 | stiff,
13 | slowMo,
14 | };
15 |
--------------------------------------------------------------------------------
/src/types.d.ts:
--------------------------------------------------------------------------------
1 | import { Easing } from '@popmotion/easing';
2 |
3 | export type NumberObject = { [key: string]: number };
4 | export type EaseObject = { [key: string]: Easing };
5 | export type Easings = EaseObject | Easing;
6 | export type Easing = (v: number) => number;
7 |
8 | export interface SpringConfig {
9 | stiffness?: number; // The spring stiffness coefficient.
10 | damping?: number; // Defines how the spring’s motion should be damped due to the forces of friction.
11 | mass?: number; // The mass of the object attached to the end of the spring.
12 | allowsOverdamping?: boolean; // Whether or not the spring allows "overdamping" (a damping ratio > 1). Defaults to false.
13 | overshootClamping?: boolean; // False when overshooting is allowed, true when it is not. Defaults to false.
14 | restVelocityThreshold?: number; // When spring's velocity is below `restVelocityThreshold`, it is at rest. Defaults to .001.
15 | restDisplacementThreshold?: number; // When the spring's displacement (current value) is below `restDisplacementThreshold`, it is at rest. Defaults to .001.
16 | }
17 |
18 | export interface MorphOptions {
19 | keepFrom?: boolean;
20 | type?: string;
21 | getMargins?: boolean;
22 | portalElement?: HTMLElement;
23 | zIndex?: number;
24 | spring?: SpringConfig;
25 | isReversed?: boolean;
26 | easings?: Easings;
27 | progress?: number;
28 | withMethods?: boolean;
29 | }
30 | export interface FadeOptions extends MorphOptions {
31 | isInitial?: boolean;
32 | }
33 |
34 | // Morph
35 | export interface MorphObj {
36 | ref: (to: HTMLElement) => void;
37 | style: React.CSSProperties;
38 | resize?: () => void;
39 | }
40 |
41 | export type MorphFn = (obj: { style?: React.CSSProperties }) => MorphObj;
42 |
43 | export type Morph = MorphObj & MorphFn;
44 |
--------------------------------------------------------------------------------
/src/useFade.ts:
--------------------------------------------------------------------------------
1 | import { useRef, useCallback, useEffect } from 'react';
2 | import { Spring } from 'wobble';
3 |
4 | import { getRect, cloneElement, applyOverlayStyle } from './util';
5 | import { FadeOptions } from './types';
6 | import { linear, easeOut, easeInOut } from '@popmotion/easing';
7 | import { clamp, interpolate } from '@popmotion/popcorn';
8 |
9 | const globalAny: any = global;
10 |
11 | const defaultsOptions = {
12 | keepFrom: false,
13 | type: 'morph',
14 | getMargins: false,
15 | portalElement: globalAny.document && globalAny.document.body,
16 | spring: {
17 | damping: 26,
18 | mass: 1,
19 | stiffness: 180,
20 | overshootClamping: true,
21 | },
22 | easings: linear,
23 | delaysRatio: 0.1,
24 | isInitial: false,
25 | };
26 |
27 | export default function useFade(opts: FadeOptions = defaultsOptions) {
28 | const options = { ...defaultsOptions, ...opts };
29 | const { getMargins, isInitial, delaysRatio } = options;
30 |
31 | const prevNodeRef = useRef() as React.MutableRefObject;
32 | const cloneContainerRef = useRef() as React.MutableRefObject;
33 | const isMountedRef = useRef() as React.MutableRefObject;
34 |
35 | const cleanup = () => {
36 | if (!cloneContainerRef.current) return;
37 | prevNodeRef.current.style.visibility = null;
38 | options.portalElement.removeChild(cloneContainerRef.current);
39 | cloneContainerRef.current = null;
40 | };
41 |
42 | const halfClampEnd = clamp(1 - delaysRatio, 1);
43 | const easeFast = (x: number) =>
44 | easeInOut(
45 | Number(interpolate([1 - delaysRatio, 1], [0, 1])(halfClampEnd(x))),
46 | );
47 |
48 | const spring = new Spring({
49 | fromValue: Number(isInitial),
50 | toValue: Number(!isInitial),
51 | ...options.spring,
52 | });
53 |
54 | spring
55 | .onUpdate(s => {
56 | if (!cloneContainerRef.current) return;
57 |
58 | cloneContainerRef.current.style.opacity = String(
59 | easeFast(s.currentValue),
60 | );
61 | })
62 | .onStop(cleanup);
63 |
64 | const getRef = useCallback(n => {
65 | const node = n || prevNodeRef.current;
66 | const hasNode = !!node;
67 |
68 | if (hasNode && isMountedRef.current) {
69 | node.style.visibility = 'visible';
70 | const rect = getRect(node, { getMargins });
71 |
72 | if (!cloneContainerRef.current)
73 | cloneContainerRef.current = cloneElement(node, options);
74 |
75 | node.style.visibility = 'hidden';
76 |
77 | prevNodeRef.current = node;
78 |
79 | applyOverlayStyle(cloneContainerRef.current, {
80 | ...rect,
81 | // border: '2px solid red',
82 | });
83 | }
84 |
85 | const toValue = Number(!!n);
86 |
87 | if (spring.currentValue === toValue) cleanup();
88 |
89 | spring.updateConfig({ toValue }).start();
90 | }, []);
91 |
92 | isMountedRef.current = true;
93 |
94 | const style: React.CSSProperties = { visibility: 'hidden' };
95 |
96 | const props = {
97 | ref: getRef,
98 | style,
99 | };
100 |
101 | const propsFn = ({ style = {}, ...extra } = {}) => ({
102 | ...props,
103 | style: { ...props.style, ...style },
104 | });
105 |
106 | propsFn.ref = getRef;
107 | propsFn.style = style;
108 |
109 | return propsFn;
110 | }
111 |
--------------------------------------------------------------------------------
/src/useMorph.ts:
--------------------------------------------------------------------------------
1 | import { useRef, useCallback, useEffect } from 'react';
2 | import { Spring } from 'wobble';
3 | import { linear } from '@popmotion/easing';
4 |
5 | import morphTransition from './morphTransition';
6 | import { getRect } from './util';
7 | import { MorphOptions, Morph } from './types';
8 |
9 | const globalAny: any = global;
10 |
11 | type AnimateObject = {
12 | from: HTMLElement;
13 | to: HTMLElement;
14 | rectFrom: CSSStyleDeclaration;
15 | rectTo: CSSStyleDeclaration;
16 | willBack?: boolean;
17 | };
18 |
19 | const defaultsOptions = {
20 | keepFrom: false,
21 | type: 'morph',
22 | getMargins: false,
23 | portalElement: globalAny.document && globalAny.document.body,
24 | spring: {
25 | damping: 26,
26 | mass: 1,
27 | stiffness: 180,
28 | },
29 | easings: linear,
30 | isReversed: false,
31 | withMethods: false,
32 | };
33 |
34 | export default function useMorph(opts: MorphOptions = defaultsOptions): Morph {
35 | const options = { ...defaultsOptions, ...opts };
36 | const {
37 | getMargins,
38 | keepFrom,
39 | spring: { damping, mass, stiffness },
40 | isReversed,
41 | } = options;
42 |
43 | const backAnimationRef = useRef() as React.MutableRefObject;
44 | const prevToRef = useRef() as React.MutableRefObject;
45 | const prevToRectRef = useRef() as React.MutableRefObject;
46 | const prevSpringRef = useRef() as React.MutableRefObject;
47 | const cleanupFromRef = useRef() as React.MutableRefObject<() => void>;
48 | const setProgressRef = useRef() as React.MutableRefObject<
49 | (progress: number) => void
50 | >;
51 |
52 | let isAnimating = false;
53 | let cleanup: () => void;
54 |
55 | function resize() {
56 | if (!prevToRef.current) return;
57 | prevToRectRef.current = getRect(prevToRef.current, { getMargins });
58 | }
59 |
60 | // Window on resize effect.
61 | useEffect(() => {
62 | if (!prevToRef.current) return;
63 |
64 | window.addEventListener('resize', resize);
65 |
66 | return () => window.removeEventListener('resize', resize);
67 | }, []);
68 |
69 | const animate = ({ from, to, rectFrom, rectTo, willBack }: AnimateObject) => {
70 | if (!to) return;
71 |
72 | to.style.visibility = 'visible';
73 |
74 | if (!from) return;
75 |
76 | isAnimating = true;
77 |
78 | const prevSpring = prevSpringRef.current;
79 |
80 | switch (options.type) {
81 | case 'fade':
82 | case 'morph':
83 | default:
84 | const morph = morphTransition({
85 | from,
86 | to,
87 | rectFrom,
88 | rectTo,
89 | fromValue:
90 | prevSpring !== undefined && prevSpring.currentValue !== 1
91 | ? 1 - prevSpring.currentValue
92 | : 0,
93 | initialVelocity:
94 | prevSpring !== undefined && prevSpring.currentVelocity !== 0
95 | ? prevSpring.currentVelocity * -1
96 | : 0,
97 | onUpdate(s) {
98 | prevSpringRef.current = s;
99 | },
100 | willBack,
101 | options,
102 | });
103 |
104 | cleanup = morph.cleanup;
105 | setProgressRef.current = morph.setProgress;
106 |
107 | cleanupFromRef.current = cleanup;
108 | }
109 |
110 | return () => {
111 | if (isAnimating) cleanup();
112 | };
113 | };
114 |
115 | useEffect(() => {
116 | if (!setProgressRef.current) return;
117 | setProgressRef.current(options.progress);
118 | }, [options.progress]);
119 |
120 | const getRef = useCallback(
121 | to => {
122 | const from = prevToRef.current;
123 | const cleanupFrom = cleanupFromRef.current;
124 |
125 | if (from === to) return;
126 |
127 | const willUnmount = !to;
128 | const willAnimate = !!to && !!from;
129 |
130 | const willBack = keepFrom && willAnimate;
131 | const isBackwards = keepFrom && willUnmount && !!from;
132 |
133 | if (cleanupFrom) cleanupFrom();
134 |
135 | if (isBackwards) {
136 | animate(backAnimationRef.current);
137 |
138 | return;
139 | }
140 |
141 | if (willUnmount) {
142 | if (cleanup) cleanup();
143 | return;
144 | }
145 |
146 | const rectFrom = prevToRectRef.current;
147 | const rectTo = getRect(to, { getMargins });
148 |
149 | animate({ from, rectFrom, to, rectTo, willBack });
150 |
151 | backAnimationRef.current = {
152 | from: to,
153 | rectFrom: rectTo,
154 | to: from,
155 | rectTo: rectFrom,
156 | };
157 |
158 | if (!willBack) {
159 | prevToRef.current = to;
160 | prevToRectRef.current = rectTo;
161 | }
162 | },
163 | [keepFrom, damping, mass, stiffness, isReversed],
164 | );
165 |
166 | const style: React.CSSProperties = { visibility: 'hidden' };
167 |
168 | const props = {
169 | ref: getRef,
170 | style,
171 | };
172 |
173 | const propsFn: Morph = ({ style = {}, ...extra } = {}) => ({
174 | ...props,
175 | style: { ...props.style, ...style },
176 | });
177 |
178 | propsFn.ref = getRef;
179 | propsFn.style = style;
180 |
181 | if (options.withMethods) {
182 | propsFn.resize = resize;
183 | }
184 |
185 | return propsFn;
186 | }
187 |
--------------------------------------------------------------------------------
/src/useMorphList.ts:
--------------------------------------------------------------------------------
1 | import useMorph from './useMorph';
2 | import { MorphOptions } from './types';
3 |
4 | type OptionsMapperFn = (items: any[]) => MorphOptions;
5 |
6 | const useMorphList = (
7 | items: any[] | number,
8 | options: OptionsMapperFn | MorphOptions = {},
9 | ) => {
10 | let list = items;
11 |
12 | if (typeof list === 'number') list = Array(list).fill(0);
13 |
14 | const optionsFn = typeof options === 'function' ? options : () => options;
15 |
16 | return list
17 | .map(optionsFn)
18 | .map((options: MorphOptions, i: number) =>
19 | useMorph({ zIndex: i, ...options }),
20 | );
21 | };
22 |
23 | export default useMorphList;
24 |
--------------------------------------------------------------------------------
/src/useMorphs.ts:
--------------------------------------------------------------------------------
1 | import useMorph from './useMorph';
2 | import { MorphOptions, Morph } from './types';
3 |
4 | type ObjectKey = {
5 | key?: string;
6 | };
7 |
8 | function useMorphs<
9 | A extends string,
10 | B extends string,
11 | C extends string,
12 | D extends string,
13 | E extends string,
14 | F extends string,
15 | G extends string,
16 | H extends string
17 | >(
18 | keys: [A, B, C, D, E, F, G, H],
19 | options?: MorphOptions,
20 | ): { [key in A | B | C | D | E | F | G | H]: Morph };
21 |
22 | function useMorphs<
23 | A extends string,
24 | B extends string,
25 | C extends string,
26 | D extends string,
27 | E extends string,
28 | F extends string,
29 | G extends string
30 | >(
31 | keys: [A, B, C, D, E, F, G],
32 | options?: MorphOptions,
33 | ): { [key in A | B | C | D | E | F | G]: Morph };
34 |
35 | function useMorphs<
36 | A extends string,
37 | B extends string,
38 | C extends string,
39 | D extends string,
40 | E extends string,
41 | F extends string
42 | >(
43 | keys: [A, B, C, D, E, F],
44 | options?: MorphOptions,
45 | ): { [key in A | B | C | D | E | F]: Morph };
46 |
47 | function useMorphs<
48 | A extends string,
49 | B extends string,
50 | C extends string,
51 | D extends string,
52 | E extends string
53 | >(
54 | keys: [A, B, C, D, E],
55 | options?: MorphOptions,
56 | ): { [key in A | B | C | D | E]: Morph };
57 |
58 | function useMorphs<
59 | A extends string,
60 | B extends string,
61 | C extends string,
62 | D extends string
63 | >(
64 | keys: [A, B, C, D],
65 | options?: MorphOptions,
66 | ): { [key in A | B | C | D]: Morph };
67 |
68 | function useMorphs(
69 | keys: [A, B, C],
70 | options?: MorphOptions,
71 | ): { [key in A | B | C]: Morph };
72 |
73 | function useMorphs (
74 | keys: [A, B],
75 | options?: MorphOptions,
76 | ): { [key in A | B]: Morph };
77 |
78 | function useMorphs(keys, options = {}): ObjectKey {
79 | const morphObject = keys.reduce((acc: Morph, key: string, i: number) => {
80 | return { ...acc, [key]: useMorph({ zIndex: i, ...options }) };
81 | }, {});
82 |
83 | return morphObject;
84 | }
85 |
86 | export default useMorphs;
87 |
--------------------------------------------------------------------------------
/src/util.ts:
--------------------------------------------------------------------------------
1 | import { MorphOptions, NumberObject, Easing } from './types';
2 | import { createReversed, linear } from './easings';
3 |
4 | const px = (x: number) => `${x}px`;
5 |
6 | export const getRects = (node: HTMLElement) => {
7 | const { left, top, width, height } = node.getBoundingClientRect();
8 | return { left: px(left), top: px(top), width: px(width), height: px(height) };
9 | };
10 |
11 | export const applyOverlayStyle = (node: HTMLElement, styles = {}) => {
12 | Object.assign(node.style, {
13 | position: 'absolute',
14 | // border: '2px solid red',
15 | 'transform-origin': 'top left',
16 | ...styles,
17 | });
18 | };
19 |
20 | export const diffRect = (a: HTMLElement['style'], b: HTMLElement['style']) => ({
21 | translateY: parseInt(a.top || '0', 10) - parseInt(b.top || '0', 10),
22 | translateX: parseInt(a.left || '0', 10) - parseInt(b.left || '0', 10),
23 | scaleY: parseInt(a.height || '0', 10) / parseInt(b.height || '0', 10),
24 | scaleX: parseInt(a.width || '0', 10) / parseInt(b.width || '0', 10),
25 | });
26 |
27 | export const getTransformString = (
28 | { translateY, translateX, scaleY, scaleX }: NumberObject,
29 | removeScale = false,
30 | ) => `
31 | translateY(${px(translateY)})
32 | translateX(${px(translateX)})
33 | ${
34 | !removeScale
35 | ? `
36 | scaleY(${scaleY})
37 | scaleX(${scaleX})
38 | `
39 | : ''
40 | }
41 | `;
42 |
43 | export const getRect = (elm: HTMLElement, { getMargins = false } = {}) => {
44 | const box = elm.getBoundingClientRect();
45 | const styles = getComputedStyle(elm);
46 |
47 | return {
48 | top: px(
49 | box.top +
50 | window.scrollY -
51 | (getMargins ? parseInt(styles.marginTop || '0', 10) : 0),
52 | ),
53 | left: px(
54 | box.left +
55 | window.scrollX -
56 | (getMargins ? parseInt(styles.marginLeft || '0', 10) : 0),
57 | ),
58 | width: px(
59 | box.width +
60 | (getMargins
61 | ? parseInt(styles.marginLeft || '0', 10) +
62 | parseInt(styles.marginRight || '0', 10)
63 | : 0),
64 | ),
65 | height: px(
66 | box.height +
67 | (getMargins
68 | ? parseInt(styles.marginTop || '0', 10) +
69 | parseInt(styles.marginBottom || '0', 10)
70 | : 0),
71 | ),
72 | } as CSSStyleDeclaration;
73 | };
74 |
75 | export const getValueFromProgress = (
76 | from: number,
77 | to: number,
78 | progress: number,
79 | ) => -progress * from + progress * to + from;
80 |
81 | export const interpolateObject = (
82 | from: NumberObject = {},
83 | to: NumberObject = {},
84 | { easings = linear, isReversed }: MorphOptions,
85 | ) => (t: number) => ({
86 | ...Object.keys(from).reduce((acc, key) => {
87 | const shouldRev = isReversed ? createReversed : (x: Easing) => x;
88 | const easeFn = shouldRev(
89 | typeof easings === 'function' ? easings : easings[key] || linear,
90 | );
91 |
92 | return {
93 | [key]: getValueFromProgress(from[key], to[key], easeFn(t)),
94 | ...acc,
95 | };
96 | }, {}),
97 | });
98 |
99 | export const cloneElement = (
100 | element: HTMLElement,
101 | { portalElement, zIndex = 0 }: MorphOptions,
102 | ) => {
103 | const cloneContainer = document.createElement('div');
104 | const clone = element.cloneNode(true);
105 |
106 | cloneContainer.classList.add('rm-cloned');
107 | // cloneContainer.style.pointerEvents = "none";
108 | cloneContainer.style.zIndex = String(1 + zIndex);
109 | cloneContainer.appendChild(clone);
110 | portalElement.appendChild(cloneContainer);
111 |
112 | return cloneContainer;
113 | };
114 |
115 | export const clamp = (min: number, max: number) => (x: number) =>
116 | Math.min(Math.max(x, min), max);
117 | export const clampProgress = clamp(0, 1);
118 | export const lerp = (from: number, to: number, isClamped: Boolean) => (
119 | t: number,
120 | ) => getValueFromProgress(from, to, isClamped ? clampProgress(t) : t);
121 |
122 | export default {
123 | interpolateObject,
124 | };
125 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "baseUrl": "src",
4 | "module": "commonjs",
5 | "target": "es5",
6 | "lib": ["es5", "es6", "es7", "es2017", "dom"],
7 | "moduleResolution": "node",
8 | "declaration": true,
9 | "outDir": "./lib",
10 | "jsx": "react",
11 | "skipLibCheck": true,
12 | "sourceMap": true,
13 | "strict": false
14 | },
15 | "plugins": ["@typescript-eslint"],
16 | "include": ["src/*"]
17 | }
18 |
--------------------------------------------------------------------------------