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