@ruckc/truss-ol 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.
@@ -1,4 +1,5 @@
1
1
  <script lang="ts">
2
+ import { cssvars } from './cssvars.js';
2
3
  import type OLMap from 'ol/Map.js';
3
4
  import { watchView, type ControlPosition, type HeadingStatus } from './util.js';
4
5
 
@@ -81,7 +82,7 @@
81
82
 
82
83
  <div class="cp" data-pos={position} data-heading={status} data-bearing={bearing}>
83
84
  <button type="button" class="b" aria-label={`Compass: bearing ${bearing} degrees. Reset to north`} title="Reset to north" disabled={!map} onclick={reset}>
84
- <svg viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" style:transform={`rotate(${rotation}rad)`}>
85
+ <svg viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" {@attach cssvars(() => ({ 'transform': `rotate(${rotation}rad)` }))}>
85
86
  <polygon points="12,2 16,12 8,12" fill="var(--tr-danger)" />
86
87
  <polygon points="12,22 16,12 8,12" fill="var(--tr-on-surface-variant)" />
87
88
  <circle cx="12" cy="12" r="1.6" fill="var(--tr-surface)" />
@@ -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>
@@ -0,0 +1,6 @@
1
+ type $$ComponentProps = {
2
+ css: string;
3
+ };
4
+ declare const GeneratedStyle: import("svelte").Component<$$ComponentProps, {}, "">;
5
+ type GeneratedStyle = ReturnType<typeof GeneratedStyle>;
6
+ export default GeneratedStyle;
package/dist/Map.svelte CHANGED
@@ -1,4 +1,6 @@
1
1
  <script lang="ts">
2
+ import { cssvars } from './cssvars.js';
3
+ import SsrStyle from './SsrStyle.svelte';
2
4
  import { onMount, type Snippet } from 'svelte';
3
5
  import { Button } from '@ruckc/truss-ui';
4
6
  import 'ol/ol.css';
@@ -640,7 +642,8 @@
640
642
  $effect(() => { center; zoom; if (ready) sync?.view(); });
641
643
  </script>
642
644
 
643
- <div class="trm" style:height={typeof height === 'number' ? `${height}px` : height}>
645
+ <SsrStyle {uid} rules={{ '': `height:${typeof height === 'number' ? `${height}px` : height}` }} />
646
+ <div class="trm" data-sv={uid} {@attach cssvars(() => ({ 'height': typeof height === 'number' ? `${height}px` : height }))}>
644
647
  <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
645
648
  <div class="map" bind:this={el} tabindex="0" role="application" aria-label="Map. Arrow keys pan, plus and minus zoom."></div>
646
649
 
@@ -684,7 +687,7 @@
684
687
  <div class="lt">{lg.title}</div>
685
688
  <div class="lsz">
686
689
  {#each lg.steps as st (st.value)}
687
- <span class="ls"><i style:width="{st.radius * 2}px" style:height="{st.radius * 2}px"></i>{st.label}</span>
690
+ <span class="ls"><i {@attach cssvars(() => ({ 'width': `${st.radius * 2}px` }))} {@attach cssvars(() => ({ 'height': `${st.radius * 2}px` }))}></i>{st.label}</span>
688
691
  {/each}
689
692
  </div>
690
693
  {/if}
@@ -693,10 +696,10 @@
693
696
  {#if lg}
694
697
  <div class="lt">{lg.title}</div>
695
698
  {#if lg.gradient}
696
- <div class="lbar" style:background={lg.gradient} role="img" aria-label="{lg.title}: {lg.labels![0]} to {lg.labels![1]}"></div>
699
+ <div class="lbar" {@attach cssvars(() => ({ 'background': lg.gradient! }))} role="img" aria-label="{lg.title}: {lg.labels![0]} to {lg.labels![1]}"></div>
697
700
  <div class="lends"><span>{lg.labels![0]}</span><span>{lg.labels![1]}</span></div>
698
701
  {:else}
699
- <ul class="lcat">{#each lg.categories! as c (c.label)}<li><i style:background={c.color}></i>{c.label}</li>{/each}</ul>
702
+ <ul class="lcat">{#each lg.categories! as c (c.label)}<li><i {@attach cssvars(() => ({ 'background': c.color }))}></i>{c.label}</li>{/each}</ul>
700
703
  {/if}
701
704
  {/if}
702
705
  {/each}
@@ -1,4 +1,5 @@
1
1
  <script lang="ts">
2
+ import { cssvars } from './cssvars.js';
2
3
  import type OLMap from 'ol/Map.js';
3
4
  import type { getPointResolution } from 'ol/proj.js';
4
5
  import { watchView, scaleSegment, scaleTicks, scaleRatio, formatRatio, describeRatio, describeSegment, type ControlPosition, type ScaleSegment, type ScaleUnit } from './util.js';
@@ -54,12 +55,12 @@
54
55
  {#each segments as s (s.unit)}
55
56
  {#if variant === 'segmented'}
56
57
  {@const t = scaleTicks(s)}
57
- <div class="seg" style:width={`${s.width}px`}>
58
+ <div class="seg" {@attach cssvars(() => ({ 'width': `${s.width}px` }))}>
58
59
  <div class="track">{#each { length: t.count } as _, i}<span class:dark={i % 2 === 0}></span>{/each}</div>
59
- <div class="ticks">{#each t.ticks as k (k.pos)}<span style:left={`${k.pos * 100}%`}>{k.label}</span>{/each}</div>
60
+ <div class="ticks">{#each t.ticks as k (k.pos)}<span {@attach cssvars(() => ({ 'left': `${k.pos * 100}%` }))}>{k.label}</span>{/each}</div>
60
61
  </div>
61
62
  {:else}
62
- <div class="bar" style:width={`${s.width}px`}>{s.label}</div>
63
+ <div class="bar" {@attach cssvars(() => ({ 'width': `${s.width}px` }))}>{s.label}</div>
63
64
  {/if}
64
65
  {/each}
65
66
  </div>
@@ -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} />
@@ -0,0 +1,7 @@
1
+ type $$ComponentProps = {
2
+ uid: string;
3
+ rules: Record<string, string>;
4
+ };
5
+ declare const SsrStyle: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type SsrStyle = ReturnType<typeof SsrStyle>;
7
+ export default SsrStyle;
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,7 @@
1
+ import type { Attachment } from 'svelte/attachments';
2
+ /**
3
+ * @internal Sets CSS properties on an element through the CSSOM (`el.style.setProperty`), which a Content-Security-Policy without
4
+ * `style-src 'unsafe-inline'` allows (a `style` attribute rendered into server markup is blocked). Runs on the client after mount and
5
+ * re-runs when what `get` reads changes. A copy of the core's helper (the packages do not depend on the core).
6
+ */
7
+ export declare function cssvars(get: () => Record<string, string | number>): Attachment<HTMLElement | SVGElement>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @internal Sets CSS properties on an element through the CSSOM (`el.style.setProperty`), which a Content-Security-Policy without
3
+ * `style-src 'unsafe-inline'` allows (a `style` attribute rendered into server markup is blocked). Runs on the client after mount and
4
+ * re-runs when what `get` reads changes. A copy of the core's helper (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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruckc/truss-ol",
3
- "version": "1.46.0",
3
+ "version": "1.48.0",
4
4
  "description": "OpenLayers map styled with Truss UI",
5
5
  "type": "module",
6
6
  "license": "MIT",