mirror of
https://github.com/rive-app/rive-react.git
synced 2026-03-13 08:22:30 +08:00
Compare commits
341 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9a4dc0b5c | ||
|
|
19b58f5eb6 | ||
|
|
6263449898 | ||
|
|
630f70a81d | ||
|
|
bbd0d08fed | ||
|
|
ef23793d26 | ||
|
|
ca10584ed4 | ||
|
|
6fe765df84 | ||
|
|
c62b80af09 | ||
|
|
777337c481 | ||
|
|
da4b5978e7 | ||
|
|
09c0d1f947 | ||
|
|
0ca5933c41 | ||
|
|
f272fd92f0 | ||
|
|
192a562764 | ||
|
|
224a768737 | ||
|
|
c085bd5ea3 | ||
|
|
bb13c71982 | ||
|
|
779e06583c | ||
|
|
e172e0f210 | ||
|
|
abbcf14b70 | ||
|
|
a0885648ce | ||
|
|
9f768bdd0c | ||
|
|
94c9a2a60b | ||
|
|
dfe0d10936 | ||
|
|
d27eb7254d | ||
|
|
c0b27bd018 | ||
|
|
739ac7c370 | ||
|
|
b1b8040b4f | ||
|
|
1f6ae83de3 | ||
|
|
e5ff233c34 | ||
|
|
64795564d8 | ||
|
|
f0b32056a4 | ||
|
|
b5dc2fa8da | ||
|
|
0108d425dd | ||
|
|
74a27143b4 | ||
|
|
2cfb8a4955 | ||
|
|
af6c3f84c6 | ||
|
|
351d9966b1 | ||
|
|
ba73cb7053 | ||
|
|
4a4f8a7151 | ||
|
|
b5baef5ce7 | ||
|
|
79f80d39cd | ||
|
|
e1ed8250e3 | ||
|
|
a40ba0dacc | ||
|
|
7ea9c8fbcb | ||
|
|
d4cef9a131 | ||
|
|
99489af287 | ||
|
|
d881bb18c8 | ||
|
|
2e461c66b3 | ||
|
|
bb078296d0 | ||
|
|
f9bad8b62d | ||
|
|
e42f5e32d7 | ||
|
|
83fa6635ec | ||
|
|
bdd4c84d8b | ||
|
|
414543d37d | ||
|
|
119f7eea2a | ||
|
|
92b0342882 | ||
|
|
38b0a1cc86 | ||
|
|
2fd87e45e8 | ||
|
|
dc99fe27cc | ||
|
|
2358c82626 | ||
|
|
0475d47535 | ||
|
|
f51e538479 | ||
|
|
29fa6e76fb | ||
|
|
2459c489bf | ||
|
|
927dbc6b32 | ||
|
|
8ebbfb164f | ||
|
|
388fd16b5b | ||
|
|
8c87bc0ab7 | ||
|
|
280b2ec4a4 | ||
|
|
55a40c7d9f | ||
|
|
d4e6243dbb | ||
|
|
dc738d00a6 | ||
|
|
2ae22d6c30 | ||
|
|
4a3fc22261 | ||
|
|
bdc734b90b | ||
|
|
eeda717178 | ||
|
|
178f04df61 | ||
|
|
ef11079784 | ||
|
|
11f548b21c | ||
|
|
d0ff23c124 | ||
|
|
a83f5a275a | ||
|
|
b437230063 | ||
|
|
10912052f2 | ||
|
|
fe8265cd58 | ||
|
|
5b458b76e5 | ||
|
|
1decbc7d85 | ||
|
|
87627125f5 | ||
|
|
e823e9519f | ||
|
|
ac88187118 | ||
|
|
1897e823b9 | ||
|
|
1a2e57a82c | ||
|
|
0d16feeec1 | ||
|
|
ca48907649 | ||
|
|
9b02c0f1bc | ||
|
|
b25c775994 | ||
|
|
17811adac4 | ||
|
|
e4fcef529e | ||
|
|
f51fe6ee2a | ||
|
|
0f558e66e1 | ||
|
|
7a67fb14f7 | ||
|
|
da3fc317ff | ||
|
|
9b40a1a02e | ||
|
|
aa92c01329 | ||
|
|
99a8a42a15 | ||
|
|
f0ea7add89 | ||
|
|
ac9f322ccb | ||
|
|
e1c2d108e9 | ||
|
|
3aaee0bcf8 | ||
|
|
e3739f1a1f | ||
|
|
0e0a2bd972 | ||
|
|
5c47a411f2 | ||
|
|
16dc257b2f | ||
|
|
4678ea9ecf | ||
|
|
d58963e29d | ||
|
|
c32433284a | ||
|
|
8bb5652df0 | ||
|
|
9ecacf37fe | ||
|
|
f837fbe0d4 | ||
|
|
8e181d6ae2 | ||
|
|
a3a41dca40 | ||
|
|
b78c9715d7 | ||
|
|
520e5bb51d | ||
|
|
586ee4c002 | ||
|
|
3d6c7ed499 | ||
|
|
c3900b7845 | ||
|
|
d369817113 | ||
|
|
d68302ccb3 | ||
|
|
bbd4cc7af6 | ||
|
|
3936277f65 | ||
|
|
aa2a783d1c | ||
|
|
d8d7d64749 | ||
|
|
af3edad2c2 | ||
|
|
5326f800f7 | ||
|
|
b44f9ad9e1 | ||
|
|
b2495300b7 | ||
|
|
eb436263d7 | ||
|
|
0e6385288e | ||
|
|
78f75434fc | ||
|
|
a9c2950419 | ||
|
|
e799f64554 | ||
|
|
95a1daa4ef | ||
|
|
8a5b88c591 | ||
|
|
d3b29cf7d7 | ||
|
|
611522b3e0 | ||
|
|
89d35976d4 | ||
|
|
a7875b26a4 | ||
|
|
4653b8bea1 | ||
|
|
0d0688feb6 | ||
|
|
7a97c14c93 | ||
|
|
cff787524d | ||
|
|
a34a588ee5 | ||
|
|
aa89f2a1ba | ||
|
|
39d275b3e0 | ||
|
|
e22acf98ba | ||
|
|
2e52e35ddc | ||
|
|
f67cb244d2 | ||
|
|
c2319b8dea | ||
|
|
877e43e354 | ||
|
|
6a033a99d3 | ||
|
|
88f7558ddf | ||
|
|
cfe3a298fb | ||
|
|
8e24185f3f | ||
|
|
5fad06d4bd | ||
|
|
df14bc383b | ||
|
|
b8dc1e5371 | ||
|
|
1196dd4c4e | ||
|
|
06ceb3cdb0 | ||
|
|
acaa12f7fc | ||
|
|
0acf384570 | ||
|
|
97a29acfdc | ||
|
|
5eb5ccfdaa | ||
|
|
edcc2c1320 | ||
|
|
68d8ca44fa | ||
|
|
ee9b83d764 | ||
|
|
187066c2cb | ||
|
|
427d74d14f | ||
|
|
061377432e | ||
|
|
53d7548b15 | ||
|
|
e1a4ca0058 | ||
|
|
83ebd6776d | ||
|
|
75dac6fe64 | ||
|
|
e13c023933 | ||
|
|
95183ff8d5 | ||
|
|
64416e0b4d | ||
|
|
1c6837bf92 | ||
|
|
15330ababe | ||
|
|
af70b8150d | ||
|
|
a984e007f4 | ||
|
|
04d8e01f87 | ||
|
|
44e46c5dee | ||
|
|
323e92e636 | ||
|
|
a07fa02ed6 | ||
|
|
d710e1e4b2 | ||
|
|
d35e9b2805 | ||
|
|
cf44463805 | ||
|
|
f59f44692a | ||
|
|
6ba68fab9e | ||
|
|
982addf163 | ||
|
|
dfd89c7691 | ||
|
|
0247a46c47 | ||
|
|
44626c7450 | ||
|
|
c0eb7d689d | ||
|
|
ff7a6aa676 | ||
|
|
dc89439d84 | ||
|
|
7ebc10a4da | ||
|
|
e8e1a5bc08 | ||
|
|
1bb8885f22 | ||
|
|
00d13badcf | ||
|
|
b9ab7b83d2 | ||
|
|
e0f00174c8 | ||
|
|
200a86a6ba | ||
|
|
26622596c8 | ||
|
|
ac789f0855 | ||
|
|
6ecdc05aea | ||
|
|
f8aa50fa49 | ||
|
|
b59bfdef84 | ||
|
|
948ded25f7 | ||
|
|
27f7f2b250 | ||
|
|
184ba2e110 | ||
|
|
f6d8db323b | ||
|
|
301e58f390 | ||
|
|
4cce3067a7 | ||
|
|
4496eff598 | ||
|
|
5e98586354 | ||
|
|
f19295f9a5 | ||
|
|
70546308b4 | ||
|
|
62a425f30e | ||
|
|
4a554dd1ad | ||
|
|
3e6262f21f | ||
|
|
e57a99b2d1 | ||
|
|
8a968ec266 | ||
|
|
b5f00e5c97 | ||
|
|
22e6dd3494 | ||
|
|
08b9f9a2aa | ||
|
|
a24b910096 | ||
|
|
33760042d1 | ||
|
|
2c82fa04e7 | ||
|
|
2b249494d5 | ||
|
|
b56c17d48c | ||
|
|
a6fe08ced9 | ||
|
|
cd1e1410f4 | ||
|
|
353fbf8e9d | ||
|
|
ae05ad4375 | ||
|
|
ff8bbb084c | ||
|
|
89a6802fa0 | ||
|
|
91025e6772 | ||
|
|
d3bc913bcf | ||
|
|
ce56321e1d | ||
|
|
4b6f5410fd | ||
|
|
6544874d3d | ||
|
|
ed90c7f7c9 | ||
|
|
e06fdd1c8b | ||
|
|
b8ffb6b53c | ||
|
|
2dc925ef70 | ||
|
|
639de79c9e | ||
|
|
a9961c821a | ||
|
|
fc082d1a03 | ||
|
|
87fa1ae2a5 | ||
|
|
62490a50f9 | ||
|
|
fcc1a16df4 | ||
|
|
29e0ceb797 | ||
|
|
3e6a951ca1 | ||
|
|
04910f78f1 | ||
|
|
c2977c705c | ||
|
|
4e2137422b | ||
|
|
0696417926 | ||
|
|
f11a433365 | ||
|
|
48a4726d1f | ||
|
|
c927f24b5a | ||
|
|
3cbbf99fec | ||
|
|
03f05f57b7 | ||
|
|
8b483b807b | ||
|
|
816fcfcdbc | ||
|
|
6c28a8795e | ||
|
|
6a57630ae6 | ||
|
|
acba24c4ed | ||
|
|
1e6eb5ec92 | ||
|
|
6871a81ebd | ||
|
|
33053b3b7f | ||
|
|
4040083d5a | ||
|
|
2153b81e6b | ||
|
|
6b1500e681 | ||
|
|
503702cf1f | ||
|
|
7be20b0a87 | ||
|
|
78491f5819 | ||
|
|
39edb88a19 | ||
|
|
fd1a1653b1 | ||
|
|
8d7f0ab28c | ||
|
|
2a2e532564 | ||
|
|
2b1aa01a87 | ||
|
|
06c4e2aea3 | ||
|
|
819bd51ea9 | ||
|
|
6b7f113296 | ||
|
|
a62e9b3a9a | ||
|
|
04685c0bcd | ||
|
|
48fd9f9d80 | ||
|
|
3c578b730f | ||
|
|
7a46886133 | ||
|
|
092049d20f | ||
|
|
f7aced03cd | ||
|
|
eb07281415 | ||
|
|
156b3bdfb5 | ||
|
|
24d8e0a907 | ||
|
|
a1a155849a | ||
|
|
59e67cec3d | ||
|
|
84b18cc3dd | ||
|
|
1092b44947 | ||
|
|
efe28aa5f3 | ||
|
|
16d836c959 | ||
|
|
838ed1abf8 | ||
|
|
d010a55cc0 | ||
|
|
fd1c00a995 | ||
|
|
45aec2db1c | ||
|
|
62b3a1d8dc | ||
|
|
5be9d2f874 | ||
|
|
49a6b1de11 | ||
|
|
ec61a6835d | ||
|
|
ac29fa30a7 | ||
|
|
e966316971 | ||
|
|
ae6efc14d4 | ||
|
|
8ce77f153c | ||
|
|
08638359bb | ||
|
|
7dbade4589 | ||
|
|
8175c4a4d4 | ||
|
|
795ee53340 | ||
|
|
04353db432 | ||
|
|
1f0e511f6e | ||
|
|
7aee5cfab4 | ||
|
|
3477afdef1 | ||
|
|
8b43a82c5f | ||
|
|
bd49e6a4ee | ||
|
|
1dbb9cd38d | ||
|
|
aee7407f79 | ||
|
|
b48de9db84 | ||
|
|
6772f166b7 | ||
|
|
3a0a959383 | ||
|
|
314d7c19cc | ||
|
|
802648eda8 | ||
|
|
5ad5a957a6 |
35
.eslintrc.js
35
.eslintrc.js
@@ -1,29 +1,38 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
es2021: true
|
||||
es2021: true,
|
||||
},
|
||||
extends: ['plugin:react/recommended', 'prettier', 'plugin:storybook/recommended'],
|
||||
extends: [
|
||||
'plugin:react/recommended',
|
||||
'prettier',
|
||||
'plugin:storybook/recommended',
|
||||
],
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
ecmaFeatures: {
|
||||
jsx: true
|
||||
jsx: true,
|
||||
},
|
||||
ecmaVersion: 12,
|
||||
sourceType: 'module'
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: ['@typescript-eslint', 'prettier'],
|
||||
plugins: ['@typescript-eslint', 'prettier', 'react-hooks'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-unused-vars': 'error',
|
||||
'prefer-const': ['warn', {
|
||||
destructuring: 'all'
|
||||
}],
|
||||
'prefer-const': [
|
||||
'warn',
|
||||
{
|
||||
destructuring: 'all',
|
||||
},
|
||||
],
|
||||
'no-var': 'error',
|
||||
eqeqeq: ['error', 'smart']
|
||||
eqeqeq: ['error', 'smart'],
|
||||
'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks
|
||||
'react-hooks/exhaustive-deps': 'off', // Checks effect dependencies
|
||||
},
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect'
|
||||
}
|
||||
}
|
||||
};
|
||||
version: 'detect',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
26
.github/workflows/add_to_project.yml
vendored
Normal file
26
.github/workflows/add_to_project.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: Adds all new issues to project board
|
||||
|
||||
on:
|
||||
issues:
|
||||
types:
|
||||
- opened
|
||||
|
||||
jobs:
|
||||
add-to-project:
|
||||
name: Add issue to project
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/add-to-project@v0.5.0
|
||||
with:
|
||||
project-url: https://github.com/orgs/rive-app/projects/12/views/1
|
||||
github-token: ${{ secrets.ADD_TO_PROJECT_ACTION }}
|
||||
|
||||
- uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
github.rest.issues.addLabels({
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
labels: ["triage"]
|
||||
})
|
||||
85
.github/workflows/publish.yml
vendored
85
.github/workflows/publish.yml
vendored
@@ -1,43 +1,28 @@
|
||||
name: Publish to NPM
|
||||
on:
|
||||
pull_request:
|
||||
types: [closed]
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
major:
|
||||
description: 'Major'
|
||||
type: boolean
|
||||
default: false
|
||||
minor:
|
||||
description: 'Minor'
|
||||
type: boolean
|
||||
default: false
|
||||
jobs:
|
||||
determine_version:
|
||||
name: Determine the next build version
|
||||
if: github.event.pull_request.merged == true
|
||||
publish_job:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
version: ${{ steps.echo_version.outputs.version }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
working-directory: ./
|
||||
- name: Git config
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup Git config
|
||||
run: |
|
||||
git config --local user.email 'hello@rive.app'
|
||||
git config --local user.name ${{ github.actor }}
|
||||
- name: Authenticate with registry
|
||||
run: npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
|
||||
- id: determine_version
|
||||
name: Get Version
|
||||
run: npm run release -- --ci --release-version | tail -n 1 > RELEASE_VERSION
|
||||
working-directory: ./
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
|
||||
- id: echo_version
|
||||
run: echo "::set-output name=version::$(cat ./RELEASE_VERSION)"
|
||||
|
||||
merge_job:
|
||||
if: github.event.pull_request.merged == true
|
||||
runs-on: ubuntu-latest
|
||||
needs: [determine_version]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16.x'
|
||||
@@ -50,30 +35,24 @@ jobs:
|
||||
run: npm run lint
|
||||
- name: Run Tests
|
||||
run: npm test
|
||||
- name: Build main dist
|
||||
run: npm run build
|
||||
- name: Copy separated builds
|
||||
run: ./scripts/build.sh
|
||||
- name: Copy package jsons to separate react outputs
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: ./scripts/setup_all_packages.sh
|
||||
- name: Bump Versions of react outputs
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
RELEASE_VERSION: ${{ needs.determine_version.outputs.version }}
|
||||
run: ./scripts/bump_all_versions.sh
|
||||
- name: Git config
|
||||
run: |
|
||||
git config --local user.email 'hello@rive.app'
|
||||
git config --local user.name ${{ github.actor }}
|
||||
- name: Authenticate with registry
|
||||
run: npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
|
||||
- name: Release rive-react
|
||||
- if: ${{ inputs.major == true }}
|
||||
name: Major Release - Bump version number, update changelog, push and tag
|
||||
run: npm run release:major
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
|
||||
run: npm run release -- --ci
|
||||
- name: Release @rive-app/react-* variants
|
||||
PAT_GITHUB: ${{ secrets.PAT_GITHUB }}
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
- if: ${{inputs.major == false && inputs.minor == true}}
|
||||
name: Minor release - Bump version number, update changelog, push and tag
|
||||
run: npm run release:minor
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
|
||||
run: ./scripts/publish_all.sh
|
||||
PAT_GITHUB: ${{ secrets.PAT_GITHUB }}
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
- if: ${{inputs.major == false && inputs.minor == false}}
|
||||
name: Patch release - Bump version number, update changelog, push and tag
|
||||
run: npm run release:patch
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
|
||||
PAT_GITHUB: ${{ secrets.PAT_GITHUB }}
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
12
.github/workflows/storybook.yml
vendored
12
.github/workflows/storybook.yml
vendored
@@ -1,10 +1,12 @@
|
||||
name: Deploy Storybook
|
||||
on:
|
||||
pull_request:
|
||||
types: [closed]
|
||||
branches:
|
||||
- main
|
||||
paths: ['src', 'examples/stories/**'] # Trigger the action only when files change in the folders defined here
|
||||
# Testing to see if this job is causing the race condition
|
||||
workflow_dispatch:
|
||||
# pull_request:
|
||||
# types: [closed]
|
||||
# branches:
|
||||
# - main
|
||||
# paths: ['src', 'examples/stories/**'] # Trigger the action only when files change in the folders defined here
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
{
|
||||
"git": {
|
||||
"addUntrackedFiles": true,
|
||||
"requireCleanWorkingDir": false,
|
||||
"commitMessage": "chore: release ${version}",
|
||||
"tagName": "v${version}",
|
||||
"changelog": "npx auto-changelog --stdout --commit-limit false --unreleased --template https://raw.githubusercontent.com/release-it/release-it/master/templates/changelog-compact.hbs"
|
||||
@@ -12,6 +14,12 @@
|
||||
"releaseName": "${version}"
|
||||
},
|
||||
"hooks": {
|
||||
"after:bump": ["npx auto-changelog -p", "git add ./CHANGELOG.md"]
|
||||
"after:version:bump": [
|
||||
"npm run build",
|
||||
"npm run setup-builds",
|
||||
"npm run setup-packages",
|
||||
"npx auto-changelog -p",
|
||||
"npm run publish:all"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
1110
CHANGELOG.md
1110
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
74
CONTRIBUTING.md
Normal file
74
CONTRIBUTING.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# Contributing
|
||||
|
||||
We love contributions! If you want to run the project locally to test out changes, run the examples, or just see how things work under the hood, read on below.
|
||||
|
||||
## Local development
|
||||
|
||||
This runtime consumes specific tied-down versions of the [JS/WASM runtime](https://github.com/rive-app/rive-wasm) to have better control over changes that occur in that downstream runtime.
|
||||
|
||||
### Installation
|
||||
|
||||
1. Clone the project down
|
||||
2. Run `npm i` in the shell/terminal at the base of the project to install the dependencies needed for the project
|
||||
|
||||
### Local dev server
|
||||
|
||||
To start the local dev server to reflect any changes made to the core `src/` files, run the following in a terminal tab:
|
||||
|
||||
```
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### Running the example storybook locally
|
||||
|
||||
We use Storybook to deploy our examples out onto a public-facing page for folks to view and see code examples for. It also serves as the place we'll include any example suites. These story files are stored in `examples/**.stories.mdx`. `.mdx` is an extension Storybook supports to support both `jsx` (React files) and `md` (markdown) in one file.
|
||||
|
||||
To run Storybook, run the following command in the terminal:
|
||||
|
||||
```
|
||||
npm run storybook
|
||||
```
|
||||
|
||||
Any changes made in any files should reflect automatically, including the `.mdx` example files, and `src/` files.
|
||||
|
||||
### Testing
|
||||
|
||||
We also have a suite of unit tests against the high-level component and various hooks exported in the `test/` folder. When adding new components, changing the API, or underlying functionality, make sure to add a test here!
|
||||
|
||||
To run the test suite:
|
||||
|
||||
```
|
||||
npm test
|
||||
```
|
||||
|
||||
## Making changes
|
||||
|
||||
When you're ready to make changes, push up to a feature branch off of the `main` branch. Create a pull request to this repository in Github. When creating commit messages, please be as descriptive as possible to the changes being made.
|
||||
|
||||
For example, if the change is simply a bug fix or patch change:
|
||||
|
||||
```
|
||||
git commit -m "Fix: Fixing a return type from useRive"
|
||||
```
|
||||
|
||||
Or if it's simply a docs change:
|
||||
|
||||
```
|
||||
git commit -m "Docs: Adding a new link for another example page"
|
||||
```
|
||||
|
||||
For minor/major version releases, also ensure you preface commit messages with:
|
||||
|
||||
```
|
||||
git commit -m "Major: Restructuring the useRive API with new parameters"
|
||||
```
|
||||
|
||||
These messages help make the changelog clear as to what changes are made for future devs to see.
|
||||
|
||||
When pull requests are merged, the runtime will automatically deploy the next release version. By default, patch versions are published. If you want to set the next version as a minor/major version to be released, you have to manually update the `package.json` file at the root of the project to the verison you want it to.
|
||||
|
||||
You can find the deploy scripts in `.github/`
|
||||
|
||||
## Bumping the underlying JS/WASM runtime
|
||||
|
||||
Many times, fixes to the runtime and feature adds come from the underlying JS/WASM runtime. In these cases, just bump the `@rive-app/canvas` and `@rive-app/webgl` versions to the verison you need to incorporate the fix/feature. Run `npm i` and test out the change locally against the Storybook examples and run the test suite to make sure nothing breaks, and then submit a PR with just the `package.json` change if that's all that's needed.
|
||||
217
README.md
217
README.md
@@ -1,208 +1,79 @@
|
||||

|
||||
[](https://rive-app.github.io/rive-react)
|
||||

|
||||

|
||||
|
||||
# Rive React
|
||||
|
||||
React Runtime for [Rive](https://rive.app).
|
||||

|
||||
|
||||
A wrapper around [Rive.js](https://github.com/rive-app/rive-wasm), providing full control over the js runtime while making it super simple to use in React applications.
|
||||
A React runtime library for [Rive](https://rive.app).
|
||||
|
||||
Detailed runtime documentation can be found in [Rive's help center](https://help.rive.app/runtimes).
|
||||
This library is a wrapper around the [JS/Wasm runtime](https://github.com/rive-app/rive-wasm), giving full control over the js runtime while providing components and hooks for React applications.
|
||||
|
||||
## Create and ship interactive animations to any platform
|
||||
## Table of contents
|
||||
|
||||
[Rive](https://rive.app) is a real-time interactive design and animation tool. Use our collaborative editor to create motion graphics that respond to different states and user inputs. Then load your animations into apps, games, and websites with our lightweight open-source runtimes.
|
||||
- :star: [Rive Overview](#rive-overview)
|
||||
- 🚀 [Getting Started & API docs](#getting-started)
|
||||
- :mag: [Supported Versions](#supported-versions)
|
||||
- :books: [Examples](#examples)
|
||||
- :runner: [Migration Guides](#migration-guides)
|
||||
- 👨💻 [Contributing](#contributing)
|
||||
- :question: [Issues](#issues)
|
||||
|
||||
## Installation
|
||||
## Rive overview
|
||||
|
||||
```
|
||||
npm i --save rive-react
|
||||
```
|
||||
[Rive](https://rive.app) is a real-time interactive design and animation tool that helps teams create and run interactive animations anywhere. Designers and developers use our collaborative editor to create motion graphics that respond to different states and user inputs. Our lightweight open-source runtime libraries allow them to load their animations into apps, games, and websites.
|
||||
|
||||
_Note: This library is using React hooks so the minimum version required for both react and react-dom is 16.8.0._
|
||||
:house_with_garden: [Homepage](https://rive.app/)
|
||||
|
||||
## Usage
|
||||
:blue_book: [General help docs](https://rive.app/community/doc/)
|
||||
|
||||
### Component
|
||||
🛠 [Rive Forums](https://rive.app/community/forums/home)
|
||||
|
||||
Rive React provides a basic component as it's default import for displaying simple animations. Note that any animations or state machines instantiated through this component will autoplay.
|
||||
## Getting started
|
||||
|
||||
```js
|
||||
import Rive from 'rive-react';
|
||||
Follow along with the link below for a quick start in getting Rive React integrated into your React apps.
|
||||
|
||||
function Example() {
|
||||
return <Rive src="loader.riv" />;
|
||||
}
|
||||
- [Getting Started with Rive in React](https://rive.app/community/doc/react/docRfaSQ0eaE)
|
||||
- [API documentation](https://rive.app/community/doc/parameters-and-return-values/docJlDMNulDh)
|
||||
|
||||
export default Example;
|
||||
```
|
||||
For more information, see the Runtime sections of the Rive help documentation:
|
||||
|
||||
#### Props
|
||||
- [Animation Playback](https://rive.app/community/doc/animation-playback/docDKKxsr7ko)
|
||||
- [Layout](https://rive.app/community/doc/layout/docBl81zd1GB)
|
||||
- [State Machines](https://rive.app/community/doc/state-machines/docxeznG7iiK)
|
||||
- [Rive Text](https://rive.app/community/doc/text/docn2E6y1lXo)
|
||||
- [Rive Events](https://rive.app/community/doc/rive-events/docbOnaeffgr)
|
||||
- [Loading Assets](https://rive.app/community/doc/loading-assets/doct4wVHGPgC)
|
||||
|
||||
- `src`: File path or URL to the .riv file to display.
|
||||
- `artboard`: _(optional)_ Name to display.
|
||||
- `animations`: _(optional)_ Name or list of names of animtions to play.
|
||||
- `stateMachines`: _(optional)_ Name of state machine to play.
|
||||
- `layout`: _(optional)_ Layout object to define how animations are displayed on the canvas. See [Rive.js](https://github.com/rive-app/rive-wasm#layout) for more details.
|
||||
- _All attributes and eventHandlers that can be passed to a `canvas` element can also be passed to the `Rive` component and used in the same manner._
|
||||
## Supported versions
|
||||
|
||||
#### Styles and Classes
|
||||
|
||||
When rendering out a Rive component, in the DOM, it will show as a `<div>` element that contains the `<canvas>` element that powers the Rive animations. The purpose of the `<div>` element is to help control the sizing of the component. By default, the container has the following styles set on the `style` attribute:
|
||||
```css
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
```
|
||||
|
||||
If you decide to pass in a `className` to the Rive component, you will override these attributes, and you will need to either set these style attributes in your CSS associated with that `className`, or set your own sizing preferences.
|
||||
|
||||
### useRive Hook
|
||||
|
||||
For more advanced usage, the `useRive` hook is provided. The hook will return a component and a [Rive.js](https://github.com/rive-app/rive-wasm) `Rive` object which gives you control of the current rive file.
|
||||
|
||||
```js
|
||||
import { useRive } from 'rive-react';
|
||||
|
||||
function Example() {
|
||||
const params = {
|
||||
src: 'loader.riv',
|
||||
autoplay: false,
|
||||
};
|
||||
const { RiveComponent, rive } = useRive(params);
|
||||
|
||||
return (
|
||||
<RiveComponent
|
||||
onMouseEnter={() => rive && rive.play()}
|
||||
onMouseLeave={() => rive && rive.pause()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default Example;
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
- `riveParams`: Set of parameters that are passed to the Rive.js `Rive` class constructor. `null` and `undefined` can be passed to conditionally display the .riv file.
|
||||
- `opts`: Rive React specific options.
|
||||
|
||||
#### Return Values
|
||||
|
||||
- `RiveComponent`: A Component that can be used to display your .riv file. This component accepts the same attributes and event handlers as a `canvas` element.
|
||||
- `rive`: A Rive.js `Rive` object. This will return as null until the .riv file has fully loaded.
|
||||
- `canvas`: HTMLCanvasElement object, on which the .riv file is rendering.
|
||||
- `setCanvasRef`: A callback ref that can be passed to your own canvas element, if you wish to have control over the rendering of the Canvas element.
|
||||
- `setContainerRef`: A callback ref that can be passed to a container element that wraps the canvas element, if you which to have control over the rendering of the container element.
|
||||
_For the vast majority of use cases, you can just the returned `RiveComponent` and don't need to worry about `setCanvasRef` and `setContainerRef`._
|
||||
|
||||
#### riveParams
|
||||
|
||||
- `src?`: _(optional)_ File path or URL to the .riv file to use. One of `src` or `buffer` must be provided.
|
||||
- `buffer?`: _(optional)_ ArrayBuffer containing the raw bytes from a .riv file. One of `src` or `buffer` must be provided.
|
||||
- `artboard?`: _(optional)_ Name of the artboard to use.
|
||||
- `animations?`: _(optional)_ Name or list of names of animations to play.
|
||||
- `stateMachines?`: _(optional)_ Name of list of names of state machines to load.
|
||||
- `layout?`: _(optional)_ Layout object to define how animations are displayed on the canvas. See [Rive.js](https://github.com/rive-app/rive-wasm#layout) for more details.
|
||||
- `autoplay?`: _(optional)_ If `true`, the animation will automatically start playing when loaded. Defaults to false.
|
||||
- `onLoad?`: _(optional)_ Callback that get's fired when the .rive file loads .
|
||||
- `onLoadError?`: _(optional)_ Callback that get's fired when an error occurs loading the .riv file.
|
||||
- `onPlay?`: _(optional)_ Callback that get's fired when the animation starts playing.
|
||||
- `onPause?`: _(optional)_ Callback that get's fired when the animation pauses.
|
||||
- `onStop?`: _(optional)_ Callback that get's fired when the animation stops playing.
|
||||
- `onLoop?`: _(optional)_ Callback that get's fired when the animation completes a loop.
|
||||
- `onStateChange?`: _(optional)_ Callback that get's fired when a state change occurs.
|
||||
|
||||
#### opts
|
||||
|
||||
- `useDevicePixelRatio`: _(optional)_ If `true`, the hook will scale the resolution of the animation based the [devicePixelRatio](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio). Defaults to `true`. NOTE: Requires the `setContainerRef` ref callback to be passed to a element wrapping a canvas element. If you use the `RiveComponent`, then this will happen automatically.
|
||||
- `fitCanvasToArtboardHeight`: _(optional)_ If `true`, then the canvas will resize based on the height of the artboard. Defaults to `false`.
|
||||
- `useOffscreenRenderer`: _(optional)_ If `true`, the Rive instance will share (or create if one does not exist) an offscreen `WebGL` context. This allows you to display multiple Rive animations on one screen to work around some browser limitations regarding multiple concurrent WebGL contexts. If `false`, each Rive instance will have its own dedicated `WebGL` context, and you may need to be cautious of the browser limitations just mentioned. Defaults to `true`.
|
||||
|
||||
### useStateMachineInput Hook
|
||||
|
||||
The `useStateMachineInput` hook is provided to make it easier to interact with state machine inputs on a rive file.
|
||||
|
||||
```js
|
||||
import { useRive, useStateMachineInput } from 'rive-react';
|
||||
|
||||
function Example() {
|
||||
const STATE_MACHINE_NAME = 'button';
|
||||
const INPUT_NAME = 'onClick';
|
||||
|
||||
const { RiveComponent, rive } = useRive({
|
||||
src: 'button.riv',
|
||||
stateMachines: STATE_MACHINE_NAME,
|
||||
autoplay: true,
|
||||
});
|
||||
|
||||
const onClickInput = useStateMachineInput(
|
||||
rive,
|
||||
STATE_MACHINE_NAME,
|
||||
INPUT_NAME
|
||||
);
|
||||
|
||||
// This example is using a state machine with a trigger input.
|
||||
return <RiveComponent onClick={() => onClickInput.fire()} />;
|
||||
}
|
||||
|
||||
export default Example;
|
||||
```
|
||||
|
||||
See our [examples](examples) folder for working examples of [Boolean](examples/state-machine-boolean-input) and [Number](examples/state-machine-number-input) inputs.
|
||||
|
||||
#### Parameters
|
||||
|
||||
- `rive`: A `Rive` object. This is returned by the `useRive` hook.
|
||||
- `stateMachineName`: Name of the state machine.
|
||||
- `inputName`: Name of the state machine input.
|
||||
- `initialValue`: Initial value to set on a state machine input when it's loaded in, for number or boolean inputs. **Note** that this may trigger any transitional animations between the initial state and any next states that depend on the input this `initialValue` is being set to. If this is problematic or conflicting for your case, we recommend setting the true initial value of the input on your state machine in the Rive editor.
|
||||
|
||||
#### Return Value
|
||||
|
||||
A Rive.js `stateMachineInput` object.
|
||||
This library supports React versions `^16.8.0` through `^18.0.0`.
|
||||
|
||||
## Examples
|
||||
|
||||
The [examples](examples) shows a number of different ways to use Rive React. See the instructions for each example to run locally.
|
||||
Check out our Storybook instance that shows how to use the library in small examples, along with code snippets! This includes examples using the basic component, as well as the convenient hooks exported to take advantage of state machines.
|
||||
|
||||
- [Example page](https://rive-app.github.io/rive-react)
|
||||
- [Login screen w/ input tracking](https://rive-app.github.io/rive-use-cases/?path=/story/example-loginformcomponent--primary)
|
||||
- [Mouse tracking](https://codesandbox.io/s/rive-mouse-track-test-t0y965?file=/src/App.js)
|
||||
- [Accessibility concerns](https://rive.app/blog/accesible-web-animations-aria-live-regions)
|
||||
|
||||
## Migration notes
|
||||
### Awesome Rive
|
||||
|
||||
### Migrating from version 0.0.x to 1.x.x
|
||||
For even more examples and resources on using Rive at runtime or in other tools, checkout the [awesome-rive](https://github.com/rive-app/awesome-rive) repo.
|
||||
|
||||
Starting in v 1.0.0, we've migrated from wrapping around the `@rive-app/canvas` runtime (which uses the `CanvasRendereringContext2D` renderer) to the `@rive-app/webgl` runtime (which uses the WebGL renderer). The high-level API doesn't require any change to upgrade, but there are some notes to consider about the backing renderer.
|
||||
## Migration guides
|
||||
|
||||
The backing `WebGL` runtime allows for best performance across all devices, as well as support for some features that are not supported in the `canvas` renderer runtime. To allow the `react` runtime to support some of the newer features in Rive, we needed to switch the `rive-react` backing runtime to `@rive-app/webgl`.
|
||||
Using an older version of the runtime and need to learn how to upgrade to the latest version? Check out the migration guides below in our help center that help guide you through version bumps; breaking changes and all!
|
||||
|
||||
One note about this switch is that some browsers may limit the number of concurrent WebGL contexts. For example, Chrome may only support up to 16 contexts concurrently. We pass a property called `useOffscreenRenderer` set to true to the backing runtime when instantiating Rive by default, which helps to manage the lifecycle of the `canvas` with a single offscreen `WebGL` context, even if there are many Rive animations on the screen (i.e 16+). If you need a single `WebGL` context per Rive animation/instance, pass in the `useOffscreenRenderer` property set to `false` in the `useRive` options, or as a prop in the default export component from this runtime. See below for an example:
|
||||
[Migration guides](https://rive.app/community/doc/migrating-from-v3-to-v4/dociIPXVHKFF)
|
||||
|
||||
```js
|
||||
const {rive, RiveComponent} = useRive({
|
||||
src: 'foo.riv',
|
||||
}, {
|
||||
// Default (you don't need to set this)
|
||||
useOffscreenRenderer: true,
|
||||
// To override and use one context per Rive instance, uncomment and use the line below
|
||||
// useOffscreenRenderer: false,
|
||||
});
|
||||
## Contributing
|
||||
|
||||
// or you can override the flag in JSX via props
|
||||
return (
|
||||
<Rive src="foo.riv" useOffscreenRenderer={false} />
|
||||
);
|
||||
```
|
||||
We love contributions! Check out our [contributing docs](./CONTRIBUTING.md) to get more details into how to run this project, the examples, and more all locally.
|
||||
|
||||
### Migrating from version 1.x.x to 2.x.x
|
||||
## Issues
|
||||
|
||||
#### Package split
|
||||
|
||||
In most cases, you may be able to migrate safely. We are mainly enabling the React runtime to work with both backing renderers `@rive-app/webgl` and `@rive-app/canvas`, such that you can use either `@rive-app/react-canvas` or `@rive-app/react-webgl` as the dependency in your React applications. Another change that is mostly internal is that by default, `rive-react` will now use `@rive-app/canvas` (as opposed to `@rive-app/webgl`) to wrap around, as it currently yields the fastest performance across devices. Therefore, **we recommend installing `@rive-app/react-canvas` in your applicaions**. However, if you need a WebGL backing renderer, you may want to use `@rive-app/react-webgl`.
|
||||
|
||||
#### Classes, styles, and component props
|
||||
Starting in v2.0, we introduce one breaking change where any non-style props set on the `RiveComponent` (i.e `aria-*`, `role`, etc.) will be set on the inner `<canvas>` element. Previously, all extra props would be set onto the containing `<div>` element. Both the `className` and `style` props will continue to be set on the `<div>` element that wraps the canvas, as this dictates the sizing of the Rive component.
|
||||
|
||||
|
||||
### Migrating to 3.0
|
||||
|
||||
There are no breaking changes here. If you have migrated to v2.x.x, you can safely migrate to 3.0.
|
||||
Have an issue with using the runtime, or want to suggest a feature/API to help make your development life better? Log an issue in our [issues](https://github.com/rive-app/rive-react/issues) tab! You can also browse older issues and discussion threads there to see solutions that may have worked for common problems.
|
||||
|
||||
3
docs/0.233bd6e2.iframe.bundle.js
Normal file
3
docs/0.233bd6e2.iframe.bundle.js
Normal file
File diff suppressed because one or more lines are too long
8
docs/0.233bd6e2.iframe.bundle.js.LICENSE.txt
Normal file
8
docs/0.233bd6e2.iframe.bundle.js.LICENSE.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Prism: Lightweight, robust, elegant syntax highlighting
|
||||
*
|
||||
* @license MIT <https://opensource.org/licenses/MIT>
|
||||
* @author Lea Verou <https://lea.verou.me>
|
||||
* @namespace
|
||||
* @public
|
||||
*/
|
||||
1
docs/0.233bd6e2.iframe.bundle.js.map
Normal file
1
docs/0.233bd6e2.iframe.bundle.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"0.233bd6e2.iframe.bundle.js","sources":[],"mappings":";A","sourceRoot":""}
|
||||
2
docs/0.f3c14cfa225a4c40c8ba.manager.bundle.js
Normal file
2
docs/0.f3c14cfa225a4c40c8ba.manager.bundle.js
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Prism: Lightweight, robust, elegant syntax highlighting
|
||||
*
|
||||
* @license MIT <https://opensource.org/licenses/MIT>
|
||||
* @author Lea Verou <https://lea.verou.me>
|
||||
* @namespace
|
||||
* @public
|
||||
*/
|
||||
1
docs/1.44288d676d5217e7dfaf.manager.bundle.js
Normal file
1
docs/1.44288d676d5217e7dfaf.manager.bundle.js
Normal file
File diff suppressed because one or more lines are too long
1
docs/1.7e5fbb8d.iframe.bundle.js
Normal file
1
docs/1.7e5fbb8d.iframe.bundle.js
Normal file
File diff suppressed because one or more lines are too long
1
docs/2.89943a03.iframe.bundle.js
Normal file
1
docs/2.89943a03.iframe.bundle.js
Normal file
@@ -0,0 +1 @@
|
||||
(window.webpackJsonp=window.webpackJsonp||[]).push([[2],{"./node_modules/@storybook/preview-web/dist/esm/renderDocs.js":function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,"renderDocs",(function(){return renderDocs})),__webpack_require__.d(__webpack_exports__,"unmountDocs",(function(){return unmountDocs}));__webpack_require__("./node_modules/regenerator-runtime/runtime.js"),__webpack_require__("./node_modules/core-js/modules/es.object.to-string.js"),__webpack_require__("./node_modules/core-js/modules/es.promise.js");var react=__webpack_require__("./node_modules/react/index.js"),react_default=__webpack_require__.n(react),react_dom=__webpack_require__("./node_modules/react-dom/index.js"),react_dom_default=__webpack_require__.n(react_dom),wrapper={fontSize:"14px",letterSpacing:"0.2px",margin:"10px 0"},main={margin:"auto",padding:30,borderRadius:10,background:"rgba(0,0,0,0.03)"},heading={textAlign:"center"},NoDocs_NoDocs=function NoDocs(){return react_default.a.createElement("div",{style:wrapper,className:"sb-nodocs sb-wrapper"},react_default.a.createElement("div",{style:main},react_default.a.createElement("h1",{style:heading},"No Docs"),react_default.a.createElement("p",null,"Sorry, but there are no docs for the selected story. To add them, set the story's ",react_default.a.createElement("code",null,"docs")," parameter. If you think this is an error:"),react_default.a.createElement("ul",null,react_default.a.createElement("li",null,"Please check the story definition."),react_default.a.createElement("li",null,"Please check the Storybook config."),react_default.a.createElement("li",null,"Try reloading the page.")),react_default.a.createElement("p",null,"If the problem persists, check the browser console, or the terminal you've run Storybook from.")))};function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg),value=info.value}catch(error){return void reject(error)}info.done?resolve(value):Promise.resolve(value).then(_next,_throw)}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise((function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(void 0)}))}}function renderDocs(story,docsContext,element,callback){return function renderDocsAsync(_x,_x2,_x3){return _renderDocsAsync.apply(this,arguments)}(story,docsContext,element).then(callback)}function _renderDocsAsync(){return(_renderDocsAsync=_asyncToGenerator(regeneratorRuntime.mark((function _callee(story,docsContext,element){var _docs$getContainer,_docs$getPage,docs,DocsContainer,Page,docsElement;return regeneratorRuntime.wrap((function _callee$(_context){for(;;)switch(_context.prev=_context.next){case 0:if(!(null!=(docs=story.parameters.docs)&&docs.getPage||null!=docs&&docs.page)||(null!=docs&&docs.getContainer||null!=docs&&docs.container)){_context.next=3;break}throw new Error("No `docs.container` set, did you run `addon-docs/preset`?");case 3:if(_context.t1=docs.container,_context.t1){_context.next=8;break}return _context.next=7,null===(_docs$getContainer=docs.getContainer)||void 0===_docs$getContainer?void 0:_docs$getContainer.call(docs);case 7:_context.t1=_context.sent;case 8:if(_context.t0=_context.t1,_context.t0){_context.next=11;break}_context.t0=function(_ref){var children=_ref.children;return react_default.a.createElement(react_default.a.Fragment,null,children)};case 11:if(DocsContainer=_context.t0,_context.t3=docs.page,_context.t3){_context.next=17;break}return _context.next=16,null===(_docs$getPage=docs.getPage)||void 0===_docs$getPage?void 0:_docs$getPage.call(docs);case 16:_context.t3=_context.sent;case 17:if(_context.t2=_context.t3,_context.t2){_context.next=20;break}_context.t2=NoDocs_NoDocs;case 20:return Page=_context.t2,docsElement=react_default.a.createElement(DocsContainer,{key:story.componentId,context:docsContext},react_default.a.createElement(Page,null)),_context.next=24,new Promise((function(resolve){react_dom_default.a.render(docsElement,element,resolve)}));case 24:case"end":return _context.stop()}}),_callee)})))).apply(this,arguments)}function unmountDocs(element){react_dom_default.a.unmountComponentAtNode(element)}NoDocs_NoDocs.displayName="NoDocs"}}]);
|
||||
2
docs/5.c79123fa7941ae9f0387.manager.bundle.js
Normal file
2
docs/5.c79123fa7941ae9f0387.manager.bundle.js
Normal file
File diff suppressed because one or more lines are too long
31
docs/5.c79123fa7941ae9f0387.manager.bundle.js.LICENSE.txt
Normal file
31
docs/5.c79123fa7941ae9f0387.manager.bundle.js.LICENSE.txt
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
1
docs/6.2d406554b9c913afb448.manager.bundle.js
Normal file
1
docs/6.2d406554b9c913afb448.manager.bundle.js
Normal file
File diff suppressed because one or more lines are too long
3
docs/6.e2fef599.iframe.bundle.js
Normal file
3
docs/6.e2fef599.iframe.bundle.js
Normal file
File diff suppressed because one or more lines are too long
31
docs/6.e2fef599.iframe.bundle.js.LICENSE.txt
Normal file
31
docs/6.e2fef599.iframe.bundle.js.LICENSE.txt
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
1
docs/6.e2fef599.iframe.bundle.js.map
Normal file
1
docs/6.e2fef599.iframe.bundle.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"6.e2fef599.iframe.bundle.js","sources":[],"mappings":";A","sourceRoot":""}
|
||||
1
docs/7.15129502.iframe.bundle.js
Normal file
1
docs/7.15129502.iframe.bundle.js
Normal file
File diff suppressed because one or more lines are too long
1
docs/7.480c60c60f21bf435941.manager.bundle.js
Normal file
1
docs/7.480c60c60f21bf435941.manager.bundle.js
Normal file
File diff suppressed because one or more lines are too long
2
docs/8.6c22300703a58b9d6b46.manager.bundle.js
Normal file
2
docs/8.6c22300703a58b9d6b46.manager.bundle.js
Normal file
File diff suppressed because one or more lines are too long
12
docs/8.6c22300703a58b9d6b46.manager.bundle.js.LICENSE.txt
Normal file
12
docs/8.6c22300703a58b9d6b46.manager.bundle.js.LICENSE.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
/*!
|
||||
* OverlayScrollbars
|
||||
* https://github.com/KingSora/OverlayScrollbars
|
||||
*
|
||||
* Version: 1.13.0
|
||||
*
|
||||
* Copyright KingSora | Rene Haas.
|
||||
* https://github.com/KingSora
|
||||
*
|
||||
* Released under the MIT license.
|
||||
* Date: 02.08.2020
|
||||
*/
|
||||
1
docs/8.b569e86b.iframe.bundle.js
Normal file
1
docs/8.b569e86b.iframe.bundle.js
Normal file
File diff suppressed because one or more lines are too long
3
docs/9.1e553722.iframe.bundle.js
Normal file
3
docs/9.1e553722.iframe.bundle.js
Normal file
File diff suppressed because one or more lines are too long
12
docs/9.1e553722.iframe.bundle.js.LICENSE.txt
Normal file
12
docs/9.1e553722.iframe.bundle.js.LICENSE.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
/*!
|
||||
* OverlayScrollbars
|
||||
* https://github.com/KingSora/OverlayScrollbars
|
||||
*
|
||||
* Version: 1.13.0
|
||||
*
|
||||
* Copyright KingSora | Rene Haas.
|
||||
* https://github.com/KingSora
|
||||
*
|
||||
* Released under the MIT license.
|
||||
* Date: 02.08.2020
|
||||
*/
|
||||
1
docs/9.1e553722.iframe.bundle.js.map
Normal file
1
docs/9.1e553722.iframe.bundle.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"9.1e553722.iframe.bundle.js","sources":[],"mappings":";A","sourceRoot":""}
|
||||
1
docs/9.5e61b7f1b71ff49bf163.manager.bundle.js
Normal file
1
docs/9.5e61b7f1b71ff49bf163.manager.bundle.js
Normal file
@@ -0,0 +1 @@
|
||||
(window.webpackJsonp=window.webpackJsonp||[]).push([[9],{931:function(module,exports){module.exports=function(e,n){return n=n||{},new Promise((function(t,r){var s=new XMLHttpRequest,o=[],u=[],i={},a=function(){return{ok:2==(s.status/100|0),statusText:s.statusText,status:s.status,url:s.responseURL,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(s.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([s.response]))},clone:a,headers:{keys:function(){return o},entries:function(){return u},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var l in s.open(n.method||"get",e,!0),s.onload=function(){s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,n,t){o.push(n=n.toLowerCase()),u.push([n,t]),i[n]=i[n]?i[n]+","+t:t})),t(a())},s.onerror=r,s.withCredentials="include"==n.credentials,n.headers)s.setRequestHeader(l,n.headers[l]);s.send(n.body||null)}))}}}]);
|
||||
BIN
docs/baseball.riv
Normal file
BIN
docs/baseball.riv
Normal file
Binary file not shown.
BIN
docs/favicon.ico
Normal file
BIN
docs/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
367
docs/iframe.html
Normal file
367
docs/iframe.html
Normal file
@@ -0,0 +1,367 @@
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Webpack App</title><meta name="viewport" content="width=device-width,initial-scale=1"><base target="_parent"><style>/* While we aren't showing the main block yet, but still preparing, we want everything the user
|
||||
has rendered, which may or may not be in #root, to be display none */
|
||||
.sb-show-preparing-story:not(.sb-show-main) > :not(.sb-preparing-story) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sb-show-preparing-docs:not(.sb-show-main) > :not(.sb-preparing-docs) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Hide our own blocks when we aren't supposed to be showing them */
|
||||
:not(.sb-show-preparing-story) > .sb-preparing-story,
|
||||
:not(.sb-show-preparing-docs) > .sb-preparing-docs,
|
||||
:not(.sb-show-nopreview) > .sb-nopreview,
|
||||
:not(.sb-show-errordisplay) > .sb-errordisplay {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sb-show-main.sb-main-centered {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.sb-show-main.sb-main-centered #root {
|
||||
box-sizing: border-box;
|
||||
margin: auto;
|
||||
padding: 1rem;
|
||||
max-height: 100%; /* Hack for centering correctly in IE11 */
|
||||
}
|
||||
|
||||
/* Vertical centering fix for IE11 */
|
||||
@media screen and (-ms-high-contrast: none), (-ms-high-contrast: active) {
|
||||
.sb-show-main.sb-main-centered:after {
|
||||
content: '';
|
||||
min-height: inherit;
|
||||
font-size: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.sb-show-main.sb-main-fullscreen {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.sb-show-main.sb-main-padded {
|
||||
margin: 0;
|
||||
padding: 1rem;
|
||||
display: block;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.sb-wrapper {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 20px;
|
||||
font-family: 'Nunito Sans', -apple-system, '.SFNSText-Regular', 'San Francisco',
|
||||
BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.sb-heading {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.2px;
|
||||
margin: 10px 0;
|
||||
padding-right: 25px;
|
||||
}
|
||||
|
||||
.sb-nopreview {
|
||||
display: flex;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.sb-nopreview_main {
|
||||
margin: auto;
|
||||
padding: 30px;
|
||||
border-radius: 10px;
|
||||
background: rgba(0, 0, 0, 0.03);
|
||||
}
|
||||
|
||||
.sb-nopreview_heading {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.sb-errordisplay {
|
||||
border: 20px solid rgb(187, 49, 49);
|
||||
background: #222;
|
||||
color: #fff;
|
||||
z-index: 999999;
|
||||
}
|
||||
|
||||
.sb-errordisplay_code {
|
||||
padding: 10px;
|
||||
background: #000;
|
||||
color: #eee;
|
||||
font-family: 'Operator Mono', 'Fira Code Retina', 'Fira Code', 'FiraCode-Retina', 'Andale Mono',
|
||||
'Lucida Console', Consolas, Monaco, monospace;
|
||||
}
|
||||
|
||||
.sb-errordisplay pre {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
@-webkit-keyframes sb-rotate360 {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@keyframes sb-rotate360 {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@-webkit-keyframes sb-glow {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.4;
|
||||
}
|
||||
}
|
||||
@keyframes sb-glow {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.4;
|
||||
}
|
||||
}
|
||||
|
||||
/* We display the preparing loaders *over* the rendering story */
|
||||
.sb-preparing-story,
|
||||
.sb-preparing-docs {
|
||||
background-color: white;
|
||||
/* Maximum possible z-index. It would be better to use stacking contexts to ensure it's always
|
||||
on top, but this isn't possible as it would require making CSS changes that could affect user code */
|
||||
z-index: 2147483647;
|
||||
}
|
||||
|
||||
.sb-loader {
|
||||
-webkit-animation: sb-rotate360 0.7s linear infinite;
|
||||
animation: sb-rotate360 0.7s linear infinite;
|
||||
border-color: rgba(97, 97, 97, 0.29);
|
||||
border-radius: 50%;
|
||||
border-style: solid;
|
||||
border-top-color: #646464;
|
||||
border-width: 2px;
|
||||
display: inline-block;
|
||||
height: 32px;
|
||||
left: 50%;
|
||||
margin-left: -16px;
|
||||
margin-top: -16px;
|
||||
mix-blend-mode: difference;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transition: all 200ms ease-out;
|
||||
vertical-align: top;
|
||||
width: 32px;
|
||||
z-index: 4;
|
||||
}
|
||||
|
||||
.sb-previewBlock {
|
||||
background: #fff;
|
||||
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-radius: 4px;
|
||||
box-shadow: rgba(0, 0, 0, 0.1) 0 1px 3px 0;
|
||||
margin: 25px auto 40px;
|
||||
max-width: 600px;
|
||||
}
|
||||
|
||||
.sb-previewBlock_header {
|
||||
align-items: center;
|
||||
box-shadow: rgba(0, 0, 0, 0.1) 0 -1px 0 0 inset;
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
height: 40px;
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
.sb-previewBlock_icon {
|
||||
-webkit-animation: sb-glow 1.5s ease-in-out infinite;
|
||||
animation: sb-glow 1.5s ease-in-out infinite;
|
||||
background: #e6e6e6;
|
||||
height: 14px;
|
||||
width: 14px;
|
||||
}
|
||||
.sb-previewBlock_icon:last-child {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.sb-previewBlock_body {
|
||||
-webkit-animation: sb-glow 1.5s ease-in-out infinite;
|
||||
animation: sb-glow 1.5s ease-in-out infinite;
|
||||
height: 182px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.sb-argstableBlock {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
font-size: 13px;
|
||||
line-height: 20px;
|
||||
margin: 25px auto 40px;
|
||||
max-width: 600px;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
}
|
||||
.sb-argstableBlock th:first-of-type,
|
||||
.sb-argstableBlock td:first-of-type {
|
||||
padding-left: 20px;
|
||||
}
|
||||
.sb-argstableBlock th:nth-of-type(2),
|
||||
.sb-argstableBlock td:nth-of-type(2) {
|
||||
width: 35%;
|
||||
}
|
||||
.sb-argstableBlock th:nth-of-type(3),
|
||||
.sb-argstableBlock td:nth-of-type(3) {
|
||||
width: 15%;
|
||||
}
|
||||
.sb-argstableBlock th:laste-of-type,
|
||||
.sb-argstableBlock td:laste-of-type {
|
||||
width: 25%;
|
||||
padding-right: 20px;
|
||||
}
|
||||
.sb-argstableBlock th span,
|
||||
.sb-argstableBlock td span {
|
||||
-webkit-animation: sb-glow 1.5s ease-in-out infinite;
|
||||
animation: sb-glow 1.5s ease-in-out infinite;
|
||||
background-color: rgba(0, 0, 0, 0.1);
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
color: transparent;
|
||||
}
|
||||
.sb-argstableBlock th {
|
||||
padding: 10px 15px;
|
||||
}
|
||||
|
||||
.sb-argstableBlock-body {
|
||||
border-radius: 4px;
|
||||
box-shadow: rgba(0, 0, 0, 0.1) 0 1px 3px 1px, rgba(0, 0, 0, 0.065) 0 0 0 1px;
|
||||
}
|
||||
.sb-argstableBlock-body tr {
|
||||
background: transparent;
|
||||
overflow: hidden;
|
||||
}
|
||||
.sb-argstableBlock-body tr:not(:first-child) {
|
||||
border-top: 1px solid #e6e6e6;
|
||||
}
|
||||
.sb-argstableBlock-body tr:first-child td:first-child {
|
||||
border-top-left-radius: 4px;
|
||||
}
|
||||
.sb-argstableBlock-body tr:first-child td:last-child {
|
||||
border-top-right-radius: 4px;
|
||||
}
|
||||
.sb-argstableBlock-body tr:last-child td:first-child {
|
||||
border-bottom-left-radius: 4px;
|
||||
}
|
||||
.sb-argstableBlock-body tr:last-child td:last-child {
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
.sb-argstableBlock-body td {
|
||||
background: #fff;
|
||||
padding-bottom: 10px;
|
||||
padding-top: 10px;
|
||||
vertical-align: top;
|
||||
}
|
||||
.sb-argstableBlock-body td:not(:first-of-type) {
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
}
|
||||
.sb-argstableBlock-body button {
|
||||
-webkit-animation: sb-glow 1.5s ease-in-out infinite;
|
||||
animation: sb-glow 1.5s ease-in-out infinite;
|
||||
background-color: rgba(0, 0, 0, 0.1);
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
color: transparent;
|
||||
display: inline;
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
padding: 10px 16px;
|
||||
}
|
||||
|
||||
.sb-argstableBlock-summary {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.sb-argstableBlock-code {
|
||||
margin-right: 4px;
|
||||
margin-bottom: 4px;
|
||||
padding: 2px 5px;
|
||||
}</style><script>/* globals window */
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
try {
|
||||
if (window.top !== window) {
|
||||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.top.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
||||
window.__VUE_DEVTOOLS_GLOBAL_HOOK__ = window.top.__VUE_DEVTOOLS_GLOBAL_HOOK__;
|
||||
window.top.__VUE_DEVTOOLS_CONTEXT__ = window.document;
|
||||
}
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('unable to connect to top frame for connecting dev tools');
|
||||
}
|
||||
|
||||
window.onerror = function onerror(message, source, line, column, err) {
|
||||
if (window.CONFIG_TYPE !== 'DEVELOPMENT') return;
|
||||
// eslint-disable-next-line no-var, vars-on-top
|
||||
var xhr = new window.XMLHttpRequest();
|
||||
xhr.open('POST', '/runtime-error');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
|
||||
xhr.send(
|
||||
JSON.stringify({
|
||||
/* eslint-disable object-shorthand */
|
||||
message: message,
|
||||
source: source,
|
||||
line: line,
|
||||
column: column,
|
||||
error: err && { message: err.message, name: err.name, stack: err.stack },
|
||||
origin: 'preview',
|
||||
/* eslint-enable object-shorthand */
|
||||
})
|
||||
);
|
||||
};</script><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link rel="stylesheet" data-href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap"><link rel="stylesheet" data-href="https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap"><style>body {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
font-size: 16px;
|
||||
}</style><style>#root[hidden],
|
||||
#docs-root[hidden] {
|
||||
display: none !important;
|
||||
}</style></head><body><div class="sb-preparing-story sb-wrapper"><div class="sb-loader"></div></div><div class="sb-preparing-docs sb-wrapper"><div class="sb-previewBlock"><div class="sb-previewBlock_header"><div class="sb-previewBlock_icon"></div><div class="sb-previewBlock_icon"></div><div class="sb-previewBlock_icon"></div><div class="sb-previewBlock_icon"></div></div><div class="sb-previewBlock_body"><div class="sb-loader"></div></div></div><table aria-hidden="true" class="sb-argstableBlock"><thead class="sb-argstableBlock-head"><tr><th><span>Name</span></th><th><span>Description</span></th><th><span>Default</span></th><th><span>Control</span></th></tr></thead><tbody class="sb-argstableBlock-body"><tr><td><span>propertyName</span><span title="Required">*</span></td><td><div><span>This is a short description</span></div><div class="sb-argstableBlock-summary"><div><span class="sb-argstableBlock-code">summary</span></div></div></td><td><div><span class="sb-argstableBlock-code">defaultValue</span></div></td><td><button>Set string</button></td></tr><tr><td><span>propertyName</span><span>*</span></td><td><div><span>This is a short description</span></div><div class="sb-argstableBlock-summary"><div><span class="sb-argstableBlock-code">summary</span></div></div></td><td><div><span class="sb-argstableBlock-code">defaultValue</span></div></td><td><button>Set string</button></td></tr><tr><td><span>propertyName</span><span>*</span></td><td><div><span>This is a short description</span></div><div class="sb-argstableBlock-summary"><div><span class="sb-argstableBlock-code">summary</span></div></div></td><td><div><span class="sb-argstableBlock-code">defaultValue</span></div></td><td><button>Set string</button></td></tr></tbody></table></div><div class="sb-nopreview sb-wrapper"><div class="sb-nopreview_main"><h1 class="sb-nopreview_heading sb-heading">No Preview</h1><p>Sorry, but you either have no stories or none are selected somehow.</p><ul><li>Please check the Storybook config.</li><li>Try reloading the page.</li></ul><p>If the problem persists, check the browser console, or the terminal you've run Storybook from.</p></div></div><div class="sb-errordisplay sb-wrapper"><pre id="error-message" class="sb-heading"></pre><pre class="sb-errordisplay_code"><code id="error-stack"></code></pre></div><div id="root"></div><div id="docs-root"></div><script>window['CONFIG_TYPE'] = "PRODUCTION";
|
||||
|
||||
|
||||
|
||||
window['LOGLEVEL'] = "info";
|
||||
|
||||
|
||||
|
||||
window['FRAMEWORK_OPTIONS'] = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
window['FEATURES'] = {"postcss":true,"emotionAlias":false,"warnOnLegacyHierarchySeparator":true,"buildStoriesJson":false,"storyStoreV7":false,"modernInlineRender":false,"breakingChangesV7":false,"interactionsDebugger":false,"babelModeV7":false,"argTypeTargetsV7":false,"previewMdx2":false};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
window['STORIES'] = [{"titlePrefix":"","directory":"./examples/stories","files":"*.stories.mdx","importPathMatcher":"^\\.[\\\\/](?:examples\\/stories\\/(?!\\.)(?=.)[^/]*?\\.stories\\.mdx)$"},{"titlePrefix":"","directory":"./examples/stories","files":"*.stories.@(js|jsx|ts|tsx)","importPathMatcher":"^\\.[\\\\/](?:examples\\/stories\\/(?!\\.)(?=.)[^/]*?\\.stories\\.(js|jsx|ts|tsx))$"}];</script><script src="runtime~main.e7f32bf8.iframe.bundle.js"></script><script src="vendors~main.16f7136c.iframe.bundle.js"></script><script src="main.19f2d967.iframe.bundle.js"></script></body></html>
|
||||
59
docs/index.html
Normal file
59
docs/index.html
Normal file
@@ -0,0 +1,59 @@
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><title>Webpack App</title><meta name="viewport" content="width=device-width,initial-scale=1"/><style>html, body {
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}</style><script>/* globals window */
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
try {
|
||||
if (window.top !== window) {
|
||||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.top.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
||||
}
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('unable to connect to top frame for connecting dev tools');
|
||||
}
|
||||
|
||||
window.onerror = function onerror(message, source, line, column, err) {
|
||||
if (window.CONFIG_TYPE !== 'DEVELOPMENT') return;
|
||||
// eslint-disable-next-line no-var, vars-on-top
|
||||
var xhr = new window.XMLHttpRequest();
|
||||
xhr.open('POST', '/runtime-error');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
|
||||
xhr.send(
|
||||
JSON.stringify({
|
||||
/* eslint-disable object-shorthand */
|
||||
message: message,
|
||||
source: source,
|
||||
line: line,
|
||||
column: column,
|
||||
error: err && { message: err.message, name: err.name, stack: err.stack },
|
||||
origin: 'manager',
|
||||
/* eslint-enable object-shorthand */
|
||||
})
|
||||
);
|
||||
};</script><style>#root[hidden],
|
||||
#docs-root[hidden] {
|
||||
display: none !important;
|
||||
}</style></head><body><div id="root"></div><div id="docs-root"></div><script>window['CONFIG_TYPE'] = "PRODUCTION";
|
||||
|
||||
|
||||
|
||||
window['LOGLEVEL'] = "info";
|
||||
|
||||
|
||||
|
||||
window['FEATURES'] = {"postcss":true,"emotionAlias":false,"warnOnLegacyHierarchySeparator":true,"buildStoriesJson":false,"storyStoreV7":false,"modernInlineRender":false,"breakingChangesV7":false,"interactionsDebugger":false,"babelModeV7":false,"argTypeTargetsV7":false,"previewMdx2":false};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
window['DOCS_MODE'] = false;</script><script src="runtime~main.8ab76b1af44e6332b6fc.manager.bundle.js"></script><script src="vendors~main.59133444ce5b3a186e53.manager.bundle.js"></script><script src="main.5ff01ce9b2f269a4e646.manager.bundle.js"></script></body></html>
|
||||
BIN
docs/like.riv
Normal file
BIN
docs/like.riv
Normal file
Binary file not shown.
1
docs/main.19f2d967.iframe.bundle.js
Normal file
1
docs/main.19f2d967.iframe.bundle.js
Normal file
File diff suppressed because one or more lines are too long
1
docs/main.5ff01ce9b2f269a4e646.manager.bundle.js
Normal file
1
docs/main.5ff01ce9b2f269a4e646.manager.bundle.js
Normal file
@@ -0,0 +1 @@
|
||||
(window.webpackJsonp=window.webpackJsonp||[]).push([[2],{455:function(module,exports,__webpack_require__){__webpack_require__(456),__webpack_require__(822),__webpack_require__(826),__webpack_require__(827),__webpack_require__(823),__webpack_require__(820),__webpack_require__(819),__webpack_require__(821),__webpack_require__(818),__webpack_require__(824),__webpack_require__(825),module.exports=__webpack_require__(817)},502:function(module,exports){}},[[455,3,4]]]);
|
||||
BIN
docs/piggy-bank.riv
Normal file
BIN
docs/piggy-bank.riv
Normal file
Binary file not shown.
BIN
docs/poison-loader.riv
Normal file
BIN
docs/poison-loader.riv
Normal file
Binary file not shown.
1
docs/project.json
Normal file
1
docs/project.json
Normal file
@@ -0,0 +1 @@
|
||||
{"generatedAt":1656373830741,"builder":{"name":"webpack4"},"hasCustomBabel":false,"hasCustomWebpack":false,"hasStaticDirs":true,"hasStorybookEslint":true,"refCount":0,"packageManager":{"type":"npm","version":"8.11.0"},"storybookVersion":"6.5.9","language":"typescript","storybookPackages":{"@storybook/addon-actions":{"version":"6.5.9"},"@storybook/builder-webpack4":{"version":"6.5.9"},"@storybook/manager-webpack4":{"version":"6.5.9"},"@storybook/react":{"version":"6.5.9"},"@storybook/testing-library":{"version":"0.0.11"},"eslint-plugin-storybook":{"version":"0.5.13"}},"framework":{"name":"react"},"addons":{"@storybook/addon-links":{"version":"6.5.9"},"@storybook/addon-essentials":{"version":"6.5.9"},"@storybook/addon-interactions":{"version":"6.5.9"}}}
|
||||
BIN
docs/rive_logo_black_2x.png
Normal file
BIN
docs/rive_logo_black_2x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
1
docs/runtime~main.8ab76b1af44e6332b6fc.manager.bundle.js
Normal file
1
docs/runtime~main.8ab76b1af44e6332b6fc.manager.bundle.js
Normal file
@@ -0,0 +1 @@
|
||||
!function(modules){function webpackJsonpCallback(data){for(var moduleId,chunkId,chunkIds=data[0],moreModules=data[1],executeModules=data[2],i=0,resolves=[];i<chunkIds.length;i++)chunkId=chunkIds[i],Object.prototype.hasOwnProperty.call(installedChunks,chunkId)&&installedChunks[chunkId]&&resolves.push(installedChunks[chunkId][0]),installedChunks[chunkId]=0;for(moduleId in moreModules)Object.prototype.hasOwnProperty.call(moreModules,moduleId)&&(modules[moduleId]=moreModules[moduleId]);for(parentJsonpFunction&&parentJsonpFunction(data);resolves.length;)resolves.shift()();return deferredModules.push.apply(deferredModules,executeModules||[]),checkDeferredModules()}function checkDeferredModules(){for(var result,i=0;i<deferredModules.length;i++){for(var deferredModule=deferredModules[i],fulfilled=!0,j=1;j<deferredModule.length;j++){var depId=deferredModule[j];0!==installedChunks[depId]&&(fulfilled=!1)}fulfilled&&(deferredModules.splice(i--,1),result=__webpack_require__(__webpack_require__.s=deferredModule[0]))}return result}var installedModules={},installedChunks={3:0},deferredModules=[];function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={i:moduleId,l:!1,exports:{}};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.l=!0,module.exports}__webpack_require__.e=function requireEnsure(chunkId){var promises=[],installedChunkData=installedChunks[chunkId];if(0!==installedChunkData)if(installedChunkData)promises.push(installedChunkData[2]);else{var promise=new Promise((function(resolve,reject){installedChunkData=installedChunks[chunkId]=[resolve,reject]}));promises.push(installedChunkData[2]=promise);var onScriptComplete,script=document.createElement("script");script.charset="utf-8",script.timeout=120,__webpack_require__.nc&&script.setAttribute("nonce",__webpack_require__.nc),script.src=function jsonpScriptSrc(chunkId){return __webpack_require__.p+""+({}[chunkId]||chunkId)+"."+{0:"f3c14cfa225a4c40c8ba",1:"44288d676d5217e7dfaf",5:"c79123fa7941ae9f0387",6:"2d406554b9c913afb448",7:"480c60c60f21bf435941",8:"6c22300703a58b9d6b46",9:"5e61b7f1b71ff49bf163"}[chunkId]+".manager.bundle.js"}(chunkId);var error=new Error;onScriptComplete=function(event){script.onerror=script.onload=null,clearTimeout(timeout);var chunk=installedChunks[chunkId];if(0!==chunk){if(chunk){var errorType=event&&("load"===event.type?"missing":event.type),realSrc=event&&event.target&&event.target.src;error.message="Loading chunk "+chunkId+" failed.\n("+errorType+": "+realSrc+")",error.name="ChunkLoadError",error.type=errorType,error.request=realSrc,chunk[1](error)}installedChunks[chunkId]=void 0}};var timeout=setTimeout((function(){onScriptComplete({type:"timeout",target:script})}),12e4);script.onerror=script.onload=onScriptComplete,document.head.appendChild(script)}return Promise.all(promises)},__webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.d=function(exports,name,getter){__webpack_require__.o(exports,name)||Object.defineProperty(exports,name,{enumerable:!0,get:getter})},__webpack_require__.r=function(exports){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(exports,"__esModule",{value:!0})},__webpack_require__.t=function(value,mode){if(1&mode&&(value=__webpack_require__(value)),8&mode)return value;if(4&mode&&"object"==typeof value&&value&&value.__esModule)return value;var ns=Object.create(null);if(__webpack_require__.r(ns),Object.defineProperty(ns,"default",{enumerable:!0,value:value}),2&mode&&"string"!=typeof value)for(var key in value)__webpack_require__.d(ns,key,function(key){return value[key]}.bind(null,key));return ns},__webpack_require__.n=function(module){var getter=module&&module.__esModule?function getDefault(){return module.default}:function getModuleExports(){return module};return __webpack_require__.d(getter,"a",getter),getter},__webpack_require__.o=function(object,property){return Object.prototype.hasOwnProperty.call(object,property)},__webpack_require__.p="",__webpack_require__.oe=function(err){throw console.error(err),err};var jsonpArray=window.webpackJsonp=window.webpackJsonp||[],oldJsonpFunction=jsonpArray.push.bind(jsonpArray);jsonpArray.push=webpackJsonpCallback,jsonpArray=jsonpArray.slice();for(var i=0;i<jsonpArray.length;i++)webpackJsonpCallback(jsonpArray[i]);var parentJsonpFunction=oldJsonpFunction;checkDeferredModules()}([]);
|
||||
1
docs/runtime~main.e7f32bf8.iframe.bundle.js
Normal file
1
docs/runtime~main.e7f32bf8.iframe.bundle.js
Normal file
@@ -0,0 +1 @@
|
||||
!function(modules){function webpackJsonpCallback(data){for(var moduleId,chunkId,chunkIds=data[0],moreModules=data[1],executeModules=data[2],i=0,resolves=[];i<chunkIds.length;i++)chunkId=chunkIds[i],Object.prototype.hasOwnProperty.call(installedChunks,chunkId)&&installedChunks[chunkId]&&resolves.push(installedChunks[chunkId][0]),installedChunks[chunkId]=0;for(moduleId in moreModules)Object.prototype.hasOwnProperty.call(moreModules,moduleId)&&(modules[moduleId]=moreModules[moduleId]);for(parentJsonpFunction&&parentJsonpFunction(data);resolves.length;)resolves.shift()();return deferredModules.push.apply(deferredModules,executeModules||[]),checkDeferredModules()}function checkDeferredModules(){for(var result,i=0;i<deferredModules.length;i++){for(var deferredModule=deferredModules[i],fulfilled=!0,j=1;j<deferredModule.length;j++){var depId=deferredModule[j];0!==installedChunks[depId]&&(fulfilled=!1)}fulfilled&&(deferredModules.splice(i--,1),result=__webpack_require__(__webpack_require__.s=deferredModule[0]))}return result}var installedModules={},installedChunks={4:0},deferredModules=[];function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={i:moduleId,l:!1,exports:{}};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.l=!0,module.exports}__webpack_require__.e=function requireEnsure(chunkId){var promises=[],installedChunkData=installedChunks[chunkId];if(0!==installedChunkData)if(installedChunkData)promises.push(installedChunkData[2]);else{var promise=new Promise((function(resolve,reject){installedChunkData=installedChunks[chunkId]=[resolve,reject]}));promises.push(installedChunkData[2]=promise);var onScriptComplete,script=document.createElement("script");script.charset="utf-8",script.timeout=120,__webpack_require__.nc&&script.setAttribute("nonce",__webpack_require__.nc),script.src=function jsonpScriptSrc(chunkId){return __webpack_require__.p+""+({}[chunkId]||chunkId)+"."+{0:"233bd6e2",1:"7e5fbb8d",2:"89943a03",6:"e2fef599",7:"15129502",8:"b569e86b",9:"1e553722"}[chunkId]+".iframe.bundle.js"}(chunkId);var error=new Error;onScriptComplete=function(event){script.onerror=script.onload=null,clearTimeout(timeout);var chunk=installedChunks[chunkId];if(0!==chunk){if(chunk){var errorType=event&&("load"===event.type?"missing":event.type),realSrc=event&&event.target&&event.target.src;error.message="Loading chunk "+chunkId+" failed.\n("+errorType+": "+realSrc+")",error.name="ChunkLoadError",error.type=errorType,error.request=realSrc,chunk[1](error)}installedChunks[chunkId]=void 0}};var timeout=setTimeout((function(){onScriptComplete({type:"timeout",target:script})}),12e4);script.onerror=script.onload=onScriptComplete,document.head.appendChild(script)}return Promise.all(promises)},__webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.d=function(exports,name,getter){__webpack_require__.o(exports,name)||Object.defineProperty(exports,name,{enumerable:!0,get:getter})},__webpack_require__.r=function(exports){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(exports,"__esModule",{value:!0})},__webpack_require__.t=function(value,mode){if(1&mode&&(value=__webpack_require__(value)),8&mode)return value;if(4&mode&&"object"==typeof value&&value&&value.__esModule)return value;var ns=Object.create(null);if(__webpack_require__.r(ns),Object.defineProperty(ns,"default",{enumerable:!0,value:value}),2&mode&&"string"!=typeof value)for(var key in value)__webpack_require__.d(ns,key,function(key){return value[key]}.bind(null,key));return ns},__webpack_require__.n=function(module){var getter=module&&module.__esModule?function getDefault(){return module.default}:function getModuleExports(){return module};return __webpack_require__.d(getter,"a",getter),getter},__webpack_require__.o=function(object,property){return Object.prototype.hasOwnProperty.call(object,property)},__webpack_require__.p="",__webpack_require__.oe=function(err){throw console.error(err),err};var jsonpArray=window.webpackJsonp=window.webpackJsonp||[],oldJsonpFunction=jsonpArray.push.bind(jsonpArray);jsonpArray.push=webpackJsonpCallback,jsonpArray=jsonpArray.slice();for(var i=0;i<jsonpArray.length;i++)webpackJsonpCallback(jsonpArray[i]);var parentJsonpFunction=oldJsonpFunction;checkDeferredModules()}([]);
|
||||
BIN
docs/skills.riv
Normal file
BIN
docs/skills.riv
Normal file
Binary file not shown.
BIN
docs/truck.riv
Normal file
BIN
docs/truck.riv
Normal file
Binary file not shown.
3
docs/vendors~main.16f7136c.iframe.bundle.js
Normal file
3
docs/vendors~main.16f7136c.iframe.bundle.js
Normal file
File diff suppressed because one or more lines are too long
106
docs/vendors~main.16f7136c.iframe.bundle.js.LICENSE.txt
Normal file
106
docs/vendors~main.16f7136c.iframe.bundle.js.LICENSE.txt
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
object-assign
|
||||
(c) Sindre Sorhus
|
||||
@license MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* The buffer module from node.js, for the browser.
|
||||
*
|
||||
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* https://github.com/es-shims/es5-shim
|
||||
* @license es5-shim Copyright 2009-2020 by contributors, MIT License
|
||||
* see https://github.com/es-shims/es5-shim/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
/*!
|
||||
* https://github.com/paulmillr/es6-shim
|
||||
* @license es6-shim Copyright 2013-2016 by Paul Miller (http://paulmillr.com)
|
||||
* and contributors, MIT License
|
||||
* es6-shim: v0.35.4
|
||||
* see https://github.com/paulmillr/es6-shim/blob/0.35.3/LICENSE
|
||||
* Details and documentation:
|
||||
* https://github.com/paulmillr/es6-shim/
|
||||
*/
|
||||
|
||||
/*!
|
||||
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
||||
*
|
||||
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* isobject <https://github.com/jonschlinkert/isobject>
|
||||
*
|
||||
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
/** @license React v0.20.2
|
||||
* scheduler.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v17.0.2
|
||||
* react-dom.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v17.0.2
|
||||
* react-is.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v17.0.2
|
||||
* react-jsx-runtime.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v17.0.2
|
||||
* react.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
//! stable.js 0.1.8, https://github.com/Two-Screen/stable
|
||||
|
||||
//! © 2018 Angry Bytes and contributors. MIT licensed.
|
||||
1
docs/vendors~main.16f7136c.iframe.bundle.js.map
Normal file
1
docs/vendors~main.16f7136c.iframe.bundle.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"vendors~main.16f7136c.iframe.bundle.js","sources":[],"mappings":";A","sourceRoot":""}
|
||||
2
docs/vendors~main.59133444ce5b3a186e53.manager.bundle.js
Normal file
2
docs/vendors~main.59133444ce5b3a186e53.manager.bundle.js
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
object-assign
|
||||
(c) Sindre Sorhus
|
||||
@license MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Fuse.js v3.6.1 - Lightweight fuzzy-search (http://fusejs.io)
|
||||
*
|
||||
* Copyright (c) 2012-2017 Kirollos Risk (http://kiro.me)
|
||||
* All Rights Reserved. Apache Software License 2.0
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
/*!
|
||||
* https://github.com/es-shims/es5-shim
|
||||
* @license es5-shim Copyright 2009-2020 by contributors, MIT License
|
||||
* see https://github.com/es-shims/es5-shim/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
/*!
|
||||
* https://github.com/paulmillr/es6-shim
|
||||
* @license es6-shim Copyright 2013-2016 by Paul Miller (http://paulmillr.com)
|
||||
* and contributors, MIT License
|
||||
* es6-shim: v0.35.4
|
||||
* see https://github.com/paulmillr/es6-shim/blob/0.35.3/LICENSE
|
||||
* Details and documentation:
|
||||
* https://github.com/paulmillr/es6-shim/
|
||||
*/
|
||||
|
||||
/*!
|
||||
* isobject <https://github.com/jonschlinkert/isobject>
|
||||
*
|
||||
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
/*! store2 - v2.13.1 - 2021-12-20
|
||||
* Copyright (c) 2021 Nathan Bubna; Licensed (MIT OR GPL-3.0) */
|
||||
|
||||
/**
|
||||
* React Router DOM v6.0.2
|
||||
*
|
||||
* Copyright (c) Remix Software Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE.md file in the root directory of this source tree.
|
||||
*
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* React Router v6.0.2
|
||||
*
|
||||
* Copyright (c) Remix Software Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE.md file in the root directory of this source tree.
|
||||
*
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/** @license React v0.20.2
|
||||
* scheduler.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v17.0.2
|
||||
* react-dom.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v17.0.2
|
||||
* react.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
|
||||
|
||||
@@ -54,6 +54,44 @@ The example below shows how to start with a Rive instance that does not autoplay
|
||||
</Story>
|
||||
</Canvas>
|
||||
|
||||
<Canvas withSource="open">
|
||||
<Story name="Play/pause with intersection observer">
|
||||
{() => {
|
||||
const ref = useRef(null);
|
||||
const { rive, RiveComponent } = useRive({
|
||||
src: 'baseball.riv',
|
||||
autoplay: false,
|
||||
animations: "Hover"
|
||||
});
|
||||
useEffect(() => {
|
||||
const observer = new IntersectionObserver(
|
||||
([things]) => {
|
||||
if (rive) {
|
||||
if (things.isIntersecting) {
|
||||
rive.play("Hover");
|
||||
} else {
|
||||
rive.pause("Hover");
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
rootMargin: '0px',
|
||||
threshold: 0.1,
|
||||
}
|
||||
)
|
||||
if (ref && ref.current) {
|
||||
observer.observe(ref.current)
|
||||
}
|
||||
}, [rive]);
|
||||
return (
|
||||
<div ref={ref} className="center">
|
||||
<RiveComponent className="base-canvas-size" />
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Story>
|
||||
</Canvas>
|
||||
|
||||
## Play/pause with external elements
|
||||
|
||||
This example shows how you can control Rive elements via user interaction outside of the canvas, such as other buttons. Here, the play/pause button will toggle whether or not to play or pause the Rive animation.
|
||||
@@ -95,5 +133,5 @@ While user interaction is a common way to control animation playback for Rives,
|
||||
|
||||
### API-driven playback
|
||||
|
||||
Another common way to control animation playback is through API responses. As long as you hold a reference to the `rive` instance returned from the `useRive` hook, you can invoke control methods on that instance in places such as callbacks from API responses.
|
||||
Another common way to control animation playback is through API responses. Imagine an API that you poll for loading progress of a task. Based on that progress response, you may play or stop a given animation. As long as you hold a reference to the `rive` instance returned from the `useRive` hook, you can invoke control methods on that instance in places such as callbacks from API responses.
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import { useState } from 'react';
|
||||
|
||||
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
|
||||
|
||||
import RiveComponent, {useRive, useStateMachineInput} from '../../src';
|
||||
import {Button} from './components/Button';
|
||||
import RiveComponent, { useRive, useStateMachineInput } from '../../src';
|
||||
import { Button } from './components/Button';
|
||||
import './rive-overview.css';
|
||||
|
||||
<Meta title="React Runtime/Overview" />
|
||||
@@ -31,6 +31,7 @@ There's multiple ways to render Rive using the React runtime. See the associated
|
||||
```tsx
|
||||
import RiveComponent from '@rive-app/react-canvas';
|
||||
```
|
||||
|
||||
The React runtime exports a default React component you can insert as JSX. Under the hood, it renders a `<canvas>` element that runs the animation, and a wrapping `<div>` element that handles sizing of the canvas based on the parent that wraps the component.
|
||||
|
||||
**When to use this**: Use this for simple rendering cases where you don't need to control playback or setup state machine inputs to advance state machines. It will simply autoplay the first animation it finds in the `.riv`, the animation name you provide it, or the state machine name if you provide one.
|
||||
@@ -56,12 +57,13 @@ In addition to the props laid out below, the component accepts other props that
|
||||
### useRive Hook
|
||||
|
||||
```tsx
|
||||
import {useRive} from '@rive-app/react-canvas';
|
||||
import { useRive } from '@rive-app/react-canvas';
|
||||
```
|
||||
|
||||
The runtime also exports a named `useRive` hook that allows for more control at Rive instantiation, since it passes back a `rive` object you can use to manipulate state machines, control playback, and more.
|
||||
|
||||
**When to use this:** When you need to control your Rive animation in any aspect, such as controlling playback, using state machine inputs to advance state machines, add adding callbacks on certain Rive-specific events such as `onStateChange`, `onPause`, etc.
|
||||
|
||||
<Canvas withSource="open">
|
||||
<Story name="useRive Hook">
|
||||
{() => {
|
||||
@@ -69,7 +71,7 @@ The runtime also exports a named `useRive` hook that allows for more control at
|
||||
const [animationText, setAnimationText] = useState('');
|
||||
const { rive, RiveComponent: RiveComponentPlayback } = useRive({
|
||||
src: 'truck.riv',
|
||||
stateMachines: "drive",
|
||||
stateMachines: 'drive',
|
||||
artboard: 'Truck',
|
||||
autoplay: true,
|
||||
onPause: () => {
|
||||
@@ -88,15 +90,19 @@ The runtime also exports a named `useRive` hook that allows for more control at
|
||||
setIsPlaying(true);
|
||||
}
|
||||
};
|
||||
return ((
|
||||
return (
|
||||
<>
|
||||
<div className="center">
|
||||
<RiveComponentPlayback className="base-canvas-size" />
|
||||
<RiveComponentPlayback className="base-canvas-size">
|
||||
<p>Animation that can be paused and played by clicking on it</p>
|
||||
</RiveComponentPlayback>
|
||||
<p>{animationText}</p>
|
||||
<Button onClick={togglePlaying}>{isPlaying ? 'Pause' : 'Play'}</Button>
|
||||
<Button onClick={togglePlaying}>
|
||||
{isPlaying ? 'Pause' : 'Play'}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
));
|
||||
);
|
||||
}}
|
||||
</Story>
|
||||
</Canvas>
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
<!-- RiveTestHook.stories.mdx -->
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
|
||||
|
||||
import RiveComponent, {useRive, useStateMachineInput} from '../../src';
|
||||
import {Button} from './components/Button';
|
||||
import RiveComponent, {
|
||||
EventType,
|
||||
useRive,
|
||||
useStateMachineInput,
|
||||
} from '../../src';
|
||||
import { Button } from './components/Button';
|
||||
import './rive-overview.css';
|
||||
|
||||
<Meta title="React Runtime/State Machines" />
|
||||
|
||||
# State Machine Usage
|
||||
|
||||
Not familiar with Rive State Machines? Check out our [help docs](https://help.rive.app/editor/state-machine) on what these are first!
|
||||
Not familiar with Rive State Machines? Check out our [help docs](https://rive.app/community/doc/state-machine/docwH5zPdh93) on what these are first!
|
||||
|
||||
The `useStateMachineInput` hook is a helper that makes grabbing references to state machine inputs easier to setup. This hook should be used along with the `useRive` hook, as you need to pass in the `rive` instance returned from `useRive`. See each of the examples below to see usage of the hook creating instance of three types of inputs:
|
||||
|
||||
- Booleans
|
||||
- Numbers
|
||||
- Triggers
|
||||
@@ -90,8 +95,8 @@ Once you grab a reference to the state machine input, you can get/set the value
|
||||
<Canvas withSource="open">
|
||||
<Story name="Number input">
|
||||
{() => {
|
||||
const STATE_MACHINE_NAME = 'State Machine ';
|
||||
const INPUT_NAME = 'Level';
|
||||
const STATE_MACHINE_NAME = 'skill-controller';
|
||||
const INPUT_NAME = 'level';
|
||||
const { rive, RiveComponent: RiveComponentTouch } = useRive({
|
||||
src: 'skills.riv',
|
||||
stateMachines: STATE_MACHINE_NAME,
|
||||
@@ -101,7 +106,11 @@ Once you grab a reference to the state machine input, you can get/set the value
|
||||
// levelInput is a number state machine input. To transition the state machine,
|
||||
// we need to set the value to a number. For this state machine input, we need
|
||||
// to set to 0, 1 or 2 for a state transition to occur.
|
||||
const levelInput = useStateMachineInput(rive, STATE_MACHINE_NAME, INPUT_NAME);
|
||||
const levelInput = useStateMachineInput(
|
||||
rive,
|
||||
STATE_MACHINE_NAME,
|
||||
INPUT_NAME
|
||||
);
|
||||
return (
|
||||
// The animation will fit to the parent element, so we set a large height
|
||||
// and width for this example.
|
||||
@@ -155,3 +164,59 @@ Unlike the boolean and number inputs, you invoke the `.fire()` method on a trigg
|
||||
}}
|
||||
</Story>
|
||||
</Canvas>
|
||||
|
||||
## Rive Text
|
||||
|
||||
A simple example showing Rive Text rendering. Note that if you are using the `@rive-app/react-canvas-lite` package,
|
||||
the Rive Text bit will not render on the graphic, however, the rest of the Rive content should without issue.
|
||||
|
||||
<Canvas withSource="open">
|
||||
<Story name="Rive Text">
|
||||
{() => {
|
||||
const STATE_MACHINE_NAME = 'State Machine 1';
|
||||
const { rive, RiveComponent } = useRive({
|
||||
src: 'text_test.riv',
|
||||
stateMachines: STATE_MACHINE_NAME,
|
||||
autoplay: true,
|
||||
automaticallyHandleEvents: true,
|
||||
});
|
||||
return (
|
||||
<div className="center">
|
||||
<RiveComponent className="base-canvas-size" />
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Story>
|
||||
</Canvas>
|
||||
|
||||
## Rive Events
|
||||
|
||||
To listen for Rive Events reported during state machine play, use the `on` API to add an event listener.
|
||||
|
||||
<Canvas withSource="open">
|
||||
<Story name="Rive Events">
|
||||
{() => {
|
||||
const STATE_MACHINE_NAME = 'State Machine 1';
|
||||
const { rive, RiveComponent } = useRive({
|
||||
src: 'rating_animation.riv',
|
||||
stateMachines: STATE_MACHINE_NAME,
|
||||
autoplay: true,
|
||||
automaticallyHandleEvents: true,
|
||||
});
|
||||
useEffect(() => {
|
||||
if (rive) {
|
||||
rive.on(EventType.RiveEvent, onRiveEventReceived);
|
||||
}
|
||||
}, [rive]);
|
||||
const onRiveEventReceived = (riveEvent) => {
|
||||
console.log('Rive Event Fired', riveEvent);
|
||||
};
|
||||
return (
|
||||
<div className="center">
|
||||
<RiveComponent className="base-canvas-size" />
|
||||
<p>Click on the 5 star!</p>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Story>
|
||||
</Canvas>
|
||||
|
||||
BIN
examples/stories/assets/baseball.riv
Normal file
BIN
examples/stories/assets/baseball.riv
Normal file
Binary file not shown.
BIN
examples/stories/assets/rating_animation.riv
Normal file
BIN
examples/stories/assets/rating_animation.riv
Normal file
Binary file not shown.
Binary file not shown.
BIN
examples/stories/assets/text_test.riv
Normal file
BIN
examples/stories/assets/text_test.riv
Normal file
Binary file not shown.
9
npm/react-canvas-lite/README.md
Normal file
9
npm/react-canvas-lite/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# @rive-app/react-canvas-lite
|
||||
|
||||
Output for `rive-react` using the backing `@rive-app/canvas-lite` JS runtime.
|
||||
|
||||
## Why Lite?
|
||||
|
||||
The current `@rive-app/react-canvas` dependency supports all Rive features and contains the necessary backing dependencies to render those graphics. This `lite` version has the same API, but does not compile and build with certain dependencies in order to keep the package size as small as possible.
|
||||
|
||||
At this time, this lite version of `@rive-app/react-canvas-lite` will not render Rive Text onto the canvas or play Rive Audio. Note however, that even if your Rive file may include Rive Text components, rendering the graphic should not cause any app errors, or cease to render. The same is true for playing audio.
|
||||
26
npm/react-canvas-lite/package.json
Normal file
26
npm/react-canvas-lite/package.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "@rive-app/react-canvas-lite",
|
||||
"version": "4.18.2",
|
||||
"description": "React wrapper around the @rive-app/canvas-lite library",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/types/index.d.ts",
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/rive-app/rive-react.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/rive-app/rive-react/issues"
|
||||
},
|
||||
"homepage": "https://github.com/rive-app/rive-react#readme",
|
||||
"dependencies": {
|
||||
"@rive-app/canvas-lite": "2.26.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0"
|
||||
}
|
||||
}
|
||||
26
npm/react-canvas/package.json
Normal file
26
npm/react-canvas/package.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "@rive-app/react-canvas",
|
||||
"version": "4.18.2",
|
||||
"description": "React wrapper around the @rive-app/canvas library",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/types/index.d.ts",
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/rive-app/rive-react.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/rive-app/rive-react/issues"
|
||||
},
|
||||
"homepage": "https://github.com/rive-app/rive-react#readme",
|
||||
"dependencies": {
|
||||
"@rive-app/canvas": "2.26.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0"
|
||||
}
|
||||
}
|
||||
26
npm/react-webgl/package.json
Normal file
26
npm/react-webgl/package.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "@rive-app/react-webgl",
|
||||
"version": "4.18.2",
|
||||
"description": "React wrapper around the @rive-app/webgl library",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/types/index.d.ts",
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/rive-app/rive-react.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/rive-app/rive-react/issues"
|
||||
},
|
||||
"homepage": "https://github.com/rive-app/rive-react#readme",
|
||||
"dependencies": {
|
||||
"@rive-app/webgl": "2.26.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0"
|
||||
}
|
||||
}
|
||||
26
npm/react-webgl2/package.json
Normal file
26
npm/react-webgl2/package.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "@rive-app/react-webgl2",
|
||||
"version": "4.18.2",
|
||||
"description": "React wrapper around the @rive-app/webgl2 library",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/types/index.d.ts",
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/rive-app/rive-react.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/rive-app/rive-react/issues"
|
||||
},
|
||||
"homepage": "https://github.com/rive-app/rive-react#readme",
|
||||
"dependencies": {
|
||||
"@rive-app/webgl2": "2.26.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0"
|
||||
}
|
||||
}
|
||||
20
package.json
20
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rive-react",
|
||||
"version": "3.0.8",
|
||||
"version": "4.18.2",
|
||||
"description": "React wrapper around the rive-js library",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/types/index.d.ts",
|
||||
@@ -16,7 +16,14 @@
|
||||
"types:check": "tsc --noEmit",
|
||||
"release": "release-it",
|
||||
"storybook": "start-storybook -p 6006",
|
||||
"build-storybook": "build-storybook -o docs-build"
|
||||
"build-storybook": "build-storybook -o docs-build",
|
||||
"release:patch": "npm run release -- --ci",
|
||||
"release:minor": "npm run release -- minor --ci",
|
||||
"release:major": "npm run release -- major --ci",
|
||||
"setup-builds": "./scripts/build.sh",
|
||||
"setup-packages": "./scripts/setup_all_packages.sh",
|
||||
"bump-versions": "./scripts/bump_all_versions.sh $npm_package_version",
|
||||
"publish:all": "./scripts/publish_all.sh --access public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -29,11 +36,13 @@
|
||||
},
|
||||
"homepage": "https://github.com/rive-app/rive-react#readme",
|
||||
"dependencies": {
|
||||
"@rive-app/canvas": "1.0.65",
|
||||
"@rive-app/webgl": "1.0.62"
|
||||
"@rive-app/canvas": "2.26.3",
|
||||
"@rive-app/canvas-lite": "2.26.3",
|
||||
"@rive-app/webgl": "2.26.3",
|
||||
"@rive-app/webgl2": "2.26.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.18.0",
|
||||
@@ -65,6 +74,7 @@
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"eslint-plugin-promise": "^5.1.0",
|
||||
"eslint-plugin-react": "^7.27.1",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-storybook": "^0.5.12",
|
||||
"jest": "^27.0.4",
|
||||
"prettier": "^2.3.1",
|
||||
|
||||
@@ -5,6 +5,8 @@ set -e
|
||||
# Copy the build to each react-variant build for npm release
|
||||
cp -r ./dist ./npm/react-webgl
|
||||
cp -r ./dist ./npm/react-canvas
|
||||
cp -r ./dist ./npm/react-canvas-lite
|
||||
cp -r ./dist ./npm/react-webgl2
|
||||
|
||||
echo "Replacing the canvas with webgl references in react-webgl"
|
||||
pushd ./npm/react-webgl/dist
|
||||
@@ -16,3 +18,25 @@ else
|
||||
find . -type f -name "*.js" -print0 | xargs -0 sed -i -e 's/@rive-app\/canvas/@rive-app\/webgl/g'
|
||||
fi
|
||||
popd
|
||||
|
||||
echo "Replacing the canvas with webgl2 references in react-webgl2"
|
||||
pushd ./npm/react-webgl2/dist
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
find . -type f -name "*.ts" -print0 | xargs -0 sed -i '' -e 's/@rive-app\/canvas/@rive-app\/webgl2/g'
|
||||
find . -type f -name "*.js" -print0 | xargs -0 sed -i '' -e 's/@rive-app\/canvas/@rive-app\/webgl2/g'
|
||||
else
|
||||
find . -type f -name "*.ts" -print0 | xargs -0 sed -i -e 's/@rive-app\/canvas/@rive-app\/webgl2/g'
|
||||
find . -type f -name "*.js" -print0 | xargs -0 sed -i -e 's/@rive-app\/canvas/@rive-app\/webgl2/g'
|
||||
fi
|
||||
popd
|
||||
|
||||
echo "Replacing the canvas with canvas-lite references in react-canvas-lite"
|
||||
pushd ./npm/react-canvas-lite/dist
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
find . -type f -name "*.ts" -print0 | xargs -0 sed -i '' -e 's/@rive-app\/canvas/@rive-app\/canvas-lite/g'
|
||||
find . -type f -name "*.js" -print0 | xargs -0 sed -i '' -e 's/@rive-app\/canvas/@rive-app\/canvas-lite/g'
|
||||
else
|
||||
find . -type f -name "*.ts" -print0 | xargs -0 sed -i -e 's/@rive-app\/canvas/@rive-app\/canvas-lite/g'
|
||||
find . -type f -name "*.js" -print0 | xargs -0 sed -i -e 's/@rive-app\/canvas/@rive-app\/canvas-lite/g'
|
||||
fi
|
||||
popd
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Bump the version number of every npm module in the npm folder.
|
||||
for dir in ./npm/*; do
|
||||
pushd $dir > /dev/null
|
||||
repo_name=`echo $dir | sed 's:.*/::' | sed 's/_/-/g'`
|
||||
echo Bumping version of $repo_name
|
||||
../../scripts/bump_version.sh $repo_name $RELEASE_VERSION
|
||||
popd > /dev/null
|
||||
done
|
||||
@@ -1,12 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Bumps the version of a single npm module found in the current working
|
||||
# directory. Call bump_version.sh from the path with package.json in it.
|
||||
|
||||
set -e
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
# RELEASE_VERSION will come from an env variable passed in from the GH action workflow
|
||||
node $SCRIPT_DIR/nextVersion.js "$RELEASE_VERSION" `pwd`
|
||||
|
||||
# Replace the dist package json with the newly trimmed one
|
||||
cp -f ./package.json ./dist/package.json
|
||||
@@ -1,33 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const path = process.argv[3];
|
||||
const package = require(path + '/package.json');
|
||||
const currentVersion = package.version;
|
||||
const nextVersion = process.argv[2].trim().replace(/\'/g, '"');
|
||||
|
||||
if (!nextVersion || nextVersion === currentVersion) {
|
||||
throw new Error('Next version is not defined or is a version that already exists');
|
||||
}
|
||||
|
||||
// Returns -1 if first is less than second, 1 if first is greater than second, otherwise 0 if equal.
|
||||
function compareVersion(first, second) {
|
||||
// Assumption: only numbers in our versions.
|
||||
const firstParts = first.split('.').map((value) => parseInt(value));
|
||||
const secondParts = second.split('.').map((value) => parseInt(value));
|
||||
|
||||
for (let i = 0; i < Math.max(firstParts.length, secondParts.length); i++) {
|
||||
const first = i < firstParts.length ? firstParts[i] : 0;
|
||||
const second = i < secondParts.length ? secondParts[i] : 0;
|
||||
if (first < second) {
|
||||
return -1;
|
||||
}
|
||||
if (second < first) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (compareVersion(currentVersion, nextVersion) <= 0) {
|
||||
package.version = nextVersion;
|
||||
fs.writeFileSync(path + '/package.json', JSON.stringify(package, null, 2));
|
||||
}
|
||||
@@ -5,6 +5,6 @@ set -e
|
||||
for dir in ./npm/*; do
|
||||
pushd $dir > /dev/null
|
||||
echo Publishing `echo $dir | sed 's:.*/::'`
|
||||
npm publish --access public
|
||||
npm publish $@
|
||||
popd > /dev/null
|
||||
done
|
||||
|
||||
@@ -3,14 +3,17 @@ set -e
|
||||
|
||||
echo "Copying package.json to rive-react npm package folders"
|
||||
|
||||
cp package.json npm/react-canvas
|
||||
cp package.json npm/react-webgl
|
||||
|
||||
# Bump the version number of every npm module in the npm folder.
|
||||
for dir in ./npm/*; do
|
||||
echo $dir
|
||||
pushd $dir > /dev/null
|
||||
echo $dir
|
||||
if [ -f "./package.json" ]; then
|
||||
echo "Removing existing package.json..."
|
||||
rm "./package.json"
|
||||
echo "package.json deleted from $dir"
|
||||
fi
|
||||
cp ../../package.json ./
|
||||
repo_name=`echo $dir | sed 's:.*/::' | sed 's/_/-/g'`
|
||||
echo Setting package.json on npm packages
|
||||
echo $repo_name
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
const fs = require('fs');
|
||||
const path = process.argv[2];
|
||||
const npmPackageSplit = process.argv[3].split('-');
|
||||
const renderer = npmPackageSplit[npmPackageSplit.length - 1];
|
||||
// extracts "webgl" or "canvas-lite" from the npm package name
|
||||
const renderer = npmPackageSplit.slice(1).join('-');
|
||||
const package = require(path + '/package.json');
|
||||
|
||||
function trimNpmPackage() {
|
||||
|
||||
@@ -21,14 +21,34 @@ export interface RiveProps {
|
||||
*/
|
||||
stateMachines?: string | string[];
|
||||
/**
|
||||
* Specify a starting Layout object to set Fill and Alignment for the drawing surface. See docs at https://help.rive.app/runtimes/layout for more on layout configuration.
|
||||
* Specify a starting Layout object to set Fill and Alignment for the drawing surface. See docs at https://rive.app/community/doc/layout/docBl81zd1GB for more on layout configuration.
|
||||
*/
|
||||
layout?: Layout;
|
||||
/**
|
||||
* For `@rive-app/react-webgl`, sets this property to maintain a single WebGL context for multiple canvases. **We recommend to keep the default value** when rendering multiple Rive instances on a page.
|
||||
*/
|
||||
useOffscreenRenderer?: boolean;
|
||||
};
|
||||
/**
|
||||
* Specify whether to disable Rive listeners on the canvas, thus preventing any event listeners to be attached to the canvas element
|
||||
*/
|
||||
shouldDisableRiveListeners?: boolean;
|
||||
/**
|
||||
* Specify whether to resize the canvas to its container automatically
|
||||
*/
|
||||
shouldResizeCanvasToContainer?: boolean;
|
||||
/**
|
||||
* Enable Rive Events to be handled by the runtime. This means any special Rive Event may have
|
||||
* functionality that can be invoked implicitly when detected.
|
||||
*
|
||||
* For example, if during the render loop an OpenUrlEvent is detected, the
|
||||
* browser may try to open the specified URL in the payload.
|
||||
*
|
||||
* This flag is false by default to prevent any unwanted behaviors from taking place.
|
||||
* This means any special Rive Event will have to be handled manually by subscribing to
|
||||
* EventType.RiveEvent
|
||||
*/
|
||||
automaticallyHandleEvents?: boolean;
|
||||
}
|
||||
|
||||
const Rive = ({
|
||||
src,
|
||||
@@ -37,6 +57,10 @@ const Rive = ({
|
||||
stateMachines,
|
||||
layout,
|
||||
useOffscreenRenderer = true,
|
||||
shouldDisableRiveListeners = false,
|
||||
shouldResizeCanvasToContainer = true,
|
||||
automaticallyHandleEvents = false,
|
||||
children,
|
||||
...rest
|
||||
}: RiveProps & ComponentProps<'canvas'>) => {
|
||||
const params = {
|
||||
@@ -46,14 +70,17 @@ const Rive = ({
|
||||
layout,
|
||||
stateMachines,
|
||||
autoplay: true,
|
||||
shouldDisableRiveListeners,
|
||||
automaticallyHandleEvents,
|
||||
};
|
||||
|
||||
const options = {
|
||||
useOffscreenRenderer,
|
||||
shouldResizeCanvasToContainer,
|
||||
};
|
||||
|
||||
const { RiveComponent } = useRive(params, options);
|
||||
return <RiveComponent {...rest} />;
|
||||
return <RiveComponent {...rest}>{children}</RiveComponent>;
|
||||
};
|
||||
|
||||
export default Rive;
|
||||
|
||||
38
src/hooks/elementObserver.ts
Normal file
38
src/hooks/elementObserver.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
class FakeIntersectionObserver {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
}
|
||||
|
||||
const MyIntersectionObserver =
|
||||
globalThis.IntersectionObserver || FakeIntersectionObserver;
|
||||
|
||||
class ElementObserver {
|
||||
private observer;
|
||||
|
||||
private elementsMap: Map<Element, Function> = new Map();
|
||||
|
||||
constructor() {
|
||||
this.observer = new MyIntersectionObserver(this.onObserved);
|
||||
}
|
||||
public onObserved = (entries: IntersectionObserverEntry[]) => {
|
||||
entries.forEach((entry) => {
|
||||
const elementCallback = this.elementsMap.get(entry.target as Element);
|
||||
if (elementCallback) {
|
||||
elementCallback(entry);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
public registerCallback(element: Element, callback: Function) {
|
||||
this.observer.observe(element);
|
||||
this.elementsMap.set(element, callback);
|
||||
}
|
||||
|
||||
public removeCallback(element: Element) {
|
||||
this.observer.unobserve(element);
|
||||
this.elementsMap.delete(element);
|
||||
}
|
||||
}
|
||||
|
||||
export default ElementObserver;
|
||||
94
src/hooks/useContainerSize.ts
Normal file
94
src/hooks/useContainerSize.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Dimensions } from '../types';
|
||||
|
||||
// There are polyfills for this, but they add hundreds of lines of code
|
||||
class FakeResizeObserver {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
}
|
||||
|
||||
function throttle(f: Function, delay: number) {
|
||||
let timer = 0;
|
||||
return function (this: Function, ...args: any) {
|
||||
clearTimeout(timer);
|
||||
timer = window.setTimeout(() => f.apply(this, args), delay);
|
||||
};
|
||||
}
|
||||
|
||||
const MyResizeObserver = globalThis.ResizeObserver || FakeResizeObserver;
|
||||
const hasResizeObserver = globalThis.ResizeObserver !== undefined;
|
||||
|
||||
const useResizeObserver = hasResizeObserver;
|
||||
const useWindowListener = !useResizeObserver;
|
||||
|
||||
/**
|
||||
* Hook to listen for a ref element's resize events being triggered. When resized,
|
||||
* it sets state to an object of {width: number, height: number} indicating the contentRect
|
||||
* size of the element at the new resize.
|
||||
*
|
||||
* @param containerRef - Ref element to listen for resize events on
|
||||
* @returns - Size object with width and height attributes
|
||||
*/
|
||||
export default function useSize(
|
||||
containerRef: React.MutableRefObject<HTMLElement | null>,
|
||||
shouldResizeCanvasToContainer = true
|
||||
) {
|
||||
const [size, setSize] = useState<Dimensions>({
|
||||
width: 0,
|
||||
height: 0,
|
||||
});
|
||||
|
||||
// internet explorer does not support ResizeObservers.
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined' && shouldResizeCanvasToContainer) {
|
||||
const handleResize = () => {
|
||||
setSize({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
};
|
||||
|
||||
if (useWindowListener) {
|
||||
// only pay attention to window size changes when we do not have the resizeObserver (IE only)
|
||||
handleResize();
|
||||
window.addEventListener('resize', handleResize);
|
||||
}
|
||||
|
||||
return () => window.removeEventListener('resize', handleResize);
|
||||
}
|
||||
}, []);
|
||||
const observer = useRef(
|
||||
new MyResizeObserver(
|
||||
throttle((entries: any) => {
|
||||
if (useResizeObserver) {
|
||||
setSize({
|
||||
width: entries[entries.length - 1].contentRect.width,
|
||||
height: entries[entries.length - 1].contentRect.height,
|
||||
});
|
||||
}
|
||||
}, 0)
|
||||
)
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const currentObserver = observer.current;
|
||||
if (!shouldResizeCanvasToContainer) {
|
||||
currentObserver.disconnect();
|
||||
return;
|
||||
}
|
||||
const containerEl = containerRef.current;
|
||||
if (containerRef.current && useResizeObserver) {
|
||||
currentObserver.observe(containerRef.current);
|
||||
}
|
||||
|
||||
return () => {
|
||||
currentObserver.disconnect();
|
||||
if (containerEl && useResizeObserver) {
|
||||
currentObserver.unobserve(containerEl);
|
||||
}
|
||||
};
|
||||
}, [containerRef, observer]);
|
||||
|
||||
return size;
|
||||
}
|
||||
51
src/hooks/useDevicePixelRatio.ts
Normal file
51
src/hooks/useDevicePixelRatio.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
/**
|
||||
* Listen for devicePixelRatio changes and set the new value accordingly. This could
|
||||
* happen for reasons such as:
|
||||
* - User moves window from retina screen display to a separate monitor
|
||||
* - User controls zoom settings on the browser
|
||||
*
|
||||
* Source: https://github.com/rexxars/use-device-pixel-ratio/blob/main/index.ts
|
||||
*
|
||||
* @param customDevicePixelRatio - Number to force a dpr to abide by, rather than using the window's
|
||||
*
|
||||
* @returns dpr: Number - Device pixel ratio; ratio of physical px to resolution in CSS pixels for current device
|
||||
*/
|
||||
export default function useDevicePixelRatio(customDevicePixelRatio?: number) {
|
||||
const dpr = customDevicePixelRatio || getDevicePixelRatio();
|
||||
const [currentDpr, setCurrentDpr] = useState(dpr);
|
||||
|
||||
useEffect(() => {
|
||||
const canListen = typeof window !== 'undefined' && 'matchMedia' in window;
|
||||
if (!canListen) {
|
||||
return;
|
||||
}
|
||||
|
||||
const updateDpr = () => {
|
||||
const newDpr = customDevicePixelRatio || getDevicePixelRatio();
|
||||
setCurrentDpr(newDpr);
|
||||
};
|
||||
const mediaMatcher = window.matchMedia(
|
||||
`screen and (resolution: ${currentDpr}dppx)`
|
||||
);
|
||||
mediaMatcher.hasOwnProperty('addEventListener')
|
||||
? mediaMatcher.addEventListener('change', updateDpr)
|
||||
: mediaMatcher.addListener(updateDpr);
|
||||
|
||||
return () => {
|
||||
mediaMatcher.hasOwnProperty('removeEventListener')
|
||||
? mediaMatcher.removeEventListener('change', updateDpr)
|
||||
: mediaMatcher.removeListener(updateDpr);
|
||||
};
|
||||
}, [currentDpr, customDevicePixelRatio]);
|
||||
|
||||
return currentDpr;
|
||||
}
|
||||
|
||||
function getDevicePixelRatio(): number {
|
||||
const hasDprProp =
|
||||
typeof window !== 'undefined' &&
|
||||
typeof window.devicePixelRatio === 'number';
|
||||
const dpr = hasDprProp ? window.devicePixelRatio : 1;
|
||||
return Math.min(Math.max(1, dpr), 3);
|
||||
}
|
||||
32
src/hooks/useIntersectionObserver.ts
Normal file
32
src/hooks/useIntersectionObserver.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { useCallback } from 'react';
|
||||
import ElementObserver from './elementObserver';
|
||||
|
||||
let observer: ElementObserver;
|
||||
const getObserver = () => {
|
||||
if(!observer) {
|
||||
observer = new ElementObserver();
|
||||
}
|
||||
return observer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to observe elements when they are intersecting with the viewport
|
||||
*
|
||||
* @returns - API to observer and unobserve elements
|
||||
*/
|
||||
export default function useIntersectionObserver() {
|
||||
const observe = useCallback((element: Element, callback: Function) => {
|
||||
const observer = getObserver();
|
||||
observer.registerCallback(element, callback);
|
||||
}, []);
|
||||
|
||||
const unobserve = useCallback((element: Element) => {
|
||||
const observer = getObserver();
|
||||
observer.removeCallback(element);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
observe,
|
||||
unobserve,
|
||||
};
|
||||
}
|
||||
195
src/hooks/useResizeCanvas.ts
Normal file
195
src/hooks/useResizeCanvas.ts
Normal file
@@ -0,0 +1,195 @@
|
||||
import { useEffect, useState, MutableRefObject, useCallback } from 'react';
|
||||
import { Bounds } from '@rive-app/canvas';
|
||||
import { Dimensions, UseRiveOptions } from '../types';
|
||||
import useDevicePixelRatio from './useDevicePixelRatio';
|
||||
import useContainerSize from './useContainerSize';
|
||||
import { getOptions } from '../utils';
|
||||
|
||||
interface UseResizeCanvasProps {
|
||||
/**
|
||||
* Whether or not Rive is loaded and renderer is associated with the canvas
|
||||
*/
|
||||
riveLoaded: boolean;
|
||||
/**
|
||||
* Ref to the canvas element
|
||||
*/
|
||||
canvasElem: HTMLCanvasElement | null;
|
||||
/**
|
||||
* Ref to the container element of the canvas
|
||||
*/
|
||||
containerRef: MutableRefObject<HTMLElement | null>;
|
||||
/**
|
||||
* (Optional) Callback to be invoked after the canvas has been resized due to a resize
|
||||
* of its parent container. This is where you would want to reset the layout
|
||||
* dimensions for the Rive renderer to dictate the new min/max bounds of the
|
||||
* canvas.
|
||||
*
|
||||
* Using the high-level JS runtime, this might be a simple call to `rive.resizeToCanvas()`
|
||||
* Using the low-level JSruntime, this might be invoking the renderer's `.align()` method
|
||||
* with the Layout and min/max X/Y values of the canvas.
|
||||
*
|
||||
* @returns void
|
||||
*/
|
||||
onCanvasHasResized?: () => void;
|
||||
/**
|
||||
* (Optional) Options passed to the useRive hook, including the shouldResizeCanvasToContainer option
|
||||
* which prevents the canvas element from resizing to its parent container
|
||||
*/
|
||||
options?: Partial<UseRiveOptions>;
|
||||
/**
|
||||
* (Optional) AABB bounds of the artboard. If provided, the canvas will be sized to the artboard
|
||||
* height if the fitCanvasToArtboardHeight option is true.
|
||||
*/
|
||||
artboardBounds?: Bounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper hook to listen for changes in the <canvas> parent container size and size the <canvas>
|
||||
* to match. If a resize event has occurred, a supplied callback (onCanvasHasResized)
|
||||
* will be inokved to allow for any re-calculation needed (i.e. Rive layout on the canvas).
|
||||
*
|
||||
* This hook is useful if you are not intending to use the `useRive` hook yourself, but still
|
||||
* want to use the auto-sizing logic on the canvas/container.
|
||||
*
|
||||
* @param props - Object to supply necessary props to the hook
|
||||
*/
|
||||
export default function useResizeCanvas({
|
||||
riveLoaded = false,
|
||||
canvasElem,
|
||||
containerRef,
|
||||
options = {},
|
||||
onCanvasHasResized,
|
||||
artboardBounds,
|
||||
}: UseResizeCanvasProps) {
|
||||
const presetOptions = getOptions(options);
|
||||
const [
|
||||
{ height: lastContainerHeight, width: lastContainerWidth },
|
||||
setLastContainerDimensions,
|
||||
] = useState<Dimensions>({
|
||||
height: 0,
|
||||
width: 0,
|
||||
});
|
||||
const [
|
||||
{ height: lastCanvasHeight, width: lastCanvasWidth },
|
||||
setLastCanvasSize,
|
||||
] = useState<Dimensions>({
|
||||
height: 0,
|
||||
width: 0,
|
||||
});
|
||||
|
||||
const [isFirstSizing, setIsFirstSizing] = useState(true);
|
||||
|
||||
const {
|
||||
fitCanvasToArtboardHeight,
|
||||
shouldResizeCanvasToContainer,
|
||||
useDevicePixelRatio: shouldUseDevicePixelRatio,
|
||||
customDevicePixelRatio,
|
||||
} = presetOptions;
|
||||
|
||||
const containerSize = useContainerSize(
|
||||
containerRef,
|
||||
shouldResizeCanvasToContainer
|
||||
);
|
||||
const currentDevicePixelRatio = useDevicePixelRatio(customDevicePixelRatio);
|
||||
|
||||
const { maxX, maxY } = artboardBounds ?? {};
|
||||
|
||||
const getContainerDimensions = useCallback(() => {
|
||||
const width = containerRef.current?.clientWidth ?? 0;
|
||||
const height = containerRef.current?.clientHeight ?? 0;
|
||||
if (fitCanvasToArtboardHeight && artboardBounds) {
|
||||
const { maxY, maxX } = artboardBounds;
|
||||
return { width, height: width * (maxY / maxX) };
|
||||
}
|
||||
return {
|
||||
width,
|
||||
height,
|
||||
};
|
||||
}, [containerRef, fitCanvasToArtboardHeight, maxX, maxY]);
|
||||
|
||||
useEffect(() => {
|
||||
// If Rive is not ready, the container is not ready, or the user supplies a flag
|
||||
// to not resize the canvas to the container, then return early
|
||||
if (
|
||||
!shouldResizeCanvasToContainer ||
|
||||
!containerRef.current ||
|
||||
!riveLoaded
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { width, height } = getContainerDimensions();
|
||||
let hasResized = false;
|
||||
if (canvasElem) {
|
||||
// Check if the canvas parent container bounds have changed and set
|
||||
// new values accordingly
|
||||
const boundsChanged =
|
||||
width !== lastContainerWidth || height !== lastContainerHeight;
|
||||
if (presetOptions.fitCanvasToArtboardHeight && boundsChanged) {
|
||||
containerRef.current.style.height = height + 'px';
|
||||
hasResized = true;
|
||||
}
|
||||
if (presetOptions.useDevicePixelRatio) {
|
||||
// Check if devicePixelRatio may have changed and get new canvas
|
||||
// width/height values to set the size
|
||||
const canvasSizeChanged =
|
||||
width * currentDevicePixelRatio !== lastCanvasWidth ||
|
||||
height * currentDevicePixelRatio !== lastCanvasHeight;
|
||||
if (boundsChanged || canvasSizeChanged) {
|
||||
const newCanvasWidthProp = currentDevicePixelRatio * width;
|
||||
const newCanvasHeightProp = currentDevicePixelRatio * height;
|
||||
canvasElem.width = newCanvasWidthProp;
|
||||
canvasElem.height = newCanvasHeightProp;
|
||||
canvasElem.style.width = width + 'px';
|
||||
canvasElem.style.height = height + 'px';
|
||||
setLastCanvasSize({
|
||||
width: newCanvasWidthProp,
|
||||
height: newCanvasHeightProp,
|
||||
});
|
||||
hasResized = true;
|
||||
}
|
||||
} else if (boundsChanged) {
|
||||
canvasElem.width = width;
|
||||
canvasElem.height = height;
|
||||
setLastCanvasSize({
|
||||
width: width,
|
||||
height: height,
|
||||
});
|
||||
hasResized = true;
|
||||
}
|
||||
setLastContainerDimensions({ width, height });
|
||||
}
|
||||
|
||||
// Callback to perform any Rive-related actions after resizing the canvas
|
||||
// (i.e., reset the Rive layout in the render loop)
|
||||
if (onCanvasHasResized && (isFirstSizing || hasResized)) {
|
||||
onCanvasHasResized && onCanvasHasResized();
|
||||
}
|
||||
isFirstSizing && setIsFirstSizing(false);
|
||||
}, [
|
||||
canvasElem,
|
||||
containerRef,
|
||||
containerSize,
|
||||
currentDevicePixelRatio,
|
||||
getContainerDimensions,
|
||||
isFirstSizing,
|
||||
setIsFirstSizing,
|
||||
lastCanvasHeight,
|
||||
lastCanvasWidth,
|
||||
lastContainerHeight,
|
||||
lastContainerWidth,
|
||||
onCanvasHasResized,
|
||||
shouldResizeCanvasToContainer,
|
||||
fitCanvasToArtboardHeight,
|
||||
shouldUseDevicePixelRatio,
|
||||
riveLoaded,
|
||||
]);
|
||||
|
||||
// Reset width and height values when the canvas changes
|
||||
useEffect(() => {
|
||||
setLastCanvasSize({
|
||||
width: 0,
|
||||
height: 0,
|
||||
});
|
||||
}, [canvasElem]);
|
||||
}
|
||||
@@ -6,14 +6,12 @@ import React, {
|
||||
ComponentProps,
|
||||
RefCallback,
|
||||
} from 'react';
|
||||
import { Rive, EventType } from '@rive-app/canvas';
|
||||
import {
|
||||
UseRiveParameters,
|
||||
UseRiveOptions,
|
||||
RiveState,
|
||||
Dimensions,
|
||||
} from '../types';
|
||||
import { useWindowSize } from '../utils';
|
||||
import { Rive, EventType, Fit } from '@rive-app/canvas';
|
||||
import { UseRiveParameters, UseRiveOptions, RiveState } from '../types';
|
||||
import useResizeCanvas from './useResizeCanvas';
|
||||
import useDevicePixelRatio from './useDevicePixelRatio';
|
||||
import { getOptions } from '../utils';
|
||||
import useIntersectionObserver from './useIntersectionObserver';
|
||||
|
||||
type RiveComponentProps = {
|
||||
setContainerRef: RefCallback<HTMLElement>;
|
||||
@@ -25,6 +23,7 @@ function RiveComponent({
|
||||
setCanvasRef,
|
||||
className = '',
|
||||
style,
|
||||
children,
|
||||
...rest
|
||||
}: RiveComponentProps & ComponentProps<'canvas'>) {
|
||||
const containerStyle = {
|
||||
@@ -39,27 +38,17 @@ function RiveComponent({
|
||||
className={className}
|
||||
{...(!className && { style: containerStyle })}
|
||||
>
|
||||
<canvas ref={setCanvasRef} style={{ verticalAlign: 'top' }} {...rest} />
|
||||
<canvas
|
||||
ref={setCanvasRef}
|
||||
style={{ verticalAlign: 'top', width: 0, height: 0 }}
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
</canvas>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const defaultOptions = {
|
||||
useDevicePixelRatio: true,
|
||||
fitCanvasToArtboardHeight: false,
|
||||
useOffscreenRenderer: true,
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns options, with defaults set.
|
||||
*
|
||||
* @param opts
|
||||
* @returns
|
||||
*/
|
||||
function getOptions(opts: Partial<UseRiveOptions>) {
|
||||
return Object.assign({}, defaultOptions, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Hook for loading a Rive file.
|
||||
*
|
||||
@@ -78,113 +67,92 @@ export default function useRive(
|
||||
riveParams?: UseRiveParameters,
|
||||
opts: Partial<UseRiveOptions> = {}
|
||||
): RiveState {
|
||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||
const [canvasElem, setCanvasElem] = useState<HTMLCanvasElement | null>(null);
|
||||
const containerRef = useRef<HTMLElement | null>(null);
|
||||
const [rive, setRive] = useState<Rive | null>(null);
|
||||
const [dimensions, setDimensions] = useState<Dimensions>({
|
||||
height: 0,
|
||||
width: 0,
|
||||
});
|
||||
|
||||
// Listen to changes in the window sizes and update the bounds when changes
|
||||
// occur.
|
||||
const windowSize = useWindowSize();
|
||||
const [rive, setRive] = useState<Rive | null>(null);
|
||||
|
||||
const isParamsLoaded = Boolean(riveParams);
|
||||
const options = getOptions(opts);
|
||||
|
||||
/**
|
||||
* Gets the intended dimensions of the canvas element.
|
||||
*
|
||||
* The intended dimensions are those of the container element, unless the
|
||||
* option `fitCanvasToArtboardHeight` is true, then they are adjusted to
|
||||
* the height of the artboard.
|
||||
*
|
||||
* @returns Dimensions object.
|
||||
*/
|
||||
function getCanvasDimensions() {
|
||||
const { width, height } =
|
||||
containerRef.current?.getBoundingClientRect() ?? new DOMRect(0, 0, 0, 0);
|
||||
|
||||
if (rive && options.fitCanvasToArtboardHeight) {
|
||||
const { maxY, maxX } = rive.bounds;
|
||||
return { width, height: width * (maxY / maxX) };
|
||||
}
|
||||
return { width, height };
|
||||
}
|
||||
const devicePixelRatio = useDevicePixelRatio();
|
||||
|
||||
/**
|
||||
* Updates the width and height of the canvas.
|
||||
* When the canvas/parent container resize, reset the Rive layout to match the
|
||||
* new (0, 0, canvas.width, canvas.height) bounds in the render loop
|
||||
*/
|
||||
function updateBounds() {
|
||||
if (!containerRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { width, height } = getCanvasDimensions();
|
||||
const boundsChanged =
|
||||
width !== dimensions.width || height !== dimensions.height;
|
||||
if (canvasRef.current && rive && boundsChanged) {
|
||||
if (options.fitCanvasToArtboardHeight) {
|
||||
containerRef.current.style.height = height + 'px';
|
||||
}
|
||||
if (options.useDevicePixelRatio) {
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
canvasRef.current.width = dpr * width;
|
||||
canvasRef.current.height = dpr * height;
|
||||
canvasRef.current.style.width = width + 'px';
|
||||
canvasRef.current.style.height = height + 'px';
|
||||
} else {
|
||||
canvasRef.current.width = width;
|
||||
canvasRef.current.height = height;
|
||||
}
|
||||
setDimensions({ width, height });
|
||||
|
||||
// Updating the canvas width or height will clear the canvas, so call
|
||||
// startRendering() to redraw the current frame as the animation might
|
||||
// be paused and not advancing.
|
||||
rive.startRendering();
|
||||
}
|
||||
|
||||
// Always resize to Canvas
|
||||
const onCanvasHasResized = useCallback(() => {
|
||||
if (rive) {
|
||||
if (rive.layout && rive.layout.fit === Fit.Layout) {
|
||||
if (canvasElem) {
|
||||
const resizeFactor = devicePixelRatio * rive.layout.layoutScaleFactor;
|
||||
rive.devicePixelRatioUsed = devicePixelRatio;
|
||||
rive.artboardWidth = canvasElem?.width / resizeFactor;
|
||||
rive.artboardHeight = canvasElem?.height / resizeFactor;
|
||||
}
|
||||
}
|
||||
|
||||
rive.startRendering();
|
||||
rive.resizeToCanvas();
|
||||
}
|
||||
}
|
||||
}, [rive, devicePixelRatio]);
|
||||
|
||||
/**
|
||||
* Listen to changes on the windowSize and the rive file being loaded
|
||||
* and update the canvas bounds as needed.
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (rive) {
|
||||
updateBounds();
|
||||
}
|
||||
}, [rive, windowSize]);
|
||||
// Watch the canvas parent container resize and size the canvas to match
|
||||
useResizeCanvas({
|
||||
riveLoaded: !!rive,
|
||||
canvasElem,
|
||||
containerRef,
|
||||
options,
|
||||
onCanvasHasResized,
|
||||
artboardBounds: rive?.bounds,
|
||||
});
|
||||
|
||||
/**
|
||||
* Ref callback called when the canvas element mounts and unmounts.
|
||||
*/
|
||||
const setCanvasRef: RefCallback<HTMLCanvasElement> = useCallback(
|
||||
(canvas: HTMLCanvasElement | null) => {
|
||||
if (canvas && riveParams) {
|
||||
const { useOffscreenRenderer } = options;
|
||||
const r = new Rive({
|
||||
useOffscreenRenderer,
|
||||
...riveParams,
|
||||
canvas,
|
||||
});
|
||||
r.on(EventType.Load, () => setRive(r));
|
||||
} else if (canvas === null && canvasRef.current) {
|
||||
canvasRef.current.height = 0;
|
||||
canvasRef.current.width = 0;
|
||||
if (canvas === null && canvasElem) {
|
||||
canvasElem.height = 0;
|
||||
canvasElem.width = 0;
|
||||
}
|
||||
|
||||
canvasRef.current = canvas;
|
||||
setCanvasElem(canvas);
|
||||
},
|
||||
[isParamsLoaded]
|
||||
[]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!canvasElem || !riveParams) {
|
||||
return;
|
||||
}
|
||||
let isLoaded = rive != null;
|
||||
let r: Rive | null;
|
||||
if (rive == null) {
|
||||
const { useOffscreenRenderer } = options;
|
||||
r = new Rive({
|
||||
useOffscreenRenderer,
|
||||
...riveParams,
|
||||
canvas: canvasElem,
|
||||
});
|
||||
r.on(EventType.Load, () => {
|
||||
isLoaded = true;
|
||||
// Check if the component/canvas is mounted before setting state to avoid setState
|
||||
// on an unmounted component in some rare cases
|
||||
if (canvasElem) {
|
||||
setRive(r);
|
||||
} else {
|
||||
// If unmounted, cleanup the rive object immediately
|
||||
r!.cleanup();
|
||||
}
|
||||
});
|
||||
}
|
||||
return () => {
|
||||
if(!isLoaded) {
|
||||
r?.cleanup();
|
||||
}
|
||||
}
|
||||
}, [canvasElem, isParamsLoaded, rive]);
|
||||
/**
|
||||
* Ref callback called when the container element mounts
|
||||
*/
|
||||
@@ -199,33 +167,75 @@ export default function useRive(
|
||||
* Set up IntersectionObserver to stop rendering if the animation is not in
|
||||
* view.
|
||||
*/
|
||||
const { observe, unobserve } = useIntersectionObserver();
|
||||
|
||||
useEffect(() => {
|
||||
const observer = new IntersectionObserver(([entry]) => {
|
||||
let timeoutId: ReturnType<typeof setTimeout>;
|
||||
let isPaused = false;
|
||||
// This is a workaround to retest whether an element is offscreen or not.
|
||||
// There seems to be a bug in Chrome that triggers an intersection change when an element
|
||||
// is moved within the DOM using insertBefore.
|
||||
// For some reason, when this is called whithin the context of a React application, the
|
||||
// intersection callback is called only once reporting isIntersecting as false but never
|
||||
// triggered back with isIntersecting as true.
|
||||
// For this reason we retest after 10 millisecond whether the element is actually off the
|
||||
// viewport or not.
|
||||
const retestIntersection = () => {
|
||||
if (canvasElem && isPaused) {
|
||||
const size = canvasElem.getBoundingClientRect();
|
||||
const isIntersecting =
|
||||
size.width > 0 &&
|
||||
size.height > 0 &&
|
||||
size.top <
|
||||
(window.innerHeight || document.documentElement.clientHeight) &&
|
||||
size.bottom > 0 &&
|
||||
size.left <
|
||||
(window.innerWidth || document.documentElement.clientWidth) &&
|
||||
size.right > 0;
|
||||
if (isIntersecting) {
|
||||
rive?.startRendering();
|
||||
isPaused = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
const onChange = (entry: IntersectionObserverEntry) => {
|
||||
entry.isIntersecting
|
||||
? rive && rive.startRendering()
|
||||
: rive && rive.stopRendering();
|
||||
});
|
||||
|
||||
if (canvasRef.current) {
|
||||
observer.observe(canvasRef.current);
|
||||
}
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
isPaused = !entry.isIntersecting;
|
||||
clearTimeout(timeoutId);
|
||||
if (!entry.isIntersecting && entry.boundingClientRect.width === 0) {
|
||||
timeoutId = setTimeout(retestIntersection, 10);
|
||||
}
|
||||
};
|
||||
}, [rive]);
|
||||
if (canvasElem && options.shouldUseIntersectionObserver !== false) {
|
||||
observe(canvasElem, onChange);
|
||||
}
|
||||
return () => {
|
||||
if (canvasElem) {
|
||||
unobserve(canvasElem);
|
||||
}
|
||||
};
|
||||
}, [
|
||||
observe,
|
||||
unobserve,
|
||||
rive,
|
||||
canvasElem,
|
||||
options.shouldUseIntersectionObserver,
|
||||
]);
|
||||
|
||||
/**
|
||||
* On unmount, stop rive from rendering.
|
||||
* On unmount, call cleanup to cleanup any WASM generated objects that need
|
||||
* to be manually destroyed.
|
||||
*/
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (rive) {
|
||||
rive.stop();
|
||||
rive.cleanup();
|
||||
setRive(null);
|
||||
}
|
||||
};
|
||||
}, [rive]);
|
||||
}, [rive, canvasElem]);
|
||||
|
||||
/**
|
||||
* Listen for changes in the animations params
|
||||
@@ -253,11 +263,12 @@ export default function useRive(
|
||||
/>
|
||||
);
|
||||
},
|
||||
[]
|
||||
[setCanvasRef, setContainerRef]
|
||||
);
|
||||
|
||||
return {
|
||||
canvas: canvasRef.current,
|
||||
canvas: canvasElem,
|
||||
container: containerRef.current,
|
||||
setCanvasRef,
|
||||
setContainerRef,
|
||||
rive,
|
||||
|
||||
57
src/hooks/useRiveFile.ts
Normal file
57
src/hooks/useRiveFile.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import type {
|
||||
UseRiveFileParameters,
|
||||
RiveFileState,
|
||||
FileStatus,
|
||||
} from '../types';
|
||||
import { EventType, RiveFile } from '@rive-app/canvas';
|
||||
|
||||
/**
|
||||
* Custom hook for initializing and managing a RiveFile instance within a component.
|
||||
* It sets up a RiveFile based on provided source parameters (URL or ArrayBuffer) and ensures
|
||||
* proper cleanup to avoid memory leaks when the component unmounts or inputs change.
|
||||
*
|
||||
* @param params - Object containing parameters accepted by the Rive file in the @rive-app/canvas runtime,
|
||||
*
|
||||
* @returns {RiveFileState} Contains the active RiveFile instance (`riveFile`) and the loading status.
|
||||
*/
|
||||
function useRiveFile(params: UseRiveFileParameters): RiveFileState {
|
||||
const [riveFile, setRiveFile] = useState<RiveFile | null>(null);
|
||||
const [status, setStatus] = useState<FileStatus>('idle');
|
||||
|
||||
useEffect(() => {
|
||||
let file: RiveFile | null = null;
|
||||
|
||||
const loadRiveFile = async () => {
|
||||
try {
|
||||
setStatus('loading');
|
||||
file = new RiveFile(params);
|
||||
file.init();
|
||||
file.on(EventType.Load, () => {
|
||||
// We request an instance to add +1 to the referencesCount so it doesn't get destroyed
|
||||
// while this hook is active
|
||||
file?.getInstance();
|
||||
setRiveFile(file);
|
||||
setStatus('success');
|
||||
});
|
||||
file.on(EventType.LoadError, () => {
|
||||
setStatus('failed');
|
||||
});
|
||||
setRiveFile(file);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
setStatus('failed');
|
||||
}
|
||||
};
|
||||
|
||||
loadRiveFile();
|
||||
|
||||
return () => {
|
||||
file?.cleanup();
|
||||
};
|
||||
}, [params.src, params.buffer]);
|
||||
|
||||
return { riveFile, status };
|
||||
}
|
||||
|
||||
export default useRiveFile;
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Rive, StateMachineInput } from '@rive-app/canvas';
|
||||
import { EventType, Rive, StateMachineInput } from '@rive-app/canvas';
|
||||
|
||||
/**
|
||||
* Custom hook for fetching a stateMachine input from a rive file.
|
||||
@@ -18,21 +18,33 @@ export default function useStateMachineInput(
|
||||
const [input, setInput] = useState<StateMachineInput | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!rive || !stateMachineName || !inputName) {
|
||||
setInput(null);
|
||||
}
|
||||
|
||||
if (rive && stateMachineName && inputName) {
|
||||
const inputs = rive.stateMachineInputs(stateMachineName);
|
||||
if (inputs) {
|
||||
const selectedInput = inputs.find((input) => input.name === inputName);
|
||||
if (initialValue !== undefined && selectedInput) {
|
||||
selectedInput.value = initialValue;
|
||||
}
|
||||
setInput(selectedInput || null);
|
||||
function setStateMachineInput() {
|
||||
if (!rive || !stateMachineName || !inputName) {
|
||||
setInput(null);
|
||||
}
|
||||
} else {
|
||||
setInput(null);
|
||||
|
||||
if (rive && stateMachineName && inputName) {
|
||||
const inputs = rive.stateMachineInputs(stateMachineName);
|
||||
if (inputs) {
|
||||
const selectedInput = inputs.find(
|
||||
(input) => input.name === inputName
|
||||
);
|
||||
if (initialValue !== undefined && selectedInput) {
|
||||
selectedInput.value = initialValue;
|
||||
}
|
||||
setInput(selectedInput || null);
|
||||
}
|
||||
} else {
|
||||
setInput(null);
|
||||
}
|
||||
}
|
||||
setStateMachineInput();
|
||||
if (rive) {
|
||||
rive.on(EventType.Load, () => {
|
||||
// Check if the component/canvas is mounted before setting state to avoid setState
|
||||
// on an unmounted component in some rare cases
|
||||
setStateMachineInput();
|
||||
});
|
||||
}
|
||||
}, [rive]);
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import Rive from './components/Rive';
|
||||
import Rive, { RiveProps } from './components/Rive';
|
||||
import useRive from './hooks/useRive';
|
||||
import useStateMachineInput from './hooks/useStateMachineInput';
|
||||
import useResizeCanvas from './hooks/useResizeCanvas';
|
||||
import useRiveFile from './hooks/useRiveFile';
|
||||
|
||||
export default Rive;
|
||||
export { useRive, useStateMachineInput };
|
||||
export { RiveState, UseRiveParameters, UseRiveOptions } from './types';
|
||||
export { useRive, useStateMachineInput, useResizeCanvas, useRiveFile , RiveProps };
|
||||
export { RiveState, UseRiveParameters, UseRiveFileParameters, UseRiveOptions } from './types';
|
||||
export * from '@rive-app/canvas';
|
||||
|
||||
36
src/types.ts
36
src/types.ts
@@ -1,12 +1,20 @@
|
||||
import { RefCallback, ComponentProps } from 'react';
|
||||
import { Rive, RiveParameters } from '@rive-app/canvas';
|
||||
import {
|
||||
Rive,
|
||||
RiveFile,
|
||||
RiveFileParameters,
|
||||
RiveParameters,
|
||||
} from '@rive-app/canvas';
|
||||
import { ComponentProps, RefCallback } from 'react';
|
||||
|
||||
export type UseRiveParameters = Partial<Omit<RiveParameters, 'canvas'>> | null;
|
||||
|
||||
export type UseRiveOptions = {
|
||||
useDevicePixelRatio: boolean;
|
||||
customDevicePixelRatio: number;
|
||||
fitCanvasToArtboardHeight: boolean;
|
||||
useOffscreenRenderer: boolean;
|
||||
shouldResizeCanvasToContainer: boolean;
|
||||
shouldUseIntersectionObserver?: boolean;
|
||||
};
|
||||
|
||||
export type Dimensions = {
|
||||
@@ -17,17 +25,35 @@ export type Dimensions = {
|
||||
/**
|
||||
* @typedef RiveState
|
||||
* @property canvas - Canvas element the Rive Animation is attached to.
|
||||
* @property container - Container element of the canvas.
|
||||
* @property setCanvasRef - Ref callback to be passed to the canvas element.
|
||||
* @property setContainerRef - Ref callback to be passed to the container element
|
||||
* of the canvas. This is optional, however if not used then the hook will
|
||||
* not take care of automatically resizing the canvas to it's outer
|
||||
* @property setContainerRef - Ref callback to be passed to the container
|
||||
* element of the canvas. This is optional, however if not used then the hook
|
||||
* will not take care of automatically resizing the canvas to it's outer
|
||||
* container if the window resizes.
|
||||
* @property rive - The loaded Rive Animation
|
||||
*/
|
||||
export type RiveState = {
|
||||
canvas: HTMLCanvasElement | null;
|
||||
container: HTMLElement | null;
|
||||
setCanvasRef: RefCallback<HTMLCanvasElement>;
|
||||
setContainerRef: RefCallback<HTMLElement>;
|
||||
rive: Rive | null;
|
||||
RiveComponent: (props: ComponentProps<'canvas'>) => JSX.Element;
|
||||
};
|
||||
|
||||
export type UseRiveFileParameters = Partial<
|
||||
Omit<RiveFileParameters, 'onLoad' | 'onLoadError'>
|
||||
>;
|
||||
|
||||
export type FileStatus = 'idle' | 'loading' | 'failed' | 'success';
|
||||
|
||||
/**
|
||||
* @typedef RiveFileState
|
||||
* @property data - The RiveFile instance
|
||||
* @property status - The status of the file
|
||||
*/
|
||||
export type RiveFileState = {
|
||||
riveFile: RiveFile | null;
|
||||
status: FileStatus;
|
||||
};
|
||||
|
||||
30
src/utils.ts
30
src/utils.ts
@@ -1,24 +1,12 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Dimensions } from './types';
|
||||
import { UseRiveOptions } from './types';
|
||||
|
||||
export function useWindowSize() {
|
||||
const [windowSize, setWindowSize] = useState<Dimensions>({
|
||||
width: 0,
|
||||
height: 0,
|
||||
});
|
||||
const defaultOptions = {
|
||||
useDevicePixelRatio: true,
|
||||
fitCanvasToArtboardHeight: false,
|
||||
useOffscreenRenderer: true,
|
||||
shouldResizeCanvasToContainer: true,
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
const handleResize = () => {
|
||||
setWindowSize({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
};
|
||||
window.addEventListener('resize', handleResize);
|
||||
handleResize();
|
||||
return () => window.removeEventListener('resize', handleResize);
|
||||
}
|
||||
}, []);
|
||||
return windowSize;
|
||||
export function getOptions(opts: Partial<UseRiveOptions>) {
|
||||
return Object.assign({}, defaultOptions, opts);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import RiveComponent from '../src/components/Rive';
|
||||
import {render} from '@testing-library/react'
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
jest.mock('@rive-app/canvas', () => ({
|
||||
Rive: jest.fn().mockImplementation(() => ({
|
||||
@@ -26,8 +26,29 @@ jest.mock('@rive-app/canvas', () => ({
|
||||
|
||||
describe('Rive Component', () => {
|
||||
it('renders the component as a canvas and a div wrapper', () => {
|
||||
const {container, getByLabelText} = render(<RiveComponent src="foo.riv" className="container-styles" aria-label="Foo label" />);
|
||||
const { container, getByLabelText } = render(
|
||||
<RiveComponent
|
||||
src="foo.riv"
|
||||
className="container-styles"
|
||||
aria-label="Foo label"
|
||||
/>
|
||||
);
|
||||
expect(container.firstChild).toHaveClass('container-styles');
|
||||
expect(getByLabelText('Foo label').tagName).toEqual('CANVAS');
|
||||
});
|
||||
|
||||
it('allows children to render in the canvas body', () => {
|
||||
const accessibleFallbackText = 'An animated test';
|
||||
const { getByText } = render(
|
||||
<RiveComponent
|
||||
src="foo.riv"
|
||||
className="container-styles"
|
||||
aria-label="Foo label"
|
||||
>
|
||||
<p>{accessibleFallbackText}</p>
|
||||
</RiveComponent>
|
||||
);
|
||||
|
||||
expect(getByText(accessibleFallbackText)).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
39
test/elementObserver.test.tsx
Normal file
39
test/elementObserver.test.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
// TODO move this
|
||||
const observe = jest.fn();
|
||||
const unobserve = jest.fn();
|
||||
const disconnect = jest.fn();
|
||||
|
||||
jest.spyOn(globalThis, 'IntersectionObserver').mockImplementation(() => {
|
||||
return {
|
||||
observe,
|
||||
unobserve,
|
||||
disconnect,
|
||||
root: null,
|
||||
thresholds: [],
|
||||
rootMargin: '',
|
||||
takeRecords: () => [],
|
||||
};
|
||||
});
|
||||
|
||||
import ElementObserver from '../src/hooks/elementObserver';
|
||||
|
||||
describe('elementObserver', () => {
|
||||
it('registers a callback and observes the element', () => {
|
||||
const observer = new ElementObserver();
|
||||
const element = document.createElement('li');
|
||||
observer.registerCallback(element, ()=>{});
|
||||
expect(observe).toHaveBeenCalled();
|
||||
expect(observe).toHaveBeenCalledWith(element);
|
||||
});
|
||||
|
||||
it('unregisters a callback and unobserves the element', () => {
|
||||
const observer = new ElementObserver();
|
||||
const element = document.createElement('li');
|
||||
observer.removeCallback(element);
|
||||
expect(unobserve).toHaveBeenCalled();
|
||||
expect(unobserve).toHaveBeenCalledWith(element);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
jest.clearAllMocks();
|
||||
42
test/useIntersectionObserver.test.tsx
Normal file
42
test/useIntersectionObserver.test.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { renderHook, act } from '@testing-library/react-hooks';
|
||||
import ElementObserver from '../src/hooks/elementObserver';
|
||||
jest.mock('../src/hooks/elementObserver');
|
||||
|
||||
import useIntersectionObserver from '../src/hooks/useIntersectionObserver';
|
||||
|
||||
describe('useIntersectionObserver', () => {
|
||||
it('returns an object on initialization', () => {
|
||||
const { result } = renderHook(() => useIntersectionObserver());
|
||||
expect(result.current).toBeDefined();
|
||||
});
|
||||
|
||||
it('registers a callback', () => {
|
||||
const { result } = renderHook(() => useIntersectionObserver());
|
||||
const element = document.createElement('li');
|
||||
const callback = () => {};
|
||||
act(() => {
|
||||
result.current.observe(element, callback);
|
||||
});
|
||||
const mockElementObserver = (ElementObserver as jest.Mock).mock
|
||||
.instances[0];
|
||||
const registerCallback = mockElementObserver.registerCallback;
|
||||
expect(registerCallback.mock.calls.length).toBe(1);
|
||||
expect(registerCallback.mock.calls[0].length).toBe(2);
|
||||
expect(registerCallback.mock.calls[0][0]).toBe(element);
|
||||
expect(registerCallback.mock.calls[0][1]).toBe(callback);
|
||||
});
|
||||
|
||||
it('unregisters a callback', () => {
|
||||
const { result } = renderHook(() => useIntersectionObserver());
|
||||
const element = document.createElement('li');
|
||||
act(() => {
|
||||
result.current.unobserve(element);
|
||||
});
|
||||
const mockElementObserver = (ElementObserver as jest.Mock).mock
|
||||
.instances[0];
|
||||
const removeCallback = mockElementObserver.removeCallback;
|
||||
expect(removeCallback.mock.calls.length).toBe(1);
|
||||
expect(removeCallback.mock.calls[0].length).toBe(1);
|
||||
expect(removeCallback.mock.calls[0][0]).toBe(element);
|
||||
});
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import { renderHook, act } from '@testing-library/react-hooks';
|
||||
|
||||
import useRive from '../src/hooks/useRive';
|
||||
import * as rive from '@rive-app/canvas';
|
||||
import { render } from '@testing-library/react';
|
||||
import { render, waitFor } from '@testing-library/react';
|
||||
|
||||
jest.mock('@rive-app/canvas', () => ({
|
||||
Rive: jest.fn().mockImplementation(() => ({
|
||||
@@ -29,6 +29,23 @@ jest.mock('@rive-app/canvas', () => ({
|
||||
}));
|
||||
|
||||
describe('useRive', () => {
|
||||
let controlledRiveloadCb: () => void;
|
||||
let baseRiveMock: Partial<rive.Rive>;
|
||||
|
||||
beforeEach(() => {
|
||||
baseRiveMock = {
|
||||
on: (_: rive.EventType, cb: rive.EventCallback) =>
|
||||
((controlledRiveloadCb as rive.EventCallback) = cb),
|
||||
stop: jest.fn(),
|
||||
stopRendering: jest.fn(),
|
||||
startRendering: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
controlledRiveloadCb = () => {};
|
||||
});
|
||||
|
||||
it('returns rive as null if no params are passed', () => {
|
||||
const { result } = renderHook(() => useRive());
|
||||
expect(result.current.rive).toBe(null);
|
||||
@@ -40,14 +57,8 @@ describe('useRive', () => {
|
||||
src: 'file-src',
|
||||
};
|
||||
|
||||
const riveMock = {
|
||||
on: (_: string, cb: () => void) => cb(),
|
||||
stop: jest.fn(),
|
||||
stopRendering: jest.fn(),
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
mocked(rive.Rive).mockImplementation(() => riveMock);
|
||||
mocked(rive.Rive).mockImplementation(() => baseRiveMock);
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
const { result } = renderHook(() => useRive(params));
|
||||
@@ -55,8 +66,13 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
|
||||
expect(result.current.rive).toBe(riveMock);
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
expect(result.current.rive).toBe(baseRiveMock);
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
|
||||
@@ -68,9 +84,7 @@ describe('useRive', () => {
|
||||
const resizeToCanvasMock = jest.fn();
|
||||
|
||||
const riveMock = {
|
||||
on: (_: string, cb: () => void) => cb(),
|
||||
stop: jest.fn(),
|
||||
stopRendering: jest.fn(),
|
||||
...baseRiveMock,
|
||||
resizeToCanvas: resizeToCanvasMock,
|
||||
};
|
||||
|
||||
@@ -85,6 +99,17 @@ describe('useRive', () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
await act(async () => {
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(500);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(500);
|
||||
containerSpy.dispatchEvent(new Event('resize'));
|
||||
});
|
||||
|
||||
expect(result.current.rive).toBe(riveMock);
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
@@ -92,16 +117,16 @@ describe('useRive', () => {
|
||||
expect(resizeToCanvasMock).toBeCalled();
|
||||
});
|
||||
|
||||
it('stops the rive object on unmount', async () => {
|
||||
it('calls cleanup on the rive object on unmount', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
};
|
||||
|
||||
const stopMock = jest.fn();
|
||||
const cleanupMock = jest.fn();
|
||||
|
||||
const riveMock = {
|
||||
on: (_: string, cb: () => void) => cb(),
|
||||
stop: stopMock,
|
||||
...baseRiveMock,
|
||||
cleanup: cleanupMock,
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
@@ -113,33 +138,32 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
unmount();
|
||||
|
||||
expect(stopMock).toBeCalled();
|
||||
expect(cleanupMock).toBeCalled();
|
||||
});
|
||||
|
||||
it('sets the a bounds with the devicePixelRatio by default', async () => {
|
||||
it('sets the bounds with the devicePixelRatio by default', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
};
|
||||
|
||||
global.devicePixelRatio = 2;
|
||||
|
||||
const riveMock = {
|
||||
on: (_: string, cb: () => void) => cb(),
|
||||
stop: jest.fn(),
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
mocked(rive.Rive).mockImplementation(() => riveMock);
|
||||
mocked(rive.Rive).mockImplementation(() => baseRiveMock);
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
const containerSpy = document.createElement('div');
|
||||
containerSpy.getBoundingClientRect = jest.fn().mockImplementation(() => ({
|
||||
width: 100,
|
||||
height: 100,
|
||||
}));
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(100);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(100);
|
||||
|
||||
const { result } = renderHook(() => useRive(params));
|
||||
|
||||
@@ -147,6 +171,12 @@ describe('useRive', () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
// Height and width should be 2* the width and height returned from containers
|
||||
// bounding rect
|
||||
@@ -158,6 +188,46 @@ describe('useRive', () => {
|
||||
expect(canvasSpy).toHaveAttribute('style', 'width: 100px; height: 100px;');
|
||||
});
|
||||
|
||||
it('sets the bounds with a specified customDevicePixelRatio if one is set', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
};
|
||||
|
||||
global.devicePixelRatio = 2;
|
||||
|
||||
// @ts-ignore
|
||||
mocked(rive.Rive).mockImplementation(() => baseRiveMock);
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
const containerSpy = document.createElement('div');
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(100);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(100);
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useRive(params, { customDevicePixelRatio: 1 })
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
// Height and width should be 2* the width and height returned from containers
|
||||
// bounding rect
|
||||
expect(canvasSpy).toHaveAttribute('height', '100');
|
||||
expect(canvasSpy).toHaveAttribute('width', '100');
|
||||
|
||||
// Style height and width should be the same as returned from containers
|
||||
// bounding rect
|
||||
expect(canvasSpy).toHaveAttribute('style', 'width: 100px; height: 100px;');
|
||||
});
|
||||
|
||||
it('sets the a bounds without the devicePixelRatio if useDevicePixelRatio is false', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
@@ -166,20 +236,13 @@ describe('useRive', () => {
|
||||
useDevicePixelRatio: false,
|
||||
};
|
||||
|
||||
const riveMock = {
|
||||
on: (_: string, cb: () => void) => cb(),
|
||||
stop: jest.fn(),
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
mocked(rive.Rive).mockImplementation(() => riveMock);
|
||||
mocked(rive.Rive).mockImplementation(() => baseRiveMock);
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
const containerSpy = document.createElement('div');
|
||||
containerSpy.getBoundingClientRect = jest.fn().mockImplementation(() => ({
|
||||
width: 100,
|
||||
height: 100,
|
||||
}));
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(100);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(100);
|
||||
|
||||
const { result } = renderHook(() => useRive(params, opts));
|
||||
|
||||
@@ -187,13 +250,19 @@ describe('useRive', () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
// Height and width should be same as containers bounding rect
|
||||
expect(canvasSpy).toHaveAttribute('height', '100');
|
||||
expect(canvasSpy).toHaveAttribute('width', '100');
|
||||
});
|
||||
|
||||
it('uses artbound height to set bounds if fitCanvasToArtboardHeight is true', async () => {
|
||||
it('uses artboard height to set bounds if fitCanvasToArtboardHeight is true', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
};
|
||||
@@ -203,8 +272,7 @@ describe('useRive', () => {
|
||||
};
|
||||
|
||||
const riveMock = {
|
||||
on: (_: string, cb: () => void) => cb(),
|
||||
stop: jest.fn(),
|
||||
...baseRiveMock,
|
||||
bounds: {
|
||||
maxX: 100,
|
||||
maxY: 50,
|
||||
@@ -216,10 +284,8 @@ describe('useRive', () => {
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
const containerSpy = document.createElement('div');
|
||||
containerSpy.getBoundingClientRect = jest.fn().mockImplementation(() => ({
|
||||
width: 100,
|
||||
height: 100,
|
||||
}));
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(100);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(100);
|
||||
|
||||
const { result } = renderHook(() => useRive(params, opts));
|
||||
|
||||
@@ -227,6 +293,12 @@ describe('useRive', () => {
|
||||
result.current.setContainerRef(containerSpy);
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
// Height and width should be same as containers bounding rect
|
||||
expect(canvasSpy).toHaveAttribute('height', '50');
|
||||
@@ -236,43 +308,6 @@ describe('useRive', () => {
|
||||
expect(containerSpy).toHaveAttribute('style', 'height: 50px;');
|
||||
});
|
||||
|
||||
it('configures a IntersectionObserver on mounting', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
};
|
||||
|
||||
const observeMock = jest.fn();
|
||||
|
||||
const restore = global.IntersectionObserver;
|
||||
global.IntersectionObserver = jest.fn().mockImplementation(() => ({
|
||||
observe: observeMock,
|
||||
}));
|
||||
|
||||
const riveMock = {
|
||||
on: (_: string, cb: () => void) => cb(),
|
||||
stop: jest.fn(),
|
||||
bounds: {
|
||||
maxX: 100,
|
||||
maxY: 50,
|
||||
},
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
mocked(rive.Rive).mockImplementation(() => riveMock);
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
|
||||
const { result } = renderHook(() => useRive(params));
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
|
||||
expect(observeMock).toBeCalledWith(canvasSpy);
|
||||
|
||||
global.IntersectionObserver = restore;
|
||||
});
|
||||
|
||||
it('updates the playing animations when the animations param changes', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
@@ -283,7 +318,7 @@ describe('useRive', () => {
|
||||
const stopMock = jest.fn();
|
||||
|
||||
const riveMock = {
|
||||
on: (_: string, cb: () => void) => cb(),
|
||||
...baseRiveMock,
|
||||
stop: stopMock,
|
||||
play: playMock,
|
||||
animationNames: ['light'],
|
||||
@@ -302,6 +337,12 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
rerender({
|
||||
src: 'file-src',
|
||||
@@ -323,7 +364,7 @@ describe('useRive', () => {
|
||||
const stopMock = jest.fn();
|
||||
|
||||
const riveMock = {
|
||||
on: (_: string, cb: () => void) => cb(),
|
||||
...baseRiveMock,
|
||||
stop: stopMock,
|
||||
play: playMock,
|
||||
pause: pauseMock,
|
||||
@@ -344,6 +385,12 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
rerender({
|
||||
src: 'file-src',
|
||||
@@ -360,14 +407,8 @@ describe('useRive', () => {
|
||||
src: 'file-src',
|
||||
};
|
||||
|
||||
const riveMock = {
|
||||
on: (_: string, cb: () => void) => cb(),
|
||||
stop: jest.fn(),
|
||||
stopRendering: jest.fn(),
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
mocked(rive.Rive).mockImplementation(() => riveMock);
|
||||
mocked(rive.Rive).mockImplementation(() => baseRiveMock);
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
const { result } = renderHook(() => useRive(params));
|
||||
@@ -375,6 +416,12 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
const { RiveComponent: RiveTestComponent } = result.current;
|
||||
const { container } = render(
|
||||
@@ -382,4 +429,142 @@ describe('useRive', () => {
|
||||
);
|
||||
expect(container.firstChild).not.toHaveStyle('width: 50%');
|
||||
});
|
||||
|
||||
it('has a canvas size of 0 by default', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
mocked(rive.Rive).mockImplementation(() => baseRiveMock);
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
const { result } = renderHook(() => useRive(params));
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
const { RiveComponent: RiveTestComponent } = result.current;
|
||||
const { container } = render(<RiveTestComponent />);
|
||||
expect(container.querySelector('canvas')).toHaveStyle('width: 0');
|
||||
});
|
||||
|
||||
it('sets the canvas width and height after calculating the container size', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
};
|
||||
|
||||
global.devicePixelRatio = 2;
|
||||
|
||||
// @ts-ignore
|
||||
mocked(rive.Rive).mockImplementation(() => baseRiveMock);
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
const containerSpy = document.createElement('div');
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(100);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(100);
|
||||
|
||||
const { result } = renderHook(() => useRive(params));
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
expect(canvasSpy).toHaveStyle('height: 100px');
|
||||
expect(canvasSpy).toHaveStyle('width: 100px');
|
||||
});
|
||||
|
||||
it('updates the canvas dimensions and size if there is a new canvas size calculation', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
};
|
||||
|
||||
window.devicePixelRatio = 2;
|
||||
|
||||
// @ts-ignore
|
||||
mocked(rive.Rive).mockImplementation(() => baseRiveMock);
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
const containerSpy = document.createElement('div');
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(100);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(100);
|
||||
|
||||
const { result } = renderHook(() => useRive(params));
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(200);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(200);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
containerSpy.dispatchEvent(new Event('resize'));
|
||||
});
|
||||
|
||||
expect(canvasSpy).toHaveAttribute('width', '400');
|
||||
expect(canvasSpy).toHaveAttribute('height', '400');
|
||||
});
|
||||
|
||||
it('prevents resizing if shouldResizeCanvasToContainer option is false', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
};
|
||||
const options = {
|
||||
shouldResizeCanvasToContainer: false,
|
||||
};
|
||||
|
||||
window.devicePixelRatio = 2;
|
||||
|
||||
// @ts-ignore
|
||||
mocked(rive.Rive).mockImplementation(() => baseRiveMock);
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
canvasSpy.width = 200;
|
||||
canvasSpy.height = 200;
|
||||
const containerSpy = document.createElement('div');
|
||||
|
||||
const { result } = renderHook(() => useRive(params, options));
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(500);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(500);
|
||||
containerSpy.dispatchEvent(new Event('resize'));
|
||||
});
|
||||
|
||||
expect(canvasSpy.width).toBe(200);
|
||||
expect(canvasSpy.height).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
142
test/useRiveFile.test.tsx
Normal file
142
test/useRiveFile.test.tsx
Normal file
@@ -0,0 +1,142 @@
|
||||
import { renderHook } from '@testing-library/react-hooks';
|
||||
import { mocked } from 'jest-mock';
|
||||
|
||||
import useRiveFile from '../src/hooks/useRiveFile';
|
||||
import { RiveFile } from '@rive-app/canvas';
|
||||
|
||||
jest.mock('@rive-app/canvas', () => ({
|
||||
RiveFile: jest.fn().mockImplementation(() => ({
|
||||
cleanup: jest.fn(),
|
||||
on: jest.fn(),
|
||||
init: jest.fn(),
|
||||
getInstance: jest.fn(),
|
||||
})),
|
||||
EventType: {
|
||||
Load: 'load',
|
||||
loadError: 'loadError',
|
||||
},
|
||||
}));
|
||||
|
||||
|
||||
describe('useRiveFile', () => {
|
||||
beforeEach(() => {
|
||||
mocked(RiveFile).mockClear();
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('initializes RiveFile with provided parameters', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { result } = renderHook(() => useRiveFile(params));
|
||||
|
||||
expect(RiveFile).toHaveBeenCalledWith(params);
|
||||
expect(result.current.riveFile).toBeDefined();
|
||||
});
|
||||
|
||||
it('cleans up RiveFile on unmount', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { result, unmount } = renderHook(() => useRiveFile(params));
|
||||
|
||||
const riveInstance = result.current.riveFile;
|
||||
expect(riveInstance).toBeDefined();
|
||||
|
||||
unmount();
|
||||
|
||||
expect(riveInstance?.cleanup).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not reinitialize RiveFile if src has not changed', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { rerender } = renderHook(() => useRiveFile(params));
|
||||
|
||||
rerender();
|
||||
|
||||
expect(RiveFile).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('does not reinitialize RiveFile if buffer has not changed', async () => {
|
||||
const params = {
|
||||
buffer: new ArrayBuffer(10),
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { rerender } = renderHook(() => useRiveFile(params));
|
||||
|
||||
rerender();
|
||||
|
||||
expect(RiveFile).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('reinitializes RiveFile if src changes', async () => {
|
||||
let params = {
|
||||
src: 'file-src',
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { rerender } = renderHook(() => useRiveFile(params));
|
||||
|
||||
params = {
|
||||
src: 'new-file-src',
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
rerender();
|
||||
|
||||
expect(RiveFile).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('reinitializes RiveFile if buffer changes', async () => {
|
||||
let params = {
|
||||
buffer: new ArrayBuffer(10),
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { rerender } = renderHook(() => useRiveFile(params));
|
||||
|
||||
params = {
|
||||
buffer: new ArrayBuffer(20),
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
rerender();
|
||||
|
||||
expect(RiveFile).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('handles RiveFile initialization failure gracefully', async () => {
|
||||
|
||||
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
|
||||
const error = new Error("Initialization failed");
|
||||
|
||||
mocked(RiveFile).mockImplementation(() => {
|
||||
throw error;
|
||||
});
|
||||
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
enableRiveAssetCDN: false,
|
||||
};
|
||||
|
||||
const { result, rerender } = renderHook(() => useRiveFile(params));
|
||||
|
||||
rerender();
|
||||
|
||||
expect(result.current.status).toBe('failed');
|
||||
expect(result.current.riveFile).toBeNull();
|
||||
expect(consoleSpy).toHaveBeenCalledWith(error);
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
@@ -2,12 +2,13 @@ import { mocked } from 'jest-mock';
|
||||
import { renderHook } from '@testing-library/react-hooks';
|
||||
|
||||
import useStateMachineInput from '../src/hooks/useStateMachineInput';
|
||||
import {Rive, StateMachineInput} from '@rive-app/canvas';
|
||||
import { Rive, StateMachineInput } from '@rive-app/canvas';
|
||||
|
||||
jest.mock('@rive-app/canvas', () => ({
|
||||
Rive: jest.fn().mockImplementation(() => ({
|
||||
on: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
stateMachineInputs: jest.fn(),
|
||||
})),
|
||||
Layout: jest.fn(),
|
||||
Fit: {
|
||||
@@ -26,6 +27,21 @@ jest.mock('@rive-app/canvas', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
function getRiveMock({
|
||||
smiInputs,
|
||||
}: {
|
||||
smiInputs?: null | StateMachineInput[];
|
||||
} = {}) {
|
||||
const riveMock = new Rive({
|
||||
canvas: undefined as unknown as HTMLCanvasElement,
|
||||
});
|
||||
if (smiInputs) {
|
||||
riveMock.stateMachineInputs = jest.fn().mockReturnValue(smiInputs);
|
||||
}
|
||||
|
||||
return riveMock;
|
||||
}
|
||||
|
||||
describe('useStateMachineInput', () => {
|
||||
it('returns null if there is null rive object passed', () => {
|
||||
const { result } = renderHook(() => useStateMachineInput(null));
|
||||
@@ -33,29 +49,33 @@ describe('useStateMachineInput', () => {
|
||||
});
|
||||
|
||||
it('returns null if there is no state machine name', () => {
|
||||
const riveMock = {};
|
||||
mocked(Rive).mockImplementation(() => riveMock as Rive);
|
||||
const riveMock = getRiveMock();
|
||||
|
||||
const { result } = renderHook(() => useStateMachineInput(riveMock as Rive, '', 'testInput'));
|
||||
mocked(Rive).mockImplementation(() => riveMock);
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useStateMachineInput(riveMock, '', 'testInput')
|
||||
);
|
||||
expect(result.current).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null if there is no state machine input name', () => {
|
||||
const riveMock = {};
|
||||
mocked(Rive).mockImplementation(() => riveMock as Rive);
|
||||
const riveMock = getRiveMock();
|
||||
|
||||
const { result } = renderHook(() => useStateMachineInput(riveMock as Rive, 'smName', ''));
|
||||
const { result } = renderHook(() =>
|
||||
useStateMachineInput(riveMock, 'smName', '')
|
||||
);
|
||||
expect(result.current).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null if there are no inputs for the state machine', () => {
|
||||
const riveMock = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
stateMachineInputs: (_: string) => [] as StateMachineInput[],
|
||||
};
|
||||
mocked(Rive).mockImplementation(() => riveMock as Rive);
|
||||
const riveMock = getRiveMock({ smiInputs: [] });
|
||||
|
||||
const { result } = renderHook(() => useStateMachineInput(riveMock as Rive, 'smName', ''));
|
||||
mocked(Rive).mockImplementation(() => riveMock);
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useStateMachineInput(riveMock as Rive, 'smName', '')
|
||||
);
|
||||
expect(result.current).toBeNull();
|
||||
});
|
||||
|
||||
@@ -63,13 +83,13 @@ describe('useStateMachineInput', () => {
|
||||
const smInput = {
|
||||
name: 'boolInput',
|
||||
} as StateMachineInput;
|
||||
const riveMock = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
stateMachineInputs: (_: string) => [smInput] as StateMachineInput[],
|
||||
};
|
||||
mocked(Rive).mockImplementation(() => riveMock as Rive);
|
||||
const riveMock = getRiveMock({ smiInputs: [smInput] });
|
||||
|
||||
const { result } = renderHook(() => useStateMachineInput(riveMock as Rive, 'smName', 'numInput'));
|
||||
mocked(Rive).mockImplementation(() => riveMock);
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useStateMachineInput(riveMock, 'smName', 'numInput')
|
||||
);
|
||||
expect(result.current).toBeNull();
|
||||
});
|
||||
|
||||
@@ -77,13 +97,13 @@ describe('useStateMachineInput', () => {
|
||||
const smInput = {
|
||||
name: 'boolInput',
|
||||
} as StateMachineInput;
|
||||
const riveMock = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
stateMachineInputs: (_: string) => [smInput] as StateMachineInput[],
|
||||
};
|
||||
mocked(Rive).mockImplementation(() => riveMock as Rive);
|
||||
const riveMock = getRiveMock({ smiInputs: [smInput] });
|
||||
|
||||
const { result } = renderHook(() => useStateMachineInput(riveMock as Rive, 'smName', 'boolInput'));
|
||||
mocked(Rive).mockImplementation(() => riveMock);
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useStateMachineInput(riveMock, 'smName', 'boolInput')
|
||||
);
|
||||
expect(result.current).toBe(smInput);
|
||||
});
|
||||
|
||||
@@ -92,13 +112,12 @@ describe('useStateMachineInput', () => {
|
||||
name: 'boolInput',
|
||||
value: false,
|
||||
} as StateMachineInput;
|
||||
const riveMock = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
stateMachineInputs: (_: string) => [smInput] as StateMachineInput[],
|
||||
};
|
||||
mocked(Rive).mockImplementation(() => riveMock as Rive);
|
||||
const riveMock = getRiveMock({ smiInputs: [smInput] });
|
||||
mocked(Rive).mockImplementation(() => riveMock);
|
||||
|
||||
const { result } = renderHook(() => useStateMachineInput(riveMock as Rive, 'smName', 'boolInput', true));
|
||||
const { result } = renderHook(() =>
|
||||
useStateMachineInput(riveMock, 'smName', 'boolInput', true)
|
||||
);
|
||||
expect(result.current).toStrictEqual({
|
||||
...smInput,
|
||||
value: true,
|
||||
|
||||
Reference in New Issue
Block a user