uview-plus 3.8.55 → 3.8.106
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/changelog.md +2147 -1828
- package/components/u-action-sheet/props.js +3 -1
- package/components/u-action-sheet/u-action-sheet.vue +22 -2
- package/components/u-album/props.js +3 -1
- package/components/u-alert/props.js +4 -2
- package/components/u-avatar/props.js +4 -1
- package/components/u-avatar-group/props.js +4 -1
- package/components/u-back-top/props.js +4 -1
- package/components/u-badge/props.js +4 -1
- package/components/u-barcode/u-barcode.vue +44 -15
- package/components/u-box/props.js +5 -2
- package/components/u-button/props.js +4 -1
- package/components/u-button/u-button.vue +2 -5
- package/components/u-button/vue.scss +3 -3
- package/components/u-calendar/calendar.js +8 -0
- package/components/u-calendar/props.js +43 -1
- package/components/u-calendar/u-calendar.vue +16 -0
- package/components/u-calendar-strip/props.js +3 -1
- package/components/u-canvas/u-canvas.vue +1028 -423
- package/components/u-car-keyboard/props.js +3 -1
- package/components/u-card/props.js +3 -1
- package/components/u-cell/props.js +4 -1
- package/components/u-cell/u-cell.vue +9 -1
- package/components/u-cell-group/props.js +4 -1
- package/components/u-checkbox/props.js +4 -1
- package/components/u-checkbox/u-checkbox.vue +7 -3
- package/components/u-checkbox-group/props.js +3 -1
- package/components/u-circle-progress/props.js +4 -1
- package/components/u-code/props.js +4 -1
- package/components/u-code-input/props.js +4 -1
- package/components/u-col/props.js +4 -1
- package/components/u-collapse/props.js +4 -1
- package/components/u-collapse-item/props.js +4 -1
- package/components/u-color-picker/u-color-picker.vue +1 -0
- package/components/u-column-notice/props.js +4 -1
- package/components/u-count-down/props.js +4 -1
- package/components/u-count-to/props.js +4 -1
- package/components/u-cropper/u-cropper.vue +95 -51
- package/components/u-datetime-picker/props.js +4 -1
- package/components/u-datetime-picker/u-datetime-picker.vue +53 -4
- package/components/u-divider/props.js +4 -1
- package/components/u-dragsort/u-dragsort.vue +57 -32
- package/components/u-dropdown/props.js +3 -1
- package/components/u-dropdown-item/props.js +3 -1
- package/components/u-empty/props.js +4 -1
- package/components/u-form/props.js +4 -1
- package/components/u-form-item/props.js +4 -1
- package/components/u-gap/props.js +4 -1
- package/components/u-grid/props.js +4 -1
- package/components/u-grid-item/props.js +4 -1
- package/components/u-guide/props.js +3 -1
- package/components/u-icon/props.js +4 -1
- package/components/u-icon/u-icon.vue +11 -2
- package/components/u-icon/upicon.ttf +0 -0
- package/components/u-icon/util.js +103 -10
- package/components/u-image/props.js +4 -1
- package/components/u-image/u-image.vue +280 -267
- package/components/u-index-anchor/props.js +4 -1
- package/components/u-index-item/props.js +2 -1
- package/components/u-index-item/u-index-item.vue +1 -1
- package/components/u-index-list/props.js +4 -1
- package/components/u-index-list/u-index-list.vue +1 -1
- package/components/u-input/props.js +3 -1
- package/components/u-keyboard/props.js +4 -1
- package/components/u-line/props.js +4 -1
- package/components/u-line-progress/props.js +6 -3
- package/components/u-link/props.js +4 -1
- package/components/u-list/props.js +4 -1
- package/components/u-list-item/props.js +4 -1
- package/components/u-loading-icon/props.js +4 -1
- package/components/u-loading-page/props.js +3 -1
- package/components/u-loadmore/props.js +4 -1
- package/components/u-markdown/u-markdown.vue +45 -3
- package/components/u-modal/props.js +4 -1
- package/components/u-navbar/props.js +4 -2
- package/components/u-navbar/u-navbar.vue +15 -9
- package/components/u-no-network/props.js +4 -1
- package/components/u-notice-bar/props.js +4 -1
- package/components/u-notify/props.js +4 -1
- package/components/u-novel-reader/content-normalizer.js +80 -0
- package/components/u-novel-reader/layout-engine.js +225 -0
- package/components/u-novel-reader/measure-adapter.js +69 -0
- package/components/u-novel-reader/novelReader.js +35 -0
- package/components/u-novel-reader/persistence.js +144 -0
- package/components/u-novel-reader/props.js +100 -0
- package/components/u-novel-reader/reader-catalog.vue +234 -0
- package/components/u-novel-reader/reader-content.vue +226 -0
- package/components/u-novel-reader/reader-core.js +151 -0
- package/components/u-novel-reader/reader-settings.vue +325 -0
- package/components/u-novel-reader/reader-toolbar.vue +313 -0
- package/components/u-novel-reader/theme-vars.scss +49 -0
- package/components/u-novel-reader/u-novel-reader.vue +836 -0
- package/components/u-number-box/props.js +4 -1
- package/components/u-number-box/u-number-box.vue +2 -2
- package/components/u-number-keyboard/props.js +4 -1
- package/components/u-overlay/props.js +4 -1
- package/components/u-pagination/u-pagination.vue +60 -39
- package/components/u-parse/props.js +4 -1
- package/components/u-picker/props.js +4 -1
- package/components/u-picker-column/props.js +3 -1
- package/components/u-popover/props.js +2 -1
- package/components/u-popup/props.js +4 -1
- package/components/u-poster/u-poster.vue +246 -214
- package/components/u-qrcode/qrcode.js +105 -97
- package/components/u-qrcode/u-qrcode.vue +242 -289
- package/components/u-radio/props.js +4 -1
- package/components/u-radio/u-radio.vue +7 -3
- package/components/u-radio-group/props.js +4 -1
- package/components/u-rate/props.js +4 -1
- package/components/u-read-more/props.js +4 -1
- package/components/u-row/props.js +4 -1
- package/components/u-row-notice/props.js +4 -1
- package/components/u-safe-bottom/props.js +2 -1
- package/components/u-scroll-list/props.js +4 -1
- package/components/u-scroll-list/scrollWxs.wxs +1 -1
- package/components/u-search/props.js +3 -1
- package/components/u-skeleton/props.js +4 -1
- package/components/u-slider/props.js +3 -1
- package/components/u-slider/u-slider.vue +71 -29
- package/components/u-status-bar/props.js +4 -1
- package/components/u-steps/props.js +4 -1
- package/components/u-steps-item/props.js +4 -1
- package/components/u-sticky/props.js +4 -1
- package/components/u-sticky/u-sticky.vue +11 -0
- package/components/u-subsection/props.js +3 -1
- package/components/u-swipe-action/props.js +4 -1
- package/components/u-swipe-action-item/index.wxs +43 -25
- package/components/u-swipe-action-item/nvue.js +9 -0
- package/components/u-swipe-action-item/other.js +32 -21
- package/components/u-swipe-action-item/props.js +9 -1
- package/components/u-swipe-action-item/swipeActionItem.js +1 -0
- package/components/u-swipe-action-item/u-swipe-action-item.vue +42 -4
- package/components/u-swiper/props.js +9 -1
- package/components/u-swiper/swiper.js +1 -0
- package/components/u-swiper/u-swiper.vue +2 -0
- package/components/u-swiper-indicator/props.js +4 -1
- package/components/u-switch/props.js +4 -1
- package/components/u-switch/u-switch.vue +1 -1
- package/components/u-tabbar/props.js +3 -1
- package/components/u-tabbar/u-tabbar.vue +2 -1
- package/components/u-tabbar-item/props.js +4 -1
- package/components/u-tabbar-item/u-tabbar-item.vue +64 -21
- package/components/u-table/props.js +3 -1
- package/components/u-table2/tableRow.vue +155 -69
- package/components/u-table2/u-table2.vue +327 -137
- package/components/u-tabs/props.js +4 -1
- package/components/u-tabs/u-tabs.vue +11 -8
- package/components/u-tabs-item/props.js +3 -1
- package/components/u-tabs-pro/u-tabs-pro.vue +212 -0
- package/components/u-tag/props.js +4 -1
- package/components/u-td/props.js +3 -1
- package/components/u-text/props.js +4 -1
- package/components/u-text/text.js +1 -1
- package/components/u-text/u-text.vue +18 -6
- package/components/u-textarea/props.js +3 -1
- package/components/u-textarea/u-textarea.vue +16 -5
- package/components/u-th/props.js +3 -1
- package/components/u-toolbar/props.js +4 -1
- package/components/u-tooltip/props.js +10 -2
- package/components/u-tooltip/tooltip.js +2 -1
- package/components/u-tooltip/u-tooltip.vue +31 -3
- package/components/u-tr/props.js +3 -1
- package/components/u-transition/nvue-ani-map.js +75 -68
- package/components/u-transition/props.js +4 -1
- package/components/u-transition/transitionMixin.js +164 -163
- package/components/u-upload/props.js +4 -1
- package/components/u-upload/u-upload.vue +48 -41
- package/components/u-waterfall/u-waterfall.vue +162 -110
- package/index.js +65 -8
- package/libs/config/config.js +1 -1
- package/libs/config/props.js +180 -204
- package/libs/css/components.scss +3 -0
- package/libs/function/index.js +66 -0
- package/libs/function/uni-api-shims.js +29 -0
- package/libs/i18n/index.js +71 -36
- package/libs/i18n/locale-packs.js +11 -0
- package/libs/i18n/locales/all.js +23 -0
- package/libs/i18n/locales/{de.json → de.js} +1 -1
- package/libs/i18n/locales/{en.json → en.js} +2 -2
- package/libs/i18n/locales/{es.json → es.js} +1 -1
- package/libs/i18n/locales/{fr.json → fr.js} +2 -2
- package/libs/i18n/locales/{ja.json → ja.js} +1 -1
- package/libs/i18n/locales/{ko.json → ko.js} +1 -1
- package/libs/i18n/locales/{ru.json → ru.js} +1 -1
- package/libs/i18n/locales/{th.json → th.js} +1 -1
- package/libs/i18n/locales/{zh-Hans.json → zh-Hans.js} +1 -1
- package/libs/i18n/locales/{zh-Hant.json → zh-Hant.js} +1 -1
- package/libs/mixin/mixin.js +18 -54
- package/libs/root/index.js +78 -5
- package/libs/root/page.js +7 -7
- package/libs/root/root.js +73 -3
- package/libs/util/app-nvue-webview-canvas.js +486 -0
- package/libs/util/gcanvas/bridge/bridge-weex.js +10 -7
- package/libs/util/gcanvas/context-2d/FillStyleLinearGradient.js +0 -0
- package/libs/util/gcanvas/context-2d/FillStylePattern.js +0 -0
- package/libs/util/gcanvas/context-2d/FillStyleRadialGradient.js +0 -0
- package/libs/util/gcanvas/context-2d/RenderingContext.js +0 -0
- package/libs/util/gcanvas/context-webgl/ActiveInfo.js +0 -0
- package/libs/util/gcanvas/context-webgl/Buffer.js +0 -0
- package/libs/util/gcanvas/context-webgl/Framebuffer.js +0 -0
- package/libs/util/gcanvas/context-webgl/GLenum.js +0 -0
- package/libs/util/gcanvas/context-webgl/GLmethod.js +0 -0
- package/libs/util/gcanvas/context-webgl/GLtype.js +0 -0
- package/libs/util/gcanvas/context-webgl/Program.js +0 -0
- package/libs/util/gcanvas/context-webgl/Renderbuffer.js +0 -0
- package/libs/util/gcanvas/context-webgl/RenderingContext.js +0 -0
- package/libs/util/gcanvas/context-webgl/Shader.js +0 -0
- package/libs/util/gcanvas/context-webgl/ShaderPrecisionFormat.js +0 -0
- package/libs/util/gcanvas/context-webgl/Texture.js +0 -0
- package/libs/util/gcanvas/context-webgl/UniformLocation.js +0 -0
- package/libs/util/gcanvas/context-webgl/classUtils.js +0 -0
- package/libs/util/gcanvas/env/canvas.js +0 -0
- package/libs/util/gcanvas/env/image.js +0 -0
- package/libs/util/gcanvas/env/tool.js +0 -0
- package/libs/util/gcanvas/index.js +3 -3
- package/package.json +4 -5
- package/tsconfig.json +18 -0
- package/types/comps/calendar.d.ts +38 -0
- package/types/comps/checkbox.d.ts +12 -0
- package/types/comps/lineProgress.d.ts +5 -0
- package/types/comps/navbar.d.ts +3 -3
- package/types/comps/swipeActionItem.d.ts +13 -0
- package/types/comps/swiper.d.ts +5 -0
- package/types/comps/tabs.d.ts +2 -1
- package/types/comps/text.d.ts +1 -1
- package/types/comps/tooltip.d.ts +36 -1
- package/types/func.d.ts +23 -0
- package/types/index.d.ts +1 -0
- /package/components/u-markdown/{marked.esm.js → marked.esm.mjs} +0 -0
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
const DEFAULT_TIMEOUT = 15000
|
|
2
|
+
const DEFAULT_CHUNK_SIZE = 64 * 1024
|
|
3
|
+
|
|
4
|
+
function normalizeMessage(input) {
|
|
5
|
+
const data = input && input.detail ? input.detail.data : input
|
|
6
|
+
if (Array.isArray(data)) {
|
|
7
|
+
return data[data.length - 1] || null
|
|
8
|
+
}
|
|
9
|
+
return data || null
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function toError(error, fallback) {
|
|
13
|
+
if (error instanceof Error) return error
|
|
14
|
+
if (error && error.message) return new Error(error.message)
|
|
15
|
+
return new Error(error ? String(error) : fallback)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createWebViewCanvasBridge(options = {}) {
|
|
19
|
+
const getWebView = typeof options.getWebView === 'function'
|
|
20
|
+
? options.getWebView
|
|
21
|
+
: () => options.webView
|
|
22
|
+
const chunkSize = Math.max(1024, Number(options.chunkSize) || DEFAULT_CHUNK_SIZE)
|
|
23
|
+
const pending = Object.create(null)
|
|
24
|
+
const readyWaiters = []
|
|
25
|
+
let sequence = 0
|
|
26
|
+
let destroyed = false
|
|
27
|
+
let readyInfo = null
|
|
28
|
+
let readyPingTimer = null
|
|
29
|
+
|
|
30
|
+
const rejectPending = (error) => {
|
|
31
|
+
Object.keys(pending).forEach((requestId) => {
|
|
32
|
+
const request = pending[requestId]
|
|
33
|
+
clearTimeout(request.timer)
|
|
34
|
+
delete pending[requestId]
|
|
35
|
+
request.reject(error)
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const scheduleReadyPing = () => {
|
|
40
|
+
if (destroyed || readyInfo || readyPingTimer) return
|
|
41
|
+
const ping = () => {
|
|
42
|
+
readyPingTimer = null
|
|
43
|
+
if (destroyed || readyInfo) return
|
|
44
|
+
try {
|
|
45
|
+
const webView = getWebView()
|
|
46
|
+
if (webView && typeof webView.evalJs === 'function') {
|
|
47
|
+
webView.evalJs('window.__upCanvasRuntime && window.__upCanvasRuntime.announceReady()')
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (typeof options.onError === 'function') options.onError(error)
|
|
51
|
+
}
|
|
52
|
+
readyPingTimer = setTimeout(ping, 100)
|
|
53
|
+
}
|
|
54
|
+
ping()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const resolveReady = (message) => {
|
|
58
|
+
const previousSessionId = readyInfo && readyInfo.sessionId
|
|
59
|
+
if (previousSessionId && message.sessionId && previousSessionId !== message.sessionId) {
|
|
60
|
+
rejectPending(new Error('Canvas WebView reloaded'))
|
|
61
|
+
}
|
|
62
|
+
readyInfo = message
|
|
63
|
+
if (readyPingTimer) {
|
|
64
|
+
clearTimeout(readyPingTimer)
|
|
65
|
+
readyPingTimer = null
|
|
66
|
+
}
|
|
67
|
+
readyWaiters.splice(0).forEach((waiter) => {
|
|
68
|
+
clearTimeout(waiter.timer)
|
|
69
|
+
waiter.resolve(message)
|
|
70
|
+
})
|
|
71
|
+
if (typeof options.onReady === 'function') options.onReady(message)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const ready = (timeout = DEFAULT_TIMEOUT) => {
|
|
75
|
+
if (destroyed) return Promise.reject(new Error('Canvas WebView bridge destroyed'))
|
|
76
|
+
if (readyInfo) return Promise.resolve(readyInfo)
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
const waiter = {
|
|
79
|
+
resolve,
|
|
80
|
+
reject,
|
|
81
|
+
timer: setTimeout(() => {
|
|
82
|
+
const index = readyWaiters.indexOf(waiter)
|
|
83
|
+
if (index !== -1) readyWaiters.splice(index, 1)
|
|
84
|
+
reject(new Error('Canvas WebView ready timeout'))
|
|
85
|
+
}, timeout)
|
|
86
|
+
}
|
|
87
|
+
readyWaiters.push(waiter)
|
|
88
|
+
scheduleReadyPing()
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const settleRequest = (requestId, error, result) => {
|
|
93
|
+
const request = pending[requestId]
|
|
94
|
+
if (!request) return false
|
|
95
|
+
clearTimeout(request.timer)
|
|
96
|
+
delete pending[requestId]
|
|
97
|
+
if (error) request.reject(error)
|
|
98
|
+
else request.resolve(result)
|
|
99
|
+
return true
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const request = async (type, payload, timeout = DEFAULT_TIMEOUT) => {
|
|
103
|
+
await ready(timeout)
|
|
104
|
+
if (destroyed) throw new Error('Canvas WebView bridge destroyed')
|
|
105
|
+
|
|
106
|
+
const webView = getWebView()
|
|
107
|
+
if (!webView || typeof webView.evalJs !== 'function') {
|
|
108
|
+
throw new Error('Canvas WebView is unavailable')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const requestId = ++sequence
|
|
112
|
+
const serialized = JSON.stringify({ requestId, type, payload: payload || {} })
|
|
113
|
+
const total = Math.max(1, Math.ceil(serialized.length / chunkSize))
|
|
114
|
+
|
|
115
|
+
return new Promise((resolve, reject) => {
|
|
116
|
+
pending[requestId] = {
|
|
117
|
+
resolve,
|
|
118
|
+
reject,
|
|
119
|
+
timer: setTimeout(() => {
|
|
120
|
+
settleRequest(requestId, new Error(`Canvas ${type} request timeout`))
|
|
121
|
+
}, timeout)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
const asyncSends = []
|
|
126
|
+
for (let index = 0; index < total; index += 1) {
|
|
127
|
+
const chunk = serialized.slice(index * chunkSize, (index + 1) * chunkSize)
|
|
128
|
+
const result = webView.evalJs(
|
|
129
|
+
`window.__upCanvasRuntime.receiveChunk(${JSON.stringify(requestId)}, ${index}, ${total}, ${JSON.stringify(chunk)})`
|
|
130
|
+
)
|
|
131
|
+
if (result && typeof result.then === 'function') asyncSends.push(result)
|
|
132
|
+
}
|
|
133
|
+
if (asyncSends.length) {
|
|
134
|
+
Promise.all(asyncSends).catch((error) => {
|
|
135
|
+
settleRequest(requestId, toError(error, 'Canvas request dispatch failed'))
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
} catch (error) {
|
|
139
|
+
settleRequest(requestId, toError(error, 'Canvas request dispatch failed'))
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const handleMessage = (input) => {
|
|
145
|
+
const message = normalizeMessage(input)
|
|
146
|
+
if (!message || message.channel !== 'u-canvas') return false
|
|
147
|
+
|
|
148
|
+
if (message.action === 'canvasReady') {
|
|
149
|
+
resolveReady(message)
|
|
150
|
+
return true
|
|
151
|
+
}
|
|
152
|
+
if (message.action === 'canvasTouch') {
|
|
153
|
+
if (typeof options.onTouch === 'function') options.onTouch(message)
|
|
154
|
+
return true
|
|
155
|
+
}
|
|
156
|
+
if (message.action === 'canvasResponse') {
|
|
157
|
+
return settleRequest(message.requestId, null, message.result)
|
|
158
|
+
}
|
|
159
|
+
if (message.action === 'canvasError') {
|
|
160
|
+
const error = new Error(message.message || 'Canvas WebView request failed')
|
|
161
|
+
if (!settleRequest(message.requestId, error) && typeof options.onError === 'function') {
|
|
162
|
+
options.onError(error)
|
|
163
|
+
}
|
|
164
|
+
return true
|
|
165
|
+
}
|
|
166
|
+
return false
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const destroy = () => {
|
|
170
|
+
if (destroyed) return
|
|
171
|
+
destroyed = true
|
|
172
|
+
if (readyPingTimer) clearTimeout(readyPingTimer)
|
|
173
|
+
readyPingTimer = null
|
|
174
|
+
const error = new Error('Canvas WebView bridge destroyed')
|
|
175
|
+
readyWaiters.splice(0).forEach((waiter) => {
|
|
176
|
+
clearTimeout(waiter.timer)
|
|
177
|
+
waiter.reject(error)
|
|
178
|
+
})
|
|
179
|
+
rejectPending(error)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
ready,
|
|
184
|
+
request,
|
|
185
|
+
handleMessage,
|
|
186
|
+
destroy
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function normalizeImageDataArgs(args) {
|
|
191
|
+
if (args.length === 1 && args[0] && typeof args[0] === 'object') return args[0]
|
|
192
|
+
return { x: args[0], y: args[1], width: args[2], height: args[3] }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function normalizePutImageDataArgs(args) {
|
|
196
|
+
if (args.length === 1 && args[0] && typeof args[0] === 'object') return args[0]
|
|
197
|
+
return { data: args[0], x: args[1], y: args[2], width: args[3], height: args[4] }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function cloneOptions(options) {
|
|
201
|
+
const result = {}
|
|
202
|
+
Object.keys(options || {}).forEach((key) => {
|
|
203
|
+
if (typeof options[key] !== 'function') result[key] = options[key]
|
|
204
|
+
})
|
|
205
|
+
return result
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function withCallbacks(promise, options) {
|
|
209
|
+
const success = options && options.success
|
|
210
|
+
const fail = options && options.fail
|
|
211
|
+
const complete = options && options.complete
|
|
212
|
+
return promise.then((result) => {
|
|
213
|
+
if (typeof success === 'function') success(result)
|
|
214
|
+
if (typeof complete === 'function') complete(result)
|
|
215
|
+
return result
|
|
216
|
+
}, (error) => {
|
|
217
|
+
if (typeof fail === 'function') fail(error)
|
|
218
|
+
if (typeof complete === 'function') complete(error)
|
|
219
|
+
throw error
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function createWebViewCanvasContext(options = {}) {
|
|
224
|
+
const bridge = options.bridge
|
|
225
|
+
if (!bridge || typeof bridge.request !== 'function') {
|
|
226
|
+
throw new Error('Canvas WebView bridge is required')
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const resolveImage = typeof options.resolveImage === 'function'
|
|
230
|
+
? options.resolveImage
|
|
231
|
+
: source => Promise.resolve(source)
|
|
232
|
+
const measureTextFallback = typeof options.measureText === 'function'
|
|
233
|
+
? options.measureText
|
|
234
|
+
: (text, state) => {
|
|
235
|
+
const matched = String(state.font || '').match(/(\d+(?:\.\d+)?)px/)
|
|
236
|
+
const fontSize = matched ? Number(matched[1]) : 10
|
|
237
|
+
return { width: String(text).length * fontSize * 0.6 }
|
|
238
|
+
}
|
|
239
|
+
const state = {
|
|
240
|
+
fillStyle: '#000000',
|
|
241
|
+
strokeStyle: '#000000',
|
|
242
|
+
lineWidth: 1,
|
|
243
|
+
lineCap: 'butt',
|
|
244
|
+
lineJoin: 'miter',
|
|
245
|
+
miterLimit: 10,
|
|
246
|
+
globalAlpha: 1,
|
|
247
|
+
globalCompositeOperation: 'source-over',
|
|
248
|
+
font: '10px sans-serif',
|
|
249
|
+
textAlign: 'start',
|
|
250
|
+
textBaseline: 'alphabetic',
|
|
251
|
+
shadowOffsetX: 0,
|
|
252
|
+
shadowOffsetY: 0,
|
|
253
|
+
shadowBlur: 0,
|
|
254
|
+
shadowColor: 'rgba(0,0,0,0)',
|
|
255
|
+
lineDashOffset: 0,
|
|
256
|
+
lineDash: []
|
|
257
|
+
}
|
|
258
|
+
const context = {}
|
|
259
|
+
let commands = []
|
|
260
|
+
let resources = Object.create(null)
|
|
261
|
+
let resourceSequence = 0
|
|
262
|
+
let drawTail = Promise.resolve()
|
|
263
|
+
let lastDraw = drawTail
|
|
264
|
+
|
|
265
|
+
const nextResourceId = type => `${type}-${++resourceSequence}`
|
|
266
|
+
const rememberResource = (resource) => {
|
|
267
|
+
resources[resource.id] = resource
|
|
268
|
+
return { __upCanvasRef: resource.id }
|
|
269
|
+
}
|
|
270
|
+
const serializeValue = (value) => {
|
|
271
|
+
if (value && value.__upCanvasResource) return rememberResource(value)
|
|
272
|
+
if (Array.isArray(value)) return value.map(serializeValue)
|
|
273
|
+
return value
|
|
274
|
+
}
|
|
275
|
+
const enqueueCall = (method, args) => {
|
|
276
|
+
commands.push({
|
|
277
|
+
type: 'call',
|
|
278
|
+
method,
|
|
279
|
+
args: (args || []).map(serializeValue)
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
const enqueueSet = (property, value) => {
|
|
283
|
+
commands.push({
|
|
284
|
+
type: 'set',
|
|
285
|
+
property,
|
|
286
|
+
value: serializeValue(value)
|
|
287
|
+
})
|
|
288
|
+
}
|
|
289
|
+
const property = name => ({
|
|
290
|
+
enumerable: true,
|
|
291
|
+
configurable: false,
|
|
292
|
+
get() {
|
|
293
|
+
return state[name]
|
|
294
|
+
},
|
|
295
|
+
set(value) {
|
|
296
|
+
state[name] = value
|
|
297
|
+
enqueueSet(name, value)
|
|
298
|
+
}
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
Object.defineProperties(context, {
|
|
302
|
+
fillStyle: property('fillStyle'),
|
|
303
|
+
strokeStyle: property('strokeStyle'),
|
|
304
|
+
lineWidth: property('lineWidth'),
|
|
305
|
+
lineCap: property('lineCap'),
|
|
306
|
+
lineJoin: property('lineJoin'),
|
|
307
|
+
miterLimit: property('miterLimit'),
|
|
308
|
+
globalAlpha: property('globalAlpha'),
|
|
309
|
+
globalCompositeOperation: property('globalCompositeOperation'),
|
|
310
|
+
font: property('font'),
|
|
311
|
+
textAlign: property('textAlign'),
|
|
312
|
+
textBaseline: property('textBaseline'),
|
|
313
|
+
shadowOffsetX: property('shadowOffsetX'),
|
|
314
|
+
shadowOffsetY: property('shadowOffsetY'),
|
|
315
|
+
shadowBlur: property('shadowBlur'),
|
|
316
|
+
shadowColor: property('shadowColor'),
|
|
317
|
+
lineDashOffset: property('lineDashOffset')
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
const methodOperations = [
|
|
321
|
+
'rect', 'clearRect', 'fillRect', 'strokeRect', 'fill', 'stroke',
|
|
322
|
+
'beginPath', 'closePath', 'moveTo', 'lineTo', 'arc', 'arcTo',
|
|
323
|
+
'bezierCurveTo', 'quadraticCurveTo', 'ellipse', 'clip', 'save',
|
|
324
|
+
'restore', 'translate', 'rotate', 'scale', 'setTransform',
|
|
325
|
+
'transform', 'resetTransform', 'fillText', 'strokeText'
|
|
326
|
+
]
|
|
327
|
+
methodOperations.forEach((method) => {
|
|
328
|
+
context[method] = (...args) => enqueueCall(method, args)
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
const createGradient = (kind, args) => {
|
|
332
|
+
const resource = {
|
|
333
|
+
__upCanvasResource: true,
|
|
334
|
+
type: 'gradient',
|
|
335
|
+
id: nextResourceId('gradient'),
|
|
336
|
+
kind,
|
|
337
|
+
args,
|
|
338
|
+
stops: [],
|
|
339
|
+
addColorStop(offset, color) {
|
|
340
|
+
this.stops.push([Number(offset), String(color)])
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return resource
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const imageSource = (source) => {
|
|
347
|
+
if (typeof source === 'string') return source
|
|
348
|
+
if (source && typeof source.src === 'string') return source.src
|
|
349
|
+
throw new Error('Canvas image source must be a string')
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const createImageResource = (source) => ({
|
|
353
|
+
__upCanvasResource: true,
|
|
354
|
+
type: 'image',
|
|
355
|
+
id: nextResourceId('image'),
|
|
356
|
+
source: Promise.resolve().then(() => resolveImage(imageSource(source)))
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
const snapshotResources = (resourceMap) => Object.keys(resourceMap).map((id) => {
|
|
360
|
+
const resource = resourceMap[id]
|
|
361
|
+
if (resource.type === 'gradient') {
|
|
362
|
+
return Promise.resolve({
|
|
363
|
+
type: 'gradient',
|
|
364
|
+
id: resource.id,
|
|
365
|
+
kind: resource.kind,
|
|
366
|
+
args: resource.args.slice(),
|
|
367
|
+
stops: resource.stops.map(stop => stop.slice())
|
|
368
|
+
})
|
|
369
|
+
}
|
|
370
|
+
if (resource.type === 'image') {
|
|
371
|
+
return resource.source.then(src => ({ type: 'image', id: resource.id, src }))
|
|
372
|
+
}
|
|
373
|
+
if (resource.type === 'pattern') {
|
|
374
|
+
return resource.source.then(source => ({
|
|
375
|
+
type: 'pattern',
|
|
376
|
+
id: resource.id,
|
|
377
|
+
source,
|
|
378
|
+
repetition: resource.repetition
|
|
379
|
+
}))
|
|
380
|
+
}
|
|
381
|
+
return Promise.reject(new Error(`Unsupported Canvas resource: ${resource.type}`))
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
context.createLinearGradient = (...args) => createGradient('linear', args)
|
|
385
|
+
context.createRadialGradient = (...args) => createGradient('radial', args)
|
|
386
|
+
context.createConicGradient = (...args) => createGradient('conic', args)
|
|
387
|
+
context.createPattern = (source, repetition = 'repeat') => ({
|
|
388
|
+
__upCanvasResource: true,
|
|
389
|
+
type: 'pattern',
|
|
390
|
+
id: nextResourceId('pattern'),
|
|
391
|
+
source: Promise.resolve().then(() => resolveImage(imageSource(source))),
|
|
392
|
+
repetition
|
|
393
|
+
})
|
|
394
|
+
context.drawImage = (source, ...args) => {
|
|
395
|
+
const resource = source && source.__upCanvasResource
|
|
396
|
+
? source
|
|
397
|
+
: createImageResource(source)
|
|
398
|
+
enqueueCall('drawImage', [resource, ...args])
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
context.setFillStyle = value => { context.fillStyle = value }
|
|
402
|
+
context.setStrokeStyle = value => { context.strokeStyle = value }
|
|
403
|
+
context.setLineWidth = value => { context.lineWidth = value }
|
|
404
|
+
context.setLineCap = value => { context.lineCap = value }
|
|
405
|
+
context.setLineJoin = value => { context.lineJoin = value }
|
|
406
|
+
context.setTextAlign = value => { context.textAlign = value }
|
|
407
|
+
context.setTextBaseline = value => { context.textBaseline = value }
|
|
408
|
+
context.setGlobalAlpha = value => { context.globalAlpha = value }
|
|
409
|
+
context.setMiterLimit = value => { context.miterLimit = value }
|
|
410
|
+
context.setGlobalCompositeOperation = value => { context.globalCompositeOperation = value }
|
|
411
|
+
context.setFont = value => { context.font = value }
|
|
412
|
+
context.setFontSize = value => {
|
|
413
|
+
const size = Number(value) || 10
|
|
414
|
+
context.font = /\d+(?:\.\d+)?px/.test(state.font)
|
|
415
|
+
? state.font.replace(/\d+(?:\.\d+)?px/, `${size}px`)
|
|
416
|
+
: `${size}px sans-serif`
|
|
417
|
+
}
|
|
418
|
+
context.setShadow = (offsetX, offsetY, blur, color) => {
|
|
419
|
+
context.shadowOffsetX = offsetX
|
|
420
|
+
context.shadowOffsetY = offsetY
|
|
421
|
+
context.shadowBlur = blur
|
|
422
|
+
context.shadowColor = color
|
|
423
|
+
}
|
|
424
|
+
context.setLineDash = (segments) => {
|
|
425
|
+
state.lineDash = Array.isArray(segments) ? segments.slice() : []
|
|
426
|
+
enqueueCall('setLineDash', [state.lineDash])
|
|
427
|
+
}
|
|
428
|
+
context.getLineDash = () => state.lineDash.slice()
|
|
429
|
+
|
|
430
|
+
context.measureText = text => measureTextFallback(String(text), state)
|
|
431
|
+
context.measureTextAsync = text => bridge.request('measureText', {
|
|
432
|
+
text: String(text),
|
|
433
|
+
font: state.font
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
context.draw = (reserve = false, callback) => {
|
|
437
|
+
const batchCommands = commands
|
|
438
|
+
const batchResources = resources
|
|
439
|
+
commands = []
|
|
440
|
+
resources = Object.create(null)
|
|
441
|
+
const execute = async () => {
|
|
442
|
+
const definitions = await Promise.all(snapshotResources(batchResources))
|
|
443
|
+
return bridge.request('draw', {
|
|
444
|
+
reserve: !!reserve,
|
|
445
|
+
commands: batchCommands,
|
|
446
|
+
resources: definitions
|
|
447
|
+
})
|
|
448
|
+
}
|
|
449
|
+
const operation = drawTail.then(execute, execute)
|
|
450
|
+
drawTail = operation.catch(() => {})
|
|
451
|
+
lastDraw = operation
|
|
452
|
+
if (typeof callback === 'function') operation.then(result => callback(result))
|
|
453
|
+
return operation
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
context.toTempFilePath = (options = {}) => withCallbacks(
|
|
457
|
+
lastDraw.then(() => bridge.request('export', cloneOptions(options))),
|
|
458
|
+
options
|
|
459
|
+
)
|
|
460
|
+
context.getImageData = (...args) => {
|
|
461
|
+
const options = normalizeImageDataArgs(args)
|
|
462
|
+
return withCallbacks(
|
|
463
|
+
lastDraw.then(() => bridge.request('getImageData', cloneOptions(options))),
|
|
464
|
+
options
|
|
465
|
+
)
|
|
466
|
+
}
|
|
467
|
+
context.putImageData = (...args) => {
|
|
468
|
+
const options = normalizePutImageDataArgs(args)
|
|
469
|
+
const payload = cloneOptions(options)
|
|
470
|
+
if (payload.data && payload.data.data) {
|
|
471
|
+
payload.data = {
|
|
472
|
+
width: payload.data.width,
|
|
473
|
+
height: payload.data.height,
|
|
474
|
+
data: Array.from(payload.data.data)
|
|
475
|
+
}
|
|
476
|
+
} else if (payload.data && !Array.isArray(payload.data)) {
|
|
477
|
+
payload.data = Array.from(payload.data)
|
|
478
|
+
}
|
|
479
|
+
return withCallbacks(
|
|
480
|
+
lastDraw.then(() => bridge.request('putImageData', payload)),
|
|
481
|
+
options
|
|
482
|
+
)
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return context
|
|
486
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
const isWeex = typeof WXEnvironment !== 'undefined';
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const weexPlatform = isWeex ? String(WXEnvironment.platform || '').toLowerCase() : '';
|
|
3
|
+
const isWeexIOS = isWeex && weexPlatform.indexOf('ios') !== -1;
|
|
4
|
+
// 显式识别鸿蒙,避免被静态检查判定为未适配,且防止仅按 !ios 归入 Android
|
|
5
|
+
const isWeexHarmony = isWeex && (weexPlatform.indexOf('harmony') !== -1 || weexPlatform.indexOf('ohos') !== -1);
|
|
6
|
+
const isWeexAndroid = isWeex && !isWeexIOS && !isWeexHarmony;
|
|
7
|
+
// 鸿蒙 weex 与 Android 共用非 iOS native bridge 路径
|
|
8
|
+
const isWeexAndroidLike = isWeexAndroid || isWeexHarmony;
|
|
4
9
|
|
|
5
10
|
import GLmethod from '../context-webgl/GLmethod';
|
|
6
11
|
|
|
@@ -184,7 +189,7 @@ const GBridge = {
|
|
|
184
189
|
+ format + ',' + type + ',' + (image ? image.src : 0)
|
|
185
190
|
)
|
|
186
191
|
}
|
|
187
|
-
} else if (
|
|
192
|
+
} else if (isWeexAndroidLike) {
|
|
188
193
|
if (args.length === 6) {
|
|
189
194
|
const [target, level, internalformat, format, type, image] = args;
|
|
190
195
|
GCanvasModule.texImage2D(componentId, target, level, internalformat, format, type, image.src);
|
|
@@ -203,7 +208,7 @@ const GBridge = {
|
|
|
203
208
|
GLmethod.texSubImage2D + ',' + 6 + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset, + ',' + format + ',' + type + ',' + image.src
|
|
204
209
|
)
|
|
205
210
|
}
|
|
206
|
-
} else if (
|
|
211
|
+
} else if (isWeexAndroidLike) {
|
|
207
212
|
GCanvasModule.texSubImage2D(componentId, target, level, xoffset, yoffset, format, type, image.src);
|
|
208
213
|
}
|
|
209
214
|
},
|
|
@@ -213,9 +218,7 @@ const GBridge = {
|
|
|
213
218
|
},
|
|
214
219
|
|
|
215
220
|
perloadImage([url, id], callback) {
|
|
216
|
-
console.log('********************asda**********')
|
|
217
221
|
GCanvasModule.preLoadImage([url, id], function (image) {
|
|
218
|
-
console.log('********************asda2**********')
|
|
219
222
|
image.url = url;
|
|
220
223
|
image.id = id;
|
|
221
224
|
callback(image);
|
|
@@ -239,4 +242,4 @@ const GBridge = {
|
|
|
239
242
|
}
|
|
240
243
|
}
|
|
241
244
|
|
|
242
|
-
export default GBridge;
|
|
245
|
+
export default GBridge;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -10,7 +10,7 @@ export let Image = GImage;
|
|
|
10
10
|
|
|
11
11
|
export let WeexBridge = GBridgeWeex;
|
|
12
12
|
|
|
13
|
-
export function enable(el, { bridge, debug, disableAutoSwap, disableComboCommands } = {}) {
|
|
13
|
+
export function enable(el, { bridge, debug, disableAutoSwap, disableComboCommands, clearColor = 'white' } = {}) {
|
|
14
14
|
|
|
15
15
|
const GBridge = GImage.GBridge = GCanvas.GBridge = GWebGLRenderingContext.GBridge = GContext2D.GBridge = bridge;
|
|
16
16
|
|
|
@@ -20,7 +20,7 @@ export function enable(el, { bridge, debug, disableAutoSwap, disableComboCommand
|
|
|
20
20
|
false, // supportScroll
|
|
21
21
|
false, // newCanvasMode
|
|
22
22
|
1, // compatible
|
|
23
|
-
|
|
23
|
+
clearColor,// clearColor
|
|
24
24
|
false // sameLevel: newCanvasMode = true && true => GCanvasView and Webview is same level
|
|
25
25
|
]);
|
|
26
26
|
|
|
@@ -36,4 +36,4 @@ export function enable(el, { bridge, debug, disableAutoSwap, disableComboCommand
|
|
|
36
36
|
canvas.height = el.style.height;
|
|
37
37
|
|
|
38
38
|
return canvas;
|
|
39
|
-
};
|
|
39
|
+
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "uview-plus",
|
|
3
3
|
"name": "uview-plus",
|
|
4
4
|
"displayName": "零云®uview-plus3.0重磅发布,全面的Vue3鸿蒙跨端移动组件库,组件丰富维护更新稳定。",
|
|
5
|
-
"version": "3.8.
|
|
5
|
+
"version": "3.8.106",
|
|
6
6
|
"description": "零云®uview-plus已兼容vue3支持多语言,120+全面的组件和便捷的工具会让您信手拈来。近期新增拖动排序、条码、图片裁剪、下拉刷新、虚拟列表、签名、Markdown等。",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"uview",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"echarts",
|
|
12
12
|
"ui",
|
|
13
13
|
"可视化"
|
|
14
|
-
],
|
|
14
|
+
],
|
|
15
15
|
"main": "index.js",
|
|
16
16
|
"repository": "https://github.com/ijry/uview-plus",
|
|
17
17
|
"engines": {
|
|
@@ -102,9 +102,8 @@
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
},
|
|
105
|
-
"dependencies": {
|
|
106
|
-
},
|
|
105
|
+
"dependencies": {},
|
|
107
106
|
"publishConfig": {
|
|
108
107
|
"registry": "https://registry.npmjs.org/"
|
|
109
108
|
}
|
|
110
|
-
}
|
|
109
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"sourceMap": true,
|
|
4
|
+
"jsx": "preserve",
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleResolution": "Node",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"useDefineForClassFields": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"lib": ["esnext", "dom"]
|
|
16
|
+
},
|
|
17
|
+
"include": ["./**/*.ts", "./**/*.d.ts", "./**/*.tsx", "./**/*.vue", "./**/*.nvue"]
|
|
18
|
+
}
|