-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update: 创建标尺插件 * update: 更新代码结构 * update: 安装标尺插件 * update: 删除多余的监听 * update: 更新标尺内容 * update: 标尺自适应 * refactor: 重构ruler代码 * refactor: 重构标尺逻辑 * refactor: 重构部分代码 * refactor: 更新画布尺寸变化时标尺变化 * update: 更新drawTicks逻辑 * update: 更新刻度线绘制逻辑 * update: 更新drawTicks逻辑 * update: 更新标尺绘制逻辑 * update: 删除无用代码 * refactor: 提高可读性 * update: 更新标尺更新逻辑 * update: 更新标尺响应事件 * update: 添加注释 * update: 标尺增加间隔参数 * refactor: 重构app事件监听位置 * update: 更新标尺配置项 * update: 修复axis为y时标尺不显示问题 * update: 将操作层统一在app中管理 * update: 更新菜单中的标尺 * update: 更新标尺可见性切换逻辑 * update: 添加标尺切换快捷键 --------- Co-authored-by: yanheng <yanheng@siactpower.com>
- Loading branch information
1 parent
b351c18
commit 544101d
Showing
28 changed files
with
576 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "@pictode/plugin-ruler", | ||
"private": false, | ||
"version": "1.0.0", | ||
"main": "dist/pictode-plugin-ruler.umd.js", | ||
"module": "dist/pictode-plugin-ruler.mjs", | ||
"types": "types/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/pictode-plugin-ruler.mjs", | ||
"require": "./dist/pictode-plugin-ruler.umd.js", | ||
"types": "./types/index.d.ts" | ||
} | ||
}, | ||
"files": [ | ||
"dist/**/*", | ||
"types/**/*" | ||
], | ||
"scripts": { | ||
"build": "npm run build:type && vite build", | ||
"build:type": "npm run clear:type && tsc --declaration --emitDeclarationOnly --project tsconfig.build.json", | ||
"clear:type": "rimraf ./types" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/JessYan0913/pictode.git", | ||
"directory": "packages/plugin-ruler" | ||
}, | ||
"keywords": [ | ||
"pictode", | ||
"konva.js", | ||
"canvas" | ||
], | ||
"author": "JessYan0913", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/JessYan0913/pictode/issues" | ||
}, | ||
"homepage": "https://github.com/JessYan0913/pictode#readme", | ||
"dependencies": { | ||
"@pictode/core": "workspace:^", | ||
"@pictode/utils": "workspace:^", | ||
"dot": "2.0.0-beta.1", | ||
"rimraf": "^3.0.2", | ||
"roughjs": "^4.5.2" | ||
}, | ||
"peerDependencies": { | ||
"@pictode/core": "workspace:^" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.9.3", | ||
"vite": "^4.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { App, Plugin } from '@pictode/core'; | ||
|
||
import './method'; | ||
|
||
import { Ruler } from './ruler'; | ||
import { Options, RulerAxis } from './types'; | ||
|
||
const DEFAULT_OPTIONS: Options = { | ||
enabled: true, | ||
axis: 'x', | ||
jump: 50, | ||
thickness: 40, | ||
fill: '#ffffff', | ||
}; | ||
|
||
export class RulerPlugin implements Plugin { | ||
public name: string = 'rulerPlugin'; | ||
public app?: App; | ||
public options: Options; | ||
public rulers: Ruler[]; | ||
private axis: RulerAxis[]; | ||
|
||
constructor(options?: Partial<Options>) { | ||
this.options = { ...DEFAULT_OPTIONS, ...options }; | ||
this.axis = []; | ||
this.rulers = []; | ||
if (typeof this.options.axis === 'string') { | ||
this.axis = [this.options.axis]; | ||
} else { | ||
this.axis = this.options.axis; | ||
} | ||
} | ||
|
||
public install(app: App) { | ||
this.app = app; | ||
for (const axis of this.axis) { | ||
this.rulers = this.rulers || []; | ||
this.rulers.push(new Ruler(this.app, axis, { ...this.options })); | ||
} | ||
this.app.emit('ruler:installed', { ruler: this }); | ||
} | ||
|
||
public destroy(): void { | ||
this.rulers.forEach((ruler) => ruler.destroy()); | ||
this.app?.emit('ruler:destroy', { ruler: this }); | ||
} | ||
|
||
public enable(): void { | ||
this.rulers.forEach((ruler) => ruler.triggerVisible(true)); | ||
} | ||
|
||
public disable(): void { | ||
this.rulers.forEach((ruler) => ruler.triggerVisible(false)); | ||
} | ||
|
||
public isEnabled(): boolean { | ||
return this.rulers.some((ruler) => ruler.enabled); | ||
} | ||
|
||
public triggerVisible(visible?: boolean): void { | ||
const rulerVisible = visible || !this.isEnabled(); | ||
this.rulers.forEach((ruler) => ruler.triggerVisible(rulerVisible)); | ||
} | ||
|
||
public update(): void { | ||
this.rulers.forEach((ruler) => ruler.update()); | ||
} | ||
} | ||
|
||
export default RulerPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { App } from '@pictode/core'; | ||
|
||
import { RulerPlugin } from './index'; | ||
|
||
App.prototype.triggerRulerVisible = function (enabled?: boolean) { | ||
const rulerPlugin = this.getPlugin<RulerPlugin>('rulerPlugin'); | ||
if (rulerPlugin) { | ||
rulerPlugin.triggerVisible(enabled); | ||
} | ||
return this; | ||
}; | ||
|
||
App.prototype.rulerUpdate = function () { | ||
const rulerPlugin = this.getPlugin<RulerPlugin>('rulerPlugin'); | ||
if (rulerPlugin) { | ||
rulerPlugin.update(); | ||
} | ||
return this; | ||
}; |
Oops, something went wrong.