diff --git a/README.md b/README.md index 79bac3a..ca9fa40 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ JavaScript (TypeScript) tweening engine for easy animations, incorporating optim [![NPM Downloads][downloads-image]][downloads-url] [![Build and Tests][ci-image]][ci-url] +More languages: [English](./README.md), [简体中文](./README_zh-CN.md) + --- ```html diff --git a/README_zh-CN.md b/README_zh-CN.md index 1b322eb..5d1cd07 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -1,213 +1,187 @@ # tween.js -tween.js 是用于简单动画的 JavaScript 补间引擎,结合了优化的 Robert Penner 方程。 +用于简单动画的 JavaScript (TypeScript) 补间引擎,结合优化的 Robert Penner 方程式。 [![NPM Version][npm-image]][npm-url] -[![NPM Downloads][downloads-image]][downloads-url] -[![Travis tests][travis-image]][travis-url] -[![Flattr this][flattr-image]][flattr-url] [![CDNJS][cdnjs-image]][cdnjs-url] +[![NPM Downloads][downloads-image]][downloads-url] +[![Build and Tests][ci-image]][ci-url] -```javascript -var box = document.createElement('div') -box.style.setProperty('background-color', '#008800') -box.style.setProperty('width', '100px') -box.style.setProperty('height', '100px') -document.body.appendChild(box) +更多语言: [English](./README.md), [简体中文](./README_zh-CN.md) -// 设置循环动画 -function animate(time) { +--- + +```html + + +
+ + + + ``` -[在线代码测试](https://codepen.io/mikebolt/pen/zzzvZg) +[在 CodePen 上试试这个例子](https://codepen.io/trusktr/pen/KKGaBVz?editors=1000) ## 安装 -下载 [library](https://raw.githubusercontent.com/tweenjs/tween.js/master/src/Tween.js) 并将它引入至你的代码中: +## 从 CDN 安装 + +从上例中的内容分发网络 (CDN) 安装。 + +cdnjs: ```html - + ``` -您也可以在代码中引用 CDN 托管的版本,这要感谢 cdnjs 。例如: +或者 unpkg.com: ```html - + ``` -See [tween.js](https://cdnjs.com/libraries/tween.js/) for more versions. +请注意,unpkg.com 支持 URL 中的 semver 版本,其中 URL 中的 `^` 告诉 unpkg 为你提供最新版本 20.x.x。 -查看更多 [tween.js](https://cdnjs.com/libraries/tween.js/) 版本. +## 使用 script 标签构建并包含在你的项目中 -### 更多高级用户想要的... +目前需要 npm 来构建项目。 -#### 使用 `npm` +```bash +git clone https://github.com/tweenjs/tween.js +cd tween.js +npm install +npm run build +``` + +这将在 `dist` 目录中创建一些构建。 目前有两种不同的库版本: + +- UMD : `tween.umd.js` +- ES6 Module : `tween.es.js` + +你现在可以将 tween.umd.js 复制到你的项目中,然后将其包含在一个 script 标签,它将 TWEEN 添加到全局范围, + +```html + +``` + +或将 TWEEN 作为 JavaScript 模块导入, + +```html + +``` + +其中 `path/to` 替换为你放置文件的位置。 + +## 使用 `npm install` 和 `import` 从 `node_modules` 中添加 + +你可以将 tween.js 添加为 npm 依赖项: ```bash npm install @tweenjs/tween.js ``` -然后用标准的 node.js `require` 包含 Tween.js 模块: +### 使用构建工具 + +如果你使用 [Node.js](https://nodejs.org/)、[Parcel](https://parceljs.org/)、[Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/)、[Vite](https://vitejs.dev/) 或者其他的构建工具,那么你现在可以使用以下方式来导入 tween.js: ```javascript -var TWEEN = require('@tweenjs/tween.js') +import * as TWEEN from '@tweenjs/tween.js' ``` -您可以像所有其他示例一样使用 Tween.js,例如: +### 没有构建工具 -```javascript -var t = new TWEEN.Tween(/* etc */) -t.start() -``` - -你将需要使用诸如`browserify`之类的工具将使用此风格的代码转换为可以在浏览器中运行的代码(浏览器无法识别 `require`) - -#### Use `bower` - -```bash -bower install @tweenjs/tweenjs --save -``` - -或者安装特定的 tag.他们是 git tags,如果你已经在本地克隆仓库,你可以在命令行中运行`git tag`查看 tag 列表,或者你可以查看下 [tween.js tags page](https://github.com/tweenjs/tween.js/tags) 列表.例如,安装 `v16.3.0`: - -```bash -bower install @tweenjs/tweenjs#v16.3.0 -``` - -然后引入库源码: +如果你将 `node_modules` 作为网站的一部分提供服务,则可以使用 `importmap` script 标签从 `node_modules` 导入。 首先,假设 `node_modules` 位于你网站的根目录,你可以编写一个导入映射: ```html - + ``` -## Features +现在,在任何 module script 中,你都可以通过包名导入它: -- 只做一件事且仅只做一件事: 补间特性 -- 不关注 CSS 单位 (e.g. appending `px`) -- 不插入颜色 -- 缓和功能可以在 Tween 之外重用 -- 也可以使用自定义缓动功能 +```javascript +import * as TWEEN from '@tweenjs/tween.js' +``` -## Documentation +# 特性 -- [使用指南](./docs/user_guide_zh-CN.md) -- [贡献者指南](./docs/contributor_guide_zh-CN.md) -- [教程](http://learningthreejs.com/blog/2011/08/17/tweenjs-for-smooth-animation/) using tween.js with three.js -- 其他: [libtween](https://github.com/jsm174/libtween), [jsm174](https://github.com/jsm174) 写的一个 C 语言版本的 tween.js. -- 其他: [es6-tween](https://github.com/tweenjs/es6-tween), [dalisoft](https://github.com/dalisoft) 写的一个 ES6/Harmony 版本的 tween.js. -- [理解 tween.js](https://mikebolt.me/article/understanding-tweenjs.html) +- 做一件事并且只做一件事:补间属性 +- 不处理 CSS 单位(例如附加 `px`) +- 不插值颜色 +- 缓动函数可在 Tween 之外重复使用 +- 也可以使用自定义缓动函数 -## 示例 +# 文档
-
-
+
+
|
- Custom functions - (source) + hello world + (source) |
-
-
+
+
|
- Stop all chained tweens - (source) + Bars + (source) |
-
-
-
-
- |
-
- Yoyo - (source) - |
-
-
-
-
- |
-
- Relative values - (source) - |
-
-
+
+
|
- Repeat - (source) - |
-
-
-
-
- |
-
- Dynamic to - (source) - |
-
-
-
-
- |
-
- Array interpolation - (source) - |
-
-
-
-
- |
-
- Video and time - (source) - |
-
-
-
-
- |
-
- Simplest possible example - (source) + Black and red + (source) |
-
+
|
@@ -217,81 +191,192 @@ bower install @tweenjs/tweenjs#v16.3.0 |
-
-
+
+
|
- Black and red - (source) + Simplest possible example + (source) |
-
-
+
+
|
- Bars - (source) + Video and time + (source) |
-
-
+
+
|
- hello world - (source) + Array interpolation + (source) + |
+
+
+
+
+ |
+
+ Dynamic to, object + (source) + |
+
+
+
+
+ |
+
+ Dynamic to, interpolation array + (source) + |
+
+
+
+
+ |
+
+ Dynamic to, large interpolation array + (source) + |
+
+
+
+
+ |
+
+ Repeat + (source) + |
+
+
+
+
+ |
+
+ Relative values + (source) + |
+
+
+
+
+ |
+
+ Yoyo + (source) + |
+
+
+
+
+ |
+
+ Stop all chained tweens + (source) + |
+
+
+
+
+ |
+
+ Custom functions + (source) + |
+
+
+
+
+ |
+
+ Relative start time + (source) + |
+
+
+
+
+ |
+
+ Pause tween + (source) + |
+
+
+
+
+ |
+
+ Complex properties + (source) + |
+
+
+
+
+ |
+
+ Animate an array of values + (source) |
](https://lume.io)
+[](https://aframe.io)
+[](http://www.moma.org/interactives/exhibitions/2012/inventingabstraction/)
+[](http://www.chromeweblab.com/)
+[](http://5013.es/toys/macchina)
+[](http://egraether.com/mine3d/)
+[](http://ro.me)
+[](http://data-arts.appspot.com/globe)
+[](http://www.androidify.com/)
+[](http://thewildernessdowntown.com/)
+[](http://dejavis.org/linechart)
[npm-image]: https://img.shields.io/npm/v/@tweenjs/tween.js.svg
[npm-url]: https://npmjs.org/package/@tweenjs/tween.js
[downloads-image]: https://img.shields.io/npm/dm/@tweenjs/tween.js.svg
[downloads-url]: https://npmjs.org/package/@tweenjs/tween.js
-[travis-image]: https://travis-ci.org/tweenjs/tween.js.svg?branch=master
-[travis-url]: https://travis-ci.org/tweenjs/tween.js
-[flattr-image]: https://api.flattr.com/button/flattr-badge-large.png
-[flattr-url]: https://flattr.com/thing/45014/tween-js
+[ci-image]: https://github.com/tweenjs/tween.js/workflows/build%20and%20tests/badge.svg?branch=master
+[ci-url]: https://github.com/tweenjs/tween.js/actions
[cdnjs-image]: https://img.shields.io/cdnjs/v/tween.js.svg
[cdnjs-url]: https://cdnjs.com/libraries/tween.js
diff --git a/docs/contributor_guide.md b/docs/contributor_guide.md
index 23a6a2d..6eec404 100644
--- a/docs/contributor_guide.md
+++ b/docs/contributor_guide.md
@@ -1,5 +1,7 @@
# tween.js contributor guide
+More languages: [English](./contributor_guide.md), [简体中文](./contributor_guide_zh-CN.md)
+
This guide is for people who want to _contribute_ to the library or are curious to learn what's behind the scenes: how is it tested? what do we automate? how do we do releases? etc.
If you are looking for documentation on _how to use_ the library, the [user guide](./user_guide.md) is for you.
diff --git a/docs/contributor_guide_zh-CN.md b/docs/contributor_guide_zh-CN.md
index 7ab6104..e4b4a80 100644
--- a/docs/contributor_guide_zh-CN.md
+++ b/docs/contributor_guide_zh-CN.md
@@ -1,43 +1,49 @@
# tween.js 贡献者指南
-本指南适用于想要向库贡献的人,或者想了解背后的内容:如何进行测试?我们自动化什么?我们如何做发布?等等.
+更多语言: [English](./contributor_guide.md), [简体中文](./contributor_guide_zh-CN.md)
-如果您正在查找*如何使用*库的文档,[用户指南](./ user_guide_zh-CN.md)是适合你的。
+本指南适用于想要向库贡献的人,或者想了解背后的内容:如何进行测试?我们自动化什么?我们如何做发布?等等。
-**这个文档是一个正在进行的工作.更多内容将分阶段添加.如果你有问题,你想看到回答,请在 [as comments on this issue](https://github.com/tweenjs/tween.js/issues/323) 中提出.谢谢!**
+如果你正在查找*如何使用*库的文档,[用户指南](./user_guide_zh-CN.md) 是适合你的。
+
+**NOTE: 这个文档是一个正在进行的工作。更多内容将分阶段添加。如果你有问题,你想看到回答,请在 [as comments on this issue](https://github.com/tweenjs/tween.js/issues/323) 中提出,谢谢!**
目录:
-- [开发者要求](#developer-requirements)
-- [测试](#testing)
-- [持续集成](#continuous-integration)
-- [发布过程](#release-process)
+- [tween.js 贡献者指南](#tween.js-贡献者指南)
+- [开发者要求](#开发者要求)
+- [测试](#测试)
+ - [单元测试](#单元测试)
+ - [代码风格和 lint 测试](#代码风格和-lint-测试)
+ - [其他类型的测试](#其他类型的测试)
+- [持续集成](#持续集成)
+- [发布流程](#发布流程)
## 开发者要求
-虽然 tween.js*不*需要 nodejs 工作,我们用它来开发.所以我们需要 [安装 nodejs](https://nodejs.org/en/download/),然后才能在库中工作.
+虽然 tween.js *不*需要依赖 node.js 运行,但我们使用 node.js 来进行开发。所以我们需要先 [安装 node.js](https://nodejs.org/en/download/),然后才能在库中工作。
-Node.js 包含了我们使用的`npm`工具来运行脚本,比如打包,运行测试等等.请确保它在你的系统中正常工作,然后再尝试运行下面详述的任何步骤。
+Node.js 包括我们用来运行脚本的 npm 工具,例如打包、运行测试等的脚本。在你尝试运行下面详述的任何步骤之前,请确保它在你的系统中正常工作。
-一旦安装了 node.js,请克隆 tween.js 仓库:
+安装 node.js 后,克隆 tween.js 存储库:
```bash
git clone https://github.com/tweenjs/tween.js.git
```
-进入该文件夹
+进入该文件夹:
```bash
cd tween.js
```
-运行脚本安装依赖
+并运行脚本来安装开发依赖项:
```bash
npm install
```
-或者三行:
+或者分三行:
```bash
git clone https://github.com/tweenjs/tween.js.git
@@ -45,211 +51,71 @@ cd tween.js
npm install
```
-一旦`npm install`成功,试着运行测试:
+`npm install` 成功完成后,尝试运行测试:
```bash
npm test
```
-如果您遇到上述任何问题,请尝试使用你的搜索引擎搜索错误文本.这通常是最快的路线,因为许多人可能已经遇到同样的问题。
+如果你在运行上述任何步骤时遇到问题,请尝试使用你选择的搜索引擎搜索错误文本。这通常是最快的解决方法,因为很多人可能已经遇到过同样的问题。
## 测试
-`test`目录中有一套自动化测试.
+`test` 目录中有一套自动化测试。
-这些可以快速找到代码上的回归,在添加新功能或更改代码以修复错误时非常有用;我们不想引入新的问题!他们还能发现代码风格问题,这有助于我们保持库 cohesive.
+这些可以快速发现代码上的回归,在添加新功能或更改代码以修复 Bug 时很有用;我们不想引入新的 Bugs!自动化测试还会发现风格问题,这有助于我们保持库的凝聚力。
-运行测试用例,输入:
+要运行测试,请输入:
```bash
npm test
```
-在更改库中的代码后,你应该运行测试.如果你更改测试描述的行为,则测试将不会通过,你将得到指向失败测试的错误.这可能是因为...
+你应该在更改库中的代码后运行测试。如果你更改测试描述的行为,测试将不会通过,你将得到指向失败测试的错误。 这可能是因为...
-- 你忽略了一些东西,或者你的代码有错误,或者...
+- 你忽略了一些东西,或者你的代码有错误,或者...
- 库或测试本身是错误的
-经常发生的是第一次,但第二次发生了,有边缘情况
+以上两种情况,发生频率更高的是第一个,但第如果二个发生了,可能是边缘情况。
-**自动化测试通过之后,您应该执行的另一件事是运行`examples`文件夹中的示例**.这不常见,但是可能会发生这样的情况:您的更改引入了自动化测试未检查的外观差异,唯一注意到这一点的方法是运行示例,并在输出上产生差异.如果你不想捡出两个库的副本,你可以看看[在线例子](https://github.com/tweenjs/tween.js#examples).
+**自动化测试通过之后,你应该做的另一件事是运行 `examples` 文件夹中的示例**。有种情况很少见,但可能会发生:你的更改引入了自动测试未检查的外观差异,注意到这一点的唯一方法是运行示例并让人工发现输出中的差异。如果你不想签出库的两个副本,可以查看[在线例子](https://github.com/tweenjs/tween.js#examples)。
### 单元测试
-测试用例在`src/tests.ts`文件中.
+测试用例在 `src/tests.ts` 文件中。
-测试使用[nodeunit](https://www.npmjs.com/package/nodeunit)执行.
+测试使用 [nodeunit](https://www.npmjs.com/package/nodeunit) 执行。
-**TODO:** 如果在浏览器中打开`test/unit/nodeunit.html`,测试也应该能够正常工作,但是现在已经被破坏了.有一个[打开的问题](https://github.com/tweenjs/tween.js/issues/307)使他们再次工作。
+**TODO:** 如果在浏览器中打开 `test/unit/nodeunit.html`,测试也应该能够正常运行,但是现在已经被损坏。有一个 [打开的问题](https://github.com/tweenjs/tween.js/issues/307) 可以使他们再次工作。
-### 修正和样式测试
+### 代码风格和 lint 测试
-我们使用[JSCS](http://jscs.info/)和[JSHint](http://jshint.com/)来确保代码风格是统一的。
+我们使用 [JSCS](http://jscs.info/) 和 [JSHint](http://jshint.com/) 来保证代码风格的统一。
-#### JSCS
+要自动格式化代码并报告不可被格式化的代码片段的任何错误,请运行:
-这个工具可以帮助我们发现大部分"修饰"代码风格问题.例如,空格与制表符,括号之间的空格等.
-
-运行:
-
-```bash
-npm run test-style
+```base
+npm run test-lint
```
-JSCS 规则在`test/jscs.json`中.
-
-#### JSHint
-
-这个工具帮助我们发现代码质量问题.例如,使用正确的相等运算符,未使用的变量等.
-
-运行:
-
-```bash
-npm run test-correctness
-```
-
-JSHint 规则在`test/jshintrc`中.
+Prettier 规则在 `.prettierrc.js` 中,ESLint 规则在 `.eslintrc.js` 中。
### 其他类型的测试
-我们想测试性能回归,也就是说,如果变化使得事情变得更慢,或者说性能变差,那么我们可以比较不同浏览器之间相同代码的性能.
+我们想回归测试性能,即如果更改使运行变得更慢,或者简单地测试性能,那么我们可以比较不同浏览器之间相同代码的性能。
-有一个[open issue](https://github.com/tweenjs/discuss/issues/3)来跟踪这方面的工作,但我们还没有取得进展.请求帮助!:-)
+有一个[open issue](https://github.com/tweenjs/discuss/issues/3)来跟踪这方面的工作,但我们还没有取得进展。请求帮助! :-)
## 持续集成
-我们实施了一个持续集成系统,为我们自动完成任务.它在每次发出拉取请求时自动运行测试,并且在某些情况下还可以自动发布新版本.
+我们使用 GitHub Actions 进行持续集成,以便为每个 pull request 运行构建和测试。 `.github/workflows/tests.yml` 文件告诉 GitHub 要运行什么;在我们的例子中,我们在该文件中指定的操作系统和 Node.js 版本中运行 `npm install`,然后运行 `npm test`。
-如果建议的拉取请求中的变更破坏了任何内容,则贡献者可以获得反馈,而无需等待人员查看代码.此外,请求不能合并,直到测试通过.
+**TODO**:将 macOS 和 Windows 添加到运行测试的操作系统。 请求帮助! :)
-我们正在使用 Travis CI 平台来运行测试.您会在拉请求页面的底部找到一个小信息区,让您了解测试的状态.
+## 发布流程
-所有检查通过的例子:
+目前发布过程是手动的。
-
+当准备好在 `master` 分支上发布时,确保没有未提交的更改,然后运行 `npm run release:patch` 发布一个新版本,其补丁号已被修改,`npm run release:minor` ,修改 minor 版本号并发布一个新版本,或者 `npm run release:major` 修改 major 版本号并发布一个新版本。
-当检查失败时:
-
-
-
-如果一个 pull request 通过添加新的提交被更新,测试将再次运行.
-
-Travis 配置了`.travis.yml`文件(如果你没有在你的文件浏览器或 Finder 中看到它,那是因为文件名以一个点开头,因此它被*隐藏*了)-尝试用终端打开).
-
-## 发布过程
-
-我们使用[semantic-release](https://github.com/semantic-release/semantic-release)工具结合 Travis 自动[在 GitHub 上创建版本](https://github.com/tweenjs/tween.js/releases)并将它们发布到[npm](https://npmjs.org).
-
-每次 pull request 合并时,Travis 都会运行测试.如果他们通过没有错误.Travis 将运行`after_success`步骤:
-
-```yaml
-after_success:
- - npm run semantic-release
-```
-
-这反过来会运行`package.json`中的`semantic-release`脚本:
-
-```json
-"semantic-release": "semantic-release pre && npm publish && semantic-release post"
-```
-
-当新版本发布时:
-
-- `semantic-release`决定了下一个版本号
-- 一个新的条目被添加到 GitHub 发布列表,以及包含在更改中的所有提交列表,以及一个包含该版本的 ZIP 文件,供希望下载 ZIP 的用户使用
-- git commit 是用版本号(像[Bower](http://bower.io/)这样的工具使用标签)
-- 它也被发布到 npm,在 package.json 里有新的版本号
-
-**Note:** `semantic-release`的默认配置选项只在分支名称为`master`的情况下运行.否则,我们会产生大量的推送和发布,因为 Travis 在每个 pull request 中运行!
-
-请注意`package.json`中的版本号是故意为`0.0.0-development`,因为我们不想鼓励任何人手动修改这个,但是我们也不能从文件中删除`version`字段,或者直接使用 git 仓库安装模块将会失败.
-
-### 如何确定新的版本号
-
-和 npm 一样,`semantic-release`遵循[semver](http://semver.org/)约定,所以每个版本都由唯一的`MAJOR.MINOR.PATCH`版本号来标识.例如,给定版本`1.2.3`:1 = 重要,2 = 轻微,3 = 补丁。
-
-在这个系统中,重大更改(例如,API 被修改,更新到新版本可能需要更新使用库的代码)应该增加主编号.如果存在向后兼容的更改(例如,不修改现有 API 的新功能),次要号码将会增加.较小的更改(如文档更新)只会增加修补程序编号.
-
-`semantic-release`使用提交消息自动决定下一个版本号.
-
-这真是*太好了*,因为跟踪版本号或决定新版本是主要还是次要的改变是一件非常无聊的事情,最好留给机器自己去做.
-
-为了自动构建,提交消息需要遵循一定的语法:
-
-`