Browse Source

KERNEL-14041 feat: core/platform文件夹

es6
zsmj 2 years ago
parent
commit
2d645fa7e7
  1. 3
      package.json
  2. 559
      src/core/platform/web/config.js
  3. 590
      src/core/platform/web/detectElementResize.js
  4. 1472
      src/core/platform/web/dom.js
  5. 285
      src/core/platform/web/function.js
  6. 4
      src/core/platform/web/index.js
  7. 107
      src/core/platform/web/load.js

3
package.json

@ -12,6 +12,7 @@
"@babel/polyfill": "7.6.0", "@babel/polyfill": "7.6.0",
"@fui/babel-preset-fineui": "^2.0.0", "@fui/babel-preset-fineui": "^2.0.0",
"@fui/eslint-plugin": "^1.0.19", "@fui/eslint-plugin": "^1.0.19",
"@juggle/resize-observer": "^3.4.0",
"@types/node": "15.6.1", "@types/node": "15.6.1",
"@typescript-eslint/eslint-plugin": "2.33.0", "@typescript-eslint/eslint-plugin": "2.33.0",
"@typescript-eslint/parser": "2.33.0", "@typescript-eslint/parser": "2.33.0",
@ -91,4 +92,4 @@
"@types/yargs": "17.0.13", "@types/yargs": "17.0.13",
"yargs": "17.6.2" "yargs": "17.6.2"
} }
} }

559
src/core/platform/web/config.js

@ -1,286 +1,315 @@
import { Plugin } from "../../6.plugin";
// 工程配置 // 工程配置
!(function () { // 注册布局
// 注册布局 // adapt类布局优先级规则
// adapt类布局优先级规则 // 1、支持flex的浏览器下使用flex布局
// 1、支持flex的浏览器下使用flex布局 // 2、不支持flex的浏览器下使用inline布局
// 2、不支持flex的浏览器下使用inline布局 // 3、当列宽既需要自动列宽又需要自适应列宽时,inline布局也处理不了了。当横向出滚动条时使用table布局,不出滚动条时使用float布局
// 3、当列宽既需要自动列宽又需要自适应列宽时,inline布局也处理不了了。当横向出滚动条时使用table布局,不出滚动条时使用float布局 let _isSupportFlex, _isSupportGrid;
var _isSupportFlex, _isSupportGrid;
var isSupportFlex = function () {
if (_isSupportFlex == null) {
_isSupportFlex = !!(BI.isSupportCss3 && BI.isSupportCss3("flex"));
}
return _isSupportFlex;
};
var isSupportGrid = function () {
if (_isSupportGrid == null) {
_isSupportGrid = !!(BI.isSupportCss3 && BI.isSupportCss3("grid"));
}
return _isSupportGrid;
};
// 判断浏览器是否支持sticky 属性
var isSupportSticky = (function () {
var vendorList = ["", "-webkit-", "-ms-", "-moz-", "-o-"],
vendorListLength = vendorList.length,
stickyElement = document.createElement("div");
for (var i = 0; i < vendorListLength; i++) {
stickyElement.style.position = vendorList[i] + "sticky";
if (stickyElement.style.position !== "") {
return true;
}
}
return false;
})();
BI.Plugin.configWidget("bi.horizontal", function (ob) {
var supportFlex = isSupportFlex();
// // 在横向自适应场景下我们需要使用table的自适应撑出滚动条的特性(flex处理不了这种情况)
// // 主要出现在center_adapt或者horizontal_adapt的场景,或者主动设置horizontalAlign的场景
// if (ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch) {
// return BI.extend({}, ob, {type: "bi.table_adapt"});
// }
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_horizontal" });
}
return BI.extend({
scrollx: true
}, ob, { type: "bi.inline" });
});
BI.Plugin.configWidget("bi.vertical", function (ob) {
if (ob.horizontalAlign === BI.HorizontalAlign.Left || ob.horizontalAlign === BI.HorizontalAlign.Right) {
if (isSupportFlex()) {
return BI.extend({}, ob, { type: "bi.flex_vertical" });
}
return BI.extend({}, ob, {
horizontalAlign: BI.HorizontalAlign.Stretch,
type: "bi.vertical",
items: BI.map(ob.items, function (i, item) {
return {
type: "bi.inline",
horizontalAlign: ob.horizontalAlign,
items: [item]
};
})
});
}
if (ob.verticalAlign === BI.VerticalAlign.Stretch) {
if (isSupportFlex()) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch,
}, ob, { type: "bi.flex_vertical" });
}
}
return ob;
});
BI.Plugin.configWidget("bi.inline", function (ob) {
// 当列宽既需要自动列宽又需要自适应列宽时,inline布局也处理不了了,降级table处理吧
var hasAutoAndFillColumnSize = false;
if (ob.columnSize && ob.columnSize.length > 0) {
if ((ob.columnSize.indexOf("") >= 0 || ob.columnSize.indexOf("auto") >= 0) && ob.columnSize.indexOf("fill") >= 0) {
hasAutoAndFillColumnSize = true;
}
} else {
var hasAuto = false, hasFill = false;
BI.each(ob.items, function (i, item) {
if (item.width === "fill") {
hasFill = true;
} else if (BI.isNull(item.width) || item.width === "" || item.width === "auto") {
hasAuto = true;
}
});
hasAutoAndFillColumnSize = hasAuto && hasFill;
}
if (hasAutoAndFillColumnSize) { function isSupportFlex() {
// 宽度是不是受限 if (!_isSupportFlex) {
if ((ob.scrollable !== true && ob.scrollx !== true) || ob.horizontalAlign === BI.HorizontalAlign.Stretch) { _isSupportFlex = !!(BI.isSupportCss3 && BI.isSupportCss3("flex"));
return BI.extend({ }
verticalAlign: BI.VerticalAlign.Top
}, ob, { type: "bi.horizontal_float_fill" }); return _isSupportFlex;
} }
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch function isSupportGrid() {
}, ob, { type: "bi.table_adapt" }); if (!_isSupportGrid) {
} _isSupportGrid = !!(BI.isSupportCss3 && BI.isSupportCss3("grid"));
if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) { }
return BI.extend({}, ob, { type: "bi.responsive_inline" });
} return _isSupportGrid;
return ob; }
});
BI.Plugin.configWidget("bi.center_adapt", function (ob) {
var supportFlex = isSupportFlex();
// var isAdapt = !ob.horizontalAlign || ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
// if (!isAdapt || justOneItem) {
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_center_adapt" });
}
return BI.extend({}, ob, { type: "bi.inline_center_adapt" });
// }
// return ob;
});
BI.Plugin.configWidget("bi.vertical_adapt", function (ob) {
var supportFlex = isSupportFlex();
// var isAdapt = ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
// if (!isAdapt || justOneItem) {
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_vertical_center_adapt" });
}
return BI.extend({}, ob, { type: "bi.inline_vertical_adapt" });
// }
// return ob;
});
BI.Plugin.configWidget("bi.horizontal_adapt", function (ob) {
var justOneItem = (ob.items && ob.items.length <= 1);
var isAdapt = !ob.horizontalAlign || ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
var verticalAlignTop = !ob.verticalAlign || ob.verticalAlign === BI.VerticalAlign.TOP;
if (verticalAlignTop && justOneItem) {
return BI.extend({}, ob, { type: "bi.horizontal_auto" });
}
var supportFlex = isSupportFlex();
// 在横向自适应场景下我们需要使用table的自适应撑出滚动条的特性(flex处理不了这种情况)
// 主要出现在center_adapt或者horizontal_adapt的场景,或者主动设置horizontalAlign的场景
if (isAdapt) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center
}, ob, { type: "bi.table_adapt" });
}
if (supportFlex) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center,
scrollx: false
}, ob, { type: "bi.flex_horizontal" });
}
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center
}, ob, { type: "bi.table_adapt" });
});
BI.Plugin.configWidget("bi.horizontal_float", function (ob) {
if (isSupportFlex()) {
return BI.extend({}, ob, { type: "bi.flex_horizontal_adapt" });
}
if (ob.items && ob.items.length <= 1) {
return BI.extend({}, ob, { type: "bi.inline_horizontal_adapt" });
}
return ob;
});
BI.Plugin.configWidget("bi.horizontal_fill", function (ob) { // 判断浏览器是否支持sticky 属性
const isSupportSticky = (function () {
const vendorList = ["", "-webkit-", "-ms-", "-moz-", "-o-"],
vendorListLength = vendorList.length,
stickyElement = document.createElement("div");
for (let i = 0; i < vendorListLength; i++) {
stickyElement.style.position = `${vendorList[i]}sticky`;
if (stickyElement.style.position !== "") {
return true;
}
}
return false;
}());
const configWidget = Plugin.configWidget;
configWidget("bi.horizontal", ob => {
const supportFlex = isSupportFlex();
// // 在横向自适应场景下我们需要使用table的自适应撑出滚动条的特性(flex处理不了这种情况)
// // 主要出现在center_adapt或者horizontal_adapt的场景,或者主动设置horizontalAlign的场景
// if (ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch) {
// return BI.extend({}, ob, {type: "bi.table_adapt"});
// }
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_horizontal" });
}
return BI.extend({
scrollx: true,
}, ob, { type: "bi.inline" });
});
configWidget("bi.vertical", ob => {
if (ob.horizontalAlign === BI.HorizontalAlign.Left || ob.horizontalAlign === BI.HorizontalAlign.Right) {
if (isSupportFlex()) { if (isSupportFlex()) {
return BI.extend({ return BI.extend({}, ob, { type: "bi.flex_vertical" });
horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch,
scrollx: false
}, ob, { type: "bi.flex_horizontal" });
}
if ((ob.horizontalAlign && ob.horizontalAlign !== BI.HorizontalAlign.Stretch) || (ob.scrollable === true || ob.scrollx === true)) {
// 宽度不受限,要用table布局
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch
}, ob, { type: "bi.table_adapt" });
} }
return BI.extend({}, ob, { type: "bi.horizontal_float_fill" });
}); return BI.extend({}, ob, {
BI.Plugin.configWidget("bi.vertical_fill", function (ob) { horizontalAlign: BI.HorizontalAlign.Stretch,
type: "bi.vertical",
items: BI.map(ob.items, (i, item) => {
return {
type: "bi.inline",
horizontalAlign: ob.horizontalAlign,
items: [item],
};
}),
});
}
if (ob.verticalAlign === BI.VerticalAlign.Stretch) {
if (isSupportFlex()) { if (isSupportFlex()) {
return BI.extend({ return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch, horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch,
scrolly: false
}, ob, { type: "bi.flex_vertical" }); }, ob, { type: "bi.flex_vertical" });
} }
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) { }
// 有滚动条,降级到table布局处理
return BI.extend({}, ob, { return ob;
type: "bi.td", });
items: BI.map(ob.items, function (i, item) { configWidget("bi.inline", ob => {
return [item]; // 当列宽既需要自动列宽又需要自适应列宽时,inline布局也处理不了了,降级table处理吧
}) let hasAutoAndFillColumnSize = false;
}); if (ob.columnSize && ob.columnSize.length > 0) {
} if ((ob.columnSize.indexOf("") >= 0 || ob.columnSize.indexOf("auto") >= 0) && ob.columnSize.indexOf("fill") >= 0) {
var hasAuto = false; hasAutoAndFillColumnSize = true;
if (ob.rowSize && ob.rowSize.length > 0) { }
if (ob.rowSize.indexOf("") >= 0 || ob.rowSize.indexOf("auto") >= 0) { } else {
let hasAuto = false, hasFill = false;
BI.each(ob.items, (i, item) => {
if (item.width === "fill") {
hasFill = true;
} else if (BI.isNull(item.width) || item.width === "" || item.width === "auto") {
hasAuto = true; hasAuto = true;
} }
} else { });
BI.each(ob.items, function (i, item) { hasAutoAndFillColumnSize = hasAuto && hasFill;
if (BI.isNull(item.height) || item.height === "") { }
hasAuto = true;
}
});
}
if (hasAuto) {
// 有自动高的时候
return BI.extend({}, ob, { type: "bi.vtape_auto" });
}
return BI.extend({}, ob, { type: "bi.vtape" });
});
BI.Plugin.configWidget("bi.horizontal_sticky", function (ob) {
if (!isSupportSticky) {
return BI.extend({ scrollx: true }, ob, { type: "bi.horizontal_fill" });
}
});
BI.Plugin.configWidget("bi.vertical_sticky", function (ob) {
if (!isSupportSticky) {
return BI.extend({ scrolly: true }, ob, { type: "bi.vertical_fill" });
}
});
BI.Plugin.configWidget("bi.left_right_vertical_adapt", function (ob) { if (hasAutoAndFillColumnSize) {
if (isSupportFlex()) { // 宽度是不是受限
// IE下其实也是可以使用flex布局的,只要排除掉出现滚动条的情况 if ((ob.scrollable !== true && ob.scrollx !== true) || ob.horizontalAlign === BI.HorizontalAlign.Stretch) {
// if (!BI.isIE() || (ob.scrollable !== true && ob.scrolly !== true)) { return BI.extend({
return BI.extend({}, ob, { type: "bi.flex_left_right_vertical_adapt" }); verticalAlign: BI.VerticalAlign.Top,
// } }, ob, { type: "bi.horizontal_float_fill" });
} }
return ob;
}); return BI.extend({
BI.Plugin.configWidget("bi.flex_horizontal", function (ob) { horizontalAlign: BI.HorizontalAlign.Stretch,
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) { }, ob, { type: "bi.table_adapt" });
if (ob.hgap > 0 || ob.lgap > 0 || ob.rgap > 0) { }
if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) { if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) {
return BI.extend({}, ob, { type: "bi.responsive_flex_scrollable_horizontal" }); return BI.extend({}, ob, { type: "bi.responsive_inline" });
} }
return BI.extend({}, ob, { type: "bi.flex_scrollable_horizontal" });
return ob;
});
configWidget("bi.center_adapt", ob => {
const supportFlex = isSupportFlex();
// var isAdapt = !ob.horizontalAlign || ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
// if (!isAdapt || justOneItem) {
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_center_adapt" });
}
return BI.extend({}, ob, { type: "bi.inline_center_adapt" });
// }
// return ob;
});
configWidget("bi.vertical_adapt", ob => {
const supportFlex = isSupportFlex();
// var isAdapt = ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
// if (!isAdapt || justOneItem) {
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_vertical_center_adapt" });
}
return BI.extend({}, ob, { type: "bi.inline_vertical_adapt" });
// }
// return ob;
});
configWidget("bi.horizontal_adapt", ob => {
const justOneItem = (ob.items && ob.items.length <= 1);
const isAdapt = !ob.horizontalAlign || ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
const verticalAlignTop = !ob.verticalAlign || ob.verticalAlign === BI.VerticalAlign.TOP;
if (verticalAlignTop && justOneItem) {
return BI.extend({}, ob, { type: "bi.horizontal_auto" });
}
const supportFlex = isSupportFlex();
// 在横向自适应场景下我们需要使用table的自适应撑出滚动条的特性(flex处理不了这种情况)
// 主要出现在center_adapt或者horizontal_adapt的场景,或者主动设置horizontalAlign的场景
if (isAdapt) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center,
}, ob, { type: "bi.table_adapt" });
}
if (supportFlex) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center,
scrollx: false,
}, ob, { type: "bi.flex_horizontal" });
}
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center,
}, ob, { type: "bi.table_adapt" });
});
configWidget("bi.horizontal_float", ob => {
if (isSupportFlex()) {
return BI.extend({}, ob, { type: "bi.flex_horizontal_adapt" });
}
if (ob.items && ob.items.length <= 1) {
return BI.extend({}, ob, { type: "bi.inline_horizontal_adapt" });
}
return ob;
});
configWidget("bi.horizontal_fill", ob => {
if (isSupportFlex()) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch,
scrollx: false,
}, ob, { type: "bi.flex_horizontal" });
}
if ((ob.horizontalAlign && ob.horizontalAlign !== BI.HorizontalAlign.Stretch) || (ob.scrollable === true || ob.scrollx === true)) {
// 宽度不受限,要用table布局
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch,
}, ob, { type: "bi.table_adapt" });
}
return BI.extend({}, ob, { type: "bi.horizontal_float_fill" });
});
configWidget("bi.vertical_fill", ob => {
if (isSupportFlex()) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch,
scrolly: false,
}, ob, { type: "bi.flex_vertical" });
}
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) {
// 有滚动条,降级到table布局处理
return BI.extend({}, ob, {
type: "bi.td",
items: BI.map(ob.items, (i, item) => [item]),
});
}
let hasAuto = false;
if (ob.rowSize && ob.rowSize.length > 0) {
if (ob.rowSize.indexOf("") >= 0 || ob.rowSize.indexOf("auto") >= 0) {
hasAuto = true;
}
} else {
BI.each(ob.items, (i, item) => {
if (BI.isNull(item.height) || item.height === "") {
hasAuto = true;
} }
} });
if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) { }
return BI.extend({}, ob, { type: "bi.responsive_flex_horizontal" }); if (hasAuto) {
} // 有自动高的时候
}); return BI.extend({}, ob, { type: "bi.vtape_auto" });
BI.Plugin.configWidget("bi.flex_vertical", function (ob) { }
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) {
if (ob.hgap > 0 || ob.lgap > 0 || ob.rgap > 0) { return BI.extend({}, ob, { type: "bi.vtape" });
return BI.extend({}, ob, { type: "bi.flex_scrollable_vertical" }); });
configWidget("bi.horizontal_sticky", ob => {
if (!isSupportSticky) {
return BI.extend({ scrollx: true }, ob, { type: "bi.horizontal_fill" });
}
});
configWidget("bi.vertical_sticky", ob => {
if (!isSupportSticky) {
return BI.extend({ scrolly: true }, ob, { type: "bi.vertical_fill" });
}
});
configWidget("bi.left_right_vertical_adapt", ob => {
if (isSupportFlex()) {
// IE下其实也是可以使用flex布局的,只要排除掉出现滚动条的情况
// if (!BI.isIE() || (ob.scrollable !== true && ob.scrolly !== true)) {
return BI.extend({}, ob, { type: "bi.flex_left_right_vertical_adapt" });
// }
}
return ob;
});
configWidget("bi.flex_horizontal", ob => {
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) {
if (ob.hgap > 0 || ob.lgap > 0 || ob.rgap > 0) {
if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) {
return BI.extend({}, ob, { type: "bi.responsive_flex_scrollable_horizontal" });
} }
}
});
BI.Plugin.configWidget("bi.table", function (ob) { return BI.extend({}, ob, { type: "bi.flex_scrollable_horizontal" });
if (!isSupportGrid()) { }
return BI.extend({}, ob, { type: "bi.td" }); }
} if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) {
return ob; return BI.extend({}, ob, { type: "bi.responsive_flex_horizontal" });
}); }
});
configWidget("bi.flex_vertical", ob => {
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) {
if (ob.hgap > 0 || ob.lgap > 0 || ob.rgap > 0) {
return BI.extend({}, ob, { type: "bi.flex_scrollable_vertical" });
}
}
});
BI.Plugin.configWidget("bi.radio", function (ob) { configWidget("bi.table", ob => {
if (BI.isIE() && BI.getIEVersion() <= 9) { if (!isSupportGrid()) {
return BI.extend({}, ob, { type: "bi.image_radio" }); return BI.extend({}, ob, { type: "bi.td" });
} }
return ob;
});
BI.Plugin.configWidget("bi.checkbox", function (ob) { return ob;
if (BI.isIE() && BI.getIEVersion() <= 9) { });
return BI.extend({}, ob, { type: "bi.image_checkbox" });
} configWidget("bi.radio", ob => {
if (BI.isIE() && BI.getIEVersion() <= 9) {
return BI.extend({}, ob, { type: "bi.image_radio" });
}
return ob;
});
configWidget("bi.checkbox", ob => {
if (BI.isIE() && BI.getIEVersion() <= 9) {
return BI.extend({}, ob, { type: "bi.image_checkbox" });
}
return ob;
});
configWidget("bi.half_icon_button", ob => {
if (BI.isIE() && BI.getIEVersion() < 9) {
return ob; return ob;
}); }
return BI.extend({}, ob, { type: "bi.half_button" });
});
BI.Plugin.configWidget("bi.half_icon_button", function (ob) {
if (BI.isIE() && BI.getIEVersion() < 9) {
return ob;
}
return BI.extend({}, ob, { type: "bi.half_button" });
});
}());

590
src/core/platform/web/detectElementResize.js

@ -1,571 +1,15 @@
/** import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
* Detect Element Resize.
* A minimal library which polyfills the ResizeObserver API and is entirely based on the latest Draft Specification.
* https://github.com/juggle/resize-observer
* version: 3.4.0
**/
var ResizeObserverPolyfill = (function (exports) {
'use strict';
var resizeObservers = []; const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
var hasActiveObservations = function () { function addResizeListener(element, fn) {
return resizeObservers.some(function (ro) {
return ro.activeTargets.length > 0;
});
};
var hasSkippedObservations = function () {
return resizeObservers.some(function (ro) {
return ro.skippedTargets.length > 0;
});
};
var msg = 'ResizeObserver loop completed with undelivered notifications.';
var deliverResizeLoopError = function () {
var event;
if (typeof ErrorEvent === 'function') {
event = new ErrorEvent('error', {
message: msg
});
} else {
event = document.createEvent('Event');
event.initEvent('error', false, false);
event.message = msg;
}
window.dispatchEvent(event);
};
var ResizeObserverBoxOptions;
(function (ResizeObserverBoxOptions) {
ResizeObserverBoxOptions["BORDER_BOX"] = "border-box";
ResizeObserverBoxOptions["CONTENT_BOX"] = "content-box";
ResizeObserverBoxOptions["DEVICE_PIXEL_CONTENT_BOX"] = "device-pixel-content-box";
})(ResizeObserverBoxOptions || (ResizeObserverBoxOptions = {}));
var freeze = function (obj) {
return Object.freeze(obj);
};
var ResizeObserverSize = (function () {
function ResizeObserverSize(inlineSize, blockSize) {
this.inlineSize = inlineSize;
this.blockSize = blockSize;
freeze(this);
}
return ResizeObserverSize;
}());
var DOMRectReadOnly = (function () {
function DOMRectReadOnly(x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.top = this.y;
this.left = this.x;
this.bottom = this.top + this.height;
this.right = this.left + this.width;
return freeze(this);
}
DOMRectReadOnly.prototype.toJSON = function () {
var _a = this, x = _a.x, y = _a.y, top = _a.top, right = _a.right, bottom = _a.bottom, left = _a.left,
width = _a.width, height = _a.height;
return { x: x, y: y, top: top, right: right, bottom: bottom, left: left, width: width, height: height };
};
DOMRectReadOnly.fromRect = function (rectangle) {
return new DOMRectReadOnly(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
};
return DOMRectReadOnly;
}());
var isSVG = function (target) {
return target instanceof SVGElement && 'getBBox' in target;
};
var isHidden = function (target) {
if (isSVG(target)) {
var _a = target.getBBox(), width = _a.width, height = _a.height;
return !width && !height;
}
var _b = target, offsetWidth = _b.offsetWidth, offsetHeight = _b.offsetHeight;
return !(offsetWidth || offsetHeight || target.getClientRects().length);
};
var isElement = function (obj) {
var _a;
if (obj instanceof Element) {
return true;
}
var scope = (_a = obj === null || obj === void 0 ? void 0 : obj.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
return !!(scope && obj instanceof scope.Element);
};
var isReplacedElement = function (target) {
switch (target.tagName) {
case 'INPUT':
if (target.type !== 'image') {
break;
}
case 'VIDEO':
case 'AUDIO':
case 'EMBED':
case 'OBJECT':
case 'CANVAS':
case 'IFRAME':
case 'IMG':
return true;
}
return false;
};
var global = typeof window !== 'undefined' ? window : {};
var cache = new WeakMap();
var scrollRegexp = /auto|scroll/;
var verticalRegexp = /^tb|vertical/;
var IE = (/msie|trident/i).test(global.navigator && global.navigator.userAgent);
var parseDimension = function (pixel) {
return parseFloat(pixel || '0');
};
var size = function (inlineSize, blockSize, switchSizes) {
if (inlineSize === void 0) {
inlineSize = 0;
}
if (blockSize === void 0) {
blockSize = 0;
}
if (switchSizes === void 0) {
switchSizes = false;
}
return new ResizeObserverSize((switchSizes ? blockSize : inlineSize) || 0, (switchSizes ? inlineSize : blockSize) || 0);
};
var zeroBoxes = freeze({
devicePixelContentBoxSize: size(),
borderBoxSize: size(),
contentBoxSize: size(),
contentRect: new DOMRectReadOnly(0, 0, 0, 0)
});
var calculateBoxSizes = function (target, forceRecalculation) {
if (forceRecalculation === void 0) {
forceRecalculation = false;
}
if (cache.has(target) && !forceRecalculation) {
return cache.get(target);
}
if (isHidden(target)) {
cache.set(target, zeroBoxes);
return zeroBoxes;
}
var cs = getComputedStyle(target);
var svg = isSVG(target) && target.ownerSVGElement && target.getBBox();
var removePadding = !IE && cs.boxSizing === 'border-box';
var switchSizes = verticalRegexp.test(cs.writingMode || '');
var canScrollVertically = !svg && scrollRegexp.test(cs.overflowY || '');
var canScrollHorizontally = !svg && scrollRegexp.test(cs.overflowX || '');
var paddingTop = svg ? 0 : parseDimension(cs.paddingTop);
var paddingRight = svg ? 0 : parseDimension(cs.paddingRight);
var paddingBottom = svg ? 0 : parseDimension(cs.paddingBottom);
var paddingLeft = svg ? 0 : parseDimension(cs.paddingLeft);
var borderTop = svg ? 0 : parseDimension(cs.borderTopWidth);
var borderRight = svg ? 0 : parseDimension(cs.borderRightWidth);
var borderBottom = svg ? 0 : parseDimension(cs.borderBottomWidth);
var borderLeft = svg ? 0 : parseDimension(cs.borderLeftWidth);
var horizontalPadding = paddingLeft + paddingRight;
var verticalPadding = paddingTop + paddingBottom;
var horizontalBorderArea = borderLeft + borderRight;
var verticalBorderArea = borderTop + borderBottom;
var horizontalScrollbarThickness = !canScrollHorizontally ? 0 : target.offsetHeight - verticalBorderArea - target.clientHeight;
var verticalScrollbarThickness = !canScrollVertically ? 0 : target.offsetWidth - horizontalBorderArea - target.clientWidth;
var widthReduction = removePadding ? horizontalPadding + horizontalBorderArea : 0;
var heightReduction = removePadding ? verticalPadding + verticalBorderArea : 0;
var contentWidth = svg ? svg.width : parseDimension(cs.width) - widthReduction - verticalScrollbarThickness;
var contentHeight = svg ? svg.height : parseDimension(cs.height) - heightReduction - horizontalScrollbarThickness;
var borderBoxWidth = contentWidth + horizontalPadding + verticalScrollbarThickness + horizontalBorderArea;
var borderBoxHeight = contentHeight + verticalPadding + horizontalScrollbarThickness + verticalBorderArea;
var boxes = freeze({
devicePixelContentBoxSize: size(Math.round(contentWidth * devicePixelRatio), Math.round(contentHeight * devicePixelRatio), switchSizes),
borderBoxSize: size(borderBoxWidth, borderBoxHeight, switchSizes),
contentBoxSize: size(contentWidth, contentHeight, switchSizes),
contentRect: new DOMRectReadOnly(paddingLeft, paddingTop, contentWidth, contentHeight)
});
cache.set(target, boxes);
return boxes;
};
var calculateBoxSize = function (target, observedBox, forceRecalculation) {
var _a = calculateBoxSizes(target, forceRecalculation), borderBoxSize = _a.borderBoxSize,
contentBoxSize = _a.contentBoxSize, devicePixelContentBoxSize = _a.devicePixelContentBoxSize;
switch (observedBox) {
case ResizeObserverBoxOptions.DEVICE_PIXEL_CONTENT_BOX:
return devicePixelContentBoxSize;
case ResizeObserverBoxOptions.BORDER_BOX:
return borderBoxSize;
default:
return contentBoxSize;
}
};
var ResizeObserverEntry = (function () {
function ResizeObserverEntry(target) {
var boxes = calculateBoxSizes(target);
this.target = target;
this.contentRect = boxes.contentRect;
this.borderBoxSize = freeze([boxes.borderBoxSize]);
this.contentBoxSize = freeze([boxes.contentBoxSize]);
this.devicePixelContentBoxSize = freeze([boxes.devicePixelContentBoxSize]);
}
return ResizeObserverEntry;
}());
var calculateDepthForNode = function (node) {
if (isHidden(node)) {
return Infinity;
}
var depth = 0;
var parent = node.parentNode;
while (parent) {
depth += 1;
parent = parent.parentNode;
}
return depth;
};
var broadcastActiveObservations = function () {
var shallowestDepth = Infinity;
var callbacks = [];
resizeObservers.forEach(function processObserver(ro) {
if (ro.activeTargets.length === 0) {
return;
}
var entries = [];
ro.activeTargets.forEach(function processTarget(ot) {
var entry = new ResizeObserverEntry(ot.target);
var targetDepth = calculateDepthForNode(ot.target);
entries.push(entry);
ot.lastReportedSize = calculateBoxSize(ot.target, ot.observedBox);
if (targetDepth < shallowestDepth) {
shallowestDepth = targetDepth;
}
});
callbacks.push(function resizeObserverCallback() {
ro.callback.call(ro.observer, entries, ro.observer);
});
ro.activeTargets.splice(0, ro.activeTargets.length);
});
for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
var callback = callbacks_1[_i];
callback();
}
return shallowestDepth;
};
var gatherActiveObservationsAtDepth = function (depth) {
resizeObservers.forEach(function processObserver(ro) {
ro.activeTargets.splice(0, ro.activeTargets.length);
ro.skippedTargets.splice(0, ro.skippedTargets.length);
ro.observationTargets.forEach(function processTarget(ot) {
if (ot.isActive()) {
if (calculateDepthForNode(ot.target) > depth) {
ro.activeTargets.push(ot);
} else {
ro.skippedTargets.push(ot);
}
}
});
});
};
var process = function () {
var depth = 0;
gatherActiveObservationsAtDepth(depth);
while (hasActiveObservations()) {
depth = broadcastActiveObservations();
gatherActiveObservationsAtDepth(depth);
}
if (hasSkippedObservations()) {
deliverResizeLoopError();
}
return depth > 0;
};
var trigger;
var callbacks = [];
var notify = function () {
return callbacks.splice(0).forEach(function (cb) {
return cb();
});
};
var queueMicroTask = function (callback) {
if (!trigger) {
var toggle_1 = 0;
var el_1 = document.createTextNode('');
var config = { characterData: true };
new MutationObserver(function () {
return notify();
}).observe(el_1, config);
trigger = function () {
el_1.textContent = "".concat(toggle_1 ? toggle_1-- : toggle_1++);
};
}
callbacks.push(callback);
trigger();
};
var queueResizeObserver = function (cb) {
queueMicroTask(function ResizeObserver() {
requestAnimationFrame(cb);
});
};
var watching = 0;
var isWatching = function () {
return !!watching;
};
var CATCH_PERIOD = 250;
var observerConfig = { attributes: true, characterData: true, childList: true, subtree: true };
var events = [
'resize',
'load',
'transitionend',
'animationend',
'animationstart',
'animationiteration',
'keyup',
'keydown',
'mouseup',
'mousedown',
'mouseover',
'mouseout',
'blur',
'focus'
];
var time = function (timeout) {
if (timeout === void 0) {
timeout = 0;
}
return Date.now() + timeout;
};
var scheduled = false;
var Scheduler = (function () {
function Scheduler() {
var _this = this;
this.stopped = true;
this.listener = function () {
return _this.schedule();
};
}
Scheduler.prototype.run = function (timeout) {
var _this = this;
if (timeout === void 0) {
timeout = CATCH_PERIOD;
}
if (scheduled) {
return;
}
scheduled = true;
var until = time(timeout);
queueResizeObserver(function () {
var elementsHaveResized = false;
try {
elementsHaveResized = process();
} finally {
scheduled = false;
timeout = until - time();
if (!isWatching()) {
return;
}
if (elementsHaveResized) {
_this.run(1000);
} else if (timeout > 0) {
_this.run(timeout);
} else {
_this.start();
}
}
});
};
Scheduler.prototype.schedule = function () {
this.stop();
this.run();
};
Scheduler.prototype.observe = function () {
var _this = this;
var cb = function () {
return _this.observer && _this.observer.observe(document.body, observerConfig);
};
document.body ? cb() : global.addEventListener('DOMContentLoaded', cb);
};
Scheduler.prototype.start = function () {
var _this = this;
if (this.stopped) {
this.stopped = false;
this.observer = new MutationObserver(this.listener);
this.observe();
events.forEach(function (name) {
return global.addEventListener(name, _this.listener, true);
});
}
};
Scheduler.prototype.stop = function () {
var _this = this;
if (!this.stopped) {
this.observer && this.observer.disconnect();
events.forEach(function (name) {
return global.removeEventListener(name, _this.listener, true);
});
this.stopped = true;
}
};
return Scheduler;
}());
var scheduler = new Scheduler();
var updateCount = function (n) {
!watching && n > 0 && scheduler.start();
watching += n;
!watching && scheduler.stop();
};
var skipNotifyOnElement = function (target) {
return !isSVG(target)
&& !isReplacedElement(target)
&& getComputedStyle(target).display === 'inline';
};
var ResizeObservation = (function () {
function ResizeObservation(target, observedBox) {
this.target = target;
this.observedBox = observedBox || ResizeObserverBoxOptions.CONTENT_BOX;
this.lastReportedSize = {
inlineSize: -1,
blockSize: -1
};
}
ResizeObservation.prototype.isActive = function () {
var size = calculateBoxSize(this.target, this.observedBox, true);
if (skipNotifyOnElement(this.target)) {
this.lastReportedSize = size;
}
if (this.lastReportedSize.inlineSize !== size.inlineSize
|| this.lastReportedSize.blockSize !== size.blockSize) {
return true;
}
return false;
};
return ResizeObservation;
}());
var ResizeObserverDetail = (function () {
function ResizeObserverDetail(resizeObserver, callback) {
this.activeTargets = [];
this.skippedTargets = [];
this.observationTargets = [];
this.observer = resizeObserver;
this.callback = callback;
}
return ResizeObserverDetail;
}());
var observerMap = new WeakMap();
var getObservationIndex = function (observationTargets, target) {
for (var i = 0; i < observationTargets.length; i += 1) {
if (observationTargets[i].target === target) {
return i;
}
}
return -1;
};
var ResizeObserverController = (function () {
function ResizeObserverController() {
}
ResizeObserverController.connect = function (resizeObserver, callback) {
var detail = new ResizeObserverDetail(resizeObserver, callback);
observerMap.set(resizeObserver, detail);
};
ResizeObserverController.observe = function (resizeObserver, target, options) {
var detail = observerMap.get(resizeObserver);
var firstObservation = detail.observationTargets.length === 0;
if (getObservationIndex(detail.observationTargets, target) < 0) {
firstObservation && resizeObservers.push(detail);
detail.observationTargets.push(new ResizeObservation(target, options && options.box));
updateCount(1);
scheduler.schedule();
}
};
ResizeObserverController.unobserve = function (resizeObserver, target) {
var detail = observerMap.get(resizeObserver);
var index = getObservationIndex(detail.observationTargets, target);
var lastObservation = detail.observationTargets.length === 1;
if (index >= 0) {
lastObservation && resizeObservers.splice(resizeObservers.indexOf(detail), 1);
detail.observationTargets.splice(index, 1);
updateCount(-1);
}
};
ResizeObserverController.disconnect = function (resizeObserver) {
var _this = this;
var detail = observerMap.get(resizeObserver);
detail.observationTargets.slice().forEach(function (ot) {
return _this.unobserve(resizeObserver, ot.target);
});
detail.activeTargets.splice(0, detail.activeTargets.length);
};
return ResizeObserverController;
}());
var ResizeObserver = (function () {
function ResizeObserver(callback) {
if (arguments.length === 0) {
throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");
}
if (typeof callback !== 'function') {
throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");
}
ResizeObserverController.connect(this, callback);
}
ResizeObserver.prototype.observe = function (target, options) {
if (arguments.length === 0) {
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");
}
if (!isElement(target)) {
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");
}
ResizeObserverController.observe(this, target, options);
};
ResizeObserver.prototype.unobserve = function (target) {
if (arguments.length === 0) {
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");
}
if (!isElement(target)) {
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");
}
ResizeObserverController.unobserve(this, target);
};
ResizeObserver.prototype.disconnect = function () {
ResizeObserverController.disconnect(this);
};
ResizeObserver.toString = function () {
return 'function ResizeObserver () { [polyfill code] }';
};
return ResizeObserver;
}());
return ResizeObserver;
})();
var ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
var addResizeListener = function (element, fn) {
if (ResizeObserver) { if (ResizeObserver) {
if (!element.__resizeObserver__) { if (!element.__resizeObserver__) {
var resizeObserver = new ResizeObserver(function () { const resizeObserver = new ResizeObserver((() => {
element.__resizeListeners__.forEach(function (listener) { element.__resizeListeners__.forEach(listener => {
BI.$(element).is(":visible") && listener(); BI.$(element).is(":visible") && listener();
}); });
}); }));
resizeObserver.observe(element); resizeObserver.observe(element);
element.__resizeObserver__ = resizeObserver; element.__resizeObserver__ = resizeObserver;
} }
@ -574,16 +18,18 @@ var addResizeListener = function (element, fn) {
} }
element.__resizeListeners__.push(fn); element.__resizeListeners__.push(fn);
} }
}; }
var removeResizeListener = function (element, fn) {
function removeResizeListener(element, fn) {
if (ResizeObserver) { if (ResizeObserver) {
if (BI.isNull(fn)) { if (BI.isNull(fn)) {
element.__resizeListeners__ = []; element.__resizeListeners__ = [];
element.__resizeObserver__ && element.__resizeObserver__.unobserve(element); element.__resizeObserver__ && element.__resizeObserver__.unobserve(element);
element.__resizeObserver__ = null; element.__resizeObserver__ = null;
return; return;
} }
var index = element.__resizeListeners__.indexOf(fn); const index = element.__resizeListeners__.indexOf(fn);
if (index >= 0) { if (index >= 0) {
element.__resizeListeners__.splice(index, 1); element.__resizeListeners__.splice(index, 1);
if (!element.__resizeListeners__.length) { if (!element.__resizeListeners__.length) {
@ -592,19 +38,17 @@ var removeResizeListener = function (element, fn) {
} }
} }
} }
}; }
export const ResizeDetector = { export const ResizeDetector = {
addResizeListener: function (widget, fn) { addResizeListener(widget, fn) {
addResizeListener(widget.element[0], fn); addResizeListener(widget.element[0], fn);
return function () { return function () {
removeResizeListener(widget.element[0], fn); removeResizeListener(widget.element[0], fn);
}; };
}, removeResizeListener: function (widget, fn) { },
removeResizeListener(widget, fn) {
removeResizeListener(widget.element[0], fn); removeResizeListener(widget.element[0], fn);
} },
}; };
Object.assign(BI, {
ResizeDetector
});

1472
src/core/platform/web/dom.js

File diff suppressed because it is too large Load Diff

285
src/core/platform/web/function.js

@ -1,151 +1,170 @@
// 浏览器相关方法 // 浏览器相关方法
BI._.extend(BI, { import { isString } from "../../2.base";
isIE: function () {
if(!_global.navigator) {
return false;
}
if (this.__isIE == null) {
this.__isIE = /(msie|trident)/i.test(navigator.userAgent.toLowerCase());
}
return this.__isIE;
},
getIEVersion: function () { let __isIE;
if(!_global.navigator) {
return 0;
}
if (this.__IEVersion != null) {
return this.__IEVersion;
}
var version = 0;
var agent = navigator.userAgent.toLowerCase();
var v1 = agent.match(/(?:msie\s([\w.]+))/);
var v2 = agent.match(/(?:trident.*rv:([\w.]+))/);
if (v1 && v2 && v1[1] && v2[1]) {
version = Math.max(v1[1] * 1, v2[1] * 1);
} else if (v1 && v1[1]) {
version = v1[1] * 1;
} else if (v2 && v2[1]) {
version = v2[1] * 1;
} else {
version = 0;
}
return this.__IEVersion = version;
},
isIE9Below: function () { export function isIE() {
if (!BI.isIE()) { if (!_global.navigator) {
return false; return false;
} }
return this.getIEVersion() < 9; if (!__isIE) {
}, __isIE = /(msie|trident)/i.test(navigator.userAgent.toLowerCase());
}
isEdge: function () { return __isIE;
if(!_global.navigator) { }
return false;
}
return /edg/i.test(navigator.userAgent.toLowerCase());
},
isChrome: function () { let __IEVersion;
if(!_global.navigator) {
return false;
}
return /chrome/i.test(navigator.userAgent.toLowerCase());
},
isFireFox: function () { export function getIEVersion() {
if(!_global.navigator) { if (!_global.navigator) {
return false; return 0;
} }
return /firefox/i.test(navigator.userAgent.toLowerCase()); if (__IEVersion) {
}, return __IEVersion;
}
let version = 0;
const agent = navigator.userAgent.toLowerCase();
const v1 = agent.match(/(?:msie\s([\w.]+))/);
const v2 = agent.match(/(?:trident.*rv:([\w.]+))/);
if (v1 && v2 && v1[1] && v2[1]) {
version = Math.max(v1[1] * 1, v2[1] * 1);
} else if (v1 && v1[1]) {
version = v1[1] * 1;
} else if (v2 && v2[1]) {
version = v2[1] * 1;
} else {
version = 0;
}
__IEVersion = version;
isOpera: function () { return __IEVersion;
if(!_global.navigator) { }
return false;
}
return /opera/i.test(navigator.userAgent.toLowerCase());
},
isSafari: function () { export function isIE9Below() {
if(!_global.navigator) { if (!isIE()) {
return false; return false;
} }
return /safari/i.test(navigator.userAgent.toLowerCase()) && !/chrome/i.test(navigator.userAgent.toLowerCase());
},
isKhtml: function () { return getIEVersion() < 9;
if(!_global.navigator) { }
return false;
}
return /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
},
isMac: function () { export function isEdge() {
if(!_global.navigator) { if (!_global.navigator) {
return false; return false;
} }
return /macintosh|mac os x/i.test(navigator.userAgent);
},
isWindows: function () { return /edg/i.test(navigator.userAgent.toLowerCase());
if(!_global.navigator) { }
return false;
}
return /windows|win32/i.test(navigator.userAgent);
},
isSupportCss3: function (style) { export function isChrome() {
if(!_global.document) { if (!_global.navigator) {
return false; return false;
} }
var prefix = ["webkit", "Moz", "ms", "o"],
i, len,
humpString = [],
htmlStyle = document.documentElement.style,
_toHumb = function (string) {
if (!BI.isString(string)) {
return "";
}
return string.replace(/-(\w)/g, function ($0, $1) {
return $1.toUpperCase();
});
};
for ( i = 0; i < prefix.length; i++) {
humpString.push(_toHumb(prefix[i] + "-" + style));
}
humpString.push(_toHumb(style));
for (i = 0, len = humpString.length; i < len; i++) { return /chrome/i.test(navigator.userAgent.toLowerCase());
if (humpString[i] in htmlStyle) { }
return true;
} export function isFireFox() {
} if (!_global.navigator) {
return false;
}
return /firefox/i.test(navigator.userAgent.toLowerCase());
}
export function isOpera() {
if (!_global.navigator) {
return false;
}
return /opera/i.test(navigator.userAgent.toLowerCase());
}
export function isSafari() {
if (!_global.navigator) {
return false;
}
return /safari/i.test(navigator.userAgent.toLowerCase()) && !/chrome/i.test(navigator.userAgent.toLowerCase());
}
export function isKhtml() {
if (!_global.navigator) {
return false;
}
return /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
}
export function isMac() {
if (!_global.navigator) {
return false;
}
return /macintosh|mac os x/i.test(navigator.userAgent);
}
export function isWindows() {
if (!_global.navigator) {
return false; return false;
}, }
return /windows|win32/i.test(navigator.userAgent);
}
export function isSupportCss3(style) {
if (!_global.document) {
return false;
}
const prefix = ["webkit", "Moz", "ms", "o"];
const humpString = [];
const htmlStyle = document.documentElement.style;
let i;
let len;
getSafariVersion: function () { function _toHumb(string) {
if (!_global.navigator) { if (!isString(string)) {
return 0; return "";
} }
var agent = navigator.userAgent.toLowerCase();
var version = agent.match(/version\/([\d.]+)/); return string.replace(/-(\w)/g, ($0, $1) => $1.toUpperCase());
if (version && version[1]) { };
return version[1] * 1;
for (i = 0; i < prefix.length; i++) {
humpString.push(_toHumb(`${prefix[i]}-${style}`));
}
humpString.push(_toHumb(style));
for (i = 0, len = humpString.length; i < len; i++) {
if (humpString[i] in htmlStyle) {
return true;
} }
}
return false;
}
export function getSafariVersion() {
if (!_global.navigator) {
return 0; return 0;
}, }
const agent = navigator.userAgent.toLowerCase();
getMinimumFontSize: function () { const version = agent.match(/version\/([\d.]+)/);
// not work for firefox if (version && version[1]) {
const el = document.createElement('div'); return version[1] * 1;
el.style.fontSize = "1px"; }
document.body.appendChild(el);
const size = getComputedStyle(el).fontSize; return 0;
el.remove(); }
return parseInt(size);
} export function getMinimumFontSize() {
}); // not work for firefox
const el = document.createElement("div");
el.style.fontSize = "1px";
document.body.appendChild(el);
const size = getComputedStyle(el).fontSize;
el.remove();
return parseInt(size, 10);
}

4
src/core/platform/web/index.js

@ -0,0 +1,4 @@
export * as DOM from "./dom";
export * from "./detectElementResize";
export * from "./function";
export * from "./load";

107
src/core/platform/web/load.js

@ -1,55 +1,56 @@
BI._.extend(BI, { const _LOADED = {}; // alex:保存加载过的
$import: function () { function loadReady(src, must) {
var _LOADED = {}; // alex:保存加载过的 const $scripts = BI.$("head script, body script");
function loadReady (src, must) { BI.$.each($scripts, (i, item) => {
var $scripts = BI.$("head script, body script"); if (item.src.indexOf(src) !== -1) {
BI.$.each($scripts, function (i, item) { _LOADED[src] = true;
if (item.src.indexOf(src) != -1) {
_LOADED[src] = true;
}
});
var $links = BI.$("head link");
BI.$.each($links, function (i, item) {
if (item.href.indexOf(src) != -1 && must) {
_LOADED[src] = false;
BI.$(item).remove();
}
});
} }
});
const $links = BI.$("head link");
BI.$.each($links, (i, item) => {
if (item.href.indexOf(src) !== -1 && must) {
_LOADED[src] = false;
BI.$(item).remove();
}
});
}
// must=true 强行加载 /**
return function (src, ext, must) { *
loadReady(src, must); * @param src
// alex:如果已经加载过了的,直接return * @param ext
if (_LOADED[src] === true) { * @param must 强行加载
return; */
} export function $import(src, ext, must) {
if (ext === "css") { loadReady(src, must);
var link = document.createElement("link"); // alex:如果已经加载过了的,直接return
link.rel = "stylesheet"; if (_LOADED[src] === true) {
link.type = "text/css"; return;
link.href = src; }
var head = document.getElementsByTagName("head")[0]; if (ext === "css") {
head.appendChild(link); const link = document.createElement("link");
_LOADED[src] = true; link.rel = "stylesheet";
} else { link.type = "text/css";
// alex:这里用同步调用的方式,必须等待ajax完成 link.href = src;
BI.$.ajax({ const head = document.getElementsByTagName("head")[0];
url: src, head.appendChild(link);
dataType: "script", // alex:指定dataType为script,jquery会帮忙做globalEval的事情 _LOADED[src] = true;
async: false, } else {
cache: true, // alex:这里用同步调用的方式,必须等待ajax完成
complete: function (res, status) { BI.$.ajax({
/* url: src,
* alex:发现jquery会很智能地判断一下返回的数据类型是不是script,然后做一个globalEval dataType: "script", // alex:指定dataType为script,jquery会帮忙做globalEval的事情
* 所以当status为success时就不需要再把其中的内容加到script里面去了 async: false,
*/ cache: true,
if (status == "success") { complete(res, status) {
_LOADED[src] = true; /*
} * alex:发现jquery会很智能地判断一下返回的数据类型是不是script,然后做一个globalEval
} * 所以当status为success时就不需要再把其中的内容加到script里面去了
}); */
} if (status === "success") {
}; _LOADED[src] = true;
}() }
}); },
});
}
}

Loading…
Cancel
Save