feat: 修复 l7utils mini-adapter mixin 循环引用

This commit is contained in:
2912401452 2021-11-10 10:50:51 +08:00
parent f3390fab7c
commit f0efd3868f
2 changed files with 30 additions and 25 deletions

View File

@ -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';

View File

@ -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;