@swiftplot/react 0.5.2 → 0.6.0-rc.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/README.md CHANGED
@@ -14,7 +14,8 @@ project stands, what it lacks and what 1.0 needs: [swiftplot.dev/status](https:/
14
14
  [Discussions](https://github.com/GusevP/swiftplot/discussions).
15
15
 
16
16
  **For AI coding assistants:** [`llms-full.txt`](https://swiftplot.dev/llms-full.txt) is a guide to writing code with
17
- swiftplot, and [`llms.txt`](https://swiftplot.dev/llms.txt) its index.
17
+ swiftplot, and [`llms.txt`](https://swiftplot.dev/llms.txt) its index. `swiftplot/schema.json` is a JSON Schema of the
18
+ easy charts' props, for a model that answers with a chart as JSON.
18
19
 
19
20
  <img src="https://raw.githubusercontent.com/GusevP/swiftplot/main/assets/pan.gif" alt="Panning and zooming a line of a million points" width="640" />
20
21
 
@@ -97,12 +98,12 @@ Gzip size of the minified bundle of each entry in `site/scripts/size/`, built fr
97
98
 
98
99
  | entry | imports | KB |
99
100
  | ------------------ | ------------------------------------------------------- | ---: |
100
- | plot-line | `plot` and `line` from `swiftplot` | 14.4 |
101
- | plot-line-features | the same with `tooltip`, `legend`, `zoom` and `animate` | 19.1 |
102
- | line-chart | `lineChart` from `swiftplot/charts` | 37.6 |
103
- | all-charts | every chart of `swiftplot/charts` | 54.7 |
104
- | react-line-chart | `LineChart` from `@swiftplot/react`, React not counted | 39.3 |
105
- | vue-line-chart | `LineChart` from `@swiftplot/vue`, Vue not counted | 39.8 |
101
+ | plot-line | `plot` and `line` from `swiftplot` | 15.4 |
102
+ | plot-line-features | the same with `tooltip`, `legend`, `zoom` and `animate` | 20.7 |
103
+ | line-chart | `lineChart` from `swiftplot/charts` | 40.2 |
104
+ | all-charts | every chart of `swiftplot/charts` | 57.6 |
105
+ | react-line-chart | `LineChart` from `@swiftplot/react`, React not counted | 42.0 |
106
+ | vue-line-chart | `LineChart` from `@swiftplot/vue`, Vue not counted | 42.5 |
106
107
 
107
108
  On chart-bench's page, which bundles `plot`, `line`, `area`, `ticks`, `dots`, `tooltip` and `animate`, swiftplot 0.5.0 adds 19.3 KB and uPlot 23.9 KB (`results/bundle.json`: the arm's page less the same page with no chart). uPlot ships more in its size: it is one module that comes whole, with its legend, cursor, selection and series types whether a page uses them or not.
108
109
 
package/dist/bind.js CHANGED
@@ -36,6 +36,17 @@ const changed = (was, now) => [...new Set([...Object.keys(was), ...Object.keys(n
36
36
  const useLayout = typeof document === 'undefined' ? useEffect : useLayoutEffect;
37
37
  const FALLBACK = 'data-swiftplot-fallback';
38
38
  const LAYER = 'data-swiftplot-fallback-layer';
39
+ // The text of styles.css, whose counter-reset tells a probe that the shipped file already applies in its root.
40
+ const RULE = `@layer swiftplot {
41
+ :where([data-swiftplot-fallback='fill']) {
42
+ height: 100%;
43
+ counter-reset: swiftplot-fallback;
44
+ }
45
+ :where([data-swiftplot-fallback='fixed']) {
46
+ height: 300px;
47
+ counter-reset: swiftplot-fallback;
48
+ }
49
+ }\n`;
39
50
  const styles = new WeakMap();
40
51
  const detached = new WeakMap();
41
52
  const windowOf = (el) => (el.ownerDocument?.defaultView ?? globalThis);
@@ -68,11 +79,20 @@ function fallback(el) {
68
79
  for (const h of ['fill', 'fixed']) {
69
80
  if (el.clientHeight - parseFloat(cs.paddingTop) - parseFloat(cs.paddingBottom) > 0)
70
81
  break;
71
- sheet(el);
72
82
  el.setAttribute(FALLBACK, h);
83
+ if (h === 'fill' && !shipped(el))
84
+ sheet(el);
73
85
  }
74
86
  el.style.contain = contain;
75
87
  }
88
+ // A probe of its own rather than the host, whose counter-reset the app's CSS may set.
89
+ function shipped(el) {
90
+ const probe = el.appendChild(el.ownerDocument.createElement('swiftplot-probe'));
91
+ probe.setAttribute(FALLBACK, 'fill');
92
+ const on = windowOf(el).getComputedStyle(probe).counterReset === 'swiftplot-fallback 0';
93
+ probe.remove();
94
+ return on;
95
+ }
76
96
  function sheet(el) {
77
97
  const doc = el.ownerDocument;
78
98
  const root = el.getRootNode();
@@ -88,7 +108,10 @@ function sheet(el) {
88
108
  }
89
109
  const style = doc.createElement('style');
90
110
  style.setAttribute(LAYER, '');
91
- style.textContent = `@layer swiftplot { :where([${FALLBACK}=fill]) { height: 100% } :where([${FALLBACK}=fixed]) { height: 300px } }`;
111
+ // A script's nonce would not pass style-src, and a page may give scripts and styles different ones.
112
+ style.nonce =
113
+ [...doc.querySelectorAll('style[nonce], link[rel~="stylesheet" i][nonce]')].find(e => e.nonce)?.nonce ?? '';
114
+ style.textContent = RULE;
92
115
  parent.prepend(style);
93
116
  styles.set(root, style);
94
117
  // A sheet put first later (React 19 does so with its first precedence sheet) would declare its layers ahead of ours.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swiftplot/react",
3
- "version": "0.5.2",
3
+ "version": "0.6.0-rc.0",
4
4
  "description": "React components for swiftplot charts",
5
5
  "keywords": [
6
6
  "chart",
@@ -22,20 +22,24 @@
22
22
  },
23
23
  "homepage": "https://swiftplot.dev",
24
24
  "type": "module",
25
- "sideEffects": false,
25
+ "sideEffects": [
26
+ "*.css"
27
+ ],
26
28
  "exports": {
27
29
  ".": {
28
30
  "types": "./dist/index.d.ts",
29
31
  "default": "./dist/index.js"
30
- }
32
+ },
33
+ "./styles.css": "./styles.css"
31
34
  },
32
35
  "files": [
33
- "dist"
36
+ "dist",
37
+ "styles.css"
34
38
  ],
35
39
  "peerDependencies": {
36
40
  "react": "^18.3 || ^19",
37
41
  "react-dom": "^18.3 || ^19",
38
- "swiftplot": "^0.5.2"
42
+ "swiftplot": "^0.6.0-rc.0"
39
43
  },
40
44
  "devDependencies": {
41
45
  "@types/node": "^24.19.2",
@@ -47,7 +51,7 @@
47
51
  "react-dom": "^19.3.1",
48
52
  "typescript": "^7.0.2",
49
53
  "vitest": "^5.1.1",
50
- "swiftplot": "0.5.2"
54
+ "swiftplot": "0.6.0-rc.0"
51
55
  },
52
56
  "scripts": {
53
57
  "build": "tsc -p tsconfig.build.json",
package/styles.css ADDED
@@ -0,0 +1,10 @@
1
+ @layer swiftplot {
2
+ :where([data-swiftplot-fallback='fill']) {
3
+ height: 100%;
4
+ counter-reset: swiftplot-fallback;
5
+ }
6
+ :where([data-swiftplot-fallback='fixed']) {
7
+ height: 300px;
8
+ counter-reset: swiftplot-fallback;
9
+ }
10
+ }