@ruckc/truss-chart 1.46.0 → 1.47.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/BarChart.svelte +2 -1
- package/dist/ChartFrame.svelte +6 -2
- package/dist/ColorScale.svelte +6 -2
- package/dist/DensityChart.svelte +7 -3
- package/dist/GeneratedStyle.svelte +9 -0
- package/dist/GeneratedStyle.svelte.d.ts +6 -0
- package/dist/LineChart.svelte +3 -2
- package/dist/SsrStyle.svelte +15 -0
- package/dist/SsrStyle.svelte.d.ts +7 -0
- package/dist/Tooltip.svelte +2 -1
- package/dist/csp.d.ts +1 -0
- package/dist/csp.js +12 -0
- package/dist/cssvars.d.ts +9 -0
- package/dist/cssvars.js +25 -0
- package/package.json +1 -1
package/dist/BarChart.svelte
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import ChartFrame from './ChartFrame.svelte';
|
|
3
|
+
import { cssvars } from './cssvars.js';
|
|
3
4
|
import { watchFill } from './fill.js';
|
|
4
5
|
import Tooltip from './Tooltip.svelte';
|
|
5
6
|
import type { ChartSelection, Series } from './types.js';
|
|
@@ -232,7 +233,7 @@
|
|
|
232
233
|
<Tooltip x={tip.x} y={tip.y} width={w}>
|
|
233
234
|
<div class="head">{tip.cat}</div>
|
|
234
235
|
{#if tip.detail}<div class="detail">{tip.detail}</div>{/if}
|
|
235
|
-
<div class="row"><span class="line-key"
|
|
236
|
+
<div class="row"><span class="line-key" {@attach cssvars(() => ({ background: tip!.color }))}></span><b>{yFormat(tip.value)}</b><span class="name">{tipName(tip)}</span></div>
|
|
236
237
|
</Tooltip>
|
|
237
238
|
{/if}
|
|
238
239
|
{/snippet}
|
package/dist/ChartFrame.svelte
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
+
import { cssvars } from './cssvars.js';
|
|
4
|
+
import SsrStyle from './SsrStyle.svelte';
|
|
5
|
+
const uid = $props.id();
|
|
3
6
|
import type { LegendItem } from './types.js';
|
|
4
7
|
|
|
5
8
|
let {
|
|
@@ -36,11 +39,12 @@
|
|
|
36
39
|
</figcaption>
|
|
37
40
|
|
|
38
41
|
{#if items.length > 1}
|
|
39
|
-
<
|
|
42
|
+
<SsrStyle {uid} rules={Object.fromEntries(items.map((it, k) => [` li:nth-child(${k + 1}) .key`, `background:${it.color}`]))} />
|
|
43
|
+
<ul class="legend" data-sv={uid} aria-label="Legend">
|
|
40
44
|
{#each items as it (it.name)}
|
|
41
45
|
<li>
|
|
42
46
|
<button type="button" aria-pressed={!it.hidden} onclick={() => ontoggle?.(it.name)}>
|
|
43
|
-
<span class="key"
|
|
47
|
+
<span class="key" {@attach cssvars(() => ({ background: it.color }))}></span>{it.name}
|
|
44
48
|
</button>
|
|
45
49
|
</li>
|
|
46
50
|
{/each}
|
package/dist/ColorScale.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 { gradientFrom, type ScaleKind } from './util.js';
|
|
3
6
|
|
|
4
7
|
let {
|
|
@@ -53,10 +56,11 @@
|
|
|
53
56
|
const ends = $derived(vertical ? [high, low] : [low, high]);
|
|
54
57
|
</script>
|
|
55
58
|
|
|
56
|
-
<
|
|
59
|
+
<SsrStyle {uid} rules={{ '': `--size:${size}px`, ' .bar': `background:${bg}` }} />
|
|
60
|
+
<figure class="cs" class:vertical role="img" aria-label={name} data-sv={uid} {@attach cssvars(() => ({ '--size': `${size}px` }))}>
|
|
57
61
|
{#if caption}<figcaption>{caption}</figcaption>{/if}
|
|
58
62
|
<div class="body">
|
|
59
|
-
<div class="bar"
|
|
63
|
+
<div class="bar" {@attach cssvars(() => ({ background: bg }))}></div>
|
|
60
64
|
<div class="ends" aria-hidden="true">
|
|
61
65
|
<span>{ends[0]}</span>
|
|
62
66
|
{#if mid}<span>{mid}</span>{/if}
|
package/dist/DensityChart.svelte
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import { startDrag } from '@ruckc/truss-ui';
|
|
4
4
|
import ChartFrame from './ChartFrame.svelte';
|
|
5
|
+
import { cssvars, csstext } from './cssvars.js';
|
|
6
|
+
import SsrStyle from './SsrStyle.svelte';
|
|
7
|
+
const uid = $props.id();
|
|
5
8
|
import { watchFill } from './fill.js';
|
|
6
9
|
import ColorScale from './ColorScale.svelte';
|
|
7
10
|
import Tooltip from './Tooltip.svelte';
|
|
@@ -416,16 +419,17 @@
|
|
|
416
419
|
{#snippet chart()}
|
|
417
420
|
<ChartFrame {title} {subtitle} {items} ontoggle={toggle}>
|
|
418
421
|
{#snippet plot(w)}
|
|
422
|
+
<SsrStyle {uid} rules={{ ' canvas': `height:${H}px` }} />
|
|
419
423
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
|
|
420
424
|
<div
|
|
421
|
-
class="dc" role="group" tabindex="0" bind:this={box} bind:clientWidth={cw}
|
|
425
|
+
class="dc" data-sv={uid} role="group" tabindex="0" bind:this={box} bind:clientWidth={cw}
|
|
422
426
|
aria-label="{title ?? 'Density chart'}, {fmtValue(total)} points. Drag or arrow keys pan, wheel or plus and minus zoom, 0 resets the view."
|
|
423
427
|
onpointerdown={down} onpointermove={move}
|
|
424
428
|
onpointerleave={() => (hover = null)} onblur={() => (hover = null)} onkeydown={key}
|
|
425
429
|
ondblclick={(e) => { const r = box!.getBoundingClientRect(); zoomAt(e.clientX - r.left, e.clientY - r.top, 2); }}
|
|
426
430
|
>
|
|
427
|
-
<canvas bind:this={canvas}
|
|
428
|
-
{#if hover}<div class="ring"
|
|
431
|
+
<canvas bind:this={canvas} {@attach cssvars(() => ({ height: `${H}px` }))} aria-hidden="true" data-mode={mode || undefined}></canvas>
|
|
432
|
+
{#if hover}<div class="ring" {@attach csstext(() => `left: ${hover!.rx}px; top: ${hover!.ry}px; width: ${hover!.rw}px; height: ${hover!.rh}px`)}></div>{/if}
|
|
429
433
|
</div>
|
|
430
434
|
<button type="button" class="reset" disabled={zoom === null} onclick={reset}>Reset view</button>
|
|
431
435
|
<div class="sr" role="status" aria-live="polite">{readout}</div>
|
|
@@ -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/LineChart.svelte
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import ChartFrame from './ChartFrame.svelte';
|
|
3
|
+
import { cssvars } from './cssvars.js';
|
|
3
4
|
import Tooltip from './Tooltip.svelte';
|
|
4
5
|
import { watchFill } from './fill.js';
|
|
5
6
|
import type { Series, Band, ReferenceLine, ChartSelection } from './types.js';
|
|
@@ -286,10 +287,10 @@
|
|
|
286
287
|
<Tooltip x={X(xs[hover])} y={height / 2} width={w}>
|
|
287
288
|
<div class="head">{fx(xs[hover])}</div>
|
|
288
289
|
{#each vis as s, si}
|
|
289
|
-
<div class="row"><span class="line-key"
|
|
290
|
+
<div class="row"><span class="line-key" {@attach cssvars(() => ({ background: s.color }))}></span><b>{s.values[hover] == null ? '—' : yFormat(s.values[hover]!)}</b><span class="name">{tipName(s.name, hover, si)}</span></div>
|
|
290
291
|
{/each}
|
|
291
292
|
{#if bandAt(hover)}
|
|
292
|
-
<div class="row"><span class="band-key"
|
|
293
|
+
<div class="row"><span class="band-key" {@attach cssvars(() => ({ background: bandColor }))}></span><b>{rangeText(bandAt(hover)!)}</b><span class="name">{bandLabel}</span></div>
|
|
293
294
|
{/if}
|
|
294
295
|
</Tooltip>
|
|
295
296
|
{/if}
|
|
@@ -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/Tooltip.svelte
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
+
import { csstext } from './cssvars.js';
|
|
3
4
|
|
|
4
5
|
/** Positioned inside a `position: relative` host. Values lead, names follow, line keys not boxes. */
|
|
5
6
|
let { x, y, width, children }: { x: number; y: number; width: number; children: Snippet } = $props();
|
|
@@ -7,7 +8,7 @@
|
|
|
7
8
|
const pos = $derived(`left: ${x}px; top: ${y}px`);
|
|
8
9
|
</script>
|
|
9
10
|
|
|
10
|
-
<div class="tip" role="status"
|
|
11
|
+
<div class="tip" role="status" {@attach csstext(() => pos)} data-flip={x > width * 0.6}>{@render children()}</div>
|
|
11
12
|
|
|
12
13
|
<style>
|
|
13
14
|
.tip { position: absolute; z-index: 5; transform: translate(12px, -50%); min-width: 120px; padding: 6px 10px; pointer-events: none; background: var(--tr-surface-container-highest); border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-md); box-shadow: var(--tr-elevation-2); font-size: var(--tr-text-sm); white-space: nowrap; }
|
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,9 @@
|
|
|
1
|
+
import type { Attachment } from 'svelte/attachments';
|
|
2
|
+
/**
|
|
3
|
+
* @internal Set CSS properties on an element through the CSSOM (`el.style.setProperty` / `el.style.cssText`), which a Content-Security-Policy
|
|
4
|
+
* without `style-src 'unsafe-inline'` allows (a `style` attribute rendered into server markup is blocked). They run on the client after mount and
|
|
5
|
+
* re-run when what `get` reads changes. Copies of the core's helpers (the packages do not depend on the core).
|
|
6
|
+
*/
|
|
7
|
+
export declare function cssvars(get: () => Record<string, string | number>): Attachment<HTMLElement | SVGElement>;
|
|
8
|
+
/** A whole declaration list (`'left: 4px; top: 2px'`). */
|
|
9
|
+
export declare function csstext(get: () => string): Attachment<HTMLElement | SVGElement>;
|
package/dist/cssvars.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal Set CSS properties on an element through the CSSOM (`el.style.setProperty` / `el.style.cssText`), which a Content-Security-Policy
|
|
3
|
+
* without `style-src 'unsafe-inline'` allows (a `style` attribute rendered into server markup is blocked). They run on the client after mount and
|
|
4
|
+
* re-run when what `get` reads changes. Copies of the core's helpers (the packages do not depend on the core).
|
|
5
|
+
*/
|
|
6
|
+
export function cssvars(get) {
|
|
7
|
+
return (el) => {
|
|
8
|
+
const now = get();
|
|
9
|
+
for (const k in now)
|
|
10
|
+
el.style.setProperty(k, String(now[k]));
|
|
11
|
+
return () => {
|
|
12
|
+
for (const k in now)
|
|
13
|
+
el.style.removeProperty(k);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** A whole declaration list (`'left: 4px; top: 2px'`). */
|
|
18
|
+
export function csstext(get) {
|
|
19
|
+
return (el) => {
|
|
20
|
+
el.style.cssText = get();
|
|
21
|
+
return () => {
|
|
22
|
+
el.style.cssText = '';
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}
|