@blocklet/editor 2.5.44 → 2.5.46
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.
|
@@ -2,11 +2,12 @@ import { css } from '@emotion/css';
|
|
|
2
2
|
import { useTheme } from '@mui/material';
|
|
3
3
|
import defaultTheme from './defaultTheme';
|
|
4
4
|
import codeHighlight from './code-highlight';
|
|
5
|
+
import { isHeadFontTooTall, isBodyFontTooTall } from '../utils/guard';
|
|
5
6
|
const createCustomTheme = (theme) => {
|
|
6
7
|
const noMarginTopStyle = css(`
|
|
7
|
-
// 首个元素的 margin-top 设置为 0
|
|
8
|
+
// 首个元素的 margin-top 设置为 0 或者为 “超高” 字体预留一点空间
|
|
8
9
|
.be-editable &:first-child {
|
|
9
|
-
margin-top: 0;
|
|
10
|
+
margin-top: ${isHeadFontTooTall || isBodyFontTooTall ? '2px' : '0'};
|
|
10
11
|
}
|
|
11
12
|
`);
|
|
12
13
|
const paragraph = css(
|
|
@@ -6,3 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
export declare function isHTMLElement(x: unknown): x is HTMLElement;
|
|
9
|
+
/**
|
|
10
|
+
* Determines if the specified font is too tall
|
|
11
|
+
*/
|
|
12
|
+
export declare function isFontTooTall(fontFamily: string): boolean;
|
|
13
|
+
export declare const isHeadFontTooTall: boolean;
|
|
14
|
+
export declare const isBodyFontTooTall: boolean;
|
package/lib/main/utils/guard.js
CHANGED
|
@@ -8,3 +8,29 @@
|
|
|
8
8
|
export function isHTMLElement(x) {
|
|
9
9
|
return x instanceof HTMLElement;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Determines if the specified font is too tall
|
|
13
|
+
*/
|
|
14
|
+
export function isFontTooTall(fontFamily) {
|
|
15
|
+
const fontSizePx = 16;
|
|
16
|
+
const threshold = 1.1;
|
|
17
|
+
const container = document.createElement('div');
|
|
18
|
+
container.style.fontSize = `${fontSizePx}px`;
|
|
19
|
+
container.style.fontFamily = fontFamily;
|
|
20
|
+
container.style.opacity = '0';
|
|
21
|
+
container.style.whiteSpace = 'nowrap';
|
|
22
|
+
container.style.position = 'absolute';
|
|
23
|
+
container.style.pointerEvents = 'none';
|
|
24
|
+
const span = document.createElement('span');
|
|
25
|
+
span.textContent = 'Éy';
|
|
26
|
+
container.appendChild(span);
|
|
27
|
+
document.body.appendChild(container);
|
|
28
|
+
const renderHeight = span.getBoundingClientRect().height;
|
|
29
|
+
document.body.removeChild(container);
|
|
30
|
+
return renderHeight > fontSizePx * threshold;
|
|
31
|
+
}
|
|
32
|
+
const typography = window?.blocklet?.theme?.common?.typography;
|
|
33
|
+
const headFont = typography?.h1?.fontFamily;
|
|
34
|
+
const bodyFont = typography?.fontFamily;
|
|
35
|
+
export const isHeadFontTooTall = headFont ? isFontTooTall(headFont) : false;
|
|
36
|
+
export const isBodyFontTooTall = bodyFont ? isFontTooTall(bodyFont) : false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/editor",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.46",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"ufo": "^1.5.4",
|
|
74
74
|
"url-join": "^4.0.1",
|
|
75
75
|
"zustand": "^4.5.5",
|
|
76
|
-
"@blocklet/pdf": "2.5.
|
|
76
|
+
"@blocklet/pdf": "2.5.46"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@babel/core": "^7.25.2",
|