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

common-rte

v1.0.28

Published

Multi-Page Rich Text Editor for Web

Downloads

27

Readme

Common RTE

A multi-page rich text editor for the web. It leverages fontkit and Konva for text rendering as well as shape rendering on the canvas. The coexistence of freely positioned shapes and text, along with the multi-page rendering, are essential features of this editor. This is intended to replicate a Google Docs experience, while for a Notion-like experience I would recommend Lexical.

It also makes use of a Rope data structure, IntervalTree, and LayoutTree to assure that no characters are dropped while typing quickly and that layout operations can be cached in a way that is decoupled from other data safely.

Features:

  • Bold, italics, underline and other formatting
  • Visuals including rectangles, circles, and images
  • Restore from Markdown (partially implemented)
  • Restore from JSON for complex formatting
  • 100ms or less response times in many cases

Example Usage

<div id="cmnToolbarPrimary" class="toolbar">
          <label>Alter Text:</label>
          <button id="cmnColor">Color</button>
          <select id="cmnFontSize">
            <option value="10">10</option>
            <option value="14">14</option>
            <option value="16">16</option>
            <option value="18">18</option>
            <option value="24">24</option>
            <option value="36">36</option>
            <option value="48">48</option>
          </select>
          <button id="cmnBold">Bold</button>
          <button id="cmnItalic">Italic</button>
          <button id="cmnUnderline">Underline</button>
          <label>Add Visuals:</label>
          <button id="cmnCircle">Circle</button>
          <button id="cmnRectangle">Rectangle</button>
          <button id="cmnImageButton">Image</button>
          <input id="cmnImageFile" type="file" class="hidden" />
          <span>Last Saved:</span>
          <span id="cmnLastSaved"></span>
        </div>
        <div id="cmnToolbarShape" class="toolbar">
          <label>Shape Properties:</label>
          <label>Width</label>
          <input id="cmnShapeWidth" type="text" name="width" />
          <label>Height</label>
          <input id="cmnShapeHeight" type="text" name="height" />
          <button id="cmnShapeColor">Color</button>
        </div>
        <div id="cmnContainer"></div>
        <script type="module" src="./src/index.ts"></script>
        <style>
            @font-face {
              font-family: "Inter";
              src: url("./src/assets/fonts/Inter-Regular.ttf");
              font-weight: normal;
              font-style: normal;
            }
            @font-face {
              font-family: "Oswald";
              src: url("./src/assets/fonts/Oswald[wght].ttf");
              font-weight: normal;
              font-style: normal;
            }
            .toolbar {
              display: flex;
              flex-direction: row;
              gap: 5px;
              position: fixed;
              top: 0;
              left: 0;
              z-index: 2;
            }
            .hidden {
              display: none;
            }
            body {
              padding: 25px 0;
            }
          </style>
          <div className="preloadFont" style="font-family: 'Inter'">
            .
          </div>
          <div className="preloadFont" style="font-family: 'Oswald'">
            .
          </div>
          <script type="module">
            // @ts-nocheck

import { initializeMultiPageRTE } from "./src/initializeMultiPageRTE";
import {
  defaultStyle,
  MultiPageEditor,
} from "./src/useMultiPageRTE";

import fontUrlInter from "./src/assets/fonts/Inter-Regular.ttf";
import fontUrlOswald from "./src/assets/fonts/Oswald[wght].ttf"

const pxPerIn = 96;
const marginSizeIn = { x: 1, y: 0.5 };
const documentSizeIn = {
  width: 8.3,
  height: 11.7,
};

const marginSize = {
  x: marginSizeIn.x * pxPerIn,
  y: marginSizeIn.y * pxPerIn,
};

const documentSize = {
  width: documentSizeIn.width * pxPerIn,
  height: documentSizeIn.height * pxPerIn,
};

const mainTextSize = {
  width: (documentSizeIn.width - marginSizeIn.x * 2) * pxPerIn,
  height: (documentSizeIn.height - marginSizeIn.y * 2) * pxPerIn,
};

const debounceCallback = (content, masterJson, masterVisuals) =>
  console.info("debounce content", masterJson, masterVisuals);

initializeMultiPageRTE(
  testMarkdown, // initial markdown content
  null, // initial masterJson
  [], // initial masterVisuals
  mainTextSize,
  documentSize,
  marginSize,
  debounceCallback, // after 3s, all content is output for saving
  [
    {
      name: "Inter",
      url: fontUrlInter
    },
    {
      name: "Oswald",
      url: fontUrlOswald
    },
  ],
  uploadImage // async function takes fileName, fileSize, fileType, and base64 fileData, must return url to image
);
</script>

Development

  • npm run dev (starts a Vite server to use the editor at index.html)

Publishing

  • npm run build (outputs to the dist directory for publsihing)
  • npm publish