diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..758659af --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: ant-design +open_collective: ant-design diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..acfc98e8 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,43 @@ +name: CodeQL + +on: + push: + branches: [master] + pull_request: + branches: [master] + schedule: + - cron: '17 18 * * 2' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [javascript] + + steps: + - name: Checkout + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + with: + persist-credentials: false + + - name: Initialize CodeQL + uses: github/codeql-action/init@411bbbe57033eedfc1a82d68c01345aa96c737d7 + with: + languages: ${{ matrix.language }} + queries: +security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@411bbbe57033eedfc1a82d68c01345aa96c737d7 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@411bbbe57033eedfc1a82d68c01345aa96c737d7 + with: + category: '/language:${{ matrix.language }}' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5e426ee2..a33292ef 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,113 +1,15 @@ -name: CI +name: ✅ test on: push: - branches: [master, 3.0] + branches: [master] pull_request: branches: [master] -jobs: - setup: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@master - - - uses: actions/setup-node@v1 - with: - node-version: '12' - - - name: cache package-lock.json - uses: actions/cache@v2 - with: - path: package-temp-dir - key: lock-${{ github.sha }} - - - name: create package-lock.json - run: npm i --package-lock-only - - - name: hack for singe file - run: | - if [ ! -d "package-temp-dir" ]; then - mkdir package-temp-dir - fi - cp package-lock.json package-temp-dir - - name: cache node_modules - id: node_modules_cache_id - uses: actions/cache@v2 - with: - path: node_modules - key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - - - name: install - if: steps.node_modules_cache_id.outputs.cache-hit != 'true' - run: npm ci - - lint: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@master - - - name: restore cache from package-lock.json - uses: actions/cache@v2 - with: - path: package-temp-dir - key: lock-${{ github.sha }} - - - name: restore cache from node_modules - uses: actions/cache@v2 - with: - path: node_modules - key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - - - name: lint - run: npm run lint +permissions: + contents: read - needs: setup - - compile: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@master - - - name: restore cache from package-lock.json - uses: actions/cache@v2 - with: - path: package-temp-dir - key: lock-${{ github.sha }} - - - name: restore cache from node_modules - uses: actions/cache@v2 - with: - path: node_modules - key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - - - name: compile - run: npm run compile - - needs: setup - - coverage: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@master - - - name: restore cache from package-lock.json - uses: actions/cache@v2 - with: - path: package-temp-dir - key: lock-${{ github.sha }} - - - name: restore cache from node_modules - uses: actions/cache@v2 - with: - path: node_modules - key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - - - name: coverage - run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash) - - needs: setup +jobs: + test: + uses: react-component/rc-test/.github/workflows/test-utoo.yml@b8ebddc81ef706b50faff0242ab34ad8ecdd9a59 + secrets: inherit diff --git a/.github/workflows/react-doctor.yml b/.github/workflows/react-doctor.yml new file mode 100644 index 00000000..0b6c9553 --- /dev/null +++ b/.github/workflows/react-doctor.yml @@ -0,0 +1,25 @@ +name: React Doctor + +on: + pull_request: + branches: [master] + +permissions: + contents: read + pull-requests: write + +concurrency: + group: react-doctor-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + react-doctor: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + with: + persist-credentials: false + + - uses: millionco/react-doctor@0b4f4f4bd248a154e64eb508a48347f71154b3f3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml new file mode 100644 index 00000000..b6fd3e3d --- /dev/null +++ b/.github/workflows/surge-preview.yml @@ -0,0 +1,38 @@ +name: Surge Preview + +on: + pull_request: + branches: [master] + +permissions: + contents: read + pull-requests: write + statuses: write + +concurrency: + group: surge-preview-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + preview: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + with: + persist-credentials: false + + - name: Install dependencies + run: npm install --legacy-peer-deps --ignore-scripts --no-audit --loglevel=warn + + - name: Build preview + if: ${{ secrets.SURGE_TOKEN != '' }} + run: npm run build + - uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec + if: ${{ secrets.SURGE_TOKEN != '' }} + env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + with: + dist: docs-dist + failOnError: false + github_token: ${{ secrets.GITHUB_TOKEN }} + surge_token: ${{ env.SURGE_TOKEN }} diff --git a/.gitignore b/.gitignore index cc16e2a1..0124cfdc 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,7 @@ coverage yarn.lock package-lock.json .vscode -.doc +.vercel # production /dist /docs-dist @@ -43,3 +43,4 @@ package-lock.json .umi-test .env.local src/.umi +src/.umi-production diff --git a/.prettierignore b/.prettierignore index b785a086..2adbab11 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,4 +4,7 @@ package.json .umi .umi-production -.umi-test \ No newline at end of file +.umi-test +src/.umi-production +docs-dist +build diff --git a/.umirc.ts b/.umirc.ts index 5433878f..634552b1 100644 --- a/.umirc.ts +++ b/.umirc.ts @@ -3,12 +3,16 @@ import { defineConfig } from 'dumi'; const path = require('path'); export default defineConfig({ - title: 'rc-tween-one', + title: '@rc-component/tween-one', favicon: 'https://zos.alipayobjects.com/rmsportal/TOXWfHIUGHvZIyb.svg', logo: 'https://zos.alipayobjects.com/rmsportal/TOXWfHIUGHvZIyb.svg', - outputPath: '.doc', + outputPath: 'docs-dist', alias: { + '@rc-component/tween-one/es': path.join(__dirname, 'src'), + '@rc-component/tween-one/lib': path.join(__dirname, 'src'), + '@rc-component/tween-one': path.join(__dirname, 'src'), 'rc-tween-one/es': path.join(__dirname, 'src'), 'rc-tween-one/lib': path.join(__dirname, 'src'), + 'rc-tween-one': path.join(__dirname, 'src'), }, -}); \ No newline at end of file +}); diff --git a/README.md b/README.md index ad2fc517..57e086a7 100644 --- a/README.md +++ b/README.md @@ -1,155 +1,164 @@ +
+

@rc-component/tween-one

+

Ant Design Part of the Ant Design ecosystem.

+

🎬 Tween animation primitives for React, maintained in the Ant Design ecosystem.

+
-# rc-tween-one ---- +

English | 简体中文

-React TweenOne Component +
-[![NPM version][npm-image]][npm-url] -[![build status][github-actions-image]][github-actions-url] -[![Codecov][codecov-image]][codecov-url] -[![node version][node-image]][node-url] -[![npm download][download-image]][download-url] +[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![bundle size][bundlephobia-image]][bundlephobia-url] [![dumi][dumi-image]][dumi-url] -[npm-image]: http://img.shields.io/npm/v/rc-tween-one.svg?style=flat-square -[npm-url]: http://npmjs.org/package/rc-tween-one -[github-actions-image]: https://github.com/react-component/tween-one/workflows/CI/badge.svg -[github-actions-url]: https://github.com/react-component/tween-one/actions -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/tween-one/master.svg?style=flat-square -[codecov-url]: https://codecov.io/gh/react-component/tween-one/branch/master -[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square -[node-url]: http://nodejs.org/download/ -[download-image]: https://img.shields.io/npm/dm/rc-tween-one.svg?style=flat-square -[download-url]: https://npmjs.org/package/rc-tween-one +
+## Highlights -## Browser Support - -|![IE](https://github.com/alrra/browser-logos/blob/master/src/edge/edge_48x48.png?raw=true) | ![Chrome](https://github.com/alrra/browser-logos/blob/master/src/chrome/chrome_48x48.png?raw=true) | ![Firefox](https://github.com/alrra/browser-logos/blob/master/src/firefox/firefox_48x48.png?raw=true) | ![Opera](https://github.com/alrra/browser-logos/blob/master/src/opera/opera_48x48.png?raw=true) | ![Safari](https://github.com/alrra/browser-logos/blob/master/src/safari/safari_48x48.png?raw=true)| -| --- | --- | --- | --- | --- | -| IE 10+ ✔ | Chrome 31.0+ ✔ | Firefox 31.0+ ✔ | Opera 30.0+ ✔ | Safari 7.0+ ✔ | +- Declarative tween animation component for React elements and SVG. +- Timeline, repeat, yoyo, path motion, SVG draw/morph, number animation, and group transition support. +- Used by Ant Design motion examples and legacy animation demos. -## Development +## Install +```bash +npm install @rc-component/tween-one ``` -npm install -npm start + +`rc-tween-one` is the legacy package name. New releases should use the scoped `@rc-component/tween-one` package. + +## Usage + +```tsx +import TweenOne from '@rc-component/tween-one'; + +export default () => ( + + demo + +); ``` -## Example +## Plugin APIs -http://localhost:8100/examples/ +```tsx +import TweenOne, { Plugins } from '@rc-component/tween-one'; +import SvgDrawPlugin from '@rc-component/tween-one/es/plugin/SvgDrawPlugin'; -2.x: http://react-component.github.io/tween-one/ +Plugins.push(SvgDrawPlugin); -3.x: https://tween-one.vercel.app/ +export default () => ( + + + +); +``` -## install +## Examples +- Local docs: run `npm start` and open the printed dumi URL. +- Pull request previews are published by Vercel and Surge. +- Motion API docs: https://motion.ant.design/api/tween-one -[![rc-tween-one](https://nodei.co/npm/rc-tween-one.png)](https://npmjs.org/package/rc-tween-one) +## Browser Support +| Edge | Chrome | Firefox | Opera | Safari | +| ------ | ---------- | ----------- | --------- | --------- | +| IE 10+ | Chrome 31+ | Firefox 31+ | Opera 30+ | Safari 7+ | -## Usage +## Development -```js | pure -var TweenOne = require('rc-tween-one'); -var React = require('react'); -React.render( - demo -, container); +```bash +npm install --legacy-peer-deps +npm start ``` -### Plugin +Useful checks: -```js | pure -var TweenOne = require('rc-tween-one'); -var React = require('react'); -var SvgDrawPlugin = require('rc-tween-one/lib/plugin/SvgDrawPlugin'); -TweenOne.plugins.push(SvgDrawPlugin); -React.render( - -, container); +```bash +npm run lint +npm run tsc +npm test +npm run build +npm run compile ``` -### TweenOneGroup -```js | pure -var TweenOne = require('rc-tween-one'); -var React = require('react'); -var TweenOneGroup = TweenOne.TweenOneGroup; -React.render( -
demo
-
demo
-
, container); +## Release + +```bash +npm run prepublishOnly ``` +The release flow is handled by `@rc-component/np` through the `rc-np` command after the package build. ## API 中文文档 ### props -| name | type | default | description | -|------------|----------------|---------|----------------| -| animation | object / array | null | animate configure parameters | -| paused | boolean | false | animate timeline pause | -| reverse | boolean | false | animate timeline revers | -| delay | number | 0 | animate timeline delay | -| repeat | number | 0 | `animation` all data repeat, To repeat indefinitely, use -1 | -| repeatDelay | number | 0 | animate timeline repeat delay | -| yoyo | boolean | false | `animation` all data alternating backward and forward on each repeat. | -| onChange | func | null | when the animation change called, callback({ moment, targets, index, mode, ratio, vars, index, repeat }) | -| onChangeTimeline | func | null | when the animation change called, callback({ mode, targets, vars, moment, totalTime, repeat }) | -| moment | number | null | set the current frame | -| regionStartTime | number | 0 | Set the start time of the animation region | -| regionEndTime | number | null | Set the end time of the animation region | -| attr | boolean | false | attribute animation is `true`, when morph SVG must be `true`. | -| resetStyle | boolean | false | update animation data, reset init style | -| component | string / React.Element | `div` | component tag | -| componentProps | object | null | component is React.Element, component tag props, not add `style` | - +| name | type | default | description | +| ---------------- | ---------------------- | ------- | -------------------------------------------------------------------------------------------------------- | +| animation | object / array | null | animate configure parameters | +| paused | boolean | false | animate timeline pause | +| reverse | boolean | false | animate timeline revers | +| delay | number | 0 | animate timeline delay | +| repeat | number | 0 | `animation` all data repeat, To repeat indefinitely, use -1 | +| repeatDelay | number | 0 | animate timeline repeat delay | +| yoyo | boolean | false | `animation` all data alternating backward and forward on each repeat. | +| onChange | func | null | when the animation change called, callback({ moment, targets, index, mode, ratio, vars, index, repeat }) | +| onChangeTimeline | func | null | when the animation change called, callback({ mode, targets, vars, moment, totalTime, repeat }) | +| moment | number | null | set the current frame | +| regionStartTime | number | 0 | Set the start time of the animation region | +| regionEndTime | number | null | Set the end time of the animation region | +| attr | boolean | false | attribute animation is `true`, when morph SVG must be `true`. | +| resetStyle | boolean | false | update animation data, reset init style | +| component | string / React.Element | `div` | component tag | +| componentProps | object | null | component is React.Element, component tag props, not add `style` | ### animation = { } > Basic animation param. please view [animation terms](https://motion.ant.design/language/animate-term) -| name | type | default | description | -|------------|----------------|---------|----------------| -| [key: string] | `string` `number` `array` | null | All variables based on number, such as left, x, color, shadow | -| type | string | `to` | play type: `to` `from` `set`| -| duration | number | 450 | animate duration | -| delay | number | 0 | animate delay | -| repeat | number | 0 | animate repeat, To repeat indefinitely, use -1 | -| repeatDelay| number | 0 | repeat start delay | -| appearTo | number | null | Add to the specified time | -| yoyo | boolean | false | `true`: alternating backward and forward on each repeat. | -| ease | string | `easeInOutQuad` | animate ease [refer](http://easings.net/en) or svg path `M0,100 C30,60 0,20 50,50 C70,70 60,0 100,0` | -| bezier | object | null | bezier curve animate | -| onStart | func | null | A function that should be called when the tween begins, callback(e), e: { index, target } | -| onUpdate | func | null | A function that should be called every time the animate updates, callback(e), e: { index, targets, ratio } | -| onComplete | func | null | A function that should be called when the animate has completed, callback(e), e: { index, targets } | -| onRepeat | func | null | A function that should be called each time the animate repeats, callback(e), e: { index, targets } | +| name | type | default | description | +| ------------- | ------------------------- | --------------- | ---------------------------------------------------------------------------------------------------------- | +| [key: string] | `string` `number` `array` | null | All variables based on number, such as left, x, color, shadow | +| type | string | `to` | play type: `to` `from` `set` | +| duration | number | 450 | animate duration | +| delay | number | 0 | animate delay | +| repeat | number | 0 | animate repeat, To repeat indefinitely, use -1 | +| repeatDelay | number | 0 | repeat start delay | +| appearTo | number | null | Add to the specified time | +| yoyo | boolean | false | `true`: alternating backward and forward on each repeat. | +| ease | string | `easeInOutQuad` | animate ease [refer](http://easings.net/en) or svg path `M0,100 C30,60 0,20 50,50 C70,70 60,0 100,0` | +| bezier | object | null | bezier curve animate | +| onStart | func | null | A function that should be called when the tween begins, callback(e), e: { index, target } | +| onUpdate | func | null | A function that should be called every time the animate updates, callback(e), e: { index, targets, ratio } | +| onComplete | func | null | A function that should be called when the animate has completed, callback(e), e: { index, targets } | +| onRepeat | func | null | A function that should be called each time the animate repeats, callback(e), e: { index, targets } | > Cannot be used at the same time `reverse` and `repeat: -1`. ### animation =[ ] is timeline + ```js | pure ``` + ## Plugins + ### SvgDrawPlugin ```js | pure -import { Plugins } from 'rc-tween-one'; -import SvgDrawPlugin from 'rc-tween-one/es/plugin/SvgDrawPlugin'; +import { Plugins } from '@rc-component/tween-one'; +import SvgDrawPlugin from '@rc-component/tween-one/es/plugin/SvgDrawPlugin'; Plugins.push(SvgDrawPlugin); - +; ``` SVGDraw = string or number; @@ -159,75 +168,94 @@ SVGDraw = string or number; ### SvgMorphPlugin ```js | pure -import { Plugins } from 'rc-tween-one'; -import SvgMorphPlugin from 'rc-tween-one/es/plugin/SvgMorphPlugin'; +import { Plugins } from '@rc-component/tween-one'; +import SvgMorphPlugin from '@rc-component/tween-one/es/plugin/SvgMorphPlugin'; Plugins.push(SvgMorphPlugin); - +; ``` -#### SvgMorphPlugin API -| name | type | default | description | -|------------------|--------|---------|----------------| -| path | string | null | svg path, ref: `M0,0L100,0`;| -| attr | string | null | Svg tag attributes, example: `polygon` is ` points`, `path` is `d`. | -| maxSegmentLength | number | 0.5 | The lower the value, the smoother the generated animation will be, but at the expense of performance;| +#### SvgMorphPlugin API +| name | type | default | description | +| ---------------- | ------ | ------- | ----------------------------------------------------------------------------------------------------- | +| path | string | null | svg path, ref: `M0,0L100,0`; | +| attr | string | null | Svg tag attributes, example: `polygon` is ` points`, `path` is `d`. | +| maxSegmentLength | number | 0.5 | The lower the value, the smoother the generated animation will be, but at the expense of performance; | -### PathPlugin +### PathMotionPlugin ```js | pure -import { Plugins } from 'rc-tween-one'; -import PathMotionPlugin from 'rc-tween-one/es/plugin/PathMotionPlugin'; +import { Plugins } from '@rc-component/tween-one'; +import PathMotionPlugin from '@rc-component/tween-one/es/plugin/PathMotionPlugin'; Plugins.push(PathMotionPlugin); - +; ``` + #### PathMotion API -| name | type | default | description | -| ------ | ------------------- | --------------- | ----------------------------- | -| path | string / {x,y}[] | null | svg path, ref: `M0,0L100,0`; | -| pathVars | IPathVars | null | Only valid if path is array `[{x, y}, {x, y}]` | -| center | `number \ string[]` | `['50%','50%']` | center point, ref: `[50px, 50px]`; | -| x | boolean | true | x follow the path. | -| y | boolean | true | y follow the path. | -| rotate | boolean | true | rotate follow the path. | +| name | type | default | description | +| -------- | ------------------- | --------------- | ---------------------------------------------- | +| path | string / {x,y}[] | null | svg path, ref: `M0,0L100,0`; | +| pathVars | IPathVars | null | Only valid if path is array `[{x, y}, {x, y}]` | +| center | `number \ string[]` | `['50%','50%']` | center point, ref: `[50px, 50px]`; | +| x | boolean | true | x follow the path. | +| y | boolean | true | y follow the path. | +| rotate | boolean | true | rotate follow the path. | ##### IPathVars -| name | type | default | description | -| ------ | ------------------- | --------------- | ----------------------------- | -| type | `thru \ soft \ cubic` | `thru` | path type. `thru` same as the path; `soft` with the curve of attraction facing them, but not through the point; `cubic` allows you to define standard Cubic Bezier, example: `[start, control, control, end]`. | -| curviness | 0-2 | 1 | This determines how "curvy" the resulting path is. `0` is lines, `1` is curved path, `2` would make it much more curvy. It can be `1.5`. | -| relative | boolean | false | Increase relative to current value. example: if the target's x starts at 100 and the path is `[{x:5}, {x:10}, {x:-2}]` , it would first move to `105`, then `115`, and finally end at `113`. | + +| name | type | default | description | +| --------- | --------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| type | `thru \ soft \ cubic` | `thru` | path type. `thru` same as the path; `soft` with the curve of attraction facing them, but not through the point; `cubic` allows you to define standard Cubic Bezier, example: `[start, control, control, end]`. | +| curviness | 0-2 | 1 | This determines how "curvy" the resulting path is. `0` is lines, `1` is curved path, `2` would make it much more curvy. It can be `1.5`. | +| relative | boolean | false | Increase relative to current value. example: if the target's x starts at 100 and the path is `[{x:5}, {x:10}, {x:-2}]` , it would first move to `105`, then `115`, and finally end at `113`. | ### ChildrenPlugin #### Children = { value:, floatLength, formatMoney }; -| name | type | default | description | -|---|---|---|---| -| value | number | null | children number to value. | -| floatLength | number | null | float precision length | -| formatMoney | `true` \ { thousand, decimal } | null | format number to money. | +| name | type | default | description | +| ----------- | ------------------------------ | ------- | ------------------------- | +| value | number | null | children number to value. | +| floatLength | number | null | float precision length | +| formatMoney | `true` \ { thousand, decimal } | null | format number to money. | #### formatMoney = { thousand, decimal } -| name | type | default | description | -|---|---|---|---| -| thousand | string | `,` | no explanation. | -| decimal | string | `.` | no explanation. | +| name | type | default | description | +| -------- | ------ | ------- | --------------- | +| thousand | string | `,` | no explanation. | +| decimal | string | `.` | no explanation. | ## TweenOneGroup -| name | type | default | description | -|------------|----------------|---------|----------------| -| appear | boolean | true | whether support appear anim | -| enter | object / array / func | `{ x: 30, opacity: 0, type: 'from' }` | enter anim twee-one data. when array is tween-one timeline, func refer to queue-anim | -| leave | object / array / func | `{ x: 30, opacity: 0 }` | leave anim twee-one data. when array is tween-one timeline, func refer to queue-anim | -| onEnd | func | - | one animation end callback | -| animatingClassName | array | `['tween-one-entering', 'tween-one-leaving']` | className to every element of animating | -| resetStyle | boolean | true | TweenOne resetStyle, reset the initial style when changing animation. | -| exclusive | boolean | false | Whether to allow a new animate to execute immediately when switching. `enter => leave`: execute immediately leave | -| component | React.Element/String | div | component tag | -| componentProps | object | - | component tag props | +| name | type | default | description | +| ------------------ | --------------------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | +| appear | boolean | true | whether support appear anim | +| enter | object / array / func | `{ x: 30, opacity: 0, type: 'from' }` | enter anim twee-one data. when array is tween-one timeline, func refer to queue-anim | +| leave | object / array / func | `{ x: 30, opacity: 0 }` | leave anim twee-one data. when array is tween-one timeline, func refer to queue-anim | +| onEnd | func | - | one animation end callback | +| animatingClassName | array | `['tween-one-entering', 'tween-one-leaving']` | className to every element of animating | +| resetStyle | boolean | true | TweenOne resetStyle, reset the initial style when changing animation. | +| exclusive | boolean | false | Whether to allow a new animate to execute immediately when switching. `enter => leave`: execute immediately leave | +| component | React.Element/String | div | component tag | +| componentProps | object | - | component tag props | + +## License + +@rc-component/tween-one is released under the [MIT](./LICENSE) license. + +[npm-image]: https://img.shields.io/npm/v/@rc-component/tween-one.svg?style=flat-square +[npm-url]: https://www.npmjs.com/package/@rc-component/tween-one +[github-actions-image]: https://github.com/react-component/tween-one/actions/workflows/main.yml/badge.svg +[github-actions-url]: https://github.com/react-component/tween-one/actions/workflows/main.yml +[codecov-image]: https://img.shields.io/codecov/c/github/react-component/tween-one/master.svg?style=flat-square +[codecov-url]: https://codecov.io/gh/react-component/tween-one/branch/master +[download-image]: https://img.shields.io/npm/dm/@rc-component/tween-one.svg?style=flat-square +[download-url]: https://www.npmjs.com/package/@rc-component/tween-one +[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/tween-one +[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/tween-one +[dumi-url]: https://github.com/umijs/dumi +[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 00000000..83abc0ca --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,261 @@ +
+

@rc-component/tween-one

+

Ant Design Ant Design 生态的一部分。

+

🎬 React 补间动画基础组件。

+
+ +

English | 简体中文

+ + +
+ +[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![bundle size][bundlephobia-image]][bundlephobia-url] [![dumi][dumi-image]][dumi-url] + +
+ +## 特性 + +- 面向 React 元素和 SVG 的声明式补间动画组件。 +- 支持时间线、重复、yoyo、路径动画、SVG 绘制/变形、数字动画和分组过渡。 +- 被 Ant Design 的动画示例和旧动画演示使用。 + +## 安装 + +```bash +npm install @rc-component/tween-one +``` + +`rc-tween-one` 是旧包名。新版本应使用带 scope 的 `@rc-component/tween-one` 包。 + +## 使用 + +```tsx +import TweenOne from '@rc-component/tween-one'; + +export default () => ( + + demo + +); +``` + +## 插件 API + +```tsx +import TweenOne, { Plugins } from '@rc-component/tween-one'; +import SvgDrawPlugin from '@rc-component/tween-one/es/plugin/SvgDrawPlugin'; + +Plugins.push(SvgDrawPlugin); + +export default () => ( + + + +); +``` + +## 示例 + +- 本地文档:运行 `npm start`,并打开终端输出的 dumi 地址。 +- Pull Request 预览由 Vercel 和 Surge 发布。 +- 动画 API 文档:https://motion.ant.design/api/tween-one + +## 浏览器支持 + +| Edge | Chrome | Firefox | Opera | Safari | +| ------ | ---------- | ----------- | --------- | --------- | +| IE 10+ | Chrome 31+ | Firefox 31+ | Opera 30+ | Safari 7+ | + +## 本地开发 + +```bash +npm install --legacy-peer-deps +npm start +``` + +常用检查: + +```bash +npm run lint +npm run tsc +npm test +npm run build +npm run compile +``` + +## 发布 + +```bash +npm run prepublishOnly +``` + +包构建完成后,发布流程由 `@rc-component/np` 通过 `rc-np` 命令处理。 +## API + +中文文档 + +### Props + +| 名称 | 类型 | 默认值 | 说明 | +| ---------------- | ---------------------- | ------- | -------------------------------------------------------------------------------------------------------- | +| animation | object / array | null | 动画配置参数 | +| paused | boolean | false | 暂停动画时间线 | +| reverse | boolean | false | 反向播放动画时间线 | +| delay | number | 0 | 动画时间线延迟 | +| repeat | number | 0 | `animation` 中所有数据的重复次数;无限重复请使用 -1 | +| repeatDelay | number | 0 | 动画时间线重复延迟 | +| yoyo | boolean | false | 每次重复时让 `animation` 中所有数据正反交替播放。 | +| onChange | func | null | 动画变化时调用,`callback({ moment, targets, index, mode, ratio, vars, index, repeat })` | +| onChangeTimeline | func | null | 动画时间线变化时调用,`callback({ mode, targets, vars, moment, totalTime, repeat })` | +| moment | number | null | 设置当前帧 | +| regionStartTime | number | 0 | 设置动画区间的开始时间 | +| regionEndTime | number | null | 设置动画区间的结束时间 | +| attr | boolean | false | 属性动画为 `true`;SVG morph 时必须为 `true`。 | +| resetStyle | boolean | false | 更新动画数据时重置初始样式 | +| component | string / React.Element | `div` | 组件标签 | +| componentProps | object | null | 当 `component` 为 `React.Element` 时传入组件属性,不添加 `style` | + +### animation = { } + +> 基础动画参数。请查看[动画术语](https://motion.ant.design/language/animate-term)。 + +| 名称 | 类型 | 默认值 | 说明 | +| ------------- | ------------------------- | --------------- | ---------------------------------------------------------------------------------------------------------- | +| [key: string] | `string` `number` `array` | null | 所有基于数值的变量,例如 left、x、color、shadow | +| type | string | `to` | 播放类型:`to`、`from`、`set` | +| duration | number | 450 | 动画时长 | +| delay | number | 0 | 动画延迟 | +| repeat | number | 0 | 动画重复次数;无限重复请使用 -1 | +| repeatDelay | number | 0 | 重复开始延迟 | +| appearTo | number | null | 添加到指定时间 | +| yoyo | boolean | false | `true`:每次重复时正反交替播放。 | +| ease | string | `easeInOutQuad` | 动画缓动,参考[这里](http://easings.net/en),也可传入 SVG 路径 `M0,100 C30,60 0,20 50,50 C70,70 60,0 100,0` | +| bezier | object | null | 贝塞尔曲线动画 | +| onStart | func | null | 补间开始时调用的函数,`callback(e)`,`e: { index, target }` | +| onUpdate | func | null | 动画每次更新时调用的函数,`callback(e)`,`e: { index, targets, ratio }` | +| onComplete | func | null | 动画完成时调用的函数,`callback(e)`,`e: { index, targets }` | +| onRepeat | func | null | 动画每次重复时调用的函数,`callback(e)`,`e: { index, targets }` | + +> `reverse` 和 `repeat: -1` 不能同时使用。 + +### animation = [] 为时间线 + +```js | pure + +``` + +## 插件 + +### SvgDrawPlugin + +```js | pure +import { Plugins } from '@rc-component/tween-one'; +import SvgDrawPlugin from '@rc-component/tween-one/es/plugin/SvgDrawPlugin'; +Plugins.push(SvgDrawPlugin); + +; +``` + +SVGDraw = string 或 number; + +{ SVGDraw: 30 } 或 { SVGDraw: 'start end' },start 和 end 的值可以为 `%`。 + +### SvgMorphPlugin + +```js | pure +import { Plugins } from '@rc-component/tween-one'; +import SvgMorphPlugin from '@rc-component/tween-one/es/plugin/SvgMorphPlugin'; +Plugins.push(SvgMorphPlugin); + +; +``` + +#### SvgMorphPlugin API + +| name | type | 默认 | description | +| ---------------- | ------ | ------- | ----------------------------------------------------------------------------------------------------- | +| path | string | null | SVG 路径,参考:`M0,0L100,0`; | +| attr | string | null | SVG 标签属性,例如 `polygon` 为 `points`,`path` 为 `d`。 | +| maxSegmentLength | number | 0.5 | 值越小,生成的动画越平滑,但会牺牲性能。 | + +### PathMotionPlugin + +```js | pure +import { Plugins } from '@rc-component/tween-one'; +import PathMotionPlugin from '@rc-component/tween-one/es/plugin/PathMotionPlugin'; +Plugins.push(PathMotionPlugin); + +; +``` + +#### PathMotion API + +| name | type | 默认 | description | +| -------- | ------------------- | --------------- | ---------------------------------------------- | +| path | string / {x,y}[] | null | SVG 路径,参考:`M0,0L100,0`; | +| pathVars | IPathVars | null | 仅在 path 为数组时有效 `[{x, y}, {x, y}]` | +| center | `number \ string[]` | `['50%','50%']` | 中心点,参考:`[50px, 50px]`; | +| x | boolean | true | x 跟随路径。 | +| y | boolean | true | y 跟随路径。 | +| rotate | boolean | true | rotate 跟随路径。 | + +##### IPathVars + +| name | type | 默认 | description | +| --------- | --------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| type | `thru \ soft \ cubic` | `thru` | 路径类型。`thru` 与路径一致;`soft` 使用趋近点但不穿过点的曲线;`cubic` 可定义标准三次贝塞尔,例如 `[start, control, control, end]`。 | +| curviness | 0-2 | 1 | 决定生成路径的弯曲程度。`0` 为直线,`1` 为曲线路径,`2` 更弯曲,也可以是 `1.5`。 | +| relative | boolean | false | 基于当前值相对增加。例如目标 x 从 100 开始,路径为 `[{x:5}, {x:10}, {x:-2}]`,则会先移动到 `105`,再到 `115`,最终停在 `113`。 | + +### ChildrenPlugin + +#### Children = { value, floatLength, formatMoney } + +| name | type | 默认 | description | +| ----------- | ------------------------------ | ------- | ------------------------- | +| value | number | null | 将子节点数字转换为值。 | +| floatLength | number | null | 小数精度长度 | +| formatMoney | `true` \ { thousand, decimal } | null | 将数字格式化为金额。 | + +#### formatMoney = { thousand, decimal } + +| name | type | 默认 | description | +| -------- | ------ | ------- | --------------- | +| thousand | string | `,` | 无说明。 | +| decimal | string | `.` | 无说明。 | + +## TweenOneGroup + +| 名称 | 类型 | 默认值 | 说明 | +| ------------------ | --------------------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | +| appear | boolean | true | 是否支持 appear 动画 | +| enter | object / array / func | `{ x: 30, opacity: 0, type: 'from' }` | 进入动画数据。数组表示 tween-one 时间线,函数用法参考 queue-anim。 | +| leave | object / array / func | `{ x: 30, opacity: 0 }` | 离开动画数据。数组表示 tween-one 时间线,函数用法参考 queue-anim。 | +| onEnd | func | - | 单个动画结束回调 | +| animatingClassName | array | `['tween-one-entering', 'tween-one-leaving']` | 添加到每个动画中元素的 className | +| resetStyle | boolean | true | TweenOne resetStyle,动画变化时重置初始样式。 | +| exclusive | boolean | false | 切换时是否允许新动画立即执行。`enter => leave` 表示立即执行 leave。 | +| component | React.Element/String | div | 组件标签 | +| componentProps | object | - | 组件标签 props | + +## 许可证 + +@rc-component/tween-one 基于 [MIT](./LICENSE) 许可证发布。 + +[npm-image]: https://img.shields.io/npm/v/@rc-component/tween-one.svg?style=flat-square +[npm-url]: https://www.npmjs.com/package/@rc-component/tween-one +[github-actions-image]: https://github.com/react-component/tween-one/actions/workflows/main.yml/badge.svg +[github-actions-url]: https://github.com/react-component/tween-one/actions/workflows/main.yml +[codecov-image]: https://img.shields.io/codecov/c/github/react-component/tween-one/master.svg?style=flat-square +[codecov-url]: https://codecov.io/gh/react-component/tween-one/branch/master +[download-image]: https://img.shields.io/npm/dm/@rc-component/tween-one.svg?style=flat-square +[download-url]: https://www.npmjs.com/package/@rc-component/tween-one +[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/tween-one +[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/tween-one +[dumi-url]: https://github.com/umijs/dumi +[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square diff --git a/docs/demo/group.md b/docs/demo/group.md index 1ef5b42a..db2acae8 100644 --- a/docs/demo/group.md +++ b/docs/demo/group.md @@ -6,7 +6,7 @@ order: 8 ### appear = false ```jsx -import TweenOneGroup from 'rc-tween-one/es/TweenOneGroup'; +import TweenOneGroup from '@rc-component/tween-one/es/TweenOneGroup'; import React from 'react'; import { Button } from 'antd'; import 'antd/dist/antd.css'; @@ -48,7 +48,7 @@ export default () => { ### exclusive = true ```jsx -import TweenOneGroup from 'rc-tween-one/es/TweenOneGroup'; +import TweenOneGroup from '@rc-component/tween-one/es/TweenOneGroup'; import React from 'react'; import { Button } from 'antd'; import 'antd/dist/antd.css'; @@ -86,7 +86,7 @@ export default () => { ### children change ```jsx -import TweenOneGroup from 'rc-tween-one/es/TweenOneGroup'; +import TweenOneGroup from '@rc-component/tween-one/es/TweenOneGroup'; import React from 'react'; import { Button } from 'antd'; import 'antd/dist/antd.css'; diff --git a/docs/demo/plugin-gradient.md b/docs/demo/plugin-gradient.md index 1adea0c8..9bd9bd0f 100644 --- a/docs/demo/plugin-gradient.md +++ b/docs/demo/plugin-gradient.md @@ -7,7 +7,7 @@ order: 6 ```jsx import React from 'react'; -import TweenOne from 'rc-tween-one'; +import TweenOne from '@rc-component/tween-one'; export default () => { return ( diff --git a/docs/examples/animParam.tsx b/docs/examples/animParam.tsx index f0c46d57..c6ceb6fd 100644 --- a/docs/examples/animParam.tsx +++ b/docs/examples/animParam.tsx @@ -1,4 +1,4 @@ -import Tween from 'rc-tween-one'; +import Tween from '@rc-component/tween-one'; import React from 'react'; import { Form, InputNumber, Input, Button, Checkbox, Select, AutoComplete } from 'antd'; import 'antd/dist/antd.css'; diff --git a/docs/examples/attr.tsx b/docs/examples/attr.tsx index a3a0d642..0a1d2ba1 100644 --- a/docs/examples/attr.tsx +++ b/docs/examples/attr.tsx @@ -1,4 +1,4 @@ -import Tween from 'rc-tween-one'; +import Tween from '@rc-component/tween-one'; import React from 'react'; export default () => { diff --git a/docs/examples/blurFilter.tsx b/docs/examples/blurFilter.tsx index cbd6bb33..95c46d2c 100644 --- a/docs/examples/blurFilter.tsx +++ b/docs/examples/blurFilter.tsx @@ -1,18 +1,14 @@ -import Tween from 'rc-tween-one'; +import Tween from '@rc-component/tween-one'; import React from 'react'; export default function Demo() { return (

- filter 里的滤镜,'grayScale', 'sepia', - 'hueRotate', 'invert', 'brightness', - 'contrast', 'blur' + filter 里的滤镜,'grayScale', 'sepia', 'hueRotate', + 'invert', 'brightness', 'contrast', 'blur'

- + { @@ -9,7 +9,10 @@ export default () => { }; React.useEffect(() => { window.addEventListener('mousemove', mouseMove); - }, []) + return () => { + window.removeEventListener('mousemove', mouseMove); + }; + }, []); return ( 执行动效 diff --git a/docs/examples/group.tsx b/docs/examples/group.tsx index 98ce73fd..d0e2ddcd 100644 --- a/docs/examples/group.tsx +++ b/docs/examples/group.tsx @@ -1,4 +1,4 @@ -import TweenOneGroup from 'rc-tween-one/es/TweenOneGroup'; +import TweenOneGroup from '@rc-component/tween-one/es/TweenOneGroup'; import React from 'react'; import { Button } from 'antd'; import 'antd/dist/antd.css'; diff --git a/docs/examples/numberDance.tsx b/docs/examples/numberDance.tsx index bba86631..2cea6227 100644 --- a/docs/examples/numberDance.tsx +++ b/docs/examples/numberDance.tsx @@ -1,7 +1,6 @@ -import Tween from 'rc-tween-one'; +import Tween from '@rc-component/tween-one'; import React from 'react'; -import ChildrenPlugin from 'rc-tween-one/es/plugin/ChildrenPlugin'; - +import ChildrenPlugin from '@rc-component/tween-one/es/plugin/ChildrenPlugin'; Tween.plugins.push(ChildrenPlugin); export default function Demo() { diff --git a/docs/examples/pathMotion.tsx b/docs/examples/pathMotion.tsx index 644046bd..f81b2a5b 100644 --- a/docs/examples/pathMotion.tsx +++ b/docs/examples/pathMotion.tsx @@ -1,6 +1,6 @@ -import Tween from 'rc-tween-one'; +import Tween from '@rc-component/tween-one'; import React from 'react'; -import PathPlugin from 'rc-tween-one/es/plugin/PathMotionPlugin'; +import PathPlugin from '@rc-component/tween-one/es/plugin/PathMotionPlugin'; Tween.plugins.push(PathPlugin); @@ -107,7 +107,9 @@ export default function Demo() { height: '30px', background: '#1890ff', }} - >c + > + c +
); diff --git a/docs/examples/resetStyle.tsx b/docs/examples/resetStyle.tsx index 28a4b1a4..a9a4b890 100644 --- a/docs/examples/resetStyle.tsx +++ b/docs/examples/resetStyle.tsx @@ -1,4 +1,4 @@ -import Tween from 'rc-tween-one'; +import Tween from '@rc-component/tween-one'; import React, { useEffect } from 'react'; import 'antd/dist/antd.css'; diff --git a/docs/examples/simple.tsx b/docs/examples/simple.tsx index 5902e662..33b4e602 100644 --- a/docs/examples/simple.tsx +++ b/docs/examples/simple.tsx @@ -1,4 +1,4 @@ -import Tween from 'rc-tween-one'; +import Tween from '@rc-component/tween-one'; import React from 'react'; export default () => { @@ -6,11 +6,7 @@ export default () => { console.log(e); // eslint-disable-line no-console }; return ( - +
执行动效
); diff --git a/docs/examples/svg.tsx b/docs/examples/svg.tsx index 9c77332b..f2661fb9 100644 --- a/docs/examples/svg.tsx +++ b/docs/examples/svg.tsx @@ -1,6 +1,6 @@ -import Tween, { Plugins } from 'rc-tween-one'; +import Tween, { Plugins } from '@rc-component/tween-one'; import React from 'react'; -import SvgMorphPlugin from 'rc-tween-one/es/plugin/SvgMorphPlugin'; +import SvgMorphPlugin from '@rc-component/tween-one/es/plugin/SvgMorphPlugin'; // Tween.plugins.push(SvgMorphPlugin); Plugins.push(SvgMorphPlugin); @@ -26,8 +26,7 @@ export default function Demo() { animation={{ SVGMorph: { maxSegmentLength: 0.15, - path: - 'M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z', + path: 'M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z', }, duration: 1000, }} diff --git a/docs/examples/svgDraw.tsx b/docs/examples/svgDraw.tsx index f0cc5afa..e9cdae2e 100644 --- a/docs/examples/svgDraw.tsx +++ b/docs/examples/svgDraw.tsx @@ -1,6 +1,6 @@ -import Tween, { Plugins } from 'rc-tween-one'; +import Tween, { Plugins } from '@rc-component/tween-one'; import React from 'react'; -import SvgDrawPlugin from 'rc-tween-one/es/plugin/SvgDrawPlugin'; +import SvgDrawPlugin from '@rc-component/tween-one/es/plugin/SvgDrawPlugin'; Plugins.push(SvgDrawPlugin); diff --git a/docs/examples/type.tsx b/docs/examples/type.tsx index 5d838c6d..f5fa20de 100644 --- a/docs/examples/type.tsx +++ b/docs/examples/type.tsx @@ -1,4 +1,4 @@ -import Tween from 'rc-tween-one'; +import Tween from '@rc-component/tween-one'; import React from 'react'; import { Button, Space } from 'antd'; import 'antd/dist/antd.css'; diff --git a/docs/examples/useInTable.tsx b/docs/examples/useInTable.tsx index 30a9b6c6..0c8a9dc0 100644 --- a/docs/examples/useInTable.tsx +++ b/docs/examples/useInTable.tsx @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import Table from 'antd/lib/table'; import Button from 'antd/lib/button'; -import TweenOneGroup from 'rc-tween-one/es/TweenOneGroup'; +import TweenOneGroup from '@rc-component/tween-one/es/TweenOneGroup'; import 'antd/dist/antd.css'; import './useInTable.less'; diff --git a/docs/index.md b/docs/index.md index 2f269c3e..c78e1d00 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,6 +1,6 @@ --- -title: rc-tween-one +title: "@rc-component/tween-one" order: 0 --- - \ No newline at end of file + diff --git a/now.json b/now.json deleted file mode 100644 index 196bc225..00000000 --- a/now.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": 2, - "name": "rc-tween-one", - "builds": [ - { - "src": "package.json", - "use": "@now/static-build", - "config": { "distDir": ".doc" } - } - ] -} diff --git a/package.json b/package.json index 06dbf392..2089892f 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { - "name": "rc-tween-one", + "name": "@rc-component/tween-one", "version": "3.0.6", - "description": "tween-one anim component for react", + "description": "🎬 Tween animation component for React", "typings": "es/index.d.ts", + "types": "./es/index.d.ts", "engines": { "node": ">=8.x" }, @@ -39,26 +40,30 @@ "assets/*.css", "assets/*.less" ], - "licenses": "MIT", + "license": "MIT", "main": "./lib/index", "module": "./es/index", "sideEffects": false, "scripts": { "start": "dumi dev", - "docs:build": "dumi build", + "build": "npm run docs:build", + "docs:build": "NODE_OPTIONS=--openssl-legacy-provider dumi build", "docs:deploy": "gh-pages -d docs-dist", "compile": "father-build", "deploy": "npm run docs:build && npm run docs:deploy", "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"", "test": "umi-test test", - "test:coverage": "umi-test --coverage", - "prepublishOnly": "npm run compile && np --tag=beta --no-cleanup --yolo --no-publish --any-branch", - "lint": "eslint src/ --fix --ext .tsx,.ts", - "lint:tsc": "tsc -p tsconfig.json --noEmit", - "now-build": "npm run docs:build" + "coverage": "umi-test --coverage --collectCoverageFrom=src/**/*.{ts,tsx} --collectCoverageFrom=!src/.umi-production/**", + "test:coverage": "npm run coverage", + "prepublishOnly": "npm run compile && rc-np", + "lint": "eslint src/ --ext .tsx,.ts", + "tsc": "tsc -p tsconfig.json --noEmit", + "lint:tsc": "tsc -p tsconfig.json --noEmit" }, "devDependencies": { "@ant-design/icons": "^4.3.0", + "@babel/core": "^7.29.7", + "@rc-component/np": "^1.0.4", "@types/enzyme": "^3.10.5", "@types/jest": "^25.2.1", "@types/lodash": "^4.14.135", @@ -73,9 +78,8 @@ "eslint": "^7.14.0", "father": "^2.22.6", "father-build": "^1.18.6", - "gh-pages": "^3.1.0", + "gh-pages": "^6.3.0", "husky": "^4.3.0", - "np": "^6.0.3", "prettier": "^2.1.2", "react": "^16.9.0", "react-dom": "^16.9.0", @@ -91,6 +95,10 @@ "style-utils": "^0.3.4", "tween-one": "^1.0.50" }, + "overrides": { + "cheerio": "1.0.0-rc.12", + "@babel/core": "^7.29.7" + }, "husky": { "hooks": { "pre-commit": [ diff --git a/src/TweenOne.tsx b/src/TweenOne.tsx index d9aeff51..5cb5b68d 100644 --- a/src/TweenOne.tsx +++ b/src/TweenOne.tsx @@ -84,7 +84,7 @@ const TweenOne: TweenOneRef = React.forwardRef( animRef.current.kill(); } if (resetStyle && animRef.current) { - const s = !component ? { ...style, ...children.props.style } : style + const s = !component ? { ...style, ...children?.props?.style } : style; const styleStr = Object.keys(s) .map((key: string) => `${toStyleUpperCase(key)}:${stylesToCss(key, s[key])}`) .join(';'); @@ -94,20 +94,20 @@ const TweenOne: TweenOneRef = React.forwardRef( delete item._tweenOneVars; // eslint-disable-line no-underscore-dangle }); } - animRef.current = - animation && - TweenOneJS(doms, { - animation, - attr, - yoyo, - moment, - repeat, - reverse, - paused, - repeatDelay, - onChange, - onChangeTimeline, - }); + animRef.current = animation + ? (TweenOneJS(doms, { + animation, + attr, + yoyo, + moment, + repeat, + reverse, + paused, + repeatDelay, + onChange, + onChangeTimeline, + }) as Tween) + : undefined; prevAnim.current = animation; } }, [animation]); diff --git a/tsconfig.json b/tsconfig.json index 3d0aeab3..aa4fc940 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,22 +9,20 @@ "declaration": true, "esModuleInterop": true, "sourceMap": true, + "skipLibCheck": true, "baseUrl": "./", "strict": true, "paths": { "@/*": ["src/*"], "@@/*": ["src/.umi/*"], - "rc-tween-one": ["src/index.tsx"] + "@rc-component/tween-one": ["src/index.tsx"], + "@rc-component/tween-one/es/*": ["src/*"], + "@rc-component/tween-one/lib/*": ["src/*"], + "rc-tween-one": ["src/index.tsx"], + "rc-tween-one/es/*": ["src/*"], + "rc-tween-one/lib/*": ["src/*"] }, "allowSyntheticDefaultImports": true }, - "exclude": [ - "node_modules", - "lib", - "es", - "dist", - "typings", - "**/__test__", - "test" - ] + "exclude": ["node_modules", "lib", "es", "dist", "docs-dist", "typings", "**/__test__", "test"] } diff --git a/typings/global/index.d.ts b/typings/global/index.d.ts index b58f3e31..0461c582 100644 --- a/typings/global/index.d.ts +++ b/typings/global/index.d.ts @@ -6,7 +6,12 @@ declare module 'tween-functions'; declare module 'raf'; declare module 'flubber'; - +// declare module '@rc-component/tween-one'; +declare module '@rc-component/tween-one/es/plugin/ChildrenPlugin'; +declare module '@rc-component/tween-one/es/plugin/PathMotionPlugin'; +declare module '@rc-component/tween-one/es/plugin/SvgDrawPlugin'; +declare module '@rc-component/tween-one/es/plugin/SvgMorphPlugin'; +declare module '@rc-component/tween-one/es/TweenOneGroup'; // declare module 'rc-tween-one'; declare module 'rc-tween-one/es/plugin/ChildrenPlugin'; declare module 'rc-tween-one/es/plugin/PathMotionPlugin'; @@ -14,7 +19,6 @@ declare module 'rc-tween-one/es/plugin/SvgDrawPlugin'; declare module 'rc-tween-one/es/plugin/SvgMorphPlugin'; declare module 'rc-tween-one/es/TweenOneGroup'; - interface Element { _tweenOneVars: any; } diff --git a/vercel.json b/vercel.json new file mode 100644 index 00000000..34abd4b1 --- /dev/null +++ b/vercel.json @@ -0,0 +1,6 @@ +{ + "buildCommand": "npm run build", + "outputDirectory": "docs-dist", + "installCommand": "npm install --legacy-peer-deps --ignore-scripts --no-audit --loglevel=warn", + "framework": null +}