@rokkit/chart 1.1.16 → 1.1.18

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Plot.svelte +19 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/chart",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "type": "module",
5
5
  "description": "Data-driven chart components",
6
6
  "repository": {
package/src/Plot.svelte CHANGED
@@ -1,7 +1,5 @@
1
1
  <script>
2
2
  import { setContext, getContext, untrack } from 'svelte'
3
- import { zoom as d3Zoom } from 'd3-zoom'
4
- import { select } from 'd3-selection'
5
3
  import { PlotState } from './PlotState.svelte.js'
6
4
  import { defaultPreset } from './lib/preset.js'
7
5
  import Axis from './Plot/Axis.svelte'
@@ -132,15 +130,26 @@
132
130
 
133
131
  $effect(() => {
134
132
  if (!zoom || !svgEl) return
135
- const zoomBehavior = d3Zoom()
136
- .scaleExtent([1, 8])
137
- .on('zoom', (event) => {
138
- plotState.applyZoom(event.transform)
139
- })
140
- const sel = select(svgEl)
141
- sel.call(zoomBehavior)
133
+ // d3-zoom/d3-selection are client-only; load them dynamically so they are
134
+ // not bundled into (and tree-shaken-as-unused from) the SSR/main bundle.
135
+ let cancelled = false
136
+ let detach
137
+ Promise.all([import('d3-zoom'), import('d3-selection')]).then(
138
+ ([{ zoom: d3Zoom }, { select }]) => {
139
+ if (cancelled || !svgEl) return
140
+ const zoomBehavior = d3Zoom()
141
+ .scaleExtent([1, 8])
142
+ .on('zoom', (event) => {
143
+ plotState.applyZoom(event.transform)
144
+ })
145
+ const sel = select(svgEl)
146
+ sel.call(zoomBehavior)
147
+ detach = () => sel.on('.zoom', null)
148
+ }
149
+ )
142
150
  return () => {
143
- sel.on('.zoom', null)
151
+ cancelled = true
152
+ detach?.()
144
153
  plotState.resetZoom()
145
154
  }
146
155
  })