uni-shared.d.ts 13.5 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2
import { FontFaceDescriptors } from 'css-font-loading-module';

fxy060608's avatar
fxy060608 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
export declare const ACTION_TYPE_ADD_EVENT = 8;

export declare const ACTION_TYPE_CREATE = 3;

export declare const ACTION_TYPE_EVENT = 20;

export declare const ACTION_TYPE_INSERT = 4;

export declare const ACTION_TYPE_PAGE_CREATE = 1;

export declare const ACTION_TYPE_PAGE_CREATED = 2;

export declare const ACTION_TYPE_REMOVE = 5;

export declare const ACTION_TYPE_REMOVE_ATTRIBUTE = 7;

export declare const ACTION_TYPE_REMOVE_EVENT = 9;

export declare const ACTION_TYPE_SET_ATTRIBUTE = 6;

export declare const ACTION_TYPE_SET_TEXT = 10;

/**
 * nodeId
 * event
 * flag
 */
export declare type AddEventAction = [
typeof ACTION_TYPE_ADD_EVENT,
number,
string,
number
];

fxy060608's avatar
fxy060608 已提交
37
export declare function addFont(family: string, source: string, desc?: FontFaceDescriptors): Promise<void>;
fxy060608's avatar
fxy060608 已提交
38

fxy060608's avatar
fxy060608 已提交
39 40
export declare const BACKGROUND_COLOR = "#f7f7f7";

fxy060608's avatar
fxy060608 已提交
41 42
export declare const BUILT_IN_TAGS: string[];

fxy060608's avatar
fxy060608 已提交
43 44 45
export declare function cache<T>(fn: (str: string) => T): (str: string) => T;

export declare function cacheStringFunction(fn: (string: string) => string): (str: string) => string;
fxy060608's avatar
fxy060608 已提交
46

Q
qiang 已提交
47 48 49 50 51 52 53
export declare function callOptions(options: Options, errMsg: string): void;

export declare function callOptions(options: Options, data: {
    [key: string]: any;
    errMsg: string;
}): void;

fxy060608's avatar
fxy060608 已提交
54 55
export declare const COMPONENT_NAME_PREFIX = "VUni";

fxy060608's avatar
fxy060608 已提交
56 57 58
export declare const COMPONENT_PREFIX: string;

export declare const COMPONENT_SELECTOR_PREFIX = "uni-";
fxy060608's avatar
fxy060608 已提交
59

fxy060608's avatar
fxy060608 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73
/**
 * nodeId
 * tag
 * parentNodeId
 * nodeJson
 */
export declare type CreateAction = [
typeof ACTION_TYPE_CREATE,
number,
string | number,
number,
Partial<UniNodeJSON>?
];

fxy060608's avatar
fxy060608 已提交
74 75
export declare function createRpx2Unit(unit: string, unitRatio: number, unitPrecision: number): (val: string) => string;

fxy060608's avatar
fxy060608 已提交
76 77
export declare const DATA_RE: RegExp;

fxy060608's avatar
fxy060608 已提交
78 79 80 81 82
export declare function debounce(fn: Function, delay: number): {
    (this: any): void;
    cancel(): void;
};

fxy060608's avatar
fxy060608 已提交
83 84 85 86 87 88 89 90 91
/**
 * Decode text using `decodeURIComponent`. Returns the original text if it
 * fails.
 *
 * @param text - string to decode
 * @returns decoded string
 */
export declare function decode(text: string | number): string;

fxy060608's avatar
fxy060608 已提交
92
export declare function decodeAttr(name: string): any;
fxy060608's avatar
fxy060608 已提交
93

fxy060608's avatar
fxy060608 已提交
94 95
export declare function decodedQuery(query?: Record<string, any>): Record<string, string>;

fxy060608's avatar
fxy060608 已提交
96 97
export declare function decodeEvent(name: string): any;

fxy060608's avatar
fxy060608 已提交
98
export declare function decodeTag(tag: string | number): string;
fxy060608's avatar
fxy060608 已提交
99

fxy060608's avatar
fxy060608 已提交
100 101 102 103 104 105
export declare const defaultRpx2Unit: {
    unit: string;
    unitRatio: number;
    unitPrecision: number;
};

fxy060608's avatar
fxy060608 已提交
106 107 108
export declare function encodeAttr(name: string): string;

export declare function encodeEvent(name: string): any;
fxy060608's avatar
fxy060608 已提交
109 110 111

export declare function encodeTag(tag: string): string | number;

fxy060608's avatar
fxy060608 已提交
112 113 114 115 116 117
export declare const EventModifierFlags: {
    stop: number;
    prevent: number;
    self: number;
};

D
DCloud_LXH 已提交
118 119 120 121 122
export declare function formatDateTime({ date, mode }: {
    date?: Date | undefined;
    mode?: string | undefined;
}): string;

fxy060608's avatar
fxy060608 已提交
123 124
export declare function formatLog(module: string, ...args: any[]): string;

Q
qiang 已提交
125
export declare function getCustomDataset(el: HTMLElement | HTMLElementWithDataset): DOMStringMap & Record<string, any>;
Q
qiang 已提交
126

fxy060608's avatar
fxy060608 已提交
127 128
export declare function getEnvLocale(): string;

fxy060608's avatar
fxy060608 已提交
129 130
export declare function getLen(str?: string): number;

Q
qiang 已提交
131 132 133 134
declare interface HTMLElementWithDataset extends HTMLElement {
    __uniDataset?: Record<string, any>;
}

Q
qiang 已提交
135
export declare function initCustomDataset(): void;
Q
qiang 已提交
136

fxy060608's avatar
fxy060608 已提交
137 138 139 140 141 142 143
/**
 * nodeId
 * parentNodeId
 * refNodeId
 */
export declare type InsertAction = [typeof ACTION_TYPE_INSERT, number, number, number];

fxy060608's avatar
fxy060608 已提交
144 145
export declare const invokeArrayFns: (fns: Function[], arg?: any) => any;

fxy060608's avatar
fxy060608 已提交
146 147 148 149 150 151
export declare function isBuiltInComponent(tag: string): boolean;

export declare function isCustomElement(tag: string): boolean;

export declare function isNativeTag(tag: string): boolean;

fxy060608's avatar
fxy060608 已提交
152 153 154 155
export declare function isServiceCustomElement(_tag: string): boolean;

export declare function isServiceNativeTag(tag: string): boolean;

fxy060608's avatar
fxy060608 已提交
156 157
export declare interface IUniPageNode {
    pageId: number;
fxy060608's avatar
fxy060608 已提交
158
    pageNode: IUniPageNode | null;
fxy060608's avatar
fxy060608 已提交
159
    isUnmounted: boolean;
fxy060608's avatar
fxy060608 已提交
160 161
    genId: () => number;
    push: (...args: any[]) => void;
fxy060608's avatar
fxy060608 已提交
162
    onCreate: (thisNode: UniNode, nodeName: string | number) => UniNode;
fxy060608's avatar
fxy060608 已提交
163 164
    onInsertBefore: (thisNode: UniNode, newChild: UniNode, refChild: UniNode | null) => UniNode;
    onRemoveChild: (oldChild: UniNode) => UniNode;
fxy060608's avatar
fxy060608 已提交
165 166
    onAddEvent: (thisNode: UniNode, name: string, flag: number) => void;
    onRemoveEvent: (thisNode: UniNode, name: string) => void;
fxy060608's avatar
fxy060608 已提交
167 168 169 170
    onSetAttribute: (thisNode: UniNode, qualifiedName: string, value: unknown) => void;
    onRemoveAttribute: (thisNode: UniNode, qualifiedName: string) => void;
    onTextContent: (thisNode: UniNode, text: string) => void;
    onNodeValue: (thisNode: UniNode, val: string | null) => void;
fxy060608's avatar
fxy060608 已提交
171 172
}

fxy060608's avatar
fxy060608 已提交
173 174
export declare const NAVBAR_HEIGHT = 44;

fxy060608's avatar
fxy060608 已提交
175 176 177 178 179 180 181 182
export declare const NODE_TYPE_COMMENT = 8;

export declare const NODE_TYPE_ELEMENT = 1;

export declare const NODE_TYPE_PAGE = 0;

export declare const NODE_TYPE_TEXT = 3;

fxy060608's avatar
fxy060608 已提交
183 184
export declare function normalizeDataset(el: Element): any;

fxy060608's avatar
fxy060608 已提交
185 186
export declare function normalizeEventType(type: string, options?: AddEventListenerOptions): string;

fxy060608's avatar
fxy060608 已提交
187 188
export declare function normalizeTarget(el: HTMLElement): {
    id: string;
Q
qiang 已提交
189
    dataset: DOMStringMap & Record<string, any>;
fxy060608's avatar
fxy060608 已提交
190 191 192 193
    offsetTop: number;
    offsetLeft: number;
};

fxy060608's avatar
fxy060608 已提交
194 195
export declare const ON_REACH_BOTTOM_DISTANCE = 50;

fxy060608's avatar
fxy060608 已提交
196
export declare function once<T extends (...args: any[]) => any>(fn: T, ctx?: unknown): T;
fxy060608's avatar
fxy060608 已提交
197

Q
qiang 已提交
198 199 200 201 202 203
declare interface Options {
    success?: (res: any) => void;
    fail?: (res: any) => void;
    complete?: (res: any) => void;
}

fxy060608's avatar
fxy060608 已提交
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
export declare type PageAction = PageCreateAction | PageCreatedAction | PageUpdateAction;

export declare type PageCreateAction = [typeof ACTION_TYPE_PAGE_CREATE, PageCreateData];

export declare type PageCreatedAction = [typeof ACTION_TYPE_PAGE_CREATED];

export declare interface PageCreateData extends PageNodeOptions {
}

export declare interface PageNodeOptions {
    css: boolean;
    route: string;
    version: number;
    locale: string;
    platform: string;
    pixelRatio: number;
    windowWidth: number;
    disableScroll: boolean;
    onPageScroll: boolean;
    onPageReachBottom: boolean;
    onReachBottomDistance: number;
    statusbarHeight: number;
    windowTop: number;
    windowBottom: number;
}

export declare type PageUpdateAction = CreateAction | InsertAction | RemoveAction | AddEventAction | RemoveEventAction | SetAttributeAction | RemoveAttributeAction | SetTextAction;

fxy060608's avatar
fxy060608 已提交
232 233
export declare function parseEventName(name: string): [string, EventListenerOptions | undefined];

fxy060608's avatar
fxy060608 已提交
234 235 236 237 238 239 240 241 242
/**
 * https://github.com/vuejs/vue-router-next/blob/master/src/query.ts
 * @internal
 *
 * @param search - search string to parse
 * @returns a query object
 */
export declare function parseQuery(search: string): Record<string, any>;

fxy060608's avatar
fxy060608 已提交
243 244 245 246 247
export declare function parseUrl(url: string): {
    path: string;
    query: Record<string, any>;
};

fxy060608's avatar
fxy060608 已提交
248 249 250 251
export declare function passive(passive: boolean): {
    passive: boolean;
};

fxy060608's avatar
fxy060608 已提交
252 253
export declare const PLUS_RE: RegExp;

fxy060608's avatar
fxy060608 已提交
254 255
export declare function plusReady(callback: () => void): void;

fxy060608's avatar
fxy060608 已提交
256 257
export declare const PRIMARY_COLOR = "#007aff";

fxy060608's avatar
fxy060608 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
/**
 * nodeId
 */
export declare type RemoveAction = [typeof ACTION_TYPE_REMOVE, number];

/**
 * nodeId
 * name
 */
export declare type RemoveAttributeAction = [
typeof ACTION_TYPE_REMOVE_ATTRIBUTE,
number,
string
];

/**
 * nodeId
 * event
 */
export declare type RemoveEventAction = [
typeof ACTION_TYPE_REMOVE_EVENT,
number,
string
];

fxy060608's avatar
fxy060608 已提交
283 284
export declare function removeLeadingSlash(str: string): string;

fxy060608's avatar
fxy060608 已提交
285 286
export declare const RESPONSIVE_MIN_WIDTH = 768;

fxy060608's avatar
fxy060608 已提交
287 288
export declare type Rpx2UnitOptions = typeof defaultRpx2Unit;

fxy060608's avatar
fxy060608 已提交
289 290
export declare const sanitise: (val: unknown) => any;

fxy060608's avatar
fxy060608 已提交
291 292
export declare const SCHEME_RE: RegExp;

fxy060608's avatar
fxy060608 已提交
293 294 295
declare function scrollTo_2(scrollTop: number | string, duration: number): void;
export { scrollTo_2 as scrollTo }

fxy060608's avatar
fxy060608 已提交
296 297
export declare const SELECTED_COLOR = "#0062cc";

fxy060608's avatar
fxy060608 已提交
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
/**
 * nodeId
 * name
 * value
 */
export declare type SetAttributeAction = [
typeof ACTION_TYPE_SET_ATTRIBUTE,
number,
string,
unknown
];

/**
 * nodeId
 * text
 */
export declare type SetTextAction = [typeof ACTION_TYPE_SET_TEXT, number, string];

fxy060608's avatar
fxy060608 已提交
316 317 318 319 320 321
export declare function stringifyQuery(obj?: Record<string, any>, encodeStr?: typeof encodeURIComponent): string;

export declare const TABBAR_HEIGHT = 50;

export declare const TAGS: string[];

fxy060608's avatar
fxy060608 已提交
322 323 324 325 326 327
export declare const UNI_SSR = "__uniSSR";

export declare const UNI_SSR_DATA = "data";

export declare const UNI_SSR_GLOBAL_DATA = "globalData";

fxy060608's avatar
fxy060608 已提交
328 329
export declare const UNI_SSR_STORE = "store";

fxy060608's avatar
fxy060608 已提交
330 331
export declare const UNI_SSR_TITLE = "title";

fxy060608's avatar
fxy060608 已提交
332 333 334 335
export declare class UniBaseNode extends UniNode {
    attributes: Record<string, unknown>;
    style: UniCSSStyleDeclaration;
    protected _html: string | null;
fxy060608's avatar
fxy060608 已提交
336
    constructor(nodeType: UniNodeType, nodeName: string, container: UniElement | IUniPageNode);
fxy060608's avatar
fxy060608 已提交
337 338 339 340 341 342 343 344 345
    get className(): string;
    set className(val: string);
    get innerHTML(): string;
    set innerHTML(html: string);
    addEventListener(type: string, listener: UniEventListener, options?: AddEventListenerOptions): void;
    removeEventListener(type: string, callback: UniEventListener, options?: EventListenerOptions): void;
    getAttribute(qualifiedName: string): unknown;
    removeAttribute(qualifiedName: string): void;
    setAttribute(qualifiedName: string, value: unknown): void;
fxy060608's avatar
fxy060608 已提交
346 347 348 349
    toJSON(opts?: {
        attr?: boolean;
        children?: boolean;
    }): Partial<UniNodeJSON>;
fxy060608's avatar
fxy060608 已提交
350 351 352
}

export declare class UniCommentNode extends UniNode {
fxy060608's avatar
fxy060608 已提交
353 354 355 356 357 358 359 360
    constructor(text: string, container: UniElement | IUniPageNode);
    toJSON(opts?: {
        attr?: boolean;
    }): {
        i?: undefined;
    } | {
        i: number;
    };
fxy060608's avatar
fxy060608 已提交
361 362 363 364 365 366 367 368 369 370 371
}

declare class UniCSSStyleDeclaration {
    [name: string]: string | unknown;
    private _cssText;
    private _value;
    setProperty(property: string, value: string | null): void;
    getPropertyValue(property: string): string | string[];
    removeProperty(property: string): string;
    get cssText(): string;
    set cssText(cssText: string);
fxy060608's avatar
fxy060608 已提交
372
    toJSON(): UniCSSStyleDeclarationJSON | undefined;
fxy060608's avatar
fxy060608 已提交
373 374 375 376 377 378
}

declare type UniCSSStyleDeclarationJSON = string | null | Record<string, string | string[]> | [string, Record<string, string | string[]>];

export declare class UniElement extends UniBaseNode {
    tagName: string;
fxy060608's avatar
fxy060608 已提交
379
    constructor(nodeName: string, container: UniElement | IUniPageNode);
fxy060608's avatar
fxy060608 已提交
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
}

export declare class UniEvent {
    type: string;
    bubbles: boolean;
    cancelable: boolean;
    defaultPrevented: boolean;
    timeStamp: number;
    _stop: boolean;
    _end: boolean;
    constructor(type: string, opts: UniEventOptions);
    preventDefault(): void;
    stopImmediatePropagation(): void;
    stopPropagation(): void;
}

export declare interface UniEventListener {
    (evt: UniEvent): void;
fxy060608's avatar
fxy060608 已提交
398
    modifiers?: string[];
fxy060608's avatar
fxy060608 已提交
399 400 401 402 403 404 405 406
}

declare interface UniEventOptions {
    bubbles: boolean;
    cancelable: boolean;
}

declare class UniEventTarget {
fxy060608's avatar
fxy060608 已提交
407
    listeners: Record<string, UniEventListener[]>;
fxy060608's avatar
fxy060608 已提交
408 409
    dispatchEvent(evt: UniEvent): boolean;
    addEventListener(type: string, listener: UniEventListener, options?: AddEventListenerOptions): void;
fxy060608's avatar
fxy060608 已提交
410
    removeEventListener(type: string, callback: UniEventListener, options?: AddEventListenerOptions): void;
fxy060608's avatar
fxy060608 已提交
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
}

export declare class UniInputElement extends UniElement {
    get value(): string | number;
    set value(val: string | number);
}

export declare class UniNode extends UniEventTarget {
    nodeId?: number;
    nodeType: UniNodeType;
    nodeName: string;
    childNodes: UniNode[];
    pageNode: IUniPageNode | null;
    parentNode: UniNode | null;
    protected _text: string | null;
fxy060608's avatar
fxy060608 已提交
426
    constructor(nodeType: UniNodeType, nodeName: string, container: UniElement | IUniPageNode);
fxy060608's avatar
fxy060608 已提交
427 428 429
    get firstChild(): UniNode | null;
    get lastChild(): UniNode | null;
    get nextSibling(): UniNode | null;
fxy060608's avatar
fxy060608 已提交
430 431
    get nodeValue(): string | null;
    set nodeValue(_val: string | null);
fxy060608's avatar
fxy060608 已提交
432 433 434 435
    get textContent(): string;
    set textContent(text: string);
    get parentElement(): UniElement | null;
    get previousSibling(): UniNode | null;
fxy060608's avatar
fxy060608 已提交
436
    appendChild(newChild: UniNode): UniNode;
fxy060608's avatar
fxy060608 已提交
437
    cloneNode(deep?: boolean): UniNode;
fxy060608's avatar
fxy060608 已提交
438 439
    insertBefore(newChild: UniNode, refChild: UniNode | null): UniNode;
    removeChild(oldChild: UniNode): UniNode;
fxy060608's avatar
fxy060608 已提交
440 441 442 443 444 445 446 447 448 449
}

export declare interface UniNodeJSON {
    /**
     * nodeId
     */
    i: number;
    /**
     * nodeName
     */
fxy060608's avatar
fxy060608 已提交
450
    n: string | number;
fxy060608's avatar
fxy060608 已提交
451 452 453 454
    /**
     * attributes
     */
    a: Record<string, unknown>;
fxy060608's avatar
fxy060608 已提交
455 456 457 458
    /**
     * listeners
     */
    e: Record<string, number>;
fxy060608's avatar
fxy060608 已提交
459 460 461
    /**
     * style
     */
fxy060608's avatar
fxy060608 已提交
462
    s?: UniCSSStyleDeclarationJSON;
fxy060608's avatar
fxy060608 已提交
463 464 465 466 467 468 469 470 471 472 473 474
    /**
     * text
     */
    t?: string;
}

declare type UniNodeType = typeof NODE_TYPE_PAGE | typeof NODE_TYPE_ELEMENT | typeof NODE_TYPE_TEXT | typeof NODE_TYPE_COMMENT;

export declare class UniTextAreaElement extends UniInputElement {
}

export declare class UniTextNode extends UniBaseNode {
fxy060608's avatar
fxy060608 已提交
475
    constructor(text: string, container: UniElement | IUniPageNode);
fxy060608's avatar
fxy060608 已提交
476 477 478 479
    get nodeValue(): string;
    set nodeValue(text: string);
}

fxy060608's avatar
fxy060608 已提交
480 481
export declare function updateElementStyle(element: HTMLElement, styles: Partial<CSSStyleDeclaration>): void;

fxy060608's avatar
fxy060608 已提交
482 483
export declare const WEB_INVOKE_APPSERVICE = "WEB_INVOKE_APPSERVICE";

fxy060608's avatar
fxy060608 已提交
484
export { }