Skip to content

Commit

Permalink
feat: 全面兼容zrender默认参数,升级核心依赖。
Browse files Browse the repository at this point in the history
  • Loading branch information
l-x-f committed Aug 18, 2022
1 parent 508f860 commit e64804d
Show file tree
Hide file tree
Showing 22 changed files with 1,092 additions and 1,470 deletions.
6 changes: 3 additions & 3 deletions dist/auto-drawing.esm.js

Large diffs are not rendered by default.

434 changes: 231 additions & 203 deletions dist/auto-drawing.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/auto-drawing.min.js

Large diffs are not rendered by default.

73 changes: 67 additions & 6 deletions dist/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ZRenderInitOptions extends ZRenderInitOpt {
*/
export declare type BaseShape<T> = Partial<T & {
zlevel: number;
draggable: boolean;
draggable: boolean | 'horizontal' | 'vertical';
}> & PathStyleProps;
/**
* 自定义ZRenderType
Expand All @@ -32,6 +32,71 @@ export declare type AllShape = Line | Circle | Arc | CompoundPath | Polygon | Po
export declare type ZRenderGroup = Group & {
params?: Record<string, any>;
};
/**
* 公共参数类型
*/
export declare type CommonType = {
/**
* 旋转的弧度。默认 0
*/
rotation: number;
/**
* 旋转和缩放的原点X。默认 0
*/
originX: number;
/**
* 旋转和缩放的原点Y。默认 0
*/
originY: number;
/**
* 缩放X。默认 1
*/
scaleX: number;
/**
* 缩放Y。默认 1
*/
scaleY: number;
/**
* 是否进行裁剪。默认false
*/
culling: boolean;
/**
* 鼠标移到元素上时的鼠标样式。 默认'pointer'
*/
cursor: string;
/**
* 图形是否可拖曳。 默认false
*/
draggable: boolean | 'horizontal' | 'vertical';
/**
* 图形是否不可见,为 true 时不绘制图形,但是仍能触发鼠标事件。 默认false
*/
invisible: boolean;
/**
* 是否渐进式渲染。当图形元素过多时才使用,用大于 0 的数字表示渲染顺序。 默认 -1
*/
progressive: boolean;
/**
* 是否使用包围盒检验鼠标是否移动到物体。false 则检测元素实际的内容。 默认 false
*/
rectHover: boolean;
/**
* 是否响应鼠标事件。 默认 false
*/
silent: boolean;
/**
* 控制图形的前后顺序。z 值小的图形会被 z 值大的图形覆盖。z 相比 zlevel 优先级更低,而且不会创建新的 Canvas。 默认 0
*/
z: number;
/**
* 0与 z 类似,优先级比 z 更低。 默认 0
*/
z2: number;
/**
* 图形层级 默认 0
*/
zlevel: number;
};
/**
* 图形数据类型
*/
Expand Down Expand Up @@ -156,10 +221,6 @@ export declare type ShapeCoreType = Partial<{
* 文本字号
*/
fontSize: number;
/**
* 图形层级
*/
zlevel: number;
/**
* 组数据
*/
Expand All @@ -172,7 +233,7 @@ export declare type ShapeCoreType = Partial<{
* 附加参数
*/
params: Record<string, any>;
}> & PathStyleProps;
}> & PathStyleProps & Partial<CommonType>;
/**
* 缩放平移回调数据
*/
Expand Down
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-drawing",
"version": "0.0.8",
"version": "0.1.0",
"description": "auto-drawing based zrender",
"types": "dist/index.d.ts",
"module": "dist/auto-drawing.esm.js",
Expand All @@ -15,7 +15,8 @@
"dev": "rollup -c -w",
"build": "rollup -c",
"commit": "git-cz",
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx --fix"
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx --fix",
"release": "node ./scripts/release.js"
},
"keywords": [
"auto-drawing",
Expand All @@ -25,22 +26,25 @@
],
"dependencies": {
"lodash-es": "^4.17.21",
"zrender": "^5.1.1"
"zrender": "5.1.1"
},
"devDependencies": {
"@babel/core": "^7.14.8",
"@babel/preset-env": "^7.14.8",
"@commitlint/cli": "^8.1.0",
"@commitlint/config-conventional": "^8.1.0",
"@types/lodash-es": "^4.17.4",
"@typescript-eslint/eslint-plugin": "^4.28.5",
"@typescript-eslint/parser": "^4.28.5",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"chalk": "4.1.2",
"commitizen": "^4.0.3",
"cz-conventional-changelog": "^3.0.2",
"cz-customizable": "^6.2.0",
"enquirer": "^2.3.6",
"eslint": "^7.31.0",
"execa": "5.1.0",
"husky": "^3.0.2",
"lint-staged": "^8.1.5",
"lint-staged": "^13.0.3",
"prettier": "^2.4.1",
"rollup": "^2.54.0",
"rollup-plugin-babel": "^4.4.0",
Expand All @@ -49,8 +53,9 @@
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.30.0",
"semver": "^7.3.7",
"string": "^3.3.3",
"typescript": "^4.3.5"
"typescript": "^4.7.4"
},
"husky": {
"hooks": {
Expand Down
98 changes: 98 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const semver = require('semver')
const { prompt } = require('enquirer')
const execa = require('execa')
const { version: currentVersion } = require('../package.json')

// 版本列表
const versionIncrements = [
'patch(补丁)',
'minor(次版本)',
'major(主版本)',
'prepatch(预构建补丁)',
'preminor(预构建次版本)',
'premajor(预构建主版本)',
'prerelease(预构建发布版本)'
]

// 步骤打印
const step = msg => console.log(chalk.green(msg))

// 增加版本号
const inc = i => semver.inc(currentVersion, i)

// 运行脚本
const run = (bin, args, opts = {}) => execa(bin, args, { stdio: 'inherit', ...opts })

/**
* 更新版本号
* @param {string} version
*/
function updatePackage(version) {
const pkgPath = path.resolve(__dirname, '../package.json')
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
pkg.version = version
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
step(`updated package.json version to ${version}\n`)
}

function getInc(value) {
const r = /(\w+)/g
return r.exec(value)[0]
}

/**
* 提交 打标签 推送到远程仓库
* @param {string} version
*/
async function publish(version) {
try {
await run('git', ['add', '-A'])
await run('git', ['tag', '-a', version, '-m', `Release v${version}`])
await run('yarn', ['commit', '-m', `release: v${version}`])
await run('git', ['pull'])
await run('git', ['push', '--tags'])
await run('git', ['push'])
step(`push version to ${version}\n`)
} catch (error) {
throw new Error(error)
}
}

// 主函数
async function main() {
let version

const { release } = await prompt({
type: 'select',
name: 'release',
message: 'Select release type',
choices: versionIncrements.map(i => `${i} (${inc(getInc(i))})`).concat(['custom(自定义版本)'])
})

if (release === 'custom') {
version = (
await prompt({
type: 'input',
name: 'version',
message: 'Input custom version',
initial: version
})
).version
} else {
version = release.match(/\((.*)\)/)[1]
}

if (!semver.valid(version)) {
throw new Error(`invalid target version: ${version}`)
}
updatePackage(version)
await publish(version)
}

main().catch(err => {
console.error(err)
})
17 changes: 4 additions & 13 deletions src/core/arc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Arc, ArcShape } from 'zrender'
import { BaseShape } from '../index'
import { getCommonParams } from '../utils/getCommonParams'

export type IArcOptions = BaseShape<ArcShape> & { radius?: number; x?: number; y?: number }

Expand All @@ -9,20 +10,10 @@ export type IArcOptions = BaseShape<ArcShape> & { radius?: number; x?: number; y
* @returns
*/
function createArc(options?: IArcOptions): Arc {
const {
r = 0,
cx = 0,
cy = 0,
startAngle = 0,
endAngle = 360,
zlevel = 0,
draggable = false,
clockwise = true,
...rest
} = options || {}
const { common, other } = getCommonParams(options)
const { r = 0, cx = 0, cy = 0, startAngle = 0, endAngle = 360, clockwise = true, ...rest } = other
const shape = new Arc({
zlevel,
draggable,
...common,
shape: {
cx,
cy,
Expand Down
20 changes: 4 additions & 16 deletions src/core/bezierCurve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BezierCurve, BezierCurveShape } from 'zrender'
import { BaseShape } from '../index'
import { getCommonParams } from '../utils/getCommonParams'

export type IBezierCurveOptions = BaseShape<BezierCurveShape>

Expand All @@ -9,23 +10,10 @@ export type IBezierCurveOptions = BaseShape<BezierCurveShape>
* @returns
*/
function createBezierCurve(options?: IBezierCurveOptions): BezierCurve {
const {
x1,
y1,
x2,
y2,
cpx1,
cpy1,
cpx2,
cpy2,
percent = 1,
zlevel = 0,
draggable = false,
...rest
} = options || {}
const { common, other } = getCommonParams(options)
const { x1, y1, x2, y2, cpx1, cpy1, cpx2, cpy2, percent = 1, ...rest } = other
const shape = new BezierCurve({
zlevel,
draggable,
...common,
shape: {
// 必选参数
x1,
Expand Down
7 changes: 4 additions & 3 deletions src/core/circle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Circle, CircleShape } from 'zrender'
import { BaseShape } from '../index'
import { getCommonParams } from '../utils/getCommonParams'

export type ICircleOptions = BaseShape<CircleShape & { radius: number; x: number; y: number }>

Expand All @@ -9,10 +10,10 @@ export type ICircleOptions = BaseShape<CircleShape & { radius: number; x: number
* @returns
*/
function createCircle(options?: ICircleOptions): Circle {
const { r = 0, cx = 0, cy = 0, zlevel = 0, draggable = false, ...rest } = options || {}
const { common, other } = getCommonParams(options)
const { r = 0, cx = 0, cy = 0, ...rest } = other
const shape = new Circle({
zlevel,
draggable,
...common,
shape: {
cx,
cy,
Expand Down
7 changes: 4 additions & 3 deletions src/core/compoundPath.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CompoundPath, CompoundPathShape, Polygon, Polyline } from 'zrender'
import { BaseShape } from '../index'
import { getCommonParams } from '../utils/getCommonParams'

export type ICompoundPathOptions = BaseShape<CompoundPathShape> & {
/**
Expand All @@ -18,11 +19,11 @@ export type ICompoundPathOptions = BaseShape<CompoundPathShape> & {
* @returns
*/
function createCompoundPath(options?: ICompoundPathOptions): CompoundPath {
const { paths = [], zlevel = 0, isClose = true, draggable = false, ...rest } = options || {}
const { common, other } = getCommonParams(options)
const { paths = [], isClose = true, ...rest } = other
const PathShape = isClose ? Polygon : Polyline
const shape = new CompoundPath({
zlevel,
draggable,
...common,
shape: {
paths: [
new PathShape({
Expand Down

0 comments on commit e64804d

Please sign in to comment.