@zuilib/text-editor 0.8.0 → 0.9.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 +8 -0
- package/dist/index.d.ts +148 -98
- package/dist/index.js +575 -180
- package/dist/styles.css +17 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog — @zuilib/text-editor
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
- **Ink drawing style**: `drawingStyle="ink"` on the editor renders shapes
|
|
6
|
+
as one seeded, pressure-varying pen stroke with misregistered fills and
|
|
7
|
+
tapered connectors, and switches the canvas face to Recursive (casual
|
|
8
|
+
axes) when the host loads it. Renderer-only: the drawing format is
|
|
9
|
+
unchanged. Geometry helpers are exported (`inkStroke`, `seedFrom`, …)
|
|
10
|
+
|
|
3
11
|
## 0.8.0
|
|
4
12
|
|
|
5
13
|
- **Syntax highlighting** for fenced code blocks, driven by the package's
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,146 @@ type BlockWidthDefaults = Readonly<{
|
|
|
30
30
|
drawing?: BlockWidth;
|
|
31
31
|
}>;
|
|
32
32
|
|
|
33
|
+
/** Card-like shapes: fillable, bindable, carrying the three text slots */
|
|
34
|
+
type BoxType = 'rect' | 'ellipse' | 'diamond' | 'note' | 'cylinder' | 'cloud' | 'queue' | 'actor';
|
|
35
|
+
type ConnectorType = 'arrow' | 'line';
|
|
36
|
+
type DrawingShapeType = BoxType | ConnectorType | 'text';
|
|
37
|
+
declare const BOX_TYPES: readonly BoxType[];
|
|
38
|
+
declare const CONNECTOR_TYPES: readonly ConnectorType[];
|
|
39
|
+
declare const SHAPE_TYPES: readonly DrawingShapeType[];
|
|
40
|
+
type Point = Readonly<{
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
}>;
|
|
44
|
+
type BindingSide = 'top' | 'right' | 'bottom' | 'left';
|
|
45
|
+
/**
|
|
46
|
+
* Where a connector endpoint attaches to a box.
|
|
47
|
+
*
|
|
48
|
+
* `fixedPoint` is a ratio inside the box's bounding box (`[0,0]` top-left,
|
|
49
|
+
* `[1,1]` bottom-right). Omitted = the box center, which makes the endpoint
|
|
50
|
+
* auto-aim at the other end. `mode: 'inside'` pins the endpoint exactly on
|
|
51
|
+
* the fixed point; the default (`'orbit'`) projects it onto the outline with
|
|
52
|
+
* a small gap.
|
|
53
|
+
*/
|
|
54
|
+
type Binding = Readonly<{
|
|
55
|
+
id: string;
|
|
56
|
+
fixedPoint?: readonly [number, number];
|
|
57
|
+
mode?: 'orbit' | 'inside';
|
|
58
|
+
}>;
|
|
59
|
+
type DrawingShape = Readonly<{
|
|
60
|
+
id: string;
|
|
61
|
+
type: DrawingShapeType;
|
|
62
|
+
/** Top-left corner (boxes/text) or start point (connectors) */
|
|
63
|
+
x: number;
|
|
64
|
+
y: number;
|
|
65
|
+
/** Size (boxes/text) or delta to the end point (connectors) */
|
|
66
|
+
w: number;
|
|
67
|
+
h: number;
|
|
68
|
+
stroke: string;
|
|
69
|
+
fill: string;
|
|
70
|
+
strokeWidth: number;
|
|
71
|
+
/** Standalone text, main (center) content of a box, or connector label */
|
|
72
|
+
text?: string;
|
|
73
|
+
/** Small heading rendered at the top of a box */
|
|
74
|
+
label?: string;
|
|
75
|
+
/** Small line rendered at the bottom of a box */
|
|
76
|
+
footer?: string;
|
|
77
|
+
/** Connector: box the start point is attached to */
|
|
78
|
+
startBinding?: Binding;
|
|
79
|
+
/** Connector: box the end point is attached to */
|
|
80
|
+
endBinding?: Binding;
|
|
81
|
+
/** Arrow: arrowheads on both ends */
|
|
82
|
+
bidirectional?: boolean;
|
|
83
|
+
/** Connector routing: right-angled auto-routed path instead of a straight line */
|
|
84
|
+
routing?: 'elbow';
|
|
85
|
+
/**
|
|
86
|
+
* Elbow override: position of the middle segment as a fraction of the
|
|
87
|
+
* span, applied only when the routed path is a simple three-segment Z.
|
|
88
|
+
*/
|
|
89
|
+
elbow?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Connector: intermediate path points between start and end (absolute
|
|
92
|
+
* canvas coordinates). Takes precedence over `routing`.
|
|
93
|
+
*/
|
|
94
|
+
waypoints?: readonly Point[];
|
|
95
|
+
}>;
|
|
96
|
+
type DrawingData = Readonly<{
|
|
97
|
+
version: 2;
|
|
98
|
+
/**
|
|
99
|
+
* Logical canvas width. When set the drawing is scaled to fit narrower
|
|
100
|
+
* layouts (SVG viewBox); when omitted the canvas is fluid and shapes are
|
|
101
|
+
* in CSS pixels.
|
|
102
|
+
*/
|
|
103
|
+
canvasWidth?: number;
|
|
104
|
+
canvasHeight: number;
|
|
105
|
+
/**
|
|
106
|
+
* Block width: `full` (default) spans the editor; `text` aligns with the
|
|
107
|
+
* text column; `content` fits the shapes' horizontal extent. The editor
|
|
108
|
+
* omits `full` unless it was written explicitly (an insertion default or
|
|
109
|
+
* the source payload); unknown values are dropped.
|
|
110
|
+
*/
|
|
111
|
+
width?: BlockWidth;
|
|
112
|
+
shapes: readonly DrawingShape[];
|
|
113
|
+
}>;
|
|
114
|
+
declare const EMPTY_DRAWING: DrawingData;
|
|
115
|
+
declare const STROKE_COLORS: readonly ["#1e1e1e", "#e03131", "#2f9e44", "#1971c2", "#f08c00", "#7048e8"];
|
|
116
|
+
declare const FILL_COLORS: readonly ["transparent", "#ffc9c9", "#b2f2bb", "#a5d8ff", "#ffec99", "#d0bfff"];
|
|
117
|
+
/** Edge midpoints, used by the ```diagram skeleton's `side` option */
|
|
118
|
+
declare const SIDE_FIXED_POINTS: Record<BindingSide, readonly [number, number]>;
|
|
119
|
+
declare function serializeDrawingData(data: DrawingData): string;
|
|
120
|
+
/**
|
|
121
|
+
* Parse a ```drawing payload. Exactly one format is accepted: version 2 as
|
|
122
|
+
* written by the editor (the ```diagram skeleton is a separate block type,
|
|
123
|
+
* see skeleton.ts). Shapes that fail validation are dropped and a malformed
|
|
124
|
+
* document yields an empty canvas. Never throws.
|
|
125
|
+
*/
|
|
126
|
+
declare function parseDrawingData(json: string): DrawingData;
|
|
127
|
+
declare function normalizeDrawingData(parsed: unknown): DrawingData;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* "Ink" rendering: one confident pen stroke instead of a plotted outline.
|
|
131
|
+
* Every shape's centerline is resampled densely, displaced along its normal
|
|
132
|
+
* by a smooth low-frequency field (two sines, integer frequencies on closed
|
|
133
|
+
* paths so the seam is continuous) and widened by a slowly varying pressure
|
|
134
|
+
* factor. The result is a filled ring path, not an SVG stroke, so the width
|
|
135
|
+
* can breathe along the path. Everything is seeded from the shape id: the
|
|
136
|
+
* same shape draws the same way on every render, undo, export and machine.
|
|
137
|
+
*
|
|
138
|
+
* This is a renderer concern only — the drawing format never sees it.
|
|
139
|
+
*/
|
|
140
|
+
type DrawingStyle = 'clean' | 'ink';
|
|
141
|
+
type InkOptions = Readonly<{
|
|
142
|
+
closed: boolean;
|
|
143
|
+
seed: number;
|
|
144
|
+
/** Nominal stroke width; the pressure factor varies it by ±30 % */
|
|
145
|
+
width: number;
|
|
146
|
+
/** Peak displacement from the geometric path, in px */
|
|
147
|
+
amplitude: number;
|
|
148
|
+
}>;
|
|
149
|
+
type InkStroke = Readonly<{
|
|
150
|
+
/** Filled outline of the stroke (use `fillRule="evenodd"`) */
|
|
151
|
+
ring: string;
|
|
152
|
+
/** Displaced centerline, for fills */
|
|
153
|
+
center: string;
|
|
154
|
+
}>;
|
|
155
|
+
/** FNV-1a: a stable 32-bit seed from a shape id */
|
|
156
|
+
declare function seedFrom(text: string): number;
|
|
157
|
+
/** Wobble amplitude for a shape of the given smallest dimension (px) */
|
|
158
|
+
declare function inkAmplitude(size: number): number;
|
|
159
|
+
/** Fill misregistration for a shape: a seeded 2–3 px offset */
|
|
160
|
+
declare function inkFillOffset(seed: number): Point;
|
|
161
|
+
/** Ink stroke along a polyline (open) or polygon (closed) */
|
|
162
|
+
declare function inkStroke(points: readonly Point[], options: InkOptions): InkStroke;
|
|
163
|
+
/** Rectangle outline with circular corners, as a polygon */
|
|
164
|
+
declare function roundedRectPolygon(r: Readonly<{
|
|
165
|
+
x: number;
|
|
166
|
+
y: number;
|
|
167
|
+
w: number;
|
|
168
|
+
h: number;
|
|
169
|
+
}>, radius: number, segments?: number): Point[];
|
|
170
|
+
/** Polyline with its interior corners rounded (quadratic), as points */
|
|
171
|
+
declare function roundedPolyline(points: readonly Point[], cornerRadius?: number, segments?: number): Point[];
|
|
172
|
+
|
|
33
173
|
type EditorMode = 'edit-raw' | 'edit-md' | 'view';
|
|
34
174
|
|
|
35
175
|
type EditorRootProps = Readonly<{
|
|
@@ -55,6 +195,12 @@ type EditorRootProps = Readonly<{
|
|
|
55
195
|
* insertion — markdown without a width marker always means `full`.
|
|
56
196
|
*/
|
|
57
197
|
defaultBlockWidth?: BlockWidthDefaults;
|
|
198
|
+
/**
|
|
199
|
+
* `clean` (default) draws crisp geometry; `ink` draws every shape as a
|
|
200
|
+
* single pen stroke with pressure and slightly misregistered fills, and
|
|
201
|
+
* sets the casual face (Recursive, if the host loads it).
|
|
202
|
+
*/
|
|
203
|
+
drawingStyle?: DrawingStyle;
|
|
58
204
|
children: ReactNode;
|
|
59
205
|
}>;
|
|
60
206
|
/**
|
|
@@ -62,7 +208,7 @@ type EditorRootProps = Readonly<{
|
|
|
62
208
|
* beneath it (`Content`, `Toolbar`, `Outline`, or your own components using
|
|
63
209
|
* `useMarkdownEditor`) shares the same editor instance.
|
|
64
210
|
*/
|
|
65
|
-
declare function EditorRoot({ value, onChange, readOnly, className, mode, autoFocus, measure, defaultBlockWidth, children, }: EditorRootProps): ReactElement;
|
|
211
|
+
declare function EditorRoot({ value, onChange, readOnly, className, mode, autoFocus, measure, defaultBlockWidth, drawingStyle, children, }: EditorRootProps): ReactElement;
|
|
66
212
|
|
|
67
213
|
type EditorContentProps = Readonly<{
|
|
68
214
|
placeholder?: string;
|
|
@@ -285,102 +431,6 @@ declare function $isFrontmatterNode(node: LexicalNode | null | undefined): node
|
|
|
285
431
|
*/
|
|
286
432
|
declare const FRONTMATTER: MultilineElementTransformer;
|
|
287
433
|
|
|
288
|
-
/** Card-like shapes: fillable, bindable, carrying the three text slots */
|
|
289
|
-
type BoxType = 'rect' | 'ellipse' | 'diamond' | 'note' | 'cylinder' | 'cloud' | 'queue' | 'actor';
|
|
290
|
-
type ConnectorType = 'arrow' | 'line';
|
|
291
|
-
type DrawingShapeType = BoxType | ConnectorType | 'text';
|
|
292
|
-
declare const BOX_TYPES: readonly BoxType[];
|
|
293
|
-
declare const CONNECTOR_TYPES: readonly ConnectorType[];
|
|
294
|
-
declare const SHAPE_TYPES: readonly DrawingShapeType[];
|
|
295
|
-
type Point = Readonly<{
|
|
296
|
-
x: number;
|
|
297
|
-
y: number;
|
|
298
|
-
}>;
|
|
299
|
-
type BindingSide = 'top' | 'right' | 'bottom' | 'left';
|
|
300
|
-
/**
|
|
301
|
-
* Where a connector endpoint attaches to a box.
|
|
302
|
-
*
|
|
303
|
-
* `fixedPoint` is a ratio inside the box's bounding box (`[0,0]` top-left,
|
|
304
|
-
* `[1,1]` bottom-right). Omitted = the box center, which makes the endpoint
|
|
305
|
-
* auto-aim at the other end. `mode: 'inside'` pins the endpoint exactly on
|
|
306
|
-
* the fixed point; the default (`'orbit'`) projects it onto the outline with
|
|
307
|
-
* a small gap.
|
|
308
|
-
*/
|
|
309
|
-
type Binding = Readonly<{
|
|
310
|
-
id: string;
|
|
311
|
-
fixedPoint?: readonly [number, number];
|
|
312
|
-
mode?: 'orbit' | 'inside';
|
|
313
|
-
}>;
|
|
314
|
-
type DrawingShape = Readonly<{
|
|
315
|
-
id: string;
|
|
316
|
-
type: DrawingShapeType;
|
|
317
|
-
/** Top-left corner (boxes/text) or start point (connectors) */
|
|
318
|
-
x: number;
|
|
319
|
-
y: number;
|
|
320
|
-
/** Size (boxes/text) or delta to the end point (connectors) */
|
|
321
|
-
w: number;
|
|
322
|
-
h: number;
|
|
323
|
-
stroke: string;
|
|
324
|
-
fill: string;
|
|
325
|
-
strokeWidth: number;
|
|
326
|
-
/** Standalone text, main (center) content of a box, or connector label */
|
|
327
|
-
text?: string;
|
|
328
|
-
/** Small heading rendered at the top of a box */
|
|
329
|
-
label?: string;
|
|
330
|
-
/** Small line rendered at the bottom of a box */
|
|
331
|
-
footer?: string;
|
|
332
|
-
/** Connector: box the start point is attached to */
|
|
333
|
-
startBinding?: Binding;
|
|
334
|
-
/** Connector: box the end point is attached to */
|
|
335
|
-
endBinding?: Binding;
|
|
336
|
-
/** Arrow: arrowheads on both ends */
|
|
337
|
-
bidirectional?: boolean;
|
|
338
|
-
/** Connector routing: right-angled auto-routed path instead of a straight line */
|
|
339
|
-
routing?: 'elbow';
|
|
340
|
-
/**
|
|
341
|
-
* Elbow override: position of the middle segment as a fraction of the
|
|
342
|
-
* span, applied only when the routed path is a simple three-segment Z.
|
|
343
|
-
*/
|
|
344
|
-
elbow?: number;
|
|
345
|
-
/**
|
|
346
|
-
* Connector: intermediate path points between start and end (absolute
|
|
347
|
-
* canvas coordinates). Takes precedence over `routing`.
|
|
348
|
-
*/
|
|
349
|
-
waypoints?: readonly Point[];
|
|
350
|
-
}>;
|
|
351
|
-
type DrawingData = Readonly<{
|
|
352
|
-
version: 2;
|
|
353
|
-
/**
|
|
354
|
-
* Logical canvas width. When set the drawing is scaled to fit narrower
|
|
355
|
-
* layouts (SVG viewBox); when omitted the canvas is fluid and shapes are
|
|
356
|
-
* in CSS pixels.
|
|
357
|
-
*/
|
|
358
|
-
canvasWidth?: number;
|
|
359
|
-
canvasHeight: number;
|
|
360
|
-
/**
|
|
361
|
-
* Block width: `full` (default) spans the editor; `text` aligns with the
|
|
362
|
-
* text column; `content` fits the shapes' horizontal extent. The editor
|
|
363
|
-
* omits `full` unless it was written explicitly (an insertion default or
|
|
364
|
-
* the source payload); unknown values are dropped.
|
|
365
|
-
*/
|
|
366
|
-
width?: BlockWidth;
|
|
367
|
-
shapes: readonly DrawingShape[];
|
|
368
|
-
}>;
|
|
369
|
-
declare const EMPTY_DRAWING: DrawingData;
|
|
370
|
-
declare const STROKE_COLORS: readonly ["#1e1e1e", "#e03131", "#2f9e44", "#1971c2", "#f08c00", "#7048e8"];
|
|
371
|
-
declare const FILL_COLORS: readonly ["transparent", "#ffc9c9", "#b2f2bb", "#a5d8ff", "#ffec99", "#d0bfff"];
|
|
372
|
-
/** Edge midpoints, used by the ```diagram skeleton's `side` option */
|
|
373
|
-
declare const SIDE_FIXED_POINTS: Record<BindingSide, readonly [number, number]>;
|
|
374
|
-
declare function serializeDrawingData(data: DrawingData): string;
|
|
375
|
-
/**
|
|
376
|
-
* Parse a ```drawing payload. Exactly one format is accepted: version 2 as
|
|
377
|
-
* written by the editor (the ```diagram skeleton is a separate block type,
|
|
378
|
-
* see skeleton.ts). Shapes that fail validation are dropped and a malformed
|
|
379
|
-
* document yields an empty canvas. Never throws.
|
|
380
|
-
*/
|
|
381
|
-
declare function parseDrawingData(json: string): DrawingData;
|
|
382
|
-
declare function normalizeDrawingData(parsed: unknown): DrawingData;
|
|
383
|
-
|
|
384
434
|
type SerializedDrawingNode = Spread<{
|
|
385
435
|
data: string;
|
|
386
436
|
}, SerializedLexicalNode>;
|
|
@@ -1252,4 +1302,4 @@ declare const codeTokenizer: LexicalTokenizer;
|
|
|
1252
1302
|
*/
|
|
1253
1303
|
declare function registerCodeBlockHighlighting(editor: LexicalEditor): () => void;
|
|
1254
1304
|
|
|
1255
|
-
export { $createDrawingNode, $createFrontmatterNode, $getSelectedTable, $getTableDensity, $getTableSettings, $getTableWidth, $isDrawingNode, $isFrontmatterNode, $isTableWidthExplicit, $setTableDensity, $setTableSettings, $setTableWidth, BLOCK_WIDTHS, BOX_DEFINITIONS, BOX_TYPES, BUILTIN_CODE_LANGUAGES, type Binding, type BindingSide, type BlockWidth, type BlockWidthDefaults, type BoxDefinition, type BoxType, CODE_BLOCK, CODE_TOKEN_TYPES, COLOR_PRESETS, CONNECTOR_TYPES, type CodeGrammar, type CodeRule, type CodeToken, type CodeTokenType, 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, PLAIN_LANGUAGE, 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 TableSettingsOptions, type TextField, Toolbar, ToolbarButton, ToolbarDivider, type ToolbarItems, anchorPoint, bindEndpoints, boxOutline, codeTokenizer, connectorPoints, drawingToMermaid, expandSkeleton, findBoxAt, fixedPointFor, formatTableSettingsMarker, getCodeLanguages, hasCodeLanguage, isBlockWidth, isDrawingSkeleton, makeBinding, normalizeDrawingData, parseDrawingData, parseDrawingSkeleton, parseTableSettingsMarker, registerCodeBlockHighlighting, registerCodeLanguage, resolveBindings, resolveCodeLanguage, routeElbow, serializeDrawingData, tokenizeCode, useMarkdownEditor };
|
|
1305
|
+
export { $createDrawingNode, $createFrontmatterNode, $getSelectedTable, $getTableDensity, $getTableSettings, $getTableWidth, $isDrawingNode, $isFrontmatterNode, $isTableWidthExplicit, $setTableDensity, $setTableSettings, $setTableWidth, BLOCK_WIDTHS, BOX_DEFINITIONS, BOX_TYPES, BUILTIN_CODE_LANGUAGES, type Binding, type BindingSide, type BlockWidth, type BlockWidthDefaults, type BoxDefinition, type BoxType, CODE_BLOCK, CODE_TOKEN_TYPES, COLOR_PRESETS, CONNECTOR_TYPES, type CodeGrammar, type CodeRule, type CodeToken, type CodeTokenType, 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, type DrawingStyle, EMPTY_DRAWING, type EditorContentProps, type EditorMode, type EditorRootProps, FILL_COLORS, FRONTMATTER, FormatButtons, FrontmatterNode, HistoryButtons, type InkOptions, type InkStroke, InsertButtons, MarkdownEditor, type MarkdownEditorApi, type Props as MarkdownEditorProps, type MermaidDirection, type MermaidOptions, PLAIN_LANGUAGE, 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 TableSettingsOptions, type TextField, Toolbar, ToolbarButton, ToolbarDivider, type ToolbarItems, anchorPoint, bindEndpoints, boxOutline, codeTokenizer, connectorPoints, drawingToMermaid, expandSkeleton, findBoxAt, fixedPointFor, formatTableSettingsMarker, getCodeLanguages, hasCodeLanguage, inkAmplitude, inkFillOffset, inkStroke, isBlockWidth, isDrawingSkeleton, makeBinding, normalizeDrawingData, parseDrawingData, parseDrawingSkeleton, parseTableSettingsMarker, registerCodeBlockHighlighting, registerCodeLanguage, resolveBindings, resolveCodeLanguage, roundedPolyline, roundedRectPolygon, routeElbow, seedFrom, serializeDrawingData, tokenizeCode, useMarkdownEditor };
|