Skip to content

Commit

Permalink
New release
Browse files Browse the repository at this point in the history
  • Loading branch information
tomayac committed Jan 9, 2024
1 parent 08fa2ea commit 53375fe
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 65 deletions.
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "always",
Expand Down
101 changes: 58 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "text-fragments-polyfill",
"version": "5.6.0",
"version": "5.7.0",
"description": "This is a polyfill for the [Text Fragments](https://wicg.github.io/scroll-to-text-fragment/) feature for browsers that don't support it natively.",
"main": "./dist/text-fragments.js",
"browser": "./dist/text-fragments.js",
Expand Down
42 changes: 22 additions & 20 deletions src/fragment-generation-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,24 @@ export const generateFragment = (selection, startTime = Date.now()) => {

/**
* Attampts to generate a fragment using a given range. @see {@link generateFragment}
*
*
* @param {Range} range
* @param {Date} [startTime] - the time when generation began, for timeout
* purposes. Defaults to current timestamp.
* @return {GenerateFragmentResult}
*/
export const generateFragmentFromRange = (range, startTime = Date.now()) => {
try {
return doGenerateFragmentFromRange(range, startTime);
} catch (err) {
if (err.isTimeout) {
return {status: GenerateFragmentStatus.TIMEOUT};
} else {
return {status: GenerateFragmentStatus.EXECUTION_FAILED};
export const generateFragmentFromRange =
(range, startTime = Date.now()) => {
try {
return doGenerateFragmentFromRange(range, startTime);
} catch (err) {
if (err.isTimeout) {
return {status: GenerateFragmentStatus.TIMEOUT};
} else {
return {status: GenerateFragmentStatus.EXECUTION_FAILED};
}
}
}
}
}

/**
* Checks whether fragment generation can be attempted for a given range. This
Expand Down Expand Up @@ -153,16 +154,17 @@ export const isValidRangeForFragmentGeneration = (range) => {
* @throws {Error} - Will throw if computation takes longer than the accepted
* timeout length.
*/
const doGenerateFragment = (selection, startTime) => {
let range;
try {
range = selection.getRangeAt(0);
} catch {
return {status: GenerateFragmentStatus.INVALID_SELECTION};
}
const doGenerateFragment =
(selection, startTime) => {
let range;
try {
range = selection.getRangeAt(0);
} catch {
return {status: GenerateFragmentStatus.INVALID_SELECTION};
}

return doGenerateFragmentFromRange(range, startTime);
}
return doGenerateFragmentFromRange(range, startTime);
}
/**
* @see {@link doGenerateFragment}
*/
Expand Down

0 comments on commit 53375fe

Please sign in to comment.