All Projects → RazrFalcon → svgdom

RazrFalcon / svgdom

Licence: other
Library to represent an SVG as a DOM.

Programming Languages

rust
11053 projects
python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to svgdom

hotshot
Takes screenshots of DOM elements
Stars: ✭ 19 (-36.67%)
Mutual labels:  dom
Dom
Modern DOM API.
Stars: ✭ 88 (+193.33%)
Mutual labels:  dom
dom-navigator
⚓️ JS library that allow keyboard navigation through DOM elements (←↑→↓).
Stars: ✭ 36 (+20%)
Mutual labels:  dom
shaven
DOM building utility & Template engine based on JsonML + syntax sugar
Stars: ✭ 66 (+120%)
Mutual labels:  dom
html-dom-parser
📝 HTML to DOM parser.
Stars: ✭ 56 (+86.67%)
Mutual labels:  dom
Prakma
Prakma is a framework to make applications using JSX, focusing on writing functional components.
Stars: ✭ 16 (-46.67%)
Mutual labels:  dom
texthighlighter
a no dependency typescript npm package for highlighting user selected text
Stars: ✭ 17 (-43.33%)
Mutual labels:  dom
lish
Javascript Selection Object Library
Stars: ✭ 14 (-53.33%)
Mutual labels:  dom
theroomjs
A vanilla javascript plugin that allows you to outline dom elements like web inspectors
Stars: ✭ 53 (+76.67%)
Mutual labels:  dom
xmlresolver
The xmlresolver project provides an advanced implementation of the SAX EntityResolver (and extended EntityResolver2), the Transformer URIResolver, the DOM LSResourceResolver, the StAX XMLResolver, and a new NamespaceResolver. It uses the OASIS XML Catalogs V1.1 Standard to provide a mapping from external identifiers and URIs to local resources.
Stars: ✭ 31 (+3.33%)
Mutual labels:  dom
fox
A Fortran XML library
Stars: ✭ 51 (+70%)
Mutual labels:  dom
page-content-tester
Paco is a Java based framework for non-blocking and highly parallelized Dom testing.
Stars: ✭ 13 (-56.67%)
Mutual labels:  dom
scrollparent.js
A function to get the scrolling parent of an html element.
Stars: ✭ 51 (+70%)
Mutual labels:  dom
micell
A collection of functions for front-end development
Stars: ✭ 16 (-46.67%)
Mutual labels:  dom
pablopunk.com
Blazing fast personal website with Jamstack
Stars: ✭ 16 (-46.67%)
Mutual labels:  dom
XrayDOM
🔥 X-ray your DOM using just the cursor and never open the console again!
Stars: ✭ 13 (-56.67%)
Mutual labels:  dom
notes
Notas sobre JavaScript Full Stack
Stars: ✭ 70 (+133.33%)
Mutual labels:  dom
replace-jquery
Automatically finds jQuery methods from existing projects and generates vanilla js alternatives.
Stars: ✭ 1,101 (+3570%)
Mutual labels:  dom
preact-delegate
Preact delegate DOM events
Stars: ✭ 17 (-43.33%)
Mutual labels:  dom
ElementFinder
Fetch data from HTML and XML via xpath/css and prepare it with regexp
Stars: ✭ 29 (-3.33%)
Mutual labels:  dom

svgdom

Build Status Crates.io Documentation

svgdom is an SVG Full 1.1 processing library, which allows you to parse, manipulate, generate and write an SVG content.

Deprecation

This library was an attempt to create a generic SVG DOM which can be used by various applications. But it the end it turned out that it's easier and faster to use roxmltree + svgtypes to extract only the data you need.

There are two main problems with svgdom:

  1. You can't make a nice API with a Vec-based tree and you can't have a safe API with an Rc-tree.

    The current implementation uses so-called Rc-tree, which provides a nice API, but all the checks are done in the runtime, so you can get a panic quite easily. It's also hard/verbose to make immutable nodes. You essentially need two types of nodes: one for immutable and one for mutable "references". A Vec-based tree would not have such problems, but you can't implement the simplest operations with it, like copying an attribute from one node to another since you have to have a mutable and an immutable references for this. And Rust forbids this. So you need some sort of generational indexes and so on. This solution is complicated in its own way. Performance is also in question, since inserting/removing an object in the middle of a Vec is expensive.

  2. The SVG parsing itself is pretty complex too. There are a lot of ways you can implement it.

    svgdom creates a custom Rc-tree where all the attributes are stored as owned data. This requires a lot of allocations (usually unnecessary). The parsing/preprocessing algorithm itself can be found in docs/preprocessor.md The problem with it is that you can't tweak it. And in many cases, it produces results that you do not need or do not expect. svgdom was originally used by svgcleaner and resvg and both of these projects are no longer using it.

Purpose

svgdom is designed to simplify generic SVG processing and manipulations. Unfortunately, an SVG is very complex format (PDF spec is 826 pages long), with lots of features and implementing all of them will lead to an enormous library.

That's why svgdom supports only a static subset of an SVG. No scripts, external resources and complex CSS styling. Parser will convert as much as possible data to a simple doc->elements->attributes structure.

For example, the fill parameter of an element can be set: as an element's attribute, as part of a style attribute, inside a style element as CSS2, inside an ENTITY, using a JS code and probably with lots of other methods.

Not to mention, that the fill attribute supports 4 different types of data.

With svgdom you can just use node.has_attribute(AttributeId::Fill) and don't worry where this attribute was defined in the original file.

Same goes for transforms, paths and other SVG types.

The main downside of this approach is that you can't save an original formatting and some data.

See the preprocessor doc for details.

Benefits

  • The element link(IRI, FuncIRI) is not just a text, but an actual link to another node.
  • At any time you can check which elements linked to the specific element. See Node's doc for details.
  • Support for many SVG specific data types like paths, transforms, IRI's, styles, etc. Thanks to svgtypes.
  • A complete support of text nodes: XML escaping, xml:space.
  • Fine-grained control over the SVG output.

Limitations

  • Only SVG elements and attributes will be parsed.
  • Attribute values, CDATA with CSS, DOCTYPE, text data and whitespaces will not be preserved.
  • UTF-8 only.
  • Only most popular attributes are parsed, other stored as strings.
  • No compressed SVG (.svgz). You should decompress it by yourself.
  • CSS support is minimal.
  • SVG 1.1 Full only (no 2.0 Draft, Basic, Tiny subsets).

Differences between svgdom and SVG spec

  • Library follows SVG spec in the data parsing, writing, but not in the tree structure.
  • Everything is a Node. There are no separated ElementNode, TextNode, etc. You still have all the data, but not in the specific struct's. You can check the node type via Node::node_type().

Dependency

Rust >= 1.32

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].