@sentropic/design-system-svelte 0.39.0 → 0.41.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/LICENSE.THIRD-PARTY.md +2 -1
- package/README.md +7 -0
- package/dist/Dc2bContentSizeFixture.svelte.d.ts +10 -0
- package/dist/Dc2bContentSizeFixture.svelte.d.ts.map +1 -0
- package/dist/DiagramCard.svelte +25 -36
- package/dist/DiagramCard.svelte.d.ts +4 -8
- package/dist/DiagramCard.svelte.d.ts.map +1 -1
- package/dist/DiagramCardHeader.svelte +11 -10
- package/dist/DiagramCardHeader.svelte.d.ts.map +1 -1
- package/dist/DiagramSceneFigure.svelte +1207 -0
- package/dist/DiagramSceneFigure.svelte.d.ts +134 -0
- package/dist/DiagramSceneFigure.svelte.d.ts.map +1 -0
- package/dist/DiagramZone.svelte +21 -47
- package/dist/DiagramZone.svelte.d.ts +2 -4
- package/dist/DiagramZone.svelte.d.ts.map +1 -1
- package/dist/DiagramZoneHeader.svelte +2 -1
- package/dist/DiagramZoneHeader.svelte.d.ts.map +1 -1
- package/dist/diagram-icons/PROVENANCE.md +4 -0
- package/dist/diagram-icons/registry.d.ts.map +1 -1
- package/dist/diagram-icons/registry.js +2 -1
- package/dist/diagram-render/renderCardSvg.d.ts +5 -15
- package/dist/diagram-render/renderCardSvg.d.ts.map +1 -1
- package/dist/diagram-render/renderCardSvg.js +9 -15
- package/dist/diagram-render/renderZoneSvg.d.ts +2 -11
- package/dist/diagram-render/renderZoneSvg.d.ts.map +1 -1
- package/dist/diagram-render/renderZoneSvg.js +5 -10
- package/dist/diagramCardModel.d.ts +2 -581
- package/dist/diagramCardModel.d.ts.map +1 -1
- package/dist/diagramCardModel.js +2 -1133
- package/dist/diagramFontMeasure.d.ts +5 -0
- package/dist/diagramFontMeasure.d.ts.map +1 -0
- package/dist/diagramFontMeasure.js +41 -0
- package/dist/diagramRenderedBounds.d.ts +6 -0
- package/dist/diagramRenderedBounds.d.ts.map +1 -0
- package/dist/diagramRenderedBounds.js +51 -0
- package/dist/diagramSceneModel.d.ts +162 -0
- package/dist/diagramSceneModel.d.ts.map +1 -0
- package/dist/diagramSceneModel.js +309 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/package.json +9 -5
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Browser-only font read; the layout/cache still own geometry. */
|
|
2
|
+
import { type CardLineMeasure } from './diagramCardModel.js';
|
|
3
|
+
import type { SceneModel } from '@sentropic/diagram-canvas/diagramSceneModel';
|
|
4
|
+
export declare function measureRenderedSceneFont(frame: HTMLElement, _scene: SceneModel, _previous: CardLineMeasure): CardLineMeasure | undefined;
|
|
5
|
+
//# sourceMappingURL=diagramFontMeasure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagramFontMeasure.d.ts","sourceRoot":"","sources":["../src/lib/diagramFontMeasure.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,OAAO,EACL,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC;AAE9E,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS,CAmCxI"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Browser-only font read; the layout/cache still own geometry. */
|
|
2
|
+
import { CARD_GEOMETRY, createCardMeasure } from './diagramCardModel.js';
|
|
3
|
+
export function measureRenderedSceneFont(frame, _scene, _previous) {
|
|
4
|
+
const card = frame.querySelector('.st-diagramCard, .st-diagramZone--expanded');
|
|
5
|
+
if (card === null)
|
|
6
|
+
return undefined;
|
|
7
|
+
const context = frame.ownerDocument.createElement('canvas').getContext('2d');
|
|
8
|
+
if (context === null)
|
|
9
|
+
return undefined;
|
|
10
|
+
const root = getComputedStyle(card);
|
|
11
|
+
const selectors = { kicker: '.st-diagramCard-kicker', title: '.st-diagramCard-title',
|
|
12
|
+
body: '.st-diagramCard-line, .st-diagramZone-subtitle', footer: '.st-diagramCard-footer, .st-diagramZone-footer' };
|
|
13
|
+
const fonts = Object.fromEntries(Object.entries(selectors).map(([role, selector]) => {
|
|
14
|
+
const element = frame.querySelector(selector);
|
|
15
|
+
const geometry = CARD_GEOMETRY[role];
|
|
16
|
+
if (element === null)
|
|
17
|
+
return [role, {
|
|
18
|
+
font: geometry.weight + ' ' + geometry.size + 'px ' + (root.fontFamily || 'Inter, system-ui, sans-serif'),
|
|
19
|
+
spacing: role === 'kicker' ? 0.04 * geometry.size : 0,
|
|
20
|
+
}];
|
|
21
|
+
const style = getComputedStyle(element);
|
|
22
|
+
return [role, { font: style.font || (style.fontWeight || geometry.weight) + ' ' +
|
|
23
|
+
(style.fontSize || geometry.size + 'px') + ' ' + (style.fontFamily || root.fontFamily || 'Inter, system-ui, sans-serif'),
|
|
24
|
+
spacing: parseFloat(style.letterSpacing) || (role === 'kicker' ? 0.04 * geometry.size : 0) }];
|
|
25
|
+
}));
|
|
26
|
+
const widthOf = (text, role) => {
|
|
27
|
+
const font = fonts[role];
|
|
28
|
+
context.font = font.font;
|
|
29
|
+
const normalized = role === 'kicker' ? text.toUpperCase() : text;
|
|
30
|
+
return context.measureText(normalized).width + normalized.length * font.spacing + 2;
|
|
31
|
+
};
|
|
32
|
+
const version = 'computed-font:' + JSON.stringify(fonts) + ':' + Object.keys(fonts).map(role => widthOf('Mm09 É—', role)).join(',');
|
|
33
|
+
const heights = Object.fromEntries(Object.keys(fonts).map(role => {
|
|
34
|
+
context.font = fonts[role].font;
|
|
35
|
+
const metrics = context.measureText('Mg');
|
|
36
|
+
return [role, (metrics.fontBoundingBoxAscent ?? 0) + (metrics.fontBoundingBoxDescent ?? 0)];
|
|
37
|
+
}));
|
|
38
|
+
const measured = createCardMeasure(widthOf, version + ':' + JSON.stringify(heights), true, role => heights[role]);
|
|
39
|
+
// A14 uses the loaded face for ellipses even when line counts do not change.
|
|
40
|
+
return measured;
|
|
41
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Rect } from '@sentropic/diagram-canvas';
|
|
2
|
+
/** Painted bounds in world units, after font/layout settling. DOM-free
|
|
3
|
+
* scene geometry remains the SSR fallback. Include text ink and SVG strokes:
|
|
4
|
+
* getBoundingClientRect alone excludes both text overshoot and stroke width. */
|
|
5
|
+
export declare function measureRenderedBounds(frame: HTMLElement, fallback: Rect | undefined, zoom: number): Rect | undefined;
|
|
6
|
+
//# sourceMappingURL=diagramRenderedBounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagramRenderedBounds.d.ts","sourceRoot":"","sources":["../src/lib/diagramRenderedBounds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAEtD;;gFAEgF;AAChF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAuCpH"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Painted bounds in world units, after font/layout settling. DOM-free
|
|
2
|
+
* scene geometry remains the SSR fallback. Include text ink and SVG strokes:
|
|
3
|
+
* getBoundingClientRect alone excludes both text overshoot and stroke width. */
|
|
4
|
+
export function measureRenderedBounds(frame, fallback, zoom) {
|
|
5
|
+
const world = frame.querySelector('.st-diagramSceneFigure-world');
|
|
6
|
+
if (!world || !(zoom > 0))
|
|
7
|
+
return fallback;
|
|
8
|
+
const first = world.querySelector('[data-scene-occurrence],[data-scene-label]')?.getBoundingClientRect();
|
|
9
|
+
if (!first || first.width === 0 && first.height === 0)
|
|
10
|
+
return fallback;
|
|
11
|
+
const origin = world.getBoundingClientRect();
|
|
12
|
+
let left = fallback?.x ?? Infinity, top = fallback?.y ?? Infinity;
|
|
13
|
+
let right = fallback === undefined ? -Infinity : fallback.x + fallback.width;
|
|
14
|
+
let bottom = fallback === undefined ? -Infinity : fallback.y + fallback.height;
|
|
15
|
+
let measured = false;
|
|
16
|
+
const include = (box, stroke = 0) => {
|
|
17
|
+
if (box.width === 0 && box.height === 0)
|
|
18
|
+
return;
|
|
19
|
+
measured = true;
|
|
20
|
+
left = Math.min(left, (box.left - origin.left - stroke) / zoom);
|
|
21
|
+
top = Math.min(top, (box.top - origin.top - stroke) / zoom);
|
|
22
|
+
right = Math.max(right, (box.right - origin.left + stroke) / zoom);
|
|
23
|
+
bottom = Math.max(bottom, (box.bottom - origin.top + stroke) / zoom);
|
|
24
|
+
};
|
|
25
|
+
for (const element of world.querySelectorAll('[data-scene-occurrence],.st-diagramCard,.st-diagramZone,[data-scene-label],[data-diagram-icon],.st-badge,[data-badge],.st-diagramCard-rule,.st-diagramZone-rule,.st-diagramZone-footerRule,button,svg polyline,svg path,svg line,svg rect,svg text')) {
|
|
26
|
+
if (element.closest('defs'))
|
|
27
|
+
continue;
|
|
28
|
+
const style = getComputedStyle(element);
|
|
29
|
+
const width = style.stroke && style.stroke !== 'none' ? parseFloat(style.strokeWidth) || 0 : 0;
|
|
30
|
+
const matrix = element.getScreenCTM?.();
|
|
31
|
+
const scale = matrix ? Math.max(Math.hypot(matrix.a, matrix.b), Math.hypot(matrix.c, matrix.d)) : zoom;
|
|
32
|
+
const stroke = width / 2 * (style.vectorEffect === 'non-scaling-stroke' ? 1 : scale);
|
|
33
|
+
include(element.getBoundingClientRect(), stroke);
|
|
34
|
+
}
|
|
35
|
+
const walker = frame.ownerDocument.createTreeWalker(world, 4);
|
|
36
|
+
let text;
|
|
37
|
+
while ((text = walker.nextNode())) {
|
|
38
|
+
if (!text.textContent?.trim() || text.parentElement?.closest('defs,title,desc,[hidden]'))
|
|
39
|
+
continue;
|
|
40
|
+
const range = frame.ownerDocument.createRange();
|
|
41
|
+
range.selectNodeContents(text);
|
|
42
|
+
if (typeof range.getClientRects === 'function')
|
|
43
|
+
for (const box of range.getClientRects())
|
|
44
|
+
include(box);
|
|
45
|
+
}
|
|
46
|
+
if (!measured || !Number.isFinite(left))
|
|
47
|
+
return fallback;
|
|
48
|
+
// CSS layout uses a 1/64 px grid. Always round the outer edges outward.
|
|
49
|
+
const x = Math.floor(left * 64) / 64, y = Math.floor(top * 64) / 64;
|
|
50
|
+
return { x, y, width: Math.ceil(right * 64) / 64 - x, height: Math.ceil(bottom * 64) / 64 - y };
|
|
51
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `DiagramSceneFigure` — the pure half of the scene host (DC-2a lot L4,
|
|
3
|
+
* SPEC_EVOL_DC2A §4.3, §5, §6.7, Appendix D).
|
|
4
|
+
*
|
|
5
|
+
* Everything here is a function of its arguments: no `window`, no
|
|
6
|
+
* `document`, no timer. The Svelte component owns the DOM reads (figure
|
|
7
|
+
* width, window height, token values, reduced-motion query) and feeds
|
|
8
|
+
* them in.
|
|
9
|
+
*
|
|
10
|
+
* The host consumes the public API of `@sentropic/diagram-canvas` only
|
|
11
|
+
* (layout, scene, camera). The semantic-document and view types are read
|
|
12
|
+
* off the layout signature, so this package names no other diagram layer.
|
|
13
|
+
*/
|
|
14
|
+
import { layoutMeasured, type CameraFit, type LayoutHints, type LayoutMetrics, type LayoutOptions, type LayoutResult, type LevelOrientation, type LineMeasurer, type Rect, type RowPackOptions, type Vec2 } from "@sentropic/diagram-canvas";
|
|
15
|
+
import type { CardPresentationInput } from "./diagramCardModel.js";
|
|
16
|
+
/** The semantic document the layout engine reads. */
|
|
17
|
+
export type SceneDocument = Parameters<typeof layoutMeasured>[0];
|
|
18
|
+
/** A view document: the optional retained source view, and the emitted view. */
|
|
19
|
+
export type SceneView = NonNullable<Parameters<typeof layoutMeasured>[2]>;
|
|
20
|
+
/** An occurrence id of a view (`occurrence:…`). */
|
|
21
|
+
export type SceneOccurrenceRef = NonNullable<LayoutOptions["collapsed"]>[number];
|
|
22
|
+
export type ScenePresentation = NonNullable<LayoutOptions["presentation"]>;
|
|
23
|
+
export type SceneLaidOut = Extract<LayoutResult, {
|
|
24
|
+
readonly status: "laid-out";
|
|
25
|
+
}>;
|
|
26
|
+
export type SceneOrientations = Readonly<Record<string, LevelOrientation>>;
|
|
27
|
+
/**
|
|
28
|
+
* `targetWidth` handed to the engine when the host supplies none. The
|
|
29
|
+
* measured path never re-packs on it (D-3) and the host never reads the
|
|
30
|
+
* layout fit report (Z-8), so a resize re-runs no layout.
|
|
31
|
+
*/
|
|
32
|
+
export declare const DEFAULT_SCENE_TARGET_WIDTH = 1440;
|
|
33
|
+
/**
|
|
34
|
+
* Edge-label wrapping width of the measured path (`measured.ts`, §4.6.3
|
|
35
|
+
* step 5). The engine does not export it; rendered text must wrap with the
|
|
36
|
+
* same allocation as the engine's measured label.
|
|
37
|
+
*/
|
|
38
|
+
export declare const EDGE_LABEL_ALLOCATION = 400;
|
|
39
|
+
/** Zoom ratio of one button or key step. */
|
|
40
|
+
export declare const ZOOM_STEP_RATIO = 1.2;
|
|
41
|
+
/** Zoom ratio per wheel delta unit (Ctrl + wheel, trackpad pinch). */
|
|
42
|
+
export declare const WHEEL_ZOOM_RATE = 0.0015;
|
|
43
|
+
export interface SceneLayoutInput {
|
|
44
|
+
readonly document: SceneDocument;
|
|
45
|
+
/** Retained source view (authored occurrences, fold groups). Optional: the engine synthesises one. */
|
|
46
|
+
readonly view?: SceneView;
|
|
47
|
+
readonly registry: LayoutOptions["registry"];
|
|
48
|
+
readonly bindings?: LayoutOptions["bindings"];
|
|
49
|
+
readonly presentation: ScenePresentation;
|
|
50
|
+
readonly measureLines: LineMeasurer;
|
|
51
|
+
readonly collapsed: readonly SceneOccurrenceRef[];
|
|
52
|
+
readonly hints?: LayoutHints;
|
|
53
|
+
readonly metrics?: Partial<LayoutMetrics>;
|
|
54
|
+
readonly rowPack?: RowPackOptions;
|
|
55
|
+
readonly targetWidth?: number;
|
|
56
|
+
readonly previousOrientation?: SceneOrientations;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* One full layout pass (§6.5: fold → measure → place → route, never patched).
|
|
60
|
+
* Row-pack is always selected: an absent `rowPack` resolves to the DS
|
|
61
|
+
* defaults. `measureText` is the compatibility measurer the measured path
|
|
62
|
+
* never calls; it is derived from the shared line measurer so the type's
|
|
63
|
+
* required field carries no second metric source.
|
|
64
|
+
*/
|
|
65
|
+
export declare function layoutScene(input: SceneLayoutInput): LayoutResult;
|
|
66
|
+
/** Collapsed occurrence ids recorded by a view's fold groups. */
|
|
67
|
+
export declare function collapsedOccurrencesOf(view: SceneView | undefined): SceneOccurrenceRef[];
|
|
68
|
+
export type SceneNodeKind = "card" | "zone" | "legend-key" | "label";
|
|
69
|
+
export interface SceneNodeModel {
|
|
70
|
+
readonly occurrence: SceneOccurrenceRef;
|
|
71
|
+
readonly entity: string;
|
|
72
|
+
readonly kind: SceneNodeKind;
|
|
73
|
+
/** Zones only: drawn as the atomic card (collapsed) or as the frame. */
|
|
74
|
+
readonly collapsed: boolean;
|
|
75
|
+
readonly rect: Rect;
|
|
76
|
+
readonly presentation?: CardPresentationInput;
|
|
77
|
+
/** Text of a node with no card form (L-R12 label) or of a legend key. */
|
|
78
|
+
readonly text: string;
|
|
79
|
+
}
|
|
80
|
+
export interface SceneEdgeModel {
|
|
81
|
+
readonly occurrence: SceneOccurrenceRef;
|
|
82
|
+
readonly points: readonly Vec2[];
|
|
83
|
+
}
|
|
84
|
+
export interface SceneLabelModel {
|
|
85
|
+
readonly occurrence: SceneOccurrenceRef;
|
|
86
|
+
readonly lines: readonly string[];
|
|
87
|
+
readonly box: Rect;
|
|
88
|
+
}
|
|
89
|
+
export interface SceneModel {
|
|
90
|
+
/** Bottom to top, in the scene's paint order. */
|
|
91
|
+
readonly nodes: readonly SceneNodeModel[];
|
|
92
|
+
readonly edges: readonly SceneEdgeModel[];
|
|
93
|
+
readonly labels: readonly SceneLabelModel[];
|
|
94
|
+
/**
|
|
95
|
+
* Fit bbox (BF-7): `rectUnion(scene.bounds, placed label boxes)`.
|
|
96
|
+
* `undefined` for an empty scene.
|
|
97
|
+
*/
|
|
98
|
+
readonly bounds?: Rect;
|
|
99
|
+
readonly orientations: SceneOrientations;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The drawable scene of one laid-out result: nodes at emitted geometry,
|
|
103
|
+
* routes, and the engine's emitted edge-label boxes. Results without emitted
|
|
104
|
+
* boxes use the legacy placement replay with the same measurer, margin and
|
|
105
|
+
* blockers (cards, collapsed boxes and expanded-zone title bands).
|
|
106
|
+
*/
|
|
107
|
+
export declare function resolveScene(result: SceneLaidOut, input: Pick<SceneLayoutInput, "document" | "presentation" | "measureLines" | "metrics">): SceneModel;
|
|
108
|
+
export interface SceneCameraInput {
|
|
109
|
+
readonly bounds?: Rect;
|
|
110
|
+
readonly viewWidth: number;
|
|
111
|
+
readonly windowHeight: number;
|
|
112
|
+
readonly maxDisplayScale?: number;
|
|
113
|
+
readonly minReadableScale?: number;
|
|
114
|
+
}
|
|
115
|
+
/** §5.1 / BF-2 fit of the scene bounds, as `cameraFit` computes it. */
|
|
116
|
+
export declare function sceneFit(input: SceneCameraInput): CameraFit;
|
|
117
|
+
/**
|
|
118
|
+
* The camera zoom for a request (Z-1, Z-7, Z-8). `undefined` means « no
|
|
119
|
+
* request yet »: the camera sits at the fit. Any number lands inside the
|
|
120
|
+
* current `[minZoom, maxZoom]`, whatever input produced it.
|
|
121
|
+
*/
|
|
122
|
+
export declare function resolveZoom(requested: number | undefined, fit: CameraFit): number;
|
|
123
|
+
export interface ScenePlacement {
|
|
124
|
+
/** Scroll extent of the drawing at this zoom, CSS px. */
|
|
125
|
+
readonly contentWidth: number;
|
|
126
|
+
readonly contentHeight: number;
|
|
127
|
+
/** Translation of the world origin inside the scroll extent, CSS px. */
|
|
128
|
+
readonly translateX: number;
|
|
129
|
+
readonly translateY: number;
|
|
130
|
+
/** An axis overflows the fit box: the viewport scrolls it from its start (BF-2). */
|
|
131
|
+
readonly overflowX: boolean;
|
|
132
|
+
readonly overflowY: boolean;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Where the drawing sits in the fit box at a zoom: centred on every axis it
|
|
136
|
+
* fits, flush with the start on an axis it overflows (the viewport scrolls
|
|
137
|
+
* that axis). Transform only — geometry is never touched (Z-6).
|
|
138
|
+
*/
|
|
139
|
+
export declare function scenePlacement(bounds: Rect | undefined, zoom: number, fit: Pick<CameraFit, "fitWidth" | "fitHeight">): ScenePlacement;
|
|
140
|
+
/** A CSS `<time>` token value (`240ms`, `0.24s`) in milliseconds; 0 when absent or unreadable. */
|
|
141
|
+
export declare function parseDurationMs(value: string | undefined): number;
|
|
142
|
+
/** A unitless number token value; `undefined` when absent or unreadable. */
|
|
143
|
+
export declare function parseScale(value: string | undefined): number | undefined;
|
|
144
|
+
export type Easing = (progress: number) => number;
|
|
145
|
+
/**
|
|
146
|
+
* The easing of a CSS `cubic-bezier(x1, y1, x2, y2)` token value. Any other
|
|
147
|
+
* value (absent token, keyword) is linear: the host holds no easing literal.
|
|
148
|
+
*/
|
|
149
|
+
export declare function parseEasing(value: string | undefined): Easing;
|
|
150
|
+
export declare function interpolateRect(from: Rect, to: Rect, eased: number): Rect;
|
|
151
|
+
/**
|
|
152
|
+
* Displayed rectangles of a transition (T-1): every occurrence present in
|
|
153
|
+
* both states moves from its previous to its new rectangle; an occurrence
|
|
154
|
+
* with no previous rectangle sits at its final one (the host fades it in).
|
|
155
|
+
* `eased >= 1` returns the final rectangles themselves, so a finished or
|
|
156
|
+
* instant transition is exactly the layout output.
|
|
157
|
+
*/
|
|
158
|
+
export declare function displayedRects(from: ReadonlyMap<string, Rect>, to: ReadonlyMap<string, Rect>, eased: number): ReadonlyMap<string, Rect>;
|
|
159
|
+
export declare function rectsOf(scene: SceneModel): ReadonlyMap<string, Rect>;
|
|
160
|
+
/** Whether two rectangle sets are the same drawing: same ids, same numbers. */
|
|
161
|
+
export declare function sameRects(left: ReadonlyMap<string, Rect>, right: ReadonlyMap<string, Rect>): boolean;
|
|
162
|
+
//# sourceMappingURL=diagramSceneModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagramSceneModel.d.ts","sourceRoot":"","sources":["../src/lib/diagramSceneModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAQL,cAAc,EAKd,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,cAAc,EACnB,KAAK,IAAI,EACV,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE,qDAAqD;AACrD,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,gFAAgF;AAChF,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1E,mDAAmD;AACnD,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AACjF,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;AAC3E,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AAClF,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAE3E;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,OAAO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AE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAGzE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,EAC/B,EAAE,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,EAC7B,KAAK,EAAE,MAAM,GACZ,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAQ3B;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAEpE;AAED,+EAA+E;AAC/E,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,OAAO,CAOpG"}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `DiagramSceneFigure` — the pure half of the scene host (DC-2a lot L4,
|
|
3
|
+
* SPEC_EVOL_DC2A §4.3, §5, §6.7, Appendix D).
|
|
4
|
+
*
|
|
5
|
+
* Everything here is a function of its arguments: no `window`, no
|
|
6
|
+
* `document`, no timer. The Svelte component owns the DOM reads (figure
|
|
7
|
+
* width, window height, token values, reduced-motion query) and feeds
|
|
8
|
+
* them in.
|
|
9
|
+
*
|
|
10
|
+
* The host consumes the public API of `@sentropic/diagram-canvas` only
|
|
11
|
+
* (layout, scene, camera). The semantic-document and view types are read
|
|
12
|
+
* off the layout signature, so this package names no other diagram layer.
|
|
13
|
+
*/
|
|
14
|
+
import { buildScene, cameraFit, clampZoom, CONTENT_INSET, DEFAULT_ALLOCATED_LINES, DEFAULT_LAYOUT_METRICS, layoutFolded, layoutMeasured, placeEdgeLabels, rectUnion, relationRoute, sceneNodes, } from "@sentropic/diagram-canvas";
|
|
15
|
+
/**
|
|
16
|
+
* `targetWidth` handed to the engine when the host supplies none. The
|
|
17
|
+
* measured path never re-packs on it (D-3) and the host never reads the
|
|
18
|
+
* layout fit report (Z-8), so a resize re-runs no layout.
|
|
19
|
+
*/
|
|
20
|
+
export const DEFAULT_SCENE_TARGET_WIDTH = 1440;
|
|
21
|
+
/**
|
|
22
|
+
* Edge-label wrapping width of the measured path (`measured.ts`, §4.6.3
|
|
23
|
+
* step 5). The engine does not export it; rendered text must wrap with the
|
|
24
|
+
* same allocation as the engine's measured label.
|
|
25
|
+
*/
|
|
26
|
+
export const EDGE_LABEL_ALLOCATION = 400;
|
|
27
|
+
/** Zoom ratio of one button or key step. */
|
|
28
|
+
export const ZOOM_STEP_RATIO = 1.2;
|
|
29
|
+
/** Zoom ratio per wheel delta unit (Ctrl + wheel, trackpad pinch). */
|
|
30
|
+
export const WHEEL_ZOOM_RATE = 0.0015;
|
|
31
|
+
/**
|
|
32
|
+
* One full layout pass (§6.5: fold → measure → place → route, never patched).
|
|
33
|
+
* Row-pack is always selected: an absent `rowPack` resolves to the DS
|
|
34
|
+
* defaults. `measureText` is the compatibility measurer the measured path
|
|
35
|
+
* never calls; it is derived from the shared line measurer so the type's
|
|
36
|
+
* required field carries no second metric source.
|
|
37
|
+
*/
|
|
38
|
+
export function layoutScene(input) {
|
|
39
|
+
const options = {
|
|
40
|
+
registry: input.registry,
|
|
41
|
+
...(input.bindings === undefined ? {} : { bindings: input.bindings }),
|
|
42
|
+
measureText: (text) => {
|
|
43
|
+
const layout = input.measureLines({
|
|
44
|
+
text,
|
|
45
|
+
role: "body",
|
|
46
|
+
availableWidth: Number.MAX_SAFE_INTEGER,
|
|
47
|
+
allocatedLines: 1,
|
|
48
|
+
folded: false,
|
|
49
|
+
});
|
|
50
|
+
return { width: layout.width, height: layout.height };
|
|
51
|
+
},
|
|
52
|
+
presentation: input.presentation,
|
|
53
|
+
measureLines: input.measureLines,
|
|
54
|
+
collapsed: input.collapsed,
|
|
55
|
+
...(input.hints === undefined ? {} : { hints: input.hints }),
|
|
56
|
+
...(input.metrics === undefined ? {} : { metrics: input.metrics }),
|
|
57
|
+
rowPack: input.rowPack ?? {},
|
|
58
|
+
targetWidth: input.targetWidth ?? DEFAULT_SCENE_TARGET_WIDTH,
|
|
59
|
+
...(input.previousOrientation === undefined ? {} : { previousOrientation: input.previousOrientation }),
|
|
60
|
+
};
|
|
61
|
+
return input.view === undefined
|
|
62
|
+
? layoutMeasured(input.document, options)
|
|
63
|
+
: layoutFolded(input.document, input.view, options);
|
|
64
|
+
}
|
|
65
|
+
/** Collapsed occurrence ids recorded by a view's fold groups. */
|
|
66
|
+
export function collapsedOccurrencesOf(view) {
|
|
67
|
+
if (view === undefined)
|
|
68
|
+
return [];
|
|
69
|
+
const found = [];
|
|
70
|
+
for (const key of Object.keys(view.groups).sort()) {
|
|
71
|
+
const group = view.groups[key];
|
|
72
|
+
if (group.collapsed === true && group.occurrence !== undefined)
|
|
73
|
+
found.push(group.occurrence);
|
|
74
|
+
}
|
|
75
|
+
return found;
|
|
76
|
+
}
|
|
77
|
+
const byCodeUnit = (left, right) => (left < right ? -1 : left > right ? 1 : 0);
|
|
78
|
+
function edgeLabelOf(document, relation) {
|
|
79
|
+
const attributes = document.relations[relation]?.attributes;
|
|
80
|
+
const label = attributes?.["label"];
|
|
81
|
+
return label !== undefined && label.kind === "text" && typeof label.value === "string" && label.value !== ""
|
|
82
|
+
? label.value
|
|
83
|
+
: undefined;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The drawable scene of one laid-out result: nodes at emitted geometry,
|
|
87
|
+
* routes, and the engine's emitted edge-label boxes. Results without emitted
|
|
88
|
+
* boxes use the legacy placement replay with the same measurer, margin and
|
|
89
|
+
* blockers (cards, collapsed boxes and expanded-zone title bands).
|
|
90
|
+
*/
|
|
91
|
+
export function resolveScene(result, input) {
|
|
92
|
+
const view = result.view;
|
|
93
|
+
const frame = buildScene({ document: input.document, views: { [view.viewId]: view } }, view.viewId);
|
|
94
|
+
const collapsed = new Set(collapsedOccurrencesOf(view));
|
|
95
|
+
const nodes = sceneNodes(frame).map((node) => {
|
|
96
|
+
const presentation = input.presentation.entities[node.occurrence];
|
|
97
|
+
const form = presentation?.form;
|
|
98
|
+
const titled = presentation?.text.title !== undefined && presentation.text.title !== "";
|
|
99
|
+
const kind = form === "legend-key"
|
|
100
|
+
? "legend-key"
|
|
101
|
+
: !titled
|
|
102
|
+
? "label"
|
|
103
|
+
: form === "card"
|
|
104
|
+
? "card"
|
|
105
|
+
: form === "container" || form === "legend"
|
|
106
|
+
? "zone"
|
|
107
|
+
: "label";
|
|
108
|
+
return {
|
|
109
|
+
occurrence: node.occurrence,
|
|
110
|
+
entity: node.entity,
|
|
111
|
+
kind,
|
|
112
|
+
collapsed: kind === "zone" && collapsed.has(node.occurrence),
|
|
113
|
+
rect: node.rect,
|
|
114
|
+
...(presentation === undefined ? {} : { presentation }),
|
|
115
|
+
text: presentation?.text.title ?? presentation?.text.body ?? "",
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
const headerHeights = new Map((result.measurements?.headers ?? []).map((header) => [header.occurrence, header.height]));
|
|
119
|
+
const blockers = [];
|
|
120
|
+
for (const node of nodes) {
|
|
121
|
+
if (node.kind !== "zone" || node.collapsed) {
|
|
122
|
+
blockers.push(node.rect);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const height = headerHeights.get(node.occurrence);
|
|
126
|
+
if (height === undefined)
|
|
127
|
+
continue;
|
|
128
|
+
blockers.push({
|
|
129
|
+
x: node.rect.x + CONTENT_INSET,
|
|
130
|
+
y: node.rect.y + CONTENT_INSET,
|
|
131
|
+
width: node.rect.width - 2 * CONTENT_INSET,
|
|
132
|
+
height,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const edges = [];
|
|
136
|
+
const entries = [];
|
|
137
|
+
const labelLines = new Map();
|
|
138
|
+
for (const id of Object.keys(view.relationOccurrences).sort(byCodeUnit)) {
|
|
139
|
+
const occurrence = view.relationOccurrences[id];
|
|
140
|
+
if (occurrence.waypoints === undefined)
|
|
141
|
+
continue;
|
|
142
|
+
const points = relationRoute(view, occurrence.id) ?? [];
|
|
143
|
+
if (points.length < 2)
|
|
144
|
+
continue;
|
|
145
|
+
edges.push({ occurrence: occurrence.id, points });
|
|
146
|
+
const label = edgeLabelOf(input.document, occurrence.relation);
|
|
147
|
+
if (label === undefined)
|
|
148
|
+
continue;
|
|
149
|
+
const layout = input.measureLines({
|
|
150
|
+
text: label,
|
|
151
|
+
role: "edge-label",
|
|
152
|
+
availableWidth: EDGE_LABEL_ALLOCATION,
|
|
153
|
+
allocatedLines: DEFAULT_ALLOCATED_LINES["edge-label"],
|
|
154
|
+
folded: false,
|
|
155
|
+
});
|
|
156
|
+
labelLines.set(id, layout.lines);
|
|
157
|
+
entries.push({ id, route: points, size: { width: layout.width, height: layout.height } });
|
|
158
|
+
}
|
|
159
|
+
const margin = input.metrics?.labelMargin ?? DEFAULT_LAYOUT_METRICS.labelMargin;
|
|
160
|
+
const labels = [];
|
|
161
|
+
let bounds = frame.bounds;
|
|
162
|
+
const replayed = result.labelBoxes === undefined ? placeEdgeLabels(entries, blockers, margin) : undefined;
|
|
163
|
+
for (const { id } of entries) {
|
|
164
|
+
const box = result.labelBoxes === undefined ? replayed?.get(id)?.box : result.labelBoxes[id];
|
|
165
|
+
if (box === undefined)
|
|
166
|
+
continue;
|
|
167
|
+
labels.push({ occurrence: id, lines: labelLines.get(id) ?? [], box });
|
|
168
|
+
bounds = bounds === undefined ? box : rectUnion(bounds, box);
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
nodes,
|
|
172
|
+
edges,
|
|
173
|
+
labels,
|
|
174
|
+
...(bounds === undefined ? {} : { bounds }),
|
|
175
|
+
orientations: result.orientations ?? {},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** §5.1 / BF-2 fit of the scene bounds, as `cameraFit` computes it. */
|
|
179
|
+
export function sceneFit(input) {
|
|
180
|
+
return cameraFit({
|
|
181
|
+
...(input.bounds === undefined ? {} : { bounds: input.bounds }),
|
|
182
|
+
viewWidth: input.viewWidth,
|
|
183
|
+
windowHeight: input.windowHeight,
|
|
184
|
+
...(input.maxDisplayScale === undefined ? {} : { maxDisplayScale: input.maxDisplayScale }),
|
|
185
|
+
...(input.minReadableScale === undefined ? {} : { minReadableScale: input.minReadableScale }),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The camera zoom for a request (Z-1, Z-7, Z-8). `undefined` means « no
|
|
190
|
+
* request yet »: the camera sits at the fit. Any number lands inside the
|
|
191
|
+
* current `[minZoom, maxZoom]`, whatever input produced it.
|
|
192
|
+
*/
|
|
193
|
+
export function resolveZoom(requested, fit) {
|
|
194
|
+
return requested === undefined || !Number.isFinite(requested) ? fit.zoom : clampZoom(requested, fit);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Where the drawing sits in the fit box at a zoom: centred on every axis it
|
|
198
|
+
* fits, flush with the start on an axis it overflows (the viewport scrolls
|
|
199
|
+
* that axis). Transform only — geometry is never touched (Z-6).
|
|
200
|
+
*/
|
|
201
|
+
export function scenePlacement(bounds, zoom, fit) {
|
|
202
|
+
if (bounds === undefined) {
|
|
203
|
+
return { contentWidth: 0, contentHeight: 0, translateX: 0, translateY: 0, overflowX: false, overflowY: false };
|
|
204
|
+
}
|
|
205
|
+
const contentWidth = bounds.width * zoom;
|
|
206
|
+
const contentHeight = bounds.height * zoom;
|
|
207
|
+
// Half a CSS px of tolerance: a fit computed by division must not scroll.
|
|
208
|
+
const overflowX = contentWidth > fit.fitWidth + 0.5;
|
|
209
|
+
const overflowY = contentHeight > fit.fitHeight + 0.5;
|
|
210
|
+
const startX = overflowX ? 0 : (fit.fitWidth - contentWidth) / 2;
|
|
211
|
+
const startY = overflowY ? 0 : (fit.fitHeight - contentHeight) / 2;
|
|
212
|
+
return {
|
|
213
|
+
contentWidth,
|
|
214
|
+
contentHeight,
|
|
215
|
+
translateX: startX - bounds.x * zoom,
|
|
216
|
+
translateY: startY - bounds.y * zoom,
|
|
217
|
+
overflowX,
|
|
218
|
+
overflowY,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/* ─────────────────────────── transition ─────────────────────────── */
|
|
222
|
+
/** A CSS `<time>` token value (`240ms`, `0.24s`) in milliseconds; 0 when absent or unreadable. */
|
|
223
|
+
export function parseDurationMs(value) {
|
|
224
|
+
if (value === undefined)
|
|
225
|
+
return 0;
|
|
226
|
+
const match = /^\s*([+-]?(?:\d+\.?\d*|\.\d+))(ms|s)\s*$/.exec(value);
|
|
227
|
+
if (match === null)
|
|
228
|
+
return 0;
|
|
229
|
+
const amount = Number(match[1]) * (match[2] === "s" ? 1000 : 1);
|
|
230
|
+
return Number.isFinite(amount) && amount > 0 ? amount : 0;
|
|
231
|
+
}
|
|
232
|
+
/** A unitless number token value; `undefined` when absent or unreadable. */
|
|
233
|
+
export function parseScale(value) {
|
|
234
|
+
if (value === undefined || value.trim() === "")
|
|
235
|
+
return undefined;
|
|
236
|
+
const amount = Number(value);
|
|
237
|
+
return Number.isFinite(amount) && amount > 0 ? amount : undefined;
|
|
238
|
+
}
|
|
239
|
+
const linear = (progress) => progress;
|
|
240
|
+
/**
|
|
241
|
+
* The easing of a CSS `cubic-bezier(x1, y1, x2, y2)` token value. Any other
|
|
242
|
+
* value (absent token, keyword) is linear: the host holds no easing literal.
|
|
243
|
+
*/
|
|
244
|
+
export function parseEasing(value) {
|
|
245
|
+
if (value === undefined)
|
|
246
|
+
return linear;
|
|
247
|
+
const match = /^\s*cubic-bezier\(\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^)]+)\)\s*$/.exec(value);
|
|
248
|
+
if (match === null)
|
|
249
|
+
return linear;
|
|
250
|
+
const [x1, y1, x2, y2] = match.slice(1, 5).map(Number);
|
|
251
|
+
if (![x1, y1, x2, y2].every(Number.isFinite) || x1 < 0 || x1 > 1 || x2 < 0 || x2 > 1)
|
|
252
|
+
return linear;
|
|
253
|
+
const bezier = (a, b, t) => {
|
|
254
|
+
const inverse = 1 - t;
|
|
255
|
+
return 3 * inverse * inverse * t * a + 3 * inverse * t * t * b + t * t * t;
|
|
256
|
+
};
|
|
257
|
+
return (progress) => {
|
|
258
|
+
if (progress <= 0)
|
|
259
|
+
return 0;
|
|
260
|
+
if (progress >= 1)
|
|
261
|
+
return 1;
|
|
262
|
+
// x(t) is monotonic for control abscissae in [0, 1]: bisect for t.
|
|
263
|
+
let low = 0;
|
|
264
|
+
let high = 1;
|
|
265
|
+
for (let step = 0; step < 32; step += 1) {
|
|
266
|
+
const middle = (low + high) / 2;
|
|
267
|
+
if (bezier(x1, x2, middle) < progress)
|
|
268
|
+
low = middle;
|
|
269
|
+
else
|
|
270
|
+
high = middle;
|
|
271
|
+
}
|
|
272
|
+
return bezier(y1, y2, (low + high) / 2);
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
export function interpolateRect(from, to, eased) {
|
|
276
|
+
const mix = (a, b) => a + (b - a) * eased;
|
|
277
|
+
return { x: mix(from.x, to.x), y: mix(from.y, to.y), width: mix(from.width, to.width), height: mix(from.height, to.height) };
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Displayed rectangles of a transition (T-1): every occurrence present in
|
|
281
|
+
* both states moves from its previous to its new rectangle; an occurrence
|
|
282
|
+
* with no previous rectangle sits at its final one (the host fades it in).
|
|
283
|
+
* `eased >= 1` returns the final rectangles themselves, so a finished or
|
|
284
|
+
* instant transition is exactly the layout output.
|
|
285
|
+
*/
|
|
286
|
+
export function displayedRects(from, to, eased) {
|
|
287
|
+
if (eased >= 1)
|
|
288
|
+
return to;
|
|
289
|
+
const displayed = new Map();
|
|
290
|
+
for (const [id, target] of to) {
|
|
291
|
+
const origin = from.get(id);
|
|
292
|
+
displayed.set(id, origin === undefined ? target : interpolateRect(origin, target, eased));
|
|
293
|
+
}
|
|
294
|
+
return displayed;
|
|
295
|
+
}
|
|
296
|
+
export function rectsOf(scene) {
|
|
297
|
+
return new Map(scene.nodes.map((node) => [node.occurrence, node.rect]));
|
|
298
|
+
}
|
|
299
|
+
/** Whether two rectangle sets are the same drawing: same ids, same numbers. */
|
|
300
|
+
export function sameRects(left, right) {
|
|
301
|
+
if (left.size !== right.size)
|
|
302
|
+
return false;
|
|
303
|
+
for (const [id, a] of left) {
|
|
304
|
+
const b = right.get(id);
|
|
305
|
+
if (b === undefined || a.x !== b.x || a.y !== b.y || a.width !== b.width || a.height !== b.height)
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
return true;
|
|
309
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -83,6 +83,9 @@ export type { DiagramCardProps } from "./DiagramCard.svelte";
|
|
|
83
83
|
export { default as DiagramZone } from "./DiagramZone.svelte";
|
|
84
84
|
export type { DiagramZoneProps } from "./DiagramZone.svelte";
|
|
85
85
|
export type { DiagramCardToggle, DiagramGlyphPaths, DiagramZoneToggle, ZoneDiagnostic, ZoneChildSpec, } from "./diagramCardModel.js";
|
|
86
|
+
export { default as DiagramSceneFigure } from "./DiagramSceneFigure.svelte";
|
|
87
|
+
export type { DiagramSceneCamera, DiagramSceneFigureLabels, DiagramSceneFigureProps, } from "./DiagramSceneFigure.svelte";
|
|
88
|
+
export type { SceneDocument, SceneOccurrenceRef, ScenePresentation, SceneView, } from "@sentropic/diagram-canvas/diagramSceneModel";
|
|
86
89
|
export { default as Divider } from "./Divider.svelte";
|
|
87
90
|
export { default as DonutChart } from "./DonutChart.svelte";
|
|
88
91
|
export { default as Drawer } from "./Drawer.svelte";
|
|
@@ -402,4 +405,7 @@ export { default as Dashboard } from "./Dashboard.svelte";
|
|
|
402
405
|
export type { DashboardProps, DashboardNavItem, DashboardKpi } from "./Dashboard.svelte";
|
|
403
406
|
export { default as Wizard } from "./Wizard.svelte";
|
|
404
407
|
export type { WizardProps, WizardStep } from "./Wizard.svelte";
|
|
408
|
+
export { createLayoutCache } from "@sentropic/diagram-canvas";
|
|
409
|
+
export type { LayoutCacheConfig, LayoutCacheStats } from "@sentropic/diagram-canvas";
|
|
410
|
+
export type { DiagramSceneSize, SceneLayoutCache } from "@sentropic/diagram-canvas/diagramSceneModel";
|
|
405
411
|
//# sourceMappingURL=index.d.ts.map
|