@ue-too/board 0.5.1

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.
Files changed (55) hide show
  1. package/LICENSE.txt +19 -0
  2. package/board.tsbuildinfo +1 -0
  3. package/boardify/index.d.ts +192 -0
  4. package/camera/base.d.ts +189 -0
  5. package/camera/camera-mux/animation-and-lock/animation-and-lock.d.ts +50 -0
  6. package/camera/camera-mux/animation-and-lock/index.d.ts +4 -0
  7. package/camera/camera-mux/animation-and-lock/pan-control-state-machine.d.ts +137 -0
  8. package/camera/camera-mux/animation-and-lock/rotation-control-state-machine.d.ts +131 -0
  9. package/camera/camera-mux/animation-and-lock/zoom-control-state-machine.d.ts +143 -0
  10. package/camera/camera-mux/index.d.ts +3 -0
  11. package/camera/camera-mux/interface.d.ts +12 -0
  12. package/camera/camera-mux/relay.d.ts +27 -0
  13. package/camera/camera-rig/camera-rig.d.ts +207 -0
  14. package/camera/camera-rig/index.d.ts +5 -0
  15. package/camera/camera-rig/pan-handler.d.ts +113 -0
  16. package/camera/camera-rig/rotation-handler.d.ts +78 -0
  17. package/camera/camera-rig/update-batcher/index.d.ts +3 -0
  18. package/camera/camera-rig/update-batcher/position-update-batcher.d.ts +58 -0
  19. package/camera/camera-rig/update-batcher/rotation-update-batcher.d.ts +54 -0
  20. package/camera/camera-rig/update-batcher/zoom-udpate-batcher.d.ts +60 -0
  21. package/camera/camera-rig/zoom-handler.d.ts +77 -0
  22. package/camera/default-camera.d.ts +170 -0
  23. package/camera/index.d.ts +8 -0
  24. package/camera/interface.d.ts +59 -0
  25. package/camera/update-publisher.d.ts +172 -0
  26. package/camera/utils/coordinate-conversion.d.ts +75 -0
  27. package/camera/utils/index.d.ts +5 -0
  28. package/camera/utils/matrix.d.ts +114 -0
  29. package/camera/utils/position.d.ts +71 -0
  30. package/camera/utils/rotation.d.ts +64 -0
  31. package/camera/utils/zoom.d.ts +25 -0
  32. package/index.d.ts +5 -0
  33. package/index.js +2 -0
  34. package/index.js.map +1 -0
  35. package/input-interpretation/index.d.ts +3 -0
  36. package/input-interpretation/input-state-machine/index.d.ts +4 -0
  37. package/input-interpretation/input-state-machine/kmt-input-context.d.ts +130 -0
  38. package/input-interpretation/input-state-machine/kmt-input-state-machine.d.ts +194 -0
  39. package/input-interpretation/input-state-machine/touch-input-context.d.ts +44 -0
  40. package/input-interpretation/input-state-machine/touch-input-state-machine.d.ts +64 -0
  41. package/input-interpretation/raw-input-parser/index.d.ts +2 -0
  42. package/input-interpretation/raw-input-parser/vanilla-kmt-event-parser.d.ts +87 -0
  43. package/input-interpretation/raw-input-parser/vanilla-touch-event-parser.d.ts +55 -0
  44. package/input-interpretation/raw-input-publisher/index.d.ts +1 -0
  45. package/input-interpretation/raw-input-publisher/raw-input-publisher.d.ts +130 -0
  46. package/package.json +39 -0
  47. package/utils/canvas-position-dimension.d.ts +18 -0
  48. package/utils/coorindate-conversion.d.ts +5 -0
  49. package/utils/drawing-utils.d.ts +55 -0
  50. package/utils/drawing.d.ts +30 -0
  51. package/utils/handler-pipeline.d.ts +30 -0
  52. package/utils/index.d.ts +8 -0
  53. package/utils/observable.d.ts +9 -0
  54. package/utils/ruler.d.ts +1 -0
  55. package/utils/zoomlevel-adjustment.d.ts +28 -0
@@ -0,0 +1,130 @@
1
+ import type { Point } from "@ue-too/math";
2
+ import { CameraMux } from "../../camera/camera-mux";
3
+ import { ObservableBoardCamera } from "../../camera/interface";
4
+ /**
5
+ * @description The unsubscribe to user raw input.
6
+ *
7
+ * @category Event Parser
8
+ */
9
+ export type UnsubscribeToUserRawInput = () => void;
10
+ /**
11
+ * @description The raw user pan input event payload.
12
+ *
13
+ * @category Event Parser
14
+ */
15
+ export type RawUserPanInputEventPayload = {
16
+ diff: Point;
17
+ };
18
+ /**
19
+ * @description The raw user pan input event.
20
+ * Use type to discriminate between pan, zoom, and rotate events.
21
+ *
22
+ * @category Event Parser
23
+ */
24
+ export type RawUserPanInputEvent = {
25
+ type: "pan";
26
+ } & RawUserPanInputEventPayload;
27
+ /**
28
+ * @description The raw user zoom input event payload.
29
+ *
30
+ * @category Event Parser
31
+ */
32
+ export type RawUserZoomInputEventPayload = {
33
+ deltaZoomAmount: number;
34
+ anchorPoint: Point;
35
+ };
36
+ /**
37
+ * @description The raw user zoom input event.
38
+ * Use type to discriminate between pan, zoom, and rotate events.
39
+ *
40
+ * @category Event Parser
41
+ */
42
+ export type RawUserZoomInputEvent = {
43
+ type: "zoom";
44
+ } & RawUserZoomInputEventPayload;
45
+ /**
46
+ * @description The raw user rotate input event payload.
47
+ *
48
+ * @category Event Parser
49
+ */
50
+ export type RawUserRotateInputEventPayload = {
51
+ deltaRotation: number;
52
+ };
53
+ /**
54
+ * @description The raw user rotate input event.
55
+ * Use type to discriminate between pan, zoom, and rotate events.
56
+ *
57
+ * @category Event Parser
58
+ */
59
+ export type RawUserRotateInputEvent = {
60
+ type: "rotate";
61
+ } & RawUserRotateInputEventPayload;
62
+ /**
63
+ * @description The raw user input event map.
64
+ *
65
+ * @category Event Parser
66
+ */
67
+ export type RawUserInputEventMap = {
68
+ "pan": RawUserPanInputEventPayload;
69
+ "zoom": RawUserZoomInputEventPayload;
70
+ "rotate": RawUserRotateInputEventPayload;
71
+ "all": RawUserInputEvent;
72
+ };
73
+ /**
74
+ * @description The raw user input event.
75
+ * Use type to discriminate between pan, zoom, and rotate events.
76
+ *
77
+ * @category Event Parser
78
+ */
79
+ export type RawUserInputEvent = RawUserPanInputEvent | RawUserZoomInputEvent | RawUserRotateInputEvent;
80
+ /**
81
+ * @description The raw user input callback.
82
+ * This is the function type of callbacks for raw user input events.
83
+ *
84
+ * @category Event Parser
85
+ */
86
+ export type RawUserInputCallback<K extends keyof RawUserInputEventMap> = (event: RawUserInputEventMap[K]) => void;
87
+ export interface UserInputPublisher {
88
+ notifyPan(diff: Point): void;
89
+ notifyZoom(deltaZoomAmount: number, anchorPoint: Point): void;
90
+ notifyRotate(deltaRotation: number): void;
91
+ on<K extends keyof RawUserInputEventMap>(eventName: K, callback: (event: RawUserInputEventMap[K]) => void): UnsubscribeToUserRawInput;
92
+ }
93
+ /**
94
+ * @description The raw user input publisher.
95
+ * Publishs raw user input events to the input flow control, and subscribers.
96
+ *
97
+ * @category Event Parser
98
+ */
99
+ export declare class RawUserInputPublisher implements UserInputPublisher {
100
+ private pan;
101
+ private zoom;
102
+ private rotate;
103
+ private all;
104
+ private _cameraMux;
105
+ constructor(cameraMux: CameraMux);
106
+ notifyPan(diff: Point): void;
107
+ notifyZoom(deltaZoomAmount: number, anchorPoint: Point): void;
108
+ notifyRotate(deltaRotation: number): void;
109
+ on<K extends keyof RawUserInputEventMap>(eventName: K, callback: (event: RawUserInputEventMap[K]) => void): UnsubscribeToUserRawInput;
110
+ get cameraMux(): CameraMux;
111
+ set cameraMux(cameraMux: CameraMux);
112
+ }
113
+ /**
114
+ * @description Creates a default raw user input publisher.
115
+ *
116
+ * @category Event Parser
117
+ */
118
+ export declare function createDefaultRawUserInputPublisher(camera: ObservableBoardCamera): RawUserInputPublisher;
119
+ export declare class RawUserInputPublisherWithWebWorkerRelay implements UserInputPublisher {
120
+ private pan;
121
+ private zoom;
122
+ private rotate;
123
+ private all;
124
+ private webWorker;
125
+ constructor(webWorker: Worker);
126
+ notifyPan(diff: Point): void;
127
+ notifyZoom(deltaZoomAmount: number, anchorPoint: Point): void;
128
+ notifyRotate(deltaRotation: number): void;
129
+ on<K extends keyof RawUserInputEventMap>(eventName: K, callback: (event: RawUserInputEventMap[K]) => void): UnsubscribeToUserRawInput;
130
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@ue-too/board",
3
+ "type": "module",
4
+ "version": "0.5.1",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./index.d.ts",
8
+ "import": "./index.js",
9
+ "default": "./index.js"
10
+ },
11
+ "./package.json": "./package.json"
12
+ },
13
+ "main": "./index.js",
14
+ "types": "./index.d.ts",
15
+ "module": "./index.js",
16
+ "dependencies": {
17
+ "@ue-too/math": "^0.5.1",
18
+ "@ue-too/being": "^0.5.1"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/ue-too/ue-too.git"
23
+ },
24
+ "author": "niuee",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/ue-too/ue-too/issues"
28
+ },
29
+ "homepage": "https://github.com/ue-too/ue-too#readme",
30
+ "keywords": [
31
+ "canvas",
32
+ "infinite-canvas",
33
+ "pixi.js",
34
+ "PIXI"
35
+ ],
36
+ "scripts": {
37
+ "test": "echo \"Error: no test specified\" && exit 1"
38
+ }
39
+ }
@@ -0,0 +1,18 @@
1
+ import { Observer, SubscriptionOptions } from "../utils/observable";
2
+ export type CanvasUpdateObserver = (rect: DOMRect) => void;
3
+ export declare class CanvasPositionDimensionPublisher {
4
+ private lastRect;
5
+ private resizeObserver;
6
+ private intersectionObserver;
7
+ private scrollHandler;
8
+ private resizeHandler;
9
+ private _observers;
10
+ constructor(canvas: HTMLCanvasElement);
11
+ dispose(): void;
12
+ attach(canvas: HTMLCanvasElement): void;
13
+ private publishPositionUpdate;
14
+ onPositionUpdate(observer: Observer<[DOMRect]>, options?: SubscriptionOptions): void;
15
+ }
16
+ export declare function getTrueRect(rect: DOMRect, computedStyle: CSSStyleDeclaration): DOMRect;
17
+ export declare function reverseYAxis(context: CanvasRenderingContext2D): CanvasRenderingContext2D;
18
+ export declare function invertYAxisForDrawImageWith9Args(args: any[]): typeof args;
@@ -0,0 +1,5 @@
1
+ import { Point } from "@ue-too/math";
2
+ export declare function pointConversion(point: Point): {
3
+ x: number;
4
+ y: number;
5
+ };
@@ -0,0 +1,55 @@
1
+ import type { Point } from "@ue-too/math";
2
+ import { Boundaries } from "../camera/utils/position";
3
+ /**
4
+ * @description Draws a crosshair on the canvas.
5
+ * @deprecated
6
+ *
7
+ * @category Board
8
+ */
9
+ export declare function drawCrossHair(context: CanvasRenderingContext2D, pos: Point, cameraZoomLevel: number, alignCoordinateSystem: boolean, size: number, color?: string): void;
10
+ /**
11
+ * @description Draws a bounding box on the canvas.
12
+ * @deprecated
13
+ *
14
+ * @category Board
15
+ */
16
+ export declare function drawBoundingBox(context: CanvasRenderingContext2D, boundaries: Boundaries, alignCoordinateSystem: boolean): void;
17
+ /**
18
+ * @description Draws the axis of the board.
19
+ * @deprecated
20
+ *
21
+ * @category Board
22
+ */
23
+ export declare function drawAxis(context: CanvasRenderingContext2D, boundaries: Boundaries, zoomLevel: number, alignCoordinateSystem: boolean): void;
24
+ /**
25
+ * @description Draws the grid of the board.
26
+ * argument points are in world space
27
+ * @deprecated
28
+ *
29
+ * @category Board
30
+ */
31
+ export declare function drawGrid(context: CanvasRenderingContext2D, topLeftCorner: Point, topRightCorner: Point, bottomLeftCorner: Point, bottomRightCorner: Point, alignCoordinateSystem: boolean, cameraZoomLevel: number): void;
32
+ /**
33
+ * @description Draws a ruler on the canvas.
34
+ * argument points are in world space
35
+ * @deprecated
36
+ *
37
+ * @category Board
38
+ */
39
+ export declare function drawRulerLegacy(context: CanvasRenderingContext2D, topLeftCorner: Point, topRightCorner: Point, bottomLeftCorner: Point, bottomRightCorner: Point, alignCoordinateSystem: boolean, cameraZoomLevel: number): void;
40
+ /**
41
+ * @description Draws the position text on the canvas.
42
+ * argument points are in world space
43
+ * @deprecated
44
+ *
45
+ * @category Board
46
+ */
47
+ export declare function drawPositionText(context: CanvasRenderingContext2D, pos: Point, cameraZoomLevel: number, alignCoordinateSystem: boolean, offset?: number, color?: string): void;
48
+ /**
49
+ * @description Draws a reference circle on the canvas.
50
+ * argument points are in world space
51
+ * @deprecated
52
+ *
53
+ * @category Board
54
+ */
55
+ export declare function drawReferenceCircle(context: CanvasRenderingContext2D, pos: Point, alignCoordinateSystem: boolean): void;
@@ -0,0 +1,30 @@
1
+ import { Point } from "@ue-too/math";
2
+ export declare function drawArrow(context: CanvasRenderingContext2D, cameraZoomLevel: number, startPoint: Point, endPoint: Point, width?: number, arrowRatio?: number): void;
3
+ export declare const MAJOR_TICK_LENGTH = 30;
4
+ export declare const MINOR_TICK_LENGTH: number;
5
+ export declare const HALF_TICK_LENGTH: number;
6
+ export declare const TEXT_MAJOR_TICK_OFFSET = 10;
7
+ export declare const TEXT_HALF_TICK_OFFSET = 2.5;
8
+ export declare const TEXT_MAJOR_TICK_FONT_SIZE = 20;
9
+ export declare const TEXT_HALF_TICK_FONT_SIZE = 10;
10
+ /**
11
+ * @description Draws a ruler on the canvas.
12
+ * argument points are in world space
13
+ *
14
+ * @category Utils
15
+ *
16
+ */
17
+ export declare function drawRuler(context: CanvasRenderingContext2D, topLeftCorner: Point, topRightCorner: Point, bottomLeftCorner: Point, alignCoordinateSystem: boolean, cameraZoomLevel: number): void;
18
+ export declare function calculateTickValues(minValue: number, maxValue: number, orderOfMagnitude?: number): {
19
+ minMajorTickValue: number;
20
+ maxMajorTickValue: number;
21
+ majorTickStep: number;
22
+ minMinTickValue: number;
23
+ maxMaxTickValue: number;
24
+ minTickStep: number;
25
+ minHalfTickValue: number;
26
+ maxHalfTickValue: number;
27
+ halfTickStep: number;
28
+ calibrationMultiplier: number;
29
+ normalizedOrderOfMagnitude: number;
30
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @description Type definition for a handler function that takes a generic value and additional arguments
3
+ * The handler must return the same type as its first argument
4
+ * This is a utility type to be used in the handler pipeline. (Probably don't need to use this directly)
5
+ * Using the {@link createHandlerChain} function to create a handler chain would have typescript infer the correct type for the handler chain.
6
+ *
7
+ * @category Utils
8
+ */
9
+ export type Handler<T, Args extends any[]> = (value: T, ...args: Args) => T;
10
+ /**
11
+ * @description Creates a handler chain from an array of handlers.
12
+ *
13
+ * Use it like this:
14
+ * ```typescript
15
+ * const handlerChain = createHandlerChain(handler1, handler2, handler3);
16
+ * ```
17
+ * or like this:
18
+ * ```typescript
19
+ * const handlers = [handler1, handler2, handler3];
20
+ * const handlerChain = createHandlerChain(handlers);
21
+ * ```
22
+ *
23
+ * The function signature of all the handlers must be the same. (if they're not, you need to explicitly specify the type for the handler chain)
24
+ *
25
+ * @param handlers Array of handler functions to be chained
26
+ * @returns A single handler function that executes all handlers in sequence
27
+ *
28
+ * @category Utils
29
+ */
30
+ export declare function createHandlerChain<T, Args extends any[]>(...handlers: Handler<T, Args>[] | [Handler<T, Args>[]]): Handler<T, Args>;
@@ -0,0 +1,8 @@
1
+ export * from "./coorindate-conversion";
2
+ export * from "./ruler";
3
+ export * from "./observable";
4
+ export * from "./handler-pipeline";
5
+ export * from "./canvas-position-dimension";
6
+ export * from "./drawing-utils";
7
+ export * from "./drawing";
8
+ export * from "./zoomlevel-adjustment";
@@ -0,0 +1,9 @@
1
+ export type Observer<T extends any[]> = (...data: T) => void;
2
+ export interface SubscriptionOptions {
3
+ signal?: AbortSignal;
4
+ }
5
+ export declare class Observable<T extends any[]> {
6
+ private observers;
7
+ subscribe(observer: Observer<T>, options?: SubscriptionOptions): () => void;
8
+ notify(...data: T): void;
9
+ }
@@ -0,0 +1 @@
1
+ export declare function calculateOrderOfMagnitude(value: number): number;
@@ -0,0 +1,28 @@
1
+ import { Boundaries } from "../camera/utils/position";
2
+ import { ZoomLevelLimits } from "../camera/utils/zoom";
3
+ /**
4
+ * @description Calculates the minimum zoom level based on the dimensions of the boundaries.
5
+ * Used when the canvas on the html is resized.
6
+ *
7
+ * @category Camera
8
+ */
9
+ export declare function minZoomLevelBaseOnDimensions(boundaries: Boundaries | undefined, canvasWidth: number, canvasHeight: number, cameraRotation: number): number | undefined;
10
+ /**
11
+ * @description Determines if the zoom level boundaries should be updated when the canvas is resized.
12
+ * Zoom level boundaries adjustment only tightens the zoom level boundaries; it does not relax them.
13
+ *
14
+ * @category Camera
15
+ */
16
+ export declare function zoomLevelBoundariesShouldUpdate(zoomLevelBoundaries: ZoomLevelLimits | undefined, targetMinZoomLevel: number | undefined): boolean;
17
+ /**
18
+ * @description Calculates the minimum zoom level based on the width of the boundaries.
19
+ * Used when the canvas on the html is resized.
20
+ * @category Camera
21
+ */
22
+ export declare function minZoomLevelBaseOnWidth(boundaries: Boundaries | undefined, canvasWidth: number, canvasHeight: number, cameraRotation: number): number | undefined;
23
+ /**
24
+ * @description Calculates the minimum zoom level based on the height of the boundaries.
25
+ * Used when the canvas on the html is resized.
26
+ * @category Camera
27
+ */
28
+ export declare function minZoomLevelBaseOnHeight(boundaries: Boundaries | undefined, canvasWidth: number, canvasHeight: number, cameraRotation: number): number | undefined;