-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Hadrien Gardeur <hadrien.gardeur@gmail.com> Co-authored-by: Jiminy Panoz <JayPanoz@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1eb6035
commit 587c788
Showing
23 changed files
with
635 additions
and
270 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
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,20 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [1.3.0] - 2024-11-22 | ||
|
||
### Added | ||
|
||
- (`epubReadingSystem`)[https://www.w3.org/TR/epub-rs-33/#app-epubReadingSystem] is available to publications. | ||
|
||
### Fixed | ||
|
||
- Ensure CSS-only locator ranges are correct, especially relevant when using the `go_text` command (#77). | ||
|
||
### Changed | ||
|
||
- The `ColumnSnapper` and `ScrollSnapper` report progress that now includes a reference progression – a.k.a. progression by a ReadiumWindow viewport – in addition to the current one (#62). |
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,67 +1,69 @@ | ||
import { Locator } from "@readium/shared"; | ||
import { TextQuoteAnchor } from "../vendor/hypothesis/anchoring/types"; | ||
|
||
function isReplacedLikeElement(element: Element): boolean { | ||
const tagName = element.tagName.toUpperCase(); | ||
return tagName === "IMG" || tagName === "VIDEO" || tagName === "AUDIO" || tagName === "IFRAME" || tagName === "OBJECT" || tagName === "EMBED" || tagName === "CANVAS"; | ||
} | ||
|
||
// Based on the kotlin-toolkit code | ||
export function rangeFromLocator(doc: Document, locator: Locator) { | ||
try { | ||
let locations = locator.locations; | ||
let text = locator.text; | ||
if (text && text.highlight) { | ||
let root; | ||
if (locations && locations.getCssSelector()) { | ||
root = doc.querySelector(locations.getCssSelector()!); | ||
} | ||
if (!root) { | ||
root = doc.body; | ||
} | ||
|
||
let anchor = new TextQuoteAnchor(root, text.highlight, { | ||
prefix: text.before, | ||
suffix: text.after, | ||
}); | ||
try { | ||
return anchor.toRange(); | ||
} catch (error) { | ||
// We don't watch to "crash" when the quote is not found | ||
console.warn("Quote not found:", anchor); | ||
return null; | ||
} | ||
} | ||
|
||
if (locations) { | ||
var element = null; | ||
|
||
if (!element && locations.getCssSelector()) { | ||
element = doc.querySelector(locations.getCssSelector()!); | ||
} | ||
|
||
if (!element && locations.fragments) { | ||
for (const htmlId of locations.fragments) { | ||
element = doc.getElementById(htmlId); | ||
if (element) { | ||
break; | ||
const locations = locator.locations; | ||
const text = locator.text; | ||
if (text && text.highlight) { | ||
let root; | ||
if (locations && locations.getCssSelector()) { | ||
root = doc.querySelector(locations.getCssSelector()!); | ||
} | ||
if (!root) { | ||
root = doc.body; | ||
} | ||
|
||
const anchor = new TextQuoteAnchor(root, text.highlight, { | ||
prefix: text.before, | ||
suffix: text.after, | ||
}); | ||
try { | ||
return anchor.toRange(); | ||
} catch (error) { | ||
// We don't watch to "crash" when the quote is not found | ||
console.warn("Quote not found:", anchor); | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
if (element) { | ||
let range = doc.createRange(); | ||
|
||
// This is a special case where the node is | ||
// a single element with no children. Not sure | ||
// yet how effective this is yet, may remove in future. | ||
if(element.childNodes.length === 0) { | ||
range.selectNodeContents(element); | ||
return range; | ||
} | ||
if (locations) { | ||
let element = null; | ||
|
||
range.setStartBefore(element); | ||
range.setEndAfter(element); | ||
return range; | ||
if (!element && locations.getCssSelector()) { | ||
element = doc.querySelector(locations.getCssSelector()!); | ||
} | ||
|
||
if (!element && locations.fragments) { | ||
for (const htmlId of locations.fragments) { | ||
element = doc.getElementById(htmlId); | ||
if (element) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (element) { | ||
const range = doc.createRange(); | ||
|
||
if (element.childNodes.length === 0 || isReplacedLikeElement(element)) { | ||
range.selectNode(element); | ||
return range; | ||
} | ||
|
||
range.setStartBefore(element); | ||
range.setEndAfter(element); | ||
return range; | ||
} | ||
} | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
console.error(e); | ||
} | ||
return null; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [1.3.0] - 2024-11-22 | ||
|
||
### Changed | ||
|
||
- `findNearestPosition` in the (`EPUBNavigator`)[https://github.com/readium/ts-toolkit/blob/develop/navigator/src/epub/EpubNavigator.ts] has been replaced by `findLastPositionInProgressionRange` and `findNearestPositions` (#62). | ||
- The Readium CSS dependency is now on the latest 1.x version, and added as a dependency using the `@readium/css` NPM package. |
Oops, something went wrong.