Skip to content

Commit

Permalink
feat: 完成工具类型的类型声明
Browse files Browse the repository at this point in the history
  • Loading branch information
xyy94813 committed Mar 5, 2024
1 parent 45d6362 commit 3a667ec
Show file tree
Hide file tree
Showing 7 changed files with 636 additions and 0 deletions.
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/* Language and Environment */
"target": "es5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"dom",
"esnext"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
// "jsx": "preserve", /* Specify what JSX code is generated. */
Expand Down
8 changes: 8 additions & 0 deletions types/common/Geometry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { LngLatLike } from './LngLat.d';

export type Position = LngLatLike;
export type Line = Position[];
export type Ring = Position[];
export type PolygonWithHoleCoords = Ring[];
export type PolygonCoords = Ring | PolygonWithHoleCoords;
export type MultiPolygonCoords = Ring[][];
11 changes: 11 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import type { LngLat, LngLatLike } from './common/LngLat';
import type Bounds from './common/Bounds';
import type Pixel from './common/Pixel';
import type Size from './common/Size';

import type GeometryUtil from './utils/GeometryUtil';
import type DomUtil from './utils/DomUtil';
import type Browser from './utils/Browser';
import type Util from './utils/Util';

/**
* 高德地图 JS API v2 类型声明
*/
Expand All @@ -13,6 +19,11 @@ declare namespace AMap {
Bounds,
Pixel,
Size,
// 工具
GeometryUtil,
Browser,
Util,
DomUtil,
};
}

Expand Down
59 changes: 59 additions & 0 deletions types/utils/Browser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 浏览器信息
*
* https://lbs.amap.com/api/javascript-api-v2/documentation#browser
*/
export interface Browser {
ua: string;
mobile: boolean;
plat: string;
mac: boolean;
windows: boolean;
ios: boolean;
iPad: boolean;
iPhone: boolean;
android: boolean;
android23: boolean;
chrome: boolean;
firefox: boolean;
safari: boolean;
wechat: boolean;
uc: boolean;
qq: boolean;
ie: boolean;
ie6: boolean;
ie7: boolean;
ie8: boolean;
ie9: boolean;
ie10: boolean;
ie11: boolean;
edge: boolean;
ielt9: boolean;
baidu: boolean;
isLocalStorage: boolean;
isGeolocation: boolean;
mobileWebkit: boolean;
mobileWebkit3d: boolean;
mobileOpera: boolean;
retina: boolean;
touch: boolean;
msPointer: boolean;
pointer: boolean;
baseRender: string;
wasm: boolean;
webkit: boolean;
ie3d: boolean;
webkit3d: boolean;
gecko3d: boolean;
opera3d: boolean;
any3d: boolean;
isCanvas: boolean;
isSvg: boolean;
isVML: boolean;
isWorker: boolean;
isWebsocket: boolean;
isWebGL: boolean;
checkWebGL: () => boolean;
}

export default Browser;
142 changes: 142 additions & 0 deletions types/utils/DomUtil.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import Pixel from '../common/Pixel.d';
/**
* DOM 辅助工具
*
* https://lbs.amap.com/api/javascript-api-v2/documentation#domutil
*/
export interface DomUtil {
/**
* 获取 DOM 元素的大小
* @param obj [width, height]
*/
getViewport(obj: HTMLElement): [number, number];

/**
* 获取DOM元素距离窗口左上角的距离
*
* @param {HTMLElement} element
* @returns {[number, number]} [x, y]
*/
getViewportOffset(element: HTMLElement): [number, number];

/**
* 在parentNode内部创建一个className类名的tagName元素
* @param {string} tagName 节点类型
* @param {HTMLElement} container 上级节点对象
* @param {string} className
* @param {string} position 插入位置
* @returns {HTMLElement}
*/
create(
tagName: string,
container: HTMLElement | null,
className?: string,
position?: string,
): HTMLElement;

/**
* DOM 元素是否包含 className
* @param {HTMLElement} el
* @param {string} name
* @returns {boolean}
*/
hasClass(el: HTMLElement, name: string): boolean;
hasClass(): undefined;
hasClass(el: HTMLElement): undefined;
/**
* 给 DOM 元素添加一个 className
* @param {HTMLElement} el
* @param {string} name
*/
addClass(el: HTMLElement, name: string): void;
/**
* 给 DOM 元素设置为 className 样式
* @param {HTMLElement} el
* @param {string} name
*/
setClass(el: HTMLElement, name: string): void;
/**
* 给 DOM 元素删除一个 className
* @param {HTMLElement} el
* @param {string} name
*/
removeClass(el: HTMLElement, name: string): void;
/**
* 将 DOM 元素从父节点删除
*
* @param {HTMLElement} el
*/
remove(el: HTMLElement): void;
/**
* 清空DOM元素
*
* @param {HTMLElement} el
*/
empty(el: HTMLElement): void;
/**
* 给DOM元素旋转一个角度,以 center 为中心,center 以元素左上角为坐标原点
* @param {HTMLElement} target
* @param {number} angle
* @param {Pixel} center
*/
rotate(target: HTMLElement, angle: number, center: Pixel): void;
/**
* 给 DOM 元素删除一组样式,Object 同样式表
* @param {HTMLElement | HTMLElement[]} obj
* @param {Object} css
* @returns {DomUtil}
*
* @example AMap.DomUtil.setCss(container, { width: '100vw'})
*/
setCss(obj: HTMLElement | HTMLElement[], css: any): DomUtil;
/**
* 给DOM元素设定一个透明度
*
* @param {HTMLElement} el
* @param {number} value
*/
setOpacity(el: HTMLElement, value: number): void;

/**
* 基于 on 的结果,添加或删除一个 className。
* 文档中未提及,但是存在。
* @param {HTMLElement} el
* @param {string} name
* @param {boolean} on
* @returns {void}
*/
toggleClass(el: HTMLElement, name: string, on: boolean): void;

/**
* 给 DOM 节点填充文本。
* 文档中未提及,但是存在。
* @param {HTMLElement} el
* @param {string} name
* @returns {typeof el}
*/
fillText(el: HTMLElement, name: string): typeof el;
/**
* 获取 DOM 节点的样式的值。
* 文档中未提及,但是存在。
* @param {HTMLElement} el
* @param {string} property css 属性名
* @returns {string}
*
* @example AMap.DomUtil.getStyle(ele, 'opacity')
*/
getStyle(el: HTMLElement, property: string): string;
/**
* 文档中未提及,但是存在。暂不清楚其功能。
*/
mousePos(el: HTMLElement, event: any, n: any): any;
/**
* 文档中未提及,但是存在。暂不清楚其功能。
*/
watchSize(el: HTMLElement, fn: Function, event: any): any;
/**
* 文档中未提及,但是存在。暂不清楚其功能。
*/
watchSize2(el: HTMLElement, fn: Function, event: any): any;
}

export default DomUtil;
Loading

0 comments on commit 3a667ec

Please sign in to comment.