@fragiola/flow-svelte 0.0.0-stage → 0.0.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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -2
  3. package/dist/components/background.svelte +150 -0
  4. package/dist/components/background.svelte.d.ts +25 -0
  5. package/dist/components/connection-line.svelte +120 -0
  6. package/dist/components/connection-line.svelte.d.ts +25 -0
  7. package/dist/components/controls.svelte +54 -0
  8. package/dist/components/controls.svelte.d.ts +17 -0
  9. package/dist/components/edge-label.svelte +126 -0
  10. package/dist/components/edge-label.svelte.d.ts +25 -0
  11. package/dist/components/edge-path.svelte +116 -0
  12. package/dist/components/edge-path.svelte.d.ts +27 -0
  13. package/dist/components/edge-toolbar.svelte +137 -0
  14. package/dist/components/edge-toolbar.svelte.d.ts +39 -0
  15. package/dist/components/edge.svelte +90 -0
  16. package/dist/components/edge.svelte.d.ts +41 -0
  17. package/dist/components/edges.svelte +242 -0
  18. package/dist/components/edges.svelte.d.ts +49 -0
  19. package/dist/components/fit-view.svelte +84 -0
  20. package/dist/components/fit-view.svelte.d.ts +32 -0
  21. package/dist/components/handle.svelte +96 -0
  22. package/dist/components/handle.svelte.d.ts +17 -0
  23. package/dist/components/node-toolbar.svelte +153 -0
  24. package/dist/components/node-toolbar.svelte.d.ts +42 -0
  25. package/dist/components/node.svelte +73 -0
  26. package/dist/components/node.svelte.d.ts +42 -0
  27. package/dist/components/nodes-selection.svelte +102 -0
  28. package/dist/components/nodes-selection.svelte.d.ts +26 -0
  29. package/dist/components/nodes.svelte +108 -0
  30. package/dist/components/nodes.svelte.d.ts +45 -0
  31. package/dist/components/reconnect-anchor.svelte +119 -0
  32. package/dist/components/reconnect-anchor.svelte.d.ts +26 -0
  33. package/dist/components/root.svelte +698 -0
  34. package/dist/components/root.svelte.d.ts +106 -0
  35. package/dist/components/selection-box.svelte +91 -0
  36. package/dist/components/selection-box.svelte.d.ts +20 -0
  37. package/dist/components/toggle-interactive.svelte +98 -0
  38. package/dist/components/toggle-interactive.svelte.d.ts +25 -0
  39. package/dist/components/viewport.svelte +108 -0
  40. package/dist/components/viewport.svelte.d.ts +16 -0
  41. package/dist/components/zoom-in.svelte +65 -0
  42. package/dist/components/zoom-in.svelte.d.ts +18 -0
  43. package/dist/components/zoom-out.svelte +65 -0
  44. package/dist/components/zoom-out.svelte.d.ts +18 -0
  45. package/dist/connection/index.d.ts +1 -0
  46. package/dist/connection/index.js +3 -0
  47. package/dist/context.d.ts +71 -0
  48. package/dist/context.js +81 -0
  49. package/dist/drag/index.d.ts +1 -0
  50. package/dist/drag/index.js +3 -0
  51. package/dist/index.d.ts +45 -0
  52. package/dist/index.js +25 -0
  53. package/dist/keyboard/index.d.ts +1 -0
  54. package/dist/keyboard/index.js +3 -0
  55. package/dist/minimap/index.d.ts +4 -0
  56. package/dist/minimap/index.js +7 -0
  57. package/dist/minimap/mini-map-context.d.ts +7 -0
  58. package/dist/minimap/mini-map-context.js +13 -0
  59. package/dist/minimap/mini-map-mask.svelte +65 -0
  60. package/dist/minimap/mini-map-mask.svelte.d.ts +19 -0
  61. package/dist/minimap/mini-map-node.svelte +88 -0
  62. package/dist/minimap/mini-map-node.svelte.d.ts +17 -0
  63. package/dist/minimap/mini-map.svelte +188 -0
  64. package/dist/minimap/mini-map.svelte.d.ts +39 -0
  65. package/dist/parts.d.ts +21 -0
  66. package/dist/parts.js +24 -0
  67. package/dist/reconnection/index.d.ts +1 -0
  68. package/dist/reconnection/index.js +3 -0
  69. package/dist/resize/index.d.ts +3 -0
  70. package/dist/resize/index.js +5 -0
  71. package/dist/resize/node-resizer.svelte +134 -0
  72. package/dist/resize/node-resizer.svelte.d.ts +36 -0
  73. package/dist/resize/resize-handle.svelte +192 -0
  74. package/dist/resize/resize-handle.svelte.d.ts +44 -0
  75. package/dist/runes/create-flow-ref.svelte.d.ts +32 -0
  76. package/dist/runes/create-flow-ref.svelte.js +32 -0
  77. package/dist/runes/internal.svelte.d.ts +31 -0
  78. package/dist/runes/internal.svelte.js +63 -0
  79. package/dist/runes/use-connection.svelte.d.ts +8 -0
  80. package/dist/runes/use-connection.svelte.js +18 -0
  81. package/dist/runes/use-control-button.svelte.d.ts +16 -0
  82. package/dist/runes/use-control-button.svelte.js +41 -0
  83. package/dist/runes/use-edge.svelte.d.ts +48 -0
  84. package/dist/runes/use-edge.svelte.js +98 -0
  85. package/dist/runes/use-edges.svelte.d.ts +4 -0
  86. package/dist/runes/use-edges.svelte.js +7 -0
  87. package/dist/runes/use-flow-ref.svelte.d.ts +18 -0
  88. package/dist/runes/use-flow-ref.svelte.js +19 -0
  89. package/dist/runes/use-flow-store.svelte.d.ts +13 -0
  90. package/dist/runes/use-flow-store.svelte.js +18 -0
  91. package/dist/runes/use-flow.svelte.d.ts +22 -0
  92. package/dist/runes/use-flow.svelte.js +18 -0
  93. package/dist/runes/use-handle.svelte.d.ts +56 -0
  94. package/dist/runes/use-handle.svelte.js +94 -0
  95. package/dist/runes/use-internal-node.svelte.d.ts +10 -0
  96. package/dist/runes/use-internal-node.svelte.js +16 -0
  97. package/dist/runes/use-key-press.svelte.d.ts +16 -0
  98. package/dist/runes/use-key-press.svelte.js +45 -0
  99. package/dist/runes/use-node-connections.svelte.d.ts +18 -0
  100. package/dist/runes/use-node-connections.svelte.js +30 -0
  101. package/dist/runes/use-node-id.svelte.d.ts +5 -0
  102. package/dist/runes/use-node-id.svelte.js +8 -0
  103. package/dist/runes/use-node.svelte.d.ts +47 -0
  104. package/dist/runes/use-node.svelte.js +122 -0
  105. package/dist/runes/use-nodes-data.svelte.d.ts +10 -0
  106. package/dist/runes/use-nodes-data.svelte.js +20 -0
  107. package/dist/runes/use-nodes.svelte.d.ts +4 -0
  108. package/dist/runes/use-nodes.svelte.js +7 -0
  109. package/dist/runes/use-on-viewport-change.svelte.d.ts +17 -0
  110. package/dist/runes/use-on-viewport-change.svelte.js +28 -0
  111. package/dist/runes/use-selection.svelte.d.ts +12 -0
  112. package/dist/runes/use-selection.svelte.js +19 -0
  113. package/dist/runes/use-viewport.svelte.d.ts +7 -0
  114. package/dist/runes/use-viewport.svelte.js +10 -0
  115. package/dist/selection/index.d.ts +1 -0
  116. package/dist/selection/index.js +3 -0
  117. package/dist/subflows/index.d.ts +1 -0
  118. package/dist/subflows/index.js +3 -0
  119. package/dist/typed.d.ts +32 -0
  120. package/dist/typed.js +15 -0
  121. package/dist/utils/engine-facade.d.ts +11 -0
  122. package/dist/utils/engine-facade.js +64 -0
  123. package/dist/utils/flow-store.svelte.d.ts +39 -0
  124. package/dist/utils/flow-store.svelte.js +133 -0
  125. package/dist/utils/merge-props.d.ts +8 -0
  126. package/dist/utils/merge-props.js +33 -0
  127. package/dist/utils/plain.svelte.d.ts +12 -0
  128. package/dist/utils/plain.svelte.js +44 -0
  129. package/dist/utils/portal-content.svelte +8 -0
  130. package/dist/utils/portal-content.svelte.d.ts +7 -0
  131. package/dist/utils/portal.svelte +34 -0
  132. package/dist/utils/portal.svelte.d.ts +8 -0
  133. package/dist/utils/render.d.ts +93 -0
  134. package/dist/utils/render.js +87 -0
  135. package/dist/utils/shallow-equal.d.ts +5 -0
  136. package/dist/utils/shallow-equal.js +32 -0
  137. package/package.json +105 -3
@@ -0,0 +1,133 @@
1
+ import { untrack } from "svelte";
2
+ /** A counter its readers depend on. */
3
+ class Counter {
4
+ value = $state(0);
5
+ }
6
+ const keyOf = (entity) => `${entity.kind}\u0000${entity.id}`;
7
+ /** @internal the store of a root (its model a getter: another `model` prop is followed) */
8
+ export function createFlowStore(model) {
9
+ const view = new Counter();
10
+ const entity = new Counter();
11
+ const measure = new Counter();
12
+ const records = new Map();
13
+ let engine = null;
14
+ const tokenOf = ({ kind, id }) => !engine
15
+ ? []
16
+ : kind === "node"
17
+ ? [
18
+ engine.get("node-rect-by", { nodeId: id }),
19
+ engine.is("node-measured", { nodeId: id }),
20
+ ]
21
+ : [engine.get("edge-path-by", { edgeId: id })];
22
+ /** A change: of the view only, only a measurement, or of everything. */
23
+ const tell = (kind) => {
24
+ view.value++;
25
+ if (kind === "view")
26
+ return;
27
+ if (kind === "entity") {
28
+ for (const record of records.values())
29
+ record.token = undefined;
30
+ entity.value++;
31
+ return;
32
+ }
33
+ measure.value++;
34
+ for (const record of records.values()) {
35
+ const token = tokenOf(record.entity);
36
+ const was = record.token;
37
+ const same = was !== undefined &&
38
+ token.length === was.length &&
39
+ token.every((value, i) => Object.is(value, was[i]));
40
+ if (same)
41
+ continue;
42
+ record.token = token;
43
+ record.counter.value++;
44
+ }
45
+ };
46
+ // a commit that keeps both lists changes no node's or edge's own view (the lists the store
47
+ // starts from: the model's when it is made)
48
+ const listsOf = (current) => ({
49
+ model: current,
50
+ nodes: current.get("all-nodes"),
51
+ edges: current.get("all-edges"),
52
+ });
53
+ let lists = untrack(() => listsOf(model()));
54
+ return {
55
+ get view() {
56
+ return view.value;
57
+ },
58
+ get records() {
59
+ return records.size;
60
+ },
61
+ track(scope, of) {
62
+ if (scope === "view") {
63
+ view.value;
64
+ return;
65
+ }
66
+ entity.value;
67
+ // An entity reader without an entity (handle, resizer, minimap node attributes) does
68
+ // not re-read on a measurement, unlike React's and Vue's: none of those attributes
69
+ // depends on one today, and re-reading them would re-render every handle on a zoom
70
+ // (render-counts test). A feature that adds a measured attribute must track `measure`.
71
+ if (of)
72
+ (records.get(keyOf(of))?.counter ?? measure).value;
73
+ },
74
+ acquire(of) {
75
+ const key = keyOf(of);
76
+ let record = records.get(key);
77
+ if (!record) {
78
+ record = {
79
+ entity: { kind: of.kind, id: of.id },
80
+ counter: new Counter(),
81
+ readers: 0,
82
+ token: tokenOf(of),
83
+ };
84
+ records.set(key, record);
85
+ }
86
+ const held = record;
87
+ held.readers += 1;
88
+ let released = false;
89
+ return () => {
90
+ if (released)
91
+ return;
92
+ released = true;
93
+ held.readers -= 1;
94
+ if (held.readers <= 0 && records.get(key) === held) {
95
+ records.delete(key);
96
+ }
97
+ };
98
+ },
99
+ commit() {
100
+ const next = listsOf(model());
101
+ const changed = lists.model !== next.model ||
102
+ lists.nodes !== next.nodes ||
103
+ lists.edges !== next.edges;
104
+ lists = next;
105
+ tell(changed ? "entity" : "view");
106
+ },
107
+ attach(created) {
108
+ engine = created;
109
+ // the measurements before the engine counted nothing: read again at the next one
110
+ for (const record of records.values())
111
+ record.token = undefined;
112
+ // several render levels give the nodes ranks that follow the drawn edges, so the view
113
+ const layered = () => created.get("render-layers").length > 1;
114
+ let wasLayered = layered();
115
+ const stop = created.adapter.subscribe((change) => {
116
+ const isLayered = layered();
117
+ const levels = isLayered || wasLayered;
118
+ wasLayered = isLayered;
119
+ if (change.gesture || levels)
120
+ tell("entity");
121
+ else if (change.measured)
122
+ tell(change.viewport ? "entity" : "measured");
123
+ else
124
+ tell("view");
125
+ });
126
+ return () => {
127
+ stop();
128
+ if (engine === created)
129
+ engine = null;
130
+ };
131
+ },
132
+ };
133
+ }
@@ -0,0 +1,8 @@
1
+ type AnyProps = Record<string | symbol, unknown>;
2
+ /**
3
+ * Merges `external` props over `internal` ones: plain props from `external` win, event handlers
4
+ * are composed (internal first, then external), classes are joined, and symbol-keyed props
5
+ * (attachments) of both are kept.
6
+ */
7
+ export declare function mergeProps(internal: AnyProps, external: AnyProps): AnyProps;
8
+ export {};
@@ -0,0 +1,33 @@
1
+ function isHandler(key, value) {
2
+ return (typeof key === "string" &&
3
+ /^on[a-z]/.test(key) &&
4
+ typeof value === "function");
5
+ }
6
+ /**
7
+ * Merges `external` props over `internal` ones: plain props from `external` win, event handlers
8
+ * are composed (internal first, then external), classes are joined, and symbol-keyed props
9
+ * (attachments) of both are kept.
10
+ */
11
+ export function mergeProps(internal, external) {
12
+ const merged = { ...internal };
13
+ for (const key of Reflect.ownKeys(external)) {
14
+ const value = external[key];
15
+ const current = merged[key];
16
+ if (value === undefined) {
17
+ continue;
18
+ }
19
+ if (isHandler(key, value) && isHandler(key, current)) {
20
+ merged[key] = (...args) => {
21
+ current(...args);
22
+ value(...args);
23
+ };
24
+ }
25
+ else if (key === "class" && current !== undefined) {
26
+ merged.class = [current, value];
27
+ }
28
+ else {
29
+ merged[key] = value;
30
+ }
31
+ }
32
+ return merged;
33
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A value the app owns, without its proxy (a frozen value is taken as it is). Plain objects and
3
+ * arrays are copied here, key by key (a proxy read through gives its values), the frozen parts
4
+ * shared; anything else goes to `$state.snapshot`. Not `$state.snapshot` for the whole value: it
5
+ * clones each primitive with `structuredClone` (#54: ~250 ms of a 10 000-node open). Cyclic data
6
+ * is not supported (the model refuses it anyway), and a shared object comes out as two copies.
7
+ */
8
+ export declare function plain<V>(value: V): V;
9
+ /** A list the app owns, as the model takes it: plain entries, the frozen ones shared. */
10
+ export declare function plainList<E extends object>(list: readonly E[] | undefined): readonly E[] | undefined;
11
+ /** Warns once per message and root: misuse that the root ignores. */
12
+ export declare function warnOnce(): (message: string) => void;
@@ -0,0 +1,44 @@
1
+ // What the app gives, as the core takes it: plain data, never a Svelte proxy (S4). A list the app
2
+ // keeps in a deep `$state` is a proxy; the model holds frozen plain data, and a frozen list or
3
+ // entry (the model's own, written back to `bind:nodes`) is taken as it is.
4
+ /**
5
+ * A value the app owns, without its proxy (a frozen value is taken as it is). Plain objects and
6
+ * arrays are copied here, key by key (a proxy read through gives its values), the frozen parts
7
+ * shared; anything else goes to `$state.snapshot`. Not `$state.snapshot` for the whole value: it
8
+ * clones each primitive with `structuredClone` (#54: ~250 ms of a 10 000-node open). Cyclic data
9
+ * is not supported (the model refuses it anyway), and a shared object comes out as two copies.
10
+ */
11
+ export function plain(value) {
12
+ return copy(value);
13
+ }
14
+ function copy(value) {
15
+ if (value === null || typeof value !== "object" || Object.isFrozen(value)) {
16
+ return value;
17
+ }
18
+ if (Array.isArray(value))
19
+ return value.map(copy);
20
+ if (Object.getPrototypeOf(value) === Object.prototype) {
21
+ const result = {};
22
+ for (const key of Object.keys(value)) {
23
+ result[key] = copy(value[key]);
24
+ }
25
+ return result;
26
+ }
27
+ return $state.snapshot(value);
28
+ }
29
+ /** A list the app owns, as the model takes it: plain entries, the frozen ones shared. */
30
+ export function plainList(list) {
31
+ if (list === undefined)
32
+ return undefined;
33
+ return Object.isFrozen(list) ? list : list.map((entry) => plain(entry));
34
+ }
35
+ /** Warns once per message and root: misuse that the root ignores. */
36
+ export function warnOnce() {
37
+ const warned = new Set();
38
+ return (message) => {
39
+ if (warned.has(message))
40
+ return;
41
+ warned.add(message);
42
+ console.warn(`[@fragiola/flow-svelte] ${message}`);
43
+ };
44
+ }
@@ -0,0 +1,8 @@
1
+ <!-- What `Portal` mounts in its target: its children. -->
2
+ <script lang="ts">
3
+ import type { Snippet } from "svelte";
4
+
5
+ let { children }: { children: Snippet } = $props();
6
+ </script>
7
+
8
+ {@render children()}
@@ -0,0 +1,7 @@
1
+ import type { Snippet } from "svelte";
2
+ type $$ComponentProps = {
3
+ children: Snippet;
4
+ };
5
+ declare const PortalContent: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type PortalContent = ReturnType<typeof PortalContent>;
7
+ export default PortalContent;
@@ -0,0 +1,34 @@
1
+ <!--
2
+ Renders its children into another element (`target`): the edges' HTML layer for an edge label
3
+ (SVG holds no HTML), the root for a node toolbar (outside the zoom). Svelte has no portal: the
4
+ content is mounted there as its own component, with every context of this place
5
+ (`getAllContexts`), and unmounted when this goes or the target changes. Nothing renders where
6
+ it is written, and nothing on the server (as React's portal before its target exists).
7
+ -->
8
+ <script lang="ts">
9
+ import { getAllContexts, mount, type Snippet, unmount } from "svelte";
10
+ import PortalContent from "./portal-content.svelte";
11
+
12
+ let {
13
+ target,
14
+ children,
15
+ }: { target: Element | null | undefined; children: Snippet } = $props();
16
+
17
+ const contexts = getAllContexts();
18
+ $effect(() => {
19
+ const into = target;
20
+ if (!into) return;
21
+ const content = mount(PortalContent, {
22
+ target: into,
23
+ props: {
24
+ get children() {
25
+ return children;
26
+ },
27
+ },
28
+ context: contexts,
29
+ });
30
+ return () => {
31
+ void unmount(content);
32
+ };
33
+ });
34
+ </script>
@@ -0,0 +1,8 @@
1
+ import { type Snippet } from "svelte";
2
+ type $$ComponentProps = {
3
+ target: Element | null | undefined;
4
+ children: Snippet;
5
+ };
6
+ declare const Portal: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type Portal = ReturnType<typeof Portal>;
8
+ export default Portal;
@@ -0,0 +1,93 @@
1
+ import type { Snippet } from "svelte";
2
+ import { type Attachment } from "svelte/attachments";
3
+ import type { ClassValue, HTMLAttributes, HTMLButtonAttributes, SVGAttributes } from "svelte/elements";
4
+ /** A style as a primitive takes it: a CSS string or a record of properties (camelCase or kebab-case). */
5
+ export type StyleValue = string | Readonly<Record<string, string | number | null | undefined>>;
6
+ /** The structural style a primitive writes: kebab-case properties (`undefined` removes one). */
7
+ export type StyleRecord = Readonly<Record<string, string | number | undefined>>;
8
+ /**
9
+ * Props a `render` snippet receives as `props`: spread them onto the element it renders
10
+ * (`<section {...props}>`). They carry the primitive's attachment, which registers the element.
11
+ */
12
+ export type RenderedProps<E extends Element = HTMLElement> = (E extends SVGElement ? SVGAttributes<E> : HTMLAttributes<E>) & {
13
+ [dataAttribute: `data-${string}`]: string | undefined;
14
+ };
15
+ /** What a primitive's `render` snippet receives. */
16
+ export interface RenderSnippetProps<State, E extends Element = HTMLElement> {
17
+ /** what goes on your element (`{...props}`): attributes, handlers, style, the attachment */
18
+ props: RenderedProps<E>;
19
+ /** the primitive's state */
20
+ state: State;
21
+ /** the primitive's content: render it inside your element (`{@render children()}`) */
22
+ children: Snippet;
23
+ }
24
+ /** Replaces the element a primitive renders (never `asChild`): a snippet of `{ props, state, children }`. */
25
+ export type RenderSnippet<State, E extends Element = HTMLElement> = Snippet<[
26
+ RenderSnippetProps<State, E>
27
+ ]>;
28
+ /** The props every primitive accepts on top of the element's own. */
29
+ export interface PrimitiveProps<State, E extends Element = HTMLElement> {
30
+ /** replaces the rendered element (never `asChild`) */
31
+ render?: RenderSnippet<State, E> | undefined;
32
+ /** a class (any of Svelte's forms), or a function of the primitive's state returning one */
33
+ class?: ClassValue | ((state: State) => ClassValue) | null | undefined;
34
+ /**
35
+ * a style (a CSS string or a record), or a function of the primitive's state returning one.
36
+ * Structural keys the primitive sets (position, its place, its size) always win.
37
+ */
38
+ style?: StyleValue | ((state: State) => StyleValue | undefined) | undefined;
39
+ /** the rendered element, once mounted (`bind:ref`) */
40
+ ref?: E | null | undefined;
41
+ }
42
+ type ElementAttributes<E extends Element> = E extends SVGElement ? SVGAttributes<E> : E extends HTMLButtonElement ? HTMLButtonAttributes : HTMLAttributes<E>;
43
+ /** The props of a primitive rendering an element `E` (a `div` by default). */
44
+ export type ElementPrimitiveProps<State, E extends Element = HTMLDivElement> = PrimitiveProps<State, E> & Omit<ElementAttributes<E>, "class" | "style" | "children">;
45
+ /** The props of a primitive that renders a `div` by default. */
46
+ export type DivPrimitiveProps<State> = ElementPrimitiveProps<State, HTMLDivElement>;
47
+ /** The props of a primitive that renders a `button` by default. */
48
+ export type ButtonPrimitiveProps<State> = ElementPrimitiveProps<State, HTMLButtonElement>;
49
+ /** The props of a primitive that renders an SVG element `E` by default. */
50
+ export type SvgPrimitiveProps<State, E extends SVGElement> = ElementPrimitiveProps<State, E>;
51
+ /** A part's `data-*` attributes, as a rune's `props` carry them. */
52
+ export type DataAttributes = {
53
+ readonly [name: `data-${string}`]: string | undefined;
54
+ };
55
+ /**
56
+ * A consumer's style (a CSS string or a record) as one record of kebab-case properties. A record's
57
+ * `undefined` (or `null`) key is kept as `undefined`, so it removes the part's default key, as in
58
+ * React and Vue.
59
+ */
60
+ export declare function styleRecord(style: StyleValue | null | undefined): Record<string, string | number | undefined>;
61
+ /** A record of kebab-case properties as a CSS string (`undefined`: nothing). */
62
+ export declare function styleString(record: Readonly<Record<string, string | number | undefined>>): string | undefined;
63
+ /** A length in pixels for an inline style. */
64
+ export declare function px(value: number): string;
65
+ interface ElementOptions<State> {
66
+ /** the consumer's props: `class`, `style`, handlers, ARIA, attachments, … */
67
+ rest: object;
68
+ /** the consumer's `class` (a value or a function of the state) */
69
+ className?: PrimitiveProps<State>["class"];
70
+ /** the consumer's `style` (a value or a function of the state) */
71
+ style?: PrimitiveProps<State>["style"];
72
+ state: State;
73
+ /** the primitive's own props: data-*, handlers, SVG attributes, its attachment */
74
+ own: object;
75
+ /** structural style: always wins over the consumer's */
76
+ structural?: StyleRecord | undefined;
77
+ /** a default style the consumer's overrides */
78
+ baseStyle?: StyleRecord | undefined;
79
+ }
80
+ /**
81
+ * The props of a primitive's element: the consumer's over the primitive's (handlers composed,
82
+ * internal first; attachments kept), the class and the style resolved against the state, the
83
+ * structural style keys over the consumer's (an `undefined` one removes the consumer's), the
84
+ * consumer's over the default ones (an `undefined` one removes the default).
85
+ */
86
+ export declare function elementProps<State, E extends Element = HTMLElement>(options: ElementOptions<State>): RenderedProps<E>;
87
+ /**
88
+ * The attachment that gives the consumer's `ref` (`bind:ref`) the element, as the props a
89
+ * primitive spreads: it runs once the element is mounted, whether the element is the primitive's
90
+ * own or the one its `render` snippet renders, and gives `null` when it goes.
91
+ */
92
+ export declare function refProps(set: (element: Element | null) => void): Record<symbol, Attachment<Element>>;
93
+ export {};
@@ -0,0 +1,87 @@
1
+ import { createAttachmentKey } from "svelte/attachments";
2
+ import { mergeProps } from "./merge-props.js";
3
+ /** `fontSize` → `font-size` (a custom property and a kebab-case name stay). */
4
+ function cssName(name) {
5
+ return name.startsWith("--")
6
+ ? name
7
+ : name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
8
+ }
9
+ /**
10
+ * A consumer's style (a CSS string or a record) as one record of kebab-case properties. A record's
11
+ * `undefined` (or `null`) key is kept as `undefined`, so it removes the part's default key, as in
12
+ * React and Vue.
13
+ */
14
+ export function styleRecord(style) {
15
+ const result = {};
16
+ if (typeof style === "string") {
17
+ for (const declaration of style.split(/;(?![^(]*\))/g)) {
18
+ const index = declaration.indexOf(":");
19
+ if (index > 0) {
20
+ result[cssName(declaration.slice(0, index).trim())] =
21
+ declaration.slice(index + 1).trim();
22
+ }
23
+ }
24
+ }
25
+ else if (style) {
26
+ for (const [name, value] of Object.entries(style)) {
27
+ result[cssName(name)] = value ?? undefined;
28
+ }
29
+ }
30
+ return result;
31
+ }
32
+ /** A record of kebab-case properties as a CSS string (`undefined`: nothing). */
33
+ export function styleString(record) {
34
+ const declarations = Object.entries(record)
35
+ .filter(([, value]) => value !== undefined)
36
+ .map(([name, value]) => `${name}: ${value}`);
37
+ return declarations.length > 0 ? declarations.join("; ") : undefined;
38
+ }
39
+ /** A length in pixels for an inline style. */
40
+ export function px(value) {
41
+ return `${value}px`;
42
+ }
43
+ /**
44
+ * The props of a primitive's element: the consumer's over the primitive's (handlers composed,
45
+ * internal first; attachments kept), the class and the style resolved against the state, the
46
+ * structural style keys over the consumer's (an `undefined` one removes the consumer's), the
47
+ * consumer's over the default ones (an `undefined` one removes the default).
48
+ */
49
+ export function elementProps(options) {
50
+ const { state } = options;
51
+ const props = mergeProps(options.own, options.rest);
52
+ const className = typeof options.className === "function"
53
+ ? options.className(state)
54
+ : options.className;
55
+ if (className !== undefined && className !== null) {
56
+ props.class = className;
57
+ }
58
+ const consumer = typeof options.style === "function"
59
+ ? options.style(state)
60
+ : options.style;
61
+ const style = {
62
+ ...options.baseStyle,
63
+ ...styleRecord(consumer),
64
+ ...options.structural,
65
+ };
66
+ const css = styleString(style);
67
+ if (css !== undefined) {
68
+ props.style = css;
69
+ }
70
+ else {
71
+ delete props.style;
72
+ }
73
+ return props;
74
+ }
75
+ /**
76
+ * The attachment that gives the consumer's `ref` (`bind:ref`) the element, as the props a
77
+ * primitive spreads: it runs once the element is mounted, whether the element is the primitive's
78
+ * own or the one its `render` snippet renders, and gives `null` when it goes.
79
+ */
80
+ export function refProps(set) {
81
+ return {
82
+ [createAttachmentKey()]: (element) => {
83
+ set(element);
84
+ return () => set(null);
85
+ },
86
+ };
87
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Whether two records (a part's state) hold the same values, a nested record or array compared by
3
+ * its own entries: what decides that a part does not re-render.
4
+ */
5
+ export declare function shallowEqual(a: Readonly<Record<string, unknown>> | undefined, b: Readonly<Record<string, unknown>> | undefined): boolean;
@@ -0,0 +1,32 @@
1
+ // The React adapter's (packages/react/src/utils/shallow-equal.ts, itself from Splitter): nested
2
+ // records compared one level down (a part's attributes, its rect).
3
+ function same(a, b) {
4
+ if (Object.is(a, b))
5
+ return true;
6
+ if (typeof a !== "object" ||
7
+ typeof b !== "object" ||
8
+ a === null ||
9
+ b === null ||
10
+ Array.isArray(a) !== Array.isArray(b)) {
11
+ return false;
12
+ }
13
+ const aRecord = a;
14
+ const bRecord = b;
15
+ const keys = Object.keys(aRecord);
16
+ return (keys.length === Object.keys(bRecord).length &&
17
+ keys.every((key) => Object.hasOwn(bRecord, key) &&
18
+ Object.is(aRecord[key], bRecord[key])));
19
+ }
20
+ /**
21
+ * Whether two records (a part's state) hold the same values, a nested record or array compared by
22
+ * its own entries: what decides that a part does not re-render.
23
+ */
24
+ export function shallowEqual(a, b) {
25
+ if (a === b)
26
+ return true;
27
+ if (!a || !b)
28
+ return false;
29
+ const keys = Object.keys(a);
30
+ return (keys.length === Object.keys(b).length &&
31
+ keys.every((key) => Object.hasOwn(b, key) && same(a[key], b[key])));
32
+ }
package/package.json CHANGED
@@ -1,6 +1,108 @@
1
1
  {
2
2
  "name": "@fragiola/flow-svelte",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.0",
4
+ "description": "Composable, unstyled Svelte 5 primitives for @fragiola/flow: node-based editors and diagrams (nodes, edges, handles, connections, a pannable and zoomable viewport) styled entirely by you.",
5
+ "keywords": [
6
+ "svelte",
7
+ "flow",
8
+ "node-editor",
9
+ "diagram",
10
+ "graph",
11
+ "headless"
12
+ ],
13
+ "license": "MIT",
14
+ "type": "module",
15
+ "author": {
16
+ "name": "Mauro de Souza",
17
+ "email": "maurodesouza.me@gmail.com",
18
+ "url": "https://github.com/maurodesouza"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/fragiola/flow.git",
23
+ "directory": "packages/svelte"
24
+ },
25
+ "homepage": "https://fragiola.com/flow",
26
+ "bugs": {
27
+ "url": "https://github.com/fragiola/flow/issues"
28
+ },
29
+ "sideEffects": false,
30
+ "svelte": "./dist/index.js",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "svelte": "./dist/index.js",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "./selection": {
38
+ "types": "./dist/selection/index.d.ts",
39
+ "svelte": "./dist/selection/index.js",
40
+ "default": "./dist/selection/index.js"
41
+ },
42
+ "./subflows": {
43
+ "types": "./dist/subflows/index.d.ts",
44
+ "svelte": "./dist/subflows/index.js",
45
+ "default": "./dist/subflows/index.js"
46
+ },
47
+ "./drag": {
48
+ "types": "./dist/drag/index.d.ts",
49
+ "svelte": "./dist/drag/index.js",
50
+ "default": "./dist/drag/index.js"
51
+ },
52
+ "./resize": {
53
+ "types": "./dist/resize/index.d.ts",
54
+ "svelte": "./dist/resize/index.js",
55
+ "default": "./dist/resize/index.js"
56
+ },
57
+ "./connection": {
58
+ "types": "./dist/connection/index.d.ts",
59
+ "svelte": "./dist/connection/index.js",
60
+ "default": "./dist/connection/index.js"
61
+ },
62
+ "./reconnection": {
63
+ "types": "./dist/reconnection/index.d.ts",
64
+ "svelte": "./dist/reconnection/index.js",
65
+ "default": "./dist/reconnection/index.js"
66
+ },
67
+ "./keyboard": {
68
+ "types": "./dist/keyboard/index.d.ts",
69
+ "svelte": "./dist/keyboard/index.js",
70
+ "default": "./dist/keyboard/index.js"
71
+ },
72
+ "./minimap": {
73
+ "types": "./dist/minimap/index.d.ts",
74
+ "svelte": "./dist/minimap/index.js",
75
+ "default": "./dist/minimap/index.js"
76
+ },
77
+ "./package.json": "./package.json"
78
+ },
79
+ "files": [
80
+ "dist",
81
+ "!dist/**/*.test.*",
82
+ "README.md",
83
+ "LICENSE"
84
+ ],
85
+ "dependencies": {
86
+ "@fragiola/flow": "0.0.0"
87
+ },
88
+ "peerDependencies": {
89
+ "svelte": "^5.29.0"
90
+ },
91
+ "devDependencies": {
92
+ "@sveltejs/package": "3.0.2",
93
+ "@sveltejs/vite-plugin-svelte": "7.3.1",
94
+ "@testing-library/jest-dom": "7.0.1",
95
+ "@testing-library/svelte": "5.4.2",
96
+ "jsdom": "30.1.1",
97
+ "svelte": "5.57.3",
98
+ "svelte-check": "4.7.8",
99
+ "typescript": "6.0.3",
100
+ "vite": "8.3.1",
101
+ "vitest": "5.0.2"
102
+ },
103
+ "scripts": {
104
+ "build": "svelte-package --input src --output dist --tsconfig tsconfig.build.json",
105
+ "typecheck": "svelte-check --tsconfig tsconfig.json --fail-on-warnings",
106
+ "test": "vitest run"
107
+ }
6
108
  }