Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
58f3c3d6
U
uni-app
项目概览
DCloud
/
uni-app
14 天 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
58f3c3d6
编写于
10月 09, 2023
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "chore: build types metadata"
This reverts commit
7790ee4a
.
上级
eaa79fcb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
4013 addition
and
0 deletion
+4013
-0
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+1649
-0
packages/uni-shared/dist/uni-shared.d.ts
packages/uni-shared/dist/uni-shared.d.ts
+883
-0
packages/uni-shared/dist/uni-shared.es.js
packages/uni-shared/dist/uni-shared.es.js
+1481
-0
未找到文件。
packages/uni-shared/dist/uni-shared.cjs.js
0 → 100644
浏览文件 @
58f3c3d6
'
use strict
'
;
var
shared
=
require
(
'
@vue/shared
'
);
const
BUILT_IN_TAG_NAMES
=
[
'
ad
'
,
'
ad-content-page
'
,
'
ad-draw
'
,
'
audio
'
,
'
button
'
,
'
camera
'
,
'
canvas
'
,
'
checkbox
'
,
'
checkbox-group
'
,
'
cover-image
'
,
'
cover-view
'
,
'
editor
'
,
'
form
'
,
'
functional-page-navigator
'
,
'
icon
'
,
'
image
'
,
'
input
'
,
'
label
'
,
'
live-player
'
,
'
live-pusher
'
,
'
map
'
,
'
movable-area
'
,
'
movable-view
'
,
'
navigator
'
,
'
official-account
'
,
'
open-data
'
,
'
picker
'
,
'
picker-view
'
,
'
picker-view-column
'
,
'
progress
'
,
'
radio
'
,
'
radio-group
'
,
'
rich-text
'
,
'
scroll-view
'
,
'
slider
'
,
'
swiper
'
,
'
swiper-item
'
,
'
switch
'
,
'
text
'
,
'
textarea
'
,
'
video
'
,
'
view
'
,
'
web-view
'
,
];
const
BUILT_IN_TAGS
=
BUILT_IN_TAG_NAMES
.
map
((
tag
)
=>
'
uni-
'
+
tag
);
const
TAGS
=
[
'
app
'
,
'
layout
'
,
'
content
'
,
'
main
'
,
'
top-window
'
,
'
left-window
'
,
'
right-window
'
,
'
tabbar
'
,
'
page
'
,
'
page-head
'
,
'
page-wrapper
'
,
'
page-body
'
,
'
page-refresh
'
,
'
actionsheet
'
,
'
modal
'
,
'
toast
'
,
'
resize-sensor
'
,
'
shadow-root
'
,
].
map
((
tag
)
=>
'
uni-
'
+
tag
);
const
NVUE_BUILT_IN_TAGS
=
[
'
svg
'
,
'
view
'
,
'
a
'
,
'
div
'
,
'
img
'
,
'
image
'
,
'
text
'
,
'
span
'
,
'
input
'
,
'
textarea
'
,
'
spinner
'
,
'
select
'
,
// slider 被自定义 u-slider 替代
// 'slider',
'
slider-neighbor
'
,
'
indicator
'
,
'
canvas
'
,
'
list
'
,
'
cell
'
,
'
header
'
,
'
loading
'
,
'
loading-indicator
'
,
'
refresh
'
,
'
scrollable
'
,
'
scroller
'
,
'
video
'
,
'
web
'
,
'
embed
'
,
'
tabbar
'
,
'
tabheader
'
,
'
datepicker
'
,
'
timepicker
'
,
'
marquee
'
,
'
countdown
'
,
'
dc-switch
'
,
'
waterfall
'
,
'
richtext
'
,
'
recycle-list
'
,
'
u-scalable
'
,
'
barcode
'
,
'
gcanvas
'
,
];
const
UVUE_BUILT_IN_TAGS
=
[
'
loading-indicator
'
,
'
list-view
'
,
'
list-item
'
,
'
swiper
'
,
'
swiper-item
'
,
'
rich-text
'
,
'
sticky-view
'
,
// 自定义
'
uni-slider
'
,
];
const
NVUE_U_BUILT_IN_TAGS
=
[
'
u-text
'
,
'
u-image
'
,
'
u-input
'
,
'
u-textarea
'
,
'
u-video
'
,
'
u-web-view
'
,
'
u-slider
'
,
'
u-ad
'
,
'
u-ad-draw
'
,
'
u-rich-text
'
,
];
function
isBuiltInComponent
(
tag
)
{
// h5 平台会被转换为 v-uni-
return
BUILT_IN_TAGS
.
indexOf
(
'
uni-
'
+
tag
.
replace
(
'
v-uni-
'
,
''
))
!==
-
1
;
}
function
isH5CustomElement
(
tag
)
{
return
TAGS
.
indexOf
(
tag
)
!==
-
1
||
BUILT_IN_TAGS
.
indexOf
(
tag
)
!==
-
1
;
}
function
isH5NativeTag
(
tag
)
{
return
(
tag
!==
'
head
'
&&
(
shared
.
isHTMLTag
(
tag
)
||
shared
.
isSVGTag
(
tag
))
&&
!
isBuiltInComponent
(
tag
));
}
function
isAppNativeTag
(
tag
)
{
return
shared
.
isHTMLTag
(
tag
)
||
shared
.
isSVGTag
(
tag
)
||
isBuiltInComponent
(
tag
);
}
const
NVUE_CUSTOM_COMPONENTS
=
[
'
ad
'
,
'
ad-draw
'
,
'
button
'
,
'
checkbox-group
'
,
'
checkbox
'
,
'
form
'
,
'
icon
'
,
'
label
'
,
'
movable-area
'
,
'
movable-view
'
,
'
navigator
'
,
'
picker
'
,
'
progress
'
,
'
radio-group
'
,
'
radio
'
,
'
rich-text
'
,
'
swiper-item
'
,
'
swiper
'
,
'
switch
'
,
'
slider
'
,
'
picker-view
'
,
'
picker-view-column
'
,
];
function
isAppUVueNativeTag
(
tag
)
{
if
(
UVUE_BUILT_IN_TAGS
.
includes
(
tag
))
{
return
true
;
}
if
(
NVUE_CUSTOM_COMPONENTS
.
includes
(
tag
))
{
return
false
;
}
if
(
isBuiltInComponent
(
tag
))
{
return
true
;
}
// u-text,u-video...
if
(
NVUE_U_BUILT_IN_TAGS
.
includes
(
tag
))
{
return
true
;
}
return
false
;
}
function
isAppNVueNativeTag
(
tag
)
{
if
(
NVUE_BUILT_IN_TAGS
.
includes
(
tag
))
{
return
true
;
}
if
(
NVUE_CUSTOM_COMPONENTS
.
includes
(
tag
))
{
return
false
;
}
if
(
isBuiltInComponent
(
tag
))
{
return
true
;
}
// u-text,u-video...
if
(
NVUE_U_BUILT_IN_TAGS
.
includes
(
tag
))
{
return
true
;
}
return
false
;
}
function
isMiniProgramNativeTag
(
tag
)
{
return
isBuiltInComponent
(
tag
);
}
function
createIsCustomElement
(
tags
=
[])
{
return
function
isCustomElement
(
tag
)
{
return
tags
.
includes
(
tag
);
};
}
function
isComponentTag
(
tag
)
{
return
tag
[
0
].
toLowerCase
()
+
tag
.
slice
(
1
)
===
'
component
'
;
}
const
COMPONENT_SELECTOR_PREFIX
=
'
uni-
'
;
const
COMPONENT_PREFIX
=
'
v-
'
+
COMPONENT_SELECTOR_PREFIX
;
const
LINEFEED
=
'
\n
'
;
const
NAVBAR_HEIGHT
=
44
;
const
TABBAR_HEIGHT
=
50
;
const
ON_REACH_BOTTOM_DISTANCE
=
50
;
const
RESPONSIVE_MIN_WIDTH
=
768
;
const
UNI_STORAGE_LOCALE
=
'
UNI_LOCALE
'
;
// quickapp-webview 不能使用 default 作为插槽名称
const
SLOT_DEFAULT_NAME
=
'
d
'
;
const
COMPONENT_NAME_PREFIX
=
'
VUni
'
;
const
I18N_JSON_DELIMITERS
=
[
'
%
'
,
'
%
'
];
const
PRIMARY_COLOR
=
'
#007aff
'
;
const
SELECTED_COLOR
=
'
#0062cc
'
;
// 选中的颜色,如选项卡默认的选中颜色
const
BACKGROUND_COLOR
=
'
#f7f7f7
'
;
// 背景色,如标题栏默认背景色
const
UNI_SSR
=
'
__uniSSR
'
;
const
UNI_SSR_TITLE
=
'
title
'
;
const
UNI_SSR_STORE
=
'
store
'
;
const
UNI_SSR_DATA
=
'
data
'
;
const
UNI_SSR_GLOBAL_DATA
=
'
globalData
'
;
const
SCHEME_RE
=
/^
([
a-z-
]
+:
)?\/\/
/i
;
const
DATA_RE
=
/^data:.*,.*/
;
const
WEB_INVOKE_APPSERVICE
=
'
WEB_INVOKE_APPSERVICE
'
;
const
WXS_PROTOCOL
=
'
wxs://
'
;
const
JSON_PROTOCOL
=
'
json://
'
;
const
WXS_MODULES
=
'
wxsModules
'
;
const
RENDERJS_MODULES
=
'
renderjsModules
'
;
// lifecycle
// App and Page
const
ON_SHOW
=
'
onShow
'
;
const
ON_HIDE
=
'
onHide
'
;
//App
const
ON_LAUNCH
=
'
onLaunch
'
;
const
ON_ERROR
=
'
onError
'
;
const
ON_THEME_CHANGE
=
'
onThemeChange
'
;
const
OFF_THEME_CHANGE
=
'
offThemeChange
'
;
const
ON_KEYBOARD_HEIGHT_CHANGE
=
'
onKeyboardHeightChange
'
;
const
ON_PAGE_NOT_FOUND
=
'
onPageNotFound
'
;
const
ON_UNHANDLE_REJECTION
=
'
onUnhandledRejection
'
;
//Page
const
ON_LOAD
=
'
onLoad
'
;
const
ON_READY
=
'
onReady
'
;
const
ON_UNLOAD
=
'
onUnload
'
;
// 百度特有
const
ON_INIT
=
'
onInit
'
;
// 微信特有
const
ON_SAVE_EXIT_STATE
=
'
onSaveExitState
'
;
const
ON_RESIZE
=
'
onResize
'
;
const
ON_BACK_PRESS
=
'
onBackPress
'
;
const
ON_PAGE_SCROLL
=
'
onPageScroll
'
;
const
ON_TAB_ITEM_TAP
=
'
onTabItemTap
'
;
const
ON_REACH_BOTTOM
=
'
onReachBottom
'
;
const
ON_PULL_DOWN_REFRESH
=
'
onPullDownRefresh
'
;
const
ON_SHARE_TIMELINE
=
'
onShareTimeline
'
;
const
ON_ADD_TO_FAVORITES
=
'
onAddToFavorites
'
;
const
ON_SHARE_APP_MESSAGE
=
'
onShareAppMessage
'
;
// navigationBar
const
ON_NAVIGATION_BAR_BUTTON_TAP
=
'
onNavigationBarButtonTap
'
;
const
ON_NAVIGATION_BAR_CHANGE
=
'
onNavigationBarChange
'
;
const
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
=
'
onNavigationBarSearchInputClicked
'
;
const
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
=
'
onNavigationBarSearchInputChanged
'
;
const
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
=
'
onNavigationBarSearchInputConfirmed
'
;
const
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
=
'
onNavigationBarSearchInputFocusChanged
'
;
// framework
const
ON_APP_ENTER_FOREGROUND
=
'
onAppEnterForeground
'
;
const
ON_APP_ENTER_BACKGROUND
=
'
onAppEnterBackground
'
;
const
ON_WEB_INVOKE_APP_SERVICE
=
'
onWebInvokeAppService
'
;
const
ON_WXS_INVOKE_CALL_METHOD
=
'
onWxsInvokeCallMethod
'
;
function
isComponentInternalInstance
(
vm
)
{
return
!!
vm
.
appContext
;
}
function
resolveComponentInstance
(
instance
)
{
return
(
instance
&&
(
isComponentInternalInstance
(
instance
)
?
instance
.
proxy
:
instance
));
}
function
resolveOwnerVm
(
vm
)
{
if
(
!
vm
)
{
return
;
}
let
componentName
=
vm
.
type
.
name
;
while
(
componentName
&&
isBuiltInComponent
(
shared
.
hyphenate
(
componentName
)))
{
// ownerInstance 内置组件需要使用父 vm
vm
=
vm
.
parent
;
componentName
=
vm
.
type
.
name
;
}
return
vm
.
proxy
;
}
function
isElement
(
el
)
{
// Element
return
el
.
nodeType
===
1
;
}
function
resolveOwnerEl
(
instance
,
multi
=
false
)
{
const
{
vnode
}
=
instance
;
if
(
isElement
(
vnode
.
el
))
{
return
multi
?
(
vnode
.
el
?
[
vnode
.
el
]
:
[])
:
vnode
.
el
;
}
const
{
subTree
}
=
instance
;
// ShapeFlags.ARRAY_CHILDREN = 1<<4
if
(
subTree
.
shapeFlag
&
16
)
{
const
elemVNodes
=
subTree
.
children
.
filter
((
vnode
)
=>
vnode
.
el
&&
isElement
(
vnode
.
el
));
if
(
elemVNodes
.
length
>
0
)
{
if
(
multi
)
{
return
elemVNodes
.
map
((
node
)
=>
node
.
el
);
}
return
elemVNodes
[
0
].
el
;
}
}
return
multi
?
(
vnode
.
el
?
[
vnode
.
el
]
:
[])
:
vnode
.
el
;
}
function
dynamicSlotName
(
name
)
{
return
name
===
'
default
'
?
SLOT_DEFAULT_NAME
:
name
;
}
const
customizeRE
=
/:/g
;
function
customizeEvent
(
str
)
{
return
shared
.
camelize
(
str
.
replace
(
customizeRE
,
'
-
'
));
}
let
lastLogTime
=
0
;
function
formatLog
(
module
,
...
args
)
{
const
now
=
Date
.
now
();
const
diff
=
lastLogTime
?
now
-
lastLogTime
:
0
;
lastLogTime
=
now
;
return
`[
${
now
}
][
${
diff
}
ms][
${
module
}
]:
${
args
.
map
((
arg
)
=>
JSON
.
stringify
(
arg
))
.
join
(
'
'
)}
`
;
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
function
cacheStringFunction
(
fn
)
{
return
cache
(
fn
);
}
function
getLen
(
str
=
''
)
{
return
(
''
+
str
).
replace
(
/
[^\x
00-
\x
ff
]
/g
,
'
**
'
).
length
;
}
function
hasLeadingSlash
(
str
)
{
return
str
.
indexOf
(
'
/
'
)
===
0
;
}
function
addLeadingSlash
(
str
)
{
return
hasLeadingSlash
(
str
)
?
str
:
'
/
'
+
str
;
}
function
removeLeadingSlash
(
str
)
{
return
hasLeadingSlash
(
str
)
?
str
.
slice
(
1
)
:
str
;
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
ret
=
fns
[
i
](
arg
);
}
return
ret
;
};
function
updateElementStyle
(
element
,
styles
)
{
for
(
const
attrName
in
styles
)
{
element
.
style
[
attrName
]
=
styles
[
attrName
];
}
}
function
once
(
fn
,
ctx
=
null
)
{
let
res
;
return
((...
args
)
=>
{
if
(
fn
)
{
res
=
fn
.
apply
(
ctx
,
args
);
fn
=
null
;
}
return
res
;
});
}
const
sanitise
=
(
val
)
=>
(
val
&&
JSON
.
parse
(
JSON
.
stringify
(
val
)))
||
val
;
const
_completeValue
=
(
value
)
=>
(
value
>
9
?
value
:
'
0
'
+
value
);
function
formatDateTime
({
date
=
new
Date
(),
mode
=
'
date
'
})
{
if
(
mode
===
'
time
'
)
{
return
(
_completeValue
(
date
.
getHours
())
+
'
:
'
+
_completeValue
(
date
.
getMinutes
()));
}
else
{
return
(
date
.
getFullYear
()
+
'
-
'
+
_completeValue
(
date
.
getMonth
()
+
1
)
+
'
-
'
+
_completeValue
(
date
.
getDate
()));
}
}
function
callOptions
(
options
,
data
)
{
options
=
options
||
{};
if
(
shared
.
isString
(
data
))
{
data
=
{
errMsg
:
data
,
};
}
if
(
/:ok$/
.
test
(
data
.
errMsg
))
{
if
(
shared
.
isFunction
(
options
.
success
))
{
options
.
success
(
data
);
}
}
else
{
if
(
shared
.
isFunction
(
options
.
fail
))
{
options
.
fail
(
data
);
}
}
if
(
shared
.
isFunction
(
options
.
complete
))
{
options
.
complete
(
data
);
}
}
function
getValueByDataPath
(
obj
,
path
)
{
if
(
!
shared
.
isString
(
path
))
{
return
;
}
path
=
path
.
replace
(
/
\[(\d
+
)\]
/g
,
'
.$1
'
);
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getValueByDataPath
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
sortObject
(
obj
)
{
let
sortObj
=
{};
if
(
shared
.
isPlainObject
(
obj
))
{
Object
.
keys
(
obj
)
.
sort
()
.
forEach
((
key
)
=>
{
const
_key
=
key
;
sortObj
[
_key
]
=
obj
[
_key
];
});
}
return
!
Object
.
keys
(
sortObj
)
?
obj
:
sortObj
;
}
function
formatKey
(
key
)
{
return
shared
.
camelize
(
key
.
substring
(
5
));
}
// question/139181,增加副作用,避免 initCustomDataset 在 build 下被 tree-shaking
const
initCustomDatasetOnce
=
/*#__PURE__*/
once
(()
=>
{
const
prototype
=
HTMLElement
.
prototype
;
const
setAttribute
=
prototype
.
setAttribute
;
prototype
.
setAttribute
=
function
(
key
,
value
)
{
if
(
key
.
startsWith
(
'
data-
'
)
&&
this
.
tagName
.
startsWith
(
'
UNI-
'
))
{
const
dataset
=
this
.
__uniDataset
||
(
this
.
__uniDataset
=
{});
dataset
[
formatKey
(
key
)]
=
value
;
}
setAttribute
.
call
(
this
,
key
,
value
);
};
const
removeAttribute
=
prototype
.
removeAttribute
;
prototype
.
removeAttribute
=
function
(
key
)
{
if
(
this
.
__uniDataset
&&
key
.
startsWith
(
'
data-
'
)
&&
this
.
tagName
.
startsWith
(
'
UNI-
'
))
{
delete
this
.
__uniDataset
[
formatKey
(
key
)];
}
removeAttribute
.
call
(
this
,
key
);
};
});
function
getCustomDataset
(
el
)
{
return
shared
.
extend
({},
el
.
dataset
,
el
.
__uniDataset
);
}
const
unitRE
=
new
RegExp
(
`"[^"]+"|'[^']+'|url\\([^)]+\\)|(\\d*\\.?\\d+)[r|u]px`
,
'
g
'
);
function
toFixed
(
number
,
precision
)
{
const
multiplier
=
Math
.
pow
(
10
,
precision
+
1
);
const
wholeNumber
=
Math
.
floor
(
number
*
multiplier
);
return
(
Math
.
round
(
wholeNumber
/
10
)
*
10
)
/
multiplier
;
}
const
defaultRpx2Unit
=
{
unit
:
'
rem
'
,
unitRatio
:
10
/
320
,
unitPrecision
:
5
,
};
const
defaultMiniProgramRpx2Unit
=
{
unit
:
'
rpx
'
,
unitRatio
:
1
,
unitPrecision
:
1
,
};
const
defaultNVueRpx2Unit
=
defaultMiniProgramRpx2Unit
;
function
createRpx2Unit
(
unit
,
unitRatio
,
unitPrecision
)
{
// ignore: rpxCalcIncludeWidth
return
(
val
)
=>
val
.
replace
(
unitRE
,
(
m
,
$1
)
=>
{
if
(
!
$1
)
{
return
m
;
}
if
(
unitRatio
===
1
)
{
return
`
${
$1
}${
unit
}
`
;
}
const
value
=
toFixed
(
parseFloat
(
$1
)
*
unitRatio
,
unitPrecision
);
return
value
===
0
?
'
0
'
:
`
${
value
}${
unit
}
`
;
});
}
function
passive
(
passive
)
{
return
{
passive
};
}
function
normalizeDataset
(
el
)
{
// TODO
return
JSON
.
parse
(
JSON
.
stringify
(
el
.
dataset
||
{}));
}
function
normalizeTarget
(
el
)
{
const
{
id
,
offsetTop
,
offsetLeft
}
=
el
;
return
{
id
,
dataset
:
getCustomDataset
(
el
),
offsetTop
,
offsetLeft
,
};
}
function
addFont
(
family
,
source
,
desc
)
{
const
fonts
=
document
.
fonts
;
if
(
fonts
)
{
const
fontFace
=
new
FontFace
(
family
,
source
,
desc
);
return
fontFace
.
load
().
then
(()
=>
{
fonts
.
add
&&
fonts
.
add
(
fontFace
);
});
}
return
new
Promise
((
resolve
)
=>
{
const
style
=
document
.
createElement
(
'
style
'
);
const
values
=
[];
if
(
desc
)
{
const
{
style
,
weight
,
stretch
,
unicodeRange
,
variant
,
featureSettings
}
=
desc
;
style
&&
values
.
push
(
`font-style:
${
style
}
`
);
weight
&&
values
.
push
(
`font-weight:
${
weight
}
`
);
stretch
&&
values
.
push
(
`font-stretch:
${
stretch
}
`
);
unicodeRange
&&
values
.
push
(
`unicode-range:
${
unicodeRange
}
`
);
variant
&&
values
.
push
(
`font-variant:
${
variant
}
`
);
featureSettings
&&
values
.
push
(
`font-feature-settings:
${
featureSettings
}
`
);
}
style
.
innerText
=
`@font-face{font-family:"
${
family
}
";src:
${
source
}
;
${
values
.
join
(
'
;
'
)}
}`
;
document
.
head
.
appendChild
(
style
);
resolve
();
});
}
function
scrollTo
(
scrollTop
,
duration
,
isH5
)
{
if
(
shared
.
isString
(
scrollTop
))
{
const
el
=
document
.
querySelector
(
scrollTop
);
if
(
el
)
{
const
{
height
,
top
}
=
el
.
getBoundingClientRect
();
scrollTop
=
top
+
window
.
pageYOffset
;
if
(
isH5
)
{
scrollTop
-=
height
;
}
}
}
if
(
scrollTop
<
0
)
{
scrollTop
=
0
;
}
const
documentElement
=
document
.
documentElement
;
const
{
clientHeight
,
scrollHeight
}
=
documentElement
;
scrollTop
=
Math
.
min
(
scrollTop
,
scrollHeight
-
clientHeight
);
if
(
duration
===
0
)
{
// 部分浏览器(比如微信)中 scrollTop 的值需要通过 document.body 来控制
documentElement
.
scrollTop
=
document
.
body
.
scrollTop
=
scrollTop
;
return
;
}
if
(
window
.
scrollY
===
scrollTop
)
{
return
;
}
const
scrollTo
=
(
duration
)
=>
{
if
(
duration
<=
0
)
{
window
.
scrollTo
(
0
,
scrollTop
);
return
;
}
const
distaince
=
scrollTop
-
window
.
scrollY
;
requestAnimationFrame
(
function
()
{
window
.
scrollTo
(
0
,
window
.
scrollY
+
(
distaince
/
duration
)
*
10
);
scrollTo
(
duration
-
10
);
});
};
scrollTo
(
duration
);
}
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
const
res
=
obj
?
Object
.
keys
(
obj
)
.
map
((
key
)
=>
{
let
val
=
obj
[
key
];
if
(
typeof
val
===
undefined
||
val
===
null
)
{
val
=
''
;
}
else
if
(
shared
.
isPlainObject
(
val
))
{
val
=
JSON
.
stringify
(
val
);
}
return
encodeStr
(
key
)
+
'
=
'
+
encodeStr
(
val
);
})
.
filter
((
x
)
=>
x
.
length
>
0
)
.
join
(
'
&
'
)
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
/**
* Decode text using `decodeURIComponent`. Returns the original text if it
* fails.
*
* @param text - string to decode
* @returns decoded string
*/
function
decode
(
text
)
{
try
{
return
decodeURIComponent
(
''
+
text
);
}
catch
(
err
)
{
}
return
''
+
text
;
}
function
decodedQuery
(
query
=
{})
{
const
decodedQuery
=
{};
Object
.
keys
(
query
).
forEach
((
name
)
=>
{
try
{
decodedQuery
[
name
]
=
decode
(
query
[
name
]);
}
catch
(
e
)
{
decodedQuery
[
name
]
=
query
[
name
];
}
});
return
decodedQuery
;
}
const
PLUS_RE
=
/
\+
/g
;
// %2B
/**
* https://github.com/vuejs/vue-router-next/blob/master/src/query.ts
* @internal
*
* @param search - search string to parse
* @returns a query object
*/
function
parseQuery
(
search
)
{
const
query
=
{};
// avoid creating an object with an empty key and empty value
// because of split('&')
if
(
search
===
''
||
search
===
'
?
'
)
return
query
;
const
hasLeadingIM
=
search
[
0
]
===
'
?
'
;
const
searchParams
=
(
hasLeadingIM
?
search
.
slice
(
1
)
:
search
).
split
(
'
&
'
);
for
(
let
i
=
0
;
i
<
searchParams
.
length
;
++
i
)
{
// pre decode the + into space
const
searchParam
=
searchParams
[
i
].
replace
(
PLUS_RE
,
'
'
);
// allow the = character
let
eqPos
=
searchParam
.
indexOf
(
'
=
'
);
let
key
=
decode
(
eqPos
<
0
?
searchParam
:
searchParam
.
slice
(
0
,
eqPos
));
let
value
=
eqPos
<
0
?
null
:
decode
(
searchParam
.
slice
(
eqPos
+
1
));
if
(
key
in
query
)
{
// an extra variable for ts types
let
currentValue
=
query
[
key
];
if
(
!
shared
.
isArray
(
currentValue
))
{
currentValue
=
query
[
key
]
=
[
currentValue
];
}
currentValue
.
push
(
value
);
}
else
{
query
[
key
]
=
value
;
}
}
return
query
;
}
function
parseUrl
(
url
)
{
const
[
path
,
querystring
]
=
url
.
split
(
'
?
'
,
2
);
return
{
path
,
query
:
parseQuery
(
querystring
||
''
),
};
}
function
parseNVueDataset
(
attr
)
{
const
dataset
=
{};
if
(
attr
)
{
Object
.
keys
(
attr
).
forEach
((
key
)
=>
{
if
(
key
.
indexOf
(
'
data-
'
)
===
0
)
{
dataset
[
key
.
replace
(
'
data-
'
,
''
)]
=
attr
[
key
];
}
});
}
return
dataset
;
}
function
plusReady
(
callback
)
{
if
(
!
shared
.
isFunction
(
callback
))
{
return
;
}
if
(
window
.
plus
)
{
return
callback
();
}
document
.
addEventListener
(
'
plusready
'
,
callback
);
}
class
DOMException
extends
Error
{
constructor
(
message
)
{
super
(
message
);
this
.
name
=
'
DOMException
'
;
}
}
function
normalizeEventType
(
type
,
options
)
{
if
(
options
)
{
if
(
options
.
capture
)
{
type
+=
'
Capture
'
;
}
if
(
options
.
once
)
{
type
+=
'
Once
'
;
}
if
(
options
.
passive
)
{
type
+=
'
Passive
'
;
}
}
return
`on
${
shared
.
capitalize
(
shared
.
camelize
(
type
))}
`
;
}
class
UniEvent
{
constructor
(
type
,
opts
)
{
this
.
defaultPrevented
=
false
;
this
.
timeStamp
=
Date
.
now
();
this
.
_stop
=
false
;
this
.
_end
=
false
;
this
.
type
=
type
;
this
.
bubbles
=
!!
opts
.
bubbles
;
this
.
cancelable
=
!!
opts
.
cancelable
;
}
preventDefault
()
{
this
.
defaultPrevented
=
true
;
}
stopImmediatePropagation
()
{
this
.
_end
=
this
.
_stop
=
true
;
}
stopPropagation
()
{
this
.
_stop
=
true
;
}
}
function
createUniEvent
(
evt
)
{
if
(
evt
instanceof
UniEvent
)
{
return
evt
;
}
const
[
type
]
=
parseEventName
(
evt
.
type
);
const
uniEvent
=
new
UniEvent
(
type
,
{
bubbles
:
false
,
cancelable
:
false
,
});
shared
.
extend
(
uniEvent
,
evt
);
return
uniEvent
;
}
class
UniEventTarget
{
constructor
()
{
this
.
listeners
=
Object
.
create
(
null
);
}
dispatchEvent
(
evt
)
{
const
listeners
=
this
.
listeners
[
evt
.
type
];
if
(
!
listeners
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
))
{
console
.
error
(
formatLog
(
'
dispatchEvent
'
,
this
.
nodeId
),
evt
.
type
,
'
not found
'
);
}
return
false
;
}
// 格式化事件类型
const
event
=
createUniEvent
(
evt
);
const
len
=
listeners
.
length
;
for
(
let
i
=
0
;
i
<
len
;
i
++
)
{
listeners
[
i
].
call
(
this
,
event
);
if
(
event
.
_end
)
{
break
;
}
}
return
event
.
cancelable
&&
event
.
defaultPrevented
;
}
addEventListener
(
type
,
listener
,
options
)
{
type
=
normalizeEventType
(
type
,
options
);
(
this
.
listeners
[
type
]
||
(
this
.
listeners
[
type
]
=
[])).
push
(
listener
);
}
removeEventListener
(
type
,
callback
,
options
)
{
type
=
normalizeEventType
(
type
,
options
);
const
listeners
=
this
.
listeners
[
type
];
if
(
!
listeners
)
{
return
;
}
const
index
=
listeners
.
indexOf
(
callback
);
if
(
index
>
-
1
)
{
listeners
.
splice
(
index
,
1
);
}
}
}
const
optionsModifierRE
=
/
(?:
Once|Passive|Capture
)
$/
;
function
parseEventName
(
name
)
{
let
options
;
if
(
optionsModifierRE
.
test
(
name
))
{
options
=
{};
let
m
;
while
((
m
=
name
.
match
(
optionsModifierRE
)))
{
name
=
name
.
slice
(
0
,
name
.
length
-
m
[
0
].
length
);
options
[
m
[
0
].
toLowerCase
()]
=
true
;
}
}
return
[
shared
.
hyphenate
(
name
.
slice
(
2
)),
options
];
}
const
EventModifierFlags
=
/*#__PURE__*/
(()
=>
{
return
{
stop
:
1
,
prevent
:
1
<<
1
,
self
:
1
<<
2
,
};
})();
function
encodeModifier
(
modifiers
)
{
let
flag
=
0
;
if
(
modifiers
.
includes
(
'
stop
'
))
{
flag
|=
EventModifierFlags
.
stop
;
}
if
(
modifiers
.
includes
(
'
prevent
'
))
{
flag
|=
EventModifierFlags
.
prevent
;
}
if
(
modifiers
.
includes
(
'
self
'
))
{
flag
|=
EventModifierFlags
.
self
;
}
return
flag
;
}
const
NODE_TYPE_PAGE
=
0
;
const
NODE_TYPE_ELEMENT
=
1
;
const
NODE_TYPE_TEXT
=
3
;
const
NODE_TYPE_COMMENT
=
8
;
function
sibling
(
node
,
type
)
{
const
{
parentNode
}
=
node
;
if
(
!
parentNode
)
{
return
null
;
}
const
{
childNodes
}
=
parentNode
;
return
childNodes
[
childNodes
.
indexOf
(
node
)
+
(
type
===
'
n
'
?
1
:
-
1
)]
||
null
;
}
function
removeNode
(
node
)
{
const
{
parentNode
}
=
node
;
if
(
parentNode
)
{
const
{
childNodes
}
=
parentNode
;
const
index
=
childNodes
.
indexOf
(
node
);
if
(
index
>
-
1
)
{
node
.
parentNode
=
null
;
childNodes
.
splice
(
index
,
1
);
}
}
}
function
checkNodeId
(
node
)
{
if
(
!
node
.
nodeId
&&
node
.
pageNode
)
{
node
.
nodeId
=
node
.
pageNode
.
genId
();
}
}
// 为优化性能,各平台不使用proxy来实现node的操作拦截,而是直接通过pageNode定制
class
UniNode
extends
UniEventTarget
{
constructor
(
nodeType
,
nodeName
,
container
)
{
super
();
this
.
pageNode
=
null
;
this
.
parentNode
=
null
;
this
.
_text
=
null
;
if
(
container
)
{
const
{
pageNode
}
=
container
;
if
(
pageNode
)
{
this
.
pageNode
=
pageNode
;
this
.
nodeId
=
pageNode
.
genId
();
!
pageNode
.
isUnmounted
&&
pageNode
.
onCreate
(
this
,
nodeName
);
}
}
this
.
nodeType
=
nodeType
;
this
.
nodeName
=
nodeName
;
this
.
childNodes
=
[];
}
get
firstChild
()
{
return
this
.
childNodes
[
0
]
||
null
;
}
get
lastChild
()
{
const
{
childNodes
}
=
this
;
const
length
=
childNodes
.
length
;
return
length
?
childNodes
[
length
-
1
]
:
null
;
}
get
nextSibling
()
{
return
sibling
(
this
,
'
n
'
);
}
get
nodeValue
()
{
return
null
;
}
set
nodeValue
(
_val
)
{
}
get
textContent
()
{
return
this
.
_text
||
''
;
}
set
textContent
(
text
)
{
this
.
_text
=
text
;
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
this
.
pageNode
.
onTextContent
(
this
,
text
);
}
}
get
parentElement
()
{
const
{
parentNode
}
=
this
;
if
(
parentNode
&&
parentNode
.
nodeType
===
NODE_TYPE_ELEMENT
)
{
return
parentNode
;
}
return
null
;
}
get
previousSibling
()
{
return
sibling
(
this
,
'
p
'
);
}
appendChild
(
newChild
)
{
return
this
.
insertBefore
(
newChild
,
null
);
}
cloneNode
(
deep
)
{
const
cloned
=
shared
.
extend
(
Object
.
create
(
Object
.
getPrototypeOf
(
this
)),
this
);
const
{
attributes
}
=
cloned
;
if
(
attributes
)
{
cloned
.
attributes
=
shared
.
extend
({},
attributes
);
}
if
(
deep
)
{
cloned
.
childNodes
=
cloned
.
childNodes
.
map
((
childNode
)
=>
childNode
.
cloneNode
(
true
));
}
return
cloned
;
}
insertBefore
(
newChild
,
refChild
)
{
// 先从现在的父节点移除(注意:不能触发onRemoveChild,否则会生成先remove该 id,再 insert)
removeNode
(
newChild
);
newChild
.
pageNode
=
this
.
pageNode
;
newChild
.
parentNode
=
this
;
checkNodeId
(
newChild
);
const
{
childNodes
}
=
this
;
if
(
refChild
)
{
const
index
=
childNodes
.
indexOf
(
refChild
);
if
(
index
===
-
1
)
{
throw
new
DOMException
(
`Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.`
);
}
childNodes
.
splice
(
index
,
0
,
newChild
);
}
else
{
childNodes
.
push
(
newChild
);
}
return
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
?
this
.
pageNode
.
onInsertBefore
(
this
,
newChild
,
refChild
)
:
newChild
;
}
removeChild
(
oldChild
)
{
const
{
childNodes
}
=
this
;
const
index
=
childNodes
.
indexOf
(
oldChild
);
if
(
index
===
-
1
)
{
throw
new
DOMException
(
`Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.`
);
}
oldChild
.
parentNode
=
null
;
childNodes
.
splice
(
index
,
1
);
return
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
?
this
.
pageNode
.
onRemoveChild
(
oldChild
)
:
oldChild
;
}
}
const
ATTR_CLASS
=
'
class
'
;
const
ATTR_STYLE
=
'
style
'
;
const
ATTR_INNER_HTML
=
'
innerHTML
'
;
const
ATTR_TEXT_CONTENT
=
'
textContent
'
;
const
ATTR_V_SHOW
=
'
.vShow
'
;
const
ATTR_V_OWNER_ID
=
'
.vOwnerId
'
;
const
ATTR_V_RENDERJS
=
'
.vRenderjs
'
;
const
ATTR_CHANGE_PREFIX
=
'
change:
'
;
class
UniBaseNode
extends
UniNode
{
constructor
(
nodeType
,
nodeName
,
container
)
{
super
(
nodeType
,
nodeName
,
container
);
this
.
attributes
=
Object
.
create
(
null
);
this
.
style
=
null
;
this
.
vShow
=
null
;
this
.
_html
=
null
;
}
get
className
()
{
return
(
this
.
attributes
[
ATTR_CLASS
]
||
''
);
}
set
className
(
val
)
{
this
.
setAttribute
(
ATTR_CLASS
,
val
);
}
get
innerHTML
()
{
return
''
;
}
set
innerHTML
(
html
)
{
this
.
_html
=
html
;
}
addEventListener
(
type
,
listener
,
options
)
{
super
.
addEventListener
(
type
,
listener
,
options
);
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
if
(
listener
.
wxsEvent
)
{
this
.
pageNode
.
onAddWxsEvent
(
this
,
normalizeEventType
(
type
,
options
),
listener
.
wxsEvent
,
encodeModifier
(
listener
.
modifiers
||
[]));
}
else
{
this
.
pageNode
.
onAddEvent
(
this
,
normalizeEventType
(
type
,
options
),
encodeModifier
(
listener
.
modifiers
||
[]));
}
}
}
removeEventListener
(
type
,
callback
,
options
)
{
super
.
removeEventListener
(
type
,
callback
,
options
);
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
this
.
pageNode
.
onRemoveEvent
(
this
,
normalizeEventType
(
type
,
options
));
}
}
getAttribute
(
qualifiedName
)
{
if
(
qualifiedName
===
ATTR_STYLE
)
{
return
this
.
style
;
}
return
this
.
attributes
[
qualifiedName
];
}
removeAttribute
(
qualifiedName
)
{
if
(
qualifiedName
==
ATTR_STYLE
)
{
this
.
style
=
null
;
}
else
{
delete
this
.
attributes
[
qualifiedName
];
}
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
this
.
pageNode
.
onRemoveAttribute
(
this
,
qualifiedName
);
}
}
setAttribute
(
qualifiedName
,
value
)
{
if
(
qualifiedName
===
ATTR_STYLE
)
{
this
.
style
=
value
;
}
else
{
this
.
attributes
[
qualifiedName
]
=
value
;
}
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
this
.
pageNode
.
onSetAttribute
(
this
,
qualifiedName
,
value
);
}
}
toJSON
({
attr
,
normalize
,
}
=
{})
{
const
{
attributes
,
style
,
listeners
,
_text
}
=
this
;
const
res
=
{};
if
(
Object
.
keys
(
attributes
).
length
)
{
res
.
a
=
normalize
?
normalize
(
attributes
)
:
attributes
;
}
const
events
=
Object
.
keys
(
listeners
);
if
(
events
.
length
)
{
let
w
=
undefined
;
const
e
=
{};
events
.
forEach
((
name
)
=>
{
const
handlers
=
listeners
[
name
];
if
(
handlers
.
length
)
{
// 可能存在多个 handler 且不同 modifiers 吗?
const
{
wxsEvent
,
modifiers
}
=
handlers
[
0
];
const
modifier
=
encodeModifier
(
modifiers
||
[]);
if
(
!
wxsEvent
)
{
e
[
name
]
=
modifier
;
}
else
{
if
(
!
w
)
{
w
=
{};
}
w
[
name
]
=
[
normalize
?
normalize
(
wxsEvent
)
:
wxsEvent
,
modifier
];
}
}
});
res
.
e
=
normalize
?
normalize
(
e
,
false
)
:
e
;
if
(
w
)
{
res
.
w
=
normalize
?
normalize
(
w
,
false
)
:
w
;
}
}
if
(
style
!==
null
)
{
res
.
s
=
normalize
?
normalize
(
style
)
:
style
;
}
if
(
!
attr
)
{
res
.
i
=
this
.
nodeId
;
res
.
n
=
this
.
nodeName
;
}
if
(
_text
!==
null
)
{
res
.
t
=
normalize
?
normalize
(
_text
)
:
_text
;
}
return
res
;
}
}
class
UniCommentNode
extends
UniNode
{
constructor
(
text
,
container
)
{
super
(
NODE_TYPE_COMMENT
,
'
#comment
'
,
container
);
this
.
_text
=
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
text
:
''
;
}
toJSON
(
opts
=
{})
{
// 暂时不传递 text 到 view 层,没啥意义,节省点数据量
return
opts
.
attr
?
{}
:
{
i
:
this
.
nodeId
,
};
// return opts.attr
// ? { t: this._text as string }
// : {
// i: this.nodeId!,
// t: this._text as string,
// }
}
}
class
UniElement
extends
UniBaseNode
{
constructor
(
nodeName
,
container
)
{
super
(
NODE_TYPE_ELEMENT
,
nodeName
.
toUpperCase
(),
container
);
this
.
tagName
=
this
.
nodeName
;
}
}
class
UniInputElement
extends
UniElement
{
get
value
()
{
return
this
.
getAttribute
(
'
value
'
);
}
set
value
(
val
)
{
this
.
setAttribute
(
'
value
'
,
val
);
}
}
class
UniTextAreaElement
extends
UniInputElement
{
}
class
UniTextNode
extends
UniBaseNode
{
constructor
(
text
,
container
)
{
super
(
NODE_TYPE_TEXT
,
'
#text
'
,
container
);
this
.
_text
=
text
;
}
get
nodeValue
()
{
return
this
.
_text
||
''
;
}
set
nodeValue
(
text
)
{
this
.
_text
=
text
;
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
this
.
pageNode
.
onNodeValue
(
this
,
text
);
}
}
}
const
forcePatchProps
=
{
AD
:
[
'
data
'
],
'
AD-DRAW
'
:
[
'
data
'
],
'
LIVE-PLAYER
'
:
[
'
picture-in-picture-mode
'
],
MAP
:
[
'
markers
'
,
'
polyline
'
,
'
circles
'
,
'
controls
'
,
'
include-points
'
,
'
polygons
'
,
],
PICKER
:
[
'
range
'
,
'
value
'
],
'
PICKER-VIEW
'
:
[
'
value
'
],
'
RICH-TEXT
'
:
[
'
nodes
'
],
VIDEO
:
[
'
danmu-list
'
,
'
header
'
],
'
WEB-VIEW
'
:
[
'
webview-styles
'
],
};
const
forcePatchPropKeys
=
[
'
animation
'
];
const
forcePatchProp
=
(
el
,
key
)
=>
{
if
(
forcePatchPropKeys
.
indexOf
(
key
)
>
-
1
)
{
return
true
;
}
const
keys
=
forcePatchProps
[
el
.
nodeName
];
if
(
keys
&&
keys
.
indexOf
(
key
)
>
-
1
)
{
return
true
;
}
return
false
;
};
const
ACTION_TYPE_PAGE_CREATE
=
1
;
const
ACTION_TYPE_PAGE_CREATED
=
2
;
const
ACTION_TYPE_CREATE
=
3
;
const
ACTION_TYPE_INSERT
=
4
;
const
ACTION_TYPE_REMOVE
=
5
;
const
ACTION_TYPE_SET_ATTRIBUTE
=
6
;
const
ACTION_TYPE_REMOVE_ATTRIBUTE
=
7
;
const
ACTION_TYPE_ADD_EVENT
=
8
;
const
ACTION_TYPE_REMOVE_EVENT
=
9
;
const
ACTION_TYPE_SET_TEXT
=
10
;
const
ACTION_TYPE_ADD_WXS_EVENT
=
12
;
const
ACTION_TYPE_PAGE_SCROLL
=
15
;
const
ACTION_TYPE_EVENT
=
20
;
/**
* 需要手动传入 timer,主要是解决 App 平台的定制 timer
*/
function
debounce
(
fn
,
delay
,
{
clearTimeout
,
setTimeout
})
{
let
timeout
;
const
newFn
=
function
()
{
clearTimeout
(
timeout
);
const
timerFn
=
()
=>
fn
.
apply
(
this
,
arguments
);
timeout
=
setTimeout
(
timerFn
,
delay
);
};
newFn
.
cancel
=
function
()
{
clearTimeout
(
timeout
);
};
return
newFn
;
}
class
EventChannel
{
constructor
(
id
,
events
)
{
this
.
id
=
id
;
this
.
listener
=
{};
this
.
emitCache
=
[];
if
(
events
)
{
Object
.
keys
(
events
).
forEach
((
name
)
=>
{
this
.
on
(
name
,
events
[
name
]);
});
}
}
emit
(
eventName
,
...
args
)
{
const
fns
=
this
.
listener
[
eventName
];
if
(
!
fns
)
{
return
this
.
emitCache
.
push
({
eventName
,
args
,
});
}
fns
.
forEach
((
opt
)
=>
{
opt
.
fn
.
apply
(
opt
.
fn
,
args
);
});
this
.
listener
[
eventName
]
=
fns
.
filter
((
opt
)
=>
opt
.
type
!==
'
once
'
);
}
on
(
eventName
,
fn
)
{
this
.
_addListener
(
eventName
,
'
on
'
,
fn
);
this
.
_clearCache
(
eventName
);
}
once
(
eventName
,
fn
)
{
this
.
_addListener
(
eventName
,
'
once
'
,
fn
);
this
.
_clearCache
(
eventName
);
}
off
(
eventName
,
fn
)
{
const
fns
=
this
.
listener
[
eventName
];
if
(
!
fns
)
{
return
;
}
if
(
fn
)
{
for
(
let
i
=
0
;
i
<
fns
.
length
;)
{
if
(
fns
[
i
].
fn
===
fn
)
{
fns
.
splice
(
i
,
1
);
i
--
;
}
i
++
;
}
}
else
{
delete
this
.
listener
[
eventName
];
}
}
_clearCache
(
eventName
)
{
for
(
let
index
=
0
;
index
<
this
.
emitCache
.
length
;
index
++
)
{
const
cache
=
this
.
emitCache
[
index
];
const
_name
=
eventName
?
cache
.
eventName
===
eventName
?
eventName
:
null
:
cache
.
eventName
;
if
(
!
_name
)
continue
;
const
location
=
this
.
emit
.
apply
(
this
,
[
_name
,
...
cache
.
args
]);
if
(
typeof
location
===
'
number
'
)
{
this
.
emitCache
.
pop
();
continue
;
}
this
.
emitCache
.
splice
(
index
,
1
);
index
--
;
}
}
_addListener
(
eventName
,
type
,
fn
)
{
(
this
.
listener
[
eventName
]
||
(
this
.
listener
[
eventName
]
=
[])).
push
({
fn
,
type
,
});
}
}
const
PAGE_HOOKS
=
[
ON_INIT
,
ON_LOAD
,
ON_SHOW
,
ON_HIDE
,
ON_UNLOAD
,
ON_BACK_PRESS
,
ON_PAGE_SCROLL
,
ON_TAB_ITEM_TAP
,
ON_REACH_BOTTOM
,
ON_PULL_DOWN_REFRESH
,
ON_SHARE_TIMELINE
,
ON_SHARE_APP_MESSAGE
,
ON_ADD_TO_FAVORITES
,
ON_SAVE_EXIT_STATE
,
ON_NAVIGATION_BAR_BUTTON_TAP
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
,
];
const
PAGE_SYNC_HOOKS
=
[
ON_LOAD
,
ON_SHOW
];
function
isRootImmediateHook
(
name
)
{
return
PAGE_SYNC_HOOKS
.
indexOf
(
name
)
>
-
1
;
}
function
isRootHook
(
name
)
{
return
PAGE_HOOKS
.
indexOf
(
name
)
>
-
1
;
}
const
UniLifecycleHooks
=
[
ON_SHOW
,
ON_HIDE
,
ON_LAUNCH
,
ON_ERROR
,
ON_THEME_CHANGE
,
ON_PAGE_NOT_FOUND
,
ON_UNHANDLE_REJECTION
,
ON_INIT
,
ON_LOAD
,
ON_READY
,
ON_UNLOAD
,
ON_RESIZE
,
ON_BACK_PRESS
,
ON_PAGE_SCROLL
,
ON_TAB_ITEM_TAP
,
ON_REACH_BOTTOM
,
ON_PULL_DOWN_REFRESH
,
ON_SHARE_TIMELINE
,
ON_ADD_TO_FAVORITES
,
ON_SHARE_APP_MESSAGE
,
ON_SAVE_EXIT_STATE
,
ON_NAVIGATION_BAR_BUTTON_TAP
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
,
];
const
MINI_PROGRAM_PAGE_RUNTIME_HOOKS
=
/*#__PURE__*/
(()
=>
{
return
{
onPageScroll
:
1
,
onShareAppMessage
:
1
<<
1
,
onShareTimeline
:
1
<<
2
,
};
})();
function
isUniLifecycleHook
(
name
,
value
,
checkType
=
true
)
{
// 检查类型
if
(
checkType
&&
!
shared
.
isFunction
(
value
))
{
return
false
;
}
if
(
UniLifecycleHooks
.
indexOf
(
name
)
>
-
1
)
{
// 已预定义
return
true
;
}
else
if
(
name
.
indexOf
(
'
on
'
)
===
0
)
{
// 以 on 开头
return
true
;
}
return
false
;
}
let
vueApp
;
const
createVueAppHooks
=
[];
/**
* 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑
*/
function
onCreateVueApp
(
hook
)
{
// TODO 每个 nvue 页面都会触发
if
(
vueApp
)
{
return
hook
(
vueApp
);
}
createVueAppHooks
.
push
(
hook
);
}
function
invokeCreateVueAppHook
(
app
)
{
vueApp
=
app
;
createVueAppHooks
.
forEach
((
hook
)
=>
hook
(
app
));
}
const
invokeCreateErrorHandler
=
once
((
app
,
createErrorHandler
)
=>
{
if
(
shared
.
isFunction
(
app
.
_component
.
onError
))
{
return
createErrorHandler
(
app
);
}
});
const
E
=
function
()
{
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
};
E
.
prototype
=
{
on
:
function
(
name
,
callback
,
ctx
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
(
e
[
name
]
||
(
e
[
name
]
=
[])).
push
({
fn
:
callback
,
ctx
:
ctx
,
});
return
this
;
},
once
:
function
(
name
,
callback
,
ctx
)
{
var
self
=
this
;
function
listener
()
{
self
.
off
(
name
,
listener
);
callback
.
apply
(
ctx
,
arguments
);
}
listener
.
_
=
callback
;
return
this
.
on
(
name
,
listener
,
ctx
);
},
emit
:
function
(
name
)
{
var
data
=
[].
slice
.
call
(
arguments
,
1
);
var
evtArr
=
((
this
.
e
||
(
this
.
e
=
{}))[
name
]
||
[]).
slice
();
var
i
=
0
;
var
len
=
evtArr
.
length
;
for
(
i
;
i
<
len
;
i
++
)
{
evtArr
[
i
].
fn
.
apply
(
evtArr
[
i
].
ctx
,
data
);
}
return
this
;
},
off
:
function
(
name
,
callback
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
var
evts
=
e
[
name
];
var
liveEvents
=
[];
if
(
evts
&&
callback
)
{
for
(
var
i
=
0
,
len
=
evts
.
length
;
i
<
len
;
i
++
)
{
if
(
evts
[
i
].
fn
!==
callback
&&
evts
[
i
].
fn
.
_
!==
callback
)
liveEvents
.
push
(
evts
[
i
]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
liveEvents
.
length
?
(
e
[
name
]
=
liveEvents
)
:
delete
e
[
name
];
return
this
;
},
};
var
E$1
=
E
;
const
borderStyles
=
{
black
:
'
rgba(0,0,0,0.4)
'
,
white
:
'
rgba(255,255,255,0.4)
'
,
};
function
normalizeTabBarStyles
(
borderStyle
)
{
if
(
borderStyle
&&
borderStyle
in
borderStyles
)
{
return
borderStyles
[
borderStyle
];
}
return
borderStyle
;
}
function
normalizeTitleColor
(
titleColor
)
{
return
titleColor
===
'
black
'
?
'
#000000
'
:
'
#ffffff
'
;
}
function
normalizeStyles
(
pageStyle
,
themeConfig
=
{},
mode
=
'
light
'
)
{
const
modeStyle
=
themeConfig
[
mode
];
const
styles
=
{};
if
(
!
modeStyle
)
{
return
pageStyle
;
}
Object
.
keys
(
pageStyle
).
forEach
((
key
)
=>
{
let
styleItem
=
pageStyle
[
key
]
// Object Array String
;
styles
[
key
]
=
(()
=>
{
if
(
shared
.
isPlainObject
(
styleItem
))
{
return
normalizeStyles
(
styleItem
,
themeConfig
,
mode
);
}
else
if
(
shared
.
isArray
(
styleItem
))
{
return
styleItem
.
map
((
item
)
=>
shared
.
isPlainObject
(
item
)
?
normalizeStyles
(
item
,
themeConfig
,
mode
)
:
item
);
}
else
if
(
shared
.
isString
(
styleItem
)
&&
styleItem
.
startsWith
(
'
@
'
))
{
const
_key
=
styleItem
.
replace
(
'
@
'
,
''
);
let
_styleItem
=
modeStyle
[
_key
]
||
styleItem
;
switch
(
key
)
{
case
'
titleColor
'
:
_styleItem
=
normalizeTitleColor
(
_styleItem
);
break
;
case
'
borderStyle
'
:
_styleItem
=
normalizeTabBarStyles
(
_styleItem
);
break
;
}
return
_styleItem
;
}
return
styleItem
;
})();
});
return
styles
;
}
function
getEnvLocale
()
{
const
{
env
}
=
process
;
const
lang
=
env
.
LC_ALL
||
env
.
LC_MESSAGES
||
env
.
LANG
||
env
.
LANGUAGE
;
return
(
lang
&&
lang
.
replace
(
/
[
.:
]
.*/
,
''
))
||
'
en
'
;
}
exports
.
ACTION_TYPE_ADD_EVENT
=
ACTION_TYPE_ADD_EVENT
;
exports
.
ACTION_TYPE_ADD_WXS_EVENT
=
ACTION_TYPE_ADD_WXS_EVENT
;
exports
.
ACTION_TYPE_CREATE
=
ACTION_TYPE_CREATE
;
exports
.
ACTION_TYPE_EVENT
=
ACTION_TYPE_EVENT
;
exports
.
ACTION_TYPE_INSERT
=
ACTION_TYPE_INSERT
;
exports
.
ACTION_TYPE_PAGE_CREATE
=
ACTION_TYPE_PAGE_CREATE
;
exports
.
ACTION_TYPE_PAGE_CREATED
=
ACTION_TYPE_PAGE_CREATED
;
exports
.
ACTION_TYPE_PAGE_SCROLL
=
ACTION_TYPE_PAGE_SCROLL
;
exports
.
ACTION_TYPE_REMOVE
=
ACTION_TYPE_REMOVE
;
exports
.
ACTION_TYPE_REMOVE_ATTRIBUTE
=
ACTION_TYPE_REMOVE_ATTRIBUTE
;
exports
.
ACTION_TYPE_REMOVE_EVENT
=
ACTION_TYPE_REMOVE_EVENT
;
exports
.
ACTION_TYPE_SET_ATTRIBUTE
=
ACTION_TYPE_SET_ATTRIBUTE
;
exports
.
ACTION_TYPE_SET_TEXT
=
ACTION_TYPE_SET_TEXT
;
exports
.
ATTR_CHANGE_PREFIX
=
ATTR_CHANGE_PREFIX
;
exports
.
ATTR_CLASS
=
ATTR_CLASS
;
exports
.
ATTR_INNER_HTML
=
ATTR_INNER_HTML
;
exports
.
ATTR_STYLE
=
ATTR_STYLE
;
exports
.
ATTR_TEXT_CONTENT
=
ATTR_TEXT_CONTENT
;
exports
.
ATTR_V_OWNER_ID
=
ATTR_V_OWNER_ID
;
exports
.
ATTR_V_RENDERJS
=
ATTR_V_RENDERJS
;
exports
.
ATTR_V_SHOW
=
ATTR_V_SHOW
;
exports
.
BACKGROUND_COLOR
=
BACKGROUND_COLOR
;
exports
.
BUILT_IN_TAGS
=
BUILT_IN_TAGS
;
exports
.
BUILT_IN_TAG_NAMES
=
BUILT_IN_TAG_NAMES
;
exports
.
COMPONENT_NAME_PREFIX
=
COMPONENT_NAME_PREFIX
;
exports
.
COMPONENT_PREFIX
=
COMPONENT_PREFIX
;
exports
.
COMPONENT_SELECTOR_PREFIX
=
COMPONENT_SELECTOR_PREFIX
;
exports
.
DATA_RE
=
DATA_RE
;
exports
.
Emitter
=
E$1
;
exports
.
EventChannel
=
EventChannel
;
exports
.
EventModifierFlags
=
EventModifierFlags
;
exports
.
I18N_JSON_DELIMITERS
=
I18N_JSON_DELIMITERS
;
exports
.
JSON_PROTOCOL
=
JSON_PROTOCOL
;
exports
.
LINEFEED
=
LINEFEED
;
exports
.
MINI_PROGRAM_PAGE_RUNTIME_HOOKS
=
MINI_PROGRAM_PAGE_RUNTIME_HOOKS
;
exports
.
NAVBAR_HEIGHT
=
NAVBAR_HEIGHT
;
exports
.
NODE_TYPE_COMMENT
=
NODE_TYPE_COMMENT
;
exports
.
NODE_TYPE_ELEMENT
=
NODE_TYPE_ELEMENT
;
exports
.
NODE_TYPE_PAGE
=
NODE_TYPE_PAGE
;
exports
.
NODE_TYPE_TEXT
=
NODE_TYPE_TEXT
;
exports
.
NVUE_BUILT_IN_TAGS
=
NVUE_BUILT_IN_TAGS
;
exports
.
NVUE_U_BUILT_IN_TAGS
=
NVUE_U_BUILT_IN_TAGS
;
exports
.
OFF_THEME_CHANGE
=
OFF_THEME_CHANGE
;
exports
.
ON_ADD_TO_FAVORITES
=
ON_ADD_TO_FAVORITES
;
exports
.
ON_APP_ENTER_BACKGROUND
=
ON_APP_ENTER_BACKGROUND
;
exports
.
ON_APP_ENTER_FOREGROUND
=
ON_APP_ENTER_FOREGROUND
;
exports
.
ON_BACK_PRESS
=
ON_BACK_PRESS
;
exports
.
ON_ERROR
=
ON_ERROR
;
exports
.
ON_HIDE
=
ON_HIDE
;
exports
.
ON_INIT
=
ON_INIT
;
exports
.
ON_KEYBOARD_HEIGHT_CHANGE
=
ON_KEYBOARD_HEIGHT_CHANGE
;
exports
.
ON_LAUNCH
=
ON_LAUNCH
;
exports
.
ON_LOAD
=
ON_LOAD
;
exports
.
ON_NAVIGATION_BAR_BUTTON_TAP
=
ON_NAVIGATION_BAR_BUTTON_TAP
;
exports
.
ON_NAVIGATION_BAR_CHANGE
=
ON_NAVIGATION_BAR_CHANGE
;
exports
.
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
=
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
;
exports
.
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
=
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
;
exports
.
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
=
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
;
exports
.
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
=
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
;
exports
.
ON_PAGE_NOT_FOUND
=
ON_PAGE_NOT_FOUND
;
exports
.
ON_PAGE_SCROLL
=
ON_PAGE_SCROLL
;
exports
.
ON_PULL_DOWN_REFRESH
=
ON_PULL_DOWN_REFRESH
;
exports
.
ON_REACH_BOTTOM
=
ON_REACH_BOTTOM
;
exports
.
ON_REACH_BOTTOM_DISTANCE
=
ON_REACH_BOTTOM_DISTANCE
;
exports
.
ON_READY
=
ON_READY
;
exports
.
ON_RESIZE
=
ON_RESIZE
;
exports
.
ON_SAVE_EXIT_STATE
=
ON_SAVE_EXIT_STATE
;
exports
.
ON_SHARE_APP_MESSAGE
=
ON_SHARE_APP_MESSAGE
;
exports
.
ON_SHARE_TIMELINE
=
ON_SHARE_TIMELINE
;
exports
.
ON_SHOW
=
ON_SHOW
;
exports
.
ON_TAB_ITEM_TAP
=
ON_TAB_ITEM_TAP
;
exports
.
ON_THEME_CHANGE
=
ON_THEME_CHANGE
;
exports
.
ON_UNHANDLE_REJECTION
=
ON_UNHANDLE_REJECTION
;
exports
.
ON_UNLOAD
=
ON_UNLOAD
;
exports
.
ON_WEB_INVOKE_APP_SERVICE
=
ON_WEB_INVOKE_APP_SERVICE
;
exports
.
ON_WXS_INVOKE_CALL_METHOD
=
ON_WXS_INVOKE_CALL_METHOD
;
exports
.
PLUS_RE
=
PLUS_RE
;
exports
.
PRIMARY_COLOR
=
PRIMARY_COLOR
;
exports
.
RENDERJS_MODULES
=
RENDERJS_MODULES
;
exports
.
RESPONSIVE_MIN_WIDTH
=
RESPONSIVE_MIN_WIDTH
;
exports
.
SCHEME_RE
=
SCHEME_RE
;
exports
.
SELECTED_COLOR
=
SELECTED_COLOR
;
exports
.
SLOT_DEFAULT_NAME
=
SLOT_DEFAULT_NAME
;
exports
.
TABBAR_HEIGHT
=
TABBAR_HEIGHT
;
exports
.
TAGS
=
TAGS
;
exports
.
UNI_SSR
=
UNI_SSR
;
exports
.
UNI_SSR_DATA
=
UNI_SSR_DATA
;
exports
.
UNI_SSR_GLOBAL_DATA
=
UNI_SSR_GLOBAL_DATA
;
exports
.
UNI_SSR_STORE
=
UNI_SSR_STORE
;
exports
.
UNI_SSR_TITLE
=
UNI_SSR_TITLE
;
exports
.
UNI_STORAGE_LOCALE
=
UNI_STORAGE_LOCALE
;
exports
.
UVUE_BUILT_IN_TAGS
=
UVUE_BUILT_IN_TAGS
;
exports
.
UniBaseNode
=
UniBaseNode
;
exports
.
UniCommentNode
=
UniCommentNode
;
exports
.
UniElement
=
UniElement
;
exports
.
UniEvent
=
UniEvent
;
exports
.
UniInputElement
=
UniInputElement
;
exports
.
UniLifecycleHooks
=
UniLifecycleHooks
;
exports
.
UniNode
=
UniNode
;
exports
.
UniTextAreaElement
=
UniTextAreaElement
;
exports
.
UniTextNode
=
UniTextNode
;
exports
.
WEB_INVOKE_APPSERVICE
=
WEB_INVOKE_APPSERVICE
;
exports
.
WXS_MODULES
=
WXS_MODULES
;
exports
.
WXS_PROTOCOL
=
WXS_PROTOCOL
;
exports
.
addFont
=
addFont
;
exports
.
addLeadingSlash
=
addLeadingSlash
;
exports
.
borderStyles
=
borderStyles
;
exports
.
cache
=
cache
;
exports
.
cacheStringFunction
=
cacheStringFunction
;
exports
.
callOptions
=
callOptions
;
exports
.
createIsCustomElement
=
createIsCustomElement
;
exports
.
createRpx2Unit
=
createRpx2Unit
;
exports
.
createUniEvent
=
createUniEvent
;
exports
.
customizeEvent
=
customizeEvent
;
exports
.
debounce
=
debounce
;
exports
.
decode
=
decode
;
exports
.
decodedQuery
=
decodedQuery
;
exports
.
defaultMiniProgramRpx2Unit
=
defaultMiniProgramRpx2Unit
;
exports
.
defaultNVueRpx2Unit
=
defaultNVueRpx2Unit
;
exports
.
defaultRpx2Unit
=
defaultRpx2Unit
;
exports
.
dynamicSlotName
=
dynamicSlotName
;
exports
.
forcePatchProp
=
forcePatchProp
;
exports
.
formatDateTime
=
formatDateTime
;
exports
.
formatLog
=
formatLog
;
exports
.
getCustomDataset
=
getCustomDataset
;
exports
.
getEnvLocale
=
getEnvLocale
;
exports
.
getLen
=
getLen
;
exports
.
getValueByDataPath
=
getValueByDataPath
;
exports
.
initCustomDatasetOnce
=
initCustomDatasetOnce
;
exports
.
invokeArrayFns
=
invokeArrayFns
;
exports
.
invokeCreateErrorHandler
=
invokeCreateErrorHandler
;
exports
.
invokeCreateVueAppHook
=
invokeCreateVueAppHook
;
exports
.
isAppNVueNativeTag
=
isAppNVueNativeTag
;
exports
.
isAppNativeTag
=
isAppNativeTag
;
exports
.
isAppUVueNativeTag
=
isAppUVueNativeTag
;
exports
.
isBuiltInComponent
=
isBuiltInComponent
;
exports
.
isComponentInternalInstance
=
isComponentInternalInstance
;
exports
.
isComponentTag
=
isComponentTag
;
exports
.
isH5CustomElement
=
isH5CustomElement
;
exports
.
isH5NativeTag
=
isH5NativeTag
;
exports
.
isMiniProgramNativeTag
=
isMiniProgramNativeTag
;
exports
.
isRootHook
=
isRootHook
;
exports
.
isRootImmediateHook
=
isRootImmediateHook
;
exports
.
isUniLifecycleHook
=
isUniLifecycleHook
;
exports
.
normalizeDataset
=
normalizeDataset
;
exports
.
normalizeEventType
=
normalizeEventType
;
exports
.
normalizeStyles
=
normalizeStyles
;
exports
.
normalizeTabBarStyles
=
normalizeTabBarStyles
;
exports
.
normalizeTarget
=
normalizeTarget
;
exports
.
normalizeTitleColor
=
normalizeTitleColor
;
exports
.
onCreateVueApp
=
onCreateVueApp
;
exports
.
once
=
once
;
exports
.
parseEventName
=
parseEventName
;
exports
.
parseNVueDataset
=
parseNVueDataset
;
exports
.
parseQuery
=
parseQuery
;
exports
.
parseUrl
=
parseUrl
;
exports
.
passive
=
passive
;
exports
.
plusReady
=
plusReady
;
exports
.
removeLeadingSlash
=
removeLeadingSlash
;
exports
.
resolveComponentInstance
=
resolveComponentInstance
;
exports
.
resolveOwnerEl
=
resolveOwnerEl
;
exports
.
resolveOwnerVm
=
resolveOwnerVm
;
exports
.
sanitise
=
sanitise
;
exports
.
scrollTo
=
scrollTo
;
exports
.
sortObject
=
sortObject
;
exports
.
stringifyQuery
=
stringifyQuery
;
exports
.
updateElementStyle
=
updateElementStyle
;
packages/uni-shared/dist/uni-shared.d.ts
0 → 100644
浏览文件 @
58f3c3d6
import
type
{
App
}
from
'
vue
'
;
import
type
{
ComponentInternalInstance
}
from
'
@vue/runtime-core
'
;
import
{
ComponentOptionsBase
}
from
'
@vue/runtime-core
'
;
import
{
ComponentOptionsBase
as
ComponentOptionsBase_2
}
from
'
vue
'
;
import
type
{
ComponentPublicInstance
}
from
'
@vue/runtime-core
'
;
import
{
ComponentPublicInstance
as
ComponentPublicInstance_2
}
from
'
vue
'
;
import
{
createApp
}
from
'
vue
'
;
import
type
{
RendererNode
}
from
'
@vue/runtime-core
'
;
export
declare
const
ACTION_TYPE_ADD_EVENT
=
8
;
export
declare
const
ACTION_TYPE_ADD_WXS_EVENT
=
12
;
export
declare
const
ACTION_TYPE_CREATE
=
3
;
export
declare
const
ACTION_TYPE_EVENT
=
20
;
export
declare
const
ACTION_TYPE_INSERT
=
4
;
export
declare
const
ACTION_TYPE_PAGE_CREATE
=
1
;
export
declare
const
ACTION_TYPE_PAGE_CREATED
=
2
;
export
declare
const
ACTION_TYPE_PAGE_SCROLL
=
15
;
export
declare
const
ACTION_TYPE_REMOVE
=
5
;
export
declare
const
ACTION_TYPE_REMOVE_ATTRIBUTE
=
7
;
export
declare
const
ACTION_TYPE_REMOVE_EVENT
=
9
;
export
declare
const
ACTION_TYPE_SET_ATTRIBUTE
=
6
;
export
declare
const
ACTION_TYPE_SET_TEXT
=
10
;
/**
* nodeId
* event
* flag
*/
export
declare
type
AddEventAction
=
[
typeof
ACTION_TYPE_ADD_EVENT
,
number
,
string
|
number
,
number
];
export
declare
function
addFont
(
family
:
string
,
source
:
string
,
desc
?:
FontFaceDescriptors
):
Promise
<
void
>
;
export
declare
function
addLeadingSlash
(
str
:
string
):
string
;
/**
* nodeId
* event
* wxsEvent
* flag
*/
export
declare
type
AddWxsEventAction
=
[
typeof
ACTION_TYPE_ADD_WXS_EVENT
,
number
,
string
|
number
,
string
|
number
,
number
];
export
declare
const
ATTR_CHANGE_PREFIX
=
"
change:
"
;
export
declare
const
ATTR_CLASS
=
"
class
"
;
export
declare
const
ATTR_INNER_HTML
=
"
innerHTML
"
;
export
declare
const
ATTR_STYLE
=
"
style
"
;
export
declare
const
ATTR_TEXT_CONTENT
=
"
textContent
"
;
export
declare
const
ATTR_V_OWNER_ID
=
"
.vOwnerId
"
;
export
declare
const
ATTR_V_RENDERJS
=
"
.vRenderjs
"
;
export
declare
const
ATTR_V_SHOW
=
"
.vShow
"
;
export
declare
const
BACKGROUND_COLOR
=
"
#f7f7f7
"
;
export
declare
const
borderStyles
:
{
black
:
string
;
white
:
string
;
};
export
declare
const
BUILT_IN_TAG_NAMES
:
string
[];
export
declare
const
BUILT_IN_TAGS
:
string
[];
export
declare
function
cache
<
T
>
(
fn
:
(
str
:
string
)
=>
T
):
(
str
:
string
)
=>
T
;
export
declare
function
cacheStringFunction
(
fn
:
(
string
:
string
)
=>
string
):
(
str
:
string
)
=>
string
;
export
declare
function
callOptions
(
options
:
Options
,
errMsg
:
string
):
void
;
export
declare
function
callOptions
(
options
:
Options
,
data
:
{
[
key
:
string
]:
any
;
errMsg
:
string
;
}):
void
;
export
declare
const
COMPONENT_NAME_PREFIX
=
"
VUni
"
;
export
declare
const
COMPONENT_PREFIX
:
string
;
export
declare
const
COMPONENT_SELECTOR_PREFIX
=
"
uni-
"
;
/**
* nodeId
* tag
* parentNodeId
* refNodeId
* nodeJson
*/
export
declare
type
CreateAction
=
[
typeof
ACTION_TYPE_CREATE
,
number
,
string
|
number
,
number
,
number
,
Partial
<
UniNodeJSON
|
UniNodeJSONMinify
>
?
];
export
declare
function
createIsCustomElement
(
tags
?:
string
[]):
(
tag
:
string
)
=>
boolean
;
export
declare
function
createRpx2Unit
(
unit
:
string
,
unitRatio
:
number
,
unitPrecision
:
number
):
(
val
:
string
)
=>
string
;
export
declare
function
createUniEvent
(
evt
:
Record
<
string
,
any
>
):
UniEvent
;
declare
type
CreateVueAppHook
=
(
app
:
App
)
=>
void
;
export
declare
function
customizeEvent
(
str
:
string
):
string
;
export
declare
const
DATA_RE
:
RegExp
;
/**
* 需要手动传入 timer,主要是解决 App 平台的定制 timer
*/
export
declare
function
debounce
(
fn
:
Function
,
delay
:
number
,
{
clearTimeout
,
setTimeout
}:
Timer
):
{
(
this
:
any
):
void
;
cancel
():
void
;
};
/**
* Decode text using `decodeURIComponent`. Returns the original text if it
* fails.
*
* @param text - string to decode
* @returns decoded string
*/
export
declare
function
decode
(
text
:
string
|
number
):
string
;
export
declare
function
decodedQuery
(
query
?:
Record
<
string
,
any
>
):
Record
<
string
,
string
>
;
export
declare
const
defaultMiniProgramRpx2Unit
:
{
unit
:
string
;
unitRatio
:
number
;
unitPrecision
:
number
;
};
export
declare
const
defaultNVueRpx2Unit
:
{
unit
:
string
;
unitRatio
:
number
;
unitPrecision
:
number
;
};
export
declare
const
defaultRpx2Unit
:
{
unit
:
string
;
unitRatio
:
number
;
unitPrecision
:
number
;
};
declare
type
DictArray
=
[
number
,
number
][];
export
declare
function
dynamicSlotName
(
name
:
string
):
string
;
export
declare
interface
Emitter
{
e
:
Record
<
string
,
unknown
>
;
on
:
(
name
:
EventName
,
callback
:
EventCallback
,
ctx
?:
any
)
=>
this
;
once
:
(
name
:
EventName
,
callback
:
EventCallback
,
ctx
?:
any
)
=>
this
;
emit
:
(
name
:
EventName
,
...
args
:
any
[])
=>
this
;
off
:
(
name
:
EventName
,
callback
?:
EventCallback
)
=>
this
;
}
export
declare
const
Emitter
:
new
()
=>
Emitter
;
declare
type
EventCallback
=
Function
;
export
declare
class
EventChannel
{
id
?:
number
;
private
listener
;
private
emitCache
;
constructor
(
id
?:
number
,
events
?:
NavigateToOptionEvents
);
emit
(
eventName
:
string
,
...
args
:
any
[]):
number
|
undefined
;
on
(
eventName
:
string
,
fn
:
EventChannelListener
[
'
fn
'
]):
void
;
once
(
eventName
:
string
,
fn
:
EventChannelListener
[
'
fn
'
]):
void
;
off
(
eventName
:
string
,
fn
:
EventChannelListener
[
'
fn
'
]):
void
;
_clearCache
(
eventName
?:
string
):
void
;
_addListener
(
eventName
:
string
,
type
:
EventChannelListener
[
'
type
'
],
fn
:
EventChannelListener
[
'
fn
'
]):
void
;
}
declare
interface
EventChannelListener
{
type
:
'
on
'
|
'
once
'
;
fn
:
(...
args
:
any
[])
=>
void
;
}
export
declare
const
EventModifierFlags
:
{
stop
:
number
;
prevent
:
number
;
self
:
number
;
};
declare
type
EventName
=
string
;
export
declare
const
forcePatchProp
:
(
el
:
{
nodeName
:
string
;
},
key
:
string
)
=>
boolean
;
export
declare
function
formatDateTime
({
date
,
mode
}:
{
date
?:
Date
|
undefined
;
mode
?:
string
|
undefined
;
}):
string
;
export
declare
function
formatLog
(
module
:
string
,
...
args
:
any
[]):
string
;
export
declare
function
getCustomDataset
(
el
:
HTMLElement
|
HTMLElementWithDataset
):
DOMStringMap
&
Record
<
string
,
any
>
;
export
declare
function
getEnvLocale
():
string
;
export
declare
function
getLen
(
str
?:
string
):
number
;
export
declare
function
getValueByDataPath
(
obj
:
any
,
path
:
string
):
unknown
;
declare
interface
HTMLElementWithDataset
extends
HTMLElement
{
__uniDataset
?:
Record
<
string
,
any
>
;
}
export
declare
const
I18N_JSON_DELIMITERS
:
[
string
,
string
];
export
declare
const
initCustomDatasetOnce
:
()
=>
void
;
/**
* nodeId
* parentNodeId
* refNodeId
* nodeJson
*/
export
declare
type
InsertAction
=
[
typeof
ACTION_TYPE_INSERT
,
number
,
number
,
number
,
Partial
<
UniNodeJSON
|
UniNodeJSONMinify
>
?
];
export
declare
const
invokeArrayFns
:
(
fns
:
Function
[],
arg
?:
any
)
=>
any
;
export
declare
const
invokeCreateErrorHandler
:
(
app
:
App
,
createErrorHandler
:
(
app
:
App
)
=>
App
[
'
config
'
][
'
errorHandler
'
])
=>
((
err
:
unknown
,
instance
:
ComponentPublicInstance_2
<
{},
{},
{},
{},
{},
{},
{},
{},
false
,
ComponentOptionsBase_2
<
any
,
any
,
any
,
any
,
any
,
any
,
any
,
any
,
any
,
{},
{},
string
>
,
{}
>
|
null
,
info
:
string
)
=>
void
)
|
undefined
;
export
declare
function
invokeCreateVueAppHook
(
app
:
App
):
void
;
export
declare
function
isAppNativeTag
(
tag
:
string
):
boolean
;
export
declare
function
isAppNVueNativeTag
(
tag
:
string
):
boolean
;
export
declare
function
isAppUVueNativeTag
(
tag
:
string
):
boolean
;
export
declare
function
isBuiltInComponent
(
tag
:
string
):
boolean
;
export
declare
function
isComponentInternalInstance
(
vm
:
unknown
):
vm
is
ComponentInternalInstance
;
export
declare
function
isComponentTag
(
tag
:
string
):
boolean
;
export
declare
function
isH5CustomElement
(
tag
:
string
):
boolean
;
export
declare
function
isH5NativeTag
(
tag
:
string
):
boolean
;
export
declare
function
isMiniProgramNativeTag
(
tag
:
string
):
boolean
;
export
declare
function
isRootHook
(
name
:
string
):
boolean
;
export
declare
function
isRootImmediateHook
(
name
:
string
):
boolean
;
export
declare
function
isUniLifecycleHook
(
name
:
string
,
value
:
unknown
,
checkType
?:
boolean
):
boolean
;
export
declare
interface
IUniPageNode
{
pageId
:
number
;
pageNode
:
IUniPageNode
|
null
;
isUnmounted
:
boolean
;
genId
:
()
=>
number
;
push
:
(...
args
:
any
[])
=>
void
;
onCreate
:
(
thisNode
:
UniNode
,
nodeName
:
string
|
number
)
=>
UniNode
;
onInsertBefore
:
(
thisNode
:
UniNode
,
newChild
:
UniNode
,
refChild
:
UniNode
|
null
)
=>
UniNode
;
onRemoveChild
:
(
oldChild
:
UniNode
)
=>
UniNode
;
onAddEvent
:
(
thisNode
:
UniNode
,
name
:
string
,
flag
:
number
)
=>
void
;
onAddWxsEvent
:
(
thisNode
:
UniNode
,
name
:
string
,
wxsEvent
:
string
,
flag
:
number
)
=>
void
;
onRemoveEvent
:
(
thisNode
:
UniNode
,
name
:
string
)
=>
void
;
onSetAttribute
:
(
thisNode
:
UniNode
,
qualifiedName
:
string
,
value
:
unknown
)
=>
void
;
onRemoveAttribute
:
(
thisNode
:
UniNode
,
qualifiedName
:
string
)
=>
void
;
onTextContent
:
(
thisNode
:
UniNode
,
text
:
string
)
=>
void
;
onNodeValue
:
(
thisNode
:
UniNode
,
val
:
string
|
null
)
=>
void
;
}
export
declare
const
JSON_PROTOCOL
=
"
json://
"
;
export
declare
const
LINEFEED
=
"
\n
"
;
export
declare
const
MINI_PROGRAM_PAGE_RUNTIME_HOOKS
:
{
readonly
onPageScroll
:
1
;
readonly
onShareAppMessage
:
number
;
readonly
onShareTimeline
:
number
;
};
export
declare
const
NAVBAR_HEIGHT
=
44
;
declare
type
NavigateToOptionEvents
=
Record
<
string
,
(...
args
:
any
[])
=>
void
>
;
export
declare
const
NODE_TYPE_COMMENT
=
8
;
export
declare
const
NODE_TYPE_ELEMENT
=
1
;
export
declare
const
NODE_TYPE_PAGE
=
0
;
export
declare
const
NODE_TYPE_TEXT
=
3
;
export
declare
function
normalizeDataset
(
el
:
Element
):
any
;
export
declare
function
normalizeEventType
(
type
:
string
,
options
?:
AddEventListenerOptions
):
string
;
export
declare
function
normalizeStyles
<
T
extends
Object
>
(
pageStyle
:
T
,
themeConfig
?:
UniApp
.
ThemeJson
,
mode
?:
UniApp
.
ThemeMode
):
T
;
export
declare
function
normalizeTabBarStyles
(
borderStyle
?:
string
):
string
|
undefined
;
export
declare
function
normalizeTarget
(
el
:
HTMLElement
):
{
id
:
string
;
dataset
:
DOMStringMap
&
Record
<
string
,
any
>
;
offsetTop
:
number
;
offsetLeft
:
number
;
};
export
declare
function
normalizeTitleColor
(
titleColor
:
string
):
"
#000000
"
|
"
#ffffff
"
;
export
declare
interface
NVue
{
config
:
NVueConfigAPI
;
document
:
NVueDocument
;
requireModule
:
(
name
:
string
)
=>
Record
<
string
,
unknown
>
|
void
;
supports
:
(
condition
:
string
)
=>
boolean
|
void
;
isRegisteredModule
:
(
name
:
string
,
method
?:
string
)
=>
boolean
;
isRegisteredComponent
:
(
name
:
string
)
=>
boolean
;
}
export
declare
const
NVUE_BUILT_IN_TAGS
:
string
[];
export
declare
const
NVUE_U_BUILT_IN_TAGS
:
string
[];
export
declare
interface
NVueConfigAPI
{
bundleUrl
:
string
;
bundleType
:
string
;
env
:
NVueEnvironment
;
}
export
declare
interface
NVueDocument
{
id
:
string
;
URL
:
string
;
taskCenter
:
NVueTaskCenter
;
open
:
()
=>
void
;
close
:
()
=>
void
;
createElement
:
(
tagName
:
string
,
props
?:
Record
<
string
,
unknown
>
)
=>
NVueElement
;
createText
:
(
text
:
string
)
=>
Record
<
string
,
unknown
>
;
createComment
:
(
text
:
string
)
=>
Record
<
string
,
unknown
>
;
fireEvent
:
(
type
:
string
)
=>
void
;
destroy
:
()
=>
void
;
}
export
declare
interface
NVueElement
{
nodeType
:
number
;
nodeId
:
string
;
type
:
string
;
ref
:
string
;
text
?:
string
;
attr
:
Record
<
string
,
unknown
>
;
styleSheet
:
Record
<
string
,
Record
<
string
,
Record
<
string
,
unknown
>>>
;
classList
:
string
[];
parentNode
:
NVueElement
|
null
;
children
:
Array
<
NVueElement
>
;
previousSibling
:
NVueElement
|
null
;
nextSibling
:
NVueElement
|
null
;
appendChild
:
(
node
:
NVueElement
)
=>
void
;
removeChild
:
(
node
:
NVueElement
,
preserved
?:
boolean
)
=>
void
;
insertBefore
:
(
node
:
NVueElement
,
before
:
NVueElement
)
=>
void
;
insertAfter
:
(
node
:
NVueElement
,
after
:
NVueElement
)
=>
void
;
setAttr
:
(
key
:
string
,
value
:
any
,
silent
?:
boolean
)
=>
void
;
setAttrs
:
(
attrs
:
Record
<
string
,
unknown
>
,
silent
?:
boolean
)
=>
void
;
setClassList
:
(
classList
:
string
[])
=>
void
;
setStyle
:
(
key
:
string
,
value
:
any
,
silent
?:
boolean
)
=>
void
;
setStyles
:
(
attrs
:
Record
<
string
,
unknown
>
,
silent
?:
boolean
)
=>
void
;
setStyleSheet
:
(
styleSheet
:
Record
<
string
,
Record
<
string
,
Record
<
string
,
unknown
>>>
)
=>
void
;
addEvent
:
(
type
:
string
,
handler
:
Function
,
args
?:
Array
<
any
>
)
=>
void
;
removeEvent
:
(
type
:
string
)
=>
void
;
fireEvent
:
(
type
:
string
)
=>
void
;
destroy
:
()
=>
void
;
}
export
declare
interface
NVueEnvironment
{
platform
:
string
;
osName
:
string
;
osVersion
:
string
;
appName
:
string
;
appVersion
:
string
;
deviceModel
:
string
;
deviceWidth
:
number
;
deviceHeight
:
number
;
scale
:
number
;
userAgent
?:
string
;
dpr
?:
number
;
rem
?:
number
;
}
export
declare
interface
NVueInstanceContext
{
Vue
:
Vue_2
;
}
export
declare
interface
NVueInstanceOption
{
instanceId
:
string
;
config
:
NVueConfigAPI
;
document
?:
NVueDocument
;
Vue
?:
Vue_2
;
app
?:
ComponentPublicInstance_2
;
data
?:
Record
<
string
,
unknown
>
;
}
export
declare
interface
NVueRuntimeContext
{
nvue
:
NVue
;
service
:
Record
<
string
,
unknown
>
;
BroadcastChannel
?:
Function
;
SharedObject
:
Record
<
string
,
unknown
>
;
}
export
declare
interface
NVueTaskCenter
{
instanceId
:
string
;
callbackManager
:
unknown
;
send
:
(
type
:
string
,
params
:
Record
<
string
,
unknown
>
,
args
:
any
[],
options
?:
Record
<
string
,
unknown
>
)
=>
void
;
registerHook
:
(
componentId
:
string
,
type
:
string
,
hook
:
string
,
fn
:
Function
)
=>
void
;
updateData
:
(
componentId
:
string
,
data
:
Record
<
string
,
unknown
>
|
void
,
callback
?:
Function
)
=>
void
;
}
export
declare
const
OFF_THEME_CHANGE
=
"
offThemeChange
"
;
export
declare
const
ON_ADD_TO_FAVORITES
=
"
onAddToFavorites
"
;
export
declare
const
ON_APP_ENTER_BACKGROUND
=
"
onAppEnterBackground
"
;
export
declare
const
ON_APP_ENTER_FOREGROUND
=
"
onAppEnterForeground
"
;
export
declare
const
ON_BACK_PRESS
=
"
onBackPress
"
;
export
declare
const
ON_ERROR
=
"
onError
"
;
export
declare
const
ON_HIDE
=
"
onHide
"
;
export
declare
const
ON_INIT
=
"
onInit
"
;
export
declare
const
ON_KEYBOARD_HEIGHT_CHANGE
=
"
onKeyboardHeightChange
"
;
export
declare
const
ON_LAUNCH
=
"
onLaunch
"
;
export
declare
const
ON_LOAD
=
"
onLoad
"
;
export
declare
const
ON_NAVIGATION_BAR_BUTTON_TAP
=
"
onNavigationBarButtonTap
"
;
export
declare
const
ON_NAVIGATION_BAR_CHANGE
=
"
onNavigationBarChange
"
;
export
declare
const
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
=
"
onNavigationBarSearchInputChanged
"
;
export
declare
const
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
=
"
onNavigationBarSearchInputClicked
"
;
export
declare
const
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
=
"
onNavigationBarSearchInputConfirmed
"
;
export
declare
const
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
=
"
onNavigationBarSearchInputFocusChanged
"
;
export
declare
const
ON_PAGE_NOT_FOUND
=
"
onPageNotFound
"
;
export
declare
const
ON_PAGE_SCROLL
=
"
onPageScroll
"
;
export
declare
const
ON_PULL_DOWN_REFRESH
=
"
onPullDownRefresh
"
;
export
declare
const
ON_REACH_BOTTOM
=
"
onReachBottom
"
;
export
declare
const
ON_REACH_BOTTOM_DISTANCE
=
50
;
export
declare
const
ON_READY
=
"
onReady
"
;
export
declare
const
ON_RESIZE
=
"
onResize
"
;
export
declare
const
ON_SAVE_EXIT_STATE
=
"
onSaveExitState
"
;
export
declare
const
ON_SHARE_APP_MESSAGE
=
"
onShareAppMessage
"
;
export
declare
const
ON_SHARE_TIMELINE
=
"
onShareTimeline
"
;
export
declare
const
ON_SHOW
=
"
onShow
"
;
export
declare
const
ON_TAB_ITEM_TAP
=
"
onTabItemTap
"
;
export
declare
const
ON_THEME_CHANGE
=
"
onThemeChange
"
;
export
declare
const
ON_UNHANDLE_REJECTION
=
"
onUnhandledRejection
"
;
export
declare
const
ON_UNLOAD
=
"
onUnload
"
;
export
declare
const
ON_WEB_INVOKE_APP_SERVICE
=
"
onWebInvokeAppService
"
;
export
declare
const
ON_WXS_INVOKE_CALL_METHOD
=
"
onWxsInvokeCallMethod
"
;
export
declare
function
once
<
T
extends
(...
args
:
any
[])
=>
any
>
(
fn
:
T
,
ctx
?:
unknown
):
T
;
/**
* 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑
*/
export
declare
function
onCreateVueApp
(
hook
:
CreateVueAppHook
):
void
;
declare
interface
Options
{
success
?:
(
res
:
any
)
=>
void
;
fail
?:
(
res
:
any
)
=>
void
;
complete
?:
(
res
:
any
)
=>
void
;
}
export
declare
type
PageAction
=
PageCreateAction
|
PageCreatedAction
|
PageUpdateAction
|
PageScrollAction
;
export
declare
type
PageCreateAction
=
[
typeof
ACTION_TYPE_PAGE_CREATE
,
PageCreateData
];
export
declare
type
PageCreatedAction
=
[
typeof
ACTION_TYPE_PAGE_CREATED
];
export
declare
interface
PageCreateData
extends
PageNodeOptions
{
}
export
declare
interface
PageNodeOptions
{
css
:
boolean
;
route
:
string
;
version
:
number
;
locale
:
string
;
platform
:
string
;
pixelRatio
:
number
;
windowWidth
:
number
;
disableScroll
:
boolean
;
onPageScroll
:
boolean
;
onPageReachBottom
:
boolean
;
onReachBottomDistance
:
number
;
statusbarHeight
:
number
;
windowTop
:
number
;
windowBottom
:
number
;
}
/**
* onReachBottomDistance
*/
export
declare
type
PageScrollAction
=
[
typeof
ACTION_TYPE_PAGE_SCROLL
,
number
];
export
declare
type
PageUpdateAction
=
CreateAction
|
InsertAction
|
RemoveAction
|
AddEventAction
|
AddWxsEventAction
|
RemoveEventAction
|
SetAttributeAction
|
RemoveAttributeAction
|
SetTextAction
;
export
declare
function
parseEventName
(
name
:
string
):
[
string
,
EventListenerOptions
|
undefined
];
export
declare
function
parseNVueDataset
(
attr
?:
Record
<
string
,
unknown
>
):
Record
<
string
,
unknown
>
;
/**
* https://github.com/vuejs/vue-router-next/blob/master/src/query.ts
* @internal
*
* @param search - search string to parse
* @returns a query object
*/
export
declare
function
parseQuery
(
search
:
string
):
Record
<
string
,
any
>
;
export
declare
function
parseUrl
(
url
:
string
):
{
path
:
string
;
query
:
Record
<
string
,
any
>
;
};
export
declare
function
passive
(
passive
:
boolean
):
{
passive
:
boolean
;
};
export
declare
const
PLUS_RE
:
RegExp
;
export
declare
function
plusReady
(
callback
:
()
=>
void
):
void
;
export
declare
const
PRIMARY_COLOR
=
"
#007aff
"
;
/**
* nodeId
*/
export
declare
type
RemoveAction
=
[
typeof
ACTION_TYPE_REMOVE
,
number
];
/**
* nodeId
* name
*/
export
declare
type
RemoveAttributeAction
=
[
typeof
ACTION_TYPE_REMOVE_ATTRIBUTE
,
number
,
string
|
number
];
/**
* nodeId
* event
*/
export
declare
type
RemoveEventAction
=
[
typeof
ACTION_TYPE_REMOVE_EVENT
,
number
,
string
|
number
];
export
declare
function
removeLeadingSlash
(
str
:
string
):
string
;
export
declare
const
RENDERJS_MODULES
=
"
renderjsModules
"
;
export
declare
function
resolveComponentInstance
(
instance
?:
ComponentInternalInstance
|
ComponentPublicInstance
):
ComponentPublicInstance
|
undefined
;
export
declare
function
resolveOwnerEl
(
instance
:
ComponentInternalInstance
,
multi
:
true
):
RendererNode
[];
export
declare
function
resolveOwnerEl
(
instance
:
ComponentInternalInstance
):
RendererNode
|
null
;
export
declare
function
resolveOwnerVm
(
vm
:
ComponentInternalInstance
):
ComponentPublicInstance
<
{},
{},
{},
{},
{},
{},
{},
{},
false
,
ComponentOptionsBase
<
any
,
any
,
any
,
any
,
any
,
any
,
any
,
any
,
any
,
{},
{},
string
>
,
{}
>
|
undefined
;
export
declare
const
RESPONSIVE_MIN_WIDTH
=
768
;
export
declare
type
Rpx2UnitOptions
=
typeof
defaultRpx2Unit
;
export
declare
const
sanitise
:
(
val
:
unknown
)
=>
any
;
export
declare
const
SCHEME_RE
:
RegExp
;
declare
function
scrollTo_2
(
scrollTop
:
number
|
string
,
duration
:
number
,
isH5
?:
boolean
):
void
;
export
{
scrollTo_2
as
scrollTo
}
export
declare
const
SELECTED_COLOR
=
"
#0062cc
"
;
/**
* nodeId
* name
* value
*/
export
declare
type
SetAttributeAction
=
[
typeof
ACTION_TYPE_SET_ATTRIBUTE
,
number
,
string
|
number
,
unknown
|
number
];
/**
* nodeId
* text
*/
export
declare
type
SetTextAction
=
[
typeof
ACTION_TYPE_SET_TEXT
,
number
,
string
|
number
];
export
declare
const
SLOT_DEFAULT_NAME
=
"
d
"
;
export
declare
function
sortObject
<
T
extends
Object
>
(
obj
:
T
):
T
;
export
declare
function
stringifyQuery
(
obj
?:
Record
<
string
,
any
>
,
encodeStr
?:
typeof
encodeURIComponent
):
string
;
export
declare
const
TABBAR_HEIGHT
=
50
;
export
declare
const
TAGS
:
string
[];
declare
interface
Timer
{
setTimeout
:
Function
;
clearTimeout
:
Function
;
}
export
declare
const
UNI_SSR
=
"
__uniSSR
"
;
export
declare
const
UNI_SSR_DATA
=
"
data
"
;
export
declare
const
UNI_SSR_GLOBAL_DATA
=
"
globalData
"
;
export
declare
const
UNI_SSR_STORE
=
"
store
"
;
export
declare
const
UNI_SSR_TITLE
=
"
title
"
;
export
declare
const
UNI_STORAGE_LOCALE
=
"
UNI_LOCALE
"
;
export
declare
class
UniBaseNode
extends
UniNode
{
attributes
:
Record
<
string
,
unknown
>
;
style
:
null
|
string
|
Record
<
string
,
string
|
string
[]
>
;
vShow
:
null
|
boolean
;
protected
_html
:
string
|
null
;
constructor
(
nodeType
:
UniNodeType
,
nodeName
:
string
,
container
:
UniElement
|
IUniPageNode
);
get
className
():
string
;
set
className
(
val
:
string
);
get
innerHTML
():
string
;
set
innerHTML
(
html
:
string
);
addEventListener
(
type
:
string
,
listener
:
UniEventListener
,
options
?:
AddEventListenerOptions
):
void
;
removeEventListener
(
type
:
string
,
callback
:
UniEventListener
,
options
?:
EventListenerOptions
):
void
;
getAttribute
(
qualifiedName
:
string
):
unknown
;
removeAttribute
(
qualifiedName
:
string
):
void
;
setAttribute
(
qualifiedName
:
string
,
value
:
unknown
):
void
;
toJSON
({
attr
,
normalize
,
}?:
{
attr
?:
boolean
;
children
?:
boolean
;
normalize
?:
(
val
:
any
,
includeValue
?:
boolean
)
=>
any
|
number
;
}):
Partial
<
UniNodeJSON
>
;
}
export
declare
class
UniCommentNode
extends
UniNode
{
constructor
(
text
:
string
,
container
:
UniElement
|
IUniPageNode
);
toJSON
(
opts
?:
{
attr
?:
boolean
;
}):
{
i
?:
undefined
;
}
|
{
i
:
number
;
};
}
declare
type
UniCSSStyleDeclarationJSON
=
string
|
null
|
Record
<
string
,
string
|
string
[]
>
|
[
string
,
Record
<
string
,
string
|
string
[]
>
];
export
declare
class
UniElement
extends
UniBaseNode
{
tagName
:
string
;
constructor
(
nodeName
:
string
,
container
:
UniElement
|
IUniPageNode
);
}
export
declare
class
UniEvent
{
type
:
string
;
bubbles
:
boolean
;
cancelable
:
boolean
;
defaultPrevented
:
boolean
;
detail
?:
Record
<
string
,
any
>
;
timeStamp
:
number
;
_stop
:
boolean
;
_end
:
boolean
;
constructor
(
type
:
string
,
opts
:
UniEventOptions
);
preventDefault
():
void
;
stopImmediatePropagation
():
void
;
stopPropagation
():
void
;
}
export
declare
interface
UniEventListener
{
(
evt
:
UniEvent
):
void
;
modifiers
?:
string
[];
wxsEvent
?:
string
;
}
declare
interface
UniEventOptions
{
bubbles
:
boolean
;
cancelable
:
boolean
;
}
declare
class
UniEventTarget
{
listeners
:
Record
<
string
,
UniEventListener
[]
>
;
dispatchEvent
(
evt
:
UniEvent
):
boolean
;
addEventListener
(
type
:
string
,
listener
:
UniEventListener
,
options
?:
AddEventListenerOptions
):
void
;
removeEventListener
(
type
:
string
,
callback
:
UniEventListener
,
options
?:
AddEventListenerOptions
):
void
;
}
export
declare
class
UniInputElement
extends
UniElement
{
get
value
():
string
|
number
;
set
value
(
val
:
string
|
number
);
}
export
declare
const
UniLifecycleHooks
:
readonly
[
"
onShow
"
,
"
onHide
"
,
"
onLaunch
"
,
"
onError
"
,
"
onThemeChange
"
,
"
onPageNotFound
"
,
"
onUnhandledRejection
"
,
"
onInit
"
,
"
onLoad
"
,
"
onReady
"
,
"
onUnload
"
,
"
onResize
"
,
"
onBackPress
"
,
"
onPageScroll
"
,
"
onTabItemTap
"
,
"
onReachBottom
"
,
"
onPullDownRefresh
"
,
"
onShareTimeline
"
,
"
onAddToFavorites
"
,
"
onShareAppMessage
"
,
"
onSaveExitState
"
,
"
onNavigationBarButtonTap
"
,
"
onNavigationBarSearchInputClicked
"
,
"
onNavigationBarSearchInputChanged
"
,
"
onNavigationBarSearchInputConfirmed
"
,
"
onNavigationBarSearchInputFocusChanged
"
];
export
declare
class
UniNode
extends
UniEventTarget
{
nodeId
?:
number
;
nodeType
:
UniNodeType
;
nodeName
:
string
;
childNodes
:
UniNode
[];
pageNode
:
IUniPageNode
|
null
;
parentNode
:
UniNode
|
null
;
__vueParentComponent
?:
ComponentInternalInstance
;
protected
_text
:
string
|
null
;
constructor
(
nodeType
:
UniNodeType
,
nodeName
:
string
,
container
:
UniElement
|
IUniPageNode
);
get
firstChild
():
UniNode
|
null
;
get
lastChild
():
UniNode
|
null
;
get
nextSibling
():
UniNode
|
null
;
get
nodeValue
():
string
|
null
;
set
nodeValue
(
_val
:
string
|
null
);
get
textContent
():
string
;
set
textContent
(
text
:
string
);
get
parentElement
():
UniElement
|
null
;
get
previousSibling
():
UniNode
|
null
;
appendChild
(
newChild
:
UniNode
):
UniNode
;
cloneNode
(
deep
?:
boolean
):
UniNode
;
insertBefore
(
newChild
:
UniNode
,
refChild
:
UniNode
|
null
):
UniNode
;
removeChild
(
oldChild
:
UniNode
):
UniNode
;
}
export
declare
interface
UniNodeJSON
{
/**
* nodeId
*/
i
:
number
;
/**
* nodeName
*/
n
:
string
|
number
;
/**
* attributes
*/
a
:
Record
<
string
,
unknown
>
;
/**
* listeners
*/
e
:
Record
<
string
,
number
>
;
/**
* wxs listeners
*/
w
:
Record
<
string
,
[
string
,
number
]
>
;
/**
* style
*/
s
?:
UniCSSStyleDeclarationJSON
;
/**
* text
*/
t
?:
string
;
}
declare
interface
UniNodeJSONMinify
{
/**
* nodeId
*/
i
:
number
;
/**
* nodeName
*/
n
:
string
|
number
;
/**
* attributes
*/
a
:
DictArray
;
/**
* listeners
*/
e
:
DictArray
;
/**
* wxs listeners
*/
w
:
[
number
,
[
number
,
number
]][];
/**
* style
*/
s
?:
DictArray
;
/**
* text
*/
t
?:
number
;
}
declare
type
UniNodeType
=
typeof
NODE_TYPE_PAGE
|
typeof
NODE_TYPE_ELEMENT
|
typeof
NODE_TYPE_TEXT
|
typeof
NODE_TYPE_COMMENT
;
export
declare
class
UniTextAreaElement
extends
UniInputElement
{
}
export
declare
class
UniTextNode
extends
UniBaseNode
{
constructor
(
text
:
string
,
container
:
UniElement
|
IUniPageNode
);
get
nodeValue
():
string
;
set
nodeValue
(
text
:
string
);
}
export
declare
function
updateElementStyle
(
element
:
HTMLElement
,
styles
:
Partial
<
CSSStyleDeclaration
>
):
void
;
export
declare
const
UVUE_BUILT_IN_TAGS
:
string
[];
declare
interface
Vue_2
{
createApp
:
typeof
createApp
;
}
export
{
Vue_2
as
Vue
}
export
declare
const
WEB_INVOKE_APPSERVICE
=
"
WEB_INVOKE_APPSERVICE
"
;
export
declare
const
WXS_MODULES
=
"
wxsModules
"
;
export
declare
const
WXS_PROTOCOL
=
"
wxs://
"
;
export
{
}
packages/uni-shared/dist/uni-shared.es.js
0 → 100644
浏览文件 @
58f3c3d6
import
{
isHTMLTag
,
isSVGTag
,
hyphenate
,
camelize
,
isString
,
isFunction
,
isPlainObject
,
extend
,
isArray
,
capitalize
}
from
'
@vue/shared
'
;
const
BUILT_IN_TAG_NAMES
=
[
'
ad
'
,
'
ad-content-page
'
,
'
ad-draw
'
,
'
audio
'
,
'
button
'
,
'
camera
'
,
'
canvas
'
,
'
checkbox
'
,
'
checkbox-group
'
,
'
cover-image
'
,
'
cover-view
'
,
'
editor
'
,
'
form
'
,
'
functional-page-navigator
'
,
'
icon
'
,
'
image
'
,
'
input
'
,
'
label
'
,
'
live-player
'
,
'
live-pusher
'
,
'
map
'
,
'
movable-area
'
,
'
movable-view
'
,
'
navigator
'
,
'
official-account
'
,
'
open-data
'
,
'
picker
'
,
'
picker-view
'
,
'
picker-view-column
'
,
'
progress
'
,
'
radio
'
,
'
radio-group
'
,
'
rich-text
'
,
'
scroll-view
'
,
'
slider
'
,
'
swiper
'
,
'
swiper-item
'
,
'
switch
'
,
'
text
'
,
'
textarea
'
,
'
video
'
,
'
view
'
,
'
web-view
'
,
];
const
BUILT_IN_TAGS
=
BUILT_IN_TAG_NAMES
.
map
((
tag
)
=>
'
uni-
'
+
tag
);
const
TAGS
=
[
'
app
'
,
'
layout
'
,
'
content
'
,
'
main
'
,
'
top-window
'
,
'
left-window
'
,
'
right-window
'
,
'
tabbar
'
,
'
page
'
,
'
page-head
'
,
'
page-wrapper
'
,
'
page-body
'
,
'
page-refresh
'
,
'
actionsheet
'
,
'
modal
'
,
'
toast
'
,
'
resize-sensor
'
,
'
shadow-root
'
,
].
map
((
tag
)
=>
'
uni-
'
+
tag
);
const
NVUE_BUILT_IN_TAGS
=
[
'
svg
'
,
'
view
'
,
'
a
'
,
'
div
'
,
'
img
'
,
'
image
'
,
'
text
'
,
'
span
'
,
'
input
'
,
'
textarea
'
,
'
spinner
'
,
'
select
'
,
// slider 被自定义 u-slider 替代
// 'slider',
'
slider-neighbor
'
,
'
indicator
'
,
'
canvas
'
,
'
list
'
,
'
cell
'
,
'
header
'
,
'
loading
'
,
'
loading-indicator
'
,
'
refresh
'
,
'
scrollable
'
,
'
scroller
'
,
'
video
'
,
'
web
'
,
'
embed
'
,
'
tabbar
'
,
'
tabheader
'
,
'
datepicker
'
,
'
timepicker
'
,
'
marquee
'
,
'
countdown
'
,
'
dc-switch
'
,
'
waterfall
'
,
'
richtext
'
,
'
recycle-list
'
,
'
u-scalable
'
,
'
barcode
'
,
'
gcanvas
'
,
];
const
UVUE_BUILT_IN_TAGS
=
[
'
loading-indicator
'
,
'
list-view
'
,
'
list-item
'
,
'
swiper
'
,
'
swiper-item
'
,
'
rich-text
'
,
'
sticky-view
'
,
// 自定义
'
uni-slider
'
,
];
const
NVUE_U_BUILT_IN_TAGS
=
[
'
u-text
'
,
'
u-image
'
,
'
u-input
'
,
'
u-textarea
'
,
'
u-video
'
,
'
u-web-view
'
,
'
u-slider
'
,
'
u-ad
'
,
'
u-ad-draw
'
,
'
u-rich-text
'
,
];
function
isBuiltInComponent
(
tag
)
{
// h5 平台会被转换为 v-uni-
return
BUILT_IN_TAGS
.
indexOf
(
'
uni-
'
+
tag
.
replace
(
'
v-uni-
'
,
''
))
!==
-
1
;
}
function
isH5CustomElement
(
tag
)
{
return
TAGS
.
indexOf
(
tag
)
!==
-
1
||
BUILT_IN_TAGS
.
indexOf
(
tag
)
!==
-
1
;
}
function
isH5NativeTag
(
tag
)
{
return
(
tag
!==
'
head
'
&&
(
isHTMLTag
(
tag
)
||
isSVGTag
(
tag
))
&&
!
isBuiltInComponent
(
tag
));
}
function
isAppNativeTag
(
tag
)
{
return
isHTMLTag
(
tag
)
||
isSVGTag
(
tag
)
||
isBuiltInComponent
(
tag
);
}
const
NVUE_CUSTOM_COMPONENTS
=
[
'
ad
'
,
'
ad-draw
'
,
'
button
'
,
'
checkbox-group
'
,
'
checkbox
'
,
'
form
'
,
'
icon
'
,
'
label
'
,
'
movable-area
'
,
'
movable-view
'
,
'
navigator
'
,
'
picker
'
,
'
progress
'
,
'
radio-group
'
,
'
radio
'
,
'
rich-text
'
,
'
swiper-item
'
,
'
swiper
'
,
'
switch
'
,
'
slider
'
,
'
picker-view
'
,
'
picker-view-column
'
,
];
function
isAppUVueNativeTag
(
tag
)
{
if
(
UVUE_BUILT_IN_TAGS
.
includes
(
tag
))
{
return
true
;
}
if
(
NVUE_CUSTOM_COMPONENTS
.
includes
(
tag
))
{
return
false
;
}
if
(
isBuiltInComponent
(
tag
))
{
return
true
;
}
// u-text,u-video...
if
(
NVUE_U_BUILT_IN_TAGS
.
includes
(
tag
))
{
return
true
;
}
return
false
;
}
function
isAppNVueNativeTag
(
tag
)
{
if
(
NVUE_BUILT_IN_TAGS
.
includes
(
tag
))
{
return
true
;
}
if
(
NVUE_CUSTOM_COMPONENTS
.
includes
(
tag
))
{
return
false
;
}
if
(
isBuiltInComponent
(
tag
))
{
return
true
;
}
// u-text,u-video...
if
(
NVUE_U_BUILT_IN_TAGS
.
includes
(
tag
))
{
return
true
;
}
return
false
;
}
function
isMiniProgramNativeTag
(
tag
)
{
return
isBuiltInComponent
(
tag
);
}
function
createIsCustomElement
(
tags
=
[])
{
return
function
isCustomElement
(
tag
)
{
return
tags
.
includes
(
tag
);
};
}
function
isComponentTag
(
tag
)
{
return
tag
[
0
].
toLowerCase
()
+
tag
.
slice
(
1
)
===
'
component
'
;
}
const
COMPONENT_SELECTOR_PREFIX
=
'
uni-
'
;
const
COMPONENT_PREFIX
=
'
v-
'
+
COMPONENT_SELECTOR_PREFIX
;
const
LINEFEED
=
'
\n
'
;
const
NAVBAR_HEIGHT
=
44
;
const
TABBAR_HEIGHT
=
50
;
const
ON_REACH_BOTTOM_DISTANCE
=
50
;
const
RESPONSIVE_MIN_WIDTH
=
768
;
const
UNI_STORAGE_LOCALE
=
'
UNI_LOCALE
'
;
// quickapp-webview 不能使用 default 作为插槽名称
const
SLOT_DEFAULT_NAME
=
'
d
'
;
const
COMPONENT_NAME_PREFIX
=
'
VUni
'
;
const
I18N_JSON_DELIMITERS
=
[
'
%
'
,
'
%
'
];
const
PRIMARY_COLOR
=
'
#007aff
'
;
const
SELECTED_COLOR
=
'
#0062cc
'
;
// 选中的颜色,如选项卡默认的选中颜色
const
BACKGROUND_COLOR
=
'
#f7f7f7
'
;
// 背景色,如标题栏默认背景色
const
UNI_SSR
=
'
__uniSSR
'
;
const
UNI_SSR_TITLE
=
'
title
'
;
const
UNI_SSR_STORE
=
'
store
'
;
const
UNI_SSR_DATA
=
'
data
'
;
const
UNI_SSR_GLOBAL_DATA
=
'
globalData
'
;
const
SCHEME_RE
=
/^
([
a-z-
]
+:
)?\/\/
/i
;
const
DATA_RE
=
/^data:.*,.*/
;
const
WEB_INVOKE_APPSERVICE
=
'
WEB_INVOKE_APPSERVICE
'
;
const
WXS_PROTOCOL
=
'
wxs://
'
;
const
JSON_PROTOCOL
=
'
json://
'
;
const
WXS_MODULES
=
'
wxsModules
'
;
const
RENDERJS_MODULES
=
'
renderjsModules
'
;
// lifecycle
// App and Page
const
ON_SHOW
=
'
onShow
'
;
const
ON_HIDE
=
'
onHide
'
;
//App
const
ON_LAUNCH
=
'
onLaunch
'
;
const
ON_ERROR
=
'
onError
'
;
const
ON_THEME_CHANGE
=
'
onThemeChange
'
;
const
OFF_THEME_CHANGE
=
'
offThemeChange
'
;
const
ON_KEYBOARD_HEIGHT_CHANGE
=
'
onKeyboardHeightChange
'
;
const
ON_PAGE_NOT_FOUND
=
'
onPageNotFound
'
;
const
ON_UNHANDLE_REJECTION
=
'
onUnhandledRejection
'
;
//Page
const
ON_LOAD
=
'
onLoad
'
;
const
ON_READY
=
'
onReady
'
;
const
ON_UNLOAD
=
'
onUnload
'
;
// 百度特有
const
ON_INIT
=
'
onInit
'
;
// 微信特有
const
ON_SAVE_EXIT_STATE
=
'
onSaveExitState
'
;
const
ON_RESIZE
=
'
onResize
'
;
const
ON_BACK_PRESS
=
'
onBackPress
'
;
const
ON_PAGE_SCROLL
=
'
onPageScroll
'
;
const
ON_TAB_ITEM_TAP
=
'
onTabItemTap
'
;
const
ON_REACH_BOTTOM
=
'
onReachBottom
'
;
const
ON_PULL_DOWN_REFRESH
=
'
onPullDownRefresh
'
;
const
ON_SHARE_TIMELINE
=
'
onShareTimeline
'
;
const
ON_ADD_TO_FAVORITES
=
'
onAddToFavorites
'
;
const
ON_SHARE_APP_MESSAGE
=
'
onShareAppMessage
'
;
// navigationBar
const
ON_NAVIGATION_BAR_BUTTON_TAP
=
'
onNavigationBarButtonTap
'
;
const
ON_NAVIGATION_BAR_CHANGE
=
'
onNavigationBarChange
'
;
const
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
=
'
onNavigationBarSearchInputClicked
'
;
const
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
=
'
onNavigationBarSearchInputChanged
'
;
const
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
=
'
onNavigationBarSearchInputConfirmed
'
;
const
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
=
'
onNavigationBarSearchInputFocusChanged
'
;
// framework
const
ON_APP_ENTER_FOREGROUND
=
'
onAppEnterForeground
'
;
const
ON_APP_ENTER_BACKGROUND
=
'
onAppEnterBackground
'
;
const
ON_WEB_INVOKE_APP_SERVICE
=
'
onWebInvokeAppService
'
;
const
ON_WXS_INVOKE_CALL_METHOD
=
'
onWxsInvokeCallMethod
'
;
function
isComponentInternalInstance
(
vm
)
{
return
!!
vm
.
appContext
;
}
function
resolveComponentInstance
(
instance
)
{
return
(
instance
&&
(
isComponentInternalInstance
(
instance
)
?
instance
.
proxy
:
instance
));
}
function
resolveOwnerVm
(
vm
)
{
if
(
!
vm
)
{
return
;
}
let
componentName
=
vm
.
type
.
name
;
while
(
componentName
&&
isBuiltInComponent
(
hyphenate
(
componentName
)))
{
// ownerInstance 内置组件需要使用父 vm
vm
=
vm
.
parent
;
componentName
=
vm
.
type
.
name
;
}
return
vm
.
proxy
;
}
function
isElement
(
el
)
{
// Element
return
el
.
nodeType
===
1
;
}
function
resolveOwnerEl
(
instance
,
multi
=
false
)
{
const
{
vnode
}
=
instance
;
if
(
isElement
(
vnode
.
el
))
{
return
multi
?
(
vnode
.
el
?
[
vnode
.
el
]
:
[])
:
vnode
.
el
;
}
const
{
subTree
}
=
instance
;
// ShapeFlags.ARRAY_CHILDREN = 1<<4
if
(
subTree
.
shapeFlag
&
16
)
{
const
elemVNodes
=
subTree
.
children
.
filter
((
vnode
)
=>
vnode
.
el
&&
isElement
(
vnode
.
el
));
if
(
elemVNodes
.
length
>
0
)
{
if
(
multi
)
{
return
elemVNodes
.
map
((
node
)
=>
node
.
el
);
}
return
elemVNodes
[
0
].
el
;
}
}
return
multi
?
(
vnode
.
el
?
[
vnode
.
el
]
:
[])
:
vnode
.
el
;
}
function
dynamicSlotName
(
name
)
{
return
name
===
'
default
'
?
SLOT_DEFAULT_NAME
:
name
;
}
const
customizeRE
=
/:/g
;
function
customizeEvent
(
str
)
{
return
camelize
(
str
.
replace
(
customizeRE
,
'
-
'
));
}
let
lastLogTime
=
0
;
function
formatLog
(
module
,
...
args
)
{
const
now
=
Date
.
now
();
const
diff
=
lastLogTime
?
now
-
lastLogTime
:
0
;
lastLogTime
=
now
;
return
`[
${
now
}
][
${
diff
}
ms][
${
module
}
]:
${
args
.
map
((
arg
)
=>
JSON
.
stringify
(
arg
))
.
join
(
'
'
)}
`
;
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
function
cacheStringFunction
(
fn
)
{
return
cache
(
fn
);
}
function
getLen
(
str
=
''
)
{
return
(
''
+
str
).
replace
(
/
[^\x
00-
\x
ff
]
/g
,
'
**
'
).
length
;
}
function
hasLeadingSlash
(
str
)
{
return
str
.
indexOf
(
'
/
'
)
===
0
;
}
function
addLeadingSlash
(
str
)
{
return
hasLeadingSlash
(
str
)
?
str
:
'
/
'
+
str
;
}
function
removeLeadingSlash
(
str
)
{
return
hasLeadingSlash
(
str
)
?
str
.
slice
(
1
)
:
str
;
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
ret
=
fns
[
i
](
arg
);
}
return
ret
;
};
function
updateElementStyle
(
element
,
styles
)
{
for
(
const
attrName
in
styles
)
{
element
.
style
[
attrName
]
=
styles
[
attrName
];
}
}
function
once
(
fn
,
ctx
=
null
)
{
let
res
;
return
((...
args
)
=>
{
if
(
fn
)
{
res
=
fn
.
apply
(
ctx
,
args
);
fn
=
null
;
}
return
res
;
});
}
const
sanitise
=
(
val
)
=>
(
val
&&
JSON
.
parse
(
JSON
.
stringify
(
val
)))
||
val
;
const
_completeValue
=
(
value
)
=>
(
value
>
9
?
value
:
'
0
'
+
value
);
function
formatDateTime
({
date
=
new
Date
(),
mode
=
'
date
'
})
{
if
(
mode
===
'
time
'
)
{
return
(
_completeValue
(
date
.
getHours
())
+
'
:
'
+
_completeValue
(
date
.
getMinutes
()));
}
else
{
return
(
date
.
getFullYear
()
+
'
-
'
+
_completeValue
(
date
.
getMonth
()
+
1
)
+
'
-
'
+
_completeValue
(
date
.
getDate
()));
}
}
function
callOptions
(
options
,
data
)
{
options
=
options
||
{};
if
(
isString
(
data
))
{
data
=
{
errMsg
:
data
,
};
}
if
(
/:ok$/
.
test
(
data
.
errMsg
))
{
if
(
isFunction
(
options
.
success
))
{
options
.
success
(
data
);
}
}
else
{
if
(
isFunction
(
options
.
fail
))
{
options
.
fail
(
data
);
}
}
if
(
isFunction
(
options
.
complete
))
{
options
.
complete
(
data
);
}
}
function
getValueByDataPath
(
obj
,
path
)
{
if
(
!
isString
(
path
))
{
return
;
}
path
=
path
.
replace
(
/
\[(\d
+
)\]
/g
,
'
.$1
'
);
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getValueByDataPath
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
sortObject
(
obj
)
{
let
sortObj
=
{};
if
(
isPlainObject
(
obj
))
{
Object
.
keys
(
obj
)
.
sort
()
.
forEach
((
key
)
=>
{
const
_key
=
key
;
sortObj
[
_key
]
=
obj
[
_key
];
});
}
return
!
Object
.
keys
(
sortObj
)
?
obj
:
sortObj
;
}
function
formatKey
(
key
)
{
return
camelize
(
key
.
substring
(
5
));
}
// question/139181,增加副作用,避免 initCustomDataset 在 build 下被 tree-shaking
const
initCustomDatasetOnce
=
/*#__PURE__*/
once
(()
=>
{
const
prototype
=
HTMLElement
.
prototype
;
const
setAttribute
=
prototype
.
setAttribute
;
prototype
.
setAttribute
=
function
(
key
,
value
)
{
if
(
key
.
startsWith
(
'
data-
'
)
&&
this
.
tagName
.
startsWith
(
'
UNI-
'
))
{
const
dataset
=
this
.
__uniDataset
||
(
this
.
__uniDataset
=
{});
dataset
[
formatKey
(
key
)]
=
value
;
}
setAttribute
.
call
(
this
,
key
,
value
);
};
const
removeAttribute
=
prototype
.
removeAttribute
;
prototype
.
removeAttribute
=
function
(
key
)
{
if
(
this
.
__uniDataset
&&
key
.
startsWith
(
'
data-
'
)
&&
this
.
tagName
.
startsWith
(
'
UNI-
'
))
{
delete
this
.
__uniDataset
[
formatKey
(
key
)];
}
removeAttribute
.
call
(
this
,
key
);
};
});
function
getCustomDataset
(
el
)
{
return
extend
({},
el
.
dataset
,
el
.
__uniDataset
);
}
const
unitRE
=
new
RegExp
(
`"[^"]+"|'[^']+'|url\\([^)]+\\)|(\\d*\\.?\\d+)[r|u]px`
,
'
g
'
);
function
toFixed
(
number
,
precision
)
{
const
multiplier
=
Math
.
pow
(
10
,
precision
+
1
);
const
wholeNumber
=
Math
.
floor
(
number
*
multiplier
);
return
(
Math
.
round
(
wholeNumber
/
10
)
*
10
)
/
multiplier
;
}
const
defaultRpx2Unit
=
{
unit
:
'
rem
'
,
unitRatio
:
10
/
320
,
unitPrecision
:
5
,
};
const
defaultMiniProgramRpx2Unit
=
{
unit
:
'
rpx
'
,
unitRatio
:
1
,
unitPrecision
:
1
,
};
const
defaultNVueRpx2Unit
=
defaultMiniProgramRpx2Unit
;
function
createRpx2Unit
(
unit
,
unitRatio
,
unitPrecision
)
{
// ignore: rpxCalcIncludeWidth
return
(
val
)
=>
val
.
replace
(
unitRE
,
(
m
,
$1
)
=>
{
if
(
!
$1
)
{
return
m
;
}
if
(
unitRatio
===
1
)
{
return
`
${
$1
}${
unit
}
`
;
}
const
value
=
toFixed
(
parseFloat
(
$1
)
*
unitRatio
,
unitPrecision
);
return
value
===
0
?
'
0
'
:
`
${
value
}${
unit
}
`
;
});
}
function
passive
(
passive
)
{
return
{
passive
};
}
function
normalizeDataset
(
el
)
{
// TODO
return
JSON
.
parse
(
JSON
.
stringify
(
el
.
dataset
||
{}));
}
function
normalizeTarget
(
el
)
{
const
{
id
,
offsetTop
,
offsetLeft
}
=
el
;
return
{
id
,
dataset
:
getCustomDataset
(
el
),
offsetTop
,
offsetLeft
,
};
}
function
addFont
(
family
,
source
,
desc
)
{
const
fonts
=
document
.
fonts
;
if
(
fonts
)
{
const
fontFace
=
new
FontFace
(
family
,
source
,
desc
);
return
fontFace
.
load
().
then
(()
=>
{
fonts
.
add
&&
fonts
.
add
(
fontFace
);
});
}
return
new
Promise
((
resolve
)
=>
{
const
style
=
document
.
createElement
(
'
style
'
);
const
values
=
[];
if
(
desc
)
{
const
{
style
,
weight
,
stretch
,
unicodeRange
,
variant
,
featureSettings
}
=
desc
;
style
&&
values
.
push
(
`font-style:
${
style
}
`
);
weight
&&
values
.
push
(
`font-weight:
${
weight
}
`
);
stretch
&&
values
.
push
(
`font-stretch:
${
stretch
}
`
);
unicodeRange
&&
values
.
push
(
`unicode-range:
${
unicodeRange
}
`
);
variant
&&
values
.
push
(
`font-variant:
${
variant
}
`
);
featureSettings
&&
values
.
push
(
`font-feature-settings:
${
featureSettings
}
`
);
}
style
.
innerText
=
`@font-face{font-family:"
${
family
}
";src:
${
source
}
;
${
values
.
join
(
'
;
'
)}
}`
;
document
.
head
.
appendChild
(
style
);
resolve
();
});
}
function
scrollTo
(
scrollTop
,
duration
,
isH5
)
{
if
(
isString
(
scrollTop
))
{
const
el
=
document
.
querySelector
(
scrollTop
);
if
(
el
)
{
const
{
height
,
top
}
=
el
.
getBoundingClientRect
();
scrollTop
=
top
+
window
.
pageYOffset
;
if
(
isH5
)
{
scrollTop
-=
height
;
}
}
}
if
(
scrollTop
<
0
)
{
scrollTop
=
0
;
}
const
documentElement
=
document
.
documentElement
;
const
{
clientHeight
,
scrollHeight
}
=
documentElement
;
scrollTop
=
Math
.
min
(
scrollTop
,
scrollHeight
-
clientHeight
);
if
(
duration
===
0
)
{
// 部分浏览器(比如微信)中 scrollTop 的值需要通过 document.body 来控制
documentElement
.
scrollTop
=
document
.
body
.
scrollTop
=
scrollTop
;
return
;
}
if
(
window
.
scrollY
===
scrollTop
)
{
return
;
}
const
scrollTo
=
(
duration
)
=>
{
if
(
duration
<=
0
)
{
window
.
scrollTo
(
0
,
scrollTop
);
return
;
}
const
distaince
=
scrollTop
-
window
.
scrollY
;
requestAnimationFrame
(
function
()
{
window
.
scrollTo
(
0
,
window
.
scrollY
+
(
distaince
/
duration
)
*
10
);
scrollTo
(
duration
-
10
);
});
};
scrollTo
(
duration
);
}
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
const
res
=
obj
?
Object
.
keys
(
obj
)
.
map
((
key
)
=>
{
let
val
=
obj
[
key
];
if
(
typeof
val
===
undefined
||
val
===
null
)
{
val
=
''
;
}
else
if
(
isPlainObject
(
val
))
{
val
=
JSON
.
stringify
(
val
);
}
return
encodeStr
(
key
)
+
'
=
'
+
encodeStr
(
val
);
})
.
filter
((
x
)
=>
x
.
length
>
0
)
.
join
(
'
&
'
)
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
/**
* Decode text using `decodeURIComponent`. Returns the original text if it
* fails.
*
* @param text - string to decode
* @returns decoded string
*/
function
decode
(
text
)
{
try
{
return
decodeURIComponent
(
''
+
text
);
}
catch
(
err
)
{
}
return
''
+
text
;
}
function
decodedQuery
(
query
=
{})
{
const
decodedQuery
=
{};
Object
.
keys
(
query
).
forEach
((
name
)
=>
{
try
{
decodedQuery
[
name
]
=
decode
(
query
[
name
]);
}
catch
(
e
)
{
decodedQuery
[
name
]
=
query
[
name
];
}
});
return
decodedQuery
;
}
const
PLUS_RE
=
/
\+
/g
;
// %2B
/**
* https://github.com/vuejs/vue-router-next/blob/master/src/query.ts
* @internal
*
* @param search - search string to parse
* @returns a query object
*/
function
parseQuery
(
search
)
{
const
query
=
{};
// avoid creating an object with an empty key and empty value
// because of split('&')
if
(
search
===
''
||
search
===
'
?
'
)
return
query
;
const
hasLeadingIM
=
search
[
0
]
===
'
?
'
;
const
searchParams
=
(
hasLeadingIM
?
search
.
slice
(
1
)
:
search
).
split
(
'
&
'
);
for
(
let
i
=
0
;
i
<
searchParams
.
length
;
++
i
)
{
// pre decode the + into space
const
searchParam
=
searchParams
[
i
].
replace
(
PLUS_RE
,
'
'
);
// allow the = character
let
eqPos
=
searchParam
.
indexOf
(
'
=
'
);
let
key
=
decode
(
eqPos
<
0
?
searchParam
:
searchParam
.
slice
(
0
,
eqPos
));
let
value
=
eqPos
<
0
?
null
:
decode
(
searchParam
.
slice
(
eqPos
+
1
));
if
(
key
in
query
)
{
// an extra variable for ts types
let
currentValue
=
query
[
key
];
if
(
!
isArray
(
currentValue
))
{
currentValue
=
query
[
key
]
=
[
currentValue
];
}
currentValue
.
push
(
value
);
}
else
{
query
[
key
]
=
value
;
}
}
return
query
;
}
function
parseUrl
(
url
)
{
const
[
path
,
querystring
]
=
url
.
split
(
'
?
'
,
2
);
return
{
path
,
query
:
parseQuery
(
querystring
||
''
),
};
}
function
parseNVueDataset
(
attr
)
{
const
dataset
=
{};
if
(
attr
)
{
Object
.
keys
(
attr
).
forEach
((
key
)
=>
{
if
(
key
.
indexOf
(
'
data-
'
)
===
0
)
{
dataset
[
key
.
replace
(
'
data-
'
,
''
)]
=
attr
[
key
];
}
});
}
return
dataset
;
}
function
plusReady
(
callback
)
{
if
(
!
isFunction
(
callback
))
{
return
;
}
if
(
window
.
plus
)
{
return
callback
();
}
document
.
addEventListener
(
'
plusready
'
,
callback
);
}
class
DOMException
extends
Error
{
constructor
(
message
)
{
super
(
message
);
this
.
name
=
'
DOMException
'
;
}
}
function
normalizeEventType
(
type
,
options
)
{
if
(
options
)
{
if
(
options
.
capture
)
{
type
+=
'
Capture
'
;
}
if
(
options
.
once
)
{
type
+=
'
Once
'
;
}
if
(
options
.
passive
)
{
type
+=
'
Passive
'
;
}
}
return
`on
${
capitalize
(
camelize
(
type
))}
`
;
}
class
UniEvent
{
constructor
(
type
,
opts
)
{
this
.
defaultPrevented
=
false
;
this
.
timeStamp
=
Date
.
now
();
this
.
_stop
=
false
;
this
.
_end
=
false
;
this
.
type
=
type
;
this
.
bubbles
=
!!
opts
.
bubbles
;
this
.
cancelable
=
!!
opts
.
cancelable
;
}
preventDefault
()
{
this
.
defaultPrevented
=
true
;
}
stopImmediatePropagation
()
{
this
.
_end
=
this
.
_stop
=
true
;
}
stopPropagation
()
{
this
.
_stop
=
true
;
}
}
function
createUniEvent
(
evt
)
{
if
(
evt
instanceof
UniEvent
)
{
return
evt
;
}
const
[
type
]
=
parseEventName
(
evt
.
type
);
const
uniEvent
=
new
UniEvent
(
type
,
{
bubbles
:
false
,
cancelable
:
false
,
});
extend
(
uniEvent
,
evt
);
return
uniEvent
;
}
class
UniEventTarget
{
constructor
()
{
this
.
listeners
=
Object
.
create
(
null
);
}
dispatchEvent
(
evt
)
{
const
listeners
=
this
.
listeners
[
evt
.
type
];
if
(
!
listeners
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
))
{
console
.
error
(
formatLog
(
'
dispatchEvent
'
,
this
.
nodeId
),
evt
.
type
,
'
not found
'
);
}
return
false
;
}
// 格式化事件类型
const
event
=
createUniEvent
(
evt
);
const
len
=
listeners
.
length
;
for
(
let
i
=
0
;
i
<
len
;
i
++
)
{
listeners
[
i
].
call
(
this
,
event
);
if
(
event
.
_end
)
{
break
;
}
}
return
event
.
cancelable
&&
event
.
defaultPrevented
;
}
addEventListener
(
type
,
listener
,
options
)
{
type
=
normalizeEventType
(
type
,
options
);
(
this
.
listeners
[
type
]
||
(
this
.
listeners
[
type
]
=
[])).
push
(
listener
);
}
removeEventListener
(
type
,
callback
,
options
)
{
type
=
normalizeEventType
(
type
,
options
);
const
listeners
=
this
.
listeners
[
type
];
if
(
!
listeners
)
{
return
;
}
const
index
=
listeners
.
indexOf
(
callback
);
if
(
index
>
-
1
)
{
listeners
.
splice
(
index
,
1
);
}
}
}
const
optionsModifierRE
=
/
(?:
Once|Passive|Capture
)
$/
;
function
parseEventName
(
name
)
{
let
options
;
if
(
optionsModifierRE
.
test
(
name
))
{
options
=
{};
let
m
;
while
((
m
=
name
.
match
(
optionsModifierRE
)))
{
name
=
name
.
slice
(
0
,
name
.
length
-
m
[
0
].
length
);
options
[
m
[
0
].
toLowerCase
()]
=
true
;
}
}
return
[
hyphenate
(
name
.
slice
(
2
)),
options
];
}
const
EventModifierFlags
=
/*#__PURE__*/
(()
=>
{
return
{
stop
:
1
,
prevent
:
1
<<
1
,
self
:
1
<<
2
,
};
})();
function
encodeModifier
(
modifiers
)
{
let
flag
=
0
;
if
(
modifiers
.
includes
(
'
stop
'
))
{
flag
|=
EventModifierFlags
.
stop
;
}
if
(
modifiers
.
includes
(
'
prevent
'
))
{
flag
|=
EventModifierFlags
.
prevent
;
}
if
(
modifiers
.
includes
(
'
self
'
))
{
flag
|=
EventModifierFlags
.
self
;
}
return
flag
;
}
const
NODE_TYPE_PAGE
=
0
;
const
NODE_TYPE_ELEMENT
=
1
;
const
NODE_TYPE_TEXT
=
3
;
const
NODE_TYPE_COMMENT
=
8
;
function
sibling
(
node
,
type
)
{
const
{
parentNode
}
=
node
;
if
(
!
parentNode
)
{
return
null
;
}
const
{
childNodes
}
=
parentNode
;
return
childNodes
[
childNodes
.
indexOf
(
node
)
+
(
type
===
'
n
'
?
1
:
-
1
)]
||
null
;
}
function
removeNode
(
node
)
{
const
{
parentNode
}
=
node
;
if
(
parentNode
)
{
const
{
childNodes
}
=
parentNode
;
const
index
=
childNodes
.
indexOf
(
node
);
if
(
index
>
-
1
)
{
node
.
parentNode
=
null
;
childNodes
.
splice
(
index
,
1
);
}
}
}
function
checkNodeId
(
node
)
{
if
(
!
node
.
nodeId
&&
node
.
pageNode
)
{
node
.
nodeId
=
node
.
pageNode
.
genId
();
}
}
// 为优化性能,各平台不使用proxy来实现node的操作拦截,而是直接通过pageNode定制
class
UniNode
extends
UniEventTarget
{
constructor
(
nodeType
,
nodeName
,
container
)
{
super
();
this
.
pageNode
=
null
;
this
.
parentNode
=
null
;
this
.
_text
=
null
;
if
(
container
)
{
const
{
pageNode
}
=
container
;
if
(
pageNode
)
{
this
.
pageNode
=
pageNode
;
this
.
nodeId
=
pageNode
.
genId
();
!
pageNode
.
isUnmounted
&&
pageNode
.
onCreate
(
this
,
nodeName
);
}
}
this
.
nodeType
=
nodeType
;
this
.
nodeName
=
nodeName
;
this
.
childNodes
=
[];
}
get
firstChild
()
{
return
this
.
childNodes
[
0
]
||
null
;
}
get
lastChild
()
{
const
{
childNodes
}
=
this
;
const
length
=
childNodes
.
length
;
return
length
?
childNodes
[
length
-
1
]
:
null
;
}
get
nextSibling
()
{
return
sibling
(
this
,
'
n
'
);
}
get
nodeValue
()
{
return
null
;
}
set
nodeValue
(
_val
)
{
}
get
textContent
()
{
return
this
.
_text
||
''
;
}
set
textContent
(
text
)
{
this
.
_text
=
text
;
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
this
.
pageNode
.
onTextContent
(
this
,
text
);
}
}
get
parentElement
()
{
const
{
parentNode
}
=
this
;
if
(
parentNode
&&
parentNode
.
nodeType
===
NODE_TYPE_ELEMENT
)
{
return
parentNode
;
}
return
null
;
}
get
previousSibling
()
{
return
sibling
(
this
,
'
p
'
);
}
appendChild
(
newChild
)
{
return
this
.
insertBefore
(
newChild
,
null
);
}
cloneNode
(
deep
)
{
const
cloned
=
extend
(
Object
.
create
(
Object
.
getPrototypeOf
(
this
)),
this
);
const
{
attributes
}
=
cloned
;
if
(
attributes
)
{
cloned
.
attributes
=
extend
({},
attributes
);
}
if
(
deep
)
{
cloned
.
childNodes
=
cloned
.
childNodes
.
map
((
childNode
)
=>
childNode
.
cloneNode
(
true
));
}
return
cloned
;
}
insertBefore
(
newChild
,
refChild
)
{
// 先从现在的父节点移除(注意:不能触发onRemoveChild,否则会生成先remove该 id,再 insert)
removeNode
(
newChild
);
newChild
.
pageNode
=
this
.
pageNode
;
newChild
.
parentNode
=
this
;
checkNodeId
(
newChild
);
const
{
childNodes
}
=
this
;
if
(
refChild
)
{
const
index
=
childNodes
.
indexOf
(
refChild
);
if
(
index
===
-
1
)
{
throw
new
DOMException
(
`Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.`
);
}
childNodes
.
splice
(
index
,
0
,
newChild
);
}
else
{
childNodes
.
push
(
newChild
);
}
return
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
?
this
.
pageNode
.
onInsertBefore
(
this
,
newChild
,
refChild
)
:
newChild
;
}
removeChild
(
oldChild
)
{
const
{
childNodes
}
=
this
;
const
index
=
childNodes
.
indexOf
(
oldChild
);
if
(
index
===
-
1
)
{
throw
new
DOMException
(
`Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.`
);
}
oldChild
.
parentNode
=
null
;
childNodes
.
splice
(
index
,
1
);
return
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
?
this
.
pageNode
.
onRemoveChild
(
oldChild
)
:
oldChild
;
}
}
const
ATTR_CLASS
=
'
class
'
;
const
ATTR_STYLE
=
'
style
'
;
const
ATTR_INNER_HTML
=
'
innerHTML
'
;
const
ATTR_TEXT_CONTENT
=
'
textContent
'
;
const
ATTR_V_SHOW
=
'
.vShow
'
;
const
ATTR_V_OWNER_ID
=
'
.vOwnerId
'
;
const
ATTR_V_RENDERJS
=
'
.vRenderjs
'
;
const
ATTR_CHANGE_PREFIX
=
'
change:
'
;
class
UniBaseNode
extends
UniNode
{
constructor
(
nodeType
,
nodeName
,
container
)
{
super
(
nodeType
,
nodeName
,
container
);
this
.
attributes
=
Object
.
create
(
null
);
this
.
style
=
null
;
this
.
vShow
=
null
;
this
.
_html
=
null
;
}
get
className
()
{
return
(
this
.
attributes
[
ATTR_CLASS
]
||
''
);
}
set
className
(
val
)
{
this
.
setAttribute
(
ATTR_CLASS
,
val
);
}
get
innerHTML
()
{
return
''
;
}
set
innerHTML
(
html
)
{
this
.
_html
=
html
;
}
addEventListener
(
type
,
listener
,
options
)
{
super
.
addEventListener
(
type
,
listener
,
options
);
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
if
(
listener
.
wxsEvent
)
{
this
.
pageNode
.
onAddWxsEvent
(
this
,
normalizeEventType
(
type
,
options
),
listener
.
wxsEvent
,
encodeModifier
(
listener
.
modifiers
||
[]));
}
else
{
this
.
pageNode
.
onAddEvent
(
this
,
normalizeEventType
(
type
,
options
),
encodeModifier
(
listener
.
modifiers
||
[]));
}
}
}
removeEventListener
(
type
,
callback
,
options
)
{
super
.
removeEventListener
(
type
,
callback
,
options
);
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
this
.
pageNode
.
onRemoveEvent
(
this
,
normalizeEventType
(
type
,
options
));
}
}
getAttribute
(
qualifiedName
)
{
if
(
qualifiedName
===
ATTR_STYLE
)
{
return
this
.
style
;
}
return
this
.
attributes
[
qualifiedName
];
}
removeAttribute
(
qualifiedName
)
{
if
(
qualifiedName
==
ATTR_STYLE
)
{
this
.
style
=
null
;
}
else
{
delete
this
.
attributes
[
qualifiedName
];
}
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
this
.
pageNode
.
onRemoveAttribute
(
this
,
qualifiedName
);
}
}
setAttribute
(
qualifiedName
,
value
)
{
if
(
qualifiedName
===
ATTR_STYLE
)
{
this
.
style
=
value
;
}
else
{
this
.
attributes
[
qualifiedName
]
=
value
;
}
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
this
.
pageNode
.
onSetAttribute
(
this
,
qualifiedName
,
value
);
}
}
toJSON
({
attr
,
normalize
,
}
=
{})
{
const
{
attributes
,
style
,
listeners
,
_text
}
=
this
;
const
res
=
{};
if
(
Object
.
keys
(
attributes
).
length
)
{
res
.
a
=
normalize
?
normalize
(
attributes
)
:
attributes
;
}
const
events
=
Object
.
keys
(
listeners
);
if
(
events
.
length
)
{
let
w
=
undefined
;
const
e
=
{};
events
.
forEach
((
name
)
=>
{
const
handlers
=
listeners
[
name
];
if
(
handlers
.
length
)
{
// 可能存在多个 handler 且不同 modifiers 吗?
const
{
wxsEvent
,
modifiers
}
=
handlers
[
0
];
const
modifier
=
encodeModifier
(
modifiers
||
[]);
if
(
!
wxsEvent
)
{
e
[
name
]
=
modifier
;
}
else
{
if
(
!
w
)
{
w
=
{};
}
w
[
name
]
=
[
normalize
?
normalize
(
wxsEvent
)
:
wxsEvent
,
modifier
];
}
}
});
res
.
e
=
normalize
?
normalize
(
e
,
false
)
:
e
;
if
(
w
)
{
res
.
w
=
normalize
?
normalize
(
w
,
false
)
:
w
;
}
}
if
(
style
!==
null
)
{
res
.
s
=
normalize
?
normalize
(
style
)
:
style
;
}
if
(
!
attr
)
{
res
.
i
=
this
.
nodeId
;
res
.
n
=
this
.
nodeName
;
}
if
(
_text
!==
null
)
{
res
.
t
=
normalize
?
normalize
(
_text
)
:
_text
;
}
return
res
;
}
}
class
UniCommentNode
extends
UniNode
{
constructor
(
text
,
container
)
{
super
(
NODE_TYPE_COMMENT
,
'
#comment
'
,
container
);
this
.
_text
=
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
text
:
''
;
}
toJSON
(
opts
=
{})
{
// 暂时不传递 text 到 view 层,没啥意义,节省点数据量
return
opts
.
attr
?
{}
:
{
i
:
this
.
nodeId
,
};
// return opts.attr
// ? { t: this._text as string }
// : {
// i: this.nodeId!,
// t: this._text as string,
// }
}
}
class
UniElement
extends
UniBaseNode
{
constructor
(
nodeName
,
container
)
{
super
(
NODE_TYPE_ELEMENT
,
nodeName
.
toUpperCase
(),
container
);
this
.
tagName
=
this
.
nodeName
;
}
}
class
UniInputElement
extends
UniElement
{
get
value
()
{
return
this
.
getAttribute
(
'
value
'
);
}
set
value
(
val
)
{
this
.
setAttribute
(
'
value
'
,
val
);
}
}
class
UniTextAreaElement
extends
UniInputElement
{
}
class
UniTextNode
extends
UniBaseNode
{
constructor
(
text
,
container
)
{
super
(
NODE_TYPE_TEXT
,
'
#text
'
,
container
);
this
.
_text
=
text
;
}
get
nodeValue
()
{
return
this
.
_text
||
''
;
}
set
nodeValue
(
text
)
{
this
.
_text
=
text
;
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
this
.
pageNode
.
onNodeValue
(
this
,
text
);
}
}
}
const
forcePatchProps
=
{
AD
:
[
'
data
'
],
'
AD-DRAW
'
:
[
'
data
'
],
'
LIVE-PLAYER
'
:
[
'
picture-in-picture-mode
'
],
MAP
:
[
'
markers
'
,
'
polyline
'
,
'
circles
'
,
'
controls
'
,
'
include-points
'
,
'
polygons
'
,
],
PICKER
:
[
'
range
'
,
'
value
'
],
'
PICKER-VIEW
'
:
[
'
value
'
],
'
RICH-TEXT
'
:
[
'
nodes
'
],
VIDEO
:
[
'
danmu-list
'
,
'
header
'
],
'
WEB-VIEW
'
:
[
'
webview-styles
'
],
};
const
forcePatchPropKeys
=
[
'
animation
'
];
const
forcePatchProp
=
(
el
,
key
)
=>
{
if
(
forcePatchPropKeys
.
indexOf
(
key
)
>
-
1
)
{
return
true
;
}
const
keys
=
forcePatchProps
[
el
.
nodeName
];
if
(
keys
&&
keys
.
indexOf
(
key
)
>
-
1
)
{
return
true
;
}
return
false
;
};
const
ACTION_TYPE_PAGE_CREATE
=
1
;
const
ACTION_TYPE_PAGE_CREATED
=
2
;
const
ACTION_TYPE_CREATE
=
3
;
const
ACTION_TYPE_INSERT
=
4
;
const
ACTION_TYPE_REMOVE
=
5
;
const
ACTION_TYPE_SET_ATTRIBUTE
=
6
;
const
ACTION_TYPE_REMOVE_ATTRIBUTE
=
7
;
const
ACTION_TYPE_ADD_EVENT
=
8
;
const
ACTION_TYPE_REMOVE_EVENT
=
9
;
const
ACTION_TYPE_SET_TEXT
=
10
;
const
ACTION_TYPE_ADD_WXS_EVENT
=
12
;
const
ACTION_TYPE_PAGE_SCROLL
=
15
;
const
ACTION_TYPE_EVENT
=
20
;
/**
* 需要手动传入 timer,主要是解决 App 平台的定制 timer
*/
function
debounce
(
fn
,
delay
,
{
clearTimeout
,
setTimeout
})
{
let
timeout
;
const
newFn
=
function
()
{
clearTimeout
(
timeout
);
const
timerFn
=
()
=>
fn
.
apply
(
this
,
arguments
);
timeout
=
setTimeout
(
timerFn
,
delay
);
};
newFn
.
cancel
=
function
()
{
clearTimeout
(
timeout
);
};
return
newFn
;
}
class
EventChannel
{
constructor
(
id
,
events
)
{
this
.
id
=
id
;
this
.
listener
=
{};
this
.
emitCache
=
[];
if
(
events
)
{
Object
.
keys
(
events
).
forEach
((
name
)
=>
{
this
.
on
(
name
,
events
[
name
]);
});
}
}
emit
(
eventName
,
...
args
)
{
const
fns
=
this
.
listener
[
eventName
];
if
(
!
fns
)
{
return
this
.
emitCache
.
push
({
eventName
,
args
,
});
}
fns
.
forEach
((
opt
)
=>
{
opt
.
fn
.
apply
(
opt
.
fn
,
args
);
});
this
.
listener
[
eventName
]
=
fns
.
filter
((
opt
)
=>
opt
.
type
!==
'
once
'
);
}
on
(
eventName
,
fn
)
{
this
.
_addListener
(
eventName
,
'
on
'
,
fn
);
this
.
_clearCache
(
eventName
);
}
once
(
eventName
,
fn
)
{
this
.
_addListener
(
eventName
,
'
once
'
,
fn
);
this
.
_clearCache
(
eventName
);
}
off
(
eventName
,
fn
)
{
const
fns
=
this
.
listener
[
eventName
];
if
(
!
fns
)
{
return
;
}
if
(
fn
)
{
for
(
let
i
=
0
;
i
<
fns
.
length
;)
{
if
(
fns
[
i
].
fn
===
fn
)
{
fns
.
splice
(
i
,
1
);
i
--
;
}
i
++
;
}
}
else
{
delete
this
.
listener
[
eventName
];
}
}
_clearCache
(
eventName
)
{
for
(
let
index
=
0
;
index
<
this
.
emitCache
.
length
;
index
++
)
{
const
cache
=
this
.
emitCache
[
index
];
const
_name
=
eventName
?
cache
.
eventName
===
eventName
?
eventName
:
null
:
cache
.
eventName
;
if
(
!
_name
)
continue
;
const
location
=
this
.
emit
.
apply
(
this
,
[
_name
,
...
cache
.
args
]);
if
(
typeof
location
===
'
number
'
)
{
this
.
emitCache
.
pop
();
continue
;
}
this
.
emitCache
.
splice
(
index
,
1
);
index
--
;
}
}
_addListener
(
eventName
,
type
,
fn
)
{
(
this
.
listener
[
eventName
]
||
(
this
.
listener
[
eventName
]
=
[])).
push
({
fn
,
type
,
});
}
}
const
PAGE_HOOKS
=
[
ON_INIT
,
ON_LOAD
,
ON_SHOW
,
ON_HIDE
,
ON_UNLOAD
,
ON_BACK_PRESS
,
ON_PAGE_SCROLL
,
ON_TAB_ITEM_TAP
,
ON_REACH_BOTTOM
,
ON_PULL_DOWN_REFRESH
,
ON_SHARE_TIMELINE
,
ON_SHARE_APP_MESSAGE
,
ON_ADD_TO_FAVORITES
,
ON_SAVE_EXIT_STATE
,
ON_NAVIGATION_BAR_BUTTON_TAP
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
,
];
const
PAGE_SYNC_HOOKS
=
[
ON_LOAD
,
ON_SHOW
];
function
isRootImmediateHook
(
name
)
{
return
PAGE_SYNC_HOOKS
.
indexOf
(
name
)
>
-
1
;
}
function
isRootHook
(
name
)
{
return
PAGE_HOOKS
.
indexOf
(
name
)
>
-
1
;
}
const
UniLifecycleHooks
=
[
ON_SHOW
,
ON_HIDE
,
ON_LAUNCH
,
ON_ERROR
,
ON_THEME_CHANGE
,
ON_PAGE_NOT_FOUND
,
ON_UNHANDLE_REJECTION
,
ON_INIT
,
ON_LOAD
,
ON_READY
,
ON_UNLOAD
,
ON_RESIZE
,
ON_BACK_PRESS
,
ON_PAGE_SCROLL
,
ON_TAB_ITEM_TAP
,
ON_REACH_BOTTOM
,
ON_PULL_DOWN_REFRESH
,
ON_SHARE_TIMELINE
,
ON_ADD_TO_FAVORITES
,
ON_SHARE_APP_MESSAGE
,
ON_SAVE_EXIT_STATE
,
ON_NAVIGATION_BAR_BUTTON_TAP
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
,
];
const
MINI_PROGRAM_PAGE_RUNTIME_HOOKS
=
/*#__PURE__*/
(()
=>
{
return
{
onPageScroll
:
1
,
onShareAppMessage
:
1
<<
1
,
onShareTimeline
:
1
<<
2
,
};
})();
function
isUniLifecycleHook
(
name
,
value
,
checkType
=
true
)
{
// 检查类型
if
(
checkType
&&
!
isFunction
(
value
))
{
return
false
;
}
if
(
UniLifecycleHooks
.
indexOf
(
name
)
>
-
1
)
{
// 已预定义
return
true
;
}
else
if
(
name
.
indexOf
(
'
on
'
)
===
0
)
{
// 以 on 开头
return
true
;
}
return
false
;
}
let
vueApp
;
const
createVueAppHooks
=
[];
/**
* 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑
*/
function
onCreateVueApp
(
hook
)
{
// TODO 每个 nvue 页面都会触发
if
(
vueApp
)
{
return
hook
(
vueApp
);
}
createVueAppHooks
.
push
(
hook
);
}
function
invokeCreateVueAppHook
(
app
)
{
vueApp
=
app
;
createVueAppHooks
.
forEach
((
hook
)
=>
hook
(
app
));
}
const
invokeCreateErrorHandler
=
once
((
app
,
createErrorHandler
)
=>
{
if
(
isFunction
(
app
.
_component
.
onError
))
{
return
createErrorHandler
(
app
);
}
});
const
E
=
function
()
{
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
};
E
.
prototype
=
{
on
:
function
(
name
,
callback
,
ctx
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
(
e
[
name
]
||
(
e
[
name
]
=
[])).
push
({
fn
:
callback
,
ctx
:
ctx
,
});
return
this
;
},
once
:
function
(
name
,
callback
,
ctx
)
{
var
self
=
this
;
function
listener
()
{
self
.
off
(
name
,
listener
);
callback
.
apply
(
ctx
,
arguments
);
}
listener
.
_
=
callback
;
return
this
.
on
(
name
,
listener
,
ctx
);
},
emit
:
function
(
name
)
{
var
data
=
[].
slice
.
call
(
arguments
,
1
);
var
evtArr
=
((
this
.
e
||
(
this
.
e
=
{}))[
name
]
||
[]).
slice
();
var
i
=
0
;
var
len
=
evtArr
.
length
;
for
(
i
;
i
<
len
;
i
++
)
{
evtArr
[
i
].
fn
.
apply
(
evtArr
[
i
].
ctx
,
data
);
}
return
this
;
},
off
:
function
(
name
,
callback
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
var
evts
=
e
[
name
];
var
liveEvents
=
[];
if
(
evts
&&
callback
)
{
for
(
var
i
=
0
,
len
=
evts
.
length
;
i
<
len
;
i
++
)
{
if
(
evts
[
i
].
fn
!==
callback
&&
evts
[
i
].
fn
.
_
!==
callback
)
liveEvents
.
push
(
evts
[
i
]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
liveEvents
.
length
?
(
e
[
name
]
=
liveEvents
)
:
delete
e
[
name
];
return
this
;
},
};
var
E$1
=
E
;
const
borderStyles
=
{
black
:
'
rgba(0,0,0,0.4)
'
,
white
:
'
rgba(255,255,255,0.4)
'
,
};
function
normalizeTabBarStyles
(
borderStyle
)
{
if
(
borderStyle
&&
borderStyle
in
borderStyles
)
{
return
borderStyles
[
borderStyle
];
}
return
borderStyle
;
}
function
normalizeTitleColor
(
titleColor
)
{
return
titleColor
===
'
black
'
?
'
#000000
'
:
'
#ffffff
'
;
}
function
normalizeStyles
(
pageStyle
,
themeConfig
=
{},
mode
=
'
light
'
)
{
const
modeStyle
=
themeConfig
[
mode
];
const
styles
=
{};
if
(
!
modeStyle
)
{
return
pageStyle
;
}
Object
.
keys
(
pageStyle
).
forEach
((
key
)
=>
{
let
styleItem
=
pageStyle
[
key
]
// Object Array String
;
styles
[
key
]
=
(()
=>
{
if
(
isPlainObject
(
styleItem
))
{
return
normalizeStyles
(
styleItem
,
themeConfig
,
mode
);
}
else
if
(
isArray
(
styleItem
))
{
return
styleItem
.
map
((
item
)
=>
isPlainObject
(
item
)
?
normalizeStyles
(
item
,
themeConfig
,
mode
)
:
item
);
}
else
if
(
isString
(
styleItem
)
&&
styleItem
.
startsWith
(
'
@
'
))
{
const
_key
=
styleItem
.
replace
(
'
@
'
,
''
);
let
_styleItem
=
modeStyle
[
_key
]
||
styleItem
;
switch
(
key
)
{
case
'
titleColor
'
:
_styleItem
=
normalizeTitleColor
(
_styleItem
);
break
;
case
'
borderStyle
'
:
_styleItem
=
normalizeTabBarStyles
(
_styleItem
);
break
;
}
return
_styleItem
;
}
return
styleItem
;
})();
});
return
styles
;
}
function
getEnvLocale
()
{
const
{
env
}
=
process
;
const
lang
=
env
.
LC_ALL
||
env
.
LC_MESSAGES
||
env
.
LANG
||
env
.
LANGUAGE
;
return
(
lang
&&
lang
.
replace
(
/
[
.:
]
.*/
,
''
))
||
'
en
'
;
}
export
{
ACTION_TYPE_ADD_EVENT
,
ACTION_TYPE_ADD_WXS_EVENT
,
ACTION_TYPE_CREATE
,
ACTION_TYPE_EVENT
,
ACTION_TYPE_INSERT
,
ACTION_TYPE_PAGE_CREATE
,
ACTION_TYPE_PAGE_CREATED
,
ACTION_TYPE_PAGE_SCROLL
,
ACTION_TYPE_REMOVE
,
ACTION_TYPE_REMOVE_ATTRIBUTE
,
ACTION_TYPE_REMOVE_EVENT
,
ACTION_TYPE_SET_ATTRIBUTE
,
ACTION_TYPE_SET_TEXT
,
ATTR_CHANGE_PREFIX
,
ATTR_CLASS
,
ATTR_INNER_HTML
,
ATTR_STYLE
,
ATTR_TEXT_CONTENT
,
ATTR_V_OWNER_ID
,
ATTR_V_RENDERJS
,
ATTR_V_SHOW
,
BACKGROUND_COLOR
,
BUILT_IN_TAGS
,
BUILT_IN_TAG_NAMES
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
DATA_RE
,
E$1
as
Emitter
,
EventChannel
,
EventModifierFlags
,
I18N_JSON_DELIMITERS
,
JSON_PROTOCOL
,
LINEFEED
,
MINI_PROGRAM_PAGE_RUNTIME_HOOKS
,
NAVBAR_HEIGHT
,
NODE_TYPE_COMMENT
,
NODE_TYPE_ELEMENT
,
NODE_TYPE_PAGE
,
NODE_TYPE_TEXT
,
NVUE_BUILT_IN_TAGS
,
NVUE_U_BUILT_IN_TAGS
,
OFF_THEME_CHANGE
,
ON_ADD_TO_FAVORITES
,
ON_APP_ENTER_BACKGROUND
,
ON_APP_ENTER_FOREGROUND
,
ON_BACK_PRESS
,
ON_ERROR
,
ON_HIDE
,
ON_INIT
,
ON_KEYBOARD_HEIGHT_CHANGE
,
ON_LAUNCH
,
ON_LOAD
,
ON_NAVIGATION_BAR_BUTTON_TAP
,
ON_NAVIGATION_BAR_CHANGE
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
,
ON_PAGE_NOT_FOUND
,
ON_PAGE_SCROLL
,
ON_PULL_DOWN_REFRESH
,
ON_REACH_BOTTOM
,
ON_REACH_BOTTOM_DISTANCE
,
ON_READY
,
ON_RESIZE
,
ON_SAVE_EXIT_STATE
,
ON_SHARE_APP_MESSAGE
,
ON_SHARE_TIMELINE
,
ON_SHOW
,
ON_TAB_ITEM_TAP
,
ON_THEME_CHANGE
,
ON_UNHANDLE_REJECTION
,
ON_UNLOAD
,
ON_WEB_INVOKE_APP_SERVICE
,
ON_WXS_INVOKE_CALL_METHOD
,
PLUS_RE
,
PRIMARY_COLOR
,
RENDERJS_MODULES
,
RESPONSIVE_MIN_WIDTH
,
SCHEME_RE
,
SELECTED_COLOR
,
SLOT_DEFAULT_NAME
,
TABBAR_HEIGHT
,
TAGS
,
UNI_SSR
,
UNI_SSR_DATA
,
UNI_SSR_GLOBAL_DATA
,
UNI_SSR_STORE
,
UNI_SSR_TITLE
,
UNI_STORAGE_LOCALE
,
UVUE_BUILT_IN_TAGS
,
UniBaseNode
,
UniCommentNode
,
UniElement
,
UniEvent
,
UniInputElement
,
UniLifecycleHooks
,
UniNode
,
UniTextAreaElement
,
UniTextNode
,
WEB_INVOKE_APPSERVICE
,
WXS_MODULES
,
WXS_PROTOCOL
,
addFont
,
addLeadingSlash
,
borderStyles
,
cache
,
cacheStringFunction
,
callOptions
,
createIsCustomElement
,
createRpx2Unit
,
createUniEvent
,
customizeEvent
,
debounce
,
decode
,
decodedQuery
,
defaultMiniProgramRpx2Unit
,
defaultNVueRpx2Unit
,
defaultRpx2Unit
,
dynamicSlotName
,
forcePatchProp
,
formatDateTime
,
formatLog
,
getCustomDataset
,
getEnvLocale
,
getLen
,
getValueByDataPath
,
initCustomDatasetOnce
,
invokeArrayFns
,
invokeCreateErrorHandler
,
invokeCreateVueAppHook
,
isAppNVueNativeTag
,
isAppNativeTag
,
isAppUVueNativeTag
,
isBuiltInComponent
,
isComponentInternalInstance
,
isComponentTag
,
isH5CustomElement
,
isH5NativeTag
,
isMiniProgramNativeTag
,
isRootHook
,
isRootImmediateHook
,
isUniLifecycleHook
,
normalizeDataset
,
normalizeEventType
,
normalizeStyles
,
normalizeTabBarStyles
,
normalizeTarget
,
normalizeTitleColor
,
onCreateVueApp
,
once
,
parseEventName
,
parseNVueDataset
,
parseQuery
,
parseUrl
,
passive
,
plusReady
,
removeLeadingSlash
,
resolveComponentInstance
,
resolveOwnerEl
,
resolveOwnerVm
,
sanitise
,
scrollTo
,
sortObject
,
stringifyQuery
,
updateElementStyle
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录