cseen 0.1.0 → 0.2.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 +10 -2
- package/dist/all.d.ts +1 -0
- package/dist/all.js +1 -0
- package/dist/all.js.map +1 -1
- package/dist/anim/mount.js +58 -2
- package/dist/anim/mount.js.map +1 -1
- package/dist/anim/orbit.js +2 -0
- package/dist/anim/orbit.js.map +1 -1
- package/dist/core/nodes.d.ts +67 -2
- package/dist/core/nodes.js +68 -0
- package/dist/core/nodes.js.map +1 -1
- package/dist/core/render.d.ts +13 -1
- package/dist/core/render.js +47 -6
- package/dist/core/render.js.map +1 -1
- package/dist/core/scene.js +10 -3
- package/dist/core/scene.js.map +1 -1
- package/dist/cseen.css +2 -0
- package/dist/draw/heads.d.ts +11 -0
- package/dist/draw/heads.js +26 -0
- package/dist/draw/heads.js.map +1 -0
- package/dist/draw/overlap.d.ts +50 -0
- package/dist/draw/overlap.js +80 -0
- package/dist/draw/overlap.js.map +1 -0
- package/dist/draw/shapes.d.ts +27 -2
- package/dist/draw/shapes.js +26 -1
- package/dist/draw/shapes.js.map +1 -1
- package/dist/draw/svgplane.d.ts +30 -1
- package/dist/draw/svgplane.js +34 -0
- package/dist/draw/svgplane.js.map +1 -1
- package/dist/draw/words.d.ts +29 -0
- package/dist/draw/words.js +30 -0
- package/dist/draw/words.js.map +1 -0
- package/dist/flow/flow.d.ts +10 -2
- package/dist/flow/flow.js +18 -26
- package/dist/flow/flow.js.map +1 -1
- package/dist/flow/index.d.ts +1 -1
- package/dist/flow/sequence.d.ts +40 -3
- package/dist/flow/sequence.js +241 -81
- package/dist/flow/sequence.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/uml/factory.d.ts +15 -0
- package/dist/uml/factory.js +16 -0
- package/dist/uml/factory.js.map +1 -0
- package/dist/uml/index.d.ts +3 -0
- package/dist/uml/index.js +3 -0
- package/dist/uml/index.js.map +1 -0
- package/dist/uml/uml.d.ts +187 -0
- package/dist/uml/uml.js +599 -0
- package/dist/uml/uml.js.map +1 -0
- package/package.json +6 -2
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { Group, Path, type NodeOpts } from '../core/nodes.ts';
|
|
2
|
+
import { type LineHead } from '../draw/heads.ts';
|
|
3
|
+
import { type Rect } from '../draw/overlap.ts';
|
|
4
|
+
/** The kind of UML diagram. It names the frame (`uc Library`) and decides the defaults: `uc` use cases, `class`, `state` machines and `act` activities. */
|
|
5
|
+
export type UmlKind = 'uc' | 'class' | 'state' | 'act';
|
|
6
|
+
/** The look of every kind of node, and what it needs to say. All of them take `href`, `role` and `fill`. */
|
|
7
|
+
interface Common {
|
|
8
|
+
/** makes the node a link to this address: one Tab stop, named after what it says. Unsafe addresses such as `javascript:` are refused. */
|
|
9
|
+
href?: string;
|
|
10
|
+
/** colour role (`ink`, `faint`, `accent`, `s1` to `s8`) or a role you define in CSS */
|
|
11
|
+
role?: string;
|
|
12
|
+
}
|
|
13
|
+
/** A person or system outside the one drawn: a stick figure with its name below. */
|
|
14
|
+
export interface ActorNode extends Common {
|
|
15
|
+
/** the name under the figure; `\n` breaks a line */
|
|
16
|
+
actor: string;
|
|
17
|
+
}
|
|
18
|
+
/** A thing the system does for an actor: an ellipse. */
|
|
19
|
+
export interface UseCaseNode extends Common {
|
|
20
|
+
/** what it says inside the ellipse; `\n` breaks a line */
|
|
21
|
+
useCase: string;
|
|
22
|
+
}
|
|
23
|
+
/** A class in three compartments: name, attributes, operations. Write members as UML does: `+ name : Type [0..1]`, `- hidden`, `+ run(x : Type) : Result`. */
|
|
24
|
+
export interface ClassNode extends Common {
|
|
25
|
+
/** the name of the class */
|
|
26
|
+
class: string;
|
|
27
|
+
/** shown in guillemets above the name, such as `interface`, `enumeration` or `dataclass` */
|
|
28
|
+
stereotype?: string;
|
|
29
|
+
/** the attributes, one per line, in the first compartment */
|
|
30
|
+
attrs?: string[];
|
|
31
|
+
/** the operations, one per line, in the second compartment */
|
|
32
|
+
ops?: string[];
|
|
33
|
+
}
|
|
34
|
+
/** A state of a state machine: a rounded box. */
|
|
35
|
+
export interface StateNode extends Common {
|
|
36
|
+
/** the name of the state */
|
|
37
|
+
state: string;
|
|
38
|
+
}
|
|
39
|
+
/** An action of an activity diagram: a rounded box. */
|
|
40
|
+
export interface ActionNode extends Common {
|
|
41
|
+
/** what it does */
|
|
42
|
+
action: string;
|
|
43
|
+
}
|
|
44
|
+
/** A choice in an activity or state diagram: a diamond. Put the conditions on the lines that leave it, as `[guards]`. */
|
|
45
|
+
export interface DecisionNode extends Common {
|
|
46
|
+
/** marks the node as a decision */
|
|
47
|
+
decision: true;
|
|
48
|
+
}
|
|
49
|
+
/** The black dot where an activity or state machine starts. */
|
|
50
|
+
export interface StartNode extends Common {
|
|
51
|
+
/** marks the node as the start */
|
|
52
|
+
start: true;
|
|
53
|
+
}
|
|
54
|
+
/** The bull's eye where it ends. */
|
|
55
|
+
export interface EndNode extends Common {
|
|
56
|
+
/** marks the node as the end */
|
|
57
|
+
end: true;
|
|
58
|
+
}
|
|
59
|
+
/** A plain box with words in it, for anything else. */
|
|
60
|
+
export interface BoxNode extends Common {
|
|
61
|
+
/** what it says; `\n` breaks a line */
|
|
62
|
+
box: string;
|
|
63
|
+
}
|
|
64
|
+
/** Anything that can be a node of a UML diagram. */
|
|
65
|
+
export type UmlNodeSpec = ActorNode | UseCaseNode | ClassNode | StateNode | ActionNode | DecisionNode | StartNode | EndNode | BoxNode;
|
|
66
|
+
/** A line between two nodes. */
|
|
67
|
+
export interface UmlEdge {
|
|
68
|
+
/** the key of the node it leaves */
|
|
69
|
+
from: string;
|
|
70
|
+
/** the key of the node it reaches, where the head is */
|
|
71
|
+
to: string;
|
|
72
|
+
/**
|
|
73
|
+
* The end of the line at `to`: `none`, `open` (a plain arrow), `solid`, `inherit` (hollow triangle), `compose` (filled
|
|
74
|
+
* diamond) or `aggregate` (hollow diamond). Left out, it follows UML: `none` between an actor and a use case, a hollow
|
|
75
|
+
* triangle on a dashed line towards an `interface`, and `open` otherwise. A diamond belongs at the whole's end, so
|
|
76
|
+
* put the whole in `to`.
|
|
77
|
+
*/
|
|
78
|
+
head?: LineHead;
|
|
79
|
+
/** draw it dashed. Left out, a label in guillemets (`«include»`, `«create»`) makes it dashed, as UML does for dependencies. */
|
|
80
|
+
dash?: boolean;
|
|
81
|
+
/** words on the line. On a line that leaves a decision, `[` and `]` are added if missing. */
|
|
82
|
+
label?: string;
|
|
83
|
+
/** a multiplicity at each end, `[at from, at to]`, such as `['1', '0..*']` */
|
|
84
|
+
ends?: [string?, string?];
|
|
85
|
+
/** colour role of the line and its head (`ink` by default, or `accent`, `s1` to `s8`, or a role you define in CSS) */
|
|
86
|
+
role?: string;
|
|
87
|
+
}
|
|
88
|
+
/** A frame drawn around some of the nodes, with its title in the corner: the boundary of a system, or a composite state. */
|
|
89
|
+
export interface UmlFrame {
|
|
90
|
+
/** the name in the corner */
|
|
91
|
+
title: string;
|
|
92
|
+
/** the keys of the nodes it holds */
|
|
93
|
+
around: string[];
|
|
94
|
+
}
|
|
95
|
+
/** Everything a UML diagram shows, described once. `wide` and `narrow` only say where things go. */
|
|
96
|
+
export interface UmlSpec {
|
|
97
|
+
/** the kind of diagram, which starts the title tab and sets the defaults */
|
|
98
|
+
kind: UmlKind;
|
|
99
|
+
/** the name in the title tab of the outer frame. Leave it out for a diagram with no outer frame. */
|
|
100
|
+
name?: string;
|
|
101
|
+
/** the nodes by key */
|
|
102
|
+
nodes: Record<string, UmlNodeSpec>;
|
|
103
|
+
/** the lines, drawn in this order */
|
|
104
|
+
edges?: UmlEdge[];
|
|
105
|
+
/** frames around groups of nodes */
|
|
106
|
+
frames?: UmlFrame[];
|
|
107
|
+
/** swimlanes: one name per column of the wide grid. On a phone, where there are no columns, each node says its lane. */
|
|
108
|
+
lanes?: string[];
|
|
109
|
+
/**
|
|
110
|
+
* Where the nodes go for a wide screen: one string per row, with a key for each cell, separated by spaces. A key that
|
|
111
|
+
* repeats over neighbouring cells makes the node span them, and `.` is an empty cell.
|
|
112
|
+
*/
|
|
113
|
+
wide: string[];
|
|
114
|
+
/** The same for a phone. Without it the nodes stack in one column in the order of `nodes`. */
|
|
115
|
+
narrow?: string[];
|
|
116
|
+
}
|
|
117
|
+
/** Options of `uml`. */
|
|
118
|
+
export interface UmlOpts extends NodeOpts {
|
|
119
|
+
/** draw the narrow grid: at most 358 px wide, text of 12 px, and boxes that wrap their words */
|
|
120
|
+
narrow?: boolean;
|
|
121
|
+
}
|
|
122
|
+
/** The node that was drawn for a key: its shape, size and place, in pixels from the top left of the diagram. */
|
|
123
|
+
export declare class UmlNode extends Group {
|
|
124
|
+
/** what it says */
|
|
125
|
+
name: string;
|
|
126
|
+
/** its box in pixels from the top left of the diagram area */
|
|
127
|
+
rect: Rect;
|
|
128
|
+
constructor(name: string, rect: Rect);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A UML diagram: use cases, classes, states or activities, with the notation UML uses. Describe it once as a `UmlSpec`;
|
|
132
|
+
* it is drawn wide or narrow from the same description. Everything is placed on a grid, lines are routed around the
|
|
133
|
+
* boxes, and `problems()` lists whatever still sits on something else.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* const s = new Scene({ view: 'front', size: [360, 240] });
|
|
137
|
+
* const d = s.add(new Uml({
|
|
138
|
+
* kind: 'class',
|
|
139
|
+
* nodes: { shape: { class: 'Shape', stereotype: 'interface', ops: ['+ area() : float'] }, circle: { class: 'Circle', attrs: ['+ r : float'] } },
|
|
140
|
+
* edges: [{ from: 'circle', to: 'shape' }],
|
|
141
|
+
* wide: ['shape', 'circle'],
|
|
142
|
+
* }));
|
|
143
|
+
* d.check();
|
|
144
|
+
*/
|
|
145
|
+
export declare class Uml extends Group {
|
|
146
|
+
/** the nodes by key */
|
|
147
|
+
nodes: Map<string, UmlNode>;
|
|
148
|
+
/** the lines, in the order of the spec */
|
|
149
|
+
lines: Path[];
|
|
150
|
+
private placed;
|
|
151
|
+
private extra;
|
|
152
|
+
private top;
|
|
153
|
+
private narrow;
|
|
154
|
+
private spec;
|
|
155
|
+
constructor(spec: UmlSpec, o?: UmlOpts);
|
|
156
|
+
/** the size of the whole diagram on the page, width and height in world units, outer frame and every label included */
|
|
157
|
+
extent(): [number, number];
|
|
158
|
+
/** every box, label or line that sits on another, every text wider than its box or leaving the diagram, and, for a narrow diagram, a width over 358 px. Empty when the diagram is clean. */
|
|
159
|
+
problems(): string[];
|
|
160
|
+
/** throws when there are `problems`, otherwise returns the diagram */
|
|
161
|
+
check(): this;
|
|
162
|
+
private clear;
|
|
163
|
+
private words;
|
|
164
|
+
/** records the lines of a text for the overlap check, with the left edge `x0` and the middle of its first line at `y` */
|
|
165
|
+
private note;
|
|
166
|
+
private shape;
|
|
167
|
+
private stroke;
|
|
168
|
+
private oval;
|
|
169
|
+
private rounded;
|
|
170
|
+
/** gives a node its size. `room` is the width a narrow diagram can give it. */
|
|
171
|
+
private size;
|
|
172
|
+
private build;
|
|
173
|
+
/** the defaults of UML for a line: its head and whether it is dashed */
|
|
174
|
+
private edgeOf;
|
|
175
|
+
private actorTitle;
|
|
176
|
+
private lanes;
|
|
177
|
+
private draw;
|
|
178
|
+
private route;
|
|
179
|
+
private line;
|
|
180
|
+
/** where a straight line from the middle of a node towards `toward` leaves its outline */
|
|
181
|
+
private edgePoint;
|
|
182
|
+
/** puts words on a line where nothing else is: above a flat stretch, beside an upright one, trying other places if the first is taken */
|
|
183
|
+
private label;
|
|
184
|
+
/** a multiplicity at the end of a line, beside it */
|
|
185
|
+
private endWord;
|
|
186
|
+
}
|
|
187
|
+
export {};
|