Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix line jumps #61

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/mini-editor/src/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export function Code({
<pre
ref={ref}
className={`language-${language}`}
style={{ opacity: dimensions ? 1 : 0 }}
style={{
opacity: dimensions ? 1 : 0,
overflow: dimensions ? undefined : "hidden", // avoid scrollbars when measuring
}}
>
<code>
{dimensions ? (
Expand Down
18 changes: 14 additions & 4 deletions packages/smooth-lines/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ function SmoothLines({
minZoom = 0,
maxZoom = 1.2,
}: Props) {
const lines = useLineTransitions(prevLines, nextLines)
const { lines, verticalInterval } = useLineTransitions(
prevLines,
nextLines
)

const prevFocusKeys = prevFocus.map(
index => prevLines[index]?.key
Expand Down Expand Up @@ -88,7 +91,13 @@ function SmoothLines({

const zoom = tweenProp(prevZoom, nextZoom, progress)
const dx = tweenProp(prevDX, nextDX, progress)
const dy = tweenProp(prevDY, nextDY, progress)
const dy = tweenProp(
prevDY,
nextDY,
progress,
verticalInterval
)

const focusHeight = tweenProp(
prevContentHeight,
nextContentHeight,
Expand Down Expand Up @@ -264,12 +273,13 @@ function Content({
function tweenProp(
start: number,
end: number,
progress: number
progress: number,
interval: [number, number] = [0, 1]
) {
return tween(
{
fixed: false,
interval: [0, 1],
interval,
extremes: [start, end],
ease: easing.easeInOutCubic,
},
Expand Down
15 changes: 11 additions & 4 deletions packages/smooth-lines/src/line-transitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ function getLineTransitions(
const enterCount = enterIndex
const exitCount = exitIndex

return linesData.map(lineData =>
getLineTransition(lineData, enterCount, exitCount)
)
return {
lines: linesData.map(lineData =>
getLineTransition(lineData, enterCount, exitCount)
),
verticalInterval: verticalInterval(
enterCount,
exitCount
),
}
}

function getLineTransition(
Expand Down Expand Up @@ -153,6 +159,7 @@ function getLineTransition(
fixed: false,
extremes: [prevIndex, nextIndex],
interval: [startY, endY],
ease: easing.easeInOutCubic,
},
tweenX: { fixed: true, value: 0 },
}
Expand All @@ -165,7 +172,7 @@ function sortUniqueConcat(a: number[], b: number[]) {
function verticalInterval(
enterCount: number,
exitCount: number
) {
): [number, number] {
if (enterCount <= 0 && exitCount <= 0) return [0, 1]
if (enterCount <= 0 && exitCount >= 1) return [0.33, 1]
if (enterCount >= 1 && exitCount <= 0) return [0, 0.67]
Expand Down
71 changes: 61 additions & 10 deletions packages/storybook/src/mini-editor-hike.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ export const x = () => {
{...xprops}
progress={progress}
backward={backward}
minColumns={50}
/>
)}
</WithProgress>
Expand All @@ -358,20 +359,70 @@ export const x = () => {
const xprops = {
steps: [
{
code:
"<html>\n <body>\n <style>\n h1 {\n border: 4px solid black;\n padding: 20px 7px;\n margin: 0;\n }\n </style>\n <h1>Lorem ipsum dolor sit amet</h1>\n </body>\n</html>\n",
code: `const app = <h1 style={{ color: 'blue' }}>Hello World</h1>

ReactDOM.render(app, document.getElementById('root'))`,
focus: "1",
},
{
code:
"<html>\n <body>\n <style>\n h1 {\n border: 4px solid black;\n padding: 20px 7px;\n margin: 0;\n filter: blur(3px);\n }\n </style>\n <h1>Lorem ipsum dolor sit amet</h1>\n </body>\n</html>\n",
focus: "4,8,9",
code: `function MyComponent() {
return (
<div>
<button>Hello</button>
<button>Hello</button>
<button>Hello</button>
<button>Hello</button>
<button>Hello</button>
</div>
)
}

const app = <h1 style={{ color: 'blue' }}>Hello World</h1>

ReactDOM.render(app, document.getElementById('root'))`,
focus: "1:7",
},
{
code:
"<html>\n <body>\n <style>\n h1 {\n border: 4px solid black;\n padding: 20px 7px;\n margin: 0;\n filter: drop-shadow(\n 2px 2px 2px blue\n );\n }\n </style>\n <h1>Lorem ipsum dolor sit amet</h1>\n </body>\n</html>\n",
focus: "4,8:11",
code: `function MyComponent() {
return (
<div>
<button>Hello</button>
<button>Hello</button>
<button>Hello</button>
<button>Hello</button>
<button>Hello</button>
</div>
)
}

const app = <h1 style={{ color: 'blue' }}>Hello World</h1>

ReactDOM.render(app, document.getElementById('root'))`,
focus: "1:7",
},
{
code: `function MyComponent() {
return (
<div>
<button>Bye</button>
<button>Bye</button>
<button>Bye</button>
</div>
)
}

const app = <h1 style={{ color: 'blue' }}>Hello World</h1>

ReactDOM.render(app, document.getElementById('root'))`,
focus: "7",
},
{
code: `const app = <h1 style={{ color: 'blue' }}>Hello World</h1>

ReactDOM.render(app, document.getElementById('root'))`,
focus: "1",
},
],
lang: "html",
file: "index.html",
lang: "jsx",
file: "index.js",
}