• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    getWithUniqueId(uniqueId, options) {
121        __JSScopeUtil__.syncInstanceId(this.instanceId_);
122        let promise = this.ohos_componentSnapshot.getWithUniqueId(uniqueId, options);
123        __JSScopeUtil__.restoreInstanceId();
124        return promise;
125    }
126
127    getSyncWithUniqueId(uniqueId, options) {
128        __JSScopeUtil__.syncInstanceId(this.instanceId_);
129        let pixelmap = this.ohos_componentSnapshot.getSyncWithUniqueId(uniqueId, options);
130        __JSScopeUtil__.restoreInstanceId();
131        return pixelmap;
132    }
133
134    createFromComponent(content, delay, checkImageStatus, options) {
135        if (content === undefined || content === null) {
136            let paramErrMsg =
137            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
138            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
139            __JSScopeUtil__.restoreInstanceId();
140            return new Promise((resolve, reject) => {
141                reject({ message: paramErrMsg, code: 401 });
142            });
143        }
144        __JSScopeUtil__.syncInstanceId(this.instanceId_);
145        let promise = this.ohos_componentSnapshot.createFromComponent(content.getFrameNode(), delay, checkImageStatus, options);
146        __JSScopeUtil__.restoreInstanceId();
147        return promise;
148    }
149}
150
151class DragController {
152    /**
153     * Construct new instance of DragController.
154     * initialize with instanceId.
155     * @param instanceId obtained on the c++ side.
156     * @since 11
157     */
158    constructor(instanceId) {
159        this.instanceId_ = instanceId;
160        this.ohos_dragController = globalThis.requireNapi('arkui.dragController');
161    }
162
163    executeDrag(custom, dragInfo, callback) {
164        __JSScopeUtil__.syncInstanceId(this.instanceId_);
165        if (typeof callback !== 'undefined') {
166            this.ohos_dragController.executeDrag(custom, dragInfo, callback);
167            __JSScopeUtil__.restoreInstanceId();
168        } else {
169            let eventPromise = this.ohos_dragController.executeDrag(custom, dragInfo);
170            __JSScopeUtil__.restoreInstanceId();
171            return eventPromise;
172        }
173    }
174
175    createDragAction(customs, dragInfo) {
176        __JSScopeUtil__.syncInstanceId(this.instanceId_);
177        let dragAction = this.ohos_dragController.createDragAction(customs, dragInfo);
178        __JSScopeUtil__.restoreInstanceId();
179        return dragAction;
180    }
181
182    getDragPreview() {
183        __JSScopeUtil__.syncInstanceId(this.instanceId_);
184        let dragPreview = this.ohos_dragController.getDragPreview();
185        __JSScopeUtil__.restoreInstanceId();
186        return dragPreview;
187    }
188
189    setDragEventStrictReportingEnabled(enable) {
190        __JSScopeUtil__.syncInstanceId(this.instanceId_);
191        JSViewAbstract.setDragEventStrictReportingEnabled(enable);
192        __JSScopeUtil__.restoreInstanceId();
193    }
194
195    notifyDragStartRequest(request) {
196        __JSScopeUtil__.syncInstanceId(this.instanceId_);
197        JSViewAbstract.notifyDragStartRequest(request);
198        __JSScopeUtil__.restoreInstanceId();
199    }
200
201    cancelDataLoading(key) {
202        __JSScopeUtil__.syncInstanceId(this.instanceId_);
203        JSViewAbstract.cancelDataLoading(key);
204        __JSScopeUtil__.restoreInstanceId();
205    }
206}
207
208class UIObserver {
209    constructor(instanceId) {
210        this.instanceId_ = instanceId;
211        this.ohos_observer = globalThis.requireNapi('arkui.observer');
212    }
213    on(...args) {
214        __JSScopeUtil__.syncInstanceId(this.instanceId_);
215        this.ohos_observer.on(...args);
216        __JSScopeUtil__.restoreInstanceId();
217    }
218    off(...args) {
219        __JSScopeUtil__.syncInstanceId(this.instanceId_);
220        this.ohos_observer.off(...args);
221        __JSScopeUtil__.restoreInstanceId();
222    }
223}
224
225class MeasureUtils {
226    /**
227     * Construct new instance of MeasureUtils.
228     * initialize with instanceId.
229     * @param instanceId obtained on the c++ side.
230     * @since 12
231     */
232    constructor(instanceId) {
233        this.instanceId_ = instanceId;
234        this.ohos_measureUtils = globalThis.requireNapi('measure');
235    }
236
237    measureText(options) {
238        __JSScopeUtil__.syncInstanceId(this.instanceId_);
239        let number = this.ohos_measureUtils.measureText(options);
240        __JSScopeUtil__.restoreInstanceId();
241        return number;
242    }
243
244    measureTextSize(options) {
245        __JSScopeUtil__.syncInstanceId(this.instanceId_);
246        let sizeOption = this.ohos_measureUtils.measureTextSize(options);
247        __JSScopeUtil__.restoreInstanceId();
248        return sizeOption;
249    }
250}
251
252class FrameCallback {
253}
254
255class UIContext {
256    /**
257     * Construct new instance of UIContext.
258     * initialize with instanceId.
259     * @param instanceId obtained on the c++ side.
260     * @since 10
261     */
262    constructor(instanceId) {
263        this.instanceId_ = instanceId;
264    }
265
266    static createUIContextWithoutWindow(context) {
267        let utils = globalThis.requireNapi('arkui.containerUtils');
268        let uicontext = undefined;
269        if (utils) {
270            uicontext = utils.createContainerWithoutWindow(context);
271        }
272
273        return uicontext;
274    }
275
276    static destroyUIContextWithoutWindow() {
277        let utils = globalThis.requireNapi('arkui.containerUtils');
278        if (utils) {
279            utils.destroyContainerWithoutWindow();
280        }
281    }
282
283    getDragController() {
284        this.dragController_ = new DragController(this.instanceId_);
285        return this.dragController_;
286    }
287
288    getFont() {
289        this.font_ = new Font(this.instanceId_);
290        return this.font_;
291    }
292
293    getRouter() {
294        this.router_ = new Router(this.instanceId_);
295        return this.router_;
296    }
297
298    createAnimator(options) {
299        __JSScopeUtil__.syncInstanceId(this.instanceId_);
300        this.animator_ = globalThis.requireNapi('animator');
301        let animatorResult = this.animator_.create(options);
302        __JSScopeUtil__.restoreInstanceId();
303        return animatorResult;
304    }
305
306    getPromptAction() {
307        this.promptAction_ = new PromptAction(this.instanceId_);
308        return this.promptAction_;
309    }
310
311    getMediaQuery() {
312        this.mediaQuery_ = new MediaQuery(this.instanceId_);
313        return this.mediaQuery_;
314    }
315
316    getUIInspector() {
317        this.UIInspector_ = new UIInspector(this.instanceId_);
318        return this.UIInspector_;
319    }
320
321    getFilteredInspectorTree(filter) {
322        __JSScopeUtil__.syncInstanceId(this.instanceId_);
323        if (typeof filter === 'undefined') {
324            let result_ = globalThis.getFilteredInspectorTree();
325            __JSScopeUtil__.restoreInstanceId();
326            return result_;
327        } else {
328            let result_ = globalThis.getFilteredInspectorTree(filter);
329            __JSScopeUtil__.restoreInstanceId();
330            return result_;
331        }
332    }
333
334    getFilteredInspectorTreeById(id, depth, filter) {
335        __JSScopeUtil__.syncInstanceId(this.instanceId_);
336        if (typeof filter === 'undefined') {
337            let result_ = globalThis.getFilteredInspectorTreeById(id, depth);
338            __JSScopeUtil__.restoreInstanceId();
339            return result_;
340        } else {
341            let result_ = globalThis.getFilteredInspectorTreeById(id, depth, filter);
342            __JSScopeUtil__.restoreInstanceId();
343            return result_;
344        }
345    }
346
347    getComponentSnapshot() {
348        this.ComponentSnapshot_ = new ComponentSnapshot(this.instanceId_);
349        return this.ComponentSnapshot_;
350    }
351
352    vp2px(value) {
353        __JSScopeUtil__.syncInstanceId(this.instanceId_);
354        let vp2pxResult = globalThis.vp2px(value);
355        __JSScopeUtil__.restoreInstanceId();
356        return vp2pxResult;
357    }
358
359    px2vp(value) {
360        __JSScopeUtil__.syncInstanceId(this.instanceId_);
361        let px2vpResult = globalThis.px2vp(value);
362        __JSScopeUtil__.restoreInstanceId();
363        return px2vpResult;
364    }
365
366    fp2px(value) {
367        __JSScopeUtil__.syncInstanceId(this.instanceId_);
368        let fp2pxResult = globalThis.fp2px(value);
369        __JSScopeUtil__.restoreInstanceId();
370        return fp2pxResult;
371    }
372
373    px2fp(value) {
374        __JSScopeUtil__.syncInstanceId(this.instanceId_);
375        let px2fpResult = globalThis.px2fp(value);
376        __JSScopeUtil__.restoreInstanceId();
377        return px2fpResult;
378    }
379
380    lpx2px(value) {
381        __JSScopeUtil__.syncInstanceId(this.instanceId_);
382        let lpx2pxResult = globalThis.lpx2px(value);
383        __JSScopeUtil__.restoreInstanceId();
384        return lpx2pxResult;
385    }
386
387    px2lpx(value) {
388        __JSScopeUtil__.syncInstanceId(this.instanceId_);
389        let px2lpxResult = globalThis.px2lpx(value);
390        __JSScopeUtil__.restoreInstanceId();
391        return px2lpxResult;
392    }
393
394    getComponentUtils() {
395        if (this.componentUtils_ == null) {
396            this.componentUtils_ = new ComponentUtils(this.instanceId_);
397        }
398        return this.componentUtils_;
399    }
400
401    getOverlayManager() {
402        if(!this.overlayManager_) {
403            this.overlayManager_ = new OverlayManager(this.instanceId_);
404        }
405        this.overlayManager_.setOverlayManagerOptions();
406        return this.overlayManager_;
407    }
408    setOverlayManagerOptions(options) {
409        if(!this.overlayManager_) {
410            this.overlayManager_ = new OverlayManager(this.instanceId_);
411        }
412        return this.overlayManager_.setOverlayManagerOptions(options);
413    }
414    getOverlayManagerOptions() {
415        if(!this.overlayManager_) {
416            this.overlayManager_ = new OverlayManager(this.instanceId_);
417        }
418        return this.overlayManager_.getOverlayManagerOptions();
419    }
420
421    animateTo(value, event) {
422        __JSScopeUtil__.syncInstanceId(this.instanceId_);
423        Context.animateTo(value, event);
424        __JSScopeUtil__.restoreInstanceId();
425    }
426
427    showAlertDialog(options) {
428        __JSScopeUtil__.syncInstanceId(this.instanceId_);
429        AlertDialog.show(options);
430        __JSScopeUtil__.restoreInstanceId();
431    }
432
433    showActionSheet(value) {
434        __JSScopeUtil__.syncInstanceId(this.instanceId_);
435        ActionSheet.show(value);
436        __JSScopeUtil__.restoreInstanceId();
437    }
438
439    openBindSheet(content, options, targetId) {
440        let paramErrMsg =
441            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
442            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
443        __JSScopeUtil__.syncInstanceId(this.instanceId_);
444        let argLength = arguments.length;
445        if (argLength < 1 || content === null || content === undefined) {
446            __JSScopeUtil__.restoreInstanceId();
447            return new Promise((resolve, reject) => {
448                reject({ message: paramErrMsg, code: 401 });
449            });
450        }
451        if ((argLength >= 3 && (targetId === null || targetId === undefined))) {
452            __JSScopeUtil__.restoreInstanceId();
453            return new Promise((resolve, reject) => {
454                reject({ message: paramErrMsg, code: 401 });
455            });
456        }
457        let result_;
458        if (argLength === 1) {
459            result_ = Context.openBindSheet(content.getNodePtr());
460        } else if (argLength === 2) {
461            result_ = Context.openBindSheet(content.getNodePtr(), options);
462        } else {
463            result_ = Context.openBindSheet(content.getNodePtr(), options, targetId);
464        }
465        __JSScopeUtil__.restoreInstanceId();
466        return result_;
467    }
468
469    updateBindSheet(content, options, partialUpdate) {
470        let paramErrMsg =
471            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
472            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
473        __JSScopeUtil__.syncInstanceId(this.instanceId_);
474        let argLength = arguments.length;
475        if (argLength < 2 || content === null || content === undefined) {
476            __JSScopeUtil__.restoreInstanceId();
477            return new Promise((resolve, reject) => {
478                reject({ message: paramErrMsg, code: 401 });
479            });
480        }
481        let result_;
482        if (argLength === 2) {
483            result_ = Context.updateBindSheet(content.getNodePtr(), options);
484        } else {
485            result_ = Context.updateBindSheet(content.getNodePtr(), options, partialUpdate);
486        }
487        __JSScopeUtil__.restoreInstanceId();
488        return result_;
489    }
490
491    closeBindSheet(content) {
492        let paramErrMsg =
493            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
494            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
495        __JSScopeUtil__.syncInstanceId(this.instanceId_);
496        if (arguments.length < 1 || content === null || content === undefined) {
497            __JSScopeUtil__.restoreInstanceId();
498            return new Promise((resolve, reject) => {
499                reject({ message: paramErrMsg, code: 401 });
500            });
501        }
502        let result_ = Context.closeBindSheet(content.getNodePtr());
503        __JSScopeUtil__.restoreInstanceId();
504        return result_;
505    }
506
507    showDatePickerDialog(options) {
508        __JSScopeUtil__.syncInstanceId(this.instanceId_);
509        DatePickerDialog.show(options);
510        __JSScopeUtil__.restoreInstanceId();
511    }
512
513    showTimePickerDialog(options) {
514        __JSScopeUtil__.syncInstanceId(this.instanceId_);
515        TimePickerDialog.show(options);
516        __JSScopeUtil__.restoreInstanceId();
517    }
518
519    showTextPickerDialog(options) {
520        __JSScopeUtil__.syncInstanceId(this.instanceId_);
521        TextPickerDialog.show(options);
522        __JSScopeUtil__.restoreInstanceId();
523    }
524
525    runScopedTask(callback) {
526        __JSScopeUtil__.syncInstanceId(this.instanceId_);
527        if (callback !== undefined) {
528            callback();
529        }
530        __JSScopeUtil__.restoreInstanceId();
531    }
532
533    setKeyboardAvoidMode(value) {
534        __JSScopeUtil__.syncInstanceId(this.instanceId_);
535        __KeyboardAvoid__.setKeyboardAvoid(value);
536        __JSScopeUtil__.restoreInstanceId();
537    }
538
539    getKeyboardAvoidMode() {
540        __JSScopeUtil__.syncInstanceId(this.instanceId_);
541        let keyBoardAvoidMode = __KeyboardAvoid__.getKeyboardAvoid();
542        __JSScopeUtil__.restoreInstanceId();
543        return keyBoardAvoidMode;
544    }
545
546    setPixelRoundMode(pixelRoundMode) {
547        __JSScopeUtil__.syncInstanceId(this.instanceId_);
548        JSViewAbstract.setPixelRoundMode(pixelRoundMode);
549        __JSScopeUtil__.restoreInstanceId();
550    }
551
552    getPixelRoundMode() {
553        __JSScopeUtil__.syncInstanceId(this.instanceId_);
554        let pixelRoundMode = JSViewAbstract.getPixelRoundMode();
555        __JSScopeUtil__.restoreInstanceId();
556        return pixelRoundMode;
557    }
558
559    dispatchKeyEvent(node, event) {
560        __JSScopeUtil__.syncInstanceId(this.instanceId_);
561        let result = JSViewAbstract.dispatchKeyEvent(node, event);
562        __JSScopeUtil__.restoreInstanceId();
563        return result;
564    }
565
566    getAtomicServiceBar() {
567        const bundleMgr = globalThis.requireNapi('bundle.bundleManager');
568        if (!bundleMgr || !bundleMgr.BundleFlag) {
569            return undefined;
570        }
571        let data = bundleMgr.getBundleInfoForSelfSync(bundleMgr.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION);
572        if (data.appInfo.bundleType == 1) {
573            this.atomServiceBar = new AtomicServiceBar(this.instanceId_);
574            return this.atomServiceBar;
575        } else {
576            return undefined;
577        }
578    }
579
580    getUIObserver() {
581        this.observer_ = new UIObserver(this.instanceId_);
582        return this.observer_;
583    }
584
585    keyframeAnimateTo(param, keyframes) {
586        __JSScopeUtil__.syncInstanceId(this.instanceId_);
587        Context.keyframeAnimateTo(param, keyframes);
588        __JSScopeUtil__.restoreInstanceId();
589    }
590
591    animateToImmediately(param, event) {
592        __JSScopeUtil__.syncInstanceId(this.instanceId_);
593        Context.animateToImmediately(param, event);
594        __JSScopeUtil__.restoreInstanceId();
595    }
596
597    getMeasureUtils() {
598        this.measureUtils_ = new MeasureUtils(this.instanceId_);
599        return this.measureUtils_;
600    }
601
602    getHostContext() {
603        __JSScopeUtil__.syncInstanceId(this.instanceId_);
604        let context = getContext();
605        __JSScopeUtil__.restoreInstanceId();
606        return context;
607    }
608
609    getSharedLocalStorage() {
610        __JSScopeUtil__.syncInstanceId(this.instanceId_);
611        let localStorage = NativeLocalStorage.GetShared();
612        __JSScopeUtil__.restoreInstanceId();
613        return localStorage;
614    }
615
616    getFrameNodeById(id) {
617        __JSScopeUtil__.syncInstanceId(this.instanceId_);
618        let nodePtr = getUINativeModule().getFrameNodeByKey(id);
619        if (!nodePtr) {
620            __JSScopeUtil__.restoreInstanceId();
621            return null;
622        }
623        let xNode = globalThis.__getArkUINode__();
624        let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr);
625        if (!node) {
626            node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr);
627        }
628        __JSScopeUtil__.restoreInstanceId();
629        return node;
630    }
631
632    getAttachedFrameNodeById(id) {
633        __JSScopeUtil__.syncInstanceId(this.instanceId_);
634        let nodePtr = getUINativeModule().getAttachedFrameNodeById(id);
635        if (!nodePtr) {
636            __JSScopeUtil__.restoreInstanceId();
637            return null;
638        }
639        let xNode = globalThis.__getArkUINode__();
640        let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr);
641        if (!node) {
642            node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr);
643        }
644        __JSScopeUtil__.restoreInstanceId();
645        return node;
646    }
647
648    getFrameNodeByNodeId(id) {
649        __JSScopeUtil__.syncInstanceId(this.instanceId_);
650        let nodePtr = getUINativeModule().getFrameNodeById(id);
651        let xNode = globalThis.__getArkUINode__();
652        let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr);
653        if (!node) {
654            node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr);
655        }
656        __JSScopeUtil__.restoreInstanceId();
657        return node;
658    }
659
660    getFrameNodeByUniqueId(uniqueId) {
661        __JSScopeUtil__.syncInstanceId(this.instanceId_);
662        let nodePtr = getUINativeModule().getFrameNodeByUniqueId(uniqueId);
663        if (nodePtr === undefined) {
664            __JSScopeUtil__.restoreInstanceId();
665            return null;
666        }
667        let xNode = globalThis.__getArkUINode__();
668        let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr);
669        if (!node) {
670            node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr);
671        }
672        __JSScopeUtil__.restoreInstanceId();
673        return node;
674    }
675
676    getPageInfoByUniqueId(uniqueId) {
677        __JSScopeUtil__.syncInstanceId(this.instanceId_);
678        const pageInfo = getUINativeModule().getPageInfoByUniqueId(uniqueId);
679        __JSScopeUtil__.restoreInstanceId();
680        return pageInfo;
681    }
682
683    getNavigationInfoByUniqueId(uniqueId) {
684        __JSScopeUtil__.syncInstanceId(this.instanceId_);
685        const navigationInfo = getUINativeModule().getNavigationInfoByUniqueId(uniqueId);
686        __JSScopeUtil__.restoreInstanceId();
687        return navigationInfo;
688    }
689
690    getFocusController() {
691        if (this.focusController_ == null) {
692            this.focusController_ = new FocusController(this.instanceId_);
693        }
694        return this.focusController_;
695    }
696
697    setDynamicDimming(id, number) {
698        __JSScopeUtil__.syncInstanceId(this.instanceId_);
699        let nodePtr = getUINativeModule().getFrameNodeByKey(id);
700        if (!nodePtr) {
701            return;
702        }
703        Context.setDynamicDimming(nodePtr, number);
704    }
705
706    getCursorController() {
707        if (this.cursorController_ == null) {
708            this.cursorController_ = new CursorController(this.instanceId_);
709        }
710        return this.cursorController_;
711    }
712
713    getContextMenuController() {
714        if (this.contextMenuController_ == null) {
715            this.contextMenuController_ = new ContextMenuController(this.instanceId_);
716        }
717        return this.contextMenuController_;
718    }
719
720    getWindowName() {
721        __JSScopeUtil__.syncInstanceId(this.instanceId_);
722        const windowName = getUINativeModule().common.getWindowName();
723        __JSScopeUtil__.restoreInstanceId();
724        return windowName;
725    }
726
727    getWindowWidthBreakpoint() {
728        __JSScopeUtil__.syncInstanceId(this.instanceId_);
729        const breakpoint = getUINativeModule().common.getWindowWidthBreakpoint();
730        __JSScopeUtil__.restoreInstanceId();
731        return breakpoint;
732    }
733
734    getWindowHeightBreakpoint() {
735        __JSScopeUtil__.syncInstanceId(this.instanceId_);
736        const breakpoint = getUINativeModule().common.getWindowHeightBreakpoint();
737        __JSScopeUtil__.restoreInstanceId();
738        return breakpoint;
739    }
740
741    clearResourceCache() {
742        getUINativeModule().resource.clearCache();
743    }
744
745    postFrameCallback(frameCallback) {
746        __JSScopeUtil__.syncInstanceId(this.instanceId_);
747        getUINativeModule().common.postFrameCallback(frameCallback, 0);
748        __JSScopeUtil__.restoreInstanceId();
749    }
750
751    postDelayedFrameCallback(frameCallback, delayMillis) {
752        __JSScopeUtil__.syncInstanceId(this.instanceId_);
753        getUINativeModule().common.postFrameCallback(frameCallback, delayMillis);
754        __JSScopeUtil__.restoreInstanceId();
755    }
756
757    requireDynamicSyncScene(id) {
758        __JSScopeUtil__.syncInstanceId(this.instanceId_);
759        let dynamicSceneInfo = getUINativeModule().requireDynamicSyncScene(id);
760        if (!dynamicSceneInfo) {
761            __JSScopeUtil__.restoreInstanceId();
762            return [];
763        }
764        if (dynamicSceneInfo.tag === 'Swiper') {
765            __JSScopeUtil__.restoreInstanceId();
766            let nodeRef = dynamicSceneInfo.nativeRef;
767            return SwiperDynamicSyncScene.createInstances(nodeRef);
768        }
769        if (dynamicSceneInfo.tag === 'Marquee') {
770            __JSScopeUtil__.restoreInstanceId();
771            let nodeRef = dynamicSceneInfo.nativeRef;
772            return MarqueeDynamicSyncScene.createInstances(nodeRef);
773        }
774        __JSScopeUtil__.restoreInstanceId();
775        return [];
776    }
777
778    isFollowingSystemFontScale() {
779        __JSScopeUtil__.syncInstanceId(this.instanceId_);
780        let isFollowing = Context.isFollowingSystemFontScale();
781        __JSScopeUtil__.restoreInstanceId();
782        return isFollowing;
783    }
784
785    getMaxFontScale() {
786        __JSScopeUtil__.syncInstanceId(this.instanceId_);
787        let maxFontScale = Context.getMaxFontScale();
788        __JSScopeUtil__.restoreInstanceId();
789        return maxFontScale;
790    }
791
792    bindTabsToScrollable(tabsController, scroller) {
793        __JSScopeUtil__.syncInstanceId(this.instanceId_);
794        Context.bindTabsToScrollable(tabsController, scroller);
795        __JSScopeUtil__.restoreInstanceId();
796    }
797
798    unbindTabsFromScrollable(tabsController, scroller) {
799        __JSScopeUtil__.syncInstanceId(this.instanceId_);
800        Context.unbindTabsFromScrollable(tabsController, scroller);
801        __JSScopeUtil__.restoreInstanceId();
802    }
803
804    bindTabsToNestedScrollable(tabsController, parentScroller, childScroller) {
805        __JSScopeUtil__.syncInstanceId(this.instanceId_);
806        Context.bindTabsToNestedScrollable(tabsController, parentScroller, childScroller);
807        __JSScopeUtil__.restoreInstanceId();
808    }
809
810    unbindTabsFromNestedScrollable(tabsController, parentScroller, childScroller) {
811        __JSScopeUtil__.syncInstanceId(this.instanceId_);
812        Context.unbindTabsFromNestedScrollable(tabsController, parentScroller, childScroller);
813        __JSScopeUtil__.restoreInstanceId();
814    }
815
816    enableSwipeBack(enabled) {
817        __JSScopeUtil__.syncInstanceId(this.instanceId_);
818        Context.enableSwipeBack(enabled);
819        __JSScopeUtil__.restoreInstanceId();
820    }
821
822    getTextMenuController() {
823        if (this.textMenuController_ == null) {
824            this.textMenuController_ = new TextMenuController(this.instanceId_);
825        }
826        return this.textMenuController_;
827    }
828
829    freezeUINode(idOrUniqueId, isFreeze) {
830        __JSScopeUtil__.syncInstanceId(this.instanceId_);
831        if (typeof idOrUniqueId === "string") {
832            getUINativeModule().common.freezeUINodeById(idOrUniqueId, isFreeze);
833        } else if (typeof idOrUniqueId === "number") {
834            getUINativeModule().common.freezeUINodeByUniqueId(idOrUniqueId, isFreeze);
835        }
836        __JSScopeUtil__.restoreInstanceId();
837    }
838}
839
840class DynamicSyncScene {
841    /**
842     * Construct new instance of DynamicSyncScene.
843     * initialize with instanceId.
844     * @param {Object} nodeRef - obtained on the c++ side.
845     * @param {Object} frameRateRange - frameRateRange
846     * @since 12
847     */
848    constructor(nodeRef, frameRateRange) {
849        this.frameRateRange = { ...frameRateRange };
850        if (!nodeRef.invalid()) {
851            this.nodeRef = nodeRef;
852            this.nodePtr = this.nodeRef.getNativeHandle();
853        }
854    }
855
856    /**
857     * Get the frame rate range.
858     * @returns {Object} The frame rate range.
859     */
860    getFrameRateRange() {
861        return this.frameRateRange;
862    }
863}
864
865class SwiperDynamicSyncScene extends DynamicSyncScene {
866    /**
867     * Create instances of SwiperDynamicSyncScene.
868     * @param {Object} nodeRef - obtained on the c++ side.
869     * @returns {SwiperDynamicSyncScene[]} Array of SwiperDynamicSyncScene instances.
870     */
871    static createInstances(nodeRef) {
872        return [new SwiperDynamicSyncScene(nodeRef, 0), new SwiperDynamicSyncScene(nodeRef, 1)];
873    }
874
875    /**
876     * Construct new instance of SwiperDynamicSyncScene.
877     * @param {Object} nodeRef - obtained on the c++ side.
878     * @param {number} type - type of the scenes.
879     */
880    constructor(nodeRef, type) {
881        super(nodeRef, { min: 0, max: 120, expected: 120 });
882        this.type = type;
883    }
884
885    /**
886     * Set the frame rate range.
887     * @param {Object} frameRateRange - The new frame rate range.
888     */
889    setFrameRateRange(frameRateRange) {
890        this.frameRateRange = { ...frameRateRange };
891        getUINativeModule().setFrameRateRange(this.nodePtr, frameRateRange, this.type);
892    }
893}
894
895class MarqueeDynamicSyncScene extends DynamicSyncScene {
896    /**
897     * Create instances of MarqueeDynamicSyncScene.
898     * @param {Object} nodeRef - obtained on the c++ side.
899     * @returns {MarqueeDynamicSyncScene[]} Array of MarqueeDynamicSyncScene instances.
900     */
901    static createInstances(nodeRef) {
902        return [new MarqueeDynamicSyncScene(nodeRef, 1)];
903    }
904
905    /**
906     * Construct new instance of MarqueeDynamicSyncScene.
907     * @param {Object} nodeRef - obtained on the c++ side.
908     */
909    constructor(nodeRef, type) {
910        super(nodeRef, { min: 0, max: 120, expected: 120 });
911        this.type = type;
912    }
913
914    /**
915     * Set the frame rate range.
916     * @param {Object} frameRateRange - The new frame rate range.
917     */
918    setFrameRateRange(frameRateRange) {
919        this.frameRateRange = { ...frameRateRange }; // 确保每个实例有独立的frameRateRange
920        getUINativeModule().setMarqueeFrameRateRange(this.nodePtr, frameRateRange, this.type);
921    }
922}
923
924class FocusController {
925    /**
926     * Construct new instance of FocusController.
927     * initialize with instanceId.
928     * @param instanceId obtained on the c++ side.
929     * @since 12
930     */
931    constructor(instanceId) {
932        this.instanceId_ = instanceId;
933        this.ohos_focusController = globalThis.requireNapi('arkui.focusController');
934    }
935
936    clearFocus() {
937        if (this.ohos_focusController === null || this.ohos_focusController === undefined) {
938            return;
939        }
940        __JSScopeUtil__.syncInstanceId(this.instanceId_);
941        this.ohos_focusController.clearFocus();
942        __JSScopeUtil__.restoreInstanceId();
943    }
944
945    requestFocus(value) {
946        if (this.ohos_focusController === null || this.ohos_focusController === undefined) {
947            return false;
948        }
949        __JSScopeUtil__.syncInstanceId(this.instanceId_);
950        let result = this.ohos_focusController.requestFocus(value);
951        __JSScopeUtil__.restoreInstanceId();
952        return result;
953    }
954
955    activate(isActive, autoInactive) {
956        if (this.ohos_focusController === null || this.ohos_focusController === undefined) {
957            return false;
958        }
959        __JSScopeUtil__.syncInstanceId(this.instanceId_);
960        if (arguments.length === 2) {
961            let result = this.ohos_focusController.activate(isActive, autoInactive);
962            __JSScopeUtil__.restoreInstanceId();
963            return result;
964        } else {
965            let result = this.ohos_focusController.activate(isActive);
966            __JSScopeUtil__.restoreInstanceId();
967            return result;
968        }
969    }
970
971    setAutoFocusTransfer(value) {
972        if (this.ohos_focusController === null || this.ohos_focusController === undefined) {
973            return;
974        }
975        __JSScopeUtil__.syncInstanceId(this.instanceId_);
976        this.ohos_focusController.setAutoFocusTransfer(value);
977        __JSScopeUtil__.restoreInstanceId();
978    }
979
980    configWindowMask(enable) {
981        if (this.ohos_focusController === null || this.ohos_focusController === undefined) {
982            return;
983        }
984        __JSScopeUtil__.syncInstanceId(this.instanceId_);
985        this.ohos_focusController.configWindowMask(enable);
986        __JSScopeUtil__.restoreInstanceId();
987    }
988
989    setKeyProcessingMode(value) {
990        if (this.ohos_focusController === null || this.ohos_focusController === undefined) {
991            return;
992        }
993        __JSScopeUtil__.syncInstanceId(this.instanceId_);
994        this.ohos_focusController.setKeyProcessingMode(value);
995        __JSScopeUtil__.restoreInstanceId();
996    }
997}
998
999class CursorController {
1000    /**
1001     * Construct new instance of CursorController.
1002     * initialzie with instanceId.
1003     * @param instanceId obtained on the c++ side.
1004     * @since 12
1005     */
1006    constructor(instanceId) {
1007        this.instanceId_ = instanceId;
1008    }
1009
1010    restoreDefault() {
1011        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1012        cursorControl.restoreDefault();
1013        __JSScopeUtil__.restoreInstanceId();
1014    }
1015
1016    setCursor(value) {
1017        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1018        cursorControl.setCursor(value);
1019        __JSScopeUtil__.restoreInstanceId();
1020    }
1021}
1022
1023class ContextMenuController {
1024    /**
1025     * Construct new instance of ContextMenuController.
1026     * initialzie with instanceId.
1027     * @param instanceId obtained on the c++ side.
1028     * @since 12
1029     */
1030    constructor(instanceId) {
1031        this.instanceId_ = instanceId;
1032    }
1033
1034    close() {
1035        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1036        ContextMenu.close();
1037        __JSScopeUtil__.restoreInstanceId();
1038    }
1039}
1040
1041class ComponentUtils {
1042    /**
1043     * Construct new instance of ComponentUtils.
1044     * initialize with instanceId.
1045     * @param instanceId obtained on the c++ side.
1046     * @since 10
1047     */
1048    constructor(instanceId) {
1049        this.instanceId_ = instanceId;
1050        this.ohos_componentUtils = globalThis.requireNapi('arkui.componentUtils');
1051    }
1052    getRectangleById(id) {
1053        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1054        if (typeof this.ohos_componentUtils.getRectangleById !== 'function'){
1055            throw Error('getRectangleById is not callable');
1056        }
1057        let componentInformation = this.ohos_componentUtils?.getRectangleById?.(id);
1058        __JSScopeUtil__.restoreInstanceId();
1059        return componentInformation;
1060    }
1061}
1062
1063class Router {
1064    /**
1065     * Construct new instance of Font.
1066     * initialize with instanceId.
1067     * @param instanceId obtained on the c++ side.
1068     * @since 10
1069     */
1070    constructor(instanceId) {
1071        this.instanceId_ = instanceId;
1072        this.ohos_router = globalThis.requireNapi('router');
1073    }
1074
1075    pushUrl(options, modeOrCallback, callback) {
1076        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1077        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
1078            let promise = this.ohos_router.pushUrl(options);
1079            __JSScopeUtil__.restoreInstanceId();
1080            return promise;
1081        }
1082        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
1083            this.ohos_router.pushUrl(options, modeOrCallback, callback);
1084            __JSScopeUtil__.restoreInstanceId();
1085        }
1086        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
1087            let promise = this.ohos_router.pushUrl(options, modeOrCallback);
1088            __JSScopeUtil__.restoreInstanceId();
1089            if (promise) {
1090                return promise;
1091            }
1092        }
1093    }
1094
1095    replaceUrl(options, modeOrCallback, callback) {
1096        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1097        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
1098            let promise = this.ohos_router.replaceUrl(options);
1099            __JSScopeUtil__.restoreInstanceId();
1100            return promise;
1101        }
1102        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
1103            this.ohos_router.replaceUrl(options, modeOrCallback, callback);
1104            __JSScopeUtil__.restoreInstanceId();
1105        }
1106        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
1107            let promise = this.ohos_router.replaceUrl(options, modeOrCallback);
1108            __JSScopeUtil__.restoreInstanceId();
1109            if (promise) {
1110                return promise;
1111            }
1112        }
1113    }
1114
1115    back(options, params) {
1116        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1117        if (typeof options === 'number' || arguments.length === 2) {
1118            this.ohos_router.back(options, params);
1119        } else {
1120            this.ohos_router.back(options);
1121        }
1122        __JSScopeUtil__.restoreInstanceId();
1123    }
1124
1125    clear() {
1126        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1127        this.ohos_router.clear();
1128        __JSScopeUtil__.restoreInstanceId();
1129    }
1130
1131    getLength() {
1132        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1133        let result = this.ohos_router.getLength();
1134        __JSScopeUtil__.restoreInstanceId();
1135        return result;
1136    }
1137
1138    getState() {
1139        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1140        let state = this.ohos_router.getState();
1141        __JSScopeUtil__.restoreInstanceId();
1142        return state;
1143    }
1144
1145    getStateByIndex(index) {
1146        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1147        let state = this.ohos_router.getStateByIndex(index);
1148        __JSScopeUtil__.restoreInstanceId();
1149        return state;
1150    }
1151
1152    getStateByUrl(url) {
1153        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1154        let state = this.ohos_router.getStateByUrl(url);
1155        __JSScopeUtil__.restoreInstanceId();
1156        return state;
1157    }
1158
1159    showAlertBeforeBackPage(options) {
1160        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1161        this.ohos_router.showAlertBeforeBackPage(options);
1162        __JSScopeUtil__.restoreInstanceId();
1163    }
1164
1165    hideAlertBeforeBackPage() {
1166        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1167        this.ohos_router.hideAlertBeforeBackPage();
1168        __JSScopeUtil__.restoreInstanceId();
1169    }
1170
1171    getParams() {
1172        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1173        let object = this.ohos_router.getParams();
1174        __JSScopeUtil__.restoreInstanceId();
1175        return object;
1176    }
1177
1178    pushNamedRoute(options, modeOrCallback, callback) {
1179        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1180        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
1181            let promise = this.ohos_router.pushNamedRoute(options);
1182            __JSScopeUtil__.restoreInstanceId();
1183            return promise;
1184        }
1185        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
1186            this.ohos_router.pushNamedRoute(options, modeOrCallback, callback);
1187            __JSScopeUtil__.restoreInstanceId();
1188        }
1189        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
1190            let promise = this.ohos_router.pushNamedRoute(options, modeOrCallback);
1191            __JSScopeUtil__.restoreInstanceId();
1192            if (promise) {
1193                return promise;
1194            }
1195        }
1196    }
1197
1198    replaceNamedRoute(options, modeOrCallback, callback) {
1199        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1200        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
1201            let promise = this.ohos_router.replaceNamedRoute(options);
1202            __JSScopeUtil__.restoreInstanceId();
1203            return promise;
1204        }
1205        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
1206            this.ohos_router.replaceNamedRoute(options, modeOrCallback, callback);
1207            __JSScopeUtil__.restoreInstanceId();
1208        }
1209        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
1210            let promise = this.ohos_router.replaceNamedRoute(options, modeOrCallback);
1211            __JSScopeUtil__.restoreInstanceId();
1212            if (promise) {
1213                return promise;
1214            }
1215        }
1216    }
1217}
1218
1219class PromptAction {
1220    /**
1221     * Construct new instance of PromptAction.
1222     * initialize with instanceId.
1223     * @param instanceId obtained on the c++ side.
1224     * @since 10
1225     */
1226    constructor(instanceId) {
1227        this.instanceId_ = instanceId;
1228        this.ohos_prompt = globalThis.requireNapi('promptAction');
1229    }
1230
1231    showToast(options) {
1232        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1233        this.ohos_prompt.showToast(options);
1234        __JSScopeUtil__.restoreInstanceId();
1235    }
1236
1237    openToast(options) {
1238        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1239        let promise = this.ohos_prompt.openToast(options);
1240        __JSScopeUtil__.restoreInstanceId();
1241        return promise;
1242    }
1243
1244    closeToast(toastId) {
1245        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1246        this.ohos_prompt.closeToast(toastId);
1247        __JSScopeUtil__.restoreInstanceId();
1248    }
1249
1250    showDialog(options, callback) {
1251        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1252        if (typeof callback !== 'undefined') {
1253            this.ohos_prompt.showDialog(options, callback);
1254            __JSScopeUtil__.restoreInstanceId();
1255        }
1256        else {
1257            let showDialogSuccessResponse = this.ohos_prompt.showDialog(options);
1258            __JSScopeUtil__.restoreInstanceId();
1259            return showDialogSuccessResponse;
1260        }
1261    }
1262
1263    openCustomDialog(content, options) {
1264        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1265        if (arguments.length === 2) {
1266            let result_ = this.ohos_prompt.openCustomDialog(content.getFrameNode(), options);
1267            __JSScopeUtil__.restoreInstanceId();
1268            return result_;
1269        }
1270        else {
1271            if (content.builderNode_ === undefined) {
1272                let result_ = this.ohos_prompt.openCustomDialog(content);
1273                __JSScopeUtil__.restoreInstanceId();
1274                return result_;
1275            }
1276            else {
1277                let result_ = this.ohos_prompt.openCustomDialog(content.getFrameNode());
1278                __JSScopeUtil__.restoreInstanceId();
1279                return result_;
1280            }
1281        }
1282    }
1283
1284    openCustomDialogWithController(content, controller, options) {
1285        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1286        let paramErrMsg =
1287            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
1288            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
1289        let isDialogController = controller instanceof this.ohos_prompt.DialogController;
1290        if (!isDialogController) {
1291            __JSScopeUtil__.restoreInstanceId();
1292            return new Promise((resolve, reject) => {
1293                reject({ message: paramErrMsg, code: 401 });
1294            });
1295        }
1296        if (typeof options === 'undefined') {
1297            let result_ = this.ohos_prompt.openCustomDialogWithController(content.getFrameNode(), controller);
1298            __JSScopeUtil__.restoreInstanceId();
1299            return result_;
1300        }
1301        let result_ = this.ohos_prompt.openCustomDialogWithController(content.getFrameNode(), controller, options);
1302        __JSScopeUtil__.restoreInstanceId();
1303        return result_;
1304    }
1305
1306    presentCustomDialog(builder, controller, options) {
1307        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1308        if (typeof controller === 'undefined' && typeof options === 'undefined') {
1309            let result_ = this.ohos_prompt.presentCustomDialog(builder);
1310            __JSScopeUtil__.restoreInstanceId();
1311            return result_;
1312        }
1313        let paramErrMsg =
1314            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
1315            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
1316        let isDialogController = controller instanceof this.ohos_prompt.DialogController;
1317        if (!isDialogController) {
1318            __JSScopeUtil__.restoreInstanceId();
1319            return new Promise((resolve, reject) => {
1320                reject({ message: paramErrMsg, code: 401 });
1321            });
1322        }
1323        if (typeof options === 'undefined') {
1324            let result_ = this.ohos_prompt.presentCustomDialog(builder, controller);
1325            __JSScopeUtil__.restoreInstanceId();
1326            return result_;
1327        }
1328        let result_ = this.ohos_prompt.presentCustomDialog(builder, controller, options);
1329        __JSScopeUtil__.restoreInstanceId();
1330        return result_;
1331    }
1332
1333    updateCustomDialog(content, options) {
1334        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1335        let result_ = this.ohos_prompt.updateCustomDialog(content.getFrameNode(), options);
1336        __JSScopeUtil__.restoreInstanceId();
1337        return result_;
1338    }
1339
1340    closeCustomDialog(content) {
1341        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1342        if (typeof content === 'number') {
1343            this.ohos_prompt.closeCustomDialog(content);
1344            __JSScopeUtil__.restoreInstanceId();
1345        }
1346        else {
1347            let result_ = this.ohos_prompt.closeCustomDialog(content.getFrameNode());
1348            __JSScopeUtil__.restoreInstanceId();
1349            return result_;
1350        }
1351    }
1352
1353    getTopOrder() {
1354        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1355        let result_ = this.ohos_prompt.__getTopOrder__();
1356        __JSScopeUtil__.restoreInstanceId();
1357        return result_;
1358    }
1359
1360    getBottomOrder() {
1361        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1362        let result_ = this.ohos_prompt.__getBottomOrder__();
1363        __JSScopeUtil__.restoreInstanceId();
1364        return result_;
1365    }
1366
1367    openPopup(content, target, options) {
1368        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1369        let argLength = arguments.length;
1370        let paramErrMsg =
1371            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
1372            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
1373        if (argLength < 2 || argLength > 3 || content === null || content === undefined || target === null || target === undefined) {
1374            __JSScopeUtil__.restoreInstanceId();
1375            return new Promise((resolve, reject) => {
1376                reject({ message: paramErrMsg, code: 401 });
1377            });
1378        }
1379        let result_;
1380        if (argLength === 2) {
1381            result_ = Context.openPopup(content.getNodePtr(), target);
1382        } else {
1383            result_ = Context.openPopup(content.getNodePtr(), target, options);
1384        }
1385        __JSScopeUtil__.restoreInstanceId();
1386        return result_;
1387    }
1388
1389    updatePopup(content, options, partialUpdate) {
1390        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1391        let argLength = arguments.length;
1392        let paramErrMsg =
1393            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
1394            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
1395        if (argLength < 2 || argLength > 3 || content === null || content === undefined || options === null || options === undefined) {
1396            __JSScopeUtil__.restoreInstanceId();
1397            return new Promise((resolve, reject) => {
1398                reject({ message: paramErrMsg, code: 401 });
1399            });
1400        }
1401        let result_;
1402        if (argLength === 2) {
1403            result_ = Context.updatePopup(content.getNodePtr(), options);
1404        } else {
1405            result_ = Context.updatePopup(content.getNodePtr(), options, partialUpdate);
1406        }
1407        __JSScopeUtil__.restoreInstanceId();
1408        return result_;
1409    }
1410
1411    closePopup(content) {
1412        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1413        let argLength = arguments.length;
1414        const paramErrMsg =
1415            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
1416            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
1417        if (argLength !== 1 || content === null || content === undefined) {
1418            __JSScopeUtil__.restoreInstanceId();
1419            return new Promise((resolve, reject) => {
1420                reject({ message: paramErrMsg, code: 401 });
1421            });
1422        }
1423        let result_ = Context.closePopup(content.getNodePtr());
1424        __JSScopeUtil__.restoreInstanceId();
1425        return result_;
1426    }
1427
1428    openMenu(content, target, options) {
1429        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1430        let argLength = arguments.length;
1431        let paramErrMsg =
1432            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
1433            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
1434        if (argLength < 2 || argLength > 3 || content === null || content === undefined || target === null || target === undefined) {
1435            __JSScopeUtil__.restoreInstanceId();
1436            return new Promise((resolve, reject) => {
1437                reject({ message: paramErrMsg, code: 401 });
1438            });
1439        }
1440        let result_;
1441        if (argLength === 2) {
1442            result_ = Context.openMenu(content.getNodePtr(), target);
1443        } else {
1444            result_ = Context.openMenu(content.getNodePtr(), target, options);
1445        }
1446        __JSScopeUtil__.restoreInstanceId();
1447        return result_;
1448    }
1449
1450    updateMenu(content, options, partialUpdate) {
1451        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1452        let argLength = arguments.length;
1453        let paramErrMsg =
1454            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
1455            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
1456        if (argLength < 2 || argLength > 3 || content === null || content === undefined || options === null || options === undefined) {
1457            __JSScopeUtil__.restoreInstanceId();
1458            return new Promise((resolve, reject) => {
1459                reject({ message: paramErrMsg, code: 401 });
1460            });
1461        }
1462        let result_;
1463        if (argLength === 2) {
1464            result_ = Context.updateMenu(content.getNodePtr(), options);
1465        } else {
1466            result_ = Context.updateMenu(content.getNodePtr(), options, partialUpdate);
1467        }
1468        __JSScopeUtil__.restoreInstanceId();
1469        return result_;
1470    }
1471
1472    closeMenu(content) {
1473        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1474        let argLength = arguments.length;
1475        const paramErrMsg =
1476            'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' +
1477            ' 2. Incorrect parameter types; 3. Parameter verification failed.';
1478        if (argLength !== 1 || content === null || content === undefined) {
1479            __JSScopeUtil__.restoreInstanceId();
1480            return new Promise((resolve, reject) => {
1481                reject({ message: paramErrMsg, code: 401 });
1482            });
1483        }
1484        let result_ = Context.closeMenu(content.getNodePtr());
1485        __JSScopeUtil__.restoreInstanceId();
1486        return result_;
1487    }
1488
1489    showActionMenu(options, callback) {
1490        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1491        if (typeof callback !== 'undefined') {
1492            this.ohos_prompt.showActionMenu(options, callback);
1493            __JSScopeUtil__.restoreInstanceId();
1494        }
1495        else {
1496            let actionMenuSuccessResponse = this.ohos_prompt.showActionMenu(options);
1497            __JSScopeUtil__.restoreInstanceId();
1498            return actionMenuSuccessResponse;
1499        }
1500    }
1501}
1502
1503class AtomicServiceBar {
1504    /**
1505     * Construct new instance of AtomicServiceBar.
1506     * initialize with instanceId.
1507     * @param instanceId obtained on the c++ side.
1508     * @since 11
1509     */
1510    constructor(instanceId) {
1511        this.instanceId_ = instanceId;
1512        this.ohos_atomicServiceBar = globalThis.requireNapi('atomicservicebar');
1513    }
1514
1515    setVisible(visible) {
1516        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1517        this.ohos_atomicServiceBar.setVisible(visible);
1518        __JSScopeUtil__.restoreInstanceId();
1519    }
1520
1521    setBackgroundColor(color) {
1522        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1523        this.ohos_atomicServiceBar.setBackgroundColor(color);
1524        __JSScopeUtil__.restoreInstanceId();
1525    }
1526
1527    setTitleContent(content) {
1528        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1529        this.ohos_atomicServiceBar.setTitleContent(content);
1530        __JSScopeUtil__.restoreInstanceId();
1531    }
1532
1533    setTitleFontStyle(font) {
1534        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1535        this.ohos_atomicServiceBar.setTitleFontStyle(font);
1536        __JSScopeUtil__.restoreInstanceId();
1537    }
1538
1539    setIconColor(color) {
1540        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1541        this.ohos_atomicServiceBar.setIconColor(color);
1542        __JSScopeUtil__.restoreInstanceId();
1543    }
1544
1545    getBarRect() {
1546        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1547        let rect = this.ohos_atomicServiceBar.getBarRect();
1548        __JSScopeUtil__.restoreInstanceId();
1549        return rect;
1550    }
1551}
1552
1553class OverlayManager {
1554    /**
1555     * Construct new instance of Overlay.
1556     * initialize with instanceId.
1557     * @param instanceId obtained on the c++ side.
1558     * @since 12
1559     */
1560    constructor(instanceId) {
1561        this.instanceId_ = instanceId;
1562        this.ohos_overlayManager = globalThis.requireNapi('overlay');
1563    }
1564
1565    setOverlayManagerOptions(options) {
1566        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1567        let res = this.ohos_overlayManager.setOverlayManagerOptions(options);
1568        __JSScopeUtil__.restoreInstanceId();
1569        return res;
1570    }
1571
1572    getOverlayManagerOptions() {
1573        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1574        let res = this.ohos_overlayManager.getOverlayManagerOptions();
1575        __JSScopeUtil__.restoreInstanceId();
1576        return res;
1577    }
1578
1579    addComponentContent(content, index) {
1580        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1581        if (typeof index !== 'undefined') {
1582            this.ohos_overlayManager.addFrameNode(content.getFrameNode(), index);
1583        } else {
1584            this.ohos_overlayManager.addFrameNode(content.getFrameNode());
1585        }
1586        __JSScopeUtil__.restoreInstanceId();
1587    }
1588
1589    addComponentContentWithOrder(content, levelOrder) {
1590        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1591        if (typeof levelOrder !== 'undefined') {
1592            this.ohos_overlayManager.addFrameNodeWithOrder(content.getFrameNode(), levelOrder);
1593        } else {
1594            this.ohos_overlayManager.addFrameNodeWithOrder(content.getFrameNode());
1595        }
1596        __JSScopeUtil__.restoreInstanceId();
1597    }
1598
1599    removeComponentContent(content) {
1600        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1601        this.ohos_overlayManager.removeFrameNode(content.getFrameNode());
1602        __JSScopeUtil__.restoreInstanceId();
1603    }
1604
1605    showComponentContent(content) {
1606        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1607        this.ohos_overlayManager.showNode(content.getFrameNode());
1608        __JSScopeUtil__.restoreInstanceId();
1609    }
1610
1611    hideComponentContent(content) {
1612        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1613        this.ohos_overlayManager.hideNode(content.getFrameNode());
1614        __JSScopeUtil__.restoreInstanceId();
1615    }
1616
1617    showAllComponentContents() {
1618        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1619        this.ohos_overlayManager.showAllFrameNodes();
1620        __JSScopeUtil__.restoreInstanceId();
1621    }
1622
1623    hideAllComponentContents() {
1624        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1625        this.ohos_overlayManager.hideAllFrameNodes();
1626        __JSScopeUtil__.restoreInstanceId();
1627    }
1628}
1629
1630class TextMenuController {
1631    /**
1632     * Construct new instance of TextMenuController.
1633     * initialzie with instanceId.
1634     * @param instanceId obtained on the c++ side.
1635     * @since 16
1636     */
1637    constructor(instanceId) {
1638        this.instanceId_ = instanceId;
1639    }
1640
1641    setMenuOptions(textMenuOptions) {
1642        __JSScopeUtil__.syncInstanceId(this.instanceId_);
1643        TextMenu.setMenuOptions(textMenuOptions);
1644        __JSScopeUtil__.restoreInstanceId();
1645    }
1646}
1647
1648/**
1649 * Get UIContext instance.
1650 * @param instanceId obtained on the c++ side.
1651 * @returns UIContext instance.
1652 */
1653function __getUIContext__(instanceId) {
1654    return new UIContext(instanceId);
1655}
1656
1657/**
1658 * Get FrameNode by id of UIContext instance.
1659 * @param instanceId obtained on the C++ side.
1660 * @param nodeId the id of frameNode.
1661 * @returns FrameNode instance.
1662 */
1663function __getFrameNodeByNodeId__(instanceId, nodeId) {
1664    const uiContext = __getUIContext__(instanceId);
1665    return uiContext.getFrameNodeByNodeId(nodeId);
1666}
1667
1668/**
1669 * check regex valid
1670 * @param pattern regex string
1671 * @returns valid result
1672 */
1673function __checkRegexValid__(pattern) {
1674    let result = true;
1675    try {
1676        new RegExp(pattern);
1677    } catch (error) {
1678        result = false;
1679    } finally {
1680        return result;
1681    }
1682}
1683