@ghchinoy/litflow 0.1.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.
@@ -0,0 +1,1000 @@
1
+ import { LitElement as P, html as $, svg as Z, css as A } from "lit";
2
+ import { unsafeStatic as F, html as E } from "lit/static-html.js";
3
+ import { property as a, customElement as z, query as T, state as S } from "lit/decorators.js";
4
+ import { signal as N, SignalWatcher as B } from "@lit-labs/signals";
5
+ import { infiniteExtent as K, Position as I, getBezierPath as j, adoptUserNodes as U, updateAbsolutePositions as H, XYPanZoom as J, PanOnScrollMode as M, XYDrag as Q, getHandlePosition as X, getSmoothStepPath as Y, getStraightPath as tt, XYHandle as et, ConnectionMode as ot, XYMinimap as st, getBoundsOfRects as nt, getInternalNodesBounds as rt } from "@xyflow/system";
6
+ import { m3Tokens as it } from "./theme.js";
7
+ function at() {
8
+ return {
9
+ nodes: N([]),
10
+ edges: N([]),
11
+ nodeLookup: /* @__PURE__ */ new Map(),
12
+ parentLookup: /* @__PURE__ */ new Map(),
13
+ nodeExtent: K,
14
+ snapGrid: [15, 15],
15
+ snapToGrid: !1,
16
+ nodeOrigin: [0, 0],
17
+ multiSelectionActive: !1,
18
+ transform: N([0, 0, 1]),
19
+ autoPanOnNodeDrag: !0,
20
+ nodesDraggable: !0,
21
+ selectNodesOnDrag: !0,
22
+ nodeDragThreshold: 0,
23
+ panZoom: null,
24
+ domNode: null,
25
+ connectionInProgress: N(null)
26
+ };
27
+ }
28
+ var dt = Object.defineProperty, lt = Object.getOwnPropertyDescriptor, k = (t, o, e, n) => {
29
+ for (var s = n > 1 ? void 0 : n ? lt(o, e) : o, r = t.length - 1, i; r >= 0; r--)
30
+ (i = t[r]) && (s = (n ? i(o, e, s) : i(s)) || s);
31
+ return n && s && dt(o, e, s), s;
32
+ };
33
+ let x = class extends B(P) {
34
+ constructor() {
35
+ super(...arguments), this.label = "", this.type = "default", this.data = {}, this.selected = !1, this.nodeId = "";
36
+ }
37
+ createRenderRoot() {
38
+ return this;
39
+ }
40
+ render() {
41
+ return $`
42
+ <div class="label" style="font-size: 12px; color: #222; pointer-events: none;">${this.label}</div>
43
+ <slot></slot>
44
+ ${this.type === "input" || this.type === "default" ? $`<lit-handle type="source" data-handlepos="bottom" data-nodeid="${this.nodeId}"></lit-handle>` : ""}
45
+ ${this.type === "output" || this.type === "default" ? $`<lit-handle type="target" data-handlepos="top" data-nodeid="${this.nodeId}"></lit-handle>` : ""}
46
+ `;
47
+ }
48
+ };
49
+ k([
50
+ a({ type: String })
51
+ ], x.prototype, "label", 2);
52
+ k([
53
+ a({ type: String, reflect: !0 })
54
+ ], x.prototype, "type", 2);
55
+ k([
56
+ a({ type: Object })
57
+ ], x.prototype, "data", 2);
58
+ k([
59
+ a({ type: Boolean, reflect: !0 })
60
+ ], x.prototype, "selected", 2);
61
+ k([
62
+ a({ type: String, attribute: "data-id", reflect: !0 })
63
+ ], x.prototype, "nodeId", 2);
64
+ x = k([
65
+ z("lit-node")
66
+ ], x);
67
+ var ht = Object.defineProperty, pt = Object.getOwnPropertyDescriptor, _ = (t, o, e, n) => {
68
+ for (var s = n > 1 ? void 0 : n ? pt(o, e) : o, r = t.length - 1, i; r >= 0; r--)
69
+ (i = t[r]) && (s = (n ? i(o, e, s) : i(s)) || s);
70
+ return n && s && ht(o, e, s), s;
71
+ };
72
+ let m = class extends B(P) {
73
+ constructor() {
74
+ super(...arguments), this.sourceX = 0, this.sourceY = 0, this.targetX = 0, this.targetY = 0, this.sourcePosition = I.Right, this.targetPosition = I.Left, this.selected = !1;
75
+ }
76
+ render() {
77
+ const [t] = j({
78
+ sourceX: this.sourceX,
79
+ sourceY: this.sourceY,
80
+ sourcePosition: this.sourcePosition,
81
+ targetX: this.targetX,
82
+ targetY: this.targetY,
83
+ targetPosition: this.targetPosition
84
+ });
85
+ return Z`
86
+ <path d="${t}" />
87
+ `;
88
+ }
89
+ };
90
+ m.styles = A`
91
+ :host {
92
+ display: contents;
93
+ }
94
+
95
+ path {
96
+ fill: none;
97
+ stroke: #b1b1b7;
98
+ stroke-width: 2;
99
+ }
100
+
101
+ :host([selected]) path {
102
+ stroke: #555;
103
+ }
104
+ `;
105
+ _([
106
+ a({ type: Number })
107
+ ], m.prototype, "sourceX", 2);
108
+ _([
109
+ a({ type: Number })
110
+ ], m.prototype, "sourceY", 2);
111
+ _([
112
+ a({ type: Number })
113
+ ], m.prototype, "targetX", 2);
114
+ _([
115
+ a({ type: Number })
116
+ ], m.prototype, "targetY", 2);
117
+ _([
118
+ a({ type: String })
119
+ ], m.prototype, "sourcePosition", 2);
120
+ _([
121
+ a({ type: String })
122
+ ], m.prototype, "targetPosition", 2);
123
+ _([
124
+ a({ type: Boolean, reflect: !0 })
125
+ ], m.prototype, "selected", 2);
126
+ m = _([
127
+ z("lit-edge")
128
+ ], m);
129
+ var ct = Object.defineProperty, ut = Object.getOwnPropertyDescriptor, g = (t, o, e, n) => {
130
+ for (var s = n > 1 ? void 0 : n ? ut(o, e) : o, r = t.length - 1, i; r >= 0; r--)
131
+ (i = t[r]) && (s = (n ? i(o, e, s) : i(s)) || s);
132
+ return n && s && ct(o, e, s), s;
133
+ };
134
+ const b = {
135
+ fromAttribute: (t) => t !== "false" && t !== null,
136
+ toAttribute: (t) => t ? "" : null
137
+ };
138
+ let u = class extends B(P) {
139
+ constructor() {
140
+ super(...arguments), this._drags = /* @__PURE__ */ new Map(), this._state = at(), this.nodeTypes = {
141
+ default: "lit-node",
142
+ input: "lit-node",
143
+ output: "lit-node"
144
+ }, this.showControls = !1, this.showMinimap = !1, this.showGrid = !0, this.nodesDraggable = !0, this.nodesConnectable = !0, this.panOnDrag = !0, this.zoomOnScroll = !0, this.zoomOnPinch = !0, this.zoomOnDoubleClick = !0, this._width = 0, this._height = 0, this.viewport = { x: 0, y: 0, zoom: 1 };
145
+ }
146
+ set nodes(t) {
147
+ this._state.nodes.set(t), U(t, this._state.nodeLookup, this._state.parentLookup, {
148
+ nodeOrigin: this._state.nodeOrigin,
149
+ nodeExtent: this._state.nodeExtent
150
+ }), H(this._state.nodeLookup, this._state.parentLookup, {
151
+ nodeOrigin: this._state.nodeOrigin,
152
+ nodeExtent: this._state.nodeExtent
153
+ });
154
+ }
155
+ get nodes() {
156
+ return this._state.nodes.get();
157
+ }
158
+ set edges(t) {
159
+ this._state.edges.set(t);
160
+ }
161
+ get edges() {
162
+ return this._state.edges.get();
163
+ }
164
+ connectedCallback() {
165
+ super.connectedCallback(), this._resizeObserver = new ResizeObserver((t) => {
166
+ for (const o of t)
167
+ if (o.target === this)
168
+ this._width = o.contentRect.width, this._height = o.contentRect.height;
169
+ else if (o.target !== this._renderer) {
170
+ const e = o.target.dataset.id;
171
+ e && this._updateNodeDimensions(e, o.target);
172
+ }
173
+ }), this._resizeObserver.observe(this);
174
+ }
175
+ disconnectedCallback() {
176
+ super.disconnectedCallback(), this._resizeObserver?.disconnect();
177
+ }
178
+ async _updateNodeDimensions(t, o) {
179
+ const e = this._state.nodeLookup.get(t);
180
+ if (e) {
181
+ "updateComplete" in o && await o.updateComplete;
182
+ const { width: n, height: s } = o.getBoundingClientRect(), r = this._state.transform.get()[2];
183
+ e.measured = {
184
+ width: n / r,
185
+ height: s / r
186
+ };
187
+ const i = this.nodes.find((p) => p.id === t);
188
+ i && (i.measured = e.measured);
189
+ const h = o.querySelectorAll("lit-handle");
190
+ if (h && h.length > 0) {
191
+ const p = [], d = [];
192
+ h.forEach((c) => {
193
+ const l = c.getBoundingClientRect(), f = o.getBoundingClientRect(), v = {
194
+ id: c.handleId || null,
195
+ type: c.type,
196
+ position: c.position,
197
+ x: (l.left - f.left) / r,
198
+ y: (l.top - f.top) / r,
199
+ width: l.width / r,
200
+ height: l.height / r
201
+ };
202
+ c.type === "source" ? p.push(v) : d.push(v);
203
+ }), e.internals.handleBounds = {
204
+ source: p,
205
+ target: d
206
+ }, console.log(`Node ${t} handleBounds:`, e.internals.handleBounds);
207
+ }
208
+ H(this._state.nodeLookup, this._state.parentLookup, {
209
+ nodeOrigin: this._state.nodeOrigin,
210
+ nodeExtent: this._state.nodeExtent
211
+ }), this._state.nodes.set([...this.nodes]);
212
+ }
213
+ }
214
+ _selectNode(t, o) {
215
+ const e = this.nodes.map((n) => n.id === t ? { ...n, selected: !n.selected } : o ? n : { ...n, selected: !1 });
216
+ this.nodes = e;
217
+ }
218
+ firstUpdated() {
219
+ this._renderer && (this._state.domNode = this._renderer, this._resizeObserver?.observe(this._renderer), this._renderer.onclick = () => {
220
+ this.nodes = this.nodes.map((t) => ({ ...t, selected: !1 }));
221
+ }, this._panZoom = J({
222
+ domNode: this._renderer,
223
+ minZoom: 0.5,
224
+ maxZoom: 2,
225
+ translateExtent: this._state.nodeExtent,
226
+ viewport: this.viewport,
227
+ onDraggingChange: () => {
228
+ },
229
+ onPanZoom: (t, { x: o, y: e, zoom: n }) => {
230
+ this.viewport = { x: o, y: e, zoom: n }, this._state.transform.set([o, e, n]), this._viewport && (this._viewport.style.transform = `translate(${o}px,${e}px) scale(${n})`);
231
+ }
232
+ }), this._panZoom.update({
233
+ noWheelClassName: "nowheel",
234
+ noPanClassName: "nopan",
235
+ preventScrolling: !0,
236
+ panOnScroll: !1,
237
+ panOnDrag: this.panOnDrag,
238
+ panOnScrollMode: M.Free,
239
+ panOnScrollSpeed: 0.5,
240
+ userSelectionActive: !1,
241
+ zoomOnPinch: this.zoomOnPinch,
242
+ zoomOnScroll: this.zoomOnScroll,
243
+ zoomOnDoubleClick: this.zoomOnDoubleClick,
244
+ zoomActivationKeyPressed: !1,
245
+ lib: "lit",
246
+ onTransformChange: () => {
247
+ },
248
+ connectionInProgress: !1,
249
+ paneClickDistance: 0
250
+ }), this._state.panZoom = this._panZoom);
251
+ }
252
+ updated(t) {
253
+ (t.has("nodes") || t.has("nodesDraggable")) && this._setupDrags(), this._panZoom && (t.has("panOnDrag") || t.has("zoomOnScroll") || t.has("zoomOnPinch") || t.has("zoomOnDoubleClick")) && this._panZoom.update({
254
+ noWheelClassName: "nowheel",
255
+ noPanClassName: "nopan",
256
+ preventScrolling: !0,
257
+ panOnScroll: !1,
258
+ panOnDrag: this.panOnDrag,
259
+ panOnScrollMode: M.Free,
260
+ panOnScrollSpeed: 0.5,
261
+ userSelectionActive: !1,
262
+ zoomOnPinch: this.zoomOnPinch,
263
+ zoomOnScroll: this.zoomOnScroll,
264
+ zoomOnDoubleClick: this.zoomOnDoubleClick,
265
+ zoomActivationKeyPressed: !1,
266
+ lib: "lit",
267
+ onTransformChange: () => {
268
+ },
269
+ connectionInProgress: !1,
270
+ paneClickDistance: 0
271
+ });
272
+ }
273
+ _setupDrags() {
274
+ const t = this.shadowRoot?.querySelectorAll(".xyflow__node"), o = /* @__PURE__ */ new Set();
275
+ t?.forEach((e) => {
276
+ const n = e.dataset.id;
277
+ if (n) {
278
+ if (o.add(n), this._resizeObserver?.observe(e), e.onclick = (r) => {
279
+ r.stopPropagation(), this._selectNode(n, r.shiftKey || r.metaKey);
280
+ }, e.style.cursor = this.nodesDraggable ? "grab" : "default", !this.nodesDraggable) {
281
+ this._drags.delete(n);
282
+ return;
283
+ }
284
+ let s = this._drags.get(n);
285
+ s || (s = Q({
286
+ getStoreItems: () => ({
287
+ ...this._state,
288
+ nodes: this._state.nodes.get(),
289
+ edges: this._state.edges.get(),
290
+ transform: this._state.transform.get(),
291
+ panBy: async (r) => {
292
+ const { panZoom: i, nodeExtent: h } = this._state, p = this._state.transform.get();
293
+ return i ? !!await i.setViewportConstrained(
294
+ {
295
+ x: p[0] + r.x,
296
+ y: p[1] + r.y,
297
+ zoom: p[2]
298
+ },
299
+ [[0, 0], [this.offsetWidth, this.offsetHeight]],
300
+ h
301
+ ) : !1;
302
+ },
303
+ updateNodePositions: (r) => {
304
+ r.forEach((i, h) => {
305
+ const p = this._state.nodeLookup.get(h);
306
+ if (p) {
307
+ p.position = i.position, p.internals.positionAbsolute = i.internals.positionAbsolute;
308
+ const d = this.nodes.find((c) => c.id === h);
309
+ d && (d.position = i.position);
310
+ }
311
+ }), H(this._state.nodeLookup, this._state.parentLookup, {
312
+ nodeOrigin: this._state.nodeOrigin,
313
+ nodeExtent: this._state.nodeExtent
314
+ }), this._state.nodes.set([...this.nodes]);
315
+ },
316
+ unselectNodesAndEdges: () => {
317
+ }
318
+ })
319
+ }), this._drags.set(n, s)), s.update({
320
+ domNode: e,
321
+ nodeId: n
322
+ });
323
+ }
324
+ });
325
+ for (const e of this._drags.keys())
326
+ o.has(e) || this._drags.delete(e);
327
+ }
328
+ _renderEdge(t) {
329
+ const o = this._state.nodeLookup.get(t.source), e = this._state.nodeLookup.get(t.target);
330
+ if (!o || !e) return null;
331
+ const n = this.nodes.find((l) => l.id === t.source), s = this.nodes.find((l) => l.id === t.target);
332
+ if (n?.hidden || s?.hidden) return null;
333
+ const r = (o.internals.handleBounds?.source || []).find(
334
+ (l) => l.id === (t.sourceHandle || null)
335
+ ) || o.internals.handleBounds?.source?.[0] || {
336
+ id: null,
337
+ type: "source",
338
+ nodeId: t.source,
339
+ position: I.Bottom,
340
+ x: (o.measured.width || 0) / 2,
341
+ y: o.measured.height || 0,
342
+ width: 1,
343
+ height: 1
344
+ }, i = (e.internals.handleBounds?.target || []).find(
345
+ (l) => l.id === (t.targetHandle || null)
346
+ ) || e.internals.handleBounds?.target?.[0] || {
347
+ id: null,
348
+ type: "target",
349
+ nodeId: t.target,
350
+ position: I.Top,
351
+ x: (e.measured.width || 0) / 2,
352
+ y: 0,
353
+ width: 1,
354
+ height: 1
355
+ }, h = X(o, r, r.position, !0), p = X(e, i, i.position, !0);
356
+ let d = "";
357
+ const c = {
358
+ sourceX: h.x,
359
+ sourceY: h.y,
360
+ sourcePosition: r.position,
361
+ targetX: p.x,
362
+ targetY: p.y,
363
+ targetPosition: i.position
364
+ };
365
+ switch (t.type) {
366
+ case "straight":
367
+ [d] = tt(c);
368
+ break;
369
+ case "smoothstep":
370
+ [d] = Y(c);
371
+ break;
372
+ case "step":
373
+ [d] = Y({ ...c, borderRadius: 0 });
374
+ break;
375
+ default:
376
+ [d] = j(c);
377
+ break;
378
+ }
379
+ return Z`
380
+ <path
381
+ d="${d}"
382
+ fill="none"
383
+ stroke="${t.selected ? "var(--md-sys-color-primary)" : "var(--md-sys-color-outline-variant)"}"
384
+ stroke-width="2"
385
+ style="pointer-events: none;"
386
+ />
387
+ `;
388
+ }
389
+ _onHandlePointerDown(t) {
390
+ const { event: o, handleId: e, nodeId: n, type: s, handleDomNode: r } = t.detail, i = s === "target";
391
+ if (this._state.connectionInProgress.get() || !this.nodesConnectable)
392
+ return;
393
+ const h = r.getBoundingClientRect(), p = r.parentElement?.getBoundingClientRect(), d = this._state.transform.get()[2], c = {
394
+ id: e,
395
+ nodeId: n,
396
+ type: s,
397
+ position: r.position,
398
+ x: (h.left - (p?.left ?? 0)) / d,
399
+ y: (h.top - (p?.top ?? 0)) / d,
400
+ width: h.width / d,
401
+ height: h.height / d
402
+ };
403
+ et.onPointerDown(o, {
404
+ handleId: e,
405
+ nodeId: n,
406
+ isTarget: i,
407
+ domNode: this._renderer,
408
+ handleDomNode: r,
409
+ nodeLookup: this._state.nodeLookup,
410
+ connectionMode: ot.Strict,
411
+ lib: "lit",
412
+ autoPanOnConnect: !0,
413
+ flowId: "lit-flow",
414
+ dragThreshold: 0,
415
+ panBy: async (l) => {
416
+ const f = this._panZoom?.getViewport();
417
+ return f ? (await this._panZoom?.setViewport({
418
+ x: f.x + l.x,
419
+ y: f.y + l.y,
420
+ zoom: f.zoom
421
+ }), !0) : !1;
422
+ },
423
+ getTransform: () => this._state.transform.get(),
424
+ getFromHandle: () => c,
425
+ updateConnection: (l) => {
426
+ l.inProgress ? this._state.connectionInProgress.set(l) : this._state.connectionInProgress.set(null);
427
+ },
428
+ cancelConnection: () => {
429
+ this._state.connectionInProgress.set(null);
430
+ },
431
+ onConnect: (l) => {
432
+ this.dispatchEvent(new CustomEvent("connect", {
433
+ detail: l
434
+ }));
435
+ const f = `e-${l.source}${l.sourceHandle || ""}-${l.target}${l.targetHandle || ""}`;
436
+ this.edges = [...this.edges, { ...l, id: f }];
437
+ },
438
+ connectionRadius: 20
439
+ });
440
+ }
441
+ _renderConnectionLine(t) {
442
+ if (!t) return null;
443
+ const [o] = j({
444
+ sourceX: t.from.x,
445
+ sourceY: t.from.y,
446
+ sourcePosition: t.fromPosition,
447
+ targetX: t.to.x,
448
+ targetY: t.to.y,
449
+ targetPosition: t.toPosition
450
+ });
451
+ return Z`
452
+ <path
453
+ class="xyflow__connection-path"
454
+ d="${o}"
455
+ fill="none"
456
+ stroke="#b1b1b7"
457
+ stroke-width="2"
458
+ stroke-dasharray="5,5"
459
+ />
460
+ `;
461
+ }
462
+ render() {
463
+ const t = this._state.transform.get(), o = this._state.connectionInProgress.get();
464
+ return E`
465
+ <div class="xyflow__renderer ${this.showGrid ? "has-grid" : ""}">
466
+ <div
467
+ class="xyflow__viewport"
468
+ style="transform: translate(${t[0]}px, ${t[1]}px) scale(${t[2]})"
469
+ >
470
+ <div class="xyflow__nodes" @handle-pointer-down="${this._onHandlePointerDown}">
471
+ ${this.nodes.map((e) => {
472
+ if (e.hidden) return null;
473
+ const s = this._state.nodeLookup.get(e.id)?.internals.positionAbsolute || e.position, r = this.nodeTypes[e.type || "default"] || this.nodeTypes.default, i = F(r), h = e.style || {}, p = Object.entries(h).map(([C, D]) => `${C.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${typeof D == "number" ? `${D}px` : D}`).join("; "), d = e.width || h.width, c = e.height || h.height, l = d ? `width: ${typeof d == "number" ? `${d}px` : d};` : "", f = c ? `height: ${typeof c == "number" ? `${c}px` : c};` : "", v = e.zIndex ? `z-index: ${e.zIndex};` : "";
474
+ return E`
475
+ <${i}
476
+ class="xyflow__node"
477
+ data-id="${e.id}"
478
+ type="${e.type || "default"}"
479
+ .nodeId="${e.id}"
480
+ style="transform: translate(${s.x}px, ${s.y}px); ${p} ${l} ${f} ${v}"
481
+ .data="${e.data}"
482
+ .label="${e.data.label}"
483
+ .type="${e.type || "default"}"
484
+ ?selected="${e.selected}"
485
+ >
486
+ </${i}>
487
+ `;
488
+ })}
489
+ </div>
490
+ <svg class="xyflow__edges">
491
+ ${this.edges.map((e) => this._renderEdge(e))}
492
+ ${this._renderConnectionLine(o)}
493
+ </svg>
494
+ </div>
495
+ </div>
496
+ ${this.showControls ? E`<lit-controls .panZoom="${this._panZoom}"></lit-controls>` : ""}
497
+ ${this.showMinimap ? E`
498
+ <lit-minimap
499
+ .panZoom="${this._panZoom}"
500
+ .nodeLookup="${this._state.nodeLookup}"
501
+ .transform="${this._state.transform.get()}"
502
+ .translateExtent="${this._state.nodeExtent}"
503
+ .width="${this._width}"
504
+ .height="${this._height}"
505
+ ></lit-minimap>
506
+ ` : ""}
507
+ `;
508
+ }
509
+ };
510
+ u.styles = [
511
+ it,
512
+ A`
513
+ :host {
514
+ display: block;
515
+ width: 100%;
516
+ height: 100%;
517
+ overflow: hidden;
518
+ position: relative;
519
+ background-color: var(--md-sys-color-background);
520
+ color: var(--md-sys-color-on-background);
521
+ font-family: var(--md-sys-typescale-body-medium-font);
522
+ }
523
+
524
+ .xyflow__renderer {
525
+ width: 100%;
526
+ height: 100%;
527
+ position: absolute;
528
+ top: 0;
529
+ left: 0;
530
+ }
531
+
532
+ .xyflow__renderer.has-grid {
533
+ background-image: radial-gradient(var(--md-sys-color-outline-variant) 1px, transparent 0);
534
+ background-size: 20px 20px;
535
+ }
536
+
537
+ .xyflow__viewport {
538
+ transform-origin: 0 0;
539
+ width: 100%;
540
+ height: 100%;
541
+ }
542
+
543
+ .xyflow__edges {
544
+ position: absolute;
545
+ width: 100%;
546
+ height: 100%;
547
+ pointer-events: none;
548
+ overflow: visible;
549
+ }
550
+
551
+ .xyflow__nodes {
552
+ position: absolute;
553
+ width: 100%;
554
+ height: 100%;
555
+ pointer-events: none;
556
+ }
557
+
558
+ .xyflow__node {
559
+ position: absolute;
560
+ pointer-events: all;
561
+ cursor: grab;
562
+ user-select: none;
563
+ display: block;
564
+ background: var(--lit-flow-node-bg);
565
+ border: 1px solid var(--lit-flow-node-border);
566
+ padding: 12px;
567
+ border-radius: var(--md-sys-shape-corner-small);
568
+ min-width: 120px;
569
+ text-align: center;
570
+ box-shadow: var(--md-sys-elevation-1);
571
+ box-sizing: border-box;
572
+ color: var(--lit-flow-node-text);
573
+ font-size: var(--md-sys-typescale-body-medium-size);
574
+ transition: box-shadow 0.2s ease-in-out, border-color 0.2s ease-in-out;
575
+ }
576
+
577
+ .xyflow__node[type="group"] {
578
+ padding: 0;
579
+ background: none;
580
+ border: none;
581
+ box-shadow: none;
582
+ pointer-events: none;
583
+ }
584
+
585
+ .xyflow__node[type="group"] > * {
586
+ pointer-events: all;
587
+ }
588
+
589
+ .xyflow__node[selected] {
590
+ border-color: var(--lit-flow-node-selected-border);
591
+ border-width: 2px;
592
+ box-shadow: var(--md-sys-elevation-2);
593
+ }
594
+
595
+ .xyflow__node[type="input"] {
596
+ border-top: 4px solid var(--md-sys-color-primary);
597
+ }
598
+
599
+ .xyflow__node[type="output"] {
600
+ border-bottom: 4px solid var(--md-sys-color-secondary);
601
+ }
602
+
603
+ .xyflow__node:active {
604
+ cursor: grabbing;
605
+ }
606
+
607
+ .lit-flow__handle {
608
+ display: block;
609
+ position: absolute;
610
+ width: 10px;
611
+ height: 10px;
612
+ border-radius: 50%;
613
+ z-index: 10;
614
+ pointer-events: all;
615
+ cursor: pointer;
616
+ border: 2px solid var(--lit-flow-handle-outline);
617
+ background-clip: padding-box;
618
+ box-sizing: border-box;
619
+ transition: transform 0.1s ease-in-out;
620
+ }
621
+
622
+ .lit-flow__handle:hover {
623
+ transform: scale(1.2);
624
+ }
625
+
626
+ .lit-flow__handle.source {
627
+ background-color: var(--lit-flow-handle-source);
628
+ }
629
+
630
+ .lit-flow__handle.target {
631
+ background-color: var(--lit-flow-handle-target);
632
+ }
633
+
634
+ .lit-flow__handle[data-handlepos="top"] {
635
+ top: -5px;
636
+ left: 50%;
637
+ transform: translateX(-50%);
638
+ }
639
+
640
+ .lit-flow__handle[data-handlepos="bottom"] {
641
+ bottom: -5px;
642
+ left: 50%;
643
+ transform: translateX(-50%);
644
+ }
645
+
646
+ .lit-flow__handle[data-handlepos="left"] {
647
+ left: -5px;
648
+ top: 50%;
649
+ transform: translateY(-50%);
650
+ }
651
+
652
+ .lit-flow__handle[data-handlepos="right"] {
653
+ right: -5px;
654
+ top: 50%;
655
+ transform: translateY(-50%);
656
+ }
657
+
658
+ .xyflow__connection-path {
659
+ fill: none;
660
+ stroke: var(--md-sys-color-outline);
661
+ stroke-width: 2;
662
+ stroke-dasharray: 5,5;
663
+ pointer-events: none;
664
+ }
665
+ `
666
+ ];
667
+ g([
668
+ T(".xyflow__renderer")
669
+ ], u.prototype, "_renderer", 2);
670
+ g([
671
+ T(".xyflow__viewport")
672
+ ], u.prototype, "_viewport", 2);
673
+ g([
674
+ S()
675
+ ], u.prototype, "_panZoom", 2);
676
+ g([
677
+ S()
678
+ ], u.prototype, "_state", 2);
679
+ g([
680
+ a({ type: Object })
681
+ ], u.prototype, "nodeTypes", 2);
682
+ g([
683
+ a({ type: Boolean, attribute: "show-controls", reflect: !0 })
684
+ ], u.prototype, "showControls", 2);
685
+ g([
686
+ a({ type: Boolean, attribute: "show-minimap", reflect: !0, converter: b })
687
+ ], u.prototype, "showMinimap", 2);
688
+ g([
689
+ a({ type: Boolean, attribute: "show-grid", reflect: !0, converter: b })
690
+ ], u.prototype, "showGrid", 2);
691
+ g([
692
+ a({ type: Boolean, attribute: "nodes-draggable", reflect: !0, converter: b })
693
+ ], u.prototype, "nodesDraggable", 2);
694
+ g([
695
+ a({ type: Boolean, attribute: "nodes-connectable", reflect: !0, converter: b })
696
+ ], u.prototype, "nodesConnectable", 2);
697
+ g([
698
+ a({ type: Boolean, attribute: "pan-on-drag", reflect: !0, converter: b })
699
+ ], u.prototype, "panOnDrag", 2);
700
+ g([
701
+ a({ type: Boolean, attribute: "zoom-on-scroll", reflect: !0, converter: b })
702
+ ], u.prototype, "zoomOnScroll", 2);
703
+ g([
704
+ a({ type: Boolean, attribute: "zoom-on-pinch", reflect: !0, converter: b })
705
+ ], u.prototype, "zoomOnPinch", 2);
706
+ g([
707
+ a({ type: Boolean, attribute: "zoom-on-double-click", reflect: !0, converter: b })
708
+ ], u.prototype, "zoomOnDoubleClick", 2);
709
+ g([
710
+ S()
711
+ ], u.prototype, "_width", 2);
712
+ g([
713
+ S()
714
+ ], u.prototype, "_height", 2);
715
+ g([
716
+ a({ type: Array })
717
+ ], u.prototype, "nodes", 1);
718
+ g([
719
+ a({ type: Array })
720
+ ], u.prototype, "edges", 1);
721
+ g([
722
+ a({ type: Object })
723
+ ], u.prototype, "viewport", 2);
724
+ u = g([
725
+ z("lit-flow")
726
+ ], u);
727
+ var gt = Object.defineProperty, ft = Object.getOwnPropertyDescriptor, L = (t, o, e, n) => {
728
+ for (var s = n > 1 ? void 0 : n ? ft(o, e) : o, r = t.length - 1, i; r >= 0; r--)
729
+ (i = t[r]) && (s = (n ? i(o, e, s) : i(s)) || s);
730
+ return n && s && gt(o, e, s), s;
731
+ };
732
+ let O = class extends P {
733
+ constructor() {
734
+ super(), this.type = "source", this.position = I.Top, this.addEventListener("mousedown", (t) => this._onPointerDown(t)), this.addEventListener("touchstart", (t) => this._onPointerDown(t));
735
+ }
736
+ createRenderRoot() {
737
+ return this;
738
+ }
739
+ _onPointerDown(t) {
740
+ t.stopPropagation();
741
+ const o = this.getAttribute("data-nodeid");
742
+ this.dispatchEvent(new CustomEvent("handle-pointer-down", {
743
+ bubbles: !0,
744
+ composed: !0,
745
+ detail: {
746
+ event: t,
747
+ handleId: this.handleId,
748
+ nodeId: o,
749
+ type: this.type,
750
+ handleDomNode: this
751
+ }
752
+ }));
753
+ }
754
+ connectedCallback() {
755
+ super.connectedCallback(), this.classList.add("lit-flow__handle"), this.classList.add(this.type), this.classList.add("connectable"), this.classList.add("connectableend");
756
+ }
757
+ updated(t) {
758
+ (t.has("nodeId") || t.has("handleId") || t.has("type")) && this.setAttribute("data-id", `lit-flow-${this.nodeId || ""}-${this.handleId || ""}-${this.type}`);
759
+ }
760
+ render() {
761
+ return $`
762
+ <div style="
763
+ width: 100%;
764
+ height: 100%;
765
+ background: inherit;
766
+ border-radius: inherit;
767
+ pointer-events: none;
768
+ "></div>
769
+ `;
770
+ }
771
+ };
772
+ L([
773
+ a({ type: String, reflect: !0 })
774
+ ], O.prototype, "type", 2);
775
+ L([
776
+ a({ type: String, reflect: !0, attribute: "data-handlepos" })
777
+ ], O.prototype, "position", 2);
778
+ L([
779
+ a({ type: String, reflect: !0, attribute: "data-handleid" })
780
+ ], O.prototype, "handleId", 2);
781
+ L([
782
+ a({ type: String, reflect: !0, attribute: "data-nodeid" })
783
+ ], O.prototype, "nodeId", 2);
784
+ O = L([
785
+ z("lit-handle")
786
+ ], O);
787
+ var mt = Object.defineProperty, yt = Object.getOwnPropertyDescriptor, V = (t, o, e, n) => {
788
+ for (var s = n > 1 ? void 0 : n ? yt(o, e) : o, r = t.length - 1, i; r >= 0; r--)
789
+ (i = t[r]) && (s = (n ? i(o, e, s) : i(s)) || s);
790
+ return n && s && mt(o, e, s), s;
791
+ };
792
+ let R = class extends B(P) {
793
+ _zoomIn() {
794
+ this.panZoom?.scaleBy(1.2);
795
+ }
796
+ _zoomOut() {
797
+ this.panZoom?.scaleBy(1 / 1.2);
798
+ }
799
+ _fitView() {
800
+ this.panZoom?.setViewport({ x: 0, y: 0, zoom: 1 });
801
+ }
802
+ render() {
803
+ return $`
804
+ <button @click="${this._zoomIn}" title="Zoom In">
805
+ <svg viewBox="0 0 24 24"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></svg>
806
+ </button>
807
+ <button @click="${this._zoomOut}" title="Zoom Out">
808
+ <svg viewBox="0 0 24 24"><path d="M19 13H5v-2h14v2z"/></svg>
809
+ </button>
810
+ <button @click="${this._fitView}" title="Reset View">
811
+ <svg viewBox="0 0 24 24"><path d="M4 6h16v2H4zm0 5h16v2H4zm0 5h16v2H4z"/></svg>
812
+ </button>
813
+ `;
814
+ }
815
+ };
816
+ R.styles = A`
817
+ :host {
818
+ display: block;
819
+ position: absolute;
820
+ left: 10px;
821
+ bottom: 10px;
822
+ z-index: 5;
823
+ display: flex;
824
+ flex-direction: column;
825
+ gap: 4px;
826
+ background: var(--md-sys-color-surface);
827
+ padding: 4px;
828
+ border-radius: var(--md-sys-shape-corner-extra-small);
829
+ box-shadow: var(--md-sys-elevation-1);
830
+ border: 1px solid var(--md-sys-color-outline-variant);
831
+ }
832
+
833
+ button {
834
+ width: 28px;
835
+ height: 28px;
836
+ display: flex;
837
+ align-items: center;
838
+ justify-content: center;
839
+ background: none;
840
+ border: none;
841
+ border-radius: var(--md-sys-shape-corner-extra-small);
842
+ cursor: pointer;
843
+ padding: 0;
844
+ color: var(--md-sys-color-on-surface);
845
+ transition: background-color 0.2s ease;
846
+ }
847
+
848
+ button:hover {
849
+ background: var(--md-sys-color-surface-variant);
850
+ }
851
+
852
+ button svg {
853
+ width: 18px;
854
+ height: 18px;
855
+ fill: currentColor;
856
+ }
857
+ `;
858
+ V([
859
+ a({ type: Object })
860
+ ], R.prototype, "panZoom", 2);
861
+ R = V([
862
+ z("lit-controls")
863
+ ], R);
864
+ var _t = Object.defineProperty, bt = Object.getOwnPropertyDescriptor, w = (t, o, e, n) => {
865
+ for (var s = n > 1 ? void 0 : n ? bt(o, e) : o, r = t.length - 1, i; r >= 0; r--)
866
+ (i = t[r]) && (s = (n ? i(o, e, s) : i(s)) || s);
867
+ return n && s && _t(o, e, s), s;
868
+ };
869
+ let y = class extends B(P) {
870
+ constructor() {
871
+ super(...arguments), this.nodeLookup = /* @__PURE__ */ new Map(), this.transform = [0, 0, 1], this.translateExtent = [[-1 / 0, -1 / 0], [1 / 0, 1 / 0]], this.width = 0, this.height = 0;
872
+ }
873
+ updated(t) {
874
+ if (!this._minimapInstance && this.panZoom) {
875
+ const o = this.shadowRoot?.querySelector("svg");
876
+ o && (this._minimapInstance = st({
877
+ domNode: o,
878
+ panZoom: this.panZoom,
879
+ getTransform: () => this.transform,
880
+ getViewScale: () => {
881
+ const e = this._getBoundingRect();
882
+ return Math.max(e.width / 200, e.height / 150);
883
+ }
884
+ }));
885
+ }
886
+ this._minimapInstance && (t.has("width") || t.has("height") || t.has("translateExtent")) && this._minimapInstance.update({
887
+ width: this.width,
888
+ height: this.height,
889
+ translateExtent: this.translateExtent
890
+ });
891
+ }
892
+ _getBoundingRect() {
893
+ const t = {
894
+ x: -this.transform[0] / this.transform[2],
895
+ y: -this.transform[1] / this.transform[2],
896
+ width: this.width / this.transform[2],
897
+ height: this.height / this.transform[2]
898
+ };
899
+ return this.nodeLookup.size > 0 ? nt(rt(this.nodeLookup), t) : t;
900
+ }
901
+ render() {
902
+ const t = this._getBoundingRect(), o = {
903
+ x: -this.transform[0] / this.transform[2],
904
+ y: -this.transform[1] / this.transform[2],
905
+ width: this.width / this.transform[2],
906
+ height: this.height / this.transform[2]
907
+ }, e = 200, n = 150, s = t.width / e, r = t.height / n, i = Math.max(s, r), h = i * e, p = i * n, d = 5 * i, c = t.x - (h - t.width) / 2 - d, l = t.y - (p - t.height) / 2 - d, f = h + d * 2, v = p + d * 2;
908
+ return $`
909
+ <svg
910
+ width="${e}"
911
+ height="${n}"
912
+ viewBox="${c} ${l} ${f} ${v}"
913
+ >
914
+ ${Array.from(this.nodeLookup.values()).map((C) => {
915
+ const { x: D, y: W } = C.internals.positionAbsolute, G = C.measured.width || 0, q = C.measured.height || 0;
916
+ return Z`
917
+ <rect
918
+ class="minimap-node"
919
+ x="${D}"
920
+ y="${W}"
921
+ width="${G}"
922
+ height="${q}"
923
+ rx="2"
924
+ ry="2"
925
+ />
926
+ `;
927
+ })}
928
+ <path
929
+ class="minimap-mask"
930
+ d="M${c - d},${l - d}h${f + d * 2}v${v + d * 2}h${-f - d * 2}z
931
+ M${o.x},${o.y}h${o.width}v${o.height}h${-o.width}z"
932
+ />
933
+ </svg>
934
+ `;
935
+ }
936
+ };
937
+ y.styles = A`
938
+ :host {
939
+ display: block;
940
+ position: absolute;
941
+ right: 10px;
942
+ bottom: 10px;
943
+ z-index: 5;
944
+ background: var(--md-sys-color-surface);
945
+ border: 1px solid var(--md-sys-color-outline-variant);
946
+ border-radius: var(--md-sys-shape-corner-extra-small);
947
+ box-shadow: var(--md-sys-elevation-1);
948
+ overflow: hidden;
949
+ }
950
+
951
+ svg {
952
+ display: block;
953
+ }
954
+
955
+ .minimap-node {
956
+ fill: var(--md-sys-color-surface-variant);
957
+ stroke: var(--md-sys-color-outline-variant);
958
+ stroke-width: 1;
959
+ }
960
+
961
+ .minimap-mask {
962
+ fill: var(--lit-flow-minimap-mask);
963
+ fill-rule: evenodd;
964
+ }
965
+ `;
966
+ w([
967
+ a({ type: Object })
968
+ ], y.prototype, "panZoom", 2);
969
+ w([
970
+ a({ type: Object })
971
+ ], y.prototype, "nodeLookup", 2);
972
+ w([
973
+ a({ type: Array })
974
+ ], y.prototype, "transform", 2);
975
+ w([
976
+ a({ type: Array })
977
+ ], y.prototype, "translateExtent", 2);
978
+ w([
979
+ a({ type: Number })
980
+ ], y.prototype, "width", 2);
981
+ w([
982
+ a({ type: Number })
983
+ ], y.prototype, "height", 2);
984
+ w([
985
+ S()
986
+ ], y.prototype, "_minimapInstance", 2);
987
+ y = w([
988
+ z("lit-minimap")
989
+ ], y);
990
+ export {
991
+ R as LitControls,
992
+ m as LitEdge,
993
+ u as LitFlow,
994
+ O as LitHandle,
995
+ y as LitMinimap,
996
+ x as LitNode,
997
+ at as createInitialState,
998
+ it as m3Tokens
999
+ };
1000
+ //# sourceMappingURL=litflow.js.map