npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

word-marker

v1.1.15

Published

The library used to tag web page text, which can store tag information.

Downloads

67

Readme

work-marker

word-marker is a library used to tag web page text, which can store tag information.

Support for custom tag styles, highlighting, and more

demo

在线地址

import wordMarker from "word-marker";

document.querySelector<HTMLDivElement>("#app")!.innerHTML = "文本标记";

const wMarker = wordMarker(document.querySelector<HTMLDivElement>("#app")!, {
  data: [],
});

Options

type MarkOptions = {
  // 是否懒加载,默认为高度超过窗口 4 倍开启
  lazy?: boolean;
  // 滚动元素, 如果懒加载开启则默认为 document
  scrollBy?: HTMLElement | Document;
  // 标记元素指定的唯一属性字段
  attribute?: string;
  // 标记的样式
  color?: string;
  // 标记的透明度
  globalAlpha?: number;
  // 层级
  zIndex?: number;
  // 标记的数据
  data?: MarkData[];
  // 初始化时处理所有元素
  tag?: (node: HTMLElement) => void;
  // 是否忽略某个元素
  ignoreNode?: (node: ChildNode) => boolean;
  // 划词回调
  callback?: (data?: MarkData, range?: Range) => void;
  // 自定义标记的样式
  mark?: (ctx: CanvasRenderingContext2D, range: Range) => void;
  // 高亮标记的样式
  highlight?: (ctx: CanvasRenderingContext2D, range: Range) => void;
};

Returns

function wordMarker(
  container: HTMLElement,
  options: MarkOptions
): {
  /**
   * 自动标记数据
   * @param ele
   * @param text
   */
  selectText(ele: HTMLElement, text: string): void;
  /**
   * 触发标记动作
   */
  triggerMarker(): void;
  /**
   * 获取所有的实际标记数据
   * @returns 获取标记数据
   */
  getActualMarkData(): MarkData[];
  /**
   * 获取所有的标记数据
   * @returns 获取标记数据
   */
  getMarkData(): MarkData[];
  /**
   * 添加标记
   * @param data
   */
  addMark(data: MarkData | MarkData[]): void;
  /**
   * 修改标记备注
   * @param id
   * @param msg
   */
  modifyMark(id: string, msg: string): void;
  /**
   * 根据 ID 获取标记位置
   * @param id
   * @returns
   */
  getPosition(id: string): { x: number; y: number } | undefined;
  /**
   * 根据 ID 删除标记
   * @param id
   */
  deleteMark(id: string | string[]): void;
  /**
   * 根据 x y 获取该位置是否有标记
   * @param x
   * @param y
   * @returns
   */
  checkMark(x: number, y: number): MarkData | undefined;
  /**
   * 高亮标记
   * @param id
   */
  highlightMark(id?: string): void;
  /**
   * 重新刷新标记
   */
  refresh(): void;
  /**
   * 清除所有标记
   */
  clear(): void;
  /**
   * 销毁所有事件
   */
  destory(): void;
};