@markuplint/ml-core 3.5.0 → 3.6.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.
Files changed (53) hide show
  1. package/lib/index.d.ts +11 -1
  2. package/lib/ml-core.d.ts +22 -11
  3. package/lib/ml-dom/helper/accname.js +3 -2
  4. package/lib/ml-dom/helper/create-node.d.ts +5 -1
  5. package/lib/ml-dom/helper/debug.js +3 -2
  6. package/lib/ml-dom/helper/getIndent.d.ts +7 -7
  7. package/lib/ml-dom/helper/getIndent.js +7 -9
  8. package/lib/ml-dom/helper/walkers.d.ts +14 -4
  9. package/lib/ml-dom/helper/walkers.js +1 -1
  10. package/lib/ml-dom/manipulations/child-node-methods.d.ts +18 -5
  11. package/lib/ml-dom/manipulations/get-children.d.ts +3 -1
  12. package/lib/ml-dom/node/attr.d.ts +93 -90
  13. package/lib/ml-dom/node/attr.js +3 -3
  14. package/lib/ml-dom/node/block.d.ts +35 -31
  15. package/lib/ml-dom/node/character-data.d.ts +59 -52
  16. package/lib/ml-dom/node/child-node.d.ts +9 -2
  17. package/lib/ml-dom/node/comment.d.ts +15 -12
  18. package/lib/ml-dom/node/document-fragment.d.ts +22 -19
  19. package/lib/ml-dom/node/document-type.d.ts +34 -31
  20. package/lib/ml-dom/node/document.d.ts +1600 -1583
  21. package/lib/ml-dom/node/document.js +15 -12
  22. package/lib/ml-dom/node/dom-token-list.d.ts +26 -26
  23. package/lib/ml-dom/node/dom-token-list.js +1 -1
  24. package/lib/ml-dom/node/element.d.ts +1902 -1896
  25. package/lib/ml-dom/node/element.js +18 -13
  26. package/lib/ml-dom/node/named-node-map.d.ts +44 -39
  27. package/lib/ml-dom/node/named-node-map.js +2 -1
  28. package/lib/ml-dom/node/node-list.d.ts +9 -3
  29. package/lib/ml-dom/node/node-list.js +2 -1
  30. package/lib/ml-dom/node/node-store.d.ts +8 -3
  31. package/lib/ml-dom/node/node.d.ts +491 -471
  32. package/lib/ml-dom/node/node.js +6 -3
  33. package/lib/ml-dom/node/parent-node.d.ts +66 -57
  34. package/lib/ml-dom/node/parent-node.js +6 -3
  35. package/lib/ml-dom/node/rule-mapper.d.ts +7 -7
  36. package/lib/ml-dom/node/rule-mapper.js +2 -1
  37. package/lib/ml-dom/node/text.d.ts +49 -46
  38. package/lib/ml-dom/node/types.d.ts +80 -12
  39. package/lib/ml-dom/node/unexpected-call-error.d.ts +1 -2
  40. package/lib/ml-dom/token/token.d.ts +44 -44
  41. package/lib/ml-rule/create-rule.d.ts +3 -1
  42. package/lib/ml-rule/create-test-rule.d.ts +5 -3
  43. package/lib/ml-rule/ml-rule-context.d.ts +55 -47
  44. package/lib/ml-rule/ml-rule.d.ts +33 -23
  45. package/lib/ml-rule/ml-rule.js +4 -5
  46. package/lib/ml-rule/types.d.ts +31 -13
  47. package/lib/plugin/plugin.d.ts +3 -1
  48. package/lib/plugin/types.d.ts +5 -5
  49. package/lib/ruleset/index.d.ts +4 -4
  50. package/lib/test/index.d.ts +19 -7
  51. package/lib/types.d.ts +8 -8
  52. package/lib/utils/get-location-from-chars.d.ts +9 -4
  53. package/package.json +10 -11
@@ -26,7 +26,7 @@ class MLDocument extends parent_node_1.MLParentNode {
26
26
  constructor(
27
27
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
28
28
  ast, ruleset, schemas, options) {
29
- var _a;
29
+ var _a, _b;
30
30
  // @ts-ignore
31
31
  super(ast, null);
32
32
  /**
@@ -40,8 +40,8 @@ class MLDocument extends parent_node_1.MLParentNode {
40
40
  _MLDocument_tokenList.set(this, null);
41
41
  this.isFragment = ast.isFragment;
42
42
  this.specs = (0, ml_spec_1.schemaToSpec)(schemas);
43
- this.booleanish = (options === null || options === void 0 ? void 0 : options.booleanish) || false;
44
- this.endTag = (_a = options === null || options === void 0 ? void 0 : options.endTag) !== null && _a !== void 0 ? _a : 'omittable';
43
+ this.booleanish = (_a = options === null || options === void 0 ? void 0 : options.booleanish) !== null && _a !== void 0 ? _a : false;
44
+ this.endTag = (_b = options === null || options === void 0 ? void 0 : options.endTag) !== null && _b !== void 0 ? _b : 'omittable';
45
45
  tslib_1.__classPrivateFieldSet(this, _MLDocument_filename, options === null || options === void 0 ? void 0 : options.filename, "f");
46
46
  // console.log(ast.nodeList.map((n, i) => `${i}: ${n.uuid} "${n.raw.trim()}"(${n.type})`));
47
47
  this.nodeList = Object.freeze(ast.nodeList
@@ -2118,13 +2118,14 @@ class MLDocument extends parent_node_1.MLParentNode {
2118
2118
  const selectorTarget = node.is(node.ELEMENT_NODE) ? node : null;
2119
2119
  // node specs and special rules for node by selector
2120
2120
  ruleset.nodeRules.forEach(nodeRule => {
2121
+ var _a, _b;
2121
2122
  if (!nodeRule.rules) {
2122
2123
  return;
2123
2124
  }
2124
2125
  if (!selectorTarget) {
2125
2126
  return;
2126
2127
  }
2127
- const selector = nodeRule.selector || nodeRule.regexSelector;
2128
+ const selector = (_a = nodeRule.selector) !== null && _a !== void 0 ? _a : nodeRule.regexSelector;
2128
2129
  const matches = (0, selector_1.matchSelector)(selectorTarget, selector);
2129
2130
  if (!matches.matched) {
2130
2131
  return;
@@ -2138,12 +2139,12 @@ class MLDocument extends parent_node_1.MLParentNode {
2138
2139
  if (rule == null) {
2139
2140
  continue;
2140
2141
  }
2141
- const convertedRule = (0, ml_config_1.exchangeValueOnRule)(rule, matches.data || {});
2142
+ const convertedRule = (0, ml_config_1.exchangeValueOnRule)(rule, (_b = matches.data) !== null && _b !== void 0 ? _b : {});
2142
2143
  if (convertedRule === undefined) {
2143
2144
  continue;
2144
2145
  }
2145
2146
  const globalRule = ruleset.rules[ruleName];
2146
- const mergedRule = globalRule ? (0, ml_config_1.mergeRule)(globalRule, convertedRule) : convertedRule;
2147
+ const mergedRule = globalRule != null ? (0, ml_config_1.mergeRule)(globalRule, convertedRule) : convertedRule;
2147
2148
  ruleLog('↑ nodeRule (%s): %O', ruleName, mergedRule);
2148
2149
  ruleMapper.set(node, ruleName, {
2149
2150
  from: 'nodeRules',
@@ -2153,19 +2154,20 @@ class MLDocument extends parent_node_1.MLParentNode {
2153
2154
  }
2154
2155
  });
2155
2156
  // overwrite rule to child node
2156
- if (selectorTarget && ruleset.childNodeRules.length) {
2157
+ if (selectorTarget && ruleset.childNodeRules.length > 0) {
2157
2158
  const descendants = [];
2158
2159
  const children = Array.from(selectorTarget.childNodes);
2159
2160
  (0, walkers_1.syncWalk)(children, childNode => {
2160
2161
  descendants.push(childNode);
2161
2162
  });
2162
- ruleset.childNodeRules.forEach((nodeRule, i) => {
2163
+ ruleset.childNodeRules.forEach(nodeRule => {
2164
+ var _a;
2163
2165
  if (!nodeRule.rules) {
2164
2166
  return;
2165
2167
  }
2166
2168
  const nodeRuleRules = nodeRule.rules;
2167
- const selector = nodeRule.selector || nodeRule.regexSelector;
2168
- if (!selector) {
2169
+ const selector = (_a = nodeRule.selector) !== null && _a !== void 0 ? _a : nodeRule.regexSelector;
2170
+ if (selector == null) {
2169
2171
  return;
2170
2172
  }
2171
2173
  const matches = (0, selector_1.matchSelector)(selectorTarget, selector);
@@ -2177,16 +2179,17 @@ class MLDocument extends parent_node_1.MLParentNode {
2177
2179
  }
2178
2180
  const targetDescendants = nodeRule.inheritance ? descendants : children;
2179
2181
  Object.keys(nodeRuleRules).forEach(ruleName => {
2182
+ var _a;
2180
2183
  const rule = nodeRuleRules[ruleName];
2181
2184
  if (rule == null) {
2182
2185
  return;
2183
2186
  }
2184
- const convertedRule = (0, ml_config_1.exchangeValueOnRule)(rule, matches.data || {});
2187
+ const convertedRule = (0, ml_config_1.exchangeValueOnRule)(rule, (_a = matches.data) !== null && _a !== void 0 ? _a : {});
2185
2188
  if (convertedRule === undefined) {
2186
2189
  return;
2187
2190
  }
2188
2191
  const globalRule = ruleset.rules[ruleName];
2189
- const mergedRule = globalRule ? (0, ml_config_1.mergeRule)(globalRule, convertedRule) : convertedRule;
2192
+ const mergedRule = globalRule != null ? (0, ml_config_1.mergeRule)(globalRule, convertedRule) : convertedRule;
2190
2193
  ruleLog('↑ childNodeRule (%s): %O', ruleName, mergedRule);
2191
2194
  targetDescendants.forEach(descendant => {
2192
2195
  ruleMapper.set(descendant, ruleName, {
@@ -1,33 +1,33 @@
1
1
  import type { MLAttr } from './attr';
2
2
  import type { RuleInfo } from '@markuplint/ml-config';
3
3
  type Scope = {
4
- raw: string;
5
- startOffset: number;
6
- startLine: number;
7
- startCol: number;
8
- rule: RuleInfo<any, any>;
4
+ raw: string;
5
+ startOffset: number;
6
+ startLine: number;
7
+ startCol: number;
8
+ rule: RuleInfo<any, any>;
9
9
  };
10
10
  export declare class MLDomTokenList extends Array<string> implements DOMTokenList {
11
- #private;
12
- constructor(tokens: string, ownerAttrs: MLAttr<any, any>[]);
13
- get value(): string;
14
- add(...tokens: readonly string[]): void;
15
- /**
16
- * @implements `@markuplint/ml-core` API: `MLDomTokenList`
17
- */
18
- allTokens(): Scope[];
19
- contains(token: string): boolean;
20
- forEach(callbackfn: (value: string, index: number, parent: any) => void, thisArg?: any): void;
21
- item(index: number): string | null;
22
- /**
23
- * @implements `@markuplint/ml-core` API: `MLDomTokenList`
24
- */
25
- pick(token: string): Scope | null;
26
- remove(...tokens: readonly string[]): void;
27
- replace(token: string, newToken: string): boolean;
28
- supports(token: string): boolean;
29
- toString(): string;
30
- toggle(token: string, force?: boolean): boolean;
31
- private _pick;
11
+ #private;
12
+ constructor(tokens: string, ownerAttrs: MLAttr<any, any>[]);
13
+ get value(): string;
14
+ add(...tokens: readonly string[]): void;
15
+ /**
16
+ * @implements `@markuplint/ml-core` API: `MLDomTokenList`
17
+ */
18
+ allTokens(): Scope[];
19
+ contains(token: string): boolean;
20
+ forEach(callbackfn: (value: string, index: number, parent: any) => void, thisArg?: any): void;
21
+ item(index: number): string | null;
22
+ /**
23
+ * @implements `@markuplint/ml-core` API: `MLDomTokenList`
24
+ */
25
+ pick(token: string): Scope | null;
26
+ remove(...tokens: readonly string[]): void;
27
+ replace(token: string, newToken: string): boolean;
28
+ supports(token: string): boolean;
29
+ toString(): string;
30
+ toggle(token: string, force?: boolean): boolean;
31
+ private _pick;
32
32
  }
33
33
  export {};
@@ -45,7 +45,7 @@ class MLDomTokenList extends Array {
45
45
  let offset = 0;
46
46
  const tokens = Array.from(this);
47
47
  const locs = [];
48
- while (tokens.length) {
48
+ while (tokens.length > 0) {
49
49
  const token = tokens.shift();
50
50
  if (!token) {
51
51
  break;