From 79a979f8ed40ce32f273e365e420f461b1abe040 Mon Sep 17 00:00:00 2001 From: Titus Smith <83970048+acdn-tsmith@users.noreply.github.com> Date: Fri, 18 Sep 2026 14:40:04 -0400 Subject: [PATCH] fix(theme): export v5 theme for ESM bundles. close #21757 --- package.json | 13 +++++++++++ test/types/esm/basic.ts | 5 +++- test/ut/spec/api/theme.test.ts | 42 ++++++++++++++++++++++++++++++++++ theme/v5.d.ts | 20 ++++++++++++++++ theme/v5.js | 6 +++-- theme/v5.mjs | 25 ++++++++++++++++++++ 6 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 test/ut/spec/api/theme.test.ts create mode 100644 theme/v5.d.ts create mode 100644 theme/v5.mjs diff --git a/package.json b/package.json index e7136daa42..a06056f76e 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "lib/component/*.js", "extension/**/*.js", "theme/*.js", + "theme/*.mjs", "i18n/*.js" ], "scripts": { @@ -142,6 +143,18 @@ "./index.simple.js": "./index.simple.js", "./index": "./index.js", "./index.js": "./index.js", + "./theme/v5": { + "types": "./theme/v5.d.ts", + "import": "./theme/v5.mjs", + "require": "./theme/v5.js", + "default": "./theme/v5.js" + }, + "./theme/v5.js": { + "types": "./theme/v5.d.ts", + "import": "./theme/v5.mjs", + "require": "./theme/v5.js", + "default": "./theme/v5.js" + }, "./theme/*": "./theme/*", "./i18n/*": "./i18n/*", "./types/dist/all": "./types/dist/all.d.ts", diff --git a/test/types/esm/basic.ts b/test/types/esm/basic.ts index 0ce9ed4750..8b7f5660a0 100644 --- a/test/types/esm/basic.ts +++ b/test/types/esm/basic.ts @@ -18,6 +18,9 @@ */ import * as echarts from 'echarts'; +import {v5Theme} from 'echarts/theme/v5.js'; + +echarts.registerTheme('v5-explicit', v5Theme); const dom = document.createElement('div'); dom.className = 'chart'; @@ -34,4 +37,4 @@ const option: echarts.EChartsOption = { } }] }; -chart.setOption(option); \ No newline at end of file +chart.setOption(option); diff --git a/test/ut/spec/api/theme.test.ts b/test/ut/spec/api/theme.test.ts new file mode 100644 index 0000000000..c5aefc4843 --- /dev/null +++ b/test/ut/spec/api/theme.test.ts @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +const mockRegisterTheme = jest.fn(); +jest.mock('echarts/lib/echarts', function () { + return { registerTheme: mockRegisterTheme }; +}, { virtual: true }); + +const { v5Theme }: { v5Theme: { color: string[] } } = require('../../../../theme/v5'); + +describe('api/theme', function () { + it('exports the v5 compatibility theme for explicit registration', function () { + expect(v5Theme.color).toEqual([ + '#5470c6', + '#91cc75', + '#fac858', + '#ee6666', + '#73c0de', + '#3ba272', + '#fc8452', + '#9a60b4', + '#ea7ccc' + ]); + expect(mockRegisterTheme).toHaveBeenCalledWith('v5', v5Theme); + }); +}); diff --git a/theme/v5.d.ts b/theme/v5.d.ts new file mode 100644 index 0000000000..8a7ab1b3ee --- /dev/null +++ b/theme/v5.d.ts @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export const v5Theme: Record; diff --git a/theme/v5.js b/theme/v5.js index 2344d359a9..229ace03a9 100644 --- a/theme/v5.js +++ b/theme/v5.js @@ -81,7 +81,7 @@ var gradientColor = ['#f6efa6', '#d88273', '#bf444c']; - echarts.registerTheme('v5', { + var v5Theme = { color: colorPalette, gradientColor: gradientColor, @@ -577,5 +577,7 @@ color: '#333' } } - }); + }; + echarts.registerTheme('v5', v5Theme); + exports.v5Theme = v5Theme; }); diff --git a/theme/v5.mjs b/theme/v5.mjs new file mode 100644 index 0000000000..ec54e6cd9e --- /dev/null +++ b/theme/v5.mjs @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import * as echarts from 'echarts'; +import { v5Theme } from './v5.js'; + +echarts.registerTheme('v5', v5Theme); + +export { v5Theme };