html-validate 6.9.1 → 6.10.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.
@@ -1,3 +1,2 @@
1
1
  export { A as AttributeData, $ as AttributeEvent, f as CSSStyleDeclaration, a1 as ConditionalEvent, C as Config, a as ConfigData, b as ConfigError, c as ConfigLoader, J as ConfigReadyEvent, a4 as DOMLoadEvent, a5 as DOMReadyEvent, t as DeferredMessage, a2 as DirectiveEvent, a3 as DoctypeEvent, D as DynamicValue, _ as ElementReadyEvent, I as Event, G as EventCallback, E as EventDump, F as EventHandler, e as HtmlElement, H as HtmlValidate, a7 as ListenEventMap, L as Location, r as Message, l as MetaCopyableProperty, M as MetaData, j as MetaElement, k as MetaTable, i as NestedError, N as NodeClosed, z as Parser, y as Plugin, P as ProcessElementContext, o as Report, q as Reporter, s as Result, R as Rule, m as RuleDocumentation, h as SchemaValidationError, S as Severity, n as Source, K as SourceReadyEvent, d as StaticConfigLoader, Y as TagCloseEvent, X as TagEndEvent, V as TagOpenEvent, Z as TagReadyEvent, Q as TagStartEvent, x as TemplateExtractor, T as TextNode, g as TokenDump, O as TokenEvent, u as TransformContext, w as Transformer, a6 as TriggerEventMap, U as UserError, a0 as WhitespaceEvent, W as WrappedError, p as configPresets, B as ruleExists, v as version } from './core.js';
2
2
  import 'ajv';
3
- import 'ajv/dist/types';
@@ -1,5 +1,4 @@
1
1
  import { SchemaObject, ErrorObject } from 'ajv';
2
- import { SchemaObject as SchemaObject$1 } from 'ajv/dist/types';
3
2
 
4
3
  /** @internal */
5
4
  declare type EventCallback = (event: string, data: any) => void;
@@ -1699,7 +1698,7 @@ declare class MetaTable {
1699
1698
  /**
1700
1699
  * @public
1701
1700
  */
1702
- getJSONSchema(): SchemaObject$1;
1701
+ getJSONSchema(): SchemaObject;
1703
1702
  /**
1704
1703
  * Finds the global element definition and merges each known element with the
1705
1704
  * global, e.g. to assign global attributes.
package/dist/cjs/core.js CHANGED
@@ -363,6 +363,32 @@ class SchemaValidationError extends UserError {
363
363
  }
364
364
  }
365
365
 
366
+ /**
367
+ * Computes hash for given string.
368
+ *
369
+ * @internal
370
+ */
371
+ function cyrb53(str) {
372
+ const a = 2654435761;
373
+ const b = 1597334677;
374
+ const c = 2246822507;
375
+ const d = 3266489909;
376
+ const e = 4294967296;
377
+ const f = 2097151;
378
+ const seed = 0;
379
+ let h1 = 0xdeadbeef ^ seed;
380
+ let h2 = 0x41c6ce57 ^ seed;
381
+ for (let i = 0, ch; i < str.length; i++) {
382
+ ch = str.charCodeAt(i);
383
+ h1 = Math.imul(h1 ^ ch, a);
384
+ h2 = Math.imul(h2 ^ ch, b);
385
+ }
386
+ h1 = Math.imul(h1 ^ (h1 >>> 16), c) ^ Math.imul(h2 ^ (h2 >>> 13), d);
387
+ h2 = Math.imul(h2 ^ (h2 >>> 16), c) ^ Math.imul(h1 ^ (h1 >>> 13), d);
388
+ return e * (f & h2) + (h1 >>> 0);
389
+ }
390
+ const computeHash = cyrb53;
391
+
366
392
  const projectRoot = path__default["default"].resolve(__dirname, "../../");
367
393
  const legacyRequire = require;
368
394
  const distFolder = path__default["default"].resolve(projectRoot, "dist/cjs");
@@ -767,6 +793,35 @@ var schema = {
767
793
  definitions: definitions
768
794
  };
769
795
 
796
+ /**
797
+ * AJV keyword "regexp" to validate the type to be a regular expression.
798
+ * Injects errors with the "type" keyword to give the same output.
799
+ */
800
+ /* istanbul ignore next: manual testing */
801
+ const ajvRegexpValidate = function (data, dataCxt) {
802
+ const valid = data instanceof RegExp;
803
+ if (!valid) {
804
+ ajvRegexpValidate.errors = [
805
+ {
806
+ instancePath: dataCxt === null || dataCxt === void 0 ? void 0 : dataCxt.instancePath,
807
+ schemaPath: undefined,
808
+ keyword: "type",
809
+ message: "should be a regular expression",
810
+ params: {
811
+ keyword: "type",
812
+ },
813
+ },
814
+ ];
815
+ }
816
+ return valid;
817
+ };
818
+ const ajvRegexpKeyword = {
819
+ keyword: "regexp",
820
+ schema: false,
821
+ errors: true,
822
+ validate: ajvRegexpValidate,
823
+ };
824
+
770
825
  var TextContent$1;
771
826
  (function (TextContent) {
772
827
  /* forbid node to have text content, inter-element whitespace is ignored */
@@ -874,6 +929,43 @@ function migrateElement(src) {
874
929
  return result;
875
930
  }
876
931
 
932
+ /**
933
+ * Returns true if given element is a descendant of given tagname.
934
+ *
935
+ * @internal
936
+ */
937
+ function isDescendant(node, tagName) {
938
+ let cur = node.parent;
939
+ while (cur && !cur.isRootElement()) {
940
+ if (cur.is(tagName)) {
941
+ return true;
942
+ }
943
+ cur = cur.parent;
944
+ }
945
+ return false;
946
+ }
947
+
948
+ /**
949
+ * Returns true if given element has given attribute (no matter the value, null,
950
+ * dynamic, etc).
951
+ */
952
+ function hasAttribute(node, attr) {
953
+ return node.hasAttribute(attr);
954
+ }
955
+
956
+ /**
957
+ * Matches attribute against value.
958
+ */
959
+ function matchAttribute(node, key, op, value) {
960
+ const nodeValue = (node.getAttributeValue(key) || "").toLowerCase();
961
+ switch (op) {
962
+ case "!=":
963
+ return nodeValue !== value;
964
+ case "=":
965
+ return nodeValue === value;
966
+ }
967
+ }
968
+
877
969
  const dynamicKeys = [
878
970
  "metadata",
879
971
  "flow",
@@ -885,44 +977,17 @@ const dynamicKeys = [
885
977
  "labelable",
886
978
  ];
887
979
  const functionTable = {
888
- isDescendant,
889
- hasAttribute,
890
- matchAttribute,
980
+ isDescendant: isDescendantFacade,
981
+ hasAttribute: hasAttributeFacade,
982
+ matchAttribute: matchAttributeFacade,
891
983
  };
984
+ const schemaCache = new Map();
892
985
  function clone(src) {
893
986
  return JSON.parse(JSON.stringify(src));
894
987
  }
895
988
  function overwriteMerge$1(a, b) {
896
989
  return b;
897
990
  }
898
- /**
899
- * AJV keyword "regexp" to validate the type to be a regular expression.
900
- * Injects errors with the "type" keyword to give the same output.
901
- */
902
- /* istanbul ignore next: manual testing */
903
- const ajvRegexpValidate = function (data, dataCxt) {
904
- const valid = data instanceof RegExp;
905
- if (!valid) {
906
- ajvRegexpValidate.errors = [
907
- {
908
- instancePath: dataCxt === null || dataCxt === void 0 ? void 0 : dataCxt.instancePath,
909
- schemaPath: undefined,
910
- keyword: "type",
911
- message: "should be regexp",
912
- params: {
913
- keyword: "type",
914
- },
915
- },
916
- ];
917
- }
918
- return valid;
919
- };
920
- const ajvRegexpKeyword = {
921
- keyword: "regexp",
922
- schema: false,
923
- errors: true,
924
- validate: ajvRegexpValidate,
925
- };
926
991
  /**
927
992
  * @public
928
993
  */
@@ -1059,11 +1124,20 @@ class MetaTable {
1059
1124
  * Construct a new AJV schema validator.
1060
1125
  */
1061
1126
  getSchemaValidator() {
1062
- const ajv = new Ajv__default["default"]({ strict: true, strictTuples: true, strictTypes: true });
1063
- ajv.addMetaSchema(ajvSchemaDraft);
1064
- ajv.addKeyword(ajvRegexpKeyword);
1065
- ajv.addKeyword({ keyword: "copyable" });
1066
- return ajv.compile(this.schema);
1127
+ const hash = computeHash(JSON.stringify(this.schema));
1128
+ const cached = schemaCache.get(hash);
1129
+ if (cached) {
1130
+ return cached;
1131
+ }
1132
+ else {
1133
+ const ajv = new Ajv__default["default"]({ strict: true, strictTuples: true, strictTypes: true });
1134
+ ajv.addMetaSchema(ajvSchemaDraft);
1135
+ ajv.addKeyword(ajvRegexpKeyword);
1136
+ ajv.addKeyword({ keyword: "copyable" });
1137
+ const validate = ajv.compile(this.schema);
1138
+ schemaCache.set(hash, validate);
1139
+ return validate;
1140
+ }
1067
1141
  }
1068
1142
  /**
1069
1143
  * @public
@@ -1165,36 +1239,27 @@ function parseExpression(expr) {
1165
1239
  return [func, options];
1166
1240
  }
1167
1241
  }
1168
- function isDescendant(node, tagName) {
1242
+ function isDescendantFacade(node, tagName) {
1169
1243
  if (typeof tagName !== "string") {
1170
1244
  throw new Error(`Property expression "isDescendant" must take string argument when evaluating metadata for <${node.tagName}>`);
1171
1245
  }
1172
- let cur = node.parent;
1173
- while (cur && !cur.isRootElement()) {
1174
- if (cur.is(tagName)) {
1175
- return true;
1176
- }
1177
- cur = cur.parent;
1178
- }
1179
- return false;
1246
+ return isDescendant(node, tagName);
1180
1247
  }
1181
- function hasAttribute(node, attr) {
1248
+ function hasAttributeFacade(node, attr) {
1182
1249
  if (typeof attr !== "string") {
1183
1250
  throw new Error(`Property expression "hasAttribute" must take string argument when evaluating metadata for <${node.tagName}>`);
1184
1251
  }
1185
- return node.hasAttribute(attr);
1252
+ return hasAttribute(node, attr);
1186
1253
  }
1187
- function matchAttribute(node, match) {
1254
+ function matchAttributeFacade(node, match) {
1188
1255
  if (!Array.isArray(match) || match.length !== 3) {
1189
1256
  throw new Error(`Property expression "matchAttribute" must take [key, op, value] array as argument when evaluating metadata for <${node.tagName}>`);
1190
1257
  }
1191
1258
  const [key, op, value] = match.map((x) => x.toLowerCase());
1192
- const nodeValue = (node.getAttributeValue(key) || "").toLowerCase();
1193
1259
  switch (op) {
1194
1260
  case "!=":
1195
- return nodeValue !== value;
1196
1261
  case "=":
1197
- return nodeValue === value;
1262
+ return matchAttribute(node, key, op, value);
1198
1263
  default:
1199
1264
  throw new Error(`Property expression "matchAttribute" has invalid operator "${op}" when evaluating metadata for <${node.tagName}>`);
1200
1265
  }
@@ -3048,7 +3113,7 @@ var TRANSFORMER_API;
3048
3113
  /** @public */
3049
3114
  const name = "html-validate";
3050
3115
  /** @public */
3051
- const version = "6.9.1";
3116
+ const version = "6.10.0";
3052
3117
  /** @public */
3053
3118
  const homepage = "https://html-validate.org";
3054
3119
  /** @public */