• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024-2025 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/* THIS IS AUTOGENERATED FILE, PLEASE DON`T CHANGE IT MANUALLY */
16class ArkResourcesHelper {
17    static $r(name, id) {
18        let splitted = name.split('.', 2);
19        let strType = splitted[1];
20        let type = undefined;
21        switch (strType) {
22            case 'float':
23                type = ArkResourcesHelper.FLOAT;
24                break;
25            case 'color':
26            default:
27                type = ArkResourcesHelper.COLOR;
28                break;
29        }
30        return { 'id': id !== null && id !== void 0 ? id : -1, 'type': type, 'params': [name], 'bundleName': '', 'moduleName': '' };
31    }
32}
33ArkResourcesHelper.COLOR = 10001;
34ArkResourcesHelper.FLOAT = 10002;
35class ArkThemeNativeHelper {
36    static sendThemeToNative(theme, elmtId, darkSetStatus) {
37        const lightColorArray = ArkThemeNativeHelper.convertColorsToArray(theme.colors);
38        const darkColorArray = ArkThemeNativeHelper.convertColorsToArray(theme.darkColors);
39        WithTheme.sendThemeToNative(lightColorArray, darkColorArray, elmtId, darkSetStatus);
40    }
41    static createInternal(themeScopeId, themeId, theme, colorMode, onThemeScopeDestroy, darkSetStatus) {
42        if (colorMode && colorMode !== ThemeColorMode.SYSTEM) {
43            ArkThemeScopeManager.getInstance().onEnterLocalColorMode(colorMode);
44        }
45        const lightColorArray = ArkThemeNativeHelper.convertColorsToArray(theme === null || theme === void 0 ? void 0 : theme.colors);
46        const darkColorArray = ArkThemeNativeHelper.convertColorsToArray(theme === null || theme === void 0 ? void 0 : theme.darkColors);
47        getUINativeModule().theme.createAndBindTheme(themeScopeId, themeId, lightColorArray, darkColorArray, colorMode, onThemeScopeDestroy, darkSetStatus );
48        if (colorMode && colorMode !== ThemeColorMode.SYSTEM) {
49            ArkThemeScopeManager.getInstance().onExitLocalColorMode();
50        }
51    }
52    static setDefaultTheme(theme) {
53        const colorArray = ArkThemeNativeHelper.convertColorsToArray(theme === null || theme === void 0 ? void 0 : theme.colors);
54        let darkColorArray = [];
55        if(!!theme?.darkColors) {
56            darkColorArray = ArkThemeNativeHelper.convertColorsToArray(theme === null || theme === void 0 ? void 0 : theme.darkColors);
57        }else {
58            darkColorArray = colorArray;
59        }
60
61        ArkThemeScopeManager.getInstance().onEnterLocalColorMode(ThemeColorMode.LIGHT);
62        getUINativeModule().theme.setDefaultTheme(colorArray, false);
63        ArkThemeScopeManager.getInstance().onEnterLocalColorMode(ThemeColorMode.DARK);
64        getUINativeModule().theme.setDefaultTheme(darkColorArray, true);
65        ArkThemeScopeManager.getInstance().onExitLocalColorMode();
66    }
67    static convertThemeToColorArray(theme) {
68        return [
69            theme.colors.brand,
70            theme.colors.warning,
71            theme.colors.alert,
72            theme.colors.confirm,
73            theme.colors.fontPrimary,
74            theme.colors.fontSecondary,
75            theme.colors.fontTertiary,
76            theme.colors.fontFourth,
77            theme.colors.fontEmphasize,
78            theme.colors.fontOnPrimary,
79            theme.colors.fontOnSecondary,
80            theme.colors.fontOnTertiary,
81            theme.colors.fontOnFourth,
82            theme.colors.iconPrimary,
83            theme.colors.iconSecondary,
84            theme.colors.iconTertiary,
85            theme.colors.iconFourth,
86            theme.colors.iconEmphasize,
87            theme.colors.iconSubEmphasize,
88            theme.colors.iconOnPrimary,
89            theme.colors.iconOnSecondary,
90            theme.colors.iconOnTertiary,
91            theme.colors.iconOnFourth,
92            theme.colors.backgroundPrimary,
93            theme.colors.backgroundSecondary,
94            theme.colors.backgroundTertiary,
95            theme.colors.backgroundFourth,
96            theme.colors.backgroundEmphasize,
97            theme.colors.compForegroundPrimary,
98            theme.colors.compBackgroundPrimary,
99            theme.colors.compBackgroundPrimaryTran,
100            theme.colors.compBackgroundPrimaryContrary,
101            theme.colors.compBackgroundGray,
102            theme.colors.compBackgroundSecondary,
103            theme.colors.compBackgroundTertiary,
104            theme.colors.compBackgroundEmphasize,
105            theme.colors.compBackgroundNeutral,
106            theme.colors.compEmphasizeSecondary,
107            theme.colors.compEmphasizeTertiary,
108            theme.colors.compDivider,
109            theme.colors.compCommonContrary,
110            theme.colors.compBackgroundFocus,
111            theme.colors.compFocusedPrimary,
112            theme.colors.compFocusedSecondary,
113            theme.colors.compFocusedTertiary,
114            theme.colors.interactiveHover,
115            theme.colors.interactivePressed,
116            theme.colors.interactiveFocus,
117            theme.colors.interactiveActive,
118            theme.colors.interactiveSelect,
119            theme.colors.interactiveClick,
120        ];
121    }
122    static convertColorsToArray(colors) {
123        const basisColors = ArkThemeScopeManager.getSystemColors();
124        if (!colors) {
125            return new Array(Object.keys(basisColors).length).fill(undefined);
126        }
127        const colorArray = [];
128        for (let attr in basisColors) {
129            colorArray.push(colors[attr]);
130        }
131        return colorArray;
132    }
133}
134globalThis.LazyForEach.getItemGeneratorForThemeSupport = function (paramItemGenerator) {
135    const themeScope = ArkThemeScopeManager.getInstance().lastLocalThemeScope();
136    if (themeScope === undefined) {
137        return paramItemGenerator;
138    }
139    const itemGeneratorWrapper = (...params) => {
140        const result = ArkThemeScopeManager.getInstance().onDeepRenderScopeEnter(themeScope);
141        paramItemGenerator(...params);
142        if (result === true) {
143            ArkThemeScopeManager.getInstance().onDeepRenderScopeExit();
144        }
145    };
146    return itemGeneratorWrapper;
147};
148if (globalThis.WithTheme !== undefined) {
149    globalThis.ListItem.getDeepRenderFuncForThemeSupport = function (deepRenderFunction) {
150        const themeScope = ArkThemeScopeManager.getInstance().lastLocalThemeScope();
151        if (themeScope === undefined) {
152            return deepRenderFunction;
153        }
154        const deepRenderFunctionWrapper = (elmtId, isInitialRender) => {
155            const result = ArkThemeScopeManager.getInstance().onDeepRenderScopeEnter(themeScope);
156            deepRenderFunction(elmtId, isInitialRender);
157            if (result === true) {
158                ArkThemeScopeManager.getInstance().onDeepRenderScopeExit();
159            }
160        };
161        return deepRenderFunctionWrapper;
162    };
163}
164class ArkThemeCache {
165    constructor() {
166        this.cache = [];
167    }
168    static getInstance() {
169        if (!ArkThemeCache.instance) {
170            ArkThemeCache.instance = new ArkThemeCache();
171        }
172        return ArkThemeCache.instance;
173    }
174    add(theme) {
175        if (this.contains(theme)) {
176            return;
177        }
178        this.cache.push(theme);
179    }
180    remove(theme) {
181        const index = this.cache.indexOf(theme);
182        if (index === -1) {
183            return;
184        }
185        this.cache.splice(index, 1);
186        getUINativeModule().theme.removeFromCache(theme.id);
187    }
188    get(baselineThemeId, customTheme, colorMode) {
189        return this.cache.find((item) => {
190            return item.getParentThemeId() === baselineThemeId &&
191                item.getColorMode() === colorMode &&
192                this.isEqualsCustomThemes(item.getCustomTheme(), customTheme);
193        });
194    }
195    contains(theme) {
196        return this.containsByAttributes(theme.getParentThemeId(), theme.getCustomTheme(), theme.getColorMode());
197    }
198    containsByAttributes(baselineThemeId, customTheme, colorMode) {
199        return this.get(baselineThemeId, customTheme, colorMode) !== undefined;
200    }
201    isEqualsCustomThemes(theme1, theme2) {
202        if (theme1 === theme2) {
203            return true;
204        }
205        if (!theme1 || !theme2) {
206            return false;
207        }
208        if (theme1.colors === theme2.colors && theme1.darkColors === theme2.darkColors) {
209            return true;
210        }
211        if (!theme1.colors || !theme2.colors || !theme1.darkColors || !theme2.darkColors) {
212            return false;
213        }
214        let keys1 = Object.keys(theme1.colors);
215        let keys2 = Object.keys(theme2.colors);
216        let darkKeys1 = Object.keys(theme1.darkColors);
217        let darkKeys2 = Object.keys(theme2.darkColors);
218        if (keys1.length !== keys2.length || darkKeys1.length !== darkKeys2.length) {
219            return false;
220        }
221        for (let key of keys1) {
222            if (!keys2.includes(key)) {
223                return false;
224            }
225            let value1 = theme1.colors[key];
226            let value2 = theme2.colors[key];
227            if (value1 !== value2) {
228                return false;
229            }
230        }
231        for (let key of darkKeys1) {
232            if (!darkKeys2.includes(key)) {
233                return false;
234            }
235            let value1 = theme1.darkColors[key];
236            let value2 = theme2.darkColors[key];
237            if (value1 !== value2) {
238                return false;
239            }
240        }
241        return true;
242    }
243}
244let themeCounter = 0;
245class ArkThemeBase {
246    constructor(parentId, customTheme, colorMode, colors, darkColors, shapes, typography) {
247        this.scopesCounter = 0;
248        this.bindedThemeScopesIds = [];
249        this.isJustCreated = true;
250        this.parentThemeId = -1;
251        this.id = themeCounter++;
252        this.parentThemeId = parentId;
253        this.customTheme = ArkThemeBase.copyCustomTheme(customTheme);
254        this.colorMode = colorMode;
255        this.colors = colors;
256        this.darkColors = darkColors;
257        this.shapes = shapes;
258        this.typography = typography;
259    }
260    bindToScope(themeScopeId) {
261        if (this.bindedThemeScopesIds.includes(themeScopeId)) {
262            return;
263        }
264        this.scopesCounter++;
265        this.bindedThemeScopesIds.push(themeScopeId);
266        if (this.isJustCreated) {
267            ArkThemeCache.getInstance().add(this);
268            this.isJustCreated = false;
269        }
270    }
271    unbindFromScope(themeScopeId) {
272        const index = this.bindedThemeScopesIds.indexOf(themeScopeId);
273        if (index === -1) {
274            return;
275        }
276        this.scopesCounter--;
277        this.bindedThemeScopesIds.splice(index, 1);
278        if (this.canBeDestroyed()) {
279            ArkThemeCache.getInstance().remove(this);
280        }
281    }
282    canBeDestroyed() {
283        return !this.isJustCreated && this.scopesCounter === 0;
284    }
285    getParentThemeId() {
286        return this.parentThemeId;
287    }
288    getCustomTheme() {
289        return this.customTheme;
290    }
291    getColorMode() {
292        return this.colorMode;
293    }
294    static copyCustomTheme(customTheme) {
295        if (!customTheme) {
296            return undefined;
297        }
298        const copyTheme = {};
299        if (customTheme.colors) {
300            copyTheme.colors = {};
301            Object.assign(copyTheme.colors, customTheme.colors);
302        }
303        if (customTheme.darkColors) {
304            copyTheme.darkColors = {};
305            // For properties missing in darkColors, use the values from colors
306            Object.assign(copyTheme.darkColors, customTheme?.colors, customTheme.darkColors);
307        }
308
309        if (customTheme.shapes) {
310            copyTheme.shapes = {};
311            Object.assign(copyTheme.shapes, customTheme.shapes);
312        }
313        if (customTheme.typography) {
314            copyTheme.typography = {};
315            Object.assign(copyTheme.typography, customTheme.typography);
316        }
317        return copyTheme;
318    }
319}
320class ArkSystemColors {
321    constructor() {
322        this.brand = ArkResourcesHelper.$r('sys.color.brand', 125830976);
323        this.warning = ArkResourcesHelper.$r('sys.color.warning', 125830979);
324        this.alert = ArkResourcesHelper.$r('sys.color.alert', 125830980);
325        this.confirm = ArkResourcesHelper.$r('sys.color.confirm', 125830981);
326        this.fontPrimary = ArkResourcesHelper.$r('sys.color.font_primary', 125830982);
327        this.fontSecondary = ArkResourcesHelper.$r('sys.color.font_secondary', 125830983);
328        this.fontTertiary = ArkResourcesHelper.$r('sys.color.font_tertiary', 125830984);
329        this.fontFourth = ArkResourcesHelper.$r('sys.color.font_fourth', 125830985);
330        this.fontEmphasize = ArkResourcesHelper.$r('sys.color.font_emphasize', 125830986);
331        this.fontOnPrimary = ArkResourcesHelper.$r('sys.color.font_on_primary', 125830987);
332        this.fontOnSecondary = ArkResourcesHelper.$r('sys.color.font_on_secondary', 125830988);
333        this.fontOnTertiary = ArkResourcesHelper.$r('sys.color.font_on_tertiary', 125830989);
334        this.fontOnFourth = ArkResourcesHelper.$r('sys.color.font_on_fourth', 125830990);
335        this.iconPrimary = ArkResourcesHelper.$r('sys.color.icon_primary', 125830991);
336        this.iconSecondary = ArkResourcesHelper.$r('sys.color.icon_secondary', 125830992);
337        this.iconTertiary = ArkResourcesHelper.$r('sys.color.icon_tertiary', 125830993);
338        this.iconFourth = ArkResourcesHelper.$r('sys.color.icon_fourth', 125830994);
339        this.iconEmphasize = ArkResourcesHelper.$r('sys.color.icon_emphasize', 125830995);
340        this.iconSubEmphasize = ArkResourcesHelper.$r('sys.color.icon_sub_emphasize', 125830996);
341        this.iconOnPrimary = ArkResourcesHelper.$r('sys.color.icon_on_primary', 125831057);
342        this.iconOnSecondary = ArkResourcesHelper.$r('sys.color.icon_on_secondary', 125831058);
343        this.iconOnTertiary = ArkResourcesHelper.$r('sys.color.icon_on_tertiary', 125831059);
344        this.iconOnFourth = ArkResourcesHelper.$r('sys.color.icon_on_fourth', 125831060);
345        this.backgroundPrimary = ArkResourcesHelper.$r('sys.color.background_primary', 125831061);
346        this.backgroundSecondary = ArkResourcesHelper.$r('sys.color.background_secondary', 125831062);
347        this.backgroundTertiary = ArkResourcesHelper.$r('sys.color.background_tertiary', 125831063);
348        this.backgroundFourth = ArkResourcesHelper.$r('sys.color.background_fourth', 125831064);
349        this.backgroundEmphasize = ArkResourcesHelper.$r('sys.color.background_emphasize', 125831065);
350        this.compForegroundPrimary = ArkResourcesHelper.$r('sys.color.comp_foreground_primary', 125831003);
351        this.compBackgroundPrimary = ArkResourcesHelper.$r('sys.color.comp_background_primary', 125831004);
352        this.compBackgroundPrimaryTran = ArkResourcesHelper.$r('sys.color.comp_background_primary_tran');
353        this.compBackgroundPrimaryContrary = ArkResourcesHelper.$r('sys.color.comp_background_primary_contrary', 125831005);
354        this.compBackgroundGray = ArkResourcesHelper.$r('sys.color.comp_background_gray', 125831006);
355        this.compBackgroundSecondary = ArkResourcesHelper.$r('sys.color.comp_background_secondary', 125831007);
356        this.compBackgroundTertiary = ArkResourcesHelper.$r('sys.color.comp_background_tertiary', 125831008);
357        this.compBackgroundEmphasize = ArkResourcesHelper.$r('sys.color.comp_background_emphasize', 125831009);
358        this.compBackgroundNeutral = ArkResourcesHelper.$r('sys.color.neutral', 125831066);
359        this.compEmphasizeSecondary = ArkResourcesHelper.$r('sys.color.comp_emphasize_secondary', 125831011);
360        this.compEmphasizeTertiary = ArkResourcesHelper.$r('sys.color.comp_emphasize_tertiary', 125831012);
361        this.compDivider = ArkResourcesHelper.$r('sys.color.comp_divider', 125831013);
362        this.compCommonContrary = ArkResourcesHelper.$r('sys.color.comp_common_contrary', 125831014);
363        this.compBackgroundFocus = ArkResourcesHelper.$r('sys.color.comp_background_focus', 125831015);
364        this.compFocusedPrimary = ArkResourcesHelper.$r('sys.color.comp_focused_primary', 125831016);
365        this.compFocusedSecondary = ArkResourcesHelper.$r('sys.color.comp_focused_secondary', 125831017);
366        this.compFocusedTertiary = ArkResourcesHelper.$r('sys.color.comp_focused_tertiary', 125831018);
367        this.interactiveHover = ArkResourcesHelper.$r('sys.color.interactive_hover', 125831019);
368        this.interactivePressed = ArkResourcesHelper.$r('sys.color.interactive_pressed', 125831020);
369        this.interactiveFocus = ArkResourcesHelper.$r('sys.color.interactive_focus', 125831021);
370        this.interactiveActive = ArkResourcesHelper.$r('sys.color.interactive_active', 125831022);
371        this.interactiveSelect = ArkResourcesHelper.$r('sys.color.interactive_select', 125831023);
372        this.interactiveClick = ArkResourcesHelper.$r('sys.color.interactive_click', 125831024);
373    }
374}
375class ArkSystemCornerRadius {
376    constructor() {
377        this.none = ArkResourcesHelper.$r('sys.float.corner_radius_none');
378        this.level1 = ArkResourcesHelper.$r('sys.float.corner_radius_level1');
379        this.level2 = ArkResourcesHelper.$r('sys.float.corner_radius_level2');
380        this.level3 = ArkResourcesHelper.$r('sys.float.corner_radius_level3');
381        this.level4 = ArkResourcesHelper.$r('sys.float.corner_radius_level4');
382        this.level5 = ArkResourcesHelper.$r('sys.float.corner_radius_level5');
383        this.level6 = ArkResourcesHelper.$r('sys.float.corner_radius_level6');
384        this.level7 = ArkResourcesHelper.$r('sys.float.corner_radius_level7');
385        this.level8 = ArkResourcesHelper.$r('sys.float.corner_radius_level8');
386        this.level9 = ArkResourcesHelper.$r('sys.float.corner_radius_level9');
387        this.level10 = ArkResourcesHelper.$r('sys.float.corner_radius_level10');
388        this.level11 = ArkResourcesHelper.$r('sys.float.corner_radius_level11');
389        this.level12 = ArkResourcesHelper.$r('sys.float.corner_radius_level12');
390        this.level16 = ArkResourcesHelper.$r('sys.float.corner_radius_level16');
391    }
392}
393class ArkSystemPaddings {
394    constructor() {
395        this.level0 = ArkResourcesHelper.$r('sys.float.padding_level0');
396        this.level1 = ArkResourcesHelper.$r('sys.float.padding_level1');
397        this.level2 = ArkResourcesHelper.$r('sys.float.padding_level2');
398        this.level3 = ArkResourcesHelper.$r('sys.float.padding_level3');
399        this.level4 = ArkResourcesHelper.$r('sys.float.padding_level4');
400        this.level5 = ArkResourcesHelper.$r('sys.float.padding_level5');
401        this.level6 = ArkResourcesHelper.$r('sys.float.padding_level6');
402        this.level7 = ArkResourcesHelper.$r('sys.float.padding_level7');
403        this.level8 = ArkResourcesHelper.$r('sys.float.padding_level8');
404        this.level9 = ArkResourcesHelper.$r('sys.float.padding_level9');
405        this.level10 = ArkResourcesHelper.$r('sys.float.padding_level10');
406        this.level11 = ArkResourcesHelper.$r('sys.float.padding_level11');
407        this.level12 = ArkResourcesHelper.$r('sys.float.padding_level12');
408        this.level16 = ArkResourcesHelper.$r('sys.float.padding_level16');
409        this.level24 = ArkResourcesHelper.$r('sys.float.padding_level24');
410        this.level32 = ArkResourcesHelper.$r('sys.float.padding_level32');
411        this.level36 = ArkResourcesHelper.$r('sys.float.padding_level36');
412    }
413}
414class ArkSystemOutlines {
415    constructor() {
416        this.none = ArkResourcesHelper.$r('sys.float.outline_none');
417        this.xs = ArkResourcesHelper.$r('sys.float.outline_extra_small');
418        this.s = ArkResourcesHelper.$r('sys.float.outline_small');
419        this.m = ArkResourcesHelper.$r('sys.float.outline_medium');
420        this.l = ArkResourcesHelper.$r('sys.float.outline_larger');
421        this.xl = ArkResourcesHelper.$r('sys.float.outline_extra_larger');
422    }
423}
424class ArkSystemBorders {
425    constructor() {
426        this.none = ArkResourcesHelper.$r('sys.float.border_none');
427        this.xs = ArkResourcesHelper.$r('sys.float.border_extra_small');
428        this.s = ArkResourcesHelper.$r('sys.float.border_small');
429        this.m = ArkResourcesHelper.$r('sys.float.border_medium');
430        this.l = ArkResourcesHelper.$r('sys.float.border_larger');
431        this.xl = ArkResourcesHelper.$r('sys.float.border_extra_larger');
432    }
433}
434class ArkSystemShapes {
435    constructor() {
436        this.cornerRadius = new ArkSystemCornerRadius();
437        this.paddings = new ArkSystemPaddings();
438        this.borders = new ArkSystemBorders();
439        this.outlines = new ArkSystemOutlines();
440    }
441}
442class ArkTypographyWeights {
443}
444ArkTypographyWeights.thin = 100;
445ArkTypographyWeights.ultralight = 200;
446ArkTypographyWeights.light = 300;
447ArkTypographyWeights.regular = 400;
448ArkTypographyWeights.medium = 500;
449ArkTypographyWeights.semibold = 600;
450ArkTypographyWeights.bold = 700;
451ArkTypographyWeights.heavy = 800;
452ArkTypographyWeights.black = 900;
453class ArkSystemTypography {
454    constructor() {
455        this.displayLarge = {
456            weight: ArkTypographyWeights.light,
457            size: ArkResourcesHelper.$r('sys.float.Display_L')
458        };
459        this.displayMiddle = {
460            weight: ArkTypographyWeights.light,
461            size: ArkResourcesHelper.$r('sys.float.Display_M')
462        };
463        this.displaySmall = {
464            weight: ArkTypographyWeights.light,
465            size: ArkResourcesHelper.$r('sys.float.Display_S')
466        };
467        this.titleLarge = {
468            weight: ArkTypographyWeights.bold,
469            size: ArkResourcesHelper.$r('sys.float.Title_L')
470        };
471        this.titleMiddle = {
472            weight: ArkTypographyWeights.bold,
473            size: ArkResourcesHelper.$r('sys.float.Title_M')
474        };
475        this.titleSmall = {
476            weight: ArkTypographyWeights.bold,
477            size: ArkResourcesHelper.$r('sys.float.Title_S')
478        };
479        this.subtitleLarge = {
480            weight: ArkTypographyWeights.medium,
481            size: ArkResourcesHelper.$r('sys.float.Subtitle_L')
482        };
483        this.subtitleMiddle = {
484            weight: ArkTypographyWeights.medium,
485            size: ArkResourcesHelper.$r('sys.float.Subtitle_M')
486        };
487        this.subtitleSmall = {
488            weight: ArkTypographyWeights.medium,
489            size: ArkResourcesHelper.$r('sys.float.Subtitle_S')
490        };
491        this.bodyLarge = {
492            weight: ArkTypographyWeights.medium,
493            size: ArkResourcesHelper.$r('sys.float.Body_L')
494        };
495        this.bodyMiddle = {
496            weight: ArkTypographyWeights.regular,
497            size: ArkResourcesHelper.$r('sys.float.Body_M')
498        };
499        this.bodySmall = {
500            weight: ArkTypographyWeights.regular,
501            size: ArkResourcesHelper.$r('sys.float.Body_S')
502        };
503        this.captionLarge = {
504            weight: ArkTypographyWeights.medium,
505            size: ArkResourcesHelper.$r('sys.float.Caption_L')
506        };
507        this.captionMiddle = {
508            weight: ArkTypographyWeights.medium,
509            size: ArkResourcesHelper.$r('sys.float.Caption_M')
510        };
511        this.captionSmall = {
512            weight: ArkTypographyWeights.medium,
513            size: ArkResourcesHelper.$r('sys.float.Caption_S')
514        };
515    }
516}
517class ArkSystemTheme extends ArkThemeBase {
518    constructor() {
519        super(-1, undefined, ThemeColorMode.SYSTEM, new ArkSystemColors(), new ArkSystemColors(), new ArkSystemShapes(), new ArkSystemTypography());
520    }
521}
522if (globalThis.WithTheme !== undefined) {
523    globalThis.WithTheme.create = function (themeOptions) {
524        var _a;
525        const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
526        const colorMode = (_a = themeOptions === null || themeOptions === void 0 ? void 0 : themeOptions.colorMode) !== null && _a !== void 0 ? _a : ThemeColorMode.SYSTEM;
527        const cloneTheme = ArkThemeScopeManager.cloneCustomThemeWithExpand(themeOptions === null || themeOptions === void 0 ? void 0 : themeOptions.theme);
528        const theme = ArkThemeScopeManager.getInstance().makeTheme(cloneTheme, colorMode);
529        theme.bindToScope(elmtId);
530        const onThemeScopeDestroy = () => {
531            ArkThemeScopeManager.getInstance().onScopeDestroy(elmtId);
532        };
533        ArkThemeNativeHelper.sendThemeToNative(theme, elmtId, !!cloneTheme?.darkColors);
534        ArkThemeNativeHelper.createInternal(elmtId, theme.id, cloneTheme, colorMode, onThemeScopeDestroy, !!cloneTheme?.darkColors);
535        ArkThemeScopeManager.getInstance().onScopeEnter(elmtId, themeOptions !== null && themeOptions !== void 0 ? themeOptions : {}, theme);
536    };
537    globalThis.WithTheme.pop = function () {
538        var _a;
539        if (PUV2ViewBase.isNeedBuildPrebuildCmd() && PUV2ViewBase.prebuildFuncQueues.has(PUV2ViewBase.prebuildingElmtId_)) {
540            const prebuildFunc = () => {
541                ArkThemeScopeManager.getInstance().setIsFirstRender(true);
542                globalThis.WithTheme.pop();
543            };
544            (_a = PUV2ViewBase.prebuildFuncQueues.get(PUV2ViewBase.prebuildingElmtId_)) === null || _a === void 0 ? void 0 : _a.push(prebuildFunc);
545            ViewStackProcessor.PushPrebuildCompCmd();
546            return;
547        }
548        ArkThemeScopeManager.getInstance().onScopeExit();
549        getUINativeModule().theme.pop();
550    };
551}
552class ArkColorsImpl {
553    constructor(colors, baselineColors) {
554        Object.assign(this, baselineColors, colors);
555    }
556    static expandByBrandColor(colors) {
557        var _a, _b, _c, _d, _e, _f, _g, _h, _j;
558        if (colors.brand) {
559            const brandColors = ArkColorsImpl.makeBrandColors(colors.brand);
560            colors.fontEmphasize = (_a = colors.fontEmphasize) !== null && _a !== void 0 ? _a : brandColors.primary;
561            colors.iconEmphasize = (_b = colors.iconEmphasize) !== null && _b !== void 0 ? _b : brandColors.primary;
562            colors.iconSubEmphasize = (_c = colors.iconSubEmphasize) !== null && _c !== void 0 ? _c : brandColors.tertiary;
563            colors.backgroundEmphasize = (_d = colors.backgroundEmphasize) !== null && _d !== void 0 ? _d : brandColors.primary;
564            colors.compBackgroundEmphasize = (_e = colors.compBackgroundEmphasize) !== null && _e !== void 0 ? _e : brandColors.primary;
565            colors.compEmphasizeSecondary = (_f = colors.compEmphasizeSecondary) !== null && _f !== void 0 ? _f : brandColors.fourth;
566            colors.compEmphasizeTertiary = (_g = colors.compEmphasizeTertiary) !== null && _g !== void 0 ? _g : brandColors.fifth;
567            colors.interactiveFocus = (_h = colors.interactiveFocus) !== null && _h !== void 0 ? _h : brandColors.primary;
568            colors.interactiveActive = (_j = colors.interactiveActive) !== null && _j !== void 0 ? _j : brandColors.primary;
569        }
570    }
571    static makeBrandColors(brandColor) {
572        const result = {
573            primary: undefined,
574            secondary: undefined,
575            tertiary: undefined,
576            fourth: undefined,
577            fifth: undefined,
578            sixth: undefined
579        };
580        if (brandColor) {
581            if (brandColor instanceof Object) {
582                result.primary = brandColor;
583                result.secondary = ArkColorsImpl.makeResourceWithOpacity(brandColor, 0.6);
584                result.tertiary = ArkColorsImpl.makeResourceWithOpacity(brandColor, 0.4);
585                result.fourth = ArkColorsImpl.makeResourceWithOpacity(brandColor, 0.2);
586                result.fifth = ArkColorsImpl.makeResourceWithOpacity(brandColor, 0.1);
587                result.sixth = ArkColorsImpl.makeResourceWithOpacity(brandColor, 0.05);
588            }
589            else {
590                const argbColor = getUINativeModule().resource.getColorValue(brandColor);
591                result.primary = argbColor;
592                result.secondary = ArkColorsImpl.blendOpacity(argbColor, 0.6);
593                result.tertiary = ArkColorsImpl.blendOpacity(argbColor, 0.4);
594                result.fourth = ArkColorsImpl.blendOpacity(argbColor, 0.2);
595                result.fifth = ArkColorsImpl.blendOpacity(argbColor, 0.1);
596                result.sixth = ArkColorsImpl.blendOpacity(argbColor, 0.05);
597            }
598        }
599        return result;
600    }
601    static makeResourceWithOpacity(resourceColor, opacityRatio) {
602        return {
603            'id': resourceColor.id,
604            'type': resourceColor.type,
605            'params': [...resourceColor.params],
606            'bundleName': resourceColor.bundleName,
607            'moduleName': resourceColor.moduleName,
608            'opacityRatio': opacityRatio
609        };
610    }
611    static blendOpacity(argbColor, opacityRatio) {
612        if (opacityRatio < 0 || opacityRatio > 1.0) {
613            return argbColor;
614        }
615        const alpha = (argbColor >> 24) & 0xFF;
616        const outAlpha = (alpha * opacityRatio) & 0xFF;
617        return ((argbColor & 0x00FFFFFF) | (outAlpha & 0xFF) << 24) >>> 0;
618    }
619}
620class ArkCornerRadiusImpl {
621    constructor(corners, baselineCorners) {
622        Object.assign(this, baselineCorners, corners);
623    }
624}
625class ArkPaddingsImpl {
626    constructor(paddings, baselinePaddings) {
627        Object.assign(this, baselinePaddings, paddings);
628    }
629}
630class ArkOutlinesImpl {
631    constructor(outlines = {}, baselineOutlines) {
632        Object.assign(this, baselineOutlines, outlines);
633    }
634}
635class ArkBordersImpl {
636    constructor(borders = {}, baselineBorders) {
637        Object.assign(this, baselineBorders, borders);
638    }
639}
640class ArkShapesImpl {
641    constructor(shapes, baselineShapes) {
642        this.cornerRadius = new ArkCornerRadiusImpl(shapes === null || shapes === void 0 ? void 0 : shapes.cornerRadius, baselineShapes.cornerRadius);
643        this.paddings = new ArkPaddingsImpl(shapes === null || shapes === void 0 ? void 0 : shapes.paddings, baselineShapes.paddings);
644        this.borders = new ArkBordersImpl(shapes === null || shapes === void 0 ? void 0 : shapes.borders, baselineShapes.borders);
645        this.outlines = new ArkOutlinesImpl(shapes === null || shapes === void 0 ? void 0 : shapes.outlines, baselineShapes.outlines);
646    }
647}
648class ArkTypographyImpl {
649    constructor(typography, baselineTypography) {
650        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35;
651        this.displayLarge = {
652            weight: (_b = (_a = typography === null || typography === void 0 ? void 0 : typography.displayLarge) === null || _a === void 0 ? void 0 : _a.weight) !== null && _b !== void 0 ? _b : ArkTypographyWeights.light,
653            size: (_d = (_c = typography === null || typography === void 0 ? void 0 : typography.displayLarge) === null || _c === void 0 ? void 0 : _c.size) !== null && _d !== void 0 ? _d : baselineTypography.displayLarge.size
654        };
655        this.displayMiddle = {
656            weight: (_f = (_e = typography === null || typography === void 0 ? void 0 : typography.displayMiddle) === null || _e === void 0 ? void 0 : _e.weight) !== null && _f !== void 0 ? _f : ArkTypographyWeights.light,
657            size: (_h = (_g = typography === null || typography === void 0 ? void 0 : typography.displayMiddle) === null || _g === void 0 ? void 0 : _g.size) !== null && _h !== void 0 ? _h : baselineTypography.displayMiddle.size
658        };
659        this.displaySmall = {
660            weight: (_k = (_j = typography === null || typography === void 0 ? void 0 : typography.displaySmall) === null || _j === void 0 ? void 0 : _j.weight) !== null && _k !== void 0 ? _k : ArkTypographyWeights.light,
661            size: (_m = (_l = typography === null || typography === void 0 ? void 0 : typography.displaySmall) === null || _l === void 0 ? void 0 : _l.size) !== null && _m !== void 0 ? _m : baselineTypography.displaySmall.size
662        };
663        this.titleLarge = {
664            weight: (_p = (_o = typography === null || typography === void 0 ? void 0 : typography.titleLarge) === null || _o === void 0 ? void 0 : _o.weight) !== null && _p !== void 0 ? _p : ArkTypographyWeights.bold,
665            size: (_r = (_q = typography === null || typography === void 0 ? void 0 : typography.titleLarge) === null || _q === void 0 ? void 0 : _q.size) !== null && _r !== void 0 ? _r : baselineTypography.titleLarge.size
666        };
667        this.titleMiddle = {
668            weight: (_t = (_s = typography === null || typography === void 0 ? void 0 : typography.titleMiddle) === null || _s === void 0 ? void 0 : _s.weight) !== null && _t !== void 0 ? _t : ArkTypographyWeights.bold,
669            size: (_v = (_u = typography === null || typography === void 0 ? void 0 : typography.titleMiddle) === null || _u === void 0 ? void 0 : _u.size) !== null && _v !== void 0 ? _v : baselineTypography.titleMiddle.size
670        };
671        this.titleSmall = {
672            weight: (_x = (_w = typography === null || typography === void 0 ? void 0 : typography.titleSmall) === null || _w === void 0 ? void 0 : _w.weight) !== null && _x !== void 0 ? _x : ArkTypographyWeights.bold,
673            size: (_z = (_y = typography === null || typography === void 0 ? void 0 : typography.titleSmall) === null || _y === void 0 ? void 0 : _y.size) !== null && _z !== void 0 ? _z : baselineTypography.titleSmall.size
674        };
675        this.subtitleLarge = {
676            weight: (_1 = (_0 = typography === null || typography === void 0 ? void 0 : typography.subtitleLarge) === null || _0 === void 0 ? void 0 : _0.weight) !== null && _1 !== void 0 ? _1 : ArkTypographyWeights.medium,
677            size: (_3 = (_2 = typography === null || typography === void 0 ? void 0 : typography.subtitleLarge) === null || _2 === void 0 ? void 0 : _2.size) !== null && _3 !== void 0 ? _3 : baselineTypography.subtitleLarge.size
678        };
679        this.subtitleMiddle = {
680            weight: (_5 = (_4 = typography === null || typography === void 0 ? void 0 : typography.subtitleMiddle) === null || _4 === void 0 ? void 0 : _4.weight) !== null && _5 !== void 0 ? _5 : ArkTypographyWeights.medium,
681            size: (_7 = (_6 = typography === null || typography === void 0 ? void 0 : typography.subtitleMiddle) === null || _6 === void 0 ? void 0 : _6.size) !== null && _7 !== void 0 ? _7 : baselineTypography.subtitleMiddle.size
682        };
683        this.subtitleSmall = {
684            weight: (_9 = (_8 = typography === null || typography === void 0 ? void 0 : typography.subtitleSmall) === null || _8 === void 0 ? void 0 : _8.weight) !== null && _9 !== void 0 ? _9 : ArkTypographyWeights.medium,
685            size: (_11 = (_10 = typography === null || typography === void 0 ? void 0 : typography.subtitleSmall) === null || _10 === void 0 ? void 0 : _10.size) !== null && _11 !== void 0 ? _11 : baselineTypography.subtitleSmall.size
686        };
687        this.bodyLarge = {
688            weight: (_13 = (_12 = typography === null || typography === void 0 ? void 0 : typography.bodyLarge) === null || _12 === void 0 ? void 0 : _12.weight) !== null && _13 !== void 0 ? _13 : ArkTypographyWeights.medium,
689            size: (_15 = (_14 = typography === null || typography === void 0 ? void 0 : typography.bodyLarge) === null || _14 === void 0 ? void 0 : _14.size) !== null && _15 !== void 0 ? _15 : baselineTypography.bodyLarge.size
690        };
691        this.bodyMiddle = {
692            weight: (_17 = (_16 = typography === null || typography === void 0 ? void 0 : typography.bodyMiddle) === null || _16 === void 0 ? void 0 : _16.weight) !== null && _17 !== void 0 ? _17 : ArkTypographyWeights.regular,
693            size: (_19 = (_18 = typography === null || typography === void 0 ? void 0 : typography.bodyMiddle) === null || _18 === void 0 ? void 0 : _18.size) !== null && _19 !== void 0 ? _19 : baselineTypography.bodyMiddle.size
694        };
695        this.bodySmall = {
696            weight: (_21 = (_20 = typography === null || typography === void 0 ? void 0 : typography.bodySmall) === null || _20 === void 0 ? void 0 : _20.weight) !== null && _21 !== void 0 ? _21 : ArkTypographyWeights.regular,
697            size: (_23 = (_22 = typography === null || typography === void 0 ? void 0 : typography.bodySmall) === null || _22 === void 0 ? void 0 : _22.size) !== null && _23 !== void 0 ? _23 : baselineTypography.bodySmall.size
698        };
699        this.captionLarge = {
700            weight: (_25 = (_24 = typography === null || typography === void 0 ? void 0 : typography.captionLarge) === null || _24 === void 0 ? void 0 : _24.weight) !== null && _25 !== void 0 ? _25 : ArkTypographyWeights.medium,
701            size: (_27 = (_26 = typography === null || typography === void 0 ? void 0 : typography.captionLarge) === null || _26 === void 0 ? void 0 : _26.size) !== null && _27 !== void 0 ? _27 : baselineTypography.captionLarge.size
702        };
703        this.captionMiddle = {
704            weight: (_29 = (_28 = typography === null || typography === void 0 ? void 0 : typography.captionMiddle) === null || _28 === void 0 ? void 0 : _28.weight) !== null && _29 !== void 0 ? _29 : ArkTypographyWeights.medium,
705            size: (_31 = (_30 = typography === null || typography === void 0 ? void 0 : typography.captionMiddle) === null || _30 === void 0 ? void 0 : _30.size) !== null && _31 !== void 0 ? _31 : baselineTypography.captionMiddle.size
706        };
707        this.captionSmall = {
708            weight: (_33 = (_32 = typography === null || typography === void 0 ? void 0 : typography.captionSmall) === null || _32 === void 0 ? void 0 : _32.weight) !== null && _33 !== void 0 ? _33 : ArkTypographyWeights.medium,
709            size: (_35 = (_34 = typography === null || typography === void 0 ? void 0 : typography.captionSmall) === null || _34 === void 0 ? void 0 : _34.size) !== null && _35 !== void 0 ? _35 : baselineTypography.captionSmall.size
710        };
711    }
712}
713class ArkThemeImpl extends ArkThemeBase {
714    constructor(customTheme, colorMode, baselineTheme) {
715        if (!customTheme) {
716            super(baselineTheme.id, undefined, colorMode, new ArkColorsImpl(undefined, baselineTheme.colors), new ArkColorsImpl(undefined, baselineTheme.darkColors), new ArkShapesImpl(undefined, baselineTheme.shapes), new ArkTypographyImpl(undefined, baselineTheme.typography));
717            return;
718        }
719        super(baselineTheme.id, customTheme, colorMode, new ArkColorsImpl(customTheme.colors, baselineTheme.colors), new ArkColorsImpl(customTheme.darkColors, baselineTheme.darkColors), new ArkShapesImpl(customTheme.shapes, baselineTheme.shapes), new ArkTypographyImpl(customTheme.typography, baselineTheme.typography));
720    }
721}
722class ArkThemeScopeItem {
723    constructor() {
724        this.isInWhiteList = undefined;
725        this.listener = undefined;
726    }
727}
728class ArkThemeScopeArray extends Array {
729    binarySearch(elmtId) {
730        let start = 0;
731        let end = this.length - 1;
732        while (start <= end) {
733            let mid = (start + end) >> 1;
734            if (this[mid].elmtId === elmtId) {
735                return mid;
736            }
737            if (elmtId < this[mid].elmtId) {
738                end = mid - 1;
739            }
740            else {
741                start = mid + 1;
742            }
743        }
744        return -1;
745    }
746}
747class ArkThemeScope {
748    constructor(ownerComponentId, withThemeId, withThemeOptions, theme) {
749        this.ownerComponentId = ownerComponentId;
750        this.withThemeId = withThemeId;
751        this.withThemeOptions = withThemeOptions;
752        this.theme = theme;
753        this.prevColorMode = this.colorMode();
754    }
755    getOwnerComponentId() {
756        return this.ownerComponentId;
757    }
758    getWithThemeId() {
759        return this.withThemeId;
760    }
761    addComponentToScope(elmtId, owner, componentName) {
762        if (this.isComponentInScope(elmtId)) {
763            return;
764        }
765        if (!this.components) {
766            this.components = new ArkThemeScopeArray();
767        }
768        this.components.push({ elmtId: elmtId, ownerId: owner.id__(), owner: owner, name: componentName });
769    }
770    addCustomListenerInScope(listener) {
771        const len = this.components ? this.components.length : -1;
772        if (len <= 0) {
773            return;
774        }
775        const listenerId = listener.id__();
776        let themeScopeItem = this.components[len - 1];
777        if (themeScopeItem.elmtId === listenerId) {
778            themeScopeItem.listener = listener;
779            return;
780        }
781        themeScopeItem = this.components.find((item) => item.elmtId === listenerId);
782        if (themeScopeItem) {
783            themeScopeItem.listener = listener;
784        }
785    }
786    removeComponentFromScope(elmtId) {
787        if (this.components) {
788            const index = this.components.binarySearch(elmtId);
789            if (index > -1) {
790                this.components.splice(index, 1);
791            }
792        }
793    }
794    isComponentInScope(elmtId) {
795        return this.components && (this.components.binarySearch(elmtId) > -1);
796    }
797    componentsInScope() {
798        return this.components;
799    }
800    colorMode() {
801        var _a;
802        return (_a = this.withThemeOptions.colorMode) !== null && _a !== void 0 ? _a : ThemeColorMode.SYSTEM;
803    }
804    customTheme() {
805        var _a;
806        return (_a = this.withThemeOptions.theme) !== null && _a !== void 0 ? _a : {};
807    }
808    getTheme() {
809        return this.theme;
810    }
811    options() {
812        return this.withThemeOptions;
813    }
814    updateWithThemeOptions(options, theme) {
815        var _a;
816        this.prevColorMode = this.colorMode();
817        this.withThemeOptions = options;
818        if (this.theme !== theme) {
819            (_a = this.theme) === null || _a === void 0 ? void 0 : _a.unbindFromScope(this.getWithThemeId());
820            this.theme = theme;
821        }
822    }
823    isColorModeChanged() {
824        return this.prevColorMode !== this.colorMode();
825    }
826}
827class ArkThemeScopeManager {
828    constructor() {
829        this.localThemeScopes = [];
830        this.themeScopes = undefined;
831        this.ifElseLastScope = undefined;
832        this.ifElseScopes = [];
833        this.lastThemeScopeId = 0;
834        this.listeners = [];
835        this.defaultTheme = undefined;
836        this.themeIdStack = [];
837    }
838    onComponentCreateEnter(componentName, elmtId, isFirstRender, ownerComponent) {
839        this.handledIsFirstRender = isFirstRender;
840        this.handledOwnerComponentId = ownerComponent.id__();
841        this.handledComponentElmtId = elmtId;
842        if (!this.themeScopes || componentName === 'WithTheme') {
843            return;
844        }
845        if (this.themeScopes.length === 0) {
846            this.handleThemeScopeChange(undefined);
847            return;
848        }
849        let scope = undefined;
850        if (isFirstRender) {
851            const currentLocalScope = this.localThemeScopes[this.localThemeScopes.length - 1];
852            const currentIfElseScope = this.ifElseScopes[this.ifElseScopes.length - 1];
853            if (currentLocalScope) {
854                scope = currentLocalScope;
855                scope.addComponentToScope(elmtId, ownerComponent, componentName);
856            }
857            else if (currentIfElseScope) {
858                scope = currentIfElseScope;
859                scope.addComponentToScope(elmtId, ownerComponent, componentName);
860            }
861            else {
862                const parentScope = ownerComponent.themeScope_;
863                if (parentScope) {
864                    scope = parentScope;
865                    scope.addComponentToScope(elmtId, ownerComponent, componentName);
866                }
867            }
868        }
869        if (scope === undefined) {
870            scope = this.scopeForElmtId(elmtId);
871        }
872        if (scope === undefined && (this.themeIdStack.length > 0)) {
873            scope = this.themeScopes.find(item => item.getWithThemeId() === this.themeIdStack[this.themeIdStack.length - 1]);
874        }
875        this.handledColorMode = scope === null || scope === void 0 ? void 0 : scope.colorMode();
876        if (this.handledColorMode === ThemeColorMode.LIGHT || this.handledColorMode === ThemeColorMode.DARK) {
877            this.onEnterLocalColorMode(this.handledColorMode);
878        }
879        if (componentName === 'If') {
880            this.ifElseLastScope = scope;
881        }
882        this.handledThemeScope = scope;
883        this.handleThemeScopeChange(this.handledThemeScope);
884        if (scope) {
885            this.themeIdStack.push(scope.getWithThemeId());
886        }
887    }
888    onComponentCreateExit(elmtId) {
889        if (this.handledColorMode === ThemeColorMode.LIGHT || this.handledColorMode === ThemeColorMode.DARK) {
890            this.onExitLocalColorMode();
891        }
892        this.handledThemeScope = undefined;
893        this.handledComponentElmtId = undefined;
894        if (this.themeIdStack.length > 0) {
895            this.themeIdStack.pop();
896        }
897    }
898    onScopeEnter(withThemeId, withThemeOptions, theme) {
899        this.lastThemeScopeId = withThemeId;
900        if (this.handledIsFirstRender === true) {
901            let themeScope = new ArkThemeScope(this.handledOwnerComponentId, withThemeId, withThemeOptions, theme);
902            this.localThemeScopes.push(themeScope);
903            if (!this.themeScopes) {
904                this.themeScopes = new Array();
905            }
906            this.themeScopes.push(themeScope);
907        }
908        else {
909            const scope = this.themeScopes.find(item => item.getWithThemeId() === withThemeId);
910            scope === null || scope === void 0 ? void 0 : scope.updateWithThemeOptions(withThemeOptions, theme);
911            this.forceRerenderScope(scope);
912        }
913    }
914    onScopeExit() {
915        if (this.handledIsFirstRender === true) {
916            this.localThemeScopes.pop();
917        }
918    }
919    onScopeDestroy(themeScopeId) {
920        var _a;
921        this.themeScopes = (_a = this.themeScopes) === null || _a === void 0 ? void 0 : _a.filter((scope) => {
922            if (scope.getWithThemeId() === themeScopeId) {
923                this.onScopeDestroyInternal(scope);
924                return false;
925            }
926            return true;
927        });
928    }
929    onScopeDestroyInternal(scope) {
930        const theme = scope.getTheme();
931        if (theme) {
932            theme.unbindFromScope(scope.getWithThemeId());
933        }
934        const index = this.localThemeScopes.indexOf(scope);
935        if (index !== -1) {
936            this.localThemeScopes.splice(index, 1);
937        }
938        WithTheme.removeThemeInNative(scope.getWithThemeId());
939    }
940    onViewPUCreate(ownerComponent) {
941        var _a;
942        if (ownerComponent.parent_ === undefined) {
943            this.subscribeListener(ownerComponent);
944        }
945        ownerComponent.themeScope_ = this.scopeForElmtId(ownerComponent.id__());
946        (_a = ownerComponent.themeScope_) === null || _a === void 0 ? void 0 : _a.addCustomListenerInScope(ownerComponent);
947    }
948    onViewPUDelete(ownerComponent) {
949        var _a;
950        this.unsubscribeListener(ownerComponent);
951        const ownerComponentId = ownerComponent.id__();
952        this.themeScopes = (_a = this.themeScopes) === null || _a === void 0 ? void 0 : _a.filter((scope) => {
953            if (scope.getOwnerComponentId() === ownerComponentId) {
954                this.onScopeDestroyInternal(scope);
955                return false;
956            }
957            return true;
958        });
959    }
960    onIfElseBranchUpdateEnter() {
961        this.ifElseScopes.push(this.ifElseLastScope);
962    }
963    onIfElseBranchUpdateExit(removedElmtIds) {
964        const scope = this.ifElseScopes.pop();
965        if (removedElmtIds && scope) {
966            removedElmtIds.forEach(elmtId => scope.removeComponentFromScope(elmtId));
967        }
968    }
969    onDeepRenderScopeEnter(themeScope) {
970        if (themeScope) {
971            this.localThemeScopes.push(themeScope);
972            return true;
973        }
974        return false;
975    }
976    onDeepRenderScopeExit() {
977        this.localThemeScopes.pop();
978    }
979    subscribeListener(listener) {
980        if (this.listeners.includes(listener)) {
981            return;
982        }
983        this.listeners.push(listener);
984    }
985    unsubscribeListener(listener) {
986        const index = this.listeners.indexOf(listener, 0);
987        if (index > -1) {
988            this.listeners.splice(index, 1);
989        }
990        const scope = listener.themeScope_;
991        if (scope) {
992            scope.removeComponentFromScope(listener.id__());
993            listener.themeScope_ = undefined;
994        }
995    }
996    getFinalTheme(ownerComponent) {
997        var _a, _b, _c;
998        return (_c = (_b = (_a = ownerComponent.themeScope_) === null || _a === void 0 ? void 0 : _a.getTheme()) !== null && _b !== void 0 ? _b : this.defaultTheme) !== null && _c !== void 0 ? _c : ArkThemeScopeManager.SystemTheme;
999    }
1000    scopeForElmtId(elmtId) {
1001        var _a;
1002        if (this.handledThemeScope && this.handledComponentElmtId === elmtId) {
1003            return this.handledThemeScope;
1004        }
1005        if (this.handledIsFirstRender) {
1006            if (this.localThemeScopes.length > 0) {
1007                return this.localThemeScopes[this.localThemeScopes.length - 1];
1008            }
1009        }
1010        return (_a = this.themeScopes) === null || _a === void 0 ? void 0 : _a.find(item => item.isComponentInScope(elmtId));
1011    }
1012    lastLocalThemeScope() {
1013        if (this.localThemeScopes.length > 0) {
1014            return this.localThemeScopes[this.localThemeScopes.length - 1];
1015        }
1016        return undefined;
1017    }
1018    onEnterLocalColorMode(colorMode) {
1019        getUINativeModule().resource.updateColorMode(colorMode);
1020    }
1021    onExitLocalColorMode() {
1022        getUINativeModule().resource.restore();
1023    }
1024    forceRerenderScope(scope) {
1025        var _a, _b, _c;
1026        if (scope === undefined) {
1027            return;
1028        }
1029        const theme = (_b = (_a = scope === null || scope === void 0 ? void 0 : scope.getTheme()) !== null && _a !== void 0 ? _a : this.defaultTheme) !== null && _b !== void 0 ? _b : ArkThemeScopeManager.SystemTheme;
1030        (_c = scope.componentsInScope()) === null || _c === void 0 ? void 0 : _c.forEach((item) => this.notifyScopeThemeChanged(item, theme, scope.isColorModeChanged()));
1031    }
1032    notifyScopeThemeChanged(item, themeWillApply, isColorModeChanged) {
1033        if (item.owner) {
1034            const listener = item.owner;
1035            if (isColorModeChanged) {
1036                listener.forceRerenderNode(item.elmtId);
1037            }
1038            else {
1039                let isInWhiteList = item.isInWhiteList;
1040                if (isInWhiteList === undefined) {
1041                    isInWhiteList = ArkThemeWhiteList.isInWhiteList(item.name);
1042                    item.isInWhiteList = isInWhiteList;
1043                }
1044                if (isInWhiteList === true) {
1045                    listener.forceRerenderNode(item.elmtId);
1046                }
1047            }
1048        }
1049        if (item.listener) {
1050            const listener = item.listener;
1051            listener.onWillApplyTheme(themeWillApply);
1052        }
1053    }
1054    makeTheme(customTheme, colorMode) {
1055        var _a;
1056        const baselineTheme = (_a = this.defaultTheme) !== null && _a !== void 0 ? _a : ArkThemeScopeManager.SystemTheme;
1057        const theme = ArkThemeCache.getInstance().get(baselineTheme.id, customTheme, colorMode);
1058        return theme ? theme : new ArkThemeImpl(customTheme, colorMode, baselineTheme);
1059    }
1060    static cloneCustomThemeWithExpand(customTheme) {
1061        const theme = ArkThemeBase.copyCustomTheme(customTheme);
1062        if (theme === null || theme === void 0 ? void 0 : theme.colors) {
1063            ArkColorsImpl.expandByBrandColor(theme.colors);
1064        }
1065        if (theme === null || theme === void 0 ? void 0 : theme.darkColors) {
1066            ArkColorsImpl.expandByBrandColor(theme.darkColors);
1067        }
1068        return theme;
1069    }
1070    setDefaultTheme(customTheme) {
1071        var _a;
1072        (_a = this.defaultTheme) === null || _a === void 0 ? void 0 : _a.unbindFromScope(0);
1073        this.defaultTheme = ArkThemeScopeManager.SystemTheme;
1074        const cloneTheme = ArkThemeScopeManager.cloneCustomThemeWithExpand(customTheme);
1075        this.defaultTheme = this.makeTheme(cloneTheme, ThemeColorMode.SYSTEM);
1076        this.defaultTheme.bindToScope(0);
1077        ArkThemeNativeHelper.sendThemeToNative(this.defaultTheme, 0, !!cloneTheme?.darkColors);
1078        ArkThemeNativeHelper.setDefaultTheme(cloneTheme);
1079        this.notifyGlobalThemeChanged();
1080    }
1081    static getSystemColors() {
1082        return ArkThemeScopeManager.SystemTheme.colors;
1083    }
1084    notifyGlobalThemeChanged() {
1085        this.listeners.forEach(listener => {
1086            if (listener.parent_ === undefined) {
1087                listener.onGlobalThemeChanged();
1088            }
1089        });
1090    }
1091    handleThemeScopeChange(scope) {
1092        var _a;
1093        const currentThemeScopeId = (_a = scope === null || scope === void 0 ? void 0 : scope.getWithThemeId()) !== null && _a !== void 0 ? _a : 0;
1094        if (currentThemeScopeId !== this.lastThemeScopeId) {
1095            this.lastThemeScopeId = currentThemeScopeId;
1096            WithTheme.setThemeScopeId(currentThemeScopeId);
1097        }
1098    }
1099    setIsFirstRender(isFirstRender) {
1100        this.handledIsFirstRender = isFirstRender;
1101    }
1102    static getInstance() {
1103        if (!ArkThemeScopeManager.instance) {
1104            ArkThemeScopeManager.instance = new ArkThemeScopeManager();
1105            ViewBuildNodeBase.setArkThemeScopeManager(ArkThemeScopeManager.instance);
1106        }
1107        return ArkThemeScopeManager.instance;
1108    }
1109}
1110ArkThemeScopeManager.SystemTheme = new ArkSystemTheme();
1111ArkThemeScopeManager.instance = undefined;
1112globalThis.themeScopeMgr = ArkThemeScopeManager.getInstance();
1113class ArkThemeWhiteList {
1114    static isInWhiteList(componentName) {
1115        let start = 0;
1116        let end = ArkThemeWhiteList.whiteList.length - 1;
1117        while (start <= end) {
1118            let mid = (start + end) >> 1;
1119            if (ArkThemeWhiteList.whiteList[mid].localeCompare(componentName) === 0) {
1120                return true;
1121            }
1122            if (ArkThemeWhiteList.whiteList[mid].localeCompare(componentName) === 1) {
1123                end = mid - 1;
1124            }
1125            else {
1126                start = mid + 1;
1127            }
1128        }
1129        return false;
1130    }
1131}
1132ArkThemeWhiteList.whiteList = [
1133    'AlphabetIndexer',
1134    'Badge',
1135    'Button',
1136    'DataPanel',
1137    'Menu',
1138    'MenuItem',
1139    'PatternLock',
1140    'QRCode',
1141    'Radio',
1142    'Scroll',
1143    'Swiper',
1144    'Text',
1145];
1146