Skip to content

Commit f08e6c0

Browse files
committed
feat: add scaleMin & scaleMax
1 parent 0ebb469 commit f08e6c0

File tree

7 files changed

+11
-8
lines changed

7 files changed

+11
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mind-elixir",
3-
"version": "5.0.3",
3+
"version": "5.0.4",
44
"type": "module",
55
"description": "Mind elixir is a free open source mind map core.",
66
"keywords": [

src/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const options: Options = {
7373
return true
7474
},
7575
},
76-
scaleSensitivity: 0.2,
76+
// scaleMin:0.1
7777
// alignment: 'nodes',
7878
}
7979

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ function MindElixir(
3838
theme,
3939
alignment,
4040
scaleSensitivity,
41+
scaleMax,
42+
scaleMin,
4143
handleWheel,
4244
}: Options
4345
): void {
@@ -65,7 +67,9 @@ function MindElixir(
6567
this.draggable = draggable ?? true
6668
this.editable = editable ?? true
6769
this.allowUndo = allowUndo ?? false
68-
this.scaleSensitivity = scaleSensitivity ?? 0.2
70+
this.scaleSensitivity = scaleSensitivity ?? 0.1
71+
this.scaleMax = scaleMax ?? 1.4
72+
this.scaleMin = scaleMin ?? 0.2
6973
this.generateMainBranch = generateMainBranch || main
7074
this.generateSubBranch = generateSubBranch || sub
7175
this.overflowHidden = overflowHidden ?? false

src/interact.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export const disableEdit = function (this: MindElixirInstance) {
114114
* @param {number}
115115
*/
116116
export const scale = function (this: MindElixirInstance, scaleVal: number, offset: { x: number; y: number } = { x: 0, y: 0 }) {
117+
if (scaleVal < this.scaleMin || scaleVal > this.scaleMax) return
117118
const rect = this.container.getBoundingClientRect()
118119
// refer to /refs/scale-calc.excalidraw for the process
119120
// remove coordinate system influence and calculate quantities directly
@@ -132,7 +133,7 @@ export const scale = function (this: MindElixirInstance, scaleVal: number, offse
132133
// Note: cursor needs to be reversed, probably because transform itself is reversed
133134
const xres = (-xc + xb) * (1 - scaleVal / oldScale)
134135
const yres = (-yc + yb) * (1 - scaleVal / oldScale)
135-
console.log(xc, yc, xb, yb)
136+
136137
this.map.style.transform = `translate(${xCurrent - xres}px, ${yCurrent - yres}px) scale(${scaleVal})`
137138
this.scaleVal = scaleVal
138139
this.bus.fire('scale', scaleVal)

src/plugin/keypress.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,9 @@ export const handleZoom = function (
7070
const { scaleVal, scaleSensitivity } = mei
7171
switch (direction) {
7272
case 'in':
73-
if (scaleVal > 1.6) return
7473
mei.scale(scaleVal + scaleSensitivity, offset)
7574
break
7675
case 'out':
77-
if (scaleVal < 0.6) return
7876
mei.scale(scaleVal - scaleSensitivity, offset)
7977
}
8078
}

src/plugin/toolBar.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ function createToolBarRBContainer(mind: MindElixirInstance) {
5050
mind.toCenter()
5151
}
5252
zo.onclick = () => {
53-
if (mind.scaleVal < 0.6) return
5453
mind.scale(mind.scaleVal - mind.scaleSensitivity)
5554
}
5655
zi.onclick = () => {
57-
if (mind.scaleVal > 1.6) return
5856
mind.scale(mind.scaleVal + mind.scaleSensitivity)
5957
}
6058
return toolBarRBContainer

src/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ export interface Options {
144144
selectionContainer?: string | HTMLElement
145145
alignment?: Alignment
146146
scaleSensitivity?: number
147+
scaleMin?: number
148+
scaleMax?: number
147149
handleWheel?: true | ((e: WheelEvent) => void)
148150
}
149151

0 commit comments

Comments
 (0)