@pixerate/editor-svelte 0.208.2 → 0.209.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/AnimatedEdge.svelte +76 -0
- package/dist/canvas/AnimatedEdge.svelte.d.ts +32 -0
- package/dist/canvas/EdgeAnimation.svelte +97 -0
- package/dist/canvas/EdgeAnimation.svelte.d.ts +16 -0
- package/dist/canvas/index.d.ts +4 -0
- package/dist/canvas/index.js +5 -0
- package/dist/canvas/prefersReducedMotion.svelte.d.ts +7 -0
- package/dist/canvas/prefersReducedMotion.svelte.js +22 -0
- package/package.json +2 -2
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
getCanvasEdgeAnimation,
|
|
4
|
+
getCanvasEdgePath,
|
|
5
|
+
resolveCanvasEdgeAnimation,
|
|
6
|
+
type CanvasAnimatedEdgePathType,
|
|
7
|
+
type CanvasEdgeAnimation,
|
|
8
|
+
type Position
|
|
9
|
+
} from '@pixerate/editor/canvas';
|
|
10
|
+
import EdgeAnimation from './EdgeAnimation.svelte';
|
|
11
|
+
|
|
12
|
+
/** The props Svelte Flow passes a custom edge (the subset `<AnimatedEdge>` uses). */
|
|
13
|
+
interface Props {
|
|
14
|
+
id: string;
|
|
15
|
+
sourceX: number;
|
|
16
|
+
sourceY: number;
|
|
17
|
+
targetX: number;
|
|
18
|
+
targetY: number;
|
|
19
|
+
sourcePosition?: Position;
|
|
20
|
+
targetPosition?: Position;
|
|
21
|
+
/** `data.animation` is the animation; `data.pathType` the path style (default `default`, a bézier). */
|
|
22
|
+
data?: { animation?: CanvasEdgeAnimation | null; pathType?: CanvasAnimatedEdgePathType; [key: string]: any };
|
|
23
|
+
label?: string;
|
|
24
|
+
labelStyle?: string;
|
|
25
|
+
/** Inline CSS for the edge line (e.g. `stroke: #38bdf8`). */
|
|
26
|
+
style?: string;
|
|
27
|
+
markerStart?: string;
|
|
28
|
+
markerEnd?: string;
|
|
29
|
+
selected?: boolean;
|
|
30
|
+
/** Width of the invisible line that takes the pointer. Default 20. */
|
|
31
|
+
interactionWidth?: number;
|
|
32
|
+
/** Hold the first frame. Default: follow `prefers-reduced-motion`. */
|
|
33
|
+
reducedMotion?: boolean;
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A Svelte Flow edge that plays `data.animation` (travelling dots, marching dashes, a beam or a
|
|
39
|
+
* pulse) over its line. Register it as an edge type (`edgeTypes={{ animated: AnimatedEdge }}`) and
|
|
40
|
+
* give edges `type: "animated"`; `data.pathType` picks the path (`default`, `straight`, `step`,
|
|
41
|
+
* `smoothstep`, `simplebezier`), drawn as Svelte Flow draws it. An edge without an animation is a
|
|
42
|
+
* plain edge. Agents change animations with `createCanvasEdgeAnimationToolProvider`.
|
|
43
|
+
*/
|
|
44
|
+
let {
|
|
45
|
+
id,
|
|
46
|
+
sourceX,
|
|
47
|
+
sourceY,
|
|
48
|
+
targetX,
|
|
49
|
+
targetY,
|
|
50
|
+
sourcePosition,
|
|
51
|
+
targetPosition,
|
|
52
|
+
data,
|
|
53
|
+
label,
|
|
54
|
+
labelStyle,
|
|
55
|
+
style,
|
|
56
|
+
markerStart,
|
|
57
|
+
markerEnd,
|
|
58
|
+
interactionWidth = 20,
|
|
59
|
+
reducedMotion
|
|
60
|
+
}: Props = $props();
|
|
61
|
+
|
|
62
|
+
const edgePath = $derived(getCanvasEdgePath({ sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, type: data?.pathType }));
|
|
63
|
+
const animation = $derived(getCanvasEdgeAnimation({ data }));
|
|
64
|
+
const stroke = $derived(style?.match(/(?:^|;)\s*stroke\s*:\s*([^;]+)/)?.[1]?.trim());
|
|
65
|
+
const trackOpacity = $derived(animation ? resolveCanvasEdgeAnimation(animation).trackOpacity : 1);
|
|
66
|
+
const lineStyle = $derived([style, trackOpacity !== 1 ? `stroke-opacity: ${trackOpacity}` : ''].filter(Boolean).join('; '));
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<path {id} d={edgePath.path} fill="none" class="svelte-flow__edge-path" style={lineStyle} marker-start={markerStart} marker-end={markerEnd} />
|
|
70
|
+
{#if interactionWidth > 0}
|
|
71
|
+
<path d={edgePath.path} fill="none" stroke-opacity="0" stroke-width={interactionWidth} class="svelte-flow__edge-interaction" />
|
|
72
|
+
{/if}
|
|
73
|
+
<EdgeAnimation {animation} path={edgePath.path} {id} stroke={stroke ?? 'var(--xy-edge-stroke, #b1b1b7)'} {reducedMotion} />
|
|
74
|
+
{#if label}
|
|
75
|
+
<text x={edgePath.labelX} y={edgePath.labelY} text-anchor="middle" dominant-baseline="central" class="svelte-flow__edge-text" style={labelStyle}>{label}</text>
|
|
76
|
+
{/if}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type CanvasAnimatedEdgePathType, type CanvasEdgeAnimation, type Position } from '@pixerate/editor/canvas';
|
|
2
|
+
/** The props Svelte Flow passes a custom edge (the subset `<AnimatedEdge>` uses). */
|
|
3
|
+
interface Props {
|
|
4
|
+
id: string;
|
|
5
|
+
sourceX: number;
|
|
6
|
+
sourceY: number;
|
|
7
|
+
targetX: number;
|
|
8
|
+
targetY: number;
|
|
9
|
+
sourcePosition?: Position;
|
|
10
|
+
targetPosition?: Position;
|
|
11
|
+
/** `data.animation` is the animation; `data.pathType` the path style (default `default`, a bézier). */
|
|
12
|
+
data?: {
|
|
13
|
+
animation?: CanvasEdgeAnimation | null;
|
|
14
|
+
pathType?: CanvasAnimatedEdgePathType;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
label?: string;
|
|
18
|
+
labelStyle?: string;
|
|
19
|
+
/** Inline CSS for the edge line (e.g. `stroke: #38bdf8`). */
|
|
20
|
+
style?: string;
|
|
21
|
+
markerStart?: string;
|
|
22
|
+
markerEnd?: string;
|
|
23
|
+
selected?: boolean;
|
|
24
|
+
/** Width of the invisible line that takes the pointer. Default 20. */
|
|
25
|
+
interactionWidth?: number;
|
|
26
|
+
/** Hold the first frame. Default: follow `prefers-reduced-motion`. */
|
|
27
|
+
reducedMotion?: boolean;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}
|
|
30
|
+
declare const AnimatedEdge: import("svelte").Component<Props, {}, "">;
|
|
31
|
+
type AnimatedEdge = ReturnType<typeof AnimatedEdge>;
|
|
32
|
+
export default AnimatedEdge;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getCanvasEdgeAnimationRender, type CanvasEdgeAnimation } from '@pixerate/editor/canvas';
|
|
3
|
+
import { createPrefersReducedMotion } from './prefersReducedMotion.svelte.js';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
/** The animation (`edge.data.animation`). Renders nothing when null. */
|
|
7
|
+
animation: CanvasEdgeAnimation | null | undefined;
|
|
8
|
+
/** SVG path data of the edge, as your edge draws it. */
|
|
9
|
+
path: string;
|
|
10
|
+
/** Edge id: keeps glow filter ids unique. */
|
|
11
|
+
id: string;
|
|
12
|
+
/** Colour when the animation has none (the edge's stroke). Default `currentColor`. */
|
|
13
|
+
stroke?: string;
|
|
14
|
+
/** Hold the first frame. Default: follow `prefers-reduced-motion`. */
|
|
15
|
+
reducedMotion?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The moving part of an animated edge (dots, dashes, a beam or a pulse) as an SVG `<g>`, drawn
|
|
20
|
+
* along `path` with SMIL, so nothing runs per frame in JavaScript. Put it in your own Svelte Flow
|
|
21
|
+
* edge after `<BaseEdge>`, or use `<AnimatedEdge>`. It ignores the pointer.
|
|
22
|
+
*/
|
|
23
|
+
let { animation, path, id, stroke, reducedMotion }: Props = $props();
|
|
24
|
+
|
|
25
|
+
const prefers = createPrefersReducedMotion();
|
|
26
|
+
const render = $derived.by(() => {
|
|
27
|
+
if (!animation) return null;
|
|
28
|
+
try {
|
|
29
|
+
return getCanvasEdgeAnimationRender(animation, { path, id, stroke, reducedMotion: reducedMotion ?? prefers.current });
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const pathId = $derived(`pixerate-edge-path-${id.replace(/[^a-zA-Z0-9_-]/g, '_')}`);
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
{#if render}
|
|
38
|
+
<g class="pixerate-edge-animation" data-edge-animation={render.kind} data-moving={render.moving ? 'true' : 'false'} style="pointer-events: none">
|
|
39
|
+
<defs>
|
|
40
|
+
<path id={pathId} d={path} />
|
|
41
|
+
{#if render.glowFilter}
|
|
42
|
+
<filter
|
|
43
|
+
id={render.glowFilter.id}
|
|
44
|
+
filterUnits="userSpaceOnUse"
|
|
45
|
+
x={render.glowFilter.x}
|
|
46
|
+
y={render.glowFilter.y}
|
|
47
|
+
width={render.glowFilter.width}
|
|
48
|
+
height={render.glowFilter.height}
|
|
49
|
+
>
|
|
50
|
+
<feGaussianBlur stdDeviation={render.glowFilter.stdDeviation} result="blur" />
|
|
51
|
+
<feMerge>
|
|
52
|
+
<feMergeNode in="blur" />
|
|
53
|
+
<feMergeNode in="SourceGraphic" />
|
|
54
|
+
</feMerge>
|
|
55
|
+
</filter>
|
|
56
|
+
{/if}
|
|
57
|
+
</defs>
|
|
58
|
+
{#each render.elements as el (el.key)}
|
|
59
|
+
{#if el.type === 'dot'}
|
|
60
|
+
{#if render.moving}
|
|
61
|
+
<circle r={el.r} fill={el.fill} filter={el.filter}>
|
|
62
|
+
<animateMotion
|
|
63
|
+
dur="{el.motion.dur}s"
|
|
64
|
+
begin="{el.motion.begin}s"
|
|
65
|
+
repeatCount="indefinite"
|
|
66
|
+
keyPoints={el.motion.keyPoints}
|
|
67
|
+
keyTimes={el.motion.keyTimes}
|
|
68
|
+
calcMode="linear"
|
|
69
|
+
>
|
|
70
|
+
<mpath href="#{pathId}" />
|
|
71
|
+
</animateMotion>
|
|
72
|
+
</circle>
|
|
73
|
+
{:else}
|
|
74
|
+
<circle cx={el.at.x} cy={el.at.y} r={el.r} fill={el.fill} filter={el.filter} />
|
|
75
|
+
{/if}
|
|
76
|
+
{:else}
|
|
77
|
+
<path
|
|
78
|
+
d={path}
|
|
79
|
+
fill="none"
|
|
80
|
+
stroke={el.stroke}
|
|
81
|
+
stroke-width={el.strokeWidth}
|
|
82
|
+
stroke-linecap={el.strokeLinecap}
|
|
83
|
+
stroke-dasharray={el.strokeDasharray}
|
|
84
|
+
stroke-dashoffset={el.strokeDashoffset}
|
|
85
|
+
stroke-opacity={el.opacity}
|
|
86
|
+
filter={el.filter}
|
|
87
|
+
>
|
|
88
|
+
{#if render.moving}
|
|
89
|
+
{#each el.animate as a (a.attributeName)}
|
|
90
|
+
<animate attributeName={a.attributeName} values={a.values} dur="{a.dur}s" begin="{a.begin}s" repeatCount="indefinite" />
|
|
91
|
+
{/each}
|
|
92
|
+
{/if}
|
|
93
|
+
</path>
|
|
94
|
+
{/if}
|
|
95
|
+
{/each}
|
|
96
|
+
</g>
|
|
97
|
+
{/if}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type CanvasEdgeAnimation } from '@pixerate/editor/canvas';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** The animation (`edge.data.animation`). Renders nothing when null. */
|
|
4
|
+
animation: CanvasEdgeAnimation | null | undefined;
|
|
5
|
+
/** SVG path data of the edge, as your edge draws it. */
|
|
6
|
+
path: string;
|
|
7
|
+
/** Edge id: keeps glow filter ids unique. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Colour when the animation has none (the edge's stroke). Default `currentColor`. */
|
|
10
|
+
stroke?: string;
|
|
11
|
+
/** Hold the first frame. Default: follow `prefers-reduced-motion`. */
|
|
12
|
+
reducedMotion?: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare const EdgeAnimation: import("svelte").Component<Props, {}, "">;
|
|
15
|
+
type EdgeAnimation = ReturnType<typeof EdgeAnimation>;
|
|
16
|
+
export default EdgeAnimation;
|
package/dist/canvas/index.d.ts
CHANGED
|
@@ -29,6 +29,10 @@ export { createCanvasMeasure, type CanvasMeasure, type CreateCanvasMeasureOption
|
|
|
29
29
|
export { measureBetween, measureToLine, measureSelection, measureLabel, isMeasureModifierHeld, snapToGrid, snapResize, snapNodeResize, inferResizeHandle, resizeHandleAxes, getResizingNodeRect, RESIZE_HANDLES, fitCubics, fitCubicRun, fitPathData, fitFreehandPath, cubicsToPathData, cubicPointAt, isStraightCubic, type MeasureGuide, type MeasureSelectionResult, type MeasureSelectionOptions, type ResizeHandle, type SnapResizeOptions, type SnapResizeResult, type SnapNodeResizeOptions, type SnapNodeResizeResult, type CubicSegment, type FitCubicsOptions, type FitPathDataOptions } from '@pixerate/editor/canvas';
|
|
30
30
|
export { alignNodes, distributeNodes, matchSize, reorderNodes, applyNodeUpdates, invertNodeUpdates, lockNodes, unlockNodes, toggleLockNodes, isLocked, getNodeSize, getNodeRect, getAbsolutePosition, readStyleSize, withStyleSize, computeSnapGuides, createGuideIndex, createNodeGuideIndex, snapNodeDrag, findConnectorSnap, nearestHandlePositions, handlePoint, positionToSide, sideToPosition, oppositePosition, CONNECTION_LINE_TYPES, CanvasScenesStore, createCanvasScenesStore, parseCanvasScenes, fitViewportToRect, fitViewportToNodes, matchArrangeShortcut, DEFAULT_ARRANGE_SHORTCUTS, type AlignEdge, type DistributeAxis, type DistributeMode, type SizeDimension, type ZOrderOperation, type CanvasNodeUpdate, type GuideLine, type GuideIndex, type SnapGuidesOptions, type SnapResult, type ConnectorSnap, type ConnectorSnapTarget, type CanvasConnectionLineType, type CanvasScene, type CanvasScenesState, type CanvasViewport, type CanvasArrangeAction, type ArrangeShortcutBinding } from '@pixerate/editor/canvas';
|
|
31
31
|
export { default as ShapeNode } from './ShapeNode.svelte';
|
|
32
|
+
export { default as AnimatedEdge } from './AnimatedEdge.svelte';
|
|
33
|
+
export { default as EdgeAnimation } from './EdgeAnimation.svelte';
|
|
34
|
+
export { createPrefersReducedMotion } from './prefersReducedMotion.svelte.js';
|
|
35
|
+
export { CANVAS_EDGE_ANIMATION_KINDS, CANVAS_EDGE_ANIMATION_SCHEMA, createCanvasEdgeAnimationToolProvider, getCanvasEdgeAnimation, getCanvasEdgeAnimationRender, getCanvasEdgePath, measureSvgPath, normalizeCanvasEdgeAnimation, resolveCanvasEdgeAnimation, sampleCanvasEdgeAnimation, setCanvasEdgeAnimation, type CanvasAnimatedEdgePathType, type CanvasEdgeAnimation, type CanvasEdgeAnimationDirection, type CanvasEdgeAnimationElement, type CanvasEdgeAnimationFrame, type CanvasEdgeAnimationKind, type CanvasEdgeAnimationKindInfo, type CanvasEdgeAnimationRender, type CanvasEdgeAnimationRenderOptions, type CanvasEdgeAnimationTiming, type CanvasEdgeAnimationToolProviderOptions, type CanvasEdgeAnimationToolTarget, type CanvasEdgeAnimationToolEdge, type CanvasEdgePath, type CanvasEdgePathParams, type MeasuredSvgPath, type SvgPathPoint } from '@pixerate/editor/canvas';
|
|
32
36
|
export { default as CanvasNodeEffectLayer } from './CanvasNodeEffectLayer.svelte';
|
|
33
37
|
export { default as CanvasEffectsPanel } from './CanvasEffectsPanel.svelte';
|
|
34
38
|
export * from './canvasEffects.svelte.js';
|
package/dist/canvas/index.js
CHANGED
|
@@ -50,6 +50,11 @@ export { createCanvasMeasure } from './createCanvasMeasure.svelte.js';
|
|
|
50
50
|
export { measureBetween, measureToLine, measureSelection, measureLabel, isMeasureModifierHeld, snapToGrid, snapResize, snapNodeResize, inferResizeHandle, resizeHandleAxes, getResizingNodeRect, RESIZE_HANDLES, fitCubics, fitCubicRun, fitPathData, fitFreehandPath, cubicsToPathData, cubicPointAt, isStraightCubic } from '@pixerate/editor/canvas';
|
|
51
51
|
export { alignNodes, distributeNodes, matchSize, reorderNodes, applyNodeUpdates, invertNodeUpdates, lockNodes, unlockNodes, toggleLockNodes, isLocked, getNodeSize, getNodeRect, getAbsolutePosition, readStyleSize, withStyleSize, computeSnapGuides, createGuideIndex, createNodeGuideIndex, snapNodeDrag, findConnectorSnap, nearestHandlePositions, handlePoint, positionToSide, sideToPosition, oppositePosition, CONNECTION_LINE_TYPES, CanvasScenesStore, createCanvasScenesStore, parseCanvasScenes, fitViewportToRect, fitViewportToNodes, matchArrangeShortcut, DEFAULT_ARRANGE_SHORTCUTS } from '@pixerate/editor/canvas';
|
|
52
52
|
export { default as ShapeNode } from './ShapeNode.svelte';
|
|
53
|
+
// Animated edges: travelling dots, marching dashes, beams and pulses, and their agent tools
|
|
54
|
+
export { default as AnimatedEdge } from './AnimatedEdge.svelte';
|
|
55
|
+
export { default as EdgeAnimation } from './EdgeAnimation.svelte';
|
|
56
|
+
export { createPrefersReducedMotion } from './prefersReducedMotion.svelte.js';
|
|
57
|
+
export { CANVAS_EDGE_ANIMATION_KINDS, CANVAS_EDGE_ANIMATION_SCHEMA, createCanvasEdgeAnimationToolProvider, getCanvasEdgeAnimation, getCanvasEdgeAnimationRender, getCanvasEdgePath, measureSvgPath, normalizeCanvasEdgeAnimation, resolveCanvasEdgeAnimation, sampleCanvasEdgeAnimation, setCanvasEdgeAnimation } from '@pixerate/editor/canvas';
|
|
53
58
|
export { default as CanvasNodeEffectLayer } from './CanvasNodeEffectLayer.svelte';
|
|
54
59
|
export { default as CanvasEffectsPanel } from './CanvasEffectsPanel.svelte';
|
|
55
60
|
export * from './canvasEffects.svelte.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Follows `prefers-reduced-motion: reduce`: `current` is true while the user asks for reduced
|
|
3
|
+
* motion. Create it in a component (it listens until the component is destroyed).
|
|
4
|
+
*/
|
|
5
|
+
export declare function createPrefersReducedMotion(): {
|
|
6
|
+
readonly current: boolean;
|
|
7
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const REDUCED_MOTION = '(prefers-reduced-motion: reduce)';
|
|
2
|
+
/**
|
|
3
|
+
* Follows `prefers-reduced-motion: reduce`: `current` is true while the user asks for reduced
|
|
4
|
+
* motion. Create it in a component (it listens until the component is destroyed).
|
|
5
|
+
*/
|
|
6
|
+
export function createPrefersReducedMotion() {
|
|
7
|
+
const query = typeof window !== 'undefined' && typeof window.matchMedia === 'function' ? window.matchMedia(REDUCED_MOTION) : null;
|
|
8
|
+
let reduced = $state(query?.matches ?? false);
|
|
9
|
+
$effect(() => {
|
|
10
|
+
if (!query)
|
|
11
|
+
return;
|
|
12
|
+
const update = () => (reduced = query.matches);
|
|
13
|
+
update();
|
|
14
|
+
query.addEventListener?.('change', update);
|
|
15
|
+
return () => query.removeEventListener?.('change', update);
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
get current() {
|
|
19
|
+
return reduced;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.209.0",
|
|
4
4
|
"description": "Svelte bindings and prompt/rich-text components for @pixerate/editor",
|
|
5
5
|
"author": "Pixerate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -184,7 +184,7 @@
|
|
|
184
184
|
"**/*.css"
|
|
185
185
|
],
|
|
186
186
|
"dependencies": {
|
|
187
|
-
"@pixerate/editor": "0.
|
|
187
|
+
"@pixerate/editor": "0.281.0"
|
|
188
188
|
},
|
|
189
189
|
"peerDependencies": {
|
|
190
190
|
"@dagrejs/dagre": "^1.1.4",
|