import IPostMessage from '../IPostMessage'; import Cache from './Cache/Cache'; import AppendFlagController from './Flags/AppendFlagController'; import IFlags from './Flags/IFlags'; import { IAddFont } from './IAddFont'; import ISaveFile from './ISaveFile'; import ILoadFile from './LoadFile/ILoadFile'; import { ITypes } from './Types'; type FlagControllers = { append: AppendFlagController; }; /** * Web-based applications often require additional assets to function, but downloading them every time is undesirable. The JS Applet SDK offers a wide range of APIs for storing different kinds of assets. * * Generally, there are four types of assets: * - CSS & JavaScript files * - Fonts * - Audio-visual content (image, video, and audio files) * - Arbitrary data (e.g., JSON files, plain text, binary data) * * And the SDK also provides two different APIs: * - `sos.offline` & `sos.offline.cache`: A file system abstraction for caching files that are removed when the applet configuration is changed or the applet is reloaded. This method is usually preferred if the files can be re-downloaded. * - `sos.fileSystem`: Direct access to the file system. All files are stored permanently and are not removed when the applet configuration changes. * * Using the `sos.offline` and `sos.offline.cache` APIs allows you to ship an applet without content, including only basic bootstrapping code, and load the content dynamically. The content will then be available even when the device is offline. * * :::warning * Emulator has certain limitations while handling offline files. [Read more here](https://docs.signageos.io/hc/en-us/articles/4405238997138) * ::: */ export default class Offline { private messagePrefix; private window; private postMessage; static MESSAGE_PREFIX: string; readonly cache: Cache; readonly types: ITypes; readonly loadFile: ILoadFile; readonly flags: IFlags; private readonly flagControllers; private FlagControllers; private LoadFileControllers; /** @internal */ constructor(messagePrefix: string, window: Window, postMessage: IPostMessage); /** * The `addFiles()` method downloads the specified files and stores them locally. * The order in which the files are downloaded and stored is **not** guaranteed. * * CSS and JavaScript files are specific because they must be loaded with an HTML tag. The `sos.offline` API methods download, save, and append the resource to the web page. When adding a file, choose a unique identifier (`uid`) that should not change for the resource. The file will be overwritten if another file is added with the same `uid`. * * @param files Array of files to be downloaded and stored locally. * @returns {Promise>} Resolves when all files are added. * @throws {Error} If the `files` parameter is not an array of objects. * @since 1.0.0 * * @example // {@link https://github.com/signageos/applet-examples/blob/master/examples/content-js-api/offline-resources | Example of Applet that save files and load them in one file} * @example * await sos.offline.addFile([{ * uri: 'https://unpkg.com/normalize.css@8.0.1/normalize.css', * uid: 'normalize.css', * type: sos.offline.types.css, * flags: [sos.offline.flags.append(document.head)], * }, { * uri: 'https://code.jquery.com/jquery-3.7.1.slim.min.js', * uid: 'jquery-3.7.1.slim.min.js', * type: sos.offline.types.javascript, * flags: [sos.offline.flags.append(document.body)], * }]); */ addFiles(files: ISaveFile[]): Promise[]>; /** * Method `addFile()` will allow you to load single resource into applet. If you want to load more resource, use `addFiles()`. * * The order in which the files are downloaded and stored **is** guaranteed. * * @param files Array of files to be downloaded and stored locally. * @returns {Promise} Resolves when all files are added and the files are appended to the document when flags are used. * @throws {Error} If the `files` parameter is not an array of objects * @since 1.0.0 * * @example * const file = { // File that will be loaded into an applet * "uri": "https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js", * "uid": "jquery-2.2.4.min.js", * "type": sos.offline.types.javascript, * "flags": [sos.offline.flags.append(document.body)] * } * * await sos.offline.addFile(file); // And finally load file */ addFilesSync(files: ISaveFile[]): Promise; /** * The `addFile()` method downloads the specified file and stores it locally. * * CSS and JavaScript files are specific because they must be loaded with an HTML tag. The `sos.offline` API methods download, save, and append the resource to the web page. When adding a file, choose a unique identifier (`uid`) that should not change for the resource. The file will be overwritten if another file is added with the same `uid`. * * :::info * The file URL must point to a file. If your URI leads to a redirect (e.g. from http to https), the API will not work. * ::: * * @param file URI of the file to be downloaded. * @param file.uid Unique file identifier is used for later file retrieval, must contain a-z,A-Z,0-9 characters. * @param file.type Type of the file, e.g. 'javascript', 'css', etc. * @param file.headers HTTP headers to be sent with the request for the file. * @param file.flags Additional flags for appending stored files to the DOM or other operations * @returns {Promise} Resolves when the file is added and the file is appended to the document when flags are used. * @throws {Error} If the `file` parameter is not an object. * @throws {Error} If the `file` parameter does not contain a valid parameters. * @since 1.0.0 * * @example * await sos.offline.addFile({ * uri: 'https://code.jquery.com/jquery-3.7.1.slim.min.js', * uid: 'jquery-3.7.1.slim.min.js', * type: sos.offline.types.javascript, * flags: [sos.offline.flags.append(document.body)], * }); */ addFile(file: ISaveFile): Promise; /** * The `addFont()` method downloads the specified file and stores it locally. You should use this method for loading fonts instead of * using `addFile()`, because it also generates appropriate font-face definition. * * @param font.uid Unique file identifier is used for later file retrieval, must contain a-z,A-Z,0-9 and . characters. * @param font.append Reference to HTMLElement where the generated font-face will resist. * @param font.fontFamily Font family that can be referenced from your CSS. * @param font.formats URI where these formats will be downloaded from. * @param font.fontStretch Allows you to make text wider or narrower. * @param font.fontStyle Specifies the font style for a text. (Either `normal`, `italic`, `oblique`, `initial` or `inherit`) * @param font.fontWeight Sets how thick or thin characters in text should be displayed * @param font.unicodeRange Defines the range of Unicode characters the font supports, default value is "U+0-10FFFF" * @param font.formats Dictionary of supported formats with its files * @throws {Error} If the `font` parameter is not an object. * @returns {Promise} Resolves when the font is added and the style element is appended to the document. * @since 2.0.0 * * @example // {@link https://github.com/signageos/applet-examples/tree/master/examples/content-js-api/fonts | Example of Applet that loads custom font} */ addFont(font: IAddFont): Promise; private handleFileFlag; private getMessagePrefix; } export {};