@lupinum/board-core 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/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/chunk-5JZXHZWR.js +68 -0
- package/dist/colors.d.ts +9 -0
- package/dist/engine/camera-session.d.ts +14 -0
- package/dist/engine/command-runtime.d.ts +31 -0
- package/dist/engine/events.d.ts +21 -0
- package/dist/engine/interaction-adapter.d.ts +3 -0
- package/dist/engine/node-shape.d.ts +16 -0
- package/dist/engine/options.d.ts +17 -0
- package/dist/engine/persistence.d.ts +18 -0
- package/dist/engine/subscribables.d.ts +34 -0
- package/dist/engine/transaction.d.ts +56 -0
- package/dist/engine.d.ts +17 -0
- package/dist/errors.d.ts +17 -0
- package/dist/helpers/animation.d.ts +9 -0
- package/dist/helpers/clone.d.ts +6 -0
- package/dist/helpers/ids.d.ts +2 -0
- package/dist/helpers/node-shape.d.ts +2 -0
- package/dist/helpers/selection-helpers.d.ts +8 -0
- package/dist/hierarchy.d.ts +16 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +4159 -0
- package/dist/internal.d.ts +9 -0
- package/dist/internal.js +10 -0
- package/dist/invariants.d.ts +3 -0
- package/dist/math.d.ts +16 -0
- package/dist/resize.d.ts +26 -0
- package/dist/selection.d.ts +7 -0
- package/dist/snap.d.ts +29 -0
- package/dist/state/initial.d.ts +2 -0
- package/dist/state/selectors.d.ts +5 -0
- package/dist/state/types.d.ts +31 -0
- package/dist/subscribable.d.ts +20 -0
- package/dist/types.d.ts +576 -0
- package/package.json +50 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { InternalBoardCommit, InternalHistoryRoot } from './state/types.js';
|
|
2
|
+
export type { InternalBoardPlugin, InternalBoardPluginDefinition, InternalInteractionAdapter, InternalPluginContext, InternalPluginPersistence, } from './types.js';
|
|
3
|
+
/** Resolve the unsupported first-party pointer/session surface used by framework adapters. */
|
|
4
|
+
export declare function getBoardInteractionAdapter(engine: import('./types.js').BoardEngine): InternalInteractionAdapter;
|
|
5
|
+
import type { BoardEventMap, BoardPlugin, BoardPluginApis, InternalBoardPlugin, InternalBoardPluginDefinition, InternalInteractionAdapter } from './types.js';
|
|
6
|
+
export declare function defineInternalBoardPlugin<TPluginApis extends BoardPluginApis = BoardPluginApis, TEvents extends {
|
|
7
|
+
[K in keyof TEvents]: (...args: never[]) => unknown;
|
|
8
|
+
} = BoardEventMap>(plugin: InternalBoardPluginDefinition<TPluginApis, TEvents>): InternalBoardPlugin<TPluginApis, TEvents>;
|
|
9
|
+
export declare function assertInternalBoardPlugin(plugin: BoardPlugin): asserts plugin is InternalBoardPlugin;
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BoardState, GridSettings, ValidationFailure, InteractionState } from './types.js';
|
|
2
|
+
export declare function cloneInteraction(interaction: InteractionState): InteractionState;
|
|
3
|
+
export declare function validateState(state: BoardState, grid: GridSettings, context: string): ValidationFailure[];
|
package/dist/math.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Bounds, Camera, Point } from './types.js';
|
|
2
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
3
|
+
export declare function lerp(a: number, b: number, t: number): number;
|
|
4
|
+
export declare function lerpCamera(from: Camera, to: Camera, t: number): Camera;
|
|
5
|
+
export declare function screenToWorld(point: Point, camera: Camera): Point;
|
|
6
|
+
export declare function worldToScreen(point: Point, camera: Camera): Point;
|
|
7
|
+
export declare function getVisibleBounds(width: number, height: number, camera: Camera): Bounds;
|
|
8
|
+
export declare function pointInBounds(point: Point, bounds: Bounds): boolean;
|
|
9
|
+
export declare function boundsIntersect(a: Bounds, b: Bounds): boolean;
|
|
10
|
+
export declare function boundsContain(outer: Bounds, inner: Bounds): boolean;
|
|
11
|
+
export declare function getBoundsFromPoints(a: Point, b: Point): Bounds;
|
|
12
|
+
export declare function snapValue(value: number, step: number): number;
|
|
13
|
+
export declare function snapPoint(point: Point, step: number): Point;
|
|
14
|
+
export declare function snapBounds(bounds: Bounds, step: number): Bounds;
|
|
15
|
+
export declare function snapSize(value: number, step: number, min: number): number;
|
|
16
|
+
export declare function zoomCameraAtScreenPoint(screenPoint: Point, delta: number, camera: Camera, min: number, max: number): Camera;
|
package/dist/resize.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BoardNode, ResizeHandle } from './types.js';
|
|
2
|
+
interface ResizeConstraints {
|
|
3
|
+
minWidth: number;
|
|
4
|
+
minHeight: number;
|
|
5
|
+
}
|
|
6
|
+
type NodeBounds = Pick<BoardNode, 'x' | 'y' | 'width' | 'height'>;
|
|
7
|
+
export declare function applyResizeDelta(node: NodeBounds, handle: ResizeHandle, deltaX: number, deltaY: number, constraints: ResizeConstraints): NodeBounds;
|
|
8
|
+
export declare function snapResizedBounds(bounds: NodeBounds, handle: ResizeHandle, gridSize: number, constraints: ResizeConstraints): NodeBounds;
|
|
9
|
+
/**
|
|
10
|
+
* Aspect-ratio-locked variant of applyResizeDelta.
|
|
11
|
+
*
|
|
12
|
+
* For corner handles the dominant axis (larger normalised delta) drives the
|
|
13
|
+
* resize and the other axis is computed from `aspectRatio = width / height`.
|
|
14
|
+
* For edge handles the active axis drives and the perpendicular axis is
|
|
15
|
+
* derived, effectively upgrading the handle to its nearest corner.
|
|
16
|
+
*/
|
|
17
|
+
export declare function applyResizeDeltaLocked(node: NodeBounds, handle: ResizeHandle, deltaX: number, deltaY: number, constraints: ResizeConstraints, aspectRatio: number): NodeBounds;
|
|
18
|
+
/**
|
|
19
|
+
* Aspect-ratio-preserving snap. Snaps the primary dimension to the grid
|
|
20
|
+
* and derives the secondary exactly from the ratio so the shape stays true.
|
|
21
|
+
*
|
|
22
|
+
* For N / S handles height is primary; for everything else width is primary.
|
|
23
|
+
* `startBounds` is needed to keep the fixed edge anchored after snapping.
|
|
24
|
+
*/
|
|
25
|
+
export declare function snapResizedBoundsLocked(bounds: NodeBounds, startBounds: NodeBounds, handle: ResizeHandle, gridSize: number, constraints: ResizeConstraints, aspectRatio: number): NodeBounds;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Bounds, BoardEngine, BoardNode, NodeId } from './types.js';
|
|
2
|
+
/** Return the currently selected nodes in snapshot order. */
|
|
3
|
+
export declare function getSelectionNodes(engine: BoardEngine): BoardNode[];
|
|
4
|
+
/** Compute the bounding box of the current selection, or `null` when empty. */
|
|
5
|
+
export declare function getSelectionBounds(engine: BoardEngine): Bounds | null;
|
|
6
|
+
/** Toggle a list of ids in an existing selection array. */
|
|
7
|
+
export declare function toggleIds(current: NodeId[], ids: NodeId[]): NodeId[];
|
package/dist/snap.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BoardNode, NodeId, ResizeHandle, SnapAxis, SnapGuide } from './types.js';
|
|
2
|
+
interface EdgeCandidate {
|
|
3
|
+
axis: SnapAxis;
|
|
4
|
+
value: number;
|
|
5
|
+
extentMin: number;
|
|
6
|
+
extentMax: number;
|
|
7
|
+
nodeId?: NodeId;
|
|
8
|
+
}
|
|
9
|
+
export interface SnapEdgeIndex {
|
|
10
|
+
readonly x: readonly EdgeCandidate[];
|
|
11
|
+
readonly y: readonly EdgeCandidate[];
|
|
12
|
+
}
|
|
13
|
+
export interface SnapResult {
|
|
14
|
+
bounds: Pick<BoardNode, 'x' | 'y' | 'width' | 'height'>;
|
|
15
|
+
guides: SnapGuide[];
|
|
16
|
+
}
|
|
17
|
+
export interface DragSnapResult {
|
|
18
|
+
dx: number;
|
|
19
|
+
dy: number;
|
|
20
|
+
guides: SnapGuide[];
|
|
21
|
+
}
|
|
22
|
+
export declare function collectNodeEdges(node: Pick<BoardNode, 'x' | 'y' | 'width' | 'height'>): EdgeCandidate[];
|
|
23
|
+
export declare function collectOtherNodeEdges(nodes: Iterable<BoardNode>, excludeId: NodeId): EdgeCandidate[];
|
|
24
|
+
export declare function collectOtherNodeEdgesExcluding(nodes: Iterable<BoardNode>, excludeIds: Set<NodeId>): EdgeCandidate[];
|
|
25
|
+
/** Rebuildable index derived only from the current canonical node root. */
|
|
26
|
+
export declare function buildSnapEdgeIndex(nodes: Iterable<BoardNode>): SnapEdgeIndex;
|
|
27
|
+
export declare function snapBoundsToEdges(bounds: Pick<BoardNode, 'x' | 'y' | 'width' | 'height'>, handle: ResizeHandle, otherEdges: EdgeCandidate[] | SnapEdgeIndex, threshold: number, excludeIds?: ReadonlySet<NodeId>): SnapResult;
|
|
28
|
+
export declare function snapPositionToEdges(bounds: Pick<BoardNode, 'x' | 'y' | 'width' | 'height'>, otherEdges: EdgeCandidate[] | SnapEdgeIndex, threshold: number, excludeIds?: ReadonlySet<NodeId>): DragSnapResult;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { InternalBoardSnapshot, BoardState, BoardNode, GridSettings, NodeId } from '../types.js';
|
|
2
|
+
import type { MutableBoardState } from './types.js';
|
|
3
|
+
export declare function buildPublicNodeMap(state: Pick<MutableBoardState, 'nodes'>): ReadonlyMap<NodeId, BoardNode>;
|
|
4
|
+
export declare function buildSnapshot(state: MutableBoardState, grid: GridSettings, publicNodes: ReadonlyMap<NodeId, BoardNode>): InternalBoardSnapshot;
|
|
5
|
+
export declare function buildPublicState(state: MutableBoardState, grid: GridSettings, publicNodes: ReadonlyMap<NodeId, BoardNode>): BoardState;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BoardEventMap, BoardNode, Camera, CommandMetadata, GridSettings, InteractionState, NodeConstraints, NodeId, Point, SnapGuide, ZoomSettings } from '../types.js';
|
|
2
|
+
export declare const DEFAULT_CAMERA: Camera;
|
|
3
|
+
export declare const DEFAULT_ZOOM: ZoomSettings;
|
|
4
|
+
export declare const DEFAULT_GRID: GridSettings;
|
|
5
|
+
export declare const DEFAULT_NODE_CONSTRAINTS: NodeConstraints;
|
|
6
|
+
export declare const DEFAULT_VIEWPORT_SIZE: Point;
|
|
7
|
+
export interface MutableBoardState {
|
|
8
|
+
camera: Camera;
|
|
9
|
+
nodes: Map<NodeId, BoardNode>;
|
|
10
|
+
selection: Set<NodeId>;
|
|
11
|
+
interaction: InteractionState;
|
|
12
|
+
snapGuides: SnapGuide[];
|
|
13
|
+
nextZIndex: number;
|
|
14
|
+
}
|
|
15
|
+
export type ListenerMap = Map<keyof BoardEventMap, Set<(...args: unknown[]) => void>>;
|
|
16
|
+
/** Structurally shared persistent state captured by first-party history. */
|
|
17
|
+
export interface InternalHistoryRoot {
|
|
18
|
+
readonly nodes: ReadonlyMap<NodeId, BoardNode>;
|
|
19
|
+
readonly grid: GridSettings;
|
|
20
|
+
readonly selection: ReadonlySet<NodeId>;
|
|
21
|
+
readonly nextZIndex: number;
|
|
22
|
+
readonly pluginSlices: ReadonlyMap<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
/** A successfully published outer command. */
|
|
25
|
+
export interface InternalBoardCommit {
|
|
26
|
+
readonly label: string;
|
|
27
|
+
readonly timestamp: number;
|
|
28
|
+
readonly metadata: CommandMetadata;
|
|
29
|
+
readonly before: InternalHistoryRoot;
|
|
30
|
+
readonly after: InternalHistoryRoot;
|
|
31
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Subscribable } from './types.js';
|
|
2
|
+
/** Batch coordination shared across the subscribables owned by one engine instance. */
|
|
3
|
+
export interface BatchController {
|
|
4
|
+
depth: number;
|
|
5
|
+
pending: Set<() => void>;
|
|
6
|
+
rollbacks: Set<() => void>;
|
|
7
|
+
}
|
|
8
|
+
/** Create a batch controller that defers subscriber notifications until the batch completes. */
|
|
9
|
+
export declare function createBatchController(): BatchController;
|
|
10
|
+
/**
|
|
11
|
+
* Create a mutable subscribable value.
|
|
12
|
+
*
|
|
13
|
+
* The returned object implements the public `Subscribable<T>` contract plus
|
|
14
|
+
* `set()` and `notify()` helpers used by the engine internals.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createSubscribable<T>(initial: T, batch: BatchController, reportError: (error: unknown) => void): Subscribable<T> & {
|
|
17
|
+
set(value: T): void;
|
|
18
|
+
notify(): void;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
};
|