diff --git a/packages/shims-uni-app.d.ts b/packages/shims-uni-app.d.ts index 5d34c4650fb5f1603dced0dfc1d2156faf28d6ea..6d79b4026caad313c1d2932a3d024309b7adb35c 100644 --- a/packages/shims-uni-app.d.ts +++ b/packages/shims-uni-app.d.ts @@ -393,7 +393,7 @@ declare namespace UniApp { * @param event * @param callback */ - subscribe(event: string, callback: CallbackFunction): void + subscribe(event: string, callback: CallbackFunction, once?: boolean): void /** * 取消订阅 Service 的自定义事件 * 如果没有提供参数,则移除所有的事件监听器; @@ -417,5 +417,16 @@ declare namespace UniApp { * @param pageId */ publishHandler(event: string, args?: unknown, pageId?: number): void + /** + * 执行 View 层方法,并获取返回值 + * @param name + * @param args + * @param callback + */ + invokeServiceMethod( + name: string, + args: Args, + callback?: (res: Res) => void + ): void } } diff --git a/packages/uni-app-plus/dist/style.css b/packages/uni-app-plus/dist/style.css index 35976d8232e22b6adc195a4da3be5c513cf6d0e8..c9ff84a73b6bb1ae3a96b51bbd228acc62d90d6a 100644 --- a/packages/uni-app-plus/dist/style.css +++ b/packages/uni-app-plus/dist/style.css @@ -1143,7 +1143,37 @@ uni-input[hidden] { .uni-label-pointer { cursor: pointer; } -uni-movable-area { +uni-map { + width: 300px; + height: 225px; + display: inline-block; + line-height: 0; + overflow: hidden; + position: relative; +} + +uni-map[hidden] { + display: none; +} + +.uni-map-container { + width: 100%; + height: 100%; + position: absolute; + top: 0; + left: 0; + overflow: hidden; + background-color: black; +} + +.uni-map-slot { + position: absolute; + top: 0; + width: 100%; + height: 100%; + overflow: hidden; + pointer-events: none; +}uni-movable-area { display: block; position: relative; width: 10px; diff --git a/packages/uni-app-plus/dist/uni-app-service.es.js b/packages/uni-app-plus/dist/uni-app-service.es.js index 141b710f59a267a1b5c5aeeb164b91ab5411d174..a63929cdf3a28691816ef7758f16639253fe3b07 100644 --- a/packages/uni-app-plus/dist/uni-app-service.es.js +++ b/packages/uni-app-plus/dist/uni-app-service.es.js @@ -1587,6 +1587,54 @@ var serviceContext = (function (vue) { })); } }); + const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => { + const name = 'uni.scanCode.'; + { + useI18n().add(LOCALE_EN, normalizeMessages(name, { + title: 'Scan code', + album: 'Album', + fail: 'Recognition failure', + 'flash.on': 'Tap to turn light on', + 'flash.off': 'Tap to turn light off', + })); + } + { + useI18n().add(LOCALE_ES, normalizeMessages(name, { + title: 'Código de escaneo', + album: 'Álbum', + fail: 'Échec de la reconnaissance', + 'flash.on': 'Toque para encender la luz', + 'flash.off': 'Toque para apagar la luz', + })); + } + { + useI18n().add(LOCALE_FR, normalizeMessages(name, { + title: 'Code d’analyse', + album: 'Album', + fail: 'Fallo de reconocimiento', + 'flash.on': "Appuyez pour activer l'éclairage", + 'flash.off': "Appuyez pour désactiver l'éclairage", + })); + } + { + useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, { + title: '扫码', + album: '相册', + fail: '识别失败', + 'flash.on': '轻触照亮', + 'flash.off': '轻触关闭', + })); + } + { + useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, { + title: '掃碼', + album: '相冊', + fail: '識別失敗', + 'flash.on': '輕觸照亮', + 'flash.off': '輕觸關閉', + })); + } + }); const initI18nStartSoterAuthenticationMsgsOnce = /*#__PURE__*/ once(() => { const name = 'uni.startSoterAuthentication.'; { @@ -1610,8 +1658,6 @@ var serviceContext = (function (vue) { } }); - const INVOKE_VIEW_API = 'invokeViewApi'; - 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) @@ -1694,6 +1740,9 @@ var serviceContext = (function (vue) { }; } + const INVOKE_VIEW_API = 'invokeViewApi'; + const INVOKE_SERVICE_API = 'invokeServiceApi'; + function hasRpx(str) { str = str + ''; return str.indexOf('rpx') !== -1 || str.indexOf('upx') !== -1; @@ -1861,13 +1910,15 @@ var serviceContext = (function (vue) { } } - let invokeViewMethodId = 0; + const invokeOnCallback = (name, res) => UniServiceJSBridge.emit('api.' + name, res); + + let invokeViewMethodId = 1; function publishViewMethodName() { return getCurrentPageId() + '.' + INVOKE_VIEW_API; } const invokeViewMethod = (name, args, pageId, callback) => { const { subscribe, publishHandler } = UniServiceJSBridge; - const id = invokeViewMethodId++; + const id = callback ? invokeViewMethodId++ : 0; callback && subscribe(INVOKE_VIEW_API + '.' + id, callback, true); publishHandler(publishViewMethodName(), { id, name, args }, pageId); }; @@ -1880,8 +1931,34 @@ var serviceContext = (function (vue) { return () => { unsubscribe(subscribeName); }; - }; - const invokeOnCallback = (name, res) => UniServiceJSBridge.emit('api.' + name, res); + }; + + const serviceMethods = Object.create(null); + function subscribeServiceMethod() { + UniServiceJSBridge.subscribe(INVOKE_SERVICE_API, onInvokeServiceMethod); + } + function registerServiceMethod(name, fn) { + if (!serviceMethods[name]) { + serviceMethods[name] = fn; + } + } + function onInvokeServiceMethod({ id, name, args, }, pageId) { + const publish = (res) => { + id && + UniServiceJSBridge.publishHandler(INVOKE_SERVICE_API + '.' + id, res, pageId); + }; + const handler = serviceMethods[name]; + if (handler) { + handler(args, publish); + } + else { + publish({}); + if ((process.env.NODE_ENV !== 'production')) { + console.error(formatLog('invokeViewMethod', name, 'not register')); + } + } + } + const ServiceJSBridge = /*#__PURE__*/ extend(initBridge('view' /* view 指的是 service 层订阅的是 view 层事件 */), { invokeOnCallback, invokeViewMethod, @@ -2052,8 +2129,21 @@ var serviceContext = (function (vue) { return false; } - function operateVideoPlayer(videoId, pageId, type, data) { } - function operateMap(id, pageId, type, data) { } + function operateVideoPlayer(videoId, pageId, type, data) { + UniServiceJSBridge.invokeViewMethod('video.' + videoId, { + videoId, + type, + data, + }, pageId); + } + + function operateMap(id, pageId, type, data, operateMapCallback) { + UniServiceJSBridge.invokeViewMethod('map.' + id, { + type, + data, + }, pageId, operateMapCallback); + } + function addIntersectionObserver(args, pageId) { } function removeIntersectionObserver(args, pageId) { } function addMediaQueryObserver(args, pageId) { } @@ -2295,40 +2385,48 @@ var serviceContext = (function (vue) { ]; const API_CREATE_INNER_AUDIO_CONTEXT = 'createInnerAudioContext'; + const RATES = [0.5, 0.8, 1.0, 1.25, 1.5, 2.0]; class VideoContext { constructor(id, pageId) { this.id = id; this.pageId = pageId; } play() { - operateVideoPlayer(this.id, this.pageId); + operateVideoPlayer(this.id, this.pageId, 'play'); } pause() { - operateVideoPlayer(this.id, this.pageId); + operateVideoPlayer(this.id, this.pageId, 'pause'); } stop() { - operateVideoPlayer(this.id, this.pageId); + operateVideoPlayer(this.id, this.pageId, 'stop'); } seek(position) { - operateVideoPlayer(this.id, this.pageId); + operateVideoPlayer(this.id, this.pageId, 'seek', { + position, + }); } sendDanmu(args) { - operateVideoPlayer(this.id, this.pageId); + operateVideoPlayer(this.id, this.pageId, 'sendDanmu', args); } playbackRate(rate) { - operateVideoPlayer(this.id, this.pageId); + if (!~RATES.indexOf(rate)) { + rate = 1.0; + } + operateVideoPlayer(this.id, this.pageId, 'playbackRate', { + rate, + }); } requestFullScreen(args = {}) { - operateVideoPlayer(this.id, this.pageId); + operateVideoPlayer(this.id, this.pageId, 'requestFullScreen', args); } exitFullScreen() { - operateVideoPlayer(this.id, this.pageId); + operateVideoPlayer(this.id, this.pageId, 'exitFullScreen'); } showStatusBar() { - operateVideoPlayer(this.id, this.pageId); + operateVideoPlayer(this.id, this.pageId, 'showStatusBar'); } hideStatusBar() { - operateVideoPlayer(this.id, this.pageId); + operateVideoPlayer(this.id, this.pageId, 'hideStatusBar'); } } const createVideoContext = defineSyncApi(API_CREATE_VIDEO_CONTEXT, (id, context) => { @@ -2338,28 +2436,48 @@ var serviceContext = (function (vue) { return new VideoContext(id, getPageIdByVm(getCurrentPageVm())); }); + const operateMapCallback = (options, res) => { + const errMsg = res.errMsg || ''; + if (new RegExp('\\:\\s*fail').test(errMsg)) { + options.fail && options.fail(res); + } + else { + options.success && options.success(res); + } + options.complete && options.complete(res); + }; + const operateMapWrap = (id, pageId, type, options) => { + operateMap(id, pageId, type, options, (res) => { + options && operateMapCallback(options, res); + }); + }; class MapContext { constructor(id, pageId) { this.id = id; this.pageId = pageId; } getCenterLocation(options) { - operateMap(this.id, this.pageId); + operateMapWrap(this.id, this.pageId, 'getCenterLocation', options); } moveToLocation() { - operateMap(this.id, this.pageId); + operateMapWrap(this.id, this.pageId, 'moveToLocation'); } getScale(options) { - operateMap(this.id, this.pageId); + operateMapWrap(this.id, this.pageId, 'getScale', options); } getRegion(options) { - operateMap(this.id, this.pageId); + operateMapWrap(this.id, this.pageId, 'getRegion', options); } includePoints(options) { - operateMap(this.id, this.pageId); + operateMapWrap(this.id, this.pageId, 'includePoints', options); } translateMarker(options) { - operateMap(this.id, this.pageId); + operateMapWrap(this.id, this.pageId, 'translateMarker', options); + } + $getAppMap() { + { + return plus.maps.getMapById(this.pageId + '-map-' + this.id); + } } addCustomLayer() { } removeCustomLayer() { } @@ -2370,8 +2488,7 @@ var serviceContext = (function (vue) { addMarkers() { } removeMarkers() { } moveAlong() { } - openMapAp() { } - $getAppMap() { } + openMapApp() { } } const createMapContext = defineSyncApi(API_CREATE_MAP_CONTEXT, (id, context) => { if (context) { @@ -4027,6 +4144,13 @@ var serviceContext = (function (vue) { authContent: String, }; + const API_SCAN_CODE = 'scanCode'; + const ScanCodeProtocol = { + onlyFromCamera: Boolean, + scanType: Array, + autoDecodeCharSet: Boolean, + }; + const API_GET_STORAGE = 'getStorage'; const GetStorageProtocol = { key: { @@ -5774,8 +5898,222 @@ var serviceContext = (function (vue) { } }, StartSoterAuthenticationProtocols, StartSoterAuthenticationOptions); + let plus_; + let weex_; + let BroadcastChannel_; + function getRuntime() { + return typeof window === 'object' && + typeof navigator === 'object' && + typeof document === 'object' + ? 'webview' + : 'v8'; + } + function getPageId() { + return plus_.webview.currentWebview().id; + } + let channel; + let globalEvent$1; + const callbacks$2 = {}; + function onPlusMessage$1(res) { + const message = res.data && res.data.__message; + if (!message || !message.__page) { + return; + } + const pageId = message.__page; + const callback = callbacks$2[pageId]; + callback && callback(message); + if (!message.keep) { + delete callbacks$2[pageId]; + } + } + function addEventListener(pageId, callback) { + if (getRuntime() === 'v8') { + if (BroadcastChannel_) { + channel && channel.close(); + channel = new BroadcastChannel_(getPageId()); + channel.onmessage = onPlusMessage$1; + } + else if (!globalEvent$1) { + globalEvent$1 = weex_.requireModule('globalEvent'); + globalEvent$1.addEventListener('plusMessage', onPlusMessage$1); + } + } + else { + // @ts-ignore + window.__plusMessage = onPlusMessage$1; + } + callbacks$2[pageId] = callback; + } + class Page { + constructor(webview) { + this.webview = webview; + } + sendMessage(data) { + const message = { + __message: { + data, + }, + }; + const id = this.webview.id; + if (BroadcastChannel_) { + const channel = new BroadcastChannel_(id); + channel.postMessage(message); + } + else { + plus_.webview.postMessageToUniNView && + plus_.webview.postMessageToUniNView(message, id); + } + } + close() { + this.webview.close(); + } + } + function showPage({ context = {}, url, data = {}, style = {}, onMessage, onClose, }) { + // eslint-disable-next-line + plus_ = context.plus || plus; + // eslint-disable-next-line + weex_ = context.weex || (typeof weex === 'object' ? weex : null); + // eslint-disable-next-line + BroadcastChannel_ = + context.BroadcastChannel || + (typeof BroadcastChannel === 'object' ? BroadcastChannel : null); + const titleNView = { + autoBackButton: true, + titleSize: '17px', + }; + const pageId = `page${Date.now()}`; + style = Object.assign({}, style); + if (style.titleNView !== false && style.titleNView !== 'none') { + style.titleNView = Object.assign(titleNView, style.titleNView); + } + const defaultStyle = { + top: 0, + bottom: 0, + usingComponents: {}, + popGesture: 'close', + scrollIndicator: 'none', + animationType: 'pop-in', + animationDuration: 200, + uniNView: { + path: `${(typeof process === 'object' && + process.env && + process.env.VUE_APP_TEMPLATE_PATH) || + ''}/${url}.js`, + defaultFontSize: plus_.screen.resolutionWidth / 20, + viewport: plus_.screen.resolutionWidth, + }, + }; + style = Object.assign(defaultStyle, style); + const page = plus_.webview.create('', pageId, style, { + extras: { + from: getPageId(), + runtime: getRuntime(), + data, + useGlobalEvent: !BroadcastChannel_, + }, + }); + page.addEventListener('close', onClose); + addEventListener(pageId, (message) => { + if (typeof onMessage === 'function') { + onMessage(message.data); + } + if (!message.keep) { + page.close('auto'); + } + }); + page.show(style.animationType, style.animationDuration); + return new Page(page); + } + + function getStatusBarStyle$1() { + let style = plus.navigator.getStatusBarStyle(); + if (style === 'UIStatusBarStyleBlackTranslucent' || + style === 'UIStatusBarStyleBlackOpaque' || + style === 'null') { + style = 'light'; + } + else if (style === 'UIStatusBarStyleDefault') { + style = 'dark'; + } + return style; + } + const scanCode = defineAsyncApi(API_SCAN_CODE, (options, { resolve, reject }) => { + initI18nScanCodeMsgsOnce(); + const { t } = useI18n(); + const statusBarStyle = getStatusBarStyle$1(); + const isDark = statusBarStyle !== 'light'; + let result; + let success = false; + const page = showPage({ + url: '__uniappscan', + data: Object.assign({}, options, { + messages: { + fail: t('uni.scanCode.fail'), + 'flash.on': t('uni.scanCode.flash.on'), + 'flash.off': t('uni.scanCode.flash.off'), + }, + }), + style: { + // @ts-ignore + animationType: options.animationType || 'pop-in', + titleNView: { + autoBackButton: true, + // @ts-ignore + type: 'float', + // @ts-ignore + titleText: options.titleText || t('uni.scanCode.title'), + titleColor: '#ffffff', + backgroundColor: 'rgba(0,0,0,0)', + buttons: !options.onlyFromCamera + ? [ + { + // @ts-ignore + text: options.albumText || t('uni.scanCode.album'), + fontSize: '17px', + width: '60px', + onclick: () => { + page.sendMessage({ + type: 'gallery', + }); + }, + }, + ] + : [], + }, + popGesture: 'close', + background: '#000000', + backButtonAutoControl: 'close', + }, + onMessage({ event, detail, }) { + result = detail; + success = event === 'marked'; + }, + onClose() { + if (isDark) { + plus.navigator.setStatusBarStyle('dark'); + } + result + ? success + ? (delete result.message, resolve(result)) + : reject(result.message) + : reject('cancel'); + }, + }); + if (isDark) { + plus.navigator.setStatusBarStyle('light'); + page.webview.addEventListener('popGesture', ({ type, result }) => { + if (type === 'start') { + plus.navigator.setStatusBarStyle('dark'); + } + else if (type === 'end' && !result) { + plus.navigator.setStatusBarStyle('light'); + } + }); + } + }, ScanCodeProtocol); + const onThemeChange = defineOnApi(ON_THEME_CHANGE, () => { - UniServiceJSBridge.on(ON_THEME_CHANGE, res => { + UniServiceJSBridge.on(ON_THEME_CHANGE, (res) => { UniServiceJSBridge.invokeOnCallback(ON_THEME_CHANGE, res); }); }); @@ -5929,7 +6267,7 @@ var serviceContext = (function (vue) { } }, }; - const callbacks$2 = { + const callbacks$1 = { pause: null, resume: null, start: null, @@ -5940,29 +6278,29 @@ var serviceContext = (function (vue) { const state = res.state; delete res.state; delete res.errMsg; - if (state && typeof callbacks$2[state] === 'function') { - callbacks$2[state](res); + if (state && typeof callbacks$1[state] === 'function') { + callbacks$1[state](res); } } class RecorderManager { constructor() { } onError(callback) { - callbacks$2.error = callback; + callbacks$1.error = callback; } onFrameRecorded(callback) { } onInterruptionBegin(callback) { } onInterruptionEnd(callback) { } onPause(callback) { - callbacks$2.pause = callback; + callbacks$1.pause = callback; } onResume(callback) { - callbacks$2.resume = callback; + callbacks$1.resume = callback; } onStart(callback) { - callbacks$2.start = callback; + callbacks$1.start = callback; } onStop(callback) { - callbacks$2.stop = callback; + callbacks$1.stop = callback; } pause() { Recorder.pause(); @@ -6493,7 +6831,7 @@ var serviceContext = (function (vue) { const socketTasks = []; const socketsMap = {}; - const globalEvent$1 = { + const globalEvent = { open: '', close: '', error: '', @@ -6595,8 +6933,8 @@ var serviceContext = (function (vue) { } socketStateChange(name, res = {}) { const data = name === 'message' ? res : {}; - if (this === socketTasks[0] && globalEvent$1[name]) { - UniServiceJSBridge.invokeOnCallback(globalEvent$1[name], data); + if (this === socketTasks[0] && globalEvent[name]) { + UniServiceJSBridge.invokeOnCallback(globalEvent[name], data); } // WYQ fix: App平台修复websocket onOpen时发送数据报错的Bug this._callbacks[name].forEach((callback) => { @@ -6695,7 +7033,7 @@ var serviceContext = (function (vue) { function on(event) { const api = `onSocket${capitalize(event)}`; return defineOnApi(api, () => { - globalEvent$1[event] = api; + globalEvent[event] = api; }); } const onSocketOpen = /*#__PURE__*/ on('open'); @@ -7077,7 +7415,7 @@ var serviceContext = (function (vue) { 'error', 'waiting', ]; - const callbacks$1 = { + const callbacks = { canplay: [], play: [], pause: [], @@ -7256,7 +7594,7 @@ var serviceContext = (function (vue) { }); } function onBackgroundAudioStateChange({ state, errMsg, errCode, dataUrl, }) { - callbacks$1[state].forEach((callback) => { + callbacks[state].forEach((callback) => { if (typeof callback === 'function') { callback(state === 'error' ? { @@ -7271,7 +7609,7 @@ var serviceContext = (function (vue) { eventNames.forEach((item) => { BackgroundAudioManager.prototype[`on${capitalize(item)}`] = function (callback) { - callbacks$1[item].push(callback); + callbacks[item].push(callback); }; }); }); @@ -7497,133 +7835,6 @@ var serviceContext = (function (vue) { }); }, GetLocationProtocol, GetLocationOptions); - let plus_; - let weex_; - let BroadcastChannel_; - function getRuntime() { - return typeof window === 'object' && - typeof navigator === 'object' && - typeof document === 'object' - ? 'webview' - : 'v8'; - } - function getPageId() { - return plus_.webview.currentWebview().id; - } - let channel; - let globalEvent; - const callbacks = {}; - function onPlusMessage$1(res) { - const message = res.data && res.data.__message; - if (!message || !message.__page) { - return; - } - const pageId = message.__page; - const callback = callbacks[pageId]; - callback && callback(message); - if (!message.keep) { - delete callbacks[pageId]; - } - } - function addEventListener(pageId, callback) { - if (getRuntime() === 'v8') { - if (BroadcastChannel_) { - channel && channel.close(); - channel = new BroadcastChannel_(getPageId()); - channel.onmessage = onPlusMessage$1; - } - else if (!globalEvent) { - globalEvent = weex_.requireModule('globalEvent'); - globalEvent.addEventListener('plusMessage', onPlusMessage$1); - } - } - else { - // @ts-ignore - window.__plusMessage = onPlusMessage$1; - } - callbacks[pageId] = callback; - } - class Page { - constructor(webview) { - this.webview = webview; - } - sendMessage(data) { - const message = { - __message: { - data, - }, - }; - const id = this.webview.id; - if (BroadcastChannel_) { - const channel = new BroadcastChannel_(id); - channel.postMessage(message); - } - else { - plus_.webview.postMessageToUniNView && - plus_.webview.postMessageToUniNView(message, id); - } - } - close() { - this.webview.close(); - } - } - function showPage({ context = {}, url, data = {}, style = {}, onMessage, onClose, }) { - // eslint-disable-next-line - plus_ = context.plus || plus; - // eslint-disable-next-line - weex_ = context.weex || (typeof weex === 'object' ? weex : null); - // eslint-disable-next-line - BroadcastChannel_ = - context.BroadcastChannel || - (typeof BroadcastChannel === 'object' ? BroadcastChannel : null); - const titleNView = { - autoBackButton: true, - titleSize: '17px', - }; - const pageId = `page${Date.now()}`; - style = Object.assign({}, style); - if (style.titleNView !== false && style.titleNView !== 'none') { - style.titleNView = Object.assign(titleNView, style.titleNView); - } - const defaultStyle = { - top: 0, - bottom: 0, - usingComponents: {}, - popGesture: 'close', - scrollIndicator: 'none', - animationType: 'pop-in', - animationDuration: 200, - uniNView: { - path: `${(typeof process === 'object' && - process.env && - process.env.VUE_APP_TEMPLATE_PATH) || - ''}/${url}.js`, - defaultFontSize: plus_.screen.resolutionWidth / 20, - viewport: plus_.screen.resolutionWidth, - }, - }; - style = Object.assign(defaultStyle, style); - const page = plus_.webview.create('', pageId, style, { - extras: { - from: getPageId(), - runtime: getRuntime(), - data, - useGlobalEvent: !BroadcastChannel_, - }, - }); - page.addEventListener('close', onClose); - addEventListener(pageId, (message) => { - if (typeof onMessage === 'function') { - onMessage(message.data); - } - if (!message.keep) { - page.close('auto'); - } - }); - page.show(style.animationType, style.animationDuration); - return new Page(page); - } - function getStatusBarStyle() { let style = plus.navigator.getStatusBarStyle(); if (style === 'UIStatusBarStyleBlackTranslucent' || @@ -8646,7 +8857,6 @@ var serviceContext = (function (vue) { const VD_SYNC = 'vdSync'; const ON_WEBVIEW_READY = 'onWebviewReady'; - const INVOKE_SERVICE_API = 'invokeServiceApi'; const ACTION_TYPE_DICT = 0; function onNodeEvent(nodeId, evt, pageNode) { @@ -8671,6 +8881,28 @@ var serviceContext = (function (vue) { }); } + function subscribeAd() { + // view 层通过 UniViewJSBridge.invokeServiceMethod('getAdData', args, function({data})=>{console.log(data)}) + registerServiceMethod('getAdData', (args, resolve) => { + // TODO args: view 层传输的参数,处理完之后,resolve:回传给 service,如resolve({data}) + }); + } + + const API_ROUTE = [ + 'switchTab', + 'reLaunch', + 'redirectTo', + 'navigateTo', + 'navigateBack', + ]; + function subscribeNavigator() { + API_ROUTE.forEach((name) => { + registerServiceMethod(name, (args) => { + uni[name](args); + }); + }); + } + function initNVue(webviewStyle, routeMeta, path) { if (path && routeMeta.isNVue) { webviewStyle.uniNView = { @@ -9173,11 +9405,10 @@ var serviceContext = (function (vue) { // 非纯原生 subscribe(ON_WEBVIEW_READY, subscribeWebviewReady); subscribe(VD_SYNC, onVdSync); - subscribe(INVOKE_SERVICE_API, onInvokeServiceApi); + subscribeServiceMethod(); + subscribeAd(); + subscribeNavigator(); } - } - function onInvokeServiceApi({ data: { method, args }, }) { - uni[method] && uni[method](args); } let appCtx; @@ -10531,6 +10762,7 @@ var serviceContext = (function (vue) { checkIsSupportSoterAuthentication: checkIsSupportSoterAuthentication, checkIsSoterEnrolledInDevice: checkIsSoterEnrolledInDevice, startSoterAuthentication: startSoterAuthentication, + scanCode: scanCode, onThemeChange: onThemeChange, getImageInfo: getImageInfo, getVideoInfo: getVideoInfo, diff --git a/packages/uni-app-plus/dist/uni-app-view.umd.js b/packages/uni-app-plus/dist/uni-app-view.umd.js index c8b60686b447bd021e636da0667cb44a69469b20..21adeb40d70c11749e7d34a41f5fb4bf3e083df2 100644 --- a/packages/uni-app-plus/dist/uni-app-view.umd.js +++ b/packages/uni-app-plus/dist/uni-app-view.umd.js @@ -6,12 +6,12 @@ var nvue = "[nvue] uni-view,\n[nvue] uni-label,\n[nvue] uni-swiper-item,\n[nvue] uni-scroll-view {\n display: flex;\n flex-shrink: 0;\n flex-grow: 0;\n flex-basis: auto;\n align-items: stretch;\n align-content: flex-start;\n}\n\n[nvue] uni-button {\n margin: 0;\n}\n\n[nvue-dir-row] uni-view,\n[nvue-dir-row] uni-label,\n[nvue-dir-row] uni-swiper-item {\n flex-direction: row;\n}\n\n[nvue-dir-column] uni-view,\n[nvue-dir-column] uni-label,\n[nvue-dir-column] uni-swiper-item {\n flex-direction: column;\n}\n\n[nvue-dir-row-reverse] uni-view,\n[nvue-dir-row-reverse] uni-label,\n[nvue-dir-row-reverse] uni-swiper-item {\n flex-direction: row-reverse;\n}\n\n[nvue-dir-column-reverse] uni-view,\n[nvue-dir-column-reverse] uni-label,\n[nvue-dir-column-reverse] uni-swiper-item {\n flex-direction: column-reverse;\n}\n\n[nvue] uni-view,\n[nvue] uni-image,\n[nvue] uni-input,\n[nvue] uni-scroll-view,\n[nvue] uni-swiper,\n[nvue] uni-swiper-item,\n[nvue] uni-text,\n[nvue] uni-textarea,\n[nvue] uni-video {\n position: relative;\n border: 0px solid #000000;\n box-sizing: border-box;\n}\n\n[nvue] uni-swiper-item {\n position: absolute;\n}\n"; var resizeSensor = "@keyframes once-show {\n from {\n top: 0;\n }\n}\nuni-resize-sensor,\nuni-resize-sensor > div {\n position: absolute;\n left: 0;\n top: 0;\n right: 0;\n bottom: 0;\n overflow: hidden;\n}\nuni-resize-sensor {\n display: block;\n z-index: -1;\n visibility: hidden;\n animation: once-show 1ms;\n}\nuni-resize-sensor > div > div {\n position: absolute;\n left: 0;\n top: 0;\n}\nuni-resize-sensor > div:first-child > div {\n width: 100000px;\n height: 100000px;\n}\nuni-resize-sensor > div:last-child > div {\n width: 200%;\n height: 200%;\n}\n"; function makeMap$1(str, expectsLowerCase) { - const map = Object.create(null); + const map2 = Object.create(null); const list2 = str.split(","); for (let i = 0; i < list2.length; i++) { - map[list2[i]] = true; + map2[list2[i]] = true; } - return expectsLowerCase ? (val) => !!map[val.toLowerCase()] : (val) => !!map[val]; + return expectsLowerCase ? (val) => !!map2[val.toLowerCase()] : (val) => !!map2[val]; } const GLOBALS_WHITE_LISTED = "Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt"; const isGloballyWhitelisted = /* @__PURE__ */ makeMap$1(GLOBALS_WHITE_LISTED); @@ -568,7 +568,6 @@ })); } }); - const INVOKE_VIEW_API = "invokeViewApi"; const E = function() { }; E.prototype = { @@ -642,14 +641,22 @@ } }; } - const ViewJSBridge = /* @__PURE__ */ initBridge("service"); + const INVOKE_VIEW_API = "invokeViewApi"; + const INVOKE_SERVICE_API = "invokeServiceApi"; + let invokeServiceMethodId = 1; + const invokeServiceMethod = (name, args, callback) => { + const { subscribe, publishHandler: publishHandler2 } = UniViewJSBridge; + const id2 = callback ? invokeServiceMethodId++ : 0; + callback && subscribe(INVOKE_SERVICE_API + "." + id2, callback, true); + publishHandler2(INVOKE_SERVICE_API, { id: id2, name, args }); + }; + const viewMethods = Object.create(null); function normalizeViewMethodName(pageId, name) { return pageId + "." + name; } function subscribeViewMethod(pageId) { UniViewJSBridge.subscribe(normalizeViewMethodName(pageId, INVOKE_VIEW_API), onInvokeViewMethod); } - const viewMethods = Object.create(null); function registerViewMethod(pageId, name, fn) { name = normalizeViewMethodName(pageId, name); if (!viewMethods[name]) { @@ -667,7 +674,7 @@ }, pageId) { name = normalizeViewMethodName(pageId, name); const publish = (res) => { - UniViewJSBridge.publishHandler(INVOKE_VIEW_API + "." + id2, res); + id2 && UniViewJSBridge.publishHandler(INVOKE_VIEW_API + "." + id2, res); }; const handler = viewMethods[name]; if (handler) { @@ -679,6 +686,9 @@ } } } + const ViewJSBridge = /* @__PURE__ */ extend(initBridge("service"), { + invokeServiceMethod + }); const LONGPRESS_TIMEOUT = 350; const LONGPRESS_THRESHOLD = 10; const passiveOptions$2 = passive(true); @@ -3964,7 +3974,31 @@ return result; } const isTeleport = (type) => type.__isTeleport; + const COMPONENTS = "components"; + function resolveComponent(name, maybeSelfReference) { + return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name; + } const NULL_DYNAMIC_COMPONENT = Symbol(); + function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) { + const instance = currentRenderingInstance || currentInstance; + if (instance) { + const Component = instance.type; + if (type === COMPONENTS) { + const selfName = getComponentName(Component); + if (selfName && (selfName === name || selfName === camelize(name) || selfName === capitalize(camelize(name)))) { + return Component; + } + } + const res = resolve(instance[type] || Component[type], name) || resolve(instance.appContext[type], name); + if (!res && maybeSelfReference) { + return Component; + } + return res; + } + } + function resolve(registry, name) { + return registry && (registry[name] || registry[camelize(name)] || registry[capitalize(camelize(name))]); + } const Fragment = Symbol(void 0); const Text$1 = Symbol(void 0); const Comment$1 = Symbol(void 0); @@ -5411,7 +5445,6 @@ [ON_PAGE_SCROLL, ON_REACH_BOTTOM]; const VD_SYNC = "vdSync"; const ON_WEBVIEW_READY = "onWebviewReady"; - const INVOKE_SERVICE_API = "invokeServiceApi"; const ACTION_TYPE_DICT = 0; const APP_SERVICE_ID = "__uniapp__service"; const UniViewJSBridge$1 = /* @__PURE__ */ extend(ViewJSBridge, { @@ -5729,31 +5762,20 @@ confirmColor: PRIMARY_COLOR } }); - function invokeServiceApi(method, args = {}) { - UniViewJSBridge.publishHandler(INVOKE_SERVICE_API, { - data: { - method, - args - }, - options: { - timestamp: Date.now() - } - }); - } function navigateTo(args) { - invokeServiceApi("navigateTo", args); + UniViewJSBridge.invokeServiceMethod("navigateTo", args); } function navigateBack(args) { - invokeServiceApi("navigateBack", args); + UniViewJSBridge.invokeServiceMethod("navigateBack", args); } function reLaunch(args) { - invokeServiceApi("reLaunch", args); + UniViewJSBridge.invokeServiceMethod("reLaunch", args); } function redirectTo(args) { - invokeServiceApi("redirectTo", args); + UniViewJSBridge.invokeServiceMethod("redirectTo", args); } function switchTab(args) { - invokeServiceApi("switchTab", args); + UniViewJSBridge.invokeServiceMethod("switchTab", args); } var uni$1 = /* @__PURE__ */ Object.freeze({ __proto__: null, @@ -6558,7 +6580,7 @@ return fields; } const uniLabelKey = PolySymbol("uniLabel"); - const props$o = { + const props$p = { for: { type: String, default: "" @@ -6566,7 +6588,7 @@ }; var Label = /* @__PURE__ */ defineBuiltInComponent({ name: "Label", - props: props$o, + props: props$p, setup(props2, { slots }) { @@ -7022,7 +7044,7 @@ tempCanvas.height = height; return tempCanvas; } - const props$n = { + const props$o = { canvasId: { type: String, default: "" @@ -7038,7 +7060,7 @@ compatConfig: { MODE: 3 }, - props: props$n, + props: props$o, computed: { id() { return this.canvasId; @@ -7155,7 +7177,7 @@ function actionsChanged({ actions, reserve - }, resolve) { + }, resolve2) { if (!actions) { return; } @@ -7206,7 +7228,7 @@ }); color = LinearGradient; } else if (data[0] === "pattern") { - const loaded = checkImageLoaded(data[1], actions.slice(index2 + 1), resolve, function(image2) { + const loaded = checkImageLoaded(data[1], actions.slice(index2 + 1), resolve2, function(image2) { if (image2) { c2d[method1] = c2d.createPattern(image2, data[2]); } @@ -7255,7 +7277,7 @@ var url = dataArray[0]; var otherData = dataArray.slice(1); _images = _images || {}; - if (checkImageLoaded(url, actions.slice(index2 + 1), resolve, function(image2) { + if (checkImageLoaded(url, actions.slice(index2 + 1), resolve2, function(image2) { if (image2) { c2d.drawImage.apply(c2d, [image2].concat([...otherData.slice(4, 8)], [...otherData.slice(0, 4)])); } @@ -7277,7 +7299,7 @@ } } if (!actionsWaiting.value) { - resolve({ + resolve2({ errMsg: "drawCanvas:ok" }); } @@ -7319,7 +7341,7 @@ } }); } - function checkImageLoaded(src, actions, resolve, fn) { + function checkImageLoaded(src, actions, resolve2, fn) { var image2 = _images[src]; if (image2.ready) { fn(image2); @@ -7337,7 +7359,7 @@ actionsChanged({ actions: action[0], reserve: action[1] - }, resolve); + }, resolve2); action = actions2.shift(); } }; @@ -7355,7 +7377,7 @@ dataType, quality = 1, type = "png" - }, resolve) { + }, resolve2) { const canvas2 = canvasRef.value; let data; const maxWidth = canvas2.offsetWidth - x; @@ -7412,10 +7434,10 @@ } newCanvas.height = newCanvas.width = 0; context.__hidpi__ = false; - if (!resolve) { + if (!resolve2) { return result; } else { - resolve(result); + resolve2(result); } } function putImageData({ @@ -7425,7 +7447,7 @@ width, height, compressed - }, resolve) { + }, resolve2) { try { if (!height) { height = Math.round(data.length / 4 / width); @@ -7440,12 +7462,12 @@ canvasRef.value.getContext("2d").drawImage(canvas2, x, y, width, height); canvas2.height = canvas2.width = 0; } catch (error) { - resolve({ + resolve2({ errMsg: "canvasPutImageData:fail" }); return; } - resolve({ + resolve2({ errMsg: "canvasPutImageData:ok" }); } @@ -7459,7 +7481,7 @@ fileType, quality, dirname - }, resolve) { + }, resolve2) { const res = getImageData({ x, y, @@ -7473,7 +7495,7 @@ quality }); if (!res.data || !res.data.length) { - resolve({ + resolve2({ errMsg: res.errMsg.replace("canvasPutImageData", "toTempFilePath") }); return; @@ -7486,10 +7508,10 @@ putImageData, toTempFilePath }; - function _handleSubscribe(type, data, resolve) { + function _handleSubscribe(type, data, resolve2) { let method = methods2[type]; if (type.indexOf("_") !== 0 && typeof method === "function") { - method(data, resolve); + method(data, resolve2); } } return extend(methods2, { @@ -7498,7 +7520,7 @@ }); } const uniCheckGroupKey = PolySymbol("uniCheckGroup"); - const props$m = { + const props$n = { name: { type: String, default: "" @@ -7506,7 +7528,7 @@ }; var CheckboxGroup = /* @__PURE__ */ defineBuiltInComponent({ name: "CheckboxGroup", - props: props$m, + props: props$n, emits: ["change"], setup(props2, { emit: emit2, @@ -7560,7 +7582,7 @@ } return getFieldsValue; } - const props$l = { + const props$m = { checked: { type: [Boolean, String], default: false @@ -7584,7 +7606,7 @@ }; var Checkbox = /* @__PURE__ */ defineBuiltInComponent({ name: "Checkbox", - props: props$l, + props: props$m, setup(props2, { slots }) { @@ -7732,7 +7754,7 @@ }); } } - const props$k = { + const props$l = { cursorSpacing: { type: [Number, String], default: 0 @@ -8408,7 +8430,7 @@ }); }); const id2 = useContextInfo(); - useSubscribe((type, data, resolve) => { + useSubscribe((type, data, resolve2) => { const { options, callbackId } = data; let res; let range; @@ -8545,7 +8567,7 @@ errMsg = "not ready"; } if (callbackId) { - resolve({ + resolve2({ callbackId, data: extend({}, res, { errMsg: `${type}:${errMsg ? "fail " + errMsg : "ok"}` @@ -8554,7 +8576,7 @@ } }, id2, true); } - const props$j = /* @__PURE__ */ extend({}, props$k, { + const props$k = /* @__PURE__ */ extend({}, props$l, { id: { type: String, default: "" @@ -8582,7 +8604,7 @@ }); var Editor = /* @__PURE__ */ defineBuiltInComponent({ name: "Editor", - props: props$j, + props: props$k, emit: ["ready", "focus", "blur", "input", "statuschange", ...emit$1], setup(props2, { emit: emit2 @@ -8671,7 +8693,7 @@ }; } }); - const props$i = { + const props$j = { src: { type: String, default: "" @@ -8710,7 +8732,7 @@ }; var Image$1 = /* @__PURE__ */ defineBuiltInComponent({ name: "Image", - props: props$i, + props: props$j, setup(props2, { emit: emit2 }) { @@ -8991,17 +9013,17 @@ uniForm.removeField(ctx); }); } - function getSelectedTextRange(_, resolve) { + function getSelectedTextRange(_, resolve2) { const activeElement = document.activeElement; if (!activeElement) { - return resolve({}); + return resolve2({}); } const data = {}; if (["input", "textarea"].includes(activeElement.tagName.toLowerCase())) { data.start = activeElement.selectionStart; data.end = activeElement.selectionEnd; } - resolve(data); + resolve2(data); } const UniViewJSBridgeSubscribe = function() { registerViewMethod(getCurrentPageId(), "getSelectedTextRange", getSelectedTextRange); @@ -9011,7 +9033,7 @@ function getValueString(value) { return value === null ? "" : String(value); } - const props$h = /* @__PURE__ */ extend({}, { + const props$i = /* @__PURE__ */ extend({}, { name: { type: String, default: "" @@ -9076,7 +9098,7 @@ type: String, default: "done" } - }, props$k); + }, props$l); const emit = [ "input", "focus", @@ -9282,7 +9304,7 @@ trigger: trigger2 }; } - const props$g = /* @__PURE__ */ extend({}, props$h, { + const props$h = /* @__PURE__ */ extend({}, props$i, { placeholderClass: { type: String, default: "input-placeholder" @@ -9294,7 +9316,7 @@ }); var Input = /* @__PURE__ */ defineBuiltInComponent({ name: "Input", - props: props$g, + props: props$h, emits: ["confirm", ...emit], setup(props2, { emit: emit2 @@ -9499,7 +9521,7 @@ const instance = getCurrentInstance(); instance.rebuild = callback; } - const props$f = { + const props$g = { scaleArea: { type: Boolean, default: false @@ -9508,7 +9530,7 @@ var MovableArea = /* @__PURE__ */ defineBuiltInComponent({ inheritAttrs: false, name: "MovableArea", - props: props$f, + props: props$g, setup(props2, { slots }) { @@ -10127,7 +10149,7 @@ this._springY.reconfigure(e2, t2, n); this._springScale.reconfigure(e2, t2, n); }; - const props$e = { + const props$f = { direction: { type: String, default: "none" @@ -10183,7 +10205,7 @@ }; var MovableView = /* @__PURE__ */ defineBuiltInComponent({ name: "MovableView", - props: props$e, + props: props$f, emits: ["change", "scale"], setup(props2, { slots, @@ -10776,7 +10798,7 @@ }; } const OPEN_TYPES = ["navigate", "redirect", "switchTab", "reLaunch", "navigateBack"]; - const props$d = { + const props$e = { hoverClass: { type: String, default: "navigator-hover" @@ -10818,7 +10840,7 @@ compatConfig: { MODE: 3 }, - props: props$d, + props: props$e, setup(props2, { slots }) { @@ -10875,7 +10897,7 @@ }; } }); - const props$c = { + const props$d = { value: { type: Array, default() { @@ -10922,7 +10944,7 @@ } var PickerView = /* @__PURE__ */ defineBuiltInComponent({ name: "PickerView", - props: props$c, + props: props$d, emits: ["change", "pickstart", "pickend", "update:value"], setup(props2, { slots, @@ -11883,7 +11905,7 @@ backgroundColor: "#EBEBEB", activeMode: "backwards" }; - const props$b = { + const props$c = { percent: { type: [Number, String], default: 0, @@ -11932,7 +11954,7 @@ }; var Progress = /* @__PURE__ */ defineBuiltInComponent({ name: "Progress", - props: props$b, + props: props$c, setup(props2) { const state = useProgressState(props2); _activeAnimation(state, props2); @@ -12006,7 +12028,7 @@ } } const uniRadioGroupKey = PolySymbol("uniCheckGroup"); - const props$a = { + const props$b = { name: { type: String, default: "" @@ -12014,7 +12036,7 @@ }; var RadioGroup = /* @__PURE__ */ defineBuiltInComponent({ name: "RadioGroup", - props: props$a, + props: props$b, setup(props2, { emit: emit2, slots @@ -12095,7 +12117,7 @@ } return fields; } - const props$9 = { + const props$a = { checked: { type: [Boolean, String], default: false @@ -12119,7 +12141,7 @@ }; var Radio = /* @__PURE__ */ defineBuiltInComponent({ name: "Radio", - props: props$9, + props: props$a, setup(props2, { slots }) { @@ -12415,7 +12437,7 @@ }); return parentNode; } - const props$8 = { + const props$9 = { nodes: { type: [Array, String], default: function() { @@ -12428,7 +12450,7 @@ compatConfig: { MODE: 3 }, - props: props$8, + props: props$9, setup(props2) { const rootRef = ref(null); function _renderNodes(nodes) { @@ -12455,7 +12477,7 @@ } }); const passiveOptions = passive(true); - const props$7 = { + const props$8 = { scrollX: { type: [Boolean, String], default: false @@ -12518,7 +12540,7 @@ compatConfig: { MODE: 3 }, - props: props$7, + props: props$8, emits: ["scroll", "scrolltoupper", "scrolltolower", "refresherrefresh", "refresherrestore", "refresherpulling", "refresherabort", "update:refresherTriggered"], setup(props2, { emit: emit2, @@ -12948,7 +12970,7 @@ } }); } - const props$6 = { + const props$7 = { name: { type: String, default: "" @@ -13004,7 +13026,7 @@ }; var Slider = /* @__PURE__ */ defineBuiltInComponent({ name: "Slider", - props: props$6, + props: props$7, emits: ["changing", "change"], setup(props2, { emit: emit2 @@ -13175,7 +13197,7 @@ return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m); } }; - const props$5 = { + const props$6 = { indicatorDots: { type: [Boolean, String], default: false @@ -13656,7 +13678,7 @@ } var Swiper = /* @__PURE__ */ defineBuiltInComponent({ name: "Swiper", - props: props$5, + props: props$6, emits: ["change", "transition", "animationfinish", "update:current", "update:currentItemId"], setup(props2, { slots, @@ -13762,7 +13784,7 @@ }; } }); - const props$4 = { + const props$5 = { itemId: { type: String, default: "" @@ -13770,7 +13792,7 @@ }; var SwiperItem = /* @__PURE__ */ defineBuiltInComponent({ name: "SwiperItem", - props: props$4, + props: props$5, setup(props2, { slots }) { @@ -13821,7 +13843,7 @@ }; } }); - const props$3 = { + const props$4 = { name: { type: String, default: "" @@ -13849,7 +13871,7 @@ }; var Switch = /* @__PURE__ */ defineBuiltInComponent({ name: "Switch", - props: props$3, + props: props$4, emits: ["change"], setup(props2, { emit: emit2 @@ -13953,7 +13975,7 @@ } return text2.replace(/ /g, SPACE_UNICODE.nbsp).replace(/ /g, SPACE_UNICODE.ensp).replace(/ /g, SPACE_UNICODE.emsp).replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'"); } - const props$2 = /* @__PURE__ */ extend({}, props$h, { + const props$3 = /* @__PURE__ */ extend({}, props$i, { placeholderClass: { type: String, default: "input-placeholder" @@ -13974,7 +13996,7 @@ } var Textarea = /* @__PURE__ */ defineBuiltInComponent({ name: "Textarea", - props: props$2, + props: props$3, emit: ["confirm", "linechange", ...emit], setup(props2, { emit: emit2 @@ -14133,8 +14155,8 @@ if (!name) { return; } - registerViewMethod(pageId || getCurrentPageId(), name, ({ type, data }, resolve) => { - callback(type, data, resolve); + registerViewMethod(pageId || getCurrentPageId(), name, ({ type, data }, resolve2) => { + callback(type, data, resolve2); }); } function removeSubscribe(name) { @@ -14777,7 +14799,7 @@ }); } const TEMP_PATH = "_doc/uniapp_temp/"; - const props$1 = { + const props$2 = { src: { type: String, default: "" @@ -14848,7 +14870,7 @@ } var CoverImage = /* @__PURE__ */ defineBuiltInComponent({ name: "CoverImage", - props: props$1, + props: props$2, emits: ["click", "load", "error"], setup(props2, { emit: emit2 @@ -14963,12 +14985,380 @@ super(id2, "uni-live-pusher", parentNodeId, refNodeId); } } + var map = "uni-map {\n width: 300px;\n height: 225px;\n display: inline-block;\n line-height: 0;\n overflow: hidden;\n position: relative;\n}\n\nuni-map[hidden] {\n display: none;\n}\n\n.uni-map-container {\n width: 100%;\n height: 100%;\n position: absolute;\n top: 0;\n left: 0;\n overflow: hidden;\n background-color: black;\n}\n\n.uni-map-slot {\n position: absolute;\n top: 0;\n width: 100%;\n height: 100%;\n overflow: hidden;\n pointer-events: none;\n}"; + const convertCoordinates = (lng, lat, callback) => { + callback({ + coord: { + latitude: lat, + longitude: lng + } + }); + }; + function parseHex(color) { + if (color.indexOf("#") !== 0) { + return { + color, + opacity: 1 + }; + } + const opacity = color.substr(7, 2); + return { + color: color.substr(0, 7), + opacity: opacity ? Number("0x" + opacity) / 255 : 1 + }; + } + const props$1 = { + id: { + type: String, + default: "" + }, + latitude: { + type: [Number, String], + default: "" + }, + longitude: { + type: [Number, String], + default: "" + }, + scale: { + type: [String, Number], + default: 16 + }, + markers: { + type: Array, + default() { + return []; + } + }, + polyline: { + type: Array, + default() { + return []; + } + }, + circles: { + type: Array, + default() { + return []; + } + }, + controls: { + type: Array, + default() { + return []; + } + } + }; var Map$1 = /* @__PURE__ */ defineBuiltInComponent({ - name: "Map" + name: "Map", + props: props$1, + emits: ["click", "regionchange", "controltap", "markertap", "callouttap"], + setup(props2, { + emit: emit2 + }) { + const rootRef = ref(null); + const trigger2 = useCustomEvent(rootRef, emit2); + const containerRef = ref(null); + const attrs2 = useNativeAttrs(props2, ["id"]); + const { + position, + hidden, + onParentReady + } = useNative(containerRef); + let map2; + const { + _addMarkers, + _addMapLines, + _addMapCircles, + _setMap + } = useMapMethods(props2, trigger2); + onParentReady(() => { + map2 = extend(plus.maps.create(getCurrentPageId() + "-map-" + (props2.id || Date.now()), Object.assign({}, attrs2.value, position)), { + __markers__: [], + __markers_map__: {}, + __lines__: [], + __circles__: [] + }); + map2.setZoom(parseInt(String(props2.scale))); + plus.webview.currentWebview().append(map2); + if (hidden.value) { + map2.hide(); + } + map2.onclick = (e2) => { + trigger2("click", {}, e2); + }; + map2.onstatuschanged = (e2) => { + trigger2("regionchange", {}, {}); + }; + _setMap(map2); + _addMarkers(props2.markers); + _addMapLines(props2.polyline); + _addMapCircles(props2.circles); + watch(() => attrs2.value, (attrs3) => map2 && map2.setStyles(attrs3), { + deep: true + }); + watch(() => position, (position2) => map2 && map2.setStyles(position2), { + deep: true + }); + watch(() => hidden.value, (val) => { + map2 && map2[val ? "hide" : "show"](); + }); + watch(() => props2.scale, (val) => { + map2 && map2.setZoom(parseInt(String(val))); + }); + watch([() => props2.latitude, () => props2.longitude], ([latitude, longitude]) => { + map2 && map2.setStyles({ + center: new plus.maps.Point(Number(latitude), Number(longitude)) + }); + }); + watch(() => props2.markers, (val) => { + _addMarkers(val, true); + }); + watch(() => props2.polyline, (val) => { + _addMapLines(val); + }); + watch(() => props2.circles, (val) => { + _addMapCircles(val); + }); + }); + const mapControls = computed$1(() => props2.controls.map((control) => { + const position2 = { + position: "absolute" + }; + ["top", "left", "width", "height"].forEach((key) => { + if (control.position[key]) { + position2[key] = control.position[key] + "px"; + } + }); + return { + id: control.id, + iconPath: getRealPath(control.iconPath), + position: position2 + }; + })); + onBeforeUnmount(() => { + if (map2) { + map2.close(); + } + }); + return () => { + return createVNode("uni-map", { + "ref": rootRef, + "id": props2.id + }, { + default: () => [createVNode("div", { + "ref": containerRef, + "class": "uni-map-container" + }, null, 512), mapControls.value.map((control, index2) => createVNode(resolveComponent("v-uni-cover-image"), { + "key": index2, + "src": control.iconPath, + "style": control.position, + "auto-size": true, + "onClick": () => trigger2("controltap", {}, { + controlId: control.id + }) + }, null, 8, ["src", "style", "auto-size", "onClick"])), createVNode("div", { + "class": "uni-map-slot" + }, null)], + _: 1 + }, 8, ["id"]); + }; + } }); + function useMapMethods(props2, trigger2) { + let map2; + function moveToLocation(resolve2, { + longitude, + latitude + } = {}) { + if (!map2) + return; + map2.setCenter(new plus.maps.Point(Number(longitude || props2.longitude), Number(latitude || props2.latitude))); + resolve2({ + errMsg: "moveToLocation:ok" + }); + } + function getCenterLocation(resolve2) { + if (!map2) + return; + map2.getCurrentCenter((state, point) => { + resolve2({ + longitude: point.getLng(), + latitude: point.getLat(), + errMsg: "getCenterLocation:ok" + }); + }); + } + function getRegion(resolve2) { + if (!map2) + return; + const rect = map2.getBounds(); + resolve2({ + southwest: rect.getSouthWest(), + northeast: rect.getNorthEast(), + errMsg: "getRegion:ok" + }); + } + function getScale(resolve2) { + if (!map2) + return; + resolve2({ + scale: map2.getZoom(), + errMsg: "getScale:ok" + }); + } + function _addMarker(marker) { + if (!map2) + return; + const { + id: id2, + latitude, + longitude, + iconPath, + callout, + label: label2 + } = marker; + convertCoordinates(longitude, latitude, (res) => { + const { + latitude: latitude2, + longitude: longitude2 + } = res.coord; + const nativeMarker = new plus.maps.Marker(new plus.maps.Point(longitude2, latitude2)); + if (iconPath) { + nativeMarker.setIcon(getRealPath(iconPath)); + } + if (label2 && label2.content) { + nativeMarker.setLabel(label2.content); + } + let nativeBubble = void 0; + if (callout && callout.content) { + nativeBubble = new plus.maps.Bubble(callout.content); + } + if (nativeBubble) { + nativeMarker.setBubble(nativeBubble); + } + if (id2 || id2 === 0) { + nativeMarker.onclick = (e2) => { + trigger2("markertap", {}, { + markerId: id2 + }); + }; + if (nativeBubble) { + nativeBubble.onclick = () => { + trigger2("callouttap", {}, { + markerId: id2 + }); + }; + } + } + map2.addOverlay(nativeMarker); + map2.__markers__.push(nativeMarker); + map2.__markers_map__[id2 + ""] = nativeMarker; + }); + } + function _clearMarkers() { + if (!map2) + return; + const markers = map2.__markers__; + markers.forEach((marker) => { + map2.removeOverlay(marker); + }); + map2.__markers__ = []; + map2.__markers_map__ = {}; + } + function _addMarkers(markers, clear2) { + if (clear2) { + _clearMarkers(); + } + markers.forEach((marker) => { + _addMarker(marker); + }); + } + function _addMapLines(lines) { + if (!map2) + return; + if (map2.__lines__.length > 0) { + map2.__lines__.forEach((circle) => { + map2.removeOverlay(circle); + }); + map2.__lines__ = []; + } + lines.forEach((line) => { + const { + color, + width + } = line; + const points = line.points.map((point) => new plus.maps.Point(point.longitude, point.latitude)); + const polyline = new plus.maps.Polyline(points); + if (color) { + const strokeStyle = parseHex(color); + polyline.setStrokeColor(strokeStyle.color); + polyline.setStrokeOpacity(strokeStyle.opacity); + } + if (width) { + polyline.setLineWidth(width); + } + map2.addOverlay(polyline); + map2.__lines__.push(polyline); + }); + } + function _addMapCircles(circles) { + if (!map2) + return; + if (map2.__circles__.length > 0) { + map2.__circles__.forEach((circle) => { + map2.removeOverlay(circle); + }); + map2.__circles__ = []; + } + circles.forEach((circle) => { + const { + latitude, + longitude, + color, + fillColor, + radius, + strokeWidth + } = circle; + const nativeCircle = new plus.maps.Circle(new plus.maps.Point(longitude, latitude), radius); + if (color) { + const strokeStyle = parseHex(color); + nativeCircle.setStrokeColor(strokeStyle.color); + nativeCircle.setStrokeOpacity(strokeStyle.opacity); + } + if (fillColor) { + const fillStyle = parseHex(fillColor); + nativeCircle.setFillColor(fillStyle.color); + nativeCircle.setFillOpacity(fillStyle.opacity); + } + if (strokeWidth) { + nativeCircle.setLineWidth(strokeWidth); + } + map2.addOverlay(nativeCircle); + map2.__circles__.push(nativeCircle); + }); + } + const methods2 = { + moveToLocation, + getCenterLocation, + getRegion, + getScale + }; + useSubscribe((type, data, resolve2) => { + methods2[type] && methods2[type](resolve2, data); + }, useContextInfo(), true); + return { + _addMarkers, + _addMapLines, + _addMapCircles, + _setMap(_map) { + map2 = _map; + } + }; + } class UniMap extends UniComponent { constructor(id2, parentNodeId, refNodeId, nodeJson) { - super(id2, "uni-map", Map$1, parentNodeId, refNodeId, nodeJson); + super(id2, "uni-map", Map$1, parentNodeId, refNodeId, nodeJson, ".uni-map-slot"); } } var movableArea = "uni-movable-area {\n display: block;\n position: relative;\n width: 10px;\n height: 10px;\n}\n\nuni-movable-area[hidden] {\n display: none;\n}\n"; diff --git a/packages/uni-app-plus/src/constants.ts b/packages/uni-app-plus/src/constants.ts index c35efef56e452f5af949cee04aeefde1ac8e4eba..dadbe0dbc7aab25544f08cde45e8c371d560154b 100644 --- a/packages/uni-app-plus/src/constants.ts +++ b/packages/uni-app-plus/src/constants.ts @@ -2,8 +2,6 @@ export const VD_SYNC = 'vdSync' export const ON_WEBVIEW_READY = 'onWebviewReady' -export const INVOKE_SERVICE_API = 'invokeServiceApi' - export let ACTION_MINIFY = true // __tests__ export function setActionMinify(minify: boolean) { diff --git a/packages/uni-app-plus/src/service/framework/app/subscriber/ad.ts b/packages/uni-app-plus/src/service/framework/app/subscriber/ad.ts new file mode 100644 index 0000000000000000000000000000000000000000..17b553c731e60c7e19abcdcd0f26a8e32c0cb5e7 --- /dev/null +++ b/packages/uni-app-plus/src/service/framework/app/subscriber/ad.ts @@ -0,0 +1,8 @@ +import { registerServiceMethod } from '@dcloudio/uni-core' + +export function subscribeAd() { + // view 层通过 UniViewJSBridge.invokeServiceMethod('getAdData', args, function({data})=>{console.log(data)}) + registerServiceMethod('getAdData', (args, resolve) => { + // TODO args: view 层传输的参数,处理完之后,resolve:回传给 service,如resolve({data}) + }) +} diff --git a/packages/uni-app-plus/src/service/framework/app/subscriber/index.ts b/packages/uni-app-plus/src/service/framework/app/subscriber/index.ts index a76b9c5578d64784caf78b71d46dac363b2e889c..77fbd329c94b042399f5d536cf260fb855d5a992 100644 --- a/packages/uni-app-plus/src/service/framework/app/subscriber/index.ts +++ b/packages/uni-app-plus/src/service/framework/app/subscriber/index.ts @@ -1,10 +1,9 @@ -import { - INVOKE_SERVICE_API, - ON_WEBVIEW_READY, - VD_SYNC, -} from '../../../../constants' +import { subscribeServiceMethod } from '@dcloudio/uni-core' +import { ON_WEBVIEW_READY, VD_SYNC } from '../../../../constants' import { onVdSync } from '../../dom' import { onPlusMessage } from '../initGlobalEvent' +import { subscribeAd } from './ad' +import { subscribeNavigator } from './navigator' import { subscribeWebviewReady } from './webviewReady' export function initSubscribeHandlers() { @@ -21,14 +20,8 @@ export function initSubscribeHandlers() { // 非纯原生 subscribe(ON_WEBVIEW_READY, subscribeWebviewReady) subscribe(VD_SYNC, onVdSync) - subscribe(INVOKE_SERVICE_API, onInvokeServiceApi) + subscribeServiceMethod() + subscribeAd() + subscribeNavigator() } } - -function onInvokeServiceApi({ - data: { method, args }, -}: { - data: { method: UniApp.OpenType; args: any } -}) { - uni[method] && uni[method](args) -} diff --git a/packages/uni-app-plus/src/service/framework/app/subscriber/navigator.ts b/packages/uni-app-plus/src/service/framework/app/subscriber/navigator.ts new file mode 100644 index 0000000000000000000000000000000000000000..c86a13c70638e91937676b3e76f88aab97f07da8 --- /dev/null +++ b/packages/uni-app-plus/src/service/framework/app/subscriber/navigator.ts @@ -0,0 +1,16 @@ +import { registerServiceMethod } from '@dcloudio/uni-core' + +const API_ROUTE = [ + 'switchTab', + 'reLaunch', + 'redirectTo', + 'navigateTo', + 'navigateBack', +] as const +export function subscribeNavigator() { + API_ROUTE.forEach((name) => { + registerServiceMethod(name, (args) => { + uni[name](args) + }) + }) +} diff --git a/packages/uni-app-plus/src/view/api/route.ts b/packages/uni-app-plus/src/view/api/route.ts index e876b4f12550087ff33e06623fa8633b3ee22089..0940c6ab7a58b330e333e5309a2a838c29b83c8b 100644 --- a/packages/uni-app-plus/src/view/api/route.ts +++ b/packages/uni-app-plus/src/view/api/route.ts @@ -1,28 +1,15 @@ -import { INVOKE_SERVICE_API } from '../../constants' - -function invokeServiceApi(method: string, args: Record = {}) { - UniViewJSBridge.publishHandler(INVOKE_SERVICE_API, { - data: { - method, - args, - }, - options: { - timestamp: Date.now(), - }, - }) -} export function navigateTo(args: Record) { - invokeServiceApi('navigateTo', args) + UniViewJSBridge.invokeServiceMethod('navigateTo', args) } export function navigateBack(args: Record) { - invokeServiceApi('navigateBack', args) + UniViewJSBridge.invokeServiceMethod('navigateBack', args) } export function reLaunch(args: Record) { - invokeServiceApi('reLaunch', args) + UniViewJSBridge.invokeServiceMethod('reLaunch', args) } export function redirectTo(args: Record) { - invokeServiceApi('redirectTo', args) + UniViewJSBridge.invokeServiceMethod('redirectTo', args) } export function switchTab(args: Record) { - invokeServiceApi('switchTab', args) + UniViewJSBridge.invokeServiceMethod('switchTab', args) } diff --git a/packages/uni-app-vue/dist/service.runtime.esm.js b/packages/uni-app-vue/dist/service.runtime.esm.js index 2542daa755ed688c46b6ac44f7a774581df5be9c..cb51cd75de6b605495673385ba9e0d2246ef6790 100644 --- a/packages/uni-app-vue/dist/service.runtime.esm.js +++ b/packages/uni-app-vue/dist/service.runtime.esm.js @@ -957,10 +957,10 @@ export default function vueFactory(exports) { if (type === "clear" /* CLEAR */ ) { - // collection being cleared - // trigger all effects for target - depsMap.forEach(add); - } else if (key === 'length' && isArray(target)) { + // collection being cleared + // trigger all effects for target + depsMap.forEach(add); + } else if (key === 'length' && isArray(target)) { depsMap.forEach((dep, key) => { if (key === 'length' || key >= newValue) { add(dep); @@ -1088,12 +1088,12 @@ export default function vueFactory(exports) { if (key === "__v_isReactive" /* IS_REACTIVE */ ) { - return !isReadonly; - } else if (key === "__v_isReadonly" + return !isReadonly; + } else if (key === "__v_isReadonly" /* IS_READONLY */ ) { - return isReadonly; - } else if (key === "__v_raw" + return isReadonly; + } else if (key === "__v_raw" /* RAW */ && receiver === (isReadonly ? shallow ? shallowReadonlyMap : readonlyMap : shallow ? shallowReactiveMap : reactiveMap).get(target)) { return target; @@ -1587,16 +1587,16 @@ export default function vueFactory(exports) { if (key === "__v_isReactive" /* IS_REACTIVE */ ) { - return !isReadonly; - } else if (key === "__v_isReadonly" + return !isReadonly; + } else if (key === "__v_isReadonly" /* IS_READONLY */ ) { - return isReadonly; - } else if (key === "__v_raw" + return isReadonly; + } else if (key === "__v_raw" /* RAW */ ) { - return target; - } + return target; + } return Reflect.get(hasOwn(instrumentations, key) && key in target ? instrumentations : target, key, receiver); }; @@ -1733,8 +1733,8 @@ export default function vueFactory(exports) { if (targetType === 0 /* INVALID */ ) { - return target; - } + return target; + } var proxy = new Proxy(target, targetType === 2 /* COLLECTION */ @@ -3033,12 +3033,12 @@ export default function vueFactory(exports) { if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */ ) { - // withProxy is a proxy with a different `has` trap only for - // runtime-compiled render functions using `with` block. - var proxyToUse = withProxy || proxy; - result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx)); - fallthroughAttrs = attrs; - } else { + // withProxy is a proxy with a different `has` trap only for + // runtime-compiled render functions using `with` block. + var proxyToUse = withProxy || proxy; + result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx)); + fallthroughAttrs = attrs; + } else { // functional var _render = Component; // in dev, mark attrs accessed if optional props (attrs === props) @@ -3073,9 +3073,9 @@ export default function vueFactory(exports) { if (process.env.NODE_ENV !== 'production' && result.patchFlag > 0 && result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */ ) { - ; - [root, setRoot] = getChildRoot(result); - } + ; + [root, setRoot] = getChildRoot(result); + } if (fallthroughAttrs && inheritAttrs !== false) { var keys = Object.keys(fallthroughAttrs); @@ -3089,16 +3089,16 @@ export default function vueFactory(exports) { || shapeFlag & 6 /* COMPONENT */ ) { - if (propsOptions && keys.some(isModelListener)) { - // If a v-model listener (onUpdate:xxx) has a corresponding declared - // prop, it indicates this component expects to handle v-model and - // it should not fallthrough. - // related: #1543, #1643, #1989 - fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions); - } + if (propsOptions && keys.some(isModelListener)) { + // If a v-model listener (onUpdate:xxx) has a corresponding declared + // prop, it indicates this component expects to handle v-model and + // it should not fallthrough. + // related: #1543, #1643, #1989 + fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions); + } - root = cloneVNode(root, fallthroughAttrs); - } else if (process.env.NODE_ENV !== 'production' && !accessedAttrs && root.type !== Comment$1) { + root = cloneVNode(root, fallthroughAttrs); + } else if (process.env.NODE_ENV !== 'production' && !accessedAttrs && root.type !== Comment$1) { var allAttrs = Object.keys(attrs); var eventAttrs = []; var extraAttrs = []; @@ -3292,33 +3292,33 @@ export default function vueFactory(exports) { if (patchFlag & 1024 /* DYNAMIC_SLOTS */ ) { - // slot content that references values that might have changed, - // e.g. in a v-for - return true; - } + // slot content that references values that might have changed, + // e.g. in a v-for + return true; + } if (patchFlag & 16 /* FULL_PROPS */ ) { - if (!prevProps) { - return !!nextProps; - } // presence of this flag indicates props are always non-null + if (!prevProps) { + return !!nextProps; + } // presence of this flag indicates props are always non-null - return hasPropsChanged(prevProps, nextProps, emits); - } else if (patchFlag & 8 + return hasPropsChanged(prevProps, nextProps, emits); + } else if (patchFlag & 8 /* PROPS */ ) { - var dynamicProps = nextVNode.dynamicProps; + var dynamicProps = nextVNode.dynamicProps; - for (var i = 0; i < dynamicProps.length; i++) { - var key = dynamicProps[i]; + for (var i = 0; i < dynamicProps.length; i++) { + var key = dynamicProps[i]; - if (nextProps[key] !== prevProps[key] && !isEmitListener(emits, key)) { - return true; - } + if (nextProps[key] !== prevProps[key] && !isEmitListener(emits, key)) { + return true; } } + } } else { // this path is only taken by manually written render functions // so presence of any children leads to a forced update @@ -4552,9 +4552,9 @@ export default function vueFactory(exports) { } else if (vnode.shapeFlag & 128 /* SUSPENSE */ ) { - vnode.ssContent.transition = hooks.clone(vnode.ssContent); - vnode.ssFallback.transition = hooks.clone(vnode.ssFallback); - } else { + vnode.ssContent.transition = hooks.clone(vnode.ssContent); + vnode.ssFallback.transition = hooks.clone(vnode.ssFallback); + } else { vnode.transition = hooks; } } @@ -4573,8 +4573,8 @@ export default function vueFactory(exports) { ret = ret.concat(getTransitionRawChildren(child.children, keepComment)); } // comment placeholders should be skipped, e.g. v-if else if (keepComment || child.type !== Comment$1) { - ret.push(child); - } + ret.push(child); + } } // #1126 if a transition children list contains multiple sub fragments, these // fragments will be merged into a flat children array. Since each v-for // fragment may contain different static bindings inside, we need to de-op @@ -4992,8 +4992,8 @@ export default function vueFactory(exports) { if (rawVNode.shapeFlag & 128 /* SUSPENSE */ ) { - rawVNode.ssContent = vnode; - } + rawVNode.ssContent = vnode; + } } // #1513 it's possible for the returned vnode to be cloned due to attr // fallthrough or scopeId, so the vnode here may not be the final vnode // that is mounted. Instead of caching it directly, we store the pending @@ -5123,18 +5123,18 @@ export default function vueFactory(exports) { if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */ ) { - shapeFlag -= 256 - /* COMPONENT_SHOULD_KEEP_ALIVE */ - ; - } + shapeFlag -= 256 + /* COMPONENT_SHOULD_KEEP_ALIVE */ + ; + } if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */ ) { - shapeFlag -= 512 - /* COMPONENT_KEPT_ALIVE */ - ; - } + shapeFlag -= 512 + /* COMPONENT_KEPT_ALIVE */ + ; + } vnode.shapeFlag = shapeFlag; } @@ -5757,37 +5757,37 @@ export default function vueFactory(exports) { if (patchFlag & 8 /* PROPS */ ) { - // Compiler-generated props & no keys change, just set the updated - // the props. - var propsToUpdate = instance.vnode.dynamicProps; - - for (var i = 0; i < propsToUpdate.length; i++) { - var key = propsToUpdate[i]; // PROPS flag guarantees rawProps to be non-null - - var value = rawProps[key]; - - if (options) { - // attr / props separation was done on init and will be consistent - // in this code path, so just check if attrs have it. - if (hasOwn(attrs, key)) { - if (value !== attrs[key]) { - attrs[key] = value; - hasAttrsChanged = true; - } - } else { - var camelizedKey = camelize(key); - props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false - /* isAbsent */ - ); - } - } else { + // Compiler-generated props & no keys change, just set the updated + // the props. + var propsToUpdate = instance.vnode.dynamicProps; + + for (var i = 0; i < propsToUpdate.length; i++) { + var key = propsToUpdate[i]; // PROPS flag guarantees rawProps to be non-null + + var value = rawProps[key]; + + if (options) { + // attr / props separation was done on init and will be consistent + // in this code path, so just check if attrs have it. + if (hasOwn(attrs, key)) { if (value !== attrs[key]) { attrs[key] = value; hasAttrsChanged = true; } + } else { + var camelizedKey = camelize(key); + props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false + /* isAbsent */ + ); + } + } else { + if (value !== attrs[key]) { + attrs[key] = value; + hasAttrsChanged = true; } } } + } } else { // full props update. if (setFullProps(instance, rawProps, props, attrs)) { @@ -5799,13 +5799,9 @@ export default function vueFactory(exports) { var kebabKey; for (var _key6 in rawCurrentProps) { - if (!rawProps || // for camelCase - !hasOwn(rawProps, _key6) && ( // it's possible the original props was passed in as kebab-case - // and converted to camelCase (#955) - (kebabKey = hyphenate(_key6)) === _key6 || !hasOwn(rawProps, kebabKey))) { + if (!rawProps || !hasOwn(rawProps, _key6) && ((kebabKey = hyphenate(_key6)) === _key6 || !hasOwn(rawProps, kebabKey))) { if (options) { - if (rawPrevProps && ( // for camelCase - rawPrevProps[_key6] !== undefined || // for kebab-case + if (rawPrevProps && (rawPrevProps[_key6] !== undefined || // for kebab-case rawPrevProps[kebabKey] !== undefined)) { props[_key6] = resolvePropValue(options, rawCurrentProps, _key6, undefined, instance, true /* isAbsent */ @@ -6250,18 +6246,18 @@ export default function vueFactory(exports) { if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */ ) { - var type = children._; + var type = children._; - if (type) { - // users can get the shallow readonly version of the slots object through `this.$slots`, - // we should avoid the proxy object polluting the slots of the internal instance - instance.slots = toRaw(children); // make compiler marker non-enumerable + if (type) { + // users can get the shallow readonly version of the slots object through `this.$slots`, + // we should avoid the proxy object polluting the slots of the internal instance + instance.slots = toRaw(children); // make compiler marker non-enumerable - def(children, '_', type); - } else { - normalizeObjectSlots(children, instance.slots = {}); - } + def(children, '_', type); } else { + normalizeObjectSlots(children, instance.slots = {}); + } + } else { instance.slots = {}; if (children) { @@ -6283,41 +6279,41 @@ export default function vueFactory(exports) { if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */ ) { - var type = children._; - - if (type) { - // compiled slots. - if (process.env.NODE_ENV !== 'production' && isHmrUpdating) { - // Parent was HMR updated so slot content may have changed. - // force update slots and mark instance for hmr as well - extend(slots, children); - } else if (optimized && type === 1 + var type = children._; + + if (type) { + // compiled slots. + if (process.env.NODE_ENV !== 'production' && isHmrUpdating) { + // Parent was HMR updated so slot content may have changed. + // force update slots and mark instance for hmr as well + extend(slots, children); + } else if (optimized && type === 1 + /* STABLE */ + ) { + // compiled AND stable. + // no need to update, and skip stale slots removal. + needDeletionCheck = false; + } else { + // compiled but dynamic (v-if/v-for on slots) - update slots, but skip + // normalization. + extend(slots, children); // #2893 + // when rendering the optimized slots by manually written render function, + // we need to delete the `slots._` flag if necessary to make subsequent updates reliable, + // i.e. let the `renderSlot` create the bailed Fragment + + if (!optimized && type === 1 /* STABLE */ ) { - // compiled AND stable. - // no need to update, and skip stale slots removal. - needDeletionCheck = false; - } else { - // compiled but dynamic (v-if/v-for on slots) - update slots, but skip - // normalization. - extend(slots, children); // #2893 - // when rendering the optimized slots by manually written render function, - // we need to delete the `slots._` flag if necessary to make subsequent updates reliable, - // i.e. let the `renderSlot` create the bailed Fragment - - if (!optimized && type === 1 - /* STABLE */ - ) { - delete slots._; - } + delete slots._; } - } else { - needDeletionCheck = !children.$stable; - normalizeObjectSlots(children, slots); } + } else { + needDeletionCheck = !children.$stable; + normalizeObjectSlots(children, slots); + } - deletionComparisonTarget = children; - } else if (children) { + deletionComparisonTarget = children; + } else if (children) { // non slot object children (direct value) passed to a component normalizeVNodeSlots(instance, children); deletionComparisonTarget = { @@ -6662,8 +6658,8 @@ export default function vueFactory(exports) { if (domType !== 3 /* TEXT */ ) { - nextNode = onMismatch(); - } else { + nextNode = onMismatch(); + } else { if (node.data !== vnode.children) { hasMismatch = true; process.env.NODE_ENV !== 'production' && warn("Hydration text mismatch:" + "\n- Client: ".concat(JSON.stringify(node.data)) + "\n- Server: ".concat(JSON.stringify(vnode.children))); @@ -6690,8 +6686,8 @@ export default function vueFactory(exports) { if (domType !== 1 /* ELEMENT */ ) { - nextNode = onMismatch(); - } else { + nextNode = onMismatch(); + } else { // determine anchor, adopt content nextNode = node; // if the static vnode has its content stripped during build, // adopt it from the server-rendered HTML. @@ -6726,58 +6722,58 @@ export default function vueFactory(exports) { if (shapeFlag & 1 /* ELEMENT */ ) { - if (domType !== 1 - /* ELEMENT */ - || vnode.type.toLowerCase() !== node.tagName.toLowerCase()) { - nextNode = onMismatch(); - } else { - nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized); - } - } else if (shapeFlag & 6 + if (domType !== 1 + /* ELEMENT */ + || vnode.type.toLowerCase() !== node.tagName.toLowerCase()) { + nextNode = onMismatch(); + } else { + nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized); + } + } else if (shapeFlag & 6 /* COMPONENT */ ) { - // when setting up the render effect, if the initial vnode already - // has .el set, the component will perform hydration instead of mount - // on its sub-tree. - vnode.slotScopeIds = slotScopeIds; - var container = parentNode(node); - mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized); // component may be async, so in the case of fragments we cannot rely - // on component's rendered output to determine the end of the fragment - // instead, we do a lookahead to find the end anchor node. - - nextNode = isFragmentStart ? locateClosingAsyncAnchor(node) : nextSibling(node); // #3787 - // if component is async, it may get moved / unmounted before its - // inner component is loaded, so we need to give it a placeholder - // vnode that matches its adopted DOM. - - if (isAsyncWrapper(vnode)) { - var subTree; - - if (isFragmentStart) { - subTree = createVNode(Fragment); - subTree.anchor = nextNode ? nextNode.previousSibling : container.lastChild; - } else { - subTree = node.nodeType === 3 ? createTextVNode('') : createVNode('div'); - } - - subTree.el = node; - vnode.component.subTree = subTree; + // when setting up the render effect, if the initial vnode already + // has .el set, the component will perform hydration instead of mount + // on its sub-tree. + vnode.slotScopeIds = slotScopeIds; + var container = parentNode(node); + mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized); // component may be async, so in the case of fragments we cannot rely + // on component's rendered output to determine the end of the fragment + // instead, we do a lookahead to find the end anchor node. + + nextNode = isFragmentStart ? locateClosingAsyncAnchor(node) : nextSibling(node); // #3787 + // if component is async, it may get moved / unmounted before its + // inner component is loaded, so we need to give it a placeholder + // vnode that matches its adopted DOM. + + if (isAsyncWrapper(vnode)) { + var subTree; + + if (isFragmentStart) { + subTree = createVNode(Fragment); + subTree.anchor = nextNode ? nextNode.previousSibling : container.lastChild; + } else { + subTree = node.nodeType === 3 ? createTextVNode('') : createVNode('div'); } - } else if (shapeFlag & 64 + + subTree.el = node; + vnode.component.subTree = subTree; + } + } else if (shapeFlag & 64 /* TELEPORT */ ) { - if (domType !== 8 - /* COMMENT */ - ) { - nextNode = onMismatch(); - } else { - nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren); - } - } else if (shapeFlag & 128 + if (domType !== 8 + /* COMMENT */ + ) { + nextNode = onMismatch(); + } else { + nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren); + } + } else if (shapeFlag & 128 /* SUSPENSE */ ) { - nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode); - } else if (process.env.NODE_ENV !== 'production') { + nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode); + } else if (process.env.NODE_ENV !== 'production') { warn('Invalid HostVNode type:', type, "(".concat(typeof type, ")")); } @@ -6806,78 +6802,78 @@ export default function vueFactory(exports) { if (forcePatchValue || patchFlag !== -1 /* HOISTED */ ) { - if (dirs) { - invokeDirectiveHook(vnode, null, parentComponent, 'created'); - } // props + if (dirs) { + invokeDirectiveHook(vnode, null, parentComponent, 'created'); + } // props - if (props) { - if (forcePatchValue || !optimized || patchFlag & 16 - /* FULL_PROPS */ - || patchFlag & 32 - /* HYDRATE_EVENTS */ - ) { - for (var key in props) { - if (forcePatchValue && key.endsWith('value') || isOn(key) && !isReservedProp(key)) { - patchProp(el, key, null, props[key]); - } + if (props) { + if (forcePatchValue || !optimized || patchFlag & 16 + /* FULL_PROPS */ + || patchFlag & 32 + /* HYDRATE_EVENTS */ + ) { + for (var key in props) { + if (forcePatchValue && key.endsWith('value') || isOn(key) && !isReservedProp(key)) { + patchProp(el, key, null, props[key]); } - } else if (props.onClick) { - // Fast path for click listeners (which is most often) to avoid - // iterating through props. - patchProp(el, 'onClick', null, props.onClick); } - } // vnode / directive hooks + } else if (props.onClick) { + // Fast path for click listeners (which is most often) to avoid + // iterating through props. + patchProp(el, 'onClick', null, props.onClick); + } + } // vnode / directive hooks - var vnodeHooks; + var vnodeHooks; - if (vnodeHooks = props && props.onVnodeBeforeMount) { - invokeVNodeHook(vnodeHooks, parentComponent, vnode); - } + if (vnodeHooks = props && props.onVnodeBeforeMount) { + invokeVNodeHook(vnodeHooks, parentComponent, vnode); + } - if (dirs) { - invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount'); - } + if (dirs) { + invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount'); + } - if ((vnodeHooks = props && props.onVnodeMounted) || dirs) { - queueEffectWithSuspense(() => { - vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode); - dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted'); - }, parentSuspense); - } // children + if ((vnodeHooks = props && props.onVnodeMounted) || dirs) { + queueEffectWithSuspense(() => { + vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode); + dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted'); + }, parentSuspense); + } // children - if (shapeFlag & 16 - /* ARRAY_CHILDREN */ - && // skip if element has innerHTML / textContent - !(props && (props.innerHTML || props.textContent))) { - var next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized); - var _hasWarned = false; + if (shapeFlag & 16 + /* ARRAY_CHILDREN */ + && // skip if element has innerHTML / textContent + !(props && (props.innerHTML || props.textContent))) { + var next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized); + var _hasWarned = false; - while (next) { - hasMismatch = true; + while (next) { + hasMismatch = true; - if (process.env.NODE_ENV !== 'production' && !_hasWarned) { - warn("Hydration children mismatch in <".concat(vnode.type, ">: ") + "server rendered element contains more child nodes than client vdom."); - _hasWarned = true; - } // The SSRed DOM contains more nodes than it should. Remove them. + if (process.env.NODE_ENV !== 'production' && !_hasWarned) { + warn("Hydration children mismatch in <".concat(vnode.type, ">: ") + "server rendered element contains more child nodes than client vdom."); + _hasWarned = true; + } // The SSRed DOM contains more nodes than it should. Remove them. - var cur = next; - next = next.nextSibling; - remove(cur); - } - } else if (shapeFlag & 8 - /* TEXT_CHILDREN */ - ) { - if (el.textContent !== vnode.children) { - hasMismatch = true; - process.env.NODE_ENV !== 'production' && warn("Hydration text content mismatch in <".concat(vnode.type, ">:\n") + "- Client: ".concat(el.textContent, "\n") + "- Server: ".concat(vnode.children)); - el.textContent = vnode.children; - } - } + var cur = next; + next = next.nextSibling; + remove(cur); + } + } else if (shapeFlag & 8 + /* TEXT_CHILDREN */ + ) { + if (el.textContent !== vnode.children) { + hasMismatch = true; + process.env.NODE_ENV !== 'production' && warn("Hydration text content mismatch in <".concat(vnode.type, ">:\n") + "- Client: ".concat(el.textContent, "\n") + "- Server: ".concat(vnode.children)); + el.textContent = vnode.children; + } } + } return el.nextSibling; }; @@ -7221,9 +7217,9 @@ export default function vueFactory(exports) { if (n2.patchFlag === -2 /* BAIL */ ) { - optimized = false; - n2.dynamicChildren = null; - } + optimized = false; + n2.dynamicChildren = null; + } var { type, @@ -7257,20 +7253,20 @@ export default function vueFactory(exports) { if (shapeFlag & 1 /* ELEMENT */ ) { - processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized); - } else if (shapeFlag & 6 + processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized); + } else if (shapeFlag & 6 /* COMPONENT */ ) { - processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized); - } else if (shapeFlag & 64 + processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized); + } else if (shapeFlag & 64 /* TELEPORT */ ) { - type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals); - } else if (shapeFlag & 128 + type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals); + } else if (shapeFlag & 128 /* SUSPENSE */ ) { - type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals); - } else if (process.env.NODE_ENV !== 'production') { + type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals); + } else if (process.env.NODE_ENV !== 'production') { warn('Invalid VNode type:', type, "(".concat(typeof type, ")")); } @@ -7393,12 +7389,12 @@ export default function vueFactory(exports) { if (!(process.env.NODE_ENV !== 'production') && vnode.el && hostCloneNode !== undefined && patchFlag === -1 /* HOISTED */ ) { - // If a vnode has non-null el, it means it's being reused. - // Only static vnodes can be reused, so its mounted DOM nodes should be - // exactly the same, and we can simply do a clone here. - // only do this in production since cloned trees cannot be HMR updated. - el = vnode.el = hostCloneNode(vnode.el); - } else { + // If a vnode has non-null el, it means it's being reused. + // Only static vnodes can be reused, so its mounted DOM nodes should be + // exactly the same, and we can simply do a clone here. + // only do this in production since cloned trees cannot be HMR updated. + el = vnode.el = hostCloneNode(vnode.el); + } else { el = vnode.el = hostCreateElement( // fixed by xxxxxx vnode.type, container); // mount children first, since some props may rely on child content // being already rendered, e.g. `