Skip to content

Commit

Permalink
style(format): updates Prettier config
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Feb 9, 2019
1 parent 2b226db commit 74bfcf4
Show file tree
Hide file tree
Showing 34 changed files with 719 additions and 973 deletions.
162 changes: 81 additions & 81 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
{
"name": "scroll-behavior-polyfill",
"version": "2.0.5",
"description": "A polyfill for the 'scroll-behavior' CSS-property",
"repository": {
"type": "git",
"url": "https://github.com/wessberg/scroll-behavior-polyfill.git"
},
"bugs": {
"url": "https://github.com/wessberg/scroll-behavior-polyfill/issues"
},
"scripts": {
"generate:readme": "scaffold readme --yes",
"generate:license": "scaffold license --yes",
"generate:contributing": "scaffold contributing --yes",
"generate:coc": "scaffold coc --yes",
"generate:changelog": "standard-changelog --first-release",
"generate:all": "npm run generate:license & npm run generate:contributing & npm run generate:coc & npm run generate:readme && npm run generate:changelog",
"clean:dist": "rm -rf dist",
"clean:compiled": "rm -rf compiled",
"clean": "npm run clean:dist && npm run clean:compiled",
"lint": "tsc --noEmit && tslint -c tslint.json --project tsconfig.json",
"prettier": "prettier --write '{src,documentation}/**/*.{js,ts,json,html,xml,css,md}'",
"prebuild": "npm run clean:dist",
"build": "npm run rollup",
"rollup": "rollup -c rollup.config.js",
"preversion": "npm run lint && NODE_ENV=production npm run build",
"version": "npm run generate:all && git add .",
"release": "np --no-cleanup --no-yarn"
},
"files": [
"dist/**/*.*"
],
"keywords": [
"scroll-behavior",
"smooth-scrolling",
"polyfill",
"css",
"smooth",
"scroll behavior"
],
"contributors": [
{
"name": "Frederik Wessberg",
"email": "frederikwessberg@hotmail.com",
"url": "https://github.com/wessberg",
"imageUrl": "https://avatars2.githubusercontent.com/u/20454213?s=460&v=4",
"role": "Lead Developer",
"twitter": "FredWessberg"
}
],
"license": "MIT",
"devDependencies": {
"@wessberg/rollup-plugin-ts": "1.1.28",
"@wessberg/scaffold": "1.0.16",
"@wessberg/ts-config": "^0.0.39",
"rollup": "^1.1.2",
"rollup-plugin-node-resolve": "^4.0.0",
"tslib": "^1.9.3",
"tslint": "^5.12.1",
"typescript": "^3.3.3",
"standard-changelog": "^2.0.6",
"prettier": "^1.16.4",
"pretty-quick": "^1.10.0",
"husky": "^1.3.1",
"np": "^4.0.2"
},
"dependencies": {},
"main": "./dist/index.js",
"module": "./dist/index.js",
"browser": "./dist/index.js",
"types": "./dist/index.d.ts",
"typings": "./dist/index.d.ts",
"es2015": "./dist/index.js",
"engines": {
"node": ">=4.0.0"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
"name": "scroll-behavior-polyfill",
"version": "2.0.5",
"description": "A polyfill for the 'scroll-behavior' CSS-property",
"repository": {
"type": "git",
"url": "https://github.com/wessberg/scroll-behavior-polyfill.git"
},
"bugs": {
"url": "https://github.com/wessberg/scroll-behavior-polyfill/issues"
},
"scripts": {
"generate:readme": "scaffold readme --yes",
"generate:license": "scaffold license --yes",
"generate:contributing": "scaffold contributing --yes",
"generate:coc": "scaffold coc --yes",
"generate:changelog": "standard-changelog --first-release",
"generate:all": "npm run generate:license & npm run generate:contributing & npm run generate:coc & npm run generate:readme && npm run generate:changelog",
"clean:dist": "rm -rf dist",
"clean:compiled": "rm -rf compiled",
"clean": "npm run clean:dist && npm run clean:compiled",
"lint": "tsc --noEmit && tslint -c tslint.json --project tsconfig.json",
"prettier": "prettier --write '{src,documentation}/**/*.{js,ts,json,html,xml,css,md}'",
"prebuild": "npm run clean:dist",
"build": "npm run rollup",
"rollup": "rollup -c rollup.config.js",
"preversion": "npm run lint && NODE_ENV=production npm run build",
"version": "npm run generate:all && git add .",
"release": "np --no-cleanup --no-yarn"
},
"files": [
"dist/**/*.*"
],
"keywords": [
"scroll-behavior",
"smooth-scrolling",
"polyfill",
"css",
"smooth",
"scroll behavior"
],
"contributors": [
{
"name": "Frederik Wessberg",
"email": "frederikwessberg@hotmail.com",
"url": "https://github.com/wessberg",
"imageUrl": "https://avatars2.githubusercontent.com/u/20454213?s=460&v=4",
"role": "Lead Developer",
"twitter": "FredWessberg"
}
],
"license": "MIT",
"devDependencies": {
"@wessberg/rollup-plugin-ts": "1.1.28",
"@wessberg/scaffold": "1.0.17",
"@wessberg/ts-config": "^0.0.39",
"rollup": "^1.1.2",
"rollup-plugin-node-resolve": "^4.0.0",
"tslib": "^1.9.3",
"tslint": "^5.12.1",
"typescript": "^3.3.3",
"standard-changelog": "^2.0.6",
"prettier": "^1.16.4",
"pretty-quick": "^1.10.0",
"husky": "^1.3.1",
"np": "^4.0.2"
},
"dependencies": {},
"main": "./dist/index.js",
"module": "./dist/index.js",
"browser": "./dist/index.js",
"types": "./dist/index.d.ts",
"typings": "./dist/index.d.ts",
"es2015": "./dist/index.js",
"engines": {
"node": ">=4.0.0"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
}
1 change: 1 addition & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("@wessberg/ts-config/prettier.config");
2 changes: 1 addition & 1 deletion src/adjustable-element/i-adjustable-element.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface IAdjustableElement extends Element {
__adjustingScrollPosition?: boolean;
__adjustingScrollPosition?: boolean;
}
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SUPPORTS_SCROLL_BEHAVIOR } from "./support/supports-scroll-behavior";
import { patch } from "./patch/patch";
import { SUPPORTS_ELEMENT_PROTOTYPE_SCROLL_METHODS } from "./support/supports-element-prototype-scroll-methods";
import {SUPPORTS_SCROLL_BEHAVIOR} from "./support/supports-scroll-behavior";
import {patch} from "./patch/patch";
import {SUPPORTS_ELEMENT_PROTOTYPE_SCROLL_METHODS} from "./support/supports-element-prototype-scroll-methods";

if (!SUPPORTS_SCROLL_BEHAVIOR || !SUPPORTS_ELEMENT_PROTOTYPE_SCROLL_METHODS) {
patch();
patch();
}
3 changes: 1 addition & 2 deletions src/original/element/scroll-into-view.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const ELEMENT_ORIGINAL_SCROLL_INTO_VIEW =
Element.prototype.scrollIntoView;
export const ELEMENT_ORIGINAL_SCROLL_INTO_VIEW = Element.prototype.scrollIntoView;
5 changes: 1 addition & 4 deletions src/original/element/scroll-left.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export const ELEMENT_ORIGINAL_SCROLL_LEFT_SET_DESCRIPTOR = Object.getOwnPropertyDescriptor(
Element.prototype,
"scrollLeft"
)!.set!;
export const ELEMENT_ORIGINAL_SCROLL_LEFT_SET_DESCRIPTOR = Object.getOwnPropertyDescriptor(Element.prototype, "scrollLeft")!.set!;
5 changes: 1 addition & 4 deletions src/original/element/scroll-top.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export const ELEMENT_ORIGINAL_SCROLL_TOP_SET_DESCRIPTOR = Object.getOwnPropertyDescriptor(
Element.prototype,
"scrollTop"
)!.set!;
export const ELEMENT_ORIGINAL_SCROLL_TOP_SET_DESCRIPTOR = Object.getOwnPropertyDescriptor(Element.prototype, "scrollTop")!.set!;
82 changes: 38 additions & 44 deletions src/patch/anchor/catch-navigation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { findNearestAncestorsWithScrollBehavior } from "../../util/find-nearest-ancestor-with-scroll-behavior";
import { findNearestRoot } from "../../util/find-nearest-root";
import {findNearestAncestorsWithScrollBehavior} from "../../util/find-nearest-ancestor-with-scroll-behavior";
import {findNearestRoot} from "../../util/find-nearest-root";

/**
* A Regular expression that matches id's of the form "#[digit]"
Expand All @@ -12,46 +12,40 @@ const ID_WITH_LEADING_DIGIT_REGEXP = /^#\d/;
* if the scroll behavior is smooth in the first rooter within that context
*/
export function catchNavigation(): void {
// Listen for 'click' events globally
window.addEventListener("click", e => {
// Only work with trusted events on HTMLAnchorElements
if (!e.isTrusted || !(e.target instanceof HTMLAnchorElement)) return;
const hrefAttributeValue = e.target.getAttribute("href");

// Only work with HTMLAnchorElements that navigates to a specific ID
if (hrefAttributeValue == null || !hrefAttributeValue.startsWith("#")) {
return;
}

// Find the nearest root, whether it be a ShadowRoot or the document itself
const root = findNearestRoot(e.target);

// Attempt to match the selector from that root. querySelector' doesn't support IDs that start with a digit, so work around that limitation
const elementMatch =
hrefAttributeValue.match(ID_WITH_LEADING_DIGIT_REGEXP) != null
? root.getElementById(hrefAttributeValue.slice(1))
: root.querySelector(hrefAttributeValue);

// If no selector could be found, don't proceed
if (elementMatch == null) return;

// Find the nearest ancestor that can be scrolled
const [
ancestorWithScrollBehavior,
behavior
] = findNearestAncestorsWithScrollBehavior(elementMatch);

// If the behavior isn't smooth, don't proceed
if (behavior !== "smooth") return;

// Otherwise, first prevent the default action.
e.preventDefault();

// Now, scroll to the element with that ID
ancestorWithScrollBehavior.scrollTo({
behavior,
top: (elementMatch as HTMLElement).offsetTop,
left: (elementMatch as HTMLElement).offsetLeft
});
});
// Listen for 'click' events globally
window.addEventListener("click", e => {
// Only work with trusted events on HTMLAnchorElements
if (!e.isTrusted || !(e.target instanceof HTMLAnchorElement)) return;
const hrefAttributeValue = e.target.getAttribute("href");

// Only work with HTMLAnchorElements that navigates to a specific ID
if (hrefAttributeValue == null || !hrefAttributeValue.startsWith("#")) {
return;
}

// Find the nearest root, whether it be a ShadowRoot or the document itself
const root = findNearestRoot(e.target);

// Attempt to match the selector from that root. querySelector' doesn't support IDs that start with a digit, so work around that limitation
const elementMatch = hrefAttributeValue.match(ID_WITH_LEADING_DIGIT_REGEXP) != null ? root.getElementById(hrefAttributeValue.slice(1)) : root.querySelector(hrefAttributeValue);

// If no selector could be found, don't proceed
if (elementMatch == null) return;

// Find the nearest ancestor that can be scrolled
const [ancestorWithScrollBehavior, behavior] = findNearestAncestorsWithScrollBehavior(elementMatch);

// If the behavior isn't smooth, don't proceed
if (behavior !== "smooth") return;

// Otherwise, first prevent the default action.
e.preventDefault();

// Now, scroll to the element with that ID
ancestorWithScrollBehavior.scrollTo({
behavior,
top: (elementMatch as HTMLElement).offsetTop,
left: (elementMatch as HTMLElement).offsetLeft
});
});
}
Loading

0 comments on commit 74bfcf4

Please sign in to comment.