提交 516ff43a 编写于 作者: fxy060608's avatar fxy060608

feat: add __UNI_FEATURE_RPX__

上级 e9fa8d40
...@@ -15,6 +15,7 @@ declare var __VUE_OPTIONS_API__: boolean ...@@ -15,6 +15,7 @@ declare var __VUE_OPTIONS_API__: boolean
declare var __UNI_FEATURE_WX__: boolean declare var __UNI_FEATURE_WX__: boolean
declare var __UNI_FEATURE_WXS__: boolean declare var __UNI_FEATURE_WXS__: boolean
declare var __UNI_FEATURE_RPX__: boolean
declare var __UNI_FEATURE_NVUE__: boolean declare var __UNI_FEATURE_NVUE__: boolean
declare var __UNI_FEATURE_PROMISE__: boolean declare var __UNI_FEATURE_PROMISE__: boolean
declare var __UNI_FEATURE_LONGPRESS__: boolean declare var __UNI_FEATURE_LONGPRESS__: boolean
......
import { withModifiers } from 'vue'
import safeAreaInsets from 'safe-area-insets'
export const onTouchmovePrevent = /*#__PURE__*/ withModifiers(() => {}, [
'prevent',
])
export const onTouchmoveStop = /*#__PURE__*/ withModifiers(() => {}, ['stop'])
export function getWindowOffset() {
const style = document.documentElement.style
const top = parseInt(style.getPropertyValue('--window-top'))
const bottom = parseInt(style.getPropertyValue('--window-bottom'))
const left = parseInt(style.getPropertyValue('--window-left'))
const right = parseInt(style.getPropertyValue('--window-right'))
return {
top: top ? top + safeAreaInsets.top : 0,
bottom: bottom ? bottom + safeAreaInsets.bottom : 0,
left: left ? left + safeAreaInsets.left : 0,
right: right ? right + safeAreaInsets.right : 0,
}
}
interface PageCssVars {
'--window-top'?: string
'--window-bottom'?: string
'--window-left'?: string
'--window-right'?: string
'--window-margin'?: string
'--top-window-height'?: string
}
const style = document.documentElement.style
export function updateCssVar(cssVars: Record<string, any>) {
Object.keys(cssVars).forEach((name) => {
style.setProperty(name, cssVars[name])
})
}
export function updatePageCssVar(cssVars: PageCssVars) {
return updateCssVar(cssVars)
}
interface AppCssVar {
'--status-bar-height'?: string
'--tab-bar-height'?: string
}
export function updateAppCssVar(cssVars: AppCssVar) {
return updateCssVar(cssVars)
}
const sheetsMap = new Map()
export function updateStyle(id: string, content: string) {
let style = sheetsMap.get(id)
if (style && !(style instanceof HTMLStyleElement)) {
removeStyle(id)
style = undefined
}
if (!style) {
style = document.createElement('style')
style.setAttribute('type', 'text/css')
style.innerHTML = content
document.head.appendChild(style)
} else {
style.innerHTML = content
}
sheetsMap.set(id, style)
}
export function removeStyle(id: string) {
let style = sheetsMap.get(id)
if (style) {
if (style instanceof CSSStyleSheet) {
// @ts-ignore
const index = document.adoptedStyleSheets.indexOf(style)
// @ts-ignore
document.adoptedStyleSheets = document.adoptedStyleSheets.filter(
(s: CSSStyleSheet) => s !== style
)
} else {
document.head.removeChild(style)
}
sheetsMap.delete(id)
}
}
import { withModifiers } from 'vue'
export const onTouchmovePrevent = /*#__PURE__*/ withModifiers(() => {}, [
'prevent',
])
export const onTouchmoveStop = /*#__PURE__*/ withModifiers(() => {}, ['stop'])
import safeAreaInsets from 'safe-area-insets'
export function getWindowOffset() {
const style = document.documentElement.style
const top = parseInt(style.getPropertyValue('--window-top'))
const bottom = parseInt(style.getPropertyValue('--window-bottom'))
const left = parseInt(style.getPropertyValue('--window-left'))
const right = parseInt(style.getPropertyValue('--window-right'))
return {
top: top ? top + safeAreaInsets.top : 0,
bottom: bottom ? bottom + safeAreaInsets.bottom : 0,
left: left ? left + safeAreaInsets.left : 0,
right: right ? right + safeAreaInsets.right : 0,
}
}
export * from './dom'
export * from './util' export * from './util'
export * from './icon' export * from './icon'
export * from './event'
export * from './scroll' export * from './scroll'
export * from './getRealRoute' export * from './getRealRoute'
export * from './updateCssVar'
export * from './getWindowOffset'
interface PageCssVars {
'--window-top'?: string
'--window-bottom'?: string
'--window-left'?: string
'--window-right'?: string
'--window-margin'?: string
'--top-window-height'?: string
}
const style = document.documentElement.style
function updateCssVar(cssVars: Record<string, any>) {
Object.keys(cssVars).forEach((name) => {
style.setProperty(name, cssVars[name])
})
}
export function updatePageCssVar(cssVars: PageCssVars) {
return updateCssVar(cssVars)
}
interface AppCssVar {
'--status-bar-height'?: string
'--tab-bar-height'?: string
}
export function updateAppCssVar(cssVars: AppCssVar) {
return updateCssVar(cssVars)
}
import { ComponentPublicInstance } from 'vue' import { ComponentPublicInstance } from 'vue'
import { normalizeTarget } from '@dcloudio/uni-shared' import { normalizeTarget } from '@dcloudio/uni-shared'
import { getWindowOffset } from '../../helpers/getWindowOffset' import { getWindowOffset } from '../../helpers'
const isClickEvent = (val: Event): val is MouseEvent => val.type === 'click' const isClickEvent = (val: Event): val is MouseEvent => val.type === 'click'
const isMouseEvent = (val: Event): val is MouseEvent => const isMouseEvent = (val: Event): val is MouseEvent =>
val.type.indexOf('mouse') === 0 val.type.indexOf('mouse') === 0
// normalizeNativeEvent
export function $normalizeNativeEvent( export function $nne(this: ComponentPublicInstance, evt: Event) {
this: ComponentPublicInstance,
evt: Event
) {
// TODO 目前内置组件底层实现,也会进入以下处理逻辑,可能会有影响 // TODO 目前内置组件底层实现,也会进入以下处理逻辑,可能会有影响
const { currentTarget } = evt const { currentTarget } = evt
if (!(evt instanceof Event) || !(currentTarget instanceof HTMLElement)) { if (!(evt instanceof Event) || !(currentTarget instanceof HTMLElement)) {
......
...@@ -8236,6 +8236,10 @@ function autoPrefix(style, rawName) { ...@@ -8236,6 +8236,10 @@ function autoPrefix(style, rawName) {
// upx,rpx // upx,rpx
const rpxRE = /\b([+-]?\d+(\.\d+)?)[r|u]px\b/g; const rpxRE = /\b([+-]?\d+(\.\d+)?)[r|u]px\b/g;
const normalizeRpx = (val) => { const normalizeRpx = (val) => {
// @ts-ignore
if (typeof rpx2px !== 'function') {
return val;
}
if (isString(val)) { if (isString(val)) {
return val.replace(rpxRE, (a, b) => { return val.replace(rpxRE, (a, b) => {
// @ts-ignore // @ts-ignore
...@@ -8398,7 +8402,7 @@ function createInvoker(initialValue, instance) { ...@@ -8398,7 +8402,7 @@ function createInvoker(initialValue, instance) {
if (timeStamp >= invoker.attached - 1) { if (timeStamp >= invoker.attached - 1) {
// fixed by xxxxxx // fixed by xxxxxx
const proxy = instance && instance.proxy; const proxy = instance && instance.proxy;
const normalizeNativeEvent = proxy && proxy.$normalizeNativeEvent; const normalizeNativeEvent = proxy && proxy.$nne;
callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [normalizeNativeEvent ? normalizeNativeEvent(e) : e]); callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [normalizeNativeEvent ? normalizeNativeEvent(e) : e]);
} }
}; };
......
...@@ -8236,6 +8236,10 @@ function autoPrefix(style, rawName) { ...@@ -8236,6 +8236,10 @@ function autoPrefix(style, rawName) {
// upx,rpx // upx,rpx
const rpxRE = /\b([+-]?\d+(\.\d+)?)[r|u]px\b/g; const rpxRE = /\b([+-]?\d+(\.\d+)?)[r|u]px\b/g;
const normalizeRpx = (val) => { const normalizeRpx = (val) => {
// @ts-ignore
if (typeof rpx2px !== 'function') {
return val;
}
if (isString(val)) { if (isString(val)) {
return val.replace(rpxRE, (a, b) => { return val.replace(rpxRE, (a, b) => {
// @ts-ignore // @ts-ignore
...@@ -8398,7 +8402,7 @@ function createInvoker(initialValue, instance) { ...@@ -8398,7 +8402,7 @@ function createInvoker(initialValue, instance) {
if (timeStamp >= invoker.attached - 1) { if (timeStamp >= invoker.attached - 1) {
// fixed by xxxxxx // fixed by xxxxxx
const proxy = instance && instance.proxy; const proxy = instance && instance.proxy;
const normalizeNativeEvent = proxy && proxy.$normalizeNativeEvent; const normalizeNativeEvent = proxy && proxy.$nne;
callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [normalizeNativeEvent ? normalizeNativeEvent(e) : e]); callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [normalizeNativeEvent ? normalizeNativeEvent(e) : e]);
} }
}; };
......
此差异已折叠。
...@@ -2,7 +2,6 @@ import { ...@@ -2,7 +2,6 @@ import {
ref, ref,
withCtx, withCtx,
computed, computed,
onMounted,
ComputedRef, ComputedRef,
KeepAlive, KeepAlive,
openBlock, openBlock,
...@@ -17,6 +16,7 @@ import { ...@@ -17,6 +16,7 @@ import {
import { RouterView, useRoute } from 'vue-router' import { RouterView, useRoute } from 'vue-router'
import { updateCssVar } from '@dcloudio/uni-core'
import { useTabBar } from '../../setup/state' import { useTabBar } from '../../setup/state'
import { useKeepAliveRoute } from '../../setup/page' import { useKeepAliveRoute } from '../../setup/page'
...@@ -24,19 +24,18 @@ import TabBar from './tabBar' ...@@ -24,19 +24,18 @@ import TabBar from './tabBar'
type KeepAliveRoute = ReturnType<typeof useKeepAliveRoute> type KeepAliveRoute = ReturnType<typeof useKeepAliveRoute>
const CSS_VARS = [ const DEFAULT_CSS_VAR_VALUE = '0px'
'--status-bar-height', updateCssVar({
'--top-window-height', '--status-bar-height': DEFAULT_CSS_VAR_VALUE,
'--window-left', '--top-window-height': DEFAULT_CSS_VAR_VALUE,
'--window-right', '--window-left': DEFAULT_CSS_VAR_VALUE,
'--window-margin', '--window-right': DEFAULT_CSS_VAR_VALUE,
'--tab-bar-height', '--window-margin': DEFAULT_CSS_VAR_VALUE,
] '--tab-bar-height': DEFAULT_CSS_VAR_VALUE,
})
export default defineComponent({ export default defineComponent({
name: 'Layout', name: 'Layout',
setup(_props, { emit }) { setup(_props, { emit }) {
useCssVar()
const keepAliveRoute = (__UNI_FEATURE_PAGES__ && const keepAliveRoute = (__UNI_FEATURE_PAGES__ &&
useKeepAliveRoute()) as KeepAliveRoute useKeepAliveRoute()) as KeepAliveRoute
const topWindow = __UNI_FEATURE_TOPWINDOW__ && useTopWindow() const topWindow = __UNI_FEATURE_TOPWINDOW__ && useTopWindow()
...@@ -57,11 +56,6 @@ export default defineComponent({ ...@@ -57,11 +56,6 @@ export default defineComponent({
} }
}, },
}) })
import { updateCssVar } from '../../../helpers/dom'
function useCssVar() {
CSS_VARS.forEach((name) => updateCssVar(name, '0px'))
}
function useAppClass(showTabBar?: ComputedRef<boolean>) { function useAppClass(showTabBar?: ComputedRef<boolean>) {
const showMaxWidth = ref(false) const showMaxWidth = ref(false)
......
...@@ -3,9 +3,10 @@ import { extend, isArray } from '@vue/shared' ...@@ -3,9 +3,10 @@ import { extend, isArray } from '@vue/shared'
import { Input } from '@dcloudio/uni-components' import { Input } from '@dcloudio/uni-components'
import { getRealPath } from '@dcloudio/uni-platform' import { getRealPath } from '@dcloudio/uni-platform'
import { import {
ICON_PATH_SEARCH,
createSvgIconVNode,
invokeHook, invokeHook,
updateStyle,
createSvgIconVNode,
ICON_PATH_SEARCH,
} from '@dcloudio/uni-core' } from '@dcloudio/uni-core'
import { usePageMeta } from '../../setup/provide' import { usePageMeta } from '../../setup/provide'
import { import {
...@@ -13,8 +14,6 @@ import { ...@@ -13,8 +14,6 @@ import {
usePageHeadTransparentBackgroundColor, usePageHeadTransparentBackgroundColor,
} from './transparent' } from './transparent'
import { updateStyle } from '../../../helpers/dom'
const ICON_PATH_BACK = const ICON_PATH_BACK =
'M21.781 7.844l-9.063 8.594 9.063 8.594q0.25 0.25 0.25 0.609t-0.25 0.578q-0.25 0.25-0.578 0.25t-0.578-0.25l-9.625-9.125q-0.156-0.125-0.203-0.297t-0.047-0.359q0-0.156 0.047-0.328t0.203-0.297l9.625-9.125q0.25-0.25 0.578-0.25t0.578 0.25q0.25 0.219 0.25 0.578t-0.25 0.578z' 'M21.781 7.844l-9.063 8.594 9.063 8.594q0.25 0.25 0.25 0.609t-0.25 0.578q-0.25 0.25-0.578 0.25t-0.578-0.25l-9.625-9.125q-0.156-0.125-0.203-0.297t-0.047-0.359q0-0.156 0.047-0.328t0.203-0.297l9.625-9.125q0.25-0.25 0.578-0.25t0.578 0.25q0.25 0.219 0.25 0.578t-0.25 0.578z'
......
const sheetsMap = new Map()
export function updateStyle(id: string, content: string) {
let style = sheetsMap.get(id)
if (style && !(style instanceof HTMLStyleElement)) {
removeStyle(id)
style = undefined
}
if (!style) {
style = document.createElement('style')
style.setAttribute('type', 'text/css')
style.innerHTML = content
document.head.appendChild(style)
} else {
style.innerHTML = content
}
sheetsMap.set(id, style)
}
export function removeStyle(id: string) {
let style = sheetsMap.get(id)
if (style) {
if (style instanceof CSSStyleSheet) {
// @ts-ignore
const index = document.adoptedStyleSheets.indexOf(style)
// @ts-ignore
document.adoptedStyleSheets = document.adoptedStyleSheets.filter(
(s: CSSStyleSheet) => s !== style
)
} else {
document.head.removeChild(style)
}
sheetsMap.delete(id)
}
}
const screen = window.screen const screen = window.screen
const documentElement = document.documentElement const documentElement = document.documentElement
let styleObj: CSSStyleDeclaration
export function updateCssVar(name: string, value: string) {
if (!styleObj) {
styleObj = documentElement.style
}
styleObj.setProperty(name, value)
}
export function checkMinWidth(minWidth: number) { export function checkMinWidth(minWidth: number) {
const sizes = [ const sizes = [
window.outerWidth, window.outerWidth,
......
...@@ -33,7 +33,7 @@ export function uniPagesJsonPlugin( ...@@ -33,7 +33,7 @@ export function uniPagesJsonPlugin(
if (id.endsWith(PAGES_JSON_JS)) { if (id.endsWith(PAGES_JSON_JS)) {
return { return {
code: code:
registerGlobalCode + (config.define!.__UNI_FEATURE_RPX__ ? registerGlobalCode : '') +
(options.command === 'serve' ? registerDevServerGlobalCode : '') + (options.command === 'serve' ? registerDevServerGlobalCode : '') +
parsePagesJson(code, config, options), parsePagesJson(code, config, options),
map: { mappings: '' }, map: { mappings: '' },
......
...@@ -24,6 +24,7 @@ interface PagesFeatures { ...@@ -24,6 +24,7 @@ interface PagesFeatures {
interface ManifestFeatures { interface ManifestFeatures {
wx: boolean wx: boolean
wxs: boolean wxs: boolean
rpx: boolean
promise: boolean promise: boolean
longpress: boolean longpress: boolean
routerMode: '"hash"' | '"history"' routerMode: '"hash"' | '"history"'
...@@ -158,6 +159,7 @@ function resolveManifestFeature( ...@@ -158,6 +159,7 @@ function resolveManifestFeature(
const features: ManifestFeatures = { const features: ManifestFeatures = {
wx: false, wx: false,
wxs: true, wxs: true,
rpx: true,
promise: false, promise: false,
longpress: true, longpress: true,
routerMode: '"hash"', routerMode: '"hash"',
...@@ -217,6 +219,7 @@ export function getFeatures( ...@@ -217,6 +219,7 @@ export function getFeatures(
const { const {
wx, wx,
wxs, wxs,
rpx,
nvue, nvue,
i18nEn, i18nEn,
i18nEs, i18nEs,
...@@ -245,6 +248,7 @@ export function getFeatures( ...@@ -245,6 +248,7 @@ export function getFeatures(
return { return {
__UNI_FEATURE_WX__: wx, // 是否启用小程序的组件实例 API,如:selectComponent 等(uni-core/src/service/plugin/appConfig) __UNI_FEATURE_WX__: wx, // 是否启用小程序的组件实例 API,如:selectComponent 等(uni-core/src/service/plugin/appConfig)
__UNI_FEATURE_WXS__: wxs, // 是否启用 wxs 支持,如:getComponentDescriptor 等(uni-core/src/view/plugin/appConfig) __UNI_FEATURE_WXS__: wxs, // 是否启用 wxs 支持,如:getComponentDescriptor 等(uni-core/src/view/plugin/appConfig)
__UNI_FEATURE_RPX__: rpx, // 是否启用运行时 rpx 支持
__UNI_FEATURE_PROMISE__: promise, // 是否启用旧版本的 promise 支持(即返回[err,res]的格式),默认返回标准 __UNI_FEATURE_PROMISE__: promise, // 是否启用旧版本的 promise 支持(即返回[err,res]的格式),默认返回标准
__UNI_FEATURE_LONGPRESS__: longpress, // 是否启用longpress __UNI_FEATURE_LONGPRESS__: longpress, // 是否启用longpress
__UNI_FEATURE_I18N_EN__: i18nEn, // 是否启用en __UNI_FEATURE_I18N_EN__: i18nEn, // 是否启用en
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册