import PLATFORM_CONFIGS from './lib/platform-registry'; import mergeConfigs from './lib/merge-configs'; import { DocumentDirection, PlatformConfig, PlatformConfigs, PlatformVersion, SDKInfo } from './lib/interface'; export { mergeConfigs, PLATFORM_CONFIGS }; /** * @class Platform * @description * The Platform service can be used to get information about your current device. * You can get all of the platforms associated with the device using the [platforms](#platforms) * method, including whether the app is being viewed from a mobile/tablet/desktop, if it's * on a mobile device or browser, and the exact System (iOS, Android, Windows etc). * You can also get the orientation of the device, if it uses right-to-left * language direction, and much much more. With this information you can completely * customize your app to fit any device. * * @example * ```ts * import { Platform } from 'tp-platform'; * * const plt = new Platform({}); * ``` */ export declare class Platform { /** @internal */ Css: { transform?: string; transition?: string; transitionDuration?: string; transitionDelay?: string; transitionTimingFn?: string; transitionStart?: string; transitionEnd?: string; transformOrigin?: string; animationDelay?: string; }; /** @internal */ _platforms: string[]; _settings: any; /** * Returns if this app is using right-to-left language direction or not. * We recommend the app's `index.html` file already has the correct `dir` * attribute value set, such as `` or ``. * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir) * @returns {boolean} */ isRTL: boolean; private _win; private _doc; private _versions; private _dir; private _lang; private _ua; private _qp; private _nPlt; private _readyPromise; private _readyResolve; private _readyReject; private _registry; private _core; private _pW; private _pH; private _lW; private _lH; private _isPortrait; private _uiEvtOpts; constructor(platformConfigs: PlatformConfigs); /** * @returns {boolean} returns true/false based on platform. * @description * Depending on the platform the user is on, `is(platformName)` will * return `true` or `false`. Note that the same app can return `true` * for more than one platform name. For example, an app running from * an iPad would return `true` for the platform names: `mobile`, * `ios`, `ipad`, and `tablet`. Additionally, if the app was running * from Cordova then `cordova` would be true, and if it was running * from a web browser on the iPad then `web` would be `true`. * * ``` * import { setupPlatform } from 'tp-platform'; * * const plt = setupPlatform({}); * plt.is('ios'); // true or false * ``` * * | Type | Type Name | Platform Name | Description | * |-------|-------------|-----------------|------------------------------------| * | 0 | Base | core | base application. | * | 1 | Platform | mobile | on a mobile platform. | * | 1 | Platform | tablet | on a tablet platform. | * | 1 | Platform | desktop | on a desktop platform. | * | 2 | System | android | on a device running Android System.| * | 2 | System | ios | on a device running iOS System. | * | 2 | System | linux | on a device running Linux System. | * | 2 | System | windows | on a device running Windows System.| * | 2 | System | mac | on a device running Mac OS. | * | 3 | Brand | ipad | on an iPad device. | * | 3 | Brand | iphone | on an iPhone device. | * | 4 | Environment | cordova | on a hybrid environment(cordova). | * | 4 | Environment | electron | on a hybrid environment(electron). | * | 4 | Environment | web | on an ordinary web browser. | * * @param {string} platformName */ is(platformName: string): boolean; /** * @returns {array} the array of platforms * @description * Depending on what device you are on, `platforms` can return multiple values. * Each possible value is a type of platforms. For example, on an iPhone, * it would return `core`, `mobile`, `ios`, and `iphone`. * * ``` * import { setupPlatform } from 'tp-platform'; * * const plt = setupPlatform({}); * plt.platforms(); // ['core', 'mobile', 'ios', 'iphone']. * ``` */ platforms(): Array; /** * Returns an object containing version information about all of the platforms. * * ``` * import { setupPlatform } from 'tp-platform'; * * const plt = setupPlatform({}); * plt.versions(); // {ios: {str: "10.3.0", num: 10.3, major: 10, minor: 3, patch: 0}}. * ``` * * @returns {object} An object containing all of the platforms and their versions. */ versions(): { [name: string]: PlatformVersion; }; /** * Returns a promise when the platform is ready and native functionality * can be called. If the app is running from within a web browser, then * the promise will resolve when the DOM is ready. When the app is running * from an hybrid application such as Cordova/Electron/Weichat/Alipay, * then the promise will resolve when hybrid application execute the * `triggerReady` function. * * The resolved value is the `readySource`, which states which platform * ready was used. For example, when Cordova is ready, the resolved ready * source is `cordova`. The default ready source value will be `dom`. The * `readySource` is useful if different logic should run depending on the * platform the app is running from. For example, only Cordova can execute * the status bar plugin, so the web should not run status bar plugin logic. * * ``` * import { setupPlatform } from 'tp-platform'; * * const plt = setupPlatform({}); * plt.ready().then(function (readySource) { * switch (readySource) { * case 'dom': * console.log('web env'); * break; * case 'cordova': * console.log('cordova env'); * break; * case 'electron': * console.log('electron env'); * break; * case 'alipay': * console.log('alipay env'); * break; * case 'dingtalk': * console.log('dingtalk env'); * break; * case 'wechat': * console.log('wechat env'); * break; * default: * console.log(readySource + ' not found!'); * } * }, function (reason) { * console.error('ready error', reason) * }); * ``` * @returns {promise} */ ready(): Promise; /** * @hidden * This should be triggered by the engine when the platform is * ready. If there was no custom prepareReady method from the engine, * such as Cordova or Electron, then it uses the default DOM ready. */ triggerReady(readySource: string): void; triggerFail(reason: string): void; /** * @hidden * This is the default prepareReady if it's not replaced by an hybrid app, * such as Cordova or Electron. If there was no custom prepareReady * method from an engine then it uses the method below, which triggers * the platform ready on the DOM ready event, and the default resolved * value is `dom`. */ prepareReady(): void; /** * Set the app's language direction, which will update the `dir` attribute * on the app's root `` element. We recommend the app's `index.html` * file already has the correct `dir` attribute value set, such as * `` or ``. This method is useful if the * direction needs to be dynamically changed per user/session. * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir) * @param {DocumentDirection} dir Examples: `rtl`, `ltr` * @param {boolean} updateDocument */ setDir(dir: DocumentDirection, updateDocument: boolean): void; /** * Returns app's language direction. * We recommend the app's `index.html` file already has the correct `dir` * attribute value set, such as `` or ``. * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir) * @returns {DocumentDirection} */ dir(): DocumentDirection; /** * Set the app's language and optionally the country code, which will update * the `lang` attribute on the app's root `` element. * We recommend the app's `index.html` file already has the correct `lang` * attribute value set, such as ``. This method is useful if * the language needs to be dynamically changed per user/session. * [W3C: Declaring language in HTML](http://www.w3.org/International/questions/qa-html-language-declarations) * @param {string} language Examples: `en-US`, `en-GB`, `ar`, `de`, `zh`, `es-MX` * @param {boolean} updateDocument Specifies whether the `lang` attribute of `` should be updated */ setLang(language: string, updateDocument: boolean): void; /** * Returns app's language and optional country code. * We recommend the app's `index.html` file already has the correct `lang` * attribute value set, such as ``. * [W3C: Declaring language in HTML](http://www.w3.org/International/questions/qa-html-language-declarations) * @returns {string} */ lang(): string; /** * @hidden */ win(): Window; /** * @hidden */ setWindow(win: Window): void; /** * @hidden */ doc(): HTMLDocument; /** * @hidden */ setDocument(doc: HTMLDocument): void; /** * @hidden */ setCssProps(docElement: HTMLElement): void; /** * Get the final configuration for the matching platform. */ settings(): any; /** * @hidden */ userAgent(): string; /** * @hidden */ setUserAgent(userAgent: string): void; /** * @hidden */ setQueryParams(url: string): void; /** * Get the query string parameter */ getQueryParam(key: string): any; /** * 获取带有私有前缀的url参数对象 * @private */ getQueryData(): any; /** * Get the current url. */ url(): string; /** * @hidden */ navigatorPlatform(): string; /** * @hidden */ setNavigatorPlatform(navigatorPlt: string): void; /** * Gets the width of the platform's viewport using `window.innerWidth`. * Using this method is preferred since the dimension is a cached value, * which reduces the chance of multiple and expensive DOM reads. */ width(): number; /** * Gets the height of the platform's viewport using `window.innerHeight`. * Using this method is preferred since the dimension is a cached value, * which reduces the chance of multiple and expensive DOM reads. */ height(): number; /** * Returns `true` if the app is in portait mode. */ isPortrait(): boolean; /** * Returns `true` if the app is in landscape mode. */ isLandscape(): boolean; /** * @hidden */ windowLoad(callback: Function): void; /** * @hidden */ setPlatformConfigs(platformConfigs: PlatformConfigs): void; /** * @hidden */ getPlatformConfig(platformName: string): PlatformConfig; /** * @hidden */ registry(): { [name: string]: PlatformConfig; }; /** * @hidden */ setCore(platformName: string): void; /** * @hidden * separate by ';' * @example core;ios;iphone -> ios */ testQuery(queryValue: string, queryTestValue: string): boolean; /** * @hidden */ testNavigatorPlatform(navigatorPlatformExpression: string): boolean; /** * @hidden */ matchUserAgentVersion(userAgentExpression: RegExp): any; testUserAgent(expression: string): boolean; /** * @hidden */ isPlatformMatch(queryStringName: string, userAgentAtLeastHas?: string[], userAgentMustNotHave?: string[]): boolean; /** * @hidden */ loadScript(url: string, cb: Function): void; /** * @hidden */ loadJsSDK(sdkInfo: SDKInfo, successCallback: Function, errorCallback: Function): void; /** * @hidden */ init(): void; private _initEvents(); private _calcDim(); } /** * @name setupPlatform * @description * Setup platform with default platform configs. * * @param {PlatformConfigs} platformConfigs * @return {Platform} */ export declare function setupPlatform(platformConfigs: PlatformConfigs): Platform;