Skip to content

Commit

Permalink
entry-crossing + exit-crossing + test (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ameerabuf authored Aug 19, 2024
1 parent 96c5d0f commit dac804e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
6 changes: 5 additions & 1 deletion dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ function transformRangeToPosition (range, viewportSize, rect) {
startPosition = Math.max(start, end - viewportSize);
duration = Math.min(viewportSize, height);
}
else if (name === 'exit-crossing') {
startPosition = start;
duration = height;
}
else if (name === 'cover') {
startPosition = start - viewportSize;
duration = height + viewportSize;
Expand Down Expand Up @@ -944,7 +948,7 @@ class Scroll {
*/

/**
* @typedef {'entry' | 'contain' | 'exit' | 'cover'} RangeName
* @typedef {'entry' | 'contain' | 'exit' | 'cover' | 'entry-crossing' | 'exit-crossing'} RangeName
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class Scroll {
*/

/**
* @typedef {'entry' | 'contain' | 'exit' | 'cover'} RangeName
* @typedef {'entry' | 'contain' | 'exit' | 'cover' | 'entry-crossing' | 'exit-crossing'} RangeName
*/

/**
Expand Down
4 changes: 4 additions & 0 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ function transformRangeToPosition (range, viewportSize, rect) {
startPosition = Math.max(start, end - viewportSize);
duration = Math.min(viewportSize, height);
}
else if (name === 'exit-crossing') {
startPosition = start;
duration = height;
}
else if (name === 'cover') {
startPosition = start - viewportSize;
duration = height + viewportSize;
Expand Down
16 changes: 16 additions & 0 deletions test/view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,19 @@ test('start :: entry 40% :: start add calc(10vh + 25px) :: end cover 100% :: end
t.is(result.start, 0); // -30 + 30 = 0
t.is(result.end, 300); // 150 + 150 = 300
});

test('start :: entry-crossing 40% :: end :: exit-crossing 70%', t => {
const input = getScene({
viewSource: {
offsetParent: {},
offsetHeight: 150
},
start: {name: 'entry-crossing', offset: 40},
end: {name: 'exit-crossing', offset: 70},
});

const result = getTransformedScene(input, null, SMALLER_VIEWPORT_SIZE, IS_HORIZONTAL, smallAbsoluteOffsetContext);

t.is(result.start, 10);
t.is(result.end, 105);
});
2 changes: 1 addition & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare type RangeName = 'entry' | 'exit' | 'contain' | 'cover';
declare type RangeName = 'entry' | 'exit' | 'contain' | 'cover' | 'entry-crossing' | 'exit-crossing';

declare type RangeOffset = {
name?: RangeName;
Expand Down

0 comments on commit dac804e

Please sign in to comment.