Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/utils/is-browser.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
let _isBrowser: boolean | undefined;
let IS_BROWSER: true | undefined;

export function isBrowser(): boolean {
if (_isBrowser !== undefined) {
return _isBrowser;
}
if (IS_BROWSER) return true;

if (typeof window === 'undefined' || typeof document === 'undefined') {
_isBrowser = false;
return false;
}

const body = document.body;
if (!body) {
_isBrowser = false;
return false;
}

Expand Down Expand Up @@ -47,7 +43,6 @@ export function isBrowser(): boolean {
}

if (!hasRealLayout) {
_isBrowser = false;
return false;
}

Expand All @@ -59,7 +54,6 @@ export function isBrowser(): boolean {

const ctx = canvas.getContext('2d');
if (!ctx) {
_isBrowser = false;
return false;
}

Expand All @@ -74,6 +68,6 @@ export function isBrowser(): boolean {
hasRealCanvas = false;
}

_isBrowser = hasRealCanvas;
if (hasRealCanvas) IS_BROWSER = hasRealCanvas;
return hasRealCanvas;
}
5 changes: 1 addition & 4 deletions src/utils/measure-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import { JSXNode, TextProps } from '../jsx';
import { DEFAULT_FONT } from '../renderer';
import { encodeFontFamily } from './font';
import { isBrowser } from './is-browser';
import { isNode } from './is-node';

let FONT_EXTEND_FACTOR = 1.01;

export const setFontExtendFactor = (factor: number) => {
FONT_EXTEND_FACTOR = factor;
};

if (isNode) {
registerFont(AlibabaPuHuiTi);
}
registerFont(AlibabaPuHuiTi);

let canvasContext: CanvasRenderingContext2D | null = null;
let measureSpan: HTMLSpanElement | null = null;
Expand Down