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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ai-learn-jsbridge

v0.1.2

Published

Browser JS bridge and rich-text helpers (KaTeX, blanks, image zoom).

Downloads

12

Readme

ai-learn-jsbridge

一个解耦的 JS Bridge 与富文本渲染工具集,用于:

  • KaTeX 公式渲染
  • 填空交互(唤起原生键盘、提交高亮)
  • 图片长按放大
  • 与原生应用的桥接方法注册

安装

必选:katex(公式渲染) 可选:smiles-drawer(分子式渲染)

pnpm add ai-learn-jsbridge katex
# 如果需要分子式渲染
pnpm add smiles-drawer

在应用入口引入 KaTeX 样式:

import 'katex/dist/katex.min.css'

快速开始(推荐)

一行初始化,自动挂载依赖(若已安装)并完成全部注册:

import { initAllWithAutoMount } from 'ai-learn-jsbridge'

initAllWithAutoMount() // 自动挂载 window.katex / window.SmilesDrawer,并完成初始化

说明:

  • 若你已经手动挂载了 window.katexwindow.SmilesDrawer,自动挂载会跳过。
  • 若未安装可选依赖(如 smiles-drawer),会在控制台提示,但不影响其他功能。

手动初始化(更灵活)

  1. 手动挂载依赖
import katex from 'katex'

import 'katex/dist/katex.min.css'
// import SmilesDrawer from 'smiles-drawer' // 可选

window.katex = katex
// window.SmilesDrawer = SmilesDrawer
  1. 初始化能力
import { attachWindowGlobals, initAll } from 'ai-learn-jsbridge'

initAll() // 注册点击/长按事件、原生桥方法、KaTeX 滚动增强等
attachWindowGlobals() // 可选:把 reconstructHtml 暴露到 window,兼容旧代码

在组件中渲染含公式的富文本

如果 HTML 中包含 .ql-formula 节点,使用 reconstructHtml 可直接得到可展示的 KaTeX 内容:

import { reconstructHtml } from 'ai-learn-jsbridge'

const html = reconstructHtml(rawHtml, /* isNeedArrow? */ true)
// 然后以 dangerouslySetInnerHTML 的方式渲染到 .ql-editor 容器

提示:

  • isNeedArrow(默认 false):为横向可滚动的公式显示左右箭头提示与遮罩。
  • 建议在 .ql-container .ql-editor 样式容器中渲染(Quill 或你的自定义样式)。

API 列表

  • 初始化

    • initAllWithAutoMount():自动挂载依赖 + 全量初始化 + 兼容 window 全局函数
    • initAll():只做行为注册(不自动挂载依赖)
    • autoMountDependencies():尝试挂载 window.katexwindow.SmilesDrawer
    • attachWindowGlobals():暴露 window.reconstructHtml
  • 公式/富文本

    • reconstructHtml(html: string, isNeedArrow?: boolean): string
    • initKatexScroll():增强可滚动 KaTeX 容器(遮罩与箭头)
  • 填空/原生交互

    • registerBlankBridges()
    • registerElementToTost()
    • registerFillCallBack(...)
    • registerSubmitCallBack(...)
    • popKeyboard(target: HTMLElement)
  • 图片(长按放大)

    • createLongPressHandlers(longPressDuration?: number)
    • zoomImg(target: HTMLElement)
  • 桥方法

    • registerMethodCallByNative(name: string, cb: (args:any)=>unknown)
    • callNativeMethod(name: string, args?: object)

入口文件典型用法(main.tsx)

import { initAllWithAutoMount } from 'ai-learn-jsbridge'

import 'katex/dist/katex.min.css'

initAllWithAutoMount()

迁移提示

  • 如果旧代码中使用了 window.reconstructHtml(...),初始化后调用 attachWindowGlobals(),或改为模块导入 reconstructHtml(...)
  • 使用本包后可删除旧的 ./assets/AILearnJSbridge.js 文件与引用。