Skip to content

Commit

Permalink
Adding hover() (#2916)
Browse files Browse the repository at this point in the history
* Refactor to DOM package

* Refactor

* Latest

* v11.13.0-beta.0

* Skip check

* Fixing size measurement

* Latest

* Fixing publish command

* Latest

* Fixing test

* Fixing test

* Removing unused test

* Latest

* Adding playwright suite

* Updating docker image for playwright

* Updating

* Latest

* Adding config

* Running yarn install

* Attempting to install make

* Make bundlesize optional dep

* Fixing lockfile

* Replacing bundlesize

* Fixing

* Skip test on CI

* Adding hover
  • Loading branch information
mattgperry authored Dec 3, 2024
1 parent f12b84d commit d97b58f
Show file tree
Hide file tree
Showing 136 changed files with 1,069 additions and 936 deletions.
30 changes: 30 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,40 @@ jobs:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

test-playwright:
docker:
- image: mcr.microsoft.com/playwright:v1.49.0-noble
resource_class: large
working_directory: ~/repo
steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run:
name: Playwright tests
command: yarn && yarn test-playwright
environment:
JEST_JUNIT_OUTPUT: test_reports/framer-motion-playwright.xml

- store_test_results:
path: test_reports

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

workflows:
version: 2
build:
jobs:
- test
- test-react
- test-html
- test-playwright
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ yarn-error.log
.next
stats.html

lerna-debug.log
lerna-debug.log

playwright-report
test-results
test_results
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/bl-npm-4.1.0-7f94cdcf3f-9e8521fa7e.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/cache/fsevents-patch-3340e2eb10-8.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/nan-npm-2.20.0-5b5be83e88-eb09286e6c.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/rc-npm-1.2.8-d6768ac936-2e26e052f8.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ SOURCE_FILES := $(shell find packages/framer-motion/src packages/framer-motion-3
TEST_REPORT_PATH := $(if $(CIRCLE_TEST_REPORTS),$(CIRCLE_TEST_REPORTS),$(CURDIR)/test_reports)

build: bootstrap
cd packages/framer-motion && yarn build
cd packages/framer-motion-3d && yarn build
yarn build

watch: bootstrap
cd packages/framer-motion && yarn watch
Expand Down Expand Up @@ -92,6 +91,7 @@ test-nextjs: build test-mkdir
yarn start-server-and-test "yarn dev-server || true" http://localhost:3000 "cd packages/framer-motion && cypress run --headless --config-file=cypress.rsc.json $(if $(CI), --config video=false, --reporter spec)"

test-e2e: test-nextjs test-html test-react
yarn test-playwright

test-single: build test-mkdir
yarn start-server-and-test "yarn dev-server" http://localhost:9990 "cd packages/framer-motion && cypress run --headless --spec cypress/integration/scroll.ts"
Expand Down
4 changes: 4 additions & 0 deletions dev/html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"motion": "workspace:*",
"motion-dom": "workspace:*"
},
"devDependencies": {
"vite": "^5.2.0"
}
Expand Down
58 changes: 58 additions & 0 deletions dev/html/public/playwright/gestures/hover.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<html>
<head>
<style>
body {
margin: 0;
}

.box {
width: 100px;
height: 100px;
background-color: #0077ff;
}
</style>
</head>
<body>
<div class="box" id="hover">test</div>
<div class="box" id="multi">multi</div>
<div class="box" id="once">once</div>
<script type="module" src="/src/inc.js"></script>
<script type="module">
const { hover } = window.MotionDOM

hover("#hover", ({ currentTarget }) => {
currentTarget.innerHTML = "start"

return () => {
currentTarget.innerHTML = "end"
}
})

let multiCount = 0
hover("#multi", ({ currentTarget }) => {
currentTarget.innerHTML = multiCount
multiCount++

return () => {
currentTarget.innerHTML = multiCount
multiCount++
}
})

let onceCount = 0
hover(
"#once",
({ currentTarget }) => {
currentTarget.innerHTML = onceCount
onceCount++

return () => {
currentTarget.innerHTML = onceCount
onceCount++
}
},
{ once: true }
)
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions dev/html/src/inc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as MotionDOM from "motion-dom"

window.MotionDOM = MotionDOM
59 changes: 59 additions & 0 deletions dev/inc/bundlesize.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import fs from "fs"
import path from "path"

const packagePath = path.join(
process.cwd(),
"packages/framer-motion/package.json"
)
const pkg = JSON.parse(fs.readFileSync(packagePath, "utf8"))

if (!pkg.bundlesize) {
console.log("No bundlesize configuration found")
process.exit(0)
}

let hasFailures = false

pkg.bundlesize.forEach(async ({ path: filePath, maxSize }) => {
const fullPath = path.join(
process.cwd(),
"packages/framer-motion",
filePath
)

if (!fs.existsSync(fullPath)) {
console.error(`❌ File not found: ${filePath}`)
hasFailures = true
return
}

// Create gzipped version of file
const fileContent = fs.readFileSync(fullPath)
const gzipped = await import("zlib").then((zlib) => {
return new Promise((resolve, reject) => {
zlib.gzip(fileContent, (error, result) => {
if (error) reject(error)
else resolve(result)
})
})
})

const gzippedSize = gzipped.length
const maxBytes = parseFloat(maxSize) * 1024
const gzippedSizeKb = (gzippedSize / 1024).toFixed(2)

if (gzippedSize > maxBytes) {
console.error(
`❌ ${filePath} is ${gzippedSizeKb} kB (${maxSize} allowed)`
)
hasFailures = true
} else {
console.log(
`✅ ${filePath} is ${gzippedSizeKb} kB (${maxSize} allowed)`
)
}
})

if (hasFailures) {
process.exit(1)
}
4 changes: 2 additions & 2 deletions dev/next/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "next-env",
"private": true,
"version": "11.12.0",
"version": "11.13.0-beta.0",
"type": "module",
"scripts": {
"dev": "next dev",
"dev-server": "next dev",
"start": "next start"
},
"dependencies": {
"framer-motion": "^11.12.0",
"framer-motion": "^11.13.0-beta.0",
"next": "14.x",
"react": "^18.3.1",
"react-dom": "^18.3.1"
Expand Down
53 changes: 21 additions & 32 deletions dev/next/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
]
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
4 changes: 2 additions & 2 deletions dev/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-env",
"private": true,
"version": "11.12.0",
"version": "11.13.0-beta.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -11,7 +11,7 @@
"preview": "vite preview"
},
"dependencies": {
"framer-motion": "^11.12.0",
"framer-motion": "^11.13.0-beta.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
42 changes: 21 additions & 21 deletions dev/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "esnext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
18 changes: 9 additions & 9 deletions dev/react/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts"]
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "esnext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts"]
}
15 changes: 7 additions & 8 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"version": "11.12.0",
"packages": [
"packages/*",
"dev/*"
],
"npmClient": "yarn",
"useWorkspaces": true
}
"version": "11.13.0-beta.0",
"packages": [
"packages/*",
"dev/*"
],
"npmClient": "yarn"
}
Loading

0 comments on commit d97b58f

Please sign in to comment.