Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

morphlex

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

morphlex

A tiny, optimal DOM morphing library written in TypeScript.

  • 0.0.16
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
8.9K
decreased by-26.17%
Maintainers
1
Weekly downloads
 
Created
Source

Morphlex

Morphlex is a tiny, optimal DOM morphing library written in TypeScript. DOM morphing is the process of transforming one DOM tree to reflect another, while preserving the state of the original tree and making as few changes as possible.

Morphlex uses ID Sets — a concept pioneered by Idiomorph — to match nodes with deeply nested identified elements. It also maps out sensitive elements to avoid moving them around.

ID Sets

Each element is tagged with the set of IDs it contains, allowing for more optimal matching.

Failing an ID Set match, Morphlex will search for the next best match by tag name. If no element can be found, the reference element will be deeply cloned instead.

Node sensitivity

Simply moving certain elements in the DOM tree can cause issues. To account for this, Morphlex gives priority to sensitive elements, moving less sensitive elements around them whenever possible.

This works in any direction, even if the sensitive element is deeply nested.

Try it out

The easiest way to try out Morphlex is to import it directly from UNPKG.

<script type="module">
  import { morph } from "https://www.unpkg.com/morphlex@0.0.15/dist/morphlex.min.js";

  morph(currentNode, referenceNode);
  morphInner(currentNode, referenceNode);
</script>

Alternatively, you can install it via npm and import it into your project.

npm install morphlex --save
import { morph } from "morphlex";

morph(currentNode, referenceNode);

The currentNode will be morphed into the state of the referenceNode. The referenceNode will not be mutated in this process.

Contributing

If you find a bug or have a feature request, please open an issue. If you want to contribute, please open a pull request.

[!TIP] Morphlex is written in TypeScript because it helps us avoid a whole category of potential bugs. If you’re more comfortable writing JavaScript, you’re very welcome to open a Pull Request modifying the dist/morphlex.js file. I’m happy to take care of the TypeScript conversion myself. — Joel

FAQs

Package last updated on 12 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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