🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

react-screenshots-mind

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-screenshots-mind

a picture clipping and graffiti tool by react

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
2
-60%
Maintainers
1
Weekly downloads
 
Created
Source

react-screenshots-mind

基于react-screenshots的0.0.14版本修改

  • 0.0.1
    • 增加delete or backSpace快捷键删除选中的框

a picture clipping and graffiti tool by react

Install

NPM

Usage

  • web 中使用
import React, { PureComponent } from 'react'
import Screenshot from 'react-screenshots'
import 'react-screenshots/dist/react-screenshots.css'

export default class App extends PureComponent {
  state = {
    width: window.innerWidth,
    height: window.innerHeight
  }

  onSave = ({ viewer, dataURL }) => {
    console.log('点击了保存按钮', dataURL, viewer)
  }

  onCancel = () => {
    console.log('点击了取消按钮')
  }

  onOk = ({ dataURL, viewer }) => {
    console.log('点击了确定按钮', dataURL, viewer)
  }

  render() {
    const { width, height } = this.state
    return (
      <Screenshot
        image="./demo.png"
        width={width}
        height={height}
        onSave={this.onSave}
        onCancel={this.onCancel}
        onOk={this.onOk}
      />
    )
  }
}
  • electron 中使用
  • electron 中使用可直接加载渲染进程的页面,页面路径为require.resolve('react-screenshots/dist/index.html'),不推荐自己手动开发主进程,推荐直接使用electron-screenshots模块
const $win = new BrowserWindow({
  /** 窗口参数 */
})
// 加载页面
$win.loadURL(`file://${require.resolve('react-screenshots/dist/index.html')}`)

// 渲染进程页面加载后通知主进程
ipcMain.once('SCREENSHOTS::DOM-READY', () => {
  // 发送需要截取的屏幕信息
  // display = {
  //   id, // 屏幕id
  //   x, // 屏幕位置和大小
  //   y,
  //   width,
  //   height
  // }
  $win.webContents.send('SCREENSHOTS::SEND-DISPLAY-DATA', display)
})

// 渲染进程完成桌面快照捕捉之后的回调
// 通常在这个事件之后再显示窗口,避免截图窗口自己被截图
ipcMain.once('SCREENSHOTS::CAPTURED', () => {
  $win.show()
  $win.focus()
})

// 点击保存按钮事件
ipcMain.on('SCREENSHOTS::SAVE', (e, data) => {})
// 点击取消按钮事件
ipcMain.on('SCREENSHOTS::CANCEL', e => {})
// 点击确定按钮事件
ipcMain.on('SCREENSHOTS::OK', (e, data) => {})

Props

interface Bounds {
  x1: number
  y1: number
  x2: number
  y2: number
}

interface Data {
  dataURL: string // 图片资源base64
  bounds: Bounds // 截图区域坐标信息
}
名称说明类型
image要编辑的图像资源地址string
width画布宽度number
height画布宽度number
onSave保存按钮回调function (data:Data):void {}
onCancel取消按钮回调function ():void {}
onOk取消按钮回调function (data:Data):void {}

example

import React from 'react'

function App() {
  return (
    <Screenshot
      image="./example.png"
      width={window.innerWidth}
      height={window.innerHeight}
      onSave={() => {}}
      onCancel={() => {}}
      onOk={() => {}}
    />
  )
}

Screenshot

screenshot

Keywords

clipping

FAQs

Package last updated on 07 May 2021

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