@canvus/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/README.md +80 -0
- package/dist/drop-zone.d.ts +48 -0
- package/dist/drop-zone.d.ts.map +1 -0
- package/dist/drop-zone.js +230 -0
- package/dist/drop-zone.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +143 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +278 -0
- package/dist/layout.js.map +1 -0
- package/dist/matrix.d.ts +168 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +264 -0
- package/dist/matrix.js.map +1 -0
- package/dist/renderer.d.ts +286 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +892 -0
- package/dist/renderer.js.map +1 -0
- package/dist/shadow-mount.d.ts +367 -0
- package/dist/shadow-mount.d.ts.map +1 -0
- package/dist/shadow-mount.js +1120 -0
- package/dist/shadow-mount.js.map +1 -0
- package/dist/tree.d.ts +134 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +458 -0
- package/dist/tree.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +43 -0
- package/dist/types.js.map +1 -0
- package/dist/workspace.d.ts +371 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +3922 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Canvus SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@canvus/core)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
Canvus is a headless, framework-agnostic vanilla TypeScript SDK for building visual layout editing workspaces. By separating rendering and visual handles, it enables developers to construct CMS page-builder canvases, A/B testing editors, and high-performance visual IDE tools with web-native performance.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 🚀 Key Features
|
|
11
|
+
|
|
12
|
+
* **Twin-Layer Architecture**: Renders user-supplied HTML/CSS inside an isolated Shadow DOM projection layer, keeping parent editor styles untouched. An HTML5 Canvas overlay runs overlays, coordinates selections, snap lines, and resizing handles.
|
|
13
|
+
* **Zero Framework Dependencies**: Pure TypeScript, compiling to a lightweight ESM bundle.
|
|
14
|
+
* **Operation-Driven State Synchronization**: Exposes discrete mutations (`Operation` delta payloads) for visual gestures, allowing host applications to manage a unified history stack (Undo/Redo) and multiplayer collaboration.
|
|
15
|
+
* **Pluggable Rich Text Escape Hatch**: Features a built-in plain-text editor, with a callback trigger to mount custom rich-text editors (e.g., TipTap or Quill).
|
|
16
|
+
* **Native Class Manipulation**: Supports modifying Tailwind CSS or Bootstrap style classes directly on nodes without relying on inline CSS styling attribute overwrites.
|
|
17
|
+
* **requestAnimationFrame Throttled Rendering**: Canvas repaints are scheduled for the next animation frame, avoiding performance bottlenecks on high-refresh-rate screens.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 📦 Directory Tour
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
canvus/
|
|
25
|
+
├── demo/ # Dev Workbench (Interactive local testing site)
|
|
26
|
+
├── dist/ # Compiled SDK ESM build and type declarations
|
|
27
|
+
├── docs/ # Developer documentation & Architecture Decision Records (ADRs)
|
|
28
|
+
├── src/ # SDK Core source code (TypeScript)
|
|
29
|
+
├── skills/ # Custom Agent/AI skills for codebase tasks
|
|
30
|
+
└── package.json # Scripts, build rules, and dependencies
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
For a detailed walkthrough of each source file and their individual roles, see the [Architecture Guide](file:///Users/balfaro01/Documents/GitHub/canvus/docs/architecture.md).
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 🛠️ Quick Start
|
|
38
|
+
|
|
39
|
+
### 1. Installation
|
|
40
|
+
Install via npm:
|
|
41
|
+
```bash
|
|
42
|
+
npm install @canvus/core
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Basic Usage
|
|
46
|
+
Import and initialize a workspace in your project:
|
|
47
|
+
```ts
|
|
48
|
+
import { Workspace } from "@canvus/core";
|
|
49
|
+
|
|
50
|
+
const workspace = new Workspace(container, {
|
|
51
|
+
html: '<div class="my-layout">Hello Canvus</div>',
|
|
52
|
+
onChange(ops) {
|
|
53
|
+
console.log("Operations:", ops);
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The SDK exports all core primitives — see the [API Reference](docs/api.md) for the full surface.
|
|
59
|
+
|
|
60
|
+
### 3. Development (Contributing)
|
|
61
|
+
To work on the SDK itself, clone the repo and use the local dev scripts:
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/balfaro01/canvus.git
|
|
64
|
+
cd canvus
|
|
65
|
+
npm install
|
|
66
|
+
npm run build # Compile TypeScript → dist/
|
|
67
|
+
npm run demo # Launch workbench at http://localhost:3000
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 📚 Developer Guides
|
|
73
|
+
|
|
74
|
+
To understand how to integrate, configure, and extend the Canvus SDK, explore the following documentation:
|
|
75
|
+
|
|
76
|
+
1. **[Architecture & Reflow Loop Guide](file:///Users/balfaro01/Documents/GitHub/canvus/docs/architecture.md)**: Twin-layer mounting, ResizeObserver integration, and the Synchronous Reflow Loop.
|
|
77
|
+
2. **[Operation Payloads & Undo/Redo](file:///Users/balfaro01/Documents/GitHub/canvus/docs/operations.md)**: Schema design for style, class, hierarchy, and text changes.
|
|
78
|
+
3. **[Custom Editor Integration](file:///Users/balfaro01/Documents/GitHub/canvus/docs/custom-editor-integration.md)**: Mounting TipTap/Quill rich-text editors.
|
|
79
|
+
4. **[Layout & Insertion System](file:///Users/balfaro01/Documents/GitHub/canvus/docs/layout-system.md)**: Deep-dives into Flex/Grid detection, tree hierarchy rules, and drag drop zones.
|
|
80
|
+
5. **[Complete API Reference](file:///Users/balfaro01/Documents/GitHub/canvus/docs/api.md)**: Full catalog of `Workspace` configuration, callback hooks, and API methods.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NodeTree } from "./tree.js";
|
|
2
|
+
import { Rect } from "./types.js";
|
|
3
|
+
/** Visual description of the insertion line segment in canvas-space. */
|
|
4
|
+
export interface InsertionIndicator {
|
|
5
|
+
/** Starting X coordinate in canvas-space. */
|
|
6
|
+
x1: number;
|
|
7
|
+
/** Starting Y coordinate in canvas-space. */
|
|
8
|
+
y1: number;
|
|
9
|
+
/** Ending X coordinate in canvas-space. */
|
|
10
|
+
x2: number;
|
|
11
|
+
/** Ending Y coordinate in canvas-space. */
|
|
12
|
+
y2: number;
|
|
13
|
+
/** Whether the insertion points before or after the reference child. */
|
|
14
|
+
side: "before" | "after";
|
|
15
|
+
}
|
|
16
|
+
/** Resolved drop target descriptor. */
|
|
17
|
+
export interface DropTarget {
|
|
18
|
+
/** The container node ID receiving the dropped element. */
|
|
19
|
+
parentId: string;
|
|
20
|
+
/** Insertion position within the parent's children. */
|
|
21
|
+
insertionIndex: number;
|
|
22
|
+
/** Visual indicator details for rendering. */
|
|
23
|
+
indicator: InsertionIndicator;
|
|
24
|
+
/** Grid placement details, present only if the parent is a grid container. */
|
|
25
|
+
gridPlacement?: {
|
|
26
|
+
colStart: number;
|
|
27
|
+
rowStart: number;
|
|
28
|
+
colSpan: number;
|
|
29
|
+
rowSpan: number;
|
|
30
|
+
rect: Rect;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Traverses the node tree reverse depth-first to find the deepest
|
|
35
|
+
* container under the cursor, computes the insertion point within
|
|
36
|
+
* its CSS flow layout, and returns visual indicator line coordinates.
|
|
37
|
+
*
|
|
38
|
+
* @param draggedId - The ID of the node currently being dragged.
|
|
39
|
+
* @param canvasPos - The current canvas-space cursor position.
|
|
40
|
+
* @param tree - The NodeTree model instance.
|
|
41
|
+
* @param getWrapper - Callback to fetch a mounted wrapper DOM element.
|
|
42
|
+
* @returns The resolved `DropTarget` details, or `null` if empty space.
|
|
43
|
+
*/
|
|
44
|
+
export declare function findDropTarget(draggedId: string, canvasPos: {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
}, tree: NodeTree, getWrapper: (id: string) => HTMLElement | null, getContentRoot?: (id: string) => HTMLElement | null): DropTarget | null;
|
|
48
|
+
//# sourceMappingURL=drop-zone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop-zone.d.ts","sourceRoot":"","sources":["../src/drop-zone.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,2CAA2C;IAC3C,EAAE,EAAE,MAAM,CAAC;IACX,2CAA2C;IAC3C,EAAE,EAAE,MAAM,CAAC;IACX,wEAAwE;IACxE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;CAC1B;AAED,uCAAuC;AACvC,MAAM,WAAW,UAAU;IACzB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,cAAc,EAAE,MAAM,CAAC;IACvB,8CAA8C;IAC9C,SAAS,EAAE,kBAAkB,CAAC;IAC9B,8EAA8E;IAC9E,aAAa,CAAC,EAAE;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,IAAI,CAAC;KACZ,CAAC;CACH;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EACnC,IAAI,EAAE,QAAQ,EACd,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,WAAW,GAAG,IAAI,EAC9C,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,WAAW,GAAG,IAAI,GAClD,UAAU,GAAG,IAAI,CAgOnB"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// canvus/src/drop-zone.ts
|
|
3
|
+
// Flow-Aware Drop Target Detection & Insertion Index Engine.
|
|
4
|
+
//
|
|
5
|
+
// Calculates candidate parent containers and insertion points
|
|
6
|
+
// during drag operations based on container CSS flow layouts.
|
|
7
|
+
// ─────────────────────────────────────────────────────────────
|
|
8
|
+
import { detectLayout, getFlowAxis, parseGridTracks, getGridCellAt, getGridAreaRect } from "./layout.js";
|
|
9
|
+
import { isPointInElement } from "./matrix.js";
|
|
10
|
+
/**
|
|
11
|
+
* Traverses the node tree reverse depth-first to find the deepest
|
|
12
|
+
* container under the cursor, computes the insertion point within
|
|
13
|
+
* its CSS flow layout, and returns visual indicator line coordinates.
|
|
14
|
+
*
|
|
15
|
+
* @param draggedId - The ID of the node currently being dragged.
|
|
16
|
+
* @param canvasPos - The current canvas-space cursor position.
|
|
17
|
+
* @param tree - The NodeTree model instance.
|
|
18
|
+
* @param getWrapper - Callback to fetch a mounted wrapper DOM element.
|
|
19
|
+
* @returns The resolved `DropTarget` details, or `null` if empty space.
|
|
20
|
+
*/
|
|
21
|
+
export function findDropTarget(draggedId, canvasPos, tree, getWrapper, getContentRoot) {
|
|
22
|
+
const reversedNodes = tree.flattenReverse();
|
|
23
|
+
let targetContainer = null;
|
|
24
|
+
// 1. Find the deepest container under the cursor.
|
|
25
|
+
// Exclude the dragged node and all its descendants to prevent cycles.
|
|
26
|
+
for (const node of reversedNodes) {
|
|
27
|
+
if (node.id === draggedId || tree.isAncestor(draggedId, node.id)) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (!tree.isContainer(node.id)) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (node.currentRect && isPointInElement(canvasPos.x, canvasPos.y, node.currentRect)) {
|
|
34
|
+
targetContainer = node;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!targetContainer)
|
|
39
|
+
return null;
|
|
40
|
+
const parentId = targetContainer.id;
|
|
41
|
+
const parentWrapper = getWrapper(parentId);
|
|
42
|
+
if (!parentWrapper)
|
|
43
|
+
return null;
|
|
44
|
+
const layoutElement = getContentRoot
|
|
45
|
+
? getContentRoot(parentId)
|
|
46
|
+
: parentWrapper.firstElementChild ?? parentWrapper;
|
|
47
|
+
if (!layoutElement)
|
|
48
|
+
return null;
|
|
49
|
+
// Detect parent layout properties.
|
|
50
|
+
const layoutInfo = detectLayout(layoutElement);
|
|
51
|
+
const flowAxis = getFlowAxis(layoutInfo); // "x" (horizontal) or "y" (vertical)
|
|
52
|
+
const parentRect = targetContainer.currentRect;
|
|
53
|
+
// Read styling for padding/border.
|
|
54
|
+
const cs = getComputedStyle(layoutElement);
|
|
55
|
+
const padLeft = parseFloat(cs.paddingLeft) || 0;
|
|
56
|
+
const padRight = parseFloat(cs.paddingRight) || 0;
|
|
57
|
+
const padTop = parseFloat(cs.paddingTop) || 0;
|
|
58
|
+
const padBottom = parseFloat(cs.paddingBottom) || 0;
|
|
59
|
+
// Grid container handling
|
|
60
|
+
if (layoutInfo.mode === "grid" || layoutInfo.mode === "inline-grid") {
|
|
61
|
+
const colTracks = parseGridTracks(layoutInfo.gridTemplateColumns || "", layoutInfo.gap.column);
|
|
62
|
+
const rowTracks = parseGridTracks(layoutInfo.gridTemplateRows || "", layoutInfo.gap.row);
|
|
63
|
+
const cx = canvasPos.x - parentRect.x - padLeft;
|
|
64
|
+
const cy = canvasPos.y - parentRect.y - padTop;
|
|
65
|
+
const { col, row } = getGridCellAt(cx, cy, colTracks, rowTracks, layoutInfo.gap.column, layoutInfo.gap.row);
|
|
66
|
+
let colSpan = 1;
|
|
67
|
+
let rowSpan = 1;
|
|
68
|
+
const draggedWrapper = getWrapper(draggedId);
|
|
69
|
+
if (draggedWrapper) {
|
|
70
|
+
const draggedRoot = getContentRoot
|
|
71
|
+
? getContentRoot(draggedId)
|
|
72
|
+
: draggedWrapper.firstElementChild;
|
|
73
|
+
if (draggedRoot) {
|
|
74
|
+
colSpan = getGridSpan(draggedRoot, "column");
|
|
75
|
+
rowSpan = getGridSpan(draggedRoot, "row");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const cellRect = getGridAreaRect(parentRect, padLeft, padTop, col, row, colSpan, rowSpan, colTracks, rowTracks);
|
|
79
|
+
return {
|
|
80
|
+
parentId,
|
|
81
|
+
insertionIndex: 0,
|
|
82
|
+
indicator: {
|
|
83
|
+
x1: cellRect.x,
|
|
84
|
+
y1: cellRect.y,
|
|
85
|
+
x2: cellRect.x + cellRect.width,
|
|
86
|
+
y2: cellRect.y + cellRect.height,
|
|
87
|
+
side: "before",
|
|
88
|
+
},
|
|
89
|
+
gridPlacement: {
|
|
90
|
+
colStart: col,
|
|
91
|
+
rowStart: row,
|
|
92
|
+
colSpan,
|
|
93
|
+
rowSpan,
|
|
94
|
+
rect: cellRect,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const gap = flowAxis === "y" ? layoutInfo.gap.row : layoutInfo.gap.column;
|
|
99
|
+
// Filter out the dragged node from children to get the target layout state.
|
|
100
|
+
const children = tree.getChildren(parentId).filter(c => c.id !== draggedId);
|
|
101
|
+
if (children.length === 0) {
|
|
102
|
+
// Empty container: draw insertion line at the padding boundary.
|
|
103
|
+
const indicator = flowAxis === "y"
|
|
104
|
+
? {
|
|
105
|
+
x1: parentRect.x + padLeft,
|
|
106
|
+
y1: parentRect.y + padTop,
|
|
107
|
+
x2: parentRect.x + parentRect.width - padRight,
|
|
108
|
+
y2: parentRect.y + padTop,
|
|
109
|
+
side: "before",
|
|
110
|
+
}
|
|
111
|
+
: {
|
|
112
|
+
x1: parentRect.x + padLeft,
|
|
113
|
+
y1: parentRect.y + padTop,
|
|
114
|
+
x2: parentRect.x + padLeft,
|
|
115
|
+
y2: parentRect.y + parentRect.height - padBottom,
|
|
116
|
+
side: "before",
|
|
117
|
+
};
|
|
118
|
+
return {
|
|
119
|
+
parentId,
|
|
120
|
+
insertionIndex: 0,
|
|
121
|
+
indicator,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (flowAxis === "y") {
|
|
125
|
+
// Vertical flow (column, block).
|
|
126
|
+
// Map children to their vertical center points.
|
|
127
|
+
const centers = children.map(c => {
|
|
128
|
+
const r = c.currentRect;
|
|
129
|
+
return { id: c.id, rect: r, centerY: r.y + r.height / 2 };
|
|
130
|
+
});
|
|
131
|
+
for (let i = 0; i < centers.length; i++) {
|
|
132
|
+
const center = centers[i];
|
|
133
|
+
if (!center)
|
|
134
|
+
continue;
|
|
135
|
+
if (canvasPos.y < center.centerY) {
|
|
136
|
+
const refRect = center.rect;
|
|
137
|
+
const y = refRect.y - gap / 2;
|
|
138
|
+
return {
|
|
139
|
+
parentId,
|
|
140
|
+
insertionIndex: i,
|
|
141
|
+
indicator: {
|
|
142
|
+
x1: parentRect.x + padLeft,
|
|
143
|
+
y1: y,
|
|
144
|
+
x2: parentRect.x + parentRect.width - padRight,
|
|
145
|
+
y2: y,
|
|
146
|
+
side: "before",
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Drop after the last child.
|
|
152
|
+
const lastChild = children[children.length - 1];
|
|
153
|
+
const lastRect = lastChild && lastChild.currentRect ? lastChild.currentRect : parentRect;
|
|
154
|
+
const y = lastRect.y + lastRect.height + gap / 2;
|
|
155
|
+
return {
|
|
156
|
+
parentId,
|
|
157
|
+
insertionIndex: children.length,
|
|
158
|
+
indicator: {
|
|
159
|
+
x1: parentRect.x + padLeft,
|
|
160
|
+
y1: y,
|
|
161
|
+
x2: parentRect.x + parentRect.width - padRight,
|
|
162
|
+
y2: y,
|
|
163
|
+
side: "after",
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// Horizontal flow (row, inline).
|
|
169
|
+
// Map children to their horizontal center points.
|
|
170
|
+
const centers = children.map(c => {
|
|
171
|
+
const r = c.currentRect;
|
|
172
|
+
return { id: c.id, rect: r, centerX: r.x + r.width / 2 };
|
|
173
|
+
});
|
|
174
|
+
for (let i = 0; i < centers.length; i++) {
|
|
175
|
+
const center = centers[i];
|
|
176
|
+
if (!center)
|
|
177
|
+
continue;
|
|
178
|
+
if (canvasPos.x < center.centerX) {
|
|
179
|
+
const refRect = center.rect;
|
|
180
|
+
const x = refRect.x - gap / 2;
|
|
181
|
+
return {
|
|
182
|
+
parentId,
|
|
183
|
+
insertionIndex: i,
|
|
184
|
+
indicator: {
|
|
185
|
+
x1: x,
|
|
186
|
+
y1: parentRect.y + padTop,
|
|
187
|
+
x2: x,
|
|
188
|
+
y2: parentRect.y + parentRect.height - padBottom,
|
|
189
|
+
side: "before",
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Drop after the last child.
|
|
195
|
+
const lastChild = children[children.length - 1];
|
|
196
|
+
const lastRect = lastChild && lastChild.currentRect ? lastChild.currentRect : parentRect;
|
|
197
|
+
const x = lastRect.x + lastRect.width + gap / 2;
|
|
198
|
+
return {
|
|
199
|
+
parentId,
|
|
200
|
+
insertionIndex: children.length,
|
|
201
|
+
indicator: {
|
|
202
|
+
x1: x,
|
|
203
|
+
y1: parentRect.y + padTop,
|
|
204
|
+
x2: x,
|
|
205
|
+
y2: parentRect.y + parentRect.height - padBottom,
|
|
206
|
+
side: "after",
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/** Helper to extract grid span (e.g. 'span 2') from content styles. */
|
|
212
|
+
function getGridSpan(element, dimension) {
|
|
213
|
+
const cs = getComputedStyle(element);
|
|
214
|
+
const startVal = cs.getPropertyValue(`grid-${dimension}-start`);
|
|
215
|
+
const endVal = cs.getPropertyValue(`grid-${dimension}-end`);
|
|
216
|
+
const val = cs.getPropertyValue(`grid-${dimension}`);
|
|
217
|
+
// Check for "span N" in any of these styles
|
|
218
|
+
const spanMatch = (startVal + " " + endVal + " " + val).match(/span\s+(\d+)/i);
|
|
219
|
+
if (spanMatch && spanMatch[1]) {
|
|
220
|
+
return parseInt(spanMatch[1], 10);
|
|
221
|
+
}
|
|
222
|
+
// Check if start and end are numeric indices
|
|
223
|
+
const startNum = parseInt(startVal, 10);
|
|
224
|
+
const endNum = parseInt(endVal, 10);
|
|
225
|
+
if (!isNaN(startNum) && !isNaN(endNum) && endNum > startNum) {
|
|
226
|
+
return endNum - startNum;
|
|
227
|
+
}
|
|
228
|
+
return 1;
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=drop-zone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop-zone.js","sourceRoot":"","sources":["../src/drop-zone.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,0BAA0B;AAC1B,6DAA6D;AAC7D,EAAE;AACF,8DAA8D;AAC9D,8DAA8D;AAC9D,gEAAgE;AAGhE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzG,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAmC/C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAC5B,SAAiB,EACjB,SAAmC,EACnC,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M,CAAC,IAAI,MAAM,GAAG,QAAQ,EAAE,CAAC;QAC5D,OAAO,MAAM,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type { Vec2, Rect, ViewportMatrix, WebHTMLNode, ResolvedNode, LayoutMode, ResizeAnchor, InteractionMode, DragHandleState, CanvusTool, CommandShortcut, Command, } from "./types.js";
|
|
2
|
+
export { ZOOM_MIN, ZOOM_MAX, createIdleDragState, createDefaultViewport, resolveNode, } from "./types.js";
|
|
3
|
+
export { screenToCanvas, canvasToScreen, calculateZoomAnchor, applyWheelZoom, applyPan, isPointInElement, hitTestElements, getAnchorPositions, clampScale, lerp, lerpViewport, } from "./matrix.js";
|
|
4
|
+
export type { RectChangeCallback } from "./shadow-mount.js";
|
|
5
|
+
export { ShadowMount } from "./shadow-mount.js";
|
|
6
|
+
export { NodeTree, computeAggregateBounds } from "./tree.js";
|
|
7
|
+
export type { FlexDirection, FlexWrap, LayoutInfo, ChildSlot, GridTrack, } from "./layout.js";
|
|
8
|
+
export { detectLayout, getFlowAxis, getFlowSign, getLayoutLabel, detectChildSlots, parseGridTracks, } from "./layout.js";
|
|
9
|
+
export type { OverlayStyle, OverlayFrame, LayoutBadgeInfo, GridOverlayInfo, Guide, } from "./renderer.js";
|
|
10
|
+
export { OverlayRenderer, anchorCursor, computeAlignmentGuides, computeSnappedPosition, } from "./renderer.js";
|
|
11
|
+
export type { WorkspaceConfig, WorkspaceCallbacks, } from "./workspace.js";
|
|
12
|
+
export { Workspace } from "./workspace.js";
|
|
13
|
+
export type { DropTarget, InsertionIndicator, } from "./drop-zone.js";
|
|
14
|
+
export { findDropTarget } from "./drop-zone.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names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package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// canvus/src/index.ts — Public API barrel export.
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
export { ZOOM_MIN, ZOOM_MAX, createIdleDragState, createDefaultViewport, resolveNode, } from "./types.js";
|
|
5
|
+
// ── Viewport Math ───────────────────────────────────────────
|
|
6
|
+
export { screenToCanvas, canvasToScreen, calculateZoomAnchor, applyWheelZoom, applyPan, isPointInElement, hitTestElements, getAnchorPositions, clampScale, lerp, lerpViewport, } from "./matrix.js";
|
|
7
|
+
export { ShadowMount } from "./shadow-mount.js";
|
|
8
|
+
// ── Node Tree Model ─────────────────────────────────────────
|
|
9
|
+
export { NodeTree, computeAggregateBounds } from "./tree.js";
|
|
10
|
+
export { detectLayout, getFlowAxis, getFlowSign, getLayoutLabel, detectChildSlots, parseGridTracks, } from "./layout.js";
|
|
11
|
+
export { OverlayRenderer, anchorCursor, computeAlignmentGuides, computeSnappedPosition, } from "./renderer.js";
|
|
12
|
+
export { Workspace } from "./workspace.js";
|
|
13
|
+
export { findDropTarget } from "./drop-zone.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,kDAAkD;AAClD,gEAAgE;AAmBhE,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,qBAAqB,EACrB,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,+DAA+D;AAE/D,OAAO,EACL,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,UAAU,EACV,IAAI,EACJ,YAAY,GACb,MAAM,aAAa,CAAC;AAMrB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,+DAA+D;AAE/D,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAY7D,OAAO,EACL,YAAY,EACZ,WAAW,EACX,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,eAAe,GAChB,MAAM,aAAa,CAAC;AAYrB,OAAO,EACL,eAAe,EACf,YAAY,EACZ,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,eAAe,CAAC;AASvB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAS3C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { LayoutMode, Rect } from "./types.js";
|
|
2
|
+
/** Flex direction values. */
|
|
3
|
+
export type FlexDirection = "row" | "column" | "row-reverse" | "column-reverse";
|
|
4
|
+
/** Flex wrap values. */
|
|
5
|
+
export type FlexWrap = "nowrap" | "wrap" | "wrap-reverse";
|
|
6
|
+
/**
|
|
7
|
+
* Complete layout metadata extracted from a container element's
|
|
8
|
+
* computed styles. Covers flex, grid, and block layout properties.
|
|
9
|
+
*/
|
|
10
|
+
export interface LayoutInfo {
|
|
11
|
+
/** Resolved CSS `display` mode. */
|
|
12
|
+
mode: LayoutMode;
|
|
13
|
+
/** Flex direction (only meaningful for flex/inline-flex). */
|
|
14
|
+
direction: FlexDirection | null;
|
|
15
|
+
/** Flex wrap mode. */
|
|
16
|
+
wrap: FlexWrap | null;
|
|
17
|
+
/** Resolved gap values in CSS pixels. */
|
|
18
|
+
gap: {
|
|
19
|
+
row: number;
|
|
20
|
+
column: number;
|
|
21
|
+
};
|
|
22
|
+
/** Resolved `align-items` value. */
|
|
23
|
+
alignItems: string;
|
|
24
|
+
/** Resolved `justify-content` value. */
|
|
25
|
+
justifyContent: string;
|
|
26
|
+
/** Raw `grid-template-columns` computed value. */
|
|
27
|
+
gridTemplateColumns: string | null;
|
|
28
|
+
/** Raw `grid-template-rows` computed value. */
|
|
29
|
+
gridTemplateRows: string | null;
|
|
30
|
+
/** Raw `grid-auto-flow` computed value. */
|
|
31
|
+
gridAutoFlow: string | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Describes the computed position and size of a single "slot"
|
|
35
|
+
* in a flex/grid/block container — where a child element sits.
|
|
36
|
+
*/
|
|
37
|
+
export interface ChildSlot {
|
|
38
|
+
/** Zero-based index within the parent's children. */
|
|
39
|
+
index: number;
|
|
40
|
+
/** Bounding rect of the slot, relative to the container's padding box. */
|
|
41
|
+
rect: Rect;
|
|
42
|
+
}
|
|
43
|
+
/** Describes a single grid track (column or row). */
|
|
44
|
+
export interface GridTrack {
|
|
45
|
+
/** Start offset from the container's padding edge (px). */
|
|
46
|
+
start: number;
|
|
47
|
+
/** Size of the track (px). */
|
|
48
|
+
size: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Detects the CSS layout mode and properties of an element.
|
|
52
|
+
*
|
|
53
|
+
* Reads `getComputedStyle()` to extract the resolved display
|
|
54
|
+
* mode, flex direction, gap, alignment, and grid template values.
|
|
55
|
+
*
|
|
56
|
+
* @param element - The DOM element to inspect.
|
|
57
|
+
* @returns Complete `LayoutInfo` descriptor.
|
|
58
|
+
*/
|
|
59
|
+
export declare function detectLayout(element: HTMLElement): LayoutInfo;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the primary flow axis for a layout container.
|
|
62
|
+
*
|
|
63
|
+
* - Flex row → "x" (horizontal)
|
|
64
|
+
* - Flex column → "y" (vertical)
|
|
65
|
+
* - Grid row (default auto-flow) → "x"
|
|
66
|
+
* - Block → "y" (vertical stacking)
|
|
67
|
+
*
|
|
68
|
+
* @param info - The layout info to inspect.
|
|
69
|
+
* @returns "x" for horizontal flow, "y" for vertical flow.
|
|
70
|
+
*/
|
|
71
|
+
export declare function getFlowAxis(info: LayoutInfo): "x" | "y";
|
|
72
|
+
/**
|
|
73
|
+
* Returns the flow direction sign for a layout container.
|
|
74
|
+
*
|
|
75
|
+
* `1` for normal direction, `-1` for reverse.
|
|
76
|
+
* Useful for computing insertion positions.
|
|
77
|
+
*/
|
|
78
|
+
export declare function getFlowSign(info: LayoutInfo): 1 | -1;
|
|
79
|
+
/**
|
|
80
|
+
* Detects the position and size of each child element's slot
|
|
81
|
+
* within a container, measured relative to the container's
|
|
82
|
+
* padding box.
|
|
83
|
+
*
|
|
84
|
+
* This uses `getBoundingClientRect()` for accuracy, then
|
|
85
|
+
* converts to container-relative coordinates.
|
|
86
|
+
*
|
|
87
|
+
* @param container - The parent DOM element.
|
|
88
|
+
* @returns Array of `ChildSlot` objects, one per child element.
|
|
89
|
+
*/
|
|
90
|
+
export declare function detectChildSlots(container: HTMLElement): ChildSlot[];
|
|
91
|
+
/**
|
|
92
|
+
* Parses grid track values from a resolved `grid-template-columns`
|
|
93
|
+
* or `grid-template-rows` string into an array of `GridTrack` objects.
|
|
94
|
+
*
|
|
95
|
+
* The browser resolves templates like `1fr 2fr 100px` into
|
|
96
|
+
* computed pixel values like `200px 400px 100px`. This function
|
|
97
|
+
* parses those resolved values, accounting for the layout gap between tracks.
|
|
98
|
+
*
|
|
99
|
+
* @param templateValue - The resolved CSS grid template string
|
|
100
|
+
* (e.g. "200px 400px 100px").
|
|
101
|
+
* @param gap - The layout gap in pixels between tracks.
|
|
102
|
+
* @returns Array of grid tracks with start offsets and sizes.
|
|
103
|
+
*/
|
|
104
|
+
export declare function parseGridTracks(templateValue: string, gap?: number): GridTrack[];
|
|
105
|
+
/**
|
|
106
|
+
* Maps a padding-box relative coordinate (x, y) to the grid cell indices (1-indexed).
|
|
107
|
+
*
|
|
108
|
+
* @param x - X coordinate relative to container padding edge.
|
|
109
|
+
* @param y - Y coordinate relative to container padding edge.
|
|
110
|
+
* @param columns - Parsed column tracks.
|
|
111
|
+
* @param rows - Parsed row tracks.
|
|
112
|
+
* @param colGap - Column gap.
|
|
113
|
+
* @param rowGap - Row gap.
|
|
114
|
+
* @returns { col: number, row: number } (1-indexed, matching CSS grid-column-start/grid-row-start).
|
|
115
|
+
*/
|
|
116
|
+
export declare function getGridCellAt(x: number, y: number, columns: ReadonlyArray<GridTrack>, rows: ReadonlyArray<GridTrack>, colGap: number, rowGap: number): {
|
|
117
|
+
col: number;
|
|
118
|
+
row: number;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Computes the canvas-space bounding rect of a grid area span.
|
|
122
|
+
*
|
|
123
|
+
* @param containerRect - The parent container's canvas-space bounding box.
|
|
124
|
+
* @param padLeft - Container padding-left.
|
|
125
|
+
* @param padTop - Container padding-top.
|
|
126
|
+
* @param colStart - 1-based column start index.
|
|
127
|
+
* @param rowStart - 1-based row start index.
|
|
128
|
+
* @param colSpan - Column span.
|
|
129
|
+
* @param rowSpan - Row span.
|
|
130
|
+
* @param columns - Parsed column tracks.
|
|
131
|
+
* @param rows - Parsed row tracks.
|
|
132
|
+
* @returns The bounding Rect in canvas-space.
|
|
133
|
+
*/
|
|
134
|
+
export declare function getGridAreaRect(containerRect: Rect, padLeft: number, padTop: number, colStart: number, rowStart: number, colSpan: number, rowSpan: number, columns: ReadonlyArray<GridTrack>, rows: ReadonlyArray<GridTrack>): Rect;
|
|
135
|
+
/**
|
|
136
|
+
* Returns a short, human-readable label for a layout mode.
|
|
137
|
+
* Used for layout badge overlays.
|
|
138
|
+
*
|
|
139
|
+
* @param info - The layout info to label.
|
|
140
|
+
* @returns A concise string like "FLEX →", "FLEX ↓", "GRID", "BLOCK".
|
|
141
|
+
*/
|
|
142
|
+
export declare function getLayoutLabel(info: LayoutInfo): string;
|
|
143
|
+
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAInD,6BAA6B;AAC7B,MAAM,MAA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