lukasrada / rangee Goto Github PK
View Code? Open in Web Editor NEWSerialize/deserialize Range in HTML.
License: MIT License
Serialize/deserialize Range in HTML.
License: MIT License
And mainly include the statement that rangee is not implementation for text highlighting.
Compilation is dependant on webpack - that is IMHO nonsense for now.
When I try to import this package with Vite, I get the following error:
[plugin:vite:import-analysis] Failed to resolve entry for package "rangee". The package may have incorrect
main/module/exports specified in its package.json: Failed to resolve entry for package "rangee". The package may have
incorrect main/module/exports specified in its package.json.
For using in production environment is needed to have clean & useable output (/dist).
Is webpack really need? Maybe only for demo.
Serialization of Range is determined by selector value relatively to body element.
Deserialization should return Range with same values (startContainer, startOffset, endContainer, endOffeset).
Moreover there should be serialization of range where no inner range contains any HTML element. Thus range must contains only text nodes. It requires to walk the DOM tree and to array these atomic ranges.
Thus: Atomic range => range only with text nodes.
Then these atomic ranges can be serialized and deserialized back.
When serializing content of the demo atomic:
xZrBjtowEIbfJadWYqV4PHG8HPIwYFagIkK7caUV5d2XLRzqgMgl3/SSQxTN78znsX9ncqreq+Xp61Kt+vTRvW/Ww64/LA/D9qV/exk+jptv8r1Lu9/FLb2/dXlqK9WiWlfLelH1l+t5UW2o4Nqez39OMw7+GlyAkf8b+XXmUXdHMONFbBdk9rF3K3L0ZfSmgVIvYOqvsR0y1RWb6spM9X4PzpYyuPPzD77b79Dxj+K3kcq/kPkXMv8PZyuH44mcqx2FR0k8aobH2+Ip5ZpA0QkknWBGR23p6Kh4hMITSTzRDE9ji6eUE4yOQ7d+V5vxCbZ8SrlWMT6oNXDMEYpbl4tFuZ476Zm0wxm2wxm2w3fx5z/+ZdIOZ9gOZ1s7PCXXYnSUpKNmdLwtnVIuKkUnkHSCGR21pTNywy5QeCKJJ5rhaWzxNLDbyqgbzrQbzrZueEruFasehzoD1A1HzA1HyA1vPdl68uXnhwZJOlLPRej5u092FvKZlG/pF2M7VU/FtLWhJnbUrlJC1RHXxIUW3W6179c/fuZ+2IDT7LGIU89Q4PqLt9DAJiJ269lTLQ8x4b5y3ULDO4y322E8/E17rGa4w4zFvBE1saN2W6cNqP0vBzShrY0NU7VjquDPMI478dxCz97vP/4izcIoujhl/rfjzjxSQy4hkY2XBDde0r5LQ5feDug7PNAQR3EQkoOAHBLMILH/gyWyxZLgFsvfOXp3ky+LCUmHUQokpUBWiZ3DmpLzStGJJJ1oVkPevobuJV1LUXLolu9qsyrytlVUyoWLE/gE
That is 796 chars.
I think it should be better.
Fails when range.commonAncestorContainer == range.startContainer in index.ts. startFound is always False.
An example of when this happens is selecting the range at the top of this page to the end.
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<script src="script.js" type="module"></script>
</head>
<body class="whatever">
<br/>
<br/>
start
<span>end</span>
</body>
</html>
Naive fix: (not sure if there are side effects, still testing)
Change:
let node: Node | null;
while (node = treeWalker.nextNode()) {
...
}
To:
let node = treeWalker.root;
do {
...
} while (node = treeWalker.nextNode());
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.