diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 939e534..15dfb55 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,10 +8,10 @@ just a few small guidelines you need to follow. Contributions to this project must be accompanied by a Contributor License Agreement. You (or your employer) retain the copyright to your contribution; this simply gives us permission to use and redistribute your contributions as -part of the project. Head over to to see -your current agreements on file or to sign a new one. +part of the project. Head over to [Google Open Source CLA](https://cla.developers.google.com/) +to see your current agreements on file or to sign a new one. -You generally only need to submit a CLA once, so if you've already submitted one +You generally only need to submit a CLA once. So if you've already submitted one (even if it was for a different project), you probably don't need to do it again. @@ -26,3 +26,83 @@ information on using pull requests. This project follows [Google's Open Source Community Guidelines](https://opensource.google.com/conduct/). + +## Developing & testing your changes + +### 1. Polyfill development environment + +Run a development environment: + +```shell script +npm i +npm run dev +``` + +Then open `http://localhost:3000` and choose one of the demos (test) to see how your changes apply. + +### 2. Configuring & running tests + +Test configurations are available in `test/tests.config.json` which include: + +- `polyfillFiles`: an array of our JS shim / polyfill files, those will be injected in WPT tests files. +- `harnessTests`: an array of WPT harness tests we want to test the polyfill against. +- `browsers.local`: Browser our local selenium-webdriver will test against locally. +- `browsers.sauce`: Browser our local selenium-webdriver will test against in Saucelabs / CI environment. + +#### Run the tests locally + +Simple test will serve the WPT tests folder and intercepts requests. If the request path matches a harness test we are interested in polyfilling, it will inject the polyfill. + +_Required environment variables:_ + +```dotenv +WPT_DIR=test/wpt #defaults to test/wpt +WPT_SERVER_PORT=8081 # choose any port available on your machine +``` + +_Command_ + +```shell script +npm run test:simple +``` + +Go to `localhost:8081/scroll-animations/current-time-nan.html` as an example. + +#### Run the tests via Web Driver + +##### Local web driver + +_Required environment variables:_ + +```dotenv +WPT_DIR=test/wpt # defaults to test/wpt +WPT_SERVER_PORT=8081 # choose any port available on your machine +LOCAL_BROWSER=chrome # choose one of 'chrome', 'edge', 'firefox', 'safari' +LOCAL_WEBDRIVER_BIN=? #/path/to/webdriver-binaries +``` + +_Command_ + +```shell script +npm run test:wpt +``` + +##### SauceLabs / CI + +_Required environment variables:_ + +```dotenv +TEST_ENV=sauce +WPT_DIR=test/wpt # defaults to test/wpt +WPT_SERVER_PORT=8081 # choose any port available on your machine +SC_TUNNEL_ID=sc-wpt-tunnel # please specify 'sc-wpt-tunnel' as a SauceConnect Proxy Tunnel ID + +SAUCE_NAME= # Your saucelabs account username +SAUCE_KEY= # Your API key +``` + +_Command_ + +```shell script +TEST_ENV=sauce npm run test:wpt +``` diff --git a/README.md b/README.md index cd3c5db..652bba8 100644 --- a/README.md +++ b/README.md @@ -1,126 +1,182 @@ -# Scroll-timeline Polyfill +# Scroll-timeline Polyfill for Scroll-driven Animations -A polyfill of ScrollTimeline and ViewTimeline as defined by the [spec](https://drafts.csswg.org/scroll-animations-1/). +A polyfill of ScrollTimeline and ViewTimeline as defined by [the CSS WG spec](https://drafts.csswg.org/scroll-animations-1/). -View a [cool demo showing its usage](https://flackr.github.io/scroll-timeline/demo/parallax/)! +- [View a cool demo showing its usage.](https://flackr.github.io/scroll-timeline/demo/parallax/) +- [Track the browser support for native Scroll-driven Animations.](https://caniuse.com/?search=animation-timeline) -# Usage +> [!TIP] +> When the scroll-driven animations feature is widely available as a native feature, this polyfill may not be necessary except to support older versions of browsers. -To use this polyfill, import the module into your site and you can start creating animations that use a `ScrollTimeline` or `ViewTimeline`. +## Installation + +Use one of these methods to add the polyfill and it should begin working immediately. If it's not working, see the [_Known Limitations_](#known-limitations) section. + +### [NPM package](https://www.npmjs.com/package/scroll-timeline-polyfill) + +```sh +npm install scroll-timeline-polyfill +``` + +You may also use `pnpm` or `yarn`. Once installed, import it: ```js -import 'https://flackr.github.io/scroll-timeline/dist/scroll-timeline.js'; - -document.getElementById('parallax').animate( - { transform: ['translateY(0)', 'translateY(100px)']}, - { fill: 'both', - timeline: new ScrollTimeline({ - source: document.documentElement, - }), - rangeStart: new CSSUnitValue(0, 'px'), - rangeEnd: new CSSUnitValue(200, 'px'), - }); +import "scroll-timeline-polyfill/dist/scroll-timeline.js"; ``` -Also works with CSS Animations that use a `view-timeline` or `scroll-timeline` +### JavaScript import (CDN) + +```js +import "https://flackr.github.io/scroll-timeline/dist/scroll-timeline.js"; +``` + +### HTML script tag (CDN) ```html ``` +## Usage + +To use this polyfill, start creating animations using CSS or JavaScript. + +### JavaScript usage + +Use a `ScrollTimeline` or `ViewTimeline` instance to define animations. + +```js +document.getElementById("parallax").animate( + { transform: ["translateY(0)", "translateY(100px)"] }, + { + fill: "both", + timeline: new ScrollTimeline({ + source: document.documentElement, + }), + rangeStart: new CSSUnitValue(0, "px"), + rangeEnd: new CSSUnitValue(200, "px"), + } +); +``` + +### CSS usage + +Use `animation-timeline` property with `scroll` or `view` to define animations: + ```css @keyframes parallax-effect { - to { transform: translateY(100px) } + to { + transform: translateY(100px); + } } -#parallax { +.parallax { animation: parallax-effect linear both; animation-timeline: scroll(block root); animation-range: 0px 200px; } ``` -Please ensure your CSS is hosted on the same domain as your website or included directly on the page within a