Skip to content

Instantly share code, notes, and snippets.

@Munter
Created January 17, 2019 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Munter/06b6eb424867f2e333f20d93550fb3c7 to your computer and use it in GitHub Desktop.
Save Munter/06b6eb424867f2e333f20d93550fb3c7 to your computer and use it in GitHub Desktop.
/**
* A graph model of a website, consisting of [Assets]{@link Asset} (edges) and [Relations]{@link Relation}.
*
*
* @extends EventEmitter
*/
declare class AssetGraph extends EventEmitter {
constructor(options: {
root?: string;
canonicalRoot?: string;
});
/**
* The absolute root url of the graph, always includes a trailing
* slash. A normalized version of the `root` option provided to
* the constructor.
*
* @member {String} AssetGraph#root
*/
root: string;
/**
* The absolute root url of the graph if it was deployed on its production domain.
*
* Some URLs must be canonical and point to the domain as well,
* which poses some problems when populating a dependency graph from disc.
* Canonical URLs will be treated as cross origin if `canonicalRoot` is not set.
*
* When `canonicalUrl` is set, any encounter of a relation to an asset with a canonical URL
* will be assumed to also exist on disc at the corresponding AssetGraph.root relative URL,
* and thus loaded from there.
*
* Setting a [Relation]{@link Relation} to have `relation.canonical = true` will cause
* the relations `href` to be absolute and prepended with the graphs `canonicalRoot`
*
* @member {String} AssetGraph#canonicalRoot
*/
canonicalRoot: string;
/**
* Emit a warning event on the event bus.
*
* Warnings events are emitted when AssetGraph encounters an error
* during it's lifecycle, which doesn't stop it dead in its track.
*
* Warning events are usually errors on a website that you want to fix,
* since the model might not correspond to your mental model i they go
* unfixed.
*
* If no event listeners are intercepting warning events, they will escalate to throw.
*
* @param {String | Error} messageOrError The message or error to emit
*/
warn(messageOrError: string | Error): void;
/**
* Emit a info event on the event bus.
*
* Info events are helpful hints informing of encounters
* of possible problems, where an automated fix has been applied
* and everything has been handled
*
* @param {String | Error} messageOrError The message or error to emit
*/
info(messageOrError: string | Error): void;
/**
* Add an asset to the graph.
*
* @param {Asset|String|AssetConfig} assetConfig The Asset, Url or AssetConfig to construct an Asset from
* @return {Asset} The assets instance that was added
*/
addAsset(assetConfig: Asset | string | AssetConfig): Asset;
/**
* Add assets to the graph.
*
* @param {...(Asset[]|String|String[]|AssetConfig|AssetConfig[])} assetConfigs The asset specs to add
* @return {Asset[]} The assets instances that were added
*/
addAssets(...assetConfigs: (Asset[] | string | string[] | AssetConfig | AssetConfig[])[]): Asset[];
/**
* Remove an asset from the graph. Also removes the incoming and
* outgoing relations of the asset.
*
* @param {Asset} asset The asset to remove.
* @return {AssetGraph} The AssetGraph instance (chaining-friendly).
*/
removeAsset(asset: Asset): AssetGraph;
/**
* Query assets in the graph.
*
* Example usage:
*
* const allAssetsInGraph = ag.findAssets();
*
* const htmlAssets = ag.findAssets({type: 'Html'});
*
* const localImageAssets = ag.findAssets({
* url: { protocol: 'file:', extension: { $regex: /^(?:png|gif|jpg)$/ }
* });
*
* const orphanedJavaScriptAssets = ag.findAssets(function (asset) {
* return asset.type === 'JavaScript' &&
* ag.findRelations({to: asset}).length === 0;
* });
*
* const textBasedAssetsOnGoogleCom = ag.findAssets({
* isText: true,
* url: {$regex: /^https?:\/\/(?:www\.)google\.com\//}
* });
*
* @param {Object} [queryObj={}] Query to match assets against. Will match all assets if not provided.
* @return {Asset[]} The found assets.
*/
findAssets(queryObj?: any): Asset[];
/**
* Query relations in the graph.
*
* Example usage:
*
* const allRelationsInGraph = ag.findRelations();
*
* const allHtmlScriptRelations = ag.findRelations({
* type: 'HtmlScript'
* });
*
* const htmlAnchorsPointingAtLocalImages = ag.findRelations({
* type: 'HtmlAnchor',
* to: {isImage: true, url: {$regex: /^file:/}}
* });
*
* @param {Object} [queryObj={}] Query to match Relations against. Will match all relations if not provided.
* @return {Relation[]} The found relations.
*/
findRelations(queryObj?: any): Relation[];
/**
* Register a new [Asset]{@link Asset} type in AssetGraph
*
* @static
* @param {Function} Constructor An Asset constructor
* @param {String} type a unique type for the asset
*/
static registerAsset(Constructor: (...params: any[]) => any, type: string): void;
/**
* Register a new [Relation]{@link Relation} type in AssetGraph
*
* @static
* @param {Function | String} fileNameOrConstructor A Relation constructor or a file name that exports one
* @param {String} type A unique type for the relation
*/
static registerRelation(fileNameOrConstructor: ((...params: any[]) => any) | string, type: string): void;
}
/**
* Configuration object used to construct Assets in all places where an asset is automatically
* constructed. For example in [AssetGraph.addAsset]{@link AssetGraph#addAsset}
* or in the `to`-property in [Asset.addRelation]{@link Asset#addRelation}
*
*
* @typedef {Object} AssetConfig
*
* @property {String} [type] The Assets type. Will be inferred if missing
*
* @property {Buffer} [rawSrc] `Buffer` object containing the raw source of the asset
*
* @property {String} [contentType] The Content-Type (MIME type) of the asset. For
* subclasses of Asset there will be a reasonable default.
*
* @property {String} [url] The fully qualified (absolute) url of the asset.
* If not provided, the asset will be considered inline. This property takes precedence
* over all other url parts in the configuration
*
* @property {String} [fileName]
* @property {String} [baseName]
* @property {String} [extension]
* @property {String} [protocol]
* @property {String} [username]
* @property {String} [password]
* @property {String} [hostname]
* @property {Number} [port]
* @property {String} [path]
*/
declare type AssetConfig = {
type?: string;
rawSrc?: Buffer;
contentType?: string;
url?: string;
fileName?: string;
baseName?: string;
extension?: string;
protocol?: string;
username?: string;
password?: string;
hostname?: string;
port?: number;
path?: string;
};
/**
* An asset object represents a single node in an AssetGraph, but can
* be used and manipulated on its own outside the graph context.
*/
declare class Asset {
constructor(config: AssetConfig, assetGraph: AssetGraph);
/**
* The assets defined or inferred type
*
* @type {String}
*/
type: string;
/**
* The default extension for the asset type, prepended with a dot, eg. `.html`, `.js` or `.png`
*
* @type {String}
*/
defaultExtension: string;
/**
* Some asset classes support inspection and manipulation using a high
* level interface. If you modify the parse tree, you have to call
* `asset.markDirty()` so any cached serializations of the asset are
* invalidated.
*
* These are the formats you'll get:
*
* `Html` and `Xml`:
* jsdom document object (https://github.com/tmpvar/jsdom).
*
* `Css`
* CSSOM CSSStyleSheet object (https://github.com/NV/CSSOM).
*
* `JavaScript`
* Esprima AST object (http://esprima.org/).
*
* `Json`
* Regular JavaScript object (the result of JSON.parse on the decoded source).
*
* `CacheManifest`
* A JavaScript object with a key for each section present in the
* manifest (`CACHE`, `NETWORK`, `REMOTE`). The value is an array with
* an item for each entry in the section. Refer to the source for
* details.
*
* @member {Oject} Asset#parseTree
*/
parseTree: Oject;
/**
* Load the Asset
*
* Returns a promise that is resolved when the asset is loaded.
* This is Asset's only async method, as soon as it is
* loaded, everything can happen synchronously.
*
* Usually you'll want to use `transforms.loadAssets`, which will
* handle this automatically.
*
* @async
* @return {Promise<Asset>} The loaded Asset
*/
load(): Promise<Asset>;
/**
* The loaded state of the Asset
*
* @type {Boolean}
*/
isLoaded: boolean;
/**
* Get the first non-inline ancestor asset by following the
* incoming relations, ie. the first asset that has a
* url. Returns the asset itself if it's not inline, and null if
* the asset is inline, but not in an AssetGraph.
*
* @type {?Asset}
*/
nonInlineAncestor: Asset;
/**
* The file name extension for the asset (String). It is
* automatically kept in sync with the url, but preserved if the
* asset is inlined or set to a value that ends with a slash.
*
* If updated, the url of the asset will also be updated.
*
* The extension includes the leading dot and is thus kept in the
* same format as `require('path').extname` and the `basename`
* command line utility use.
*
* @type {String}
*/
extension: string;
/**
* The file name for the asset. It is automatically kept
* in sync with the url, but preserved if the asset is inlined or
* set to a value that ends with a slash.
*
* If updated, the url of the asset will also be updated.
*
* @type {String}
*/
fileName: string;
/**
* The file name for the asset, excluding the extension. It is automatically
* kept in sync with the url, but preserved if the asset is inlined or
* set to a value that ends with a slash.
*
* If updated, the url of the asset will also be updated.
*
* @type {String}
*/
baseName: string;
/**
* The path of the asset relative to the AssetGraph root.
* Corresponds to a `new URL(...).pathName`
*
* If updated, the url of the asset will also be updated.
*
* @type {String}
*/
path: string;
/**
* The origin of the asset, `protocol://host`
* Corresponds to `new URL(...).origin`
*
* For inlined assets, this will contain the origin
* of the first non-inlined ancestor
*
* @type {String}
*/
origin: string;
/**
* Get or set the raw source of the asset.
*
* If the internal state has been changed since the asset was
* initialized, it will automatically be reserialized when this
* property is retrieved.
*
* @example
* const htmlAsset = new AssetGraph().addAsset({
* type: 'Html',
* rawSrc: new Buffer('<html><body>Hello!</body></html>')
* });
* htmlAsset.parseTree.body.innerHTML = "Bye!";
* htmlAsset.markDirty();
* htmlAsset.rawSrc.toString(); // "<html><body>Bye!</body></html>"
*
* @type {Buffer}
*/
rawSrc: Buffer;
/**
* The `data:`-url of the asset for inlining
*
* @type {String}
*/
dataUrl: string;
/**
* Get the last known byt length of the Asset
*
* Doesn't force a serialization of the asset if a value has previously been recorded.
*
* @type {Number}
*/
lastKnownByteLength: number;
/**
* Externalize an inlined Asset.
*
* This will create an URL from as many available URL parts as possible and
* auto generate the rest, then assign the URL to the Asset
*/
externalize(): void;
/**
* Unload the asset body. If the asset is in a graph, also
* remove the relations from the graph along with any inline
* assets.
* Also used internally to clean up before overwriting
* .rawSrc or .text.
*/
unload(): void;
/**
* Get the current md5 hex of the asset.
*
* @type {String}
*/
md5Hex: string;
/**
* Get or set the absolute url of the asset.
*
* The url will use the `file:` schema if loaded from disc. Will be
* falsy for inline assets.
*
* @type {String}
*/
url: string;
/**
* Determine whether the asset is inline (shorthand for checking
* whether it has a url).
*
* @type {Boolean}
*/
isInline: boolean;
/**
* Sets the `dirty` flag of the asset, which is the way to say
* that the asset has been manipulated since it was first loaded
* (read from disc or loaded via http). For inline assets the flag
* is set if the asset has been manipulated since it was last
* synchronized with (copied into) its containing asset.
*
* For assets that support a `text` or `parseTree` property, calling
* `markDirty()` will invalidate any cached serializations of the
* asset.
*
* @return {Asset} The asset itself (chaining-friendly)
*/
markDirty(): Asset;
/**
* Get/set the outgoing relations of the asset.
*
* @type {Relation[]}
*/
outgoingRelations: Relation[];
/**
* Attaches a Relation to the Asset.
*
* The ordering of certain relation types is significant
* (`HtmlScript`, for instance), so it's important that the order
* isn't scrambled in the indices. Therefore the caller must
* explicitly specify a position at which to insert the object.
*
* @param {Relation} relation The Relation to attach to the Asset
* @param {String} [position='last'] `"first"`, `"last"`, `"before"`, or `"after"`
* @param {Relation} [adjacentRelation] The adjacent relation, mandatory if the position is `"before"` or `"after"`
*/
addRelation(relation: Relation, position?: string, adjacentRelation?: Relation): void;
/**
* Remove an outgoing Relation from the Asset by reference
*
* @param {Relation} relation Outgoing Relation
* @return {Asset} The Asset itself
*/
removeRelation(relation: Relation): Asset;
/**
* The subset of outgoing Relations that point to external (non-inlined) Assets
*
* @type {Relation[]}
*/
externalRelations: Relation[];
/**
* Parse the Asset for outgoing relations and return them.
*
* @return {Relation[]} The Assets outgoing Relations
*/
findOutgoingRelationsInParseTree(): Relation[];
/**
* Get/set the relations pointing to this asset
*
* **Caveat**: Setting Does not remove/detach other relations already pointing at the
* asset, but not included in the array, so it's not strictly symmetric
* with the incomingRelations getter.
*
* @type {Relation[]}
*/
incomingRelations: Relation[];
/**
* The query parameters part of the Assets URL.
*
* Can be set with a `String` or `Object`, but always returns `String` in the getters
*
* @type {String}
*/
query: string;
/**
* The username part of a URL `protocol://<username>:password@hostname:port/`
*
* @member {String} Asset#username
*/
username: string;
/**
* The password part of a URL `protocol://username:<password>@hostname:port/`
*
* @member {String} Asset#password
*/
password: string;
/**
* The hostname part of a URL `protocol://username:password@<hostname>:port/`
*
* @member {String} Asset#hostname
*/
hostname: string;
/**
* The port part of a URL `protocol://username:password@hostname:<port>/`
*
* @member {Number} Asset#port
*/
port: number;
/**
* The protocol part of a URL `<protocol:>//username:password@hostname:port/`.
* Includes trailing `:`
*
* @member {String} Asset#protocol
*/
protocol: string;
/**
* Go through the outgoing relations of the asset and add the ones
* that refer to assets that are already part of the
* graph. Recurses into inline assets.
*
* You shouldn't need to call this manually.
*/
populate(): void;
/**
* Replace the asset in the graph with another asset, then remove
* it from the graph.
*
* Updates the incoming relations of the old asset to point at the
* new one and preserves the url of the old asset if it's not
* inline.
*
* @param {Asset} newAsset The asset to put replace this one with.
* @return {Asset} The new asset.
*/
replaceWith(newAsset: Asset): Asset;
/**
* Clone this asset instance and add the clone to the graph if
* this instance is part of a graph. As an extra service,
* optionally update some caller-specified relations to point at
* the clone.
*
* If this instance isn't inline, a url is made up for the clone.
*
* @param {Relation[]|Relation} incomingRelations (optional) Some incoming relations that should be pointed at the clone.
* @return {Asset} The cloned asset.
*/
clone(incomingRelations: Relation[] | Relation): Asset;
/**
* Get a brief text containing the type, id, and url (if not inline) of the asset.
*
* @return {String} The string, eg. "[JavaScript/141 file:///the/thing.js]"
*/
toString(): string;
/**
* A Human readable URL or Asset description if inline.
* Paths for `file://` URL's are kept relative to the current
* working directory for easier copy/paste if needed.
*
* @type {String}
*/
urlOrDescription: string;
/**
* Boolean Property that's true for all Asset instances. Avoids
* reliance on the `instanceof` operator.
*
* @constant
* @type {Boolean}
* @memberOf Asset#
* @default true
*/
readonly isAsset: boolean;
/**
* Whether the asset occurs in a context where it can be
* made external. If false, the asset will stay inline. Useful for
* "always inline" assets pointed to by {@link HtmlConditionalComment},
* {@link HtmlDataBindAttribute}, and {@link HtmlKnockoutContainerless}
* relations. Override when creating the asset.
*
* @type {Boolean}
* @memberOf Asset#
* @default true
*/
isExternalizable: boolean;
/**
* The Content-Type (MIME type) of the asset.
*
* @type {String}
* @memberOf Asset#
* @default 'appliction/octet-stream'
*/
contentType: string;
}
/**
* Adds text encoding and decoding support to {@link Asset}. Serves as a
* superclass for {@link Html}, {@link Xml}, {@link Css}, {@link JavaScript},
* {@link Json}, and {@link CacheManifest}.
*
* In addition to the [config]{@link AssetConfig} already supported by the Asset base
* class, the options `text` and `encoding` are also available
*
* @example
* var textAsset = new Text({
* // "æøå" in iso-8859-1:
* rawSrc: Buffer.from([0xe6, 0xf8, 0xe5]),
* encoding: "iso-8859-1"
* });
* textAsset.text; // "æøå" (decoded JavaScript string)
* textAsset.encoding = 'utf-8';
* textAsset.rawSrc; // <Buffer c3 a6 c3 b8 c3 a5>
*
* @class Text
* @extends Asset
* @param {AssetConfig} config The Text assets configuration
*
* @param {String} [config.text] The decoded source of the asset. Can be used
* instead of `rawSrc` and `rawSrcProxy`.
*
* @param {String} [config.encoding="utf-8"] Used to decode and reencode the {@link Asset#rawSrc}.
* Can be any encoding supported by the `iconv` module. Can be changed later
* using {@link Text#encoding}. See the docs for {@link Text#defaultEncoding}.
* If the asset is loaded via http, the encoding will be read from the `Content-Type`,
* and likewise for `data:` urls.
*
* @param {AssetGraph} assetGraph Mandatory AssetGraph instance references
*/
declare class Text extends Asset {
constructor(config: {
text?: string;
encoding?: string;
}, assetGraph: AssetGraph);
/**
* Get or set the encoding (charset) used for re-encoding the raw
* source of the asset. To affect the initial decoding of the
* `rawSrc` option, provide the `encoding` option to the
* constructor.
*
* @type {String}
*/
encoding: string;
/**
* Get or set the decoded text contents of the of the asset as a
* JavaScript string. Unlike browsers AssetGraph doesn't try to
* sniff the charset of your text-based assets. It will fall back
* to assuming utf-8 if it's unable to determine the
* encoding/charset from HTTP headers, `<meta
* http-equiv='Content-Type'>` tags ({@link Html}), `@charset` ({@link Css}), so
* if for some reason you're not using utf-8 for all your
* text-based assets, make sure to provide those hints. Other
* asset types provide no standard way to specify the charset
* within the file itself, so presently there's no way to load
* eg. JavaScript from disc if it's not utf-8 or ASCII, except by
* overriding `Text.prototype.defaultEncoding` globally.
*
* If the internal state has been changed since the asset was
* initialized, it will automatically be reserialized when the
* `text` property is retrieved, for example:
*
* var htmlAsset = new Html({
* rawSrc: Buffer.from("<body>hello</body>");
* });
* htmlAsset.text; // "<body>hello</body>"
* htmlAsset.parseTree.body.innerHTML = "bye";
* htmlAsset.markDirty();
* htmlAsset.text; // "<body>bye</body>"
*
* Setting this property after the outgoing relations have been
* accessed currently leads to undefined behavior.
*
* @type {String}
*/
text: string;
/**
* Property that's true for all Text instances. Avoids reliance on
* the `instanceof` operator.
*
* @member Text#isText
* @type {Boolean}
* @default true
*/
isText: boolean;
/**
* The default encoding for the Text (sub)class. Used for decoding
* the raw source when the encoding cannot be determined by other
* means, such as a `Content-Type` header (when the asset was
* fetched via http), or another indicator specific to the given
* asset type (`@charset` for Css, `<meta
* http-equiv="Content-Type" ...>` for Html).
*
* Factory setting is "utf-8", but you can override it by setting
* `Text.prototype.defaultEncoding` to another value supported by
* the `iconv` of `iconv-lite` modules.
*
* @member Text#defaultEncoding
* @type {String}
* @default "utf-8"
*/
defaultEncoding: string;
/**
* The assets defined or inferred type
*
* @type {String}
*/
type: string;
/**
* The default extension for the asset type, prepended with a dot, eg. `.html`, `.js` or `.png`
*
* @type {String}
*/
defaultExtension: string;
/**
* Some asset classes support inspection and manipulation using a high
* level interface. If you modify the parse tree, you have to call
* `asset.markDirty()` so any cached serializations of the asset are
* invalidated.
*
* These are the formats you'll get:
*
* `Html` and `Xml`:
* jsdom document object (https://github.com/tmpvar/jsdom).
*
* `Css`
* CSSOM CSSStyleSheet object (https://github.com/NV/CSSOM).
*
* `JavaScript`
* Esprima AST object (http://esprima.org/).
*
* `Json`
* Regular JavaScript object (the result of JSON.parse on the decoded source).
*
* `CacheManifest`
* A JavaScript object with a key for each section present in the
* manifest (`CACHE`, `NETWORK`, `REMOTE`). The value is an array with
* an item for each entry in the section. Refer to the source for
* details.
*
* @member {Oject} Asset#parseTree
*/
parseTree: Oject;
/**
* Load the Asset
*
* Returns a promise that is resolved when the asset is loaded.
* This is Asset's only async method, as soon as it is
* loaded, everything can happen synchronously.
*
* Usually you'll want to use `transforms.loadAssets`, which will
* handle this automatically.
*
* @async
* @return {Promise<Asset>} The loaded Asset
*/
load(): Promise<Asset>;
/**
* The loaded state of the Asset
*
* @type {Boolean}
*/
isLoaded: boolean;
/**
* Get the first non-inline ancestor asset by following the
* incoming relations, ie. the first asset that has a
* url. Returns the asset itself if it's not inline, and null if
* the asset is inline, but not in an AssetGraph.
*
* @type {?Asset}
*/
nonInlineAncestor: Asset;
/**
* The file name extension for the asset (String). It is
* automatically kept in sync with the url, but preserved if the
* asset is inlined or set to a value that ends with a slash.
*
* If updated, the url of the asset will also be updated.
*
* The extension includes the leading dot and is thus kept in the
* same format as `require('path').extname` and the `basename`
* command line utility use.
*
* @type {String}
*/
extension: string;
/**
* The file name for the asset. It is automatically kept
* in sync with the url, but preserved if the asset is inlined or
* set to a value that ends with a slash.
*
* If updated, the url of the asset will also be updated.
*
* @type {String}
*/
fileName: string;
/**
* The file name for the asset, excluding the extension. It is automatically
* kept in sync with the url, but preserved if the asset is inlined or
* set to a value that ends with a slash.
*
* If updated, the url of the asset will also be updated.
*
* @type {String}
*/
baseName: string;
/**
* The path of the asset relative to the AssetGraph root.
* Corresponds to a `new URL(...).pathName`
*
* If updated, the url of the asset will also be updated.
*
* @type {String}
*/
path: string;
/**
* The origin of the asset, `protocol://host`
* Corresponds to `new URL(...).origin`
*
* For inlined assets, this will contain the origin
* of the first non-inlined ancestor
*
* @type {String}
*/
origin: string;
/**
* Get or set the raw source of the asset.
*
* If the internal state has been changed since the asset was
* initialized, it will automatically be reserialized when this
* property is retrieved.
*
* @example
* const htmlAsset = new AssetGraph().addAsset({
* type: 'Html',
* rawSrc: new Buffer('<html><body>Hello!</body></html>')
* });
* htmlAsset.parseTree.body.innerHTML = "Bye!";
* htmlAsset.markDirty();
* htmlAsset.rawSrc.toString(); // "<html><body>Bye!</body></html>"
*
* @type {Buffer}
*/
rawSrc: Buffer;
/**
* The `data:`-url of the asset for inlining
*
* @type {String}
*/
dataUrl: string;
/**
* Get the last known byt length of the Asset
*
* Doesn't force a serialization of the asset if a value has previously been recorded.
*
* @type {Number}
*/
lastKnownByteLength: number;
/**
* Externalize an inlined Asset.
*
* This will create an URL from as many available URL parts as possible and
* auto generate the rest, then assign the URL to the Asset
*/
externalize(): void;
/**
* Unload the asset body. If the asset is in a graph, also
* remove the relations from the graph along with any inline
* assets.
* Also used internally to clean up before overwriting
* .rawSrc or .text.
*/
unload(): void;
/**
* Get the current md5 hex of the asset.
*
* @type {String}
*/
md5Hex: string;
/**
* Get or set the absolute url of the asset.
*
* The url will use the `file:` schema if loaded from disc. Will be
* falsy for inline assets.
*
* @type {String}
*/
url: string;
/**
* Determine whether the asset is inline (shorthand for checking
* whether it has a url).
*
* @type {Boolean}
*/
isInline: boolean;
/**
* Sets the `dirty` flag of the asset, which is the way to say
* that the asset has been manipulated since it was first loaded
* (read from disc or loaded via http). For inline assets the flag
* is set if the asset has been manipulated since it was last
* synchronized with (copied into) its containing asset.
*
* For assets that support a `text` or `parseTree` property, calling
* `markDirty()` will invalidate any cached serializations of the
* asset.
*
* @return {Asset} The asset itself (chaining-friendly)
*/
markDirty(): Asset;
/**
* Get/set the outgoing relations of the asset.
*
* @type {Relation[]}
*/
outgoingRelations: Relation[];
/**
* Attaches a Relation to the Asset.
*
* The ordering of certain relation types is significant
* (`HtmlScript`, for instance), so it's important that the order
* isn't scrambled in the indices. Therefore the caller must
* explicitly specify a position at which to insert the object.
*
* @param {Relation} relation The Relation to attach to the Asset
* @param {String} [position='last'] `"first"`, `"last"`, `"before"`, or `"after"`
* @param {Relation} [adjacentRelation] The adjacent relation, mandatory if the position is `"before"` or `"after"`
*/
addRelation(relation: Relation, position?: string, adjacentRelation?: Relation): void;
/**
* Remove an outgoing Relation from the Asset by reference
*
* @param {Relation} relation Outgoing Relation
* @return {Asset} The Asset itself
*/
removeRelation(relation: Relation): Asset;
/**
* The subset of outgoing Relations that point to external (non-inlined) Assets
*
* @type {Relation[]}
*/
externalRelations: Relation[];
/**
* Parse the Asset for outgoing relations and return them.
*
* @return {Relation[]} The Assets outgoing Relations
*/
findOutgoingRelationsInParseTree(): Relation[];
/**
* Get/set the relations pointing to this asset
*
* **Caveat**: Setting Does not remove/detach other relations already pointing at the
* asset, but not included in the array, so it's not strictly symmetric
* with the incomingRelations getter.
*
* @type {Relation[]}
*/
incomingRelations: Relation[];
/**
* The query parameters part of the Assets URL.
*
* Can be set with a `String` or `Object`, but always returns `String` in the getters
*
* @type {String}
*/
query: string;
/**
* The username part of a URL `protocol://<username>:password@hostname:port/`
*
* @member {String} Asset#username
*/
username: string;
/**
* The password part of a URL `protocol://username:<password>@hostname:port/`
*
* @member {String} Asset#password
*/
password: string;
/**
* The hostname part of a URL `protocol://username:password@<hostname>:port/`
*
* @member {String} Asset#hostname
*/
hostname: string;
/**
* The port part of a URL `protocol://username:password@hostname:<port>/`
*
* @member {Number} Asset#port
*/
port: number;
/**
* The protocol part of a URL `<protocol:>//username:password@hostname:port/`.
* Includes trailing `:`
*
* @member {String} Asset#protocol
*/
protocol: string;
/**
* Go through the outgoing relations of the asset and add the ones
* that refer to assets that are already part of the
* graph. Recurses into inline assets.
*
* You shouldn't need to call this manually.
*/
populate(): void;
/**
* Replace the asset in the graph with another asset, then remove
* it from the graph.
*
* Updates the incoming relations of the old asset to point at the
* new one and preserves the url of the old asset if it's not
* inline.
*
* @param {Asset} newAsset The asset to put replace this one with.
* @return {Asset} The new asset.
*/
replaceWith(newAsset: Asset): Asset;
/**
* Clone this asset instance and add the clone to the graph if
* this instance is part of a graph. As an extra service,
* optionally update some caller-specified relations to point at
* the clone.
*
* If this instance isn't inline, a url is made up for the clone.
*
* @param {Relation[]|Relation} incomingRelations (optional) Some incoming relations that should be pointed at the clone.
* @return {Asset} The cloned asset.
*/
clone(incomingRelations: Relation[] | Relation): Asset;
/**
* Get a brief text containing the type, id, and url (if not inline) of the asset.
*
* @return {String} The string, eg. "[JavaScript/141 file:///the/thing.js]"
*/
toString(): string;
/**
* A Human readable URL or Asset description if inline.
* Paths for `file://` URL's are kept relative to the current
* working directory for easier copy/paste if needed.
*
* @type {String}
*/
urlOrDescription: string;
/**
* Boolean Property that's true for all Asset instances. Avoids
* reliance on the `instanceof` operator.
*
* @constant
* @type {Boolean}
* @memberOf Asset#
* @default true
*/
readonly isAsset: boolean;
/**
* Whether the asset occurs in a context where it can be
* made external. If false, the asset will stay inline. Useful for
* "always inline" assets pointed to by {@link HtmlConditionalComment},
* {@link HtmlDataBindAttribute}, and {@link HtmlKnockoutContainerless}
* relations. Override when creating the asset.
*
* @type {Boolean}
* @memberOf Asset#
* @default true
*/
isExternalizable: boolean;
/**
* The Content-Type (MIME type) of the asset.
*
* @type {String}
* @memberOf Asset#
* @default 'appliction/octet-stream'
*/
contentType: string;
}
/**
* @extends {HtmlRelation}
*
* Implementation of https://www.w3.org/TR/resource-hints/#dns-prefetch
*/
declare class HtmlDnsPrefetchLink extends HtmlRelation {
/**
* The source asset of the relation.
*
* @member {Asset} Relation#from
*/
from: Asset;
/**
* The target asset of the relation.
*
* @type {Asset}
*/
to: Asset;
/**
* The ATS/DOM-node where the Relation originates in the parent document
*
* @member {Object} Relation#node
*/
node: any;
/**
* Get or set the href of the relation. The relation must be
* attached to an asset.
*
* What is actually retrieved or updated depends on the relation
* type. For `HtmlImage` the `src` attribute of the HTML element
* is changed, for `CssImport` the parsed representation of
* the @import rule is updated, etc.
*
* Most of the time you don't need to think about this property,
* as the href is automatically updated when the url of the source
* or target asset is changed, or an intermediate asset is
* inlined.
*
* @member {String} Relation#href
*/
href: string;
/**
* Get or set the fragment identifier part of the href of the relation.
*
* Setting a fragment with a non-empty value requires the value to begin with `#`
*
* @type {String}
*/
fragment: string;
/**
* Update `href` of a relation to make sure it points at the
* current url of its target asset.
*
* It's not necessary to call this function manually as long as
* the source and target assets of the relation have only been
* moved by having their `url` property changed (the recommended
* way), but some transforms will need this after some low-level
* surgery, such as attaching an existing relation to a different
* asset.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
refreshHref(): Relation;
/**
* Get the relations cross origins status defined as
* differences in protocol or hostname.
*
* This property is quite useful as part of a population
* query to ensure that the graph doesn't expand beyond
* the current host or file system
*
* @type {Boolean}
*/
crossorigin: boolean;
/**
* Get or set the canonical state of a Relation
*
* If [AssetGraph]{@link AssetGraph} has a [`canonicalRoot`]{@link AssetGraph#canonicalRoot}
* property, AssetGraph will detect absolute URLs matching `AssetGraph.canonicalRoot`
* as if they were of [`hrefType`]{@link Relation#hrefType} `rootRelative`.
*
* The getter tell you if [`Relation.href`]{@link Relation#href} will be prepended
* with `Assetgraph.canonicalRoot`.
*
* The setter will change the Relation's `href` to be prefixed with `AssetGraph.canonicalRoot`
* if `true`, and without if `false`
*
* @type {Boolean}
*/
canonical: boolean;
/**
* Get the url of the first non-inlined ancestor of the `from`-Asset
*
* @type {String}
*/
baseUrl: string;
/**
* Either `'absolute'`, `'rootRelative'`, `'protocolRelative'`, `'relative'`, or `'inline'`.
* Decides what "degree" of relative url [`refreshHref()`]{@link Relation#refreshHref} tries to issue, except for
* `'inline'` which means that the target asset is contained in a `data:` url or similar.
*
* @type {String}
*/
hrefType: string;
/**
* Inline the relation. This is only supported by certain relation
* types and will produce different results depending on the type
* (`data:` url, inline script, inline stylesheet...).
*
* Will make a clone of the target asset if it has more incoming
* relations than this one.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
inline(): Relation;
/**
* Attaches the relation to an asset.
*
* The ordering of certain relation types is significant
* (`HtmlScript`, for instance), so it's important that the order
* isn't scrambled in the indices. Therefore the caller must
* explicitly specify a position at which to insert the object.
*
* @param {String} position `"first"`, `"last"`, `"before"`, or `"after"`.
* @param {Relation} adjacentRelation The adjacent relation, mandatory if the position is `"before"` or `"after"`.
* @return {Relation} The relation itself (chaining-friendly).
*/
attach(position: string, adjacentRelation: Relation): Relation;
/**
* Detaches the relation from the asset it is currently attached
* to. If the relation is currently part of a graph, it will
* removed from it.
*
* Detaching implies that the tag/statement/declaration
* representing the relation is physically removed from the
* referring asset. Not all relation types support this.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
detach(): Relation;
/**
* Removes the relation from the graph it's currently part
* of. Doesn't detach the relation (compare with
* [`relation.detach()`]{@link Relation#detach}).
*
* @return {Relation} The relation itself (chaining-friendly).
* @api public
*/
remove(): Relation;
/**
* Get a brief text containing the type, id of the relation. Will
* also contain the `.toString()` of the relation's source and
* target assets if available.
*
* @return {String} The string, eg. `"[HtmlAnchor/141: [Html/40 file:///foo/bar/index.html] => [Html/76 file:///foo/bar/otherpage.html]]"``
*/
toString(): string;
/**
* Property that's true for all relation instances. Avoids
* reliance on the `instanceof` operator.
*
* @constant
* @type {Boolean}
* @memberOf Relation#
*/
readonly isRelation: boolean;
}
/**
* @constructor
* @augments HtmlResourceHint
* Implementation of https://www.w3.org/TR/resource-hints/#preconnect
*/
declare class HtmlPreconnectLink extends HtmlResourceHint {
/**
* The source asset of the relation.
*
* @member {Asset} Relation#from
*/
from: Asset;
/**
* The target asset of the relation.
*
* @type {Asset}
*/
to: Asset;
/**
* The ATS/DOM-node where the Relation originates in the parent document
*
* @member {Object} Relation#node
*/
node: any;
/**
* Get or set the href of the relation. The relation must be
* attached to an asset.
*
* What is actually retrieved or updated depends on the relation
* type. For `HtmlImage` the `src` attribute of the HTML element
* is changed, for `CssImport` the parsed representation of
* the @import rule is updated, etc.
*
* Most of the time you don't need to think about this property,
* as the href is automatically updated when the url of the source
* or target asset is changed, or an intermediate asset is
* inlined.
*
* @member {String} Relation#href
*/
href: string;
/**
* Get or set the fragment identifier part of the href of the relation.
*
* Setting a fragment with a non-empty value requires the value to begin with `#`
*
* @type {String}
*/
fragment: string;
/**
* Update `href` of a relation to make sure it points at the
* current url of its target asset.
*
* It's not necessary to call this function manually as long as
* the source and target assets of the relation have only been
* moved by having their `url` property changed (the recommended
* way), but some transforms will need this after some low-level
* surgery, such as attaching an existing relation to a different
* asset.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
refreshHref(): Relation;
/**
* Get the relations cross origins status defined as
* differences in protocol or hostname.
*
* This property is quite useful as part of a population
* query to ensure that the graph doesn't expand beyond
* the current host or file system
*
* @type {Boolean}
*/
crossorigin: boolean;
/**
* Get or set the canonical state of a Relation
*
* If [AssetGraph]{@link AssetGraph} has a [`canonicalRoot`]{@link AssetGraph#canonicalRoot}
* property, AssetGraph will detect absolute URLs matching `AssetGraph.canonicalRoot`
* as if they were of [`hrefType`]{@link Relation#hrefType} `rootRelative`.
*
* The getter tell you if [`Relation.href`]{@link Relation#href} will be prepended
* with `Assetgraph.canonicalRoot`.
*
* The setter will change the Relation's `href` to be prefixed with `AssetGraph.canonicalRoot`
* if `true`, and without if `false`
*
* @type {Boolean}
*/
canonical: boolean;
/**
* Get the url of the first non-inlined ancestor of the `from`-Asset
*
* @type {String}
*/
baseUrl: string;
/**
* Either `'absolute'`, `'rootRelative'`, `'protocolRelative'`, `'relative'`, or `'inline'`.
* Decides what "degree" of relative url [`refreshHref()`]{@link Relation#refreshHref} tries to issue, except for
* `'inline'` which means that the target asset is contained in a `data:` url or similar.
*
* @type {String}
*/
hrefType: string;
/**
* Inline the relation. This is only supported by certain relation
* types and will produce different results depending on the type
* (`data:` url, inline script, inline stylesheet...).
*
* Will make a clone of the target asset if it has more incoming
* relations than this one.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
inline(): Relation;
/**
* Attaches the relation to an asset.
*
* The ordering of certain relation types is significant
* (`HtmlScript`, for instance), so it's important that the order
* isn't scrambled in the indices. Therefore the caller must
* explicitly specify a position at which to insert the object.
*
* @param {String} position `"first"`, `"last"`, `"before"`, or `"after"`.
* @param {Relation} adjacentRelation The adjacent relation, mandatory if the position is `"before"` or `"after"`.
* @return {Relation} The relation itself (chaining-friendly).
*/
attach(position: string, adjacentRelation: Relation): Relation;
/**
* Detaches the relation from the asset it is currently attached
* to. If the relation is currently part of a graph, it will
* removed from it.
*
* Detaching implies that the tag/statement/declaration
* representing the relation is physically removed from the
* referring asset. Not all relation types support this.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
detach(): Relation;
/**
* Removes the relation from the graph it's currently part
* of. Doesn't detach the relation (compare with
* [`relation.detach()`]{@link Relation#detach}).
*
* @return {Relation} The relation itself (chaining-friendly).
* @api public
*/
remove(): Relation;
/**
* Get a brief text containing the type, id of the relation. Will
* also contain the `.toString()` of the relation's source and
* target assets if available.
*
* @return {String} The string, eg. `"[HtmlAnchor/141: [Html/40 file:///foo/bar/index.html] => [Html/76 file:///foo/bar/otherpage.html]]"``
*/
toString(): string;
/**
* Property that's true for all relation instances. Avoids
* reliance on the `instanceof` operator.
*
* @constant
* @type {Boolean}
* @memberOf Relation#
*/
readonly isRelation: boolean;
}
/**
* @extends {HtmlResourceHint}
*
* Implementation of https://www.w3.org/TR/resource-hints/#prefetch
*/
declare class HtmlPrefetchLink extends HtmlResourceHint {
/**
* The source asset of the relation.
*
* @member {Asset} Relation#from
*/
from: Asset;
/**
* The target asset of the relation.
*
* @type {Asset}
*/
to: Asset;
/**
* The ATS/DOM-node where the Relation originates in the parent document
*
* @member {Object} Relation#node
*/
node: any;
/**
* Get or set the href of the relation. The relation must be
* attached to an asset.
*
* What is actually retrieved or updated depends on the relation
* type. For `HtmlImage` the `src` attribute of the HTML element
* is changed, for `CssImport` the parsed representation of
* the @import rule is updated, etc.
*
* Most of the time you don't need to think about this property,
* as the href is automatically updated when the url of the source
* or target asset is changed, or an intermediate asset is
* inlined.
*
* @member {String} Relation#href
*/
href: string;
/**
* Get or set the fragment identifier part of the href of the relation.
*
* Setting a fragment with a non-empty value requires the value to begin with `#`
*
* @type {String}
*/
fragment: string;
/**
* Update `href` of a relation to make sure it points at the
* current url of its target asset.
*
* It's not necessary to call this function manually as long as
* the source and target assets of the relation have only been
* moved by having their `url` property changed (the recommended
* way), but some transforms will need this after some low-level
* surgery, such as attaching an existing relation to a different
* asset.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
refreshHref(): Relation;
/**
* Get the relations cross origins status defined as
* differences in protocol or hostname.
*
* This property is quite useful as part of a population
* query to ensure that the graph doesn't expand beyond
* the current host or file system
*
* @type {Boolean}
*/
crossorigin: boolean;
/**
* Get or set the canonical state of a Relation
*
* If [AssetGraph]{@link AssetGraph} has a [`canonicalRoot`]{@link AssetGraph#canonicalRoot}
* property, AssetGraph will detect absolute URLs matching `AssetGraph.canonicalRoot`
* as if they were of [`hrefType`]{@link Relation#hrefType} `rootRelative`.
*
* The getter tell you if [`Relation.href`]{@link Relation#href} will be prepended
* with `Assetgraph.canonicalRoot`.
*
* The setter will change the Relation's `href` to be prefixed with `AssetGraph.canonicalRoot`
* if `true`, and without if `false`
*
* @type {Boolean}
*/
canonical: boolean;
/**
* Get the url of the first non-inlined ancestor of the `from`-Asset
*
* @type {String}
*/
baseUrl: string;
/**
* Either `'absolute'`, `'rootRelative'`, `'protocolRelative'`, `'relative'`, or `'inline'`.
* Decides what "degree" of relative url [`refreshHref()`]{@link Relation#refreshHref} tries to issue, except for
* `'inline'` which means that the target asset is contained in a `data:` url or similar.
*
* @type {String}
*/
hrefType: string;
/**
* Inline the relation. This is only supported by certain relation
* types and will produce different results depending on the type
* (`data:` url, inline script, inline stylesheet...).
*
* Will make a clone of the target asset if it has more incoming
* relations than this one.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
inline(): Relation;
/**
* Attaches the relation to an asset.
*
* The ordering of certain relation types is significant
* (`HtmlScript`, for instance), so it's important that the order
* isn't scrambled in the indices. Therefore the caller must
* explicitly specify a position at which to insert the object.
*
* @param {String} position `"first"`, `"last"`, `"before"`, or `"after"`.
* @param {Relation} adjacentRelation The adjacent relation, mandatory if the position is `"before"` or `"after"`.
* @return {Relation} The relation itself (chaining-friendly).
*/
attach(position: string, adjacentRelation: Relation): Relation;
/**
* Detaches the relation from the asset it is currently attached
* to. If the relation is currently part of a graph, it will
* removed from it.
*
* Detaching implies that the tag/statement/declaration
* representing the relation is physically removed from the
* referring asset. Not all relation types support this.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
detach(): Relation;
/**
* Removes the relation from the graph it's currently part
* of. Doesn't detach the relation (compare with
* [`relation.detach()`]{@link Relation#detach}).
*
* @return {Relation} The relation itself (chaining-friendly).
* @api public
*/
remove(): Relation;
/**
* Get a brief text containing the type, id of the relation. Will
* also contain the `.toString()` of the relation's source and
* target assets if available.
*
* @return {String} The string, eg. `"[HtmlAnchor/141: [Html/40 file:///foo/bar/index.html] => [Html/76 file:///foo/bar/otherpage.html]]"``
*/
toString(): string;
/**
* Property that's true for all relation instances. Avoids
* reliance on the `instanceof` operator.
*
* @constant
* @type {Boolean}
* @memberOf Relation#
*/
readonly isRelation: boolean;
}
/**
* @extends {HtmlResourceHint}
*
* Implementation of http://w3c.github.io/preload/#dfn-preload
*/
declare class HtmlPreloadLink extends HtmlResourceHint {
/**
* The source asset of the relation.
*
* @member {Asset} Relation#from
*/
from: Asset;
/**
* The target asset of the relation.
*
* @type {Asset}
*/
to: Asset;
/**
* The ATS/DOM-node where the Relation originates in the parent document
*
* @member {Object} Relation#node
*/
node: any;
/**
* Get or set the href of the relation. The relation must be
* attached to an asset.
*
* What is actually retrieved or updated depends on the relation
* type. For `HtmlImage` the `src` attribute of the HTML element
* is changed, for `CssImport` the parsed representation of
* the @import rule is updated, etc.
*
* Most of the time you don't need to think about this property,
* as the href is automatically updated when the url of the source
* or target asset is changed, or an intermediate asset is
* inlined.
*
* @member {String} Relation#href
*/
href: string;
/**
* Get or set the fragment identifier part of the href of the relation.
*
* Setting a fragment with a non-empty value requires the value to begin with `#`
*
* @type {String}
*/
fragment: string;
/**
* Update `href` of a relation to make sure it points at the
* current url of its target asset.
*
* It's not necessary to call this function manually as long as
* the source and target assets of the relation have only been
* moved by having their `url` property changed (the recommended
* way), but some transforms will need this after some low-level
* surgery, such as attaching an existing relation to a different
* asset.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
refreshHref(): Relation;
/**
* Get the relations cross origins status defined as
* differences in protocol or hostname.
*
* This property is quite useful as part of a population
* query to ensure that the graph doesn't expand beyond
* the current host or file system
*
* @type {Boolean}
*/
crossorigin: boolean;
/**
* Get or set the canonical state of a Relation
*
* If [AssetGraph]{@link AssetGraph} has a [`canonicalRoot`]{@link AssetGraph#canonicalRoot}
* property, AssetGraph will detect absolute URLs matching `AssetGraph.canonicalRoot`
* as if they were of [`hrefType`]{@link Relation#hrefType} `rootRelative`.
*
* The getter tell you if [`Relation.href`]{@link Relation#href} will be prepended
* with `Assetgraph.canonicalRoot`.
*
* The setter will change the Relation's `href` to be prefixed with `AssetGraph.canonicalRoot`
* if `true`, and without if `false`
*
* @type {Boolean}
*/
canonical: boolean;
/**
* Get the url of the first non-inlined ancestor of the `from`-Asset
*
* @type {String}
*/
baseUrl: string;
/**
* Either `'absolute'`, `'rootRelative'`, `'protocolRelative'`, `'relative'`, or `'inline'`.
* Decides what "degree" of relative url [`refreshHref()`]{@link Relation#refreshHref} tries to issue, except for
* `'inline'` which means that the target asset is contained in a `data:` url or similar.
*
* @type {String}
*/
hrefType: string;
/**
* Inline the relation. This is only supported by certain relation
* types and will produce different results depending on the type
* (`data:` url, inline script, inline stylesheet...).
*
* Will make a clone of the target asset if it has more incoming
* relations than this one.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
inline(): Relation;
/**
* Attaches the relation to an asset.
*
* The ordering of certain relation types is significant
* (`HtmlScript`, for instance), so it's important that the order
* isn't scrambled in the indices. Therefore the caller must
* explicitly specify a position at which to insert the object.
*
* @param {String} position `"first"`, `"last"`, `"before"`, or `"after"`.
* @param {Relation} adjacentRelation The adjacent relation, mandatory if the position is `"before"` or `"after"`.
* @return {Relation} The relation itself (chaining-friendly).
*/
attach(position: string, adjacentRelation: Relation): Relation;
/**
* Detaches the relation from the asset it is currently attached
* to. If the relation is currently part of a graph, it will
* removed from it.
*
* Detaching implies that the tag/statement/declaration
* representing the relation is physically removed from the
* referring asset. Not all relation types support this.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
detach(): Relation;
/**
* Removes the relation from the graph it's currently part
* of. Doesn't detach the relation (compare with
* [`relation.detach()`]{@link Relation#detach}).
*
* @return {Relation} The relation itself (chaining-friendly).
* @api public
*/
remove(): Relation;
/**
* Get a brief text containing the type, id of the relation. Will
* also contain the `.toString()` of the relation's source and
* target assets if available.
*
* @return {String} The string, eg. `"[HtmlAnchor/141: [Html/40 file:///foo/bar/index.html] => [Html/76 file:///foo/bar/otherpage.html]]"``
*/
toString(): string;
/**
* Property that's true for all relation instances. Avoids
* reliance on the `instanceof` operator.
*
* @constant
* @type {Boolean}
* @memberOf Relation#
*/
readonly isRelation: boolean;
}
/**
* @extends {HtmlRelation}
*
* Implementation of https://www.w3.org/TR/resource-hints/#prerender
*/
declare class HtmlPrerenderLink extends HtmlRelation {
/**
* The source asset of the relation.
*
* @member {Asset} Relation#from
*/
from: Asset;
/**
* The target asset of the relation.
*
* @type {Asset}
*/
to: Asset;
/**
* The ATS/DOM-node where the Relation originates in the parent document
*
* @member {Object} Relation#node
*/
node: any;
/**
* Get or set the href of the relation. The relation must be
* attached to an asset.
*
* What is actually retrieved or updated depends on the relation
* type. For `HtmlImage` the `src` attribute of the HTML element
* is changed, for `CssImport` the parsed representation of
* the @import rule is updated, etc.
*
* Most of the time you don't need to think about this property,
* as the href is automatically updated when the url of the source
* or target asset is changed, or an intermediate asset is
* inlined.
*
* @member {String} Relation#href
*/
href: string;
/**
* Get or set the fragment identifier part of the href of the relation.
*
* Setting a fragment with a non-empty value requires the value to begin with `#`
*
* @type {String}
*/
fragment: string;
/**
* Update `href` of a relation to make sure it points at the
* current url of its target asset.
*
* It's not necessary to call this function manually as long as
* the source and target assets of the relation have only been
* moved by having their `url` property changed (the recommended
* way), but some transforms will need this after some low-level
* surgery, such as attaching an existing relation to a different
* asset.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
refreshHref(): Relation;
/**
* Get the relations cross origins status defined as
* differences in protocol or hostname.
*
* This property is quite useful as part of a population
* query to ensure that the graph doesn't expand beyond
* the current host or file system
*
* @type {Boolean}
*/
crossorigin: boolean;
/**
* Get or set the canonical state of a Relation
*
* If [AssetGraph]{@link AssetGraph} has a [`canonicalRoot`]{@link AssetGraph#canonicalRoot}
* property, AssetGraph will detect absolute URLs matching `AssetGraph.canonicalRoot`
* as if they were of [`hrefType`]{@link Relation#hrefType} `rootRelative`.
*
* The getter tell you if [`Relation.href`]{@link Relation#href} will be prepended
* with `Assetgraph.canonicalRoot`.
*
* The setter will change the Relation's `href` to be prefixed with `AssetGraph.canonicalRoot`
* if `true`, and without if `false`
*
* @type {Boolean}
*/
canonical: boolean;
/**
* Get the url of the first non-inlined ancestor of the `from`-Asset
*
* @type {String}
*/
baseUrl: string;
/**
* Either `'absolute'`, `'rootRelative'`, `'protocolRelative'`, `'relative'`, or `'inline'`.
* Decides what "degree" of relative url [`refreshHref()`]{@link Relation#refreshHref} tries to issue, except for
* `'inline'` which means that the target asset is contained in a `data:` url or similar.
*
* @type {String}
*/
hrefType: string;
/**
* Inline the relation. This is only supported by certain relation
* types and will produce different results depending on the type
* (`data:` url, inline script, inline stylesheet...).
*
* Will make a clone of the target asset if it has more incoming
* relations than this one.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
inline(): Relation;
/**
* Attaches the relation to an asset.
*
* The ordering of certain relation types is significant
* (`HtmlScript`, for instance), so it's important that the order
* isn't scrambled in the indices. Therefore the caller must
* explicitly specify a position at which to insert the object.
*
* @param {String} position `"first"`, `"last"`, `"before"`, or `"after"`.
* @param {Relation} adjacentRelation The adjacent relation, mandatory if the position is `"before"` or `"after"`.
* @return {Relation} The relation itself (chaining-friendly).
*/
attach(position: string, adjacentRelation: Relation): Relation;
/**
* Detaches the relation from the asset it is currently attached
* to. If the relation is currently part of a graph, it will
* removed from it.
*
* Detaching implies that the tag/statement/declaration
* representing the relation is physically removed from the
* referring asset. Not all relation types support this.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
detach(): Relation;
/**
* Removes the relation from the graph it's currently part
* of. Doesn't detach the relation (compare with
* [`relation.detach()`]{@link Relation#detach}).
*
* @return {Relation} The relation itself (chaining-friendly).
* @api public
*/
remove(): Relation;
/**
* Get a brief text containing the type, id of the relation. Will
* also contain the `.toString()` of the relation's source and
* target assets if available.
*
* @return {String} The string, eg. `"[HtmlAnchor/141: [Html/40 file:///foo/bar/index.html] => [Html/76 file:///foo/bar/otherpage.html]]"``
*/
toString(): string;
/**
* Property that's true for all relation instances. Avoids
* reliance on the `instanceof` operator.
*
* @constant
* @type {Boolean}
* @memberOf Relation#
*/
readonly isRelation: boolean;
}
/**
* Base Relation for all types of HTML Relations
*
* @extends Relation
*/
declare class HtmlRelation extends Relation {
/**
* The source asset of the relation.
*
* @member {Asset} Relation#from
*/
from: Asset;
/**
* The target asset of the relation.
*
* @type {Asset}
*/
to: Asset;
/**
* The ATS/DOM-node where the Relation originates in the parent document
*
* @member {Object} Relation#node
*/
node: any;
/**
* Get or set the href of the relation. The relation must be
* attached to an asset.
*
* What is actually retrieved or updated depends on the relation
* type. For `HtmlImage` the `src` attribute of the HTML element
* is changed, for `CssImport` the parsed representation of
* the @import rule is updated, etc.
*
* Most of the time you don't need to think about this property,
* as the href is automatically updated when the url of the source
* or target asset is changed, or an intermediate asset is
* inlined.
*
* @member {String} Relation#href
*/
href: string;
/**
* Get or set the fragment identifier part of the href of the relation.
*
* Setting a fragment with a non-empty value requires the value to begin with `#`
*
* @type {String}
*/
fragment: string;
/**
* Update `href` of a relation to make sure it points at the
* current url of its target asset.
*
* It's not necessary to call this function manually as long as
* the source and target assets of the relation have only been
* moved by having their `url` property changed (the recommended
* way), but some transforms will need this after some low-level
* surgery, such as attaching an existing relation to a different
* asset.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
refreshHref(): Relation;
/**
* Get the relations cross origins status defined as
* differences in protocol or hostname.
*
* This property is quite useful as part of a population
* query to ensure that the graph doesn't expand beyond
* the current host or file system
*
* @type {Boolean}
*/
crossorigin: boolean;
/**
* Get or set the canonical state of a Relation
*
* If [AssetGraph]{@link AssetGraph} has a [`canonicalRoot`]{@link AssetGraph#canonicalRoot}
* property, AssetGraph will detect absolute URLs matching `AssetGraph.canonicalRoot`
* as if they were of [`hrefType`]{@link Relation#hrefType} `rootRelative`.
*
* The getter tell you if [`Relation.href`]{@link Relation#href} will be prepended
* with `Assetgraph.canonicalRoot`.
*
* The setter will change the Relation's `href` to be prefixed with `AssetGraph.canonicalRoot`
* if `true`, and without if `false`
*
* @type {Boolean}
*/
canonical: boolean;
/**
* Get the url of the first non-inlined ancestor of the `from`-Asset
*
* @type {String}
*/
baseUrl: string;
/**
* Either `'absolute'`, `'rootRelative'`, `'protocolRelative'`, `'relative'`, or `'inline'`.
* Decides what "degree" of relative url [`refreshHref()`]{@link Relation#refreshHref} tries to issue, except for
* `'inline'` which means that the target asset is contained in a `data:` url or similar.
*
* @type {String}
*/
hrefType: string;
/**
* Inline the relation. This is only supported by certain relation
* types and will produce different results depending on the type
* (`data:` url, inline script, inline stylesheet...).
*
* Will make a clone of the target asset if it has more incoming
* relations than this one.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
inline(): Relation;
/**
* Attaches the relation to an asset.
*
* The ordering of certain relation types is significant
* (`HtmlScript`, for instance), so it's important that the order
* isn't scrambled in the indices. Therefore the caller must
* explicitly specify a position at which to insert the object.
*
* @param {String} position `"first"`, `"last"`, `"before"`, or `"after"`.
* @param {Relation} adjacentRelation The adjacent relation, mandatory if the position is `"before"` or `"after"`.
* @return {Relation} The relation itself (chaining-friendly).
*/
attach(position: string, adjacentRelation: Relation): Relation;
/**
* Detaches the relation from the asset it is currently attached
* to. If the relation is currently part of a graph, it will
* removed from it.
*
* Detaching implies that the tag/statement/declaration
* representing the relation is physically removed from the
* referring asset. Not all relation types support this.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
detach(): Relation;
/**
* Removes the relation from the graph it's currently part
* of. Doesn't detach the relation (compare with
* [`relation.detach()`]{@link Relation#detach}).
*
* @return {Relation} The relation itself (chaining-friendly).
* @api public
*/
remove(): Relation;
/**
* Get a brief text containing the type, id of the relation. Will
* also contain the `.toString()` of the relation's source and
* target assets if available.
*
* @return {String} The string, eg. `"[HtmlAnchor/141: [Html/40 file:///foo/bar/index.html] => [Html/76 file:///foo/bar/otherpage.html]]"``
*/
toString(): string;
/**
* Property that's true for all relation instances. Avoids
* reliance on the `instanceof` operator.
*
* @constant
* @type {Boolean}
* @memberOf Relation#
*/
readonly isRelation: boolean;
}
/**
* @constructor
* @abstract
* @augments HtmlRelation
*
* Abstract class for resource hint relations
*/
declare class HtmlResourceHint extends HtmlRelation {
/**
* The source asset of the relation.
*
* @member {Asset} Relation#from
*/
from: Asset;
/**
* The target asset of the relation.
*
* @type {Asset}
*/
to: Asset;
/**
* The ATS/DOM-node where the Relation originates in the parent document
*
* @member {Object} Relation#node
*/
node: any;
/**
* Get or set the href of the relation. The relation must be
* attached to an asset.
*
* What is actually retrieved or updated depends on the relation
* type. For `HtmlImage` the `src` attribute of the HTML element
* is changed, for `CssImport` the parsed representation of
* the @import rule is updated, etc.
*
* Most of the time you don't need to think about this property,
* as the href is automatically updated when the url of the source
* or target asset is changed, or an intermediate asset is
* inlined.
*
* @member {String} Relation#href
*/
href: string;
/**
* Get or set the fragment identifier part of the href of the relation.
*
* Setting a fragment with a non-empty value requires the value to begin with `#`
*
* @type {String}
*/
fragment: string;
/**
* Update `href` of a relation to make sure it points at the
* current url of its target asset.
*
* It's not necessary to call this function manually as long as
* the source and target assets of the relation have only been
* moved by having their `url` property changed (the recommended
* way), but some transforms will need this after some low-level
* surgery, such as attaching an existing relation to a different
* asset.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
refreshHref(): Relation;
/**
* Get the relations cross origins status defined as
* differences in protocol or hostname.
*
* This property is quite useful as part of a population
* query to ensure that the graph doesn't expand beyond
* the current host or file system
*
* @type {Boolean}
*/
crossorigin: boolean;
/**
* Get or set the canonical state of a Relation
*
* If [AssetGraph]{@link AssetGraph} has a [`canonicalRoot`]{@link AssetGraph#canonicalRoot}
* property, AssetGraph will detect absolute URLs matching `AssetGraph.canonicalRoot`
* as if they were of [`hrefType`]{@link Relation#hrefType} `rootRelative`.
*
* The getter tell you if [`Relation.href`]{@link Relation#href} will be prepended
* with `Assetgraph.canonicalRoot`.
*
* The setter will change the Relation's `href` to be prefixed with `AssetGraph.canonicalRoot`
* if `true`, and without if `false`
*
* @type {Boolean}
*/
canonical: boolean;
/**
* Get the url of the first non-inlined ancestor of the `from`-Asset
*
* @type {String}
*/
baseUrl: string;
/**
* Either `'absolute'`, `'rootRelative'`, `'protocolRelative'`, `'relative'`, or `'inline'`.
* Decides what "degree" of relative url [`refreshHref()`]{@link Relation#refreshHref} tries to issue, except for
* `'inline'` which means that the target asset is contained in a `data:` url or similar.
*
* @type {String}
*/
hrefType: string;
/**
* Inline the relation. This is only supported by certain relation
* types and will produce different results depending on the type
* (`data:` url, inline script, inline stylesheet...).
*
* Will make a clone of the target asset if it has more incoming
* relations than this one.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
inline(): Relation;
/**
* Attaches the relation to an asset.
*
* The ordering of certain relation types is significant
* (`HtmlScript`, for instance), so it's important that the order
* isn't scrambled in the indices. Therefore the caller must
* explicitly specify a position at which to insert the object.
*
* @param {String} position `"first"`, `"last"`, `"before"`, or `"after"`.
* @param {Relation} adjacentRelation The adjacent relation, mandatory if the position is `"before"` or `"after"`.
* @return {Relation} The relation itself (chaining-friendly).
*/
attach(position: string, adjacentRelation: Relation): Relation;
/**
* Detaches the relation from the asset it is currently attached
* to. If the relation is currently part of a graph, it will
* removed from it.
*
* Detaching implies that the tag/statement/declaration
* representing the relation is physically removed from the
* referring asset. Not all relation types support this.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
detach(): Relation;
/**
* Removes the relation from the graph it's currently part
* of. Doesn't detach the relation (compare with
* [`relation.detach()`]{@link Relation#detach}).
*
* @return {Relation} The relation itself (chaining-friendly).
* @api public
*/
remove(): Relation;
/**
* Get a brief text containing the type, id of the relation. Will
* also contain the `.toString()` of the relation's source and
* target assets if available.
*
* @return {String} The string, eg. `"[HtmlAnchor/141: [Html/40 file:///foo/bar/index.html] => [Html/76 file:///foo/bar/otherpage.html]]"``
*/
toString(): string;
/**
* Property that's true for all relation instances. Avoids
* reliance on the `instanceof` operator.
*
* @constant
* @type {Boolean}
* @memberOf Relation#
*/
readonly isRelation: boolean;
}
/**
* In graph terminology a relation represents a directed edge, a
* reference from one asset to another. For the purpose of being able
* to treat all relations equally, there's a subclass for each
* supported relation type, encapsulating the details of how to
* retrieve, update, and (optionally) inline the asset being pointed
* to.
*
* These are some examples of included subclasses:
*
* - `relations.HtmlAnchor` An anchor tag in an HTML document `<a href='...'>`.
* - `relations.HtmlImage` An `<img src='...'>` tag in an HTML document.
* - `relations.CssImport` An `@import` declaration in a CSS asset.
* - `relations.CacheManifestEntry` A line in a cache manifest.
*/
declare class Relation {
constructor(config: any);
/**
* The source asset of the relation.
*
* @member {Asset} Relation#from
*/
from: Asset;
/**
* The target asset of the relation.
*
* @type {Asset}
*/
to: Asset;
/**
* The ATS/DOM-node where the Relation originates in the parent document
*
* @member {Object} Relation#node
*/
node: any;
/**
* Get or set the href of the relation. The relation must be
* attached to an asset.
*
* What is actually retrieved or updated depends on the relation
* type. For `HtmlImage` the `src` attribute of the HTML element
* is changed, for `CssImport` the parsed representation of
* the @import rule is updated, etc.
*
* Most of the time you don't need to think about this property,
* as the href is automatically updated when the url of the source
* or target asset is changed, or an intermediate asset is
* inlined.
*
* @member {String} Relation#href
*/
href: string;
/**
* Get or set the fragment identifier part of the href of the relation.
*
* Setting a fragment with a non-empty value requires the value to begin with `#`
*
* @type {String}
*/
fragment: string;
/**
* Update `href` of a relation to make sure it points at the
* current url of its target asset.
*
* It's not necessary to call this function manually as long as
* the source and target assets of the relation have only been
* moved by having their `url` property changed (the recommended
* way), but some transforms will need this after some low-level
* surgery, such as attaching an existing relation to a different
* asset.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
refreshHref(): Relation;
/**
* Get the relations cross origins status defined as
* differences in protocol or hostname.
*
* This property is quite useful as part of a population
* query to ensure that the graph doesn't expand beyond
* the current host or file system
*
* @type {Boolean}
*/
crossorigin: boolean;
/**
* Get or set the canonical state of a Relation
*
* If [AssetGraph]{@link AssetGraph} has a [`canonicalRoot`]{@link AssetGraph#canonicalRoot}
* property, AssetGraph will detect absolute URLs matching `AssetGraph.canonicalRoot`
* as if they were of [`hrefType`]{@link Relation#hrefType} `rootRelative`.
*
* The getter tell you if [`Relation.href`]{@link Relation#href} will be prepended
* with `Assetgraph.canonicalRoot`.
*
* The setter will change the Relation's `href` to be prefixed with `AssetGraph.canonicalRoot`
* if `true`, and without if `false`
*
* @type {Boolean}
*/
canonical: boolean;
/**
* Get the url of the first non-inlined ancestor of the `from`-Asset
*
* @type {String}
*/
baseUrl: string;
/**
* Either `'absolute'`, `'rootRelative'`, `'protocolRelative'`, `'relative'`, or `'inline'`.
* Decides what "degree" of relative url [`refreshHref()`]{@link Relation#refreshHref} tries to issue, except for
* `'inline'` which means that the target asset is contained in a `data:` url or similar.
*
* @type {String}
*/
hrefType: string;
/**
* Inline the relation. This is only supported by certain relation
* types and will produce different results depending on the type
* (`data:` url, inline script, inline stylesheet...).
*
* Will make a clone of the target asset if it has more incoming
* relations than this one.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
inline(): Relation;
/**
* Attaches the relation to an asset.
*
* The ordering of certain relation types is significant
* (`HtmlScript`, for instance), so it's important that the order
* isn't scrambled in the indices. Therefore the caller must
* explicitly specify a position at which to insert the object.
*
* @param {String} position `"first"`, `"last"`, `"before"`, or `"after"`.
* @param {Relation} adjacentRelation The adjacent relation, mandatory if the position is `"before"` or `"after"`.
* @return {Relation} The relation itself (chaining-friendly).
*/
attach(position: string, adjacentRelation: Relation): Relation;
/**
* Detaches the relation from the asset it is currently attached
* to. If the relation is currently part of a graph, it will
* removed from it.
*
* Detaching implies that the tag/statement/declaration
* representing the relation is physically removed from the
* referring asset. Not all relation types support this.
*
* @return {Relation} The relation itself (chaining-friendly).
*/
detach(): Relation;
/**
* Removes the relation from the graph it's currently part
* of. Doesn't detach the relation (compare with
* [`relation.detach()`]{@link Relation#detach}).
*
* @return {Relation} The relation itself (chaining-friendly).
* @api public
*/
remove(): Relation;
/**
* Get a brief text containing the type, id of the relation. Will
* also contain the `.toString()` of the relation's source and
* target assets if available.
*
* @return {String} The string, eg. `"[HtmlAnchor/141: [Html/40 file:///foo/bar/index.html] => [Html/76 file:///foo/bar/otherpage.html]]"``
*/
toString(): string;
/**
* Property that's true for all relation instances. Avoids
* reliance on the `instanceof` operator.
*
* @constant
* @type {Boolean}
* @memberOf Relation#
*/
readonly isRelation: boolean;
}
/**
* Webfont properties object containing the main differentiators for a separate font file.
* @typedef {Object} FontProps
* @property {string} 'font-family' [CSS font-family](https://developer.mozilla.org/en-US/docs/Web/CSS/font-family), unquoted
* @property {string} 'font-weight' [CSS font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
* @property {string} 'font-style' [CSS font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style)
*/
declare type FontProps = {
'font-family': string;
'font-weight': string;
'font-style': string;
};
/**
* User agent strings by desired font format.
* @readonly
* @enum {string}
*/
declare const enum formatAgents {
eot,
ttf,
woff,
woff2
}
/**
* Download google fonts for self-hosting
*
* @async
* @param {FontProps} fontProps CSS font properties to get font for
* @param {Object} options
* @param {String[]} [options.formats=['woff2', 'woff']] List of formats that should be inclued in the output
* @param {String} [options.fontDisplay='swap'] CSS font-display value in returned CSS blocks
* @param {String} [options.text] Text to create a subset with
* @return {String} CSS asset with inlined google fonts
*/
declare function downloadGoogleFonts(fontProps: FontProps, options: {
formats?: string[];
fontDisplay?: string;
text?: string;
}): string;
/**
* Snap a desired font-weight to an available font-weight according to the font-weight snapping
* algorithm described in https://www.w3.org/TR/css-fonts-3/#fontstylematchingalg
*
* @param {Number} desiredWeight - The desired font-weight
* @param {Number[]} availableWeights - Available font-weights
*
* @return {Number} Resulting font-weight after snapping to available weights
*/
declare function resolveFontWeight(desiredWeight: number, availableWeights: number[]): number;
/**
* @typedef {Object} FontFaceDeclaration
* @property {String} 'font-family' - CSS [font-family](https://developer.mozilla.org/en-US/docs/Web/CSS/font-family) property
* @property {String} 'font-stretch' - CSS [font-stretch](https://developer.mozilla.org/en-US/docs/Web/CSS/font-stretch) property
* @property {String} 'font-weight' - CSS [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight) property, must be normalized to numbers
* @property {String} 'font-style' - CSS [font-style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style) property
*/
declare type FontFaceDeclaration = {
'font-family': string;
'font-stretch': string;
'font-weight': string;
'font-style': string;
};
/**
* Font style matching algorithm as described in https://www.w3.org/TR/css-fonts-3/#fontstylematchingalg
* @param {FontFaceDeclaration[]} fontFaceDeclarations - Array of FontFaceDeclarations to match against
* @param {FontFaceDeclaration} propsToSnap - FontFaceDeclaration to match against fontFaceDeclarations
*
* @return {FontFaceDeclaration} The nearest match from fontFaceDeclarations
*/
declare function snapToAvailableFontProperties(fontFaceDeclarations: FontFaceDeclaration[], propsToSnap: FontFaceDeclaration): FontFaceDeclaration;
/**
* Generates a unicode-range string from an array of unicode codepoints
* @param {Number[]} codePoints The code points
* @return {String} The resulting [unicode-range](https://developer.mozilla.org/en-US/docs/Web/CSS/%40font-face/unicode-range)
*/
declare function getUnicodeRanges(codePoints: number[]): string;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment