@getartisanflow/alpineflow 0.1.0-alpha

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.
Files changed (196) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -0
  3. package/dist/alpineflow-collab.esm.js +465 -0
  4. package/dist/alpineflow-collab.esm.js.map +1 -0
  5. package/dist/alpineflow-collab.js +247 -0
  6. package/dist/alpineflow-collab.js.map +1 -0
  7. package/dist/alpineflow-dagre.esm.js +1661 -0
  8. package/dist/alpineflow-dagre.esm.js.map +1 -0
  9. package/dist/alpineflow-dagre.js +1655 -0
  10. package/dist/alpineflow-dagre.js.map +1 -0
  11. package/dist/alpineflow-elk.esm.js +47378 -0
  12. package/dist/alpineflow-elk.esm.js.map +1 -0
  13. package/dist/alpineflow-elk.js +47373 -0
  14. package/dist/alpineflow-elk.js.map +1 -0
  15. package/dist/alpineflow-force.esm.js +599 -0
  16. package/dist/alpineflow-force.esm.js.map +1 -0
  17. package/dist/alpineflow-force.js +477 -0
  18. package/dist/alpineflow-force.js.map +1 -0
  19. package/dist/alpineflow-hierarchy.esm.js +398 -0
  20. package/dist/alpineflow-hierarchy.esm.js.map +1 -0
  21. package/dist/alpineflow-hierarchy.js +393 -0
  22. package/dist/alpineflow-hierarchy.js.map +1 -0
  23. package/dist/alpineflow-theme.css +473 -0
  24. package/dist/alpineflow-whiteboard.esm.js +922 -0
  25. package/dist/alpineflow-whiteboard.esm.js.map +1 -0
  26. package/dist/alpineflow-whiteboard.js +922 -0
  27. package/dist/alpineflow-whiteboard.js.map +1 -0
  28. package/dist/alpineflow.bundle.esm.js +12604 -0
  29. package/dist/alpineflow.bundle.esm.js.map +1 -0
  30. package/dist/alpineflow.css +1415 -0
  31. package/dist/alpineflow.esm.js +158 -0
  32. package/dist/alpineflow.esm.js.map +1 -0
  33. package/dist/alpineflow.js +5 -0
  34. package/dist/alpineflow.js.map +1 -0
  35. package/dist/export-DjmXOnKD.js +76 -0
  36. package/dist/export-DjmXOnKD.js.map +1 -0
  37. package/dist/geometry-DZSZoYHE.js +82 -0
  38. package/dist/geometry-DZSZoYHE.js.map +1 -0
  39. package/dist/index-C0N1DL3G.js +11728 -0
  40. package/dist/index-C0N1DL3G.js.map +1 -0
  41. package/dist/index-L3Zm-CoX.js +513 -0
  42. package/dist/index-L3Zm-CoX.js.map +1 -0
  43. package/dist/registry-CChkuoVJ.js +15 -0
  44. package/dist/registry-CChkuoVJ.js.map +1 -0
  45. package/dist/store-CaFAFEdD.js +9 -0
  46. package/dist/store-CaFAFEdD.js.map +1 -0
  47. package/dist/timer-B39XOBYL.js +124 -0
  48. package/dist/timer-B39XOBYL.js.map +1 -0
  49. package/dist/types/lib/collab.cdn.d.ts +1 -0
  50. package/dist/types/lib/collab.d.ts +2 -0
  51. package/dist/types/lib/core.cdn.d.ts +1 -0
  52. package/dist/types/lib/core.d.ts +2 -0
  53. package/dist/types/lib/dagre.cdn.d.ts +1 -0
  54. package/dist/types/lib/dagre.d.ts +1 -0
  55. package/dist/types/lib/elk.cdn.d.ts +1 -0
  56. package/dist/types/lib/elk.d.ts +1 -0
  57. package/dist/types/lib/force.cdn.d.ts +1 -0
  58. package/dist/types/lib/force.d.ts +1 -0
  59. package/dist/types/lib/hierarchy.cdn.d.ts +1 -0
  60. package/dist/types/lib/hierarchy.d.ts +1 -0
  61. package/dist/types/lib/whiteboard.cdn.d.ts +1 -0
  62. package/dist/types/lib/whiteboard.d.ts +1 -0
  63. package/dist/types/src/animate/animator.d.ts +57 -0
  64. package/dist/types/src/animate/easing.d.ts +4 -0
  65. package/dist/types/src/animate/edge-transitions.d.ts +22 -0
  66. package/dist/types/src/animate/engine.d.ts +37 -0
  67. package/dist/types/src/animate/index.d.ts +10 -0
  68. package/dist/types/src/animate/interpolators.d.ts +14 -0
  69. package/dist/types/src/animate/paths.d.ts +64 -0
  70. package/dist/types/src/animate/timeline.d.ts +149 -0
  71. package/dist/types/src/collab/awareness.d.ts +40 -0
  72. package/dist/types/src/collab/bridge.d.ts +36 -0
  73. package/dist/types/src/collab/directives/flow-cursors.d.ts +16 -0
  74. package/dist/types/src/collab/index.d.ts +19 -0
  75. package/dist/types/src/collab/providers/in-memory.d.ts +41 -0
  76. package/dist/types/src/collab/providers/reverb.d.ts +59 -0
  77. package/dist/types/src/collab/providers/websocket.d.ts +33 -0
  78. package/dist/types/src/collab/store.d.ts +22 -0
  79. package/dist/types/src/collab/types.d.ts +55 -0
  80. package/dist/types/src/core/__fixtures__/nodes.d.ts +42 -0
  81. package/dist/types/src/core/announcer.d.ts +21 -0
  82. package/dist/types/src/core/auto-pan.d.ts +37 -0
  83. package/dist/types/src/core/child-layout.d.ts +18 -0
  84. package/dist/types/src/core/child-validation.d.ts +23 -0
  85. package/dist/types/src/core/clipboard.d.ts +29 -0
  86. package/dist/types/src/core/collapse.d.ts +54 -0
  87. package/dist/types/src/core/color-mode.d.ts +11 -0
  88. package/dist/types/src/core/compute.d.ts +33 -0
  89. package/dist/types/src/core/connections.d.ts +32 -0
  90. package/dist/types/src/core/constants.d.ts +18 -0
  91. package/dist/types/src/core/controls-panel.d.ts +23 -0
  92. package/dist/types/src/core/debug.d.ts +10 -0
  93. package/dist/types/src/core/deep-merge.d.ts +10 -0
  94. package/dist/types/src/core/drag.d.ts +63 -0
  95. package/dist/types/src/core/edge-paths/avoidant.d.ts +25 -0
  96. package/dist/types/src/core/edge-paths/bezier.d.ts +26 -0
  97. package/dist/types/src/core/edge-paths/editable.d.ts +22 -0
  98. package/dist/types/src/core/edge-paths/index.d.ts +7 -0
  99. package/dist/types/src/core/edge-paths/orthogonal.d.ts +27 -0
  100. package/dist/types/src/core/edge-paths/smoothstep.d.ts +22 -0
  101. package/dist/types/src/core/edge-paths/straight.d.ts +12 -0
  102. package/dist/types/src/core/edge-paths/utils.d.ts +30 -0
  103. package/dist/types/src/core/edge-utils.d.ts +57 -0
  104. package/dist/types/src/core/export.d.ts +12 -0
  105. package/dist/types/src/core/floating-edge.d.ts +33 -0
  106. package/dist/types/src/core/geometry.d.ts +79 -0
  107. package/dist/types/src/core/gradients.d.ts +30 -0
  108. package/dist/types/src/core/graph.d.ts +38 -0
  109. package/dist/types/src/core/helper-lines.d.ts +32 -0
  110. package/dist/types/src/core/history.d.ts +19 -0
  111. package/dist/types/src/core/index.d.ts +17 -0
  112. package/dist/types/src/core/intersection.d.ts +30 -0
  113. package/dist/types/src/core/keyboard-shortcuts.d.ts +45 -0
  114. package/dist/types/src/core/lasso-hit-test.d.ts +25 -0
  115. package/dist/types/src/core/lasso.d.ts +10 -0
  116. package/dist/types/src/core/layout/dagre.d.ts +11 -0
  117. package/dist/types/src/core/layout/elk.d.ts +13 -0
  118. package/dist/types/src/core/layout/force.d.ts +15 -0
  119. package/dist/types/src/core/layout/hierarchy.d.ts +13 -0
  120. package/dist/types/src/core/long-press.d.ts +11 -0
  121. package/dist/types/src/core/markers.d.ts +49 -0
  122. package/dist/types/src/core/minimap.d.ts +18 -0
  123. package/dist/types/src/core/node-flags.d.ts +19 -0
  124. package/dist/types/src/core/pan-zoom.d.ts +62 -0
  125. package/dist/types/src/core/proximity-connect.d.ts +25 -0
  126. package/dist/types/src/core/registry.d.ts +16 -0
  127. package/dist/types/src/core/render-plan.d.ts +52 -0
  128. package/dist/types/src/core/resize.d.ts +31 -0
  129. package/dist/types/src/core/rotation.d.ts +8 -0
  130. package/dist/types/src/core/selection-box.d.ts +14 -0
  131. package/dist/types/src/core/shapes.d.ts +10 -0
  132. package/dist/types/src/core/sub-flow.d.ts +61 -0
  133. package/dist/types/src/core/svg-path.d.ts +5 -0
  134. package/dist/types/src/core/types.d.ts +1238 -0
  135. package/dist/types/src/core/wire-bridge.d.ts +36 -0
  136. package/dist/types/src/index.d.ts +43 -0
  137. package/dist/types/src/layout/dagre.d.ts +2 -0
  138. package/dist/types/src/layout/elk.d.ts +2 -0
  139. package/dist/types/src/layout/force.d.ts +2 -0
  140. package/dist/types/src/layout/hierarchy.d.ts +2 -0
  141. package/dist/types/src/plugin/connection-utils.d.ts +54 -0
  142. package/dist/types/src/plugin/data/__test-utils.d.ts +9 -0
  143. package/dist/types/src/plugin/data/canvas-animation.d.ts +62 -0
  144. package/dist/types/src/plugin/data/canvas-collapse.d.ts +35 -0
  145. package/dist/types/src/plugin/data/canvas-compute.d.ts +6 -0
  146. package/dist/types/src/plugin/data/canvas-condense.d.ts +19 -0
  147. package/dist/types/src/plugin/data/canvas-config.d.ts +4 -0
  148. package/dist/types/src/plugin/data/canvas-context.d.ts +570 -0
  149. package/dist/types/src/plugin/data/canvas-dom.d.ts +13 -0
  150. package/dist/types/src/plugin/data/canvas-edges.d.ts +37 -0
  151. package/dist/types/src/plugin/data/canvas-history.d.ts +53 -0
  152. package/dist/types/src/plugin/data/canvas-layout.d.ts +151 -0
  153. package/dist/types/src/plugin/data/canvas-nodes.d.ts +73 -0
  154. package/dist/types/src/plugin/data/canvas-rows.d.ts +13 -0
  155. package/dist/types/src/plugin/data/canvas-selection.d.ts +45 -0
  156. package/dist/types/src/plugin/data/canvas-validation.d.ts +21 -0
  157. package/dist/types/src/plugin/data/canvas-viewport.d.ts +111 -0
  158. package/dist/types/src/plugin/data/flow-canvas.d.ts +2 -0
  159. package/dist/types/src/plugin/directives/flow-action.d.ts +12 -0
  160. package/dist/types/src/plugin/directives/flow-animate.d.ts +2 -0
  161. package/dist/types/src/plugin/directives/flow-arrow-draw.d.ts +2 -0
  162. package/dist/types/src/plugin/directives/flow-circle-draw.d.ts +2 -0
  163. package/dist/types/src/plugin/directives/flow-collapse.d.ts +2 -0
  164. package/dist/types/src/plugin/directives/flow-condense.d.ts +2 -0
  165. package/dist/types/src/plugin/directives/flow-context-menu.d.ts +2 -0
  166. package/dist/types/src/plugin/directives/flow-detail.d.ts +2 -0
  167. package/dist/types/src/plugin/directives/flow-devtools.d.ts +2 -0
  168. package/dist/types/src/plugin/directives/flow-drag-handle.d.ts +2 -0
  169. package/dist/types/src/plugin/directives/flow-draggable.d.ts +2 -0
  170. package/dist/types/src/plugin/directives/flow-edge-toolbar.d.ts +2 -0
  171. package/dist/types/src/plugin/directives/flow-edge.d.ts +7 -0
  172. package/dist/types/src/plugin/directives/flow-eraser.d.ts +2 -0
  173. package/dist/types/src/plugin/directives/flow-filter.d.ts +9 -0
  174. package/dist/types/src/plugin/directives/flow-follow.d.ts +9 -0
  175. package/dist/types/src/plugin/directives/flow-freehand.d.ts +2 -0
  176. package/dist/types/src/plugin/directives/flow-handle-connectable.d.ts +12 -0
  177. package/dist/types/src/plugin/directives/flow-handle-limit.d.ts +9 -0
  178. package/dist/types/src/plugin/directives/flow-handle-validate.d.ts +10 -0
  179. package/dist/types/src/plugin/directives/flow-handle.d.ts +29 -0
  180. package/dist/types/src/plugin/directives/flow-highlighter.d.ts +2 -0
  181. package/dist/types/src/plugin/directives/flow-loading.d.ts +2 -0
  182. package/dist/types/src/plugin/directives/flow-node-toolbar.d.ts +2 -0
  183. package/dist/types/src/plugin/directives/flow-node.d.ts +10 -0
  184. package/dist/types/src/plugin/directives/flow-panel.d.ts +2 -0
  185. package/dist/types/src/plugin/directives/flow-rectangle-draw.d.ts +2 -0
  186. package/dist/types/src/plugin/directives/flow-resizer.d.ts +2 -0
  187. package/dist/types/src/plugin/directives/flow-rotate.d.ts +11 -0
  188. package/dist/types/src/plugin/directives/flow-row-select.d.ts +2 -0
  189. package/dist/types/src/plugin/directives/flow-snapshot.d.ts +14 -0
  190. package/dist/types/src/plugin/directives/flow-text-tool.d.ts +2 -0
  191. package/dist/types/src/plugin/directives/flow-timeline.d.ts +2 -0
  192. package/dist/types/src/plugin/directives/flow-viewport.d.ts +2 -0
  193. package/dist/types/src/plugin/magics/flow.d.ts +2 -0
  194. package/dist/types/src/plugin/store.d.ts +2 -0
  195. package/dist/types/src/whiteboard/index.d.ts +2 -0
  196. package/package.json +153 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ArtisanFlow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # AlpineFlow
2
+
3
+ A directive-driven flow diagram and node-graph engine for [Alpine.js](https://alpinejs.dev) -- interactive flowcharts, diagrams, and visual editors with a simple `x-flow-*` API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @getartisanflow/alpineflow alpinejs
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```js
14
+ import Alpine from 'alpinejs';
15
+ import AlpineFlow from '@getartisanflow/alpineflow';
16
+
17
+ Alpine.plugin(AlpineFlow);
18
+ Alpine.start();
19
+ ```
20
+
21
+ ```html
22
+ <div x-data="flowCanvas({
23
+ nodes: [
24
+ { id: '1', position: { x: 0, y: 0 }, data: { label: 'Hello' } },
25
+ { id: '2', position: { x: 200, y: 100 }, data: { label: 'World' } },
26
+ ],
27
+ edges: [
28
+ { id: 'e1', source: '1', target: '2' },
29
+ ],
30
+ })">
31
+ <div x-flow-viewport>
32
+ <template x-for="node in nodes" :key="node.id">
33
+ <div x-flow-node="node" x-text="node.data.label"></div>
34
+ </template>
35
+ </div>
36
+ </div>
37
+ ```
38
+
39
+ ## CSS
40
+
41
+ ```css
42
+ @import '@getartisanflow/alpineflow/css'; /* structural (required) */
43
+ @import '@getartisanflow/alpineflow/theme'; /* default theme (optional) */
44
+ ```
45
+
46
+ ## Features
47
+
48
+ - **Directive-driven API** -- build flows with `x-flow-*` directives, no framework boilerplate
49
+ - **7 edge types** -- bezier, smoothstep, straight, orthogonal, avoidant, editable, floating
50
+ - **Node shapes, groups & nesting** -- resize, rotate, and compose complex layouts
51
+ - **Connection modes** -- drag, click, proximity, multi-connect, easy connect
52
+ - **Canvas controls** -- minimap, background patterns, panels, keyboard shortcuts
53
+ - **Animation engine** -- timeline, particles, path motion (orbit, wave, pendulum, drift), camera follow
54
+ - **Compute flows** -- manual and auto modes for data-driven pipelines
55
+ - **Interactions** -- context menus, toolbars, collapse, drag from sidebar, save/restore, undo/redo, touch support
56
+ - **Theming** -- CSS variables and dark mode
57
+ - **TypeScript** -- full type definitions included
58
+
59
+ ## Optional Addons
60
+
61
+ ```bash
62
+ # Layout engines (install only what you need)
63
+ npm install @dagrejs/dagre # for @getartisanflow/alpineflow/dagre
64
+ npm install elkjs # for @getartisanflow/alpineflow/elk
65
+ npm install d3-force # for @getartisanflow/alpineflow/force
66
+ npm install d3-hierarchy # for @getartisanflow/alpineflow/hierarchy
67
+
68
+ # Whiteboard tools
69
+ import AlpineFlowWhiteboard from '@getartisanflow/alpineflow/whiteboard';
70
+
71
+ # Real-time collaboration
72
+ npm install yjs y-websocket y-protocols
73
+ import AlpineFlowCollab from '@getartisanflow/alpineflow/collab';
74
+ ```
75
+
76
+ ## Documentation
77
+
78
+ Full documentation is available at [artisanflow.dev](https://artisanflow.dev).
79
+
80
+ Follow the journey of building AlpineFlow and WireFlow at [zachiler.dev](https://zachiler.dev).
81
+
82
+ ## Acknowledgements
83
+
84
+ AlpineFlow was inspired by [React Flow](https://reactflow.dev) and its core architecture. Special thanks to the React Flow team for pioneering the open-source node-based UI space.
85
+
86
+ ## License
87
+
88
+ MIT -- Created by [Zac Hiler](https://github.com/zachiler)
@@ -0,0 +1,465 @@
1
+ import * as c from "yjs";
2
+ import { encodeStateAsUpdate as N, applyUpdate as H, encodeStateVector as C, Doc as T } from "yjs";
3
+ import { applyAwarenessUpdate as m, encodeAwarenessUpdate as b, Awareness as j } from "y-protocols/awareness";
4
+ import { WebsocketProvider as D } from "y-websocket";
5
+ const w = "__alpineflow_registry__";
6
+ function O() {
7
+ return typeof globalThis < "u" ? (globalThis[w] || (globalThis[w] = /* @__PURE__ */ new Map()), globalThis[w]) : /* @__PURE__ */ new Map();
8
+ }
9
+ function x(i, e) {
10
+ O().set(i, e);
11
+ }
12
+ const d = "collab-bridge-local";
13
+ function y(i) {
14
+ const e = new c.Map(), t = JSON.parse(JSON.stringify(i));
15
+ for (const [n, r] of Object.entries(t))
16
+ e.set(n, r);
17
+ return e;
18
+ }
19
+ class k {
20
+ constructor(e, t, n) {
21
+ if (this.destroyed = !1, this._initialSyncDone = !1, this._draggingNodeIds = /* @__PURE__ */ new Set(), this.doc = e, this.state = t, this.yNodes = e.getMap("nodes"), this.yEdges = e.getMap("edges"), n) {
22
+ const r = (s) => {
23
+ !s || this._initialSyncDone || this.destroyed || (this._initialSyncDone = !0, n.off("sync", r), this._resolveInitialState());
24
+ };
25
+ n.on("sync", r);
26
+ } else
27
+ this._resolveInitialState();
28
+ this.nodeObserver = (r, s) => {
29
+ if (this.destroyed || s.origin === d)
30
+ return;
31
+ this.pullNodesFromYjs();
32
+ const a = () => {
33
+ this.destroyed || this.pullEdgesFromYjs();
34
+ };
35
+ typeof requestAnimationFrame == "function" ? requestAnimationFrame(a) : a();
36
+ }, this.yNodes.observeDeep(this.nodeObserver), this.edgeObserver = (r, s) => {
37
+ this.destroyed || s.origin === d || this.pullEdgesFromYjs();
38
+ }, this.yEdges.observeDeep(this.edgeObserver);
39
+ }
40
+ _resolveInitialState() {
41
+ this.yNodes.size > 0 ? this.pullAllFromYjs() : this._pushInitialState();
42
+ }
43
+ _pushInitialState() {
44
+ this.doc.transact(() => {
45
+ for (const e of this.state.nodes)
46
+ this.yNodes.has(e.id) || this.yNodes.set(e.id, y(e));
47
+ for (const e of this.state.edges)
48
+ this.yEdges.has(e.id) || this.yEdges.set(e.id, y(e));
49
+ }, d);
50
+ }
51
+ // -- Push local to Yjs --
52
+ pushLocalNodeUpdate(e, t) {
53
+ this.doc.transact(() => {
54
+ const n = this.yNodes.get(e);
55
+ if (!n)
56
+ return;
57
+ const r = JSON.parse(JSON.stringify(t));
58
+ for (const [s, a] of Object.entries(r))
59
+ n.set(s, a);
60
+ }, d);
61
+ }
62
+ pushLocalNodeAdd(e) {
63
+ this.doc.transact(() => {
64
+ this.yNodes.set(e.id, y(e));
65
+ }, d);
66
+ }
67
+ pushLocalNodeRemove(e) {
68
+ this.doc.transact(() => {
69
+ this.yNodes.delete(e);
70
+ }, d);
71
+ }
72
+ pushLocalEdgeAdd(e) {
73
+ this.doc.transact(() => {
74
+ this.yEdges.set(e.id, y(e));
75
+ }, d);
76
+ }
77
+ pushLocalEdgeRemove(e) {
78
+ this.doc.transact(() => {
79
+ this.yEdges.delete(e);
80
+ }, d);
81
+ }
82
+ // -- Pull Yjs to Alpine --
83
+ /** Mark a node as being dragged locally — its position won't be overwritten by remote pulls. */
84
+ setDragging(e, t) {
85
+ t ? this._draggingNodeIds.add(e) : this._draggingNodeIds.delete(e);
86
+ }
87
+ pullAllFromYjs() {
88
+ this.pullNodesFromYjs(), this.pullEdgesFromYjs();
89
+ }
90
+ pullNodesFromYjs() {
91
+ const e = /* @__PURE__ */ new Map();
92
+ this.yNodes.forEach((n, r) => {
93
+ const s = n.toJSON();
94
+ (!s.position || typeof s.position != "object") && (s.position = { x: 0, y: 0 }), e.set(r, s);
95
+ });
96
+ const t = /* @__PURE__ */ new Set();
97
+ for (let n = 0; n < this.state.nodes.length; n++) {
98
+ const r = this.state.nodes[n];
99
+ t.add(r.id);
100
+ const s = e.get(r.id);
101
+ s && (s.position && !this._draggingNodeIds.has(r.id) && (r.position.x = s.position.x, r.position.y = s.position.y), s.data && (r.data = s.data));
102
+ }
103
+ e.forEach((n, r) => {
104
+ t.has(r) || this.state.nodes.push(n);
105
+ });
106
+ for (let n = this.state.nodes.length - 1; n >= 0; n--)
107
+ e.has(this.state.nodes[n].id) || this.state.nodes.splice(n, 1);
108
+ this.state._rebuildNodeMap?.();
109
+ }
110
+ pullEdgesFromYjs() {
111
+ const e = [];
112
+ this.yEdges.forEach((t) => {
113
+ e.push(t.toJSON());
114
+ }), this.state.edges.splice(0, this.state.edges.length, ...e), this.state._rebuildEdgeMap?.();
115
+ }
116
+ // -- Lifecycle --
117
+ destroy() {
118
+ this.destroyed = !0, this.yNodes.unobserveDeep(this.nodeObserver), this.yEdges.unobserveDeep(this.edgeObserver);
119
+ }
120
+ }
121
+ class R {
122
+ constructor(e, t) {
123
+ this.destroyed = !1, this._users = [], this._remoteStates = /* @__PURE__ */ new Map(), this._onChangeCallbacks = [], this.status = "connected", this.awareness = e, this.localUser = t, e.setLocalState({
124
+ user: t,
125
+ cursor: null,
126
+ selectedNodes: [],
127
+ viewport: { x: 0, y: 0, zoom: 1 }
128
+ }), this.changeHandler = () => {
129
+ this.destroyed || this.rebuildUsers();
130
+ }, e.on("change", this.changeHandler);
131
+ }
132
+ // -- Public API --
133
+ get me() {
134
+ return this.localUser;
135
+ }
136
+ get users() {
137
+ return this._users;
138
+ }
139
+ get userCount() {
140
+ return this._users.length + 1;
141
+ }
142
+ get connected() {
143
+ return !this.destroyed;
144
+ }
145
+ /** Get all remote awareness states (for cursor rendering). */
146
+ getRemoteStates() {
147
+ return this._remoteStates;
148
+ }
149
+ /** Subscribe to awareness changes. Returns unsubscribe function. */
150
+ onChange(e) {
151
+ return this._onChangeCallbacks.push(e), () => {
152
+ this._onChangeCallbacks = this._onChangeCallbacks.filter((t) => t !== e);
153
+ };
154
+ }
155
+ // -- Local state updates --
156
+ updateCursor(e) {
157
+ if (this.destroyed) return;
158
+ const t = this.awareness.getLocalState() ?? {};
159
+ this.awareness.setLocalState({ ...t, cursor: e });
160
+ }
161
+ updateSelection(e) {
162
+ if (this.destroyed) return;
163
+ const t = this.awareness.getLocalState() ?? {};
164
+ this.awareness.setLocalState({ ...t, selectedNodes: e });
165
+ }
166
+ updateViewport(e) {
167
+ if (this.destroyed) return;
168
+ const t = this.awareness.getLocalState() ?? {};
169
+ this.awareness.setLocalState({ ...t, viewport: e });
170
+ }
171
+ // -- Internal --
172
+ rebuildUsers() {
173
+ const e = this.awareness.getStates(), t = this.awareness.clientID, n = [];
174
+ this._remoteStates.clear(), e.forEach((r, s) => {
175
+ s !== t && r?.user && (n.push(r.user), this._remoteStates.set(s, r));
176
+ }), this._users = n;
177
+ for (const r of this._onChangeCallbacks) r();
178
+ }
179
+ // -- Lifecycle --
180
+ destroy() {
181
+ this.destroyed = !0, this.awareness.off("change", this.changeHandler), this.awareness.setLocalState(null), this._users = [], this._remoteStates.clear();
182
+ }
183
+ }
184
+ const g = "__alpineflow_collab_store__";
185
+ function F() {
186
+ return typeof globalThis < "u" ? (globalThis[g] || (globalThis[g] = /* @__PURE__ */ new WeakMap()), globalThis[g]) : /* @__PURE__ */ new WeakMap();
187
+ }
188
+ const P = F(), v = "flow-collab-cursor", A = "http://www.w3.org/2000/svg", M = "M0.5 0.5L15.5 11.5L8 12.5L5 21.5L0.5 0.5Z";
189
+ function Y(i, e) {
190
+ const t = document.createElement("div");
191
+ t.className = v, t.dataset.clientId = i, t.style.position = "absolute", t.style.left = "0", t.style.top = "0", t.style.pointerEvents = "none", t.style.zIndex = "10000", t.style.transition = "transform 0.1s ease-out", t.style.willChange = "transform";
192
+ const n = document.createElementNS(A, "svg");
193
+ n.setAttribute("width", "16"), n.setAttribute("height", "22"), n.setAttribute("viewBox", "0 0 16 22"), n.setAttribute("fill", "none"), n.style.display = "block", n.style.filter = "drop-shadow(0 1px 2px rgba(0,0,0,0.3))";
194
+ const r = document.createElementNS(A, "path");
195
+ r.setAttribute("d", M), r.setAttribute("fill", e.color), r.setAttribute("stroke", "white"), r.setAttribute("stroke-width", "1.5"), r.setAttribute("stroke-linejoin", "round"), r.classList.add("flow-collab-cursor-arrow"), n.appendChild(r), t.appendChild(n);
196
+ const s = document.createElement("span");
197
+ return s.className = "flow-collab-cursor-label", s.textContent = e.name, s.style.position = "absolute", s.style.left = "14px", s.style.top = "16px", s.style.background = e.color, s.style.color = "white", s.style.padding = "2px 8px", s.style.borderRadius = "4px", s.style.fontSize = "11px", s.style.fontWeight = "500", s.style.whiteSpace = "nowrap", s.style.lineHeight = "1.4", s.style.boxShadow = "0 1px 3px rgba(0,0,0,0.2)", t.appendChild(s), t;
198
+ }
199
+ function q(i, e) {
200
+ const t = i.querySelector(".flow-collab-cursor-arrow");
201
+ t && t.setAttribute("fill", e);
202
+ const n = i.querySelector(".flow-collab-cursor-label");
203
+ n && (n.style.background = e);
204
+ }
205
+ function W(i, e, t) {
206
+ const n = /* @__PURE__ */ new Map();
207
+ i.querySelectorAll(`.${v}`).forEach((s) => {
208
+ n.set(s.dataset.clientId, s);
209
+ });
210
+ const r = /* @__PURE__ */ new Set();
211
+ e.forEach((s, a) => {
212
+ if (!s.cursor)
213
+ return;
214
+ const o = String(a);
215
+ r.add(o);
216
+ let l = n.get(o);
217
+ l ? q(l, s.user.color) : (l = Y(o, s.user), i.appendChild(l)), l.style.transform = `translate(${s.cursor.x}px, ${s.cursor.y}px)`;
218
+ }), n.forEach((s, a) => {
219
+ r.has(a) || s.remove();
220
+ });
221
+ }
222
+ function J(i) {
223
+ i.directive("flow-cursors", (e, {}, { cleanup: t }) => {
224
+ const n = e.closest("[data-flow-canvas]");
225
+ if (!n) return;
226
+ const r = i.$data(n);
227
+ let s = null, a = null, o = !1;
228
+ function l() {
229
+ const f = P.get(n);
230
+ if (!f?.awareness) return !1;
231
+ const U = f.awareness;
232
+ function E() {
233
+ const L = U.getRemoteStates();
234
+ r.viewport?.zoom, W(e, L);
235
+ }
236
+ return E(), s = U.onChange(E), !0;
237
+ }
238
+ l() || (a = setInterval(() => {
239
+ (o || l()) && (clearInterval(a), a = null);
240
+ }, 50)), t(() => {
241
+ o = !0, a && clearInterval(a), s && s(), e.querySelectorAll(`.${v}`).forEach((f) => f.remove());
242
+ });
243
+ });
244
+ }
245
+ let _ = H, S = N, I = C;
246
+ function V(i) {
247
+ _ = i.applyUpdate, S = i.encodeStateAsUpdate, I = i.encodeStateVector;
248
+ }
249
+ function h(i) {
250
+ let e = "";
251
+ for (let t = 0; t < i.length; t++)
252
+ e += String.fromCharCode(i[t]);
253
+ return btoa(e);
254
+ }
255
+ function u(i) {
256
+ const e = atob(i), t = new Uint8Array(e.length);
257
+ for (let n = 0; n < e.length; n++)
258
+ t[n] = e.charCodeAt(n);
259
+ return t;
260
+ }
261
+ const p = "reverb-provider";
262
+ class G {
263
+ constructor(e) {
264
+ this.channel = null, this.doc = null, this.awareness = null, this.listeners = {}, this._connected = !1, this.updateHandler = null, this.awarenessHandler = null, this._saveTimer = null, this._saveDirty = !1, this.roomId = e.roomId, this.channelPattern = e.channel, this.user = e.user, this.stateUrl = e.stateUrl;
265
+ }
266
+ get connected() {
267
+ return this._connected;
268
+ }
269
+ connect(e, t) {
270
+ this.doc = e, this.awareness = t;
271
+ const n = this.channelPattern.replace("{roomId}", this.roomId), r = globalThis.Echo;
272
+ if (!r) {
273
+ console.warn("[alpineflow-collab] Laravel Echo not found. ReverbProvider requires Echo.");
274
+ return;
275
+ }
276
+ if (this.channel = r.private(n), this.channel.listenForWhisper("yjs-update", (s) => {
277
+ if (!this.doc) return;
278
+ const a = u(s.data);
279
+ _(this.doc, a, p);
280
+ }), this.channel.listenForWhisper("yjs-sync-request", (s) => {
281
+ if (!this.doc) return;
282
+ const a = u(s.sv), o = S(this.doc, a);
283
+ o.length > 2 && this.channel?.whisper("yjs-sync-response", { data: h(o) });
284
+ }), this.channel.listenForWhisper("yjs-sync-response", (s) => {
285
+ if (!this.doc) return;
286
+ const a = u(s.data);
287
+ _(this.doc, a, p);
288
+ }), this.channel.listenForWhisper("yjs-awareness", (s) => {
289
+ if (!this.awareness) return;
290
+ const a = u(s.data);
291
+ m(this.awareness, a, p);
292
+ }), this.updateHandler = (s, a) => {
293
+ a !== p && (this.channel?.whisper("yjs-update", { data: h(s) }), this._markDirty());
294
+ }, e.on("update", this.updateHandler), this.awarenessHandler = ({ added: s, updated: a }) => {
295
+ const o = [...s, ...a];
296
+ if (o.length === 0) return;
297
+ const l = b(t, o);
298
+ this.channel?.whisper("yjs-awareness", { data: h(l) });
299
+ }, t.on("update", this.awarenessHandler), this._connected = !0, this.emit("status", "connected"), this.stateUrl)
300
+ this.fetchInitialState();
301
+ else {
302
+ const s = I(e);
303
+ this.channel.whisper("yjs-sync-request", { sv: h(s) }), setTimeout(() => {
304
+ this.emit("sync", !0);
305
+ }, 1500);
306
+ }
307
+ }
308
+ disconnect() {
309
+ this.cleanupListeners(), this._connected = !1, this.emit("status", "disconnected");
310
+ }
311
+ destroy() {
312
+ this.cleanupListeners(), this.channel = null, this.doc = null, this.awareness = null, this._connected = !1, this.listeners = {};
313
+ }
314
+ on(e, t) {
315
+ (this.listeners[e] ??= /* @__PURE__ */ new Set()).add(t);
316
+ }
317
+ off(e, t) {
318
+ this.listeners[e]?.delete(t);
319
+ }
320
+ emit(e, t) {
321
+ this.listeners[e]?.forEach((n) => n(t));
322
+ }
323
+ cleanupListeners() {
324
+ this.doc && this.updateHandler && (this.doc.off("update", this.updateHandler), this.updateHandler = null), this.awareness && this.awarenessHandler && (this.awareness.off("update", this.awarenessHandler), this.awarenessHandler = null), this._saveTimer && (clearTimeout(this._saveTimer), this._saveTimer = null), this._saveDirty && this._saveStateNow();
325
+ }
326
+ /** Mark doc as dirty — will save to stateUrl within 5 seconds. */
327
+ _markDirty() {
328
+ this.stateUrl && (this._saveDirty = !0, this._saveTimer || (this._saveTimer = setTimeout(() => {
329
+ this._saveTimer = null, this._saveStateNow();
330
+ }, 5e3)));
331
+ }
332
+ /** Save current doc state to stateUrl. */
333
+ _saveStateNow() {
334
+ if (!(!this.stateUrl || !this.doc || !this._saveDirty)) {
335
+ this._saveDirty = !1;
336
+ try {
337
+ const e = S(this.doc), t = this.stateUrl.replace("{roomId}", this.roomId), n = typeof document < "u" ? document.querySelector('meta[name="csrf-token"]') : null, r = { "Content-Type": "application/json" };
338
+ n && (r["X-CSRF-TOKEN"] = n.getAttribute("content") || ""), fetch(t, {
339
+ method: "POST",
340
+ headers: r,
341
+ body: JSON.stringify({ state: h(e) })
342
+ }).catch(() => {
343
+ });
344
+ } catch {
345
+ }
346
+ }
347
+ }
348
+ async fetchInitialState() {
349
+ if (!(!this.stateUrl || !this.doc))
350
+ try {
351
+ const e = this.stateUrl.replace("{roomId}", this.roomId), t = await fetch(e);
352
+ if (!t.ok) return;
353
+ const n = await t.json();
354
+ if (n.state && this.doc) {
355
+ const r = u(n.state);
356
+ _(this.doc, r, p);
357
+ }
358
+ this.emit("sync", !0);
359
+ } catch {
360
+ }
361
+ }
362
+ }
363
+ class K {
364
+ constructor(e) {
365
+ this.wsProvider = null, this.listeners = {}, this._connected = !1, this.roomId = e.roomId, this.url = e.url, this.user = e.user;
366
+ }
367
+ get connected() {
368
+ return this._connected;
369
+ }
370
+ connect(e, t) {
371
+ this.wsProvider = new D(this.url, this.roomId, e, {
372
+ awareness: t
373
+ }), this.wsProvider.on("status", (n) => {
374
+ const r = n.status;
375
+ this._connected = r === "connected", this.emit("status", r);
376
+ }), this.wsProvider.on("sync", (n) => {
377
+ this.emit("sync", n);
378
+ });
379
+ }
380
+ disconnect() {
381
+ this.wsProvider?.disconnect(), this._connected = !1;
382
+ }
383
+ destroy() {
384
+ this.wsProvider?.destroy(), this.wsProvider = null, this._connected = !1, this.listeners = {};
385
+ }
386
+ on(e, t) {
387
+ (this.listeners[e] ??= /* @__PURE__ */ new Set()).add(t);
388
+ }
389
+ off(e, t) {
390
+ this.listeners[e]?.delete(t);
391
+ }
392
+ emit(e, t) {
393
+ this.listeners[e]?.forEach((n) => n(t));
394
+ }
395
+ }
396
+ class Z {
397
+ constructor(e) {
398
+ this.connected = !1, this.doc = null, this.awareness = null, this.peer = null, this._listeners = {}, this._synced = !1, this._docUpdateHandler = null, this._peerDocUpdateHandler = null, this._awarenessUpdateHandler = null, this._peerAwarenessUpdateHandler = null, this.roomId = e.roomId;
399
+ }
400
+ connect(e, t) {
401
+ this.doc = e, this.awareness = t, this.connected = !0, this._emit("status", "connected"), this.peer?.doc && this._setupSync();
402
+ }
403
+ disconnect() {
404
+ this.connected = !1, this._emit("status", "disconnected");
405
+ }
406
+ destroy() {
407
+ this.doc && this._docUpdateHandler && (this.doc.off("update", this._docUpdateHandler), this._docUpdateHandler = null), this.peer?.doc && this._peerDocUpdateHandler && (this.peer.doc.off("update", this._peerDocUpdateHandler), this._peerDocUpdateHandler = null), this.awareness && this._awarenessUpdateHandler && (this.awareness.off("update", this._awarenessUpdateHandler), this._awarenessUpdateHandler = null), this.peer?.awareness && this._peerAwarenessUpdateHandler && (this.peer.awareness.off("update", this._peerAwarenessUpdateHandler), this._peerAwarenessUpdateHandler = null), this.connected = !1, this._listeners = {};
408
+ }
409
+ on(e, t) {
410
+ (this._listeners[e] = this._listeners[e] || []).push(t);
411
+ }
412
+ off(e, t) {
413
+ this._listeners[e] = (this._listeners[e] || []).filter((n) => n !== t);
414
+ }
415
+ _emit(e, t) {
416
+ (this._listeners[e] || []).forEach((n) => n(t));
417
+ }
418
+ _setupSync() {
419
+ const e = this.peer;
420
+ if (!this.doc || !e?.doc || this._synced) return;
421
+ this._synced = !0, e._synced = !0;
422
+ const t = c.encodeStateAsUpdate(this.doc), n = c.encodeStateAsUpdate(e.doc);
423
+ if (c.applyUpdate(e.doc, t, "remote"), c.applyUpdate(this.doc, n, "remote"), this._docUpdateHandler = (r, s) => {
424
+ s !== "remote" && c.applyUpdate(e.doc, r, "remote");
425
+ }, this.doc.on("update", this._docUpdateHandler), this._peerDocUpdateHandler = (r, s) => {
426
+ s !== "remote" && c.applyUpdate(this.doc, r, "remote");
427
+ }, e.doc.on("update", this._peerDocUpdateHandler), this.awareness && e.awareness) {
428
+ const r = this.awareness, s = e.awareness;
429
+ this._awarenessUpdateHandler = (a) => {
430
+ const o = [...a.added, ...a.updated];
431
+ if (o.length === 0) return;
432
+ const l = b(r, o);
433
+ m(s, l, "remote");
434
+ }, r.on("update", this._awarenessUpdateHandler), this._peerAwarenessUpdateHandler = (a) => {
435
+ const o = [...a.added, ...a.updated];
436
+ if (o.length === 0) return;
437
+ const l = b(s, o);
438
+ m(r, l, "remote");
439
+ }, s.on("update", this._peerAwarenessUpdateHandler);
440
+ }
441
+ this._emit("sync", !0), e._emit("sync", !0);
442
+ }
443
+ }
444
+ function X(i, e) {
445
+ i.peer = e, e.peer = i;
446
+ }
447
+ function Q(i) {
448
+ J(i), V({ applyUpdate: H, encodeStateAsUpdate: N, encodeStateVector: C }), x("collab", {
449
+ Doc: T,
450
+ Awareness: j,
451
+ CollabBridge: k,
452
+ CollabAwareness: R
453
+ });
454
+ }
455
+ export {
456
+ R as CollabAwareness,
457
+ k as CollabBridge,
458
+ Z as InMemoryProvider,
459
+ G as ReverbProvider,
460
+ K as WebSocketProvider,
461
+ Q as default,
462
+ X as linkProviders,
463
+ J as registerFlowCursorsDirective
464
+ };
465
+ //# sourceMappingURL=alpineflow-collab.esm.js.map