@linalgo/annotate-core
Advanced tools
Comparing version 0.0.13 to 0.0.14
{ | ||
"name": "@linalgo/annotate-core", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "A library for html document annotations following W3C standards.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -12,3 +12,3 @@ export * from './annotators'; | ||
// const annotator = new Annotator(document, 'b'); | ||
// const annotator = new Annotator(document, 'mark'); | ||
// function highlight(range: Range) { | ||
@@ -15,0 +15,0 @@ // const annotation = annotator.createAnnotation(range, 'test', 'test', document.URL, 'test'); |
@@ -8,2 +8,6 @@ import { XPathSelection } from './selection'; | ||
this.range = range; | ||
const startContainer = getPathTo(range.startContainer, rootNode, this.ignoreNodeName) | ||
const endContainer = getPathTo(range.endContainer, rootNode, this.ignoreNodeName) | ||
const startOffset = getNormalizedOffset(range.startContainer, range.startOffset, this.ignoreNodeName) | ||
const endOffset = getNormalizedOffset(range.endContainer, range.endOffset, this.ignoreNodeName) | ||
this.selection = { | ||
@@ -28,3 +32,3 @@ startContainer: getPathTo(range.startContainer, rootNode, this.ignoreNodeName), | ||
return this.range; | ||
} catch(e) { | ||
} catch (e) { | ||
throw new Error(`Could not find node with selection ${selection}`); | ||
@@ -66,4 +70,6 @@ } | ||
while (!node.isSameNode(fromNode)) { | ||
if (node.nodeType != Node.TEXT_NODE && nodeName(node) !== ignoreNodeName) { | ||
path = `/${nodeName(node)}[${nodePosition(node)}]${path}`; | ||
if (node.nodeType != Node.TEXT_NODE) { | ||
if (nodeName(node) !== ignoreNodeName) { | ||
path = `/${nodeName(node)}[${nodePosition(node)}]${path}`; | ||
} | ||
} | ||
@@ -89,5 +95,5 @@ node = node.parentNode; | ||
function getNormalizedOffset(node: Node, offset: number, ignoreNodeName: string): number { | ||
let parentNode = node.parentNode; | ||
let parentNode = node; | ||
while (parentNode.nodeType == node.TEXT_NODE || nodeName(parentNode) == ignoreNodeName) { | ||
parentNode = node.parentNode; | ||
parentNode = parentNode.parentNode; | ||
} | ||
@@ -94,0 +100,0 @@ let newOffset = 0; |
Sorry, the diff of this file is too big to display
2403369
1447