| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591 |
- import { isHTMLTag, isSVGTag, hyphenate, camelize, normalizeStyle as normalizeStyle$1, isArray, isString, parseStringStyle, normalizeClass as normalizeClass$1, isFunction, isPlainObject, extend, capitalize } 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',
- ];
- const BUILT_IN_TAGS = 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 = [
- 'loading-indicator',
- 'list-view',
- 'list-item',
- 'swiper',
- 'swiper-item',
- 'rich-text',
- 'sticky-view',
- 'sticky-header',
- 'sticky-section',
- // 自定义
- 'uni-slider',
- // 原生实现
- 'button',
- ];
- const UVUE_WEB_BUILT_IN_TAGS = [
- 'list-view',
- 'list-item',
- 'sticky-section',
- 'sticky-header',
- 'cloud-db-element',
- ].map((tag) => 'uni-' + tag);
- const UVUE_IOS_BUILT_IN_TAGS = [
- 'scroll-view',
- 'web-view',
- 'slider',
- 'swiper',
- 'swiper-item',
- 'rich-text',
- 'button',
- 'list-view',
- 'list-item',
- 'switch',
- 'sticky-header',
- 'sticky-section',
- ];
- 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 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-', '');
- // TODO 区分x和非x
- return (BUILT_IN_TAGS.indexOf(realTag) !== -1 ||
- UVUE_WEB_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 || 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)) &&
- !isBuiltInComponent(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',
- ];
- function isAppUVueNativeTag(tag) {
- // 前端实现的内置组件都会注册一个根组件
- if (tag.startsWith('uni-') && tag.endsWith('-element')) {
- return true;
- }
- if (UVUE_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 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 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;
- 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_KEYBOARD_HEIGHT_CHANGE = 'onKeyboardHeightChange';
- const ON_PAGE_NOT_FOUND = 'onPageNotFound';
- const ON_UNHANDLE_REJECTION = 'onUnhandledRejection';
- 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_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_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';
- 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 Map) {
- const styleObject = {};
- value.forEach((value, key) => {
- styleObject[key] = value;
- });
- return normalizeStyle$1(styleObject);
- }
- 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 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;
- };
- 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('.'));
- }
- function sortObject(obj) {
- let sortObj = {};
- if (isPlainObject(obj)) {
- Object.keys(obj)
- .sort()
- .forEach((key) => {
- const _key = key;
- sortObj[_key] = obj[_key];
- });
- }
- return !Object.keys(sortObj) ? obj : sortObj;
- }
- function formatKey(key) {
- return camelize(key.substring(5));
- }
- // question/139181,增加副作用,避免 initCustomDataset 在 build 下被 tree-shaking
- const initCustomDatasetOnce = /*#__PURE__*/ once(() => {
- const prototype = HTMLElement.prototype;
- const setAttribute = prototype.setAttribute;
- prototype.setAttribute = function (key, value) {
- if (key.startsWith('data-') && this.tagName.startsWith('UNI-')) {
- const dataset = this.__uniDataset ||
- (this.__uniDataset = {});
- dataset[formatKey(key)] = value;
- }
- setAttribute.call(this, key, value);
- };
- const removeAttribute = prototype.removeAttribute;
- prototype.removeAttribute = function (key) {
- if (this.__uniDataset &&
- key.startsWith('data-') &&
- this.tagName.startsWith('UNI-')) {
- 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 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(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_BACK_PRESS,
- ON_PAGE_SCROLL,
- ON_TAB_ITEM_TAP,
- ON_REACH_BOTTOM,
- ON_PULL_DOWN_REFRESH,
- ON_SHARE_TIMELINE,
- ON_SHARE_APP_MESSAGE,
- 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,
- ];
- const PAGE_SYNC_HOOKS = [ON_LOAD, ON_SHOW];
- function isRootImmediateHook(name) {
- return PAGE_SYNC_HOOKS.indexOf(name) > -1;
- }
- 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_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,
- ];
- const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = /*#__PURE__*/ (() => {
- return {
- onPageScroll: 1,
- onShareAppMessage: 1 << 1,
- onShareTimeline: 1 << 2,
- };
- })();
- 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) => {
- if (isFunction(app._component.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 = {
- on: function (name, callback, ctx) {
- var e = this.e || (this.e = {});
- (e[name] || (e[name] = [])).push({
- fn: callback,
- ctx: ctx,
- });
- return this;
- },
- 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, callback) {
- var e = this.e || (this.e = {});
- var evts = e[name];
- var liveEvents = [];
- if (evts && callback) {
- for (var i = evts.length - 1; i >= 0; i--) {
- if (evts[i].fn === callback || evts[i].fn._ === callback) {
- 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 normalizeStyles(pageStyle, themeConfig = {}, mode = 'light') {
- const modeStyle = themeConfig[mode];
- const styles = {};
- if (!modeStyle) {
- return pageStyle;
- }
- Object.keys(pageStyle).forEach((key) => {
- let styleItem = pageStyle[key] // Object Array String
- ;
- styles[key] = (() => {
- if (isPlainObject(styleItem)) {
- return normalizeStyles(styleItem, themeConfig, mode);
- }
- else if (isArray(styleItem)) {
- return styleItem.map((item) => isPlainObject(item)
- ? normalizeStyles(item, themeConfig, mode)
- : item);
- }
- else 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;
- })();
- });
- return styles;
- }
- function getEnvLocale() {
- const { env } = process;
- const lang = env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE;
- return (lang && lang.replace(/[.:].*/, '')) || 'en';
- }
- 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, 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_THEME_CHANGE, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_EXIT, ON_HIDE, ON_INIT, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, 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_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, 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_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STORAGE_LOCALE, UNI_UI_CONFLICT_TAGS, UVUE_BUILT_IN_TAGS, UVUE_IOS_BUILT_IN_TAGS, UVUE_WEB_BUILT_IN_TAGS, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, borderStyles, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, customizeEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultNVueRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatDateTime, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDatasetOnce, invokeArrayFns, invokeCreateErrorHandler, invokeCreateVueAppHook, isAppNVueNativeTag, isAppNativeTag, isAppUVueNativeTag, isBuiltInComponent, isComponentInternalInstance, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, isRootImmediateHook, isUniLifecycleHook, isUniXElement, normalizeClass, normalizeDataset, normalizeEventType, normalizeProps, normalizeStyle, normalizeStyles, normalizeTabBarStyles, normalizeTarget, normalizeTitleColor, onCreateVueApp, once, parseEventName, parseNVueDataset, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveComponentInstance, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, sortObject, stringifyQuery, updateElementStyle };
|