@plait/core 0.75.0-next.9 → 0.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -90,7 +90,8 @@ export declare const PlaitBoard: {
90
90
  getElementLowerHost(board: PlaitBoard): SVGSVGElement;
91
91
  getElementHost(board: PlaitBoard): SVGSVGElement;
92
92
  getElementUpperHost(board: PlaitBoard): SVGSVGElement;
93
- getElementActiveHost(board: PlaitBoard): SVGSVGElement;
93
+ getElementTopHost(board: PlaitBoard): SVGSVGElement;
94
+ getActiveHost(board: PlaitBoard): SVGSVGElement;
94
95
  getRoughSVG(board: PlaitBoard): RoughSVG;
95
96
  getBoardContainer(board: PlaitBoard): HTMLElement;
96
97
  getBoardContext(board: PlaitBoard): PlaitBoardContext;
@@ -15,3 +15,4 @@ export * from './history';
15
15
  export * from './theme';
16
16
  export * from './direction';
17
17
  export * from './group';
18
+ export * from './svg-arc-command';
@@ -0,0 +1,9 @@
1
+ export interface SVGArcCommand {
2
+ rx: number;
3
+ ry: number;
4
+ xAxisRotation: number;
5
+ largeArcFlag: 0 | 1;
6
+ sweepFlag: 0 | 1;
7
+ endX: number;
8
+ endY: number;
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plait/core",
3
- "version": "0.75.0-next.9",
3
+ "version": "0.76.0",
4
4
  "peerDependencies": {
5
5
  "immer": "^10.0.3",
6
6
  "is-hotkey": "^0.2.0",
@@ -7,4 +7,3 @@ export * from './with-moving';
7
7
  export * from './with-options';
8
8
  export * from './with-related-fragment';
9
9
  export * from './with-selection';
10
- export * from './with-viewport';
package/utils/angle.d.ts CHANGED
@@ -12,7 +12,7 @@ export declare const hasValidAngle: (node: PlaitElement) => boolean | 0 | undefi
12
12
  export declare const isValidAngle: (angle: undefined | number) => boolean | 0 | undefined;
13
13
  export declare const rotatePointsByElement: <T>(points: T, element: PlaitElement) => T | null;
14
14
  export declare const rotatePointsByAngle: (points: Point[], angle: number | undefined) => Point[] | null;
15
- export declare const rotateAntiPointsByElement: <T>(points: T, element: PlaitElement) => T | null;
15
+ export declare const rotateAntiPointsByElement: <T>(board: PlaitBoard, points: T, element: PlaitElement, isToActive?: boolean) => T | null;
16
16
  export declare const getRectangleByAngle: (rectangle: RectangleClient, angle: number) => RectangleClient;
17
17
  export declare const isAxisChangedByAngle: (angle: number) => boolean;
18
18
  export declare function degreesToRadians(d: number): number;
@@ -20,3 +20,4 @@ export declare const isDOMNode: (value: any) => value is Node;
20
20
  export declare const hasInputOrTextareaTarget: (target: EventTarget | null) => boolean;
21
21
  export declare const isSecondaryPointer: (event: MouseEvent) => boolean;
22
22
  export declare const isMainPointer: (event: MouseEvent) => boolean;
23
+ export declare const isWheelPointer: (event: MouseEvent) => boolean;
@@ -5,3 +5,4 @@ export declare const IS_SAFARI: boolean;
5
5
  export declare const IS_EDGE_LEGACY: boolean;
6
6
  export declare const IS_CHROME: boolean;
7
7
  export declare const IS_CHROME_LEGACY: boolean;
8
+ export declare const IS_WINDOWS: boolean;
package/utils/math.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { Point } from '../interfaces';
1
+ import { Point, SVGArcCommand } from '../interfaces';
2
2
  import { RectangleClient } from '../interfaces/rectangle-client';
3
3
  export declare function distanceBetweenPointAndSegment(x: number, y: number, x1: number, y1: number, x2: number, y2: number): number;
4
4
  export declare function getNearestPointBetweenPointAndSegment(point: Point, linePoints: [Point, Point]): Point;
5
- export declare function distanceBetweenPointAndSegments(points: Point[], point: Point): number;
5
+ export declare function distanceBetweenPointAndSegments(point: Point, points: Point[]): number;
6
6
  export declare function getNearestPointBetweenPointAndSegments(point: Point, points: Point[], isClose?: Boolean): Point;
7
+ export declare function getNearestPointBetweenPointAndDiscreteSegments(point: Point, segments: [Point, Point][]): Point;
7
8
  export declare function getNearestPointBetweenPointAndEllipse(point: Point, center: Point, rx: number, ry: number): Point;
8
9
  export declare function rotate(x1: number, y1: number, x2: number, y2: number, angle: number): number[];
9
10
  export declare function distanceBetweenPointAndPoint(x1: number, y1: number, x2: number, y2: number): number;
@@ -53,30 +54,14 @@ export declare function getPointBetween(x0: number, y0: number, x1: number, y1:
53
54
  * 获取点到半椭圆弧段的最近点
54
55
  * @param point 目标点
55
56
  * @param startPoint 弧段起点
56
- * @param arcPoint 弧段数据
57
+ * @param arcCommand SVG 弧形命令参数
57
58
  */
58
59
  /**
59
60
  * 计算椭圆弧的中心点和实际半径
60
61
  */
61
- export declare function getEllipseArcCenter(startPoint: Point, arcPoint: {
62
- rx: number;
63
- ry: number;
64
- xAxisRotation: number;
65
- largeArcFlag: 0 | 1;
66
- sweepFlag: 0 | 1;
67
- endX: number;
68
- endY: number;
69
- }): {
62
+ export declare function getEllipseArcCenter(startPoint: Point, arcCommand: SVGArcCommand): {
70
63
  center: Point;
71
64
  rx: number;
72
65
  ry: number;
73
66
  };
74
- export declare function getNearestPointBetweenPointAndArc(point: Point, startPoint: Point, arcPoint: {
75
- rx: number;
76
- ry: number;
77
- xAxisRotation: number;
78
- largeArcFlag: 0 | 1;
79
- sweepFlag: 0 | 1;
80
- endX: number;
81
- endY: number;
82
- }): Point;
67
+ export declare function getNearestPointBetweenPointAndArc(point: Point, startPoint: Point, arcCommand: SVGArcCommand): Point;
@@ -1,3 +1,4 @@
1
+ import { RectangleClient } from '../interfaces';
1
2
  import { PlaitBoard } from '../interfaces/board';
2
3
  import { Point } from '../interfaces/point';
3
4
  export declare const getViewBox: (board: PlaitBoard) => DOMRect;
@@ -5,6 +6,13 @@ export declare const getViewBox: (board: PlaitBoard) => DOMRect;
5
6
  * Get the screen point starting from the upper left corner of the svg element (based on the svg screen coordinate system)
6
7
  */
7
8
  export declare function toHostPoint(board: PlaitBoard, x: number, y: number): Point;
9
+ export declare function toActiveRectangleFromViewBoxRectangle(board: PlaitBoard, rectangle: RectangleClient): RectangleClient;
10
+ export declare function toActivePointFromViewBoxPoint(board: PlaitBoard, point: Point): Point;
11
+ /**
12
+ * Get the screen point starting from the upper left corner of the svg element (based on the svg screen coordinate system)
13
+ */
14
+ export declare function toActivePoint(board: PlaitBoard, x: number, y: number): Point;
15
+ export declare function toScreenPointFromActivePoint(board: PlaitBoard, activePoint: Point): Point;
8
16
  /**
9
17
  * Get the point in the coordinate system of the svg viewBox
10
18
  */
@@ -24,6 +24,7 @@ export declare const BOARD_TO_ELEMENT_HOST: WeakMap<PlaitBoard, {
24
24
  lowerHost: SVGGElement;
25
25
  host: SVGGElement;
26
26
  upperHost: SVGGElement;
27
+ topHost: SVGGElement;
27
28
  activeHost: SVGGElement;
28
29
  container: HTMLElement;
29
30
  viewportContainer: HTMLElement;
@@ -1,30 +0,0 @@
1
- import { debounce } from '../utils/common';
2
- import { initializeViewBox, isFromScrolling, setIsFromScrolling, updateViewportOffset } from '../utils/viewport';
3
- export function withViewport(board) {
4
- const { onChange } = board;
5
- const throttleUpdate = debounce(() => {
6
- initializeViewBox(board);
7
- updateViewportOffset(board);
8
- }, 500, { leading: true });
9
- board.onChange = () => {
10
- const isSetViewport = board.operations.length && board.operations.some(op => op.type === 'set_viewport');
11
- const isOnlySetSelection = board.operations.length && board.operations.every(op => op.type === 'set_selection');
12
- if (isOnlySetSelection) {
13
- return onChange();
14
- }
15
- if (isSetViewport && isFromScrolling(board)) {
16
- setIsFromScrolling(board, false);
17
- return onChange();
18
- }
19
- if (isSetViewport) {
20
- initializeViewBox(board);
21
- updateViewportOffset(board);
22
- }
23
- else {
24
- throttleUpdate();
25
- }
26
- onChange();
27
- };
28
- return board;
29
- }
30
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2l0aC12aWV3cG9ydC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvcmUvc3JjL3BsdWdpbnMvd2l0aC12aWV3cG9ydC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsUUFBUS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0+IHtcbiAgICAgICAgY29uc3QgaXNTZXRWaWV3cG9ydCA9IGJvYXJkLm9wZXJhdGlvbnMubGVuZ3RoICYmIGJvYXJkLm9wZXJhdGlvbnMuc29tZShvcCA9PiBvcC50eXBlID09PSAnc2V0X3ZpZXdwb3J0Jyk7XG4gICAgICAgIGNvbnN0IGlzT25seVNldFNlbGVjdGlvbiA9IGJvYXJkLm9wZXJhdGlvbnMubGVuZ3RoICYmIGJvYXJkLm9wZXJhdGlvbnMuZXZlcnkob3AgPT4gb3AudHlwZSA9PT0gJ3NldF9zZWxlY3Rpb24nKTtcbiAgICAgICAgaWYgKGlzT25seVNldFNlbGVjdGlvbikge1xuICAgICAgICAgICAgcmV0dXJuIG9uQ2hhbmdlKCk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGlzU2V0Vmlld3BvcnQgJiYgaXNGcm9tU2Nyb2xsaW5nKGJvYXJkKSkge1xuICAgICAgICAgICAgc2V0SXNGcm9tU2Nyb2xsaW5nKGJvYXJkLCBmYWxzZSk7XG4gICAgICAgICAgICByZXR1cm4gb25DaGFuZ2UoKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAoaXNTZXRWaWV3cG9ydCkge1xuICAgICAgICAgICAgaW5pdGlhbGl6ZVZpZXdCb3goYm9hcmQpO1xuICAgICAgICAgICAgdXBkYXRlVmlld3BvcnRPZmZzZXQoYm9hcmQpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhyb3R0bGVVcGRhdGUoKTtcbiAgICAgICAgfVxuICAgICAgICBvbkNoYW5nZSgpO1xuICAgIH07XG5cbiAgICByZXR1cm4gYm9hcmQ7XG59XG4iXX0=
@@ -1,2 +0,0 @@
1
- import { PlaitBoard } from '../interfaces/board';
2
- export declare function withViewport(board: PlaitBoard): PlaitBoard;