@tumaet/apollon 4.7.0 → 4.8.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 (34) hide show
  1. package/README.md +2 -2
  2. package/dist/assets/style.css +1 -1
  3. package/dist/export.d.ts +73 -0
  4. package/dist/export.js +219 -0
  5. package/dist/exportStyles-Wcc8N8Xj.js +5 -0
  6. package/dist/fontStack-DOtVH2j8.js +5 -0
  7. package/dist/index.d.ts +19 -0
  8. package/dist/index.js +11295 -11167
  9. package/dist/internals.d.ts +36 -1
  10. package/dist/internals.js +12 -11
  11. package/dist/react/components/AlignmentGuides.d.ts +1 -1
  12. package/dist/react/components/DraggableGhost.d.ts +5 -0
  13. package/dist/react/constants.d.ts +10 -0
  14. package/dist/react/export/exportErrors.d.ts +10 -0
  15. package/dist/react/export/index.d.ts +13 -0
  16. package/dist/react/export/normalizeExportSvg.d.ts +16 -0
  17. package/dist/react/export/preProcessSvgForPdf.d.ts +20 -0
  18. package/dist/react/export/svgToPdf.d.ts +17 -0
  19. package/dist/react/export/svgToPng.d.ts +38 -0
  20. package/dist/react/exportStyles-CH2hautV.js +6 -0
  21. package/dist/react/hooks/useRemoteDraggingNodes.d.ts +20 -0
  22. package/dist/react/react.js +7237 -7009
  23. package/dist/react/store/diagramStore.d.ts +17 -1
  24. package/dist/react/sync/perfCounters.d.ts +6 -0
  25. package/dist/react/sync/ydoc.d.ts +2 -0
  26. package/dist/react/sync/yjsSync.d.ts +3 -2
  27. package/dist/react/typings.d.ts +17 -0
  28. package/dist/react/utils/collaboration.d.ts +10 -1
  29. package/dist/react/utils/exportUtils.d.ts +0 -130
  30. package/dist/react/utils/paletteLayout.d.ts +66 -0
  31. package/dist/{yjsSync-aPxjWNdZ.js → yjsSync-CqmgRwRE.js} +6800 -6701
  32. package/package.json +15 -1
  33. package/dist/exportStyles-Xk-Vm7Ul.js +0 -5
  34. package/dist/react/exportStyles-DZCHk5mK.js +0 -6
@@ -1,6 +1,6 @@
1
1
  import { StoreApi, UseBoundStore } from 'zustand';
2
2
  import { Node, Edge, OnNodesChange, OnEdgesChange } from '@xyflow/react';
3
- import { Assessment, InteractiveElements } from '../typings';
3
+ import { Assessment, DraggingNode, InteractiveElements } from '../typings';
4
4
  import * as Y from "yjs";
5
5
  export type DiagramStoreData = {
6
6
  nodes: Node[];
@@ -18,8 +18,24 @@ export type DiagramStore = {
18
18
  canUndo: boolean;
19
19
  canRedo: boolean;
20
20
  undoManager: Y.UndoManager | null;
21
+ collaborationEnabled: boolean;
21
22
  previewMode: boolean;
22
23
  setDiagramId: (diagramId: string) => void;
24
+ setCollaborationEnabled: (enabled: boolean) => void;
25
+ /**
26
+ * Inject the sink that forwards transient drag/resize frames onto the
27
+ * ephemeral awareness channel (wired by `YjsSync` for every editor). Kept as
28
+ * runtime wiring rather than diagram state so a `reset()` never clears it.
29
+ * The broadcast itself is gated by `collaborationEnabled`, not by this sink;
30
+ * `null` (headless, where no `YjsSync` runs) just leaves it unwired.
31
+ */
32
+ setDraggingNodesPublisher: (publisher: ((draggingNodes: DraggingNode[] | null) => void) | null) => void;
33
+ /**
34
+ * Clear the peers' live-drag overlay once a gesture's settled value is
35
+ * committed. Called from `onNodeDragStop` (after the doc write) and on
36
+ * collaboration teardown; a no-op when nothing is being broadcast.
37
+ */
38
+ endTransientNodeBroadcast: () => void;
23
39
  setNodes: (payload: Node[] | ((nodes: Node[]) => Node[])) => void;
24
40
  setEdges: (payload: Edge[] | ((edges: Edge[]) => Edge[])) => void;
25
41
  setNodesAndEdges: (nodes: Node[], edges: Edge[]) => void;
@@ -0,0 +1,6 @@
1
+ export type PerfCounters = {
2
+ storeNodeWrites: number;
3
+ };
4
+ export declare const perfCounters: PerfCounters;
5
+ export declare const getPerfCounters: () => PerfCounters | undefined;
6
+ export declare const recordStoreNodeWrite: () => void;
@@ -1,7 +1,9 @@
1
1
  import { Assessment } from '../typings';
2
2
  import { Node, Edge } from '@xyflow/react';
3
3
  import * as Y from "yjs";
4
+ export declare const STORE_ORIGIN = "store";
4
5
  export declare const getNodesMap: (ydoc: Y.Doc) => Y.Map<Node>;
5
6
  export declare const getEdgesMap: (ydoc: Y.Doc) => Y.Map<Edge>;
6
7
  export declare const getAssessments: (ydoc: Y.Doc) => Y.Map<Assessment>;
7
8
  export declare const getDiagramMetadata: (ydoc: Y.Doc) => Y.Map<string>;
9
+ export declare const reconcileYMap: <T>(map: Y.Map<T>, nextEntries: Iterable<readonly [string, T]>) => void;
@@ -1,6 +1,6 @@
1
1
  import { DiagramStore } from '../store/diagramStore';
2
2
  import { MetadataStore } from '../store/metadataStore';
3
- import { CollaborationState, CollaborationUser, CollaborationViewport, CollaboratorInfo } from '../typings';
3
+ import { CollaborationState, CollaborationUser, CollaborationViewport, CollaboratorInfo, DraggingNode } from '../typings';
4
4
  import { StoreApi } from 'zustand';
5
5
  import * as Y from "yjs";
6
6
  export declare enum MessageType {
@@ -37,6 +37,7 @@ export declare class YjsSync {
37
37
  setLocalAwarenessViewport: (viewport: CollaborationViewport | null) => void;
38
38
  setLocalAwarenessFollowing: (followingClientId: number | null) => void;
39
39
  setLocalAwarenessSelectedElement: (selectedElementId: string | null) => void;
40
+ setLocalAwarenessDraggingNodes: (draggingNodes: DraggingNode[] | null) => void;
40
41
  setLocalAwarenessState: (state: Partial<CollaborationState>) => void;
41
42
  subscribeToAwarenessChanges: (callback: (states: Map<number, CollaborationState>) => void) => () => void;
42
43
  getAwarenessStates: () => Map<number, CollaborationState>;
@@ -58,5 +59,5 @@ export declare class YjsSync {
58
59
  /**
59
60
  * Convert Base64 string to Uint8Array
60
61
  */
61
- private base64ToUint8;
62
+ static base64ToUint8(base64: string): Uint8Array;
62
63
  }
@@ -24,12 +24,29 @@ export type CollaborationViewport = {
24
24
  y: number;
25
25
  zoom: number;
26
26
  };
27
+ /**
28
+ * One node a peer is actively dragging or resizing. Broadcast over the
29
+ * ephemeral awareness channel — never written to the Yjs document — so peers
30
+ * can render the in-progress gesture live without growing the CRDT or entering
31
+ * anyone's undo history. The settled position/size is committed once on
32
+ * drop/release through the document like any other edit.
33
+ */
34
+ export type DraggingNode = {
35
+ id: string;
36
+ position: {
37
+ x: number;
38
+ y: number;
39
+ };
40
+ width?: number | null;
41
+ height?: number | null;
42
+ };
27
43
  export type CollaborationState = {
28
44
  user?: CollaborationUser;
29
45
  cursor?: CollaborationCursor | null;
30
46
  viewport?: CollaborationViewport | null;
31
47
  followingClientId?: number | null;
32
48
  selectedElementId?: string | null;
49
+ draggingNodes?: DraggingNode[] | null;
33
50
  };
34
51
  export type CollaboratorInfo = {
35
52
  id: string;
@@ -1,4 +1,4 @@
1
- import { CollaborationViewport } from '../typings';
1
+ import { CollaborationViewport, DraggingNode } from '../typings';
2
2
  export declare const randomCollabName: () => string;
3
3
  export declare const collabColorFromName: (name: string) => string;
4
4
  /**
@@ -8,3 +8,12 @@ export declare const collabColorFromName: (name: string) => string;
8
8
  * Returns `null` for anything malformed.
9
9
  */
10
10
  export declare const sanitizeCollaborationViewport: (raw: unknown) => CollaborationViewport | null;
11
+ /**
12
+ * Narrow an untrusted, peer-supplied `draggingNodes` payload before the overlay
13
+ * reader iterates it. A non-array value (or entries missing a string `id` or a
14
+ * finite numeric position) would otherwise throw in the awareness subscription
15
+ * handler and break the live overlay for everyone reading that peer. Returns the
16
+ * well-formed entries only; `null` if the value isn't an array. Per-entry
17
+ * `width`/`height` survive only when finite or explicitly `null`.
18
+ */
19
+ export declare const sanitizeDraggingNodes: (raw: unknown) => DraggingNode[] | null;
@@ -1,5 +1,4 @@
1
1
  import { ReactFlowInstance, Node, Edge, Rect } from '@xyflow/react';
2
- import { Point } from './pathParsing';
3
2
  type SvgExportMode = "web" | "compat";
4
3
  type ExportFilterOptions = {
5
4
  include?: string[];
@@ -8,134 +7,5 @@ type ExportFilterOptions = {
8
7
  };
9
8
  export declare function filterRenderedElements(container: HTMLElement, options?: ExportFilterOptions): void;
10
9
  export declare const getSVG: (container: HTMLElement, clip: Rect, options?: ExportFilterOptions, fontFaceCss?: string) => string;
11
- /**
12
- * Extract all coordinate points from an SVG path string.
13
- * This includes endpoints AND control points for bezier curves,
14
- * which is important because bezier curves are bounded by the
15
- * convex hull of all their control points.
16
- *
17
- * For S (smooth cubic) and T (smooth quadratic) commands, we also
18
- * include the reflected control point which may extend the bounds.
19
- */
20
- declare function extractPathPoints(pathD: string): Point[];
21
- declare function getNodeBoundsFromDOM(container: HTMLElement, reactFlow?: ReactFlowInstance<Node, Edge>): Rect | undefined;
22
- /**
23
- * Calculate bounds for node SVG overflow content.
24
- *
25
- * Some nodes render elements outside their viewBox (e.g., the initial marking
26
- * arrow in Reachability Graphs extends to negative coordinates). These elements
27
- * are visible because the node SVGs use overflow="visible", but they are NOT
28
- * included in reactFlow.getNodesBounds() which only considers node position
29
- * and dimensions.
30
- *
31
- * This function scans node SVGs for <line>, <path>, and <circle> elements
32
- * that extend outside the node's local coordinate system (viewBox), converts
33
- * them to global coordinates, and returns the bounding box of all such content.
34
- */
35
- declare function getNodeOverflowBoundsFromDOM(container: HTMLElement): Rect | undefined;
36
- declare function mergeBounds(a: Rect, b: Rect): Rect;
37
10
  export declare function getRenderedDiagramBounds(reactFlow: ReactFlowInstance<Node, Edge>, container: HTMLElement): Rect;
38
- declare function extractStyles(styleString: string): {
39
- transform: {
40
- x: number;
41
- y: number;
42
- };
43
- width: string | null;
44
- height: string | null;
45
- };
46
- type CSSVariableMap = Readonly<Record<string, string>>;
47
- /**
48
- * Resolve a single CSS variable reference to its final value.
49
- * Handles recursive var() resolution and fallback values.
50
- */
51
- declare function resolveCSSVariable(value: string, cssVarMap?: CSSVariableMap): string;
52
- /**
53
- * Replace CSS variables and currentColor in all attributes of an element tree.
54
- *
55
- * @param node - The DOM node to process
56
- * @param inheritedColor - The inherited 'currentColor' value from parent elements
57
- */
58
- declare function replaceCSSVariables(node: Element | ChildNode, inheritedColor?: string, cssVarMap?: CSSVariableMap): void;
59
- /**
60
- * Convert inline style properties to direct SVG attributes for better compatibility.
61
- * PowerPoint and some other applications don't properly parse CSS in style attributes.
62
- */
63
- declare function convertStyleToAttributes(node: Element | ChildNode): void;
64
- /**
65
- * Ensure all <text> elements have explicit font-size, font-weight, and font-family.
66
- *
67
- * In the browser, text inherits these from CSS (:root font-family, default font-size).
68
- * In exported SVGs opened in non-browser renderers, missing attributes cause text to
69
- * render with the renderer's own defaults (often Times New Roman at an arbitrary size).
70
- *
71
- * This pass runs AFTER convertStyleToAttributes so any font props already extracted
72
- * from inline styles are present as attributes.
73
- */
74
- declare function ensureTextFontDefaults(svg: Element): void;
75
- /**
76
- * Resolve relative `font-size` (`%`, `em`) to px against the inherited size —
77
- * otherwise stereotypes (`font-size="85%"`) balloon over the class title. Walks
78
- * depth-first carrying the resolved px; runs after ensureTextFontDefaults so
79
- * every <text> already has a px size to inherit.
80
- */
81
- declare function resolveRelativeFontSizes(el: Element, inheritedPx?: number): void;
82
- /**
83
- * Flatten cumulative `<tspan dy>` to absolute `y` — Skia collapses sibling
84
- * tspans onto one line, overlapping a stereotype with its class name. Assumes
85
- * the flat `<text><tspan/></text>` shape Apollon emits (no nested tspans).
86
- */
87
- declare function resolveTspanDy(svg: Element): void;
88
- /**
89
- * Resolve `dominant-baseline` to an explicit baseline `y` — non-browser engines
90
- * draw every label at the alphabetic baseline (too high) otherwise. Runs after
91
- * resolveTspanDy so tspan `y` is already absolute.
92
- */
93
- declare function resolveDominantBaseline(svg: Element): void;
94
- /**
95
- * Replace `text-decoration="underline"` on `<text>` elements with manual
96
- * `<line>` siblings so the underline is visible in non-browser renderers.
97
- *
98
- * resvg 2.6.2 has a rendering bug where 3+ `text-decoration="underline"`
99
- * attributes across nested `<svg>` elements cause unrelated paths (particularly
100
- * vertical lines) to disappear. This workaround removes the problematic
101
- * attribute and draws explicit underline lines using `getBBox()` for accurate
102
- * text measurements.
103
- *
104
- * The SVG must be temporarily attached to the DOM for `getBBox()` to work.
105
- */
106
- declare function replaceTextDecorationWithManualUnderline(svg: SVGSVGElement): void;
107
- /**
108
- * Embed `@font-face` CSS (typically the bundled Inter woff2 as base64) into the
109
- * export SVG so the document carries its own font and renders identically when
110
- * opened away from the editor. Inserted first so the face is declared before
111
- * any `<text>` references it. Idempotent: a second call is a no-op.
112
- */
113
- declare function embedFontFaceCss(svg: SVGSVGElement, css: string): void;
114
- /**
115
- * Final safety pass: strip any legacy <marker> references that could sneak in
116
- * from third-party content. Keeps exports clean for PowerPoint/Keynote.
117
- */
118
- declare function removeMarkerElements(svg: Element): void;
119
- /**
120
- * @internal — Exported for unit testing only. Not part of the public API.
121
- */
122
- export declare const __testing: {
123
- readonly embedFontFaceCss: typeof embedFontFaceCss;
124
- readonly filterRenderedElements: typeof filterRenderedElements;
125
- readonly getRenderedDiagramBounds: typeof getRenderedDiagramBounds;
126
- readonly extractPathPoints: typeof extractPathPoints;
127
- readonly extractStyles: typeof extractStyles;
128
- readonly resolveCSSVariable: typeof resolveCSSVariable;
129
- readonly replaceCSSVariables: typeof replaceCSSVariables;
130
- readonly convertStyleToAttributes: typeof convertStyleToAttributes;
131
- readonly ensureTextFontDefaults: typeof ensureTextFontDefaults;
132
- readonly resolveRelativeFontSizes: typeof resolveRelativeFontSizes;
133
- readonly resolveTspanDy: typeof resolveTspanDy;
134
- readonly resolveDominantBaseline: typeof resolveDominantBaseline;
135
- readonly removeMarkerElements: typeof removeMarkerElements;
136
- readonly replaceTextDecorationWithManualUnderline: typeof replaceTextDecorationWithManualUnderline;
137
- readonly mergeBounds: typeof mergeBounds;
138
- readonly getNodeBoundsFromDOM: typeof getNodeBoundsFromDOM;
139
- readonly getNodeOverflowBoundsFromDOM: typeof getNodeOverflowBoundsFromDOM;
140
- };
141
11
  export {};
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Layout math for the floating element palette. The palette is an overlay on
3
+ * the canvas (all viewports — there is no docked variant), so it must lay every
4
+ * element out in a grid that fits the available canvas WITHOUT scrolling.
5
+ *
6
+ * Objective (in priority order):
7
+ * 1. Use the FEWEST columns — a tall, narrow card preserves horizontal canvas
8
+ * space, which is what you actually draw in.
9
+ * 2. Fill the available VERTICAL space — a single column down the side reads
10
+ * like a classic palette and wastes no height.
11
+ * 3. Keep cells comfortably large — never below `COMFORT_MIN_H` just to save a
12
+ * column, and never below the HIG `CELL_MIN_H` touch floor at all.
13
+ *
14
+ * So: walk column counts low→high and take the first one whose cells, sized to
15
+ * fill the height, are still comfortable. Few elements get big capped cells in
16
+ * one column; many elements get a taller single column of moderate cells before
17
+ * a second column is ever added.
18
+ *
19
+ * Cells are rectangular (the dominant elements — class boxes, BPMN tasks — are
20
+ * ~1.6:1 wide); narrower/square elements letterbox centered inside. Sizing the
21
+ * cell, not the SVG, keeps the node components untouched.
22
+ */
23
+ export declare const PALETTE: Readonly<{
24
+ /** HIG/WCAG touch + legibility floor — never shrink a cell past this. */
25
+ readonly CELL_MIN_H: 44;
26
+ /** Bias toward fewer columns: keep a single (or narrower) column as long as
27
+ * its height-filling cells stay at least this big; only add a column when
28
+ * that would drop below it. Just above the touch floor, so the strong
29
+ * preference is fewer columns + filling the height. */
30
+ readonly COMFORT_MIN_H: 48;
31
+ /** Upper bound so few-element palettes don't get absurdly tall cells. */
32
+ readonly CELL_MAX_H: 78;
33
+ /** cellW = round(CELL_RATIO * cellH); ~matches the 160×100 class box. */
34
+ readonly CELL_RATIO: 1.6;
35
+ readonly GAP: 8;
36
+ readonly PAD: 6;
37
+ /** Keep the palette horizontally narrow so the canvas keeps its width … */
38
+ readonly MAX_FRAC_W: 0.5;
39
+ /** … but let it use most of the height. */
40
+ readonly MAX_FRAC_H: 0.9;
41
+ /** Letterbox padding around the preview inside a cell. */
42
+ readonly CONTENT_INSET: 6;
43
+ /** Space kept clear above (top offset) and below (zoom controls) the palette. */
44
+ readonly TOP_RESERVE: 10;
45
+ readonly BOTTOM_RESERVE: 84;
46
+ }>;
47
+ export interface PaletteLayout {
48
+ cols: number;
49
+ cellW: number;
50
+ cellH: number;
51
+ /** True only in the rare case all items can't fit even at the floor size. */
52
+ scroll: boolean;
53
+ }
54
+ /**
55
+ * @param itemCount total grid cells (drag elements + the color-description cell)
56
+ * @param availW measured canvas width
57
+ * @param availH measured canvas height
58
+ * @param chromeH height of non-grid palette chrome (view switch / hint), 0 if none
59
+ */
60
+ export declare function computePaletteLayout(itemCount: number, availW: number, availH: number, chromeH: number): PaletteLayout;
61
+ /**
62
+ * Preview scale that fits an element's natural size into a cell's content box.
63
+ * Elements fill their cell (so they read "big"); wide boxes fit width, tall/
64
+ * square nodes fit height and letterbox.
65
+ */
66
+ export declare function previewScaleForCell(naturalWidth: number, naturalHeight: number, cellW: number, cellH: number): number;