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

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

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

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

fxy060608's avatar
fxy060608 已提交
9 10 11
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 已提交
12

Q
qiang 已提交
13 14 15 16 17 18 19
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 已提交
20 21
export declare const COMPONENT_NAME_PREFIX = "VUni";

fxy060608's avatar
fxy060608 已提交
22 23 24
export declare const COMPONENT_PREFIX: string;

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

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

fxy060608's avatar
fxy060608 已提交
28 29
export declare const DATA_RE: RegExp;

fxy060608's avatar
fxy060608 已提交
30 31 32 33 34
export declare function debounce(fn: Function, delay: number): {
    (this: any): void;
    cancel(): void;
};

fxy060608's avatar
fxy060608 已提交
35 36 37 38 39 40 41 42 43
/**
 * 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 已提交
44
export declare function decodeAttr(name: string): any;
fxy060608's avatar
fxy060608 已提交
45

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

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

fxy060608's avatar
fxy060608 已提交
50 51 52 53 54 55
export declare const defaultRpx2Unit: {
    unit: string;
    unitRatio: number;
    unitPrecision: number;
};

fxy060608's avatar
fxy060608 已提交
56 57 58 59
export declare function encodeAttr(name: string): string;

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

D
DCloud_LXH 已提交
60 61 62 63 64
export declare function formatDateTime({ date, mode }: {
    date?: Date | undefined;
    mode?: string | undefined;
}): string;

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

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

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

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

Q
qiang 已提交
73 74 75 76
declare interface HTMLElementWithDataset extends HTMLElement {
    __uniDataset?: Record<string, any>;
}

Q
qiang 已提交
77
export declare function initCustomDataset(): void;
Q
qiang 已提交
78

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

fxy060608's avatar
fxy060608 已提交
81 82 83 84 85 86
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 已提交
87 88 89 90
export declare function isServiceCustomElement(_tag: string): boolean;

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

fxy060608's avatar
fxy060608 已提交
91 92
export declare interface IUniPageNode {
    pageId: number;
fxy060608's avatar
fxy060608 已提交
93
    pageNode: IUniPageNode | null;
fxy060608's avatar
fxy060608 已提交
94 95
    genId: () => number;
    push: (...args: any[]) => void;
fxy060608's avatar
fxy060608 已提交
96 97 98 99 100 101 102
    onCreate: (thisNode: UniNode, nodeName: string | number) => UniNode;
    onInsertBefore: (thisNode: UniNode, newChild: UniNode, index: number) => UniNode;
    onRemoveChild: (thisNode: UniNode, oldChild: UniNode) => UniNode;
    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 已提交
103 104
}

fxy060608's avatar
fxy060608 已提交
105 106
export declare const NAVBAR_HEIGHT = 44;

fxy060608's avatar
fxy060608 已提交
107 108 109 110 111 112 113 114
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 已提交
115 116
export declare function normalizeDataset(el: Element): any;

fxy060608's avatar
fxy060608 已提交
117 118
export declare function normalizeTarget(el: HTMLElement): {
    id: string;
Q
qiang 已提交
119
    dataset: DOMStringMap & Record<string, any>;
fxy060608's avatar
fxy060608 已提交
120 121 122 123
    offsetTop: number;
    offsetLeft: number;
};

fxy060608's avatar
fxy060608 已提交
124 125
export declare const ON_REACH_BOTTOM_DISTANCE = 50;

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

Q
qiang 已提交
128 129 130 131 132 133
declare interface Options {
    success?: (res: any) => void;
    fail?: (res: any) => void;
    complete?: (res: any) => void;
}

fxy060608's avatar
fxy060608 已提交
134 135 136 137 138 139 140 141 142
/**
 * 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 已提交
143 144 145 146 147
export declare function parseUrl(url: string): {
    path: string;
    query: Record<string, any>;
};

fxy060608's avatar
fxy060608 已提交
148 149 150 151
export declare function passive(passive: boolean): {
    passive: boolean;
};

fxy060608's avatar
fxy060608 已提交
152 153
export declare const PLUS_RE: RegExp;

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

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

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

fxy060608's avatar
fxy060608 已提交
160 161
export declare const RESPONSIVE_MIN_WIDTH = 768;

fxy060608's avatar
fxy060608 已提交
162 163
export declare type Rpx2UnitOptions = typeof defaultRpx2Unit;

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

fxy060608's avatar
fxy060608 已提交
166 167
export declare const SCHEME_RE: RegExp;

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

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

fxy060608's avatar
fxy060608 已提交
173 174 175 176 177 178
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 已提交
179 180 181 182 183 184
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 已提交
185 186
export declare const UNI_SSR_STORE = "store";

fxy060608's avatar
fxy060608 已提交
187 188
export declare const UNI_SSR_TITLE = "title";

fxy060608's avatar
fxy060608 已提交
189 190 191 192
export declare class UniBaseNode extends UniNode {
    attributes: Record<string, unknown>;
    style: UniCSSStyleDeclaration;
    protected _html: string | null;
fxy060608's avatar
fxy060608 已提交
193
    constructor(nodeType: UniNodeType, nodeName: string, container: UniElement | IUniPageNode);
fxy060608's avatar
fxy060608 已提交
194 195 196 197 198 199 200 201 202
    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 已提交
203 204 205 206
    toJSON(opts?: {
        attr?: boolean;
        children?: boolean;
    }): Partial<UniNodeJSON>;
fxy060608's avatar
fxy060608 已提交
207 208 209
}

export declare class UniCommentNode extends UniNode {
fxy060608's avatar
fxy060608 已提交
210 211 212 213 214 215 216 217 218 219
    constructor(text: string, container: UniElement | IUniPageNode);
    toJSON(opts?: {
        attr?: boolean;
    }): {
        t: string;
        i?: undefined;
    } | {
        i: number;
        t: string;
    };
fxy060608's avatar
fxy060608 已提交
220 221 222 223 224 225 226 227 228 229 230
}

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 已提交
231
    toJSON(): UniCSSStyleDeclarationJSON | undefined;
fxy060608's avatar
fxy060608 已提交
232 233 234 235 236 237
}

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 已提交
238
    constructor(nodeName: string, container: UniElement | IUniPageNode);
fxy060608's avatar
fxy060608 已提交
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 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 283
}

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;
}

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

declare class UniEventTarget {
    private _listeners;
    dispatchEvent(evt: UniEvent): boolean;
    addEventListener(type: string, listener: UniEventListener, options?: AddEventListenerOptions): void;
    removeEventListener(type: string, callback: UniEventListener, options?: EventListenerOptions): void;
}

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 已提交
284
    constructor(nodeType: UniNodeType, nodeName: string, container: UniElement | IUniPageNode);
fxy060608's avatar
fxy060608 已提交
285 286 287
    get firstChild(): UniNode | null;
    get lastChild(): UniNode | null;
    get nextSibling(): UniNode | null;
fxy060608's avatar
fxy060608 已提交
288 289
    get nodeValue(): string | null;
    set nodeValue(_val: string | null);
fxy060608's avatar
fxy060608 已提交
290 291 292 293
    get textContent(): string;
    set textContent(text: string);
    get parentElement(): UniElement | null;
    get previousSibling(): UniNode | null;
fxy060608's avatar
fxy060608 已提交
294
    appendChild(newChild: UniNode): UniNode;
fxy060608's avatar
fxy060608 已提交
295
    cloneNode(deep?: boolean): UniNode;
fxy060608's avatar
fxy060608 已提交
296 297
    insertBefore(newChild: UniNode, refChild: UniNode | null): UniNode;
    removeChild(oldChild: UniNode): UniNode;
fxy060608's avatar
fxy060608 已提交
298 299 300 301 302 303 304 305 306 307
}

export declare interface UniNodeJSON {
    /**
     * nodeId
     */
    i: number;
    /**
     * nodeName
     */
fxy060608's avatar
fxy060608 已提交
308
    n: string | number;
fxy060608's avatar
fxy060608 已提交
309 310 311 312 313 314 315
    /**
     * attributes
     */
    a: Record<string, unknown>;
    /**
     * style
     */
fxy060608's avatar
fxy060608 已提交
316
    s?: UniCSSStyleDeclarationJSON;
fxy060608's avatar
fxy060608 已提交
317 318 319 320 321 322 323 324 325 326 327 328
    /**
     * 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 已提交
329
    constructor(text: string, container: UniElement | IUniPageNode);
fxy060608's avatar
fxy060608 已提交
330 331 332 333
    get nodeValue(): string;
    set nodeValue(text: string);
}

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

fxy060608's avatar
fxy060608 已提交
336 337
export declare const WEB_INVOKE_APPSERVICE = "WEB_INVOKE_APPSERVICE";

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