Skip to content

Commit 732af18

Browse files
ryan-williamsclaude
andcommitted
convert lib/index.js to named exports for tree-shaking
Convert all 182 methods from aggregation pattern to named exports. Update 68 consumer files in the factory bundle to use named imports. Keep `export default lib` for backward compat with 286 non-factory files. Sub-modules (`loggers.js`, `mod.js`, `angles.js`, `dom.js`) also converted to named exports for direct re-export from `lib/index.js`. Saves ~10 KB minified across all bundles from tree-shaking 74 unused methods. Factory: 694 KB min (was 704 KB). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2b867fb commit 732af18

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1232
-1048
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"upstream_full__min_": 4831947,
33
"upstream_basic__min_": 1114816,
4-
"fork_full__min_": 4807649,
5-
"fork_basic__min_": 1093881,
6-
"fork_minimal__min_": 986167,
7-
"fork_lite__min_": 846142,
4+
"fork_full__min_": 4797107,
5+
"fork_basic__min_": 1083866,
6+
"fork_minimal__min_": 976177,
7+
"fork_lite__min_": 836151,
88
"app___upstream_basic": 1115573,
9-
"app___fork_basic": 1094029,
10-
"app___fork_lite": 846234,
11-
"fork_factory__min_": 720668,
12-
"app___fork_factory": 720668
9+
"app___fork_basic": 1084014,
10+
"app___fork_lite": 836243,
11+
"fork_factory__min_": 710590,
12+
"app___fork_factory": 710590
1313
}

perf/thresholds.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
22
"bundleSize": {
33
"lite": {
4-
"expected_bytes": 1801210
4+
"expected_bytes": 1791466
55
},
66
"lite-min": {
77
"expected_bytes": 916326
88
},
99
"minimal": {
10-
"expected_bytes": 2123964
10+
"expected_bytes": 2114209
1111
},
1212
"minimal-min": {
1313
"expected_bytes": 1076875
1414
},
1515
"basic": {
16-
"expected_bytes": 2429051
16+
"expected_bytes": 2419312
1717
},
1818
"basic-min": {
1919
"expected_bytes": 1185641

src/components/colorbar/defaults.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Lib from '../../lib/index.js';
1+
import Lib, { bigFont, coerceFont, extendFlat, noneOrAll } from '../../lib/index.js';
22
import Template from '../../plot_api/plot_template.js';
33
import handleTickValueDefaults from '../../plots/cartesian/tick_value_defaults.js';
44
import handleTickMarkDefaults from '../../plots/cartesian/tick_mark_defaults.js';
@@ -76,7 +76,7 @@ export default function colorbarDefaults(containerIn, containerOut, layout) {
7676
coerce('xpad');
7777
coerce('yanchor', defaultYAnchor);
7878
coerce('ypad');
79-
Lib.noneOrAll(colorbarIn, colorbarOut, ['x', 'y']);
79+
noneOrAll(colorbarIn, colorbarOut, ['x', 'y']);
8080

8181
coerce('outlinecolor');
8282
coerce('outlinewidth');
@@ -123,10 +123,10 @@ export default function colorbarDefaults(containerIn, containerOut, layout) {
123123

124124
var tickFont = colorbarOut.showticklabels ? colorbarOut.tickfont : font;
125125

126-
var dfltTitleFont = Lib.extendFlat({}, font, {
126+
var dfltTitleFont = extendFlat({}, font, {
127127
family: tickFont.family,
128-
size: Lib.bigFont(tickFont.size)
128+
size: bigFont(tickFont.size)
129129
});
130-
Lib.coerceFont(coerce, 'title.font', dfltTitleFont);
130+
coerceFont(coerce, 'title.font', dfltTitleFont);
131131
coerce('title.side', isVertical ? 'top' : 'right');
132132
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Lib from '../../lib/index.js';
1+
import { isPlainObject } from '../../lib/index.js';
22

33
export default function hasColorbar(container) {
4-
return Lib.isPlainObject(container.colorbar);
4+
return isPlainObject(container.colorbar);
55
}

src/components/colorscale/calc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import isNumeric from 'fast-isnumeric';
2-
import Lib from '../../lib/index.js';
2+
import { aggNums, nestedProperty } from '../../lib/index.js';
33
import _helpers from './helpers.js';
44
const { extractOpts } = _helpers;
55

@@ -9,7 +9,7 @@ export default function calc(gd, trace, opts) {
99
var containerStr = opts.containerStr;
1010

1111
var container = containerStr ?
12-
Lib.nestedProperty(trace, containerStr).get() :
12+
nestedProperty(trace, containerStr).get() :
1313
trace;
1414

1515
var cOpts = extractOpts(container);
@@ -18,8 +18,8 @@ export default function calc(gd, trace, opts) {
1818
var max = cOpts.max;
1919
var mid = cOpts.mid;
2020

21-
var minVal = function() { return Lib.aggNums(Math.min, null, vals); };
22-
var maxVal = function() { return Lib.aggNums(Math.max, null, vals); };
21+
var minVal = function() { return aggNums(Math.min, null, vals); };
22+
var maxVal = function() { return aggNums(Math.max, null, vals); };
2323

2424
if(min === undefined) {
2525
min = minVal();

src/components/colorscale/cross_trace_defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Lib from '../../lib/index.js';
1+
import { nestedProperty } from '../../lib/index.js';
22
import _helpers from './helpers.js';
33
const { hasColorscale, extractOpts } = _helpers;
44

@@ -12,7 +12,7 @@ export default function crossTraceDefaults(fullData, fullLayout) {
1212

1313
function relinkColorAttrs(outerCont, cbOpt) {
1414
var cont = cbOpt.container ?
15-
Lib.nestedProperty(outerCont, cbOpt.container).get() :
15+
nestedProperty(outerCont, cbOpt.container).get() :
1616
outerCont;
1717

1818
if(cont) {

src/components/colorscale/defaults.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import isNumeric from 'fast-isnumeric';
2-
import Lib from '../../lib/index.js';
2+
import { nestedProperty, warn } from '../../lib/index.js';
33
import hasColorbar from '../colorbar/has_colorbar.js';
44
import colorbarDefaults from '../colorbar/defaults.js';
55
import _scales from './scales.js';
@@ -9,7 +9,7 @@ import { traceIs } from '../../registry.js';
99
function npMaybe(parentCont, prefix) {
1010
var containerStr = prefix.slice(0, prefix.length - 1);
1111
return prefix ?
12-
Lib.nestedProperty(parentCont, containerStr).get() || {} :
12+
nestedProperty(parentCont, containerStr).get() || {} :
1313
parentCont;
1414
}
1515

@@ -36,7 +36,7 @@ export default function colorScaleDefaults(parentContIn, parentContOut, layout,
3636
if(colorAx) {
3737
var colorbarVisuals = (
3838
traceIs(parentContOut, 'contour') &&
39-
Lib.nestedProperty(parentContOut, 'contours.coloring').get()
39+
nestedProperty(parentContOut, 'contours.coloring').get()
4040
) || 'heatmap';
4141

4242
var stash = colorAxes[colorAx];
@@ -46,7 +46,7 @@ export default function colorScaleDefaults(parentContIn, parentContOut, layout,
4646

4747
if(stash[0] !== colorbarVisuals) {
4848
stash[0] = false;
49-
Lib.warn([
49+
warn([
5050
'Ignoring coloraxis:', colorAx, 'setting',
5151
'as it is linked to incompatible colorscales.'
5252
].join(' '));

src/components/colorscale/helpers.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { scaleLinear, scaleLog, scaleOrdinal } from 'd3-scale';
22
import tinycolor from 'tinycolor2';
33
import isNumeric from 'fast-isnumeric';
4-
import Lib from '../../lib/index.js';
4+
import { isArrayOrTypedArray, isPlainObject, nestedProperty } from '../../lib/index.js';
55
import Color from '../color/index.js';
66
import _scales from './scales.js';
77
const { isValid: isValidScale } = _scales;
88

99
function hasColorscale(trace, containerStr, colorKey) {
1010
var container = containerStr ?
11-
Lib.nestedProperty(trace, containerStr).get() || {} :
11+
nestedProperty(trace, containerStr).get() || {} :
1212
trace;
1313

1414
var color = container[colorKey || 'color'];
1515
if(color && color._inputArray) color = color._inputArray;
1616

1717
var isArrayWithOneNumber = false;
18-
if(Lib.isArrayOrTypedArray(color)) {
18+
if(isArrayOrTypedArray(color)) {
1919
for(var i = 0; i < color.length; i++) {
2020
if(isNumeric(color[i])) {
2121
isArrayWithOneNumber = true;
@@ -25,12 +25,12 @@ function hasColorscale(trace, containerStr, colorKey) {
2525
}
2626

2727
return (
28-
Lib.isPlainObject(container) && (
28+
isPlainObject(container) && (
2929
isArrayWithOneNumber ||
3030
container.showscale === true ||
3131
(isNumeric(container.cmin) && isNumeric(container.cmax)) ||
3232
isValidScale(container.colorscale) ||
33-
Lib.isPlainObject(container.colorbar)
33+
isPlainObject(container.colorbar)
3434
)
3535
);
3636
}

src/components/dragelement/cursor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Lib from '../../lib/index.js';
1+
import { constrain } from '../../lib/index.js';
22

33
// set cursors pointing toward the closest corner/side,
44
// to indicate alignment
@@ -13,12 +13,12 @@ export default function getCursor(x, y, xanchor, yanchor) {
1313
if(xanchor === 'left') x = 0;
1414
else if(xanchor === 'center') x = 1;
1515
else if(xanchor === 'right') x = 2;
16-
else x = Lib.constrain(Math.floor(x * 3), 0, 2);
16+
else x = constrain(Math.floor(x * 3), 0, 2);
1717

1818
if(yanchor === 'bottom') y = 0;
1919
else if(yanchor === 'middle') y = 1;
2020
else if(yanchor === 'top') y = 2;
21-
else y = Lib.constrain(Math.floor(y * 3), 0, 2);
21+
else y = constrain(Math.floor(y * 3), 0, 2);
2222

2323
return cursorset[y][x];
2424
}

src/components/dragelement/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import mouseOffset from 'mouse-event-offset';
22
var hasHover = typeof matchMedia === 'function' ? !matchMedia('(hover: none)').matches : typeof window !== 'undefined';
33
import supportsPassive from 'has-passive-events';
4-
import _index from '../../lib/index.js';
5-
const { removeElement } = _index;
4+
import { removeElement } from '../../lib/index.js';
65
import constants from '../../plots/cartesian/constants.js';
76
import unhover from './unhover.js';
87
import _req0 from './align.js';

0 commit comments

Comments
 (0)