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

dhivehi-input-handler

v2.0.0

Published

Automatically convert latin characters to dhivehi (thaana)

Downloads

7

Readme

Dhivehi Input Handler

Dhivehi Input Handler is a simple npm package to enable Dhivehi language input (Thaana script) in text inputs or text areas on web pages. It ensures that the input is styled correctly (right-to-left and with the appropriate font) and maps keyboard keys to the Thaana script.

Version: 2.0.0

Overview

Dhivehi Input Handler provides functionality to convert Latin script input into Dhivehi script (Thaana) for web applications. This package includes:

  • Dhivehi Keyboard Integration: Automatically converts Latin characters to Dhivehi characters using a provided keyboard mapping.
  • Content Editable Support: Dynamically converts text inside content-editable elements (e.g., TinyMCE WYSIWYG editor) to Dhivehi as you type.

Features

  • Dhivehi Input Mapping: Automatically maps standard keyboard inputs to Dhivehi characters.
  • Dynamic Integration: Works with React and Next.js applications without additional initialization.
  • Custom Attribute Support: Use the data-apply-thaana attribute to apply Dhivehi input functionality to elements.
  • Seamless integration with TinyMCE (haven't tested on other WYSIWYG editors)

Installation

To install the dhivehi-input package, use npm or yarn:

npm install dhivehi-input-handler

or

yarn add dhivehi-input-handler

Usage

To use the Dhivehi Input functionality in your project, follow these steps:

React

You can use the dhivehi-input-handler package in your React application by importing the package. The package will automatically set up the necessary functionality:

Import the dhivehi-input-handler package:

import React from "react";
import "dhivehi-input-handler";

function App() {
    return (
      <div className="App">
        <textarea rows={5} cols={10} data-apply-thaana />
        <input type="text" data-apply-thaana />
      </div>
    );
}
export default App;

Manual Initialization (Optional)

If you prefer to initialize manually, you can use the initDhivehiInputObserver function to start observing and applying Dhivehi input functionality:

Next.js

"use client";
import { initDhivehiInputObserver } from "dhivehi-input-handler";
import { useEffect } from "react";

export default function Home() {
  useEffect(() => {
    initDhivehiInputObserver();
  }, []);
  return (
    <div>
      <input type="text" data-apply-thaana />
      <textarea data-apply-thaana />
    </div>
  );
}

Integration with TinyMCE React

function ensures that content inside the contenteditable element (e.g., TinyMCE's editor body) is dynamically converted to Dhivehi while typing.

import {applyDhivehiInput} from "dhivehi-input-handler"

const handleInit = (evt, editor) => {
  const iframe = editor.getContentAreaContainer().querySelector("iframe");
  const editorBody = iframe.contentDocument.body;

  applyDhivehiInput(editorBody)
}

How It Works

  • Attribute-Based Application: The library automatically applies Dhivehi input functionality to any element with the data-apply-thaana attribute.
  • Automatic Setup: On import, the package sets up a MutationObserver to watch for new elements with the data-apply-thaana attribute and applies the necessary functionality.

Key Mappings

The package includes a mapping for the Dhivehi (Thaana) keyboard layout. When users type on a standard keyboard, the corresponding Dhivehi characters are inserted.

Font Usage

The Faruma font is included within the package and automatically applied to any input with the data-apply-thaana attribute. Ensure that your build process supports loading font files.

If needed, you can manually apply the font to any element using CSS:

[data-apply-thaana] {
  font-family: "MV_Faruma", sans-serif;
  direction: rtl;
}

Customization

You can customize the appearance of the input fields by overriding the styles in your own CSS.

input[data-apply-thaana],
textarea[data-apply-thaana] {
  font-size: 16px;
  padding: 8px;
  color: #000;
  border: 1px solid #ccc;
}