velo-plot 2.20.0 → 3.1.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.
Files changed (287) hide show
  1. package/README.md +26 -12
  2. package/dist/ChartCore-AnR_3Xkb.js +7338 -0
  3. package/dist/ChartCore-AnR_3Xkb.js.map +1 -0
  4. package/dist/GpuChartRenderer-Dxc0hrQA.js +75 -0
  5. package/dist/GpuChartRenderer-Dxc0hrQA.js.map +1 -0
  6. package/dist/{index.core-COREBDNq.js → PluginRegistry-CzMHebYP.js} +24 -38
  7. package/dist/PluginRegistry-CzMHebYP.js.map +1 -0
  8. package/dist/a11y-Bw6urYpr.js +105 -0
  9. package/dist/a11y-Bw6urYpr.js.map +1 -0
  10. package/dist/angular/hooks-entry.d.ts +1 -0
  11. package/dist/angular/hooks.d.ts +26 -0
  12. package/dist/angular/index.d.ts +8 -0
  13. package/dist/angular/velo-plot.component.d.ts +46 -0
  14. package/dist/angular-hooks.d.ts +1 -0
  15. package/dist/angular-hooks.js +9 -0
  16. package/dist/angular-hooks.js.map +1 -0
  17. package/dist/angular.d.ts +1 -0
  18. package/dist/angular.js +166 -0
  19. package/dist/angular.js.map +1 -0
  20. package/dist/assets/indicator.worker-bv0zC4EX.js.map +1 -1
  21. package/dist/astro/StackedPlot.astro +19 -0
  22. package/dist/astro/VeloPlot.astro +23 -0
  23. package/dist/{axisFormat-CzumxpCL.js → axisFormat-Sz4WIJfQ.js} +2 -2
  24. package/dist/{axisFormat-CzumxpCL.js.map → axisFormat-Sz4WIJfQ.js.map} +1 -1
  25. package/dist/bindings/shared/a11y.d.ts +26 -0
  26. package/dist/bindings/shared/chartLifecycle.d.ts +16 -0
  27. package/dist/bindings/shared/chartSyncBridge.d.ts +8 -0
  28. package/dist/bindings/shared/dimensions.d.ts +1 -0
  29. package/dist/bindings/shared/index.d.ts +9 -0
  30. package/dist/bindings/shared/indicatorBridge.d.ts +11 -0
  31. package/dist/bindings/shared/optionsSync.d.ts +7 -0
  32. package/dist/bindings/shared/seriesDiff.d.ts +8 -0
  33. package/dist/bindings/shared/stackedSync.d.ts +9 -0
  34. package/dist/bindings/shared/types.d.ts +46 -0
  35. package/dist/bindings/test-utils/index.d.ts +35 -0
  36. package/dist/bindings/test-utils/mockLifecycle.d.ts +120 -0
  37. package/dist/bindings/test-utils/vitestSveltePlugin.d.ts +3 -0
  38. package/dist/chartSyncBridge-D_rCtbFq.js +58 -0
  39. package/dist/chartSyncBridge-D_rCtbFq.js.map +1 -0
  40. package/dist/core/Chart.d.ts +1 -1
  41. package/dist/core/ChartStatistics.d.ts +1 -1
  42. package/dist/core/InteractionManager.d.ts +7 -1
  43. package/dist/core/OverlayRenderer.d.ts +5 -0
  44. package/dist/core/annotations/types.d.ts +1 -1
  45. package/dist/core/chart/ChartCore.d.ts +14 -19
  46. package/dist/core/chart/ChartFeatureHooks.d.ts +7 -0
  47. package/dist/core/chart/chartExportPatch.d.ts +2 -0
  48. package/dist/core/chart/overlaySeriesRegistry.d.ts +7 -0
  49. package/dist/core/chart/series/SeriesActions.d.ts +1 -0
  50. package/dist/core/chart/series/SeriesBufferLite.d.ts +13 -0
  51. package/dist/core/chart/series/seriesOptionsRegistry.d.ts +8 -0
  52. package/dist/core/chart/series/seriesTypeRegistry.d.ts +5 -0
  53. package/dist/core/chart/types.d.ts +1 -1
  54. package/dist/core/clipboard/index.d.ts +1 -1
  55. package/dist/core/debug/index.d.ts +1 -1
  56. package/dist/core/keybindings/index.d.ts +1 -1
  57. package/dist/core/loading/index.d.ts +1 -1
  58. package/dist/core/locale/index.d.ts +1 -1
  59. package/dist/core/stacked/paneResize.d.ts +3 -0
  60. package/dist/core/stacked/types.d.ts +10 -0
  61. package/dist/core/theme-editor/index.d.ts +1 -1
  62. package/dist/createStackedChart-DqcLCFGS.js +1338 -0
  63. package/dist/createStackedChart-DqcLCFGS.js.map +1 -0
  64. package/dist/examples/PluginDemonstration.d.ts +1 -1
  65. package/dist/hooks-DH-3bewj.js +69 -0
  66. package/dist/hooks-DH-3bewj.js.map +1 -0
  67. package/dist/{index-BBpJwOct.js → index-0InEyj0q.js} +119 -121
  68. package/dist/index-0InEyj0q.js.map +1 -0
  69. package/dist/{index-qunX30Xu.js → index-B7PTX94B.js} +2133 -2133
  70. package/dist/index-B7PTX94B.js.map +1 -0
  71. package/dist/{index-BMiZoKmm.js → index-BgrvqltV.js} +67 -67
  72. package/dist/index-BgrvqltV.js.map +1 -0
  73. package/dist/{index-DoYxf1cV.js → index-CWxIHdwX.js} +38 -98
  74. package/dist/index-CWxIHdwX.js.map +1 -0
  75. package/dist/index-CaXWSOTk.js.map +1 -1
  76. package/dist/{mockDatafeed-927foCM4.js → index-Cv6ZDLWf.js} +227 -217
  77. package/dist/index-Cv6ZDLWf.js.map +1 -0
  78. package/dist/index-Dag88bW4.js.map +1 -1
  79. package/dist/index-qhscKTDy.js.map +1 -1
  80. package/dist/index.core.d.ts +9 -7
  81. package/dist/index.d.ts +2 -15
  82. package/dist/indicators--eJGmVox.js.map +1 -1
  83. package/dist/optionsSync-QUiN4Inw.js +119 -0
  84. package/dist/optionsSync-QUiN4Inw.js.map +1 -0
  85. package/dist/plugins/3d/index.d.ts +2 -2
  86. package/dist/plugins/3d.d.ts +2 -2
  87. package/dist/plugins/3d.js +3 -1
  88. package/dist/plugins/3d.js.map +1 -1
  89. package/dist/plugins/analysis/index.d.ts +1 -1
  90. package/dist/plugins/analysis/indicators.d.ts +1 -1
  91. package/dist/plugins/analysis.d.ts +2 -2
  92. package/dist/plugins/analysis.js +2 -2
  93. package/dist/plugins/analysis.js.map +1 -1
  94. package/dist/plugins/annotations/index.d.ts +1 -1
  95. package/dist/plugins/annotations.d.ts +2 -2
  96. package/dist/plugins/annotations.js.map +1 -1
  97. package/dist/plugins/anomaly-detection.js +1 -1
  98. package/dist/plugins/anomaly-detection.js.map +1 -1
  99. package/dist/plugins/broken-axis.d.ts +2 -2
  100. package/dist/plugins/builtins/crosshair/CrosshairPlugin.d.ts +1 -1
  101. package/dist/plugins/builtins/index.d.ts +1 -1
  102. package/dist/plugins/caching.d.ts +2 -2
  103. package/dist/plugins/clipboard/index.d.ts +2 -2
  104. package/dist/plugins/clipboard.d.ts +2 -2
  105. package/dist/plugins/clipboard.js.map +1 -1
  106. package/dist/plugins/context-menu/index.d.ts +1 -1
  107. package/dist/plugins/context-menu.d.ts +2 -2
  108. package/dist/plugins/context-menu.js +1 -1
  109. package/dist/plugins/context-menu.js.map +1 -1
  110. package/dist/plugins/createPlugin.d.ts +8 -0
  111. package/dist/plugins/data-export/index.d.ts +1 -1
  112. package/dist/plugins/data-export.d.ts +2 -2
  113. package/dist/plugins/data-export.js +2 -2
  114. package/dist/plugins/data-export.js.map +1 -1
  115. package/dist/plugins/data-transform.d.ts +2 -2
  116. package/dist/plugins/data-transform.js +19 -19
  117. package/dist/plugins/data-transform.js.map +1 -1
  118. package/dist/plugins/debug/index.d.ts +2 -2
  119. package/dist/plugins/debug.d.ts +2 -2
  120. package/dist/plugins/debug.js +33 -33
  121. package/dist/plugins/debug.js.map +1 -1
  122. package/dist/plugins/forecasting/index.d.ts +1 -1
  123. package/dist/plugins/forecasting.js.map +1 -1
  124. package/dist/plugins/gpu/index.d.ts +2 -2
  125. package/dist/plugins/gpu.d.ts +2 -2
  126. package/dist/plugins/gpu.js +2033 -209
  127. package/dist/plugins/gpu.js.map +1 -1
  128. package/dist/plugins/i18n/index.d.ts +2 -2
  129. package/dist/plugins/i18n.d.ts +2 -2
  130. package/dist/plugins/i18n.js +286 -23
  131. package/dist/plugins/i18n.js.map +1 -1
  132. package/dist/plugins/index.d.ts +1 -1
  133. package/dist/plugins/keyboard.d.ts +2 -2
  134. package/dist/plugins/keyboard.js +65 -5
  135. package/dist/plugins/keyboard.js.map +1 -1
  136. package/dist/plugins/latex.js +766 -207
  137. package/dist/plugins/latex.js.map +1 -1
  138. package/dist/plugins/lazy-load.d.ts +2 -2
  139. package/dist/plugins/loading/index.d.ts +2 -3
  140. package/dist/plugins/loading.d.ts +2 -2
  141. package/dist/plugins/loading.js +3 -4
  142. package/dist/plugins/ml-integration.d.ts +2 -2
  143. package/dist/plugins/ml-integration.js +5 -5
  144. package/dist/plugins/ml-integration.js.map +1 -1
  145. package/dist/plugins/offscreen.d.ts +2 -2
  146. package/dist/plugins/offscreen.js +11 -10
  147. package/dist/plugins/offscreen.js.map +1 -1
  148. package/dist/plugins/pattern-recognition.d.ts +2 -2
  149. package/dist/plugins/pattern-recognition.js +1 -1
  150. package/dist/plugins/pattern-recognition.js.map +1 -1
  151. package/dist/plugins/radar.d.ts +2 -2
  152. package/dist/plugins/regression.d.ts +2 -2
  153. package/dist/plugins/regression.js +255 -257
  154. package/dist/plugins/regression.js.map +1 -1
  155. package/dist/plugins/roi.js +9 -9
  156. package/dist/plugins/roi.js.map +1 -1
  157. package/dist/plugins/snapshot/index.d.ts +1 -1
  158. package/dist/plugins/snapshot/types.d.ts +1 -1
  159. package/dist/plugins/snapshot.d.ts +2 -2
  160. package/dist/plugins/snapshot.js.map +1 -1
  161. package/dist/plugins/streaming/index.d.ts +2 -2
  162. package/dist/plugins/streaming.d.ts +2 -2
  163. package/dist/plugins/streaming.js +1 -1
  164. package/dist/plugins/sync/index.d.ts +3 -2
  165. package/dist/plugins/sync.d.ts +2 -2
  166. package/dist/plugins/sync.js.map +1 -1
  167. package/dist/plugins/theme-editor/index.d.ts +1 -1
  168. package/dist/plugins/theme-editor.d.ts +2 -2
  169. package/dist/plugins/tools/index.d.ts +1 -1
  170. package/dist/plugins/tools/tooltip/index.d.ts +1 -1
  171. package/dist/plugins/tools.d.ts +2 -2
  172. package/dist/plugins/tools.js +1 -1
  173. package/dist/plugins/types.d.ts +1 -1
  174. package/dist/plugins/video-recorder.d.ts +2 -2
  175. package/dist/plugins/virtualization.d.ts +2 -2
  176. package/dist/plugins/virtualization.js +1 -1
  177. package/dist/pool-DZ8shSqv.js +109 -0
  178. package/dist/pool-DZ8shSqv.js.map +1 -0
  179. package/dist/react/StackedPlot.d.ts +31 -0
  180. package/dist/react/VeloPlot.d.ts +29 -0
  181. package/dist/react/index.d.ts +25 -3
  182. package/dist/react/useChartSync.d.ts +8 -0
  183. package/dist/react/useIndicator.d.ts +12 -0
  184. package/dist/react/useVeloPlot.d.ts +19 -0
  185. package/dist/react.js +325 -24
  186. package/dist/react.js.map +1 -1
  187. package/dist/renderer/NativeWebGLRenderer.d.ts +2 -1
  188. package/dist/renderer/native/NativeWebGLRenderer.d.ts +5 -1
  189. package/dist/renderer/native/draw.d.ts +2 -47
  190. package/dist/renderer/native/drawCore.d.ts +27 -0
  191. package/dist/renderer/native/drawExtended.d.ts +29 -0
  192. package/dist/renderer/native/frameRenderExtended.d.ts +1 -0
  193. package/dist/renderer/native/frameRenderRegistry.d.ts +27 -0
  194. package/dist/renderer/native/programFactoryCore.d.ts +6 -0
  195. package/dist/renderer/native/programFactoryExtended.d.ts +4 -0
  196. package/dist/renderer/native/utils.d.ts +3 -29
  197. package/dist/renderer/native/utilsCore.d.ts +14 -0
  198. package/dist/renderer/native/utilsExtended.d.ts +17 -0
  199. package/dist/renderer/overlaySeriesExtended.d.ts +1 -0
  200. package/dist/renderer/registerExtendedSeries.d.ts +1 -0
  201. package/dist/renderer/registerWebGPU.d.ts +2 -0
  202. package/dist/renderer/seriesBufferExtended.d.ts +4 -0
  203. package/dist/scientific/index.d.ts +44 -0
  204. package/dist/scientific/registerScientific.d.ts +1 -0
  205. package/dist/scientific.d.ts +1 -0
  206. package/dist/scientific.js +91 -0
  207. package/dist/scientific.js.map +1 -0
  208. package/dist/solid/VeloPlot.d.ts +16 -0
  209. package/dist/solid/index.d.ts +13 -0
  210. package/dist/solid/useChartSync.d.ts +6 -0
  211. package/dist/solid/useIndicator.d.ts +11 -0
  212. package/dist/solid/useStackedPlot.d.ts +14 -0
  213. package/dist/solid/useVeloPlot.d.ts +18 -0
  214. package/dist/solid.d.ts +1 -0
  215. package/dist/solid.js +169 -0
  216. package/dist/solid.js.map +1 -0
  217. package/dist/stackedSync-tnrunZMt.js +100 -0
  218. package/dist/stackedSync-tnrunZMt.js.map +1 -0
  219. package/dist/svelte/StackedPlot.svelte +29 -0
  220. package/dist/svelte/StackedPlot.test.ts +114 -0
  221. package/dist/svelte/VeloPlot.svelte +44 -0
  222. package/dist/svelte/VeloPlot.test.ts +105 -0
  223. package/dist/svelte/index.d.ts +11 -0
  224. package/dist/svelte/index.test.ts +20 -0
  225. package/dist/svelte/index.ts +15 -0
  226. package/dist/svelte/useChartSync.d.ts +8 -0
  227. package/dist/svelte/useChartSync.test.ts +49 -0
  228. package/dist/svelte/useChartSync.ts +29 -0
  229. package/dist/svelte/useIndicator.d.ts +13 -0
  230. package/dist/svelte/useIndicator.test.ts +67 -0
  231. package/dist/svelte/useIndicator.ts +43 -0
  232. package/dist/svelte/useStackedPlot.d.ts +16 -0
  233. package/dist/svelte/useStackedPlot.test.ts +76 -0
  234. package/dist/svelte/useStackedPlot.ts +54 -0
  235. package/dist/svelte/useVeloPlot.d.ts +21 -0
  236. package/dist/svelte/useVeloPlot.test.ts +100 -0
  237. package/dist/svelte/useVeloPlot.ts +81 -0
  238. package/dist/svelte.d.ts +1 -0
  239. package/dist/svelte.js +140 -0
  240. package/dist/svelte.js.map +1 -0
  241. package/dist/testing/index.d.ts +1 -1
  242. package/dist/theme/index.d.ts +2 -1
  243. package/dist/trading/index.d.ts +1 -4
  244. package/dist/trading/registerTrading.d.ts +3 -0
  245. package/dist/trading.js +42 -42
  246. package/dist/types.d.ts +4 -4
  247. package/dist/{utils-BK5UUXxj.js → utils-Dx0h0bgQ.js} +9 -9
  248. package/dist/{utils-BK5UUXxj.js.map → utils-Dx0h0bgQ.js.map} +1 -1
  249. package/dist/velo-plot.full.js +2216 -1346
  250. package/dist/velo-plot.full.js.map +1 -1
  251. package/dist/velo-plot.js +33 -28
  252. package/dist/velo-plot.js.map +1 -1
  253. package/dist/vue/StackedPlot.vue.d.ts +48 -0
  254. package/dist/vue/VeloPlot.vue.d.ts +64 -0
  255. package/dist/vue/index.d.ts +250 -0
  256. package/dist/vue/useChartSync.d.ts +52 -0
  257. package/dist/vue/useIndicator.d.ts +23 -0
  258. package/dist/vue/useStackedPlot.d.ts +15 -0
  259. package/dist/vue/useVeloPlot.d.ts +20 -0
  260. package/dist/vue.d.ts +1 -0
  261. package/dist/vue.js +309 -0
  262. package/dist/vue.js.map +1 -0
  263. package/dist/workers/indicatorsAsync.d.ts +2 -0
  264. package/dist/workers/pool.d.ts +9 -0
  265. package/package.json +96 -10
  266. package/dist/ChartCore-ivzLqxVb.js +0 -8350
  267. package/dist/ChartCore-ivzLqxVb.js.map +0 -1
  268. package/dist/SciPlot-CEU4ApgD.js +0 -463
  269. package/dist/SciPlot-CEU4ApgD.js.map +0 -1
  270. package/dist/createStackedChart-DxNW0VkF.js +0 -705
  271. package/dist/createStackedChart-DxNW0VkF.js.map +0 -1
  272. package/dist/gpuRenderer-BpaMYz-k.js +0 -1848
  273. package/dist/gpuRenderer-BpaMYz-k.js.map +0 -1
  274. package/dist/index-BBpJwOct.js.map +0 -1
  275. package/dist/index-BMiZoKmm.js.map +0 -1
  276. package/dist/index-DoYxf1cV.js.map +0 -1
  277. package/dist/index-qunX30Xu.js.map +0 -1
  278. package/dist/index-x4stH3jD.js +0 -282
  279. package/dist/index-x4stH3jD.js.map +0 -1
  280. package/dist/index.core-COREBDNq.js.map +0 -1
  281. package/dist/mockDatafeed-927foCM4.js.map +0 -1
  282. package/dist/pool-15HMCNv8.js +0 -88
  283. package/dist/pool-15HMCNv8.js.map +0 -1
  284. package/dist/react/SciPlot.d.ts +0 -60
  285. package/dist/react/useSciPlot.d.ts +0 -56
  286. package/dist/symbols-DT0eLlpW.js +0 -568
  287. package/dist/symbols-DT0eLlpW.js.map +0 -1
@@ -1,1848 +0,0 @@
1
- var D = Object.defineProperty;
2
- var R = (o, e, t) => e in o ? D(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var l = (o, e, t) => R(o, typeof e != "symbol" ? e + "" : e, t);
4
- const L = `
5
- struct VSOut {
6
- @builtin(position) pos: vec4<f32>,
7
- @location(0) color: vec4<f32>,
8
- };
9
-
10
- @vertex
11
- fn vs_main(
12
- @location(0) position: vec2<f32>,
13
- @location(1) color: vec4<f32>
14
- ) -> VSOut {
15
- var out: VSOut;
16
- out.pos = vec4<f32>(position, 0.0, 1.0);
17
- out.color = color;
18
- return out;
19
- }
20
-
21
- @fragment
22
- fn fs_main(in: VSOut) -> @location(0) vec4<f32> {
23
- return in.color;
24
- }
25
- `;
26
- function F(o, e) {
27
- const t = o.createShaderModule({ code: L }), r = 6 * 4;
28
- return { pipeline: o.createRenderPipeline({
29
- layout: "auto",
30
- vertex: {
31
- module: t,
32
- entryPoint: "vs_main",
33
- buffers: [
34
- {
35
- arrayStride: r,
36
- attributes: [
37
- { shaderLocation: 0, offset: 0, format: "float32x2" },
38
- { shaderLocation: 1, offset: 2 * 4, format: "float32x4" }
39
- ]
40
- }
41
- ]
42
- },
43
- fragment: {
44
- module: t,
45
- entryPoint: "fs_main",
46
- targets: [{ format: e }]
47
- },
48
- primitive: {
49
- topology: "triangle-list",
50
- cullMode: "none"
51
- }
52
- }), vertexStride: r };
53
- }
54
- const G = `
55
- // Uniform buffer for transforms and color
56
- struct Uniforms {
57
- scale: vec2<f32>,
58
- translate: vec2<f32>,
59
- color: vec4<f32>,
60
- };
61
-
62
- @group(0) @binding(0)
63
- var<uniform> uniforms: Uniforms;
64
-
65
- struct VSInput {
66
- @location(0) position: vec2<f32>,
67
- };
68
-
69
- struct VSOutput {
70
- @builtin(position) pos: vec4<f32>,
71
- };
72
-
73
- @vertex
74
- fn vs_main(in: VSInput) -> VSOutput {
75
- var out: VSOutput;
76
- let transformed = in.position * uniforms.scale + uniforms.translate;
77
- out.pos = vec4<f32>(transformed, 0.0, 1.0);
78
- return out;
79
- }
80
-
81
- @fragment
82
- fn fs_main(in: VSOutput) -> @location(0) vec4<f32> {
83
- return uniforms.color;
84
- }
85
- `, B = 2 * 4, I = 32;
86
- function V(o, e) {
87
- const t = o.createShaderModule({ code: G }), r = globalThis.GPUShaderStage, i = globalThis.GPUBufferUsage, a = o.createBindGroupLayout({
88
- entries: [
89
- {
90
- binding: 0,
91
- visibility: r.VERTEX | r.FRAGMENT,
92
- buffer: { type: "uniform" }
93
- }
94
- ]
95
- }), n = o.createBuffer({
96
- size: I,
97
- usage: i.UNIFORM | i.COPY_DST
98
- }), s = o.createBindGroup({
99
- layout: a,
100
- entries: [
101
- {
102
- binding: 0,
103
- resource: { buffer: n }
104
- }
105
- ]
106
- }), c = o.createPipelineLayout({
107
- bindGroupLayouts: [a]
108
- });
109
- return {
110
- pipeline: o.createRenderPipeline({
111
- layout: c,
112
- vertex: {
113
- module: t,
114
- entryPoint: "vs_main",
115
- buffers: [
116
- {
117
- arrayStride: B,
118
- attributes: [
119
- { shaderLocation: 0, offset: 0, format: "float32x2" }
120
- ]
121
- }
122
- ]
123
- },
124
- fragment: {
125
- module: t,
126
- entryPoint: "fs_main",
127
- targets: [
128
- {
129
- format: e,
130
- blend: {
131
- color: {
132
- srcFactor: "src-alpha",
133
- dstFactor: "one-minus-src-alpha",
134
- operation: "add"
135
- },
136
- alpha: {
137
- srcFactor: "one",
138
- dstFactor: "one-minus-src-alpha",
139
- operation: "add"
140
- }
141
- }
142
- }
143
- ]
144
- },
145
- primitive: {
146
- topology: "line-strip",
147
- stripIndexFormat: void 0
148
- }
149
- }),
150
- bindGroupLayout: a,
151
- uniformBuffer: n,
152
- bindGroup: s,
153
- vertexStride: B
154
- };
155
- }
156
- function A(o, e, t) {
157
- const r = new Float32Array([
158
- t.scale[0],
159
- t.scale[1],
160
- t.translate[0],
161
- t.translate[1],
162
- t.color[0],
163
- t.color[1],
164
- t.color[2],
165
- t.color[3]
166
- ]);
167
- o.queue.writeBuffer(e, 0, r);
168
- }
169
- const O = `
170
- // Uniform buffer for transforms, color, point properties
171
- struct Uniforms {
172
- scale: vec2<f32>,
173
- translate: vec2<f32>,
174
- color: vec4<f32>,
175
- pointSize: f32,
176
- symbol: i32,
177
- viewport: vec2<f32>, // viewport dimensions for proper sizing
178
- };
179
-
180
- @group(0) @binding(0)
181
- var<uniform> uniforms: Uniforms;
182
-
183
- struct VSInput {
184
- @location(0) position: vec2<f32>, // point center position
185
- @location(1) quadOffset: vec2<f32>, // quad vertex offset (-1 to 1)
186
- };
187
-
188
- struct VSOutput {
189
- @builtin(position) pos: vec4<f32>,
190
- @location(0) uv: vec2<f32>, // -0.5 to 0.5 for SDF
191
- };
192
-
193
- @vertex
194
- fn vs_main(in: VSInput) -> VSOutput {
195
- var out: VSOutput;
196
-
197
- // Transform point position to NDC
198
- let transformed = in.position * uniforms.scale + uniforms.translate;
199
-
200
- // Calculate point size in NDC
201
- let pointSizeNDC = vec2<f32>(
202
- uniforms.pointSize / uniforms.viewport.x * 2.0,
203
- uniforms.pointSize / uniforms.viewport.y * 2.0
204
- );
205
-
206
- // Apply quad offset
207
- let offset = in.quadOffset * pointSizeNDC * 0.5;
208
-
209
- out.pos = vec4<f32>(transformed + offset, 0.0, 1.0);
210
- out.uv = in.quadOffset * 0.5; // -0.5 to 0.5
211
-
212
- return out;
213
- }
214
-
215
- // SDF functions
216
- fn sdCircle(p: vec2<f32>, r: f32) -> f32 {
217
- return length(p) - r;
218
- }
219
-
220
- fn sdBox(p: vec2<f32>, b: vec2<f32>) -> f32 {
221
- let d = abs(p) - b;
222
- return length(max(d, vec2<f32>(0.0))) + min(max(d.x, d.y), 0.0);
223
- }
224
-
225
- fn sdDiamond(p: vec2<f32>, r: f32) -> f32 {
226
- return (abs(p.x) + abs(p.y)) - r;
227
- }
228
-
229
- fn sdTriangle(p_in: vec2<f32>, r: f32) -> f32 {
230
- let k = sqrt(3.0);
231
- var p = p_in;
232
- p.x = abs(p.x) - r;
233
- p.y = p.y + r / k;
234
- if (p.x + k * p.y > 0.0) {
235
- p = vec2<f32>(p.x - k * p.y, -k * p.x - p.y) / 2.0;
236
- }
237
- p.x = p.x - clamp(p.x, -2.0 * r, 0.0);
238
- return -length(p) * sign(p.y);
239
- }
240
-
241
- fn sdCross(p: vec2<f32>, r: f32, thickness: f32) -> f32 {
242
- let d = abs(p);
243
- let s1 = sdBox(d, vec2<f32>(r, thickness));
244
- let s2 = sdBox(d, vec2<f32>(thickness, r));
245
- return min(s1, s2);
246
- }
247
-
248
- fn sdX(p: vec2<f32>, r: f32, thickness: f32) -> f32 {
249
- let c = cos(0.785398);
250
- let s = sin(0.785398);
251
- let m = mat2x2<f32>(c, -s, s, c);
252
- return sdCross(m * p, r, thickness);
253
- }
254
-
255
- fn sdStar(p_in: vec2<f32>, r: f32, rf: f32) -> f32 {
256
- let k1 = vec2<f32>(0.80901699, -0.58778525);
257
- let k2 = vec2<f32>(-k1.x, k1.y);
258
- var p = p_in;
259
- p.x = abs(p.x);
260
- p = p - 2.0 * max(dot(k1, p), 0.0) * k1;
261
- p = p - 2.0 * max(dot(k2, p), 0.0) * k2;
262
- p.x = abs(p.x);
263
- p.y = p.y - r;
264
- let ba = rf * vec2<f32>(-k1.y, k1.x) - vec2<f32>(0.0, 1.0);
265
- let h = clamp(dot(p, ba) / dot(ba, ba), 0.0, r);
266
- return length(p - ba * h) * sign(p.y * ba.x - p.x * ba.y);
267
- }
268
-
269
- @fragment
270
- fn fs_main(in: VSOutput) -> @location(0) vec4<f32> {
271
- var d: f32 = 0.0;
272
-
273
- if (uniforms.symbol == 0) {
274
- d = sdCircle(in.uv, 0.45);
275
- } else if (uniforms.symbol == 1) {
276
- d = sdBox(in.uv, vec2<f32>(0.35));
277
- } else if (uniforms.symbol == 2) {
278
- d = sdDiamond(in.uv, 0.45);
279
- } else if (uniforms.symbol == 3) {
280
- d = sdTriangle(vec2<f32>(in.uv.x, in.uv.y + 0.1), 0.4);
281
- } else if (uniforms.symbol == 4) {
282
- d = sdTriangle(vec2<f32>(in.uv.x, -in.uv.y + 0.1), 0.4);
283
- } else if (uniforms.symbol == 5) {
284
- d = sdCross(in.uv, 0.45, 0.15);
285
- } else if (uniforms.symbol == 6) {
286
- d = sdX(in.uv, 0.45, 0.15);
287
- } else if (uniforms.symbol == 7) {
288
- d = sdStar(in.uv, 0.45, 0.4);
289
- }
290
-
291
- if (d > 0.02) {
292
- discard;
293
- }
294
-
295
- let alpha = 1.0 - smoothstep(0.0, 0.02, d);
296
- return vec4<f32>(uniforms.color.rgb, uniforms.color.a * alpha);
297
- }
298
- `, _ = 2 * 4, z = 48, E = new Float32Array([
299
- -1,
300
- -1,
301
- // bottom-left
302
- 1,
303
- -1,
304
- // bottom-right
305
- -1,
306
- 1,
307
- // top-left
308
- -1,
309
- 1,
310
- // top-left
311
- 1,
312
- -1,
313
- // bottom-right
314
- 1,
315
- 1
316
- // top-right
317
- ]);
318
- function W(o, e) {
319
- const t = o.createShaderModule({ code: O }), r = globalThis.GPUShaderStage, i = globalThis.GPUBufferUsage, a = o.createBindGroupLayout({
320
- entries: [
321
- {
322
- binding: 0,
323
- visibility: r.VERTEX | r.FRAGMENT,
324
- buffer: { type: "uniform" }
325
- }
326
- ]
327
- }), n = o.createBuffer({
328
- size: z,
329
- usage: i.UNIFORM | i.COPY_DST
330
- }), s = o.createBuffer({
331
- size: E.byteLength,
332
- usage: i.VERTEX | i.COPY_DST,
333
- mappedAtCreation: !0
334
- });
335
- new Float32Array(s.getMappedRange()).set(E), s.unmap();
336
- const c = o.createBindGroup({
337
- layout: a,
338
- entries: [
339
- {
340
- binding: 0,
341
- resource: { buffer: n }
342
- }
343
- ]
344
- }), u = o.createPipelineLayout({
345
- bindGroupLayouts: [a]
346
- });
347
- return {
348
- pipeline: o.createRenderPipeline({
349
- layout: u,
350
- vertex: {
351
- module: t,
352
- entryPoint: "vs_main",
353
- buffers: [
354
- // Point positions (instanced)
355
- {
356
- arrayStride: _,
357
- stepMode: "instance",
358
- attributes: [
359
- { shaderLocation: 0, offset: 0, format: "float32x2" }
360
- ]
361
- },
362
- // Quad vertex offsets (per-vertex)
363
- {
364
- arrayStride: 8,
365
- // 2 floats
366
- stepMode: "vertex",
367
- attributes: [
368
- { shaderLocation: 1, offset: 0, format: "float32x2" }
369
- ]
370
- }
371
- ]
372
- },
373
- fragment: {
374
- module: t,
375
- entryPoint: "fs_main",
376
- targets: [
377
- {
378
- format: e,
379
- blend: {
380
- color: {
381
- srcFactor: "src-alpha",
382
- dstFactor: "one-minus-src-alpha",
383
- operation: "add"
384
- },
385
- alpha: {
386
- srcFactor: "one",
387
- dstFactor: "one-minus-src-alpha",
388
- operation: "add"
389
- }
390
- }
391
- }
392
- ]
393
- },
394
- primitive: {
395
- topology: "triangle-list",
396
- cullMode: "none"
397
- }
398
- }),
399
- bindGroupLayout: a,
400
- uniformBuffer: n,
401
- bindGroup: c,
402
- quadBuffer: s,
403
- vertexStride: _
404
- };
405
- }
406
- function N(o, e, t) {
407
- const r = new Float32Array([
408
- t.scale[0],
409
- t.scale[1],
410
- t.translate[0],
411
- t.translate[1],
412
- t.color[0],
413
- t.color[1],
414
- t.color[2],
415
- t.color[3],
416
- t.pointSize,
417
- t.symbol,
418
- // Will be cast to i32 in shader via bitcast
419
- t.viewport[0],
420
- t.viewport[1]
421
- ]);
422
- o.queue.writeBuffer(e, 0, r);
423
- }
424
- const X = {
425
- circle: 0,
426
- square: 1,
427
- diamond: 2,
428
- triangle: 3,
429
- triangleDown: 4,
430
- cross: 5,
431
- x: 6,
432
- star: 7
433
- }, H = 32;
434
- function Y(o, e) {
435
- const t = o.createShaderModule({ code: G }), r = globalThis.GPUShaderStage, i = globalThis.GPUBufferUsage, a = o.createBindGroupLayout({
436
- entries: [
437
- {
438
- binding: 0,
439
- visibility: r.VERTEX | r.FRAGMENT,
440
- buffer: { type: "uniform" }
441
- }
442
- ]
443
- }), n = o.createBuffer({
444
- size: H,
445
- usage: i.UNIFORM | i.COPY_DST
446
- }), s = o.createBindGroup({
447
- layout: a,
448
- entries: [
449
- {
450
- binding: 0,
451
- resource: { buffer: n }
452
- }
453
- ]
454
- }), c = o.createPipelineLayout({
455
- bindGroupLayouts: [a]
456
- });
457
- return {
458
- pipeline: o.createRenderPipeline({
459
- layout: c,
460
- vertex: {
461
- module: t,
462
- entryPoint: "vs_main",
463
- buffers: [
464
- {
465
- arrayStride: B,
466
- attributes: [
467
- { shaderLocation: 0, offset: 0, format: "float32x2" }
468
- ]
469
- }
470
- ]
471
- },
472
- fragment: {
473
- module: t,
474
- entryPoint: "fs_main",
475
- targets: [
476
- {
477
- format: e,
478
- blend: {
479
- color: {
480
- srcFactor: "src-alpha",
481
- dstFactor: "one-minus-src-alpha",
482
- operation: "add"
483
- },
484
- alpha: {
485
- srcFactor: "one",
486
- dstFactor: "one-minus-src-alpha",
487
- operation: "add"
488
- }
489
- }
490
- }
491
- ]
492
- },
493
- primitive: {
494
- topology: "triangle-strip",
495
- // Key difference from line pipeline
496
- stripIndexFormat: void 0
497
- }
498
- }),
499
- bindGroupLayout: a,
500
- uniformBuffer: n,
501
- bindGroup: s,
502
- vertexStride: B
503
- };
504
- }
505
- function $(o, e, t) {
506
- const r = new Float32Array([
507
- t.scale[0],
508
- t.scale[1],
509
- t.translate[0],
510
- t.translate[1],
511
- t.color[0],
512
- t.color[1],
513
- t.color[2],
514
- t.color[3]
515
- ]);
516
- o.queue.writeBuffer(e, 0, r);
517
- }
518
- const q = `
519
- // Uniform buffer for transforms and value range
520
- struct Uniforms {
521
- scale: vec2<f32>,
522
- translate: vec2<f32>,
523
- minValue: f32,
524
- maxValue: f32,
525
- _padding: vec2<f32>,
526
- };
527
-
528
- @group(0) @binding(0)
529
- var<uniform> uniforms: Uniforms;
530
-
531
- @group(0) @binding(1)
532
- var colormapSampler: sampler;
533
-
534
- @group(0) @binding(2)
535
- var colormapTexture: texture_1d<f32>;
536
-
537
- struct VSInput {
538
- @location(0) position: vec2<f32>,
539
- @location(1) value: f32,
540
- };
541
-
542
- struct VSOutput {
543
- @builtin(position) pos: vec4<f32>,
544
- @location(0) value: f32,
545
- };
546
-
547
- @vertex
548
- fn vs_main(in: VSInput) -> VSOutput {
549
- var out: VSOutput;
550
- let transformed = in.position * uniforms.scale + uniforms.translate;
551
- out.pos = vec4<f32>(transformed, 0.0, 1.0);
552
- out.value = in.value;
553
- return out;
554
- }
555
-
556
- @fragment
557
- fn fs_main(in: VSOutput) -> @location(0) vec4<f32> {
558
- let range = uniforms.maxValue - uniforms.minValue;
559
- var t: f32;
560
- if (range != 0.0) {
561
- t = (in.value - uniforms.minValue) / range;
562
- } else {
563
- t = 0.0;
564
- }
565
- t = clamp(t, 0.0, 1.0);
566
-
567
- return textureSample(colormapTexture, colormapSampler, t);
568
- }
569
- `, k = 3 * 4, j = 32;
570
- function K(o, e) {
571
- const t = o.createShaderModule({ code: q }), r = globalThis.GPUShaderStage, i = globalThis.GPUBufferUsage, a = o.createBindGroupLayout({
572
- entries: [
573
- {
574
- binding: 0,
575
- visibility: r.VERTEX | r.FRAGMENT,
576
- buffer: { type: "uniform" }
577
- },
578
- {
579
- binding: 1,
580
- visibility: r.FRAGMENT,
581
- sampler: {}
582
- },
583
- {
584
- binding: 2,
585
- visibility: r.FRAGMENT,
586
- texture: {
587
- sampleType: "float",
588
- viewDimension: "1d"
589
- }
590
- }
591
- ]
592
- }), n = o.createBuffer({
593
- size: j,
594
- usage: i.UNIFORM | i.COPY_DST
595
- }), s = o.createSampler({
596
- magFilter: "linear",
597
- minFilter: "linear",
598
- addressModeU: "clamp-to-edge"
599
- }), c = o.createPipelineLayout({
600
- bindGroupLayouts: [a]
601
- });
602
- return {
603
- pipeline: o.createRenderPipeline({
604
- layout: c,
605
- vertex: {
606
- module: t,
607
- entryPoint: "vs_main",
608
- buffers: [
609
- {
610
- arrayStride: k,
611
- attributes: [
612
- { shaderLocation: 0, offset: 0, format: "float32x2" },
613
- // position
614
- { shaderLocation: 1, offset: 8, format: "float32" }
615
- // value
616
- ]
617
- }
618
- ]
619
- },
620
- fragment: {
621
- module: t,
622
- entryPoint: "fs_main",
623
- targets: [
624
- {
625
- format: e,
626
- blend: {
627
- color: {
628
- srcFactor: "src-alpha",
629
- dstFactor: "one-minus-src-alpha",
630
- operation: "add"
631
- },
632
- alpha: {
633
- srcFactor: "one",
634
- dstFactor: "one-minus-src-alpha",
635
- operation: "add"
636
- }
637
- }
638
- }
639
- ]
640
- },
641
- primitive: {
642
- topology: "triangle-list",
643
- cullMode: "none"
644
- }
645
- }),
646
- bindGroupLayout: a,
647
- uniformBuffer: n,
648
- sampler: s,
649
- vertexStride: k
650
- };
651
- }
652
- function Z(o, e, t, r, i) {
653
- return o.createBindGroup({
654
- layout: e,
655
- entries: [
656
- { binding: 0, resource: { buffer: t } },
657
- { binding: 1, resource: r },
658
- { binding: 2, resource: i.createView() }
659
- ]
660
- });
661
- }
662
- function Q(o, e, t) {
663
- const r = new Float32Array([
664
- t.scale[0],
665
- t.scale[1],
666
- t.translate[0],
667
- t.translate[1],
668
- t.minValue,
669
- t.maxValue,
670
- 0,
671
- // padding
672
- 0
673
- // padding
674
- ]);
675
- o.queue.writeBuffer(e, 0, r);
676
- }
677
- function J(o) {
678
- const e = o.xMax - o.xMin, t = o.yMax - o.yMin, r = e > 0 ? 2 / e : 1, i = t > 0 ? 2 / t : 1, a = -1 - o.xMin * r, n = -1 - o.yMin * i;
679
- return {
680
- scale: [r, i],
681
- translate: [a, n]
682
- };
683
- }
684
- function ee(o) {
685
- const e = (o == null ? void 0 : o.color) ?? [1, 0, 0.3, 1], t = (o == null ? void 0 : o.opacity) ?? 1;
686
- return Array.isArray(e) ? [e[0], e[1], e[2], (e[3] ?? 1) * t] : [1, 0, 0.3, t];
687
- }
688
- class v {
689
- constructor(e, t = {}) {
690
- l(this, "info");
691
- l(this, "canvas");
692
- l(this, "opts");
693
- l(this, "viewport", null);
694
- l(this, "adapter");
695
- l(this, "device");
696
- l(this, "context");
697
- l(this, "format", null);
698
- l(this, "buffers", /* @__PURE__ */ new Map());
699
- l(this, "textures", /* @__PURE__ */ new Map());
700
- // Pipelines for different draw types
701
- l(this, "trianglePipeline", null);
702
- l(this, "linePipeline", null);
703
- l(this, "pointPipeline", null);
704
- l(this, "bandPipeline", null);
705
- l(this, "heatmapPipeline", null);
706
- // Heatmap bind groups (per texture)
707
- l(this, "heatmapBindGroups", /* @__PURE__ */ new Map());
708
- this.canvas = e, this.opts = t, this.info = {
709
- type: "webgpu",
710
- available: v.isSupported()
711
- };
712
- }
713
- static isSupported() {
714
- return typeof globalThis.navigator < "u" && typeof globalThis.navigator.gpu < "u";
715
- }
716
- async init() {
717
- if (!this.info.available)
718
- throw new Error("[gpu] WebGPU not supported");
719
- const e = globalThis.navigator.gpu;
720
- if (this.adapter = await e.requestAdapter({
721
- powerPreference: this.opts.powerPreference ?? "high-performance"
722
- }), !this.adapter)
723
- throw new Error("[gpu] Failed to request WebGPU adapter");
724
- this.device = await this.adapter.requestDevice();
725
- const t = this.canvas.getContext("webgpu");
726
- if (!t)
727
- throw new Error("[gpu] Failed to get WebGPU canvas context");
728
- this.context = t;
729
- const r = this.opts.preferredFormat ?? (e.getPreferredCanvasFormat ? e.getPreferredCanvasFormat() : "bgra8unorm");
730
- this.format = r, this.context.configure({
731
- device: this.device,
732
- format: r,
733
- alphaMode: "premultiplied"
734
- });
735
- }
736
- setViewport(e) {
737
- this.viewport = e;
738
- const t = Math.max(1, Math.floor(e.width * e.dpr)), r = Math.max(1, Math.floor(e.height * e.dpr));
739
- this.canvas.width !== t && (this.canvas.width = t), this.canvas.height !== r && (this.canvas.height = r);
740
- }
741
- createOrUpdateBuffer(e, t, r) {
742
- if (!this.device)
743
- throw new Error("[gpu] WebGPUBackend not initialized");
744
- const i = (r == null ? void 0 : r.usage) ?? "vertex", a = globalThis.GPUBufferUsage;
745
- if (!a)
746
- throw new Error(
747
- "[gpu] GPUBufferUsage not available (missing WebGPU runtime)"
748
- );
749
- const n = i === "index" ? a.INDEX | a.COPY_DST : i === "uniform" ? a.UNIFORM | a.COPY_DST : a.VERTEX | a.COPY_DST, s = t.byteLength;
750
- let c = this.buffers.get(e);
751
- if (!c || c.size < s) {
752
- if (c)
753
- try {
754
- c.destroy();
755
- } catch {
756
- }
757
- c = this.device.createBuffer({
758
- size: Math.max(4, s),
759
- usage: n
760
- }), this.buffers.set(e, c);
761
- }
762
- this.device.queue.writeBuffer(
763
- c,
764
- 0,
765
- t.buffer,
766
- t.byteOffset,
767
- t.byteLength
768
- );
769
- }
770
- deleteBuffer(e) {
771
- const t = this.buffers.get(e);
772
- if (t) {
773
- try {
774
- t.destroy();
775
- } catch {
776
- }
777
- this.buffers.delete(e);
778
- }
779
- }
780
- createOrUpdateTexture1D(e, t, r) {
781
- if (!this.device)
782
- throw new Error("[gpu] WebGPUBackend not initialized");
783
- const i = (r == null ? void 0 : r.width) ?? Math.floor(t.length / 4), a = (r == null ? void 0 : r.format) ?? "rgba8unorm", n = globalThis.GPUTextureUsage;
784
- if (!n)
785
- throw new Error(
786
- "[gpu] GPUTextureUsage not available (missing WebGPU runtime)"
787
- );
788
- let s = this.textures.get(e);
789
- s || (s = this.device.createTexture({
790
- size: { width: i, height: 1, depthOrArrayLayers: 1 },
791
- format: a,
792
- dimension: "1d",
793
- usage: n.TEXTURE_BINDING | n.COPY_DST
794
- }), this.textures.set(e, s), this.heatmapBindGroups.delete(e)), this.device.queue.writeTexture(
795
- { texture: s },
796
- t,
797
- { bytesPerRow: i * 4 },
798
- { width: i, height: 1, depthOrArrayLayers: 1 }
799
- );
800
- }
801
- deleteTexture(e) {
802
- const t = this.textures.get(e);
803
- if (t) {
804
- try {
805
- t.destroy();
806
- } catch {
807
- }
808
- this.textures.delete(e), this.heatmapBindGroups.delete(e);
809
- }
810
- }
811
- /**
812
- * Initialize all pipelines lazily
813
- */
814
- ensurePipelines() {
815
- this.trianglePipeline || (this.trianglePipeline = F(this.device, this.format)), this.linePipeline || (this.linePipeline = V(this.device, this.format)), this.pointPipeline || (this.pointPipeline = W(this.device, this.format)), this.bandPipeline || (this.bandPipeline = Y(this.device, this.format)), this.heatmapPipeline || (this.heatmapPipeline = K(this.device, this.format));
816
- }
817
- render(e, t) {
818
- if (!this.device || !this.context || !this.format)
819
- throw new Error("[gpu] WebGPUBackend not initialized");
820
- this.viewport || this.setViewport(t.viewport), this.ensurePipelines();
821
- const r = this.device.createCommandEncoder(), i = this.context.getCurrentTexture().createView(), a = r.beginRenderPass({
822
- colorAttachments: [
823
- {
824
- view: i,
825
- clearValue: {
826
- r: t.clearColor[0],
827
- g: t.clearColor[1],
828
- b: t.clearColor[2],
829
- a: t.clearColor[3]
830
- },
831
- loadOp: "clear",
832
- storeOp: "store"
833
- }
834
- ]
835
- }), n = { xMin: -1, xMax: 1, yMin: -1, yMax: 1 };
836
- for (const s of e.items) {
837
- if (!s.visible) continue;
838
- const c = this.buffers.get(s.bufferId);
839
- c && this.renderDrawCall(a, s, c, n);
840
- }
841
- a.end(), this.device.queue.submit([r.finish()]);
842
- }
843
- /**
844
- * Render with explicit bounds (for integration with chart system)
845
- */
846
- renderWithBounds(e, t, r) {
847
- if (!this.device || !this.context || !this.format)
848
- throw new Error("[gpu] WebGPUBackend not initialized");
849
- this.viewport || this.setViewport(t.viewport), this.ensurePipelines();
850
- const i = this.device.createCommandEncoder(), a = this.context.getCurrentTexture().createView(), n = i.beginRenderPass({
851
- colorAttachments: [
852
- {
853
- view: a,
854
- clearValue: {
855
- r: t.clearColor[0],
856
- g: t.clearColor[1],
857
- b: t.clearColor[2],
858
- a: t.clearColor[3]
859
- },
860
- loadOp: "clear",
861
- storeOp: "store"
862
- }
863
- ]
864
- });
865
- for (const s of e.items) {
866
- if (!s.visible) continue;
867
- const c = this.buffers.get(s.bufferId);
868
- if (!c) continue;
869
- const u = s.yBounds ? { ...r, yMin: s.yBounds.min, yMax: s.yBounds.max } : r;
870
- this.renderDrawCall(n, s, c, u);
871
- }
872
- n.end(), this.device.queue.submit([i.finish()]);
873
- }
874
- /**
875
- * Render a single draw call
876
- */
877
- renderDrawCall(e, t, r, i) {
878
- const a = J(i), n = ee(t.style);
879
- switch (t.kind) {
880
- case "triangles":
881
- case "bar":
882
- this.renderSolidTriangles(e, r, t.count, a, n);
883
- break;
884
- case "line":
885
- this.renderLine(e, r, t.count, a, n);
886
- break;
887
- case "scatter":
888
- case "points":
889
- this.renderPoints(e, r, t.count, a, n, t.style);
890
- break;
891
- case "line+scatter":
892
- this.renderLine(e, r, t.count, a, n), this.renderPoints(e, r, t.count, a, n, t.style);
893
- break;
894
- case "step":
895
- if (t.stepBufferId && t.stepCount) {
896
- const c = this.buffers.get(t.stepBufferId);
897
- c && this.renderLine(e, c, t.stepCount, a, n);
898
- } else
899
- this.renderLine(e, r, t.count, a, n);
900
- break;
901
- case "step+scatter":
902
- if (t.stepBufferId && t.stepCount) {
903
- const c = this.buffers.get(t.stepBufferId);
904
- c && this.renderLine(e, c, t.stepCount, a, n);
905
- } else
906
- this.renderLine(e, r, t.count, a, n);
907
- this.renderPoints(e, r, t.count, a, n, t.style);
908
- break;
909
- case "band":
910
- const s = [
911
- n[0],
912
- n[1],
913
- n[2],
914
- n[3] * 0.4
915
- ];
916
- this.renderBand(e, r, t.count, a, s);
917
- break;
918
- case "heatmap":
919
- this.renderHeatmap(e, r, t.count, a, t.style, t.textureId);
920
- break;
921
- }
922
- }
923
- /** Triangle list with line-pipeline uniforms (xy vertices, uniform color). */
924
- renderSolidTriangles(e, t, r, i, a) {
925
- A(this.device, this.linePipeline.uniformBuffer, {
926
- scale: i.scale,
927
- translate: i.translate,
928
- color: a
929
- }), e.setPipeline(this.linePipeline.pipeline), e.setBindGroup(0, this.linePipeline.bindGroup), e.setVertexBuffer(0, t), e.draw(r);
930
- }
931
- renderLine(e, t, r, i, a) {
932
- A(this.device, this.linePipeline.uniformBuffer, {
933
- scale: i.scale,
934
- translate: i.translate,
935
- color: a
936
- }), e.setPipeline(this.linePipeline.pipeline), e.setBindGroup(0, this.linePipeline.bindGroup), e.setVertexBuffer(0, t), e.draw(r);
937
- }
938
- renderPoints(e, t, r, i, a, n) {
939
- var p;
940
- const s = ((n == null ? void 0 : n.pointSize) ?? 4) * (((p = this.viewport) == null ? void 0 : p.dpr) ?? 1), c = X[(n == null ? void 0 : n.symbol) ?? "circle"] ?? 0, u = [
941
- this.canvas.width,
942
- this.canvas.height
943
- ];
944
- N(this.device, this.pointPipeline.uniformBuffer, {
945
- scale: i.scale,
946
- translate: i.translate,
947
- color: a,
948
- pointSize: s,
949
- symbol: c,
950
- viewport: u
951
- }), e.setPipeline(this.pointPipeline.pipeline), e.setBindGroup(0, this.pointPipeline.bindGroup), e.setVertexBuffer(0, t), e.setVertexBuffer(1, this.pointPipeline.quadBuffer), e.draw(6, r);
952
- }
953
- renderBand(e, t, r, i, a) {
954
- $(this.device, this.bandPipeline.uniformBuffer, {
955
- scale: i.scale,
956
- translate: i.translate,
957
- color: a
958
- }), e.setPipeline(this.bandPipeline.pipeline), e.setBindGroup(0, this.bandPipeline.bindGroup), e.setVertexBuffer(0, t), e.draw(r);
959
- }
960
- renderHeatmap(e, t, r, i, a, n) {
961
- if (!n) return;
962
- const s = this.textures.get(n);
963
- if (!s) return;
964
- const c = (a == null ? void 0 : a.zBounds) ?? { min: 0, max: 1 };
965
- Q(this.device, this.heatmapPipeline.uniformBuffer, {
966
- scale: i.scale,
967
- translate: i.translate,
968
- minValue: c.min,
969
- maxValue: c.max
970
- });
971
- let u = this.heatmapBindGroups.get(n);
972
- u || (u = Z(
973
- this.device,
974
- this.heatmapPipeline.bindGroupLayout,
975
- this.heatmapPipeline.uniformBuffer,
976
- this.heatmapPipeline.sampler,
977
- s
978
- ), this.heatmapBindGroups.set(n, u)), e.setPipeline(this.heatmapPipeline.pipeline), e.setBindGroup(0, u), e.setVertexBuffer(0, t), e.draw(r);
979
- }
980
- destroy() {
981
- for (const e of Array.from(this.buffers.keys()))
982
- this.deleteBuffer(e);
983
- for (const e of Array.from(this.textures.keys()))
984
- this.deleteTexture(e);
985
- this.trianglePipeline = null, this.linePipeline = null, this.pointPipeline = null, this.bandPipeline = null, this.heatmapPipeline = null, this.heatmapBindGroups.clear(), this.device = void 0, this.adapter = void 0, this.context = void 0, this.format = null;
986
- }
987
- }
988
- const ge = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
989
- __proto__: null,
990
- WebGPUBackend: v
991
- }, Symbol.toStringTag, { value: "Module" })), te = `
992
- precision highp float;
993
- attribute vec2 aPosition;
994
- uniform vec2 uScale;
995
- uniform vec2 uTranslate;
996
-
997
- void main() {
998
- vec2 pos = aPosition * uScale + uTranslate;
999
- gl_Position = vec4(pos, 0.0, 1.0);
1000
- }
1001
- `, re = `
1002
- precision highp float;
1003
- uniform vec4 uColor;
1004
-
1005
- void main() {
1006
- gl_FragColor = uColor;
1007
- }
1008
- `, ie = `
1009
- precision highp float;
1010
- attribute vec2 aPosition;
1011
- uniform vec2 uScale;
1012
- uniform vec2 uTranslate;
1013
- uniform float uPointSize;
1014
-
1015
- void main() {
1016
- vec2 pos = aPosition * uScale + uTranslate;
1017
- gl_Position = vec4(pos, 0.0, 1.0);
1018
- gl_PointSize = uPointSize;
1019
- }
1020
- `, ae = `
1021
- precision highp float;
1022
- uniform vec4 uColor;
1023
- uniform int uSymbol;
1024
-
1025
- float sdCircle(vec2 p, float r) {
1026
- return length(p) - r;
1027
- }
1028
-
1029
- float sdBox(vec2 p, vec2 b) {
1030
- vec2 d = abs(p) - b;
1031
- return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);
1032
- }
1033
-
1034
- float sdTriangle(vec2 p, float r) {
1035
- const float k = sqrt(3.0);
1036
- p.x = abs(p.x) - r;
1037
- p.y = p.y + r / k;
1038
- if (p.x + k * p.y > 0.0) p = vec2(p.x - k * p.y, -k * p.x - p.y) / 2.0;
1039
- p.x -= clamp(p.x, -2.0 * r, 0.0);
1040
- return -length(p) * sign(p.y);
1041
- }
1042
-
1043
- float sdDiamond(vec2 p, float r) {
1044
- return (abs(p.x) + abs(p.y)) - r;
1045
- }
1046
-
1047
- float sdCross(vec2 p, float r, float thickness) {
1048
- vec2 d = abs(p);
1049
- float s1 = sdBox(d, vec2(r, thickness));
1050
- float s2 = sdBox(d, vec2(thickness, r));
1051
- return min(s1, s2);
1052
- }
1053
-
1054
- float sdX(vec2 p, float r, float thickness) {
1055
- float c = cos(0.785398);
1056
- float s = sin(0.785398);
1057
- mat2 m = mat2(c, -s, s, c);
1058
- return sdCross(m * p, r, thickness);
1059
- }
1060
-
1061
- float sdStar(vec2 p, float r, float rf) {
1062
- const vec2 k1 = vec2(0.80901699, -0.58778525);
1063
- const vec2 k2 = vec2(-k1.x, k1.y);
1064
- p.x = abs(p.x);
1065
- p -= 2.0 * max(dot(k1, p), 0.0) * k1;
1066
- p -= 2.0 * max(dot(k2, p), 0.0) * k2;
1067
- p.x = abs(p.x);
1068
- p.y -= r;
1069
- vec2 ba = rf * vec2(-k1.y, k1.x) - vec2(0, 1);
1070
- float h = clamp(dot(p, ba) / dot(ba, ba), 0.0, r);
1071
- return length(p - ba * h) * sign(p.y * ba.x - p.x * ba.y);
1072
- }
1073
-
1074
- void main() {
1075
- vec2 p = gl_PointCoord - vec2(0.5);
1076
- float d = 0.0;
1077
-
1078
- if (uSymbol == 0) {
1079
- d = sdCircle(p, 0.45);
1080
- } else if (uSymbol == 1) {
1081
- d = sdBox(p, vec2(0.35));
1082
- } else if (uSymbol == 2) {
1083
- d = sdDiamond(p, 0.45);
1084
- } else if (uSymbol == 3) {
1085
- d = sdTriangle(vec2(p.x, p.y + 0.1), 0.4);
1086
- } else if (uSymbol == 4) {
1087
- d = sdTriangle(vec2(p.x, -p.y + 0.1), 0.4);
1088
- } else if (uSymbol == 5) {
1089
- d = sdCross(p, 0.45, 0.15);
1090
- } else if (uSymbol == 6) {
1091
- d = sdX(p, 0.45, 0.15);
1092
- } else if (uSymbol == 7) {
1093
- d = sdStar(p, 0.45, 0.4);
1094
- }
1095
-
1096
- if (d > 0.02) discard;
1097
-
1098
- float alpha = 1.0 - smoothstep(0.0, 0.02, d);
1099
- gl_FragColor = vec4(uColor.rgb, uColor.a * alpha);
1100
- }
1101
- `, ne = `
1102
- precision highp float;
1103
- attribute vec2 aPosition;
1104
- attribute float aValue;
1105
- uniform vec2 uScale;
1106
- uniform vec2 uTranslate;
1107
- varying float vValue;
1108
-
1109
- void main() {
1110
- gl_Position = vec4(aPosition * uScale + uTranslate, 0.0, 1.0);
1111
- vValue = aValue;
1112
- }
1113
- `, oe = `
1114
- precision highp float;
1115
- varying float vValue;
1116
- uniform float uMinValue;
1117
- uniform float uMaxValue;
1118
- uniform sampler2D uColormap;
1119
-
1120
- void main() {
1121
- float range = uMaxValue - uMinValue;
1122
- float t = (vValue - uMinValue) / (range != 0.0 ? range : 1.0);
1123
- t = clamp(t, 0.0, 1.0);
1124
- gl_FragColor = texture2D(uColormap, vec2(t, 0.5));
1125
- }
1126
- `;
1127
- function C(o, e, t) {
1128
- const r = o.createShader(e);
1129
- if (!r)
1130
- throw new Error("[WebGL] Failed to create shader");
1131
- if (o.shaderSource(r, t), o.compileShader(r), !o.getShaderParameter(r, o.COMPILE_STATUS)) {
1132
- const i = o.getShaderInfoLog(r);
1133
- throw o.deleteShader(r), new Error(`[WebGL] Shader compilation error: ${i}`);
1134
- }
1135
- return r;
1136
- }
1137
- function se(o, e, t) {
1138
- const r = o.createProgram();
1139
- if (!r)
1140
- throw new Error("[WebGL] Failed to create program");
1141
- if (o.attachShader(r, e), o.attachShader(r, t), o.linkProgram(r), !o.getProgramParameter(r, o.LINK_STATUS)) {
1142
- const i = o.getProgramInfoLog(r);
1143
- throw o.deleteProgram(r), new Error(`[WebGL] Program link error: ${i}`);
1144
- }
1145
- return r;
1146
- }
1147
- function S(o, e, t, r, i) {
1148
- const a = C(o, o.VERTEX_SHADER, e), n = C(o, o.FRAGMENT_SHADER, t), s = se(o, a, n);
1149
- o.deleteShader(a), o.deleteShader(n);
1150
- const c = {};
1151
- for (const p of r)
1152
- c[p] = o.getAttribLocation(s, p);
1153
- const u = {};
1154
- for (const p of i)
1155
- u[p] = o.getUniformLocation(s, p);
1156
- return { program: s, attributes: c, uniforms: u };
1157
- }
1158
- function ce(o) {
1159
- const e = S(
1160
- o,
1161
- te,
1162
- re,
1163
- ["aPosition"],
1164
- ["uScale", "uTranslate", "uColor"]
1165
- ), t = S(
1166
- o,
1167
- ie,
1168
- ae,
1169
- ["aPosition"],
1170
- ["uScale", "uTranslate", "uColor", "uPointSize", "uSymbol"]
1171
- ), r = S(
1172
- o,
1173
- ne,
1174
- oe,
1175
- ["aPosition", "aValue"],
1176
- ["uScale", "uTranslate", "uMinValue", "uMaxValue", "uColormap"]
1177
- );
1178
- return { line: e, point: t, heatmap: r };
1179
- }
1180
- function le(o, e) {
1181
- o.deleteProgram(e.line.program), o.deleteProgram(e.point.program), o.deleteProgram(e.heatmap.program);
1182
- }
1183
- const ue = {
1184
- circle: 0,
1185
- square: 1,
1186
- diamond: 2,
1187
- triangle: 3,
1188
- triangleDown: 4,
1189
- cross: 5,
1190
- x: 6,
1191
- star: 7
1192
- };
1193
- function fe(o) {
1194
- const e = o.xMax - o.xMin, t = o.yMax - o.yMin, r = e > 0 ? 2 / e : 1, i = t > 0 ? 2 / t : 1, a = -1 - o.xMin * r, n = -1 - o.yMin * i;
1195
- return {
1196
- scale: [r, i],
1197
- translate: [a, n]
1198
- };
1199
- }
1200
- function pe(o) {
1201
- const e = (o == null ? void 0 : o.color) ?? [1, 0, 0.3, 1], t = (o == null ? void 0 : o.opacity) ?? 1;
1202
- return Array.isArray(e) ? [e[0], e[1], e[2], (e[3] ?? 1) * t] : [1, 0, 0.3, t];
1203
- }
1204
- class y {
1205
- constructor(e, t = {}) {
1206
- l(this, "info");
1207
- l(this, "canvas");
1208
- l(this, "opts");
1209
- l(this, "gl", null);
1210
- l(this, "viewport", null);
1211
- l(this, "dpr", 1);
1212
- l(this, "programs", null);
1213
- l(this, "buffers", /* @__PURE__ */ new Map());
1214
- l(this, "textures", /* @__PURE__ */ new Map());
1215
- this.canvas = e, this.opts = t, this.info = {
1216
- type: "webgl",
1217
- available: y.isSupported()
1218
- };
1219
- }
1220
- static isSupported() {
1221
- if (typeof document > "u") return !1;
1222
- try {
1223
- const e = document.createElement("canvas");
1224
- return !!(e.getContext("webgl") || e.getContext("experimental-webgl"));
1225
- } catch {
1226
- return !1;
1227
- }
1228
- }
1229
- async init() {
1230
- if (!this.info.available)
1231
- throw new Error("[gpu] WebGL not supported");
1232
- const e = this.canvas.getContext("webgl", {
1233
- alpha: !0,
1234
- antialias: this.opts.antialias ?? !0,
1235
- preserveDrawingBuffer: this.opts.preserveDrawingBuffer ?? !0,
1236
- powerPreference: this.opts.powerPreference ?? "high-performance"
1237
- });
1238
- if (!e)
1239
- throw new Error("[gpu] Failed to get WebGL context");
1240
- this.gl = e, e.enable(e.BLEND), e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), this.programs = ce(e);
1241
- }
1242
- setViewport(e) {
1243
- this.viewport = e, this.dpr = e.dpr;
1244
- const t = Math.max(1, Math.floor(e.width * e.dpr)), r = Math.max(1, Math.floor(e.height * e.dpr));
1245
- this.canvas.width !== t && (this.canvas.width = t), this.canvas.height !== r && (this.canvas.height = r), this.gl && this.gl.viewport(0, 0, t, r);
1246
- }
1247
- createOrUpdateBuffer(e, t, r) {
1248
- if (!this.gl)
1249
- throw new Error("[gpu] WebGLBackend not initialized");
1250
- const i = this.gl;
1251
- let a = this.buffers.get(e);
1252
- a || (a = i.createBuffer(), this.buffers.set(e, a));
1253
- const n = (r == null ? void 0 : r.usage) === "index" ? i.ELEMENT_ARRAY_BUFFER : i.ARRAY_BUFFER;
1254
- i.bindBuffer(n, a), i.bufferData(n, t, i.DYNAMIC_DRAW), i.bindBuffer(n, null);
1255
- }
1256
- deleteBuffer(e) {
1257
- if (!this.gl) return;
1258
- const t = this.buffers.get(e);
1259
- t && (this.gl.deleteBuffer(t), this.buffers.delete(e));
1260
- }
1261
- createOrUpdateTexture1D(e, t, r) {
1262
- if (!this.gl)
1263
- throw new Error("[gpu] WebGLBackend not initialized");
1264
- const i = this.gl, a = (r == null ? void 0 : r.width) ?? Math.floor(t.length / 4);
1265
- let n = this.textures.get(e);
1266
- n || (n = i.createTexture(), this.textures.set(e, n)), i.bindTexture(i.TEXTURE_2D, n), i.texImage2D(i.TEXTURE_2D, 0, i.RGBA, a, 1, 0, i.RGBA, i.UNSIGNED_BYTE, t), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_MIN_FILTER, i.LINEAR), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_MAG_FILTER, i.LINEAR), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_WRAP_S, i.CLAMP_TO_EDGE), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_WRAP_T, i.CLAMP_TO_EDGE), i.bindTexture(i.TEXTURE_2D, null);
1267
- }
1268
- deleteTexture(e) {
1269
- if (!this.gl) return;
1270
- const t = this.textures.get(e);
1271
- t && (this.gl.deleteTexture(t), this.textures.delete(e));
1272
- }
1273
- render(e, t) {
1274
- this.renderWithBounds(e, t, { xMin: -1, xMax: 1, yMin: -1, yMax: 1 });
1275
- }
1276
- renderWithBounds(e, t, r) {
1277
- if (!this.gl || !this.programs)
1278
- throw new Error("[gpu] WebGLBackend not initialized");
1279
- const i = this.gl;
1280
- this.viewport || this.setViewport(t.viewport), i.clearColor(
1281
- t.clearColor[0],
1282
- t.clearColor[1],
1283
- t.clearColor[2],
1284
- t.clearColor[3]
1285
- ), i.clear(i.COLOR_BUFFER_BIT);
1286
- for (const a of e.items) {
1287
- if (!a.visible) continue;
1288
- const n = this.buffers.get(a.bufferId);
1289
- if (!n) continue;
1290
- const s = a.yBounds ? { ...r, yMin: a.yBounds.min, yMax: a.yBounds.max } : r;
1291
- this.renderDrawCall(a, n, s);
1292
- }
1293
- }
1294
- renderDrawCall(e, t, r) {
1295
- const i = fe(r), a = pe(e.style);
1296
- switch (e.kind) {
1297
- case "line":
1298
- case "step":
1299
- this.renderLine(t, e.count, i, a);
1300
- break;
1301
- case "scatter":
1302
- case "points":
1303
- this.renderPoints(t, e.count, i, a, e.style);
1304
- break;
1305
- case "line+scatter":
1306
- this.renderLine(t, e.count, i, a), this.renderPoints(t, e.count, i, a, e.style);
1307
- break;
1308
- case "step+scatter":
1309
- if (e.stepBufferId && e.stepCount) {
1310
- const s = this.buffers.get(e.stepBufferId);
1311
- s && this.renderLine(s, e.stepCount, i, a);
1312
- } else
1313
- this.renderLine(t, e.count, i, a);
1314
- this.renderPoints(t, e.count, i, a, e.style);
1315
- break;
1316
- case "band":
1317
- const n = [
1318
- a[0],
1319
- a[1],
1320
- a[2],
1321
- a[3] * 0.4
1322
- ];
1323
- this.renderBand(t, e.count, i, n);
1324
- break;
1325
- case "triangles":
1326
- case "bar":
1327
- this.renderTriangles(t, e.count, i, a);
1328
- break;
1329
- case "heatmap":
1330
- this.renderHeatmap(t, e.count, i, e.style, e.textureId);
1331
- break;
1332
- }
1333
- }
1334
- renderLine(e, t, r, i) {
1335
- const a = this.gl, n = this.programs.line;
1336
- a.useProgram(n.program), a.bindBuffer(a.ARRAY_BUFFER, e), a.enableVertexAttribArray(n.attributes.aPosition), a.vertexAttribPointer(n.attributes.aPosition, 2, a.FLOAT, !1, 0, 0), a.uniform2f(n.uniforms.uScale, r.scale[0], r.scale[1]), a.uniform2f(n.uniforms.uTranslate, r.translate[0], r.translate[1]), a.uniform4f(n.uniforms.uColor, i[0], i[1], i[2], i[3]), a.drawArrays(a.LINE_STRIP, 0, t), a.disableVertexAttribArray(n.attributes.aPosition);
1337
- }
1338
- renderPoints(e, t, r, i, a) {
1339
- const n = this.gl, s = this.programs.point, c = ((a == null ? void 0 : a.pointSize) ?? 4) * this.dpr, u = ue[(a == null ? void 0 : a.symbol) ?? "circle"] ?? 0;
1340
- n.useProgram(s.program), n.bindBuffer(n.ARRAY_BUFFER, e), n.enableVertexAttribArray(s.attributes.aPosition), n.vertexAttribPointer(s.attributes.aPosition, 2, n.FLOAT, !1, 0, 0), n.uniform2f(s.uniforms.uScale, r.scale[0], r.scale[1]), n.uniform2f(s.uniforms.uTranslate, r.translate[0], r.translate[1]), n.uniform4f(s.uniforms.uColor, i[0], i[1], i[2], i[3]), n.uniform1f(s.uniforms.uPointSize, c), n.uniform1i(s.uniforms.uSymbol, u), n.drawArrays(n.POINTS, 0, t), n.disableVertexAttribArray(s.attributes.aPosition);
1341
- }
1342
- renderBand(e, t, r, i) {
1343
- const a = this.gl, n = this.programs.line;
1344
- a.useProgram(n.program), a.bindBuffer(a.ARRAY_BUFFER, e), a.enableVertexAttribArray(n.attributes.aPosition), a.vertexAttribPointer(n.attributes.aPosition, 2, a.FLOAT, !1, 0, 0), a.uniform2f(n.uniforms.uScale, r.scale[0], r.scale[1]), a.uniform2f(n.uniforms.uTranslate, r.translate[0], r.translate[1]), a.uniform4f(n.uniforms.uColor, i[0], i[1], i[2], i[3]), a.drawArrays(a.TRIANGLE_STRIP, 0, t), a.disableVertexAttribArray(n.attributes.aPosition);
1345
- }
1346
- renderTriangles(e, t, r, i) {
1347
- const a = this.gl, n = this.programs.line;
1348
- a.useProgram(n.program), a.bindBuffer(a.ARRAY_BUFFER, e), a.enableVertexAttribArray(n.attributes.aPosition), a.vertexAttribPointer(n.attributes.aPosition, 2, a.FLOAT, !1, 0, 0), a.uniform2f(n.uniforms.uScale, r.scale[0], r.scale[1]), a.uniform2f(n.uniforms.uTranslate, r.translate[0], r.translate[1]), a.uniform4f(n.uniforms.uColor, i[0], i[1], i[2], i[3]), a.drawArrays(a.TRIANGLES, 0, t), a.disableVertexAttribArray(n.attributes.aPosition);
1349
- }
1350
- renderHeatmap(e, t, r, i, a) {
1351
- if (!a) return;
1352
- const n = this.textures.get(a);
1353
- if (!n) return;
1354
- const s = this.gl, c = this.programs.heatmap, u = (i == null ? void 0 : i.zBounds) ?? { min: 0, max: 1 };
1355
- s.useProgram(c.program), s.bindBuffer(s.ARRAY_BUFFER, e), s.enableVertexAttribArray(c.attributes.aPosition), s.vertexAttribPointer(c.attributes.aPosition, 2, s.FLOAT, !1, 12, 0), c.attributes.aValue !== -1 && (s.enableVertexAttribArray(c.attributes.aValue), s.vertexAttribPointer(c.attributes.aValue, 1, s.FLOAT, !1, 12, 8)), s.uniform2f(c.uniforms.uScale, r.scale[0], r.scale[1]), s.uniform2f(c.uniforms.uTranslate, r.translate[0], r.translate[1]), s.uniform1f(c.uniforms.uMinValue, u.min), s.uniform1f(c.uniforms.uMaxValue, u.max), s.activeTexture(s.TEXTURE0), s.bindTexture(s.TEXTURE_2D, n), s.uniform1i(c.uniforms.uColormap, 0), s.drawArrays(s.TRIANGLES, 0, t), s.disableVertexAttribArray(c.attributes.aPosition), c.attributes.aValue !== -1 && s.disableVertexAttribArray(c.attributes.aValue);
1356
- }
1357
- destroy() {
1358
- if (!this.gl) return;
1359
- const e = this.gl;
1360
- for (const t of this.buffers.values())
1361
- e.deleteBuffer(t);
1362
- this.buffers.clear();
1363
- for (const t of this.textures.values())
1364
- e.deleteTexture(t);
1365
- this.textures.clear(), this.programs && (le(e, this.programs), this.programs = null), this.gl = null;
1366
- }
1367
- }
1368
- const me = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1369
- __proto__: null,
1370
- WebGLBackend: y
1371
- }, Symbol.toStringTag, { value: "Module" }));
1372
- function m(o) {
1373
- if (!o)
1374
- return [1, 0, 0.3, 1];
1375
- if (Array.isArray(o))
1376
- return [o[0], o[1], o[2], o[3] ?? 1];
1377
- const e = o;
1378
- if (e.startsWith("#")) {
1379
- const r = e.slice(1);
1380
- if (r.length === 3) {
1381
- const i = parseInt(r[0] + r[0], 16) / 255, a = parseInt(r[1] + r[1], 16) / 255, n = parseInt(r[2] + r[2], 16) / 255;
1382
- return [i, a, n, 1];
1383
- }
1384
- if (r.length === 6) {
1385
- const i = parseInt(r.slice(0, 2), 16) / 255, a = parseInt(r.slice(2, 4), 16) / 255, n = parseInt(r.slice(4, 6), 16) / 255;
1386
- return [i, a, n, 1];
1387
- }
1388
- if (r.length === 8) {
1389
- const i = parseInt(r.slice(0, 2), 16) / 255, a = parseInt(r.slice(2, 4), 16) / 255, n = parseInt(r.slice(4, 6), 16) / 255, s = parseInt(r.slice(6, 8), 16) / 255;
1390
- return [i, a, n, s];
1391
- }
1392
- }
1393
- const t = e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
1394
- if (t) {
1395
- const r = parseInt(t[1]) / 255, i = parseInt(t[2]) / 255, a = parseInt(t[3]) / 255, n = t[4] ? parseFloat(t[4]) : 1;
1396
- return [r, i, a, n];
1397
- }
1398
- return [1, 0, 0.3, 1];
1399
- }
1400
- function de(o, e) {
1401
- const t = m(o.color), r = o.opacity ?? 1, i = [t[0], t[1], t[2], t[3] * r];
1402
- return e === "scatter" || e === "line+scatter" || e === "step+scatter" ? {
1403
- color: i,
1404
- opacity: r,
1405
- pointSize: o.pointSize ?? 4,
1406
- symbol: o.symbol ?? "circle"
1407
- } : {
1408
- color: i,
1409
- opacity: r,
1410
- lineWidth: o.lineWidth ?? 1
1411
- };
1412
- }
1413
- class U {
1414
- constructor(e) {
1415
- l(this, "backend");
1416
- l(this, "seriesBufferMap", /* @__PURE__ */ new Map());
1417
- l(this, "seriesStepBufferMap", /* @__PURE__ */ new Map());
1418
- l(this, "seriesTextureMap", /* @__PURE__ */ new Map());
1419
- this.backend = e;
1420
- }
1421
- /**
1422
- * Get buffer ID for a series
1423
- */
1424
- getBufferId(e) {
1425
- return this.seriesBufferMap.has(e) || this.seriesBufferMap.set(e, `series:${e}`), this.seriesBufferMap.get(e);
1426
- }
1427
- /**
1428
- * Get step buffer ID for a series
1429
- */
1430
- getStepBufferId(e) {
1431
- return this.seriesStepBufferMap.has(e) || this.seriesStepBufferMap.set(e, `series:${e}:step`), this.seriesStepBufferMap.get(e);
1432
- }
1433
- /**
1434
- * Get texture ID for a series
1435
- */
1436
- getTextureId(e) {
1437
- return this.seriesTextureMap.has(e) || this.seriesTextureMap.set(e, `texture:${e}`), this.seriesTextureMap.get(e);
1438
- }
1439
- /**
1440
- * Update series data in GPU buffers
1441
- */
1442
- updateSeries(e) {
1443
- const t = this.getBufferId(e.id);
1444
- if (this.backend.createOrUpdateBuffer(t, e.data, { usage: "vertex" }), e.stepData && (e.type === "step" || e.type === "step+scatter")) {
1445
- const r = this.getStepBufferId(e.id);
1446
- this.backend.createOrUpdateBuffer(r, e.stepData, { usage: "vertex" });
1447
- }
1448
- if (e.type === "heatmap" && e.colormapData) {
1449
- const r = this.getTextureId(e.id);
1450
- this.backend.createOrUpdateTexture1D(r, e.colormapData, {
1451
- width: e.colormapData.length / 4
1452
- });
1453
- }
1454
- }
1455
- /**
1456
- * Remove a series from GPU resources
1457
- */
1458
- removeSeries(e) {
1459
- const t = this.seriesBufferMap.get(e);
1460
- t && (this.backend.deleteBuffer(t), this.seriesBufferMap.delete(e));
1461
- const r = this.seriesStepBufferMap.get(e);
1462
- r && (this.backend.deleteBuffer(r), this.seriesStepBufferMap.delete(e));
1463
- const i = this.seriesTextureMap.get(e);
1464
- i && (this.backend.deleteTexture(i), this.seriesTextureMap.delete(e));
1465
- }
1466
- /**
1467
- * Build draw list from series array
1468
- */
1469
- buildDrawList(e) {
1470
- const t = [];
1471
- for (const r of e) {
1472
- this.updateSeries(r);
1473
- const i = this.getBufferId(r.id), a = r.data.length / 2, n = {
1474
- id: r.id,
1475
- kind: r.type,
1476
- bufferId: i,
1477
- count: r.type === "heatmap" ? r.data.length / 3 : a,
1478
- visible: r.visible,
1479
- style: de(r.style, r.type),
1480
- yBounds: r.yBounds
1481
- };
1482
- r.stepData && (r.type === "step" || r.type === "step+scatter") && (n.stepBufferId = this.getStepBufferId(r.id), n.stepCount = r.stepData.length / 2), r.type === "heatmap" && (n.textureId = this.getTextureId(r.id), n.style = {
1483
- zBounds: r.zBounds,
1484
- colormap: r.colormap
1485
- }), t.push(n);
1486
- }
1487
- return { items: t };
1488
- }
1489
- /**
1490
- * Cleanup all resources
1491
- */
1492
- destroy() {
1493
- for (const e of this.seriesBufferMap.values())
1494
- this.backend.deleteBuffer(e);
1495
- for (const e of this.seriesStepBufferMap.values())
1496
- this.backend.deleteBuffer(e);
1497
- for (const e of this.seriesTextureMap.values())
1498
- this.backend.deleteTexture(e);
1499
- this.seriesBufferMap.clear(), this.seriesStepBufferMap.clear(), this.seriesTextureMap.clear();
1500
- }
1501
- }
1502
- class he {
1503
- constructor(e, t = {}) {
1504
- l(this, "canvas");
1505
- l(this, "options");
1506
- l(this, "backend", null);
1507
- l(this, "adapter", null);
1508
- l(this, "dpr");
1509
- l(this, "isInitialized", !1);
1510
- l(this, "backendType", null);
1511
- // Buffer management
1512
- l(this, "bufferDataMap", /* @__PURE__ */ new Map());
1513
- l(this, "stepBufferDataMap", /* @__PURE__ */ new Map());
1514
- l(this, "colormapDataMap", /* @__PURE__ */ new Map());
1515
- this.canvas = e, this.options = t, this.dpr = window.devicePixelRatio || 1;
1516
- }
1517
- /**
1518
- * Initialize the renderer
1519
- */
1520
- async init() {
1521
- const e = this.options.backend ?? "auto";
1522
- if ((e === "webgpu" || e === "auto") && v.isSupported())
1523
- try {
1524
- const t = new v(this.canvas, {
1525
- powerPreference: this.options.powerPreference ?? "high-performance"
1526
- });
1527
- return await t.init(), this.backend = t, this.backendType = "webgpu", this.adapter = new U(t), this.isInitialized = !0, this.resize(), !0;
1528
- } catch (t) {
1529
- console.warn("[GpuRenderer] WebGPU init failed:", t);
1530
- }
1531
- if ((e === "webgl" || e === "auto") && y.isSupported())
1532
- try {
1533
- const t = new y(this.canvas, {
1534
- powerPreference: this.options.powerPreference ?? "high-performance"
1535
- });
1536
- return await t.init(), this.backend = t, this.backendType = "webgl", this.adapter = new U(t), this.isInitialized = !0, this.resize(), console.info("[GpuRenderer] Using WebGL backend (WebGPU not available)"), !0;
1537
- } catch (t) {
1538
- console.warn("[GpuRenderer] WebGL init failed:", t);
1539
- }
1540
- return !1;
1541
- }
1542
- /**
1543
- * Check if renderer is available
1544
- */
1545
- get available() {
1546
- return this.isInitialized;
1547
- }
1548
- /**
1549
- * Get the active backend type
1550
- */
1551
- get activeBackend() {
1552
- return this.backendType;
1553
- }
1554
- /**
1555
- * Set device pixel ratio
1556
- */
1557
- setDPR(e) {
1558
- this.dpr = e, this.resize();
1559
- }
1560
- /**
1561
- * Check if vertex data exists for a buffer id
1562
- */
1563
- hasBuffer(e) {
1564
- return this.bufferDataMap.has(e) || this.stepBufferDataMap.has(e);
1565
- }
1566
- hasColormap(e) {
1567
- return this.colormapDataMap.has(e);
1568
- }
1569
- /**
1570
- * Render from NativeWebGLRenderer-compatible series descriptors (chart integration path).
1571
- */
1572
- renderNativeSeries(e, t) {
1573
- var n, s, c, u, p, g;
1574
- if (!this.isInitialized || !this.backend) return;
1575
- const r = [];
1576
- for (const f of e) {
1577
- if (!f.visible) continue;
1578
- if (f.type === "boxplot") {
1579
- this.appendBoxplotDraws(f, r);
1580
- continue;
1581
- }
1582
- if (f.type === "waterfall") {
1583
- this.appendWaterfallDraws(f, r);
1584
- continue;
1585
- }
1586
- if (f.count === 0) continue;
1587
- const w = this.bufferDataMap.get(f.id);
1588
- if (!w) continue;
1589
- this.backend.createOrUpdateBuffer(f.id, w, { usage: "vertex" });
1590
- const x = m(
1591
- typeof ((n = f.style) == null ? void 0 : n.color) == "string" ? f.style.color : "#00f2ff"
1592
- ), P = ((s = f.style) == null ? void 0 : s.opacity) ?? 1, T = [
1593
- x[0],
1594
- x[1],
1595
- x[2],
1596
- x[3] * P
1597
- ], d = this.mapNativeDrawKind(f.type), h = {
1598
- id: f.id,
1599
- kind: d,
1600
- bufferId: f.id,
1601
- count: f.count,
1602
- visible: !0,
1603
- yBounds: f.yBounds
1604
- };
1605
- if (d === "scatter" || d === "line+scatter" || d === "step+scatter" || d === "points")
1606
- h.style = {
1607
- color: T,
1608
- opacity: P,
1609
- pointSize: ((c = f.style) == null ? void 0 : c.pointSize) ?? 4,
1610
- symbol: ((u = f.style) == null ? void 0 : u.symbol) ?? "circle"
1611
- };
1612
- else if (d === "heatmap") {
1613
- h.textureId = `${f.id}_colormap`, h.style = {
1614
- zBounds: f.zBounds,
1615
- colormap: f.colormap
1616
- };
1617
- const b = this.colormapDataMap.get(`${f.id}_colormap`);
1618
- b && this.backend.createOrUpdateTexture1D(h.textureId, b, {
1619
- width: b.length / 4
1620
- });
1621
- } else
1622
- h.style = {
1623
- color: T,
1624
- opacity: P,
1625
- lineWidth: ((p = f.style) == null ? void 0 : p.width) ?? ((g = f.style) == null ? void 0 : g.lineWidth) ?? 1
1626
- };
1627
- if ((d === "step" || d === "step+scatter") && f.stepBuffer && f.stepCount) {
1628
- const b = `${f.id}_step`, M = this.stepBufferDataMap.get(b);
1629
- M && (this.backend.createOrUpdateBuffer(b, M, { usage: "vertex" }), h.stepBufferId = b, h.stepCount = f.stepCount);
1630
- }
1631
- r.push(h);
1632
- }
1633
- const i = t.dpr ?? this.dpr, a = {
1634
- viewport: {
1635
- width: this.canvas.clientWidth,
1636
- height: this.canvas.clientHeight,
1637
- dpr: i
1638
- },
1639
- clearColor: t.backgroundColor ?? [0.1, 0.1, 0.18, 1],
1640
- bounds: t.bounds,
1641
- plotArea: t.plotArea
1642
- };
1643
- "renderWithBounds" in this.backend ? this.backend.renderWithBounds({ items: r }, a, t.bounds) : this.backend.render({ items: r }, a);
1644
- }
1645
- appendBoxplotDraws(e, t) {
1646
- var n, s, c;
1647
- const r = this.seriesColor(e.style), i = { color: r, opacity: ((n = e.style) == null ? void 0 : n.opacity) ?? 1, lineWidth: ((s = e.style) == null ? void 0 : s.width) ?? 1 }, a = { color: r, opacity: (((c = e.style) == null ? void 0 : c.opacity) ?? 1) * 0.85, lineWidth: 1 };
1648
- this.pushDraw(t, `${e.id}_box_faces`, "bar", e.boxCount ?? 0, a, e.yBounds), this.pushDraw(t, `${e.id}_box_lines`, "line", e.boxLinesCount ?? 0, i, e.yBounds);
1649
- }
1650
- appendWaterfallDraws(e, t) {
1651
- const r = e.style ?? {}, i = this.colorFromHex(r.positiveColor ?? "#22c55e", 0.9), a = this.colorFromHex(r.negativeColor ?? "#ef4444", 0.9), n = this.colorFromHex(r.subtotalColor ?? "#3b82f6", 0.9), s = this.colorFromHex(r.connectorColor ?? "#64748b", 0.6);
1652
- this.pushDraw(t, `${e.id}_wf_positive`, "bar", e.wfPositiveCount ?? 0, { color: i, opacity: 0.9, lineWidth: 1 }, e.yBounds), this.pushDraw(t, `${e.id}_wf_negative`, "bar", e.wfNegativeCount ?? 0, { color: a, opacity: 0.9, lineWidth: 1 }, e.yBounds), this.pushDraw(t, `${e.id}_wf_subtotal`, "bar", e.wfSubtotalCount ?? 0, { color: n, opacity: 0.9, lineWidth: 1 }, e.yBounds), r.showConnectors !== !1 && this.pushDraw(t, `${e.id}_wf_connectors`, "line", e.wfConnectorCount ?? 0, { color: s, opacity: 0.6, lineWidth: 1 }, e.yBounds);
1653
- }
1654
- pushDraw(e, t, r, i, a, n) {
1655
- if (i <= 0) return;
1656
- const s = this.bufferDataMap.get(t);
1657
- !s || !this.backend || (this.backend.createOrUpdateBuffer(t, s, { usage: "vertex" }), e.push({
1658
- id: t,
1659
- kind: r,
1660
- bufferId: t,
1661
- count: i,
1662
- visible: !0,
1663
- style: a,
1664
- yBounds: n
1665
- }));
1666
- }
1667
- seriesColor(e) {
1668
- const t = m(typeof (e == null ? void 0 : e.color) == "string" ? e.color : "#00f2ff"), r = (e == null ? void 0 : e.opacity) ?? 1;
1669
- return [t[0], t[1], t[2], t[3] * r];
1670
- }
1671
- colorFromHex(e, t) {
1672
- const r = m(e);
1673
- return [r[0], r[1], r[2], r[3] * t];
1674
- }
1675
- mapNativeDrawKind(e) {
1676
- switch (e) {
1677
- case "scatter":
1678
- return "scatter";
1679
- case "line+scatter":
1680
- return "line+scatter";
1681
- case "step":
1682
- return "step";
1683
- case "step+scatter":
1684
- return "step+scatter";
1685
- case "band":
1686
- return "band";
1687
- case "bar":
1688
- return "bar";
1689
- case "heatmap":
1690
- return "heatmap";
1691
- default:
1692
- return "line";
1693
- }
1694
- }
1695
- /**
1696
- * Create or update a buffer
1697
- */
1698
- createBuffer(e, t) {
1699
- this.bufferDataMap.set(e, t);
1700
- }
1701
- /**
1702
- * Update a buffer partially
1703
- */
1704
- updateBuffer(e, t, r) {
1705
- const i = this.bufferDataMap.get(e);
1706
- if (!i) return !1;
1707
- const a = r / 4;
1708
- return i.set(t, a), !0;
1709
- }
1710
- /**
1711
- * Get a buffer's data
1712
- */
1713
- getBuffer(e) {
1714
- return this.bufferDataMap.get(e);
1715
- }
1716
- /**
1717
- * Delete a buffer
1718
- */
1719
- deleteBuffer(e) {
1720
- this.bufferDataMap.delete(e), this.backend && this.backend.deleteBuffer(e);
1721
- }
1722
- /**
1723
- * Create or update a step buffer
1724
- */
1725
- createStepBuffer(e, t) {
1726
- this.stepBufferDataMap.set(e, t);
1727
- }
1728
- /**
1729
- * Create colormap texture
1730
- */
1731
- createColormapTexture(e, t) {
1732
- this.colormapDataMap.set(e, t), this.backend && this.backend.createOrUpdateTexture1D(e, t, {
1733
- width: t.length / 4
1734
- });
1735
- }
1736
- /**
1737
- * Render a frame
1738
- */
1739
- render(e, t) {
1740
- if (!this.isInitialized || !this.backend) return;
1741
- const r = this.buildDrawList(e), i = {
1742
- viewport: {
1743
- width: this.canvas.clientWidth,
1744
- height: this.canvas.clientHeight,
1745
- dpr: this.dpr
1746
- },
1747
- clearColor: t.backgroundColor ?? [0.1, 0.1, 0.18, 1],
1748
- bounds: t.bounds,
1749
- plotArea: t.plotArea
1750
- };
1751
- "renderWithBounds" in this.backend ? this.backend.renderWithBounds(r, i, t.bounds) : this.backend.render(r, i);
1752
- }
1753
- /**
1754
- * Build draw list from series data
1755
- */
1756
- buildDrawList(e) {
1757
- const t = [];
1758
- for (const r of e) {
1759
- const i = this.bufferDataMap.get(r.id);
1760
- if (!i) continue;
1761
- this.backend.createOrUpdateBuffer(r.id, i, { usage: "vertex" });
1762
- const a = r.type === "heatmap" ? i.length / 3 : i.length / 2, n = m(r.style.color), s = r.style.opacity ?? 1, c = [
1763
- n[0],
1764
- n[1],
1765
- n[2],
1766
- n[3] * s
1767
- ], u = {
1768
- id: r.id,
1769
- kind: r.type,
1770
- bufferId: r.id,
1771
- count: a,
1772
- visible: r.visible,
1773
- yBounds: r.yBounds
1774
- };
1775
- if (r.type === "scatter" || r.type === "line+scatter" || r.type === "step+scatter")
1776
- u.style = {
1777
- color: c,
1778
- opacity: s,
1779
- pointSize: r.style.pointSize ?? 4,
1780
- symbol: r.style.symbol ?? "circle"
1781
- };
1782
- else if (r.type === "heatmap") {
1783
- u.textureId = `colormap:${r.id}`, u.style = {
1784
- zBounds: r.zBounds,
1785
- colormap: r.colormap
1786
- };
1787
- const p = this.colormapDataMap.get(r.id);
1788
- p && this.backend.createOrUpdateTexture1D(u.textureId, p, {
1789
- width: p.length / 4
1790
- });
1791
- } else
1792
- u.style = {
1793
- color: c,
1794
- opacity: s,
1795
- lineWidth: r.style.lineWidth ?? 1
1796
- };
1797
- if ((r.type === "step" || r.type === "step+scatter") && this.stepBufferDataMap.has(r.id)) {
1798
- const p = this.stepBufferDataMap.get(r.id), g = `${r.id}:step`;
1799
- this.backend.createOrUpdateBuffer(g, p, { usage: "vertex" }), u.stepBufferId = g, u.stepCount = p.length / 2;
1800
- }
1801
- t.push(u);
1802
- }
1803
- return { items: t };
1804
- }
1805
- /**
1806
- * Handle canvas resize
1807
- */
1808
- resize() {
1809
- if (!this.backend) return;
1810
- const e = this.canvas.getBoundingClientRect();
1811
- this.backend.setViewport({
1812
- width: e.width,
1813
- height: e.height,
1814
- dpr: this.dpr
1815
- });
1816
- }
1817
- /**
1818
- * Get renderer limits
1819
- */
1820
- getLimits() {
1821
- return {
1822
- backend: this.backendType,
1823
- available: this.isInitialized
1824
- };
1825
- }
1826
- /**
1827
- * Destroy the renderer
1828
- */
1829
- destroy() {
1830
- var e, t;
1831
- (e = this.adapter) == null || e.destroy(), (t = this.backend) == null || t.destroy(), this.bufferDataMap.clear(), this.stepBufferDataMap.clear(), this.colormapDataMap.clear(), this.adapter = null, this.backend = null, this.isInitialized = !1, this.backendType = null;
1832
- }
1833
- }
1834
- async function ve(o, e) {
1835
- const t = new he(o, e);
1836
- return await t.init() ? t : null;
1837
- }
1838
- export {
1839
- he as G,
1840
- U as S,
1841
- v as W,
1842
- y as a,
1843
- ge as b,
1844
- ve as c,
1845
- me as d,
1846
- m as p
1847
- };
1848
- //# sourceMappingURL=gpuRenderer-BpaMYz-k.js.map