@tarojs/plugin-platform-harmony-ets 4.0.0-beta.57 → 4.0.0-beta.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apis/device/clipboard.ts +6 -1
- package/dist/apis/ui/interaction/index.ts +1 -11
- package/dist/components-harmony-ets/index.ets +7 -0
- package/dist/components-harmony-ets/listView.ets +26 -0
- package/dist/components-harmony-ets/scrollList.ets +94 -0
- package/dist/components-harmony-ets/scrollView.ets +1 -1
- package/dist/components-harmony-ets/stickySection.ets +42 -0
- package/dist/components-harmony-ets/tag.ts +4 -0
- package/dist/runtime-ets/dom/cssNesting.ts +34 -16
- package/dist/runtime-ets/dom/element/index.ts +1 -0
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +86 -9
- package/dist/runtime-utils.d.ts +1 -1
- package/dist/runtime-utils.js +7 -12
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.js +7 -12
- package/dist/runtime.js.map +1 -1
- package/package.json +9 -9
|
@@ -40,7 +40,12 @@ export const setClipboardData: typeof Taro.setClipboardData = function (options)
|
|
|
40
40
|
callAsyncFail(reject, res, options)
|
|
41
41
|
} else {
|
|
42
42
|
|
|
43
|
-
promptAction.showToast({
|
|
43
|
+
promptAction.showToast({
|
|
44
|
+
message: '内容已复制',
|
|
45
|
+
duration: 1500,
|
|
46
|
+
bottom: '50%',
|
|
47
|
+
showMode: 1 // 设置弹窗显示模式,显示在应用之上。
|
|
48
|
+
})
|
|
44
49
|
|
|
45
50
|
return handle.success({
|
|
46
51
|
data,
|
|
@@ -33,7 +33,6 @@ export function showToast (options) {
|
|
|
33
33
|
message: options.title,
|
|
34
34
|
duration: options.duration,
|
|
35
35
|
bottom: options.bottom,
|
|
36
|
-
// @ts-ignore
|
|
37
36
|
showMode: 1 // 设置弹窗显示模式,显示在应用之上。
|
|
38
37
|
})
|
|
39
38
|
callAsyncSuccess(resolve, resCallback('showToast'), options)
|
|
@@ -173,16 +172,7 @@ export function showActionSheet (options) {
|
|
|
173
172
|
})
|
|
174
173
|
}
|
|
175
174
|
|
|
176
|
-
export
|
|
177
|
-
return new Promise(resolve => {
|
|
178
|
-
promptAction.showToast({
|
|
179
|
-
message: '关闭中',
|
|
180
|
-
duration: 10,
|
|
181
|
-
bottom: '9999px'
|
|
182
|
-
})
|
|
183
|
-
callAsyncSuccess(resolve, resCallback('hideToast'), options)
|
|
184
|
-
})
|
|
185
|
-
}
|
|
175
|
+
export const hideToast = /* @__PURE__ */ temporarilyNotSupport('hideToast')
|
|
186
176
|
|
|
187
177
|
export const showLoading = temporarilyNotSupport('showLoading')
|
|
188
178
|
export const hideLoading = temporarilyNotSupport('hideLoading')
|
|
@@ -25,6 +25,10 @@ import { TaroCheckboxGroup, TaroCheckbox } from './checkbox'
|
|
|
25
25
|
import TaroPageMeta from './pageMeta'
|
|
26
26
|
import TaroNavigationBar from './navigationBar'
|
|
27
27
|
|
|
28
|
+
import TaroListView from './listView'
|
|
29
|
+
import TaroStickySection from './stickySection'
|
|
30
|
+
import TaroScrollList from './scrollList'
|
|
31
|
+
|
|
28
32
|
import commonStyleModify, { rowModify, columnModify, textModify, setNormalTextAttributeIntoInstance } from './style'
|
|
29
33
|
import { getButtonColor } from './button'
|
|
30
34
|
import { FlexManager } from './utils/flexManager'
|
|
@@ -82,4 +86,7 @@ export {
|
|
|
82
86
|
TaroCheckbox,
|
|
83
87
|
TaroPageMeta,
|
|
84
88
|
TaroNavigationBar,
|
|
89
|
+
TaroListView,
|
|
90
|
+
TaroStickySection,
|
|
91
|
+
TaroScrollList
|
|
85
92
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import commonStyleModify from './style'
|
|
2
|
+
|
|
3
|
+
import type { TaroViewElement, TaroAny } from '@tarojs/runtime'
|
|
4
|
+
|
|
5
|
+
@Component
|
|
6
|
+
export default struct TaroListView {
|
|
7
|
+
@Builder customBuilder() {}
|
|
8
|
+
@BuilderParam createLazyChildren: (node: TaroViewElement) => void = this.customBuilder
|
|
9
|
+
@ObjectLink node: TaroViewElement
|
|
10
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
11
|
+
|
|
12
|
+
aboutToAppear(): void {
|
|
13
|
+
if (this.node) {
|
|
14
|
+
this.node._instance = this
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
build() {
|
|
19
|
+
ListItem() {
|
|
20
|
+
Stack() {
|
|
21
|
+
this.createLazyChildren(this.node)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import commonStyleModify from './style'
|
|
4
|
+
import { TOUCH_EVENT_MAP } from './utils/constant/event'
|
|
5
|
+
import { getNodeThresholds, shouldBindEvent } from './utils/helper'
|
|
6
|
+
|
|
7
|
+
import type { TaroScrollViewElement, TaroAny, TaroEvent } from '@tarojs/runtime'
|
|
8
|
+
|
|
9
|
+
interface ScrollViewAttrs {
|
|
10
|
+
scrollBar: BarState
|
|
11
|
+
}
|
|
12
|
+
interface ScrollViewCurrentOffset {
|
|
13
|
+
xOffset: number
|
|
14
|
+
yOffset: number
|
|
15
|
+
}
|
|
16
|
+
interface ScrollViewEvent {
|
|
17
|
+
deltaX: number
|
|
18
|
+
deltaY: number
|
|
19
|
+
scrollLeft: number
|
|
20
|
+
scrollTop: number
|
|
21
|
+
scrollWidth: number
|
|
22
|
+
scrollHeight: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getAttributes (node: TaroScrollViewElement): ScrollViewAttrs {
|
|
26
|
+
const _attrs = node._attrs
|
|
27
|
+
const scrollAttrs: ScrollViewAttrs = {
|
|
28
|
+
scrollBar: typeof _attrs.showScrollbar === 'boolean'
|
|
29
|
+
? _attrs.showScrollbar ? BarState.On : BarState.Off
|
|
30
|
+
: BarState.Auto
|
|
31
|
+
}
|
|
32
|
+
return scrollAttrs
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function handleScrollEvent (node: TaroScrollViewElement, eventName = 'scroll', scrollOffset?: number) {
|
|
36
|
+
const currentOffset = node.scroller.currentOffset() as ScrollViewCurrentOffset
|
|
37
|
+
const currentXOffset = currentOffset?.xOffset || 0
|
|
38
|
+
const currentYOffset = currentOffset?.yOffset || 0
|
|
39
|
+
const value: ScrollViewEvent = {
|
|
40
|
+
deltaX: vp2px(node._attrs.scrollX ? scrollOffset : 0),
|
|
41
|
+
deltaY: vp2px(node._attrs.scrollX ? 0 : scrollOffset),
|
|
42
|
+
scrollLeft: vp2px(currentXOffset),
|
|
43
|
+
scrollTop: vp2px(currentYOffset),
|
|
44
|
+
scrollWidth: vp2px(Number(node._nodeInfo?._scroll?.width)),
|
|
45
|
+
scrollHeight: vp2px(Number(node._nodeInfo?._scroll?.height)),
|
|
46
|
+
}
|
|
47
|
+
const event: TaroEvent = createTaroEvent(eventName, { detail: value }, node)
|
|
48
|
+
|
|
49
|
+
eventHandler(event, eventName, node)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Component
|
|
53
|
+
export default struct TaroScrollList {
|
|
54
|
+
@Builder customBuilder() {}
|
|
55
|
+
@BuilderParam createLazyChildren: (node: TaroScrollViewElement) => void = this.customBuilder
|
|
56
|
+
@ObjectLink node: TaroScrollViewElement
|
|
57
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
58
|
+
|
|
59
|
+
aboutToAppear(): void {
|
|
60
|
+
if (this.node) {
|
|
61
|
+
this.node._instance = this
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
handleScroll = (scrollOffset: number) => {
|
|
66
|
+
handleScrollEvent(this.node, 'scroll', scrollOffset)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
build() {
|
|
70
|
+
List({
|
|
71
|
+
scroller: this.node.scroller
|
|
72
|
+
}) {
|
|
73
|
+
this.createLazyChildren(this.node)
|
|
74
|
+
}
|
|
75
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
76
|
+
.sticky(StickyStyle.Header)
|
|
77
|
+
.listDirection(this.node.getAttribute('scrollX') ? Axis.Horizontal: Axis.Vertical)
|
|
78
|
+
.align(Alignment.TopStart)
|
|
79
|
+
.clip(true)
|
|
80
|
+
.scrollBar(getAttributes(this.node).scrollBar)
|
|
81
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
82
|
+
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
83
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
84
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
85
|
+
}))
|
|
86
|
+
.onDidScroll(shouldBindEvent((scrollOffset: number) => { handleScrollEvent(this.node, 'scroll', scrollOffset) }, this.node, ['scroll']))
|
|
87
|
+
.onScrollStart(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollstart') }, this.node, ['scrollstart']))
|
|
88
|
+
.onScrollStop(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollend') }, this.node, ['scrollend']))
|
|
89
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
90
|
+
.onReachEnd(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrolltolower') }, this.node, ['scrolltolower']))
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
@@ -122,7 +122,7 @@ export default struct TaroScrollView {
|
|
|
122
122
|
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
123
123
|
this.node._nodeInfo.areaInfo = res[1]
|
|
124
124
|
}))
|
|
125
|
-
.
|
|
125
|
+
.onDidScroll(shouldBindEvent((xOffset: number, yOffset: number) => { handleScrollEvent(this.node, 'scroll', xOffset, yOffset) }, this.node, ['scroll']))
|
|
126
126
|
.onScrollStart(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollstart') }, this.node, ['scrollstart']))
|
|
127
127
|
.onScrollStop(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollend') }, this.node, ['scrollend']))
|
|
128
128
|
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import commonStyleModify from './style'
|
|
2
|
+
|
|
3
|
+
import type { TaroViewElement, TaroElement, TaroAny } from '@tarojs/runtime'
|
|
4
|
+
|
|
5
|
+
@Component
|
|
6
|
+
export default struct TaroStickySection {
|
|
7
|
+
@Builder customBuilder() {}
|
|
8
|
+
@BuilderParam createLazyChildren: (node: TaroViewElement) => void = this.customBuilder
|
|
9
|
+
@ObjectLink node: TaroViewElement
|
|
10
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
11
|
+
|
|
12
|
+
aboutToAppear(): void {
|
|
13
|
+
if (this.node) {
|
|
14
|
+
this.node._instance = this
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Builder
|
|
19
|
+
itemHead(header: TaroViewElement) {
|
|
20
|
+
Stack() {
|
|
21
|
+
LazyForEach(header, (item: TaroElement) => {
|
|
22
|
+
if (item.tagName === 'STICKY-HEADER') {
|
|
23
|
+
this.createLazyChildren(item as TaroViewElement)
|
|
24
|
+
}
|
|
25
|
+
}, (item: TaroElement) => `${item._nid}-${item._nodeInfo?.layer || 0}`)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
build() {
|
|
30
|
+
ListItemGroup({
|
|
31
|
+
header: this.itemHead(this.node)
|
|
32
|
+
}) {
|
|
33
|
+
ForEach(this.node.children, (item: TaroElement) => {
|
|
34
|
+
if (item.tagName === 'LIST-VIEW') {
|
|
35
|
+
this.createLazyChildren(item as TaroViewElement)
|
|
36
|
+
}
|
|
37
|
+
}, (item: TaroElement) => `${item._nid}-${item._nodeInfo?.layer || 0}`)
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -49,3 +49,7 @@ export const TaroListTagName = 'list'
|
|
|
49
49
|
export const TaroListItemTagName = 'list-item'
|
|
50
50
|
export const TaroOpenDataTagName = 'open-data'
|
|
51
51
|
export const TaroIgnoreTagName = 'ignore'
|
|
52
|
+
|
|
53
|
+
export const TaroStickySectionTagName = 'sticky-section'
|
|
54
|
+
export const TaroStickyHeaderTagName = 'sticky-header'
|
|
55
|
+
export const TaroListViewTagName = 'list-view'
|
|
@@ -163,6 +163,10 @@ function depthTraversal(root: ReactElement) {
|
|
|
163
163
|
function combineStyle(nestingStyle: NestingStyle, class_mapping: TMapping, alias: Record<string, string[]>) {
|
|
164
164
|
|
|
165
165
|
const findElement = (selector_string, combinator_type, selector_mapping, remainder_selector, declaration) => {
|
|
166
|
+
// 防止修改原数组
|
|
167
|
+
if (selector_string instanceof Array) {
|
|
168
|
+
selector_string = selector_string.slice()
|
|
169
|
+
}
|
|
166
170
|
let selector_list = [selector_string]
|
|
167
171
|
const selector_nodes: TSelectorNode[] = []
|
|
168
172
|
let shouldUseCombinations = false
|
|
@@ -182,31 +186,36 @@ function combineStyle(nestingStyle: NestingStyle, class_mapping: TMapping, alias
|
|
|
182
186
|
for (let i = 0; i < selector_list.length; i++) {
|
|
183
187
|
const selector = selector_list[i]
|
|
184
188
|
if (selector instanceof Array) {
|
|
185
|
-
let
|
|
189
|
+
let hitElements: any
|
|
186
190
|
// 如果是数组,说明他是一个多类选择器:.a.b,我们需要搜索这两个类名都指向同一个node
|
|
187
191
|
if (shouldUseCombinations) {
|
|
188
|
-
|
|
192
|
+
hitElements = generateCombinations(selector, (combination) => {
|
|
189
193
|
// combination 是组合后的选择器['parent', 'child']
|
|
190
194
|
const _obj = findSendNode(combination, selector_mapping)
|
|
191
195
|
if (_obj) return _obj
|
|
192
196
|
})
|
|
193
197
|
} else {
|
|
194
|
-
|
|
198
|
+
hitElements = findSendNode(selector, selector_mapping)
|
|
195
199
|
}
|
|
196
200
|
// 找出最后搜寻出来的node
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
if (hitElements) {
|
|
202
|
+
let objs = [hitElements]
|
|
203
|
+
objs = flattenArray(objs)
|
|
204
|
+
objs.forEach(obj => {
|
|
205
|
+
if (typeof obj.node.type === 'function') {
|
|
206
|
+
// 自定义组件,往下传递需要搜寻的内容向里面搜寻
|
|
207
|
+
const nestingData = {
|
|
208
|
+
selectors: [selector_string, combinator_type, ...remainder_selector.slice()],
|
|
209
|
+
declaration: declaration
|
|
210
|
+
}
|
|
211
|
+
obj.node.props.__nesting = obj.node.props.__nesting ?
|
|
212
|
+
[...obj.node.props.__nesting, nestingData] : [nestingData]
|
|
203
213
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
node: obj.node
|
|
214
|
+
selector_nodes.push({
|
|
215
|
+
// @ts-ignore
|
|
216
|
+
mapping: (obj.ref || obj)[combinator_type === ' > ' ? 'children' : 'descendants'],
|
|
217
|
+
node: obj.node
|
|
218
|
+
})
|
|
210
219
|
})
|
|
211
220
|
}
|
|
212
221
|
} else {
|
|
@@ -286,17 +295,19 @@ function generateCombinations (arrays: (string[] | string)[], cbFn, currentCombi
|
|
|
286
295
|
const currentArray = arrays[0]
|
|
287
296
|
if (currentArray instanceof Array) {
|
|
288
297
|
// 遍历当前数组的每个元素
|
|
298
|
+
const eles: TMappingNode[] = []
|
|
289
299
|
for (let i = 0; i < currentArray.length; i++) {
|
|
290
300
|
// 将当前元素添加到当前组合中
|
|
291
301
|
currentCombination.push(currentArray[i])
|
|
292
302
|
// 递归处理剩余的数组
|
|
293
303
|
const shouldStop = generateCombinations(arrays.slice(1), cbFn, currentCombination)
|
|
294
304
|
if (shouldStop) {
|
|
295
|
-
|
|
305
|
+
eles.push(shouldStop)
|
|
296
306
|
}
|
|
297
307
|
// 回溯,移除最后一个元素,尝试其他组合
|
|
298
308
|
currentCombination.pop()
|
|
299
309
|
}
|
|
310
|
+
return eles
|
|
300
311
|
} else {
|
|
301
312
|
// 如果不是数组,直接将当前元素添加到当前组合中
|
|
302
313
|
currentCombination.push(currentArray)
|
|
@@ -391,3 +402,10 @@ export function __combine_nesting_style__(react_tree: ReactElement, styles: Nest
|
|
|
391
402
|
}
|
|
392
403
|
return react_tree
|
|
393
404
|
}
|
|
405
|
+
|
|
406
|
+
// 拍平数组
|
|
407
|
+
function flattenArray(arr) {
|
|
408
|
+
return arr.reduce((acc, val) => {
|
|
409
|
+
return acc.concat(Array.isArray(val) ? flattenArray(val) : val)
|
|
410
|
+
}, [])
|
|
411
|
+
}
|
|
@@ -47,6 +47,7 @@ export function initHarmonyElement () {
|
|
|
47
47
|
case 'movable-view': return new TaroMovableViewElement()
|
|
48
48
|
case 'progress': return new TaroProgressElement()
|
|
49
49
|
case 'scroll-view': return new TaroScrollViewElement()
|
|
50
|
+
case 'scroll-list': return new TaroScrollViewElement()
|
|
50
51
|
case 'checkbox-group': return new TaroCheckboxGroupElement()
|
|
51
52
|
case 'input': return new TaroInputElement()
|
|
52
53
|
case 'picker': return new TaroPickerElement()
|
|
@@ -7,8 +7,8 @@ import { BORDER_STYLE_MAP, capitalizeFirstLetter, FlexManager, getNodeMarginOrPa
|
|
|
7
7
|
|
|
8
8
|
// 背景解析正则
|
|
9
9
|
const BACKGROUND_REGEX = {
|
|
10
|
-
IMAGE: /url\((['"])?(.*?)\1\)|(linear|radial)-gradient\([^)]*\)
|
|
11
|
-
COLOR: /(#[0-9a-fA-F]{3,
|
|
10
|
+
IMAGE: /url\((['"])?(.*?)\1\)|((linear|radial)-gradient\([^)]*\))/g,
|
|
11
|
+
COLOR: /(#[0-9a-fA-F]{3,8}|rgb\(\d+,\s*\d+,\s*\d+\)|rgba?\(\d+,\s*\d+,\s*\d+,\s*(?:0?\.\d+|\d+%)\)|transparent)/,
|
|
12
12
|
REPEAT: /(repeat-x|repeat-y|repeat|space|round|no-repeat)/,
|
|
13
13
|
POSITION: /(top|left|center|right|bottom|\d+(\.\d+)?(px|%|vw|vh)?)+/g,
|
|
14
14
|
SIZE: /(cover|contain|\d+(\.\d+)?(px|%|vw|vh)?)+/g
|
|
@@ -469,20 +469,24 @@ export default function convertWebStyle2HmStyle(webStyle: CSSProperties, node?:
|
|
|
469
469
|
}
|
|
470
470
|
|
|
471
471
|
function setBackgroundImage(hmStyle, value) {
|
|
472
|
-
if (typeof value === 'string'
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
472
|
+
if (typeof value === 'string') {
|
|
473
|
+
if (value.indexOf('url(') !== -1 && value.indexOf(')') !== -1) {
|
|
474
|
+
// 如果包含 url(),则说明是 background-image 属性
|
|
475
|
+
const match = value.match(new RegExp('url\\([\'"]?(.*?)[\'"]?\\)'))
|
|
476
|
+
if (match) {
|
|
477
|
+
hmStyle.backgroundImage = {
|
|
478
|
+
src: match[1]
|
|
479
|
+
}
|
|
478
480
|
}
|
|
481
|
+
} else if (value.indexOf('linear-gradient(') !== -1) {
|
|
482
|
+
hmStyle.backgroundImage = parseGradient(value)
|
|
479
483
|
}
|
|
480
484
|
}
|
|
481
|
-
// todo 渐变需要处理
|
|
482
485
|
}
|
|
483
486
|
|
|
484
487
|
// 解析background属性
|
|
485
488
|
function setBackground (backgroundValue: string) {
|
|
489
|
+
backgroundValue = preprocessCss(backgroundValue)
|
|
486
490
|
const result = {
|
|
487
491
|
'background-color': '',
|
|
488
492
|
'background-image': '',
|
|
@@ -726,3 +730,76 @@ function parseTransformOrigin (value: string) {
|
|
|
726
730
|
y: 0
|
|
727
731
|
}
|
|
728
732
|
}
|
|
733
|
+
|
|
734
|
+
function directionToAngle(direction) {
|
|
735
|
+
const map = {
|
|
736
|
+
'to top': 270,
|
|
737
|
+
'to bottom': 90,
|
|
738
|
+
'to left': 180,
|
|
739
|
+
'to right': 0,
|
|
740
|
+
'to top left': 225,
|
|
741
|
+
'to left top': 225,
|
|
742
|
+
'to top right': 315,
|
|
743
|
+
'to right top': 315,
|
|
744
|
+
'to bottom left': 135,
|
|
745
|
+
'to left bottom': 135,
|
|
746
|
+
'to bottom right': 45,
|
|
747
|
+
'to right bottom': 45
|
|
748
|
+
}
|
|
749
|
+
return map[direction.toLowerCase()] || 0 // 默认为0度(to right)
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
function parseGradient(gradientString) {
|
|
753
|
+
const directionPattern = /linear-gradient\((to [a-z ]+|\d+deg),/
|
|
754
|
+
const directionMatch = gradientString.match(directionPattern)
|
|
755
|
+
let angle
|
|
756
|
+
|
|
757
|
+
if (directionMatch) {
|
|
758
|
+
const direction = directionMatch[1]
|
|
759
|
+
if (direction.includes('deg')) {
|
|
760
|
+
angle = parseInt(direction, 10)
|
|
761
|
+
} else {
|
|
762
|
+
angle = directionToAngle(direction)
|
|
763
|
+
}
|
|
764
|
+
} else {
|
|
765
|
+
angle = 0 // 默认方向为向右(0度)
|
|
766
|
+
}
|
|
767
|
+
const colorPattern = /(?:(#[0-9a-f]{3,8}|rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(?:,\s*\d*\.?\d+\s*)?\)))\s*(\d*%|)/gi
|
|
768
|
+
const colors = []
|
|
769
|
+
let match
|
|
770
|
+
while ((match = colorPattern.exec(gradientString)) !== null) {
|
|
771
|
+
const color = match[1] ? match[1].trim() : null
|
|
772
|
+
const position = match[2] ? parseInt(match[2], 10) / 100 : null
|
|
773
|
+
colors.push([color, position])
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
if (colors.some(color => color[1] === null)) {
|
|
777
|
+
const step = 1 / (colors.length - 1)
|
|
778
|
+
colors.forEach((color, index) => (color[1] = index * step))
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return {
|
|
782
|
+
angle: angle,
|
|
783
|
+
colors: colors
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function rgbaToHex(rgba) {
|
|
788
|
+
const parts = rgba.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),?\s*(\d*\.?\d+)?\)/)
|
|
789
|
+
if (!parts) return rgba // 如果匹配失败,返回原字符串
|
|
790
|
+
|
|
791
|
+
const r = parseInt(parts[1]).toString(16).padStart(2, '0')
|
|
792
|
+
const g = parseInt(parts[2]).toString(16).padStart(2, '0')
|
|
793
|
+
const b = parseInt(parts[3]).toString(16).padStart(2, '0')
|
|
794
|
+
if (parts[4]) {
|
|
795
|
+
const a = parts[4] ? Math.round(parseFloat(parts[4]) * 255).toString(16).padStart(2, '0') : 'ff'
|
|
796
|
+
return `#${a}${r}${g}${b}`
|
|
797
|
+
} else {
|
|
798
|
+
return `#${r}${g}${b}`
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function preprocessCss(css) {
|
|
802
|
+
return css.replace(/rgba?\((\d+\s*,\s*\d+\s*,\s*\d+\s*,?\s*\d*\.?\d*)\)/g, (match) => {
|
|
803
|
+
return rgbaToHex(match)
|
|
804
|
+
})
|
|
805
|
+
}
|
package/dist/runtime-utils.d.ts
CHANGED
|
@@ -588,7 +588,7 @@ declare namespace apis {
|
|
|
588
588
|
function showToast(options: any): Promise<unknown>;
|
|
589
589
|
function showModal(options: any): Promise<unknown>;
|
|
590
590
|
function showActionSheet(options: any): Promise<unknown>;
|
|
591
|
-
|
|
591
|
+
const hideToast: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
|
|
592
592
|
const showLoading: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
|
|
593
593
|
const hideLoading: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
|
|
594
594
|
const enableAlertBeforeUnload: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
|
package/dist/runtime-utils.js
CHANGED
|
@@ -656,7 +656,12 @@ const setClipboardData = function (options) {
|
|
|
656
656
|
callAsyncFail(reject, res, options);
|
|
657
657
|
}
|
|
658
658
|
else {
|
|
659
|
-
promptAction.showToast({
|
|
659
|
+
promptAction.showToast({
|
|
660
|
+
message: '内容已复制',
|
|
661
|
+
duration: 1500,
|
|
662
|
+
bottom: '50%',
|
|
663
|
+
showMode: 1 // 设置弹窗显示模式,显示在应用之上。
|
|
664
|
+
});
|
|
660
665
|
return handle.success({
|
|
661
666
|
data,
|
|
662
667
|
}, { resolve, reject });
|
|
@@ -3645,7 +3650,6 @@ function showToast(options) {
|
|
|
3645
3650
|
message: options.title,
|
|
3646
3651
|
duration: options.duration,
|
|
3647
3652
|
bottom: options.bottom,
|
|
3648
|
-
// @ts-ignore
|
|
3649
3653
|
showMode: 1 // 设置弹窗显示模式,显示在应用之上。
|
|
3650
3654
|
});
|
|
3651
3655
|
callAsyncSuccess(resolve, resCallback('showToast'), options);
|
|
@@ -3735,16 +3739,7 @@ function showActionSheet(options) {
|
|
|
3735
3739
|
});
|
|
3736
3740
|
});
|
|
3737
3741
|
}
|
|
3738
|
-
|
|
3739
|
-
return new Promise(resolve => {
|
|
3740
|
-
promptAction.showToast({
|
|
3741
|
-
message: '关闭中',
|
|
3742
|
-
duration: 10,
|
|
3743
|
-
bottom: '9999px'
|
|
3744
|
-
});
|
|
3745
|
-
callAsyncSuccess(resolve, resCallback('hideToast'), options);
|
|
3746
|
-
});
|
|
3747
|
-
}
|
|
3742
|
+
const hideToast = /* @__PURE__ */ temporarilyNotSupport('hideToast');
|
|
3748
3743
|
const showLoading = temporarilyNotSupport('showLoading');
|
|
3749
3744
|
const hideLoading = temporarilyNotSupport('hideLoading');
|
|
3750
3745
|
const enableAlertBeforeUnload = /* @__PURE__ */ temporarilyNotSupport('enableAlertBeforeUnload');
|