1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16class Font {
17    /**
18     * Construct new instance of Font.
19     * initialize with instanceId.
20     * @param instanceId obtained on the c++ side.
21     * @since 10
22     */
23    constructor(instanceId) {
24        this.instanceId_ = instanceId;
25        this.ohos_font = globalThis.requireNapi('font');
26    }
27    registerFont(options) {
28        __JSScopeUtil__.syncInstanceId(this.instanceId_);
29        this.ohos_font.registerFont(options);
30        __JSScopeUtil__.restoreInstanceId();
31    }
32
33    getSystemFontList() {
34        __JSScopeUtil__.syncInstanceId(this.instanceId_);
35        let arrayResult_ = this.ohos_font.getSystemFontList();
36        __JSScopeUtil__.restoreInstanceId();
37        return arrayResult_;
38    }
39
40    getFontByName(fontName) {
41        __JSScopeUtil__.syncInstanceId(this.instanceId_);
42        let result_ = this.ohos_font.getFontByName(fontName);
43        __JSScopeUtil__.restoreInstanceId();
44        return result_;
45    }
46}
47
48class MediaQuery {
49    /**
50     * Construct new instance of MediaQuery.
51     * initialize with instanceId.
52     * @param instanceId obtained on the c++ side.
53     * @since 10
54     */
55    constructor(instanceId) {
56        this.instanceId_ = instanceId;
57        this.ohos_mediaQuery = globalThis.requireNapi('mediaquery');
58    }
59    matchMediaSync(condition) {
60        __JSScopeUtil__.syncInstanceId(this.instanceId_);
61        let mediaQueryListener = this.ohos_mediaQuery.matchMediaSync(condition);
62        __JSScopeUtil__.restoreInstanceId();
63        return mediaQueryListener;
64    }
65}
66
67class UIInspector {
68    /**
69     * Construct new instance of ArkUIInspector.
70     * initialize with instanceId.
71     * @param instanceId obtained on the c++ side.
72     * @since 10
73     */
74    constructor(instanceId) {
75        this.instanceId_ = instanceId;
76        this.ohos_UIInspector = globalThis.requireNapi('arkui.inspector');
77    }
78    createComponentObserver(id) {
79        __JSScopeUtil__.syncInstanceId(this.instanceId_);
80        let componentObserver = this.ohos_UIInspector.createComponentObserver(id);
81        __JSScopeUtil__.restoreInstanceId();
82        return componentObserver;
83    }
84}
85
86class ComponentSnapshot {
87    constructor(instanceId) {
88        this.instanceId_ = instanceId;
89        this.ohos_componentSnapshot = globalThis.requireNapi('arkui.componentSnapshot');
90    }
91    get(id, callback, options) {
92        __JSScopeUtil__.syncInstanceId(this.instanceId_);
93        if (typeof callback !== 'function') {
94            let promise = this.ohos_componentSnapshot.get(id, callback);
95            __JSScopeUtil__.restoreInstanceId();
96            return promise;
97        } else {
98            this.ohos_componentSnapshot.get(id, callback, options);
99            __JSScopeUtil__.restoreInstanceId();
100        }
101    }
102    createFromBuilder(builder, callback, delay, checkImageStatus, options) {
103        __JSScopeUtil__.syncInstanceId(this.instanceId_);
104        if (typeof callback !== 'function') {
105            let promise = this.ohos_componentSnapshot.createFromBuilder(builder, callback, delay, checkImageStatus);
106            __JSScopeUtil__.restoreInstanceId();
107            return promise;
108        } else {
109            this.ohos_componentSnapshot.createFromBuilder(builder, callback, delay, checkImageStatus, options);
110            __JSScopeUtil__.restoreInstanceId();
111        }
112    }
113    getSync(id, options) {
114        __JSScopeUtil__.syncInstanceId(this.instanceId_);
115        let pixelmap = this.ohos_componentSnapshot.getSync(id, options);
116        __JSScopeUtil__.restoreInstanceId();
117        return pixelmap;
118    }
119}
120
121class DragController {
122    /**
123     * Construct new instance of DragController.
124     * initialize with instanceId.
125     * @param instanceId obtained on the c++ side.
126     * @since 11
127     */
128    constructor(instanceId) {
129        this.instanceId_ = instanceId;
130        this.ohos_dragController = globalThis.requireNapi('arkui.dragController');
131    }
132
133    executeDrag(custom, dragInfo, callback) {
134        __JSScopeUtil__.syncInstanceId(this.instanceId_);
135        if (typeof callback !== 'undefined') {
136            this.ohos_dragController.executeDrag(custom, dragInfo, callback);
137            __JSScopeUtil__.restoreInstanceId();
138        } else {
139            let eventPromise = this.ohos_dragController.executeDrag(custom, dragInfo);
140            __JSScopeUtil__.restoreInstanceId();
141            return eventPromise;
142        }
143    }
144
145    createDragAction(customs, dragInfo) {
146        __JSScopeUtil__.syncInstanceId(this.instanceId_);
147        let dragAction = this.ohos_dragController.createDragAction(customs, dragInfo);
148        __JSScopeUtil__.restoreInstanceId();
149        return dragAction;
150    }
151
152    getDragPreview() {
153        __JSScopeUtil__.syncInstanceId(this.instanceId_);
154        let dragPreview = this.ohos_dragController.getDragPreview();
155        __JSScopeUtil__.restoreInstanceId();
156        return dragPreview;
157    }
158
159    setDragEventStrictReportingEnabled(enable) {
160        __JSScopeUtil__.syncInstanceId(this.instanceId_);
161        JSViewAbstract.setDragEventStrictReportingEnabled(enable);
162        __JSScopeUtil__.restoreInstanceId();
163    }
164}
165
166class UIObserver {
167    constructor(instanceId) {
168        this.instanceId_ = instanceId;
169        this.ohos_observer = globalThis.requireNapi('arkui.observer');
170    }
171    on(...args) {
172        __JSScopeUtil__.syncInstanceId(this.instanceId_);
173        this.ohos_observer.on(...args);
174        __JSScopeUtil__.restoreInstanceId();
175    }
176    off(...args) {
177        __JSScopeUtil__.syncInstanceId(this.instanceId_);
178        this.ohos_observer.off(...args);
179        __JSScopeUtil__.restoreInstanceId();
180    }
181}
182
183class MeasureUtils {
184    /**
185     * Construct new instance of MeasureUtils.
186     * initialize with instanceId.
187     * @param instanceId obtained on the c++ side.
188     * @since 12
189     */
190    constructor(instanceId) {
191        this.instanceId_ = instanceId;
192        this.ohos_measureUtils = globalThis.requireNapi('measure');
193    }
194
195    measureText(options) {
196        __JSScopeUtil__.syncInstanceId(this.instanceId_);
197        let number = this.ohos_measureUtils.measureText(options);
198        __JSScopeUtil__.restoreInstanceId();
199        return number;
200    }
201
202    measureTextSize(options) {
203        __JSScopeUtil__.syncInstanceId(this.instanceId_);
204        let sizeOption = this.ohos_measureUtils.measureTextSize(options);
205        __JSScopeUtil__.restoreInstanceId();
206        return sizeOption;
207    }
208}
209
210class FrameCallback {
211}
212
213class UIContext {
214    /**
215     * Construct new instance of UIContext.
216     * initialize with instanceId.
217     * @param instanceId obtained on the c++ side.
218     * @since 10
219     */
220    constructor(instanceId) {
221        this.instanceId_ = instanceId;
222    }
223
224    getDragController() {
225        this.dragController_ = new DragController(this.instanceId_);
226        return this.dragController_;
227    }
228
229    getFont() {
230        this.font_ = new Font(this.instanceId_);
231        return this.font_;
232    }
233
234    getRouter() {
235        this.router_ = new Router(this.instanceId_);
236        return this.router_;
237    }
238
239    createAnimator(options) {
240        __JSScopeUtil__.syncInstanceId(this.instanceId_);
241        this.animator_ = globalThis.requireNapi('animator');
242        let animatorResult = this.animator_.create(options);
243        __JSScopeUtil__.restoreInstanceId();
244        return animatorResult;
245    }
246
247    getPromptAction() {
248        this.promptAction_ = new PromptAction(this.instanceId_);
249        return this.promptAction_;
250    }
251
252    getMediaQuery() {
253        this.mediaQuery_ = new MediaQuery(this.instanceId_);
254        return this.mediaQuery_;
255    }
256
257    getUIInspector() {
258        this.UIInspector_ = new UIInspector(this.instanceId_);
259        return this.UIInspector_;
260    }
261
262    getFilteredInspectorTree(filter) {
263        __JSScopeUtil__.syncInstanceId(this.instanceId_);
264        if (typeof filter === 'undefined') {
265            let result_ = globalThis.getFilteredInspectorTree();
266            __JSScopeUtil__.restoreInstanceId();
267            return result_;
268        } else {
269            let result_ = globalThis.getFilteredInspectorTree(filter);
270            __JSScopeUtil__.restoreInstanceId();
271            return result_;
272        }
273    }
274
275    getFilteredInspectorTreeById(id, depth, filter) {
276        __JSScopeUtil__.syncInstanceId(this.instanceId_);
277        if (typeof filter === 'undefined') {
278            let result_ = globalThis.getFilteredInspectorTreeById(id, depth);
279            __JSScopeUtil__.restoreInstanceId();
280            return result_;
281        } else {
282            let result_ = globalThis.getFilteredInspectorTreeById(id, depth, filter);
283            __JSScopeUtil__.restoreInstanceId();
284            return result_;
285        }
286    }
287
288    getComponentSnapshot() {
289        this.ComponentSnapshot_ = new ComponentSnapshot(this.instanceId_);
290        return this.ComponentSnapshot_;
291    }
292
293    vp2px(value) {
294        __JSScopeUtil__.syncInstanceId(this.instanceId_);
295        let vp2pxResult = globalThis.vp2px(value);
296        __JSScopeUtil__.restoreInstanceId();
297        return vp2pxResult;
298    }
299
300    px2vp(value) {
301        __JSScopeUtil__.syncInstanceId(this.instanceId_);
302        let px2vpResult = globalThis.px2vp(value);
303        __JSScopeUtil__.restoreInstanceId();
304        return px2vpResult;
305    }
306
307    fp2px(value) {
308        __JSScopeUtil__.syncInstanceId(this.instanceId_);
309        let fp2pxResult = globalThis.fp2px(value);
310        __JSScopeUtil__.restoreInstanceId();
311        return fp2pxResult;
312    }
313
314    px2fp(value) {
315        __JSScopeUtil__.syncInstanceId(this.instanceId_);
316        let px2fpResult = globalThis.px2fp(value);
317        __JSScopeUtil__.restoreInstanceId();
318        return px2fpResult;
319    }
320
321    lpx2px(value) {
322        __JSScopeUtil__.syncInstanceId(this.instanceId_);
323        let lpx2pxResult = globalThis.lpx2px(value);
324        __JSScopeUtil__.restoreInstanceId();
325        return lpx2pxResult;
326    }
327
328    px2lpx(value) {
329        __JSScopeUtil__.syncInstanceId(this.instanceId_);
330        let px2lpxResult = globalThis.px2lpx(value);
331        __JSScopeUtil__.restoreInstanceId();
332        return px2lpxResult;
333    }
334
335    getComponentUtils() {
336        if (this.componentUtils_ == null) {
337            this.componentUtils_ = new ComponentUtils(this.instanceId_);
338        }
339        return this.componentUtils_;
340    }
341
342    getOverlayManager() {
343        this.overlayManager_ = new OverlayManager(this.instanceId_);
344        return this.overlayManager_;
345    }
346
347    animateTo(value, event) {
348        __JSScopeUtil__.syncInstanceId(this.instanceId_);
349        Context.animateTo(value, event);
350        __JSScopeUtil__.restoreInstanceId();
351    }
352
353    showAlertDialog(options) {
354        __JSScopeUtil__.syncInstanceId(this.instanceId_);
355        AlertDialog.show(options);
356        __JSScopeUtil__.restoreInstanceId();
357    }
358
359    showActionSheet(value) {
360        __JSScopeUtil__.syncInstanceId(this.instanceId_);
361        ActionSheet.show(value);
362        __JSScopeUtil__.restoreInstanceId();
363    }
364
365    openBindSheet(content, options, targetId) {
366        let paramErrMsg =
367            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
368            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
369        __JSScopeUtil__.syncInstanceId(this.instanceId_);
370        let argLength = arguments.length;
371        if (argLength < 1 || content === null || content === undefined) {
372            __JSScopeUtil__.restoreInstanceId();
373            return new Promise((resolve, reject) => {
374                reject({ message: paramErrMsg, code: 401 });
375            });
376        }
377        if ((argLength >= 3 && (targetId === null || targetId === undefined))) {
378            __JSScopeUtil__.restoreInstanceId();
379            return new Promise((resolve, reject) => {
380                reject({ message: paramErrMsg, code: 401 });
381            });
382        }
383        let result_;
384        if (argLength === 1) {
385            result_ = Context.openBindSheet(content.getNodePtr());
386        } else if (argLength === 2) {
387            result_ = Context.openBindSheet(content.getNodePtr(), options);
388        } else {
389            result_ = Context.openBindSheet(content.getNodePtr(), options, targetId);
390        }
391        __JSScopeUtil__.restoreInstanceId();
392        return result_;
393    }
394
395    updateBindSheet(content, options, partialUpdate) {
396        let paramErrMsg =
397            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
398            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
399        __JSScopeUtil__.syncInstanceId(this.instanceId_);
400        let argLength = arguments.length;
401        if (argLength < 2 || content === null || content === undefined) {
402            __JSScopeUtil__.restoreInstanceId();
403            return new Promise((resolve, reject) => {
404                reject({ message: paramErrMsg, code: 401 });
405            });
406        }
407        let result_;
408        if (argLength === 2) {
409            result_ = Context.updateBindSheet(content.getNodePtr(), options);
410        } else {
411            result_ = Context.updateBindSheet(content.getNodePtr(), options, partialUpdate);
412        }
413        __JSScopeUtil__.restoreInstanceId();
414        return result_;
415    }
416
417    closeBindSheet(content) {
418        let paramErrMsg =
419            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
420            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
421        __JSScopeUtil__.syncInstanceId(this.instanceId_);
422        if (arguments.length < 1 || content === null || content === undefined) {
423            __JSScopeUtil__.restoreInstanceId();
424            return new Promise((resolve, reject) => {
425                reject({ message: paramErrMsg, code: 401 });
426            });
427        }
428        let result_ = Context.closeBindSheet(content.getNodePtr());
429        __JSScopeUtil__.restoreInstanceId();
430        return result_;
431    }
432
433    showDatePickerDialog(options) {
434        __JSScopeUtil__.syncInstanceId(this.instanceId_);
435        DatePickerDialog.show(options);
436        __JSScopeUtil__.restoreInstanceId();
437    }
438
439    showTimePickerDialog(options) {
440        __JSScopeUtil__.syncInstanceId(this.instanceId_);
441        TimePickerDialog.show(options);
442        __JSScopeUtil__.restoreInstanceId();
443    }
444
445    showTextPickerDialog(options) {
446        __JSScopeUtil__.syncInstanceId(this.instanceId_);
447        TextPickerDialog.show(options);
448        __JSScopeUtil__.restoreInstanceId();
449    }
450
451    runScopedTask(callback) {
452        __JSScopeUtil__.syncInstanceId(this.instanceId_);
453        if (callback !== undefined) {
454            callback();
455        }
456        __JSScopeUtil__.restoreInstanceId();
457    }
458
459    setKeyboardAvoidMode(value) {
460        __JSScopeUtil__.syncInstanceId(this.instanceId_);
461        __KeyboardAvoid__.setKeyboardAvoid(value);
462        __JSScopeUtil__.restoreInstanceId();
463    }
464
465    getKeyboardAvoidMode() {
466        __JSScopeUtil__.syncInstanceId(this.instanceId_);
467        let keyBoardAvoidMode = __KeyboardAvoid__.getKeyboardAvoid();
468        __JSScopeUtil__.restoreInstanceId();
469        return keyBoardAvoidMode;
470    }
471
472    getAtomicServiceBar() {
473        const bundleMgr = globalThis.requireNapi('bundle.bundleManager');
474        if (!bundleMgr || !bundleMgr.BundleFlag) {
475            return undefined;
476        }
477        let data = bundleMgr.getBundleInfoForSelfSync(bundleMgr.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION);
478        if (data.appInfo.bundleType == 1) {
479            this.atomServiceBar = new AtomicServiceBar(this.instanceId_);
480            return this.atomServiceBar;
481        } else {
482            return undefined;
483        }
484    }
485
486    getUIObserver() {
487        this.observer_ = new UIObserver(this.instanceId_);
488        return this.observer_;
489    }
490
491    keyframeAnimateTo(param, keyframes) {
492        __JSScopeUtil__.syncInstanceId(this.instanceId_);
493        Context.keyframeAnimateTo(param, keyframes);
494        __JSScopeUtil__.restoreInstanceId();
495    }
496
497    animateToImmediately(param, event) {
498        __JSScopeUtil__.syncInstanceId(this.instanceId_);
499        Context.animateToImmediately(param, event);
500        __JSScopeUtil__.restoreInstanceId();
501    }
502
503    getMeasureUtils() {
504        this.measureUtils_ = new MeasureUtils(this.instanceId_);
505        return this.measureUtils_;
506    }
507
508    getHostContext() {
509        __JSScopeUtil__.syncInstanceId(this.instanceId_);
510        let context = getContext();
511        __JSScopeUtil__.restoreInstanceId();
512        return context;
513    }
514
515    getSharedLocalStorage() {
516        __JSScopeUtil__.syncInstanceId(this.instanceId_);
517        let localStorage = NativeLocalStorage.GetShared();
518        __JSScopeUtil__.restoreInstanceId();
519        return localStorage;
520    }
521
522    getFrameNodeById(id) {
523        __JSScopeUtil__.syncInstanceId(this.instanceId_);
524        let nodePtr = getUINativeModule().getFrameNodeByKey(id);
525        if (!nodePtr) {
526            __JSScopeUtil__.restoreInstanceId();
527            return null;
528        }
529        let xNode = globalThis.__getArkUINode__();
530        let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr);
531        if (!node) {
532            node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr);
533        }
534        __JSScopeUtil__.restoreInstanceId();
535        return node;
536    }
537
538    getAttachedFrameNodeById(id) {
539        __JSScopeUtil__.syncInstanceId(this.instanceId_);
540        let nodePtr = getUINativeModule().getAttachedFrameNodeById(id);
541        if (!nodePtr) {
542            __JSScopeUtil__.restoreInstanceId();
543            return null;
544        }
545        let xNode = globalThis.__getArkUINode__();
546        let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr);
547        if (!node) {
548            node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr);
549        }
550        __JSScopeUtil__.restoreInstanceId();
551        return node;
552    }
553
554    getFrameNodeByNodeId(id) {
555        __JSScopeUtil__.syncInstanceId(this.instanceId_);
556        let nodePtr = getUINativeModule().getFrameNodeById(id);
557        let xNode = globalThis.__getArkUINode__();
558        let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr);
559        if (!node) {
560            node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr);
561        }
562        __JSScopeUtil__.restoreInstanceId();
563        return node;
564    }
565
566    getFrameNodeByUniqueId(uniqueId) {
567        __JSScopeUtil__.syncInstanceId(this.instanceId_);
568        let nodePtr = getUINativeModule().getFrameNodeByUniqueId(uniqueId);
569        if (nodePtr === undefined) {
570            __JSScopeUtil__.restoreInstanceId();
571            return null;
572        }
573        let xNode = globalThis.__getArkUINode__();
574        let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr);
575        if (!node) {
576            node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr);
577        }
578        __JSScopeUtil__.restoreInstanceId();
579        return node;
580    }
581
582    getPageInfoByUniqueId(uniqueId) {
583        __JSScopeUtil__.syncInstanceId(this.instanceId_);
584        const pageInfo = getUINativeModule().getPageInfoByUniqueId(uniqueId);
585        __JSScopeUtil__.restoreInstanceId();
586        return pageInfo;
587    }
588
589    getNavigationInfoByUniqueId(uniqueId) {
590        __JSScopeUtil__.syncInstanceId(this.instanceId_);
591        const navigationInfo = getUINativeModule().getNavigationInfoByUniqueId(uniqueId);
592        __JSScopeUtil__.restoreInstanceId();
593        return navigationInfo;
594    }
595
596    getFocusController() {
597        if (this.focusController_ == null) {
598            this.focusController_ = new FocusController(this.instanceId_);
599        }
600        return this.focusController_;
601    }
602
603    setDynamicDimming(id, number) {
604        __JSScopeUtil__.syncInstanceId(this.instanceId_);
605        let nodePtr = getUINativeModule().getFrameNodeByKey(id);
606        if (!nodePtr) {
607            return;
608        }
609        Context.setDynamicDimming(nodePtr, number);
610    }
611
612    getCursorController() {
613        if (this.cursorController_ == null) {
614            this.cursorController_ = new CursorController(this.instanceId_);
615        }
616        return this.cursorController_;
617    }
618
619    getContextMenuController() {
620        if (this.contextMenuController_ == null) {
621            this.contextMenuController_ = new ContextMenuController(this.instanceId_);
622        }
623        return this.contextMenuController_;
624    }
625
626    getWindowName() {
627        __JSScopeUtil__.syncInstanceId(this.instanceId_);
628        const windowName = getUINativeModule().common.getWindowName();
629        __JSScopeUtil__.restoreInstanceId();
630        return windowName;
631    }
632
633    getWindowWidthBreakpoint() {
634        __JSScopeUtil__.syncInstanceId(this.instanceId_);
635        const breakpoint = getUINativeModule().common.getWindowWidthBreakpoint();
636        __JSScopeUtil__.restoreInstanceId();
637        return breakpoint;
638    }
639
640    getWindowHeightBreakpoint() {
641        __JSScopeUtil__.syncInstanceId(this.instanceId_);
642        const breakpoint = getUINativeModule().common.getWindowHeightBreakpoint();
643        __JSScopeUtil__.restoreInstanceId();
644        return breakpoint;
645    }
646
647    clearResourceCache() {
648        getUINativeModule().resource.clearCache();
649    }
650
651    postFrameCallback(frameCallback) {
652        __JSScopeUtil__.syncInstanceId(this.instanceId_);
653        getUINativeModule().common.postFrameCallback(frameCallback, 0);
654        __JSScopeUtil__.restoreInstanceId();
655    }
656
657    postDelayedFrameCallback(frameCallback, delayMillis) {
658        __JSScopeUtil__.syncInstanceId(this.instanceId_);
659        getUINativeModule().common.postFrameCallback(frameCallback, delayMillis);
660        __JSScopeUtil__.restoreInstanceId();
661    }
662
663    requireDynamicSyncScene(id) {
664        __JSScopeUtil__.syncInstanceId(this.instanceId_);
665        let dynamicSceneInfo = getUINativeModule().requireDynamicSyncScene(id);
666        if (!dynamicSceneInfo) {
667            __JSScopeUtil__.restoreInstanceId();
668            return [];
669        }
670        if (dynamicSceneInfo.tag === 'Swiper') {
671            __JSScopeUtil__.restoreInstanceId();
672            let nodeRef = dynamicSceneInfo.nativeRef;
673            return SwiperDynamicSyncScene.createInstances(nodeRef);
674        }
675        if (dynamicSceneInfo.tag === 'Marquee') {
676            __JSScopeUtil__.restoreInstanceId();
677            let nodeRef = dynamicSceneInfo.nativeRef;
678            return MarqueeDynamicSyncScene.createInstances(nodeRef);
679        }
680        __JSScopeUtil__.restoreInstanceId();
681        return [];
682    }
683
684    isFollowingSystemFontScale() {
685        __JSScopeUtil__.syncInstanceId(this.instanceId_);
686        let isFollowing = Context.isFollowingSystemFontScale();
687        __JSScopeUtil__.restoreInstanceId();
688        return isFollowing;
689    }
690
691    getMaxFontScale() {
692        __JSScopeUtil__.syncInstanceId(this.instanceId_);
693        let maxFontScale = Context.getMaxFontScale();
694        __JSScopeUtil__.restoreInstanceId();
695        return maxFontScale;
696    }
697
698    bindTabsToScrollable(tabsController, scroller) {
699        __JSScopeUtil__.syncInstanceId(this.instanceId_);
700        Context.bindTabsToScrollable(tabsController, scroller);
701        __JSScopeUtil__.restoreInstanceId();
702    }
703
704    unbindTabsFromScrollable(tabsController, scroller) {
705        __JSScopeUtil__.syncInstanceId(this.instanceId_);
706        Context.unbindTabsFromScrollable(tabsController, scroller);
707        __JSScopeUtil__.restoreInstanceId();
708    }
709
710    bindTabsToNestedScrollable(tabsController, parentScroller, childScroller) {
711        __JSScopeUtil__.syncInstanceId(this.instanceId_);
712        Context.bindTabsToNestedScrollable(tabsController, parentScroller, childScroller);
713        __JSScopeUtil__.restoreInstanceId();
714    }
715
716    unbindTabsFromNestedScrollable(tabsController, parentScroller, childScroller) {
717        __JSScopeUtil__.syncInstanceId(this.instanceId_);
718        Context.unbindTabsFromNestedScrollable(tabsController, parentScroller, childScroller);
719        __JSScopeUtil__.restoreInstanceId();
720    }
721}
722
723class DynamicSyncScene {
724    /**
725     * Construct new instance of DynamicSyncScene.
726     * initialize with instanceId.
727     * @param {Object} nodeRef - obtained on the c++ side.
728     * @param {Object} frameRateRange - frameRateRange
729     * @since 12
730     */
731    constructor(nodeRef, frameRateRange) {
732        this.frameRateRange = { ...frameRateRange };
733        if (!nodeRef.invalid()) {
734            this.nodeRef = nodeRef;
735            this.nodePtr = this.nodeRef.getNativeHandle();
736        }
737    }
738
739    /**
740     * Get the frame rate range.
741     * @returns {Object} The frame rate range.
742     */
743    getFrameRateRange() {
744        return this.frameRateRange;
745    }
746}
747
748class SwiperDynamicSyncScene extends DynamicSyncScene {
749    /**
750     * Create instances of SwiperDynamicSyncScene.
751     * @param {Object} nodeRef - obtained on the c++ side.
752     * @returns {SwiperDynamicSyncScene[]} Array of SwiperDynamicSyncScene instances.
753     */
754    static createInstances(nodeRef) {
755        return [new SwiperDynamicSyncScene(nodeRef, 0), new SwiperDynamicSyncScene(nodeRef, 1)];
756    }
757
758    /**
759     * Construct new instance of SwiperDynamicSyncScene.
760     * @param {Object} nodeRef - obtained on the c++ side.
761     * @param {number} type - type of the scenes.
762     */
763    constructor(nodeRef, type) {
764        super(nodeRef, { min: 0, max: 120, expected: 120 });
765        this.type = type;
766    }
767
768    /**
769     * Set the frame rate range.
770     * @param {Object} frameRateRange - The new frame rate range.
771     */
772    setFrameRateRange(frameRateRange) {
773        this.frameRateRange = { ...frameRateRange };
774        getUINativeModule().setFrameRateRange(this.nodePtr, frameRateRange, this.type);
775    }
776}
777
778class MarqueeDynamicSyncScene extends DynamicSyncScene {
779    /**
780     * Create instances of MarqueeDynamicSyncScene.
781     * @param {Object} nodeRef - obtained on the c++ side.
782     * @returns {MarqueeDynamicSyncScene[]} Array of MarqueeDynamicSyncScene instances.
783     */
784    static createInstances(nodeRef) {
785        return [new MarqueeDynamicSyncScene(nodeRef, 1)];
786    }
787
788    /**
789     * Construct new instance of MarqueeDynamicSyncScene.
790     * @param {Object} nodeRef - obtained on the c++ side.
791     */
792    constructor(nodeRef, type) {
793        super(nodeRef, { min: 0, max: 120, expected: 120 });
794        this.type = type;
795    }
796
797    /**
798     * Set the frame rate range.
799     * @param {Object} frameRateRange - The new frame rate range.
800     */
801    setFrameRateRange(frameRateRange) {
802        this.frameRateRange = { ...frameRateRange }; // 确保每个实例有独立的frameRateRange
803        getUINativeModule().setMarqueeFrameRateRange(this.nodePtr, frameRateRange, this.type);
804    }
805}
806
807class FocusController {
808    /**
809     * Construct new instance of FocusController.
810     * initialize with instanceId.
811     * @param instanceId obtained on the c++ side.
812     * @since 12
813     */
814    constructor(instanceId) {
815        this.instanceId_ = instanceId;
816        this.ohos_focusController = globalThis.requireNapi('arkui.focusController');
817    }
818    clearFocus() {
819        __JSScopeUtil__.syncInstanceId(this.instanceId_);
820        this.ohos_focusController.clearFocus();
821        __JSScopeUtil__.restoreInstanceId();
822    }
823
824    requestFocus(value) {
825        __JSScopeUtil__.syncInstanceId(this.instanceId_);
826        let result = this.ohos_focusController.requestFocus(value);
827        __JSScopeUtil__.restoreInstanceId();
828        return result;
829    }
830
831    activate(isActive, autoInactive) {
832        __JSScopeUtil__.syncInstanceId(this.instanceId_);
833        if (arguments.length === 2) {
834            let result = this.ohos_focusController.activate(isActive, autoInactive);
835            __JSScopeUtil__.restoreInstanceId();
836            return result;
837        } else {
838            let result = this.ohos_focusController.activate(isActive);
839            __JSScopeUtil__.restoreInstanceId();
840            return result;
841        }
842    }
843}
844
845class CursorController {
846    /**
847     * Construct new instance of CursorController.
848     * initialzie with instanceId.
849     * @param instanceId obtained on the c++ side.
850     * @since 12
851     */
852    constructor(instanceId) {
853        this.instanceId_ = instanceId;
854    }
855
856    restoreDefault() {
857        __JSScopeUtil__.syncInstanceId(this.instanceId_);
858        cursorControl.restoreDefault();
859        __JSScopeUtil__.restoreInstanceId();
860    }
861
862    setCursor(value) {
863        __JSScopeUtil__.syncInstanceId(this.instanceId_);
864        cursorControl.setCursor(value);
865        __JSScopeUtil__.restoreInstanceId();
866    }
867}
868
869class ContextMenuController {
870    /**
871     * Construct new instance of ContextMenuController.
872     * initialzie with instanceId.
873     * @param instanceId obtained on the c++ side.
874     * @since 12
875     */
876    constructor(instanceId) {
877        this.instanceId_ = instanceId;
878    }
879
880    close() {
881        __JSScopeUtil__.syncInstanceId(this.instanceId_);
882        ContextMenu.close();
883        __JSScopeUtil__.restoreInstanceId();
884    }
885}
886
887class ComponentUtils {
888    /**
889     * Construct new instance of ComponentUtils.
890     * initialize with instanceId.
891     * @param instanceId obtained on the c++ side.
892     * @since 10
893     */
894    constructor(instanceId) {
895        this.instanceId_ = instanceId;
896        this.ohos_componentUtils = globalThis.requireNapi('arkui.componentUtils');
897    }
898    getRectangleById(id) {
899        __JSScopeUtil__.syncInstanceId(this.instanceId_);
900        if (typeof this.ohos_componentUtils.getRectangleById !== 'function'){
901            throw Error('getRectangleById is not callable');
902        }
903        let componentInformation = this.ohos_componentUtils?.getRectangleById?.(id);
904        __JSScopeUtil__.restoreInstanceId();
905        return componentInformation;
906    }
907}
908
909class Router {
910    /**
911     * Construct new instance of Font.
912     * initialize with instanceId.
913     * @param instanceId obtained on the c++ side.
914     * @since 10
915     */
916    constructor(instanceId) {
917        this.instanceId_ = instanceId;
918        this.ohos_router = globalThis.requireNapi('router');
919    }
920
921    pushUrl(options, modeOrCallback, callback) {
922        __JSScopeUtil__.syncInstanceId(this.instanceId_);
923        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
924            let promise = this.ohos_router.pushUrl(options);
925            __JSScopeUtil__.restoreInstanceId();
926            return promise;
927        }
928        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
929            this.ohos_router.pushUrl(options, modeOrCallback, callback);
930            __JSScopeUtil__.restoreInstanceId();
931        }
932        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
933            let promise = this.ohos_router.pushUrl(options, modeOrCallback);
934            __JSScopeUtil__.restoreInstanceId();
935            if (promise) {
936                return promise;
937            }
938        }
939    }
940
941    replaceUrl(options, modeOrCallback, callback) {
942        __JSScopeUtil__.syncInstanceId(this.instanceId_);
943        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
944            let promise = this.ohos_router.replaceUrl(options);
945            __JSScopeUtil__.restoreInstanceId();
946            return promise;
947        }
948        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
949            this.ohos_router.replaceUrl(options, modeOrCallback, callback);
950            __JSScopeUtil__.restoreInstanceId();
951        }
952        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
953            let promise = this.ohos_router.replaceUrl(options, modeOrCallback);
954            __JSScopeUtil__.restoreInstanceId();
955            if (promise) {
956                return promise;
957            }
958        }
959    }
960
961    back(options, params) {
962        __JSScopeUtil__.syncInstanceId(this.instanceId_);
963        if (typeof options === 'number' || arguments.length === 2) {
964            this.ohos_router.back(options, params);
965        } else {
966            this.ohos_router.back(options);
967        }
968        __JSScopeUtil__.restoreInstanceId();
969    }
970
971    clear() {
972        __JSScopeUtil__.syncInstanceId(this.instanceId_);
973        this.ohos_router.clear();
974        __JSScopeUtil__.restoreInstanceId();
975    }
976
977    getLength() {
978        __JSScopeUtil__.syncInstanceId(this.instanceId_);
979        let result = this.ohos_router.getLength();
980        __JSScopeUtil__.restoreInstanceId();
981        return result;
982    }
983
984    getState() {
985        __JSScopeUtil__.syncInstanceId(this.instanceId_);
986        let state = this.ohos_router.getState();
987        __JSScopeUtil__.restoreInstanceId();
988        return state;
989    }
990
991    getStateByIndex(index) {
992        __JSScopeUtil__.syncInstanceId(this.instanceId_);
993        let state = this.ohos_router.getStateByIndex(index);
994        __JSScopeUtil__.restoreInstanceId();
995        return state;
996    }
997
998    getStateByUrl(url) {
999        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1000        let state = this.ohos_router.getStateByUrl(url);
1001        __JSScopeUtil__.restoreInstanceId();
1002        return state;
1003    }
1004
1005    showAlertBeforeBackPage(options) {
1006        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1007        this.ohos_router.showAlertBeforeBackPage(options);
1008        __JSScopeUtil__.restoreInstanceId();
1009    }
1010
1011    hideAlertBeforeBackPage() {
1012        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1013        this.ohos_router.hideAlertBeforeBackPage();
1014        __JSScopeUtil__.restoreInstanceId();
1015    }
1016
1017    getParams() {
1018        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1019        let object = this.ohos_router.getParams();
1020        __JSScopeUtil__.restoreInstanceId();
1021        return object;
1022    }
1023
1024    pushNamedRoute(options, modeOrCallback, callback) {
1025        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1026        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
1027            let promise = this.ohos_router.pushNamedRoute(options);
1028            __JSScopeUtil__.restoreInstanceId();
1029            return promise;
1030        }
1031        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
1032            this.ohos_router.pushNamedRoute(options, modeOrCallback, callback);
1033            __JSScopeUtil__.restoreInstanceId();
1034        }
1035        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
1036            let promise = this.ohos_router.pushNamedRoute(options, modeOrCallback);
1037            __JSScopeUtil__.restoreInstanceId();
1038            if (promise) {
1039                return promise;
1040            }
1041        }
1042    }
1043
1044    replaceNamedRoute(options, modeOrCallback, callback) {
1045        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1046        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
1047            let promise = this.ohos_router.replaceNamedRoute(options);
1048            __JSScopeUtil__.restoreInstanceId();
1049            return promise;
1050        }
1051        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
1052            this.ohos_router.replaceNamedRoute(options, modeOrCallback, callback);
1053            __JSScopeUtil__.restoreInstanceId();
1054        }
1055        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
1056            let promise = this.ohos_router.replaceNamedRoute(options, modeOrCallback);
1057            __JSScopeUtil__.restoreInstanceId();
1058            if (promise) {
1059                return promise;
1060            }
1061        }
1062    }
1063}
1064
1065class PromptAction {
1066    /**
1067     * Construct new instance of PromptAction.
1068     * initialize with instanceId.
1069     * @param instanceId obtained on the c++ side.
1070     * @since 10
1071     */
1072    constructor(instanceId) {
1073        this.instanceId_ = instanceId;
1074        this.ohos_prompt = globalThis.requireNapi('promptAction');
1075    }
1076
1077    showToast(options) {
1078        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1079        this.ohos_prompt.showToast(options);
1080        __JSScopeUtil__.restoreInstanceId();
1081    }
1082
1083    openToast(options) {
1084        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1085        let promise = this.ohos_prompt.openToast(options);
1086        __JSScopeUtil__.restoreInstanceId();
1087        return promise;
1088    }
1089
1090    closeToast(toastId) {
1091        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1092        this.ohos_prompt.closeToast(toastId);
1093        __JSScopeUtil__.restoreInstanceId();
1094    }
1095
1096    showDialog(options, callback) {
1097        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1098        if (typeof callback !== 'undefined') {
1099            this.ohos_prompt.showDialog(options, callback);
1100            __JSScopeUtil__.restoreInstanceId();
1101        }
1102        else {
1103            let showDialogSuccessResponse = this.ohos_prompt.showDialog(options);
1104            __JSScopeUtil__.restoreInstanceId();
1105            return showDialogSuccessResponse;
1106        }
1107    }
1108
1109    openCustomDialog(content, options) {
1110        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1111        if (arguments.length === 2) {
1112            let result_ = this.ohos_prompt.openCustomDialog(content.getFrameNode(), options);
1113            __JSScopeUtil__.restoreInstanceId();
1114            return result_;
1115        }
1116        else {
1117            if (content.builderNode_ === undefined) {
1118                let result_ = this.ohos_prompt.openCustomDialog(content);
1119                __JSScopeUtil__.restoreInstanceId();
1120                return result_;
1121            }
1122            else {
1123                let result_ = this.ohos_prompt.openCustomDialog(content.getFrameNode());
1124                __JSScopeUtil__.restoreInstanceId();
1125                return result_;
1126            }
1127        }
1128    }
1129
1130    updateCustomDialog(content, options) {
1131        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1132        let result_ = this.ohos_prompt.updateCustomDialog(content.getFrameNode(), options);
1133        __JSScopeUtil__.restoreInstanceId();
1134        return result_;
1135    }
1136
1137    closeCustomDialog(content) {
1138        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1139        if (typeof content === 'number') {
1140            this.ohos_prompt.closeCustomDialog(content);
1141            __JSScopeUtil__.restoreInstanceId();
1142        }
1143        else {
1144            let result_ = this.ohos_prompt.closeCustomDialog(content.getFrameNode());
1145            __JSScopeUtil__.restoreInstanceId();
1146            return result_;
1147        }
1148    }
1149
1150    showActionMenu(options, callback) {
1151        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1152        if (typeof callback !== 'undefined') {
1153            this.ohos_prompt.showActionMenu(options, callback);
1154            __JSScopeUtil__.restoreInstanceId();
1155        }
1156        else {
1157            let actionMenuSuccessResponse = this.ohos_prompt.showActionMenu(options);
1158            __JSScopeUtil__.restoreInstanceId();
1159            return actionMenuSuccessResponse;
1160        }
1161    }
1162}
1163
1164class AtomicServiceBar {
1165    /**
1166     * Construct new instance of AtomicServiceBar.
1167     * initialize with instanceId.
1168     * @param instanceId obtained on the c++ side.
1169     * @since 11
1170     */
1171    constructor(instanceId) {
1172        this.instanceId_ = instanceId;
1173        this.ohos_atomicServiceBar = globalThis.requireNapi('atomicservicebar');
1174    }
1175
1176    setVisible(visible) {
1177        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1178        this.ohos_atomicServiceBar.setVisible(visible);
1179        __JSScopeUtil__.restoreInstanceId();
1180    }
1181
1182    setBackgroundColor(color) {
1183        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1184        this.ohos_atomicServiceBar.setBackgroundColor(color);
1185        __JSScopeUtil__.restoreInstanceId();
1186    }
1187
1188    setTitleContent(content) {
1189        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1190        this.ohos_atomicServiceBar.setTitleContent(content);
1191        __JSScopeUtil__.restoreInstanceId();
1192    }
1193
1194    setTitleFontStyle(font) {
1195        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1196        this.ohos_atomicServiceBar.setTitleFontStyle(font);
1197        __JSScopeUtil__.restoreInstanceId();
1198    }
1199
1200    setIconColor(color) {
1201        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1202        this.ohos_atomicServiceBar.setIconColor(color);
1203        __JSScopeUtil__.restoreInstanceId();
1204    }
1205}
1206
1207class OverlayManager {
1208    /**
1209     * Construct new instance of Overlay.
1210     * initialize with instanceId.
1211     * @param instanceId obtained on the c++ side.
1212     * @since 12
1213     */
1214    constructor(instanceId) {
1215        this.instanceId_ = instanceId;
1216        this.ohos_overlayManager = globalThis.requireNapi('overlay');
1217    }
1218
1219    addComponentContent(content, index) {
1220        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1221        if (typeof index !== 'undefined') {
1222            this.ohos_overlayManager.addFrameNode(content.getFrameNode(), index);
1223        } else {
1224            this.ohos_overlayManager.addFrameNode(content.getFrameNode());
1225        }
1226        __JSScopeUtil__.restoreInstanceId();
1227    }
1228
1229    removeComponentContent(content) {
1230        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1231        this.ohos_overlayManager.removeFrameNode(content.getFrameNode());
1232        __JSScopeUtil__.restoreInstanceId();
1233    }
1234
1235    showComponentContent(content) {
1236        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1237        this.ohos_overlayManager.showNode(content.getFrameNode());
1238        __JSScopeUtil__.restoreInstanceId();
1239    }
1240
1241    hideComponentContent(content) {
1242        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1243        this.ohos_overlayManager.hideNode(content.getFrameNode());
1244        __JSScopeUtil__.restoreInstanceId();
1245    }
1246
1247    showAllComponentContents() {
1248        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1249        this.ohos_overlayManager.showAllFrameNodes();
1250        __JSScopeUtil__.restoreInstanceId();
1251    }
1252
1253    hideAllComponentContents() {
1254        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1255        this.ohos_overlayManager.hideAllFrameNodes();
1256        __JSScopeUtil__.restoreInstanceId();
1257    }
1258}
1259/**
1260 * Get UIContext instance.
1261 * @param instanceId obtained on the c++ side.
1262 * @returns UIContext instance.
1263 */
1264function __getUIContext__(instanceId) {
1265    return new UIContext(instanceId);
1266}
1267
1268/**
1269 * Get FrameNode by id of UIContext instance.
1270 * @param instanceId obtained on the C++ side.
1271 * @param nodeId the id of frameNode.
1272 * @returns FrameNode instance.
1273 */
1274function __getFrameNodeByNodeId__(instanceId, nodeId) {
1275    const uiContext = __getUIContext__(instanceId);
1276    return uiContext.getFrameNodeByNodeId(nodeId);
1277}
1278
1279/**
1280 * check regex valid
1281 * @param pattern regex string
1282 * @returns valid result
1283 */
1284function __checkRegexValid__(pattern) {
1285    let result = true;
1286    try {
1287        new RegExp(pattern);
1288    } catch (error) {
1289        result = false;
1290    } finally {
1291        return result;
1292    }
1293}