@mui/x-charts-premium 9.7.0 → 9.8.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 (100) hide show
  1. package/BarChartPremium/webgl/BarWebGLProgram.d.mts +4 -5
  2. package/BarChartPremium/webgl/BarWebGLProgram.d.ts +4 -5
  3. package/BarChartPremium/webgl/BarWebGLProgram.js +24 -65
  4. package/BarChartPremium/webgl/BarWebGLProgram.mjs +24 -65
  5. package/BarChartPremium/webgl/shaders.d.mts +1 -1
  6. package/BarChartPremium/webgl/shaders.d.ts +1 -1
  7. package/BarChartPremium/webgl/shaders.js +2 -15
  8. package/BarChartPremium/webgl/shaders.mjs +3 -15
  9. package/CHANGELOG.md +130 -1
  10. package/ChartsDataProviderPremium/ChartsDataProviderPremium.js +2 -2
  11. package/ChartsDataProviderPremium/ChartsDataProviderPremium.mjs +2 -2
  12. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.js +2 -2
  13. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.mjs +2 -2
  14. package/ChartsRadialDataProviderPremium/ChartsRadialDataProviderPremium.js +2 -2
  15. package/ChartsRadialDataProviderPremium/ChartsRadialDataProviderPremium.mjs +2 -2
  16. package/HeatmapPremium/webgl/HeatmapWebGLProgram.js +12 -37
  17. package/HeatmapPremium/webgl/HeatmapWebGLProgram.mjs +12 -37
  18. package/HeatmapPremium/webgl/shaders.d.mts +3 -3
  19. package/HeatmapPremium/webgl/shaders.d.ts +3 -3
  20. package/HeatmapPremium/webgl/shaders.js +12 -15
  21. package/HeatmapPremium/webgl/shaders.mjs +13 -15
  22. package/HeatmapPremium/webgl/useHeatmapPlotData.js +3 -8
  23. package/HeatmapPremium/webgl/useHeatmapPlotData.mjs +3 -8
  24. package/Map/FocusedMapShape.js +5 -1
  25. package/Map/FocusedMapShape.mjs +5 -1
  26. package/Map/MapImagePlot.d.mts +39 -0
  27. package/Map/MapImagePlot.d.ts +39 -0
  28. package/Map/MapImagePlot.js +138 -0
  29. package/Map/MapImagePlot.mjs +132 -0
  30. package/Map/MapShape.d.mts +1 -1
  31. package/Map/MapShape.d.ts +1 -1
  32. package/Map/MapShape.js +6 -6
  33. package/Map/MapShape.mjs +6 -6
  34. package/Map/MapShapePlot.d.mts +8 -0
  35. package/Map/MapShapePlot.d.ts +8 -0
  36. package/Map/MapShapePlot.js +17 -5
  37. package/Map/MapShapePlot.mjs +17 -5
  38. package/Map/index.d.mts +1 -0
  39. package/Map/index.d.ts +1 -0
  40. package/Map/index.js +11 -0
  41. package/Map/index.mjs +1 -0
  42. package/Map/reprojectEquirectangularImage.d.mts +60 -0
  43. package/Map/reprojectEquirectangularImage.d.ts +60 -0
  44. package/Map/reprojectEquirectangularImage.js +116 -0
  45. package/Map/reprojectEquirectangularImage.mjs +110 -0
  46. package/Map/seriesConfig/descriptionGetter.js +5 -1
  47. package/Map/seriesConfig/descriptionGetter.mjs +5 -1
  48. package/Map/seriesConfig/getColor.js +18 -6
  49. package/Map/seriesConfig/getColor.mjs +18 -6
  50. package/Map/seriesConfig/highlight.d.mts +10 -0
  51. package/Map/seriesConfig/highlight.d.ts +10 -0
  52. package/Map/seriesConfig/highlight.js +52 -0
  53. package/Map/seriesConfig/highlight.mjs +45 -0
  54. package/Map/seriesConfig/identifierCleaner.d.mts +3 -0
  55. package/Map/seriesConfig/identifierCleaner.d.ts +3 -0
  56. package/Map/seriesConfig/identifierCleaner.js +14 -0
  57. package/Map/seriesConfig/identifierCleaner.mjs +8 -0
  58. package/Map/seriesConfig/identifierSerializer.d.mts +3 -0
  59. package/Map/seriesConfig/identifierSerializer.d.ts +3 -0
  60. package/Map/seriesConfig/identifierSerializer.js +12 -0
  61. package/Map/seriesConfig/identifierSerializer.mjs +6 -0
  62. package/Map/seriesConfig/index.js +8 -6
  63. package/Map/seriesConfig/index.mjs +7 -5
  64. package/Map/seriesConfig/keyboardFocusHandler.d.mts +0 -6
  65. package/Map/seriesConfig/keyboardFocusHandler.d.ts +0 -6
  66. package/Map/seriesConfig/keyboardFocusHandler.js +40 -7
  67. package/Map/seriesConfig/keyboardFocusHandler.mjs +41 -8
  68. package/Map/seriesConfig/seriesProcessor.js +11 -2
  69. package/Map/seriesConfig/seriesProcessor.mjs +11 -2
  70. package/Map/seriesConfig/tooltip.js +8 -4
  71. package/Map/seriesConfig/tooltip.mjs +8 -4
  72. package/Map/seriesConfig/tooltipPosition.d.mts +8 -3
  73. package/Map/seriesConfig/tooltipPosition.d.ts +8 -3
  74. package/Map/seriesConfig/tooltipPosition.js +21 -27
  75. package/Map/seriesConfig/tooltipPosition.mjs +22 -27
  76. package/ScatterChartPremium/webgl/ScatterWebGLProgram.d.mts +0 -2
  77. package/ScatterChartPremium/webgl/ScatterWebGLProgram.d.ts +0 -2
  78. package/ScatterChartPremium/webgl/ScatterWebGLProgram.js +23 -81
  79. package/ScatterChartPremium/webgl/ScatterWebGLProgram.mjs +23 -81
  80. package/index.js +1 -1
  81. package/index.mjs +1 -1
  82. package/internals/createGetVisibleCoordinate.d.mts +14 -0
  83. package/internals/createGetVisibleCoordinate.d.ts +14 -0
  84. package/internals/createGetVisibleCoordinate.js +66 -0
  85. package/internals/createGetVisibleCoordinate.mjs +60 -0
  86. package/models/seriesType/mapShape.d.mts +2 -1
  87. package/models/seriesType/mapShape.d.ts +2 -1
  88. package/package.json +5 -5
  89. package/utils/webgl/glsl.d.mts +15 -0
  90. package/utils/webgl/glsl.d.ts +15 -0
  91. package/utils/webgl/glsl.js +34 -0
  92. package/utils/webgl/glsl.mjs +28 -0
  93. package/utils/webgl/instancedAttribute.d.mts +28 -0
  94. package/utils/webgl/instancedAttribute.d.ts +28 -0
  95. package/utils/webgl/instancedAttribute.js +57 -0
  96. package/utils/webgl/instancedAttribute.mjs +50 -0
  97. package/utils/webgl/utils.d.mts +21 -2
  98. package/utils/webgl/utils.d.ts +21 -2
  99. package/utils/webgl/utils.js +44 -8
  100. package/utils/webgl/utils.mjs +41 -7
@@ -0,0 +1,60 @@
1
+ // A `GeoStream` sink that only records whether a point passed through (and where),
2
+ // so a projection/clip pipeline can be probed one point at a time.
3
+
4
+ function createPointSink() {
5
+ const sink = {
6
+ hit: false,
7
+ x: 0,
8
+ y: 0,
9
+ point(x, y) {
10
+ sink.hit = true;
11
+ sink.x = x;
12
+ sink.y = y;
13
+ },
14
+ lineStart() {},
15
+ lineEnd() {},
16
+ polygonStart() {},
17
+ polygonEnd() {}
18
+ };
19
+ return sink;
20
+ }
21
+
22
+ /**
23
+ * Builds a test that maps a device pixel to its `[lon, lat]`, or `null` when the
24
+ * pixel is not part of the visible map. It combines two clips that `projection.invert`
25
+ * alone misses:
26
+ *
27
+ * - the **post-clip** (cartesian) stream rejects device pixels outside the clip
28
+ * rectangle — relevant once the map is panned/zoomed with a `clipExtent`;
29
+ * - streaming the inverted coordinate **back** through the projection applies the
30
+ * pre-clip (spherical) boundary and checks the round trip: azimuthal projections
31
+ * clamp `invert` outside the visible disk to the limb, and those clamped points do
32
+ * not project back to the pixel they came from.
33
+ */
34
+ export function createGetVisibleCoordinate(projection) {
35
+ const invert = projection.invert;
36
+ const forwardSink = createPointSink();
37
+ const forwardStream = projection.stream(forwardSink);
38
+ const postClip = projection.postclip?.();
39
+ const clipSink = createPointSink();
40
+ const clipStream = postClip?.(clipSink);
41
+ return ([deviceX, deviceY]) => {
42
+ if (clipStream) {
43
+ clipSink.hit = false;
44
+ clipStream.point(deviceX, deviceY);
45
+ if (!clipSink.hit) {
46
+ return null;
47
+ }
48
+ }
49
+ const coordinates = invert([deviceX, deviceY]);
50
+ if (!coordinates) {
51
+ return null;
52
+ }
53
+ forwardSink.hit = false;
54
+ forwardStream.point(coordinates[0], coordinates[1]);
55
+ if (!forwardSink.hit || Math.abs(forwardSink.x - deviceX) > 0.5 || Math.abs(forwardSink.y - deviceY) > 0.5) {
56
+ return null;
57
+ }
58
+ return coordinates;
59
+ };
60
+ }
@@ -94,7 +94,7 @@ export interface MapShapeSeriesType extends Omit<CommonSeriesType<'mapShape'>, '
94
94
  export type MapShapeItemIdentifier = {
95
95
  type: 'mapShape';
96
96
  seriesId: SeriesId;
97
- dataIndex: number;
97
+ name: string;
98
98
  };
99
99
  export type DefaultizedMapShapeValueType = MapShapeValueType & {
100
100
  hidden: boolean;
@@ -102,4 +102,5 @@ export type DefaultizedMapShapeValueType = MapShapeValueType & {
102
102
  export interface DefaultizedMapShapeSeriesType extends Omit<DefaultizedProps<MapShapeSeriesType, CommonDefaultizedProps | 'color'>, 'data'> {
103
103
  hidden: boolean;
104
104
  data: ReadonlyArray<DefaultizedMapShapeValueType>;
105
+ lookupByName: ReadonlyMap<string, number>;
105
106
  }
@@ -94,7 +94,7 @@ export interface MapShapeSeriesType extends Omit<CommonSeriesType<'mapShape'>, '
94
94
  export type MapShapeItemIdentifier = {
95
95
  type: 'mapShape';
96
96
  seriesId: SeriesId;
97
- dataIndex: number;
97
+ name: string;
98
98
  };
99
99
  export type DefaultizedMapShapeValueType = MapShapeValueType & {
100
100
  hidden: boolean;
@@ -102,4 +102,5 @@ export type DefaultizedMapShapeValueType = MapShapeValueType & {
102
102
  export interface DefaultizedMapShapeSeriesType extends Omit<DefaultizedProps<MapShapeSeriesType, CommonDefaultizedProps | 'color'>, 'data'> {
103
103
  hidden: boolean;
104
104
  data: ReadonlyArray<DefaultizedMapShapeValueType>;
105
+ lookupByName: ReadonlyMap<string, number>;
105
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts-premium",
3
- "version": "9.7.0",
3
+ "version": "9.8.0",
4
4
  "author": "MUI Team",
5
5
  "description": "The Premium plan edition of the MUI X Charts components.",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -31,11 +31,11 @@
31
31
  "@mui/utils": "^9.1.1",
32
32
  "clsx": "^2.1.1",
33
33
  "prop-types": "^15.8.1",
34
- "@mui/x-charts": "^9.7.0",
35
- "@mui/x-charts-pro": "^9.7.0",
36
34
  "@mui/x-charts-vendor": "^9.4.0",
37
- "@mui/x-license": "^9.7.0",
38
- "@mui/x-internals": "^9.7.0"
35
+ "@mui/x-internals": "^9.8.0",
36
+ "@mui/x-license": "^9.8.0",
37
+ "@mui/x-charts": "^9.8.0",
38
+ "@mui/x-charts-pro": "^9.8.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@emotion/react": "^11.9.0",
@@ -0,0 +1,15 @@
1
+ /**
2
+ * GLSL snippet: signed distance field for a rounded box with per-corner radii.
3
+ *
4
+ * Convention:
5
+ * - `pos` and `halfSize` are in the same pixel-space coordinates.
6
+ * - `r` carries corner radii in CSS order: top-left, top-right, bottom-right, bottom-left.
7
+ * - For uniform-radius use cases pass `vec4(scalar)`.
8
+ *
9
+ * Screen-space conventions (after the y-flip in the vertex stage):
10
+ * pos.y < 0 -> top, pos.y > 0 -> bottom
11
+ * pos.x < 0 -> left, pos.x > 0 -> right
12
+ *
13
+ * Reference: Inigo Quilez, "Distance to a rounded box".
14
+ */
15
+ export declare const ROUNDED_BOX_SDF_GLSL = "\n float roundedBoxSDF(vec2 pos, vec2 halfSize, vec4 r) {\n float radius;\n if (pos.x < 0.0) {\n radius = pos.y < 0.0 ? r.x : r.w;\n } else {\n radius = pos.y < 0.0 ? r.y : r.z;\n }\n\n vec2 q = abs(pos) - halfSize + radius;\n return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - radius;\n }\n ";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * GLSL snippet: signed distance field for a rounded box with per-corner radii.
3
+ *
4
+ * Convention:
5
+ * - `pos` and `halfSize` are in the same pixel-space coordinates.
6
+ * - `r` carries corner radii in CSS order: top-left, top-right, bottom-right, bottom-left.
7
+ * - For uniform-radius use cases pass `vec4(scalar)`.
8
+ *
9
+ * Screen-space conventions (after the y-flip in the vertex stage):
10
+ * pos.y < 0 -> top, pos.y > 0 -> bottom
11
+ * pos.x < 0 -> left, pos.x > 0 -> right
12
+ *
13
+ * Reference: Inigo Quilez, "Distance to a rounded box".
14
+ */
15
+ export declare const ROUNDED_BOX_SDF_GLSL = "\n float roundedBoxSDF(vec2 pos, vec2 halfSize, vec4 r) {\n float radius;\n if (pos.x < 0.0) {\n radius = pos.y < 0.0 ? r.x : r.w;\n } else {\n radius = pos.y < 0.0 ? r.y : r.z;\n }\n\n vec2 q = abs(pos) - halfSize + radius;\n return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - radius;\n }\n ";
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ROUNDED_BOX_SDF_GLSL = void 0;
7
+ /**
8
+ * GLSL snippet: signed distance field for a rounded box with per-corner radii.
9
+ *
10
+ * Convention:
11
+ * - `pos` and `halfSize` are in the same pixel-space coordinates.
12
+ * - `r` carries corner radii in CSS order: top-left, top-right, bottom-right, bottom-left.
13
+ * - For uniform-radius use cases pass `vec4(scalar)`.
14
+ *
15
+ * Screen-space conventions (after the y-flip in the vertex stage):
16
+ * pos.y < 0 -> top, pos.y > 0 -> bottom
17
+ * pos.x < 0 -> left, pos.x > 0 -> right
18
+ *
19
+ * Reference: Inigo Quilez, "Distance to a rounded box".
20
+ */
21
+ // language=Glsl
22
+ const ROUNDED_BOX_SDF_GLSL = exports.ROUNDED_BOX_SDF_GLSL = /* glsl */`
23
+ float roundedBoxSDF(vec2 pos, vec2 halfSize, vec4 r) {
24
+ float radius;
25
+ if (pos.x < 0.0) {
26
+ radius = pos.y < 0.0 ? r.x : r.w;
27
+ } else {
28
+ radius = pos.y < 0.0 ? r.y : r.z;
29
+ }
30
+
31
+ vec2 q = abs(pos) - halfSize + radius;
32
+ return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - radius;
33
+ }
34
+ `;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * GLSL snippet: signed distance field for a rounded box with per-corner radii.
3
+ *
4
+ * Convention:
5
+ * - `pos` and `halfSize` are in the same pixel-space coordinates.
6
+ * - `r` carries corner radii in CSS order: top-left, top-right, bottom-right, bottom-left.
7
+ * - For uniform-radius use cases pass `vec4(scalar)`.
8
+ *
9
+ * Screen-space conventions (after the y-flip in the vertex stage):
10
+ * pos.y < 0 -> top, pos.y > 0 -> bottom
11
+ * pos.x < 0 -> left, pos.x > 0 -> right
12
+ *
13
+ * Reference: Inigo Quilez, "Distance to a rounded box".
14
+ */
15
+ // language=Glsl
16
+ export const ROUNDED_BOX_SDF_GLSL = /* glsl */`
17
+ float roundedBoxSDF(vec2 pos, vec2 halfSize, vec4 r) {
18
+ float radius;
19
+ if (pos.x < 0.0) {
20
+ radius = pos.y < 0.0 ? r.x : r.w;
21
+ } else {
22
+ radius = pos.y < 0.0 ? r.y : r.z;
23
+ }
24
+
25
+ vec2 q = abs(pos) - halfSize + radius;
26
+ return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - radius;
27
+ }
28
+ `;
@@ -0,0 +1,28 @@
1
+ import type { GrowableBuffer } from "./utils.mjs";
2
+ export interface InstancedAttribute {
3
+ buffer: GrowableBuffer;
4
+ location: number;
5
+ size: number;
6
+ glType: GLenum;
7
+ normalized: boolean;
8
+ }
9
+ /**
10
+ * Creates a per-instance vertex attribute backed by a fresh grow-only GPU buffer.
11
+ *
12
+ * The caller MUST have the owning VAO bound when calling this — the
13
+ * vertexAttribPointer + vertexAttribDivisor calls register the binding into
14
+ * that VAO and the program then references it on each draw.
15
+ */
16
+ export declare function createInstancedAttribute(gl: WebGL2RenderingContext, program: WebGLProgram, name: string, size: number, glType?: GLenum, normalized?: boolean): InstancedAttribute;
17
+ /**
18
+ * Wires up a per-instance vertex attribute that reads from an existing GrowableBuffer.
19
+ * Use this when the same buffer must back the same-named attribute in multiple
20
+ * VAOs (e.g. two shader-program variants over the same data).
21
+ *
22
+ * The caller MUST have the owning VAO bound when calling this.
23
+ *
24
+ * If the attribute is missing from the program (typo, or optimized out by the
25
+ * compiler), `getAttribLocation` returns -1. We skip the GL setup in that case to
26
+ * avoid `INVALID_VALUE` errors from `enableVertexAttribArray(-1)` and warn in dev.
27
+ */
28
+ export declare function bindInstancedAttribute(gl: WebGL2RenderingContext, program: WebGLProgram, name: string, buffer: GrowableBuffer, size: number, glType?: GLenum, normalized?: boolean): InstancedAttribute;
@@ -0,0 +1,28 @@
1
+ import type { GrowableBuffer } from "./utils.js";
2
+ export interface InstancedAttribute {
3
+ buffer: GrowableBuffer;
4
+ location: number;
5
+ size: number;
6
+ glType: GLenum;
7
+ normalized: boolean;
8
+ }
9
+ /**
10
+ * Creates a per-instance vertex attribute backed by a fresh grow-only GPU buffer.
11
+ *
12
+ * The caller MUST have the owning VAO bound when calling this — the
13
+ * vertexAttribPointer + vertexAttribDivisor calls register the binding into
14
+ * that VAO and the program then references it on each draw.
15
+ */
16
+ export declare function createInstancedAttribute(gl: WebGL2RenderingContext, program: WebGLProgram, name: string, size: number, glType?: GLenum, normalized?: boolean): InstancedAttribute;
17
+ /**
18
+ * Wires up a per-instance vertex attribute that reads from an existing GrowableBuffer.
19
+ * Use this when the same buffer must back the same-named attribute in multiple
20
+ * VAOs (e.g. two shader-program variants over the same data).
21
+ *
22
+ * The caller MUST have the owning VAO bound when calling this.
23
+ *
24
+ * If the attribute is missing from the program (typo, or optimized out by the
25
+ * compiler), `getAttribLocation` returns -1. We skip the GL setup in that case to
26
+ * avoid `INVALID_VALUE` errors from `enableVertexAttribArray(-1)` and warn in dev.
27
+ */
28
+ export declare function bindInstancedAttribute(gl: WebGL2RenderingContext, program: WebGLProgram, name: string, buffer: GrowableBuffer, size: number, glType?: GLenum, normalized?: boolean): InstancedAttribute;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.bindInstancedAttribute = bindInstancedAttribute;
7
+ exports.createInstancedAttribute = createInstancedAttribute;
8
+ var _utils = require("./utils");
9
+ /**
10
+ * Creates a per-instance vertex attribute backed by a fresh grow-only GPU buffer.
11
+ *
12
+ * The caller MUST have the owning VAO bound when calling this — the
13
+ * vertexAttribPointer + vertexAttribDivisor calls register the binding into
14
+ * that VAO and the program then references it on each draw.
15
+ */
16
+ function createInstancedAttribute(gl, program, name, size, glType = gl.FLOAT, normalized = false) {
17
+ const buffer = (0, _utils.createGrowableBuffer)(gl);
18
+ return bindInstancedAttribute(gl, program, name, buffer, size, glType, normalized);
19
+ }
20
+
21
+ /**
22
+ * Wires up a per-instance vertex attribute that reads from an existing GrowableBuffer.
23
+ * Use this when the same buffer must back the same-named attribute in multiple
24
+ * VAOs (e.g. two shader-program variants over the same data).
25
+ *
26
+ * The caller MUST have the owning VAO bound when calling this.
27
+ *
28
+ * If the attribute is missing from the program (typo, or optimized out by the
29
+ * compiler), `getAttribLocation` returns -1. We skip the GL setup in that case to
30
+ * avoid `INVALID_VALUE` errors from `enableVertexAttribArray(-1)` and warn in dev.
31
+ */
32
+ function bindInstancedAttribute(gl, program, name, buffer, size, glType = gl.FLOAT, normalized = false) {
33
+ const location = gl.getAttribLocation(program, name);
34
+ if (location === -1) {
35
+ if (process.env.NODE_ENV !== 'production') {
36
+ console.warn(`WebGL attribute "${name}" not found in shader program (misspelled or optimized out).`);
37
+ }
38
+ return {
39
+ buffer,
40
+ location,
41
+ size,
42
+ glType,
43
+ normalized
44
+ };
45
+ }
46
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
47
+ gl.enableVertexAttribArray(location);
48
+ gl.vertexAttribPointer(location, size, glType, normalized, 0, 0);
49
+ gl.vertexAttribDivisor(location, 1);
50
+ return {
51
+ buffer,
52
+ location,
53
+ size,
54
+ glType,
55
+ normalized
56
+ };
57
+ }
@@ -0,0 +1,50 @@
1
+ import { createGrowableBuffer } from "./utils.mjs";
2
+ /**
3
+ * Creates a per-instance vertex attribute backed by a fresh grow-only GPU buffer.
4
+ *
5
+ * The caller MUST have the owning VAO bound when calling this — the
6
+ * vertexAttribPointer + vertexAttribDivisor calls register the binding into
7
+ * that VAO and the program then references it on each draw.
8
+ */
9
+ export function createInstancedAttribute(gl, program, name, size, glType = gl.FLOAT, normalized = false) {
10
+ const buffer = createGrowableBuffer(gl);
11
+ return bindInstancedAttribute(gl, program, name, buffer, size, glType, normalized);
12
+ }
13
+
14
+ /**
15
+ * Wires up a per-instance vertex attribute that reads from an existing GrowableBuffer.
16
+ * Use this when the same buffer must back the same-named attribute in multiple
17
+ * VAOs (e.g. two shader-program variants over the same data).
18
+ *
19
+ * The caller MUST have the owning VAO bound when calling this.
20
+ *
21
+ * If the attribute is missing from the program (typo, or optimized out by the
22
+ * compiler), `getAttribLocation` returns -1. We skip the GL setup in that case to
23
+ * avoid `INVALID_VALUE` errors from `enableVertexAttribArray(-1)` and warn in dev.
24
+ */
25
+ export function bindInstancedAttribute(gl, program, name, buffer, size, glType = gl.FLOAT, normalized = false) {
26
+ const location = gl.getAttribLocation(program, name);
27
+ if (location === -1) {
28
+ if (process.env.NODE_ENV !== 'production') {
29
+ console.warn(`WebGL attribute "${name}" not found in shader program (misspelled or optimized out).`);
30
+ }
31
+ return {
32
+ buffer,
33
+ location,
34
+ size,
35
+ glType,
36
+ normalized
37
+ };
38
+ }
39
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
40
+ gl.enableVertexAttribArray(location);
41
+ gl.vertexAttribPointer(location, size, glType, normalized, 0, 0);
42
+ gl.vertexAttribDivisor(location, 1);
43
+ return {
44
+ buffer,
45
+ location,
46
+ size,
47
+ glType,
48
+ normalized
49
+ };
50
+ }
@@ -1,7 +1,6 @@
1
1
  export declare function compileShader(gl: WebGL2RenderingContext, shaderSource: string, shaderType: WebGL2RenderingContext['FRAGMENT_SHADER'] | WebGL2RenderingContext['VERTEX_SHADER']): WebGLShader;
2
2
  export declare function uploadQuadBuffer(gl: WebGL2RenderingContext): WebGLBuffer;
3
3
  export declare function bindQuadBuffer(gl: WebGL2RenderingContext, program: WebGLProgram, quadBuffer: WebGLBuffer): void;
4
- export declare function attachShader(gl: WebGL2RenderingContext, program: WebGLProgram, shaderSource: string, shaderType: WebGL2RenderingContext['FRAGMENT_SHADER'] | WebGL2RenderingContext['VERTEX_SHADER']): WebGLShader;
5
4
  export type GrowableBuffer = {
6
5
  buffer: WebGLBuffer;
7
6
  capacity: number;
@@ -18,4 +17,24 @@ export declare function uploadGrowableBuffer(gl: WebGL2RenderingContext, target:
18
17
  /**
19
18
  * Logs WebGL errors to the console in development mode.
20
19
  */
21
- export declare function logWebGLErrors(gl: WebGL2RenderingContext): void;
20
+ export declare function logWebGLErrors(gl: WebGL2RenderingContext): void;
21
+ /** Enables the standard non-premultiplied src-alpha blending used by all premium WebGL renderers. */
22
+ export declare function setupStandardBlending(gl: WebGL2RenderingContext): void;
23
+ /**
24
+ * Returns `existing` when it's large enough to hold `length` elements, otherwise
25
+ * allocates a fresh typed array via `Ctor`. Lets consumers keep one ref per
26
+ * pool and short-circuit growth checks inline.
27
+ */
28
+ export declare function ensurePool<T extends {
29
+ length: number;
30
+ }>(existing: T | null | undefined, length: number, Ctor: new (length: number) => T): T;
31
+ export interface LinkedProgram {
32
+ program: WebGLProgram;
33
+ /** The vertex + fragment shaders that were attached. Hold them so dispose() can delete them. */
34
+ shaders: WebGLShader[];
35
+ }
36
+ /**
37
+ * Compiles vertex + fragment shaders, attaches them, links the program, and returns
38
+ * both the program and its shaders. Logs link/compile diagnostics in dev when linking fails.
39
+ */
40
+ export declare function linkProgram(gl: WebGL2RenderingContext, vertexShaderSource: string, fragmentShaderSource: string): LinkedProgram;
@@ -1,7 +1,6 @@
1
1
  export declare function compileShader(gl: WebGL2RenderingContext, shaderSource: string, shaderType: WebGL2RenderingContext['FRAGMENT_SHADER'] | WebGL2RenderingContext['VERTEX_SHADER']): WebGLShader;
2
2
  export declare function uploadQuadBuffer(gl: WebGL2RenderingContext): WebGLBuffer;
3
3
  export declare function bindQuadBuffer(gl: WebGL2RenderingContext, program: WebGLProgram, quadBuffer: WebGLBuffer): void;
4
- export declare function attachShader(gl: WebGL2RenderingContext, program: WebGLProgram, shaderSource: string, shaderType: WebGL2RenderingContext['FRAGMENT_SHADER'] | WebGL2RenderingContext['VERTEX_SHADER']): WebGLShader;
5
4
  export type GrowableBuffer = {
6
5
  buffer: WebGLBuffer;
7
6
  capacity: number;
@@ -18,4 +17,24 @@ export declare function uploadGrowableBuffer(gl: WebGL2RenderingContext, target:
18
17
  /**
19
18
  * Logs WebGL errors to the console in development mode.
20
19
  */
21
- export declare function logWebGLErrors(gl: WebGL2RenderingContext): void;
20
+ export declare function logWebGLErrors(gl: WebGL2RenderingContext): void;
21
+ /** Enables the standard non-premultiplied src-alpha blending used by all premium WebGL renderers. */
22
+ export declare function setupStandardBlending(gl: WebGL2RenderingContext): void;
23
+ /**
24
+ * Returns `existing` when it's large enough to hold `length` elements, otherwise
25
+ * allocates a fresh typed array via `Ctor`. Lets consumers keep one ref per
26
+ * pool and short-circuit growth checks inline.
27
+ */
28
+ export declare function ensurePool<T extends {
29
+ length: number;
30
+ }>(existing: T | null | undefined, length: number, Ctor: new (length: number) => T): T;
31
+ export interface LinkedProgram {
32
+ program: WebGLProgram;
33
+ /** The vertex + fragment shaders that were attached. Hold them so dispose() can delete them. */
34
+ shaders: WebGLShader[];
35
+ }
36
+ /**
37
+ * Compiles vertex + fragment shaders, attaches them, links the program, and returns
38
+ * both the program and its shaders. Logs link/compile diagnostics in dev when linking fails.
39
+ */
40
+ export declare function linkProgram(gl: WebGL2RenderingContext, vertexShaderSource: string, fragmentShaderSource: string): LinkedProgram;
@@ -3,11 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.attachShader = attachShader;
7
6
  exports.bindQuadBuffer = bindQuadBuffer;
8
7
  exports.compileShader = compileShader;
9
8
  exports.createGrowableBuffer = createGrowableBuffer;
9
+ exports.ensurePool = ensurePool;
10
+ exports.linkProgram = linkProgram;
10
11
  exports.logWebGLErrors = logWebGLErrors;
12
+ exports.setupStandardBlending = setupStandardBlending;
11
13
  exports.uploadGrowableBuffer = uploadGrowableBuffer;
12
14
  exports.uploadQuadBuffer = uploadQuadBuffer;
13
15
  function compileShader(gl, shaderSource, shaderType) {
@@ -29,13 +31,6 @@ function bindQuadBuffer(gl, program, quadBuffer) {
29
31
  gl.enableVertexAttribArray(aPosition);
30
32
  gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, 0, 0);
31
33
  }
32
- function attachShader(gl, program, shaderSource, shaderType) {
33
- const shader = gl.createShader(shaderType);
34
- gl.shaderSource(shader, shaderSource);
35
- gl.compileShader(shader);
36
- gl.attachShader(program, shader);
37
- return shader;
38
- }
39
34
  function createGrowableBuffer(gl) {
40
35
  return {
41
36
  buffer: gl.createBuffer(),
@@ -77,4 +72,45 @@ function logWebGLErrors(gl) {
77
72
  error = gl.getError();
78
73
  }
79
74
  }
75
+ }
76
+
77
+ /** Enables the standard non-premultiplied src-alpha blending used by all premium WebGL renderers. */
78
+ function setupStandardBlending(gl) {
79
+ gl.enable(gl.BLEND);
80
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
81
+ }
82
+
83
+ /**
84
+ * Returns `existing` when it's large enough to hold `length` elements, otherwise
85
+ * allocates a fresh typed array via `Ctor`. Lets consumers keep one ref per
86
+ * pool and short-circuit growth checks inline.
87
+ */
88
+ function ensurePool(existing, length, Ctor) {
89
+ if (existing != null && existing.length >= length) {
90
+ return existing;
91
+ }
92
+ return new Ctor(length);
93
+ }
94
+ /**
95
+ * Compiles vertex + fragment shaders, attaches them, links the program, and returns
96
+ * both the program and its shaders. Logs link/compile diagnostics in dev when linking fails.
97
+ */
98
+ function linkProgram(gl, vertexShaderSource, fragmentShaderSource) {
99
+ const program = gl.createProgram();
100
+ const vertexShader = compileShader(gl, vertexShaderSource, gl.VERTEX_SHADER);
101
+ const fragmentShader = compileShader(gl, fragmentShaderSource, gl.FRAGMENT_SHADER);
102
+ gl.attachShader(program, vertexShader);
103
+ gl.attachShader(program, fragmentShader);
104
+ gl.linkProgram(program);
105
+ if (process.env.NODE_ENV !== 'production' && !gl.getProgramParameter(program, gl.LINK_STATUS)) {
106
+ // WebGL best-practices: consult compile/link status only in dev mode
107
+ // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#dont_check_shader_compile_status_unless_linking_fails
108
+ console.error(`Program linking failed: ${gl.getProgramInfoLog(program)}`);
109
+ console.error(`Vertex shader info-log: ${gl.getShaderInfoLog(vertexShader)}`);
110
+ console.error(`Fragment shader info-log: ${gl.getShaderInfoLog(fragmentShader)}`);
111
+ }
112
+ return {
113
+ program,
114
+ shaders: [vertexShader, fragmentShader]
115
+ };
80
116
  }
@@ -17,13 +17,6 @@ export function bindQuadBuffer(gl, program, quadBuffer) {
17
17
  gl.enableVertexAttribArray(aPosition);
18
18
  gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, 0, 0);
19
19
  }
20
- export function attachShader(gl, program, shaderSource, shaderType) {
21
- const shader = gl.createShader(shaderType);
22
- gl.shaderSource(shader, shaderSource);
23
- gl.compileShader(shader);
24
- gl.attachShader(program, shader);
25
- return shader;
26
- }
27
20
  export function createGrowableBuffer(gl) {
28
21
  return {
29
22
  buffer: gl.createBuffer(),
@@ -65,4 +58,45 @@ export function logWebGLErrors(gl) {
65
58
  error = gl.getError();
66
59
  }
67
60
  }
61
+ }
62
+
63
+ /** Enables the standard non-premultiplied src-alpha blending used by all premium WebGL renderers. */
64
+ export function setupStandardBlending(gl) {
65
+ gl.enable(gl.BLEND);
66
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
67
+ }
68
+
69
+ /**
70
+ * Returns `existing` when it's large enough to hold `length` elements, otherwise
71
+ * allocates a fresh typed array via `Ctor`. Lets consumers keep one ref per
72
+ * pool and short-circuit growth checks inline.
73
+ */
74
+ export function ensurePool(existing, length, Ctor) {
75
+ if (existing != null && existing.length >= length) {
76
+ return existing;
77
+ }
78
+ return new Ctor(length);
79
+ }
80
+ /**
81
+ * Compiles vertex + fragment shaders, attaches them, links the program, and returns
82
+ * both the program and its shaders. Logs link/compile diagnostics in dev when linking fails.
83
+ */
84
+ export function linkProgram(gl, vertexShaderSource, fragmentShaderSource) {
85
+ const program = gl.createProgram();
86
+ const vertexShader = compileShader(gl, vertexShaderSource, gl.VERTEX_SHADER);
87
+ const fragmentShader = compileShader(gl, fragmentShaderSource, gl.FRAGMENT_SHADER);
88
+ gl.attachShader(program, vertexShader);
89
+ gl.attachShader(program, fragmentShader);
90
+ gl.linkProgram(program);
91
+ if (process.env.NODE_ENV !== 'production' && !gl.getProgramParameter(program, gl.LINK_STATUS)) {
92
+ // WebGL best-practices: consult compile/link status only in dev mode
93
+ // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#dont_check_shader_compile_status_unless_linking_fails
94
+ console.error(`Program linking failed: ${gl.getProgramInfoLog(program)}`);
95
+ console.error(`Vertex shader info-log: ${gl.getShaderInfoLog(vertexShader)}`);
96
+ console.error(`Fragment shader info-log: ${gl.getShaderInfoLog(fragmentShader)}`);
97
+ }
98
+ return {
99
+ program,
100
+ shaders: [vertexShader, fragmentShader]
101
+ };
68
102
  }