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

@hanfy/plugin-math

v2.10.12

Published

Math(数学公式)

Downloads

1

Readme

@hanfy/plugin-math

数学公式

安装

$ yarn add @hanfy/plugin-math

添加到引擎

import Engine, { EngineInterface } from '@hanfy/engine';
import Math , { MathComponent } from '@hanfy/plugin-math';

new Engine(...,{ plugins:[ Math ] , cards:[ MathComponent ]})

Math 可选项

//使用配置
new Engine(...,{
    config:{
        [Math.pluginName]:{
            //...相关配置
        }
    }
 })

请求生成公式代码为图片或 SVG

action: 请求地址,始终使用 POST 请求

type: 默认为 json

contentType: 默认以 application/json 类型发起请求

data: 请求时将这些数据一起POST到服务端

/**
 * 请求生成公式svg地址
 */
action: string;
/**
 * 数据返回类型,默认 json
 */
type?: '*' | 'json' | 'xml' | 'html' | 'text' | 'js';
/**
 * 额外携带数据上传
 */
data?: Record<string, RequestDataValue> | FormData | (() => Promise<Record<string, RequestDataValue> | FormData>)
/**
 * 请求类型,默认 application/json;
 */
contentType?: string;

配置后,插件会使用 content 字段 POST 到指定的 action 地址,里面包含了公式代码

解析服务端响应数据

默认会查找

公式对应图片地址或SVG代码:response.url || response.data && response.data.url

result: true 生成成功,data 为公式对应图片地址或SVG代码。false 生成失败,data 为错误消息

/**
 * 解析生成后的Respone,返回 result:是否成功,data:成功:公式对应图片地址或`SVG`代码,失败:错误信息
 */
parse?: (
    response: any,
) => {
    result: boolean;
    data: string;
};

画图接口

可以使用 https://g.aomao.com/latex 地址生成公式对应的 SVG 代码。该项目使用mathjax 生成 SVG 代码

演示站点:https://drawing.aomao.com/

配置:

[Math.pluginName]: {
    action: `https://g.aomao.com/latex`,
    parse: (res: any) => {
        if(res.success) return { result: true, data: res.svg}
        return { result: false}
    }
}

命令

插入公式代码

参数 1:公式代码

参数 2:公式对应图片地址或SVG代码

engine.command.execute(
	Math.pluginName,
	'公式代码', //可选
	'公式对应图片地址或`SVG`代码', //可选
);

请求生成公式代码图片或 SVG

参数 1:固定为 query 参数 2:成功后的回调 参数 3:失败后的回调。可选

engine.command.execute(Math.pluginName, "query", success:(url: string) => void, failed: (message: string) => void);