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    getFocusController() {
567        if (this.focusController_ == null) {
568            this.focusController_ = new FocusController(this.instanceId_);
569        }
570        return this.focusController_;
571    }
572
573    setDynamicDimming(id, number) {
574        __JSScopeUtil__.syncInstanceId(this.instanceId_);
575        let nodePtr = getUINativeModule().getFrameNodeByKey(id);
576        if (!nodePtr) {
577            return;
578        }
579        Context.setDynamicDimming(nodePtr, number);
580    }
581
582    getFrameNodeByUniqueId(uniqueId) {
583        __JSScopeUtil__.syncInstanceId(this.instanceId_);
584        let nodePtr = getUINativeModule().getFrameNodeByUniqueId(uniqueId);
585        if (nodePtr === undefined) {
586            __JSScopeUtil__.restoreInstanceId();
587            return null;
588        }
589        let xNode = globalThis.__getArkUINode__();
590        let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr);
591        if (!node) {
592            node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr);
593        }
594        __JSScopeUtil__.restoreInstanceId();
595        return node;
596    }
597
598    getPageInfoByUniqueId(uniqueId) {
599        __JSScopeUtil__.syncInstanceId(this.instanceId_);
600        const pageInfo = getUINativeModule().getPageInfoByUniqueId(uniqueId);
601        __JSScopeUtil__.restoreInstanceId();
602        return pageInfo;
603    }
604
605    getNavigationInfoByUniqueId(uniqueId) {
606        __JSScopeUtil__.syncInstanceId(this.instanceId_);
607        const navigationInfo = getUINativeModule().getNavigationInfoByUniqueId(uniqueId);
608        __JSScopeUtil__.restoreInstanceId();
609        return navigationInfo;
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    postFrameCallback(frameCallback) {
648        __JSScopeUtil__.syncInstanceId(this.instanceId_);
649        getUINativeModule().common.postFrameCallback(frameCallback, 0);
650        __JSScopeUtil__.restoreInstanceId();
651    }
652
653    postDelayedFrameCallback(frameCallback, delayMillis) {
654        __JSScopeUtil__.syncInstanceId(this.instanceId_);
655        getUINativeModule().common.postFrameCallback(frameCallback, delayMillis);
656        __JSScopeUtil__.restoreInstanceId();
657    }
658
659    clearResourceCache() {
660        getUINativeModule().resource.clearCache();
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        if (this.ohos_focusController === null || this.ohos_focusController === undefined) {
820            return;
821        }
822        __JSScopeUtil__.syncInstanceId(this.instanceId_);
823        this.ohos_focusController.clearFocus();
824        __JSScopeUtil__.restoreInstanceId();
825    }
826
827    requestFocus(value) {
828        if (this.ohos_focusController === null || this.ohos_focusController === undefined) {
829            return false;
830        }
831        __JSScopeUtil__.syncInstanceId(this.instanceId_);
832        let result = this.ohos_focusController.requestFocus(value);
833        __JSScopeUtil__.restoreInstanceId();
834        return result;
835    }
836
837    activate(isActive, autoInactive) {
838        __JSScopeUtil__.syncInstanceId(this.instanceId_);
839        if (arguments.length === 2) {
840            let result = this.ohos_focusController.activate(isActive, autoInactive);
841            __JSScopeUtil__.restoreInstanceId();
842            return result;
843        } else {
844            let result = this.ohos_focusController.activate(isActive);
845            __JSScopeUtil__.restoreInstanceId();
846            return result;
847        }
848    }
849
850    setAutoFocusTransfer(value) {
851        __JSScopeUtil__.syncInstanceId(this.instanceId_);
852        this.ohos_focusController.setAutoFocusTransfer(value);
853        __JSScopeUtil__.restoreInstanceId();
854    }
855}
856
857class CursorController {
858    /**
859     * Construct new instance of CursorController.
860     * initialzie with instanceId.
861     * @param instanceId obtained on the c++ side.
862     * @since 12
863     */
864    constructor(instanceId) {
865        this.instanceId_ = instanceId;
866    }
867
868    restoreDefault() {
869        __JSScopeUtil__.syncInstanceId(this.instanceId_);
870        cursorControl.restoreDefault();
871        __JSScopeUtil__.restoreInstanceId();
872    }
873
874    setCursor(value) {
875        __JSScopeUtil__.syncInstanceId(this.instanceId_);
876        cursorControl.setCursor(value);
877        __JSScopeUtil__.restoreInstanceId();
878    }
879}
880
881class ContextMenuController {
882    /**
883     * Construct new instance of ContextMenuController.
884     * initialzie with instanceId.
885     * @param instanceId obtained on the c++ side.
886     * @since 12
887     */
888    constructor(instanceId) {
889        this.instanceId_ = instanceId;
890    }
891
892    close() {
893        __JSScopeUtil__.syncInstanceId(this.instanceId_);
894        ContextMenu.close();
895        __JSScopeUtil__.restoreInstanceId();
896    }
897}
898
899class ComponentUtils {
900    /**
901     * Construct new instance of ComponentUtils.
902     * initialize with instanceId.
903     * @param instanceId obtained on the c++ side.
904     * @since 10
905     */
906    constructor(instanceId) {
907        this.instanceId_ = instanceId;
908        this.ohos_componentUtils = globalThis.requireNapi('arkui.componentUtils');
909    }
910    getRectangleById(id) {
911        __JSScopeUtil__.syncInstanceId(this.instanceId_);
912        if (typeof this.ohos_componentUtils.getRectangleById !== 'function') {
913            throw Error('getRectangleById is not callable');
914        }
915        let componentInformation = this.ohos_componentUtils?.getRectangleById?.(id);
916        __JSScopeUtil__.restoreInstanceId();
917        return componentInformation;
918    }
919}
920
921class Router {
922    /**
923     * Construct new instance of Font.
924     * initialize with instanceId.
925     * @param instanceId obtained on the c++ side.
926     * @since 10
927     */
928    constructor(instanceId) {
929        this.instanceId_ = instanceId;
930        this.ohos_router = globalThis.requireNapi('router');
931    }
932
933    pushUrl(options, modeOrCallback, callback) {
934        __JSScopeUtil__.syncInstanceId(this.instanceId_);
935        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
936            let promise = this.ohos_router.pushUrl(options);
937            __JSScopeUtil__.restoreInstanceId();
938            return promise;
939        }
940        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
941            this.ohos_router.pushUrl(options, modeOrCallback, callback);
942            __JSScopeUtil__.restoreInstanceId();
943        }
944        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
945            let promise = this.ohos_router.pushUrl(options, modeOrCallback);
946            __JSScopeUtil__.restoreInstanceId();
947            if (promise) {
948                return promise;
949            }
950        }
951    }
952
953    replaceUrl(options, modeOrCallback, callback) {
954        __JSScopeUtil__.syncInstanceId(this.instanceId_);
955        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
956            let promise = this.ohos_router.replaceUrl(options);
957            __JSScopeUtil__.restoreInstanceId();
958            return promise;
959        }
960        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
961            this.ohos_router.replaceUrl(options, modeOrCallback, callback);
962            __JSScopeUtil__.restoreInstanceId();
963        }
964        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
965            let promise = this.ohos_router.replaceUrl(options, modeOrCallback);
966            __JSScopeUtil__.restoreInstanceId();
967            if (promise) {
968                return promise;
969            }
970        }
971    }
972
973    back(options, params) {
974        __JSScopeUtil__.syncInstanceId(this.instanceId_);
975        if (typeof options === 'number' || arguments.length === 2) {
976            this.ohos_router.back(options, params);
977        } else {
978            this.ohos_router.back(options);
979        }
980        __JSScopeUtil__.restoreInstanceId();
981    }
982
983    clear() {
984        __JSScopeUtil__.syncInstanceId(this.instanceId_);
985        this.ohos_router.clear();
986        __JSScopeUtil__.restoreInstanceId();
987    }
988
989    getLength() {
990        __JSScopeUtil__.syncInstanceId(this.instanceId_);
991        let result = this.ohos_router.getLength();
992        __JSScopeUtil__.restoreInstanceId();
993        return result;
994    }
995
996    getState() {
997        __JSScopeUtil__.syncInstanceId(this.instanceId_);
998        let state = this.ohos_router.getState();
999        __JSScopeUtil__.restoreInstanceId();
1000        return state;
1001    }
1002
1003    getStateByIndex(index) {
1004        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1005        let state = this.ohos_router.getStateByIndex(index);
1006        __JSScopeUtil__.restoreInstanceId();
1007        return state;
1008    }
1009
1010    getStateByUrl(url) {
1011        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1012        let state = this.ohos_router.getStateByUrl(url);
1013        __JSScopeUtil__.restoreInstanceId();
1014        return state;
1015    }
1016
1017    showAlertBeforeBackPage(options) {
1018        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1019        this.ohos_router.showAlertBeforeBackPage(options);
1020        __JSScopeUtil__.restoreInstanceId();
1021    }
1022
1023    hideAlertBeforeBackPage() {
1024        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1025        this.ohos_router.hideAlertBeforeBackPage();
1026        __JSScopeUtil__.restoreInstanceId();
1027    }
1028
1029    getParams() {
1030        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1031        let object = this.ohos_router.getParams();
1032        __JSScopeUtil__.restoreInstanceId();
1033        return object;
1034    }
1035
1036    pushNamedRoute(options, modeOrCallback, callback) {
1037        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1038        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
1039            let promise = this.ohos_router.pushNamedRoute(options);
1040            __JSScopeUtil__.restoreInstanceId();
1041            return promise;
1042        }
1043        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
1044            this.ohos_router.pushNamedRoute(options, modeOrCallback, callback);
1045            __JSScopeUtil__.restoreInstanceId();
1046        }
1047        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
1048            let promise = this.ohos_router.pushNamedRoute(options, modeOrCallback);
1049            __JSScopeUtil__.restoreInstanceId();
1050            if (promise) {
1051                return promise;
1052            }
1053        }
1054    }
1055
1056    replaceNamedRoute(options, modeOrCallback, callback) {
1057        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1058        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
1059            let promise = this.ohos_router.replaceNamedRoute(options);
1060            __JSScopeUtil__.restoreInstanceId();
1061            return promise;
1062        }
1063        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
1064            this.ohos_router.replaceNamedRoute(options, modeOrCallback, callback);
1065            __JSScopeUtil__.restoreInstanceId();
1066        }
1067        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
1068            let promise = this.ohos_router.replaceNamedRoute(options, modeOrCallback);
1069            __JSScopeUtil__.restoreInstanceId();
1070            if (promise) {
1071                return promise;
1072            }
1073        }
1074    }
1075}
1076
1077class PromptAction {
1078    /**
1079     * Construct new instance of PromptAction.
1080     * initialize with instanceId.
1081     * @param instanceId obtained on the c++ side.
1082     * @since 10
1083     */
1084    constructor(instanceId) {
1085        this.instanceId_ = instanceId;
1086        this.ohos_prompt = globalThis.requireNapi('promptAction');
1087    }
1088
1089    showToast(options) {
1090        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1091        this.ohos_prompt.showToast(options);
1092        __JSScopeUtil__.restoreInstanceId();
1093    }
1094
1095    showDialog(options, callback) {
1096        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1097        if (typeof callback !== 'undefined') {
1098            this.ohos_prompt.showDialog(options, callback);
1099            __JSScopeUtil__.restoreInstanceId();
1100        }
1101        else {
1102            let showDialogSuccessResponse = this.ohos_prompt.showDialog(options);
1103            __JSScopeUtil__.restoreInstanceId();
1104            return showDialogSuccessResponse;
1105        }
1106    }
1107
1108    openCustomDialog(content, options) {
1109        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1110        if (arguments.length === 2) {
1111            let result_ = this.ohos_prompt.openCustomDialog(content.getFrameNode(), options);
1112            __JSScopeUtil__.restoreInstanceId();
1113            return result_;
1114        }
1115        else {
1116            if (content.builderNode_ === undefined) {
1117                let result_ = this.ohos_prompt.openCustomDialog(content);
1118                __JSScopeUtil__.restoreInstanceId();
1119                return result_;
1120            }
1121            else {
1122                let result_ = this.ohos_prompt.openCustomDialog(content.getFrameNode());
1123                __JSScopeUtil__.restoreInstanceId();
1124                return result_;
1125            }
1126        }
1127    }
1128
1129    updateCustomDialog(content, options) {
1130        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1131        let result_ = this.ohos_prompt.updateCustomDialog(content.getFrameNode(), options);
1132        __JSScopeUtil__.restoreInstanceId();
1133        return result_;
1134    }
1135
1136    closeCustomDialog(content) {
1137        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1138        if (typeof content === 'number') {
1139            this.ohos_prompt.closeCustomDialog(content);
1140            __JSScopeUtil__.restoreInstanceId();
1141        }
1142        else {
1143            let result_ = this.ohos_prompt.closeCustomDialog(content.getFrameNode());
1144            __JSScopeUtil__.restoreInstanceId();
1145            return result_;
1146        }
1147    }
1148
1149    showActionMenu(options, callback) {
1150        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1151        if (typeof callback !== 'undefined') {
1152            this.ohos_prompt.showActionMenu(options, callback);
1153            __JSScopeUtil__.restoreInstanceId();
1154        }
1155        else {
1156            let actionMenuSuccessResponse = this.ohos_prompt.showActionMenu(options);
1157            __JSScopeUtil__.restoreInstanceId();
1158            return actionMenuSuccessResponse;
1159        }
1160    }
1161}
1162
1163class AtomicServiceBar {
1164    /**
1165     * Construct new instance of AtomicServiceBar.
1166     * initialize with instanceId.
1167     * @param instanceId obtained on the c++ side.
1168     * @since 11
1169     */
1170    constructor(instanceId) {
1171        this.instanceId_ = instanceId;
1172        this.ohos_atomicServiceBar = globalThis.requireNapi('atomicservicebar');
1173    }
1174
1175    setVisible(visible) {
1176        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1177        this.ohos_atomicServiceBar.setVisible(visible);
1178        __JSScopeUtil__.restoreInstanceId();
1179    }
1180
1181    setBackgroundColor(color) {
1182        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1183        this.ohos_atomicServiceBar.setBackgroundColor(color);
1184        __JSScopeUtil__.restoreInstanceId();
1185    }
1186
1187    setTitleContent(content) {
1188        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1189        this.ohos_atomicServiceBar.setTitleContent(content);
1190        __JSScopeUtil__.restoreInstanceId();
1191    }
1192
1193    setTitleFontStyle(font) {
1194        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1195        this.ohos_atomicServiceBar.setTitleFontStyle(font);
1196        __JSScopeUtil__.restoreInstanceId();
1197    }
1198
1199    setIconColor(color) {
1200        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1201        this.ohos_atomicServiceBar.setIconColor(color);
1202        __JSScopeUtil__.restoreInstanceId();
1203    }
1204}
1205
1206class OverlayManager {
1207    /**
1208     * Construct new instance of Overlay.
1209     * initialize with instanceId.
1210     * @param instanceId obtained on the c++ side.
1211     * @since 12
1212     */
1213    constructor(instanceId) {
1214        this.instanceId_ = instanceId;
1215        this.ohos_overlayManager = globalThis.requireNapi('overlay');
1216    }
1217
1218    addComponentContent(content, index) {
1219        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1220        if (typeof index !== 'undefined') {
1221            this.ohos_overlayManager.addFrameNode(content.getFrameNode(), index);
1222        } else {
1223            this.ohos_overlayManager.addFrameNode(content.getFrameNode());
1224        }
1225        __JSScopeUtil__.restoreInstanceId();
1226    }
1227
1228    removeComponentContent(content) {
1229        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1230        this.ohos_overlayManager.removeFrameNode(content.getFrameNode());
1231        __JSScopeUtil__.restoreInstanceId();
1232    }
1233
1234    showComponentContent(content) {
1235        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1236        this.ohos_overlayManager.showNode(content.getFrameNode());
1237        __JSScopeUtil__.restoreInstanceId();
1238    }
1239
1240    hideComponentContent(content) {
1241        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1242        this.ohos_overlayManager.hideNode(content.getFrameNode());
1243        __JSScopeUtil__.restoreInstanceId();
1244    }
1245
1246    showAllComponentContents() {
1247        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1248        this.ohos_overlayManager.showAllFrameNodes();
1249        __JSScopeUtil__.restoreInstanceId();
1250    }
1251
1252    hideAllComponentContents() {
1253        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1254        this.ohos_overlayManager.hideAllFrameNodes();
1255        __JSScopeUtil__.restoreInstanceId();
1256    }
1257}
1258/**
1259 * Get UIContext instance.
1260 * @param instanceId obtained on the c++ side.
1261 * @returns UIContext instance.
1262 */
1263function __getUIContext__(instanceId) {
1264    return new UIContext(instanceId);
1265}
1266
1267/**
1268 * Get FrameNode by id of UIContext instance.
1269 * @param instanceId obtained on the C++ side.
1270 * @param nodeId the id of frameNode.
1271 * @returns FrameNode instance.
1272 */
1273function __getFrameNodeByNodeId__(instanceId, nodeId) {
1274    const uiContext = __getUIContext__(instanceId);
1275    return uiContext.getFrameNodeByNodeId(nodeId);
1276}
1277
1278/**
1279 * check regex valid
1280 * @param pattern regex string
1281 * @returns valid result
1282 */
1283function __checkRegexValid__(pattern) {
1284    let result = true;
1285    try {
1286        new RegExp(pattern);
1287    } catch (error) {
1288        result = false;
1289    } finally {
1290        return result;
1291    }
1292}