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

@hc-master/renderer

v1.2.18

Published

基于pixiJS的渲染引擎,处理智能设计项目的渲染数据JSON Schema,以数据驱动的形式渲染图形图像的React渲染组件

Downloads

26

Readme

智能设计渲染组件

基于pixiJS的渲染引擎,处理智能设计项目的渲染数据JSON Schema,以数据驱动的形式渲染图形图像的React渲染组件

Install

从npm获取 @hc-master/renderer

npm install @hc-master/renderer

Usage

在你的react项目中引入

import { Renderer } from '@hc-master/renderer'
// resDataJson为智能设计项目数据
function App() {
  const [index] = useState(0);
  const curData = useMemo(() => resDataJson.pagesData[index], [index]);
  const onMount = function(app) {
    console.log('==>>>::: 监听组件挂载');
  }
  const onCompleted = function(app) {
    console.log('==>>>::: 监听组件资源加载并渲染完成');
  }
  const onUnmount = function(app) {
    console.log('==>>>::: 监听组件卸载');
  }
  const handlePrev = function() {
    let v = indexRef.current-1;
    indexRef.current = v < 0 ? 0 : v
    setCurData(resDataJson.pagesData[indexRef.current])
  }
  const handleNext = function() {
    const count = resDataJson.pagesData.length-1;
    let v = indexRef.current+1;
    indexRef.current = v > count ? count : v;
    setCurData(resDataJson.pagesData[indexRef.current])
  }
  const handleChange = function() {
    const id = '9f6c1d44-d61c-4ad9-8f85-1d981f4548ce';
    const index = curData.stageJson.findIndex(item => item.id === id);
    // 找到指定数据
    const item = curData.stageJson[index] as FrameType;
    if (!item.photo) return
    // 改变数据内容
    item.photo = {
      ...item.photo,
      image: 'http://sts-test.gdoss.xstore.ctyun.cn/simooapp/debug/user_data/urqtj013qcgc0oct/photos/2023/08/14/1692008690_20230814_102450_159D15C9.jpg?x-amz-process=image/resize,m_fill,w_400,h_0',
      origHeight: 1501,
      origWidth: 1994,
      width: 400,
      height: 554,
      scale: {
        x: 4.98,
        y: 4.98
      },
      x: 0,
      y: 0
    };
    // 更新数据(Immutable Data)
    curData.stageJson[index] = {...item}
    setCurData({...curData})
  }
  return (
    <div className='App'>
      <Button onClick={handlePrev}>上页</Button>
      <Button onClick={handleNext}>下页</Button>
      <Button onClick={handleChange}>替换页内容</Button>
      <Renderer
         data={curData}
         designWidth={resDataJson.designWidth}
         designHeight={resDataJson.designHeight}
         onMount={onMount}
         onCompleted={onCompleted}
      />
    </div>
  )
}

Renderer组件文档

以下为组件的props详细

data

需要传入的解析的JSON,从智能设计服务获取

designWidth

渲染的画布尺寸宽度

designHeight

渲染的画布尺寸高度

pageNo 可选

标记当前页码(多页渲染时使用)

onMount

渲染组件挂载时的事件监听

onUnmount

渲染组件卸载时的事件监听

onCompleted

渲染组件完成渲染时的事件监听

onGetFontUrl

获取字体文件URL事件