npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dynamic-text-anchors

v1.5.7

Published

Dynamic Text Anchors

Downloads

36

Readme

DynamicTextAnchors (DTA)

NPM Version

Table of contents


Annotation

The thesis deals with the design of algorithms that would enable the storage of so-called text anchors (labels, notes etc.) in static and dynamic text (XML format) so that they can be re- inserted into the text even after its editing (and possibly evaluate the error during insertion). Such a program should then be usable as a library for e.g., web applications.

Important files

  1. LICENSE FILE

  2. DOCUMENTATION FILE

Installation

npm i dynamic-text-anchors

Technologies used

  • lib
    • TS
    • CSS
  • demo
    • Vue.JS
    • SCSS

How to use

import DTA from "dynamic-text-anchors";

const dta = new DTA(rootElement);

You can also import default styles:

import "dynamic-text-anchors/dist/lib/_styles.css";

DTA methods

createAnchorBlockFromSelection([selection])

Creates AnchorBlock/s from given selection or from the user's current selection. Selection must be contained within the configured rootNode. Multiple selection ranges are supported (Firefox).

removeAnchorBlocks([anchorBlocks], [destroy])

Removes the specified AnchorBlocks and their Anchors (or all, if none are specified). Accepts argument telling the function whether it should remove the Anchors from the AnchorBlock and if so, whether it should also remove them from the document either completely or "silently".

getTextNodeContainer(node)

Returns AnchorBlock containing specified textnode. If none of the AnchorBlocks is an ancestor, returns null.

sort()

Sorts AnchorBlocks by their position in the document by comparing position of the last Anchor and first Anchor of following AnchorBlocks. This method sorts in-place and expects, that individual AnchorBlock's Anchors are sorted.

serialize()

Returns the DTA data serialized in JSON object format ready to be saved.

deserialize(data)

Attempts to reconstruct AnchorBlocks and Anchors from the given data in JSON object format.


The following methods are not intended for stand-alone use (but only through DTA), but are described here for a better understanding of the mechanisms.

AnchorBlock methods

createAnchor(node, startOffset, endOffset)

Creates Anchor in specified node at specified offsets, that must be contained in the node. Returns the created Anchor.

joinAnchors()

Helper function that sorts AnchorBlock's Anchors in-place, sets the focusable Anchor, merges connecting Anchors if possible, sets aria-label and connects the Anchors internally via leftJoin and rightJoin properties.

removeAnchors([anchors], [destroy])

Removes the specified Anchors (or all, if none are specified). Accepts argument telling the function whether it should remove the Anchors from the AnchorBlock and if so, whether it should also remove them from the document either completely or "silently".

setFocused(focused, [anchors])

Adds or removes focus from specified Anchors (or all, if none are specified).

merge(to)

Attempts to merge AnchorBlock with following or preceding AnchorBlock (specified by parameter "left" or "right"). Both of the AchorBlocks must be touching. The merging AnchorBlock overrides, when there is conflict in properties and/or data.

serialize()

Returns the AnchorBlock data serialized in JSON object format ready to be saved.


Anchor methods

destroy()

Silently removes the Anchor from the document (= replace itself by textnode with it's value).

setChanged(changed)

Adds or removes data-changed attribute of Anchor.

setFocused(focused)

Adds or removes focus and data-focused attribute of Anchor.

color(color)

Sets the background color of Anchor.

serialize()

Returns the Anchor data serialized in JSON object format ready to be saved.


Utility methods

getPathFromNode(rootNode, node)

Returns the xPath string from rootNode to node.

getNodeFromPath(rootNode, xPath, resType)

Evaluates the xPath - starting from the rootNode and returns it in the desired XPathResult type.

getAllTextNodes(rootNode)

Returns all text nodes in the rootNode.

getConnectingTextNodes(rootNode, boundaryTextNode)

Returns all text nodes in the rootNode, that are connecting to the boundaryTextNode (result includes both directions).

normalizeString(str)

Returns the string in the normalized form - without diacritics, special symbols, with trimmed spaces and in lowercase.

nodePositionComparator(x, y)

Returns the evaluated result of Node.compareDocumentPosition() method.

splitArrayToChunks(array, del)

Splits given array into array of smaller chunks by the giver delimiter.

isValidHexColor(hex)

Checks if the given hex color is valid.

invertHexColor(hex)

Returns #ffffff or #000000 depending on the contrast with the given hex color.