107ac75b1Sopenharmony_ci/* 207ac75b1Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 307ac75b1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 407ac75b1Sopenharmony_ci * you may not use this file except in compliance with the License. 507ac75b1Sopenharmony_ci * You may obtain a copy of the License at 607ac75b1Sopenharmony_ci * 707ac75b1Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 807ac75b1Sopenharmony_ci * 907ac75b1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1007ac75b1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1107ac75b1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1207ac75b1Sopenharmony_ci * See the License for the specific language governing permissions and 1307ac75b1Sopenharmony_ci * limitations under the License. 1407ac75b1Sopenharmony_ci */ 1507ac75b1Sopenharmony_ci 1607ac75b1Sopenharmony_ciconst fs = require('fs'); 1707ac75b1Sopenharmony_ciconst path = require('path'); 1807ac75b1Sopenharmony_ciimport ts from 'typescript'; 1907ac75b1Sopenharmony_ci 2007ac75b1Sopenharmony_ciconst COMPONENTS = 'components'; 2107ac75b1Sopenharmony_ciconst FORM_COMPONENTS = 'form_components'; 2207ac75b1Sopenharmony_ciexport const COMPONENT_MAP: any = {}; 2307ac75b1Sopenharmony_ciexport const FORM_MAP: any = {}; 2407ac75b1Sopenharmony_ci 2507ac75b1Sopenharmony_ciexport let COMMON_ATTRS: Set<string> = new Set([]); 2607ac75b1Sopenharmony_ci 2707ac75b1Sopenharmony_ci(function readComponents() { 2807ac75b1Sopenharmony_ci const componentPath: Map<string, string> = new Map([ 2907ac75b1Sopenharmony_ci [`${COMPONENTS}`, `../${COMPONENTS}`], 3007ac75b1Sopenharmony_ci [`${FORM_COMPONENTS}`, `../${FORM_COMPONENTS}`] 3107ac75b1Sopenharmony_ci ]); 3207ac75b1Sopenharmony_ci for (const [id, relPath] of componentPath.entries()) { 3307ac75b1Sopenharmony_ci const componentsFile: string = path.join(__dirname, relPath); 3407ac75b1Sopenharmony_ci const files: string[] = fs.readdirSync(componentsFile); 3507ac75b1Sopenharmony_ci files.forEach(function(item) { 3607ac75b1Sopenharmony_ci const fPath: string = path.join(componentsFile, item); 3707ac75b1Sopenharmony_ci const json: any = require(fPath); 3807ac75b1Sopenharmony_ci const stat: any = fs.statSync(fPath); 3907ac75b1Sopenharmony_ci if (stat.isFile()) { 4007ac75b1Sopenharmony_ci if (json.name) { 4107ac75b1Sopenharmony_ci const compName: string = json.name; 4207ac75b1Sopenharmony_ci delete json.name; 4307ac75b1Sopenharmony_ci if (id === COMPONENTS) { 4407ac75b1Sopenharmony_ci COMPONENT_MAP[compName] = json; 4507ac75b1Sopenharmony_ci } else if (id === FORM_COMPONENTS) { 4607ac75b1Sopenharmony_ci FORM_MAP[compName] = json; 4707ac75b1Sopenharmony_ci } 4807ac75b1Sopenharmony_ci } else { 4907ac75b1Sopenharmony_ci if (id === COMPONENTS) { 5007ac75b1Sopenharmony_ci COMMON_ATTRS = new Set(json.attrs); 5107ac75b1Sopenharmony_ci } 5207ac75b1Sopenharmony_ci } 5307ac75b1Sopenharmony_ci } 5407ac75b1Sopenharmony_ci }); 5507ac75b1Sopenharmony_ci } 5607ac75b1Sopenharmony_ci})(); 5707ac75b1Sopenharmony_ci 5807ac75b1Sopenharmony_ciconst TRANSITION_COMMON_ATTRS: Set<string> = new Set([ 5907ac75b1Sopenharmony_ci 'slide', 'translate', 'scale', 'opacity' 6007ac75b1Sopenharmony_ci]); 6107ac75b1Sopenharmony_ciexport const GESTURE_ATTRS: Set<string> = new Set([ 6207ac75b1Sopenharmony_ci 'gesture', 'parallelGesture', 'priorityGesture' 6307ac75b1Sopenharmony_ci]); 6407ac75b1Sopenharmony_ci 6507ac75b1Sopenharmony_ciexport const ID_ATTRS: Map<string, Map<string, string | number>> = new Map(); 6607ac75b1Sopenharmony_ci 6707ac75b1Sopenharmony_ciexport const forbiddenUseStateType: Set<string> = new Set(['Scroller', 'SwiperScroller', 6807ac75b1Sopenharmony_ci 'VideoController', 'WebController', 'CustomDialogController', 'SwiperController', 6907ac75b1Sopenharmony_ci 'TabsController', 'CalendarController', 'AbilityController', 'XComponentController', 7007ac75b1Sopenharmony_ci 'CanvasRenderingContext2D', 'CanvasGradient', 'ImageBitmap', 'ImageData', 'Path2D', 7107ac75b1Sopenharmony_ci 'RenderingContextSettings', 'OffscreenCanvasRenderingContext2D', 'PatternLockController', 7207ac75b1Sopenharmony_ci 'TextAreaController', 'TextInputController', 'TextTimerController', 'SearchController', 'RichEditorController' 7307ac75b1Sopenharmony_ci]); 7407ac75b1Sopenharmony_ci 7507ac75b1Sopenharmony_ciconst FOREACH_ATTRIBUTE = ['onMove']; 7607ac75b1Sopenharmony_ciexport const INNER_COMPONENT_NAMES: Set<string> = new Set(); 7707ac75b1Sopenharmony_ciexport const NO_DEBUG_LINE_COMPONENT: Set<string> = new Set(); 7807ac75b1Sopenharmony_ciexport const BUILDIN_CONTAINER_COMPONENT: Set<string> = new Set(); 7907ac75b1Sopenharmony_ciexport const BUILDIN_STYLE_NAMES: Set<string> = new Set([ 8007ac75b1Sopenharmony_ci ...COMMON_ATTRS, ...GESTURE_ATTRS, ...TRANSITION_COMMON_ATTRS, ...FOREACH_ATTRIBUTE 8107ac75b1Sopenharmony_ci]); 8207ac75b1Sopenharmony_ciexport const AUTOMIC_COMPONENT: Set<string> = new Set(); 8307ac75b1Sopenharmony_ciexport const SINGLE_CHILD_COMPONENT: Set<string> = new Set(); 8407ac75b1Sopenharmony_ciexport const SPECIFIC_CHILD_COMPONENT: Map<string, Set<string>> = new Map(); 8507ac75b1Sopenharmony_ciexport const SPECIFIC_PARENT_COMPONENT: Map<string, Set<string>> = new Map(); 8607ac75b1Sopenharmony_ciexport const GESTURE_TYPE_NAMES: Set<string> = new Set([ 8707ac75b1Sopenharmony_ci 'TapGesture', 'LongPressGesture', 'PanGesture', 'PinchGesture', 'RotationGesture', 'GestureGroup', 8807ac75b1Sopenharmony_ci 'SwipeGesture' 8907ac75b1Sopenharmony_ci]); 9007ac75b1Sopenharmony_ciexport const CUSTOM_BUILDER_METHOD: Set<string> = new Set(); 9107ac75b1Sopenharmony_ciexport const INNER_CUSTOM_LOCALBUILDER_METHOD: Set<string> = new Set(); 9207ac75b1Sopenharmony_ciexport const INNER_STYLE_FUNCTION: Map<string, ts.Block> = new Map(); 9307ac75b1Sopenharmony_ciexport const GLOBAL_STYLE_FUNCTION: Map<string, ts.Block> = new Map(); 9407ac75b1Sopenharmony_ci 9507ac75b1Sopenharmony_ciexport interface ExtendParamterInterfance { 9607ac75b1Sopenharmony_ci attribute: string, 9707ac75b1Sopenharmony_ci parameterCount: number 9807ac75b1Sopenharmony_ci} 9907ac75b1Sopenharmony_ciexport const EXTEND_ATTRIBUTE: Map<string, Set<string>> = new Map(); 10007ac75b1Sopenharmony_ciexport const STYLES_ATTRIBUTE: Set<string> = new Set(); 10107ac75b1Sopenharmony_ci 10207ac75b1Sopenharmony_ciexport const INTERFACE_NODE_SET: Set<ts.InterfaceDeclaration> = new Set(); 10307ac75b1Sopenharmony_ci 10407ac75b1Sopenharmony_ciexport const INNER_CUSTOM_BUILDER_METHOD: Set<string> = new Set(); 10507ac75b1Sopenharmony_ciexport const GLOBAL_CUSTOM_BUILDER_METHOD: Set<string> = new Set(); 10607ac75b1Sopenharmony_ci 10707ac75b1Sopenharmony_ciexport const JS_BIND_COMPONENTS: Set<string> = new Set([ 10807ac75b1Sopenharmony_ci 'ForEach', 'LazyForEach', ...GESTURE_TYPE_NAMES, 'Gesture', 10907ac75b1Sopenharmony_ci 'PanGestureOption', 'CustomDialogController', 'Storage', 'Scroller', 'SwiperController', 11007ac75b1Sopenharmony_ci 'TabsController', 'CalendarController', 'AbilityController', 'VideoController', 'WebController', 11107ac75b1Sopenharmony_ci 'XComponentController', 'CanvasRenderingContext2D', 'CanvasGradient', 'ImageBitmap', 'ImageData', 11207ac75b1Sopenharmony_ci 'Path2D', 'RenderingContextSettings', 'OffscreenCanvasRenderingContext2D', 'DatePickerDialog', 11307ac75b1Sopenharmony_ci 'TextPickerDialog', 'AlertDialog', 'ContextMenu', 'ActionSheet', 'PatternLockController', 11407ac75b1Sopenharmony_ci 'TimePickerDialog', 'CalendarPickerDialog' 11507ac75b1Sopenharmony_ci]); 11607ac75b1Sopenharmony_ci 11707ac75b1Sopenharmony_ciexport const NEEDPOP_COMPONENT: Set<string> = new Set(['Blank', 'Search']); 11807ac75b1Sopenharmony_ci 11907ac75b1Sopenharmony_ciexport const CUSTOM_BUILDER_PROPERTIES: Set<string> = new Set(['background', 'bindPopup', 'bindMenu', 'bindContextMenu', 'title', 12007ac75b1Sopenharmony_ci 'menus', 'toolBar', 'tabBar', 'onDragStart', 'onItemDragStart', 'swipeAction', 'bindContentCover', 'bindSheet', 12107ac75b1Sopenharmony_ci 'navDestination', 'overlay', 'toolbarConfiguration', 'customKeyboard', 'bindSelectionMenu', 'description', 12207ac75b1Sopenharmony_ci 'showUnit', 'customKeyboard', 'create', 'addBuilderSpan', 'dragPreview', 'accessibilityVirtualNode']); 12307ac75b1Sopenharmony_ciexport const CUSTOM_BUILDER_PROPERTIES_WITHOUTKEY: Set<string> = new Set(['showUnit', 'create']); 12407ac75b1Sopenharmony_ciexport const CUSTOM_BUILDER_CONSTRUCTORS: Set<string> = new Set(['MenuItem', 'MenuItemGroup', 'Refresh', 'WaterFlow', 'Radio', 'Checkbox']); 12507ac75b1Sopenharmony_ci 12607ac75b1Sopenharmony_ci(function initComponent() { 12707ac75b1Sopenharmony_ci Object.keys(COMPONENT_MAP).forEach((componentName) => { 12807ac75b1Sopenharmony_ci INNER_COMPONENT_NAMES.add(componentName); 12907ac75b1Sopenharmony_ci JS_BIND_COMPONENTS.add(componentName); 13007ac75b1Sopenharmony_ci if (!COMPONENT_MAP[componentName].atomic) { 13107ac75b1Sopenharmony_ci BUILDIN_CONTAINER_COMPONENT.add(componentName); 13207ac75b1Sopenharmony_ci } else { 13307ac75b1Sopenharmony_ci AUTOMIC_COMPONENT.add(componentName); 13407ac75b1Sopenharmony_ci } 13507ac75b1Sopenharmony_ci if (COMPONENT_MAP[componentName].single) { 13607ac75b1Sopenharmony_ci SINGLE_CHILD_COMPONENT.add(componentName); 13707ac75b1Sopenharmony_ci } 13807ac75b1Sopenharmony_ci if (COMPONENT_MAP[componentName].children) { 13907ac75b1Sopenharmony_ci SPECIFIC_CHILD_COMPONENT.set(componentName, 14007ac75b1Sopenharmony_ci new Set([...COMPONENT_MAP[componentName].children])); 14107ac75b1Sopenharmony_ci } 14207ac75b1Sopenharmony_ci if (COMPONENT_MAP[componentName].attrs && COMPONENT_MAP[componentName].attrs.length) { 14307ac75b1Sopenharmony_ci COMPONENT_MAP[componentName].attrs.forEach((item) => { 14407ac75b1Sopenharmony_ci BUILDIN_STYLE_NAMES.add(item); 14507ac75b1Sopenharmony_ci }); 14607ac75b1Sopenharmony_ci } 14707ac75b1Sopenharmony_ci if (COMPONENT_MAP[componentName].noDebugLine) { 14807ac75b1Sopenharmony_ci NO_DEBUG_LINE_COMPONENT.add(componentName); 14907ac75b1Sopenharmony_ci } 15007ac75b1Sopenharmony_ci if (COMPONENT_MAP[componentName].parents) { 15107ac75b1Sopenharmony_ci SPECIFIC_PARENT_COMPONENT.set(componentName, 15207ac75b1Sopenharmony_ci new Set([...COMPONENT_MAP[componentName].parents])); 15307ac75b1Sopenharmony_ci } 15407ac75b1Sopenharmony_ci }); 15507ac75b1Sopenharmony_ci})(); 15607ac75b1Sopenharmony_ci 15707ac75b1Sopenharmony_ciexport function resetComponentMap(): void { 15807ac75b1Sopenharmony_ci ID_ATTRS.clear(); 15907ac75b1Sopenharmony_ci EXTEND_ATTRIBUTE.clear(); 16007ac75b1Sopenharmony_ci STYLES_ATTRIBUTE.clear(); 16107ac75b1Sopenharmony_ci} 162