range_fix 0.1.2+1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 0

range_fix

A workaround for the Range.getClientRects bug in Chrome. A dart port of rangefix.

Usage

A simple usage example:

final range = window.getSelection().getRangeAt(0);

final rects = RangeFix.getClientRects(range);
for (final rect in rects) {
  // Do whatever you want.
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

Changelog

0.1.2+1

  • Change the repo URL.

0.1.2

  • Fix a type error which occurs in checked mode.

0.1.1

  • Sort the rects of getClientRects() in content order

0.1.0

  • Initial version

example/range_fix.dart

// Copyright (c) 2015, Kwang Yul Seo. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

library range_fix.example;

import 'dart:html';
import 'dart:math';

import 'package:color/color.dart';
import 'package:range_fix/range_fix.dart';

final Random randomGen = new Random();

String randomColor() {
  final r = randomGen.nextInt(256);
  final g = randomGen.nextInt(256);
  final b = randomGen.nextInt(256);
  return new RgbColor(r, g, b).toCssString();
}

void renderRects(List<Rectangle> rects) {
  for (final rect in rects) {
    final element = new DivElement();
    element.style
      ..backgroundColor = randomColor()
      ..opacity = '0.5'
      ..position = 'fixed'
      ..top = new Dimension.px(rect.top).toString()
      ..left = new Dimension.px(rect.left).toString()
      ..width = new Dimension.px(rect.width).toString()
      ..height = new Dimension.px(rect.height).toString();
    document.body.append(element);
  }
}

void main() {
  querySelector('#broken').innerHtml = '${isGetClientRectsBroken()}';

  final p1 = querySelector('#p1');
  final p2 = querySelector('#p2');
  final p3 = querySelector('#p3');
  final p4 = querySelector('#p4');

  final beforeRange = new Range()
    ..setStart(p1.firstChild, 3)
    ..setEnd(p2.firstChild, 3);

  final afterRange = new Range()
    ..setStart(p3.firstChild, 3)
    ..setEnd(p4.firstChild, 3);

  renderRects(beforeRange.getClientRects());
  renderRects(RangeFix.getClientRects(afterRange));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  range_fix: ^0.1.2+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:range_fix/range_fix.dart';
  
Version Uploaded Documentation Archive
0.1.2+1 Mar 7, 2016 Go to the documentation of range_fix 0.1.2+1 Download range_fix 0.1.2+1 archive
0.1.2 Mar 7, 2016 Go to the documentation of range_fix 0.1.2 Download range_fix 0.1.2 archive
0.1.1 Nov 25, 2015 Go to the documentation of range_fix 0.1.1 Download range_fix 0.1.1 archive
0.1.0 Nov 23, 2015 Go to the documentation of range_fix 0.1.0 Download range_fix 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.0.0 <2.0.0