@zuilib/text-editor 0.4.0 → 0.5.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/CHANGELOG.md +48 -0
- package/DRAWING_FORMAT.md +240 -66
- package/README.md +94 -31
- package/dist/index.d.ts +492 -43
- package/dist/index.js +3123 -1324
- package/dist/styles.css +328 -84
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -210,14 +210,39 @@ declare function $isFrontmatterNode(node: LexicalNode | null | undefined): node
|
|
|
210
210
|
*/
|
|
211
211
|
declare const FRONTMATTER: MultilineElementTransformer;
|
|
212
212
|
|
|
213
|
-
|
|
213
|
+
/** Card-like shapes: fillable, bindable, carrying the three text slots */
|
|
214
|
+
type BoxType = 'rect' | 'ellipse' | 'diamond' | 'note' | 'cylinder' | 'cloud' | 'queue' | 'actor';
|
|
215
|
+
type ConnectorType = 'arrow' | 'line';
|
|
216
|
+
type DrawingShapeType = BoxType | ConnectorType | 'text';
|
|
217
|
+
declare const BOX_TYPES: readonly BoxType[];
|
|
218
|
+
declare const CONNECTOR_TYPES: readonly ConnectorType[];
|
|
219
|
+
declare const SHAPE_TYPES: readonly DrawingShapeType[];
|
|
220
|
+
type Point = Readonly<{
|
|
221
|
+
x: number;
|
|
222
|
+
y: number;
|
|
223
|
+
}>;
|
|
224
|
+
type BindingSide = 'top' | 'right' | 'bottom' | 'left';
|
|
225
|
+
/**
|
|
226
|
+
* Where a connector endpoint attaches to a box.
|
|
227
|
+
*
|
|
228
|
+
* `fixedPoint` is a ratio inside the box's bounding box (`[0,0]` top-left,
|
|
229
|
+
* `[1,1]` bottom-right). Omitted = the box center, which makes the endpoint
|
|
230
|
+
* auto-aim at the other end. `mode: 'inside'` pins the endpoint exactly on
|
|
231
|
+
* the fixed point; the default (`'orbit'`) projects it onto the outline with
|
|
232
|
+
* a small gap.
|
|
233
|
+
*/
|
|
234
|
+
type Binding = Readonly<{
|
|
235
|
+
id: string;
|
|
236
|
+
fixedPoint?: readonly [number, number];
|
|
237
|
+
mode?: 'orbit' | 'inside';
|
|
238
|
+
}>;
|
|
214
239
|
type DrawingShape = Readonly<{
|
|
215
240
|
id: string;
|
|
216
241
|
type: DrawingShapeType;
|
|
217
|
-
/** Top-left corner (
|
|
242
|
+
/** Top-left corner (boxes/text) or start point (connectors) */
|
|
218
243
|
x: number;
|
|
219
244
|
y: number;
|
|
220
|
-
/** Size (
|
|
245
|
+
/** Size (boxes/text) or delta to the end point (connectors) */
|
|
221
246
|
w: number;
|
|
222
247
|
h: number;
|
|
223
248
|
stroke: string;
|
|
@@ -229,44 +254,62 @@ type DrawingShape = Readonly<{
|
|
|
229
254
|
label?: string;
|
|
230
255
|
/** Small line rendered at the bottom of a box */
|
|
231
256
|
footer?: string;
|
|
232
|
-
/**
|
|
233
|
-
startBinding?:
|
|
234
|
-
/**
|
|
235
|
-
endBinding?:
|
|
236
|
-
/** Arrow:
|
|
257
|
+
/** Connector: box the start point is attached to */
|
|
258
|
+
startBinding?: Binding;
|
|
259
|
+
/** Connector: box the end point is attached to */
|
|
260
|
+
endBinding?: Binding;
|
|
261
|
+
/** Arrow: arrowheads on both ends */
|
|
237
262
|
bidirectional?: boolean;
|
|
238
|
-
/** Connector routing: right-angled
|
|
263
|
+
/** Connector routing: right-angled auto-routed path instead of a straight line */
|
|
239
264
|
routing?: 'elbow';
|
|
240
|
-
/**
|
|
265
|
+
/**
|
|
266
|
+
* Elbow override: position of the middle segment as a fraction of the
|
|
267
|
+
* span, applied only when the routed path is a simple three-segment Z.
|
|
268
|
+
*/
|
|
241
269
|
elbow?: number;
|
|
242
270
|
/**
|
|
243
271
|
* Connector: intermediate path points between start and end (absolute
|
|
244
272
|
* canvas coordinates). Takes precedence over `routing`.
|
|
245
273
|
*/
|
|
246
|
-
waypoints?:
|
|
247
|
-
x: number;
|
|
248
|
-
y: number;
|
|
249
|
-
}>;
|
|
274
|
+
waypoints?: readonly Point[];
|
|
250
275
|
}>;
|
|
251
276
|
type DrawingData = Readonly<{
|
|
252
|
-
version:
|
|
253
|
-
|
|
277
|
+
version: 2;
|
|
278
|
+
/**
|
|
279
|
+
* Logical canvas width. When set the drawing is scaled to fit narrower
|
|
280
|
+
* layouts (SVG viewBox); when omitted the canvas is fluid and shapes are
|
|
281
|
+
* in CSS pixels.
|
|
282
|
+
*/
|
|
283
|
+
canvasWidth?: number;
|
|
284
|
+
canvasHeight: number;
|
|
254
285
|
/**
|
|
255
|
-
*
|
|
256
|
-
* `content` fits the shapes' horizontal extent.
|
|
286
|
+
* Block width: `full` (default, omitted when serialized) spans the
|
|
287
|
+
* editor; `content` fits the shapes' horizontal extent.
|
|
257
288
|
*/
|
|
258
289
|
width?: BlockWidth;
|
|
259
290
|
shapes: readonly DrawingShape[];
|
|
260
291
|
}>;
|
|
292
|
+
declare const EMPTY_DRAWING: DrawingData;
|
|
293
|
+
declare const STROKE_COLORS: readonly ["#1e1e1e", "#e03131", "#2f9e44", "#1971c2", "#f08c00", "#7048e8"];
|
|
294
|
+
declare const FILL_COLORS: readonly ["transparent", "#ffc9c9", "#b2f2bb", "#a5d8ff", "#ffec99", "#d0bfff"];
|
|
295
|
+
/** Edge midpoints, used by the ```diagram skeleton's `side` option */
|
|
296
|
+
declare const SIDE_FIXED_POINTS: Record<BindingSide, readonly [number, number]>;
|
|
261
297
|
declare function serializeDrawingData(data: DrawingData): string;
|
|
298
|
+
/**
|
|
299
|
+
* Parse a ```drawing payload. Exactly one format is accepted: version 2 as
|
|
300
|
+
* written by the editor (the ```diagram skeleton is a separate block type,
|
|
301
|
+
* see skeleton.ts). Shapes that fail validation are dropped and a malformed
|
|
302
|
+
* document yields an empty canvas. Never throws.
|
|
303
|
+
*/
|
|
262
304
|
declare function parseDrawingData(json: string): DrawingData;
|
|
305
|
+
declare function normalizeDrawingData(parsed: unknown): DrawingData;
|
|
263
306
|
|
|
264
307
|
type SerializedDrawingNode = Spread<{
|
|
265
308
|
data: string;
|
|
266
309
|
}, SerializedLexicalNode>;
|
|
267
310
|
/**
|
|
268
|
-
* A block-level decorator node embedding a vector
|
|
269
|
-
*
|
|
311
|
+
* A block-level decorator node embedding a vector diagram (cards, connectors,
|
|
312
|
+
* text) edited on a canvas.
|
|
270
313
|
*
|
|
271
314
|
* The drawing is stored as a JSON string and round-trips through markdown as
|
|
272
315
|
* a ```drawing fenced code block, so documents remain plain markdown.
|
|
@@ -295,6 +338,13 @@ declare function $isDrawingNode(node: LexicalNode | null | undefined): node is D
|
|
|
295
338
|
* claims the fence first on import.
|
|
296
339
|
*/
|
|
297
340
|
declare const DRAWING: MultilineElementTransformer;
|
|
341
|
+
/**
|
|
342
|
+
* Import-only transformer for ```diagram blocks: a compact skeleton
|
|
343
|
+
* (boxes, connectors by id, auto layout) that expands into a full drawing.
|
|
344
|
+
* Once in the editor the node is a regular drawing and exports as
|
|
345
|
+
* ```drawing, so the expansion is one-way.
|
|
346
|
+
*/
|
|
347
|
+
declare const DIAGRAM: MultilineElementTransformer;
|
|
298
348
|
|
|
299
349
|
/**
|
|
300
350
|
* Markdown transformer for GFM tables. Adapted from the Lexical playground.
|
|
@@ -307,32 +357,43 @@ declare const DRAWING: MultilineElementTransformer;
|
|
|
307
357
|
declare const TABLE: ElementTransformer;
|
|
308
358
|
|
|
309
359
|
/**
|
|
310
|
-
* JSON Schema (draft-07) for the payload of a ```drawing fenced block
|
|
360
|
+
* JSON Schema (draft-07) for the payload of a ```drawing fenced block
|
|
361
|
+
* (format version 2).
|
|
311
362
|
*
|
|
312
363
|
* Use it to validate LLM- or tool-generated drawings before embedding them,
|
|
313
364
|
* or pass it as a structured-output / tool schema so a model is forced to
|
|
314
|
-
* emit valid payloads. Kept in sync with `parseDrawingData` /
|
|
315
|
-
* in
|
|
365
|
+
* emit valid payloads. Kept in sync with `parseDrawingData` /
|
|
366
|
+
* `normalizeShape` in types.ts; update both together.
|
|
367
|
+
*
|
|
368
|
+
* For generation prefer the ```diagram skeleton
|
|
369
|
+
* (`DRAWING_SKELETON_JSON_SCHEMA`): it needs no coordinates and expands into
|
|
370
|
+
* this format on import.
|
|
316
371
|
*/
|
|
317
372
|
declare const DRAWING_DATA_JSON_SCHEMA: {
|
|
318
373
|
readonly $schema: "http://json-schema.org/draft-07/schema#";
|
|
319
374
|
readonly title: "DrawingData";
|
|
320
|
-
readonly description: "Vector drawing embedded in markdown as a ```drawing fenced code block";
|
|
375
|
+
readonly description: "Vector drawing embedded in markdown as a ```drawing fenced code block (format version 2)";
|
|
321
376
|
readonly type: "object";
|
|
322
|
-
readonly required: readonly ["version", "
|
|
377
|
+
readonly required: readonly ["version", "canvasHeight", "shapes"];
|
|
323
378
|
readonly additionalProperties: false;
|
|
324
379
|
readonly properties: {
|
|
325
380
|
readonly version: {
|
|
326
|
-
readonly const:
|
|
381
|
+
readonly const: 2;
|
|
382
|
+
readonly description: "Format version; always 2";
|
|
327
383
|
};
|
|
328
|
-
readonly
|
|
384
|
+
readonly canvasHeight: {
|
|
329
385
|
readonly type: "number";
|
|
330
386
|
readonly minimum: 80;
|
|
331
|
-
readonly description: "Canvas height in pixels";
|
|
387
|
+
readonly description: "Canvas height in pixels. Make it large enough to contain every shape plus ~20px margin.";
|
|
388
|
+
};
|
|
389
|
+
readonly canvasWidth: {
|
|
390
|
+
readonly type: "number";
|
|
391
|
+
readonly minimum: 120;
|
|
392
|
+
readonly description: "Optional logical canvas width in pixels. When set, the drawing is scaled down to fit narrower layouts (SVG viewBox) so coordinates can assume this width. When omitted the canvas is fluid and coordinates are CSS pixels.";
|
|
332
393
|
};
|
|
333
394
|
readonly width: {
|
|
334
395
|
readonly enum: readonly ["full", "content"];
|
|
335
|
-
readonly description: "
|
|
396
|
+
readonly description: "Block width: \"full\" (default, omit it) spans the editor; \"content\" fits the shapes' horizontal extent and left-aligns with the text";
|
|
336
397
|
};
|
|
337
398
|
readonly shapes: {
|
|
338
399
|
readonly type: "array";
|
|
@@ -350,9 +411,38 @@ declare const DRAWING_DATA_JSON_SCHEMA: {
|
|
|
350
411
|
readonly properties: {
|
|
351
412
|
readonly x: {
|
|
352
413
|
readonly type: "number";
|
|
414
|
+
readonly description: "Absolute canvas x";
|
|
353
415
|
};
|
|
354
416
|
readonly y: {
|
|
355
417
|
readonly type: "number";
|
|
418
|
+
readonly description: "Absolute canvas y";
|
|
419
|
+
};
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
readonly binding: {
|
|
423
|
+
readonly type: "object";
|
|
424
|
+
readonly description: "Where a connector endpoint attaches to a box. Omit fixedPoint to let the endpoint auto-aim from the box center at the other end.";
|
|
425
|
+
readonly required: readonly ["id"];
|
|
426
|
+
readonly additionalProperties: false;
|
|
427
|
+
readonly properties: {
|
|
428
|
+
readonly id: {
|
|
429
|
+
readonly type: "string";
|
|
430
|
+
readonly description: "Id of the box this endpoint is attached to";
|
|
431
|
+
};
|
|
432
|
+
readonly fixedPoint: {
|
|
433
|
+
readonly type: "array";
|
|
434
|
+
readonly items: {
|
|
435
|
+
readonly type: "number";
|
|
436
|
+
readonly minimum: 0;
|
|
437
|
+
readonly maximum: 1;
|
|
438
|
+
};
|
|
439
|
+
readonly minItems: 2;
|
|
440
|
+
readonly maxItems: 2;
|
|
441
|
+
readonly description: "Attach point as a ratio of the box's bounding box: [0,0] top-left, [1,1] bottom-right, [0.5,0] top edge midpoint, [1,0.5] right edge midpoint. Omitted: the endpoint auto-aims from the box center at the other end.";
|
|
442
|
+
};
|
|
443
|
+
readonly mode: {
|
|
444
|
+
readonly enum: readonly ["orbit", "inside"];
|
|
445
|
+
readonly description: "\"orbit\" (default): the endpoint is projected onto the box outline with a 6px gap. \"inside\": the endpoint sits exactly on the fixed point.";
|
|
356
446
|
};
|
|
357
447
|
};
|
|
358
448
|
};
|
|
@@ -366,7 +456,8 @@ declare const DRAWING_DATA_JSON_SCHEMA: {
|
|
|
366
456
|
readonly description: "Unique within the drawing; connector bindings reference it";
|
|
367
457
|
};
|
|
368
458
|
readonly type: {
|
|
369
|
-
readonly enum: readonly ["rect", "ellipse", "
|
|
459
|
+
readonly enum: readonly ["rect", "ellipse", "diamond", "note", "cylinder", "cloud", "queue", "actor", "arrow", "line", "text"];
|
|
460
|
+
readonly description: "Boxes (cards with label/text/footer slots): rect, ellipse, diamond, note (sticky note with a folded corner), cylinder (database), cloud, queue (horizontal cylinder), actor (stick figure; only the text slot, rendered as a name under the figure). Connectors: arrow (head at the end), line. Free-floating annotation: text.";
|
|
370
461
|
};
|
|
371
462
|
readonly x: {
|
|
372
463
|
readonly type: "number";
|
|
@@ -386,11 +477,11 @@ declare const DRAWING_DATA_JSON_SCHEMA: {
|
|
|
386
477
|
};
|
|
387
478
|
readonly stroke: {
|
|
388
479
|
readonly type: "string";
|
|
389
|
-
readonly description: "CSS color of the outline (and of any text)";
|
|
480
|
+
readonly description: "CSS color of the outline (and of any text). Palette: #1e1e1e (default), #e03131 red, #2f9e44 green, #1971c2 blue, #f08c00 orange, #7048e8 purple.";
|
|
390
481
|
};
|
|
391
482
|
readonly fill: {
|
|
392
483
|
readonly type: "string";
|
|
393
|
-
readonly description: "CSS color of the interior; \"transparent\" for none";
|
|
484
|
+
readonly description: "CSS color of the interior; \"transparent\" for none. Palette: #ffc9c9 red, #b2f2bb green, #a5d8ff blue, #ffec99 yellow, #d0bfff purple.";
|
|
394
485
|
};
|
|
395
486
|
readonly strokeWidth: {
|
|
396
487
|
readonly type: "number";
|
|
@@ -398,23 +489,23 @@ declare const DRAWING_DATA_JSON_SCHEMA: {
|
|
|
398
489
|
};
|
|
399
490
|
readonly text: {
|
|
400
491
|
readonly type: "string";
|
|
401
|
-
readonly description: "Standalone text content; center content of a box; midpoint label of a connector";
|
|
492
|
+
readonly description: "Standalone text content; center content of a box (the name under an actor); midpoint label of a connector";
|
|
402
493
|
};
|
|
403
494
|
readonly label: {
|
|
404
495
|
readonly type: "string";
|
|
405
|
-
readonly description: "Boxes only: small bold heading at the top";
|
|
496
|
+
readonly description: "Boxes only (not actor): small bold heading at the top";
|
|
406
497
|
};
|
|
407
498
|
readonly footer: {
|
|
408
499
|
readonly type: "string";
|
|
409
|
-
readonly description: "Boxes only: small dim line at the bottom";
|
|
500
|
+
readonly description: "Boxes only (not actor): small dim line at the bottom";
|
|
410
501
|
};
|
|
411
502
|
readonly startBinding: {
|
|
412
|
-
readonly
|
|
413
|
-
readonly description: "Connectors only:
|
|
503
|
+
readonly $ref: "#/definitions/binding";
|
|
504
|
+
readonly description: "Connectors only: box the start point attaches to. The editor re-anchors the endpoint onto that box and keeps it attached as the box moves.";
|
|
414
505
|
};
|
|
415
506
|
readonly endBinding: {
|
|
416
|
-
readonly
|
|
417
|
-
readonly description: "Connectors only:
|
|
507
|
+
readonly $ref: "#/definitions/binding";
|
|
508
|
+
readonly description: "Connectors only: box the end point attaches to";
|
|
418
509
|
};
|
|
419
510
|
readonly bidirectional: {
|
|
420
511
|
readonly type: "boolean";
|
|
@@ -422,24 +513,382 @@ declare const DRAWING_DATA_JSON_SCHEMA: {
|
|
|
422
513
|
};
|
|
423
514
|
readonly routing: {
|
|
424
515
|
readonly const: "elbow";
|
|
425
|
-
readonly description: "Connectors only:
|
|
516
|
+
readonly description: "Connectors only: right-angled auto-routed path. It leaves the box perpendicular to the attach side, avoids every box on the canvas and minimises bends. Ignored when waypoints are present.";
|
|
426
517
|
};
|
|
427
518
|
readonly elbow: {
|
|
428
519
|
readonly type: "number";
|
|
429
520
|
readonly minimum: 0;
|
|
430
521
|
readonly maximum: 1;
|
|
431
|
-
readonly description: "Elbow middle
|
|
522
|
+
readonly description: "Elbow override: position of the middle segment as a fraction of the span. Applied only when the routed path is a simple three-segment Z.";
|
|
432
523
|
};
|
|
433
524
|
readonly waypoints: {
|
|
434
525
|
readonly type: "array";
|
|
435
526
|
readonly items: {
|
|
436
527
|
readonly $ref: "#/definitions/point";
|
|
437
528
|
};
|
|
438
|
-
readonly description: "Connectors only: intermediate path points in canvas coordinates, ordered start
|
|
529
|
+
readonly description: "Connectors only: intermediate path points in canvas coordinates, ordered start to end. Takes precedence over routing.";
|
|
439
530
|
};
|
|
440
531
|
};
|
|
441
532
|
};
|
|
442
533
|
};
|
|
443
534
|
};
|
|
444
535
|
|
|
445
|
-
|
|
536
|
+
type Rect = Readonly<{
|
|
537
|
+
x: number;
|
|
538
|
+
y: number;
|
|
539
|
+
w: number;
|
|
540
|
+
h: number;
|
|
541
|
+
}>;
|
|
542
|
+
|
|
543
|
+
declare function boxOutline(box: DrawingShape): Point[];
|
|
544
|
+
/** Topmost box under a point, if any; smaller boxes win over enclosing ones */
|
|
545
|
+
declare function findBoxAt(shapes: readonly DrawingShape[], point: Point, excludeId?: string, tolerance?: number): DrawingShape | null;
|
|
546
|
+
/** The point a binding refers to: its fixed point, or the box center */
|
|
547
|
+
declare function anchorPoint(box: DrawingShape, binding?: Binding): Point;
|
|
548
|
+
/**
|
|
549
|
+
* Fixed point for a drop at `point`: undefined (auto-aim) for drops near
|
|
550
|
+
* the center, otherwise a ratio snapped onto the nearest bounding-box edge.
|
|
551
|
+
*/
|
|
552
|
+
declare function fixedPointFor(box: DrawingShape, point: Point): [number, number] | undefined;
|
|
553
|
+
/**
|
|
554
|
+
* Recompute the endpoints of every bound connector from the current
|
|
555
|
+
* positions of the boxes they're attached to, and drop bindings whose box
|
|
556
|
+
* no longer exists. Idempotent, so it can run after every shape update.
|
|
557
|
+
*/
|
|
558
|
+
declare function resolveBindings(shapes: readonly DrawingShape[]): readonly DrawingShape[];
|
|
559
|
+
/** Attach a freshly drawn connector to the boxes under its endpoints */
|
|
560
|
+
declare function bindEndpoints(shape: DrawingShape, shapes: readonly DrawingShape[]): DrawingShape;
|
|
561
|
+
declare function makeBinding(box: DrawingShape, point: Point): Binding;
|
|
562
|
+
|
|
563
|
+
/** Vertices of a connector's path, start to end */
|
|
564
|
+
declare function connectorPoints(shape: DrawingShape, shapes?: readonly DrawingShape[]): Point[];
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Orthogonal route for an elbow connector: leaves each bound box
|
|
568
|
+
* perpendicular to its attach side, avoids every box on the canvas, and
|
|
569
|
+
* takes the path with the fewest bends (then the shortest). Falls back to
|
|
570
|
+
* a plain L when the grid search fails.
|
|
571
|
+
*/
|
|
572
|
+
declare function routeElbow(shape: DrawingShape, shapes: readonly DrawingShape[]): Point[];
|
|
573
|
+
|
|
574
|
+
type TextField = 'text' | 'label' | 'footer';
|
|
575
|
+
/**
|
|
576
|
+
* Geometry of a box type, kept free of React so the router, bindings,
|
|
577
|
+
* skeleton expansion and exporters can use it without a DOM.
|
|
578
|
+
*/
|
|
579
|
+
type BoxDefinition = Readonly<{
|
|
580
|
+
type: BoxType;
|
|
581
|
+
label: string;
|
|
582
|
+
/** Size used when a shape is created without explicit dimensions */
|
|
583
|
+
defaultSize: Readonly<{
|
|
584
|
+
w: number;
|
|
585
|
+
h: number;
|
|
586
|
+
}>;
|
|
587
|
+
/** Text slots the shape renders (and offers for editing) */
|
|
588
|
+
textSlots: readonly TextField[];
|
|
589
|
+
/** Fill applied when the tool is picked with the default (transparent) fill */
|
|
590
|
+
defaultFill?: string;
|
|
591
|
+
/** Closed outline used for hit-testing and binding endpoints */
|
|
592
|
+
outline: (shape: DrawingShape) => Point[];
|
|
593
|
+
/** Area the text slots lay out in */
|
|
594
|
+
textArea: (shape: DrawingShape) => Rect;
|
|
595
|
+
}>;
|
|
596
|
+
declare const BOX_DEFINITIONS: Record<BoxType, BoxDefinition>;
|
|
597
|
+
|
|
598
|
+
type ColorName = 'gray' | 'red' | 'green' | 'blue' | 'orange' | 'purple';
|
|
599
|
+
declare const COLOR_PRESETS: Record<ColorName, {
|
|
600
|
+
stroke: string;
|
|
601
|
+
fill: string;
|
|
602
|
+
}>;
|
|
603
|
+
type SkeletonBox = Readonly<{
|
|
604
|
+
id: string;
|
|
605
|
+
/** Default `'rect'` */
|
|
606
|
+
type?: BoxType;
|
|
607
|
+
label?: string;
|
|
608
|
+
text?: string;
|
|
609
|
+
footer?: string;
|
|
610
|
+
/** Omitted → auto layout */
|
|
611
|
+
x?: number;
|
|
612
|
+
y?: number;
|
|
613
|
+
/** Omitted → measured from the text, never smaller than the type's default size */
|
|
614
|
+
w?: number;
|
|
615
|
+
h?: number;
|
|
616
|
+
/** Preset → stroke + fill (fill only when `fill` isn't given) */
|
|
617
|
+
color?: ColorName;
|
|
618
|
+
stroke?: string;
|
|
619
|
+
fill?: string;
|
|
620
|
+
}>;
|
|
621
|
+
type SkeletonEnd = string | Readonly<{
|
|
622
|
+
id: string;
|
|
623
|
+
side?: BindingSide;
|
|
624
|
+
}>;
|
|
625
|
+
type SkeletonConnector = Readonly<{
|
|
626
|
+
id?: string;
|
|
627
|
+
/** Default `'arrow'` */
|
|
628
|
+
type?: ConnectorType;
|
|
629
|
+
from: SkeletonEnd;
|
|
630
|
+
to: SkeletonEnd;
|
|
631
|
+
text?: string;
|
|
632
|
+
bidirectional?: boolean;
|
|
633
|
+
/** Default `'straight'` */
|
|
634
|
+
routing?: 'elbow' | 'straight';
|
|
635
|
+
color?: ColorName;
|
|
636
|
+
stroke?: string;
|
|
637
|
+
}>;
|
|
638
|
+
type SkeletonText = Readonly<{
|
|
639
|
+
id?: string;
|
|
640
|
+
x: number;
|
|
641
|
+
y: number;
|
|
642
|
+
text: string;
|
|
643
|
+
color?: ColorName;
|
|
644
|
+
stroke?: string;
|
|
645
|
+
}>;
|
|
646
|
+
type DrawingSkeleton = Readonly<{
|
|
647
|
+
/** Auto-layout flow direction, default `'right'` */
|
|
648
|
+
direction?: 'right' | 'down';
|
|
649
|
+
canvasWidth?: number;
|
|
650
|
+
canvasHeight?: number;
|
|
651
|
+
width?: 'content';
|
|
652
|
+
boxes: readonly SkeletonBox[];
|
|
653
|
+
connectors?: readonly SkeletonConnector[];
|
|
654
|
+
texts?: readonly SkeletonText[];
|
|
655
|
+
}>;
|
|
656
|
+
/** Structural check: an object with a `boxes` array */
|
|
657
|
+
declare function isDrawingSkeleton(value: unknown): value is DrawingSkeleton;
|
|
658
|
+
/**
|
|
659
|
+
* Parse a skeleton JSON payload into drawing data. Lenient: invalid boxes,
|
|
660
|
+
* connectors and texts are dropped individually, and a malformed document
|
|
661
|
+
* yields an empty canvas. Never throws.
|
|
662
|
+
*/
|
|
663
|
+
declare function parseDrawingSkeleton(json: string): DrawingData;
|
|
664
|
+
declare function expandSkeleton(skeleton: DrawingSkeleton): DrawingData;
|
|
665
|
+
declare const DRAWING_SKELETON_JSON_SCHEMA: {
|
|
666
|
+
readonly $schema: "http://json-schema.org/draft-07/schema#";
|
|
667
|
+
readonly title: "DrawingSkeleton";
|
|
668
|
+
readonly description: "Compact intent description of a diagram. Boxes are sized from their text and laid out automatically along the connector flow; connectors are drawn between box outlines. Only say what is on the canvas — geometry is derived";
|
|
669
|
+
readonly type: "object";
|
|
670
|
+
readonly required: readonly ["boxes"];
|
|
671
|
+
readonly additionalProperties: false;
|
|
672
|
+
readonly properties: {
|
|
673
|
+
readonly direction: {
|
|
674
|
+
readonly enum: readonly ["right", "down"];
|
|
675
|
+
readonly description: "Auto-layout flow direction. Boxes connected a→b are placed in successive ranks along this axis (\"right\" = columns left to right, \"down\" = rows top to bottom). Default \"right\"";
|
|
676
|
+
};
|
|
677
|
+
readonly canvasWidth: {
|
|
678
|
+
readonly type: "number";
|
|
679
|
+
readonly minimum: 120;
|
|
680
|
+
readonly description: "Logical canvas width in px. Omit for a fluid canvas in CSS pixels";
|
|
681
|
+
};
|
|
682
|
+
readonly canvasHeight: {
|
|
683
|
+
readonly type: "number";
|
|
684
|
+
readonly minimum: 80;
|
|
685
|
+
readonly description: "Canvas height in px. Omit to fit the content";
|
|
686
|
+
};
|
|
687
|
+
readonly width: {
|
|
688
|
+
readonly enum: readonly ["content"];
|
|
689
|
+
readonly description: "Block width: \"content\" fits the drawing to its shapes and left-aligns it with the text; omit to span the editor";
|
|
690
|
+
};
|
|
691
|
+
readonly boxes: {
|
|
692
|
+
readonly type: "array";
|
|
693
|
+
readonly items: {
|
|
694
|
+
readonly $ref: "#/definitions/box";
|
|
695
|
+
};
|
|
696
|
+
readonly description: "Card-like shapes carrying up to three text slots. Order is the render order and the stacking order within a layout rank";
|
|
697
|
+
};
|
|
698
|
+
readonly connectors: {
|
|
699
|
+
readonly type: "array";
|
|
700
|
+
readonly items: {
|
|
701
|
+
readonly $ref: "#/definitions/connector";
|
|
702
|
+
};
|
|
703
|
+
readonly description: "Arrows and lines between boxes. Connectors whose from/to id does not match a box are dropped";
|
|
704
|
+
};
|
|
705
|
+
readonly texts: {
|
|
706
|
+
readonly type: "array";
|
|
707
|
+
readonly items: {
|
|
708
|
+
readonly $ref: "#/definitions/text";
|
|
709
|
+
};
|
|
710
|
+
readonly description: "Free-floating annotations not attached to any box. Prefer box slots (label/text/footer) when the text belongs to a box";
|
|
711
|
+
};
|
|
712
|
+
};
|
|
713
|
+
readonly definitions: {
|
|
714
|
+
readonly box: {
|
|
715
|
+
readonly type: "object";
|
|
716
|
+
readonly required: readonly ["id"];
|
|
717
|
+
readonly additionalProperties: false;
|
|
718
|
+
readonly properties: {
|
|
719
|
+
readonly id: {
|
|
720
|
+
readonly type: "string";
|
|
721
|
+
readonly description: "Unique within the drawing; connectors reference it";
|
|
722
|
+
};
|
|
723
|
+
readonly type: {
|
|
724
|
+
readonly enum: readonly BoxType[];
|
|
725
|
+
readonly description: "Shape: rect (default), ellipse, diamond (decision), note (sticky note, yellow by default), cylinder (database), cloud (external system), queue (message queue), actor (stick figure; only the \"text\" slot renders, below the figure)";
|
|
726
|
+
};
|
|
727
|
+
readonly label: {
|
|
728
|
+
readonly type: "string";
|
|
729
|
+
readonly description: "Small bold heading at the top of the box";
|
|
730
|
+
};
|
|
731
|
+
readonly text: {
|
|
732
|
+
readonly type: "string";
|
|
733
|
+
readonly description: "Main content, centered. Wraps automatically; \"\\n\" forces a line break";
|
|
734
|
+
};
|
|
735
|
+
readonly footer: {
|
|
736
|
+
readonly type: "string";
|
|
737
|
+
readonly description: "Small dim line at the bottom of the box";
|
|
738
|
+
};
|
|
739
|
+
readonly x: {
|
|
740
|
+
readonly type: "number";
|
|
741
|
+
readonly description: "Top-left x in px. Omit (with y) to let the layout place the box";
|
|
742
|
+
};
|
|
743
|
+
readonly y: {
|
|
744
|
+
readonly type: "number";
|
|
745
|
+
readonly description: "Top-left y in px. Omit (with x) to let the layout place the box";
|
|
746
|
+
};
|
|
747
|
+
readonly w: {
|
|
748
|
+
readonly type: "number";
|
|
749
|
+
readonly exclusiveMinimum: 0;
|
|
750
|
+
readonly description: "Width in px. Omit to size from the text (never smaller than the type default)";
|
|
751
|
+
};
|
|
752
|
+
readonly h: {
|
|
753
|
+
readonly type: "number";
|
|
754
|
+
readonly exclusiveMinimum: 0;
|
|
755
|
+
readonly description: "Height in px. Omit to size from the text (never smaller than the type default)";
|
|
756
|
+
};
|
|
757
|
+
readonly color: {
|
|
758
|
+
readonly enum: readonly ColorName[];
|
|
759
|
+
readonly description: "Named color preset. Sets the stroke (outline + text) and, for boxes, a matching pastel fill. Omit for the default gray on transparent";
|
|
760
|
+
};
|
|
761
|
+
readonly stroke: {
|
|
762
|
+
readonly type: "string";
|
|
763
|
+
readonly description: "CSS color of the outline and text; overrides the preset";
|
|
764
|
+
};
|
|
765
|
+
readonly fill: {
|
|
766
|
+
readonly type: "string";
|
|
767
|
+
readonly description: "CSS color of the interior (\"transparent\" for none); overrides the preset";
|
|
768
|
+
};
|
|
769
|
+
};
|
|
770
|
+
};
|
|
771
|
+
readonly connector: {
|
|
772
|
+
readonly type: "object";
|
|
773
|
+
readonly required: readonly ["from", "to"];
|
|
774
|
+
readonly additionalProperties: false;
|
|
775
|
+
readonly properties: {
|
|
776
|
+
readonly id: {
|
|
777
|
+
readonly type: "string";
|
|
778
|
+
readonly description: "Optional; generated when omitted";
|
|
779
|
+
};
|
|
780
|
+
readonly type: {
|
|
781
|
+
readonly enum: readonly ConnectorType[];
|
|
782
|
+
readonly description: "arrow (default; arrowhead at \"to\") or line (no arrowheads)";
|
|
783
|
+
};
|
|
784
|
+
readonly from: {
|
|
785
|
+
readonly oneOf: readonly [{
|
|
786
|
+
readonly type: "string";
|
|
787
|
+
readonly description: "Id of a box. The connector attaches to its outline, aimed at the other end";
|
|
788
|
+
}, {
|
|
789
|
+
readonly type: "object";
|
|
790
|
+
readonly required: readonly ["id"];
|
|
791
|
+
readonly additionalProperties: false;
|
|
792
|
+
readonly properties: {
|
|
793
|
+
readonly id: {
|
|
794
|
+
readonly type: "string";
|
|
795
|
+
readonly description: "Id of a box";
|
|
796
|
+
};
|
|
797
|
+
readonly side: {
|
|
798
|
+
readonly enum: readonly ["top", "right", "bottom", "left"];
|
|
799
|
+
readonly description: "Pin the endpoint to the middle of this side of the box instead of auto-aiming";
|
|
800
|
+
};
|
|
801
|
+
};
|
|
802
|
+
}];
|
|
803
|
+
readonly description: "Box a connector end attaches to: a bare box id, or {id, side} to pick the attach edge";
|
|
804
|
+
};
|
|
805
|
+
readonly to: {
|
|
806
|
+
readonly oneOf: readonly [{
|
|
807
|
+
readonly type: "string";
|
|
808
|
+
readonly description: "Id of a box. The connector attaches to its outline, aimed at the other end";
|
|
809
|
+
}, {
|
|
810
|
+
readonly type: "object";
|
|
811
|
+
readonly required: readonly ["id"];
|
|
812
|
+
readonly additionalProperties: false;
|
|
813
|
+
readonly properties: {
|
|
814
|
+
readonly id: {
|
|
815
|
+
readonly type: "string";
|
|
816
|
+
readonly description: "Id of a box";
|
|
817
|
+
};
|
|
818
|
+
readonly side: {
|
|
819
|
+
readonly enum: readonly ["top", "right", "bottom", "left"];
|
|
820
|
+
readonly description: "Pin the endpoint to the middle of this side of the box instead of auto-aiming";
|
|
821
|
+
};
|
|
822
|
+
};
|
|
823
|
+
}];
|
|
824
|
+
readonly description: "Box a connector end attaches to: a bare box id, or {id, side} to pick the attach edge";
|
|
825
|
+
};
|
|
826
|
+
readonly text: {
|
|
827
|
+
readonly type: "string";
|
|
828
|
+
readonly description: "Label rendered at the middle of the connector";
|
|
829
|
+
};
|
|
830
|
+
readonly bidirectional: {
|
|
831
|
+
readonly type: "boolean";
|
|
832
|
+
readonly description: "Arrow only: arrowheads on both ends";
|
|
833
|
+
};
|
|
834
|
+
readonly routing: {
|
|
835
|
+
readonly enum: readonly ["straight", "elbow"];
|
|
836
|
+
readonly description: "straight (default) draws a direct line; elbow draws a right-angled path routed around the boxes";
|
|
837
|
+
};
|
|
838
|
+
readonly color: {
|
|
839
|
+
readonly enum: readonly ColorName[];
|
|
840
|
+
readonly description: "Named color preset. Sets the stroke (outline + text) and, for boxes, a matching pastel fill. Omit for the default gray on transparent";
|
|
841
|
+
};
|
|
842
|
+
readonly stroke: {
|
|
843
|
+
readonly type: "string";
|
|
844
|
+
readonly description: "CSS color of the line and label; overrides the preset";
|
|
845
|
+
};
|
|
846
|
+
};
|
|
847
|
+
};
|
|
848
|
+
readonly text: {
|
|
849
|
+
readonly type: "object";
|
|
850
|
+
readonly required: readonly ["x", "y", "text"];
|
|
851
|
+
readonly additionalProperties: false;
|
|
852
|
+
readonly properties: {
|
|
853
|
+
readonly id: {
|
|
854
|
+
readonly type: "string";
|
|
855
|
+
readonly description: "Optional; generated when omitted";
|
|
856
|
+
};
|
|
857
|
+
readonly x: {
|
|
858
|
+
readonly type: "number";
|
|
859
|
+
readonly description: "Top-left x of the first line, in px";
|
|
860
|
+
};
|
|
861
|
+
readonly y: {
|
|
862
|
+
readonly type: "number";
|
|
863
|
+
readonly description: "Top-left y of the first line, in px";
|
|
864
|
+
};
|
|
865
|
+
readonly text: {
|
|
866
|
+
readonly type: "string";
|
|
867
|
+
readonly description: "Content; \"\\n\" forces a line break";
|
|
868
|
+
};
|
|
869
|
+
readonly color: {
|
|
870
|
+
readonly enum: readonly ColorName[];
|
|
871
|
+
readonly description: "Named color preset. Sets the stroke (outline + text) and, for boxes, a matching pastel fill. Omit for the default gray on transparent";
|
|
872
|
+
};
|
|
873
|
+
readonly stroke: {
|
|
874
|
+
readonly type: "string";
|
|
875
|
+
readonly description: "CSS color of the text; overrides the preset";
|
|
876
|
+
};
|
|
877
|
+
};
|
|
878
|
+
};
|
|
879
|
+
};
|
|
880
|
+
};
|
|
881
|
+
|
|
882
|
+
type MermaidDirection = 'LR' | 'TD';
|
|
883
|
+
type MermaidOptions = Readonly<{
|
|
884
|
+
direction?: MermaidDirection;
|
|
885
|
+
}>;
|
|
886
|
+
/**
|
|
887
|
+
* Export a drawing as a Mermaid `flowchart`. Boxes become nodes (in shape
|
|
888
|
+
* order), connectors bound at both ends become edges; unbound connectors
|
|
889
|
+
* are dropped and free text shapes are kept as `%% note:` comments so
|
|
890
|
+
* nothing is silently lost.
|
|
891
|
+
*/
|
|
892
|
+
declare function drawingToMermaid(data: DrawingData, options?: MermaidOptions): string;
|
|
893
|
+
|
|
894
|
+
export { $createDrawingNode, $createFrontmatterNode, $getSelectedTable, $getTableDensity, $getTableSettings, $getTableWidth, $isDrawingNode, $isFrontmatterNode, $setTableDensity, $setTableSettings, $setTableWidth, BOX_DEFINITIONS, BOX_TYPES, type Binding, type BindingSide, type BlockWidth, type BoxDefinition, type BoxType, COLOR_PRESETS, CONNECTOR_TYPES, type ColorName, type ConnectorType, DEFAULT_TABLE_SETTINGS, DIAGRAM, DRAWING, DRAWING_DATA_JSON_SCHEMA, DRAWING_SKELETON_JSON_SCHEMA, type DrawingData, DrawingNode, type DrawingShape, type DrawingShapeType, type DrawingSkeleton, EMPTY_DRAWING, type EditorContentProps, type EditorMode, type EditorRootProps, FILL_COLORS, FRONTMATTER, FormatButtons, FrontmatterNode, HistoryButtons, InsertButtons, MarkdownEditor, type MarkdownEditorApi, type Props as MarkdownEditorProps, type MermaidDirection, type MermaidOptions, type Point, SHAPE_TYPES, SIDE_FIXED_POINTS, STROKE_COLORS, type SerializedDrawingNode, type SerializedFrontmatterNode, type SkeletonBox, type SkeletonConnector, type SkeletonEnd, type SkeletonText, TABLE, TABLE_WIDTH_MARKER, type TableDensity, type TableSettings, type TextField, Toolbar, ToolbarButton, ToolbarDivider, type ToolbarItems, anchorPoint, bindEndpoints, boxOutline, connectorPoints, drawingToMermaid, expandSkeleton, findBoxAt, fixedPointFor, formatTableSettingsMarker, isDrawingSkeleton, makeBinding, normalizeDrawingData, parseDrawingData, parseDrawingSkeleton, parseTableSettingsMarker, resolveBindings, routeElbow, serializeDrawingData, useMarkdownEditor };
|