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

react-konva-dom

v0.0.3

Published

react-konva-dom

Downloads

3

Readme

react-konva-dom

一个为react-konva实现文档流的工具组件,将您从繁重的canvas元素坐标计算中解脱出来!

demo

依赖

  • konva
  • react-konva
  • react
  • lodash

安装方式

npm install react-konva-dom

引入方式

import { Layer, Stage, Rect } from 'react-konva';
import React, { Component } from 'react'
import Div from 'react-konva-dom'

class GoBang extends Component {
  constructor(...args) {
    super(...args);
    this.state = { x: 100, y: 100, ratio: 1 }
  }
  render() {
    return (
      <div className="container">
        <Stage
          width={800}
          height={800}
        >
          <Layer>
            <Div
              {...{
                x: this.state.x,
                y: this.state.y,
                width: 200,
                ratio: this.state.ratio,
                fill: '#aaa',
                stroke: 'black',
                strokeWidth: 2
              }}>
              <Rect
                {...{
                  width: 100,
                  height: 70,
                  fill: '#000',
                  strokeWidth: 0
                }} />
            </Div>
          </Layer>
        </Stage>
      </div>
    )
  }
}

说明

  1. ratio参数为Div组件特有属性,仅在最终渲染的时候对x,y,height,width等值进行缩放比计算
  2. ratioKeys参数为需要进行缩放比计算的属性名数组,默认为:['x','y','height','width'],与ratio参数配合使用
  3. Div组件本身为konva的rect组件的扩展增强,对子元素进行了dom文档流式的布局计算,从左往右,从上往下布局
  4. Div组件高度为空时,会自动根据子元素的高度进行进行计算,允许进行嵌套
  5. Div组件接受事件绑定,所有子元素均会出发冒泡,进行绝对定位的子元素也不例外
  6. 当嵌套有高度为空的子Div组件时候,由于react的渲染顺序是从上到下,第一次渲染时子Div组件的高度是无法获取到的,只有等待子Div组件渲染完成在将高度传递给父元素,这样的后果就是,当嵌套Div层级越深,渲染次数就会越多
  7. 当子元素宽度宽度为空时,会继承父Div组件的宽度
  8. 当子元素设置x,y坐标后会当作绝对定位元素进行渲染,不在文档流中布局计算,但仍会进行ratio计算