Skip to content

Commit

Permalink
$npm_package_name@$npm_package_version
Browse files Browse the repository at this point in the history
  • Loading branch information
clementroche committed Dec 27, 2023
1 parent 1e38d47 commit f625bf5
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 44 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[![LENIS](https://assets.studiofreight.com/lenis/header.png)](https://github.com/studio-freight/lenis)

[![npm version](https://img.shields.io/badge/dynamic/json?color=blue&label=npm&prefix=v&query=version&suffix=%20&url=https%3A%2F%2Fraw.githubusercontent.com%2Fstudio-freight%2Flenis%2Fmain%2Fpackage.json)](https://www.npmjs.com/package/@studio-freight/lenis)
[![size](https://img.shields.io/bundlephobia/minzip/@studio-freight/lenis?label=bundle)](https://bundlephobia.com/package/@studio-freight/lenis)
[![npm version](https://img.shields.io/badge/dynamic/json?color=blue&label=npm&prefix=v&query=version&suffix=%20&url=https://raw.githubusercontent.com/studio-freight/lenis/main/packages/lenis/package.json)](https://www.npmjs.com/package/@studio-freight/lenis)
[![download](https://img.shields.io/npm/dm/%40studio-freight%2Flenis
)](https://www.npmjs.com/package/@studio-freight/lenis)
[![gzip](https://img.shields.io/bundlephobia/minzip/@studio-freight/lenis?label=size)](https://bundlephobia.com/package/@studio-freight/lenis)

## Introduction

Expand Down
2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.cjs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.umd.js.map

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions packages/lenis/dist/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default class Lenis {
constructor({ wrapper, content, wheelEventsTarget, eventsTarget, smoothWheel, smoothTouch, syncTouch, syncTouchLerp, __iosNoInertiaSyncTouchLerp, touchInertiaMultiplier, duration, easing, lerp, infinite, orientation, gestureOrientation, touchMultiplier, wheelMultiplier, normalizeWheel, autoResize, }?: {
constructor({ wrapper, content, wheelEventsTarget, eventsTarget, smoothWheel, smoothTouch, syncTouch, syncTouchLerp, touchInertiaMultiplier, duration, easing, lerp, infinite, orientation, gestureOrientation, touchMultiplier, wheelMultiplier, normalizeWheel, autoResize, }?: {
wrapper?: Window | HTMLElement;
content?: HTMLElement;
wheelEventsTarget?: Window | HTMLElement;
Expand All @@ -8,7 +8,6 @@ export default class Lenis {
smoothTouch?: boolean;
syncTouch?: boolean;
syncTouchLerp?: number;
__iosNoInertiaSyncTouchLerp?: number;
touchInertiaMultiplier?: number;
duration?: number;
easing?: (t: number) => number;
Expand All @@ -30,7 +29,6 @@ export default class Lenis {
smoothTouch: boolean;
syncTouch: boolean;
syncTouchLerp: number;
__iosNoInertiaSyncTouchLerp: number;
touchInertiaMultiplier: number;
duration: number;
easing: (t: number) => number;
Expand Down
174 changes: 174 additions & 0 deletions packages/lenis/playground/jank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
;(function (window) {
'use strict'

const html = `
<img class="proto mover" src="/javascript.svg"/>
<div class="controls">
<button class="add"></button>
<button class="subtract" disabled></button>
<button class="stop">Stop</button>
<button class="optimize">Optimize</button>
<a href="https://developers.google.com/web/tools/chrome-devtools/evaluate-performance/"
target="_blank">
<button class="optimize">Help</button>
</a>
</div>
`

document.body.insertAdjacentHTML('beforeend', html)

var app = {},
proto = document.querySelector('.proto'),
movers,
bodySize = document.body.getBoundingClientRect(),
ballSize = proto.getBoundingClientRect(),
maxHeight = Math.floor(bodySize.height - ballSize.height),
maxWidth = 97, // 100vw - width of square (3vw)
incrementor = 10,
distance = 3,
frame,
minimum = 10,
subtract = document.querySelector('.subtract'),
add = document.querySelector('.add')

app.optimize = false
app.count = minimum
app.enableApp = true

app.init = function () {
if (movers) {
bodySize = document.body.getBoundingClientRect()
for (var i = 0; i < movers.length; i++) {
document.body.removeChild(movers[i])
}
document.body.appendChild(proto)
ballSize = proto.getBoundingClientRect()
document.body.removeChild(proto)
maxHeight = Math.floor(bodySize.height - ballSize.height)
}
for (var i = 0; i < app.count; i++) {
var m = proto.cloneNode()
var top = Math.floor(Math.random() * maxHeight)
if (top === maxHeight) {
m.classList.add('up')
} else {
m.classList.add('down')
}
m.style.left = i / (app.count / maxWidth) + 'vw'
m.style.top = top + 'px'
document.body.appendChild(m)
}
movers = document.querySelectorAll('.mover')
}

app.update = function (timestamp) {
for (var i = 0; i < app.count; i++) {
var m = movers[i]
if (!app.optimize) {
var pos = m.classList.contains('down')
? m.offsetTop + distance
: m.offsetTop - distance
if (pos < 0) pos = 0
if (pos > maxHeight) pos = maxHeight
m.style.top = pos + 'px'
if (m.offsetTop === 0) {
m.classList.remove('up')
m.classList.add('down')
}
if (m.offsetTop === maxHeight) {
m.classList.remove('down')
m.classList.add('up')
}
} else {
var pos = parseInt(m.style.top.slice(0, m.style.top.indexOf('px')))
m.classList.contains('down') ? (pos += distance) : (pos -= distance)
if (pos < 0) pos = 0
if (pos > maxHeight) pos = maxHeight
m.style.top = pos + 'px'
if (pos === 0) {
m.classList.remove('up')
m.classList.add('down')
}
if (pos === maxHeight) {
m.classList.remove('down')
m.classList.add('up')
}
}
}
frame = window.requestAnimationFrame(app.update)
}

document.querySelector('.stop').addEventListener('click', function (e) {
if (app.enableApp) {
cancelAnimationFrame(frame)
e.target.textContent = 'Start'
app.enableApp = false
} else {
frame = window.requestAnimationFrame(app.update)
e.target.textContent = 'Stop'
app.enableApp = true
}
})

document.querySelector('.optimize').addEventListener('click', function (e) {
if (e.target.textContent === 'Optimize') {
app.optimize = true
e.target.textContent = 'Un-Optimize'
} else {
app.optimize = false
e.target.textContent = 'Optimize'
}
})

add.addEventListener('click', function (e) {
cancelAnimationFrame(frame)
app.count += incrementor
subtract.disabled = false
app.init()
frame = requestAnimationFrame(app.update)
})

subtract.addEventListener('click', function () {
cancelAnimationFrame(frame)
app.count -= incrementor
app.init()
frame = requestAnimationFrame(app.update)
if (app.count === minimum) {
subtract.disabled = true
}
})

function debounce(func, wait, immediate) {
var timeout
return function () {
var context = this,
args = arguments
var later = function () {
timeout = null
if (!immediate) func.apply(context, args)
}
var callNow = immediate && !timeout
clearTimeout(timeout)
timeout = setTimeout(later, wait)
if (callNow) func.apply(context, args)
}
}

var onResize = debounce(function () {
if (app.enableApp) {
cancelAnimationFrame(frame)
app.init()
frame = requestAnimationFrame(app.update)
}
}, 500)

window.addEventListener('resize', onResize)

add.textContent = 'Add ' + incrementor
subtract.textContent = 'Subtract ' + incrementor
document.body.removeChild(proto)
proto.classList.remove('.proto')
app.init()
window.app = app
frame = window.requestAnimationFrame(app.update)
})(window)
76 changes: 68 additions & 8 deletions packages/lenis/playground/main.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,80 @@
import "./style.css"
import javascriptLogo from "./javascript.svg"
import viteLogo from "/vite.svg"
import { setupCounter } from "./counter.js"
import Lenis from "../dist/lenis.esm.js"
import Lenis from '../dist/lenis.esm.js'
import { setupCounter } from './counter.js'
// import './jank.js'
import javascriptLogo from './javascript.svg'
import './style.css'
import viteLogo from '/vite.svg'

const lenis = new Lenis()
const lenis = new Lenis({
smoothWheel: true,
syncTouch: true,
})

window.lenis = lenis

function update(deltaTime) {
lenis.raf(deltaTime)
requestAnimationFrame(update)

// console.log(window.scrollY, Math.floor(lenis.scroll))
// if (window.scrollY !== Math.floor(lenis.scroll)) {
// console.log('unsynced', window.scrollY, lenis.scroll)
// }

// console.log(window.scrollY, lenis.scroll)
}

requestAnimationFrame((deltaTime) => {
update(deltaTime)
})

document.querySelector("#app").innerHTML = `
document.querySelector('#app').innerHTML = `
<div>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="${viteLogo}" class="logo" alt="Vite logo" />
</a>
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank">
<img src="${javascriptLogo}" class="logo vanilla" alt="JavaScript logo" />
</a>
<h1>Hello Vite!</h1>
<div class="card">
<button id="counter" type="button"></button>
</div>
<p class="read-the-docs">
Click on the Vite logo to learn more
</p>
</div>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="${viteLogo}" class="logo" alt="Vite logo" />
</a>
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank">
<img src="${javascriptLogo}" class="logo vanilla" alt="JavaScript logo" />
</a>
<h1>Hello Vite!</h1>
<div class="card">
<button id="counter" type="button"></button>
</div>
<p class="read-the-docs">
Click on the Vite logo to learn more
</p>
</div>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="${viteLogo}" class="logo" alt="Vite logo" />
</a>
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank">
<img src="${javascriptLogo}" class="logo vanilla" alt="JavaScript logo" />
</a>
<h1>Hello Vite!</h1>
<div class="card">
<button id="counter" type="button"></button>
</div>
<p class="read-the-docs">
Click on the Vite logo to learn more
</p>
</div>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="${viteLogo}" class="logo" alt="Vite logo" />
Expand All @@ -31,6 +90,7 @@ document.querySelector("#app").innerHTML = `
Click on the Vite logo to learn more
</p>
</div>
</div>
`

setupCounter(document.querySelector("#counter"))
setupCounter(document.querySelector('#counter'))
2 changes: 1 addition & 1 deletion packages/lenis/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --host",
"build": "vite build",
"preview": "vite preview"
},
Expand Down
39 changes: 38 additions & 1 deletion packages/lenis/playground/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ body {
place-items: center;
min-width: 320px;
min-height: 100vh;
height: 300vh;
background-color: red;
}

h1 {
Expand All @@ -38,7 +40,7 @@ h1 {
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
/* padding: 2rem; */
text-align: center;
}

Expand Down Expand Up @@ -94,3 +96,38 @@ button:focus-visible {
background-color: #f9f9f9;
}
}

.controls {
position: fixed;
inset: 0;
z-index: 1;
}

.controls button {
display: block;
font-size: 1em;
padding: 1em;
margin: 1em;
background-color: beige;
color: black;
}

.subtract:disabled {
opacity: 0.2;
}

.mover {
height: 3vw;
position: absolute;
z-index: 0;
}

.border {
border: 1px solid black;
}

@media (max-width: 600px) {
.controls button {
min-width: 20vw;
}
}
Loading

0 comments on commit f625bf5

Please sign in to comment.