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