@extend-ai/react-xlsx 0.17.3 → 0.18.1

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 (41) hide show
  1. package/README.md +91 -0
  2. package/dist/Carlito-OFL.txt +94 -0
  3. package/dist/chart-renderer-HQSQHDCB.js +5040 -0
  4. package/dist/chart-renderer-HQSQHDCB.js.map +1 -0
  5. package/dist/chart-renderer-ZUWRNNZT.cjs +5041 -0
  6. package/dist/chart-renderer-ZUWRNNZT.cjs.map +1 -0
  7. package/dist/chunk-5ERNVHSO.cjs +94 -0
  8. package/dist/chunk-5ERNVHSO.cjs.map +1 -0
  9. package/dist/chunk-BAAMDEDS.js +104 -0
  10. package/dist/chunk-BAAMDEDS.js.map +1 -0
  11. package/dist/chunk-E2VSYCP2.cjs +104 -0
  12. package/dist/chunk-E2VSYCP2.cjs.map +1 -0
  13. package/dist/chunk-FO6MIHX4.cjs +8 -0
  14. package/dist/chunk-FO6MIHX4.cjs.map +1 -0
  15. package/dist/chunk-OZLJPZUX.js +70 -0
  16. package/dist/chunk-OZLJPZUX.js.map +1 -0
  17. package/dist/chunk-VWGKYABF.js +94 -0
  18. package/dist/chunk-VWGKYABF.js.map +1 -0
  19. package/dist/chunk-WFQGZI2Z.cjs +70 -0
  20. package/dist/chunk-WFQGZI2Z.cjs.map +1 -0
  21. package/dist/index.cjs +2739 -9039
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +53 -4
  24. package/dist/index.d.ts +53 -4
  25. package/dist/index.js +980 -7247
  26. package/dist/index.js.map +1 -1
  27. package/dist/region-map-geography-5E5SVPGS.cjs +184 -0
  28. package/dist/region-map-geography-5E5SVPGS.cjs.map +1 -0
  29. package/dist/region-map-geography-YD54DI3H.js +182 -0
  30. package/dist/region-map-geography-YD54DI3H.js.map +1 -0
  31. package/dist/spreadsheet-font-assets-7QMV43XD.cjs +121 -0
  32. package/dist/spreadsheet-font-assets-7QMV43XD.cjs.map +1 -0
  33. package/dist/spreadsheet-font-assets-V366MXRM.js +119 -0
  34. package/dist/spreadsheet-font-assets-V366MXRM.js.map +1 -0
  35. package/dist/surface-regl-NWR5ZZ5D.js +720 -0
  36. package/dist/surface-regl-NWR5ZZ5D.js.map +1 -0
  37. package/dist/surface-regl-WVLW3SEA.cjs +721 -0
  38. package/dist/surface-regl-WVLW3SEA.cjs.map +1 -0
  39. package/dist/xlsx-worker.js +234 -267
  40. package/dist/xlsx-worker.js.map +1 -1
  41. package/package.json +2 -2
@@ -0,0 +1,720 @@
1
+ import {
2
+ clipSurfaceBand,
3
+ normalizeSurfaceValue,
4
+ shadeSurfaceMatteColor,
5
+ surfaceBandEdges,
6
+ surfaceDataRatios,
7
+ surfaceNormal,
8
+ transformSurfaceNormal,
9
+ triangulateSurfaceQuad
10
+ } from "./chunk-BAAMDEDS.js";
11
+ import {
12
+ getBuiltinChartColor,
13
+ getBuiltinChartSurfaceLine,
14
+ resolveBuiltinChartColor
15
+ } from "./chunk-VWGKYABF.js";
16
+
17
+ // src/surface-regl.tsx
18
+ import createREGL from "regl";
19
+ import * as React from "react";
20
+ import { jsx, jsxs } from "react/jsx-runtime";
21
+ function clamp(value, min, max) {
22
+ return Math.max(min, Math.min(max, value));
23
+ }
24
+ function safeNumber(value) {
25
+ if (typeof value === "number" && Number.isFinite(value)) {
26
+ return value;
27
+ }
28
+ if (typeof value === "string") {
29
+ const normalized = value.trim().replace(/,/g, "");
30
+ if (!normalized) {
31
+ return null;
32
+ }
33
+ const parsed = Number(normalized);
34
+ return Number.isFinite(parsed) ? parsed : null;
35
+ }
36
+ return null;
37
+ }
38
+ function parseRgbColor(color) {
39
+ const match = /^#?([0-9a-f]{6})$/i.exec(color);
40
+ if (!match) {
41
+ return null;
42
+ }
43
+ return {
44
+ blue: Number.parseInt(match[1].slice(4, 6), 16),
45
+ green: Number.parseInt(match[1].slice(2, 4), 16),
46
+ red: Number.parseInt(match[1].slice(0, 2), 16)
47
+ };
48
+ }
49
+ function resolveSurfaceBaseColor(chart, palette) {
50
+ return chart.chartColorPalette?.[0] ?? chart.series[0]?.color ?? chart.series[0]?.lineColor ?? chart.axisLineColor ?? chart.textColor ?? palette.text;
51
+ }
52
+ function normalizeSurfaceRendererHexColor(value) {
53
+ if (typeof value !== "string") {
54
+ return null;
55
+ }
56
+ const trimmed = value.trim();
57
+ if (!trimmed) {
58
+ return null;
59
+ }
60
+ const normalized = trimmed.startsWith("#") ? trimmed.slice(1) : trimmed;
61
+ return /^[0-9a-f]{6}$/i.test(normalized) ? `#${normalized.toLowerCase()}` : null;
62
+ }
63
+ function resolveExplicitSurfaceSeriesColor(chart, kind) {
64
+ const shape = chart.series[0]?.shapeProperties;
65
+ if (kind === "fill" ? shape?.xmlFillHidden === true : shape?.xmlLineHidden === true) return "transparent";
66
+ const color = kind === "fill" ? shape?.xmlFillColor ?? shape?.solidFillHex : shape?.xmlLineColor ?? shape?.lineColorHex;
67
+ return normalizeSurfaceRendererHexColor(color);
68
+ }
69
+ function getSurfaceColorStops(chart, palette) {
70
+ const explicitFill = resolveExplicitSurfaceSeriesColor(chart, "fill");
71
+ if (explicitFill) return [explicitFill];
72
+ const colors = (chart.chartColorPalette ?? []).filter((value) => typeof value === "string" && value.length > 0);
73
+ return colors.length > 0 ? colors : [resolveSurfaceBaseColor(chart, palette)];
74
+ }
75
+ function getSurfaceDomain(chart) {
76
+ const numericValues = chart.series.flatMap((series) => series.values.map((value) => safeNumber(value)).filter((value) => value != null));
77
+ if (numericValues.length === 0) {
78
+ return null;
79
+ }
80
+ const explicitMin = typeof chart.valueAxis?.min === "number" && Number.isFinite(chart.valueAxis.min) ? chart.valueAxis.min : null;
81
+ const explicitMax = typeof chart.valueAxis?.max === "number" && Number.isFinite(chart.valueAxis.max) ? chart.valueAxis.max : null;
82
+ const rawMin = Math.min(...numericValues);
83
+ const rawMax = Math.max(...numericValues);
84
+ const spanBase = Math.max(1e-6, rawMax - Math.min(0, rawMin));
85
+ const roughStep = spanBase / 5;
86
+ const magnitude = Math.pow(10, Math.floor(Math.log10(Math.max(roughStep, 1e-6))));
87
+ const normalized = roughStep / magnitude;
88
+ const niceStep = normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 5 ? 5 : 10;
89
+ const step = typeof chart.valueAxis?.majorUnit === "number" && chart.valueAxis.majorUnit > 0 ? chart.valueAxis.majorUnit : niceStep * magnitude;
90
+ const minValue = explicitMin ?? (rawMin >= 0 ? 0 : Math.floor(rawMin / step) * step);
91
+ const maxValue = explicitMax ?? Math.ceil(rawMax / step) * step;
92
+ const safeMax = maxValue <= minValue ? minValue + step : maxValue;
93
+ const ticks = [];
94
+ for (let current = minValue; current <= safeMax + step * 1e-3; current += step) {
95
+ ticks.push(Number(current.toFixed(8)));
96
+ }
97
+ const boundedTicks = [.../* @__PURE__ */ new Set([...ticks.filter((tick) => tick < safeMax), safeMax])];
98
+ return {
99
+ maxValue,
100
+ minValue,
101
+ safeMax,
102
+ ticks: boundedTicks.length >= 2 ? boundedTicks : [minValue, safeMax]
103
+ };
104
+ }
105
+ function resolveSurfaceBandPaletteColor(chart, palette, domain, value) {
106
+ const bandIndex = resolveSurfaceBandIndex(domain, value);
107
+ const explicitColor = resolveSurfaceBandFormatColor(chart, "bandFormatColors", bandIndex);
108
+ if (explicitColor) return explicitColor;
109
+ const explicitFill = resolveExplicitSurfaceSeriesColor(chart, "fill");
110
+ if (explicitFill) return explicitFill;
111
+ const themeColors = chart.raw?.builtinThemeColors;
112
+ const paletteCount = Math.trunc((domain.safeMax - domain.minValue) / (domain.ticks[1] - domain.ticks[0])) + 1;
113
+ const builtinColor = themeColors ? resolveBuiltinChartColor(getBuiltinChartColor(chart.chartStyleId, bandIndex % paletteCount, paletteCount), themeColors) : void 0;
114
+ if (builtinColor) return builtinColor;
115
+ const stops = getSurfaceColorStops(chart, palette);
116
+ if (stops.length === 0) {
117
+ return resolveSurfaceBaseColor(chart, palette);
118
+ }
119
+ return stops[Math.min(stops.length - 1, Math.max(0, bandIndex))] ?? stops[stops.length - 1] ?? resolveSurfaceBaseColor(chart, palette);
120
+ }
121
+ function resolveSurfaceBandIndex(domain, value) {
122
+ const ticks = domain.ticks;
123
+ for (let index = 0; index < ticks.length - 1; index += 1) {
124
+ const end = ticks[index + 1] ?? domain.safeMax;
125
+ if (value <= end || index === ticks.length - 2) {
126
+ return index;
127
+ }
128
+ }
129
+ return Math.max(0, ticks.length - 2);
130
+ }
131
+ function resolveSurfaceBandColor(chart, palette, domain, value) {
132
+ return resolveSurfaceBandPaletteColor(chart, palette, domain, value);
133
+ }
134
+ function resolveSurfaceBandFormatColor(chart, key, index) {
135
+ const colors = chart.raw?.[key];
136
+ if (!colors || typeof colors !== "object" || !Object.prototype.hasOwnProperty.call(colors, index)) return null;
137
+ const color = colors[index];
138
+ return typeof color === "string" && color.length > 0 ? color : null;
139
+ }
140
+ function resolveSurfaceWireframeColor(chart, palette, domain, value) {
141
+ const bandIndex = resolveSurfaceBandIndex(domain, value);
142
+ const themeColors = chart.raw?.builtinThemeColors;
143
+ const paletteCount = Math.trunc((domain.safeMax - domain.minValue) / (domain.ticks[1] - domain.ticks[0])) + 1;
144
+ const builtinLine = themeColors ? resolveBuiltinChartColor(getBuiltinChartSurfaceLine(chart.chartStyleId, bandIndex, paletteCount), themeColors) : void 0;
145
+ return resolveSurfaceBandFormatColor(chart, "bandFormatLineColors", bandIndex) ?? resolveExplicitSurfaceSeriesColor(chart, "line") ?? builtinLine ?? resolveSurfaceBandPaletteColor(chart, palette, domain, value);
146
+ }
147
+ function colorToRgba(color, alpha = 1) {
148
+ if (color === "transparent") return [0, 0, 0, 0];
149
+ const rgb = parseRgbColor(color);
150
+ if (!rgb) {
151
+ return [0.1, 0.1, 0.1, alpha];
152
+ }
153
+ return [rgb.red / 255, rgb.green / 255, rgb.blue / 255, alpha];
154
+ }
155
+ function normalizeSurfaceX(column, cols) {
156
+ return cols <= 1 ? 0 : (column / (cols - 1) - 0.5) * 2;
157
+ }
158
+ function normalizeSurfaceY(row, rows) {
159
+ return rows <= 1 ? 0 : (row / (rows - 1) - 0.5) * 2;
160
+ }
161
+ function normalizeSurfaceZ(value, domain, heightExtent, axis) {
162
+ return -(normalizeSurfaceValue(value, domain.minValue, domain.safeMax, axis) - 0.5) * heightExtent;
163
+ }
164
+ function projectCartesian3dPoint(x, y, z, rotXRad, rotYRad, usePerspective, perspectiveStrength, rightAngleAxes) {
165
+ if (rightAngleAxes) {
166
+ return { depth: z, x: x + z * Math.sin(rotYRad), y: y - z * Math.sin(rotXRad) };
167
+ }
168
+ const cosX = Math.cos(rotXRad);
169
+ const sinX = Math.sin(rotXRad);
170
+ const cosY = Math.cos(rotYRad);
171
+ const sinY = Math.sin(rotYRad);
172
+ const x1 = x * cosY + z * sinY;
173
+ const z1 = -x * sinY + z * cosY;
174
+ const y1 = y * cosX - z1 * sinX;
175
+ const z2 = y * sinX + z1 * cosX;
176
+ const perspective = usePerspective ? 1 / Math.max(0.18, 1 + z2 * (0.24 + perspectiveStrength * 0.5)) : 1;
177
+ return {
178
+ depth: z2,
179
+ x: x1 * perspective,
180
+ y: y1 * perspective
181
+ };
182
+ }
183
+ function withProjectedDepth(point, depth) {
184
+ return {
185
+ ...point,
186
+ depth
187
+ };
188
+ }
189
+ function nudgeProjectedDepth(point, delta) {
190
+ return {
191
+ ...point,
192
+ depth: point.depth + delta
193
+ };
194
+ }
195
+ function isContourSurfaceChart(chart) {
196
+ const rawChartType = chart.raw && typeof chart.raw === "object" && typeof chart.raw.xmlChartType === "string" ? chart.raw.xmlChartType : "";
197
+ if (rawChartType === "surfaceChart") {
198
+ return true;
199
+ }
200
+ if (rawChartType === "surface3DChart") {
201
+ return false;
202
+ }
203
+ return chart.chartType === "Surface" && chart.is3d !== true;
204
+ }
205
+ function buildSurfaceMesh(chart, palette, layout) {
206
+ const rows = chart.series.length;
207
+ const cols = chart.series.reduce((max, series) => Math.max(max, series.values.length), 0);
208
+ if (rows < 2 || cols < 2) {
209
+ return null;
210
+ }
211
+ const matrix = chart.series.map((series) => Array.from({ length: cols }, (_, columnIndex) => safeNumber(series.values[columnIndex])));
212
+ const domain = getSurfaceDomain(chart);
213
+ if (!domain) {
214
+ return null;
215
+ }
216
+ const isContour = isContourSurfaceChart(chart);
217
+ const isWireframe = chart.wireframe === true;
218
+ const fillVertices = [];
219
+ const wallTriangles = [];
220
+ const contourLines = [];
221
+ const meshLines = [];
222
+ const rotX = (chart.view3d?.rotX ?? 25) * (Math.PI / 180);
223
+ const rotY = (chart.view3d?.rotY ?? 30) * (Math.PI / 180);
224
+ const usePerspective = !isContour && chart.view3d?.rAngAx === false;
225
+ const perspectiveStrength = clamp((chart.view3d?.perspective ?? (usePerspective ? 30 : 0)) / 100, 0, 1);
226
+ const ratios = surfaceDataRatios(rows, cols, chart.valueAxis?.crossBetween !== "midCat", chart.view3d?.heightPercent, chart.view3d?.depthPercent, layout);
227
+ const depthScale = ratios.depth;
228
+ const heightExtent = 2 * ratios.height;
229
+ const usesFlatMaterial = chart.surfaceMaterial === "flat";
230
+ const wallLineColor = chart.valueAxis?.majorGridlineColor ?? chart.backWall?.lineColor ?? chart.sideWall?.lineColor ?? chart.floor?.lineColor ?? chart.axisLineColor ?? "#a6a6a6";
231
+ const backWallFill = chart.backWall?.fillColor ?? "#d9d9df";
232
+ const sideWallFill = chart.sideWall?.fillColor ?? "#d5d7dc";
233
+ const floorFill = chart.floor?.fillColor ?? "#d0d2d8";
234
+ const projectPoint = (column, row, value) => {
235
+ const worldX = normalizeSurfaceX(column, cols);
236
+ if (isContour) {
237
+ return {
238
+ depth: 0,
239
+ worldX,
240
+ worldY: normalizeSurfaceY(row, rows),
241
+ worldZ: 0,
242
+ x: worldX,
243
+ y: normalizeSurfaceY(row, rows)
244
+ };
245
+ }
246
+ const worldY = normalizeSurfaceZ(value, domain, heightExtent, chart.valueAxis);
247
+ const worldZ = normalizeSurfaceY(row, rows) * depthScale;
248
+ const projected = projectCartesian3dPoint(worldX, worldY, worldZ, rotX, rotY, usePerspective, perspectiveStrength, chart.view3d?.rAngAx !== false);
249
+ return {
250
+ depth: projected.depth,
251
+ worldX,
252
+ worldY,
253
+ worldZ,
254
+ x: projected.x,
255
+ y: projected.y
256
+ };
257
+ };
258
+ const addWallQuad = (a, b, c, d, color) => {
259
+ wallTriangles.push(
260
+ { color, points: [a, b, c] },
261
+ { color, points: [a, c, d] }
262
+ );
263
+ };
264
+ const addMeshLine = (from, to, color) => {
265
+ meshLines.push({ color, from, to });
266
+ };
267
+ for (let rowIndex = 0; rowIndex < rows - 1; rowIndex += 1) {
268
+ for (let columnIndex = 0; columnIndex < cols - 1; columnIndex += 1) {
269
+ const p00 = matrix[rowIndex]?.[columnIndex];
270
+ const p10 = matrix[rowIndex]?.[columnIndex + 1];
271
+ const p01 = matrix[rowIndex + 1]?.[columnIndex];
272
+ const p11 = matrix[rowIndex + 1]?.[columnIndex + 1];
273
+ if (p00 == null || p10 == null || p01 == null || p11 == null) {
274
+ continue;
275
+ }
276
+ const triangles = triangulateSurfaceQuad([
277
+ { value: p00, x: columnIndex, y: rowIndex },
278
+ { value: p10, x: columnIndex + 1, y: rowIndex },
279
+ { value: p11, x: columnIndex + 1, y: rowIndex + 1 },
280
+ { value: p01, x: columnIndex, y: rowIndex + 1 }
281
+ ], chart.valueAxis);
282
+ for (const triangle of triangles) {
283
+ for (let band = 0; band < domain.ticks.length - 1; band += 1) {
284
+ const lower = domain.ticks[band];
285
+ const upper = domain.ticks[band + 1];
286
+ const polygon = clipSurfaceBand(clipSurfaceBand(triangle, lower, true, chart.valueAxis, band === 0), upper, false, chart.valueAxis);
287
+ if (polygon.length < 3) continue;
288
+ const bandColor = resolveSurfaceBandColor(chart, palette, domain, (lower + upper) / 2);
289
+ if (!isWireframe && bandColor !== "transparent") {
290
+ for (let index = 1; index < polygon.length - 1; index += 1) {
291
+ for (const vertex of [polygon[0], polygon[index], polygon[index + 1]]) {
292
+ const point = projectPoint(vertex.x, vertex.y, vertex.value);
293
+ fillVertices.push({ bandColor, point: isContour ? withProjectedDepth(point, 0.08) : point, value: vertex.value });
294
+ }
295
+ }
296
+ }
297
+ const color = resolveSurfaceWireframeColor(chart, palette, domain, (lower + upper) / 2);
298
+ if (color !== "transparent") {
299
+ for (const [from, to] of surfaceBandEdges(polygon, triangle)) {
300
+ contourLines.push({ color, from: projectPoint(from.x, from.y, from.value), to: projectPoint(to.x, to.y, to.value) });
301
+ }
302
+ }
303
+ }
304
+ }
305
+ }
306
+ }
307
+ const columnSkip = Math.max(1, chart.categoryAxis?.tickMarkSkip ?? 1);
308
+ const rowSkip = Math.max(1, chart.seriesAxis?.tickMarkSkip ?? 1);
309
+ if (isContour) {
310
+ const topLeft = withProjectedDepth(projectPoint(0, 0, domain.minValue), -0.12);
311
+ const topRight = withProjectedDepth(projectPoint(cols - 1, 0, domain.minValue), -0.12);
312
+ const bottomRight = withProjectedDepth(projectPoint(cols - 1, rows - 1, domain.minValue), -0.12);
313
+ const bottomLeft = withProjectedDepth(projectPoint(0, rows - 1, domain.minValue), -0.12);
314
+ if (chart.backWall?.hidden !== true && backWallFill !== "transparent") {
315
+ addWallQuad(topLeft, topRight, bottomRight, bottomLeft, backWallFill);
316
+ }
317
+ for (let columnIndex = 0; columnIndex < cols; columnIndex += columnSkip) {
318
+ addMeshLine(
319
+ withProjectedDepth(projectPoint(columnIndex, 0, domain.minValue), 0.04),
320
+ withProjectedDepth(projectPoint(columnIndex, rows - 1, domain.minValue), 0.04),
321
+ wallLineColor
322
+ );
323
+ }
324
+ for (let rowIndex = 0; rowIndex < rows; rowIndex += rowSkip) {
325
+ addMeshLine(
326
+ withProjectedDepth(projectPoint(0, rowIndex, domain.minValue), 0.04),
327
+ withProjectedDepth(projectPoint(cols - 1, rowIndex, domain.minValue), 0.04),
328
+ wallLineColor
329
+ );
330
+ }
331
+ } else {
332
+ const minPlaneValue = domain.minValue;
333
+ const wallDepthOffset = 0;
334
+ const backRow = chart.view3d?.rAngAx !== false || Math.cos(rotX) * Math.cos(rotY) >= 0 ? rows - 1 : 0;
335
+ const sideColumn = Math.sin(rotY) >= 0 ? 0 : cols - 1;
336
+ if (chart.floor?.hidden !== true && floorFill !== "transparent") {
337
+ addWallQuad(
338
+ nudgeProjectedDepth(projectPoint(0, 0, minPlaneValue), wallDepthOffset),
339
+ nudgeProjectedDepth(projectPoint(cols - 1, 0, minPlaneValue), wallDepthOffset),
340
+ nudgeProjectedDepth(projectPoint(cols - 1, rows - 1, minPlaneValue), wallDepthOffset),
341
+ nudgeProjectedDepth(projectPoint(0, rows - 1, minPlaneValue), wallDepthOffset),
342
+ floorFill
343
+ );
344
+ }
345
+ if (chart.backWall?.hidden !== true && backWallFill !== "transparent") {
346
+ addWallQuad(
347
+ nudgeProjectedDepth(projectPoint(0, backRow, domain.safeMax), wallDepthOffset),
348
+ nudgeProjectedDepth(projectPoint(cols - 1, backRow, domain.safeMax), wallDepthOffset),
349
+ nudgeProjectedDepth(projectPoint(cols - 1, backRow, minPlaneValue), wallDepthOffset),
350
+ nudgeProjectedDepth(projectPoint(0, backRow, minPlaneValue), wallDepthOffset),
351
+ backWallFill
352
+ );
353
+ }
354
+ if (chart.sideWall?.hidden !== true && sideWallFill !== "transparent") {
355
+ addWallQuad(
356
+ nudgeProjectedDepth(projectPoint(sideColumn, 0, domain.safeMax), wallDepthOffset),
357
+ nudgeProjectedDepth(projectPoint(sideColumn, rows - 1, domain.safeMax), wallDepthOffset),
358
+ nudgeProjectedDepth(projectPoint(sideColumn, rows - 1, minPlaneValue), wallDepthOffset),
359
+ nudgeProjectedDepth(projectPoint(sideColumn, 0, minPlaneValue), wallDepthOffset),
360
+ sideWallFill
361
+ );
362
+ }
363
+ for (const tick of chart.valueAxis?.majorGridlines ? domain.ticks : []) {
364
+ if (chart.backWall?.hidden !== true && wallLineColor !== "transparent") {
365
+ addMeshLine(nudgeProjectedDepth(projectPoint(0, backRow, tick), wallDepthOffset * 0.75), nudgeProjectedDepth(projectPoint(cols - 1, backRow, tick), wallDepthOffset * 0.75), wallLineColor);
366
+ }
367
+ if (chart.sideWall?.hidden !== true && wallLineColor !== "transparent") {
368
+ addMeshLine(nudgeProjectedDepth(projectPoint(sideColumn, 0, tick), wallDepthOffset * 0.75), nudgeProjectedDepth(projectPoint(sideColumn, rows - 1, tick), wallDepthOffset * 0.75), wallLineColor);
369
+ }
370
+ }
371
+ for (let columnIndex = 0; chart.categoryAxis?.majorGridlines && columnIndex < cols; columnIndex += columnSkip) {
372
+ if (chart.floor?.hidden !== true && wallLineColor !== "transparent") {
373
+ addMeshLine(nudgeProjectedDepth(projectPoint(columnIndex, 0, minPlaneValue), wallDepthOffset * 0.75), nudgeProjectedDepth(projectPoint(columnIndex, rows - 1, minPlaneValue), wallDepthOffset * 0.75), wallLineColor);
374
+ }
375
+ if (chart.backWall?.hidden !== true && wallLineColor !== "transparent") {
376
+ addMeshLine(nudgeProjectedDepth(projectPoint(columnIndex, backRow, minPlaneValue), wallDepthOffset * 0.75), nudgeProjectedDepth(projectPoint(columnIndex, backRow, domain.safeMax), wallDepthOffset * 0.75), wallLineColor);
377
+ }
378
+ }
379
+ for (let rowIndex = 0; chart.seriesAxis?.majorGridlines && rowIndex < rows; rowIndex += rowSkip) {
380
+ if (chart.floor?.hidden !== true && wallLineColor !== "transparent") {
381
+ addMeshLine(nudgeProjectedDepth(projectPoint(0, rowIndex, minPlaneValue), wallDepthOffset * 0.75), nudgeProjectedDepth(projectPoint(cols - 1, rowIndex, minPlaneValue), wallDepthOffset * 0.75), wallLineColor);
382
+ }
383
+ if (chart.sideWall?.hidden !== true && wallLineColor !== "transparent") {
384
+ addMeshLine(nudgeProjectedDepth(projectPoint(sideColumn, rowIndex, minPlaneValue), wallDepthOffset * 0.75), nudgeProjectedDepth(projectPoint(sideColumn, rowIndex, domain.safeMax), wallDepthOffset * 0.75), wallLineColor);
385
+ }
386
+ }
387
+ }
388
+ const allPoints = [
389
+ ...fillVertices.map((vertex) => vertex.point),
390
+ ...wallTriangles.flatMap((triangle) => triangle.points),
391
+ ...meshLines.flatMap((line) => [line.from, line.to]),
392
+ ...contourLines.flatMap((line) => [line.from, line.to])
393
+ ];
394
+ if (allPoints.length === 0) {
395
+ return null;
396
+ }
397
+ const minX = Math.min(...allPoints.map((point) => point.x));
398
+ const maxX = Math.max(...allPoints.map((point) => point.x));
399
+ const minY = Math.min(...allPoints.map((point) => point.y));
400
+ const maxY = Math.max(...allPoints.map((point) => point.y));
401
+ const minDepth = Math.min(...allPoints.map((point) => point.depth));
402
+ const maxDepth = Math.max(...allPoints.map((point) => point.depth));
403
+ const scale = Math.min(
404
+ layout.plot.width / Math.max(0.25, maxX - minX),
405
+ layout.plot.height / Math.max(0.25, maxY - minY)
406
+ );
407
+ const centerX = layout.plot.left + layout.plot.width / 2;
408
+ const centerY = layout.plot.top + layout.plot.height / 2;
409
+ const centerRawX = (minX + maxX) / 2;
410
+ const centerRawY = (minY + maxY) / 2;
411
+ const toScreenX = (x) => centerX + (x - centerRawX) * scale;
412
+ const toScreenY = (y) => centerY + (y - centerRawY) * scale;
413
+ const toClipPoint = (point) => {
414
+ const screenX = toScreenX(point.x);
415
+ const screenY = toScreenY(point.y);
416
+ return {
417
+ x: screenX / layout.width * 2 - 1,
418
+ y: 1 - screenY / layout.height * 2,
419
+ z: clamp((point.depth - minDepth) / Math.max(1e-6, maxDepth - minDepth) * 2 - 1, -1, 1)
420
+ };
421
+ };
422
+ const fillPositions = [];
423
+ const fillColors = [];
424
+ const wallPositions = [];
425
+ const wallColors = [];
426
+ for (const triangle of wallTriangles) {
427
+ const world = triangle.points.map((point) => ({ x: point.worldX, y: point.worldY, z: -point.worldZ }));
428
+ const normal = transformSurfaceNormal(surfaceNormal(world[0], world[1], world[2]), chart.view3d?.rotX ?? 25, chart.view3d?.rotY ?? 30, chart.view3d?.rAngAx !== false);
429
+ const rgba = colorToRgba(usesFlatMaterial ? triangle.color : shadeSurfaceMatteColor(triangle.color, normal), 1);
430
+ for (const point of triangle.points) {
431
+ const clip = toClipPoint(point);
432
+ wallPositions.push(clip.x, clip.y, clip.z);
433
+ wallColors.push(rgba[0], rgba[1], rgba[2], rgba[3]);
434
+ }
435
+ }
436
+ for (let index = 0; index < fillVertices.length; index += 3) {
437
+ const left = fillVertices[index];
438
+ const middle = fillVertices[index + 1];
439
+ const right = fillVertices[index + 2];
440
+ if (!left || !middle || !right) {
441
+ continue;
442
+ }
443
+ const world = [left, middle, right].map((vertex) => ({ x: vertex.point.worldX, y: vertex.point.worldY, z: -vertex.point.worldZ }));
444
+ const normal = transformSurfaceNormal(surfaceNormal(world[0], world[1], world[2]), chart.view3d?.rotX ?? 25, chart.view3d?.rotY ?? 30, chart.view3d?.rAngAx !== false);
445
+ const shaded = colorToRgba(usesFlatMaterial ? left.bandColor : shadeSurfaceMatteColor(left.bandColor, normal), 1);
446
+ [left, middle, right].forEach((vertex) => {
447
+ const clip = toClipPoint(vertex.point);
448
+ fillPositions.push(clip.x, clip.y, clip.z);
449
+ fillColors.push(shaded[0], shaded[1], shaded[2], shaded[3]);
450
+ });
451
+ }
452
+ const linePositions = [];
453
+ const lineColors = [];
454
+ meshLines.forEach((line) => {
455
+ const from = toClipPoint(line.from);
456
+ const to = toClipPoint(line.to);
457
+ const rgba = colorToRgba(line.color, 1);
458
+ linePositions.push(from.x, from.y, from.z - 1e-5, to.x, to.y, to.z - 1e-5);
459
+ lineColors.push(rgba[0], rgba[1], rgba[2], rgba[3], rgba[0], rgba[1], rgba[2], rgba[3]);
460
+ });
461
+ contourLines.forEach((line) => {
462
+ const from = toClipPoint(line.from);
463
+ const to = toClipPoint(line.to);
464
+ const rgba = colorToRgba(line.color, 1);
465
+ linePositions.push(from.x, from.y, from.z - 1e-5, to.x, to.y, to.z - 1e-5);
466
+ lineColors.push(rgba[0], rgba[1], rgba[2], rgba[3], rgba[0], rgba[1], rgba[2], rgba[3]);
467
+ });
468
+ return {
469
+ fillColors: new Float32Array(fillColors),
470
+ fillPositions: new Float32Array(fillPositions),
471
+ lineColors: new Float32Array(lineColors),
472
+ linePositions: new Float32Array(linePositions),
473
+ wallColors: new Float32Array(wallColors),
474
+ wallPositions: new Float32Array(wallPositions)
475
+ };
476
+ }
477
+ var MemoSurfaceChartComposite = React.memo(function MemoSurfaceChartComposite2({
478
+ background,
479
+ borderColor,
480
+ chart,
481
+ fontFamily,
482
+ layout,
483
+ onDoubleClick,
484
+ onPointerDown,
485
+ overlay,
486
+ palette,
487
+ fallback
488
+ }) {
489
+ const canvasRef = React.useRef(null);
490
+ const [ready, setReady] = React.useState(false);
491
+ const [failed, setFailed] = React.useState(false);
492
+ const isContour = isContourSurfaceChart(chart);
493
+ React.useEffect(() => {
494
+ if (isContour) {
495
+ setReady(false);
496
+ setFailed(false);
497
+ return;
498
+ }
499
+ const canvas = canvasRef.current;
500
+ if (!canvas) {
501
+ return;
502
+ }
503
+ let cancelled = false;
504
+ let reglInstance = null;
505
+ const drawSurface = () => {
506
+ try {
507
+ const scene = buildSurfaceMesh(chart, palette, layout);
508
+ if (!scene) {
509
+ if (!cancelled) {
510
+ setFailed(true);
511
+ setReady(false);
512
+ }
513
+ return;
514
+ }
515
+ const dpr = window.devicePixelRatio || 1;
516
+ canvas.width = Math.max(1, Math.round(layout.width * dpr));
517
+ canvas.height = Math.max(1, Math.round(layout.height * dpr));
518
+ reglInstance = createREGL({
519
+ attributes: {
520
+ alpha: true,
521
+ antialias: true,
522
+ depth: true,
523
+ premultipliedAlpha: true
524
+ },
525
+ canvas
526
+ });
527
+ const fillCommand = scene.fillPositions.length > 0 ? reglInstance({
528
+ attributes: {
529
+ color: scene.fillColors,
530
+ position: scene.fillPositions
531
+ },
532
+ blend: {
533
+ enable: true,
534
+ func: {
535
+ dstRGB: "one minus src alpha",
536
+ dstAlpha: "one minus src alpha",
537
+ srcRGB: "src alpha",
538
+ srcAlpha: "src alpha"
539
+ }
540
+ },
541
+ count: scene.fillPositions.length / 3,
542
+ depth: {
543
+ enable: true
544
+ },
545
+ frag: `
546
+ precision mediump float;
547
+ varying vec4 vColor;
548
+ void main() {
549
+ gl_FragColor = vColor;
550
+ }
551
+ `,
552
+ primitive: "triangles",
553
+ vert: `
554
+ precision mediump float;
555
+ attribute vec3 position;
556
+ attribute vec4 color;
557
+ varying vec4 vColor;
558
+ void main() {
559
+ gl_Position = vec4(position, 1.0);
560
+ vColor = color;
561
+ }
562
+ `
563
+ }) : null;
564
+ const wallCommand = scene.wallPositions.length > 0 ? reglInstance({
565
+ attributes: {
566
+ color: scene.wallColors,
567
+ position: scene.wallPositions
568
+ },
569
+ blend: {
570
+ enable: true,
571
+ func: {
572
+ dstRGB: "one minus src alpha",
573
+ dstAlpha: "one minus src alpha",
574
+ srcRGB: "src alpha",
575
+ srcAlpha: "src alpha"
576
+ }
577
+ },
578
+ count: scene.wallPositions.length / 3,
579
+ depth: {
580
+ enable: true,
581
+ func: "lequal"
582
+ },
583
+ frag: `
584
+ precision mediump float;
585
+ varying vec4 vColor;
586
+ void main() {
587
+ gl_FragColor = vColor;
588
+ }
589
+ `,
590
+ primitive: "triangles",
591
+ vert: `
592
+ precision mediump float;
593
+ attribute vec3 position;
594
+ attribute vec4 color;
595
+ varying vec4 vColor;
596
+ void main() {
597
+ gl_Position = vec4(position, 1.0);
598
+ vColor = color;
599
+ }
600
+ `
601
+ }) : null;
602
+ const lineCommand = scene.linePositions.length > 0 ? reglInstance({
603
+ attributes: {
604
+ color: scene.lineColors,
605
+ position: scene.linePositions
606
+ },
607
+ blend: {
608
+ enable: true,
609
+ func: {
610
+ dstRGB: "one minus src alpha",
611
+ dstAlpha: "one minus src alpha",
612
+ srcRGB: "src alpha",
613
+ srcAlpha: "src alpha"
614
+ }
615
+ },
616
+ count: scene.linePositions.length / 3,
617
+ depth: {
618
+ enable: true,
619
+ func: "lequal"
620
+ },
621
+ frag: `
622
+ precision mediump float;
623
+ varying vec4 vColor;
624
+ void main() {
625
+ gl_FragColor = vColor;
626
+ }
627
+ `,
628
+ lineWidth: 1,
629
+ primitive: "lines",
630
+ vert: `
631
+ precision mediump float;
632
+ attribute vec3 position;
633
+ attribute vec4 color;
634
+ varying vec4 vColor;
635
+ void main() {
636
+ gl_Position = vec4(position, 1.0);
637
+ vColor = color;
638
+ }
639
+ `
640
+ }) : null;
641
+ reglInstance.clear({ color: [0, 0, 0, 0], depth: 1 });
642
+ wallCommand?.();
643
+ fillCommand?.();
644
+ lineCommand?.();
645
+ if (!cancelled) {
646
+ setReady(true);
647
+ setFailed(false);
648
+ }
649
+ } catch {
650
+ if (!cancelled) {
651
+ setReady(false);
652
+ setFailed(true);
653
+ }
654
+ }
655
+ };
656
+ setReady(false);
657
+ setFailed(false);
658
+ drawSurface();
659
+ return () => {
660
+ cancelled = true;
661
+ reglInstance?.destroy();
662
+ };
663
+ }, [
664
+ chart,
665
+ isContour,
666
+ layout,
667
+ palette
668
+ ]);
669
+ const shouldRenderFallback = isContour || failed || !ready;
670
+ return /* @__PURE__ */ jsxs(
671
+ "div",
672
+ {
673
+ "aria-label": chart.title ?? chart.name ?? "Chart",
674
+ role: "img",
675
+ style: {
676
+ background,
677
+ border: borderColor.trim().toLowerCase() === "transparent" ? "none" : `1px solid ${borderColor}`,
678
+ boxSizing: "border-box",
679
+ fontFamily,
680
+ height: "100%",
681
+ overflow: "hidden",
682
+ pointerEvents: "auto",
683
+ position: "relative",
684
+ width: "100%"
685
+ },
686
+ children: [
687
+ /* @__PURE__ */ jsx(
688
+ "canvas",
689
+ {
690
+ ref: canvasRef,
691
+ style: {
692
+ display: shouldRenderFallback ? "none" : "block",
693
+ height: "100%",
694
+ inset: 0,
695
+ position: "absolute",
696
+ width: "100%"
697
+ }
698
+ }
699
+ ),
700
+ /* @__PURE__ */ jsxs(
701
+ "svg",
702
+ {
703
+ onDoubleClick,
704
+ onPointerDown,
705
+ style: { display: "block", height: "100%", inset: 0, position: "absolute", width: "100%" },
706
+ viewBox: `0 0 ${layout.width} ${layout.height}`,
707
+ children: [
708
+ shouldRenderFallback ? fallback : null,
709
+ overlay
710
+ ]
711
+ }
712
+ )
713
+ ]
714
+ }
715
+ );
716
+ }, (prev, next) => prev.chart === next.chart && prev.palette === next.palette && prev.background === next.background && prev.borderColor === next.borderColor && prev.fontFamily === next.fontFamily && prev.onDoubleClick === next.onDoubleClick && prev.onPointerDown === next.onPointerDown && prev.layout.width === next.layout.width && prev.layout.height === next.layout.height && prev.layout.plot.left === next.layout.plot.left && prev.layout.plot.top === next.layout.plot.top && prev.layout.plot.width === next.layout.plot.width && prev.layout.plot.height === next.layout.plot.height && prev.overlay === next.overlay && prev.fallback === next.fallback);
717
+ export {
718
+ MemoSurfaceChartComposite
719
+ };
720
+ //# sourceMappingURL=surface-regl-NWR5ZZ5D.js.map