@g9tm/lynxcontrols-graph 0.0.0-stage → 2.10.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/dist/core.jsx ADDED
@@ -0,0 +1,323 @@
1
+ const G9_GRAPH_IDENTITY = Object.freeze({
2
+ zoom: 1,
3
+ x: 0,
4
+ y: 0
5
+ });
6
+ function clampZoom(zoom, min, max) {
7
+ if (!Number.isFinite(zoom)) return 1;
8
+ return Math.min(max, Math.max(min, zoom));
9
+ }
10
+ function toWorld(view, sx, sy) {
11
+ return {
12
+ x: (sx - view.x) / view.zoom,
13
+ y: (sy - view.y) / view.zoom
14
+ };
15
+ }
16
+ function toScreen(view, wx, wy) {
17
+ return {
18
+ x: wx * view.zoom + view.x,
19
+ y: wy * view.zoom + view.y
20
+ };
21
+ }
22
+ function zoomAt(view, factor, sx, sy, min, max) {
23
+ const zoom = clampZoom(view.zoom * factor, min, max);
24
+ const k = zoom / view.zoom;
25
+ return {
26
+ zoom,
27
+ x: sx - (sx - view.x) * k,
28
+ y: sy - (sy - view.y) * k
29
+ };
30
+ }
31
+ function panBy(view, dx, dy) {
32
+ return {
33
+ zoom: view.zoom,
34
+ x: view.x + dx,
35
+ y: view.y + dy
36
+ };
37
+ }
38
+ function contentBounds(nodes, groups = []) {
39
+ let x0 = 1 / 0;
40
+ let y0 = 1 / 0;
41
+ let x1 = -1 / 0;
42
+ let y1 = -1 / 0;
43
+ for (const r of nodes.concat(groups)){
44
+ x0 = Math.min(x0, r.x);
45
+ y0 = Math.min(y0, r.y);
46
+ x1 = Math.max(x1, r.x + r.width);
47
+ y1 = Math.max(y1, r.y + r.height);
48
+ }
49
+ return Number.isFinite(x0) ? {
50
+ x: x0,
51
+ y: y0,
52
+ width: x1 - x0,
53
+ height: y1 - y0
54
+ } : null;
55
+ }
56
+ function fitView(bounds, width, height, options = {}) {
57
+ var _options_padding, _options_minZoom, _options_maxZoom;
58
+ if (!bounds || width <= 0 || height <= 0) return G9_GRAPH_IDENTITY;
59
+ const pad = null != (_options_padding = options.padding) ? _options_padding : 32;
60
+ const zx = (width - 2 * pad) / Math.max(1, bounds.width);
61
+ const zy = (height - 2 * pad) / Math.max(1, bounds.height);
62
+ const zoom = clampZoom(Math.min(zx, zy), null != (_options_minZoom = options.minZoom) ? _options_minZoom : 0.1, null != (_options_maxZoom = options.maxZoom) ? _options_maxZoom : 1);
63
+ return {
64
+ zoom,
65
+ x: (width - bounds.width * zoom) / 2 - bounds.x * zoom,
66
+ y: (height - bounds.height * zoom) / 2 - bounds.y * zoom
67
+ };
68
+ }
69
+ function visibleWorld(view, width, height, margin = 0.5) {
70
+ const tl = toWorld(view, -width * margin, -height * margin);
71
+ return {
72
+ x: tl.x + 0,
73
+ y: tl.y + 0,
74
+ width: width * (1 + 2 * margin) / view.zoom,
75
+ height: height * (1 + 2 * margin) / view.zoom
76
+ };
77
+ }
78
+ function intersects(a, b) {
79
+ return a.x <= b.x + b.width && b.x <= a.x + a.width && a.y <= b.y + b.height && b.y <= a.y + a.height;
80
+ }
81
+ function portPoint(node, end, role) {
82
+ var _node_ports, _ref;
83
+ const ports = null != (_node_ports = node.ports) ? _node_ports : [];
84
+ const port = (null == end ? void 0 : end.port) !== void 0 ? ports.find((p)=>p.id === end.port) : void 0;
85
+ const side = null != (_ref = null == port ? void 0 : port.side) ? _ref : 'from' === role ? 'right' : 'left';
86
+ let offset = null == port ? void 0 : port.offset;
87
+ if (port && void 0 === offset) {
88
+ const same = ports.filter((p)=>p.side === side);
89
+ offset = (same.indexOf(port) + 1) / (same.length + 1);
90
+ }
91
+ return {
92
+ x: 'right' === side ? node.x + node.width : node.x,
93
+ y: node.y + node.height * (null != offset ? offset : 0.5)
94
+ };
95
+ }
96
+ function edgeCurve(a, b, aSide = 'right', bSide = 'left', curvature = 0.5) {
97
+ const d = Math.max(40, Math.abs(b.x - a.x) * curvature);
98
+ return {
99
+ c1: {
100
+ x: a.x + ('right' === aSide ? d : -d),
101
+ y: a.y
102
+ },
103
+ c2: {
104
+ x: b.x + ('left' === bSide ? -d : d),
105
+ y: b.y
106
+ }
107
+ };
108
+ }
109
+ const r1 = (v)=>Math.round(10 * v) / 10;
110
+ function edgePathData(a, b, c1, c2) {
111
+ return `M${r1(a.x)} ${r1(a.y)}C${r1(c1.x)} ${r1(c1.y)} ${r1(c2.x)} ${r1(c2.y)} ${r1(b.x)} ${r1(b.y)}`;
112
+ }
113
+ function bezierPoint(a, c1, c2, b, t) {
114
+ const u = 1 - t;
115
+ const w0 = u * u * u;
116
+ const w1 = 3 * u * u * t;
117
+ const w2 = 3 * u * t * t;
118
+ const w3 = t * t * t;
119
+ return {
120
+ x: w0 * a.x + w1 * c1.x + w2 * c2.x + w3 * b.x,
121
+ y: w0 * a.y + w1 * c1.y + w2 * c2.y + w3 * b.y
122
+ };
123
+ }
124
+ function edgeGeometry(edge, byId, curvature = 0.5) {
125
+ const na = byId.get(edge.from.node);
126
+ const nb = byId.get(edge.to.node);
127
+ if (!na || !nb) return null;
128
+ const a = portPoint(na, edge.from, 'from');
129
+ const b = portPoint(nb, edge.to, 'to');
130
+ const sideOf = (n, end, role)=>{
131
+ var _ref;
132
+ var _n_ports_find, _n_ports;
133
+ return null != (_ref = null == (_n_ports = n.ports) ? void 0 : null == (_n_ports_find = _n_ports.find((p)=>p.id === end.port)) ? void 0 : _n_ports_find.side) ? _ref : 'from' === role ? 'right' : 'left';
134
+ };
135
+ const { c1, c2 } = edgeCurve(a, b, sideOf(na, edge.from, 'from'), sideOf(nb, edge.to, 'to'), curvature);
136
+ const xs = [
137
+ a.x,
138
+ b.x,
139
+ c1.x,
140
+ c2.x
141
+ ];
142
+ const ys = [
143
+ a.y,
144
+ b.y,
145
+ c1.y,
146
+ c2.y
147
+ ];
148
+ const x0 = Math.min(...xs);
149
+ const y0 = Math.min(...ys);
150
+ return {
151
+ id: edge.id,
152
+ d: edgePathData(a, b, c1, c2),
153
+ mid: bezierPoint(a, c1, c2, b, 0.5),
154
+ box: {
155
+ x: x0,
156
+ y: y0,
157
+ width: Math.max(...xs) - x0,
158
+ height: Math.max(...ys) - y0
159
+ }
160
+ };
161
+ }
162
+ function cullGraph(nodes, edges, visible) {
163
+ const n = new Set();
164
+ for (const node of nodes)if (intersects(node, visible)) n.add(node.id);
165
+ const e = new Set();
166
+ for (const edge of edges)if (intersects(edge.box, visible)) e.add(edge.id);
167
+ return {
168
+ nodes: n,
169
+ edges: e
170
+ };
171
+ }
172
+ function snapTo(v, grid) {
173
+ return grid && grid > 0 ? Math.round(v / grid) * grid : v;
174
+ }
175
+ function nodeAt(nodes, wx, wy) {
176
+ for(let i = nodes.length - 1; i >= 0; i--){
177
+ const n = nodes[i];
178
+ if (wx >= n.x && wx <= n.x + n.width && wy >= n.y && wy <= n.y + n.height) return n;
179
+ }
180
+ return null;
181
+ }
182
+ function nextSelection(selection, id, additive) {
183
+ if (null === id) return additive ? selection.slice() : [];
184
+ if (!additive) return [
185
+ id
186
+ ];
187
+ return selection.includes(id) ? selection.filter((s)=>s !== id) : selection.concat(id);
188
+ }
189
+ function got(m, k) {
190
+ return m.get(k);
191
+ }
192
+ function nodeInDirection(nodes, from, dir) {
193
+ var _ref;
194
+ var _nodes_;
195
+ const start = from ? nodes.find((n)=>n.id === from) : void 0;
196
+ if (!start) return null != (_ref = null == (_nodes_ = nodes[0]) ? void 0 : _nodes_.id) ? _ref : null;
197
+ const cx = start.x + start.width / 2;
198
+ const cy = start.y + start.height / 2;
199
+ let best = null;
200
+ let score = 1 / 0;
201
+ for (const n of nodes){
202
+ if (n.id === start.id) continue;
203
+ const dx = n.x + n.width / 2 - cx;
204
+ const dy = n.y + n.height / 2 - cy;
205
+ const along = 'left' === dir ? -dx : 'right' === dir ? dx : 'up' === dir ? -dy : dy;
206
+ if (along <= 0) continue;
207
+ const side = 'left' === dir || 'right' === dir ? Math.abs(dy) : Math.abs(dx);
208
+ const s = along + 2 * side;
209
+ if (s < score) {
210
+ score = s;
211
+ best = n.id;
212
+ }
213
+ }
214
+ return best;
215
+ }
216
+ function layeredLayout(nodes, edges, options = {}) {
217
+ var _options_sweeps, _options_layerGap, _options_nodeGap, _ref, _ref1;
218
+ var _raw_get, _preds_get, _options_origin, _options_origin1;
219
+ const ids = nodes.map((n)=>n.id);
220
+ const known = new Set(ids);
221
+ const out = new Map();
222
+ for (const id of ids)out.set(id, []);
223
+ const state = new Map();
224
+ const raw = new Map();
225
+ for (const id of ids)raw.set(id, []);
226
+ for (const e of edges)if (known.has(e.from.node) && known.has(e.to.node) && e.from.node !== e.to.node) null == (_raw_get = raw.get(e.from.node)) || _raw_get.push(e.to.node);
227
+ const visit = (id)=>{
228
+ state.set(id, 1);
229
+ for (const t of got(raw, id)){
230
+ var _state_get;
231
+ var _out_get;
232
+ const s = null != (_state_get = state.get(t)) ? _state_get : 0;
233
+ if (1 !== s) {
234
+ null == (_out_get = out.get(id)) || _out_get.push(t);
235
+ if (0 === s) visit(t);
236
+ }
237
+ }
238
+ state.set(id, 2);
239
+ };
240
+ for (const id of ids)if (!state.get(id)) visit(id);
241
+ const indeg = new Map(ids.map((id)=>[
242
+ id,
243
+ 0
244
+ ]));
245
+ for (const ts of out.values())for (const t of ts)indeg.set(t, got(indeg, t) + 1);
246
+ const layer = new Map(ids.map((id)=>[
247
+ id,
248
+ 0
249
+ ]));
250
+ const queue = ids.filter((id)=>0 === indeg.get(id));
251
+ for(let i = 0; i < queue.length; i++){
252
+ const id = queue[i];
253
+ for (const t of got(out, id)){
254
+ layer.set(t, Math.max(got(layer, t), got(layer, id) + 1));
255
+ indeg.set(t, got(indeg, t) - 1);
256
+ if (0 === indeg.get(t)) queue.push(t);
257
+ }
258
+ }
259
+ const depth = Math.max(0, ...Array.from(layer.values()));
260
+ const layers = Array.from({
261
+ length: depth + 1
262
+ }, ()=>[]);
263
+ for (const id of ids)layers[got(layer, id)].push(id);
264
+ const preds = new Map(ids.map((id)=>[
265
+ id,
266
+ []
267
+ ]));
268
+ for (const [s, ts] of out)for (const t of ts)null == (_preds_get = preds.get(t)) || _preds_get.push(s);
269
+ const posOf = new Map();
270
+ const index = ()=>{
271
+ for (const l of layers)l.forEach((id, i)=>{
272
+ posOf.set(id, i);
273
+ });
274
+ };
275
+ index();
276
+ const sweeps = null != (_options_sweeps = options.sweeps) ? _options_sweeps : 4;
277
+ for(let s = 0; s < sweeps; s++){
278
+ const down = s % 2 === 0;
279
+ const order = down ? layers.slice(1) : layers.slice(0, -1).reverse();
280
+ for (const l of order){
281
+ const bary = new Map();
282
+ for (const id of l){
283
+ const ns = got(down ? preds : out, id);
284
+ bary.set(id, ns.length ? ns.reduce((a, n)=>a + got(posOf, n), 0) / ns.length : got(posOf, id));
285
+ }
286
+ l.sort((a, b)=>got(bary, a) - got(bary, b) || got(posOf, a) - got(posOf, b));
287
+ l.forEach((id, i)=>{
288
+ posOf.set(id, i);
289
+ });
290
+ }
291
+ }
292
+ const size = new Map(nodes.map((n)=>[
293
+ n.id,
294
+ n
295
+ ]));
296
+ const across = 'down' === options.direction;
297
+ const layerGap = null != (_options_layerGap = options.layerGap) ? _options_layerGap : 80;
298
+ const nodeGap = null != (_options_nodeGap = options.nodeGap) ? _options_nodeGap : 24;
299
+ const ox = null != (_ref = null == (_options_origin = options.origin) ? void 0 : _options_origin.x) ? _ref : 0;
300
+ const oy = null != (_ref1 = null == (_options_origin1 = options.origin) ? void 0 : _options_origin1.y) ? _ref1 : 0;
301
+ const extent = (l)=>l.reduce((a, id)=>a + (across ? got(size, id).width : got(size, id).height), 0) + nodeGap * Math.max(0, l.length - 1);
302
+ const widest = Math.max(0, ...layers.map(extent));
303
+ const result = new Map();
304
+ let along = 0;
305
+ for (const l of layers){
306
+ const thick = Math.max(0, ...l.map((id)=>across ? got(size, id).height : got(size, id).width));
307
+ let cross = (widest - extent(l)) / 2;
308
+ for (const id of l){
309
+ const n = size.get(id);
310
+ result.set(id, across ? {
311
+ x: ox + cross,
312
+ y: oy + along
313
+ } : {
314
+ x: ox + along,
315
+ y: oy + cross
316
+ });
317
+ cross += (across ? n.width : n.height) + nodeGap;
318
+ }
319
+ along += thick + layerGap;
320
+ }
321
+ return result;
322
+ }
323
+ export { G9_GRAPH_IDENTITY, bezierPoint, clampZoom, contentBounds, cullGraph, edgeCurve, edgeGeometry, edgePathData, fitView, intersects, layeredLayout, nextSelection, nodeAt, nodeInDirection, panBy, portPoint, snapTo, toScreen, toWorld, visibleWorld, zoomAt };
package/dist/graph.css ADDED
@@ -0,0 +1,142 @@
1
+ .g9-graph {
2
+ background-color: var(--g9-surface-container-low);
3
+ flex: 1 1 0;
4
+ display: flex;
5
+ position: relative;
6
+ overflow: hidden;
7
+ }
8
+
9
+ .g9-graph__world {
10
+ transform-origin: 0 0;
11
+ width: 1px;
12
+ height: 1px;
13
+ position: absolute;
14
+ top: 0;
15
+ left: 0;
16
+ overflow: visible;
17
+ }
18
+
19
+ .g9-graph__group {
20
+ border-style: solid;
21
+ border-width: 1px;
22
+ border-color: var(--g9-outline-variant);
23
+ background-color: var(--g9-surface-container);
24
+ border-radius: 16px;
25
+ flex-direction: column;
26
+ padding: 10px 14px;
27
+ display: flex;
28
+ position: absolute;
29
+ }
30
+
31
+ .g9-graph__group-title {
32
+ font-size: 13px;
33
+ font-family: var(--g9-font-text-600);
34
+ color: var(--g9-on-surface-variant);
35
+ font-weight: 600;
36
+ }
37
+
38
+ .g9-graph__edges {
39
+ pointer-events: none;
40
+ position: absolute;
41
+ }
42
+
43
+ .g9-graph__edges--live {
44
+ width: 0;
45
+ height: 0;
46
+ top: 0;
47
+ left: 0;
48
+ }
49
+
50
+ .g9-graph__edge-label {
51
+ background-color: var(--g9-surface);
52
+ border-style: solid;
53
+ border-width: 1px;
54
+ border-color: var(--g9-outline-variant);
55
+ border-radius: 999px;
56
+ padding: 2px 8px;
57
+ display: flex;
58
+ position: absolute;
59
+ transform: translate(-50%, -50%);
60
+ }
61
+
62
+ .g9-graph__edge-text {
63
+ font-size: 11px;
64
+ font-family: var(--g9-font-text);
65
+ color: var(--g9-on-surface-variant);
66
+ }
67
+
68
+ .g9-graph__node {
69
+ border: 2px solid #0000;
70
+ border-radius: 12px;
71
+ flex-direction: column;
72
+ display: flex;
73
+ position: absolute;
74
+ }
75
+
76
+ .g9-graph__node--selected {
77
+ border-color: var(--g9-primary);
78
+ }
79
+
80
+ .g9-graph__node--focused {
81
+ border-color: var(--g9-primary);
82
+ border-style: dashed;
83
+ }
84
+
85
+ .g9-graph__node--selfocus {
86
+ border-style: solid;
87
+ }
88
+
89
+ .g9-graph__node--dragging {
90
+ opacity: .92;
91
+ }
92
+
93
+ .g9-graph__node--candidate {
94
+ border-color: var(--g9-tertiary);
95
+ border-style: dashed;
96
+ }
97
+
98
+ .g9-graph__node--over {
99
+ border-color: var(--g9-tertiary);
100
+ background-color: var(--g9-tertiary-container);
101
+ border-style: solid;
102
+ }
103
+
104
+ .g9-graph__controls {
105
+ background-color: var(--g9-surface);
106
+ border-style: solid;
107
+ border-width: 1px;
108
+ border-color: var(--g9-outline-variant);
109
+ border-radius: 12px;
110
+ flex-direction: column;
111
+ display: flex;
112
+ position: absolute;
113
+ bottom: 12px;
114
+ }
115
+
116
+ .g9-graph__controls--ltr {
117
+ right: 12px;
118
+ }
119
+
120
+ .g9-graph__controls--rtl {
121
+ left: 12px;
122
+ }
123
+
124
+ .g9-graph__button {
125
+ justify-content: center;
126
+ align-items: center;
127
+ width: 36px;
128
+ height: 36px;
129
+ display: flex;
130
+ }
131
+
132
+ .g9-graph__button:active {
133
+ background-color: var(--g9-surface-container-high);
134
+ }
135
+
136
+ .g9-graph__icon {
137
+ width: 18px;
138
+ height: 18px;
139
+ }
140
+
141
+
142
+ /*# sourceMappingURL=graph.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["webpack://./src/graph.css"],"names":[],"mappings":"AAEA;EADE,iDAAiD;EACjD,WAAW;EACX,aAAa;EACb,kBAAkB;EAClB,gBAAgB;AAClB;;AAMA;EAHE,qBAAqB;EACrB,UAAU;EACV,WAAW;EACX,kBAAkB;EAClB,MAAM;EACN,OAAO;EACP,iBAAiB;AACnB;;AAMA;EAHE,mBAAmB;EACnB,iBAAiB;EACjB,uCAAuC;EACvC,6CAA6C;EAC7C,mBAAmB;EACnB,sBAAsB;EACtB,kBAAkB;EAClB,aAAa;EACb,kBAAkB;AACpB;;AAMA;EAHE,eAAe;EACf,oCAAoC;EACpC,mCAAmC;EACnC,gBAAgB;AAClB;;AAMA;EAHE,oBAAoB;EACpB,kBAAkB;AACpB;;AAMA;EAHE,QAAQ;EACR,SAAS;EACT,MAAM;EACN,OAAO;AACT;;AAMA;EAHE,mCAAmC;EACnC,mBAAmB;EACnB,iBAAiB;EACjB,uCAAuC;EACvC,oBAAoB;EACpB,gBAAgB;EAChB,aAAa;EACb,kBAAkB;EAClB,gCAAgC;AAClC;;AAMA;EAHE,eAAe;EACf,gCAAgC;EAChC,mCAAmC;AACrC;;AAMA;EAHE,uBAAuB;EACvB,mBAAmB;EACnB,sBAAsB;EACtB,aAAa;EACb,kBAAkB;AACpB;;AAQA;EALE,+BAA+B;AACjC;;AAQA;EALE,+BAA+B;EAC/B,oBAAoB;AACtB;;AAQA;EALE,mBAAmB;AACrB;;AAQA;EALE,YAAY;AACd;;AAQA;EALE,gCAAgC;EAChC,oBAAoB;AACtB;;AAQA;EALE,gCAAgC;EAChC,8CAA8C;EAC9C,mBAAmB;AACrB;;AAQA;EALE,mCAAmC;EACnC,mBAAmB;EACnB,iBAAiB;EACjB,uCAAuC;EACvC,mBAAmB;EACnB,sBAAsB;EACtB,aAAa;EACb,kBAAkB;EAClB,YAAY;AACd;;AAQA;EALE,WAAW;AACb;;AAQA;EALE,UAAU;AACZ;;AAQA;EALE,uBAAuB;EACvB,mBAAmB;EACnB,WAAW;EACX,YAAY;EACZ,aAAa;AACf;;AAQA;EALE,kDAAkD;AACpD;;AAQA;EALE,WAAW;EACX,YAAY;AACd","sourcesContent":["/* G9GraphCanvas (2.9.0): the canvas clips; the world is transformed from its top-left (main thread); groups, edges,\n labels and cards are placed in world units; the zoom buttons sit at the bottom end. */\n.g9-graph {\n display: flex;\n position: relative;\n overflow: hidden;\n flex-grow: 1;\n flex-shrink: 1;\n flex-basis: 0px;\n background-color: var(--g9-surface-container-low);\n}\n\n.g9-graph__world {\n position: absolute;\n left: 0px;\n top: 0px;\n width: 1px;\n height: 1px;\n transform-origin: 0px 0px;\n overflow: visible;\n}\n\n.g9-graph__group {\n position: absolute;\n display: flex;\n flex-direction: column;\n border-radius: 16px;\n border-width: 1px;\n border-style: solid;\n border-color: var(--g9-outline-variant);\n background-color: var(--g9-surface-container);\n padding: 10px 14px;\n}\n\n.g9-graph__group-title {\n font-size: 13px;\n font-family: var(--g9-font-text-600);\n font-weight: 600;\n color: var(--g9-on-surface-variant);\n}\n\n.g9-graph__edges {\n position: absolute;\n pointer-events: none;\n}\n\n.g9-graph__edges--live {\n left: 0px;\n top: 0px;\n width: 0px;\n height: 0px;\n}\n\n.g9-graph__edge-label {\n position: absolute;\n display: flex;\n transform: translate(-50%, -50%);\n padding: 2px 8px;\n border-radius: 999px;\n background-color: var(--g9-surface);\n border-width: 1px;\n border-style: solid;\n border-color: var(--g9-outline-variant);\n}\n\n.g9-graph__edge-text {\n font-size: 11px;\n font-family: var(--g9-font-text);\n color: var(--g9-on-surface-variant);\n}\n\n.g9-graph__node {\n position: absolute;\n display: flex;\n flex-direction: column;\n border-radius: 12px;\n border-width: 2px;\n border-style: solid;\n border-color: transparent;\n}\n\n.g9-graph__node--selected {\n border-color: var(--g9-primary);\n}\n\n.g9-graph__node--focused {\n border-color: var(--g9-primary);\n border-style: dashed;\n}\n\n.g9-graph__node--selfocus {\n border-style: solid;\n}\n\n.g9-graph__node--dragging {\n opacity: 0.92;\n}\n\n.g9-graph__node--candidate {\n border-color: var(--g9-tertiary);\n border-style: dashed;\n}\n\n.g9-graph__node--over {\n border-color: var(--g9-tertiary);\n border-style: solid;\n background-color: var(--g9-tertiary-container);\n}\n\n.g9-graph__controls {\n position: absolute;\n bottom: 12px;\n display: flex;\n flex-direction: column;\n border-radius: 12px;\n background-color: var(--g9-surface);\n border-width: 1px;\n border-style: solid;\n border-color: var(--g9-outline-variant);\n}\n\n.g9-graph__controls--ltr {\n right: 12px;\n}\n\n.g9-graph__controls--rtl {\n left: 12px;\n}\n\n.g9-graph__button {\n display: flex;\n width: 36px;\n height: 36px;\n align-items: center;\n justify-content: center;\n}\n\n.g9-graph__button:active {\n background-color: var(--g9-surface-container-high);\n}\n\n.g9-graph__icon {\n width: 18px;\n height: 18px;\n}\n"],"sourceRoot":""}
@@ -0,0 +1,3 @@
1
+ export { G9GraphCanvas, type G9GraphCanvasHandle, type G9GraphCanvasProps, type G9GraphContextMenuEvent, type G9GraphDropEvent, type G9GraphLabels, type G9GraphNodeState, type G9GraphTarget, } from './canvas.js';
2
+ export * from './core.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,aAAa,GACnB,MAAM,UAAU,CAAC;AAClB,cAAc,QAAQ,CAAC"}
package/dist/index.jsx ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./core.jsx";
2
+ export { G9GraphCanvas } from "./canvas.jsx";
package/dist/mt.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /** A node as the main thread keeps it: id, x, y, width, height, draggable (1/0). */
2
+ export type G9MtNode = [string, number, number, number, number, number];
3
+ /**
4
+ * An edge as the main thread keeps it: id, from node, from dx, from dy, from side (1 right / -1 left), to node, to dx,
5
+ * to dy, to side, the stroke (colour, width, dash: 0 solid / 1 dashed / 2 active). dx / dy: the port's offset from the
6
+ * node's top-left.
7
+ */
8
+ export type G9MtEdge = [string, string, number, number, number, string, number, number, number, string, number, number];
9
+ /** Rounds to the grid on the main thread (0: unchanged). */
10
+ export declare function snapMT(v: number, grid: number): number;
11
+ /** `zoomAt` on the main thread: [zoom, x, y]. */
12
+ export declare function zoomAtMT(zoom: number, x: number, y: number, factor: number, sx: number, sy: number, min: number, max: number): [number, number, number];
13
+ /** The topmost node under a world point on the main thread: its index, or -1. */
14
+ export declare function nodeIndexAtMT(nodes: G9MtNode[], wx: number, wy: number): number;
15
+ /** One edge's bezier path data on the main thread (as `edgeCurve` + `edgePathData`). */
16
+ export declare function edgePathMT(ax: number, ay: number, aSide: number, bx: number, by: number, bSide: number, curvature: number): string;
17
+ /**
18
+ * The live SVG of the edges that touch moving nodes, on the main thread: `moved` maps a node id to its [x, y] now; the
19
+ * other end stays where `nodes` has it. Answers the SVG and its world rect [x, y, width, height].
20
+ */
21
+ export declare function liveEdgesSvgMT(edges: G9MtEdge[], nodes: G9MtNode[], moved: Record<string, [number, number]>, curvature: number): [string, number, number, number, number];
22
+ /** The edge an event target names (an edge label's `data-g9edge`) on the main thread, or null. */
23
+ export declare function edgeOfTargetMT(target: {
24
+ getAttribute?: (name: string) => unknown;
25
+ } | null | undefined): string | null;
26
+ //# sourceMappingURL=mt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mt.d.ts","sourceRoot":"","sources":["../src/mt.ts"],"names":[],"mappings":"AAIA,oFAAoF;AACpF,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAExE;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAExH,4DAA4D;AAC5D,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED,iDAAiD;AACjD,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,GACV,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAK1B;AAED,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAO/E;AAOD,wFAAwF;AACxF,wBAAgB,UAAU,CACxB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,MAAM,CAMR;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,QAAQ,EAAE,EACjB,KAAK,EAAE,QAAQ,EAAE,EACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACvC,SAAS,EAAE,MAAM,GAChB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAsC1C;AAED,kGAAkG;AAClG,wBAAgB,cAAc,CAAC,MAAM,EAAE;IAAE,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAQrH"}
package/dist/mt.jsx ADDED
@@ -0,0 +1,91 @@
1
+ function snapMT(v, grid) {
2
+ 'main thread';
3
+ return grid > 0 ? Math.round(v / grid) * grid : v;
4
+ }
5
+ function zoomAtMT(zoom, x, y, factor, sx, sy, min, max) {
6
+ 'main thread';
7
+ const z = Math.min(max, Math.max(min, zoom * factor));
8
+ const k = z / zoom;
9
+ return [
10
+ z,
11
+ sx - (sx - x) * k,
12
+ sy - (sy - y) * k
13
+ ];
14
+ }
15
+ function nodeIndexAtMT(nodes, wx, wy) {
16
+ 'main thread';
17
+ for(let i = nodes.length - 1; i >= 0; i--){
18
+ const n = nodes[i];
19
+ if (wx >= n[1] && wx <= n[1] + n[3] && wy >= n[2] && wy <= n[2] + n[4]) return i;
20
+ }
21
+ return -1;
22
+ }
23
+ const r1 = (v)=>{
24
+ 'main thread';
25
+ return Math.round(10 * v) / 10;
26
+ };
27
+ function edgePathMT(ax, ay, aSide, bx, by, bSide, curvature) {
28
+ 'main thread';
29
+ const d = Math.max(40, Math.abs(bx - ax) * curvature);
30
+ const c1x = ax + aSide * d;
31
+ const c2x = bx + bSide * d;
32
+ return `M${r1(ax)} ${r1(ay)}C${r1(c1x)} ${r1(ay)} ${r1(c2x)} ${r1(by)} ${r1(bx)} ${r1(by)}`;
33
+ }
34
+ function liveEdgesSvgMT(edges, nodes, moved, curvature) {
35
+ 'main thread';
36
+ const pos = {};
37
+ for (const n of nodes)pos[n[0]] = [
38
+ n[1],
39
+ n[2]
40
+ ];
41
+ let x0 = 1 / 0;
42
+ let y0 = 1 / 0;
43
+ let x1 = -1 / 0;
44
+ let y1 = -1 / 0;
45
+ const paths = [];
46
+ for (const e of edges){
47
+ var _moved_e_, _moved_e_1;
48
+ if (!moved[e[1]] && !moved[e[5]]) continue;
49
+ const a = null != (_moved_e_ = moved[e[1]]) ? _moved_e_ : pos[e[1]];
50
+ const b = null != (_moved_e_1 = moved[e[5]]) ? _moved_e_1 : pos[e[5]];
51
+ if (!a || !b) continue;
52
+ const ax = a[0] + e[2];
53
+ const ay = a[1] + e[3];
54
+ const bx = b[0] + e[6];
55
+ const by = b[1] + e[7];
56
+ const pad = Math.max(40, Math.abs(bx - ax) * curvature) + 8;
57
+ x0 = Math.min(x0, ax - pad, bx - pad);
58
+ y0 = Math.min(y0, ay - 8, by - 8);
59
+ x1 = Math.max(x1, ax + pad, bx + pad);
60
+ y1 = Math.max(y1, ay + 8, by + 8);
61
+ const dash = 0 === e[11] ? '' : ' stroke-dasharray="6 4"';
62
+ paths.push(`<path d="${edgePathMT(ax, ay, e[4], bx, by, e[8], curvature)}" fill="none" stroke="${e[9]}" stroke-width="${e[10]}"${dash}/>`);
63
+ }
64
+ if (0 === paths.length) return [
65
+ '',
66
+ 0,
67
+ 0,
68
+ 0,
69
+ 0
70
+ ];
71
+ const w = x1 - x0;
72
+ const h = y1 - y0;
73
+ return [
74
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${r1(x0)} ${r1(y0)} ${r1(w)} ${r1(h)}" width="${r1(w)}" height="${r1(h)}">${paths.join('')}</svg>`,
75
+ x0,
76
+ y0,
77
+ w,
78
+ h
79
+ ];
80
+ }
81
+ function edgeOfTargetMT(target) {
82
+ 'main thread';
83
+ try {
84
+ var _target_getAttribute;
85
+ const v = null == target ? void 0 : null == (_target_getAttribute = target.getAttribute) ? void 0 : _target_getAttribute.call(target, 'data-g9edge');
86
+ return 'string' == typeof v && v ? v : null;
87
+ } catch {
88
+ return null;
89
+ }
90
+ }
91
+ export { edgeOfTargetMT, edgePathMT, liveEdgesSvgMT, nodeIndexAtMT, snapMT, zoomAtMT };
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@g9tm/lynxcontrols-graph",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.10.0",
4
+ "description": "G9GraphCanvas: a node graph editor for ReactLynx — app-drawn cards at app-given positions, bezier edges between ports, lanes behind them; pan, wheel and pinch zoom, fit, main-thread node drag, selection, keyboard, context menus, external drops, culling. Its plain-TS core (view maths, edges, culling, layered auto-layout) at /core.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": [
8
+ "**/*.css"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "source": "./src/index.ts",
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.jsx"
15
+ },
16
+ "./core": {
17
+ "source": "./src/core.ts",
18
+ "types": "./dist/core.d.ts",
19
+ "default": "./dist/core.js"
20
+ },
21
+ "./catalog": "./catalog/catalog.json"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "catalog"
27
+ ],
28
+ "scripts": {
29
+ "build": "rslib build"
30
+ },
31
+ "dependencies": {
32
+ "@g9tm/lynxcontrols-foundation": "2.10.0"
33
+ },
34
+ "peerDependencies": {
35
+ "@g9tm/lynxcontrols": "2.10.0",
36
+ "@lynx-js/react": ">=0.129.3 <0.130.0"
37
+ }
38
+ }