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