@plait/core 0.0.58 → 0.1.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.
- package/board/board.component.d.ts +7 -8
- package/board/board.component.interface.d.ts +4 -1
- package/constants/index.d.ts +1 -0
- package/core/element/context.d.ts +0 -1
- package/core/element/element.component.d.ts +1 -2
- package/core/element/plugin-element.d.ts +0 -1
- package/core/toolbar/toolbar.component.d.ts +1 -1
- package/esm2020/board/board.component.interface.mjs +1 -1
- package/esm2020/board/board.component.mjs +58 -42
- package/esm2020/constants/index.mjs +2 -1
- package/esm2020/core/element/context.mjs +1 -1
- package/esm2020/core/element/element.component.mjs +4 -6
- package/esm2020/core/element/plugin-element.mjs +10 -4
- package/esm2020/core/toolbar/toolbar.component.mjs +6 -6
- package/esm2020/interfaces/board.mjs +26 -2
- package/esm2020/interfaces/element.mjs +7 -2
- package/esm2020/interfaces/index.mjs +2 -2
- package/esm2020/interfaces/point.mjs +1 -1
- package/esm2020/interfaces/rectangle-client.mjs +25 -0
- package/esm2020/interfaces/selection.mjs +13 -2
- package/esm2020/plugins/create-board.mjs +9 -6
- package/esm2020/plugins/with-hand.mjs +9 -14
- package/esm2020/plugins/with-selection.mjs +59 -24
- package/esm2020/transforms/board.mjs +3 -3
- package/esm2020/transforms/general.mjs +2 -3
- package/esm2020/utils/board.mjs +4 -3
- package/esm2020/utils/draw/arrow.mjs +23 -0
- package/esm2020/utils/draw/rectangle.mjs +31 -0
- package/esm2020/utils/element.mjs +36 -0
- package/esm2020/utils/index.mjs +6 -2
- package/esm2020/utils/math.mjs +7 -1
- package/esm2020/utils/matrix.mjs +9 -9
- package/esm2020/utils/selected-element.mjs +35 -0
- package/esm2020/utils/tree.mjs +7 -0
- package/esm2020/utils/weak-maps.mjs +7 -3
- package/fesm2015/plait-core.mjs +362 -121
- package/fesm2015/plait-core.mjs.map +1 -1
- package/fesm2020/plait-core.mjs +361 -119
- package/fesm2020/plait-core.mjs.map +1 -1
- package/interfaces/board.d.ts +21 -5
- package/interfaces/element.d.ts +4 -0
- package/interfaces/index.d.ts +1 -1
- package/interfaces/point.d.ts +4 -0
- package/interfaces/rectangle-client.d.ts +16 -0
- package/interfaces/selection.d.ts +9 -1
- package/package.json +1 -1
- package/plugins/create-board.d.ts +1 -1
- package/utils/draw/arrow.d.ts +8 -0
- package/utils/draw/rectangle.d.ts +14 -0
- package/utils/element.d.ts +3 -0
- package/utils/index.d.ts +5 -1
- package/utils/math.d.ts +2 -0
- package/utils/selected-element.d.ts +8 -0
- package/utils/tree.d.ts +4 -0
- package/utils/weak-maps.d.ts +8 -2
- package/esm2020/interfaces/graph.mjs +0 -2
- package/esm2020/utils/graph.mjs +0 -11
- package/interfaces/graph.d.ts +0 -6
- package/utils/graph.d.ts +0 -3
package/interfaces/board.d.ts
CHANGED
|
@@ -3,11 +3,14 @@ import { ComponentType, PlaitElement } from './element';
|
|
|
3
3
|
import { PlaitPluginElementContext } from '../core/element/context';
|
|
4
4
|
import { PlaitHistory } from './history';
|
|
5
5
|
import { PlaitOperation } from './operation';
|
|
6
|
-
import { Selection } from './selection';
|
|
6
|
+
import { Selection, Range } from './selection';
|
|
7
7
|
import { Viewport } from './viewport';
|
|
8
8
|
import { PlaitPluginElementComponent } from '../core/element/plugin-element';
|
|
9
|
+
import { RoughSVG } from 'roughjs/bin/svg';
|
|
10
|
+
import { BoardComponentInterface } from '../board/board.component.interface';
|
|
11
|
+
import { Point } from './point';
|
|
12
|
+
import { RectangleClient } from './rectangle-client';
|
|
9
13
|
export interface PlaitBoard {
|
|
10
|
-
host: SVGElement;
|
|
11
14
|
viewport: Viewport;
|
|
12
15
|
children: PlaitElement[];
|
|
13
16
|
operations: PlaitOperation[];
|
|
@@ -20,17 +23,22 @@ export interface PlaitBoard {
|
|
|
20
23
|
apply: (operation: PlaitOperation) => void;
|
|
21
24
|
onChange: () => void;
|
|
22
25
|
mousedown: (event: MouseEvent) => void;
|
|
23
|
-
globalMouseup: (event: MouseEvent) => void;
|
|
24
26
|
mousemove: (event: MouseEvent) => void;
|
|
27
|
+
globalMousemove: (event: MouseEvent) => void;
|
|
28
|
+
mouseup: (event: MouseEvent) => void;
|
|
29
|
+
globalMouseup: (event: MouseEvent) => void;
|
|
25
30
|
keydown: (event: KeyboardEvent) => void;
|
|
26
31
|
keyup: (event: KeyboardEvent) => void;
|
|
27
32
|
setFragment: (data: DataTransfer | null) => void;
|
|
28
|
-
insertFragment: (data: DataTransfer | null) => void;
|
|
33
|
+
insertFragment: (data: DataTransfer | null, targetPoint?: Point) => void;
|
|
29
34
|
deleteFragment: (data: DataTransfer | null) => void;
|
|
30
35
|
dblclick: (event: MouseEvent) => void;
|
|
31
36
|
drawElement: (context: PlaitPluginElementContext) => SVGGElement[] | ComponentType<PlaitPluginElementComponent>;
|
|
32
37
|
redrawElement: (context: PlaitPluginElementContext, previousContext?: PlaitPluginElementContext) => SVGGElement[] | void;
|
|
33
38
|
destroyElement: (context: PlaitPluginElementContext) => void;
|
|
39
|
+
isIntersectionSelection: (element: PlaitElement, range: Range) => boolean;
|
|
40
|
+
getRectangle: (element: PlaitElement) => RectangleClient | null;
|
|
41
|
+
isWithinSelection: (element: PlaitElement) => boolean;
|
|
34
42
|
}
|
|
35
43
|
export interface PlaitBoardChangeEvent {
|
|
36
44
|
children: PlaitElement[];
|
|
@@ -40,7 +48,6 @@ export interface PlaitBoardChangeEvent {
|
|
|
40
48
|
}
|
|
41
49
|
export interface PlaitBoardOptions {
|
|
42
50
|
readonly: boolean;
|
|
43
|
-
allowClearBoard: boolean;
|
|
44
51
|
hideScrollbar: boolean;
|
|
45
52
|
}
|
|
46
53
|
export interface PlaitBoardMove {
|
|
@@ -57,3 +64,12 @@ export interface PlaitBoardViewport {
|
|
|
57
64
|
scrollLeft?: number;
|
|
58
65
|
scrollTop?: number;
|
|
59
66
|
}
|
|
67
|
+
export declare const PlaitBoard: {
|
|
68
|
+
getHost(board: PlaitBoard): SVGSVGElement;
|
|
69
|
+
getElementHost(board: PlaitBoard): SVGGElement;
|
|
70
|
+
getRoughSVG(board: PlaitBoard): RoughSVG;
|
|
71
|
+
getComponent(board: PlaitBoard): BoardComponentInterface;
|
|
72
|
+
getBoardNativeElement(board: PlaitBoard): HTMLElement;
|
|
73
|
+
getRectangle(board: PlaitBoard): RectangleClient;
|
|
74
|
+
getViewportContainer(board: PlaitBoard): HTMLElement;
|
|
75
|
+
};
|
package/interfaces/element.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { PlaitNode } from './node';
|
|
2
2
|
import { Point } from './point';
|
|
3
3
|
export interface PlaitElement extends PlaitNode {
|
|
4
|
+
id: string;
|
|
4
5
|
points?: Point[];
|
|
5
6
|
type?: string;
|
|
6
7
|
}
|
|
8
|
+
export declare const PlaitElement: {
|
|
9
|
+
isElement: (value: any) => value is PlaitElement;
|
|
10
|
+
};
|
|
7
11
|
export interface ComponentType<T> {
|
|
8
12
|
new (...args: any[]): T;
|
|
9
13
|
}
|
package/interfaces/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export * from './pointer';
|
|
|
3
3
|
export * from '../core/element/context';
|
|
4
4
|
export * from './custom-types';
|
|
5
5
|
export * from './element';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './rectangle-client';
|
|
7
7
|
export * from './node';
|
|
8
8
|
export * from './operation';
|
|
9
9
|
export * from './path';
|
package/interfaces/point.d.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Point } from './point';
|
|
2
|
+
export interface RectangleClient {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const RectangleClient: {
|
|
9
|
+
isIntersect: (origin: RectangleClient, target: RectangleClient) => boolean;
|
|
10
|
+
toRectangleClient: (points: [Point, Point]) => {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { Point } from './point';
|
|
2
|
-
export
|
|
2
|
+
export declare const SELECTION_BORDER_COLOR = "#6698FF";
|
|
3
|
+
export declare const SELECTION_FILL_COLOR = "#6698FF19";
|
|
4
|
+
export interface Range {
|
|
3
5
|
anchor: Point;
|
|
4
6
|
focus: Point;
|
|
5
7
|
}
|
|
8
|
+
export interface Selection {
|
|
9
|
+
ranges: Range[];
|
|
10
|
+
}
|
|
11
|
+
export declare const Selection: {
|
|
12
|
+
isCollapsed(selection: Range): boolean;
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { PlaitBoard, PlaitBoardOptions } from '../interfaces/board';
|
|
2
2
|
import { PlaitElement } from '../interfaces/element';
|
|
3
|
-
export declare function createBoard(
|
|
3
|
+
export declare function createBoard(children: PlaitElement[], options: PlaitBoardOptions): PlaitBoard;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RoughSVG } from 'roughjs/bin/svg';
|
|
2
|
+
import { Options } from 'roughjs/bin/core';
|
|
3
|
+
import { Point } from '../../interfaces';
|
|
4
|
+
export declare function arrowPoints(start: Point, end: Point, maxHypotenuseLength?: number, degree?: number): {
|
|
5
|
+
pointLeft: Point;
|
|
6
|
+
pointRight: Point;
|
|
7
|
+
};
|
|
8
|
+
export declare function drawArrow(rs: RoughSVG, start: Point, end: Point, options: Options, maxHypotenuseLength?: number, degree?: number): SVGGElement[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Options } from 'roughjs/bin/core';
|
|
2
|
+
import { RoughSVG } from 'roughjs/bin/svg';
|
|
3
|
+
/**
|
|
4
|
+
* drawRoundRectangle
|
|
5
|
+
* @param rs RoughSVG
|
|
6
|
+
* @param x1 number
|
|
7
|
+
* @param y1 number
|
|
8
|
+
* @param x2 number
|
|
9
|
+
* @param y2 number
|
|
10
|
+
* @param options Options
|
|
11
|
+
* @param outline boolean
|
|
12
|
+
* @returns SVGGElement
|
|
13
|
+
*/
|
|
14
|
+
export declare function drawRoundRectangle(rs: RoughSVG, x1: number, y1: number, x2: number, y2: number, options: Options, outline?: boolean, borderRadius?: number): SVGGElement;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { PlaitBoard, PlaitElement, RectangleClient } from '../interfaces';
|
|
2
|
+
export declare function getRectangleByElements(board: PlaitBoard, elements: PlaitElement[], recursion: boolean): RectangleClient;
|
|
3
|
+
export declare function getBoardRectangle(board: PlaitBoard): RectangleClient;
|
package/utils/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from './board';
|
|
2
2
|
export * from './dom';
|
|
3
3
|
export * from './environment';
|
|
4
|
-
export * from './graph';
|
|
5
4
|
export * from './helper';
|
|
6
5
|
export * from './history';
|
|
7
6
|
export * from './hotkeys';
|
|
@@ -9,3 +8,8 @@ export * from './id-creator';
|
|
|
9
8
|
export * from './math';
|
|
10
9
|
export * from './matrix';
|
|
11
10
|
export * from './weak-maps';
|
|
11
|
+
export * from './selected-element';
|
|
12
|
+
export * from './draw/rectangle';
|
|
13
|
+
export * from './draw/arrow';
|
|
14
|
+
export * from './tree';
|
|
15
|
+
export * from './element';
|
package/utils/math.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RectangleClient } from '../interfaces/rectangle-client';
|
|
1
2
|
export declare function distanceBetweenPointAndSegment(x: number, y: number, x1: number, y1: number, x2: number, y2: number): number;
|
|
2
3
|
export declare function rotate(x1: number, y1: number, x2: number, y2: number, angle: number): number[];
|
|
3
4
|
export declare function distanceBetweenPointAndPoint(x1: number, y1: number, x2: number, y2: number): number;
|
|
5
|
+
export declare function distanceBetweenPointAndRectangle(x: number, y: number, rect: RectangleClient): number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PlaitBoard } from '../interfaces/board';
|
|
2
|
+
import { PlaitElement } from '../interfaces/element';
|
|
3
|
+
export declare const calcElementIntersectionSelection: (board: PlaitBoard) => PlaitElement[];
|
|
4
|
+
export declare const cacheSelectedElements: (board: PlaitBoard, selectedElements: PlaitElement[]) => void;
|
|
5
|
+
export declare const getSelectedElements: (board: PlaitBoard) => PlaitElement[];
|
|
6
|
+
export declare const addSelectedElement: (board: PlaitBoard, element: PlaitElement) => void;
|
|
7
|
+
export declare const removeSelectedElement: (board: PlaitBoard, element: PlaitElement) => void;
|
|
8
|
+
export declare const isSelectedElement: (board: PlaitBoard, element: PlaitElement) => boolean;
|
package/utils/tree.d.ts
ADDED
package/utils/weak-maps.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { RoughSVG } from 'roughjs/bin/svg';
|
|
2
2
|
import { BoardComponentInterface } from '../board/board.component.interface';
|
|
3
|
+
import { PlaitElement } from '../interfaces/element';
|
|
3
4
|
import { PlaitBoard } from '../interfaces/board';
|
|
5
|
+
import { Point } from '../interfaces/point';
|
|
4
6
|
export declare const FLUSHING: WeakMap<PlaitBoard, boolean>;
|
|
5
7
|
export declare const IS_TEXT_EDITABLE: WeakMap<PlaitBoard, boolean>;
|
|
6
8
|
export declare const BOARD_TO_ON_CHANGE: WeakMap<PlaitBoard, () => void>;
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
+
export declare const BOARD_TO_COMPONENT: WeakMap<PlaitBoard, BoardComponentInterface>;
|
|
10
|
+
export declare const BOARD_TO_ROUGH_SVG: WeakMap<PlaitBoard, RoughSVG>;
|
|
11
|
+
export declare const BOARD_TO_HOST: WeakMap<PlaitBoard, SVGSVGElement>;
|
|
12
|
+
export declare const BOARD_TO_ELEMENT_HOST: WeakMap<PlaitBoard, SVGGElement>;
|
|
13
|
+
export declare const BOARD_TO_SELECTED_ELEMENT: WeakMap<PlaitBoard, PlaitElement[]>;
|
|
14
|
+
export declare const BOARD_TO_MOVING_POINT: WeakMap<PlaitBoard, Point>;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3JhcGguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wYWNrYWdlcy9wbGFpdC9zcmMvaW50ZXJmYWNlcy9ncmFwaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGludGVyZmFjZSBSZWN0YW5nbGVDbGllbnQge1xuICAgIHg6IG51bWJlcjtcbiAgICB5OiBudW1iZXI7XG4gICAgd2lkdGg6IG51bWJlcjtcbiAgICBoZWlnaHQ6IG51bWJlcjtcbn1cbiJdfQ==
|
package/esm2020/utils/graph.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function toRectangleClient(points) {
|
|
2
|
-
const xArray = points.map(ele => ele[0]);
|
|
3
|
-
const yArray = points.map(ele => ele[1]);
|
|
4
|
-
const xMin = Math.min(...xArray);
|
|
5
|
-
const xMax = Math.max(...xArray);
|
|
6
|
-
const yMin = Math.min(...yArray);
|
|
7
|
-
const yMax = Math.max(...yArray);
|
|
8
|
-
const rect = { x: xMin, y: yMin, width: xMax - xMin, height: yMax - yMin };
|
|
9
|
-
return rect;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3JhcGguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wYWNrYWdlcy9wbGFpdC9zcmMvdXRpbHMvZ3JhcGgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0EsTUFBTSxVQUFVLGlCQUFpQixDQUFDLE1BQXNCO0lBQ3BELE1BQU0sTUFBTSxHQUFHLE1BQU0sQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLEVBQUUsQ0FBQyxHQUFHLENBQU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