Socket
Book a DemoInstallSign in
Socket

@aendra/bluemoji

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aendra/bluemoji

This is all the client libraries for the Bluemoji project. This is what you need if you're wanting to implement Bluemoji for your AppView.

3.0.21
latest
npmnpm
Version published
Maintainers
1
Created
Source

Bluemoji! 💙

This is all the client libraries for the Bluemoji project. This is what you need if you're wanting to implement Bluemoji for your AppView.

Installation

Via NPM

$ npm install @aendra/bluemoji

Usage

There are two things you'll need to do with this to make it work:

1. Facet

The facet (defined in the schema blue.moji.richtext.facet) extends the @atproto/api RichText class to support Bluemoji. Use this instead of the first-party RichText class to enable your clients to attach Bluemoji facets to records.

import { BluemojiRichText } from "@aendra/bluemoji/facet";
import { AtpAgent } from "@atproto/api";

const agent = new AtpAgent({ service: "https://api.bsky.social" });
await agent.login({ ...credentials });

// creating richtext
const rt = new BluemojiRichText({
  text: "Hello @aendra.com, check out this link: https://moji.blue :blue-kiss:"
});

await rt.detectFacets(agent); // automatically detects mentions and links

const postRecord = {
  $type: "app.bsky.feed.post",
  text: rt.text,
  facets: rt.facets,
  createdAt: new Date().toISOString()
};

// At least one facet will have a feature of type "blue.moji.richtext.facet"
assert.strictEquals(
  rt.facets.some((f) =>
    f.features.some((ff) => f.$type === "blue.moji.richtext.facet")
  ),
  true
);

### Render

Once facets are attached to a record, you can render them using the helper libraries in render/:

import { render } from "@aendra/bluemoji/render";
import { AtpAgent } from "@atproto/api";
import { record, credentials } from "./fixtures";

const agent = new AtpAgent({ service: "https://api.bsky.social" });
await agent.login({ ...credentials });

const [bluemojiFacet] = record.facets;
const element = render(bluemojiFacet, agent);

assert.ok(
  element instanceof HTMLCanvasElement || element instanceof HTMLImageElement,
  "Render returns either <img> (PNG, APNG) or <canvas> (dotLottie)"
);

Components

A few components are in development for multiple targets. To start, I hope to include renderer components for:

  • React
  • React Native
  • Web Component Custom Element

Repo Contents

src
├── facet # Facet parsing and creation
│
├── render # Facet rendering
│
├── util # Utility functions
│   ├── resizePngToUintArray.ts # Resize a PNG blob to Uint8Array
│   └── uploadBluemoji.ts # Create a blue.moji.collection.item record
│
└── components (these are all works-in-progress)
    ├── react # React renderer (WIP)
    ├── react-native # React Native renderer (WIP)
    └── webcomponent # Web Component renderer (WIP)

FAQs

Package last updated on 17 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.