html-validate 7.5.0 → 7.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/core.d.ts CHANGED
@@ -1001,731 +1001,774 @@ interface CSSStyleDeclaration {
1001
1001
  [key: string]: string;
1002
1002
  }
1003
1003
 
1004
- interface PermittedGroup {
1005
- exclude?: string | string[];
1006
- }
1007
- declare type CategoryOrTag = string;
1008
- declare type PropertyExpression = string | [string, any];
1009
- declare type PermittedEntry = CategoryOrTag | PermittedGroup | Array<CategoryOrTag | PermittedGroup>;
1010
- declare type Permitted = PermittedEntry[];
1011
- declare type PermittedOrder = string[];
1012
- declare type RequiredAncestors = string[];
1013
- declare type RequiredContent = string[];
1014
- declare enum TextContent {
1015
- NONE = "none",
1016
- DEFAULT = "default",
1017
- REQUIRED = "required",
1018
- ACCESSIBLE = "accessible"
1019
- }
1020
1004
  /**
1021
1005
  * @public
1022
1006
  */
1023
- interface MetaAttribute {
1024
- boolean?: boolean;
1025
- deprecated?: boolean | string;
1026
- enum?: Array<string | RegExp>;
1027
- list?: boolean;
1028
- omit?: boolean;
1029
- required?: boolean;
1007
+ interface TransformContext {
1008
+ /**
1009
+ * Test if an additional chainable transformer is present.
1010
+ *
1011
+ * Returns true only if there is a transformer configured for the given
1012
+ * filename.
1013
+ *
1014
+ * @param filename - Filename to use to match next transformer.
1015
+ */
1016
+ hasChain(filename: string): boolean;
1017
+ /**
1018
+ * Chain transformations.
1019
+ *
1020
+ * Sometimes multiple transformers must be applied. For instance, a Markdown
1021
+ * file with JSX in a code-block.
1022
+ *
1023
+ * @param source - Source to chain transformations on.
1024
+ * @param filename - Filename to use to match next transformer (unrelated to
1025
+ * filename set in source)
1026
+ */
1027
+ chain(source: Source, filename: string): Iterable<Source>;
1030
1028
  }
1031
- declare type PermittedAttribute = Record<string, MetaAttribute | Array<string | RegExp> | null>;
1032
- interface DeprecatedElement {
1033
- message?: string;
1034
- documentation?: string;
1035
- source?: string;
1029
+
1030
+ declare module "estree" {
1031
+ interface TemplateElement {
1032
+ start: number;
1033
+ end: number;
1034
+ }
1036
1035
  }
1037
1036
  /**
1038
1037
  * @public
1039
1038
  */
1040
- interface MetaData {
1041
- inherit?: string;
1042
- metadata?: boolean | PropertyExpression;
1043
- flow?: boolean | PropertyExpression;
1044
- sectioning?: boolean | PropertyExpression;
1045
- heading?: boolean | PropertyExpression;
1046
- phrasing?: boolean | PropertyExpression;
1047
- embedded?: boolean | PropertyExpression;
1048
- interactive?: boolean | PropertyExpression;
1049
- deprecated?: boolean | string | DeprecatedElement;
1050
- foreign?: boolean;
1051
- void?: boolean;
1052
- transparent?: boolean | string[];
1053
- implicitClosed?: string[];
1054
- scriptSupporting?: boolean;
1055
- form?: boolean;
1056
- labelable?: boolean | PropertyExpression;
1057
- deprecatedAttributes?: string[];
1058
- requiredAttributes?: string[];
1059
- attributes?: PermittedAttribute;
1060
- permittedContent?: Permitted;
1061
- permittedDescendants?: Permitted;
1062
- permittedOrder?: PermittedOrder;
1063
- permittedParent?: Permitted;
1064
- requiredAncestors?: RequiredAncestors;
1065
- requiredContent?: RequiredContent;
1066
- textContent?: TextContent;
1039
+ declare class TemplateExtractor {
1040
+ private ast;
1041
+ private filename;
1042
+ private data;
1043
+ private constructor();
1044
+ static fromFilename(filename: string): TemplateExtractor;
1045
+ /**
1046
+ * Create a new [[TemplateExtractor]] from javascript source code.
1047
+ *
1048
+ * `Source` offsets will be relative to the string, i.e. offset 0 is the first
1049
+ * character of the string. If the string is only a subset of a larger string
1050
+ * the offsets must be adjusted manually.
1051
+ *
1052
+ * @param source - Source code.
1053
+ * @param filename - Optional filename to set in the resulting
1054
+ * `Source`. Defauls to `"inline"`.
1055
+ */
1056
+ static fromString(source: string, filename?: string): TemplateExtractor;
1057
+ /**
1058
+ * Convenience function to create a [[Source]] instance from an existing file.
1059
+ *
1060
+ * @param filename - Filename with javascript source code. The file must exist
1061
+ * and be readable by the user.
1062
+ * @returns An array of Source's suitable for passing to [[Engine]] linting
1063
+ * functions.
1064
+ */
1065
+ static createSource(filename: string): Source[];
1066
+ /**
1067
+ * Extract object properties.
1068
+ *
1069
+ * Given a key `"template"` this method finds all objects literals with a
1070
+ * `"template"` property and creates a [[Source]] instance with proper offsets
1071
+ * with the value of the property. For instance:
1072
+ *
1073
+ * ```
1074
+ * const myObj = {
1075
+ * foo: 'bar',
1076
+ * };
1077
+ * ```
1078
+ *
1079
+ * The above snippet would yield a `Source` with the content `bar`.
1080
+ *
1081
+ */
1082
+ extractObjectProperty(key: string): Source[];
1067
1083
  }
1084
+
1068
1085
  /**
1069
- * Properties listed here can be used to reverse search elements with the given
1070
- * property enabled. See [[MetaTable.getTagsWithProperty]].
1071
- */
1072
- declare type MetaLookupableProperty = "metadata" | "flow" | "sectioning" | "heading" | "phrasing" | "embedded" | "interactive" | "deprecated" | "foreign" | "void" | "transparent" | "scriptSupporting" | "form" | "labelable";
1073
- /**
1074
- * Properties listed here can be copied (loaded) onto another element using
1075
- * [[HtmlElement.loadMeta]].
1076
- *
1077
1086
  * @public
1078
1087
  */
1079
- declare const MetaCopyableProperty: Array<keyof MetaElement>;
1088
+ declare type Transformer = (this: TransformContext, source: Source) => Iterable<Source>;
1089
+
1090
+ interface SchemaValidationPatch {
1091
+ properties?: Record<string, unknown>;
1092
+ definitions?: Record<string, unknown>;
1093
+ }
1080
1094
  /**
1081
1095
  * @public
1082
1096
  */
1083
- interface MetaElement extends Omit<MetaData, "deprecatedAttributes" | "requiredAttributes"> {
1084
- tagName: string;
1085
- attributes: Record<string, MetaAttribute>;
1086
- }
1087
- interface MetaDataTable {
1088
- [tagName: string]: MetaData;
1089
- }
1090
- interface ElementTable {
1091
- [tagName: string]: MetaElement;
1092
- }
1093
-
1094
- declare enum NodeType {
1095
- ELEMENT_NODE = 1,
1096
- TEXT_NODE = 3,
1097
- DOCUMENT_NODE = 9
1098
- }
1099
-
1100
- interface DOMNodeCache {
1101
- }
1102
-
1103
- declare type DOMInternalID = number;
1104
- declare const TEXT_CONTENT: unique symbol;
1105
- declare module "./cache" {
1106
- interface DOMNodeCache {
1107
- [TEXT_CONTENT]: string;
1108
- }
1109
- }
1110
- declare class DOMNode {
1111
- readonly nodeName: string;
1112
- readonly nodeType: NodeType;
1113
- readonly childNodes: DOMNode[];
1114
- readonly location: Location;
1115
- readonly unique: DOMInternalID;
1116
- private cache;
1097
+ interface Plugin {
1117
1098
  /**
1118
- * Set of disabled rules for this node.
1099
+ * Name of the plugin.
1119
1100
  *
1120
- * Rules disabled by using directives are added here.
1121
- */
1122
- private disabledRules;
1123
- /**
1124
- * Create a new DOMNode.
1101
+ * If specified this is the name used when referring to the plugin. Default is
1102
+ * to use the name/path the user used when loading the plugin. To be less
1103
+ * confusing for users you should use the same name as your package.
1125
1104
  *
1126
- * @param nodeType - What node type to create.
1127
- * @param nodeName - What node name to use. For `HtmlElement` this corresponds
1128
- * to the tagName but other node types have specific predefined values.
1129
- * @param location - Source code location of this node.
1105
+ * The name must be a valid package name according to NPM (basically lowercase
1106
+ * characters, must not begin with dot, slash or non-url safe characters).
1107
+ *
1108
+ * Hint: import and use the name from `package.json`.
1130
1109
  */
1131
- constructor(nodeType: NodeType, nodeName: string | undefined, location: Location);
1110
+ name?: string | null;
1132
1111
  /**
1133
- * Enable cache for this node.
1112
+ * Initialization callback.
1134
1113
  *
1135
- * Should not be called before the node and all children are fully constructed.
1114
+ * Called once per plugin during initialization.
1136
1115
  */
1137
- cacheEnable(): void;
1116
+ init?: () => void | null;
1138
1117
  /**
1139
- * Fetch cached value from this DOM node.
1118
+ * Setup callback.
1140
1119
  *
1141
- * Cache is not enabled until `cacheEnable()` is called by [[Parser]] (when
1142
- * the element is fully constructed).
1120
+ * Called once per source after engine is initialized.
1143
1121
  *
1144
- * @returns value or `undefined` if the value doesn't exist.
1122
+ * @param source - The source about to be validated. Readonly.
1123
+ * @param eventhandler - Eventhandler from parser. Can be used to listen for
1124
+ * parser events.
1145
1125
  */
1146
- cacheGet<K extends keyof DOMNodeCache>(key: K): DOMNodeCache[K] | undefined;
1147
- cacheGet(key: string | number | symbol): any | undefined;
1126
+ setup?: (source: Source, eventhandler: EventHandler) => void | null;
1148
1127
  /**
1149
- * Store a value in cache.
1128
+ * Configuration presets.
1150
1129
  *
1151
- * @returns the value itself is returned.
1152
- */
1153
- cacheSet<K extends keyof DOMNodeCache>(key: K, value: DOMNodeCache[K]): DOMNodeCache[K];
1154
- cacheSet<T>(key: string | number | symbol, value: T): T;
1155
- /**
1156
- * Remove a value by key from cache.
1130
+ * Each key should be the unprefixed name which a configuration later can
1131
+ * access using `${plugin}:${key}`, e.g. if a plugin named "my-plugin" exposes
1132
+ * a preset named "foobar" it can be accessed using:
1157
1133
  *
1158
- * @returns `true` if the entry existed and has been removed.
1159
- */
1160
- cacheRemove<K extends keyof DOMNodeCache>(key: K): boolean;
1161
- cacheRemove(key: string | number | symbol): boolean;
1162
- /**
1163
- * Check if key exists in cache.
1164
- */
1165
- cacheExists<K extends keyof DOMNodeCache>(key: K): boolean;
1166
- cacheExists(key: string | number | symbol): boolean;
1167
- /**
1168
- * Get the text (recursive) from all child nodes.
1169
- */
1170
- get textContent(): string;
1171
- append(node: DOMNode): void;
1172
- isRootElement(): boolean;
1173
- /**
1174
- * Tests if two nodes are the same (references the same object).
1175
- */
1176
- isSameNode(otherNode: DOMNode): boolean;
1177
- /**
1178
- * Returns a DOMNode representing the first direct child node or `null` if the
1179
- * node has no children.
1180
- */
1181
- get firstChild(): DOMNode;
1182
- /**
1183
- * Returns a DOMNode representing the last direct child node or `null` if the
1184
- * node has no children.
1185
- */
1186
- get lastChild(): DOMNode;
1187
- /**
1188
- * Disable a rule for this node.
1189
- */
1190
- disableRule(ruleId: string): void;
1191
- /**
1192
- * Disables multiple rules.
1134
+ * "extends": ["my-plugin:foobar"]
1193
1135
  */
1194
- disableRules(rules: string[]): void;
1136
+ configs?: Record<string, ConfigData | null> | null;
1195
1137
  /**
1196
- * Enable a previously disabled rule for this node.
1138
+ * List of new rules present.
1197
1139
  */
1198
- enableRule(ruleId: string): void;
1140
+ rules?: Record<string, RuleConstructor<any, any> | null> | null;
1199
1141
  /**
1200
- * Enables multiple rules.
1142
+ * Transformer available in this plugin.
1143
+ *
1144
+ * Can be given either as a single unnamed transformer or an object with
1145
+ * multiple named.
1146
+ *
1147
+ * Unnamed transformers use the plugin name similar to how a standalone
1148
+ * transformer would work:
1149
+ *
1150
+ * ```
1151
+ * "transform": {
1152
+ * "^.*\\.foo$": "my-plugin"
1153
+ * }
1154
+ * ```
1155
+ *
1156
+ * For named transformers each key should be the unprefixed name which a
1157
+ * configuration later can access using `${plugin}:${key}`, e.g. if a plugin
1158
+ * named "my-plugin" exposes a transformer named "foobar" it can be accessed
1159
+ * using:
1160
+ *
1161
+ * ```
1162
+ * "transform": {
1163
+ * "^.*\\.foo$": "my-plugin:foobar"
1164
+ * }
1165
+ * ```
1201
1166
  */
1202
- enableRules(rules: string[]): void;
1167
+ transformer?: Transformer | Record<string, Transformer | null> | null;
1203
1168
  /**
1204
- * Test if a rule is enabled for this node.
1169
+ * Extend metadata validation schema.
1205
1170
  */
1206
- ruleEnabled(ruleId: string): boolean;
1207
- generateSelector(): string | null;
1208
- }
1209
-
1210
- declare class DOMTokenList extends Array<string> {
1211
- readonly value: string;
1212
- private readonly locations;
1213
- constructor(value: string | DynamicValue | null, location: Location | null);
1214
- item(n: number): string | undefined;
1215
- location(n: number): Location | undefined;
1216
- contains(token: string): boolean;
1217
- iterator(): Generator<{
1218
- index: number;
1219
- item: string;
1220
- location: Location;
1221
- }>;
1171
+ elementSchema?: SchemaValidationPatch | null;
1222
1172
  }
1223
1173
 
1224
1174
  /**
1225
1175
  * @public
1226
1176
  */
1227
- declare enum NodeClosed {
1228
- Open = 0,
1229
- EndTag = 1,
1230
- VoidOmitted = 2,
1231
- VoidSelfClosed = 3,
1232
- ImplicitClosed = 4
1233
- }
1234
- /**
1235
- * @public
1236
- */
1237
- declare class HtmlElement extends DOMNode {
1238
- readonly tagName: string;
1239
- readonly parent: HtmlElement | null;
1240
- readonly voidElement: boolean;
1241
- readonly depth: number;
1242
- closed: NodeClosed;
1243
- protected readonly attr: {
1244
- [key: string]: Attribute[];
1245
- };
1246
- private metaElement;
1247
- private annotation;
1248
- constructor(tagName: string | undefined, parent: HtmlElement | null, closed: NodeClosed, meta: MetaElement | null, location: Location);
1177
+ declare class MetaTable {
1178
+ readonly elements: ElementTable;
1179
+ private schema;
1249
1180
  /**
1250
1181
  * @internal
1251
1182
  */
1252
- static rootNode(location: Location): HtmlElement;
1183
+ constructor();
1253
1184
  /**
1254
1185
  * @internal
1255
- *
1256
- * @param namespace - If given it is appended to the tagName.
1257
1186
  */
1258
- static fromTokens(startToken: TagOpenToken, endToken: TagCloseToken, parent: HtmlElement | null, metaTable: MetaTable | null, namespace?: string): HtmlElement;
1187
+ init(): void;
1259
1188
  /**
1260
- * Returns annotated name if set or defaults to `<tagName>`.
1189
+ * Extend validation schema.
1261
1190
  *
1262
- * E.g. `my-annotation` or `<div>`.
1263
- */
1264
- get annotatedName(): string;
1265
- /**
1266
- * Similar to childNodes but only elements.
1191
+ * @internal
1267
1192
  */
1268
- get childElements(): HtmlElement[];
1193
+ extendValidationSchema(patch: SchemaValidationPatch): void;
1269
1194
  /**
1270
- * Find the first ancestor matching a selector.
1195
+ * Load metadata table from object.
1271
1196
  *
1272
- * Implementation of DOM specification of Element.closest(selectors).
1197
+ * @internal
1198
+ * @param obj - Object with metadata to load
1199
+ * @param filename - Optional filename used when presenting validation error
1273
1200
  */
1274
- closest(selectors: string): HtmlElement | null;
1201
+ loadFromObject(obj: unknown, filename?: string | null): void;
1275
1202
  /**
1276
- * Generate a DOM selector for this element. The returned selector will be
1277
- * unique inside the current document.
1203
+ * Load metadata table from filename
1204
+ *
1205
+ * @internal
1206
+ * @param filename - Filename to load
1278
1207
  */
1279
- generateSelector(): string | null;
1208
+ loadFromFile(filename: string): void;
1280
1209
  /**
1281
- * Tests if this element has given tagname.
1210
+ * Get [[MetaElement]] for the given tag. If no specific metadata is present
1211
+ * the global metadata is returned or null if no global is present.
1282
1212
  *
1283
- * If passing "*" this test will pass if any tagname is set.
1213
+ * @public
1214
+ * @returns A shallow copy of metadata.
1284
1215
  */
1285
- is(tagName: string): boolean;
1216
+ getMetaFor(tagName: string): MetaElement | null;
1286
1217
  /**
1287
- * Load new element metadata onto this element.
1288
- *
1289
- * Do note that semantics such as `void` cannot be changed (as the element has
1290
- * already been created). In addition the element will still "be" the same
1291
- * element, i.e. even if loading meta for a `<p>` tag upon a `<div>` tag it
1292
- * will still be a `<div>` as far as the rest of the validator is concerned.
1293
- *
1294
- * In fact only certain properties will be copied onto the element:
1295
- *
1296
- * - content categories (flow, phrasing, etc)
1297
- * - required attributes
1298
- * - attribute allowed values
1299
- * - permitted/required elements
1300
- *
1301
- * Properties *not* loaded:
1302
- *
1303
- * - inherit
1304
- * - deprecated
1305
- * - foreign
1306
- * - void
1307
- * - implicitClosed
1308
- * - scriptSupporting
1309
- * - deprecatedAttributes
1218
+ * Find all tags which has enabled given property.
1310
1219
  *
1311
- * Changes to element metadata will only be visible after `element:ready` (and
1312
- * the subsequent `dom:ready` event).
1220
+ * @public
1313
1221
  */
1314
- loadMeta(meta: MetaElement): void;
1222
+ getTagsWithProperty(propName: MetaLookupableProperty): string[];
1315
1223
  /**
1316
- * Match this element against given selectors. Returns true if any selector
1317
- * matches.
1224
+ * Find tag matching tagName or inheriting from it.
1318
1225
  *
1319
- * Implementation of DOM specification of Element.matches(selectors).
1226
+ * @public
1320
1227
  */
1321
- matches(selector: string): boolean;
1322
- get meta(): MetaElement | null;
1228
+ getTagsDerivedFrom(tagName: string): string[];
1229
+ private addEntry;
1323
1230
  /**
1324
- * Set annotation for this element.
1231
+ * Construct a new AJV schema validator.
1325
1232
  */
1326
- setAnnotation(text: string): void;
1233
+ private getSchemaValidator;
1327
1234
  /**
1328
- * Set attribute. Stores all attributes set even with the same name.
1329
- *
1330
- * @param key - Attribute name
1331
- * @param value - Attribute value. Use `null` if no value is present.
1332
- * @param keyLocation - Location of the attribute name.
1333
- * @param valueLocation - Location of the attribute value (excluding quotation)
1334
- * @param originalAttribute - If attribute is an alias for another attribute
1335
- * (dynamic attributes) set this to the original attribute name.
1235
+ * @public
1336
1236
  */
1337
- setAttribute(key: string, value: string | DynamicValue | null, keyLocation: Location, valueLocation: Location | null, originalAttribute?: string): void;
1237
+ getJSONSchema(): SchemaObject;
1338
1238
  /**
1339
- * Get a list of all attributes on this node.
1239
+ * Finds the global element definition and merges each known element with the
1240
+ * global, e.g. to assign global attributes.
1340
1241
  */
1341
- get attributes(): Attribute[];
1342
- hasAttribute(key: string): boolean;
1242
+ private resolveGlobal;
1243
+ private mergeElement;
1343
1244
  /**
1344
- * Get attribute.
1345
- *
1346
- * By default only the first attribute is returned but if the code needs to
1347
- * handle duplicate attributes the `all` parameter can be set to get all
1348
- * attributes with given key.
1349
- *
1350
- * This usually only happens when code contains duplicate attributes (which
1351
- * `no-dup-attr` will complain about) or when a static attribute is combined
1352
- * with a dynamic, consider:
1353
- *
1354
- * <p class="foo" dynamic-class="bar">
1355
- *
1356
- * @param key - Attribute name
1357
- * @param all - Return single or all attributes.
1245
+ * @internal
1358
1246
  */
1359
- getAttribute(key: string): Attribute | null;
1360
- getAttribute(key: string, all: true): Attribute[];
1247
+ resolve(node: HtmlElement): void;
1248
+ }
1249
+
1250
+ declare enum NodeType {
1251
+ ELEMENT_NODE = 1,
1252
+ TEXT_NODE = 3,
1253
+ DOCUMENT_NODE = 9
1254
+ }
1255
+
1256
+ interface DOMNodeCache {
1257
+ }
1258
+
1259
+ declare type DOMInternalID = number;
1260
+ declare const TEXT_CONTENT: unique symbol;
1261
+ declare module "./cache" {
1262
+ interface DOMNodeCache {
1263
+ [TEXT_CONTENT]: string;
1264
+ }
1265
+ }
1266
+ declare class DOMNode {
1267
+ readonly nodeName: string;
1268
+ readonly nodeType: NodeType;
1269
+ readonly childNodes: DOMNode[];
1270
+ readonly location: Location;
1271
+ readonly unique: DOMInternalID;
1272
+ private cache;
1361
1273
  /**
1362
- * Get attribute value.
1363
- *
1364
- * Returns the attribute value if present.
1365
- *
1366
- * - Missing attributes return `null`.
1367
- * - Boolean attributes return `null`.
1368
- * - `DynamicValue` returns attribute expression.
1274
+ * Set of disabled rules for this node.
1369
1275
  *
1370
- * @param key - Attribute name
1371
- * @returns Attribute value or null.
1276
+ * Rules disabled by using directives are added here.
1372
1277
  */
1373
- getAttributeValue(key: string): string | null;
1278
+ private disabledRules;
1374
1279
  /**
1375
- * Add text as a child node to this element.
1280
+ * Create a new DOMNode.
1376
1281
  *
1377
- * @param text - Text to add.
1378
- * @param location - Source code location of this text.
1282
+ * @param nodeType - What node type to create.
1283
+ * @param nodeName - What node name to use. For `HtmlElement` this corresponds
1284
+ * to the tagName but other node types have specific predefined values.
1285
+ * @param location - Source code location of this node.
1379
1286
  */
1380
- appendText(text: string | DynamicValue, location: Location): void;
1287
+ constructor(nodeType: NodeType, nodeName: string | undefined, location: Location);
1381
1288
  /**
1382
- * Return a list of all known classes on the element. Dynamic values are
1383
- * ignored.
1289
+ * Enable cache for this node.
1290
+ *
1291
+ * Should not be called before the node and all children are fully constructed.
1384
1292
  */
1385
- get classList(): DOMTokenList;
1293
+ cacheEnable(): void;
1386
1294
  /**
1387
- * Get element ID if present.
1295
+ * Fetch cached value from this DOM node.
1296
+ *
1297
+ * Cache is not enabled until `cacheEnable()` is called by [[Parser]] (when
1298
+ * the element is fully constructed).
1299
+ *
1300
+ * @returns value or `undefined` if the value doesn't exist.
1388
1301
  */
1389
- get id(): string | null;
1390
- get style(): CSSStyleDeclaration;
1302
+ cacheGet<K extends keyof DOMNodeCache>(key: K): DOMNodeCache[K] | undefined;
1303
+ cacheGet(key: string | number | symbol): any | undefined;
1391
1304
  /**
1392
- * Returns the first child element or null if there are no child elements.
1305
+ * Store a value in cache.
1306
+ *
1307
+ * @returns the value itself is returned.
1393
1308
  */
1394
- get firstElementChild(): HtmlElement | null;
1309
+ cacheSet<K extends keyof DOMNodeCache>(key: K, value: DOMNodeCache[K]): DOMNodeCache[K];
1310
+ cacheSet<T>(key: string | number | symbol, value: T): T;
1395
1311
  /**
1396
- * Returns the last child element or null if there are no child elements.
1312
+ * Remove a value by key from cache.
1313
+ *
1314
+ * @returns `true` if the entry existed and has been removed.
1397
1315
  */
1398
- get lastElementChild(): HtmlElement | null;
1399
- get siblings(): HtmlElement[];
1400
- get previousSibling(): HtmlElement | null;
1401
- get nextSibling(): HtmlElement | null;
1402
- getElementsByTagName(tagName: string): HtmlElement[];
1403
- querySelector(selector: string): HtmlElement;
1404
- querySelectorAll(selector: string): HtmlElement[];
1405
- private querySelectorImpl;
1316
+ cacheRemove<K extends keyof DOMNodeCache>(key: K): boolean;
1317
+ cacheRemove(key: string | number | symbol): boolean;
1406
1318
  /**
1407
- * Visit all nodes from this node and down. Depth first.
1408
- *
1409
- * @internal
1319
+ * Check if key exists in cache.
1410
1320
  */
1411
- visitDepthFirst(callback: (node: HtmlElement) => void): void;
1321
+ cacheExists<K extends keyof DOMNodeCache>(key: K): boolean;
1322
+ cacheExists(key: string | number | symbol): boolean;
1412
1323
  /**
1413
- * Evaluates callbackk on all descendants, returning true if any are true.
1414
- *
1415
- * @internal
1324
+ * Get the text (recursive) from all child nodes.
1416
1325
  */
1417
- someChildren(callback: (node: HtmlElement) => boolean): boolean;
1326
+ get textContent(): string;
1327
+ append(node: DOMNode): void;
1328
+ isRootElement(): boolean;
1418
1329
  /**
1419
- * Evaluates callbackk on all descendants, returning true if all are true.
1420
- *
1421
- * @internal
1330
+ * Tests if two nodes are the same (references the same object).
1422
1331
  */
1423
- everyChildren(callback: (node: HtmlElement) => boolean): boolean;
1332
+ isSameNode(otherNode: DOMNode): boolean;
1424
1333
  /**
1425
- * Visit all nodes from this node and down. Breadth first.
1426
- *
1427
- * The first node for which the callback evaluates to true is returned.
1428
- *
1429
- * @internal
1334
+ * Returns a DOMNode representing the first direct child node or `null` if the
1335
+ * node has no children.
1430
1336
  */
1431
- find(callback: (node: HtmlElement) => boolean): HtmlElement | null;
1432
- }
1433
-
1434
- declare class DOMTree {
1435
- readonly root: HtmlElement;
1436
- private active;
1437
- doctype: string | null;
1438
- constructor(location: Location);
1439
- pushActive(node: HtmlElement): void;
1440
- popActive(): void;
1441
- getActive(): HtmlElement;
1337
+ get firstChild(): DOMNode;
1442
1338
  /**
1443
- * Resolve dynamic meta expressions.
1339
+ * Returns a DOMNode representing the last direct child node or `null` if the
1340
+ * node has no children.
1444
1341
  */
1445
- resolveMeta(table: MetaTable): void;
1446
- getElementsByTagName(tagName: string): HtmlElement[];
1447
- visitDepthFirst(callback: (node: HtmlElement) => void): void;
1448
- find(callback: (node: HtmlElement) => boolean): HtmlElement | null;
1449
- querySelector(selector: string): HtmlElement;
1450
- querySelectorAll(selector: string): HtmlElement[];
1451
- }
1452
-
1453
- /**
1454
- * Represents a text in the HTML document.
1455
- *
1456
- * Text nodes are appended as children of `HtmlElement` and cannot have childen
1457
- * of its own.
1458
- *
1459
- * @public
1460
- */
1461
- declare class TextNode extends DOMNode {
1462
- private readonly text;
1342
+ get lastChild(): DOMNode;
1463
1343
  /**
1464
- * @param text - Text to add. When a `DynamicValue` is used the expression is
1465
- * used as "text".
1466
- * @param location - Source code location of this node.
1344
+ * Disable a rule for this node.
1345
+ */
1346
+ disableRule(ruleId: string): void;
1347
+ /**
1348
+ * Disables multiple rules.
1467
1349
  */
1468
- constructor(text: string | DynamicValue, location: Location);
1350
+ disableRules(rules: string[]): void;
1469
1351
  /**
1470
- * Get the text from node.
1352
+ * Enable a previously disabled rule for this node.
1471
1353
  */
1472
- get textContent(): string;
1354
+ enableRule(ruleId: string): void;
1473
1355
  /**
1474
- * Flag set to true if the attribute value is static.
1356
+ * Enables multiple rules.
1475
1357
  */
1476
- get isStatic(): boolean;
1358
+ enableRules(rules: string[]): void;
1477
1359
  /**
1478
- * Flag set to true if the attribute value is dynamic.
1360
+ * Test if a rule is enabled for this node.
1479
1361
  */
1480
- get isDynamic(): boolean;
1362
+ ruleEnabled(ruleId: string): boolean;
1363
+ generateSelector(): string | null;
1364
+ }
1365
+
1366
+ declare class DOMTokenList extends Array<string> {
1367
+ readonly value: string;
1368
+ private readonly locations;
1369
+ constructor(value: string | DynamicValue | null, location: Location | null);
1370
+ item(n: number): string | undefined;
1371
+ location(n: number): Location | undefined;
1372
+ contains(token: string): boolean;
1373
+ iterator(): Generator<{
1374
+ index: number;
1375
+ item: string;
1376
+ location: Location;
1377
+ }>;
1481
1378
  }
1482
1379
 
1483
1380
  /**
1484
1381
  * @public
1485
1382
  */
1486
- interface TransformContext {
1383
+ declare enum NodeClosed {
1384
+ Open = 0,
1385
+ EndTag = 1,
1386
+ VoidOmitted = 2,
1387
+ VoidSelfClosed = 3,
1388
+ ImplicitClosed = 4
1389
+ }
1390
+ /**
1391
+ * @public
1392
+ */
1393
+ declare class HtmlElement extends DOMNode {
1394
+ readonly tagName: string;
1395
+ readonly parent: HtmlElement | null;
1396
+ readonly voidElement: boolean;
1397
+ readonly depth: number;
1398
+ closed: NodeClosed;
1399
+ protected readonly attr: {
1400
+ [key: string]: Attribute[];
1401
+ };
1402
+ private metaElement;
1403
+ private annotation;
1404
+ constructor(tagName: string | undefined, parent: HtmlElement | null, closed: NodeClosed, meta: MetaElement | null, location: Location);
1487
1405
  /**
1488
- * Test if an additional chainable transformer is present.
1489
- *
1490
- * Returns true only if there is a transformer configured for the given
1491
- * filename.
1492
- *
1493
- * @param filename - Filename to use to match next transformer.
1406
+ * @internal
1494
1407
  */
1495
- hasChain(filename: string): boolean;
1408
+ static rootNode(location: Location): HtmlElement;
1496
1409
  /**
1497
- * Chain transformations.
1410
+ * @internal
1498
1411
  *
1499
- * Sometimes multiple transformers must be applied. For instance, a Markdown
1500
- * file with JSX in a code-block.
1412
+ * @param namespace - If given it is appended to the tagName.
1413
+ */
1414
+ static fromTokens(startToken: TagOpenToken, endToken: TagCloseToken, parent: HtmlElement | null, metaTable: MetaTable | null, namespace?: string): HtmlElement;
1415
+ /**
1416
+ * Returns annotated name if set or defaults to `<tagName>`.
1501
1417
  *
1502
- * @param source - Source to chain transformations on.
1503
- * @param filename - Filename to use to match next transformer (unrelated to
1504
- * filename set in source)
1418
+ * E.g. `my-annotation` or `<div>`.
1505
1419
  */
1506
- chain(source: Source, filename: string): Iterable<Source>;
1507
- }
1508
-
1509
- declare module "estree" {
1510
- interface TemplateElement {
1511
- start: number;
1512
- end: number;
1513
- }
1514
- }
1515
- /**
1516
- * @public
1517
- */
1518
- declare class TemplateExtractor {
1519
- private ast;
1520
- private filename;
1521
- private data;
1522
- private constructor();
1523
- static fromFilename(filename: string): TemplateExtractor;
1420
+ get annotatedName(): string;
1524
1421
  /**
1525
- * Create a new [[TemplateExtractor]] from javascript source code.
1422
+ * Get list of IDs referenced by `aria-labelledby`.
1526
1423
  *
1527
- * `Source` offsets will be relative to the string, i.e. offset 0 is the first
1528
- * character of the string. If the string is only a subset of a larger string
1529
- * the offsets must be adjusted manually.
1424
+ * If the attribute is unset or empty this getter returns null.
1425
+ * If the attribute is dynamic the original {@link DynamicValue} is returned.
1530
1426
  *
1531
- * @param source - Source code.
1532
- * @param filename - Optional filename to set in the resulting
1533
- * `Source`. Defauls to `"inline"`.
1427
+ * @public
1534
1428
  */
1535
- static fromString(source: string, filename?: string): TemplateExtractor;
1429
+ get ariaLabelledby(): string[] | DynamicValue | null;
1536
1430
  /**
1537
- * Convenience function to create a [[Source]] instance from an existing file.
1431
+ * Similar to childNodes but only elements.
1432
+ */
1433
+ get childElements(): HtmlElement[];
1434
+ /**
1435
+ * Find the first ancestor matching a selector.
1538
1436
  *
1539
- * @param filename - Filename with javascript source code. The file must exist
1540
- * and be readable by the user.
1541
- * @returns An array of Source's suitable for passing to [[Engine]] linting
1542
- * functions.
1437
+ * Implementation of DOM specification of Element.closest(selectors).
1543
1438
  */
1544
- static createSource(filename: string): Source[];
1439
+ closest(selectors: string): HtmlElement | null;
1545
1440
  /**
1546
- * Extract object properties.
1441
+ * Generate a DOM selector for this element. The returned selector will be
1442
+ * unique inside the current document.
1443
+ */
1444
+ generateSelector(): string | null;
1445
+ /**
1446
+ * Tests if this element has given tagname.
1547
1447
  *
1548
- * Given a key `"template"` this method finds all objects literals with a
1549
- * `"template"` property and creates a [[Source]] instance with proper offsets
1550
- * with the value of the property. For instance:
1448
+ * If passing "*" this test will pass if any tagname is set.
1449
+ */
1450
+ is(tagName: string): boolean;
1451
+ /**
1452
+ * Load new element metadata onto this element.
1551
1453
  *
1552
- * ```
1553
- * const myObj = {
1554
- * foo: 'bar',
1555
- * };
1556
- * ```
1454
+ * Do note that semantics such as `void` cannot be changed (as the element has
1455
+ * already been created). In addition the element will still "be" the same
1456
+ * element, i.e. even if loading meta for a `<p>` tag upon a `<div>` tag it
1457
+ * will still be a `<div>` as far as the rest of the validator is concerned.
1557
1458
  *
1558
- * The above snippet would yield a `Source` with the content `bar`.
1459
+ * In fact only certain properties will be copied onto the element:
1559
1460
  *
1560
- */
1561
- extractObjectProperty(key: string): Source[];
1562
- }
1563
-
1564
- /**
1565
- * @public
1566
- */
1567
- declare type Transformer = (this: TransformContext, source: Source) => Iterable<Source>;
1568
-
1569
- interface SchemaValidationPatch {
1570
- properties?: Record<string, unknown>;
1571
- definitions?: Record<string, unknown>;
1572
- }
1573
- /**
1574
- * @public
1575
- */
1576
- interface Plugin {
1577
- /**
1578
- * Name of the plugin.
1461
+ * - content categories (flow, phrasing, etc)
1462
+ * - required attributes
1463
+ * - attribute allowed values
1464
+ * - permitted/required elements
1579
1465
  *
1580
- * If specified this is the name used when referring to the plugin. Default is
1581
- * to use the name/path the user used when loading the plugin. To be less
1582
- * confusing for users you should use the same name as your package.
1466
+ * Properties *not* loaded:
1583
1467
  *
1584
- * The name must be a valid package name according to NPM (basically lowercase
1585
- * characters, must not begin with dot, slash or non-url safe characters).
1468
+ * - inherit
1469
+ * - deprecated
1470
+ * - foreign
1471
+ * - void
1472
+ * - implicitClosed
1473
+ * - scriptSupporting
1474
+ * - deprecatedAttributes
1586
1475
  *
1587
- * Hint: import and use the name from `package.json`.
1476
+ * Changes to element metadata will only be visible after `element:ready` (and
1477
+ * the subsequent `dom:ready` event).
1588
1478
  */
1589
- name?: string | null;
1479
+ loadMeta(meta: MetaElement): void;
1590
1480
  /**
1591
- * Initialization callback.
1481
+ * Match this element against given selectors. Returns true if any selector
1482
+ * matches.
1592
1483
  *
1593
- * Called once per plugin during initialization.
1484
+ * Implementation of DOM specification of Element.matches(selectors).
1594
1485
  */
1595
- init?: () => void | null;
1486
+ matches(selector: string): boolean;
1487
+ get meta(): MetaElement | null;
1596
1488
  /**
1597
- * Setup callback.
1598
- *
1599
- * Called once per source after engine is initialized.
1600
- *
1601
- * @param source - The source about to be validated. Readonly.
1602
- * @param eventhandler - Eventhandler from parser. Can be used to listen for
1603
- * parser events.
1489
+ * Set annotation for this element.
1604
1490
  */
1605
- setup?: (source: Source, eventhandler: EventHandler) => void | null;
1491
+ setAnnotation(text: string): void;
1606
1492
  /**
1607
- * Configuration presets.
1608
- *
1609
- * Each key should be the unprefixed name which a configuration later can
1610
- * access using `${plugin}:${key}`, e.g. if a plugin named "my-plugin" exposes
1611
- * a preset named "foobar" it can be accessed using:
1493
+ * Set attribute. Stores all attributes set even with the same name.
1612
1494
  *
1613
- * "extends": ["my-plugin:foobar"]
1495
+ * @param key - Attribute name
1496
+ * @param value - Attribute value. Use `null` if no value is present.
1497
+ * @param keyLocation - Location of the attribute name.
1498
+ * @param valueLocation - Location of the attribute value (excluding quotation)
1499
+ * @param originalAttribute - If attribute is an alias for another attribute
1500
+ * (dynamic attributes) set this to the original attribute name.
1614
1501
  */
1615
- configs?: Record<string, ConfigData | null> | null;
1502
+ setAttribute(key: string, value: string | DynamicValue | null, keyLocation: Location, valueLocation: Location | null, originalAttribute?: string): void;
1616
1503
  /**
1617
- * List of new rules present.
1504
+ * Get a list of all attributes on this node.
1618
1505
  */
1619
- rules?: Record<string, RuleConstructor<any, any> | null> | null;
1506
+ get attributes(): Attribute[];
1507
+ hasAttribute(key: string): boolean;
1620
1508
  /**
1621
- * Transformer available in this plugin.
1509
+ * Get attribute.
1622
1510
  *
1623
- * Can be given either as a single unnamed transformer or an object with
1624
- * multiple named.
1511
+ * By default only the first attribute is returned but if the code needs to
1512
+ * handle duplicate attributes the `all` parameter can be set to get all
1513
+ * attributes with given key.
1625
1514
  *
1626
- * Unnamed transformers use the plugin name similar to how a standalone
1627
- * transformer would work:
1515
+ * This usually only happens when code contains duplicate attributes (which
1516
+ * `no-dup-attr` will complain about) or when a static attribute is combined
1517
+ * with a dynamic, consider:
1628
1518
  *
1629
- * ```
1630
- * "transform": {
1631
- * "^.*\\.foo$": "my-plugin"
1632
- * }
1633
- * ```
1519
+ * <p class="foo" dynamic-class="bar">
1634
1520
  *
1635
- * For named transformers each key should be the unprefixed name which a
1636
- * configuration later can access using `${plugin}:${key}`, e.g. if a plugin
1637
- * named "my-plugin" exposes a transformer named "foobar" it can be accessed
1638
- * using:
1521
+ * @param key - Attribute name
1522
+ * @param all - Return single or all attributes.
1523
+ */
1524
+ getAttribute(key: string): Attribute | null;
1525
+ getAttribute(key: string, all: true): Attribute[];
1526
+ /**
1527
+ * Get attribute value.
1528
+ *
1529
+ * Returns the attribute value if present.
1530
+ *
1531
+ * - Missing attributes return `null`.
1532
+ * - Boolean attributes return `null`.
1533
+ * - `DynamicValue` returns attribute expression.
1639
1534
  *
1640
- * ```
1641
- * "transform": {
1642
- * "^.*\\.foo$": "my-plugin:foobar"
1643
- * }
1644
- * ```
1535
+ * @param key - Attribute name
1536
+ * @returns Attribute value or null.
1645
1537
  */
1646
- transformer?: Transformer | Record<string, Transformer | null> | null;
1538
+ getAttributeValue(key: string): string | null;
1647
1539
  /**
1648
- * Extend metadata validation schema.
1540
+ * Add text as a child node to this element.
1541
+ *
1542
+ * @param text - Text to add.
1543
+ * @param location - Source code location of this text.
1649
1544
  */
1650
- elementSchema?: SchemaValidationPatch | null;
1651
- }
1652
-
1653
- /**
1654
- * @public
1655
- */
1656
- declare class MetaTable {
1657
- readonly elements: ElementTable;
1658
- private schema;
1545
+ appendText(text: string | DynamicValue, location: Location): void;
1659
1546
  /**
1660
- * @internal
1547
+ * Return a list of all known classes on the element. Dynamic values are
1548
+ * ignored.
1661
1549
  */
1662
- constructor();
1550
+ get classList(): DOMTokenList;
1663
1551
  /**
1664
- * @internal
1552
+ * Get element ID if present.
1665
1553
  */
1666
- init(): void;
1554
+ get id(): string | null;
1555
+ get style(): CSSStyleDeclaration;
1667
1556
  /**
1668
- * Extend validation schema.
1669
- *
1670
- * @internal
1557
+ * Returns the first child element or null if there are no child elements.
1671
1558
  */
1672
- extendValidationSchema(patch: SchemaValidationPatch): void;
1559
+ get firstElementChild(): HtmlElement | null;
1673
1560
  /**
1674
- * Load metadata table from object.
1561
+ * Returns the last child element or null if there are no child elements.
1562
+ */
1563
+ get lastElementChild(): HtmlElement | null;
1564
+ get siblings(): HtmlElement[];
1565
+ get previousSibling(): HtmlElement | null;
1566
+ get nextSibling(): HtmlElement | null;
1567
+ getElementsByTagName(tagName: string): HtmlElement[];
1568
+ querySelector(selector: string): HtmlElement;
1569
+ querySelectorAll(selector: string): HtmlElement[];
1570
+ private querySelectorImpl;
1571
+ /**
1572
+ * Visit all nodes from this node and down. Depth first.
1675
1573
  *
1676
1574
  * @internal
1677
- * @param obj - Object with metadata to load
1678
- * @param filename - Optional filename used when presenting validation error
1679
1575
  */
1680
- loadFromObject(obj: unknown, filename?: string | null): void;
1576
+ visitDepthFirst(callback: (node: HtmlElement) => void): void;
1681
1577
  /**
1682
- * Load metadata table from filename
1578
+ * Evaluates callbackk on all descendants, returning true if any are true.
1683
1579
  *
1684
1580
  * @internal
1685
- * @param filename - Filename to load
1686
1581
  */
1687
- loadFromFile(filename: string): void;
1582
+ someChildren(callback: (node: HtmlElement) => boolean): boolean;
1688
1583
  /**
1689
- * Get [[MetaElement]] for the given tag. If no specific metadata is present
1690
- * the global metadata is returned or null if no global is present.
1584
+ * Evaluates callbackk on all descendants, returning true if all are true.
1691
1585
  *
1692
- * @public
1693
- * @returns A shallow copy of metadata.
1586
+ * @internal
1694
1587
  */
1695
- getMetaFor(tagName: string): MetaElement | null;
1588
+ everyChildren(callback: (node: HtmlElement) => boolean): boolean;
1696
1589
  /**
1697
- * Find all tags which has enabled given property.
1590
+ * Visit all nodes from this node and down. Breadth first.
1698
1591
  *
1699
- * @public
1592
+ * The first node for which the callback evaluates to true is returned.
1593
+ *
1594
+ * @internal
1700
1595
  */
1701
- getTagsWithProperty(propName: MetaLookupableProperty): string[];
1596
+ find(callback: (node: HtmlElement) => boolean): HtmlElement | null;
1597
+ }
1598
+
1599
+ declare class DOMTree {
1600
+ readonly root: HtmlElement;
1601
+ private active;
1602
+ doctype: string | null;
1603
+ constructor(location: Location);
1604
+ pushActive(node: HtmlElement): void;
1605
+ popActive(): void;
1606
+ getActive(): HtmlElement;
1702
1607
  /**
1703
- * Find tag matching tagName or inheriting from it.
1704
- *
1705
- * @public
1608
+ * Resolve dynamic meta expressions.
1706
1609
  */
1707
- getTagsDerivedFrom(tagName: string): string[];
1708
- private addEntry;
1610
+ resolveMeta(table: MetaTable): void;
1611
+ getElementsByTagName(tagName: string): HtmlElement[];
1612
+ visitDepthFirst(callback: (node: HtmlElement) => void): void;
1613
+ find(callback: (node: HtmlElement) => boolean): HtmlElement | null;
1614
+ querySelector(selector: string): HtmlElement;
1615
+ querySelectorAll(selector: string): HtmlElement[];
1616
+ }
1617
+
1618
+ /**
1619
+ * Represents a text in the HTML document.
1620
+ *
1621
+ * Text nodes are appended as children of `HtmlElement` and cannot have childen
1622
+ * of its own.
1623
+ *
1624
+ * @public
1625
+ */
1626
+ declare class TextNode extends DOMNode {
1627
+ private readonly text;
1709
1628
  /**
1710
- * Construct a new AJV schema validator.
1629
+ * @param text - Text to add. When a `DynamicValue` is used the expression is
1630
+ * used as "text".
1631
+ * @param location - Source code location of this node.
1711
1632
  */
1712
- private getSchemaValidator;
1633
+ constructor(text: string | DynamicValue, location: Location);
1713
1634
  /**
1714
- * @public
1635
+ * Get the text from node.
1715
1636
  */
1716
- getJSONSchema(): SchemaObject;
1637
+ get textContent(): string;
1717
1638
  /**
1718
- * Finds the global element definition and merges each known element with the
1719
- * global, e.g. to assign global attributes.
1639
+ * Flag set to true if the attribute value is static.
1720
1640
  */
1721
- private resolveGlobal;
1722
- private mergeElement;
1641
+ get isStatic(): boolean;
1723
1642
  /**
1724
- * @internal
1643
+ * Flag set to true if the attribute value is dynamic.
1725
1644
  */
1726
- resolve(node: HtmlElement): void;
1645
+ get isDynamic(): boolean;
1646
+ }
1647
+
1648
+ interface PermittedGroup {
1649
+ exclude?: string | string[];
1650
+ }
1651
+ declare type CategoryOrTag = string;
1652
+ declare type PropertyExpression = string | [string, any];
1653
+ declare type PermittedEntry = CategoryOrTag | PermittedGroup | Array<CategoryOrTag | PermittedGroup>;
1654
+ declare type Permitted = PermittedEntry[];
1655
+ declare type PermittedOrder = string[];
1656
+ declare type RequiredAncestors = string[];
1657
+ declare type RequiredContent = string[];
1658
+ declare enum TextContent {
1659
+ NONE = "none",
1660
+ DEFAULT = "default",
1661
+ REQUIRED = "required",
1662
+ ACCESSIBLE = "accessible"
1663
+ }
1664
+ /**
1665
+ * Callback for the `allowed` property of `MetaAttribute`. It takes a node and
1666
+ * should return `null` if there is no errors and a string with an error
1667
+ * description if there is an error.
1668
+ *
1669
+ * @public
1670
+ */
1671
+ declare type MetaAttributeAllowedCallback = (node: HtmlElement) => string | null | undefined;
1672
+ /**
1673
+ * @public
1674
+ */
1675
+ interface MetaAttribute {
1676
+ allowed?: MetaAttributeAllowedCallback;
1677
+ boolean?: boolean;
1678
+ deprecated?: boolean | string;
1679
+ enum?: Array<string | RegExp>;
1680
+ list?: boolean;
1681
+ omit?: boolean;
1682
+ required?: boolean;
1683
+ }
1684
+ declare type PermittedAttribute = Record<string, MetaAttribute | Array<string | RegExp> | null>;
1685
+ interface DeprecatedElement {
1686
+ message?: string;
1687
+ documentation?: string;
1688
+ source?: string;
1689
+ }
1690
+ /**
1691
+ * @public
1692
+ */
1693
+ interface MetaData {
1694
+ inherit?: string;
1695
+ metadata?: boolean | PropertyExpression;
1696
+ flow?: boolean | PropertyExpression;
1697
+ sectioning?: boolean | PropertyExpression;
1698
+ heading?: boolean | PropertyExpression;
1699
+ phrasing?: boolean | PropertyExpression;
1700
+ embedded?: boolean | PropertyExpression;
1701
+ interactive?: boolean | PropertyExpression;
1702
+ deprecated?: boolean | string | DeprecatedElement;
1703
+ foreign?: boolean;
1704
+ void?: boolean;
1705
+ transparent?: boolean | string[];
1706
+ implicitClosed?: string[];
1707
+ scriptSupporting?: boolean;
1708
+ form?: boolean;
1709
+ labelable?: boolean | PropertyExpression;
1710
+ deprecatedAttributes?: string[];
1711
+ requiredAttributes?: string[];
1712
+ attributes?: PermittedAttribute;
1713
+ permittedContent?: Permitted;
1714
+ permittedDescendants?: Permitted;
1715
+ permittedOrder?: PermittedOrder;
1716
+ permittedParent?: Permitted;
1717
+ requiredAncestors?: RequiredAncestors;
1718
+ requiredContent?: RequiredContent;
1719
+ textContent?: TextContent | `${TextContent}`;
1720
+ }
1721
+ /**
1722
+ * Properties listed here can be used to reverse search elements with the given
1723
+ * property enabled. See [[MetaTable.getTagsWithProperty]].
1724
+ */
1725
+ declare type MetaLookupableProperty = "metadata" | "flow" | "sectioning" | "heading" | "phrasing" | "embedded" | "interactive" | "deprecated" | "foreign" | "void" | "transparent" | "scriptSupporting" | "form" | "labelable";
1726
+ /**
1727
+ * Properties listed here can be copied (loaded) onto another element using
1728
+ * [[HtmlElement.loadMeta]].
1729
+ *
1730
+ * @public
1731
+ */
1732
+ declare const MetaCopyableProperty: Array<keyof MetaElement>;
1733
+ /**
1734
+ * @public
1735
+ */
1736
+ interface MetaElement extends Omit<MetaData, "deprecatedAttributes" | "requiredAttributes"> {
1737
+ tagName: string;
1738
+ attributes: Record<string, MetaAttribute>;
1739
+ textContent?: TextContent;
1740
+ }
1741
+ interface MetaDataTable {
1742
+ [tagName: string]: MetaData;
1743
+ }
1744
+ interface ElementTable {
1745
+ [tagName: string]: MetaElement;
1727
1746
  }
1728
1747
 
1748
+ /**
1749
+ * Helper function to assist IDE with completion and type-checking.
1750
+ *
1751
+ * @public
1752
+ */
1753
+ declare function defineMetadata(metatable: MetaDataTable): MetaDataTable;
1754
+
1755
+ /**
1756
+ * Helpers when writing element metadata.
1757
+ *
1758
+ * @public
1759
+ */
1760
+ interface MetadataHelper {
1761
+ /** Returns an error if another attribute is omitted, i.e. it requires another attribute to be present to pass. */
1762
+ allowedIfAttributeIsPresent(...attr: string[]): MetaAttributeAllowedCallback;
1763
+ /** Returns an error if another attribute is present, i.e. it requires another attribute to be omitted to pass. */
1764
+ allowedIfAttributeIsAbsent(...attr: string[]): MetaAttributeAllowedCallback;
1765
+ /** Returns an error if another attribute does not have one of the listed values */
1766
+ allowedIfAttributeHasValue(attr: string, value: string[], options?: {
1767
+ defaultValue?: string | null;
1768
+ }): MetaAttributeAllowedCallback;
1769
+ }
1770
+ declare const metadataHelper: MetadataHelper;
1771
+
1729
1772
  /**
1730
1773
  * @public
1731
1774
  */
@@ -2239,6 +2282,48 @@ declare class StaticConfigLoader extends ConfigLoader {
2239
2282
  /** @public */
2240
2283
  declare const version: string;
2241
2284
 
2285
+ declare const HTML_CACHE_KEY: unique symbol;
2286
+ declare const A11Y_CACHE_KEY: unique symbol;
2287
+ declare const IGNORE_HIDDEN_ROOT_HTML_CACHE_KEY: unique symbol;
2288
+ declare const IGNORE_HIDDEN_ROOT_A11Y_CACHE_KEY: unique symbol;
2289
+ /**
2290
+ * @public
2291
+ */
2292
+ declare enum TextClassification {
2293
+ EMPTY_TEXT = 0,
2294
+ DYNAMIC_TEXT = 1,
2295
+ STATIC_TEXT = 2
2296
+ }
2297
+ /**
2298
+ * @public
2299
+ */
2300
+ interface TextClassificationOptions {
2301
+ /** If `true` only accessible text is considered (default false) */
2302
+ accessible?: boolean;
2303
+ /** If `true` the `hidden` and `aria-hidden` attribute is ignored on the root
2304
+ * (and parents) elements (default false) */
2305
+ ignoreHiddenRoot?: boolean;
2306
+ }
2307
+ declare module "../../dom/cache" {
2308
+ interface DOMNodeCache {
2309
+ [HTML_CACHE_KEY]: TextClassification;
2310
+ [A11Y_CACHE_KEY]: TextClassification;
2311
+ [IGNORE_HIDDEN_ROOT_HTML_CACHE_KEY]: TextClassification;
2312
+ [IGNORE_HIDDEN_ROOT_A11Y_CACHE_KEY]: TextClassification;
2313
+ }
2314
+ }
2315
+ /**
2316
+ * Checks text content of an element.
2317
+ *
2318
+ * Any text is considered including text from descendant elements. Whitespace is
2319
+ * ignored.
2320
+ *
2321
+ * If any text is dynamic `TextClassification.DYNAMIC_TEXT` is returned.
2322
+ *
2323
+ * @public
2324
+ */
2325
+ declare function classifyNodeText(node: HtmlElement, options?: TextClassificationOptions): TextClassification;
2326
+
2242
2327
  /**
2243
2328
  * @public
2244
2329
  */
@@ -2345,4 +2430,4 @@ declare type Formatter = (results: Result[]) => string;
2345
2430
  */
2346
2431
  declare function getFormatter(name: string): Formatter | null;
2347
2432
 
2348
- export { ElementReadyEvent as $, AttributeData as A, Parser as B, Config as C, DynamicValue as D, EventDump as E, ruleExists as F, EventHandler as G, HtmlValidate as H, EventCallback as I, Event as J, ConfigReadyEvent as K, Location as L, MetaData as M, NodeClosed as N, SourceReadyEvent as O, ProcessElementContext as P, TokenEvent as Q, Rule as R, Severity as S, TextNode as T, UserError as U, TagStartEvent as V, WrappedError as W, TagOpenEvent as X, TagEndEvent as Y, TagCloseEvent as Z, TagReadyEvent as _, ConfigData as a, AttributeEvent as a0, WhitespaceEvent as a1, ConditionalEvent as a2, DirectiveEvent as a3, DoctypeEvent as a4, DOMLoadEvent as a5, DOMReadyEvent as a6, TriggerEventMap as a7, ListenEventMap as a8, FileSystemConfigLoader as a9, Formatter as aa, getFormatter as ab, compatibilityCheck as ac, CompatibilityOptions as ad, ConfigError as b, ConfigLoader as c, StaticConfigLoader as d, HtmlElement as e, CSSStyleDeclaration as f, TokenDump as g, SchemaValidationError as h, NestedError as i, MetaDataTable as j, MetaElement as k, MetaTable as l, MetaCopyableProperty as m, RuleDocumentation as n, Source as o, presets as p, Report as q, Reporter as r, Message as s, Result as t, DeferredMessage as u, version as v, TransformContext as w, Transformer as x, TemplateExtractor as y, Plugin as z };
2433
+ export { TokenEvent as $, AttributeData as A, Result as B, Config as C, DynamicValue as D, EventDump as E, DeferredMessage as F, TransformContext as G, HtmlValidate as H, Transformer as I, TemplateExtractor as J, Plugin as K, Location as L, MetaData as M, NodeClosed as N, Parser as O, ProcessElementContext as P, ruleExists as Q, Rule as R, Severity as S, TextNode as T, UserError as U, EventHandler as V, WrappedError as W, EventCallback as X, Event as Y, ConfigReadyEvent as Z, SourceReadyEvent as _, ConfigData as a, TagStartEvent as a0, TagOpenEvent as a1, TagEndEvent as a2, TagCloseEvent as a3, TagReadyEvent as a4, ElementReadyEvent as a5, AttributeEvent as a6, WhitespaceEvent as a7, ConditionalEvent as a8, DirectiveEvent as a9, DoctypeEvent as aa, DOMLoadEvent as ab, DOMReadyEvent as ac, TriggerEventMap as ad, ListenEventMap as ae, FileSystemConfigLoader as af, Formatter as ag, getFormatter as ah, compatibilityCheck as ai, CompatibilityOptions as aj, ConfigError as b, ConfigLoader as c, StaticConfigLoader as d, HtmlElement as e, CSSStyleDeclaration as f, TokenDump as g, SchemaValidationError as h, NestedError as i, MetaDataTable as j, MetaElement as k, MetaAttribute as l, MetaAttributeAllowedCallback as m, MetaTable as n, MetaCopyableProperty as o, presets as p, defineMetadata as q, metadataHelper as r, RuleDocumentation as s, classifyNodeText as t, TextClassification as u, version as v, Source as w, Report as x, Reporter as y, Message as z };