dumi 2.0.18 → 2.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.
- package/dist/client/theme-api/context.d.ts +1 -1
- package/dist/client/theme-api/index.d.ts +1 -0
- package/dist/client/theme-api/index.js +1 -0
- package/dist/client/theme-api/types.d.ts +4 -0
- package/dist/client/theme-api/usePrefersColor.d.ts +7 -0
- package/dist/client/theme-api/usePrefersColor.js +199 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +6 -0
- package/dist/features/configPlugins/index.js +2 -1
- package/dist/features/derivative.js +7 -5
- package/dist/features/routes.js +5 -0
- package/dist/features/sitemap.js +1 -1
- package/dist/features/theme/index.js +20 -0
- package/dist/loaders/markdown/transformer/rehypeDemo.js +1 -1
- package/dist/types.d.ts +15 -7
- package/package.json +1 -1
- package/theme-default/builtins/Badge/index.less +20 -0
- package/theme-default/builtins/Container/index.less +29 -28
- package/theme-default/builtins/Previewer/index.less +48 -1
- package/theme-default/builtins/SourceCode/index.less +40 -1
- package/theme-default/builtins/Table/index.less +2 -2
- package/theme-default/layouts/DocLayout/index.less +26 -0
- package/theme-default/locales/en-US.json +3 -1
- package/theme-default/locales/zh-CN.json +3 -1
- package/theme-default/slots/ColorSwitch/index.d.ts +4 -0
- package/theme-default/slots/ColorSwitch/index.js +82 -0
- package/theme-default/slots/ColorSwitch/index.less +58 -0
- package/theme-default/slots/Content/index.less +45 -0
- package/theme-default/slots/ContentTabs/index.less +20 -0
- package/theme-default/slots/Features/index.less +18 -0
- package/theme-default/slots/Footer/index.less +9 -0
- package/theme-default/slots/Header/index.js +6 -2
- package/theme-default/slots/Header/index.less +21 -0
- package/theme-default/slots/Hero/index.less +17 -0
- package/theme-default/slots/HeroTitle/index.less +4 -0
- package/theme-default/slots/LangSwitch/index.less +17 -1
- package/theme-default/slots/Logo/index.less +4 -0
- package/theme-default/slots/Navbar/index.less +12 -0
- package/theme-default/slots/NotFound/index.less +9 -0
- package/theme-default/slots/PreviewerActions/index.less +45 -1
- package/theme-default/slots/RtlSwitch/index.js +24 -4
- package/theme-default/slots/RtlSwitch/index.less +29 -3
- package/theme-default/slots/SearchBar/index.less +43 -0
- package/theme-default/slots/SearchResult/index.less +48 -2
- package/theme-default/slots/Sidebar/index.less +25 -0
- package/theme-default/slots/Toc/index.less +17 -0
- package/theme-default/styles/utils.less +14 -2
- package/theme-default/styles/variables.less +17 -0
|
@@ -11,7 +11,7 @@ interface ISiteContext {
|
|
|
11
11
|
routeId: string;
|
|
12
12
|
}>;
|
|
13
13
|
components: Record<string, AtomComponentAsset>;
|
|
14
|
-
locales:
|
|
14
|
+
locales: ILocalesConfig;
|
|
15
15
|
themeConfig: IThemeConfig;
|
|
16
16
|
loading: boolean;
|
|
17
17
|
setLoading: (status: boolean) => void;
|
|
@@ -10,6 +10,7 @@ export type { IPreviewerProps } from './types';
|
|
|
10
10
|
export { useAtomAssets } from './useAtomAssets';
|
|
11
11
|
export { useLocale } from './useLocale';
|
|
12
12
|
export { useNavData } from './useNavData';
|
|
13
|
+
export { usePrefersColor } from './usePrefersColor';
|
|
13
14
|
export { useRouteMeta } from './useRouteMeta';
|
|
14
15
|
export { useFullSidebarData, useSidebarData } from './useSidebarData';
|
|
15
16
|
export { useSiteSearch } from './useSiteSearch';
|
|
@@ -9,6 +9,7 @@ export { openStackBlitz } from "./openStackBlitz";
|
|
|
9
9
|
export { useAtomAssets } from "./useAtomAssets";
|
|
10
10
|
export { useLocale } from "./useLocale";
|
|
11
11
|
export { useNavData } from "./useNavData";
|
|
12
|
+
export { usePrefersColor } from "./usePrefersColor";
|
|
12
13
|
export { useRouteMeta } from "./useRouteMeta";
|
|
13
14
|
export { useFullSidebarData, useSidebarData } from "./useSidebarData";
|
|
14
15
|
export { useSiteSearch } from "./useSiteSearch";
|
|
@@ -162,6 +162,10 @@ export interface IThemeConfig {
|
|
|
162
162
|
})[]>;
|
|
163
163
|
sidebar?: Record<string, ISidebarGroup[]>;
|
|
164
164
|
footer?: string;
|
|
165
|
+
prefersColor: {
|
|
166
|
+
default: 'light' | 'dark' | 'auto';
|
|
167
|
+
switch: boolean;
|
|
168
|
+
};
|
|
165
169
|
[key: string]: any;
|
|
166
170
|
}
|
|
167
171
|
export declare type IRoutesById = Record<string, {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare type IColorValue = 'light' | 'dark';
|
|
2
|
+
export declare type IPrefersColorValue = IColorValue | 'auto';
|
|
3
|
+
/**
|
|
4
|
+
* hook for get/set prefers-color-schema, use to control color mode for theme package
|
|
5
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
|
|
6
|
+
*/
|
|
7
|
+
export declare const usePrefersColor: () => [IColorValue, IPrefersColorValue, (val: IPrefersColorValue) => void];
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
+
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
+
|
|
15
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
16
|
+
|
|
17
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
18
|
+
|
|
19
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
20
|
+
|
|
21
|
+
import { PREFERS_COLOR_ATTR, PREFERS_COLOR_LS_KEY } from "../../constants";
|
|
22
|
+
import { useSiteData } from 'dumi';
|
|
23
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
24
|
+
var colorChanger;
|
|
25
|
+
|
|
26
|
+
var ColorChanger = /*#__PURE__*/function () {
|
|
27
|
+
/**
|
|
28
|
+
* current color
|
|
29
|
+
* @note exclude `auto`
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* current prefers color
|
|
34
|
+
* @note include `auto`
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* color change callbacks
|
|
39
|
+
*/
|
|
40
|
+
function ColorChanger(opts) {
|
|
41
|
+
var _this = this;
|
|
42
|
+
|
|
43
|
+
_classCallCheck(this, ColorChanger);
|
|
44
|
+
|
|
45
|
+
_defineProperty(this, "color", void 0);
|
|
46
|
+
|
|
47
|
+
_defineProperty(this, "prefersColor", void 0);
|
|
48
|
+
|
|
49
|
+
_defineProperty(this, "callbacks", []);
|
|
50
|
+
|
|
51
|
+
this.prefersColor = navigator.cookieEnabled && // read from localStorage first, because `auto` will not be set to attr
|
|
52
|
+
localStorage.getItem(PREFERS_COLOR_LS_KEY) || // then use default value from themeConfig
|
|
53
|
+
opts.default;
|
|
54
|
+
this.color = document.documentElement.getAttribute(PREFERS_COLOR_ATTR); // listen prefers color change
|
|
55
|
+
|
|
56
|
+
['light', 'dark'].forEach(function (color) {
|
|
57
|
+
var mediaQueryList = _this.getColorMedia(color);
|
|
58
|
+
|
|
59
|
+
var handler = function handler(ev) {
|
|
60
|
+
// only apply media prefers color in auto mode
|
|
61
|
+
if (ev.matches && _this.prefersColor === 'auto') {
|
|
62
|
+
_this.color = color;
|
|
63
|
+
document.documentElement.setAttribute(PREFERS_COLOR_ATTR, color);
|
|
64
|
+
|
|
65
|
+
_this.applyCallbacks();
|
|
66
|
+
}
|
|
67
|
+
}; // compatible with Safari 13-
|
|
68
|
+
|
|
69
|
+
/* istanbul ignore else */
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if (mediaQueryList.addEventListener) {
|
|
73
|
+
mediaQueryList.addEventListener('change', handler);
|
|
74
|
+
} else if (mediaQueryList.addListener) {
|
|
75
|
+
mediaQueryList.addListener(handler);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* get media instance for prefers color
|
|
81
|
+
* @param color prefers color
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
_createClass(ColorChanger, [{
|
|
86
|
+
key: "getColorMedia",
|
|
87
|
+
value: function getColorMedia(color) {
|
|
88
|
+
return window.matchMedia("(prefers-color-scheme: ".concat(color, ")"));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* detect color whether matches current color mode
|
|
92
|
+
* @param color expected color
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
}, {
|
|
96
|
+
key: "isColorMode",
|
|
97
|
+
value: function isColorMode(color) {
|
|
98
|
+
return this.getColorMedia(color).matches;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* apply all event change callbacks
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
}, {
|
|
105
|
+
key: "applyCallbacks",
|
|
106
|
+
value: function applyCallbacks() {
|
|
107
|
+
var _this2 = this;
|
|
108
|
+
|
|
109
|
+
this.callbacks.forEach(function (cb) {
|
|
110
|
+
return cb({
|
|
111
|
+
color: _this2.color,
|
|
112
|
+
prefersColor: _this2.prefersColor
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* listen color change
|
|
118
|
+
* @param cb callback
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
}, {
|
|
122
|
+
key: "listen",
|
|
123
|
+
value: function listen(cb) {
|
|
124
|
+
this.callbacks.push(cb);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* unlisten color change
|
|
128
|
+
* @param cb callback
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
}, {
|
|
132
|
+
key: "unlisten",
|
|
133
|
+
value: function unlisten(cb) {
|
|
134
|
+
this.callbacks.splice(this.callbacks.indexOf(cb), 1);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* set prefers color
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
}, {
|
|
141
|
+
key: "tryPrefersColor",
|
|
142
|
+
value: function tryPrefersColor(color) {
|
|
143
|
+
if (navigator.cookieEnabled) {
|
|
144
|
+
localStorage.setItem(PREFERS_COLOR_LS_KEY, color);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
this.prefersColor = color;
|
|
148
|
+
this.color = color === 'auto' ? this.isColorMode('dark') ? 'dark' : 'light' : color;
|
|
149
|
+
document.documentElement.setAttribute(PREFERS_COLOR_ATTR, color);
|
|
150
|
+
this.applyCallbacks();
|
|
151
|
+
return color;
|
|
152
|
+
}
|
|
153
|
+
}]);
|
|
154
|
+
|
|
155
|
+
return ColorChanger;
|
|
156
|
+
}();
|
|
157
|
+
/**
|
|
158
|
+
* hook for get/set prefers-color-schema, use to control color mode for theme package
|
|
159
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
export var usePrefersColor = function usePrefersColor() {
|
|
164
|
+
var _useSiteData = useSiteData(),
|
|
165
|
+
themeConfig = _useSiteData.themeConfig;
|
|
166
|
+
|
|
167
|
+
var _useState = useState(),
|
|
168
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
169
|
+
color = _useState2[0],
|
|
170
|
+
setColor = _useState2[1];
|
|
171
|
+
|
|
172
|
+
var _useState3 = useState(),
|
|
173
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
174
|
+
prefersColor = _useState4[0],
|
|
175
|
+
setPrefersColor = _useState4[1];
|
|
176
|
+
|
|
177
|
+
var tryPrefersColor = useCallback(function (val) {
|
|
178
|
+
colorChanger.tryPrefersColor(val);
|
|
179
|
+
}, []);
|
|
180
|
+
var colorChangeHandler = useCallback(function (args) {
|
|
181
|
+
setColor(args.color);
|
|
182
|
+
setPrefersColor(args.prefersColor);
|
|
183
|
+
}, []);
|
|
184
|
+
useEffect(function () {
|
|
185
|
+
var _colorChanger;
|
|
186
|
+
|
|
187
|
+
// lazy initialize, for SSR
|
|
188
|
+
(_colorChanger = colorChanger) !== null && _colorChanger !== void 0 ? _colorChanger : colorChanger = new ColorChanger({
|
|
189
|
+
default: themeConfig.prefersColor.default
|
|
190
|
+
});
|
|
191
|
+
colorChanger.listen(colorChangeHandler);
|
|
192
|
+
setColor(colorChanger.color);
|
|
193
|
+
setPrefersColor(colorChanger.prefersColor);
|
|
194
|
+
return function () {
|
|
195
|
+
return colorChanger.unlisten(colorChangeHandler);
|
|
196
|
+
};
|
|
197
|
+
}, []);
|
|
198
|
+
return [color, prefersColor, tryPrefersColor];
|
|
199
|
+
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export declare const LOCAL_THEME_DIR: string;
|
|
|
3
3
|
export declare const LOCAL_PAGES_DIR: string;
|
|
4
4
|
export declare const THEME_PREFIX = "dumi-theme-";
|
|
5
5
|
export declare const SP_ROUTE_PREFIX = "~";
|
|
6
|
+
export declare const PREFERS_COLOR_ATTR = "data-prefers-color";
|
|
7
|
+
export declare const PREFERS_COLOR_LS_KEY = "dumi:prefers-color";
|
|
6
8
|
export declare const PICKED_PKG_FIELDS: {
|
|
7
9
|
name: string;
|
|
8
10
|
description: string;
|
package/dist/constants.js
CHANGED
|
@@ -24,6 +24,8 @@ __export(constants_exports, {
|
|
|
24
24
|
LOCAL_PAGES_DIR: () => LOCAL_PAGES_DIR,
|
|
25
25
|
LOCAL_THEME_DIR: () => LOCAL_THEME_DIR,
|
|
26
26
|
PICKED_PKG_FIELDS: () => PICKED_PKG_FIELDS,
|
|
27
|
+
PREFERS_COLOR_ATTR: () => PREFERS_COLOR_ATTR,
|
|
28
|
+
PREFERS_COLOR_LS_KEY: () => PREFERS_COLOR_LS_KEY,
|
|
27
29
|
SP_ROUTE_PREFIX: () => SP_ROUTE_PREFIX,
|
|
28
30
|
THEME_PREFIX: () => THEME_PREFIX,
|
|
29
31
|
USELESS_TMP_FILES: () => USELESS_TMP_FILES
|
|
@@ -34,6 +36,8 @@ var LOCAL_THEME_DIR = `${LOCAL_DUMI_DIR}/theme`;
|
|
|
34
36
|
var LOCAL_PAGES_DIR = `${LOCAL_DUMI_DIR}/pages`;
|
|
35
37
|
var THEME_PREFIX = "dumi-theme-";
|
|
36
38
|
var SP_ROUTE_PREFIX = "~";
|
|
39
|
+
var PREFERS_COLOR_ATTR = "data-prefers-color";
|
|
40
|
+
var PREFERS_COLOR_LS_KEY = "dumi:prefers-color";
|
|
37
41
|
var PICKED_PKG_FIELDS = {
|
|
38
42
|
name: "",
|
|
39
43
|
description: "",
|
|
@@ -62,6 +66,8 @@ var USELESS_TMP_FILES = ["tsconfig.json", "typings.d.ts"];
|
|
|
62
66
|
LOCAL_PAGES_DIR,
|
|
63
67
|
LOCAL_THEME_DIR,
|
|
64
68
|
PICKED_PKG_FIELDS,
|
|
69
|
+
PREFERS_COLOR_ATTR,
|
|
70
|
+
PREFERS_COLOR_LS_KEY,
|
|
65
71
|
SP_ROUTE_PREFIX,
|
|
66
72
|
THEME_PREFIX,
|
|
67
73
|
USELESS_TMP_FILES
|
|
@@ -31,7 +31,8 @@ var configPlugins_default = (api) => {
|
|
|
31
31
|
codeBlockMode: "active"
|
|
32
32
|
},
|
|
33
33
|
themeConfig: {
|
|
34
|
-
footer: `Copyright \xA9 ${new Date().getFullYear()} | Powered by <a href="https://d.umijs.org" target="_blank" rel="noreferrer">dumi</a
|
|
34
|
+
footer: `Copyright \xA9 ${new Date().getFullYear()} | Powered by <a href="https://d.umijs.org" target="_blank" rel="noreferrer">dumi</a>`,
|
|
35
|
+
prefersColor: { default: "light", switch: true }
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
const schemas = (0, import_schema.getSchemas)();
|
|
@@ -47,14 +47,16 @@ function safeExcludeInMFSU(api, excludes) {
|
|
|
47
47
|
var derivative_default = (api) => {
|
|
48
48
|
api.describe({ key: "dumi:derivative" });
|
|
49
49
|
api.onCheck(() => {
|
|
50
|
-
var _a, _b
|
|
50
|
+
var _a, _b;
|
|
51
51
|
(0, import_assert.default)(!api.config.mpa, "MPA mode is not supported in dumi!");
|
|
52
52
|
(0, import_assert.default)(!api.config.vite, "Vite mode is not supported yet!");
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
if (typeof api.config.mfsu === "object") {
|
|
54
|
+
(0, import_assert.default)(api.config.mfsu.strategy !== "eager", "MFSU eager mode is not supported yet!");
|
|
55
|
+
(0, import_assert.default)(api.config.mfsu.esbuild !== true, "MFSU esbuild bundler is not supported yet!");
|
|
56
|
+
}
|
|
55
57
|
(0, import_assert.default)(!api.config.ssr || api.config.ssr.builder === "webpack", "Only `webpack` builder is supported in SSR mode!");
|
|
56
|
-
(0, import_assert.default)(((
|
|
57
|
-
if (((
|
|
58
|
+
(0, import_assert.default)(((_a = api.config.cssLoader) == null ? void 0 : _a.modules) === void 0, "CSS Modules is not supported! Because it is not suitable for UI library development, please use normal CSS, Less, etc. instead.");
|
|
59
|
+
if (((_b = api.userConfig.history) == null ? void 0 : _b.type) === "hash") {
|
|
58
60
|
import_plugin_utils.logger.warn("Hash history is temporarily incompatible, it is recommended to use browser history for now.");
|
|
59
61
|
}
|
|
60
62
|
try {
|
package/dist/features/routes.js
CHANGED
|
@@ -53,6 +53,10 @@ function flatRoute(route, docLayoutId) {
|
|
|
53
53
|
route.path = route.path === "*" ? route.path : route.absPath.slice(1);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
function kebabCaseRoute(route) {
|
|
57
|
+
route.path = route.path.split("/").map((p) => import_plugin_utils.lodash.kebabCase(p)).join("/");
|
|
58
|
+
route.absPath = route.absPath.split("/").map((p) => import_plugin_utils.lodash.kebabCase(p)).join("/");
|
|
59
|
+
}
|
|
56
60
|
function getClientPageFile(file, cwd) {
|
|
57
61
|
try {
|
|
58
62
|
return import_plugin_utils.resolve.sync(`dumi/dist/${file}`, {
|
|
@@ -164,6 +168,7 @@ var routes_default = (api) => {
|
|
|
164
168
|
throw new Error(`Invalid route path: ${route.path}, please rename it with only alphanumeric, dash and slash.
|
|
165
169
|
at ${route.file}`);
|
|
166
170
|
} else if (!route.isLayout) {
|
|
171
|
+
kebabCaseRoute(route);
|
|
167
172
|
flatRoute(route, docLayoutId);
|
|
168
173
|
localizeUmiRoute(route, api.config.locales);
|
|
169
174
|
}
|
package/dist/features/sitemap.js
CHANGED
|
@@ -46,7 +46,7 @@ var sitemap_default = (api) => {
|
|
|
46
46
|
hostname: api.config.sitemap.hostname,
|
|
47
47
|
xmlns: { video: false, image: false, news: false, xhtml: false }
|
|
48
48
|
});
|
|
49
|
-
const exclude = ["/404"].concat(api.config.sitemap.exclude);
|
|
49
|
+
const exclude = ["/404"].concat(api.config.sitemap.exclude || []);
|
|
50
50
|
const writeStream = import_fs.default.createWriteStream(import_path.default.join(api.paths.absOutputPath, "sitemap.xml"));
|
|
51
51
|
smis.pipe(writeStream);
|
|
52
52
|
Object.values(api.appData.routes).forEach((route) => {
|
|
@@ -115,6 +115,8 @@ var theme_default = (api) => {
|
|
|
115
115
|
memo.alias["dumi/theme-default"] = DEFAULT_THEME_PATH;
|
|
116
116
|
memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
|
|
117
117
|
memo.extraBabelIncludes.push(import_path.default.resolve(__dirname, "../../client/theme-api"));
|
|
118
|
+
memo.theme ?? (memo.theme = {});
|
|
119
|
+
memo.theme["dark-selector"] = `~'[${import_constants.PREFERS_COLOR_ATTR}="dark"]'`;
|
|
118
120
|
return memo;
|
|
119
121
|
});
|
|
120
122
|
api.onGenerateFiles(() => {
|
|
@@ -193,6 +195,24 @@ export default function DumiContextWrapper() {
|
|
|
193
195
|
}`
|
|
194
196
|
});
|
|
195
197
|
});
|
|
198
|
+
api.addEntryCodeAhead(() => {
|
|
199
|
+
const { prefersColor } = api.config.themeConfig;
|
|
200
|
+
if (prefersColor.switch === false && prefersColor.default !== "auto") {
|
|
201
|
+
return `document.documentElement.setAttribute('${import_constants.PREFERS_COLOR_ATTR}', '${prefersColor.default}');`;
|
|
202
|
+
}
|
|
203
|
+
return `(function () {
|
|
204
|
+
var cache = typeof navigator !== 'undefined' && navigator.cookieEnabled && typeof window.localStorage !== 'undefined' && localStorage.getItem('dumi:prefers-color') || '${prefersColor.default}';
|
|
205
|
+
var isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
206
|
+
var enums = ['light', 'dark', 'auto'];
|
|
207
|
+
|
|
208
|
+
document.documentElement.setAttribute(
|
|
209
|
+
'${import_constants.PREFERS_COLOR_ATTR}',
|
|
210
|
+
cache === enums[2]
|
|
211
|
+
? (isDark ? enums[1] : enums[0])
|
|
212
|
+
: (enums.indexOf(cache) > -1 ? cache : enums[0])
|
|
213
|
+
);
|
|
214
|
+
})();`;
|
|
215
|
+
});
|
|
196
216
|
if (require("@umijs/core/package").__npminstall_done && import_fs.default.existsSync(localThemePath) && import_fs.default.lstatSync(localThemePath).isSymbolicLink()) {
|
|
197
217
|
api.chainWebpack((memo) => {
|
|
198
218
|
const devThemeNodeModules = import_path.default.join(api.cwd, "../node_modules");
|
|
@@ -140,7 +140,7 @@ function rehypeDemo(opts) {
|
|
|
140
140
|
let component = "";
|
|
141
141
|
if (codeType === "external") {
|
|
142
142
|
const chunkName = [vFile.data.frontmatter.atomId, "demos"].filter(Boolean).join("__");
|
|
143
|
-
parseOpts.fileAbsPath = codeNode.properties.src;
|
|
143
|
+
parseOpts.fileAbsPath = (0, import_plugin_utils.winPath)(codeNode.properties.src);
|
|
144
144
|
parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, import_path.default.parse(parseOpts.fileAbsPath.replace(/\/index\.(j|t)sx?$/, "")).name, vFile.data.frontmatter.atomId);
|
|
145
145
|
component = `React.lazy(() => import( /* webpackChunkName: "${chunkName}" */ '${(0, import_plugin_utils.winPath)(parseOpts.fileAbsPath)}?techStack=${techStack.name}'))`;
|
|
146
146
|
if (codeValue)
|
package/dist/types.d.ts
CHANGED
|
@@ -6,9 +6,14 @@ import type { IThemeLoadResult } from "./features/theme/loader";
|
|
|
6
6
|
import type { IModify } from '@umijs/core';
|
|
7
7
|
import type { AssetsPackage, ExampleBlockAsset } from 'dumi-assets-types';
|
|
8
8
|
import type { Element } from 'hast';
|
|
9
|
-
import type { IApi as IUmiApi } from 'umi';
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
import type { defineConfig as defineUmiConfig, IApi as IUmiApi } from 'umi';
|
|
10
|
+
declare type Subset<K> = {
|
|
11
|
+
[attr in keyof K]?: K[attr] extends Array<any> ? K[attr] : K[attr] extends object ? Subset<K[attr]> : K[attr] extends object | null ? Subset<K[attr]> | null : K[attr] extends object | null | undefined ? Subset<K[attr]> | null | undefined : K[attr];
|
|
12
|
+
};
|
|
13
|
+
declare type NoStringIndex<T> = {
|
|
14
|
+
[K in keyof T as string extends K ? never : K]: T[K];
|
|
15
|
+
};
|
|
16
|
+
declare type IUmiConfig = Omit<NoStringIndex<Parameters<typeof defineUmiConfig>[0]>, 'resolve' | 'extraRemarkPlugins' | 'extraRehypePlugins' | 'themeConfig'>;
|
|
12
17
|
interface IDumiExtendsConfig {
|
|
13
18
|
resolve: {
|
|
14
19
|
docDirs: (string | {
|
|
@@ -39,10 +44,13 @@ interface IDumiExtendsConfig {
|
|
|
39
44
|
extraRehypePlugins?: (string | Function | [string | Function, object])[];
|
|
40
45
|
}
|
|
41
46
|
export declare type IDumiConfig = IUmiConfig & IDumiExtendsConfig;
|
|
42
|
-
export
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
47
|
+
export declare type IDumiUserConfig = Subset<Omit<IDumiConfig, 'locales'>> & {
|
|
48
|
+
locales?: Exclude<IDumiConfig['locales'][0], {
|
|
49
|
+
base: string;
|
|
50
|
+
}>[] | Omit<Exclude<IDumiConfig['locales'][0], {
|
|
51
|
+
suffix: string;
|
|
52
|
+
}>, 'base'>[];
|
|
53
|
+
};
|
|
46
54
|
export declare abstract class IDumiTechStack {
|
|
47
55
|
/**
|
|
48
56
|
* tech stack name, such as 'react'
|
package/package.json
CHANGED
|
@@ -14,20 +14,40 @@
|
|
|
14
14
|
&[type='info'] {
|
|
15
15
|
color: @c-primary;
|
|
16
16
|
background: lighten(@c-primary, 40%);
|
|
17
|
+
|
|
18
|
+
@{dark-selector} & {
|
|
19
|
+
color: @c-primary;
|
|
20
|
+
background: darken(@c-primary-dark, 20%);
|
|
21
|
+
}
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
&[type='warning'] {
|
|
20
25
|
color: @c-warning;
|
|
21
26
|
background: lighten(@c-warning, 48%);
|
|
27
|
+
|
|
28
|
+
@{dark-selector} & {
|
|
29
|
+
color: @c-warning;
|
|
30
|
+
background: darken(@c-warning-dark, 20%);
|
|
31
|
+
}
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
&[type='success'] {
|
|
25
35
|
color: @c-success;
|
|
26
36
|
background: lighten(@c-success, 54%);
|
|
37
|
+
|
|
38
|
+
@{dark-selector} & {
|
|
39
|
+
color: @c-success;
|
|
40
|
+
background: darken(@c-success-dark, 9%);
|
|
41
|
+
}
|
|
27
42
|
}
|
|
28
43
|
|
|
29
44
|
&[type='error'] {
|
|
30
45
|
color: @c-error;
|
|
31
46
|
background: lighten(@c-error, 47%);
|
|
47
|
+
|
|
48
|
+
@{dark-selector} & {
|
|
49
|
+
color: @c-error;
|
|
50
|
+
background: darken(@c-error-dark, 18%);
|
|
51
|
+
}
|
|
32
52
|
}
|
|
33
53
|
}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
@import (reference) '../../styles/variables.less';
|
|
2
2
|
|
|
3
|
+
.container-colors(@bg-color, @title-color, @text-color) {
|
|
4
|
+
background: @bg-color;
|
|
5
|
+
|
|
6
|
+
> h4,
|
|
7
|
+
> svg {
|
|
8
|
+
color: @title-color;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
> section {
|
|
12
|
+
color: @text-color;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
3
16
|
.@{prefix}-container.markdown {
|
|
4
17
|
padding: 18px 0;
|
|
5
18
|
padding-inline-start: 44px;
|
|
@@ -39,60 +52,48 @@
|
|
|
39
52
|
&[data-type='info'] {
|
|
40
53
|
@color: darken(desaturate(@c-primary, 45%), 10%);
|
|
41
54
|
|
|
42
|
-
|
|
55
|
+
.container-colors(lighten(@c-primary, 42%), @color, desaturate(@color, 20%));
|
|
43
56
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
color: @color;
|
|
47
|
-
}
|
|
57
|
+
@{dark-selector} & {
|
|
58
|
+
@color: lighten(desaturate(@c-primary-dark, 45%), 20%);
|
|
48
59
|
|
|
49
|
-
|
|
50
|
-
color: desaturate(@color, 20%);
|
|
60
|
+
.container-colors(darken(@c-primary-dark, 26%), @color, desaturate(@color, 20%));
|
|
51
61
|
}
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
&[data-type='warning'] {
|
|
55
65
|
@color: darken(desaturate(@c-warning, 20%), 2%);
|
|
56
66
|
|
|
57
|
-
|
|
67
|
+
.container-colors(lighten(@c-warning, 51%), @color, desaturate(@color, 24%));
|
|
58
68
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
color: @color;
|
|
62
|
-
}
|
|
69
|
+
@{dark-selector} & {
|
|
70
|
+
@color: lighten(desaturate(@c-warning, 20%), 3%);
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
color: desaturate(@color, 24%);
|
|
72
|
+
.container-colors(darken(@c-warning-dark, 18%), @color, desaturate(@color, 20%));
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
&[data-type='success'] {
|
|
70
77
|
@color: darken(desaturate(@c-success, 5%), 1%);
|
|
71
78
|
|
|
72
|
-
|
|
79
|
+
.container-colors(lighten(@c-success, 59%), @color, desaturate(@color, 22%));
|
|
73
80
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
color: @color;
|
|
77
|
-
}
|
|
81
|
+
@{dark-selector} & {
|
|
82
|
+
@color: lighten(desaturate(@c-success, 5%), 5%);
|
|
78
83
|
|
|
79
|
-
|
|
80
|
-
color: desaturate(@color, 22%);
|
|
84
|
+
.container-colors(darken(@c-success-dark, 10%), @color, desaturate(@color, 20%));
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
&[data-type='error'] {
|
|
85
89
|
@color: darken(desaturate(@c-error, 20%), 1%);
|
|
86
90
|
|
|
87
|
-
|
|
91
|
+
.container-colors(lighten(@c-error, 51%), @color, desaturate(@color, 25%));
|
|
88
92
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
color: @color;
|
|
92
|
-
}
|
|
93
|
+
@{dark-selector} & {
|
|
94
|
+
@color: lighten(desaturate(@c-error, 20%), 5%);
|
|
93
95
|
|
|
94
|
-
|
|
95
|
-
color: desaturate(@color, 25%);
|
|
96
|
+
.container-colors(darken(@c-error-dark, 22%), @color, desaturate(@color, 20%));
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
}
|