New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@linalgo/annotate-core

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@linalgo/annotate-core - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

linalgo-annotate-core-0.0.7.tgz

11

dist/annotators/annotator.d.ts

@@ -5,9 +5,14 @@ import { Selection } from '../selectors';

private tag;
nodeMap: Node[][];
annotationMap: {
[id: string]: Annotation;
};
nodeMap: {
[id: string]: Node[];
};
constructor(tag: string);
getTextNodes(node: Node): Node[];
getSubRanges(range: Range): Range[];
createAnnotation(rs: Range | Selection, task: string, entity: string, document: string): Annotation;
createAnnotation(rs: Range | Selection, task: string, entity: string, document: string, body?: string): Annotation;
showAnnotation(annotation: Annotation): Node[];
hideAnnotation(annotation: Annotation): void;
hideAnnotation(annotationId: string): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var uuid = require("uuid");
var selectors_1 = require("../selectors");

@@ -7,3 +8,4 @@ var Annotator = /** @class */ (function () {

this.tag = tag;
this.nodeMap = [];
this.annotationMap = {};
this.nodeMap = {};
}

@@ -53,6 +55,11 @@ Annotator.prototype.getTextNodes = function (node) {

};
Annotator.prototype.createAnnotation = function (rs, task, entity, document) {
Annotator.prototype.createAnnotation = function (rs, task, entity, document, body) {
if (body === void 0) { body = null; }
var selector = selectors_1.SelectorFactory.getBestSelector(rs, this.tag);
if (!body) {
body = rs.toString();
}
var annotation = {
body: "",
id: uuid.v4(),
body: body,
task: task,

@@ -66,2 +73,3 @@ entity: entity,

};
this.annotationMap[annotation.id] = annotation;
return annotation;

@@ -74,17 +82,18 @@ };

var newNodes = [];
annotation.nodeMapIndex = this.nodeMap.length;
this.nodeMap.push([]);
for (var _i = 0, _a = this.getSubRanges(range); _i < _a.length; _i++) {
var subRange = _a[_i];
var newNode = document.createElement(this.tag);
newNode.annotation = annotation;
newNode.setAttribute('annotation', annotation.id);
subRange.surroundContents(newNode);
newNodes.push(newNode);
this.nodeMap[annotation.nodeMapIndex].push(newNode);
}
this.nodeMap[annotation.id] = newNodes;
if (!this.annotationMap[annotation.id]) {
this.annotationMap[annotation.id] = annotation;
}
range.commonAncestorContainer.normalize();
return newNodes;
};
Annotator.prototype.hideAnnotation = function (annotation) {
for (var _i = 0, _a = this.nodeMap[annotation.nodeMapIndex]; _i < _a.length; _i++) {
Annotator.prototype.hideAnnotation = function (annotationId) {
for (var _i = 0, _a = this.nodeMap[annotationId]; _i < _a.length; _i++) {
var node = _a[_i];

@@ -91,0 +100,0 @@ var parent = node.parentNode;

{
"name": "@linalgo/annotate-core",
"version": "0.0.6",
"version": "0.0.7",
"description": "A library for html document annotations following W3C standards.",

@@ -26,4 +26,6 @@ "main": "./dist/index.js",

"dependencies": {
"@types/uuid": "^3.4.4",
"ts-loader": "^4.2.0",
"typescript": "^2.8.3"
"typescript": "^2.8.3",
"uuid": "^3.3.2"
},

@@ -30,0 +32,0 @@ "repository": {

@@ -0,9 +1,10 @@

import * as uuid from 'uuid';
import { Selection, SelectorFactory } from '../selectors'
import { Annotation } from './annotation';
export class Annotator {
nodeMap: Node[][] = [];
annotationMap: { [id: string]: Annotation } = {};
nodeMap: { [id: string]: Node[] } = {};

@@ -53,6 +54,10 @@ constructor(private tag: string) { }

createAnnotation(rs: Range | Selection, task: string, entity: string, document: string): Annotation {
createAnnotation(rs: Range | Selection, task: string, entity: string, document: string, body: string = null): Annotation {
let selector = SelectorFactory.getBestSelector(rs, this.tag);
if (!body) {
body = rs.toString();
}
const annotation = {
body: "",
id: uuid.v4(),
body: body,
task: task,

@@ -66,2 +71,3 @@ entity: entity,

}
this.annotationMap[annotation.id] = annotation;
return annotation;

@@ -75,11 +81,12 @@ }

const newNodes: Node[] = [];
annotation.nodeMapIndex = this.nodeMap.length;
this.nodeMap.push([]);
for (const subRange of this.getSubRanges(range)) {
const newNode = document.createElement(this.tag);
(newNode as any).annotation = annotation;
newNode.setAttribute('annotation', annotation.id);
subRange.surroundContents(newNode);
newNodes.push(newNode);
this.nodeMap[annotation.nodeMapIndex].push(newNode);
}
this.nodeMap[annotation.id] = newNodes;
if (!this.annotationMap[annotation.id]) {
this.annotationMap[annotation.id] = annotation;
}
range.commonAncestorContainer.normalize();

@@ -89,4 +96,4 @@ return newNodes;

hideAnnotation(annotation: Annotation) {
for (const node of this.nodeMap[annotation.nodeMapIndex]) {
hideAnnotation(annotationId: string) {
for (const node of this.nodeMap[annotationId]) {
var parent = node.parentNode;

@@ -93,0 +100,0 @@ while (node.firstChild) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc