From f0efd3868f32a5995bda460ab810922bb417689d Mon Sep 17 00:00:00 2001 From: 2912401452 <2912401452@qq.com> Date: Wed, 10 Nov 2021 10:50:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=20l7utils=20mini-ada?= =?UTF-8?q?pter=20mixin=20=E5=BE=AA=E7=8E=AF=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/utils/src/mini-adapter/index.ts | 3 +- packages/utils/src/mini-adapter/util/mixin.ts | 52 ++++++++++--------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/packages/utils/src/mini-adapter/index.ts b/packages/utils/src/mini-adapter/index.ts index b3ae9af75c..1e30cda963 100644 --- a/packages/utils/src/mini-adapter/index.ts +++ b/packages/utils/src/mini-adapter/index.ts @@ -84,6 +84,7 @@ export const $window = isMini ? miniWindow : globalWindow; export const $XMLHttpRequest = isMini ? XMLHttpRequest: globalWindow.XMLHttpRequest; export const $location = isMini ? location : globalWindow.location; -export { registerCanvas, registerCanvas2D } from './register'; +// TODO: +// export { registerCanvas, registerCanvas2D } from './register'; export * from './EventIniter/index'; diff --git a/packages/utils/src/mini-adapter/util/mixin.ts b/packages/utils/src/mini-adapter/util/mixin.ts index 30dfdd76f0..adf3425af8 100644 --- a/packages/utils/src/mini-adapter/util/mixin.ts +++ b/packages/utils/src/mini-adapter/util/mixin.ts @@ -1,60 +1,64 @@ -// @ts-nocheck -// tslint:disable import { screen } from '../screen'; const { availWidth: innerWidth, availHeight: innerHeight } = screen; -import { document } from '../document'; +const documentElement = { + style: [], +}; -export function parentNode(obj, level?: number) { +export function parentNode(obj: any, level?: number) { if (!('parentNode' in obj)) { - let _parent; + let parent; if (level === 0) { - _parent = function() { + parent = () => { // return document return null; }; } else if (level === 1) { - _parent = function() { - return document.documentElement; + parent = () => { + // return document.documentElement; + return documentElement; }; } else { - _parent = function() { - return document.body; + parent = () => { + // return document.body; + return null; }; } Object.defineProperty(obj, 'parentNode', { enumerable: true, - get: _parent, + get: parent, }); } if (!('parentElement' in obj)) { - let _parent; + let parent; if (level === 0) { - _parent = function() { + parent = () => { return null; }; } else if (level === 1) { - _parent = function() { - return document.documentElement; + parent = () => { + // return document.documentElement; + return documentElement; }; } else { - _parent = function() { - return document.body; + parent = () => { + // return document.body; + return null; }; } Object.defineProperty(obj, 'parentElement', { enumerable: true, - get: _parent, + get: parent, }); } } -export function style(obj) { +export function style(obj: any) { obj.style = obj.style || {}; Object.assign(obj.style, { @@ -67,7 +71,7 @@ export function style(obj) { }); } -export function clientRegion(obj) { +export function clientRegion(obj: any) { if (!('clientLeft' in obj)) { obj.clientLeft = 0; obj.clientTop = 0; @@ -95,7 +99,7 @@ export function clientRegion(obj) { } } -export function offsetRegion(obj) { +export function offsetRegion(obj: any) { if (!('offsetLeft' in obj)) { obj.offsetLeft = 0; obj.offsetTop = 0; @@ -106,7 +110,7 @@ export function offsetRegion(obj) { } } -export function scrollRegion(obj) { +export function scrollRegion(obj: any) { if (!('scrollLeft' in obj)) { obj.scrollLeft = 0; obj.scrollTop = 0; @@ -117,8 +121,8 @@ export function scrollRegion(obj) { } } -export function classList(obj) { - const noop = function() {}; +export function classList(obj: any) { + const noop = () => true; obj.classList = []; obj.classList.add = noop; obj.classList.remove = noop;