Git Product home page Git Product logo

mrkrjs's Introduction

MrkrJS

A simple highlighter utility for the browser

MrkrJS

Mrkr is a simple utility to apply arbitrary styles to highlighted text either using the native cursor or programmatically with a set of number offsets.

Installation

# npm
npm i mrkrjs

# yarn
yarn add mrkrjs

Usage

import Mrkr from 'mrkrjs';

// Create mrkr instance
const mrkr = new Mrkr(document.body, 'highlight');

Parameters

element

A target container element to apply highlighting to.

Note: Any HTMLElement works as a container, however using the body element can result in slower highlighting with larger pages.

className

The class name to apply to highlighted elements.

options (optional)

An object containing intialization parameters. The possible options are:

options.minimum number Default: undefined

The minimum amount of text that must be selected to apply highlights.

options.maximum number Default: undefined

The maximum amount of text that can be selected to apply highlights.

options.overlap boolean Default: false

Allow overlapping highlights.

options.onSelection (e, data) => void Default: undefined

Callback that's fired on selection with the cursor.

Methods

enabledSelection()

Enables the highlighter.

disabledSelection()

Disables the highlighter.

clear([ offsetTargets])

Clears a specific range of highlighted text if an array is passed, otherwise clears all highlighted text.

Parameters

offsetTargets:

{
  startOffset: number;
  endOffset: number;
}[]

setClassName(className)

Sets the current className applied to highlighted text.

parameters

className: string

getData()

Gets an array of data about the highlighted blocks of text.

Returns

{
  startOffset: number;
  endOffset: number;
  text: string;
  node: Text[];
}[]

setElement(element)

Set the highlighter's current container element.

Parameters

element: HTMLElement

highlight()

Applies the highlight class to the currently selected text.

Returns

{
  startOffset: number;
  endOffset: number;
  text: string;
  node: Text[];
}[]

highlightRange(startOffset, endOffset)

Applies the highlight class to the specified range of text offsets.

Parameters

startOffset: number endOffset: number

Returns

{
  startOffset: number;
  endOffset: number;
  text: string;
  node: Text[];
}[]

getSelectionEnabled()

Gets the current active state of the selection highlighter.

Returns

boolean

toggleSelection([ isEnabled])

Toggles the current active state of the selection highlighter or sets the passed enabled state.

Parameters

isEnabled: boolean

mrkrjs's People

Contributors

dependabot-preview[bot] avatar hodgef avatar tmarshall07 avatar dependabot-support avatar dependabot[bot] avatar anandchowdhary avatar lukasz-pluszczewski avatar

Stargazers

Guillermo avatar  avatar

Watchers

James Cloos avatar  avatar

mrkrjs's Issues

bin/postinstall is unnecessary

The bin/postinstall script is not necessary and will only pollute already noisy console log.

Also, this can be a vector of attack for malicious scripts injecting stuff into postinstall.

TypeScript types are not published to NPM

Lovely that the package is TypeScript-native.

But the benefits are lost, because the types prop is not defined in package.json.

See docs: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package

❯ tree node_modules/mrkrjs
node_modules/mrkrjs
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── bin
│   └── postinstall
├── build
│   ├── index.js
│   └── index.js.map
├── package.json
└── tsconfig.json

2 directories, 9 files

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.