# ahmux-scene-design

> 防区设计器

Latest version **0.0.1** (published 2023-03-20) · 0 weekly downloads

## Install

```sh
npm install ahmux-scene-design
pnpm add ahmux-scene-design
yarn add ahmux-scene-design
bun add ahmux-scene-design
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2023-03-20 |
| First published | 2023-03-20 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 112.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | hsh |
| Maintainers | ahmux |
| Keywords | design, scene, canvas, ahmux |

## Links

- npm: https://www.npmjs.com/package/ahmux-scene-design
- npm.io page: https://npm.io/package/ahmux-scene-design

## Dependencies (1)

- [vue](https://npm.io/package/vue.md) ^3.2.45

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2023-03-20

## README

# 场景设计器

> 基于 `vue3.2` 和 `typescript` 的场景设计器

### 如何使用

```bash
# 安装依赖
yarn install ahmux-scene-design
```

```javascript
import SceneDesign from 'ahmux-scene-design'

// 全局使用请用 Vue.use
Vue.use(SceneDesign)
```

```html
<!-- 组件使用 -->
<scene-design ref="designRef" :shapes="shapes"></scene-design>
```

> 属性说明 `id` 为生成canvas的ID `width` 画布宽度 `height`画布高度 `background`画布背景色
> `shapes` 为场景中的形状，格式为json字符串，可通过`toJson`方法获取
> `mouseListening` 是否监听鼠标事件，默认为`true`,当为`false`时，鼠标事件不会触发
```javascript
interface Props {
  id?: string,
  width?: number,
  height?: number,
  background?: string,
  shapes?: string,
  mouseListening?: boolean
}
```

### 方法说明

```javascript
// 清除画布
clear()
// 撤销
revoke()
// 强制渲染
forceReDraw()
// 转换配置成json
toJson()
// 根据id获取形状
getShapeById(id)
// 获取图片
getImage()
// 根据类型获取图片
getImageByType(type)
// 添加形状 shape 为shape 类型
addShape(shape)
// 预添加形状，添加完毕后，可使用ctrl+鼠标 确定形状的初始位置
preAddShape(shapeProp)
//根据ID编辑对应的形状
editById(id, prop)
// 根据ID删除对应的详情
removeById()
```

### 内嵌类型

> 目前内置了以下类型,详细请参见[类型定义](./dist/types/modules/shape/types.d.ts)，可根据需要自行扩展

```text
Circle:圆形
Rectangle:矩形
TextShape:文字
DefenseArea:直角防区,不推荐使用
MultiDefenseArea:曲线防区
ImageShape：图片
```

> 对应数据结构如下

```javascript
export interface ShapeProps {

}

export interface BaseShapeProps extends ShapeProps {
  id?: string;
  cloneId?: string;
  type?: string;
}

export interface RectangleProps extends BaseShapeProps {
  startX: number;
  startY: number;
  endX: number;
  endY: number;
  strokeWidth?: number;
  strokeColor?: string;
  fillColor?: string;
}

export interface CircleProps extends BaseShapeProps {
  x: number;
  y: number;
  radius: number;
  strokeWidth?: number;
  strokeColor?: string;
  fillColor?: string;
}

export interface DefenseAreaProps extends RectangleProps {
  markDistance: number;
  height: number;

}

export interface MultiDefenseAreaProps extends BaseShapeProps {
  points: Point[];

  height: number;
  strokeWidth?: number;
  strokeColor?: string;
  fillColor?: string;
}


export interface ImageShapeProps extends BaseShapeProps {
  x: number;
  y: number;
  height?: number;
  width?: number;
  url: string;
  fillColor?: string;
  strokeColor?: string;
}


export interface TextShapeProps extends BaseShapeProps {
  x: number;
  y: number;
  fontSize: number;
  fontFamily?: string;
  text: string;
  fillColor: string;
  maxWidth?: number;
  textAlign?: CanvasTextAlign;
  textBaseline?: CanvasTextBaseline;
  direction?: CanvasDirection;
}
```

---
_Source: https://npm.io/package/ahmux-scene-design · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
