Skip to content

Commit

Permalink
chore(prettier): 🤖 ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 1, 2023
1 parent ecfe9fe commit b99694f
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 200 deletions.
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ export interface CustomBehaviorOptions<T = unknown> extends BaseOptions {

/** @public */
export type CustomScrollBehaviorCallback<T = unknown> = (
actions: ScrollAction[]
actions: ScrollAction[],
) => T

const isStandardScrollBehavior = (
options: any
options: any,
): options is StandardBehaviorOptions =>
options === Object(options) && Object.keys(options).length !== 0

const isCustomScrollBehavior = <T = unknown>(
options: any
options: any,
): options is CustomBehaviorOptions<T> =>
typeof options === 'object' ? typeof options.behavior === 'function' : false

Expand Down Expand Up @@ -105,7 +105,7 @@ const isInDocument = (element: Node) => {
*/
function scrollIntoView(
target: Element,
options?: StandardBehaviorOptions | boolean
options?: StandardBehaviorOptions | boolean,
): void
/**
* Scrolls the given element into view, with options for when, and how.
Expand All @@ -126,11 +126,11 @@ function scrollIntoView(
*/
function scrollIntoView<T>(
target: Element,
options: CustomBehaviorOptions<T>
options: CustomBehaviorOptions<T>,
): T
function scrollIntoView<T = unknown>(
target: Element,
options?: StandardBehaviorOptions | CustomBehaviorOptions<T> | boolean
options?: StandardBehaviorOptions | CustomBehaviorOptions<T> | boolean,
): T | void {
// Browsers treats targets that aren't in the dom as a no-op and so should we
if (!target.isConnected || !isInDocument(target)) {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export interface CustomScrollAction {
left: number
}
export type CustomScrollBehaviorCallback<T> = (
actions: CustomScrollAction[]
actions: CustomScrollAction[],
) => T
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<script src="/node_modules/scroll-into-view-if-needed/umd/scroll-into-view-if-needed.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<script src="/node_modules/scroll-into-view-if-needed/umd/scroll-into-view-if-needed.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand Down
158 changes: 85 additions & 73 deletions tests/web-platform/css/cssom-view/scrollintoview.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<title>CSSOM View - scrollIntoView</title>
<meta charset="utf-8" />
<meta
Expand Down Expand Up @@ -59,81 +59,93 @@
expectedX = _ref[1],
expectedY = _ref[2]

test(function () {
window.scrollTo(0, 0)
testScrollIntoView(input)
var x = expectedX === 'nearest' ? expectedXRight : expectedX
var y = expectedY === 'nearest' ? expectedYBottom : expectedY
assert_approx_equals(
window.scrollX || window.pageXOffset,
x,
0.5,
'scrollX'
)
assert_approx_equals(
window.scrollY || window.pageYOffset,
y,
0.5,
'scrollY'
)
}, 'scrollIntoView(' + format_input(input) + ') starting at left,top')
test(
function () {
window.scrollTo(0, 0)
testScrollIntoView(input)
var x = expectedX === 'nearest' ? expectedXRight : expectedX
var y = expectedY === 'nearest' ? expectedYBottom : expectedY
assert_approx_equals(
window.scrollX || window.pageXOffset,
x,
0.5,
'scrollX',
)
assert_approx_equals(
window.scrollY || window.pageYOffset,
y,
0.5,
'scrollY',
)
},
'scrollIntoView(' + format_input(input) + ') starting at left,top',
)

test(function () {
window.scrollTo(0, 12000)
testScrollIntoView(input)
var x = expectedX === 'nearest' ? expectedXRight : expectedX
var y = expectedY === 'nearest' ? expectedYTop : expectedY
assert_approx_equals(
window.scrollX || window.pageXOffset,
x,
0.5,
'scrollX'
)
assert_approx_equals(
window.scrollY || window.pageYOffset,
y,
0.5,
'scrollY'
)
}, 'scrollIntoView(' + format_input(input) + ') starting at left,bottom')
test(
function () {
window.scrollTo(0, 12000)
testScrollIntoView(input)
var x = expectedX === 'nearest' ? expectedXRight : expectedX
var y = expectedY === 'nearest' ? expectedYTop : expectedY
assert_approx_equals(
window.scrollX || window.pageXOffset,
x,
0.5,
'scrollX',
)
assert_approx_equals(
window.scrollY || window.pageYOffset,
y,
0.5,
'scrollY',
)
},
'scrollIntoView(' + format_input(input) + ') starting at left,bottom',
)

test(function () {
window.scrollTo(12000, 0)
testScrollIntoView(input)
var x = expectedX === 'nearest' ? expectedXLeft : expectedX
var y = expectedY === 'nearest' ? expectedYBottom : expectedY
assert_approx_equals(
window.scrollX || window.pageXOffset,
x,
0.5,
'scrollX'
)
assert_approx_equals(
window.scrollY || window.pageYOffset,
y,
0.5,
'scrollY'
)
}, 'scrollIntoView(' + format_input(input) + ') starting at right,top')
test(
function () {
window.scrollTo(12000, 0)
testScrollIntoView(input)
var x = expectedX === 'nearest' ? expectedXLeft : expectedX
var y = expectedY === 'nearest' ? expectedYBottom : expectedY
assert_approx_equals(
window.scrollX || window.pageXOffset,
x,
0.5,
'scrollX',
)
assert_approx_equals(
window.scrollY || window.pageYOffset,
y,
0.5,
'scrollY',
)
},
'scrollIntoView(' + format_input(input) + ') starting at right,top',
)

test(function () {
window.scrollTo(12000, 12000)
testScrollIntoView(input)
var x = expectedX === 'nearest' ? expectedXLeft : expectedX
var y = expectedY === 'nearest' ? expectedYTop : expectedY
assert_approx_equals(
window.scrollX || window.pageXOffset,
x,
0.5,
'scrollX'
)
assert_approx_equals(
window.scrollY || window.pageYOffset,
y,
0.5,
'scrollY'
)
}, 'scrollIntoView(' + format_input(input) + ') starting at right,bottom')
test(
function () {
window.scrollTo(12000, 12000)
testScrollIntoView(input)
var x = expectedX === 'nearest' ? expectedXLeft : expectedX
var y = expectedY === 'nearest' ? expectedYTop : expectedY
assert_approx_equals(
window.scrollX || window.pageXOffset,
x,
0.5,
'scrollX',
)
assert_approx_equals(
window.scrollY || window.pageYOffset,
y,
0.5,
'scrollY',
)
},
'scrollIntoView(' + format_input(input) + ') starting at right,bottom',
)
})

function testScrollIntoView(input) {
Expand Down
75 changes: 39 additions & 36 deletions tests/web-platform/custom/borders.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<title>Border widths</title>
<meta charset="utf-8" />
<link
Expand Down Expand Up @@ -279,42 +279,45 @@
var outer = suite[3][0]
var inner = suite[3][1]

test(function () {
window.scrollTo(0, 0)
outerContainer.scrollTop = 0
outerContainer.scrollLeft = 0
innerContainer.scrollTop = 0
innerContainer.scrollLeft = 0
scrollIntoView(tiles[target], { block: block, inline: inline })
//tiles[target].scrollIntoView({block, inline});
test(
function () {
window.scrollTo(0, 0)
outerContainer.scrollTop = 0
outerContainer.scrollLeft = 0
innerContainer.scrollTop = 0
innerContainer.scrollLeft = 0
scrollIntoView(tiles[target], { block: block, inline: inline })
//tiles[target].scrollIntoView({block, inline});

assert_approx_equals(
outerContainer.scrollLeft,
outer.x,
1,
'outerContainer.scrollLeft'
)
assert_approx_equals(
outerContainer.scrollTop,
outer.y,
1,
'outerContainer.scrollTop'
)
assert_approx_equals(
innerContainer.scrollLeft,
inner.x,
1,
'innerContainer.scrollLeft'
)
assert_approx_equals(
innerContainer.scrollTop,
inner.y,
1,
'innerContainer.scrollTop'
)
}, 'scrollIntoView(' +
JSON.stringify({ block: block, inline: inline }) +
')')
assert_approx_equals(
outerContainer.scrollLeft,
outer.x,
1,
'outerContainer.scrollLeft',
)
assert_approx_equals(
outerContainer.scrollTop,
outer.y,
1,
'outerContainer.scrollTop',
)
assert_approx_equals(
innerContainer.scrollLeft,
inner.x,
1,
'innerContainer.scrollLeft',
)
assert_approx_equals(
innerContainer.scrollTop,
inner.y,
1,
'innerContainer.scrollTop',
)
},
'scrollIntoView(' +
JSON.stringify({ block: block, inline: inline }) +
')',
)
})

document.body.classList.remove('running')
Expand Down
16 changes: 13 additions & 3 deletions tests/web-platform/resources/testharness.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
html {
font-family: DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
font-family:
DejaVu Sans,
Bitstream Vera Sans,
Arial,
Sans;
}

#log .warning,
Expand Down Expand Up @@ -79,12 +83,18 @@ table#results span {
}

table#results span.expected {
font-family: DejaVu Sans Mono, Bitstream Vera Sans Mono, Monospace;
font-family:
DejaVu Sans Mono,
Bitstream Vera Sans Mono,
Monospace;
white-space: pre;
}

table#results span.actual {
font-family: DejaVu Sans Mono, Bitstream Vera Sans Mono, Monospace;
font-family:
DejaVu Sans Mono,
Bitstream Vera Sans Mono,
Monospace;
white-space: pre;
}

Expand Down
Loading

0 comments on commit b99694f

Please sign in to comment.