svelteplot 0.2.7 → 0.2.8

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.
@@ -129,7 +129,7 @@
129
129
  marginBottom={20}
130
130
  height={38}
131
131
  inset={0}
132
- x={{ domain, tickSpacing, tickFormat }}>
132
+ x={{ domain, tickSpacing: 30, tickFormat }}>
133
133
  <defs>
134
134
  <linearGradient id="gradient-{randId}" x2="1">
135
135
  {#each ticks as t (t)}
@@ -2,6 +2,27 @@
2
2
  import { getContext } from 'svelte';
3
3
  import type { PlotContext } from '../../types';
4
4
  import { devicePixelRatio } from 'svelte/reactivity/window';
5
+ import { MediaQuery } from 'svelte/reactivity';
6
+ import type { Attachment } from 'svelte/attachments';
7
+
8
+ const darkMode = new MediaQuery('prefers-color-scheme: dark');
9
+ let colorScheme = $state();
10
+
11
+ /**
12
+ * we need to repaint on dark mode changes in case the user
13
+ * is using any css variables or currentColor that changes
14
+ * with the color scheme
15
+ */
16
+ const watchColorScheme: Attachment = (element: Element) => {
17
+ const htmlElement = element.ownerDocument.documentElement;
18
+ const observer = new MutationObserver(() => {
19
+ colorScheme = getComputedStyle(htmlElement).colorScheme;
20
+ });
21
+ observer.observe(htmlElement, { attributes: true });
22
+ return () => {
23
+ observer.disconnect();
24
+ };
25
+ };
5
26
 
6
27
  let restProps: {} = $props();
7
28
 
@@ -14,14 +35,15 @@
14
35
  canvas element inside a foreignObject for use in a plot and takes care of
15
36
  scaling it to the device pixel ratio.
16
37
  -->
17
-
18
- <foreignObject x="0" y="0" width={plot.width} height={plot.height}>
19
- <canvas
20
- xmlns="http://www.w3.org/1999/xhtml"
21
- {...restProps}
22
- width={plot.width * (devicePixelRatio.current ?? 1)}
23
- height={plot.height * (devicePixelRatio.current ?? 1)}
24
- style="width: {plot.width}px; height: {plot.height}px;"></canvas>
38
+ <foreignObject x="0" y="0" {@attach watchColorScheme} width={plot.width} height={plot.height}>
39
+ {#key [colorScheme, darkMode.current]}
40
+ <canvas
41
+ xmlns="http://www.w3.org/1999/xhtml"
42
+ {...restProps}
43
+ width={plot.width * (devicePixelRatio.current ?? 1)}
44
+ height={plot.height * (devicePixelRatio.current ?? 1)}
45
+ style="width: {plot.width}px; height: {plot.height}px;"></canvas>
46
+ {/key}
25
47
  </foreignObject>
26
48
 
27
49
  <style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",