-
-
Notifications
You must be signed in to change notification settings - Fork 12
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 #37 from swup/typescript
Port to Typescript
- Loading branch information
Showing
11 changed files
with
1,399 additions
and
5,424 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,8 +1,11 @@ | ||
export default function updateLangAttribute(currentHtml, newHtml) { | ||
export default function updateLangAttribute( | ||
currentHtml: HTMLElement, | ||
newHtml: HTMLElement | ||
): string | null { | ||
if (currentHtml.lang !== newHtml.lang) { | ||
currentHtml.lang = newHtml.lang; | ||
return currentHtml.lang; | ||
} else { | ||
return null; | ||
} | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
import waitForStylesheet from './waitForStylesheet.js'; | ||
|
||
function isStylesheet(el: Element): el is HTMLLinkElement { | ||
return el.matches('link[rel=stylesheet][href]'); | ||
} | ||
|
||
export default function waitForAssets(elements: Element[], timeoutMs: number = 0) { | ||
return elements.filter(isStylesheet).map((el) => waitForStylesheet(el, timeoutMs)); | ||
} |
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
export default function waitForStylesheet(element: HTMLLinkElement, timeoutMs: number = 0) { | ||
const isLoaded = ({ href }: HTMLLinkElement) => { | ||
return Array.from(document.styleSheets) | ||
.map(({ href }) => href) | ||
.includes(href); | ||
}; | ||
|
||
const whenLoaded = (cb: (value?: unknown) => void) => { | ||
if (isLoaded(element)) { | ||
cb(); | ||
} else { | ||
setTimeout(() => whenLoaded(cb), 10); | ||
} | ||
}; | ||
|
||
return new Promise((resolve) => { | ||
whenLoaded(resolve); | ||
if (timeoutMs > 0) { | ||
setTimeout(resolve, timeoutMs); | ||
} | ||
}); | ||
} |
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,14 @@ | ||
{ | ||
"include": ["src"], | ||
"compilerOptions": { | ||
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ | ||
"moduleResolution": "Node16", /* Specify how TypeScript looks up a file from a given module specifier. */ | ||
"rootDirs": ["./src"], /* Allow multiple folders to be treated as one when resolving modules. */ | ||
"resolveJsonModule": true, /* Enable importing .json files. */ | ||
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ | ||
"outDir": "./dist", /* Specify an output folder for all emitted files. */ | ||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
"noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */ | ||
} | ||
} |