@yaks/diagram 0.0.0-stage → 0.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +222 -2
- package/_dist/ink.d.ts +30 -0
- package/_dist/ink.d.ts.map +1 -0
- package/_dist/layout.d.ts +92 -0
- package/_dist/layout.d.ts.map +1 -0
- package/_dist/mod.d.ts +20 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/mount.d.ts +55 -0
- package/_dist/mount.d.ts.map +1 -0
- package/_dist/pen.d.ts +50 -0
- package/_dist/pen.d.ts.map +1 -0
- package/_dist/shape.d.ts +44 -0
- package/_dist/shape.d.ts.map +1 -0
- package/_dist/steer.d.ts +13 -0
- package/_dist/steer.d.ts.map +1 -0
- package/_dist/styles.d.ts +25 -0
- package/_dist/styles.d.ts.map +1 -0
- package/_dist/svg.d.ts +22 -0
- package/_dist/svg.d.ts.map +1 -0
- package/_dist/tangle.d.ts +25 -0
- package/_dist/tangle.d.ts.map +1 -0
- package/_dist/view.d.ts +20 -0
- package/_dist/view.d.ts.map +1 -0
- package/deno.json +1 -0
- package/geometry.js +42 -0
- package/geometry.js.map +1 -0
- package/geometry.ts +44 -0
- package/ink.js +43 -0
- package/ink.js.map +1 -0
- package/ink.ts +61 -0
- package/layout.js +1048 -0
- package/layout.js.map +1 -0
- package/layout.ts +981 -0
- package/layout_bench.ts +27 -0
- package/mod.js +20 -0
- package/mod.js.map +1 -0
- package/mod.ts +20 -0
- package/mount.js +177 -0
- package/mount.js.map +1 -0
- package/mount.ts +205 -0
- package/package.json +18 -4
- package/pen.js +106 -0
- package/pen.js.map +1 -0
- package/pen.ts +130 -0
- package/shape.js +233 -0
- package/shape.js.map +1 -0
- package/shape.ts +204 -0
- package/steer.js +132 -0
- package/steer.js.map +1 -0
- package/steer.ts +112 -0
- package/styles.js +110 -0
- package/styles.js.map +1 -0
- package/styles.ts +110 -0
- package/svg.js +119 -0
- package/svg.js.map +1 -0
- package/svg.ts +193 -0
- package/tangle.js +151 -0
- package/tangle.js.map +1 -0
- package/tangle.ts +153 -0
- package/view.js +63 -0
- package/view.js.map +1 -0
- package/view.ts +65 -0
package/_dist/pen.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Layout, Link, Node } from "./layout.js";
|
|
2
|
+
import { type Curve } from "./shape.js";
|
|
3
|
+
/**
|
|
4
|
+
* The curve each line is drawn along, by its key: from the rim of one shape
|
|
5
|
+
* to the rim of the other, bent as far as its `bend`.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { curves, layout } from '@yaks/diagram'
|
|
9
|
+
* import { equal } from '@yaks/testing'
|
|
10
|
+
*
|
|
11
|
+
* let a = { entity: { eid: '0a' }, doc: { title: 'Dune' } }
|
|
12
|
+
* let b = { entity: { eid: '0b' }, review: { of: '0a' } }
|
|
13
|
+
* equal([...curves(layout([a, b])).keys()], ['0b>review.of>0a'])
|
|
14
|
+
* ```
|
|
15
|
+
*/ export declare let curves: (layout: Layout) => Map<string, Curve>;
|
|
16
|
+
/** A shape or a line, by the key a drawing marks it with: a node's eid or a
|
|
17
|
+
* link's key. */ export type Item = Node | Link;
|
|
18
|
+
export declare let keyOf: (item: Item) => string;
|
|
19
|
+
/**
|
|
20
|
+
* The order a pen draws a layout's items in: stage by stage, and within a
|
|
21
|
+
* stage each shape in the order it joined, then the lines that now have both
|
|
22
|
+
* ends drawn.
|
|
23
|
+
*/ export declare let strokes: (layout: Layout) => Item[][];
|
|
24
|
+
/**
|
|
25
|
+
* How far each item is drawn, 0 to 1, by its key, when each stage has come
|
|
26
|
+
* `reached(stage)` of the way in (0 to 1). A stage's items share its way in:
|
|
27
|
+
* the first is drawn while the stage is barely reached and the last only
|
|
28
|
+
* once it nearly is.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { layout, progress } from '@yaks/diagram'
|
|
32
|
+
* import { equal } from '@yaks/testing'
|
|
33
|
+
*
|
|
34
|
+
* let a = { entity: { eid: '0a' }, doc: { title: 'Dune' } }
|
|
35
|
+
* let drawn = layout([a], { stage: 1 })
|
|
36
|
+
* equal(progress(drawn, () => 0).get('0a'), 0)
|
|
37
|
+
* equal(progress(drawn, () => 1).get('0a'), 1)
|
|
38
|
+
* ```
|
|
39
|
+
*/ export declare let progress: (layout: Layout, reached: (stage: number) => number) => Map<string, number>;
|
|
40
|
+
/** Where the pen is: on the item it is drawing, at that item's stage. */ export type Tip = {
|
|
41
|
+
key: string;
|
|
42
|
+
stage: number;
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The pen's tip: on the latest item still being drawn, as far along its
|
|
48
|
+
* outline or line as it is drawn; none when nothing is part drawn.
|
|
49
|
+
*/ export declare let tip: (layout: Layout, drawn: Map<string, number>) => Tip | undefined;
|
|
50
|
+
//# sourceMappingURL=pen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pen.d.ts","sources":["../pen.ts"],"names":[],"mappings":"AAKA,cAAc,MAAM,EAAE,IAAI,EAAE,IAAI,sBAAqB;AACrD,SAAgB,KAAK,KAAK,qBAA+B;AAEzD;;;;;;;;;;;;CAYC,GACD,OAAO,YAAI,SAAU,QAAQ,WAAS,IAAI,MAAM,EAAE,OAQjD;AAED;eACe,GACf,YAAY,OAAO,OAAO;AAE1B,OAAO,YAAI,QAAS,MAAM,SAAO,MAAM,CAAuC;AAE9E;;;;CAIC,GACD,OAAO,YAAI,UAAW,QAAQ,WAAS,SA8BtC;AAED;;;;;;;;;;;;;;;CAeC,GACD,OAAO,YAAI,WACT,QAAQ,QACR,UAAU,OAAO,MAAM,KAAK,MAAM,KACjC,IAAI,MAAM,EAAE,MAAM,EASpB;AAED,uEAAuE,GACvE,YAAY;EAAQ,KAAK,MAAM;EAAE,OAAO,MAAM;EAAE,GAAG,MAAM;EAAE,GAAG,MAAM;;AAEpE;;;CAGC,GACD,OAAO,YAAI,MACT,QAAQ,QACR,OAAO,IAAI,MAAM,EAAE,MAAM,MACxB,MAAM,SAAS,CAejB"}
|
package/_dist/shape.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** How an entity is outlined: a box, a circle (a person), a hexagon (an
|
|
2
|
+
* agent) or a note with a folded corner (a comment). */ export type Shape = 'box' | 'round' | 'hex' | 'note';
|
|
3
|
+
/** The shape each component draws its entity as; any other is a box. */ export declare const SHAPES: Record<string, Shape>;
|
|
4
|
+
/** A shape's half width and half height, with room for the title a round
|
|
5
|
+
* shape writes under itself. */ export declare let half: (shape: Shape, task?: boolean) => [number, number];
|
|
6
|
+
/** The room kept clear between two shapes. */ export declare const APART: 24;
|
|
7
|
+
/** A round shape's radius. */ export declare let radius: (shape: Shape) => any;
|
|
8
|
+
type Spot = [number, number];
|
|
9
|
+
/** A shape's outline as an SVG path, centred on 0,0. */ export declare let outline: (shape: Shape, task?: boolean) => string;
|
|
10
|
+
/** Where a line from a shape's centre toward (dx, dy) leaves it, a little
|
|
11
|
+
* outside so an arrowhead rests on the rim. */ export declare let rim: (shape: Shape, task: boolean, dx: number, dy: number) => Spot;
|
|
12
|
+
/** The point a fraction `t` of the way round a shape's outline. */ export declare let along: (shape: Shape, task: boolean, t: number) => Spot;
|
|
13
|
+
/** A line's curve: from one rim, bending through a control point, to the
|
|
14
|
+
* other rim. */ export type Curve = {
|
|
15
|
+
x0: number;
|
|
16
|
+
y0: number;
|
|
17
|
+
cx: number;
|
|
18
|
+
cy: number;
|
|
19
|
+
x1: number;
|
|
20
|
+
y1: number;
|
|
21
|
+
};
|
|
22
|
+
/** The point a fraction `t` along a curve. */ export declare let on: (c: Curve, t: number) => Spot;
|
|
23
|
+
/** A shape where it sits: its centre, outline and whether it has a state. */ export type Seat = {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
shape: Shape;
|
|
27
|
+
state?: string;
|
|
28
|
+
};
|
|
29
|
+
/** The curve from the rim of `a` to the rim of `b`, its middle `bend` to the
|
|
30
|
+
* left of the straight line between them (to the right when negative): the
|
|
31
|
+
* control point sits twice that far out. */ export declare let curve: (a: Seat, b: Seat, bend: number) => Curve;
|
|
32
|
+
/** Where a line's name is written, a fraction along its curve: the point
|
|
33
|
+
* there, where its name and (for an edge) its short id go and how they are
|
|
34
|
+
* anchored, and the box the words cover. A line that is an edge entity has a
|
|
35
|
+
* diamond at the point, with its words beside it, or above and below when
|
|
36
|
+
* the line runs across. */ export type Tag = {
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
name: [number, number, 'start' | 'middle' | 'end'];
|
|
40
|
+
sub: [number, number, 'start' | 'middle' | 'end'];
|
|
41
|
+
box: [number, number, number, number];
|
|
42
|
+
};
|
|
43
|
+
export declare let tag: (c: Curve, t: number, name: string, edge?: string) => Tag;
|
|
44
|
+
//# sourceMappingURL=shape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shape.d.ts","sources":["../shape.ts"],"names":[],"mappings":"AAIA;sDACsD,GACtD,YAAY,QAAQ,QAAQ,UAAU,QAAQ;AAE9C,sEAAsE,GACtE,OAAO,cAAM,QAAQ,OAAO,MAAM,EAAE,OAKnC;AAED;8BAC8B,GAC9B,OAAO,YAAI,OAAQ,OAAO,OAAO,oBAAgB,MAAM,EAAE,MAAM,EAOjD;AAEd,4CAA4C,GAC5C,OAAO,cAAM,OAAQ,GAAE;AAEvB,4BAA4B,GAC5B,OAAO,YAAI,SAAU,OAAO,cAAoC;KAE3D,QAAQ,MAAM,EAAE,MAAM;AAoB3B,sDAAsD,GACtD,OAAO,YAAI,UAAW,OAAO,OAAO,mBAAe,MAAM,CASxD;AAED;6CAC6C,GAC7C,OAAO,YAAI,MACT,OAAO,OACP,MAAM,OAAO,EACb,IAAI,MAAM,EACV,IAAI,MAAM,KACT,KAWF;AAED,iEAAiE,GACjE,OAAO,YAAI,QAAS,OAAO,OAAO,MAAM,OAAO,EAAE,GAAG,MAAM,KAAG,KAgB5D;AAED;cACc,GACd,YAAY;EACV,IAAI,MAAM;EACV,IAAI,MAAM;EACV,IAAI,MAAM;EACV,IAAI,MAAM;EACV,IAAI,MAAM;EACV,IAAI,MAAM;;AAGZ,4CAA4C,GAC5C,OAAO,YAAI,KAAM,GAAG,OAAO,GAAG,MAAM,KAAG,KAMtC;AAED,2EAA2E,GAC3E,YAAY;EAAS,GAAG,MAAM;EAAE,GAAG,MAAM;EAAE,OAAO;EAAO,QAAQ,MAAM;;AAEvE;;0CAE0C,GAC1C,OAAO,YAAI,QAAS,GAAG,MAAM,GAAG,MAAM,MAAM,MAAM,KAAG,MAepD;AAED;;;;yBAIyB,GACzB,YAAY;EACV,GAAG,MAAM;EACT,GAAG,MAAM;EACT,OAAO,MAAM,EAAE,MAAM,EAAE,UAAU,WAAW;EAC5C,MAAM,MAAM,EAAE,MAAM,EAAE,UAAU,WAAW;EAC3C,MAAM,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;AAOtC,OAAO,YAAI,MACT,GAAG,OACH,GAAG,MAAM,EACT,MAAM,MAAM,EACZ,OAAO,MAAM,KACZ,IAkCF"}
|
package/_dist/steer.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Layout } from "./layout.js";
|
|
2
|
+
import { type View } from "./view.js";
|
|
3
|
+
/** What a drawing being steered is asked and told. */ export type Steering = {
|
|
4
|
+
/** The layout drawn, once there is one. */ layout: () => Layout | undefined;
|
|
5
|
+
view: () => View;
|
|
6
|
+
/** Show another part of the sheet. */ set: (view: View) => void;
|
|
7
|
+
};
|
|
8
|
+
/** Follow a reader's gestures on `el`, which holds the drawing's `<svg>`;
|
|
9
|
+
* update its touch mode when the view changes and stop when it is removed. */ export declare let steer: (el: HTMLElement, s: Steering) => {
|
|
10
|
+
touch: () => void;
|
|
11
|
+
stop: () => void;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=steer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steer.d.ts","sources":["../steer.ts"],"names":[],"mappings":"AAMA,cAAc,MAAM,sBAAqB;AACzC,SAAc,KAAK,IAAI,oBAAiC;AAExD,oDAAoD,GACpD,YAAY;EACV,yCAAyC,GACzC,cAAc,SAAS,SAAS;EAChC,YAAY;EACZ,oCAAoC,GACpC,MAAM,MAAM,SAAS,IAAI;;AAQ3B;4EAC4E,GAC5E,OAAO,YAAI,QACT,IAAI,aACJ,GAAG;EACA,aAAa,IAAI;EAAE,YAAY,IAAI;EAmFvC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stylesheet a drawing is meant to wear: thin strokes, small mono text,
|
|
3
|
+
* and a pen. Without {@link ink} each new shape and line is drawn in, one
|
|
4
|
+
* after another, as it joins; with it the page says how far each is drawn,
|
|
5
|
+
* and the stroke under the pen glows. Every colour is a custom property a
|
|
6
|
+
* page sets on the drawing or above it:
|
|
7
|
+
*
|
|
8
|
+
* - `--diagram-line` strokes and text (default: currentColor)
|
|
9
|
+
* - `--diagram-soft` names, components and reference lines
|
|
10
|
+
* - `--diagram-fill` a shape's inside (default: Canvas)
|
|
11
|
+
* - `--diagram-paper` what the drawing is on, behind a line's name
|
|
12
|
+
* (default: Canvas)
|
|
13
|
+
* - `--diagram-glow` the pen, the stroke it draws, a done mark and a shape
|
|
14
|
+
* in focus
|
|
15
|
+
* - `--diagram-font` the text's font family
|
|
16
|
+
* - `--diagram-pen` how long one stroke takes without ink() (default 0.5s)
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { css } from '@yaks/diagram'
|
|
20
|
+
* import { assert } from '@std/assert'
|
|
21
|
+
*
|
|
22
|
+
* assert(css.includes('.Diagram_Node'))
|
|
23
|
+
* ```
|
|
24
|
+
*/ export declare const css: "\n.Diagram {\n --_line: var(--diagram-line, currentColor);\n --_soft: var(--diagram-soft, color-mix(in srgb, var(--_line) 60%, transparent));\n --_paper: var(--diagram-paper, Canvas);\n --_glow: var(--diagram-glow, var(--_line));\n --_pen: var(--diagram-pen, .5s);\n display: block;\n width: 100%;\n height: auto;\n overflow: visible;\n font-family: var(--diagram-font, ui-monospace, monospace);\n}\n.Diagram_Fill { fill: var(--diagram-fill, Canvas); }\n.Diagram_Stroke, .Diagram_Line {\n fill: none;\n stroke: var(--_line);\n stroke-width: 1.15;\n stroke-linejoin: round;\n stroke-dasharray: 1 1;\n stroke-dashoffset: 0;\n}\n.Diagram_Line { stroke-width: 1.4; }\n.Diagram_Link-ref .Diagram_Line { stroke: var(--_soft); stroke-width: .9; opacity: .8; }\n.Diagram_Head { fill: var(--_line); }\n.Diagram_Head-ref { fill: var(--_soft); }\n.Diagram_Dia { fill: var(--_paper); stroke: var(--_line); stroke-width: 1.1; }\n.Diagram .Diagram_Text { fill: var(--_line); font-size: 10.5px; }\n.Diagram_Id { font-weight: 500; }\n.Diagram_Node-round .Diagram_Id, .Diagram_Node-hex .Diagram_Id { font-size: 11px; }\n.Diagram_Title { font-size: 12.5px; }\n.Diagram_Comps, .Diagram_State { fill: var(--_soft); font-size: 9px; }\n.Diagram_Name, .Diagram_Sub {\n fill: var(--_soft);\n font-size: 8.5px;\n paint-order: stroke;\n stroke: var(--_paper);\n stroke-width: 3px;\n stroke-linejoin: round;\n}\n.Diagram_Link-edge .Diagram_Name { fill: var(--_line); font-size: 10px; }\n.Diagram_Mark { fill: var(--_paper); stroke: var(--_line); stroke-width: 1; }\n.is-done .Diagram_Mark { fill: var(--_glow); stroke: var(--_glow); }\n.Diagram_Node { cursor: pointer; outline: none; }\n.Diagram_Node:hover .Diagram_Stroke, .Diagram_Node:focus-visible .Diagram_Stroke {\n stroke: var(--_glow);\n stroke-width: 1.6;\n}\n.Diagram_Pen { pointer-events: none; transition: opacity .3s; }\n.Diagram_Halo { fill: color-mix(in srgb, var(--_glow) 25%, transparent); stroke: var(--_glow); stroke-width: .8; }\n.Diagram_Hair { stroke: var(--_glow); stroke-width: .8; }\n.Diagram_Tip { fill: var(--_glow); }\n\n.Diagram:not(.is-inked) .is-new .Diagram_Stroke,\n.Diagram:not(.is-inked) .is-new .Diagram_Line {\n animation: diagram-pen var(--_pen) ease-out calc(var(--i, 0) * var(--_pen) * .6) backwards;\n}\n.Diagram:not(.is-inked) .is-new .Diagram_Text {\n animation: diagram-ink var(--_pen) ease-out calc((var(--i, 0) * .6 + .7) * var(--_pen)) backwards;\n}\n@keyframes diagram-pen {\n from { stroke-dashoffset: 1; stroke: var(--_glow); }\n 70% { stroke: var(--_glow); }\n}\n@keyframes diagram-ink { from { opacity: 0; } }\n\n.is-inked .is-gone { display: none; }\n.is-inked .Diagram_Fill, .is-inked .Diagram_Text, .is-inked .Diagram_Dia, .is-inked .Diagram_Mark {\n transition: opacity .35s;\n}\n.is-inked :not(.is-drawn) > .Diagram_Fill,\n.is-inked :not(.is-drawn) > .Diagram_Text,\n.is-inked :not(.is-drawn) > .Diagram_Dia,\n.is-inked :not(.is-drawn) > .Diagram_Mark { opacity: 0; }\n.is-inked :not(.is-drawn) > .Diagram_Line { marker-end: none; }\n.is-inked .is-drawing > .Diagram_Stroke, .is-inked .is-drawing > .Diagram_Line {\n stroke: var(--_glow);\n stroke-width: 1.6;\n}\n.is-zoomed > .Diagram { cursor: grab; }\n.is-zoomed > .Diagram:active { cursor: grabbing; }\n@media (prefers-reduced-motion: reduce) {\n .is-new .Diagram_Stroke, .is-new .Diagram_Line, .is-new .Diagram_Text { animation: none; }\n .is-inked .Diagram_Fill, .is-inked .Diagram_Text { transition: none; }\n}\n";
|
|
25
|
+
//# sourceMappingURL=styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sources":["../styles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,cAAM,k6GAqFZ"}
|
package/_dist/svg.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Layout } from "./layout.js";
|
|
2
|
+
import { type View } from "./view.js";
|
|
3
|
+
/** How a layout is drawn. */ export type SvgOptions = {
|
|
4
|
+
/** The svg's class (default `Diagram`). */ class?: string;
|
|
5
|
+
/** An accessible name for the drawing. */ title?: string;
|
|
6
|
+
/** The part of the sheet in view (default all of it). */ view?: View;
|
|
7
|
+
/** Draw what moved to make room where it is now, without gliding there
|
|
8
|
+
* from where it was (as under prefers-reduced-motion). */ still?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Draw a layout as one `<svg>` element: lines under boxes, each box a group
|
|
12
|
+
* with its id, title and components, each line named.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { layout, svg } from '@yaks/diagram'
|
|
16
|
+
* import { assert } from '@std/assert'
|
|
17
|
+
*
|
|
18
|
+
* let drawn = svg(layout([{ entity: { eid: '0a' }, doc: { title: 'Dune' } }]))
|
|
19
|
+
* assert(drawn.includes('>Dune</text>'))
|
|
20
|
+
* ```
|
|
21
|
+
*/ export declare let svg: (layout: Layout, opts?: SvgOptions) => string;
|
|
22
|
+
//# sourceMappingURL=svg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.d.ts","sources":["../svg.ts"],"names":[],"mappings":"AAKA,SAAc,KAAK,MAAM,sBAA2C;AAEpE,SAAS,KAAK,IAAI,oBAA0B;AAG5C,2BAA2B,GAC3B,YAAY;EACV,yCAAyC,GACzC,QAAQ,MAAM;EACd,wCAAwC,GACxC,QAAQ,MAAM;EACd,uDAAuD,GACvD,OAAO;EACP;0DACwD,GACxD,QAAQ,OAAO;;AAkIjB;;;;;;;;;;;CAWC,GACD,OAAO,YAAI,MAAO,QAAQ,QAAQ,OAAM,eAAkB,MAAM,CA8B/D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Layout } from "./layout.js";
|
|
2
|
+
/**
|
|
3
|
+
* Everything tangled in a layout: shapes closer than `APART`, a line through a
|
|
4
|
+
* shape that is not one of its ends, lines that cross, lines that run within
|
|
5
|
+
* a few units of each other, and a line's name on a shape or on another
|
|
6
|
+
* name. Each is said with the short ids it involves.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { layout, tangles } from '@yaks/diagram'
|
|
10
|
+
* import { equal } from '@yaks/testing'
|
|
11
|
+
*
|
|
12
|
+
* let a = { entity: { eid: '0a' }, doc: { title: 'Dune' } }
|
|
13
|
+
* let b = { entity: { eid: '0b' }, review: { of: '0a' } }
|
|
14
|
+
* equal(tangles(layout([a, b])), [])
|
|
15
|
+
* ```
|
|
16
|
+
*/ export declare let tangles: (layout: Layout) => string[];
|
|
17
|
+
/** A tangle, said as {@link tangles} says it, and the shapes and lines it
|
|
18
|
+
* involves, by their keys: a node's eid, a link's key. */ export type Knot = {
|
|
19
|
+
said: string;
|
|
20
|
+
keys: string[];
|
|
21
|
+
};
|
|
22
|
+
/** Everything tangled in a layout, as {@link tangles} finds it, with what
|
|
23
|
+
* each involves; with `only`, just the tangles that involve one of those
|
|
24
|
+
* keys. */ export declare let knots: (layout: Layout, only?: ReadonlySet<string>) => Knot[];
|
|
25
|
+
//# sourceMappingURL=tangle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tangle.d.ts","sources":["../tangle.ts"],"names":[],"mappings":"AAIA,cAAc,MAAM,sBAAqB;AAczC;;;;;;;;;;;;;;CAcC,GACD,OAAO,YAAI,UAAW,QAAQ,WAAS,MAAM,GACX;AAElC;wDACwD,GACxD,YAAY;EAAS,MAAM,MAAM;EAAE,MAAM,MAAM;;AAE/C;;SAES,GACT,OAAO,YAAI,QAAS,QAAQ,QAAQ,OAAO,YAAY,MAAM,MAAI,OA6GhE"}
|
package/_dist/view.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Layout } from "./layout.js";
|
|
2
|
+
/** The part of the sheet in view: `[x, y, width, height]`, in its units. */ export type View = [number, number, number, number];
|
|
3
|
+
/** The whole sheet. */ export declare let whole: ({}: Layout) => View;
|
|
4
|
+
/**
|
|
5
|
+
* Zoom by `k` (above 1 closer, below 1 farther) about a point given as
|
|
6
|
+
* fractions of the view, which stays where it is.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { layout, whole, zoom } from '@yaks/diagram'
|
|
10
|
+
* import { equal } from '@yaks/testing'
|
|
11
|
+
*
|
|
12
|
+
* let sheet = layout([], { width: 600, height: 400 })
|
|
13
|
+
* equal(zoom(sheet, whole(sheet), 2, [.5, .5]), [150, 100, 300, 200])
|
|
14
|
+
* equal(zoom(sheet, whole(sheet), .5, [.5, .5]), [0, 0, 600, 400])
|
|
15
|
+
* ```
|
|
16
|
+
*/ export declare let zoom: (layout: Layout, []: View, k: number, []: [number, number]) => View;
|
|
17
|
+
/** Move the view by dx, dy in the sheet's units. */ export declare let pan: (layout: Layout, []: View, dx: number, dy: number) => View;
|
|
18
|
+
/** Whether the view shows less than the whole sheet. */ export declare let zoomed: (layout: Layout, []: View) => boolean;
|
|
19
|
+
/** Where a point of the sheet is, as fractions of the view. */ export declare let within: ([]: View, []: [number, number]) => [number, number];
|
|
20
|
+
//# sourceMappingURL=view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.d.ts","sources":["../view.ts"],"names":[],"mappings":"AAGA,cAAc,MAAM,sBAAqB;AAEzC,0EAA0E,GAC1E,YAAY,QAAQ,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;AAKlD,qBAAqB,GACrB,OAAO,YAAI,QAAS,IAAmB,MAAM,KAAG,KAA6B;AAa7E;;;;;;;;;;;;CAYC,GACD,OAAO,YAAI,OACT,QAAQ,QACR,IAAc,IAAI,EAClB,GAAG,MAAM,EACT,KAAW,MAAM,EAAE,MAAM,CAAC,KACzB,KAGF;AAED,kDAAkD,GAClD,OAAO,YAAI,MACT,QAAQ,QACR,IAAc,IAAI,EAClB,IAAI,MAAM,EACV,IAAI,MAAM,KACT,KAA4C;AAE/C,sDAAsD,GACtD,OAAO,YAAI,SAAU,QAAQ,QAAQ,IAAS,IAAI,KAAG,OAAO,CACrC;AAEvB,6DAA6D,GAC7D,OAAO,YAAI,SACT,IAAc,IAAI,EAClB,KAAW,MAAM,EAAE,MAAM,CAAC,MACxB,MAAM,EAAE,MAAM,EAAiC"}
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"publish":{"exclude":["**/*_test.ts"]},"name":"@yaks/diagram","version":"0.2.36","license":"Apache-2.0","description":"Draws the entities a query selects, and the references between them, as SVG: a pure layout that keeps each entity's place as the graph changes, the markup, and a mount that follows a graph.","exports":{".":"./mod.ts"},"imports":{"@yaks/diagram":"./mod.ts"}}
|
package/geometry.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Where segments and boxes meet, for placing shapes and finding tangles.
|
|
2
|
+
// Pure.
|
|
3
|
+
/** A point. */ // Whether the segment a–b meets the box of half size w, h centred at c: the
|
|
4
|
+
// segment clipped to the box's slabs leaves something.
|
|
5
|
+
export let meets = ([ax, ay], [bx, by], [cx, cy], w, h)=>{
|
|
6
|
+
let lo = 0, hi = 1;
|
|
7
|
+
let slabs = [
|
|
8
|
+
[
|
|
9
|
+
ax,
|
|
10
|
+
bx - ax,
|
|
11
|
+
cx - w,
|
|
12
|
+
cx + w
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
ay,
|
|
16
|
+
by - ay,
|
|
17
|
+
cy - h,
|
|
18
|
+
cy + h
|
|
19
|
+
]
|
|
20
|
+
];
|
|
21
|
+
for (let [p, d, min, max] of slabs){
|
|
22
|
+
if (!d) {
|
|
23
|
+
if (p <= min || p >= max) return false;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
let t0 = (min - p) / d, t1 = (max - p) / d;
|
|
27
|
+
lo = Math.max(lo, Math.min(t0, t1));
|
|
28
|
+
hi = Math.min(hi, Math.max(t0, t1));
|
|
29
|
+
if (lo >= hi) return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
33
|
+
// Whether segments a–b and c–d cross: at a point inside both, or at the start
|
|
34
|
+
// of either, so a crossing where two paths' stretches meet counts once.
|
|
35
|
+
export let cross = ([ax, ay], [bx, by], [cx, cy], [dx, dy])=>{
|
|
36
|
+
let d = (bx - ax) * (dy - cy) - (by - ay) * (dx - cx);
|
|
37
|
+
if (!d) return false;
|
|
38
|
+
let t = ((cx - ax) * (dy - cy) - (cy - ay) * (dx - cx)) / d;
|
|
39
|
+
let u = ((cx - ax) * (by - ay) - (cy - ay) * (bx - ax)) / d;
|
|
40
|
+
return t >= 0 && t < 1 && u >= 0 && u < 1;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=geometry.js.map
|
package/geometry.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.js","sources":["./geometry.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,QAAQ;AAER,aAAa,GAGb,4EAA4E;AAC5E,uDAAuD;AACvD,OAAO,IAAI,QAAQ,CACjB,CAAC,IAAI,GAAS,EACd,CAAC,IAAI,GAAS,EACd,CAAC,IAAI,GAAS,EACd,GACA;EAEA,IAAI,KAAK,GAAG,KAAK;EACjB,IAAI,QAAQ;IAAC;MAAC;MAAI,KAAK;MAAI,KAAK;MAAG,KAAK;KAAE;IAAE;MAAC;MAAI,KAAK;MAAI,KAAK;MAAG,KAAK;KAAE;GAAC;EAC1E,KAAK,IAAI,CAAC,GAAG,GAAG,KAAK,IAAI,IAAI,MAAO;IAClC,IAAI,CAAC,GAAG;MACN,IAAI,KAAK,OAAO,KAAK,KAAK,OAAO;MACjC;IACF;IACA,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI;IACzC,KAAK,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI;IAC/B,KAAK,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI;IAC/B,IAAI,MAAM,IAAI,OAAO;EACvB;EACA,OAAO;AACT,EAAC;AAED,8EAA8E;AAC9E,wEAAwE;AACxE,OAAO,IAAI,QAAQ,CACjB,CAAC,IAAI,GAAS,EACd,CAAC,IAAI,GAAS,EACd,CAAC,IAAI,GAAS,EACd,CAAC,IAAI,GAAS;EAEd,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE;EACpD,IAAI,CAAC,GAAG,OAAO;EACf,IAAI,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI;EAC1D,IAAI,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI;EAC1D,OAAO,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK,IAAI;AAC1C,EAAC"}
|
package/geometry.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Where segments and boxes meet, for placing shapes and finding tangles.
|
|
2
|
+
// Pure.
|
|
3
|
+
|
|
4
|
+
/** A point. */
|
|
5
|
+
export type Spot = [number, number]
|
|
6
|
+
|
|
7
|
+
// Whether the segment a–b meets the box of half size w, h centred at c: the
|
|
8
|
+
// segment clipped to the box's slabs leaves something.
|
|
9
|
+
export let meets = (
|
|
10
|
+
[ax, ay]: Spot,
|
|
11
|
+
[bx, by]: Spot,
|
|
12
|
+
[cx, cy]: Spot,
|
|
13
|
+
w: number,
|
|
14
|
+
h: number,
|
|
15
|
+
) => {
|
|
16
|
+
let lo = 0, hi = 1
|
|
17
|
+
let slabs = [[ax, bx - ax, cx - w, cx + w], [ay, by - ay, cy - h, cy + h]]
|
|
18
|
+
for (let [p, d, min, max] of slabs) {
|
|
19
|
+
if (!d) {
|
|
20
|
+
if (p <= min || p >= max) return false
|
|
21
|
+
continue
|
|
22
|
+
}
|
|
23
|
+
let t0 = (min - p) / d, t1 = (max - p) / d
|
|
24
|
+
lo = Math.max(lo, Math.min(t0, t1))
|
|
25
|
+
hi = Math.min(hi, Math.max(t0, t1))
|
|
26
|
+
if (lo >= hi) return false
|
|
27
|
+
}
|
|
28
|
+
return true
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Whether segments a–b and c–d cross: at a point inside both, or at the start
|
|
32
|
+
// of either, so a crossing where two paths' stretches meet counts once.
|
|
33
|
+
export let cross = (
|
|
34
|
+
[ax, ay]: Spot,
|
|
35
|
+
[bx, by]: Spot,
|
|
36
|
+
[cx, cy]: Spot,
|
|
37
|
+
[dx, dy]: Spot,
|
|
38
|
+
) => {
|
|
39
|
+
let d = (bx - ax) * (dy - cy) - (by - ay) * (dx - cx)
|
|
40
|
+
if (!d) return false
|
|
41
|
+
let t = ((cx - ax) * (dy - cy) - (cy - ay) * (dx - cx)) / d
|
|
42
|
+
let u = ((cx - ax) * (by - ay) - (cy - ay) * (bx - ax)) / d
|
|
43
|
+
return t >= 0 && t < 1 && u >= 0 && u < 1
|
|
44
|
+
}
|
package/ink.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// A pen's progress put on a drawing in a page: each item drawn as far as it
|
|
2
|
+
// has come, hidden before it starts and finished once it is drawn, and the
|
|
3
|
+
// pen where the latest stroke is. The one place the diagram touches a
|
|
4
|
+
// document.
|
|
5
|
+
import { tip } from "./pen.js";
|
|
6
|
+
/**
|
|
7
|
+
* Draw each item of `svg` (a drawing of `layout`) as far as `drawn` says,
|
|
8
|
+
* by its `data-key`, and put the pen at the tip. An item `drawn` leaves out is
|
|
9
|
+
* drawn whole. Returns the tip, if a stroke is part drawn.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { ink, layout, progress, svg } from '@yaks/diagram'
|
|
13
|
+
* import { parseHTML } from 'linkedom'
|
|
14
|
+
* import { equal } from '@yaks/testing'
|
|
15
|
+
*
|
|
16
|
+
* let drawn = layout([{ entity: { eid: '0a' }, doc: { title: 'Dune' } }])
|
|
17
|
+
* let { document } = parseHTML(`<div>${svg(drawn)}</div>`)
|
|
18
|
+
* let sheet = document.querySelector('svg')!
|
|
19
|
+
* equal(ink(sheet as never, drawn, progress(drawn, () => .5))?.key, '0a')
|
|
20
|
+
* equal(sheet.querySelector('[data-key="0a"]')!.classList.contains('is-drawing'), true)
|
|
21
|
+
* ```
|
|
22
|
+
*/ export let ink = (svg, layout, drawn)=>{
|
|
23
|
+
svg.classList.add('is-inked');
|
|
24
|
+
for (let g of svg.querySelectorAll('[data-key]')){
|
|
25
|
+
let t = drawn.get(g.getAttribute('data-key') ?? '') ?? 1;
|
|
26
|
+
g.classList.toggle('is-gone', t <= 0);
|
|
27
|
+
g.classList.toggle('is-drawing', t > 0 && t < 1);
|
|
28
|
+
g.classList.toggle('is-drawn', t >= 1);
|
|
29
|
+
for (let s of g.querySelectorAll('.Diagram_Stroke, .Diagram_Line')){
|
|
30
|
+
s.setAttribute('style', `stroke-dashoffset:${+(1 - t).toFixed(4)}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let at = tip(layout, drawn);
|
|
34
|
+
let pen = svg.querySelector('.Diagram_Pen');
|
|
35
|
+
if (pen) {
|
|
36
|
+
pen.setAttribute('opacity', at ? '1' : '0');
|
|
37
|
+
if (at) {
|
|
38
|
+
pen.setAttribute('transform', `translate(${at.x.toFixed(1)} ${at.y.toFixed(1)})`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return at;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=ink.js.map
|
package/ink.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ink.js","sources":["./ink.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,2EAA2E;AAC3E,sEAAsE;AACtE,YAAY;AAEZ,SAAmB,GAAG,mBAAkB;AAWxC;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,IAAI,MAAM,CACf,KACA,QACA;EAEA,IAAI,SAAS,CAAC,GAAG,CAAC;EAClB,KAAK,IAAI,KAAK,IAAI,gBAAgB,CAAC,cAAe;IAChD,IAAI,IAAI,MAAM,GAAG,CAAC,EAAE,YAAY,CAAC,eAAe,OAAO;IACvD,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,KAAK;IACnC,EAAE,SAAS,CAAC,MAAM,CAAC,cAAc,IAAI,KAAK,IAAI;IAC9C,EAAE,SAAS,CAAC,MAAM,CAAC,YAAY,KAAK;IACpC,KAAK,IAAI,KAAK,EAAE,gBAAgB,CAAC,kCAAmC;MAClE,EAAE,YAAY,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI;IACpE;EACF;EACA,IAAI,KAAK,IAAI,QAAQ;EACrB,IAAI,MAAM,IAAI,aAAa,CAAC;EAC5B,IAAI,KAAK;IACP,IAAI,YAAY,CAAC,WAAW,KAAK,MAAM;IACvC,IAAI,IAAI;MACN,IAAI,YAAY,CACd,aACA,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAEtD;EACF;EACA,OAAO;AACT,EAAC"}
|
package/ink.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// A pen's progress put on a drawing in a page: each item drawn as far as it
|
|
2
|
+
// has come, hidden before it starts and finished once it is drawn, and the
|
|
3
|
+
// pen where the latest stroke is. The one place the diagram touches a
|
|
4
|
+
// document.
|
|
5
|
+
import type { Layout } from './layout.ts'
|
|
6
|
+
import { type Tip, tip } from './pen.js'
|
|
7
|
+
|
|
8
|
+
/** The part of a DOM element ink() uses. */
|
|
9
|
+
export type Inked = {
|
|
10
|
+
querySelectorAll(selector: string): Iterable<Inked>
|
|
11
|
+
querySelector(selector: string): Inked | null
|
|
12
|
+
getAttribute(name: string): string | null
|
|
13
|
+
setAttribute(name: string, value: string): void
|
|
14
|
+
classList: { add(c: string): void; toggle(c: string, on: boolean): void }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Draw each item of `svg` (a drawing of `layout`) as far as `drawn` says,
|
|
19
|
+
* by its `data-key`, and put the pen at the tip. An item `drawn` leaves out is
|
|
20
|
+
* drawn whole. Returns the tip, if a stroke is part drawn.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { ink, layout, progress, svg } from '@yaks/diagram'
|
|
24
|
+
* import { parseHTML } from 'linkedom'
|
|
25
|
+
* import { equal } from '@yaks/testing'
|
|
26
|
+
*
|
|
27
|
+
* let drawn = layout([{ entity: { eid: '0a' }, doc: { title: 'Dune' } }])
|
|
28
|
+
* let { document } = parseHTML(`<div>${svg(drawn)}</div>`)
|
|
29
|
+
* let sheet = document.querySelector('svg')!
|
|
30
|
+
* equal(ink(sheet as never, drawn, progress(drawn, () => .5))?.key, '0a')
|
|
31
|
+
* equal(sheet.querySelector('[data-key="0a"]')!.classList.contains('is-drawing'), true)
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export let ink = (
|
|
35
|
+
svg: Inked,
|
|
36
|
+
layout: Layout,
|
|
37
|
+
drawn: Map<string, number>,
|
|
38
|
+
): Tip | undefined => {
|
|
39
|
+
svg.classList.add('is-inked')
|
|
40
|
+
for (let g of svg.querySelectorAll('[data-key]')) {
|
|
41
|
+
let t = drawn.get(g.getAttribute('data-key') ?? '') ?? 1
|
|
42
|
+
g.classList.toggle('is-gone', t <= 0)
|
|
43
|
+
g.classList.toggle('is-drawing', t > 0 && t < 1)
|
|
44
|
+
g.classList.toggle('is-drawn', t >= 1)
|
|
45
|
+
for (let s of g.querySelectorAll('.Diagram_Stroke, .Diagram_Line')) {
|
|
46
|
+
s.setAttribute('style', `stroke-dashoffset:${+(1 - t).toFixed(4)}`)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
let at = tip(layout, drawn)
|
|
50
|
+
let pen = svg.querySelector('.Diagram_Pen')
|
|
51
|
+
if (pen) {
|
|
52
|
+
pen.setAttribute('opacity', at ? '1' : '0')
|
|
53
|
+
if (at) {
|
|
54
|
+
pen.setAttribute(
|
|
55
|
+
'transform',
|
|
56
|
+
`translate(${at.x.toFixed(1)} ${at.y.toFixed(1)})`,
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return at
|
|
61
|
+
}
|