2755 lines
82 KiB
JavaScript
2755 lines
82 KiB
JavaScript
import { isHTMLTag, isSVGTag, isVoidTag, hyphenate, camelize, normalizeStyle as normalizeStyle$1, isString, parseStringStyle, isArray, normalizeClass as normalizeClass$1, isFunction, extend, isPlainObject as isPlainObject$1, capitalize, makeMap } from '@vue/shared';
|
||
|
||
const BUILT_IN_TAG_NAMES = [
|
||
'ad',
|
||
'ad-content-page',
|
||
'ad-draw',
|
||
'audio',
|
||
'button',
|
||
'camera',
|
||
'canvas',
|
||
'checkbox',
|
||
'checkbox-group',
|
||
'cover-image',
|
||
'cover-view',
|
||
'editor',
|
||
'form',
|
||
'functional-page-navigator',
|
||
'icon',
|
||
'image',
|
||
'input',
|
||
'label',
|
||
'live-player',
|
||
'live-pusher',
|
||
'map',
|
||
'movable-area',
|
||
'movable-view',
|
||
'navigator',
|
||
'official-account',
|
||
'open-data',
|
||
'picker',
|
||
'picker-view',
|
||
'picker-view-column',
|
||
'progress',
|
||
'radio',
|
||
'radio-group',
|
||
'rich-text',
|
||
'scroll-view',
|
||
'slider',
|
||
'swiper',
|
||
'swiper-item',
|
||
'switch',
|
||
'text',
|
||
'textarea',
|
||
'video',
|
||
'view',
|
||
'web-view',
|
||
'location-picker',
|
||
'location-view',
|
||
];
|
||
const BUILT_IN_TAGS = BUILT_IN_TAG_NAMES.map((tag) => 'uni-' + tag);
|
||
const H5_BUILT_IN_TAG_NAMES = BUILT_IN_TAG_NAMES.filter((tag) => tag !== 'audio');
|
||
const H5_BUILT_IN_TAGS = H5_BUILT_IN_TAG_NAMES.map((tag) => 'uni-' + tag);
|
||
const TAGS = [
|
||
'app',
|
||
'layout',
|
||
'content',
|
||
'main',
|
||
'top-window',
|
||
'left-window',
|
||
'right-window',
|
||
'tabbar',
|
||
'page',
|
||
'page-head',
|
||
'page-wrapper',
|
||
'page-body',
|
||
'page-refresh',
|
||
'actionsheet',
|
||
'modal',
|
||
'toast',
|
||
'resize-sensor',
|
||
'shadow-root',
|
||
].map((tag) => 'uni-' + tag);
|
||
const NVUE_BUILT_IN_TAGS = [
|
||
'svg',
|
||
'view',
|
||
'a',
|
||
'div',
|
||
'img',
|
||
'image',
|
||
'text',
|
||
'span',
|
||
'input',
|
||
'textarea',
|
||
'spinner',
|
||
'select',
|
||
// slider 被自定义 u-slider 替代
|
||
// 'slider',
|
||
'slider-neighbor',
|
||
'indicator',
|
||
'canvas',
|
||
'list',
|
||
'cell',
|
||
'header',
|
||
'loading',
|
||
'loading-indicator',
|
||
'refresh',
|
||
'scrollable',
|
||
'scroller',
|
||
'video',
|
||
'web',
|
||
'embed',
|
||
'tabbar',
|
||
'tabheader',
|
||
'datepicker',
|
||
'timepicker',
|
||
'marquee',
|
||
'countdown',
|
||
'dc-switch',
|
||
'waterfall',
|
||
'richtext',
|
||
'recycle-list',
|
||
'u-scalable',
|
||
'barcode',
|
||
'gcanvas',
|
||
];
|
||
const UVUE_BUILT_IN_TAGS = [
|
||
'ad',
|
||
'ad-content-page',
|
||
'ad-draw',
|
||
'native-view',
|
||
'loading-indicator',
|
||
'list-view',
|
||
'list-item',
|
||
'swiper',
|
||
'swiper-item',
|
||
// 已经交由 vue 实现
|
||
// 'rich-text',
|
||
// android 平台 type=native 时原生实现
|
||
'rich-text-native',
|
||
'sticky-view',
|
||
'sticky-header',
|
||
'sticky-section',
|
||
// 自定义
|
||
'uni-slider',
|
||
// 原生实现
|
||
'button',
|
||
'nested-scroll-header',
|
||
'nested-scroll-body',
|
||
'waterflow',
|
||
'flow-item',
|
||
'share-element',
|
||
'cover-view',
|
||
'cover-image',
|
||
// custom element
|
||
'match-media',
|
||
// 'checkbox',
|
||
// 'checkbox-group',
|
||
// 'form',
|
||
// 'navigator',
|
||
// 'picker-view',
|
||
// 'picker-view-column',
|
||
// 'progress',
|
||
// 'slider',
|
||
// 'switch',
|
||
// 'radio',
|
||
// 'radio-group',
|
||
];
|
||
const UVUE_WEB_BUILT_IN_TAGS = [
|
||
'page-container',
|
||
'list-view',
|
||
'list-item',
|
||
'sticky-section',
|
||
'sticky-header',
|
||
'cloud-db-element',
|
||
'loading-element',
|
||
'loading',
|
||
].map((tag) => 'uni-' + tag);
|
||
const UVUE_MP_BUILT_IN_TAGS = [
|
||
'list-view',
|
||
'list-item',
|
||
'sticky-section',
|
||
'sticky-header',
|
||
'cloud-db-element',
|
||
'loading-element',
|
||
].map((tag) => 'uni-' + tag);
|
||
const UVUE_IOS_BUILT_IN_TAGS = [
|
||
'scroll-view',
|
||
'web-view',
|
||
'slider',
|
||
'form',
|
||
'switch',
|
||
];
|
||
const UVUE_HARMONY_BUILT_IN_TAGS = [
|
||
// TODO 列出完整列表
|
||
...BUILT_IN_TAG_NAMES,
|
||
'volume-panel',
|
||
];
|
||
const NVUE_U_BUILT_IN_TAGS = [
|
||
'u-text',
|
||
'u-image',
|
||
'u-input',
|
||
'u-textarea',
|
||
'u-video',
|
||
'u-web-view',
|
||
'u-slider',
|
||
'u-ad',
|
||
'u-ad-draw',
|
||
'u-rich-text',
|
||
];
|
||
const UVUE_WEB_BUILT_IN_CUSTOM_ELEMENTS = ['match-media'];
|
||
const UNI_UI_CONFLICT_TAGS = ['list-item'].map((tag) => 'uni-' + tag);
|
||
function isBuiltInComponent(tag) {
|
||
if (UNI_UI_CONFLICT_TAGS.indexOf(tag) !== -1) {
|
||
return false;
|
||
}
|
||
// h5 平台会被转换为 v-uni-
|
||
const realTag = 'uni-' + tag.replace('v-uni-', '');
|
||
if (process.env.UNI_APP_X !== 'true') {
|
||
return BUILT_IN_TAGS.indexOf(realTag) !== -1;
|
||
}
|
||
return (BUILT_IN_TAGS.indexOf(realTag) !== -1 ||
|
||
UVUE_WEB_BUILT_IN_TAGS.indexOf(realTag) !== -1);
|
||
}
|
||
function isWebBuiltInComponent(tag) {
|
||
if (UNI_UI_CONFLICT_TAGS.indexOf(tag) !== -1) {
|
||
return false;
|
||
}
|
||
// h5 平台会被转换为 v-uni-
|
||
const realTag = 'uni-' + tag.replace('v-uni-', '');
|
||
if (process.env.UNI_APP_X !== 'true') {
|
||
return H5_BUILT_IN_TAGS.indexOf(realTag) !== -1;
|
||
}
|
||
return (H5_BUILT_IN_TAGS.indexOf(realTag) !== -1 ||
|
||
UVUE_WEB_BUILT_IN_TAGS.indexOf(realTag) !== -1);
|
||
}
|
||
function isMPBuiltInComponent(tag) {
|
||
if (UNI_UI_CONFLICT_TAGS.indexOf(tag) !== -1) {
|
||
return false;
|
||
}
|
||
// h5 平台会被转换为 v-uni-
|
||
const realTag = 'uni-' + tag.replace('v-uni-', '');
|
||
// TODO 区分x和非x
|
||
return (BUILT_IN_TAGS.indexOf(realTag) !== -1 ||
|
||
UVUE_MP_BUILT_IN_TAGS.indexOf(realTag) !== -1);
|
||
}
|
||
function isH5CustomElement(tag, isX = false) {
|
||
if (isX && UVUE_WEB_BUILT_IN_TAGS.indexOf(tag) !== -1) {
|
||
return true;
|
||
}
|
||
return TAGS.indexOf(tag) !== -1 || H5_BUILT_IN_TAGS.indexOf(tag) !== -1;
|
||
}
|
||
function isUniXElement(name) {
|
||
return /^I?Uni.*Element(?:Impl)?$/.test(name);
|
||
}
|
||
function isH5NativeTag(tag) {
|
||
return (tag !== 'head' &&
|
||
(isHTMLTag(tag) || isSVGTag(tag)) &&
|
||
!isWebBuiltInComponent(tag));
|
||
}
|
||
function isAppNativeTag(tag) {
|
||
return isHTMLTag(tag) || isSVGTag(tag) || isBuiltInComponent(tag);
|
||
}
|
||
const NVUE_CUSTOM_COMPONENTS = [
|
||
'ad',
|
||
'ad-draw',
|
||
'button',
|
||
'checkbox-group',
|
||
'checkbox',
|
||
'form',
|
||
'icon',
|
||
'label',
|
||
'movable-area',
|
||
'movable-view',
|
||
'navigator',
|
||
'picker',
|
||
'progress',
|
||
'radio-group',
|
||
'radio',
|
||
'rich-text',
|
||
'swiper-item',
|
||
'swiper',
|
||
'switch',
|
||
'slider',
|
||
'picker-view',
|
||
'picker-view-column',
|
||
];
|
||
const UNI_AD_PLUGINS = ['uniad-plugin', 'uniad-plugin-wx'];
|
||
// 内置的easycom组件
|
||
const UVUE_BUILT_IN_EASY_COMPONENTS = [
|
||
'map',
|
||
'camera',
|
||
'live-player',
|
||
'live-pusher',
|
||
'loading',
|
||
'web-view',
|
||
'rich-text',
|
||
'page-container',
|
||
'editor',
|
||
'video',
|
||
];
|
||
function isAppUVueBuiltInEasyComponent(tag) {
|
||
return UVUE_BUILT_IN_EASY_COMPONENTS.includes(tag);
|
||
}
|
||
// 主要是指前端实现的组件列表
|
||
const UVUE_CUSTOM_COMPONENTS = [
|
||
...NVUE_CUSTOM_COMPONENTS,
|
||
...UVUE_BUILT_IN_EASY_COMPONENTS,
|
||
];
|
||
function isAppUVueNativeTag(tag) {
|
||
// 前端实现的内置组件都会注册一个根组件
|
||
if (tag.startsWith('uni-') && tag.endsWith('-element')) {
|
||
return true;
|
||
}
|
||
if (UVUE_BUILT_IN_TAGS.includes(tag)) {
|
||
return true;
|
||
}
|
||
if (UVUE_CUSTOM_COMPONENTS.includes(tag)) {
|
||
return false;
|
||
}
|
||
if (isBuiltInComponent(tag)) {
|
||
return true;
|
||
}
|
||
// u-text,u-video...
|
||
if (NVUE_U_BUILT_IN_TAGS.includes(tag)) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
// dom1 ios端 vue 实现的组件
|
||
const IOS_DOM1_VUE_COMPONENTS = ['match-media'];
|
||
function isAppIOSUVueNativeTag(tag) {
|
||
// 前端实现的内置组件都会注册一个根组件
|
||
if (tag.startsWith('uni-') && tag.endsWith('-element')) {
|
||
return true;
|
||
}
|
||
if (IOS_DOM1_VUE_COMPONENTS.includes(tag)) {
|
||
return false;
|
||
}
|
||
if (UVUE_BUILT_IN_EASY_COMPONENTS.includes(tag)) {
|
||
return false;
|
||
}
|
||
if (NVUE_BUILT_IN_TAGS.includes(tag)) {
|
||
return true;
|
||
}
|
||
// TODO
|
||
if ([
|
||
'checkbox',
|
||
'checkbox-group',
|
||
'form',
|
||
'picker-view',
|
||
'picker-view-column',
|
||
'progress',
|
||
'switch',
|
||
'radio',
|
||
'radio-group',
|
||
].includes(tag)) {
|
||
return true;
|
||
}
|
||
if (
|
||
// && tag != 'navigator' && tag != 'slider'
|
||
UVUE_BUILT_IN_TAGS.includes(tag)) {
|
||
return true;
|
||
}
|
||
if (UVUE_IOS_BUILT_IN_TAGS.includes(tag)) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
const UVUE_BUILT_IN_EASY_COMPONENTS_HARMONY = [
|
||
'video',
|
||
'map',
|
||
'loading',
|
||
'rich-text',
|
||
'editor',
|
||
];
|
||
function isAppHarmonyUVueNativeTag(tag) {
|
||
if (UVUE_BUILT_IN_EASY_COMPONENTS_HARMONY.includes(tag)) {
|
||
return false;
|
||
}
|
||
// 前端实现的内置组件都会注册一个根组件
|
||
if (tag.startsWith('uni-') && tag.endsWith('-element')) {
|
||
return true;
|
||
}
|
||
if (NVUE_BUILT_IN_TAGS.includes(tag)) {
|
||
return true;
|
||
}
|
||
if (UVUE_BUILT_IN_TAGS.includes(tag)) {
|
||
return true;
|
||
}
|
||
if (UVUE_HARMONY_BUILT_IN_TAGS.includes(tag)) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
function isAppNVueNativeTag(tag) {
|
||
if (NVUE_BUILT_IN_TAGS.includes(tag)) {
|
||
return true;
|
||
}
|
||
if (NVUE_CUSTOM_COMPONENTS.includes(tag)) {
|
||
return false;
|
||
}
|
||
if (isBuiltInComponent(tag)) {
|
||
return true;
|
||
}
|
||
// u-text,u-video...
|
||
if (NVUE_U_BUILT_IN_TAGS.includes(tag)) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
function isMiniProgramNativeTag(tag) {
|
||
return isBuiltInComponent(tag);
|
||
}
|
||
function isMiniProgramUVueNativeTag(tag) {
|
||
// 小程序平台内置的自定义元素,会被转换为 view
|
||
if (tag.startsWith('uni-') && tag.endsWith('-element')) {
|
||
return true;
|
||
}
|
||
return isMPBuiltInComponent(tag);
|
||
}
|
||
function createIsCustomElement(tags = []) {
|
||
return function isCustomElement(tag) {
|
||
return tags.includes(tag);
|
||
};
|
||
}
|
||
function isComponentTag(tag) {
|
||
return tag[0].toLowerCase() + tag.slice(1) === 'component';
|
||
}
|
||
const COMPONENT_SELECTOR_PREFIX = 'uni-';
|
||
const COMPONENT_PREFIX = 'v-' + COMPONENT_SELECTOR_PREFIX;
|
||
// TODO 是否还存在其他需要特殊处理的 void 标签?
|
||
const APP_VOID_TAGS = ['textarea'];
|
||
function isAppVoidTag(tag) {
|
||
return APP_VOID_TAGS.includes(tag) || isVoidTag(tag);
|
||
}
|
||
|
||
const LINEFEED = '\n';
|
||
const NAVBAR_HEIGHT = 44;
|
||
const TABBAR_HEIGHT = 50;
|
||
const ON_REACH_BOTTOM_DISTANCE = 50;
|
||
const RESPONSIVE_MIN_WIDTH = 768;
|
||
const UNI_STORAGE_LOCALE = 'UNI_LOCALE';
|
||
// quickapp-webview 不能使用 default 作为插槽名称
|
||
const SLOT_DEFAULT_NAME = 'd';
|
||
const COMPONENT_NAME_PREFIX = 'VUni';
|
||
const I18N_JSON_DELIMITERS = ['%', '%'];
|
||
const PRIMARY_COLOR = '#007aff';
|
||
const SELECTED_COLOR = '#0062cc'; // 选中的颜色,如选项卡默认的选中颜色
|
||
const BACKGROUND_COLOR = '#f7f7f7'; // 背景色,如标题栏默认背景色
|
||
const UNI_SSR = '__uniSSR';
|
||
const UNI_SSR_TITLE = 'title';
|
||
const UNI_SSR_STORE = 'store';
|
||
const UNI_SSR_DATA = 'data';
|
||
const UNI_SSR_GLOBAL_DATA = 'globalData';
|
||
const SCHEME_RE = /^([a-z-]+:)?\/\//i;
|
||
const DATA_RE = /^data:.*,.*/;
|
||
const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE';
|
||
const WXS_PROTOCOL = 'wxs://';
|
||
const JSON_PROTOCOL = 'json://';
|
||
const WXS_MODULES = 'wxsModules';
|
||
const RENDERJS_MODULES = 'renderjsModules';
|
||
// lifecycle
|
||
// App and Page
|
||
const ON_SHOW = 'onShow';
|
||
const ON_HIDE = 'onHide';
|
||
//App
|
||
const ON_LAUNCH = 'onLaunch';
|
||
const ON_ERROR = 'onError';
|
||
const ON_THEME_CHANGE = 'onThemeChange';
|
||
const OFF_THEME_CHANGE = 'offThemeChange';
|
||
const ON_HOST_THEME_CHANGE = 'onHostThemeChange';
|
||
const OFF_HOST_THEME_CHANGE = 'offHostThemeChange';
|
||
const ON_KEYBOARD_HEIGHT_CHANGE = 'onKeyboardHeightChange';
|
||
const ON_PAGE_NOT_FOUND = 'onPageNotFound';
|
||
const ON_UNHANDLE_REJECTION = 'onUnhandledRejection';
|
||
const ON_LAST_PAGE_BACK_PRESS = 'onLastPageBackPress';
|
||
const ON_EXIT = 'onExit';
|
||
//Page
|
||
const ON_LOAD = 'onLoad';
|
||
const ON_READY = 'onReady';
|
||
const ON_UNLOAD = 'onUnload';
|
||
// 百度特有
|
||
const ON_INIT = 'onInit';
|
||
// 微信特有
|
||
const ON_SAVE_EXIT_STATE = 'onSaveExitState';
|
||
// 抖音特有
|
||
const ON_UPLOAD_DOUYIN_VIDEO = 'onUploadDouyinVideo';
|
||
const ON_LIVE_MOUNT = 'onLiveMount';
|
||
// 支付宝特有
|
||
const ON_TITLE_CLICK = 'onTitleClick';
|
||
const ON_RESIZE = 'onResize';
|
||
const ON_BACK_PRESS = 'onBackPress';
|
||
const ON_PAGE_SCROLL = 'onPageScroll';
|
||
const ON_TAB_ITEM_TAP = 'onTabItemTap';
|
||
const ON_REACH_BOTTOM = 'onReachBottom';
|
||
const ON_PULL_DOWN_REFRESH = 'onPullDownRefresh';
|
||
const ON_SHARE_TIMELINE = 'onShareTimeline';
|
||
const ON_SHARE_CHAT = 'onShareChat'; // xhs-share
|
||
const ON_COPY_URL = 'onCopyUrl';
|
||
const ON_ADD_TO_FAVORITES = 'onAddToFavorites';
|
||
const ON_SHARE_APP_MESSAGE = 'onShareAppMessage';
|
||
// navigationBar
|
||
const ON_NAVIGATION_BAR_BUTTON_TAP = 'onNavigationBarButtonTap';
|
||
const ON_NAVIGATION_BAR_CHANGE = 'onNavigationBarChange';
|
||
const ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED = 'onNavigationBarSearchInputClicked';
|
||
const ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED = 'onNavigationBarSearchInputChanged';
|
||
const ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED = 'onNavigationBarSearchInputConfirmed';
|
||
const ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED = 'onNavigationBarSearchInputFocusChanged';
|
||
// framework
|
||
const ON_APP_ENTER_FOREGROUND = 'onAppEnterForeground';
|
||
const ON_APP_ENTER_BACKGROUND = 'onAppEnterBackground';
|
||
const ON_WEB_INVOKE_APP_SERVICE = 'onWebInvokeAppService';
|
||
const ON_WXS_INVOKE_CALL_METHOD = 'onWxsInvokeCallMethod';
|
||
// mergeVirtualHostAttributes
|
||
const VIRTUAL_HOST_STYLE = 'virtualHostStyle';
|
||
const VIRTUAL_HOST_CLASS = 'virtualHostClass';
|
||
const VIRTUAL_HOST_HIDDEN = 'virtualHostHidden';
|
||
const VIRTUAL_HOST_ID = 'virtualHostId';
|
||
// mini program css variables
|
||
const UNI_STATUS_BAR_HEIGHT = 'u_s_b_h';
|
||
const UNI_SAFE_AREA_INSET_BOTTOM = 'u_s_a_i_b';
|
||
|
||
function arrayPop(array) {
|
||
if (array.length === 0) {
|
||
return null;
|
||
}
|
||
return array.pop();
|
||
}
|
||
function arrayShift(array) {
|
||
if (array.length === 0) {
|
||
return null;
|
||
}
|
||
return array.shift();
|
||
}
|
||
function arrayFind(array, predicate) {
|
||
const index = array.findIndex(predicate);
|
||
if (index < 0) {
|
||
return null;
|
||
}
|
||
return array[index];
|
||
}
|
||
function arrayFindLast(array, predicate) {
|
||
const index = array.findLastIndex(predicate);
|
||
if (index < 0) {
|
||
return null;
|
||
}
|
||
return array[index];
|
||
}
|
||
function arrayAt(array, index) {
|
||
if (index < -array.length || index >= array.length) {
|
||
return null;
|
||
}
|
||
return array.at(index);
|
||
}
|
||
|
||
/**
|
||
* copy from @uts/shared
|
||
*/
|
||
const UTS_CLASS_METADATA_KIND_LIST = [0, 1, 2];
|
||
|
||
function getType(val) {
|
||
return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
|
||
}
|
||
function isPlainObject(val) {
|
||
if (val == null || typeof val !== 'object') {
|
||
return false;
|
||
}
|
||
const proto = Object.getPrototypeOf(val);
|
||
return proto === Object.prototype || proto === null;
|
||
}
|
||
|
||
// TODO 实现UTSError
|
||
class UTSError extends Error {
|
||
constructor(message) {
|
||
super(message);
|
||
}
|
||
}
|
||
|
||
function isUTSMetadata(metadata) {
|
||
return !!(metadata &&
|
||
UTS_CLASS_METADATA_KIND_LIST.includes(metadata.kind) &&
|
||
metadata.interfaces);
|
||
}
|
||
function isNativeType(proto) {
|
||
return !proto || proto === Object.prototype;
|
||
}
|
||
const utsMetadataKey = "$UTSMetadata$" /* IDENTIFIER.UTS_METADATA */;
|
||
/**
|
||
* 处理复杂的继承关系。
|
||
* 例如:
|
||
* class A extends abstract class B,abstract class B implements interface C
|
||
* new A() instanceof C -> true
|
||
*/
|
||
function getParentTypeList(type) {
|
||
const metadata = utsMetadataKey in type ? type[utsMetadataKey] : {};
|
||
let interfaces = [];
|
||
if (!isUTSMetadata(metadata)) {
|
||
interfaces = [];
|
||
}
|
||
else {
|
||
interfaces = metadata.interfaces || [];
|
||
}
|
||
const proto = Object.getPrototypeOf(type);
|
||
if (!isNativeType(proto)) {
|
||
interfaces.push(proto.constructor);
|
||
}
|
||
return interfaces;
|
||
}
|
||
function isImplementationOf(leftType, rightType, visited = []) {
|
||
if (isNativeType(leftType)) {
|
||
return false;
|
||
}
|
||
if (leftType === rightType) {
|
||
return true;
|
||
}
|
||
visited.push(leftType);
|
||
const parentTypeList = getParentTypeList(leftType);
|
||
return parentTypeList.some((parentType) => {
|
||
if (visited.includes(parentType)) {
|
||
return false;
|
||
}
|
||
return isImplementationOf(parentType, rightType, visited);
|
||
});
|
||
}
|
||
function isInstanceOf(value, type) {
|
||
if (type === UTSValueIterable) {
|
||
return value && value[Symbol.iterator];
|
||
}
|
||
const isNativeInstanceofType = value instanceof type;
|
||
if (isNativeInstanceofType || typeof value !== 'object' || value === null) {
|
||
return isNativeInstanceofType;
|
||
}
|
||
const proto = Object.getPrototypeOf(value).constructor;
|
||
return isImplementationOf(proto, type);
|
||
}
|
||
function isBaseType(type) {
|
||
return type === Number || type === String || type === Boolean;
|
||
}
|
||
function isUnknownType(type) {
|
||
return type === 'Unknown';
|
||
}
|
||
function isAnyType(type) {
|
||
return type === 'Any';
|
||
}
|
||
function isUTSType(type) {
|
||
return type && type.prototype && type.prototype instanceof UTSType;
|
||
}
|
||
function normalizeGenericValue(value, genericType, isJSONParse = false) {
|
||
return value == null
|
||
? null
|
||
: isBaseType(genericType) ||
|
||
isUnknownType(genericType) ||
|
||
isAnyType(genericType)
|
||
? value
|
||
: genericType === Array
|
||
? new Array(...value)
|
||
: new genericType(value, undefined, isJSONParse);
|
||
}
|
||
class UTSType {
|
||
static get$UTSMetadata$(...args) {
|
||
return {
|
||
name: '',
|
||
kind: 2 /* UTS_CLASS_METADATA_KIND.TYPE */,
|
||
interfaces: [],
|
||
fields: {},
|
||
};
|
||
}
|
||
get $UTSMetadata$() {
|
||
return UTSType.get$UTSMetadata$();
|
||
}
|
||
// TODO 缓存withGenerics结果
|
||
static withGenerics(parent, generics, isJSONParse = false) {
|
||
// 仅JSON.parse uni.request内报错,其他地方不报错
|
||
// generic类型为UTSType子类或Array或基础类型,否则报错
|
||
if (isJSONParse) {
|
||
const illegalGeneric = generics.find((item) => !(item === Array ||
|
||
isBaseType(item) ||
|
||
isUnknownType(item) ||
|
||
isAnyType(item) ||
|
||
item === UTSJSONObject ||
|
||
(item.prototype && item.prototype instanceof UTSType)));
|
||
if (illegalGeneric) {
|
||
throw new Error('Generic is not UTSType or Array or UTSJSONObject or base type, generic: ' +
|
||
illegalGeneric);
|
||
}
|
||
}
|
||
if (parent === Array) {
|
||
// 不带泛型的Array有一部分不会进入这里,需要在构造type时处理
|
||
return class UTSArray extends UTSType {
|
||
constructor(options, isJSONParse = false) {
|
||
if (!Array.isArray(options)) {
|
||
throw new UTSError(`Failed to contruct type, ${options} is not an array`);
|
||
}
|
||
super();
|
||
// @ts-expect-error
|
||
return options.map((item) => {
|
||
return normalizeGenericValue(item, generics[0], isJSONParse);
|
||
});
|
||
}
|
||
};
|
||
}
|
||
else if (parent === Map || parent === WeakMap) {
|
||
return class UTSMap extends UTSType {
|
||
constructor(options, isJSONParse = false) {
|
||
if (options == null || typeof options !== 'object') {
|
||
throw new UTSError(`Failed to contruct type, ${options} is not an object`);
|
||
}
|
||
super();
|
||
const obj = new parent();
|
||
for (const key in options) {
|
||
obj.set(normalizeGenericValue(key, generics[0], isJSONParse), normalizeGenericValue(options[key], generics[1], isJSONParse));
|
||
}
|
||
return obj;
|
||
}
|
||
};
|
||
}
|
||
else if (isUTSType(parent)) {
|
||
return class VirtualClassWithGenerics extends parent {
|
||
static get$UTSMetadata$() {
|
||
return parent.get$UTSMetadata$(...generics);
|
||
}
|
||
constructor(options, metadata = VirtualClassWithGenerics.get$UTSMetadata$(), isJSONParse = false) {
|
||
// @ts-expect-error
|
||
super(options, metadata, isJSONParse);
|
||
}
|
||
};
|
||
}
|
||
else {
|
||
return parent;
|
||
}
|
||
}
|
||
constructor() { }
|
||
static initProps(options, metadata, isJSONParse = false) {
|
||
// 为了性能,非JSON.parse场景直接返回
|
||
if (!isJSONParse) {
|
||
return options;
|
||
}
|
||
const obj = {};
|
||
if (!metadata.fields) {
|
||
return obj;
|
||
}
|
||
for (const key in metadata.fields) {
|
||
const { type, optional, jsonField } = metadata.fields[key];
|
||
const realKey = isJSONParse ? jsonField || key : key;
|
||
if (options[realKey] == null) {
|
||
if (optional) {
|
||
obj[key] = null;
|
||
continue;
|
||
}
|
||
else {
|
||
throw new UTSError(`Failed to contruct type, missing required property: ${key}`);
|
||
}
|
||
}
|
||
if (isUTSType(type)) {
|
||
// 带有泛型的数组会走此分支
|
||
obj[key] = isJSONParse
|
||
? // @ts-expect-error
|
||
new type(options[realKey], undefined, isJSONParse)
|
||
: options[realKey];
|
||
}
|
||
else if (type === Array) {
|
||
// 不带泛型的数组会走此分支
|
||
if (!Array.isArray(options[realKey])) {
|
||
throw new UTSError(`Failed to contruct type, property ${key} is not an array`);
|
||
}
|
||
obj[key] = options[realKey];
|
||
}
|
||
else {
|
||
obj[key] = options[realKey];
|
||
}
|
||
}
|
||
return obj;
|
||
}
|
||
}
|
||
|
||
function initUTSJSONObjectProperties(obj) {
|
||
const propertyList = [
|
||
'_resolveKeyPath',
|
||
'_getValue',
|
||
'toJSON',
|
||
'get',
|
||
'set',
|
||
'getAny',
|
||
'getString',
|
||
'getNumber',
|
||
'getBoolean',
|
||
'getJSON',
|
||
'getArray',
|
||
'toMap',
|
||
'forEach',
|
||
];
|
||
const propertyDescriptorMap = {};
|
||
for (let i = 0; i < propertyList.length; i++) {
|
||
const property = propertyList[i];
|
||
propertyDescriptorMap[property] = {
|
||
enumerable: false,
|
||
value: obj[property],
|
||
};
|
||
}
|
||
Object.defineProperties(obj, propertyDescriptorMap);
|
||
}
|
||
function getRealDefaultValue(defaultValue) {
|
||
return defaultValue === void 0 ? null : defaultValue;
|
||
}
|
||
class UTSJSONObject {
|
||
static keys(obj) {
|
||
return Object.keys(obj);
|
||
}
|
||
static assign(target, ...sources) {
|
||
for (let i = 0; i < sources.length; i++) {
|
||
const source = sources[i];
|
||
for (let key in source) {
|
||
target[key] = source[key];
|
||
}
|
||
}
|
||
return target;
|
||
}
|
||
constructor(content = {}) {
|
||
if (content instanceof Map) {
|
||
content.forEach((value, key) => {
|
||
this[key] = value;
|
||
});
|
||
}
|
||
else {
|
||
for (const key in content) {
|
||
if (Object.prototype.hasOwnProperty.call(content, key)) {
|
||
this[key] = content[key];
|
||
}
|
||
}
|
||
}
|
||
initUTSJSONObjectProperties(this);
|
||
}
|
||
_resolveKeyPath(keyPath) {
|
||
// 非法keyPath不抛出错误,直接返回空数组
|
||
let token = '';
|
||
const keyPathArr = [];
|
||
let inOpenParentheses = false;
|
||
for (let i = 0; i < keyPath.length; i++) {
|
||
const word = keyPath[i];
|
||
switch (word) {
|
||
case '.':
|
||
if (token.length > 0) {
|
||
keyPathArr.push(token);
|
||
token = '';
|
||
}
|
||
break;
|
||
case '[': {
|
||
inOpenParentheses = true;
|
||
if (token.length > 0) {
|
||
keyPathArr.push(token);
|
||
token = '';
|
||
}
|
||
break;
|
||
}
|
||
case ']':
|
||
if (inOpenParentheses) {
|
||
if (token.length > 0) {
|
||
const tokenFirstChar = token[0];
|
||
const tokenLastChar = token[token.length - 1];
|
||
if ((tokenFirstChar === '"' && tokenLastChar === '"') ||
|
||
(tokenFirstChar === "'" && tokenLastChar === "'") ||
|
||
(tokenFirstChar === '`' && tokenLastChar === '`')) {
|
||
if (token.length > 2) {
|
||
token = token.slice(1, -1);
|
||
}
|
||
else {
|
||
return [];
|
||
}
|
||
}
|
||
else if (!/^\d+$/.test(token)) {
|
||
return [];
|
||
}
|
||
keyPathArr.push(token);
|
||
token = '';
|
||
}
|
||
else {
|
||
return [];
|
||
}
|
||
inOpenParentheses = false;
|
||
}
|
||
else {
|
||
return [];
|
||
}
|
||
break;
|
||
default:
|
||
token += word;
|
||
break;
|
||
}
|
||
if (i === keyPath.length - 1) {
|
||
if (token.length > 0) {
|
||
keyPathArr.push(token);
|
||
token = '';
|
||
}
|
||
}
|
||
}
|
||
return keyPathArr;
|
||
}
|
||
_getValue(keyPath, defaultValue) {
|
||
const keyPathArr = this._resolveKeyPath(keyPath);
|
||
const realDefaultValue = getRealDefaultValue(defaultValue);
|
||
if (keyPathArr.length === 0) {
|
||
return realDefaultValue;
|
||
}
|
||
let value = this;
|
||
for (let i = 0; i < keyPathArr.length; i++) {
|
||
const key = keyPathArr[i];
|
||
if (value instanceof Object) {
|
||
if (key in value) {
|
||
value = value[key];
|
||
}
|
||
else {
|
||
return realDefaultValue;
|
||
}
|
||
}
|
||
else {
|
||
return realDefaultValue;
|
||
}
|
||
}
|
||
return value;
|
||
}
|
||
get(key) {
|
||
return this._getValue(key);
|
||
}
|
||
set(key, value) {
|
||
this[key] = value;
|
||
}
|
||
getAny(key, defaultValue) {
|
||
const realDefaultValue = getRealDefaultValue(defaultValue);
|
||
return this._getValue(key, realDefaultValue);
|
||
}
|
||
getString(key, defaultValue) {
|
||
const realDefaultValue = getRealDefaultValue(defaultValue);
|
||
const value = this._getValue(key, realDefaultValue);
|
||
if (typeof value === 'string') {
|
||
return value;
|
||
}
|
||
else {
|
||
return realDefaultValue;
|
||
}
|
||
}
|
||
getNumber(key, defaultValue) {
|
||
const realDefaultValue = getRealDefaultValue(defaultValue);
|
||
const value = this._getValue(key, realDefaultValue);
|
||
if (typeof value === 'number') {
|
||
return value;
|
||
}
|
||
else {
|
||
return realDefaultValue;
|
||
}
|
||
}
|
||
getBoolean(key, defaultValue) {
|
||
const realDefaultValue = getRealDefaultValue(defaultValue);
|
||
const boolean = this._getValue(key, realDefaultValue);
|
||
if (typeof boolean === 'boolean') {
|
||
return boolean;
|
||
}
|
||
else {
|
||
return realDefaultValue;
|
||
}
|
||
}
|
||
getJSON(key, defaultValue) {
|
||
const realDefaultValue = getRealDefaultValue(defaultValue);
|
||
let value = this._getValue(key, realDefaultValue);
|
||
if (value instanceof Object) {
|
||
return value;
|
||
}
|
||
else {
|
||
return realDefaultValue;
|
||
}
|
||
}
|
||
getArray(key, defaultValue) {
|
||
const realDefaultValue = getRealDefaultValue(defaultValue);
|
||
let value = this._getValue(key, realDefaultValue);
|
||
if (value instanceof Array) {
|
||
return value;
|
||
}
|
||
else {
|
||
return realDefaultValue;
|
||
}
|
||
}
|
||
toMap() {
|
||
let map = new Map();
|
||
for (let key in this) {
|
||
map.set(key, this[key]);
|
||
}
|
||
return map;
|
||
}
|
||
forEach(callback) {
|
||
for (let key in this) {
|
||
callback(this[key], key);
|
||
}
|
||
}
|
||
}
|
||
|
||
const OriginalJSON = JSON;
|
||
function createUTSJSONObjectOrArray(obj) {
|
||
if (Array.isArray(obj)) {
|
||
return obj.map((item) => {
|
||
return createUTSJSONObjectOrArray(item);
|
||
});
|
||
}
|
||
else if (isPlainObject(obj)) {
|
||
const result = new UTSJSONObject({});
|
||
for (const key in obj) {
|
||
const value = obj[key];
|
||
result[key] = createUTSJSONObjectOrArray(value);
|
||
}
|
||
return result;
|
||
}
|
||
return obj;
|
||
}
|
||
function parseObjectOrArray(object, utsType) {
|
||
const objectType = getType(object);
|
||
if (object === null || (objectType !== 'object' && objectType !== 'array')) {
|
||
return object;
|
||
}
|
||
if (utsType && utsType !== UTSJSONObject) {
|
||
try {
|
||
return new utsType(object, undefined, true);
|
||
}
|
||
catch (error) {
|
||
console.error(error);
|
||
return null;
|
||
}
|
||
}
|
||
if (objectType === 'array' || objectType === 'object') {
|
||
return createUTSJSONObjectOrArray(object);
|
||
}
|
||
return object;
|
||
}
|
||
const UTSJSON = {
|
||
parse: (text, reviver, utsType) => {
|
||
// @ts-expect-error
|
||
if (reviver && (isUTSType(reviver) || reviver === UTSJSONObject)) {
|
||
utsType = reviver;
|
||
reviver = undefined;
|
||
}
|
||
try {
|
||
const parseResult = OriginalJSON.parse(text, reviver);
|
||
return parseObjectOrArray(parseResult, utsType);
|
||
}
|
||
catch (error) {
|
||
console.error(error);
|
||
return null;
|
||
}
|
||
},
|
||
parseArray(text, utsType) {
|
||
try {
|
||
const parseResult = OriginalJSON.parse(text);
|
||
if (Array.isArray(parseResult)) {
|
||
return parseObjectOrArray(parseResult, utsType ? UTSType.withGenerics(Array, [utsType], true) : undefined);
|
||
}
|
||
return null;
|
||
}
|
||
catch (error) {
|
||
console.error(error);
|
||
return null;
|
||
}
|
||
},
|
||
parseObject(text, utsType) {
|
||
try {
|
||
const parseResult = OriginalJSON.parse(text);
|
||
if (Array.isArray(parseResult)) {
|
||
return null;
|
||
}
|
||
return parseObjectOrArray(parseResult, utsType);
|
||
}
|
||
catch (error) {
|
||
console.error(error);
|
||
return null;
|
||
}
|
||
},
|
||
stringify: (value, replacer, space) => {
|
||
try {
|
||
if (!replacer) {
|
||
const visited = new Set();
|
||
replacer = function (_, v) {
|
||
if (typeof v === 'object') {
|
||
if (visited.has(v)) {
|
||
return null;
|
||
}
|
||
visited.add(v);
|
||
}
|
||
return v;
|
||
};
|
||
}
|
||
return OriginalJSON.stringify(value, replacer, space);
|
||
}
|
||
catch (error) {
|
||
console.error(error);
|
||
return '';
|
||
}
|
||
},
|
||
};
|
||
|
||
function mapGet(map, key) {
|
||
if (!map.has(key)) {
|
||
return null;
|
||
}
|
||
return map.get(key);
|
||
}
|
||
|
||
function stringCodePointAt(str, pos) {
|
||
if (pos < 0 || pos >= str.length) {
|
||
return null;
|
||
}
|
||
return str.codePointAt(pos);
|
||
}
|
||
function stringAt(str, pos) {
|
||
if (pos < -str.length || pos >= str.length) {
|
||
return null;
|
||
}
|
||
return str.at(pos);
|
||
}
|
||
|
||
function weakMapGet(map, key) {
|
||
if (!map.has(key)) {
|
||
return null;
|
||
}
|
||
return map.get(key);
|
||
}
|
||
|
||
const UTS = {
|
||
arrayAt,
|
||
arrayFind,
|
||
arrayFindLast,
|
||
arrayPop,
|
||
arrayShift,
|
||
isInstanceOf,
|
||
UTSType,
|
||
mapGet,
|
||
stringAt,
|
||
stringCodePointAt,
|
||
weakMapGet,
|
||
JSON: UTSJSON,
|
||
};
|
||
|
||
class UniError extends Error {
|
||
constructor(errSubject, errCode, errMsg) {
|
||
let options = {};
|
||
const argsLength = Array.from(arguments).length;
|
||
switch (argsLength) {
|
||
case 0:
|
||
errSubject = '';
|
||
errMsg = '';
|
||
errCode = 0;
|
||
break;
|
||
case 1:
|
||
errMsg = errSubject;
|
||
errSubject = '';
|
||
errCode = 0;
|
||
break;
|
||
case 2:
|
||
errMsg = errSubject;
|
||
options = errCode;
|
||
errCode = options.errCode || 0;
|
||
errSubject = options.errSubject || '';
|
||
break;
|
||
}
|
||
super(errMsg);
|
||
this.name = 'UniError';
|
||
this.errSubject = errSubject;
|
||
this.errCode = errCode;
|
||
this.errMsg = errMsg;
|
||
if (options.data) {
|
||
this.data = options.data;
|
||
}
|
||
if (options.cause) {
|
||
this.cause = options.cause;
|
||
}
|
||
}
|
||
set errMsg(msg) {
|
||
this.message = msg;
|
||
}
|
||
get errMsg() {
|
||
return this.message;
|
||
}
|
||
toString() {
|
||
return this.errMsg;
|
||
}
|
||
toJSON() {
|
||
return {
|
||
errSubject: this.errSubject,
|
||
errCode: this.errCode,
|
||
errMsg: this.errMsg,
|
||
data: this.data,
|
||
cause: this.cause && typeof this.cause.toJSON === 'function'
|
||
? this.cause.toJSON()
|
||
: this.cause,
|
||
};
|
||
}
|
||
}
|
||
|
||
class UTSValueIterable {
|
||
}
|
||
|
||
function isComponentInternalInstance(vm) {
|
||
return !!vm.appContext;
|
||
}
|
||
function resolveComponentInstance(instance) {
|
||
return (instance &&
|
||
(isComponentInternalInstance(instance) ? instance.proxy : instance));
|
||
}
|
||
function resolveOwnerVm(vm) {
|
||
if (!vm) {
|
||
return;
|
||
}
|
||
let componentName = vm.type.name;
|
||
while (componentName && isBuiltInComponent(hyphenate(componentName))) {
|
||
// ownerInstance 内置组件需要使用父 vm
|
||
vm = vm.parent;
|
||
componentName = vm.type.name;
|
||
}
|
||
return vm.proxy;
|
||
}
|
||
function isElement(el) {
|
||
// Element
|
||
return el.nodeType === 1;
|
||
}
|
||
function resolveOwnerEl(instance, multi = false) {
|
||
const { vnode } = instance;
|
||
if (isElement(vnode.el)) {
|
||
return multi ? (vnode.el ? [vnode.el] : []) : vnode.el;
|
||
}
|
||
const { subTree } = instance;
|
||
// ShapeFlags.ARRAY_CHILDREN = 1<<4
|
||
if (subTree.shapeFlag & 16) {
|
||
const elemVNodes = subTree.children.filter((vnode) => vnode.el && isElement(vnode.el));
|
||
if (elemVNodes.length > 0) {
|
||
if (multi) {
|
||
return elemVNodes.map((node) => node.el);
|
||
}
|
||
return elemVNodes[0].el;
|
||
}
|
||
}
|
||
return multi ? (vnode.el ? [vnode.el] : []) : vnode.el;
|
||
}
|
||
function dynamicSlotName(name) {
|
||
return name === 'default' ? SLOT_DEFAULT_NAME : name;
|
||
}
|
||
const customizeRE = /:/g;
|
||
function customizeEvent(str) {
|
||
return camelize(str.replace(customizeRE, '-'));
|
||
}
|
||
function normalizeStyle(value) {
|
||
if (value instanceof UTSJSONObject) {
|
||
const styleObject = {};
|
||
UTSJSONObject.keys(value).forEach((key) => {
|
||
styleObject[key] = value[key];
|
||
});
|
||
return normalizeStyle$1(styleObject);
|
||
}
|
||
else if (value instanceof Map) {
|
||
const styleObject = {};
|
||
value.forEach((value, key) => {
|
||
styleObject[key] = value;
|
||
});
|
||
return normalizeStyle$1(styleObject);
|
||
}
|
||
else if (isString(value)) {
|
||
return parseStringStyle(value);
|
||
}
|
||
else if (isArray(value)) {
|
||
const res = {};
|
||
for (let i = 0; i < value.length; i++) {
|
||
const item = value[i];
|
||
const normalized = isString(item)
|
||
? parseStringStyle(item)
|
||
: normalizeStyle(item);
|
||
if (normalized) {
|
||
for (const key in normalized) {
|
||
res[key] = normalized[key];
|
||
}
|
||
}
|
||
}
|
||
return res;
|
||
}
|
||
else {
|
||
return normalizeStyle$1(value);
|
||
}
|
||
}
|
||
function normalizeClass(value) {
|
||
let res = '';
|
||
if (value instanceof UTSJSONObject) {
|
||
UTSJSONObject.keys(value).forEach((key) => {
|
||
if (value[key]) {
|
||
res += key + ' ';
|
||
}
|
||
});
|
||
}
|
||
else if (value instanceof Map) {
|
||
value.forEach((value, key) => {
|
||
if (value) {
|
||
res += key + ' ';
|
||
}
|
||
});
|
||
}
|
||
else if (isArray(value)) {
|
||
for (let i = 0; i < value.length; i++) {
|
||
const normalized = normalizeClass(value[i]);
|
||
if (normalized) {
|
||
res += normalized + ' ';
|
||
}
|
||
}
|
||
}
|
||
else {
|
||
res = normalizeClass$1(value);
|
||
}
|
||
return res.trim();
|
||
}
|
||
function normalizeProps(props) {
|
||
if (!props)
|
||
return null;
|
||
let { class: klass, style } = props;
|
||
if (klass && !isString(klass)) {
|
||
props.class = normalizeClass(klass);
|
||
}
|
||
if (style) {
|
||
props.style = normalizeStyle(style);
|
||
}
|
||
return props;
|
||
}
|
||
|
||
let lastLogTime = 0;
|
||
function formatLog(module, ...args) {
|
||
const now = Date.now();
|
||
const diff = lastLogTime ? now - lastLogTime : 0;
|
||
lastLogTime = now;
|
||
return `[${now}][${diff}ms][${module}]:${args
|
||
.map((arg) => JSON.stringify(arg))
|
||
.join(' ')}`;
|
||
}
|
||
|
||
function cache(fn) {
|
||
const cache = Object.create(null);
|
||
return (str) => {
|
||
const hit = cache[str];
|
||
return hit || (cache[str] = fn(str));
|
||
};
|
||
}
|
||
function cacheStringFunction(fn) {
|
||
return cache(fn);
|
||
}
|
||
function getLen(str = '') {
|
||
return ('' + str).replace(/[^\x00-\xff]/g, '**').length;
|
||
}
|
||
function hasLeadingSlash(str) {
|
||
return str.indexOf('/') === 0;
|
||
}
|
||
function addLeadingSlash(str) {
|
||
return hasLeadingSlash(str) ? str : '/' + str;
|
||
}
|
||
function removeLeadingSlash(str) {
|
||
return hasLeadingSlash(str) ? str.slice(1) : str;
|
||
}
|
||
const invokeArrayFns = (fns, arg) => {
|
||
let ret;
|
||
for (let i = 0; i < fns.length; i++) {
|
||
ret = fns[i](arg);
|
||
}
|
||
return ret;
|
||
};
|
||
const invokeArrayFnsWithResults = (fns, arg) => {
|
||
return fns.map((fn) => fn(arg));
|
||
};
|
||
function updateElementStyle(element, styles) {
|
||
for (const attrName in styles) {
|
||
element.style[attrName] = styles[attrName];
|
||
}
|
||
}
|
||
function once(fn, ctx = null) {
|
||
let res;
|
||
return ((...args) => {
|
||
if (fn) {
|
||
res = fn.apply(ctx, args);
|
||
fn = null;
|
||
}
|
||
return res;
|
||
});
|
||
}
|
||
const sanitise = (val) => (val && JSON.parse(JSON.stringify(val))) || val;
|
||
const _completeValue = (value) => (value > 9 ? value : '0' + value);
|
||
function formatDateTime({ date = new Date(), mode = 'date' }) {
|
||
if (mode === 'time') {
|
||
return (_completeValue(date.getHours()) + ':' + _completeValue(date.getMinutes()));
|
||
}
|
||
else {
|
||
return (date.getFullYear() +
|
||
'-' +
|
||
_completeValue(date.getMonth() + 1) +
|
||
'-' +
|
||
_completeValue(date.getDate()));
|
||
}
|
||
}
|
||
function callOptions(options, data) {
|
||
options = options || {};
|
||
if (isString(data)) {
|
||
data = {
|
||
errMsg: data,
|
||
};
|
||
}
|
||
if (/:ok$/.test(data.errMsg)) {
|
||
if (isFunction(options.success)) {
|
||
options.success(data);
|
||
}
|
||
}
|
||
else {
|
||
if (isFunction(options.fail)) {
|
||
options.fail(data);
|
||
}
|
||
}
|
||
if (isFunction(options.complete)) {
|
||
options.complete(data);
|
||
}
|
||
}
|
||
function getValueByDataPath(obj, path) {
|
||
if (!isString(path)) {
|
||
return;
|
||
}
|
||
path = path.replace(/\[(\d+)\]/g, '.$1');
|
||
const parts = path.split('.');
|
||
let key = parts[0];
|
||
if (!obj) {
|
||
obj = {};
|
||
}
|
||
if (parts.length === 1) {
|
||
return obj[key];
|
||
}
|
||
return getValueByDataPath(obj[key], parts.slice(1).join('.'));
|
||
}
|
||
/**
|
||
* @deprecated
|
||
*/
|
||
function sortObject(obj) {
|
||
return obj;
|
||
}
|
||
function getGlobalOnce() {
|
||
if (typeof globalThis !== 'undefined') {
|
||
return globalThis;
|
||
}
|
||
// worker
|
||
if (typeof self !== 'undefined') {
|
||
return self;
|
||
}
|
||
// browser
|
||
if (typeof window !== 'undefined') {
|
||
return window;
|
||
}
|
||
// nodejs
|
||
// if (typeof global !== 'undefined') {
|
||
// return global
|
||
// }
|
||
function g() {
|
||
return this;
|
||
}
|
||
if (typeof g() !== 'undefined') {
|
||
return g();
|
||
}
|
||
return (function () {
|
||
return new Function('return this')();
|
||
})();
|
||
}
|
||
let g = undefined;
|
||
function getGlobal() {
|
||
if (g) {
|
||
return g;
|
||
}
|
||
g = getGlobalOnce();
|
||
return g;
|
||
}
|
||
|
||
function formatKey(key) {
|
||
return camelize(key.substring(5));
|
||
}
|
||
// question/139181,增加副作用,避免 initCustomDataset 在 build 下被 tree-shaking
|
||
const initCustomDatasetOnce = /*#__PURE__*/ once((isBuiltInElement) => {
|
||
isBuiltInElement =
|
||
isBuiltInElement || ((el) => el.tagName.startsWith('UNI-'));
|
||
const prototype = HTMLElement.prototype;
|
||
const setAttribute = prototype.setAttribute;
|
||
prototype.setAttribute = function (key, value) {
|
||
if (key.startsWith('data-') && isBuiltInElement(this)) {
|
||
const dataset = this.__uniDataset ||
|
||
(this.__uniDataset = {});
|
||
dataset[formatKey(key)] = value;
|
||
}
|
||
// github issues5773 过滤 web 端 query key为数字开头
|
||
if (!/^\d/.test(key)) {
|
||
setAttribute.call(this, key, value);
|
||
}
|
||
};
|
||
const removeAttribute = prototype.removeAttribute;
|
||
prototype.removeAttribute = function (key) {
|
||
if (this.__uniDataset &&
|
||
key.startsWith('data-') &&
|
||
isBuiltInElement(this)) {
|
||
delete this.__uniDataset[formatKey(key)];
|
||
}
|
||
removeAttribute.call(this, key);
|
||
};
|
||
});
|
||
function getCustomDataset(el) {
|
||
return extend({}, el.dataset, el.__uniDataset);
|
||
}
|
||
|
||
const unitRE = new RegExp(`"[^"]+"|'[^']+'|url\\([^)]+\\)|(\\d*\\.?\\d+)[r|u]px`, 'g');
|
||
function toFixed(number, precision) {
|
||
const multiplier = Math.pow(10, precision + 1);
|
||
const wholeNumber = Math.floor(number * multiplier);
|
||
return (Math.round(wholeNumber / 10) * 10) / multiplier;
|
||
}
|
||
const defaultRpx2Unit = {
|
||
unit: 'rem',
|
||
unitRatio: 10 / 320,
|
||
unitPrecision: 5,
|
||
};
|
||
const defaultMiniProgramRpx2Unit = {
|
||
unit: 'rpx',
|
||
unitRatio: 1,
|
||
unitPrecision: 1,
|
||
};
|
||
const defaultNVueRpx2Unit = defaultMiniProgramRpx2Unit;
|
||
function createRpx2Unit(unit, unitRatio, unitPrecision) {
|
||
// ignore: rpxCalcIncludeWidth
|
||
return (val) => val.replace(unitRE, (m, $1) => {
|
||
if (!$1) {
|
||
return m;
|
||
}
|
||
if (unitRatio === 1) {
|
||
return `${$1}${unit}`;
|
||
}
|
||
const value = toFixed(parseFloat($1) * unitRatio, unitPrecision);
|
||
return value === 0 ? '0' : `${value}${unit}`;
|
||
});
|
||
}
|
||
function getPartClass(partName) {
|
||
return `-_part__${partName}_-`;
|
||
}
|
||
function batchGetPartClass(partNames) {
|
||
return partNames
|
||
.split(/\s+/)
|
||
.filter(Boolean)
|
||
.map((partName) => getPartClass(partName))
|
||
.join(' ');
|
||
}
|
||
|
||
function passive(passive) {
|
||
return { passive };
|
||
}
|
||
function normalizeDataset(el) {
|
||
// TODO
|
||
return JSON.parse(JSON.stringify(el.dataset || {}));
|
||
}
|
||
function normalizeTarget(el) {
|
||
const { id, offsetTop, offsetLeft } = el;
|
||
return {
|
||
id,
|
||
dataset: getCustomDataset(el),
|
||
offsetTop,
|
||
offsetLeft,
|
||
};
|
||
}
|
||
function addFont(family, source, desc) {
|
||
const fonts = document.fonts;
|
||
if (fonts) {
|
||
const fontFace = new FontFace(family, source, desc);
|
||
return fontFace.load().then(() => {
|
||
fonts.add && fonts.add(fontFace);
|
||
});
|
||
}
|
||
return new Promise((resolve) => {
|
||
const style = document.createElement('style');
|
||
const values = [];
|
||
if (desc) {
|
||
const { style, weight, stretch, unicodeRange, variant, featureSettings } = desc;
|
||
style && values.push(`font-style:${style}`);
|
||
weight && values.push(`font-weight:${weight}`);
|
||
stretch && values.push(`font-stretch:${stretch}`);
|
||
unicodeRange && values.push(`unicode-range:${unicodeRange}`);
|
||
variant && values.push(`font-variant:${variant}`);
|
||
featureSettings && values.push(`font-feature-settings:${featureSettings}`);
|
||
}
|
||
style.innerText = `@font-face{font-family:"${family}";src:${source};${values.join(';')}}`;
|
||
document.head.appendChild(style);
|
||
resolve();
|
||
});
|
||
}
|
||
function scrollTo(scrollTop, duration, isH5) {
|
||
if (isString(scrollTop)) {
|
||
const el = document.querySelector(scrollTop);
|
||
if (el) {
|
||
const { top } = el.getBoundingClientRect();
|
||
scrollTop = top + window.pageYOffset;
|
||
// 如果存在,减去 <uni-page-head> 高度
|
||
const pageHeader = document.querySelector('uni-page-head');
|
||
if (pageHeader) {
|
||
scrollTop -= pageHeader.offsetHeight;
|
||
}
|
||
}
|
||
}
|
||
if (scrollTop < 0) {
|
||
scrollTop = 0;
|
||
}
|
||
const documentElement = document.documentElement;
|
||
const { clientHeight, scrollHeight } = documentElement;
|
||
scrollTop = Math.min(scrollTop, scrollHeight - clientHeight);
|
||
if (duration === 0) {
|
||
// 部分浏览器(比如微信)中 scrollTop 的值需要通过 document.body 来控制
|
||
documentElement.scrollTop = document.body.scrollTop = scrollTop;
|
||
return;
|
||
}
|
||
if (window.scrollY === scrollTop) {
|
||
return;
|
||
}
|
||
const scrollTo = (duration) => {
|
||
if (duration <= 0) {
|
||
window.scrollTo(0, scrollTop);
|
||
return;
|
||
}
|
||
const distaince = scrollTop - window.scrollY;
|
||
requestAnimationFrame(function () {
|
||
window.scrollTo(0, window.scrollY + (distaince / duration) * 10);
|
||
scrollTo(duration - 10);
|
||
});
|
||
};
|
||
scrollTo(duration);
|
||
}
|
||
|
||
const encode = encodeURIComponent;
|
||
function stringifyQuery(obj, encodeStr = encode) {
|
||
const res = obj
|
||
? Object.keys(obj)
|
||
.map((key) => {
|
||
let val = obj[key];
|
||
if (typeof val === undefined || val === null) {
|
||
val = '';
|
||
}
|
||
else if (isPlainObject$1(val)) {
|
||
val = JSON.stringify(val);
|
||
}
|
||
return encodeStr(key) + '=' + encodeStr(val);
|
||
})
|
||
.filter((x) => x.length > 0)
|
||
.join('&')
|
||
: null;
|
||
return res ? `?${res}` : '';
|
||
}
|
||
/**
|
||
* Decode text using `decodeURIComponent`. Returns the original text if it
|
||
* fails.
|
||
*
|
||
* @param text - string to decode
|
||
* @returns decoded string
|
||
*/
|
||
function decode(text) {
|
||
try {
|
||
return decodeURIComponent('' + text);
|
||
}
|
||
catch (err) { }
|
||
return '' + text;
|
||
}
|
||
function decodedQuery(query = {}) {
|
||
const decodedQuery = {};
|
||
Object.keys(query).forEach((name) => {
|
||
try {
|
||
decodedQuery[name] = decode(query[name]);
|
||
}
|
||
catch (e) {
|
||
decodedQuery[name] = query[name];
|
||
}
|
||
});
|
||
return decodedQuery;
|
||
}
|
||
const PLUS_RE = /\+/g; // %2B
|
||
/**
|
||
* https://github.com/vuejs/vue-router-next/blob/master/src/query.ts
|
||
* @internal
|
||
*
|
||
* @param search - search string to parse
|
||
* @returns a query object
|
||
*/
|
||
function parseQuery(search) {
|
||
const query = {};
|
||
// avoid creating an object with an empty key and empty value
|
||
// because of split('&')
|
||
if (search === '' || search === '?')
|
||
return query;
|
||
const hasLeadingIM = search[0] === '?';
|
||
const searchParams = (hasLeadingIM ? search.slice(1) : search).split('&');
|
||
for (let i = 0; i < searchParams.length; ++i) {
|
||
// pre decode the + into space
|
||
const searchParam = searchParams[i].replace(PLUS_RE, ' ');
|
||
// allow the = character
|
||
let eqPos = searchParam.indexOf('=');
|
||
let key = decode(eqPos < 0 ? searchParam : searchParam.slice(0, eqPos));
|
||
let value = eqPos < 0 ? null : decode(searchParam.slice(eqPos + 1));
|
||
if (key in query) {
|
||
// an extra variable for ts types
|
||
let currentValue = query[key];
|
||
if (!isArray(currentValue)) {
|
||
currentValue = query[key] = [currentValue];
|
||
}
|
||
currentValue.push(value);
|
||
}
|
||
else {
|
||
query[key] = value;
|
||
}
|
||
}
|
||
return query;
|
||
}
|
||
|
||
function parseUrl(url) {
|
||
const [path, querystring] = url.split('?', 2);
|
||
return {
|
||
path,
|
||
query: parseQuery(querystring || ''),
|
||
};
|
||
}
|
||
|
||
function parseNVueDataset(attr) {
|
||
const dataset = {};
|
||
if (attr) {
|
||
Object.keys(attr).forEach((key) => {
|
||
if (key.indexOf('data-') === 0) {
|
||
dataset[key.replace('data-', '')] = attr[key];
|
||
}
|
||
});
|
||
}
|
||
return dataset;
|
||
}
|
||
|
||
function plusReady(callback) {
|
||
if (!isFunction(callback)) {
|
||
return;
|
||
}
|
||
if (window.plus) {
|
||
return callback();
|
||
}
|
||
document.addEventListener('plusready', callback);
|
||
}
|
||
|
||
class DOMException extends Error {
|
||
constructor(message) {
|
||
super(message);
|
||
this.name = 'DOMException';
|
||
}
|
||
}
|
||
|
||
function normalizeEventType(type, options) {
|
||
if (options) {
|
||
if (options.capture) {
|
||
type += 'Capture';
|
||
}
|
||
if (options.once) {
|
||
type += 'Once';
|
||
}
|
||
if (options.passive) {
|
||
type += 'Passive';
|
||
}
|
||
}
|
||
return `on${capitalize(camelize(type))}`;
|
||
}
|
||
class UniEvent {
|
||
constructor(type, opts) {
|
||
this.defaultPrevented = false;
|
||
this.timeStamp = Date.now();
|
||
this._stop = false;
|
||
this._end = false;
|
||
this.type = type;
|
||
this.bubbles = !!opts.bubbles;
|
||
this.cancelable = !!opts.cancelable;
|
||
}
|
||
preventDefault() {
|
||
this.defaultPrevented = true;
|
||
}
|
||
stopImmediatePropagation() {
|
||
this._end = this._stop = true;
|
||
}
|
||
stopPropagation() {
|
||
this._stop = true;
|
||
}
|
||
}
|
||
function createUniEvent(evt) {
|
||
if (evt instanceof UniEvent) {
|
||
return evt;
|
||
}
|
||
const [type] = parseEventName(evt.type);
|
||
const uniEvent = new UniEvent(type, {
|
||
bubbles: false,
|
||
cancelable: false,
|
||
});
|
||
extend(uniEvent, evt);
|
||
return uniEvent;
|
||
}
|
||
class UniEventTarget {
|
||
constructor() {
|
||
this.listeners = Object.create(null);
|
||
}
|
||
dispatchEvent(evt) {
|
||
const listeners = this.listeners[evt.type];
|
||
if (!listeners) {
|
||
if ((process.env.NODE_ENV !== 'production')) {
|
||
console.error(formatLog('dispatchEvent', this.nodeId), evt.type, 'not found');
|
||
}
|
||
return false;
|
||
}
|
||
// 格式化事件类型
|
||
const event = createUniEvent(evt);
|
||
const len = listeners.length;
|
||
for (let i = 0; i < len; i++) {
|
||
listeners[i].call(this, event);
|
||
if (event._end) {
|
||
break;
|
||
}
|
||
}
|
||
return event.cancelable && event.defaultPrevented;
|
||
}
|
||
addEventListener(type, listener, options) {
|
||
type = normalizeEventType(type, options);
|
||
(this.listeners[type] || (this.listeners[type] = [])).push(listener);
|
||
}
|
||
removeEventListener(type, callback, options) {
|
||
type = normalizeEventType(type, options);
|
||
const listeners = this.listeners[type];
|
||
if (!listeners) {
|
||
return;
|
||
}
|
||
const index = listeners.indexOf(callback);
|
||
if (index > -1) {
|
||
listeners.splice(index, 1);
|
||
}
|
||
}
|
||
}
|
||
const optionsModifierRE = /(?:Once|Passive|Capture)$/;
|
||
function parseEventName(name) {
|
||
let options;
|
||
if (optionsModifierRE.test(name)) {
|
||
options = {};
|
||
let m;
|
||
while ((m = name.match(optionsModifierRE))) {
|
||
name = name.slice(0, name.length - m[0].length);
|
||
options[m[0].toLowerCase()] = true;
|
||
}
|
||
}
|
||
return [hyphenate(name.slice(2)), options];
|
||
}
|
||
|
||
const EventModifierFlags = /*#__PURE__*/ (() => {
|
||
return {
|
||
stop: 1,
|
||
prevent: 1 << 1,
|
||
self: 1 << 2,
|
||
};
|
||
})();
|
||
function encodeModifier(modifiers) {
|
||
let flag = 0;
|
||
if (modifiers.includes('stop')) {
|
||
flag |= EventModifierFlags.stop;
|
||
}
|
||
if (modifiers.includes('prevent')) {
|
||
flag |= EventModifierFlags.prevent;
|
||
}
|
||
if (modifiers.includes('self')) {
|
||
flag |= EventModifierFlags.self;
|
||
}
|
||
return flag;
|
||
}
|
||
|
||
const NODE_TYPE_PAGE = 0;
|
||
const NODE_TYPE_ELEMENT = 1;
|
||
const NODE_TYPE_TEXT = 3;
|
||
const NODE_TYPE_COMMENT = 8;
|
||
function sibling(node, type) {
|
||
const { parentNode } = node;
|
||
if (!parentNode) {
|
||
return null;
|
||
}
|
||
const { childNodes } = parentNode;
|
||
return childNodes[childNodes.indexOf(node) + (type === 'n' ? 1 : -1)] || null;
|
||
}
|
||
function removeNode(node) {
|
||
const { parentNode } = node;
|
||
if (parentNode) {
|
||
const { childNodes } = parentNode;
|
||
const index = childNodes.indexOf(node);
|
||
if (index > -1) {
|
||
node.parentNode = null;
|
||
childNodes.splice(index, 1);
|
||
}
|
||
}
|
||
}
|
||
function checkNodeId(node) {
|
||
if (!node.nodeId && node.pageNode) {
|
||
node.nodeId = node.pageNode.genId();
|
||
}
|
||
}
|
||
// 为优化性能,各平台不使用proxy来实现node的操作拦截,而是直接通过pageNode定制
|
||
class UniNode extends UniEventTarget {
|
||
constructor(nodeType, nodeName, container) {
|
||
super();
|
||
this.pageNode = null;
|
||
this.parentNode = null;
|
||
this._text = null;
|
||
if (container) {
|
||
const { pageNode } = container;
|
||
if (pageNode) {
|
||
this.pageNode = pageNode;
|
||
this.nodeId = pageNode.genId();
|
||
!pageNode.isUnmounted && pageNode.onCreate(this, nodeName);
|
||
}
|
||
}
|
||
this.nodeType = nodeType;
|
||
this.nodeName = nodeName;
|
||
this.childNodes = [];
|
||
}
|
||
get firstChild() {
|
||
return this.childNodes[0] || null;
|
||
}
|
||
get lastChild() {
|
||
const { childNodes } = this;
|
||
const length = childNodes.length;
|
||
return length ? childNodes[length - 1] : null;
|
||
}
|
||
get nextSibling() {
|
||
return sibling(this, 'n');
|
||
}
|
||
get nodeValue() {
|
||
return null;
|
||
}
|
||
set nodeValue(_val) { }
|
||
get textContent() {
|
||
return this._text || '';
|
||
}
|
||
set textContent(text) {
|
||
this._text = text;
|
||
if (this.pageNode && !this.pageNode.isUnmounted) {
|
||
this.pageNode.onTextContent(this, text);
|
||
}
|
||
}
|
||
get parentElement() {
|
||
const { parentNode } = this;
|
||
if (parentNode && parentNode.nodeType === NODE_TYPE_ELEMENT) {
|
||
return parentNode;
|
||
}
|
||
return null;
|
||
}
|
||
get previousSibling() {
|
||
return sibling(this, 'p');
|
||
}
|
||
appendChild(newChild) {
|
||
return this.insertBefore(newChild, null);
|
||
}
|
||
cloneNode(deep) {
|
||
const cloned = extend(Object.create(Object.getPrototypeOf(this)), this);
|
||
const { attributes } = cloned;
|
||
if (attributes) {
|
||
cloned.attributes = extend({}, attributes);
|
||
}
|
||
if (deep) {
|
||
cloned.childNodes = cloned.childNodes.map((childNode) => childNode.cloneNode(true));
|
||
}
|
||
return cloned;
|
||
}
|
||
insertBefore(newChild, refChild) {
|
||
// 先从现在的父节点移除(注意:不能触发onRemoveChild,否则会生成先remove该 id,再 insert)
|
||
removeNode(newChild);
|
||
newChild.pageNode = this.pageNode;
|
||
newChild.parentNode = this;
|
||
checkNodeId(newChild);
|
||
const { childNodes } = this;
|
||
if (refChild) {
|
||
const index = childNodes.indexOf(refChild);
|
||
if (index === -1) {
|
||
throw new DOMException(`Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.`);
|
||
}
|
||
childNodes.splice(index, 0, newChild);
|
||
}
|
||
else {
|
||
childNodes.push(newChild);
|
||
}
|
||
return this.pageNode && !this.pageNode.isUnmounted
|
||
? this.pageNode.onInsertBefore(this, newChild, refChild)
|
||
: newChild;
|
||
}
|
||
removeChild(oldChild) {
|
||
const { childNodes } = this;
|
||
const index = childNodes.indexOf(oldChild);
|
||
if (index === -1) {
|
||
throw new DOMException(`Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.`);
|
||
}
|
||
oldChild.parentNode = null;
|
||
childNodes.splice(index, 1);
|
||
return this.pageNode && !this.pageNode.isUnmounted
|
||
? this.pageNode.onRemoveChild(oldChild)
|
||
: oldChild;
|
||
}
|
||
}
|
||
const ATTR_CLASS = 'class';
|
||
const ATTR_STYLE = 'style';
|
||
const ATTR_INNER_HTML = 'innerHTML';
|
||
const ATTR_TEXT_CONTENT = 'textContent';
|
||
const ATTR_V_SHOW = '.vShow';
|
||
const ATTR_V_OWNER_ID = '.vOwnerId';
|
||
const ATTR_V_RENDERJS = '.vRenderjs';
|
||
const ATTR_CHANGE_PREFIX = 'change:';
|
||
class UniBaseNode extends UniNode {
|
||
constructor(nodeType, nodeName, container) {
|
||
super(nodeType, nodeName, container);
|
||
this.attributes = Object.create(null);
|
||
this.style = null;
|
||
this.vShow = null;
|
||
this._html = null;
|
||
}
|
||
get className() {
|
||
return (this.attributes[ATTR_CLASS] || '');
|
||
}
|
||
set className(val) {
|
||
this.setAttribute(ATTR_CLASS, val);
|
||
}
|
||
get innerHTML() {
|
||
return '';
|
||
}
|
||
set innerHTML(html) {
|
||
this._html = html;
|
||
}
|
||
addEventListener(type, listener, options) {
|
||
super.addEventListener(type, listener, options);
|
||
if (this.pageNode && !this.pageNode.isUnmounted) {
|
||
if (listener.wxsEvent) {
|
||
this.pageNode.onAddWxsEvent(this, normalizeEventType(type, options), listener.wxsEvent, encodeModifier(listener.modifiers || []));
|
||
}
|
||
else {
|
||
this.pageNode.onAddEvent(this, normalizeEventType(type, options), encodeModifier(listener.modifiers || []));
|
||
}
|
||
}
|
||
}
|
||
removeEventListener(type, callback, options) {
|
||
super.removeEventListener(type, callback, options);
|
||
if (this.pageNode && !this.pageNode.isUnmounted) {
|
||
this.pageNode.onRemoveEvent(this, normalizeEventType(type, options));
|
||
}
|
||
}
|
||
getAttribute(qualifiedName) {
|
||
if (qualifiedName === ATTR_STYLE) {
|
||
return this.style;
|
||
}
|
||
return this.attributes[qualifiedName];
|
||
}
|
||
removeAttribute(qualifiedName) {
|
||
if (qualifiedName == ATTR_STYLE) {
|
||
this.style = null;
|
||
}
|
||
else {
|
||
delete this.attributes[qualifiedName];
|
||
}
|
||
if (this.pageNode && !this.pageNode.isUnmounted) {
|
||
this.pageNode.onRemoveAttribute(this, qualifiedName);
|
||
}
|
||
}
|
||
setAttribute(qualifiedName, value) {
|
||
if (qualifiedName === ATTR_STYLE) {
|
||
this.style = value;
|
||
}
|
||
else {
|
||
this.attributes[qualifiedName] = value;
|
||
}
|
||
if (this.pageNode && !this.pageNode.isUnmounted) {
|
||
this.pageNode.onSetAttribute(this, qualifiedName, value);
|
||
}
|
||
}
|
||
toJSON({ attr, normalize, } = {}) {
|
||
const { attributes, style, listeners, _text } = this;
|
||
const res = {};
|
||
if (Object.keys(attributes).length) {
|
||
res.a = normalize ? normalize(attributes) : attributes;
|
||
}
|
||
const events = Object.keys(listeners);
|
||
if (events.length) {
|
||
let w = undefined;
|
||
const e = {};
|
||
events.forEach((name) => {
|
||
const handlers = listeners[name];
|
||
if (handlers.length) {
|
||
// 可能存在多个 handler 且不同 modifiers 吗?
|
||
const { wxsEvent, modifiers } = handlers[0];
|
||
const modifier = encodeModifier(modifiers || []);
|
||
if (!wxsEvent) {
|
||
e[name] = modifier;
|
||
}
|
||
else {
|
||
if (!w) {
|
||
w = {};
|
||
}
|
||
w[name] = [normalize ? normalize(wxsEvent) : wxsEvent, modifier];
|
||
}
|
||
}
|
||
});
|
||
res.e = normalize ? normalize(e, false) : e;
|
||
if (w) {
|
||
res.w = normalize ? normalize(w, false) : w;
|
||
}
|
||
}
|
||
if (style !== null) {
|
||
res.s = normalize ? normalize(style) : style;
|
||
}
|
||
if (!attr) {
|
||
res.i = this.nodeId;
|
||
res.n = this.nodeName;
|
||
}
|
||
if (_text !== null) {
|
||
res.t = normalize ? normalize(_text) : _text;
|
||
}
|
||
return res;
|
||
}
|
||
}
|
||
|
||
class UniCommentNode extends UniNode {
|
||
constructor(text, container) {
|
||
super(NODE_TYPE_COMMENT, '#comment', container);
|
||
this._text = (process.env.NODE_ENV !== 'production') ? text : '';
|
||
}
|
||
toJSON(opts = {}) {
|
||
// 暂时不传递 text 到 view 层,没啥意义,节省点数据量
|
||
return opts.attr
|
||
? {}
|
||
: {
|
||
i: this.nodeId,
|
||
};
|
||
// return opts.attr
|
||
// ? { t: this._text as string }
|
||
// : {
|
||
// i: this.nodeId!,
|
||
// t: this._text as string,
|
||
// }
|
||
}
|
||
}
|
||
|
||
class UniElement extends UniBaseNode {
|
||
constructor(nodeName, container) {
|
||
super(NODE_TYPE_ELEMENT, nodeName.toUpperCase(), container);
|
||
this.tagName = this.nodeName;
|
||
}
|
||
}
|
||
class UniInputElement extends UniElement {
|
||
get value() {
|
||
return this.getAttribute('value');
|
||
}
|
||
set value(val) {
|
||
this.setAttribute('value', val);
|
||
}
|
||
}
|
||
class UniTextAreaElement extends UniInputElement {
|
||
}
|
||
|
||
class UniTextNode extends UniBaseNode {
|
||
constructor(text, container) {
|
||
super(NODE_TYPE_TEXT, '#text', container);
|
||
this._text = text;
|
||
}
|
||
get nodeValue() {
|
||
return this._text || '';
|
||
}
|
||
set nodeValue(text) {
|
||
this._text = text;
|
||
if (this.pageNode && !this.pageNode.isUnmounted) {
|
||
this.pageNode.onNodeValue(this, text);
|
||
}
|
||
}
|
||
}
|
||
|
||
const forcePatchProps = {
|
||
AD: ['data'],
|
||
'AD-DRAW': ['data'],
|
||
'LIVE-PLAYER': ['picture-in-picture-mode'],
|
||
MAP: [
|
||
'markers',
|
||
'polyline',
|
||
'circles',
|
||
'controls',
|
||
'include-points',
|
||
'polygons',
|
||
],
|
||
PICKER: ['range', 'value'],
|
||
'PICKER-VIEW': ['value'],
|
||
'RICH-TEXT': ['nodes'],
|
||
VIDEO: ['danmu-list', 'header'],
|
||
'WEB-VIEW': ['webview-styles'],
|
||
};
|
||
const forcePatchPropKeys = ['animation'];
|
||
|
||
const forcePatchProp = (el, key) => {
|
||
if (forcePatchPropKeys.indexOf(key) > -1) {
|
||
return true;
|
||
}
|
||
const keys = forcePatchProps[el.nodeName];
|
||
if (keys && keys.indexOf(key) > -1) {
|
||
return true;
|
||
}
|
||
return false;
|
||
};
|
||
|
||
const ACTION_TYPE_PAGE_CREATE = 1;
|
||
const ACTION_TYPE_PAGE_CREATED = 2;
|
||
const ACTION_TYPE_CREATE = 3;
|
||
const ACTION_TYPE_INSERT = 4;
|
||
const ACTION_TYPE_REMOVE = 5;
|
||
const ACTION_TYPE_SET_ATTRIBUTE = 6;
|
||
const ACTION_TYPE_REMOVE_ATTRIBUTE = 7;
|
||
const ACTION_TYPE_ADD_EVENT = 8;
|
||
const ACTION_TYPE_REMOVE_EVENT = 9;
|
||
const ACTION_TYPE_SET_TEXT = 10;
|
||
const ACTION_TYPE_ADD_WXS_EVENT = 12;
|
||
const ACTION_TYPE_PAGE_SCROLL = 15;
|
||
const ACTION_TYPE_EVENT = 20;
|
||
|
||
/**
|
||
* 需要手动传入 timer,主要是解决 App 平台的定制 timer
|
||
*/
|
||
function debounce(fn, delay, { clearTimeout, setTimeout }) {
|
||
let timeout;
|
||
const newFn = function () {
|
||
clearTimeout(timeout);
|
||
const timerFn = () => fn.apply(this, arguments);
|
||
timeout = setTimeout(timerFn, delay);
|
||
};
|
||
newFn.cancel = function () {
|
||
clearTimeout(timeout);
|
||
};
|
||
return newFn;
|
||
}
|
||
|
||
class EventChannel {
|
||
constructor(id, events) {
|
||
this.id = id;
|
||
this.listener = {};
|
||
this.emitCache = [];
|
||
if (events) {
|
||
Object.keys(events).forEach((name) => {
|
||
this.on(name, events[name]);
|
||
});
|
||
}
|
||
}
|
||
emit(eventName, ...args) {
|
||
const fns = this.listener[eventName];
|
||
if (!fns) {
|
||
return this.emitCache.push({
|
||
eventName,
|
||
args,
|
||
});
|
||
}
|
||
fns.forEach((opt) => {
|
||
opt.fn.apply(opt.fn, args);
|
||
});
|
||
this.listener[eventName] = fns.filter((opt) => opt.type !== 'once');
|
||
}
|
||
on(eventName, fn) {
|
||
this._addListener(eventName, 'on', fn);
|
||
this._clearCache(eventName);
|
||
}
|
||
once(eventName, fn) {
|
||
this._addListener(eventName, 'once', fn);
|
||
this._clearCache(eventName);
|
||
}
|
||
off(eventName, fn) {
|
||
const fns = this.listener[eventName];
|
||
if (!fns) {
|
||
return;
|
||
}
|
||
if (fn) {
|
||
for (let i = 0; i < fns.length;) {
|
||
if (fns[i].fn === fn) {
|
||
fns.splice(i, 1);
|
||
i--;
|
||
}
|
||
i++;
|
||
}
|
||
}
|
||
else {
|
||
delete this.listener[eventName];
|
||
}
|
||
}
|
||
_clearCache(eventName) {
|
||
for (let index = 0; index < this.emitCache.length; index++) {
|
||
const cache = this.emitCache[index];
|
||
const _name = eventName
|
||
? cache.eventName === eventName
|
||
? eventName
|
||
: null
|
||
: cache.eventName;
|
||
if (!_name)
|
||
continue;
|
||
const location = this.emit.apply(this, [_name, ...cache.args]);
|
||
if (typeof location === 'number') {
|
||
this.emitCache.pop();
|
||
continue;
|
||
}
|
||
this.emitCache.splice(index, 1);
|
||
index--;
|
||
}
|
||
}
|
||
_addListener(eventName, type, fn) {
|
||
(this.listener[eventName] || (this.listener[eventName] = [])).push({
|
||
fn,
|
||
type,
|
||
});
|
||
}
|
||
}
|
||
|
||
const PAGE_HOOKS = [
|
||
ON_INIT,
|
||
ON_LOAD,
|
||
ON_SHOW,
|
||
ON_HIDE,
|
||
ON_UNLOAD,
|
||
ON_RESIZE,
|
||
ON_BACK_PRESS,
|
||
ON_PAGE_SCROLL,
|
||
ON_TAB_ITEM_TAP,
|
||
ON_REACH_BOTTOM,
|
||
ON_PULL_DOWN_REFRESH,
|
||
ON_SHARE_TIMELINE,
|
||
ON_SHARE_APP_MESSAGE,
|
||
ON_SHARE_CHAT,
|
||
ON_COPY_URL,
|
||
ON_UPLOAD_DOUYIN_VIDEO,
|
||
ON_LIVE_MOUNT,
|
||
ON_TITLE_CLICK,
|
||
ON_ADD_TO_FAVORITES,
|
||
ON_SAVE_EXIT_STATE,
|
||
ON_NAVIGATION_BAR_BUTTON_TAP,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED,
|
||
];
|
||
function isRootImmediateHook(name) {
|
||
const PAGE_SYNC_HOOKS = [ON_LOAD, ON_SHOW];
|
||
return PAGE_SYNC_HOOKS.indexOf(name) > -1;
|
||
}
|
||
// isRootImmediateHookX deprecated
|
||
function isRootHook(name) {
|
||
return PAGE_HOOKS.indexOf(name) > -1;
|
||
}
|
||
const UniLifecycleHooks = [
|
||
ON_SHOW,
|
||
ON_HIDE,
|
||
ON_LAUNCH,
|
||
ON_ERROR,
|
||
ON_THEME_CHANGE,
|
||
ON_PAGE_NOT_FOUND,
|
||
ON_UNHANDLE_REJECTION,
|
||
ON_EXIT,
|
||
ON_INIT,
|
||
ON_LOAD,
|
||
ON_READY,
|
||
ON_UNLOAD,
|
||
ON_RESIZE,
|
||
ON_BACK_PRESS,
|
||
ON_PAGE_SCROLL,
|
||
ON_TAB_ITEM_TAP,
|
||
ON_REACH_BOTTOM,
|
||
ON_PULL_DOWN_REFRESH,
|
||
ON_SHARE_TIMELINE,
|
||
ON_ADD_TO_FAVORITES,
|
||
ON_SHARE_APP_MESSAGE,
|
||
ON_SHARE_CHAT,
|
||
ON_COPY_URL,
|
||
ON_UPLOAD_DOUYIN_VIDEO,
|
||
ON_LIVE_MOUNT,
|
||
ON_TITLE_CLICK,
|
||
ON_SAVE_EXIT_STATE,
|
||
ON_NAVIGATION_BAR_BUTTON_TAP,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED,
|
||
ON_LAST_PAGE_BACK_PRESS,
|
||
];
|
||
const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = /*#__PURE__*/ (() => {
|
||
return {
|
||
onPageScroll: 1,
|
||
onShareAppMessage: 1 << 1,
|
||
onShareTimeline: 1 << 2,
|
||
onShareChat: 1 << 3,
|
||
onCopyUrl: 1 << 4,
|
||
onUploadDouyinVideo: 1 << 5,
|
||
onLiveMount: 1 << 6,
|
||
onTitleClick: 1 << 7,
|
||
};
|
||
})();
|
||
function isUniLifecycleHook(name, value, checkType = true) {
|
||
// 检查类型
|
||
if (checkType && !isFunction(value)) {
|
||
return false;
|
||
}
|
||
if (UniLifecycleHooks.indexOf(name) > -1) {
|
||
// 已预定义
|
||
return true;
|
||
}
|
||
else if (name.indexOf('on') === 0) {
|
||
// 以 on 开头
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
let vueApp;
|
||
const createVueAppHooks = [];
|
||
/**
|
||
* 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑
|
||
*/
|
||
function onCreateVueApp(hook) {
|
||
// TODO 每个 nvue 页面都会触发
|
||
if (vueApp) {
|
||
return hook(vueApp);
|
||
}
|
||
createVueAppHooks.push(hook);
|
||
}
|
||
function invokeCreateVueAppHook(app) {
|
||
vueApp = app;
|
||
createVueAppHooks.forEach((hook) => hook(app));
|
||
}
|
||
const invokeCreateErrorHandler = once((app, createErrorHandler) => {
|
||
// 不再判断开发者是否监听了onError,直接返回 createErrorHandler,内部 errorHandler 会调用开发者自定义的 errorHandler,以及判断开发者是否监听了onError
|
||
return createErrorHandler(app);
|
||
});
|
||
|
||
const E = function () {
|
||
// Keep this empty so it's easier to inherit from
|
||
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
|
||
};
|
||
E.prototype = {
|
||
_id: 1,
|
||
on: function (name, callback, ctx) {
|
||
var e = this.e || (this.e = {});
|
||
(e[name] || (e[name] = [])).push({
|
||
fn: callback,
|
||
ctx: ctx,
|
||
_id: this._id,
|
||
});
|
||
return this._id++;
|
||
},
|
||
once: function (name, callback, ctx) {
|
||
var self = this;
|
||
function listener() {
|
||
self.off(name, listener);
|
||
callback.apply(ctx, arguments);
|
||
}
|
||
listener._ = callback;
|
||
return this.on(name, listener, ctx);
|
||
},
|
||
emit: function (name) {
|
||
var data = [].slice.call(arguments, 1);
|
||
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
|
||
var i = 0;
|
||
var len = evtArr.length;
|
||
for (i; i < len; i++) {
|
||
evtArr[i].fn.apply(evtArr[i].ctx, data);
|
||
}
|
||
return this;
|
||
},
|
||
off: function (name, event) {
|
||
var e = this.e || (this.e = {});
|
||
var evts = e[name];
|
||
var liveEvents = [];
|
||
if (evts && event) {
|
||
for (var i = evts.length - 1; i >= 0; i--) {
|
||
if (evts[i].fn === event ||
|
||
evts[i].fn._ === event ||
|
||
evts[i]._id === event) {
|
||
evts.splice(i, 1);
|
||
break;
|
||
}
|
||
}
|
||
liveEvents = evts;
|
||
}
|
||
// Remove event from queue to prevent memory leak
|
||
// Suggested by https://github.com/lazd
|
||
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
|
||
liveEvents.length ? (e[name] = liveEvents) : delete e[name];
|
||
return this;
|
||
},
|
||
};
|
||
var E$1 = E;
|
||
|
||
const borderStyles = {
|
||
black: 'rgba(0,0,0,0.4)',
|
||
white: 'rgba(255,255,255,0.4)',
|
||
};
|
||
function normalizeTabBarStyles(borderStyle) {
|
||
if (borderStyle && borderStyle in borderStyles) {
|
||
return borderStyles[borderStyle];
|
||
}
|
||
return borderStyle;
|
||
}
|
||
function normalizeTitleColor(titleColor) {
|
||
return titleColor === 'black' ? '#000000' : '#ffffff';
|
||
}
|
||
function resolveStringStyleItem(modeStyle, styleItem, key) {
|
||
if (isString(styleItem) && styleItem.startsWith('@')) {
|
||
const _key = styleItem.replace('@', '');
|
||
let _styleItem = modeStyle[_key] || styleItem;
|
||
switch (key) {
|
||
case 'titleColor':
|
||
_styleItem = normalizeTitleColor(_styleItem);
|
||
break;
|
||
case 'borderStyle':
|
||
_styleItem = normalizeTabBarStyles(_styleItem);
|
||
break;
|
||
}
|
||
return _styleItem;
|
||
}
|
||
return styleItem;
|
||
}
|
||
function normalizeStyles(pageStyle, themeConfig = {}, mode = 'light') {
|
||
const modeStyle = themeConfig[mode];
|
||
const styles = {};
|
||
if (typeof modeStyle === 'undefined' || !pageStyle)
|
||
return pageStyle;
|
||
Object.keys(pageStyle).forEach((key) => {
|
||
const styleItem = pageStyle[key]; // Object Array String
|
||
const parseStyleItem = () => {
|
||
if (isPlainObject$1(styleItem))
|
||
return normalizeStyles(styleItem, themeConfig, mode);
|
||
if (isArray(styleItem))
|
||
return styleItem.map((item) => {
|
||
if (isPlainObject$1(item))
|
||
return normalizeStyles(item, themeConfig, mode);
|
||
return resolveStringStyleItem(modeStyle, item);
|
||
});
|
||
return resolveStringStyleItem(modeStyle, styleItem, key);
|
||
};
|
||
styles[key] = parseStyleItem();
|
||
});
|
||
return styles;
|
||
}
|
||
|
||
// This file is auto-generated by the build process. Do not edit manually.
|
||
const UVUE_VAPOR_APP_EASYCOMS = [
|
||
'ad',
|
||
'camera',
|
||
'canvas',
|
||
'editor',
|
||
'button',
|
||
'checkbox',
|
||
'checkbox-group',
|
||
'form',
|
||
'input',
|
||
'label',
|
||
'picker',
|
||
'picker-view',
|
||
'picker-view-column',
|
||
'radio',
|
||
'radio-group',
|
||
'slider',
|
||
'switch',
|
||
'textarea',
|
||
'list-item',
|
||
'list-view',
|
||
'sticky-header',
|
||
'sticky-section',
|
||
'live-player',
|
||
'live-pusher',
|
||
'loading',
|
||
'map',
|
||
'match-media',
|
||
'navigator',
|
||
'page-container',
|
||
'progress',
|
||
'rich-text',
|
||
'swiper',
|
||
'swiper-item',
|
||
'video',
|
||
'flow-item',
|
||
'waterflow',
|
||
'web-view',
|
||
];
|
||
|
||
const APP_NATIVE_TAGS = [
|
||
'view',
|
||
'text',
|
||
'image',
|
||
'scroll-view',
|
||
'native-view',
|
||
'nested-scroll-header',
|
||
'nested-scroll-body',
|
||
'rich-text-native',
|
||
'cover-image',
|
||
'cover-view',
|
||
];
|
||
/**
|
||
* 可能后续会添加的tags,native或easycom
|
||
* movable-area
|
||
* movable-view
|
||
* share-element
|
||
* icon
|
||
* animation-view
|
||
*/
|
||
function isDom2AppNativeTag(tag) {
|
||
return APP_NATIVE_TAGS.includes(tag);
|
||
}
|
||
function isDom2VueComponentTag(tag) {
|
||
return UVUE_VAPOR_APP_EASYCOMS.includes(tag);
|
||
}
|
||
function isDom2AppVueComponentTag(tag) {
|
||
return UVUE_VAPOR_APP_EASYCOMS.includes(tag);
|
||
}
|
||
function isDom2AppUserVueComponentTag(tag) {
|
||
return !isDom2AppNativeTag(tag) && !isDom2VueComponentTag(tag);
|
||
}
|
||
|
||
class UniDOMStringMap extends Map {
|
||
constructor(options) {
|
||
super();
|
||
this._options = options;
|
||
}
|
||
get(key) {
|
||
const normalizedKey = normalizeDatasetKey(String(key));
|
||
return super.has(normalizedKey) ? super.get(normalizedKey) : null;
|
||
}
|
||
set(key, value) {
|
||
var _a, _b;
|
||
const normalizedKey = normalizeDatasetKey(String(key));
|
||
super.set(normalizedKey, value);
|
||
(_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.onSet) === null || _b === void 0 ? void 0 : _b.call(_a, normalizedKey, value);
|
||
return this;
|
||
}
|
||
has(key) {
|
||
return super.has(normalizeDatasetKey(String(key)));
|
||
}
|
||
delete(key) {
|
||
var _a, _b;
|
||
const normalizedKey = normalizeDatasetKey(String(key));
|
||
const deleted = super.delete(normalizedKey);
|
||
if (deleted) {
|
||
(_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.onDelete) === null || _b === void 0 ? void 0 : _b.call(_a, normalizedKey);
|
||
}
|
||
return deleted;
|
||
}
|
||
clear() {
|
||
const keys = Array.from(super.keys());
|
||
super.clear();
|
||
keys.forEach((key) => { var _a, _b; return (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.onDelete) === null || _b === void 0 ? void 0 : _b.call(_a, key); });
|
||
}
|
||
}
|
||
function normalizeDatasetKey(key) {
|
||
const normalizedKey = key.replace(/[A-Z]/g, (char) => char.toLowerCase());
|
||
if (normalizedKey.indexOf('data-') !== 0) {
|
||
return key;
|
||
}
|
||
return normalizedKey
|
||
.slice(5)
|
||
.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
||
}
|
||
function normalizeDatasetAttrName(key) {
|
||
return ('data-' +
|
||
normalizeDatasetKey(key).replace(/[A-Z]/g, (char) => {
|
||
return '-' + char.toLowerCase();
|
||
}));
|
||
}
|
||
function isReservedDatasetKey(target, key) {
|
||
return key in target;
|
||
}
|
||
function setDatasetValue(dataset, key, value) {
|
||
Map.prototype.set.call(dataset, normalizeDatasetKey(String(key)), value);
|
||
}
|
||
function initDataset(dataset, source) {
|
||
if (!source) {
|
||
return;
|
||
}
|
||
if (source instanceof Map) {
|
||
source.forEach((value, key) => setDatasetValue(dataset, key, value));
|
||
return;
|
||
}
|
||
Object.keys(source).forEach((key) => setDatasetValue(dataset, key, source[key]));
|
||
}
|
||
function createUniDOMStringMap(source, options) {
|
||
const target = new UniDOMStringMap(options);
|
||
initDataset(target, source);
|
||
return new Proxy(target, {
|
||
get(target, key, receiver) {
|
||
if (typeof key === 'string') {
|
||
if (!isReservedDatasetKey(target, key)) {
|
||
return target.has(key) ? target.get(key) : null;
|
||
}
|
||
}
|
||
const value = Reflect.get(target, key, target);
|
||
if (typeof value === 'function') {
|
||
return (...args) => {
|
||
const result = value.apply(target, args);
|
||
return result === target ? receiver : result;
|
||
};
|
||
}
|
||
return value;
|
||
},
|
||
set(target, key, value, receiver) {
|
||
if (typeof key === 'string' && !isReservedDatasetKey(target, key)) {
|
||
target.set(key, value);
|
||
return true;
|
||
}
|
||
return Reflect.set(target, key, value, receiver);
|
||
},
|
||
deleteProperty(target, key) {
|
||
if (typeof key === 'string' &&
|
||
!isReservedDatasetKey(target, key) &&
|
||
target.has(key)) {
|
||
return target.delete(key);
|
||
}
|
||
return Reflect.deleteProperty(target, key);
|
||
},
|
||
has(target, key) {
|
||
if (typeof key === 'string' && target.has(key)) {
|
||
return true;
|
||
}
|
||
return Reflect.has(target, key);
|
||
},
|
||
ownKeys(target) {
|
||
return Array.from(target.keys()).filter((key) => !isReservedDatasetKey(target, key));
|
||
},
|
||
getOwnPropertyDescriptor(target, key) {
|
||
if (typeof key === 'string' &&
|
||
!isReservedDatasetKey(target, key) &&
|
||
target.has(key)) {
|
||
return {
|
||
configurable: true,
|
||
enumerable: true,
|
||
value: target.get(key),
|
||
writable: true,
|
||
};
|
||
}
|
||
return Reflect.getOwnPropertyDescriptor(target, key);
|
||
},
|
||
});
|
||
}
|
||
|
||
function getEnvLocale() {
|
||
const { env } = process;
|
||
const lang = env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE;
|
||
return (lang && lang.replace(/[.:].*/, '')) || 'en';
|
||
}
|
||
|
||
const isStringIntegerKey = (key) => typeof key === 'string' &&
|
||
key !== 'NaN' &&
|
||
key[0] !== '-' &&
|
||
'' + parseInt(key, 10) === key;
|
||
const isNumberIntegerKey = (key) => typeof key === 'number' &&
|
||
!isNaN(key) &&
|
||
key >= 0 &&
|
||
parseInt(key + '', 10) === key;
|
||
/**
|
||
* 用于替代@vue/shared的isIntegerKey,原始方法在鸿蒙arkts中会引发bug。根本原因是arkts的数组的key是数字而不是字符串。
|
||
* 目前这个方法使用的地方都和数组有关,切记不能挪作他用。
|
||
* @param key
|
||
* @returns
|
||
*/
|
||
const isIntegerKey = (key) => isNumberIntegerKey(key) || isStringIntegerKey(key);
|
||
|
||
const GLOBALS_ALLOWED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
|
||
'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
|
||
'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error,' +
|
||
'uni';
|
||
const isGloballyAllowed = /*#__PURE__*/ makeMap(GLOBALS_ALLOWED);
|
||
|
||
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, BUILT_IN_TAG_NAMES, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, E$1 as Emitter, EventChannel, EventModifierFlags, H5_BUILT_IN_TAGS, H5_BUILT_IN_TAG_NAMES, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, MINI_PROGRAM_PAGE_RUNTIME_HOOKS, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVUE_BUILT_IN_TAGS, NVUE_U_BUILT_IN_TAGS, OFF_HOST_THEME_CHANGE, OFF_THEME_CHANGE, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_COPY_URL, ON_ERROR, ON_EXIT, ON_HIDE, ON_HOST_THEME_CHANGE, ON_INIT, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAST_PAGE_BACK_PRESS, ON_LAUNCH, ON_LIVE_MOUNT, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_CHANGE, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SAVE_EXIT_STATE, ON_SHARE_APP_MESSAGE, ON_SHARE_CHAT, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_TITLE_CLICK, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_UPLOAD_DOUYIN_VIDEO, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_AD_PLUGINS, UNI_SAFE_AREA_INSET_BOTTOM, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STATUS_BAR_HEIGHT, UNI_STORAGE_LOCALE, UNI_UI_CONFLICT_TAGS, UTS, UTSJSONObject, UTSValueIterable, UVUE_BUILT_IN_TAGS, UVUE_HARMONY_BUILT_IN_TAGS, UVUE_IOS_BUILT_IN_TAGS, UVUE_MP_BUILT_IN_TAGS, UVUE_WEB_BUILT_IN_CUSTOM_ELEMENTS, UVUE_WEB_BUILT_IN_TAGS, UniBaseNode, UniCommentNode, UniDOMStringMap, UniElement, UniError, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, VIRTUAL_HOST_CLASS, VIRTUAL_HOST_HIDDEN, VIRTUAL_HOST_ID, VIRTUAL_HOST_STYLE, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, batchGetPartClass, borderStyles, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniDOMStringMap, createUniEvent, customizeEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultNVueRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatDateTime, formatLog, getCustomDataset, getEnvLocale, getGlobal, getLen, getPartClass, getValueByDataPath, initCustomDatasetOnce, invokeArrayFns, invokeArrayFnsWithResults, invokeCreateErrorHandler, invokeCreateVueAppHook, isAppHarmonyUVueNativeTag, isAppIOSUVueNativeTag, isAppNVueNativeTag, isAppNativeTag, isAppUVueBuiltInEasyComponent, isAppUVueNativeTag, isAppVoidTag, isBuiltInComponent, isComponentInternalInstance, isComponentTag, isDom2AppNativeTag, isDom2AppUserVueComponentTag, isDom2AppVueComponentTag, isDom2VueComponentTag, isGloballyAllowed, isH5CustomElement, isH5NativeTag, isIntegerKey, isMPBuiltInComponent, isMiniProgramNativeTag, isMiniProgramUVueNativeTag, isRootHook, isRootImmediateHook, isUniLifecycleHook, isUniXElement, isWebBuiltInComponent, normalizeClass, normalizeDataset, normalizeDatasetAttrName, normalizeDatasetKey, normalizeEventType, normalizeProps, normalizeStyle, normalizeStyles, normalizeTabBarStyles, normalizeTarget, normalizeTitleColor, onCreateVueApp, once, parseEventName, parseNVueDataset, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveComponentInstance, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, sortObject, stringifyQuery, updateElementStyle };
|