From 71b0017fb9e45cdcd0d822e56db9c519a39a7f1e Mon Sep 17 00:00:00 2001 From: "Roy.Liu" Date: Thu, 24 Dec 2020 19:44:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85web=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/platform/web/detectElementResize.ts | 6 ++ typescript/core/platform/web/dom.ts | 58 +++++++++++++++++++ typescript/core/platform/web/eventListener.ts | 5 ++ typescript/core/platform/web/index.ts | 11 +++- typescript/core/platform/web/load.ts | 3 + 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 typescript/core/platform/web/detectElementResize.ts create mode 100644 typescript/core/platform/web/dom.ts create mode 100644 typescript/core/platform/web/eventListener.ts create mode 100644 typescript/core/platform/web/load.ts diff --git a/typescript/core/platform/web/detectElementResize.ts b/typescript/core/platform/web/detectElementResize.ts new file mode 100644 index 0000000000..beafcdcbb3 --- /dev/null +++ b/typescript/core/platform/web/detectElementResize.ts @@ -0,0 +1,6 @@ +import { Widget } from "typescript/core/widget"; + +export type _DetectElementResize = { + addResizeListener: (widget: Widget, fn: Function) => Function + removeResizeListener: (widget: Widget, fn: Function) => void +} \ No newline at end of file diff --git a/typescript/core/platform/web/dom.ts b/typescript/core/platform/web/dom.ts new file mode 100644 index 0000000000..ed4035d644 --- /dev/null +++ b/typescript/core/platform/web/dom.ts @@ -0,0 +1,58 @@ +import { Widget } from "typescript/core/widget"; + + +export type _DOM = { + ready: (fn: Function) => void + + // TODO: 引入jquery描述后处理 + patchProps: (fromElement: any, toElement: any) => void + + hang: (doms: Widget[]) => DocumentFragment + isExist: (obj: Widget) => boolean + preloadImages: (srcArray: string[], onload: Function) => void + getTextSizeWidth: (text: string, fontSize?: number) => number + getTextSizeHeight: (text: string, fontSize?: number) => number + getScrollWidth: () => number + getImage: (param: string, fillStyle?: string, backgroundColor?: string) => { width: number, height: number, src: string, style: string, param: string } + + isColor: (color: string) => boolean + isRGBColor: (color: string) => boolean + isHexColor: (color: string) => boolean + isDarkColor: (hex: string) => boolean + getContrastColor: (color: string) => string + rgb2hex: (rgbColour: string) => string + rgb2json: (rgbColour: string) => { r: number, g: number, b: number } + rgba2json: (rgbColour: string) => { r: number, g: number, b: number, a:number } + json2rgb: (rgb: { r: number, g: number, b: number }) => string + json2rgba: (rgba: { r: number, g: number, b: number, a:number }) => string + int2hex: (strNum: number) => string + hex2rgb: (color: string) => string + rgba2rgb: (rgbColor: string, bgColor?:string) => string + + getLeftPosition: (combo: Widget, popup: Widget, extraWidth?: number) => { left: number} + getInnerLeftPosition: (combo: Widget, popup?: Widget, extraWidth?: number) => { left: number} + getRightPosition: (combo: Widget, popup?: Widget, extraWidth?: number) => { left: number} + getInnerRightPosition: (combo: Widget, popup: Widget, extraWidth?: number) => { left: number} + getTopPosition: (combo: Widget, popup: Widget, extraHeight?: number) => { top: number} + getBottomPosition: (combo: Widget, popup?: Widget, extraHeight?: number) => { top: number} + isLeftSpaceEnough: (combo: Widget, popup: Widget, extraWidth?: number) => boolean + isInnerLeftSpaceEnough: (combo: Widget, popup: Widget, extraWidth?: number) => boolean + isRightSpaceEnough: (combo: Widget, popup: Widget, extraWidth?: number) => boolean + isInnerRightSpaceEnough: (combo: Widget, popup: Widget, extraWidth?: number) => boolean + isTopSpaceEnough: (combo: Widget, popup?: Widget, extraHeight?: number) => boolean + isBottomSpaceEnough: (combo: Widget, popup?: Widget, extraHeight?: number) => boolean + isRightSpaceLarger: (combo: Widget) => boolean + isBottomSpaceLarger: (combo: Widget) => boolean + getLeftAlignPosition: (combo: Widget, popup: Widget, extraWidth?: number) => { left: number} + getLeftAdaptPosition: (combo: Widget, popup: Widget, extraWidth?: number) => { left: number} + getRightAlignPosition: (combo: Widget, popup: Widget, extraWidth?: number) => { left: number} + getRightAdaptPosition: (combo: Widget, popup: Widget, extraWidth?: number) => { left: number} + getTopAlignPosition: (combo: Widget, popup: Widget, extraHeight?:number, needAdaptHeight?:boolean) => { top: number, adaptHeight?: number} + getTopAdaptPosition: (combo: Widget, popup: Widget, extraHeight?:number, needAdaptHeight?:boolean) => { top: number, adaptHeight?: number} + getBottomAlignPosition: (combo: Widget, popup: Widget, extraHeight?:number, needAdaptHeight?:boolean) => { top: number, adaptHeight?: number} + getBottomAdaptPosition: (combo: Widget, popup: Widget, extraHeight?:number, needAdaptHeight?:boolean) => { top: number, adaptHeight?: number} + getCenterAdaptPosition: (combo: Widget, popup: Widget) => { left: number } + getMiddleAdaptPosition: (combo: Widget, popup: Widget) => { top: number } + getComboPositionByDirections: (combo: Widget, popup: Widget, extraWidth?:number, extraHeight?:number, needAdaptHeight?:number, directions?:number) => { dir: string, left?: number, top?: number, change?: string} + getComboPosition: (combo: Widget, popup: Widget, extraWidth?:number, extraHeight?:number, needAdaptHeight?:number, directions?:number) => { dir: string, left?: number, top?: number, change?: string} +} \ No newline at end of file diff --git a/typescript/core/platform/web/eventListener.ts b/typescript/core/platform/web/eventListener.ts new file mode 100644 index 0000000000..1380e09673 --- /dev/null +++ b/typescript/core/platform/web/eventListener.ts @@ -0,0 +1,5 @@ +export type _EventListener = { + listen: (target: EventTarget, eventType: string, callback: Function) => void + capture: (target: EventTarget, eventType: string, callback: Function) => void + registerDefault: () => void +} \ No newline at end of file diff --git a/typescript/core/platform/web/index.ts b/typescript/core/platform/web/index.ts index 469e247a11..79b2a19c56 100644 --- a/typescript/core/platform/web/index.ts +++ b/typescript/core/platform/web/index.ts @@ -1,6 +1,11 @@ import { _function } from "./function"; +import { _EventListener } from './eventListener'; +import { _DetectElementResize } from './detectElementResize'; +import { _load } from './load'; +import { _DOM } from './dom'; - -export interface _web extends _function { - +export interface _web extends _function, _load { + EventListener: _EventListener, + ResizeDetector: _DetectElementResize, + DOM: _DOM } \ No newline at end of file diff --git a/typescript/core/platform/web/load.ts b/typescript/core/platform/web/load.ts new file mode 100644 index 0000000000..4d49d2aeb0 --- /dev/null +++ b/typescript/core/platform/web/load.ts @@ -0,0 +1,3 @@ +export type _load = { + $import: (src: string, ext?: string, must?: boolean) => void +} \ No newline at end of file