-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b15797
commit 40ea409
Showing
9 changed files
with
72 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,70 @@ | ||
interface Style { | ||
[key: string]: string; | ||
[key: string]: string | ||
} | ||
|
||
const cache = new WeakMap(); | ||
const cache = new WeakMap() | ||
|
||
export function isInView(el: HTMLElement): boolean { | ||
const rect = el.getBoundingClientRect(); | ||
const rect = el.getBoundingClientRect() | ||
|
||
if (!window.visualViewport) return false; | ||
if (!window.visualViewport) return false | ||
|
||
return ( | ||
rect.top >= 0 && | ||
rect.left >= 0 && | ||
// Need + 40 for safari detection | ||
rect.bottom <= window.visualViewport.height - 40 && | ||
rect.right <= window.visualViewport.width | ||
); | ||
) | ||
} | ||
|
||
export function set(el?: Element | HTMLElement | null, styles?: Style, ignoreCache = false) { | ||
if (!el || !(el instanceof HTMLElement) || !styles) return; | ||
let originalStyles: Style = {}; | ||
if (!el || !(el instanceof HTMLElement) || !styles) return | ||
const originalStyles: Style = {} | ||
|
||
Object.entries(styles).forEach(([key, value]: [string, string]) => { | ||
if (key.startsWith('--')) { | ||
el.style.setProperty(key, value); | ||
return; | ||
el.style.setProperty(key, value) | ||
return | ||
} | ||
|
||
originalStyles[key] = (el.style as any)[key]; | ||
(el.style as any)[key] = value; | ||
}); | ||
originalStyles[key] = (el.style as any)[key] | ||
;(el.style as any)[key] = value | ||
}) | ||
|
||
if (ignoreCache) return; | ||
if (ignoreCache) return | ||
|
||
cache.set(el, originalStyles); | ||
cache.set(el, originalStyles) | ||
} | ||
|
||
export function reset(el: Element | HTMLElement | null, prop?: string) { | ||
if (!el || !(el instanceof HTMLElement)) return; | ||
let originalStyles = cache.get(el); | ||
if (!el || !(el instanceof HTMLElement)) return | ||
const originalStyles = cache.get(el) | ||
|
||
if (!originalStyles) { | ||
return; | ||
return | ||
} | ||
|
||
if (prop) { | ||
(el.style as any)[prop] = originalStyles[prop]; | ||
;(el.style as any)[prop] = originalStyles[prop] | ||
} else { | ||
Object.entries(originalStyles).forEach(([key, value]) => { | ||
(el.style as any)[key] = value; | ||
}); | ||
;(el.style as any)[key] = value | ||
}) | ||
} | ||
} | ||
|
||
export function getTranslateY(element: HTMLElement): number | null { | ||
const style = window.getComputedStyle(element); | ||
const style = window.getComputedStyle(element) | ||
const transform = | ||
// @ts-ignore | ||
style.transform || style.webkitTransform || style.mozTransform; | ||
let mat = transform.match(/^matrix3d\((.+)\)$/); | ||
if (mat) return parseFloat(mat[1].split(', ')[13]); | ||
mat = transform.match(/^matrix\((.+)\)$/); | ||
return mat ? parseFloat(mat[1].split(', ')[5]) : null; | ||
style.transform || style.webkitTransform || style.mozTransform | ||
let mat = transform.match(/^matrix3d\((.+)\)$/) | ||
if (mat) return parseFloat(mat[1].split(', ')[13]) | ||
mat = transform.match(/^matrix\((.+)\)$/) | ||
return mat ? parseFloat(mat[1].split(', ')[5]) : null | ||
} | ||
|
||
export function dampenValue(v: number) { | ||
return 8 * (Math.log(v + 1) - 2); | ||
return 8 * (Math.log(v + 1) - 2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import { expect, Page } from '@playwright/test'; | ||
import { ANIMATION_DURATION } from './constants'; | ||
import { expect, Page } from '@playwright/test' | ||
import { ANIMATION_DURATION } from './constants' | ||
|
||
export async function openDrawer(page: Page) { | ||
await expect(page.getByTestId('content')).not.toBeVisible(); | ||
await page.getByTestId('trigger').click(); | ||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('content')).toBeVisible(); | ||
await expect(page.getByTestId('content')).not.toBeVisible() | ||
await page.getByTestId('trigger').click() | ||
await page.waitForTimeout(ANIMATION_DURATION) | ||
await expect(page.getByTestId('content')).toBeVisible() | ||
} | ||
|
||
export async function dragWithSpeed( | ||
page: Page, | ||
selector: string, | ||
startY: number, | ||
endY: number, | ||
speed: number = 10, | ||
): Promise<void> { | ||
const startX = 0; | ||
const distance = Math.abs(endY - startY); | ||
const steps = distance / speed; | ||
const delayPerStep = 10; // in milliseconds | ||
const yOffset = (endY - startY) / steps; | ||
|
||
await page.hover(selector); | ||
await page.mouse.down(); | ||
await page.mouse.move(0, -200); | ||
await page.mouse.up(); | ||
} | ||
// export async function dragWithSpeed( | ||
// page: Page, | ||
// selector: string, | ||
// startY: number, | ||
// endY: number, | ||
// speed: number = 10, | ||
// ): Promise<void> { | ||
// const startX = 0; | ||
// const distance = Math.abs(endY - startY); | ||
// const steps = distance / speed; | ||
// const delayPerStep = 10; // in milliseconds | ||
// const yOffset = (endY - startY) / steps; | ||
// | ||
// await page.hover(selector); | ||
// await page.mouse.down(); | ||
// await page.mouse.move(0, -200); | ||
// await page.mouse.up(); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 1 addition & 9 deletions
10
playground/src/components/Drawer.vue → playground/src/components/DemoDrawer.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
<script setup lang="ts"> | ||
import { | ||
DrawerClose, | ||
DrawerContent, | ||
DrawerOverlay, | ||
DrawerPortal, | ||
|