@doubao-dev/taro-runtime 0.9.1 → 0.10.0
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/README.md +117 -0
- package/assets/refresh-loading.png +0 -0
- package/dist/api/base/can-i-use.d.ts +3 -0
- package/dist/api/base/can-i-use.js +12 -0
- package/dist/api/base/event-center.d.ts +12 -0
- package/dist/api/base/event-center.js +52 -0
- package/dist/api/base/index.d.ts +1 -1
- package/dist/api/base/index.js +1 -1
- package/dist/api/base/next-tick.d.ts +3 -0
- package/dist/api/base/next-tick.js +11 -0
- package/dist/api/canvas/index.d.ts +17 -0
- package/dist/api/canvas/index.js +29 -0
- package/dist/api/create-animation.d.ts +47 -0
- package/dist/api/create-animation.js +98 -0
- package/dist/api/create-intersection-observer/index.d.ts +7 -0
- package/dist/api/create-intersection-observer/index.js +126 -0
- package/dist/api/create-selector-query/index.js +284 -109
- package/dist/api/device/accelerometer.js +1 -1
- package/dist/api/device/accessibility.js +1 -1
- package/dist/api/device/battery.js +1 -1
- package/dist/api/device/beacon.js +1 -1
- package/dist/api/device/bluetooth.js +1 -1
- package/dist/api/device/clipboard.js +1 -1
- package/dist/api/device/compass.js +1 -1
- package/dist/api/device/crypto.js +1 -1
- package/dist/api/device/device-motion.js +1 -1
- package/dist/api/device/gyroscope.js +1 -1
- package/dist/api/device/keyboard.js +1 -1
- package/dist/api/device/scan.js +1 -1
- package/dist/api/device/screen.js +1 -1
- package/dist/api/device/sms.js +1 -1
- package/dist/api/device/vibration.js +1 -1
- package/dist/api/device/wifi.js +1 -1
- package/dist/api/index.d.ts +8 -1
- package/dist/api/index.js +8 -1
- package/dist/api/interaction/index.js +1 -1
- package/dist/api/location/index.d.ts +2 -2
- package/dist/api/location/index.js +1 -1
- package/dist/api/media/image.d.ts +9 -0
- package/dist/api/media/image.js +21 -1
- package/dist/api/media/index.d.ts +2 -0
- package/dist/api/media/index.js +2 -0
- package/dist/api/media/inner-audio.d.ts +5 -0
- package/dist/api/media/inner-audio.js +7 -0
- package/dist/api/media/media.d.ts +6 -0
- package/dist/api/media/media.js +9 -0
- package/dist/api/px-transform.d.ts +11 -0
- package/dist/api/px-transform.js +31 -0
- package/dist/api/request/index.js +1 -1
- package/dist/api/request/websocket.js +1 -1
- package/dist/api/router/current-instance.d.ts +17 -0
- package/dist/api/router/current-instance.js +28 -0
- package/dist/api/router/exit-mini-program.js +1 -1
- package/dist/api/router/get-current-pages.d.ts +13 -1
- package/dist/api/router/get-current-pages.js +5 -3
- package/dist/api/router/index.d.ts +1 -0
- package/dist/api/router/index.js +1 -0
- package/dist/api/router/navigate-back.js +1 -1
- package/dist/api/router/navigate-to.js +1 -1
- package/dist/api/router/re-launch.js +1 -1
- package/dist/api/router/redirect-to.js +1 -1
- package/dist/api/runtime/download.d.ts +11 -0
- package/dist/api/runtime/download.js +18 -0
- package/dist/api/runtime/resize.d.ts +7 -0
- package/dist/api/runtime/resize.js +26 -0
- package/dist/api/runtime/system.d.ts +8 -0
- package/dist/api/runtime/system.js +10 -0
- package/dist/api/show-toast/index.js +1 -1
- package/dist/api/storage/index.d.ts +1 -1
- package/dist/api/storage/index.js +1 -1
- package/dist/api/system/index.js +1 -1
- package/dist/components/Block/index.d.ts +3 -0
- package/dist/components/Block/index.jsx +4 -0
- package/dist/components/Button/index.d.ts +7 -0
- package/dist/components/Button/index.jsx +28 -0
- package/dist/components/Canvas/index.d.ts +4 -0
- package/dist/components/Canvas/index.jsx +25 -0
- package/dist/components/Checkbox/index.d.ts +3 -0
- package/dist/components/Checkbox/index.jsx +17 -0
- package/dist/components/CheckboxGroup/index.d.ts +3 -0
- package/dist/components/CheckboxGroup/index.jsx +13 -0
- package/dist/components/CoverView/index.d.ts +6 -1
- package/dist/components/CoverView/index.js +5 -1
- package/dist/components/Form/index.d.ts +4 -0
- package/dist/components/Form/index.jsx +39 -0
- package/dist/components/Form/use-form-field.d.ts +5 -0
- package/dist/components/Form/use-form-field.js +40 -0
- package/dist/components/Icon/index.d.ts +3 -0
- package/dist/components/Icon/index.jsx +40 -0
- package/dist/components/Image/index.d.ts +3 -1
- package/dist/components/Image/index.jsx +15 -4
- package/dist/components/Input/index.d.ts +1 -1
- package/dist/components/Input/index.jsx +9 -5
- package/dist/components/Input/map.d.ts +1 -1
- package/dist/components/Label/control.d.ts +6 -0
- package/dist/components/Label/control.js +29 -0
- package/dist/components/Label/index.d.ts +3 -0
- package/dist/components/Label/index.jsx +15 -0
- package/dist/components/LivePlayer/index.d.ts +3 -0
- package/dist/components/LivePlayer/index.jsx +8 -0
- package/dist/components/Map/bridge.d.ts +1 -1
- package/dist/components/Map/index.jsx +10 -6
- package/dist/components/Movable/index.d.ts +4 -0
- package/dist/components/Movable/index.jsx +26 -0
- package/dist/components/NavigationBar/index.d.ts +3 -0
- package/dist/components/NavigationBar/index.jsx +16 -0
- package/dist/components/Navigator/index.d.ts +3 -0
- package/dist/components/Navigator/index.jsx +32 -0
- package/dist/components/OpenData/index.d.ts +3 -0
- package/dist/components/OpenData/index.js +4 -0
- package/dist/components/Picker/index.d.ts +6 -0
- package/dist/components/Picker/index.jsx +155 -0
- package/dist/components/Picker/popup.d.ts +18 -0
- package/dist/components/Picker/popup.jsx +105 -0
- package/dist/components/PickerView/index.d.ts +1 -1
- package/dist/components/PickerView/index.jsx +1 -1
- package/dist/components/PickerView/map.d.ts +1 -1
- package/dist/components/Progress/index.d.ts +3 -0
- package/dist/components/Progress/index.jsx +14 -0
- package/dist/components/Radio/index.jsx +9 -5
- package/dist/components/Radio/shared.d.ts +1 -1
- package/dist/components/RadioGroup/context.js +1 -1
- package/dist/components/RadioGroup/index.jsx +8 -4
- package/dist/components/RadioGroup/map.d.ts +1 -1
- package/dist/components/RichText/index.d.ts +3 -0
- package/dist/components/RichText/index.jsx +7 -0
- package/dist/components/ScrollView/index.d.ts +4 -1
- package/dist/components/ScrollView/index.jsx +44 -14
- package/dist/components/ScrollView/map.d.ts +4 -2
- package/dist/components/ScrollView/map.js +19 -1
- package/dist/components/ScrollView/refresh-types.d.ts +25 -0
- package/dist/components/ScrollView/refresh-types.js +2 -0
- package/dist/components/ScrollView/refresh.d.ts +10 -0
- package/dist/components/ScrollView/refresh.jsx +29 -0
- package/dist/components/ScrollView/use-refresher.d.ts +19 -0
- package/dist/components/ScrollView/use-refresher.js +214 -0
- package/dist/components/Slider/index.d.ts +3 -0
- package/dist/components/Slider/index.jsx +13 -0
- package/dist/components/Swiper/index.d.ts +3 -0
- package/dist/components/Swiper/index.jsx +79 -0
- package/dist/components/SwiperItem/index.d.ts +3 -0
- package/dist/components/SwiperItem/index.jsx +18 -0
- package/dist/components/Switch/index.d.ts +3 -0
- package/dist/components/Switch/index.jsx +32 -0
- package/dist/components/Text/format.d.ts +5 -0
- package/dist/components/Text/format.js +51 -0
- package/dist/components/Text/index.d.ts +4 -3
- package/dist/components/Text/index.jsx +3 -2
- package/dist/components/Text/map.js +9 -4
- package/dist/components/Textarea/index.d.ts +3 -0
- package/dist/components/Textarea/index.jsx +30 -0
- package/dist/components/Video/index.d.ts +3 -0
- package/dist/components/Video/index.jsx +22 -0
- package/dist/components/View/index.d.ts +5 -5
- package/dist/components/View/index.jsx +11 -13
- package/dist/components/View/map.js +5 -0
- package/dist/components/base/change-event.d.ts +18 -0
- package/dist/components/base/change-event.js +13 -0
- package/dist/components/base/wrap-text-node.d.ts +3 -0
- package/dist/components/base/wrap-text-node.jsx +34 -0
- package/dist/components/index.d.ts +24 -1
- package/dist/components/index.js +24 -1
- package/dist/exports/app.d.ts +2 -1
- package/dist/exports/app.js +3 -1
- package/dist/exports/common.d.ts +1 -0
- package/dist/exports/common.js +1 -0
- package/dist/exports/view-core.d.ts +2 -1
- package/dist/exports/view-core.js +2 -1
- package/dist/exports/view.d.ts +2 -1
- package/dist/exports/view.js +3 -1
- package/dist/hooks/lifecycle/app.js +1 -1
- package/dist/hooks/use-animation.d.ts +9 -0
- package/dist/hooks/use-animation.js +151 -0
- package/dist/internal/class-components.d.ts +11 -0
- package/dist/internal/class-components.js +42 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +1 -0
- package/dist/internal/map-context/index.d.ts +1 -1
- package/dist/internal/query-node.d.ts +9 -0
- package/dist/internal/query-node.js +35 -0
- package/dist/internal/selector-id.d.ts +6 -0
- package/dist/internal/selector-id.js +18 -0
- package/dist/react.d.ts +4 -0
- package/dist/react.js +4 -0
- package/package.json +23 -1
|
@@ -1,30 +1,77 @@
|
|
|
1
|
+
import { runOnMainThread } from '@lynx-js/react';
|
|
2
|
+
import { getMapController } from '../../internal/map-context/index.js';
|
|
3
|
+
import { getQueryCanvas, getQueryNodeProperties } from '../../internal/query-node.js';
|
|
4
|
+
import { getSelectorIdFallback } from '../../internal/selector-id.js';
|
|
5
|
+
import { createMapContext } from '../map/index.js';
|
|
1
6
|
import { getWindowInfo } from '../system/index.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const UNSUPPORTED_NODE = 'createSelectorQuery.node()';
|
|
7
|
+
function warnUnsupported(feature) {
|
|
8
|
+
console.warn(`[createSelectorQuery] unsupported: ${feature}`);
|
|
9
|
+
}
|
|
6
10
|
const UNSUPPORTED_FIELDS_COMPUTED_STYLE = 'createSelectorQuery.fields.computedStyle';
|
|
7
|
-
const UNSUPPORTED_FIELDS_PROPERTIES = 'createSelectorQuery.fields.properties';
|
|
8
|
-
const UNSUPPORTED_FIELDS_MARK = 'createSelectorQuery.fields.mark';
|
|
9
11
|
const UNSUPPORTED_FIELDS_CONTEXT = 'createSelectorQuery.fields.context';
|
|
10
|
-
const UNSUPPORTED_FIELDS_NODE = 'createSelectorQuery.fields.node';
|
|
11
12
|
const UNSUPPORTED_VIEWPORT_SCROLL_OFFSET = 'createSelectorQuery.selectViewport().scrollOffset';
|
|
12
13
|
const UNSUPPORTED_SCROLL_OFFSET = 'createSelectorQuery.scrollOffset (node is not a supported scroll container)';
|
|
14
|
+
function normalizeSelector(selector) {
|
|
15
|
+
if (typeof __DOUBAO_APPS_WEB__ !== 'undefined' && __DOUBAO_APPS_WEB__) {
|
|
16
|
+
// Web Core delegates to DOM selectors. Preserve descendant matching for Taro's deep combinator.
|
|
17
|
+
return selector.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\\.|\s*>>>\s*/g, (token) => token.trim() === '>>>' ? ' ' : token);
|
|
18
|
+
}
|
|
19
|
+
return selector;
|
|
20
|
+
}
|
|
21
|
+
function isUniqueId(value) {
|
|
22
|
+
return ((typeof value === 'number' || (typeof value === 'string' && /^\d+$/.test(value))) &&
|
|
23
|
+
Number.isSafeInteger(Number(value)) &&
|
|
24
|
+
Number(value) >= 0);
|
|
25
|
+
}
|
|
26
|
+
function resolveRootUniqueId(value) {
|
|
27
|
+
const ref = value;
|
|
28
|
+
if (isUniqueId(ref?.unique_id)) {
|
|
29
|
+
return Promise.resolve(ref.unique_id);
|
|
30
|
+
}
|
|
31
|
+
if (typeof ref?.fields !== 'function') {
|
|
32
|
+
warnUnsupported('createSelectorQuery.in(component) requires a Lynx node ref or unique_id');
|
|
33
|
+
return Promise.resolve(null);
|
|
34
|
+
}
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
ref
|
|
37
|
+
.fields?.({ unique_id: true }, (data) => {
|
|
38
|
+
resolve(isUniqueId(data?.unique_id) ? data.unique_id : null);
|
|
39
|
+
})
|
|
40
|
+
?.exec();
|
|
41
|
+
}).catch(() => null);
|
|
42
|
+
}
|
|
43
|
+
async function createLynxQuery(scope) {
|
|
44
|
+
const query = getLynxRoot()?.createSelectorQuery();
|
|
45
|
+
if (!scope) {
|
|
46
|
+
return query;
|
|
47
|
+
}
|
|
48
|
+
const id = await scope;
|
|
49
|
+
return id === null ? undefined : query?.setRoot?.(id);
|
|
50
|
+
}
|
|
13
51
|
class SelectorQueryAdapter {
|
|
14
52
|
constructor() {
|
|
15
53
|
this.tasks = [];
|
|
16
54
|
}
|
|
17
55
|
select(selector) {
|
|
18
|
-
return new NodesRefAdapter(this, {
|
|
56
|
+
return new NodesRefAdapter(this, {
|
|
57
|
+
kind: 'single',
|
|
58
|
+
selector: normalizeSelector(selector),
|
|
59
|
+
scope: this.scope
|
|
60
|
+
});
|
|
19
61
|
}
|
|
20
62
|
selectAll(selector) {
|
|
21
|
-
return new NodesRefAdapter(this, {
|
|
63
|
+
return new NodesRefAdapter(this, {
|
|
64
|
+
kind: 'multi',
|
|
65
|
+
selector: normalizeSelector(selector),
|
|
66
|
+
scope: this.scope
|
|
67
|
+
});
|
|
22
68
|
}
|
|
23
69
|
selectViewport() {
|
|
24
70
|
return new NodesRefAdapter(this, { kind: 'viewport' });
|
|
25
71
|
}
|
|
26
|
-
in(
|
|
27
|
-
|
|
72
|
+
in(component) {
|
|
73
|
+
const value = component && 'current' in component ? component.current : component;
|
|
74
|
+
this.scope = resolveRootUniqueId(value);
|
|
28
75
|
return this;
|
|
29
76
|
}
|
|
30
77
|
pushTask(task) {
|
|
@@ -41,8 +88,6 @@ class SelectorQueryAdapter {
|
|
|
41
88
|
}
|
|
42
89
|
callback?.(results);
|
|
43
90
|
})();
|
|
44
|
-
// Taro typings declare a NodesRef return value, but exec semantics are fire-and-forget.
|
|
45
|
-
return undefined;
|
|
46
91
|
}
|
|
47
92
|
}
|
|
48
93
|
class NodesRefAdapter {
|
|
@@ -51,7 +96,6 @@ class NodesRefAdapter {
|
|
|
51
96
|
this.target = target;
|
|
52
97
|
}
|
|
53
98
|
boundingClientRect(callback) {
|
|
54
|
-
console.log('boundingClientRect', this.target);
|
|
55
99
|
this.query.pushTask({
|
|
56
100
|
run: () => resolveBoundingClientRect(this.target),
|
|
57
101
|
callback: callback
|
|
@@ -74,30 +118,32 @@ class NodesRefAdapter {
|
|
|
74
118
|
}
|
|
75
119
|
context(callback) {
|
|
76
120
|
this.query.pushTask({
|
|
77
|
-
run:
|
|
121
|
+
run: () => resolveFields(this.target, { context: true }),
|
|
78
122
|
callback: callback
|
|
79
123
|
});
|
|
80
124
|
return this.query;
|
|
81
125
|
}
|
|
82
126
|
node(callback) {
|
|
83
127
|
this.query.pushTask({
|
|
84
|
-
run:
|
|
128
|
+
run: () => resolveFields(this.target, { node: true }),
|
|
85
129
|
callback: callback
|
|
86
130
|
});
|
|
87
131
|
return this.query;
|
|
88
132
|
}
|
|
89
133
|
}
|
|
90
134
|
function getLynxRoot() {
|
|
91
|
-
return lynx;
|
|
135
|
+
return typeof lynx === 'undefined' ? null : lynx;
|
|
92
136
|
}
|
|
93
137
|
async function resolveBoundingClientRect(target) {
|
|
138
|
+
if (target.kind !== 'viewport' && target.scope && (await target.scope) === null) {
|
|
139
|
+
return target.kind === 'multi' ? [] : null;
|
|
140
|
+
}
|
|
94
141
|
if (target.kind === 'viewport') {
|
|
95
142
|
const rect = getViewportRect();
|
|
96
143
|
return createRectPayload(rect, '', {});
|
|
97
144
|
}
|
|
98
145
|
if (target.kind === 'single') {
|
|
99
|
-
const invokeResult = await runSingleInvoke(target.selector, 'boundingClientRect');
|
|
100
|
-
console.log('invokeResult', invokeResult);
|
|
146
|
+
const invokeResult = await runSingleInvoke(target.selector, 'boundingClientRect', undefined, target.scope);
|
|
101
147
|
if (invokeResult.selectorUnsupported) {
|
|
102
148
|
warnUnsupported(`createSelectorQuery selector unsupported: ${target.selector}`);
|
|
103
149
|
return null;
|
|
@@ -105,7 +151,7 @@ async function resolveBoundingClientRect(target) {
|
|
|
105
151
|
if (!invokeResult.data) {
|
|
106
152
|
return null;
|
|
107
153
|
}
|
|
108
|
-
const fieldsResult = await runSingleFields(target.selector, { id: true, dataset: true });
|
|
154
|
+
const fieldsResult = await runSingleFields(target.selector, { id: true, dataset: true }, target.scope);
|
|
109
155
|
if (fieldsResult.selectorUnsupported) {
|
|
110
156
|
warnUnsupported(`createSelectorQuery selector unsupported: ${target.selector}`);
|
|
111
157
|
}
|
|
@@ -113,7 +159,7 @@ async function resolveBoundingClientRect(target) {
|
|
|
113
159
|
const dataset = fieldsResult.selectorUnsupported ? {} : toRecord(fieldsResult.data?.dataset);
|
|
114
160
|
return createRectPayload(invokeResult.data, id, dataset);
|
|
115
161
|
}
|
|
116
|
-
const fieldsResult = await runMultiFields(target.selector, { id: true, dataset: true, query: true });
|
|
162
|
+
const fieldsResult = await runMultiFields(target.selector, { id: true, dataset: true, query: true }, target.scope);
|
|
117
163
|
if (fieldsResult.selectorUnsupported) {
|
|
118
164
|
warnUnsupported(`createSelectorQuery selector unsupported: ${target.selector}`);
|
|
119
165
|
return [];
|
|
@@ -131,31 +177,127 @@ async function resolveBoundingClientRect(target) {
|
|
|
131
177
|
}));
|
|
132
178
|
return rectResults.filter((item) => item !== null);
|
|
133
179
|
}
|
|
180
|
+
function selectMainThreadElements(selector, multiple) {
|
|
181
|
+
'main thread';
|
|
182
|
+
const mainThread = lynx;
|
|
183
|
+
if (multiple) {
|
|
184
|
+
return mainThread.querySelectorAll(selector);
|
|
185
|
+
}
|
|
186
|
+
const element = mainThread.querySelector(selector);
|
|
187
|
+
return element ? [element] : [];
|
|
188
|
+
}
|
|
189
|
+
function styleProperties(keys) {
|
|
190
|
+
return keys.map((key) => [
|
|
191
|
+
key,
|
|
192
|
+
key.startsWith('--') ? key : key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
|
|
193
|
+
]);
|
|
194
|
+
}
|
|
195
|
+
function readElementStyles(element, properties) {
|
|
196
|
+
'main thread';
|
|
197
|
+
const entries = [];
|
|
198
|
+
for (const [key, property] of properties) {
|
|
199
|
+
const value = element.getComputedStyleProperty(property);
|
|
200
|
+
if (typeof value === 'string') {
|
|
201
|
+
entries.push([key, value]);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return Object.fromEntries(entries);
|
|
205
|
+
}
|
|
206
|
+
async function readComputedStyles(selector, multiple, keys) {
|
|
207
|
+
try {
|
|
208
|
+
return await runOnMainThread((selector, multiple, properties) => {
|
|
209
|
+
'main thread';
|
|
210
|
+
return selectMainThreadElements(selector, multiple).map((element) => readElementStyles(element, properties));
|
|
211
|
+
})(selector, multiple, styleProperties(keys));
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
warnUnsupported(UNSUPPORTED_FIELDS_COMPUTED_STYLE);
|
|
215
|
+
return [];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async function readMarks(selector, multiple) {
|
|
219
|
+
try {
|
|
220
|
+
return await runOnMainThread((selector, multiple) => {
|
|
221
|
+
'main thread';
|
|
222
|
+
return selectMainThreadElements(selector, multiple).map((element) => ({
|
|
223
|
+
mark: Object.fromEntries(element
|
|
224
|
+
.getAttributeNames()
|
|
225
|
+
.filter((name) => name.startsWith('mark:') || name.startsWith('data-taro-mark-'))
|
|
226
|
+
.map((name) => [name.replace(/^(mark:|data-taro-mark-)/, ''), element.getAttribute(name)]))
|
|
227
|
+
}));
|
|
228
|
+
})(selector, multiple);
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function readNodeFields(item, fields) {
|
|
235
|
+
const id = item?.id;
|
|
236
|
+
if (typeof id !== 'string' || !id) {
|
|
237
|
+
return {};
|
|
238
|
+
}
|
|
239
|
+
const names = fields.properties?.filter((name) => !/^(?:id$|class(?:Name)?$|style$|ref$|children$|key$|on[A-Z]|bind|catch)/.test(name)) ?? [];
|
|
240
|
+
const node = fields.node ? getQueryCanvas(id) : undefined;
|
|
241
|
+
return {
|
|
242
|
+
...getQueryNodeProperties(id, names),
|
|
243
|
+
...(node ? { node } : {})
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function readNodeContext(node, selector) {
|
|
247
|
+
const queriedId = typeof node?.id === 'string' ? node.id : '';
|
|
248
|
+
// Some native map nodes do not expose an ID to SelectorQuery. An exact ID can
|
|
249
|
+
// still address the mounted map through the same registry as createMapContext.
|
|
250
|
+
const id = queriedId || (selector && /^#[\w-]+$/.test(selector) ? selector.slice(1) : '');
|
|
251
|
+
if (id && getMapController(id)) {
|
|
252
|
+
return { context: createMapContext(id) };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
134
255
|
async function resolveFields(target, fields) {
|
|
135
|
-
|
|
256
|
+
if (target.kind !== 'viewport' && target.scope && (await target.scope) === null) {
|
|
257
|
+
return target.kind === 'multi' ? [] : null;
|
|
258
|
+
}
|
|
259
|
+
const styleKeys = target.kind !== 'viewport' && target.scope ? [] : (fields.computedStyle ?? []);
|
|
136
260
|
const wantsId = fields.id === true;
|
|
137
261
|
const wantsDataset = fields.dataset === true;
|
|
138
262
|
const wantsRect = fields.rect === true;
|
|
139
263
|
const wantsSize = fields.size === true;
|
|
140
264
|
const wantsScrollOffset = fields.scrollOffset === true;
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return getEmptyResult(target);
|
|
145
|
-
}
|
|
146
|
-
return getEmptyResult(target);
|
|
147
|
-
}
|
|
265
|
+
const wantsContext = fields.context === true;
|
|
266
|
+
const wantsNodeFields = wantsContext || fields.node === true || Boolean(fields.properties?.length);
|
|
267
|
+
const hasSupportedFields = wantsId || wantsDataset || wantsRect || wantsSize || wantsScrollOffset || wantsNodeFields;
|
|
148
268
|
if (target.kind === 'viewport') {
|
|
269
|
+
if (wantsContext) {
|
|
270
|
+
warnUnsupported(UNSUPPORTED_FIELDS_CONTEXT);
|
|
271
|
+
}
|
|
272
|
+
if (styleKeys.length > 0) {
|
|
273
|
+
warnUnsupported(UNSUPPORTED_FIELDS_COMPUTED_STYLE);
|
|
274
|
+
}
|
|
149
275
|
return resolveViewportFields(fields);
|
|
150
276
|
}
|
|
277
|
+
const attributes = fields.mark && !target.scope ? await readMarks(target.selector, target.kind === 'multi') : [];
|
|
278
|
+
if (!hasSupportedFields) {
|
|
279
|
+
if (styleKeys.length === 0) {
|
|
280
|
+
return target.kind === 'multi' ? attributes : (attributes[0] ?? null);
|
|
281
|
+
}
|
|
282
|
+
const styles = await readComputedStyles(target.selector, target.kind === 'multi', styleKeys);
|
|
283
|
+
const results = styles.length >= attributes.length
|
|
284
|
+
? styles.map((style, index) => ({ ...attributes[index], ...style }))
|
|
285
|
+
: attributes.map((item, index) => ({ ...item, ...styles[index] }));
|
|
286
|
+
return target.kind === 'multi' ? results : (results[0] ?? attributes[0] ?? null);
|
|
287
|
+
}
|
|
151
288
|
if (target.kind === 'single') {
|
|
152
289
|
const output = {};
|
|
153
|
-
const [baseResult, rectResult, scrollResult] = await Promise.all([
|
|
154
|
-
wantsId || wantsDataset
|
|
155
|
-
? runSingleFields(target.selector, { id: true, dataset:
|
|
290
|
+
const [baseResult, rectResult, scrollResult, styles] = await Promise.all([
|
|
291
|
+
wantsId || wantsDataset || wantsNodeFields
|
|
292
|
+
? runSingleFields(target.selector, { id: true, dataset: wantsDataset }, target.scope)
|
|
156
293
|
: Promise.resolve(null),
|
|
157
|
-
wantsRect || wantsSize
|
|
158
|
-
|
|
294
|
+
wantsRect || wantsSize
|
|
295
|
+
? runSingleInvoke(target.selector, 'boundingClientRect', undefined, target.scope)
|
|
296
|
+
: Promise.resolve(null),
|
|
297
|
+
wantsScrollOffset
|
|
298
|
+
? runSingleInvoke(target.selector, 'getScrollInfo', undefined, target.scope)
|
|
299
|
+
: Promise.resolve(null),
|
|
300
|
+
styleKeys.length ? readComputedStyles(target.selector, false, styleKeys) : []
|
|
159
301
|
]);
|
|
160
302
|
if (baseResult?.selectorUnsupported ||
|
|
161
303
|
rectResult?.selectorUnsupported ||
|
|
@@ -184,21 +326,24 @@ async function resolveFields(target, fields) {
|
|
|
184
326
|
}
|
|
185
327
|
if (wantsScrollOffset) {
|
|
186
328
|
if (scrollResult?.data) {
|
|
187
|
-
output
|
|
188
|
-
output.scrollTop = toNumber(scrollResult.data.scrollTop);
|
|
329
|
+
Object.assign(output, readScrollOffset(scrollResult.data));
|
|
189
330
|
}
|
|
190
331
|
else {
|
|
191
332
|
warnUnsupported(UNSUPPORTED_SCROLL_OFFSET);
|
|
192
333
|
}
|
|
193
334
|
}
|
|
335
|
+
if (wantsContext) {
|
|
336
|
+
Object.assign(output, readNodeContext(baseResult?.data, target.scope ? undefined : target.selector));
|
|
337
|
+
}
|
|
338
|
+
Object.assign(output, readNodeFields(baseResult?.data, fields), attributes[0], styles[0]);
|
|
194
339
|
return Object.keys(output).length > 0 ? output : null;
|
|
195
340
|
}
|
|
196
341
|
const needsQuery = wantsRect || wantsSize || wantsScrollOffset;
|
|
197
342
|
const baseResult = await runMultiFields(target.selector, {
|
|
198
|
-
id: wantsId || wantsDataset || needsQuery,
|
|
343
|
+
id: wantsId || wantsDataset || needsQuery || wantsNodeFields,
|
|
199
344
|
dataset: wantsId || wantsDataset || needsQuery,
|
|
200
345
|
query: needsQuery
|
|
201
|
-
});
|
|
346
|
+
}, target.scope);
|
|
202
347
|
if (baseResult.selectorUnsupported) {
|
|
203
348
|
warnUnsupported(`createSelectorQuery selector unsupported: ${target.selector}`);
|
|
204
349
|
return [];
|
|
@@ -206,8 +351,9 @@ async function resolveFields(target, fields) {
|
|
|
206
351
|
if (baseResult.data.length === 0) {
|
|
207
352
|
return [];
|
|
208
353
|
}
|
|
354
|
+
const styles = styleKeys.length ? await readComputedStyles(target.selector, true, styleKeys) : [];
|
|
209
355
|
let hasScrollOffsetMiss = false;
|
|
210
|
-
const mapped = await Promise.all(baseResult.data.map(async (item) => {
|
|
356
|
+
const mapped = await Promise.all(baseResult.data.map(async (item, index) => {
|
|
211
357
|
const output = {};
|
|
212
358
|
if (wantsId) {
|
|
213
359
|
output.id = toStringOrEmpty(item.id);
|
|
@@ -234,34 +380,70 @@ async function resolveFields(target, fields) {
|
|
|
234
380
|
if (wantsScrollOffset) {
|
|
235
381
|
const scrollResult = await runInvokeFromQueryRoot(item.query, 'getScrollInfo');
|
|
236
382
|
if (scrollResult.data) {
|
|
237
|
-
output
|
|
238
|
-
output.scrollTop = toNumber(scrollResult.data.scrollTop);
|
|
383
|
+
Object.assign(output, readScrollOffset(scrollResult.data));
|
|
239
384
|
}
|
|
240
385
|
else {
|
|
241
386
|
hasScrollOffsetMiss = true;
|
|
242
387
|
}
|
|
243
388
|
}
|
|
389
|
+
if (wantsContext) {
|
|
390
|
+
Object.assign(output, readNodeContext(item));
|
|
391
|
+
}
|
|
392
|
+
Object.assign(output, readNodeFields(item, fields));
|
|
393
|
+
if (attributes.length === baseResult.data.length) {
|
|
394
|
+
Object.assign(output, attributes[index]);
|
|
395
|
+
}
|
|
396
|
+
if (styles.length === baseResult.data.length) {
|
|
397
|
+
Object.assign(output, styles[index]);
|
|
398
|
+
}
|
|
244
399
|
return output;
|
|
245
400
|
}));
|
|
246
401
|
if (wantsScrollOffset && hasScrollOffsetMiss) {
|
|
247
402
|
warnUnsupported(UNSUPPORTED_SCROLL_OFFSET);
|
|
248
403
|
}
|
|
404
|
+
if ((wantsContext || fields.node) &&
|
|
405
|
+
!wantsId &&
|
|
406
|
+
!wantsDataset &&
|
|
407
|
+
!wantsRect &&
|
|
408
|
+
!wantsSize &&
|
|
409
|
+
!wantsScrollOffset &&
|
|
410
|
+
!fields.mark &&
|
|
411
|
+
!fields.properties?.length &&
|
|
412
|
+
!styleKeys.length) {
|
|
413
|
+
return mapped.map((item) => (item.context || item.node ? item : null));
|
|
414
|
+
}
|
|
249
415
|
return mapped;
|
|
250
416
|
}
|
|
417
|
+
function readScrollOffset(data) {
|
|
418
|
+
return {
|
|
419
|
+
scrollLeft: toNumber(data.scrollLeft),
|
|
420
|
+
scrollTop: toNumber(data.scrollTop),
|
|
421
|
+
...(typeof data.scrollWidth === 'number' ? { scrollWidth: data.scrollWidth } : {}),
|
|
422
|
+
...(typeof data.scrollHeight === 'number' ? { scrollHeight: data.scrollHeight } : {})
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
async function readViewportScrollOffset() {
|
|
426
|
+
const isWeb = typeof __DOUBAO_APPS_WEB__ !== 'undefined' && __DOUBAO_APPS_WEB__;
|
|
427
|
+
if (isWeb) {
|
|
428
|
+
const result = await runSingleInvoke('[part="page"]', 'getScrollInfo');
|
|
429
|
+
if (result.data) {
|
|
430
|
+
return readScrollOffset(result.data);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
warnUnsupported(UNSUPPORTED_VIEWPORT_SCROLL_OFFSET);
|
|
434
|
+
return { id: '', dataset: {}, scrollLeft: 0, scrollTop: 0 };
|
|
435
|
+
}
|
|
251
436
|
async function resolveScrollOffset(target) {
|
|
437
|
+
if (target.kind !== 'viewport' && target.scope && (await target.scope) === null) {
|
|
438
|
+
return target.kind === 'multi' ? [] : null;
|
|
439
|
+
}
|
|
252
440
|
if (target.kind === 'viewport') {
|
|
253
|
-
|
|
254
|
-
return {
|
|
255
|
-
id: '',
|
|
256
|
-
dataset: {},
|
|
257
|
-
scrollLeft: 0,
|
|
258
|
-
scrollTop: 0
|
|
259
|
-
};
|
|
441
|
+
return readViewportScrollOffset();
|
|
260
442
|
}
|
|
261
443
|
if (target.kind === 'single') {
|
|
262
444
|
const [fieldsResult, invokeResult] = await Promise.all([
|
|
263
|
-
runSingleFields(target.selector, { id: true, dataset: true }),
|
|
264
|
-
runSingleInvoke(target.selector, 'getScrollInfo')
|
|
445
|
+
runSingleFields(target.selector, { id: true, dataset: true }, target.scope),
|
|
446
|
+
runSingleInvoke(target.selector, 'getScrollInfo', undefined, target.scope)
|
|
265
447
|
]);
|
|
266
448
|
if (fieldsResult.selectorUnsupported || invokeResult.selectorUnsupported) {
|
|
267
449
|
warnUnsupported(`createSelectorQuery selector unsupported: ${target.selector}`);
|
|
@@ -274,11 +456,10 @@ async function resolveScrollOffset(target) {
|
|
|
274
456
|
return {
|
|
275
457
|
id: toStringOrEmpty(fieldsResult.data?.id),
|
|
276
458
|
dataset: toRecord(fieldsResult.data?.dataset),
|
|
277
|
-
|
|
278
|
-
scrollTop: toNumber(invokeResult.data.scrollTop)
|
|
459
|
+
...readScrollOffset(invokeResult.data)
|
|
279
460
|
};
|
|
280
461
|
}
|
|
281
|
-
const fieldsResult = await runMultiFields(target.selector, { id: true, dataset: true, query: true });
|
|
462
|
+
const fieldsResult = await runMultiFields(target.selector, { id: true, dataset: true, query: true }, target.scope);
|
|
282
463
|
if (fieldsResult.selectorUnsupported) {
|
|
283
464
|
warnUnsupported(`createSelectorQuery selector unsupported: ${target.selector}`);
|
|
284
465
|
return [];
|
|
@@ -296,8 +477,7 @@ async function resolveScrollOffset(target) {
|
|
|
296
477
|
return {
|
|
297
478
|
id: toStringOrEmpty(item.id),
|
|
298
479
|
dataset: toRecord(item.dataset),
|
|
299
|
-
|
|
300
|
-
scrollTop: toNumber(invokeResult.data.scrollTop)
|
|
480
|
+
...readScrollOffset(invokeResult.data)
|
|
301
481
|
};
|
|
302
482
|
}));
|
|
303
483
|
if (hasMiss) {
|
|
@@ -305,11 +485,7 @@ async function resolveScrollOffset(target) {
|
|
|
305
485
|
}
|
|
306
486
|
return results.filter((item) => item !== null);
|
|
307
487
|
}
|
|
308
|
-
function
|
|
309
|
-
warnUnsupported(feature);
|
|
310
|
-
return getEmptyResult(target);
|
|
311
|
-
}
|
|
312
|
-
function resolveViewportFields(fields) {
|
|
488
|
+
async function resolveViewportFields(fields) {
|
|
313
489
|
const output = {};
|
|
314
490
|
const rect = getViewportRect();
|
|
315
491
|
if (fields.id === true) {
|
|
@@ -329,42 +505,10 @@ function resolveViewportFields(fields) {
|
|
|
329
505
|
output.height = rect.height;
|
|
330
506
|
}
|
|
331
507
|
if (fields.scrollOffset === true) {
|
|
332
|
-
|
|
333
|
-
output.scrollLeft = 0;
|
|
334
|
-
output.scrollTop = 0;
|
|
335
|
-
if (fields.id !== true) {
|
|
336
|
-
output.id = '';
|
|
337
|
-
}
|
|
338
|
-
if (fields.dataset !== true) {
|
|
339
|
-
output.dataset = {};
|
|
340
|
-
}
|
|
508
|
+
Object.assign(output, await readViewportScrollOffset());
|
|
341
509
|
}
|
|
342
510
|
return Object.keys(output).length > 0 ? output : null;
|
|
343
511
|
}
|
|
344
|
-
function markUnsupportedFields(fields) {
|
|
345
|
-
let hasUnsupported = false;
|
|
346
|
-
if (Array.isArray(fields.computedStyle) && fields.computedStyle.length > 0) {
|
|
347
|
-
hasUnsupported = true;
|
|
348
|
-
warnUnsupported(UNSUPPORTED_FIELDS_COMPUTED_STYLE);
|
|
349
|
-
}
|
|
350
|
-
if (Array.isArray(fields.properties) && fields.properties.length > 0) {
|
|
351
|
-
hasUnsupported = true;
|
|
352
|
-
warnUnsupported(UNSUPPORTED_FIELDS_PROPERTIES);
|
|
353
|
-
}
|
|
354
|
-
if (fields.mark === true) {
|
|
355
|
-
hasUnsupported = true;
|
|
356
|
-
warnUnsupported(UNSUPPORTED_FIELDS_MARK);
|
|
357
|
-
}
|
|
358
|
-
if (fields.context === true) {
|
|
359
|
-
hasUnsupported = true;
|
|
360
|
-
warnUnsupported(UNSUPPORTED_FIELDS_CONTEXT);
|
|
361
|
-
}
|
|
362
|
-
if (fields.node === true) {
|
|
363
|
-
hasUnsupported = true;
|
|
364
|
-
warnUnsupported(UNSUPPORTED_FIELDS_NODE);
|
|
365
|
-
}
|
|
366
|
-
return hasUnsupported;
|
|
367
|
-
}
|
|
368
512
|
function getViewportRect() {
|
|
369
513
|
const info = getWindowInfo();
|
|
370
514
|
const width = toNumber(info.windowWidth, toNumber(info.screenWidth));
|
|
@@ -399,15 +543,28 @@ function createRectPayload(rectLike, id, dataset) {
|
|
|
399
543
|
function getEmptyResult(target) {
|
|
400
544
|
return target.kind === 'multi' ? [] : null;
|
|
401
545
|
}
|
|
402
|
-
async function runSingleFields(selector, fields) {
|
|
403
|
-
const
|
|
404
|
-
if (!
|
|
546
|
+
async function runSingleFields(selector, fields, scope) {
|
|
547
|
+
const result = await querySingleFields(selector, fields, scope);
|
|
548
|
+
if (result.data && (!fields.id || result.data.id)) {
|
|
549
|
+
return result;
|
|
550
|
+
}
|
|
551
|
+
const fallback = getSelectorIdFallback(selector);
|
|
552
|
+
if (!fallback) {
|
|
553
|
+
return result;
|
|
554
|
+
}
|
|
555
|
+
const matched = await querySingleFields(fallback.selector, fields, scope);
|
|
556
|
+
return matched.data
|
|
557
|
+
? { ...matched, data: fields.id ? { ...matched.data, id: fallback.id } : matched.data }
|
|
558
|
+
: result;
|
|
559
|
+
}
|
|
560
|
+
async function querySingleFields(selector, fields, scope) {
|
|
561
|
+
const query = await createLynxQuery(scope);
|
|
562
|
+
if (!query) {
|
|
405
563
|
return { data: null, selectorUnsupported: false };
|
|
406
564
|
}
|
|
407
565
|
return new Promise((resolve) => {
|
|
408
566
|
try {
|
|
409
|
-
|
|
410
|
-
.createSelectorQuery()
|
|
567
|
+
query
|
|
411
568
|
.select(selector)
|
|
412
569
|
.fields(fields, (data, status) => {
|
|
413
570
|
resolve({
|
|
@@ -425,15 +582,31 @@ async function runSingleFields(selector, fields) {
|
|
|
425
582
|
}
|
|
426
583
|
});
|
|
427
584
|
}
|
|
428
|
-
async function runMultiFields(selector, fields) {
|
|
429
|
-
const
|
|
430
|
-
if (
|
|
585
|
+
async function runMultiFields(selector, fields, scope) {
|
|
586
|
+
const result = await queryMultiFields(selector, fields, scope);
|
|
587
|
+
if (result.data.length) {
|
|
588
|
+
return result;
|
|
589
|
+
}
|
|
590
|
+
const fallback = getSelectorIdFallback(selector);
|
|
591
|
+
if (!fallback) {
|
|
592
|
+
return result;
|
|
593
|
+
}
|
|
594
|
+
const matched = await queryMultiFields(fallback.selector, fields, scope);
|
|
595
|
+
return matched.data.length
|
|
596
|
+
? {
|
|
597
|
+
...matched,
|
|
598
|
+
data: fields.id ? matched.data.map((item) => ({ ...item, id: fallback.id })) : matched.data
|
|
599
|
+
}
|
|
600
|
+
: result;
|
|
601
|
+
}
|
|
602
|
+
async function queryMultiFields(selector, fields, scope) {
|
|
603
|
+
const query = await createLynxQuery(scope);
|
|
604
|
+
if (!query) {
|
|
431
605
|
return { data: [], selectorUnsupported: false };
|
|
432
606
|
}
|
|
433
607
|
return new Promise((resolve) => {
|
|
434
608
|
try {
|
|
435
|
-
|
|
436
|
-
.createSelectorQuery()
|
|
609
|
+
query
|
|
437
610
|
.selectAll(selector)
|
|
438
611
|
.fields(fields, (data, status) => {
|
|
439
612
|
resolve({
|
|
@@ -451,15 +624,14 @@ async function runMultiFields(selector, fields) {
|
|
|
451
624
|
}
|
|
452
625
|
});
|
|
453
626
|
}
|
|
454
|
-
async function runSingleInvoke(selector, method, params) {
|
|
455
|
-
const
|
|
456
|
-
if (!
|
|
627
|
+
async function runSingleInvoke(selector, method, params, scope) {
|
|
628
|
+
const query = await createLynxQuery(scope);
|
|
629
|
+
if (!query) {
|
|
457
630
|
return { data: null, selectorUnsupported: false };
|
|
458
631
|
}
|
|
459
632
|
return new Promise((resolve) => {
|
|
460
633
|
try {
|
|
461
|
-
|
|
462
|
-
.createSelectorQuery()
|
|
634
|
+
query
|
|
463
635
|
.select(selector)
|
|
464
636
|
.invoke({
|
|
465
637
|
method,
|
|
@@ -571,7 +743,10 @@ function toRecord(value) {
|
|
|
571
743
|
function toRecordOrNull(value) {
|
|
572
744
|
return value && typeof value === 'object' ? value : null;
|
|
573
745
|
}
|
|
574
|
-
|
|
746
|
+
function createViewSelectorQuery() {
|
|
575
747
|
return new SelectorQueryAdapter();
|
|
576
748
|
}
|
|
749
|
+
export function createSelectorQuery() {
|
|
750
|
+
return createViewSelectorQuery();
|
|
751
|
+
}
|
|
577
752
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as appFrameworkApi from '@
|
|
1
|
+
import * as appFrameworkApi from '@doubao-dev/framework/api';
|
|
2
2
|
import { runCallbackApi } from '../utils.js';
|
|
3
3
|
const accelerometerChangeCallbacks = new Map();
|
|
4
4
|
export async function startAccelerometer(option) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as appFrameworkApi from '@
|
|
1
|
+
import * as appFrameworkApi from '@doubao-dev/framework/api';
|
|
2
2
|
import { buildOkCallbackResult, runTaroApi } from '../utils.js';
|
|
3
3
|
const batteryInfoChangeCallbacks = new Map();
|
|
4
4
|
function buildGetBatteryInfoResult(result) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as appFrameworkApi from '@
|
|
1
|
+
import * as appFrameworkApi from '@doubao-dev/framework/api';
|
|
2
2
|
import { buildOkCallbackResult, runCallbackApi, runTaroApi } from '../utils.js';
|
|
3
3
|
const bluetoothAdapterStateChangeCallbacks = new Map();
|
|
4
4
|
const bluetoothDeviceFoundCallbacks = new Map();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as appFrameworkApi from '@
|
|
1
|
+
import * as appFrameworkApi from '@doubao-dev/framework/api';
|
|
2
2
|
import { runCallbackApi } from '../utils.js';
|
|
3
3
|
const deviceMotionChangeCallbacks = new Map();
|
|
4
4
|
export async function startDeviceMotionListening(option) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as appFrameworkApi from '@
|
|
1
|
+
import * as appFrameworkApi from '@doubao-dev/framework/api';
|
|
2
2
|
import { runCallbackApi } from '../utils.js';
|
|
3
3
|
const gyroscopeChangeCallbacks = new Map();
|
|
4
4
|
export async function startGyroscope(option) {
|