New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rangefix

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rangefix

Workaround for browser bugs in Range.prototype.getClientRects and Range.prototype.getBoundingClientRect.

  • 0.2.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
decreased by-5.81%
Maintainers
1
Weekly downloads
 
Created
Source

Workaround for browser bugs in Range.prototype.getClientRects and Range.prototype.getBoundingClientRect.

In particular:

  • Chrome <= 54: Selections spanning multiple nodes return rectangles for all the parents of the endContainer. See https://code.google.com/p/chromium/issues/detail?id=324437.
  • Chrome 55: Images get no rectangle when they are wrapped in a node and you select across them.
  • Safari: Similar to the Chrome <= 54 bug, but only triggered near the edge of a block node, or programmatically near an inline node.
  • Firefox: Similar to the Chrome <= 54 bug, but only triggered near the edge of a inline node
  • IE <= 10: Rectangles are incorrectly scaled when using the browser's zoom feature.
  • Chrome: Selection across a space which spans two lines results in a bounding rectangle which doesn't cover all the individual rectangles.
  • Firefox: Selections across a space which spans two lines, and text on the next line results in a bounding rectangle which doesn't cover all the individual rectangles.

There are no known issues in Chrome >= 56, Edge and IE >= 11. In these browsers the library will fall through to native behaviour.

Install

$ npm install rangefix

Usage

CommonJS

var RangeFix = require( 'rangefix' );

AMD

define( [ 'rangefix' ], function ( Rangefix ) {
	// ...
} );

Browser global

<script src="path/to/rangefix.js"></script>

API

Replace instances of Range.prototype.getClientRects/getBoundingClientRect with RangeFix.getClientRects/getBoundingClientRect:

var range = document.getSelection().getRangeAt( 0 );

// Before
var rects = range.getClientRects();
var boundingRect = range.getBoundingClientRect();

// After
var rects = RangeFix.getClientRects( range );
var boundingRect = RangeFix.getBoundingClientRect( range );

Demo

http://edg2s.github.io/rangefix/

FAQs

Package last updated on 07 Jan 2022

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