-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from basementstudio/visualizer
[visualizer]
- Loading branch information
Showing
22 changed files
with
1,280 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"website": patch | ||
"@bsmnt/scrollytelling": minor | ||
--- | ||
|
||
Visualizer. |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module "*.scss"; |
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,48 +1,28 @@ | ||
import * as React from "react"; | ||
import { useScrollytelling } from "../../context"; | ||
import { useEffect, useState } from "react"; | ||
import { Visualizer } from "./visualizer"; | ||
import { Portal } from "@radix-ui/react-portal"; | ||
|
||
// ---- Debugger | ||
|
||
export const Debugger = () => { | ||
const { timeline, rootRef } = useScrollytelling(); | ||
const [progress, setProgress] = React.useState<{ | ||
percentage: string; | ||
px: string; | ||
}>(); | ||
export default function Debugger() { | ||
const [mountInstance, setMountInstance] = useState(false); | ||
|
||
React.useEffect(() => { | ||
if (!timeline || !rootRef.current) return; | ||
const handleUpdate = () => { | ||
const progress = timeline.progress(); | ||
if (!timeline.scrollTrigger) return; | ||
|
||
const start = timeline.scrollTrigger.start; | ||
const end = timeline.scrollTrigger.end; | ||
const scroll = (end - start) * progress; | ||
setProgress({ | ||
percentage: `${(progress * 100).toFixed(2)}%`, | ||
px: `${scroll.toFixed(0)}px`, | ||
}); | ||
useEffect(() => { | ||
const w = window as { | ||
__scrollytelling_alreadyMountedDebuggerInstance?: boolean; | ||
}; | ||
|
||
timeline.eventCallback("onUpdate", handleUpdate); | ||
|
||
return () => { | ||
timeline.eventCallback("onUpdate", null); | ||
}; | ||
}, [timeline, rootRef]); | ||
const alreadyMountedInstance = | ||
w.__scrollytelling_alreadyMountedDebuggerInstance; | ||
if (alreadyMountedInstance) return; | ||
setMountInstance(true); | ||
w.__scrollytelling_alreadyMountedDebuggerInstance = true; | ||
}, []); | ||
|
||
if (!mountInstance) return <></>; | ||
return ( | ||
<div | ||
style={{ | ||
width: "370px", | ||
padding: "24px", | ||
border: "1px solid black", | ||
fontSize: "12px", | ||
background: "#360202", | ||
}} | ||
> | ||
<pre>{JSON.stringify({ progress }, null, 2)}</pre> | ||
</div> | ||
<Portal> | ||
<Visualizer /> | ||
</Portal> | ||
); | ||
}; | ||
} |
35 changes: 35 additions & 0 deletions
35
scrollytelling/src/components/debugger/visualizer/helpers.tsx
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import s from "./visualizer.module.scss"; | ||
|
||
export const highlight = (target: SVGElement | HTMLElement) => { | ||
// Create a div element that has the same dimensions and position as the target | ||
const highlight = document.createElement("div"); | ||
|
||
highlight.style.position = "fixed"; | ||
const bounds = target.getBoundingClientRect(); | ||
highlight.style.top = `${bounds.top}px`; | ||
highlight.style.left = `${bounds.left}px`; | ||
highlight.style.width = `${bounds.width}px`; | ||
highlight.style.height = `${bounds.height}px`; | ||
|
||
highlight.classList.add(s["highlight"] as string); | ||
|
||
// Append to body. | ||
document.body.appendChild(highlight); | ||
|
||
// Clear instance | ||
return () => { | ||
document.body.removeChild(highlight); | ||
}; | ||
}; | ||
|
||
export const colors = [ | ||
["#F87171", "#991B1B"], | ||
["#FACC15", "#854D0E"], | ||
["#4ADE80", "#166534"], | ||
["#2DD4BF", "#115E59"], | ||
["#38BDF8", "#075985"], | ||
["#818CF8", "#3730A3"], | ||
["#C084FC", "#6B21A8"], | ||
["#E879F9", "#86198F"], | ||
["rgba(244, 114, 182, 0.40)", "#9D174D"], | ||
]; |
Oops, something went wrong.
360bfab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
scrollytelling-website – ./
scrollytelling-website.vercel.app
scrollytelling-website-basement.vercel.app
scrollytelling-website-git-main-basement.vercel.app
scrollytelling.basement.studio