@sentropic/design-system-svelte 0.41.2 → 0.41.4
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.
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import DiagramCard from "./DiagramCard.svelte";
|
|
21
21
|
import DiagramZone from "./DiagramZone.svelte";
|
|
22
22
|
import IconButton from "./IconButton.svelte";
|
|
23
|
-
import { measureRenderedBounds } from "./diagramRenderedBounds.js";
|
|
23
|
+
import { measureRenderedBounds, shouldRefitRenderedBounds } from "./diagramRenderedBounds.js";
|
|
24
24
|
import { measureRenderedSceneFont } from "./diagramFontMeasure.js";
|
|
25
25
|
import Select from "./Select.svelte";
|
|
26
26
|
import { DEFAULT_FLOW_TOKENS, type FlowTokens } from "@sentropic/diagram-canvas";
|
|
@@ -49,7 +49,9 @@
|
|
|
49
49
|
resolveScene,
|
|
50
50
|
resolveZoom,
|
|
51
51
|
sameRects,
|
|
52
|
+
sceneConnectorMask,
|
|
52
53
|
sceneFit,
|
|
54
|
+
sceneNodesOnPlane,
|
|
53
55
|
sceneTextRows,
|
|
54
56
|
scenePlacement,
|
|
55
57
|
WHEEL_ZOOM_RATE,
|
|
@@ -254,6 +256,7 @@
|
|
|
254
256
|
const collapsedNow = $derived(collapsed ?? foldState);
|
|
255
257
|
const arrowInstance = $props.id();
|
|
256
258
|
const arrowId = "diagram-arrow-" + arrowInstance;
|
|
259
|
+
const maskId = "diagram-connector-mask-" + arrowInstance;
|
|
257
260
|
let browserMeasure = $state.raw<CardLineMeasure>();
|
|
258
261
|
const effectiveMeasure = $derived(sceneCardMeasure(measure === defaultCardMeasure ? browserMeasure ?? measure : measure));
|
|
259
262
|
let tokenMetrics = $state.raw<Partial<LayoutMetrics>>({});
|
|
@@ -502,17 +505,25 @@
|
|
|
502
505
|
let minReadableScale = $state<number>();
|
|
503
506
|
let renderedBounds = $state.raw<{ scene: SceneModel; bounds: Rect }>();
|
|
504
507
|
const cameraBounds = $derived(renderedBounds?.scene === scene ? renderedBounds?.bounds : scene?.bounds);
|
|
508
|
+
// `zoom` is the scale the world is painted at: the fit is quantised once,
|
|
509
|
+
// in `sceneFit`, and printed as it is, so painted rects divide back by it.
|
|
510
|
+
// The first read of a scene fits; a later one refits only when it differs
|
|
511
|
+
// from that read by more than the measurement granularity. A read that
|
|
512
|
+
// comes back as the model bounds is a read like any other: it replaces an
|
|
513
|
+
// earlier, larger one, and the next one is compared to it.
|
|
514
|
+
// A fold transition paints interpolated rectangles and fading layers: no
|
|
515
|
+
// read happens while it runs, one happens when it settles.
|
|
505
516
|
function readRenderedBounds(): void {
|
|
506
|
-
if (frameEl === undefined || scene === undefined) return;
|
|
517
|
+
if (frameEl === undefined || scene === undefined || animating) return;
|
|
507
518
|
const bounds = measureRenderedBounds(frameEl, scene.bounds, zoom);
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
519
|
+
const previous = renderedBounds?.scene === scene ? renderedBounds.bounds : undefined;
|
|
520
|
+
if (bounds === undefined || !shouldRefitRenderedBounds(previous, bounds)) return;
|
|
521
|
+
if (atFit) requestedZoom = undefined;
|
|
522
|
+
renderedBounds = { scene, bounds };
|
|
512
523
|
}
|
|
513
524
|
$effect(() => {
|
|
514
525
|
const current = scene;
|
|
515
|
-
if (current === undefined) return;
|
|
526
|
+
if (current === undefined || animating) return;
|
|
516
527
|
let active = true;
|
|
517
528
|
void tick().then(() => { if (active && scene === current) readRenderedBounds(); });
|
|
518
529
|
return () => { active = false; };
|
|
@@ -682,8 +693,13 @@
|
|
|
682
693
|
|
|
683
694
|
/** Z-3/Z-4: fit and reset are one action. An overflowing axis scrolls from its start. */
|
|
684
695
|
export function fitToFrame(): void {
|
|
696
|
+
// The DOM still shows the scene as it was before this call: a running
|
|
697
|
+
// transition is ended here and read once its end state is patched in,
|
|
698
|
+
// as is a scene the tokens read below have just replaced.
|
|
699
|
+
const painted = animating ? undefined : scene;
|
|
700
|
+
if (animating) settle();
|
|
685
701
|
readCameraTokens();
|
|
686
|
-
readRenderedBounds();
|
|
702
|
+
if (scene === painted) readRenderedBounds();
|
|
687
703
|
atFit = true;
|
|
688
704
|
requestedZoom = undefined;
|
|
689
705
|
const element = viewportEl;
|
|
@@ -984,31 +1000,7 @@
|
|
|
984
1000
|
>
|
|
985
1001
|
<div class="st-diagramSceneFigure-world" style={worldStyle} data-flow-active={flowHighlight !== undefined && (flowHighlight.primary.size > 0 || flowHighlight.dimmed.size > 0) ? "true" : undefined}>
|
|
986
1002
|
{#if scene !== undefined}
|
|
987
|
-
|
|
988
|
-
fade in with the transition (T-1) while the boxes move. -->
|
|
989
|
-
<svg
|
|
990
|
-
class="st-diagramSceneFigure-edges"
|
|
991
|
-
aria-hidden="true"
|
|
992
|
-
style={animating ? `opacity:${eased}` : undefined}
|
|
993
|
-
>
|
|
994
|
-
<defs><marker id={arrowId} viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10Z" fill="var(--st-component-diagramScene-edgeStroke, #64748b)" /></marker></defs>
|
|
995
|
-
{#each scene.edges as edge (edge.occurrence)}
|
|
996
|
-
<polyline marker-end={edge.markers === undefined && !edge.directed ? `url(#${arrowId})` : undefined} class="st-diagramSceneFigure-edge" data-scene-edge={edge.occurrence} data-flow-step={edge.flow?.relation} data-flow-bundle={edge.bundle?.id} data-flow-state={stateOf(edge.occurrence)} points={pointsOf(edge.points)} />
|
|
997
|
-
{#if edge.directed}
|
|
998
|
-
<polyline class="st-diagramSceneFigure-flowHit" data-flow-hit={edge.occurrence} points={pointsOf(edge.points)} />
|
|
999
|
-
{#each edge.arrows as arrow, index (index)}
|
|
1000
|
-
<path class="st-diagramSceneFigure-flowArrow" data-flow-arrow={edge.occurrence} data-flow-state={stateOf(edge.occurrence)} d={flowTokens.flowArrowPath} transform={`translate(${arrow.tip.x} ${arrow.tip.y}) rotate(${arrow.angle}) translate(${-flowTokens.flowArrowLength} ${-flowTokens.flowArrowWidth / 2})`} />
|
|
1001
|
-
{/each}
|
|
1002
|
-
{/if}
|
|
1003
|
-
{/each}
|
|
1004
|
-
{#each scene.edges as edge (edge.occurrence)}
|
|
1005
|
-
{#if edge.markers}<g>{@html edge.markers}</g>{/if}
|
|
1006
|
-
{/each}
|
|
1007
|
-
{#each scene.labels as edgeLabel (edgeLabel.occurrence)}
|
|
1008
|
-
{#if edgeLabel.leader}<polyline class="st-diagramSceneFigure-edge" points={pointsOf(edgeLabel.leader)} />{/if}
|
|
1009
|
-
{/each}
|
|
1010
|
-
</svg>
|
|
1011
|
-
{#each scene.nodes as node (node.occurrence)}
|
|
1003
|
+
{#snippet sceneNode(node: SceneNodeModel)}
|
|
1012
1004
|
{@const rect = rectOf(node)}
|
|
1013
1005
|
<div
|
|
1014
1006
|
class="st-diagramSceneFigure-node"
|
|
@@ -1034,7 +1026,41 @@
|
|
|
1034
1026
|
<div class="st-diagramSceneFigure-label" data-entity={node.entity}>{node.text}</div>
|
|
1035
1027
|
{/if}
|
|
1036
1028
|
</div>
|
|
1037
|
-
{/
|
|
1029
|
+
{/snippet}
|
|
1030
|
+
{@const connectorMask = sceneConnectorMask(scene)}
|
|
1031
|
+
<!-- Paint order (diagram-canvas `scenePaintPlane`): expanded zone
|
|
1032
|
+
frames, connectors, boxes, labels last. A zone frame is opaque:
|
|
1033
|
+
painted after the connectors it would hide every route that
|
|
1034
|
+
runs inside it. The connector layer is masked over the footer
|
|
1035
|
+
text a frame paints itself, so a route leaving a zone passes
|
|
1036
|
+
behind it. Edges and labels fade in with the transition (T-1)
|
|
1037
|
+
while the boxes move. -->
|
|
1038
|
+
{#each sceneNodesOnPlane(scene.nodes, "frame") as node (node.occurrence)}{@render sceneNode(node)}{/each}
|
|
1039
|
+
<svg
|
|
1040
|
+
class="st-diagramSceneFigure-edges"
|
|
1041
|
+
aria-hidden="true"
|
|
1042
|
+
style={animating ? `opacity:${eased}` : undefined}
|
|
1043
|
+
>
|
|
1044
|
+
<defs><marker id={arrowId} viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10Z" fill="var(--st-component-diagramScene-edgeStroke, #64748b)" /></marker>{#if connectorMask !== undefined}<mask id={maskId} maskUnits="userSpaceOnUse" x={connectorMask.region.x} y={connectorMask.region.y} width={connectorMask.region.width} height={connectorMask.region.height}><rect x={connectorMask.region.x} y={connectorMask.region.y} width={connectorMask.region.width} height={connectorMask.region.height} fill="#fff" />{#each connectorMask.cutouts as cutout, index (index)}<rect data-scene-cutout={index} x={cutout.x} y={cutout.y} width={cutout.width} height={cutout.height} fill="#000" />{/each}</mask>{/if}</defs>
|
|
1045
|
+
<g data-scene-connectors="" mask={connectorMask === undefined ? undefined : `url(#${maskId})`}>
|
|
1046
|
+
{#each scene.edges as edge (edge.occurrence)}
|
|
1047
|
+
<polyline marker-end={edge.markers === undefined && !edge.directed ? `url(#${arrowId})` : undefined} class="st-diagramSceneFigure-edge" data-scene-edge={edge.occurrence} data-flow-step={edge.flow?.relation} data-flow-bundle={edge.bundle?.id} data-flow-state={stateOf(edge.occurrence)} points={pointsOf(edge.points)} />
|
|
1048
|
+
{#if edge.directed}
|
|
1049
|
+
<polyline class="st-diagramSceneFigure-flowHit" data-flow-hit={edge.occurrence} points={pointsOf(edge.points)} />
|
|
1050
|
+
{#each edge.arrows as arrow, index (index)}
|
|
1051
|
+
<path class="st-diagramSceneFigure-flowArrow" data-flow-arrow={edge.occurrence} data-flow-state={stateOf(edge.occurrence)} d={flowTokens.flowArrowPath} transform={`translate(${arrow.tip.x} ${arrow.tip.y}) rotate(${arrow.angle}) translate(${-flowTokens.flowArrowLength} ${-flowTokens.flowArrowWidth / 2})`} />
|
|
1052
|
+
{/each}
|
|
1053
|
+
{/if}
|
|
1054
|
+
{/each}
|
|
1055
|
+
{#each scene.edges as edge (edge.occurrence)}
|
|
1056
|
+
{#if edge.markers}<g>{@html edge.markers}</g>{/if}
|
|
1057
|
+
{/each}
|
|
1058
|
+
{#each scene.labels as edgeLabel (edgeLabel.occurrence)}
|
|
1059
|
+
{#if edgeLabel.leader}<polyline class="st-diagramSceneFigure-edge" points={pointsOf(edgeLabel.leader)} />{/if}
|
|
1060
|
+
{/each}
|
|
1061
|
+
</g>
|
|
1062
|
+
</svg>
|
|
1063
|
+
{#each sceneNodesOnPlane(scene.nodes, "box") as node (node.occurrence)}{@render sceneNode(node)}{/each}
|
|
1038
1064
|
{#each scene.badges as badge (badge.id)}
|
|
1039
1065
|
<button type="button" class="st-diagramSceneFigure-flowBadge" data-flow-badge={badge.id} data-flow-state={stateOf(badge.occurrence)} aria-pressed={JSON.stringify(selectedVisible) === JSON.stringify(badge.target)} aria-describedby={descriptionId("badge", badge.id)} tabindex={badgeTab === badge.id ? 0 : -1} style={`left:${badge.box.x}px;top:${badge.box.y}px;width:${badge.box.width}px;height:${badge.box.height}px`}>{badge.text}</button>
|
|
1040
1066
|
<span class="st-diagramSceneFigure-flowDescription" id={descriptionId("badge", badge.id)}>{flowDescription(badge.target)}</span>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagramSceneFigure.svelte.d.ts","sourceRoot":"","sources":["../src/lib/DiagramSceneFigure.svelte.ts"],"names":[],"mappings":"AAMA,OAAO,EAMH,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EAEjB,KAAK,cAAc,EACpB,MAAM,2BAA2B,CAAC;AASrC,OAAO,EAAqN,KAAK,UAAU,EAAE,KAAK,eAAe,EAAoB,MAAM,qCAAqC,CAAC;AACjU,OAAO,EAMH,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AACjC,OAAO,EAGH,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"DiagramSceneFigure.svelte.d.ts","sourceRoot":"","sources":["../src/lib/DiagramSceneFigure.svelte.ts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,IAAI;sBAKD,IAAI;qBAkBL,kBAAkB;iBAmVqB,CAAC;AACjE,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAChE,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,6 +1,66 @@
|
|
|
1
|
-
import type
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
1
|
+
import { type Rect } from '@sentropic/diagram-canvas';
|
|
2
|
+
/**
|
|
3
|
+
* Steps per unit of the grid painted bounds are read on. Browsers lay out
|
|
4
|
+
* and report rects on 1/64 CSS px (LayoutUnit), and `measureRenderedBounds`
|
|
5
|
+
* rounds each outer edge outward to 1/64 world unit.
|
|
6
|
+
*/
|
|
7
|
+
export declare const RENDERED_BOUNDS_GRID_STEPS = 64;
|
|
8
|
+
/**
|
|
9
|
+
* World-unit tolerance under which two painted-bounds reads are the same
|
|
10
|
+
* bounds. It is the granularity of the measurement below, not a tuned
|
|
11
|
+
* constant, which is why it lives with the measurement in the host:
|
|
12
|
+
*
|
|
13
|
+
* - a painted edge is read as `(edge − origin) / zoom`, both operands on the
|
|
14
|
+
* LayoutUnit grid, so a read places it within one LayoutUnit of screen
|
|
15
|
+
* space: `1 / (64 × zoom)` world unit;
|
|
16
|
+
* - no read happens under the readability floor (the camera never applies
|
|
17
|
+
* a smaller zoom), where that step is at its widest: `1 / (64 × 0.45)`;
|
|
18
|
+
* - the edge is then rounded outward to the 1/64 world-unit grid, which
|
|
19
|
+
* moves it by less than one more step;
|
|
20
|
+
* - a stroke is added to its edge in world units, at one width for every
|
|
21
|
+
* zoom and interaction state (see `measureRenderedBounds`): it shifts
|
|
22
|
+
* both reads alike.
|
|
23
|
+
*
|
|
24
|
+
* Two reads of an unchanged edge, through any two transforms, therefore
|
|
25
|
+
* differ by less than `(2 / 0.45 + 1) / 64` ≈ 0.085 world unit. On screen
|
|
26
|
+
* that is more than `(1 + zoom) / 64` CSS px at every zoom the camera
|
|
27
|
+
* applies: one LayoutUnit step read back through the outward rounding,
|
|
28
|
+
* which spans up to `ceil(1 / zoom) / 64` world unit (2/64 at 0.62, 3/64 at
|
|
29
|
+
* 0.45). A bare 1/64 CSS px is under that step: it refits on a flip of the
|
|
30
|
+
* last grid step, and a fit then alternates between two transforms. At the
|
|
31
|
+
* 0.62 cap the tolerance is 0.053 CSS px, far under the 1 CSS px paint
|
|
32
|
+
* inset, so it cannot hide a real overflow.
|
|
33
|
+
*/
|
|
34
|
+
export declare const RENDERED_BOUNDS_REFIT_TOLERANCE: number;
|
|
35
|
+
/**
|
|
36
|
+
* Whether a painted-bounds read differs enough from the previous read of
|
|
37
|
+
* the same scene to refit. The first read (`previous` absent) always fits:
|
|
38
|
+
* the tolerance bounds the distance between two reads, not between a read
|
|
39
|
+
* and the model geometry. From then on a fit is a fixed point: reading the
|
|
40
|
+
* same paint again, through any transform, never moves it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function shouldRefitRenderedBounds(previous: Rect | undefined, next: Rect): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Painted bounds in world units, after font/layout settling. DOM-free scene
|
|
45
|
+
* geometry remains the SSR fallback. Include text ink and SVG strokes:
|
|
46
|
+
* getBoundingClientRect alone excludes both text overshoot and stroke width.
|
|
47
|
+
* `zoom` is the scale the world is painted at; the scale committed on the
|
|
48
|
+
* world element takes precedence, since a camera input changes the host's
|
|
49
|
+
* zoom one flush before the DOM follows.
|
|
50
|
+
*
|
|
51
|
+
* The result does not depend on that scale, nor on a transient interaction
|
|
52
|
+
* state, beyond the read granularity `RENDERED_BOUNDS_REFIT_TOLERANCE` covers:
|
|
53
|
+
*
|
|
54
|
+
* - a stroke that scales with the world has a constant world width;
|
|
55
|
+
* - a `non-scaling-stroke` has a constant screen width, so its world width
|
|
56
|
+
* is `width / zoom`. It is framed at its widest, the one it has at the
|
|
57
|
+
* readability floor (`DEFAULT_MIN_READABLE_SCALE`, under which the camera
|
|
58
|
+
* never paints), at every zoom, and at its resting width;
|
|
59
|
+
* - geometry that paints nothing is left out: flow hit targets
|
|
60
|
+
* (`[data-flow-hit]`, a transparent 16 px stroke), flow focus targets
|
|
61
|
+
* (`[data-flow-node]`, hidden at rest and sized in screen px), transparent
|
|
62
|
+
* strokes and text, shapes with neither stroke nor fill, and hidden or
|
|
63
|
+
* clipped subtrees. What a fold transition is fading in stays in.
|
|
64
|
+
*/
|
|
65
|
+
export declare function measureRenderedBounds(frame: HTMLElement, fallback: Rect | undefined, hostZoom: number): Rect | undefined;
|
|
6
66
|
//# sourceMappingURL=diagramRenderedBounds.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagramRenderedBounds.d.ts","sourceRoot":"","sources":["../src/lib/diagramRenderedBounds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"diagramRenderedBounds.d.ts","sourceRoot":"","sources":["../src/lib/diagramRenderedBounds.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAElF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAG7C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,+BAA+B,QAA8C,CAAC;AAE3F;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CASzF;AAuDD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CA8ExH"}
|
|
@@ -1,9 +1,134 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
1
|
+
import { DEFAULT_MIN_READABLE_SCALE } from '@sentropic/diagram-canvas';
|
|
2
|
+
/**
|
|
3
|
+
* Steps per unit of the grid painted bounds are read on. Browsers lay out
|
|
4
|
+
* and report rects on 1/64 CSS px (LayoutUnit), and `measureRenderedBounds`
|
|
5
|
+
* rounds each outer edge outward to 1/64 world unit.
|
|
6
|
+
*/
|
|
7
|
+
export const RENDERED_BOUNDS_GRID_STEPS = 64;
|
|
8
|
+
const GRID = RENDERED_BOUNDS_GRID_STEPS;
|
|
9
|
+
/**
|
|
10
|
+
* World-unit tolerance under which two painted-bounds reads are the same
|
|
11
|
+
* bounds. It is the granularity of the measurement below, not a tuned
|
|
12
|
+
* constant, which is why it lives with the measurement in the host:
|
|
13
|
+
*
|
|
14
|
+
* - a painted edge is read as `(edge − origin) / zoom`, both operands on the
|
|
15
|
+
* LayoutUnit grid, so a read places it within one LayoutUnit of screen
|
|
16
|
+
* space: `1 / (64 × zoom)` world unit;
|
|
17
|
+
* - no read happens under the readability floor (the camera never applies
|
|
18
|
+
* a smaller zoom), where that step is at its widest: `1 / (64 × 0.45)`;
|
|
19
|
+
* - the edge is then rounded outward to the 1/64 world-unit grid, which
|
|
20
|
+
* moves it by less than one more step;
|
|
21
|
+
* - a stroke is added to its edge in world units, at one width for every
|
|
22
|
+
* zoom and interaction state (see `measureRenderedBounds`): it shifts
|
|
23
|
+
* both reads alike.
|
|
24
|
+
*
|
|
25
|
+
* Two reads of an unchanged edge, through any two transforms, therefore
|
|
26
|
+
* differ by less than `(2 / 0.45 + 1) / 64` ≈ 0.085 world unit. On screen
|
|
27
|
+
* that is more than `(1 + zoom) / 64` CSS px at every zoom the camera
|
|
28
|
+
* applies: one LayoutUnit step read back through the outward rounding,
|
|
29
|
+
* which spans up to `ceil(1 / zoom) / 64` world unit (2/64 at 0.62, 3/64 at
|
|
30
|
+
* 0.45). A bare 1/64 CSS px is under that step: it refits on a flip of the
|
|
31
|
+
* last grid step, and a fit then alternates between two transforms. At the
|
|
32
|
+
* 0.62 cap the tolerance is 0.053 CSS px, far under the 1 CSS px paint
|
|
33
|
+
* inset, so it cannot hide a real overflow.
|
|
34
|
+
*/
|
|
35
|
+
export const RENDERED_BOUNDS_REFIT_TOLERANCE = (2 / DEFAULT_MIN_READABLE_SCALE + 1) / GRID;
|
|
36
|
+
/**
|
|
37
|
+
* Whether a painted-bounds read differs enough from the previous read of
|
|
38
|
+
* the same scene to refit. The first read (`previous` absent) always fits:
|
|
39
|
+
* the tolerance bounds the distance between two reads, not between a read
|
|
40
|
+
* and the model geometry. From then on a fit is a fixed point: reading the
|
|
41
|
+
* same paint again, through any transform, never moves it.
|
|
42
|
+
*/
|
|
43
|
+
export function shouldRefitRenderedBounds(previous, next) {
|
|
44
|
+
if (previous === undefined)
|
|
45
|
+
return true;
|
|
46
|
+
const delta = Math.max(Math.abs(next.x - previous.x), Math.abs(next.y - previous.y), Math.abs(next.x + next.width - previous.x - previous.width), Math.abs(next.y + next.height - previous.y - previous.height));
|
|
47
|
+
return delta > RENDERED_BOUNDS_REFIT_TOLERANCE;
|
|
48
|
+
}
|
|
49
|
+
/** Token default of a resting connector stroke, CSS px. */
|
|
50
|
+
const RESTING_EDGE_STROKE_WIDTH = 1.5;
|
|
51
|
+
/** Whether a computed colour paints nothing: `transparent` or a zero alpha. */
|
|
52
|
+
function isTransparent(color) {
|
|
53
|
+
const value = color.trim().toLowerCase();
|
|
54
|
+
if (value === 'transparent')
|
|
55
|
+
return true;
|
|
56
|
+
// `rgb(0 0 0 / 0)` and the legacy four-component `rgba(0, 0, 0, 0)`; an
|
|
57
|
+
// opaque `rgb(0, 0, 0)` has three components and no alpha.
|
|
58
|
+
const alpha = /\/\s*([\d.]+%?)\s*\)$/.exec(value)?.[1] ?? /^(?:rgba|hsla)\([^,]+,[^,]+,[^,]+,\s*([\d.]+%?)\s*\)$/.exec(value)?.[1];
|
|
59
|
+
return alpha !== undefined && parseFloat(alpha) === 0;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* What the scene hosts fade during a fold transition: the connector layer,
|
|
63
|
+
* the edge labels and the entering nodes. A zero opacity on one of these is
|
|
64
|
+
* a frame of that fade, not a hidden element: it is painted once the
|
|
65
|
+
* transition settles, and the fit has to frame it.
|
|
66
|
+
*/
|
|
67
|
+
const TRANSITION_FADED = '.st-diagramSceneFigure-edges,.st-diagramSceneFigure-edgeLabel,.st-diagramSceneFigure-node';
|
|
68
|
+
/** Whether an element removes itself and its subtree from the paint for
|
|
69
|
+
* good: not rendered, fully transparent at rest, or clipped to nothing (the
|
|
70
|
+
* screen-reader-only idioms: `clip-path: inset(50%)`, `clip: rect(0 0 0 0)`,
|
|
71
|
+
* or an empty box that clips its overflow). A client rect ignores all of
|
|
72
|
+
* these. An element the host is fading in is not hidden. */
|
|
73
|
+
function hidesSubtree(element, style) {
|
|
74
|
+
if (style.display === 'none')
|
|
75
|
+
return true;
|
|
76
|
+
if (parseFloat(style.opacity) === 0 && !element.matches(TRANSITION_FADED))
|
|
77
|
+
return true;
|
|
78
|
+
if (style.clipPath === 'inset(50%)' || /^rect\((?:\s*0(?:px)?\s*,?){4}\)$/.test(style.clip ?? ''))
|
|
79
|
+
return true;
|
|
80
|
+
const overflow = style.overflowX || style.overflow;
|
|
81
|
+
if (!overflow || overflow === 'visible')
|
|
82
|
+
return false;
|
|
83
|
+
const box = element.getBoundingClientRect();
|
|
84
|
+
return box.width === 0 || box.height === 0;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Resting width of a stroke, CSS px. A selected or hovered flow step is
|
|
88
|
+
* drawn thicker (`data-flow-state`); that highlight is transient and must
|
|
89
|
+
* not move the fit, so the read uses the width the connector rests at. The
|
|
90
|
+
* thicker highlight stays inside the frame: the resting half-stroke is
|
|
91
|
+
* framed at `zoom / DEFAULT_MIN_READABLE_SCALE` ≥ 1 times its size, next to
|
|
92
|
+
* the 1 CSS px paint inset of the fit.
|
|
93
|
+
*/
|
|
94
|
+
function restingStrokeWidth(element, style) {
|
|
95
|
+
const width = parseFloat(style.strokeWidth) || 0;
|
|
96
|
+
const state = element.getAttribute('data-flow-state');
|
|
97
|
+
if (state !== 'primary' && state !== 'related')
|
|
98
|
+
return width;
|
|
99
|
+
const token = element.hasAttribute('data-flow-step') ? '--st-component-diagramScene-flowStrokeWidth' : '--st-component-diagramZone-borderWidth';
|
|
100
|
+
const resting = parseFloat(style.getPropertyValue(token));
|
|
101
|
+
return Number.isFinite(resting) ? resting : Math.min(width, RESTING_EDGE_STROKE_WIDTH);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Painted bounds in world units, after font/layout settling. DOM-free scene
|
|
105
|
+
* geometry remains the SSR fallback. Include text ink and SVG strokes:
|
|
106
|
+
* getBoundingClientRect alone excludes both text overshoot and stroke width.
|
|
107
|
+
* `zoom` is the scale the world is painted at; the scale committed on the
|
|
108
|
+
* world element takes precedence, since a camera input changes the host's
|
|
109
|
+
* zoom one flush before the DOM follows.
|
|
110
|
+
*
|
|
111
|
+
* The result does not depend on that scale, nor on a transient interaction
|
|
112
|
+
* state, beyond the read granularity `RENDERED_BOUNDS_REFIT_TOLERANCE` covers:
|
|
113
|
+
*
|
|
114
|
+
* - a stroke that scales with the world has a constant world width;
|
|
115
|
+
* - a `non-scaling-stroke` has a constant screen width, so its world width
|
|
116
|
+
* is `width / zoom`. It is framed at its widest, the one it has at the
|
|
117
|
+
* readability floor (`DEFAULT_MIN_READABLE_SCALE`, under which the camera
|
|
118
|
+
* never paints), at every zoom, and at its resting width;
|
|
119
|
+
* - geometry that paints nothing is left out: flow hit targets
|
|
120
|
+
* (`[data-flow-hit]`, a transparent 16 px stroke), flow focus targets
|
|
121
|
+
* (`[data-flow-node]`, hidden at rest and sized in screen px), transparent
|
|
122
|
+
* strokes and text, shapes with neither stroke nor fill, and hidden or
|
|
123
|
+
* clipped subtrees. What a fold transition is fading in stays in.
|
|
124
|
+
*/
|
|
125
|
+
export function measureRenderedBounds(frame, fallback, hostZoom) {
|
|
5
126
|
const world = frame.querySelector('.st-diagramSceneFigure-world');
|
|
6
|
-
if (!world
|
|
127
|
+
if (!world)
|
|
128
|
+
return fallback;
|
|
129
|
+
const committed = Number(/\bscale\(\s*([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s*\)/i.exec(world.style.transform)?.[1]);
|
|
130
|
+
const zoom = committed > 0 ? committed : hostZoom;
|
|
131
|
+
if (!(zoom > 0))
|
|
7
132
|
return fallback;
|
|
8
133
|
const first = world.querySelector('[data-scene-occurrence],[data-scene-label]')?.getBoundingClientRect();
|
|
9
134
|
if (!first || first.width === 0 && first.height === 0)
|
|
@@ -13,29 +138,66 @@ export function measureRenderedBounds(frame, fallback, zoom) {
|
|
|
13
138
|
let right = fallback === undefined ? -Infinity : fallback.x + fallback.width;
|
|
14
139
|
let bottom = fallback === undefined ? -Infinity : fallback.y + fallback.height;
|
|
15
140
|
let measured = false;
|
|
16
|
-
|
|
141
|
+
/** `pad` is the half-stroke around the box, world units. */
|
|
142
|
+
const include = (box, pad = 0) => {
|
|
17
143
|
if (box.width === 0 && box.height === 0)
|
|
18
144
|
return;
|
|
19
145
|
measured = true;
|
|
20
|
-
left = Math.min(left, (box.left - origin.left
|
|
21
|
-
top = Math.min(top, (box.top - origin.top
|
|
22
|
-
right = Math.max(right, (box.right - origin.left
|
|
23
|
-
bottom = Math.max(bottom, (box.bottom - origin.top
|
|
146
|
+
left = Math.min(left, (box.left - origin.left) / zoom - pad);
|
|
147
|
+
top = Math.min(top, (box.top - origin.top) / zoom - pad);
|
|
148
|
+
right = Math.max(right, (box.right - origin.left) / zoom + pad);
|
|
149
|
+
bottom = Math.max(bottom, (box.bottom - origin.top) / zoom + pad);
|
|
24
150
|
};
|
|
25
|
-
|
|
26
|
-
|
|
151
|
+
const styles = new Map();
|
|
152
|
+
const styleOf = (element) => {
|
|
153
|
+
let style = styles.get(element);
|
|
154
|
+
if (style === undefined)
|
|
155
|
+
styles.set(element, style = getComputedStyle(element));
|
|
156
|
+
return style;
|
|
157
|
+
};
|
|
158
|
+
const shown = new Map();
|
|
159
|
+
/** No ancestor up to the world hides or clips the element away. */
|
|
160
|
+
const inPaintedSubtree = (element) => {
|
|
161
|
+
if (element === null || element === world)
|
|
162
|
+
return true;
|
|
163
|
+
let known = shown.get(element);
|
|
164
|
+
if (known === undefined)
|
|
165
|
+
shown.set(element, known = !hidesSubtree(element, styleOf(element)) && inPaintedSubtree(element.parentElement));
|
|
166
|
+
return known;
|
|
167
|
+
};
|
|
168
|
+
// `visibility` is inherited and a descendant can restore it: only the
|
|
169
|
+
// computed value of the painting element itself counts.
|
|
170
|
+
const paints = (element) => !element.closest('defs,[hidden],[data-flow-hit],[data-flow-node]')
|
|
171
|
+
&& styleOf(element).visibility !== 'hidden' && styleOf(element).visibility !== 'collapse' && inPaintedSubtree(element);
|
|
172
|
+
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 circle,svg text')) {
|
|
173
|
+
if (!paints(element))
|
|
174
|
+
continue;
|
|
175
|
+
const style = styleOf(element);
|
|
176
|
+
let pad = 0;
|
|
177
|
+
const stroked = !!style.stroke && style.stroke !== 'none' && !isTransparent(style.stroke) && parseFloat(style.strokeOpacity) !== 0;
|
|
178
|
+
// A shape with neither a painted stroke nor a painted fill is geometry only.
|
|
179
|
+
if (!stroked && element instanceof SVGElement && (style.fill === 'none' || isTransparent(style.fill || '') || parseFloat(style.fillOpacity) === 0))
|
|
27
180
|
continue;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
181
|
+
if (stroked) {
|
|
182
|
+
if (style.vectorEffect === 'non-scaling-stroke')
|
|
183
|
+
pad = restingStrokeWidth(element, style) / 2 / DEFAULT_MIN_READABLE_SCALE;
|
|
184
|
+
else {
|
|
185
|
+
const matrix = element.getScreenCTM?.();
|
|
186
|
+
const scale = matrix ? Math.max(Math.hypot(matrix.a, matrix.b), Math.hypot(matrix.c, matrix.d)) : zoom;
|
|
187
|
+
pad = (parseFloat(style.strokeWidth) || 0) / 2 * scale / zoom;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
include(element.getBoundingClientRect(), pad);
|
|
34
191
|
}
|
|
35
192
|
const walker = frame.ownerDocument.createTreeWalker(world, 4);
|
|
36
193
|
let text;
|
|
37
194
|
while ((text = walker.nextNode())) {
|
|
38
|
-
|
|
195
|
+
const parent = text.parentElement;
|
|
196
|
+
if (!text.textContent?.trim() || !parent || parent.closest('title,desc') || !paints(parent))
|
|
197
|
+
continue;
|
|
198
|
+
const style = styleOf(parent);
|
|
199
|
+
// SVG text is filled; HTML text takes `color`.
|
|
200
|
+
if (isTransparent(parent instanceof SVGElement ? style.fill || '' : style.color || ''))
|
|
39
201
|
continue;
|
|
40
202
|
const range = frame.ownerDocument.createRange();
|
|
41
203
|
range.selectNodeContents(text);
|
|
@@ -46,6 +208,12 @@ export function measureRenderedBounds(frame, fallback, zoom) {
|
|
|
46
208
|
if (!measured || !Number.isFinite(left))
|
|
47
209
|
return fallback;
|
|
48
210
|
// CSS layout uses a 1/64 px grid. Always round the outer edges outward.
|
|
49
|
-
|
|
50
|
-
|
|
211
|
+
// `RENDERED_BOUNDS_REFIT_TOLERANCE` is derived from this same grid.
|
|
212
|
+
const x = Math.floor(left * GRID) / GRID, y = Math.floor(top * GRID) / GRID;
|
|
213
|
+
const width = Math.ceil(right * GRID) / GRID - x, height = Math.ceil(bottom * GRID) / GRID - y;
|
|
214
|
+
// Paint that stays inside the model bounds is the model bounds: hosts
|
|
215
|
+
// compare by identity, so an unchanged rect must not look like a new read.
|
|
216
|
+
if (fallback !== undefined && x === fallback.x && y === fallback.y && width === fallback.width && height === fallback.height)
|
|
217
|
+
return fallback;
|
|
218
|
+
return { x, y, width, height };
|
|
51
219
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/design-system-svelte",
|
|
3
|
-
"version": "0.41.
|
|
3
|
+
"version": "0.41.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@lucide/svelte": "^0.562.0",
|
|
66
66
|
"@sentropic/design-system-rich-text": "0.1.1",
|
|
67
67
|
"@sentropic/design-system-themes": "0.14.0",
|
|
68
|
-
"@sentropic/diagram-canvas": "0.2.
|
|
68
|
+
"@sentropic/diagram-canvas": "0.2.4",
|
|
69
69
|
"@sentropic/graph": "0.3.1"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|