Skip to content

Commit 53651ff

Browse files
committed
fix: fine tuning react
1 parent 471d156 commit 53651ff

File tree

7 files changed

+49
-13
lines changed

7 files changed

+49
-13
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "1.0.0",
44
"scripts": {
55
"dev:react": "pnpm --filter sketching-react run dev",
6-
"build:react": "pnpm --filter sketching-react run build"
6+
"build:react": "pnpm --filter sketching-react run build",
7+
"build:workspace": "pnpm --filter '*' run build"
78
},
89
"repository": {
910
"type": "git",

packages/core/src/canvas/dom/resize.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { MouseEvent } from "../event/mouse";
1212
import type { ResizeType } from "../types/dom";
1313
import { noZero } from "../utils/cipher";
1414
import {
15+
FINE_TUNE,
1516
MAX_Z_INDEX,
1617
RESIZE_LEN,
1718
RESIZE_OFS,
@@ -72,28 +73,48 @@ export class ResizeNode extends Node {
7273
const range = Range.from(startX, startY, startX, endY);
7374
const { x, y } = range.center();
7475
const offset = RESIZE_OFS / 2;
75-
target = Range.from(x - offset, y - RESIZE_OFS, x + offset, y + RESIZE_OFS);
76+
target = Range.from(
77+
x - offset - FINE_TUNE,
78+
y - RESIZE_OFS,
79+
x + offset - FINE_TUNE,
80+
y + RESIZE_OFS
81+
);
7682
break;
7783
}
7884
case RESIZE_TYPE.R: {
7985
const range = Range.from(endX, startY, endX, endY);
8086
const { x, y } = range.center();
8187
const offset = RESIZE_OFS / 2;
82-
target = Range.from(x - offset, y - RESIZE_OFS, x + offset, y + RESIZE_OFS);
88+
target = Range.from(
89+
x - offset + FINE_TUNE,
90+
y - RESIZE_OFS,
91+
x + offset + FINE_TUNE,
92+
y + RESIZE_OFS
93+
);
8394
break;
8495
}
8596
case RESIZE_TYPE.T: {
8697
const range = Range.from(startX, startY, endX, startY);
8798
const { x, y } = range.center();
8899
const offset = RESIZE_OFS / 2;
89-
target = Range.from(x - RESIZE_OFS, y - offset, x + RESIZE_OFS, y + offset);
100+
target = Range.from(
101+
x - RESIZE_OFS,
102+
y - offset - FINE_TUNE,
103+
x + RESIZE_OFS,
104+
y + offset - FINE_TUNE
105+
);
90106
break;
91107
}
92108
case RESIZE_TYPE.B: {
93109
const range = Range.from(startX, endY, endX, endY);
94110
const { x, y } = range.center();
95111
const offset = RESIZE_OFS / 2;
96-
target = Range.from(x - RESIZE_OFS, y - offset, x + RESIZE_OFS, y + offset);
112+
target = Range.from(
113+
x - RESIZE_OFS,
114+
y - offset + FINE_TUNE,
115+
x + RESIZE_OFS,
116+
y + offset + FINE_TUNE
117+
);
97118
break;
98119
}
99120
}
+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
export const noZero = (num: number) => {
2-
return Math.max(num, 0.0001);
2+
// COMPAT: 避免出现 0 值以及 0.5 值的不确定性
3+
return Math.max(num, 1);
4+
};
5+
6+
export const noFloat = (num: number, forward = true) => {
7+
// COMPAT: 避免出现小数
8+
return forward ? Math.ceil(num) : Math.floor(num);
39
};

packages/core/src/canvas/utils/constant.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
export const RESIZE_OFS = 5;
2-
export const RESIZE_LEN = 10;
1+
/* COMPAT: 数值常量如果会被计算出小数值 则尽可能在常量定义时就避免 */
2+
3+
export const RESIZE_OFS = 6;
4+
export const RESIZE_LEN = 12;
35
export const SELECT_BIAS = 3;
46
export const REFER_BIAS = 5;
7+
export const FINE_TUNE = 0.5;
58

69
export const THE_CONFIG = [30, { trailing: false }] as const;
710
export const MAX_Z_INDEX = 999999;

packages/core/src/canvas/utils/shape.ts

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class Shape {
7272
* @param options
7373
*/
7474
public static frame(ctx: CanvasRenderingContext2D, options: FrameProps) {
75+
// https://stackoverflow.com/questions/36615592/canvas-inner-stroke
7576
ctx.save();
7677
ctx.beginPath();
7778
const frame = [options.x - 1, options.y - 1, options.width + 2, options.height + 2] as const;

packages/react/src/components/right-panel/components/text/slate-kit.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { isText, isTextBlock } from "doc-editor-utils";
1515
import type { Attributes, RichTextLine, RichTextLines } from "sketching-plugin";
1616
import { TEXT_ATTRS } from "sketching-plugin";
17-
import { TRUE } from "sketching-plugin";
17+
import { TRULY } from "sketching-plugin";
1818
import { GRAY_2 } from "sketching-utils";
1919
import { BLUE_6 } from "sketching-utils";
2020

@@ -53,7 +53,7 @@ export const blocksToLines = (editor: EditorSuite, blocks: BaseNode[]) => {
5353
lineAttrs[TEXT_ATTRS.LINE_HEIGHT] = current[LINE_HEIGHT_KEY].toString();
5454
}
5555
if (current[DIVIDING_LINE_KEY]) {
56-
lineAttrs[TEXT_ATTRS.DIVIDING_LINE] = TRUE;
56+
lineAttrs[TEXT_ATTRS.DIVIDING_LINE] = TRULY;
5757
}
5858
const line: RichTextLine = { chars: [], config: lineAttrs };
5959
for (const text of current.children) {
@@ -63,8 +63,8 @@ export const blocksToLines = (editor: EditorSuite, blocks: BaseNode[]) => {
6363
// 需要处理行内格式标识 -> Attributes
6464
if (attrs.bold) target[TEXT_ATTRS.WEIGHT] = "bold";
6565
if (attrs.italic) target[TEXT_ATTRS.STYLE] = "italic";
66-
if (attrs[UNDERLINE_KEY]) target[TEXT_ATTRS.UNDERLINE] = TRUE;
67-
if (attrs[STRIKE_THROUGH_KEY]) target[TEXT_ATTRS.STRIKE_THROUGH] = TRUE;
66+
if (attrs[UNDERLINE_KEY]) target[TEXT_ATTRS.UNDERLINE] = TRULY;
67+
if (attrs[STRIKE_THROUGH_KEY]) target[TEXT_ATTRS.STRIKE_THROUGH] = TRULY;
6868
if (attrs[INLINE_CODE_KEY]) target[TEXT_ATTRS.BACKGROUND] = GRAY_2;
6969
if (attrs[HYPER_LINK_KEY]) {
7070
const href = attrs[HYPER_LINK_KEY].href;

pnpm-workspace.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
packages:
2-
- 'packages/*'
2+
- "packages/utils"
3+
- "packages/delta"
4+
- "packages/core"
5+
- "packages/plugin"
6+
- "packages/react"
37

0 commit comments

Comments
 (0)