Giter Club home page Giter Club logo

dom-movement's Introduction

dom-movement

This library provides a simple means to move from position to position in a DOM tree. It works with XML and HTML DOM trees.

General Principles

Relevance

The primary goal of this library is to model movements among the characters of a document that are visible to the end user. What this means in practice varies from use-case scenario to use-case scenario. For instance, in some cases, element attributes may correspond to text visible to the user, and in many other cases it won't.

This library's implementation aims to strike a balance between an extremely general implementation that would allow movement suitable for all usage scenarios, but which would increase code complexity and development time (and probably run into YAGNI), and too specialized an implementation that ends up not being useful except in a few specialized cases.

This library is able to move through:

  • text nodes,
  • elements,
  • documents,
  • document fragments.

The other types of DOM elements are deemed "irrelevant" and skipped.

You can add to the list of irrelevant nodes (by using the relevanceTest parameter of DOMSpace's constructor). For instance, you could decide that all nodes that are invisible due to their CSS style are irrelevant, and they would also be skipped. However, you cannot remove from the list shown above. The library provides no sanctioned way, for instance, to deem attribute notes relevant and move through them.

Intrinsic Node Relevance

Intrinsic relevance is determined by two tests that the node must pass:

  • An internal test performed by the DOMSpace implementation. This test only deems elements, text nodes, document nodes and document fragments as intrinsicly relevant.

  • If the internal test is successfull (i.e. the node was deemed intrinsically relevant), then the relevanceTest provided to the constructor, if provided, is used.

The internal test cannot be overruled by relevanceTest. You could overrule it by overriding it in a derived class but doing so is not supported. You would have to override other methods of DOMSpace in order to prevent it from crashing.

Notation

In the following examples, we will use the notation <tag_i> indicate that the element tag is intrinsically irrelevant. The absence of _i means that the element is contextually relevant. Note that the suffix merely indicates irrelevance and is not actually part of the element name.

Contextual Node Relevance

A node is contextually relevant if the node and all its ancestor nodes within the space are intrinsically relevant. Consider this tree:

<div_i>
 <p>Foo</p>
</div_i>

In this example the div element is intrinsically irrelevant. The element p is deemed intrinsically relevant. However, it would still would be contextually irrelevant because its parent is intrinsically irerelevant.

Location Relevance

Similarly, locations are relevant or irrelevant. (There is no distinction between intrinsic and contextual irrelevance for locations.) A relevant location is a location into a contextually relevant node. An irrelevant location is a location into a contextually irrelevant node. Note that a relevant location can point to an irrelevant node.

Consider this tree:

<div>
 <p_i>Foo</p_i>
</div>

The location (p, 0) points to the text node inside the paragraph. Since the paragraph is intrinsically irrelevant, the text node in it is contextually irrelevant, and the location is irrelevant too.

The location (div, 1) points to the element p in div. (The offset is 1, because at offset 0 there is a text node containing whitespace.) Although this location points to an intrinsically irrelevant node, the location itself is relevant because it is a location div, which is contextually relevant.

Reversibility

Suppose two locations A and B in a DOMSpace. When iterating over the positions from A to B, you get intermediary positions P1, P2, P3. If you iterate from B to A then the intermediary positions will be P3, P2, P1.

dom-movement's People

Contributors

dependabot[bot] avatar lddubeau avatar renovate-bot avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

dom-movement's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Using npm packages for Renovate presets is now deprecated. Please migrate to repository-based presets instead.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm tslint Unavailable

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • build(deps): update dependency karma-coverage-istanbul-instrumenter to ^1.0.4
  • build(deps): update dependency eslint to ^7.32.0
  • build(deps): update dependency eslint-config-lddubeau-base to ^6.1.0
  • build(deps): update dependency eslint-plugin-import to ^2.29.1
  • build(deps): update dependency karma-chrome-launcher to ^3.2.0
  • build(deps): update dependency sinon-chai to ^3.7.0 (sinon-chai, @types/sinon-chai)
  • build(deps): update dependency terser to ^5.31.1
  • build(deps): update dependency @types/sinon to v17
  • build(deps): update dependency chai to v5
  • build(deps): update dependency eslint to v9
  • build(deps): update dependency eslint-plugin-simple-import-sort to v12
  • build(deps): update dependency husky to v9
  • build(deps): update dependency karma-serve-static-map to v3
  • build(deps): update dependency mocha to v10 (mocha, @types/mocha)
  • build(deps): update dependency sinon to v18
  • build(deps): update dependency typescript to v5
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

npm
package.json
  • @commitlint/cli ^9.1.2
  • @commitlint/config-angular ^9.1.2
  • @types/chai ^4.2.14
  • @types/mocha ^8.0.3
  • @types/sinon ^9.0.8
  • @types/sinon-chai ^3.2.5
  • chai ^4.2.0
  • eslint ^7.14.0
  • eslint-config-lddubeau-base ^6.0.0
  • eslint-plugin-import ^2.22.1
  • eslint-plugin-jsx-a11y ^6.3.1
  • eslint-plugin-prefer-arrow ^1.2.2
  • eslint-plugin-react ^7.21.5
  • eslint-plugin-simple-import-sort ^5.0.3
  • husky ^4.3.5
  • karma ^5.2.3
  • karma-browserstack-config ^1.0.1
  • karma-browserstack-launcher ^1.6.0
  • karma-chrome-launcher ^3.1.0
  • karma-coverage-istanbul-instrumenter ^1.0.3
  • karma-coverage-istanbul-reporter ^3.0.3
  • karma-firefox-launcher ^1.3.0
  • karma-mocha ^2.0.1
  • karma-mocha-reporter ^2.2.5
  • karma-serve-static-map ^2.0.0
  • karma-source-map-support ^1.4.0
  • karma-typescript-agile-preprocessor ^2.1.3
  • mocha ^8.1.3
  • renovate-config-lddubeau ^1.0.0
  • sinon ^9.2.1
  • sinon-chai ^3.5.0
  • systemjs ^0.21.6
  • terser ^5.3.6
  • tslint ^6.1.2
  • tslint-config-lddubeau ^4.1.2
  • typescript ^4.0.3
travis
.travis.yml

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.