@ruckc/truss-graph 1.46.0 → 1.48.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/GeneratedStyle.svelte +9 -0
- package/dist/GeneratedStyle.svelte.d.ts +6 -0
- package/dist/Graph.svelte +23 -12
- package/dist/SsrStyle.svelte +15 -0
- package/dist/SsrStyle.svelte.d.ts +7 -0
- package/dist/csp.d.ts +1 -0
- package/dist/csp.js +12 -0
- package/dist/cssvars.d.ts +10 -0
- package/dist/cssvars.js +23 -0
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cspNonce } from './csp.js';
|
|
3
|
+
|
|
4
|
+
/** @internal A generated `<style>` element that carries the CSP nonce (see `configureCsp`). */
|
|
5
|
+
let { css }: { css: string } = $props();
|
|
6
|
+
const nonce = cspNonce();
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<svelte:element this={'style'} {nonce}>{css}</svelte:element>
|
package/dist/Graph.svelte
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { cssvars } from './cssvars.js';
|
|
3
|
+
import SsrStyle from './SsrStyle.svelte';
|
|
4
|
+
const uid = $props.id();
|
|
2
5
|
import { onMount, tick, type Snippet } from 'svelte';
|
|
3
6
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
7
|
import { Button, startDrag, type DragOptions } from '@ruckc/truss-ui';
|
|
@@ -582,15 +585,23 @@
|
|
|
582
585
|
}
|
|
583
586
|
</script>
|
|
584
587
|
|
|
588
|
+
<SsrStyle
|
|
589
|
+
{uid}
|
|
590
|
+
rules={{
|
|
591
|
+
'': `height:${widthFit ? px(widthFit.h) : typeof height === 'number' ? `${height}px` : height};--tx:${px(view.tx)};--ty:${px(view.ty)};--k:${view.k};--trg-lines:${Math.max(1, labelLines)}`,
|
|
592
|
+
' .viewport': `transform:translate(${view.tx}px, ${view.ty}px) scale(${view.k})`,
|
|
593
|
+
...Object.fromEntries(visible.map((n, i) => [` .viewport > .node:nth-child(${i + 2})`, `left:${px(n.x)};top:${px(n.y)};width:${px(W(n))};height:${px(H(n))}${colorOf(n) ? `;--c:${colorOf(n)}` : ''}`]))
|
|
594
|
+
}}
|
|
595
|
+
/>
|
|
585
596
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
|
|
586
597
|
<div
|
|
587
|
-
{...rest} class={'trg ' + klass} bind:this={root} bind:clientWidth={rw} bind:clientHeight={rh} role="application" tabindex="0" data-panning={panning} data-static={!interactive}
|
|
598
|
+
{...rest} class={'trg ' + klass} data-sv={uid} bind:this={root} bind:clientWidth={rw} bind:clientHeight={rh} role="application" tabindex="0" data-panning={panning} data-static={!interactive}
|
|
588
599
|
aria-label={rest['aria-label'] ?? (!interactive ? 'Graph. Arrow keys move between nodes, Enter collapses or expands.' : editable ? 'Graph editor. Arrow keys move selected nodes, Delete removes, plus and minus zoom, 0 fits to view.' : 'Graph. Arrow keys move between nodes, Enter collapses or expands, plus and minus zoom, 0 fits to view.')}
|
|
589
|
-
|
|
590
|
-
|
|
600
|
+
{@attach cssvars(() => ({ 'height': widthFit ? px(widthFit.h) : typeof height === 'number' ? `${height}px` : height }))}
|
|
601
|
+
{@attach cssvars(() => ({ '--tx': px(view.tx) }))} {@attach cssvars(() => ({ '--ty': px(view.ty) }))} {@attach cssvars(() => ({ '--k': view.k }))} {@attach cssvars(() => ({ '--trg-lines': Math.max(1, labelLines) }))}
|
|
591
602
|
onpointerdown={bgDown} onkeydown={onKey}
|
|
592
603
|
>
|
|
593
|
-
<div class="viewport" bind:this={viewport}
|
|
604
|
+
<div class="viewport" bind:this={viewport} {@attach cssvars(() => ({ 'transform': `translate(${view.tx}px, ${view.ty}px) scale(${view.k})` }))}>
|
|
594
605
|
<svg class="edges" width="1" height="1">
|
|
595
606
|
<defs>
|
|
596
607
|
<marker id="trg-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse">
|
|
@@ -630,8 +641,8 @@
|
|
|
630
641
|
class="node" role="group" tabindex="0" aria-label="{n.label}{n.subtitle ? `, ${n.subtitle}` : ''}"
|
|
631
642
|
data-id={n.id} data-kind={n.kind ?? 'neutral'} data-shape={n.shape && n.shape !== 'rect' ? n.shape : undefined} data-bare={bare} data-selected={selected.includes(n.id)} data-dragging={!!drag?.ids.includes(n.id)}
|
|
632
643
|
data-dim={hl ? !hl.has(n.id) : undefined} data-collapsed={hiding.counts.has(n.id) ? true : undefined}
|
|
633
|
-
|
|
634
|
-
|
|
644
|
+
{@attach cssvars(() => ({ 'left': px(n.x) }))} {@attach cssvars(() => ({ 'top': px(n.y) }))} {@attach cssvars(() => ({ 'width': px(W(n)) }))} {@attach cssvars(() => ({ 'height': px(H(n)) }))}
|
|
645
|
+
{@attach cssvars(() => ({ '--c': colorOf(n) }))}
|
|
635
646
|
onpointerdown={(e) => nodeDown(e, n)} onclick={(e) => nodeClick(e, n)} ondblclick={(e) => nodeDblClick(e, n)} oncontextmenu={(e) => nodeMenu(e, n)}
|
|
636
647
|
onpointerenter={() => onnodehover?.(n)} onpointerleave={() => onnodehover?.(null)}
|
|
637
648
|
>
|
|
@@ -651,12 +662,12 @@
|
|
|
651
662
|
{@const a = portAnchor(n, p, ports)}
|
|
652
663
|
{#if p.kind === 'in'}
|
|
653
664
|
<span class="port" data-side={p.side} data-port-in={n.id} data-port-id={p.id} data-hot={link?.over?.node === n.id && link.over.port === p.id}
|
|
654
|
-
|
|
665
|
+
{@attach cssvars(() => ({ 'left': `${a.x - n.x}px` }))} {@attach cssvars(() => ({ 'top': `${a.y - n.y}px` }))}></span>
|
|
655
666
|
{:else}
|
|
656
667
|
<span class="port" role="presentation" data-side={p.side} data-connectable={connectable && edit} onpointerdown={(e) => portDown(e, n, p)}
|
|
657
|
-
|
|
668
|
+
{@attach cssvars(() => ({ 'left': `${a.x - n.x}px` }))} {@attach cssvars(() => ({ 'top': `${a.y - n.y}px` }))}></span>
|
|
658
669
|
{/if}
|
|
659
|
-
{#if p.label}<span class="plabel" data-side={p.side}
|
|
670
|
+
{#if p.label}<span class="plabel" data-side={p.side} {@attach cssvars(() => ({ 'left': `${a.x - n.x}px` }))} {@attach cssvars(() => ({ 'top': `${a.y - n.y}px` }))}>{p.label}</span>{/if}
|
|
660
671
|
{/each}
|
|
661
672
|
{#if !lod && hiding.counts.has(n.id)}
|
|
662
673
|
{@const hidden = hiding.counts.get(n.id)!}
|
|
@@ -667,7 +678,7 @@
|
|
|
667
678
|
</div>
|
|
668
679
|
|
|
669
680
|
{#if mm}
|
|
670
|
-
<div class="minimap" data-pos={minimapPosition}
|
|
681
|
+
<div class="minimap" data-pos={minimapPosition} {@attach cssvars(() => ({ 'width': `${MW}px` }))} {@attach cssvars(() => ({ 'height': `${MH}px` }))}>
|
|
671
682
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
672
683
|
<svg width={mm.w} height={mm.h} role="img" aria-label="Minimap: drag to pan the view" onpointerdown={mmPan}>
|
|
673
684
|
{#each big ? [] : geo as g (g.e.id)}
|
|
@@ -676,7 +687,7 @@
|
|
|
676
687
|
<line class="mme" x1={(a.x + W(a) / 2 - mm.x0) * mm.sc} y1={(a.y + H(a) / 2 - mm.y0) * mm.sc} x2={(bn.x + W(bn) / 2 - mm.x0) * mm.sc} y2={(bn.y + H(bn) / 2 - mm.y0) * mm.sc} />
|
|
677
688
|
{/each}
|
|
678
689
|
{#each shown as n (n.id)}
|
|
679
|
-
<rect class="mmn" data-kind={n.kind ?? 'neutral'}
|
|
690
|
+
<rect class="mmn" data-kind={n.kind ?? 'neutral'} {@attach cssvars(() => ({ 'fill': colorOf(n) }))} data-selected={selected.includes(n.id)} x={(n.x - mm.x0) * mm.sc} y={(n.y - mm.y0) * mm.sc} width={Math.max(2, W(n) * mm.sc)} height={Math.max(2, H(n) * mm.sc)} rx="1.5" />
|
|
680
691
|
{/each}
|
|
681
692
|
<rect class="mmv" x={mm.view.x} y={mm.view.y} width={mm.view.w} height={mm.view.h} />
|
|
682
693
|
</svg>
|
|
@@ -689,7 +700,7 @@
|
|
|
689
700
|
<span class="lg-item"><span class="lg-node" data-kind={kind}></span>{label}</span>
|
|
690
701
|
{/each}
|
|
691
702
|
{#each legendData.catRows as [cat, label] (cat)}
|
|
692
|
-
<span class="lg-item"><span class="lg-node"
|
|
703
|
+
<span class="lg-item"><span class="lg-node" {@attach cssvars(() => ({ '--c': slotVar(cat) }))}></span>{label}</span>
|
|
693
704
|
{/each}
|
|
694
705
|
{#each legendData.edgeRows as [kind, label] (kind)}
|
|
695
706
|
<button type="button" class="lg-item lg-edge" data-kind={kind} aria-pressed={!hiddenEdgeKinds.includes(kind)} title={`Show or hide ${label} edges`} onclick={() => toggleEdgeKind(kind)}>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
import GeneratedStyle from './GeneratedStyle.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal The first-paint declarations of an element and its descendants as one nonced `<style>` rule per key, `[data-sv=uid]<key>{…}`
|
|
7
|
+
* (key `''` is the element itself), so a server-rendered graph lays out before JavaScript runs and without a `style=` attribute (blocked by a CSP
|
|
8
|
+
* without 'unsafe-inline'). The element carries `data-sv={uid}`; the CSSOM values set after mount override these rules.
|
|
9
|
+
* A copy of the core's `SsrStyle` for the declaration-string case (the packages do not depend on the core).
|
|
10
|
+
*/
|
|
11
|
+
let { uid, rules }: { uid: string; rules: Record<string, string> } = $props();
|
|
12
|
+
const css = untrack(() => Object.entries(rules).map(([sel, decl]) => `[data-sv="${uid}"]${sel}{${decl}}`).join(''));
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<GeneratedStyle {css} />
|
package/dist/csp.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cspNonce(): string | undefined;
|
package/dist/csp.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getContext } from 'svelte';
|
|
2
|
+
/**
|
|
3
|
+
* @internal The CSP nonce for a generated `<style>` element, as set by `@ruckc/truss-ui` (`setCspNonce` in the root layout, or `configureCsp`),
|
|
4
|
+
* else `<meta property="csp-nonce" nonce="…">` in the browser. Shares its state with the core through `Symbol.for` / `globalThis`.
|
|
5
|
+
*/
|
|
6
|
+
const KEY = Symbol.for('@ruckc/truss-ui:csp-nonce');
|
|
7
|
+
const STATE = Symbol.for('@ruckc/truss-ui:csp');
|
|
8
|
+
export function cspNonce() {
|
|
9
|
+
const state = globalThis[STATE];
|
|
10
|
+
const m = typeof document === 'undefined' ? null : document.querySelector('meta[property="csp-nonce"], meta[name="csp-nonce"]');
|
|
11
|
+
return getContext(KEY) || state?.nonce || m?.nonce || m?.content || undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Attachment } from 'svelte/attachments';
|
|
2
|
+
type Value = string | number | null | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* @internal Sets CSS properties (custom properties such as `--size`, or plain ones like `width`) on an element through the CSSOM (`el.style.setProperty`),
|
|
5
|
+
* which a Content-Security-Policy without `style-src 'unsafe-inline'` allows. Unlike `style=` / `style:` it renders nothing in server-rendered markup,
|
|
6
|
+
* so the component's scoped CSS must have a sensible fallback (`var(--x, default)`) for the first paint, or a `SsrStyle` rule must provide it. Runs on the
|
|
7
|
+
* client after mount and re-runs when what `get` reads changes; `null` and `undefined` remove the property.
|
|
8
|
+
*/
|
|
9
|
+
export declare function cssvars(get: () => Record<string, Value>): Attachment<HTMLElement | SVGElement>;
|
|
10
|
+
export {};
|
package/dist/cssvars.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal Sets CSS properties (custom properties such as `--size`, or plain ones like `width`) on an element through the CSSOM (`el.style.setProperty`),
|
|
3
|
+
* which a Content-Security-Policy without `style-src 'unsafe-inline'` allows. Unlike `style=` / `style:` it renders nothing in server-rendered markup,
|
|
4
|
+
* so the component's scoped CSS must have a sensible fallback (`var(--x, default)`) for the first paint, or a `SsrStyle` rule must provide it. Runs on the
|
|
5
|
+
* client after mount and re-runs when what `get` reads changes; `null` and `undefined` remove the property.
|
|
6
|
+
*/
|
|
7
|
+
export function cssvars(get) {
|
|
8
|
+
return (el) => {
|
|
9
|
+
const now = get();
|
|
10
|
+
const set = [];
|
|
11
|
+
for (const k in now) {
|
|
12
|
+
const v = now[k];
|
|
13
|
+
if (v == null)
|
|
14
|
+
continue;
|
|
15
|
+
el.style.setProperty(k, String(v));
|
|
16
|
+
set.push(k);
|
|
17
|
+
}
|
|
18
|
+
return () => {
|
|
19
|
+
for (const k of set)
|
|
20
|
+
el.style.removeProperty(k);
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|