1/* 2 * Copyright (c) 2021 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 16const fs = require('fs'); 17const path = require('path'); 18import ts from 'typescript'; 19 20export const COMPONENT_MAP: any = {}; 21 22export let COMMON_ATTRS: Set<string> = new Set([]); 23 24(function readComponents() { 25 const componentsFile: string = path.join(__dirname, '../components'); 26 const files: string[] = fs.readdirSync(componentsFile); 27 files.forEach(function(item) { 28 const fPath: string = path.join(componentsFile, item); 29 const json: any = require(fPath); 30 const stat: any = fs.statSync(fPath); 31 if (stat.isFile()) { 32 if (json.name) { 33 const compName: string = json.name; 34 delete json.name; 35 COMPONENT_MAP[compName] = json; 36 } else { 37 COMMON_ATTRS = new Set(json.attrs); 38 } 39 } 40 }); 41})(); 42 43const TRANSITION_COMMON_ATTRS: Set<string> = new Set([ 44 'slide', 'translate', 'scale', 'opacity' 45]); 46export const GESTURE_ATTRS: Set<string> = new Set([ 47 'gesture', 'parallelGesture', 'priorityGesture' 48]); 49 50export const forbiddenUseStateType: Set<string> = new Set(['Scroller', 'SwiperScroller', 51 'VideoController', 'WebController', 'CustomDialogController', 'SwiperController', 52 'TabsController', 'CalendarController', 'AbilityController', 'XComponentController', 53 'CanvasRenderingContext2D', 'CanvasGradient', 'ImageBitmap', 'ImageData', 'Path2D', 54 'RenderingContextSettings', 'OffscreenCanvasRenderingContext2D', 'PatternLockController' 55]); 56 57export const INNER_COMPONENT_NAMES: Set<string> = new Set(); 58export const NO_DEBUG_LINE_COMPONENT: Set<string> = new Set(); 59export const BUILDIN_CONTAINER_COMPONENT: Set<string> = new Set(); 60export const BUILDIN_STYLE_NAMES: Set<string> = new Set([ 61 ...COMMON_ATTRS, ...GESTURE_ATTRS, ...TRANSITION_COMMON_ATTRS 62]); 63export const AUTOMIC_COMPONENT: Set<string> = new Set(); 64export const SINGLE_CHILD_COMPONENT: Set<string> = new Set(); 65export const SPECIFIC_CHILD_COMPONENT: Map<string, Set<string>> = new Map(); 66export const GESTURE_TYPE_NAMES: Set<string> = new Set([ 67 'TapGesture', 'LongPressGesture', 'PanGesture', 'PinchGesture', 'RotationGesture', 'GestureGroup', 68 'SwipeGesture' 69]); 70export const CUSTOM_BUILDER_METHOD: Set<string> = new Set(); 71export const INNER_STYLE_FUNCTION: Map<string, ts.Block> = new Map(); 72export const GLOBAL_STYLE_FUNCTION: Map<string, ts.Block> = new Map(); 73 74export interface ExtendParamterInterfance { 75 attribute: string, 76 parameterCount: number 77} 78export const EXTEND_ATTRIBUTE: Map<string, Set<string>> = new Map(); 79export const STYLES_ATTRIBUTE: Set<string> = new Set(); 80 81export const INTERFACE_NODE_SET: Set<ts.InterfaceDeclaration> = new Set(); 82 83export const JS_BIND_COMPONENTS: Set<string> = new Set([ 84 'ForEach', 'LazyForEach', ...GESTURE_TYPE_NAMES, 'Gesture', 85 'PanGestureOption', 'CustomDialogController', 'Storage', 'Scroller', 'SwiperController', 86 'TabsController', 'CalendarController', 'AbilityController', 'VideoController', 'WebController', 87 'XComponentController', 'CanvasRenderingContext2D', 'CanvasGradient', 'ImageBitmap', 'ImageData', 88 'Path2D', 'RenderingContextSettings', 'OffscreenCanvasRenderingContext2D', 'DatePickerDialog', 89 'TextPickerDialog', 'AlertDialog', 'ContextMenu', 'ActionSheet', 'PatternLockController', 90 'TimePickerDialog' 91]); 92 93export const NEEDPOP_COMPONENT: Set<string> = new Set(['Blank', 'Search']); 94 95export const CUSTOM_BUILDER_PROPERTIES: Set<string> = new Set(['bindPopup', 'bindMenu', 'bindContextMenu', 'title', 96 'menus', 'toolBar', 'tabBar', 'onDragStart', 'onItemDragStart']); 97 98(function initComponent() { 99 Object.keys(COMPONENT_MAP).forEach((componentName) => { 100 INNER_COMPONENT_NAMES.add(componentName); 101 JS_BIND_COMPONENTS.add(componentName); 102 if (!COMPONENT_MAP[componentName].atomic) { 103 BUILDIN_CONTAINER_COMPONENT.add(componentName); 104 } else { 105 AUTOMIC_COMPONENT.add(componentName); 106 } 107 if (COMPONENT_MAP[componentName].single) { 108 SINGLE_CHILD_COMPONENT.add(componentName); 109 } 110 if (COMPONENT_MAP[componentName].children) { 111 SPECIFIC_CHILD_COMPONENT.set(componentName, 112 new Set([...COMPONENT_MAP[componentName].children])); 113 } 114 if (COMPONENT_MAP[componentName].attrs && COMPONENT_MAP[componentName].attrs.length) { 115 COMPONENT_MAP[componentName].attrs.forEach((item) => { 116 BUILDIN_STYLE_NAMES.add(item); 117 }); 118 } 119 if (COMPONENT_MAP[componentName].noDebugLine) { 120 NO_DEBUG_LINE_COMPONENT.add(componentName); 121 } 122 }); 123})(); 124