@markuplint/ml-core 3.15.0 → 4.0.0-alpha.10

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 (105) hide show
  1. package/LICENSE +1 -1
  2. package/lib/configs.browser.js +11 -11
  3. package/lib/convert-ruleset.d.ts +1 -1
  4. package/lib/convert-ruleset.js +3 -8
  5. package/lib/debug.js +9 -14
  6. package/lib/index.d.ts +13 -23
  7. package/lib/index.js +12 -29
  8. package/lib/ml-core.d.ts +5 -5
  9. package/lib/ml-core.js +94 -76
  10. package/lib/ml-dom/helper/accname.d.ts +1 -1
  11. package/lib/ml-dom/helper/accname.js +12 -19
  12. package/lib/ml-dom/helper/create-node.d.ts +4 -8
  13. package/lib/ml-dom/helper/create-node.js +38 -17
  14. package/lib/ml-dom/helper/debug.d.ts +1 -1
  15. package/lib/ml-dom/helper/debug.js +13 -22
  16. package/lib/ml-dom/helper/get-indent.d.ts +18 -0
  17. package/lib/ml-dom/helper/get-indent.js +112 -0
  18. package/lib/ml-dom/helper/walkers.d.ts +5 -15
  19. package/lib/ml-dom/helper/walkers.js +3 -8
  20. package/lib/ml-dom/index.d.ts +9 -9
  21. package/lib/ml-dom/index.js +1 -5
  22. package/lib/ml-dom/manipulations/child-node-methods.d.ts +7 -20
  23. package/lib/ml-dom/manipulations/child-node-methods.js +13 -25
  24. package/lib/ml-dom/manipulations/get-children.d.ts +3 -5
  25. package/lib/ml-dom/manipulations/get-children.js +3 -7
  26. package/lib/ml-dom/node/attr.d.ts +113 -98
  27. package/lib/ml-dom/node/attr.js +93 -50
  28. package/lib/ml-dom/node/block.d.ts +35 -39
  29. package/lib/ml-dom/node/block.js +8 -14
  30. package/lib/ml-dom/node/character-data.d.ts +55 -62
  31. package/lib/ml-dom/node/character-data.js +11 -16
  32. package/lib/ml-dom/node/child-node.d.ts +8 -15
  33. package/lib/ml-dom/node/child-node.js +1 -5
  34. package/lib/ml-dom/node/comment.d.ts +14 -17
  35. package/lib/ml-dom/node/comment.js +2 -6
  36. package/lib/ml-dom/node/document-fragment.d.ts +22 -25
  37. package/lib/ml-dom/node/document-fragment.js +4 -9
  38. package/lib/ml-dom/node/document-type.d.ts +35 -38
  39. package/lib/ml-dom/node/document-type.js +8 -14
  40. package/lib/ml-dom/node/document.d.ts +1598 -1614
  41. package/lib/ml-dom/node/document.js +330 -275
  42. package/lib/ml-dom/node/dom-token-list.d.ts +27 -27
  43. package/lib/ml-dom/node/dom-token-list.js +36 -32
  44. package/lib/ml-dom/node/element-close-tag.d.ts +20 -0
  45. package/lib/ml-dom/node/element-close-tag.js +39 -0
  46. package/lib/ml-dom/node/element.d.ts +1957 -1951
  47. package/lib/ml-dom/node/element.js +364 -348
  48. package/lib/ml-dom/node/named-node-map.d.ts +40 -45
  49. package/lib/ml-dom/node/named-node-map.js +10 -18
  50. package/lib/ml-dom/node/node-list.d.ts +5 -11
  51. package/lib/ml-dom/node/node-list.js +8 -16
  52. package/lib/ml-dom/node/node-store.d.ts +6 -11
  53. package/lib/ml-dom/node/node-store.js +14 -13
  54. package/lib/ml-dom/node/node.d.ts +480 -500
  55. package/lib/ml-dom/node/node.js +83 -73
  56. package/lib/ml-dom/node/parent-node.d.ts +60 -69
  57. package/lib/ml-dom/node/parent-node.js +32 -29
  58. package/lib/ml-dom/node/rule-mapper.d.ts +9 -9
  59. package/lib/ml-dom/node/rule-mapper.js +26 -21
  60. package/lib/ml-dom/node/text.d.ts +48 -51
  61. package/lib/ml-dom/node/text.js +8 -13
  62. package/lib/ml-dom/node/types.d.ts +42 -90
  63. package/lib/ml-dom/node/types.js +1 -2
  64. package/lib/ml-dom/node/unexpected-call-error.d.ts +2 -1
  65. package/lib/ml-dom/node/unexpected-call-error.js +1 -4
  66. package/lib/ml-dom/token/token.d.ts +45 -45
  67. package/lib/ml-dom/token/token.js +32 -26
  68. package/lib/ml-rule/create-rule.d.ts +2 -4
  69. package/lib/ml-rule/create-rule.js +1 -5
  70. package/lib/ml-rule/create-test-rule.d.ts +5 -7
  71. package/lib/ml-rule/create-test-rule.js +3 -7
  72. package/lib/ml-rule/index.d.ts +3 -3
  73. package/lib/ml-rule/index.js +3 -6
  74. package/lib/ml-rule/ml-rule-context.d.ts +49 -57
  75. package/lib/ml-rule/ml-rule-context.js +11 -11
  76. package/lib/ml-rule/ml-rule.d.ts +26 -36
  77. package/lib/ml-rule/ml-rule.js +34 -31
  78. package/lib/ml-rule/types.d.ts +18 -33
  79. package/lib/ml-rule/types.js +1 -2
  80. package/lib/plugin/index.d.ts +2 -2
  81. package/lib/plugin/index.js +2 -5
  82. package/lib/plugin/plugin.d.ts +2 -4
  83. package/lib/plugin/plugin.js +1 -5
  84. package/lib/plugin/types.d.ts +6 -6
  85. package/lib/plugin/types.js +1 -2
  86. package/lib/ruleset/index.d.ts +5 -5
  87. package/lib/ruleset/index.js +4 -8
  88. package/lib/test/index.d.ts +11 -21
  89. package/lib/test/index.js +18 -24
  90. package/lib/types.d.ts +11 -11
  91. package/lib/types.js +1 -2
  92. package/lib/utils/get-location-from-chars.d.ts +4 -9
  93. package/lib/utils/get-location-from-chars.js +4 -8
  94. package/lib/utils/index.d.ts +1 -1
  95. package/lib/utils/index.js +1 -5
  96. package/lib/utils/string-splice.js +1 -5
  97. package/package.json +19 -15
  98. package/lib/configs.d.ts +0 -2
  99. package/lib/configs.js +0 -34
  100. package/lib/ml-dom/helper/getIndent.d.ts +0 -18
  101. package/lib/ml-dom/helper/getIndent.js +0 -106
  102. package/test/ml-dom/helper/accname.spec.js +0 -85
  103. package/test/ml-dom/helper/create-node.spec.js +0 -18
  104. package/test/ml-dom/index.spec.js +0 -680
  105. package/test/ml-dom/ml-rule/create-rule.spec.js +0 -108
@@ -1,38 +1,23 @@
1
- import type { MLRuleContext } from './ml-rule-context';
2
- import type { Attr, Element } from '../ml-dom';
1
+ import type { MLRuleContext } from './ml-rule-context.js';
2
+ import type { Attr, Element } from '../ml-dom/index.js';
3
3
  import type { Translator } from '@markuplint/i18n';
4
4
  import type { PlainData, Report, RuleConfigValue, Severity } from '@markuplint/ml-config';
5
5
  export type RuleSeed<T extends RuleConfigValue = boolean, O extends PlainData = undefined> = {
6
- readonly defaultSeverity?: Severity;
7
- readonly defaultValue?: T;
8
- readonly defaultOptions?: O;
9
- verify(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
10
- fix?(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
6
+ readonly meta?: {
7
+ readonly category?: 'validation' | 'style' | 'naming-convention' | 'a11y' | 'maintainability';
8
+ };
9
+ readonly defaultSeverity?: Severity;
10
+ readonly defaultValue?: T;
11
+ readonly defaultOptions?: O;
12
+ verify(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
13
+ fix?(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
11
14
  };
12
- export type Checker<
13
- T extends RuleConfigValue,
14
- O extends PlainData = undefined,
15
- P extends Record<string, unknown> = {},
16
- > = (params: P) => CheckerReport<T, O>;
17
- export type ElementChecker<
18
- T extends RuleConfigValue,
19
- O extends PlainData = undefined,
20
- P extends Record<string, unknown> = {},
21
- > = (
22
- params: P & {
23
- el: Element<T, O>;
24
- },
25
- ) => CheckerReport<T, O>;
26
- export type AttrChecker<
27
- T extends RuleConfigValue,
28
- O extends PlainData = undefined,
29
- P extends Record<string, unknown> = {},
30
- > = (
31
- params: P & {
32
- attr: Attr<T, O>;
33
- },
34
- ) => CheckerReport<T, O>;
35
- export type CheckerReport<T extends RuleConfigValue, O extends PlainData = undefined> = (
36
- t: Translator,
37
- ) => Report<T, O> | undefined | null;
15
+ export type Checker<T extends RuleConfigValue, O extends PlainData = undefined, P extends Record<string, unknown> = {}> = (params: P) => CheckerReport<T, O>;
16
+ export type ElementChecker<T extends RuleConfigValue, O extends PlainData = undefined, P extends Record<string, unknown> = {}> = (params: P & {
17
+ el: Element<T, O>;
18
+ }) => CheckerReport<T, O>;
19
+ export type AttrChecker<T extends RuleConfigValue, O extends PlainData = undefined, P extends Record<string, unknown> = {}> = (params: P & {
20
+ attr: Attr<T, O>;
21
+ }) => CheckerReport<T, O>;
22
+ export type CheckerReport<T extends RuleConfigValue, O extends PlainData = undefined> = (t: Translator) => Report<T, O> | undefined | null;
38
23
  export type AnyRuleSeed<T extends RuleConfigValue = RuleConfigValue, O extends PlainData = PlainData> = RuleSeed<T, O>;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1,2 @@
1
- export * from './plugin';
2
- export * from './types';
1
+ export * from './plugin.js';
2
+ export * from './types.js';
@@ -1,5 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./plugin"), exports);
5
- tslib_1.__exportStar(require("./types"), exports);
1
+ export * from './plugin.js';
2
+ export * from './types.js';
@@ -1,4 +1,2 @@
1
- import type { PluginCreator, CreatePluginSettings } from './types';
2
- export declare function createPlugin<S extends CreatePluginSettings>(
3
- fn: Readonly<PluginCreator<S>>,
4
- ): Readonly<PluginCreator<S>>;
1
+ import type { PluginCreator, CreatePluginSettings } from './types.js';
2
+ export declare function createPlugin<S extends CreatePluginSettings>(fn: Readonly<PluginCreator<S>>): Readonly<PluginCreator<S>>;
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPlugin = void 0;
4
- function createPlugin(fn) {
1
+ export function createPlugin(fn) {
5
2
  return fn;
6
3
  }
7
- exports.createPlugin = createPlugin;
@@ -1,12 +1,12 @@
1
- import type { RuleSeed } from '../ml-rule';
1
+ import type { RuleSeed } from '../ml-rule/index.js';
2
2
  import type { Config } from '@markuplint/ml-config';
3
3
  export type Plugin = {
4
- readonly name: string;
5
- readonly rules?: Readonly<Record<string, Readonly<RuleSeed<any, any>>>>;
6
- readonly configs?: Readonly<Record<string, Config>>;
4
+ readonly name: string;
5
+ readonly rules?: Readonly<Record<string, Readonly<RuleSeed<any, any>>>>;
6
+ readonly configs?: Readonly<Record<string, Config>>;
7
7
  };
8
8
  export type PluginCreator<S extends CreatePluginSettings> = {
9
- readonly name: string;
10
- create(setting: S): Omit<Plugin, 'name'>;
9
+ readonly name: string;
10
+ create(setting: S): Omit<Plugin, 'name'>;
11
11
  };
12
12
  export type CreatePluginSettings = Readonly<Record<string, unknown>>;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,7 +1,7 @@
1
1
  import type { ChildNodeRule, Config, NodeRule, Rules } from '@markuplint/ml-config';
2
- export default class Ruleset {
3
- readonly childNodeRules: readonly ChildNodeRule[];
4
- readonly nodeRules: readonly NodeRule[];
5
- readonly rules: Rules;
6
- constructor(config: Config);
2
+ export declare class Ruleset {
3
+ readonly childNodeRules: readonly ChildNodeRule[];
4
+ readonly nodeRules: readonly NodeRule[];
5
+ readonly rules: Rules;
6
+ constructor(config: Config);
7
7
  }
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Ruleset {
1
+ export class Ruleset {
4
2
  constructor(config) {
5
- var _a, _b, _c;
6
- this.rules = (_a = config.rules) !== null && _a !== void 0 ? _a : {};
7
- this.nodeRules = (_b = config.nodeRules) !== null && _b !== void 0 ? _b : [];
8
- this.childNodeRules = (_c = config.childNodeRules) !== null && _c !== void 0 ? _c : [];
3
+ this.rules = config.rules ?? {};
4
+ this.nodeRules = config.nodeRules ?? [];
5
+ this.childNodeRules = config.childNodeRules ?? [];
9
6
  }
10
7
  }
11
- exports.default = Ruleset;
@@ -1,28 +1,18 @@
1
- import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
1
+ import type { MLParser } from '@markuplint/ml-ast';
2
2
  import type { Config, PlainData, RuleConfigValue } from '@markuplint/ml-config';
3
3
  import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
4
- import { Document } from '../ml-dom';
4
+ import { Document } from '../ml-dom/index.js';
5
5
  export type CreateTestOptions = {
6
- readonly config?: Config;
7
- readonly parser?: Readonly<MLMarkupLanguageParser>;
8
- readonly specs?: MLMLSpec;
6
+ readonly config?: Config;
7
+ readonly parser?: {
8
+ readonly parser: Readonly<MLParser>;
9
+ } | Readonly<MLParser>;
10
+ readonly specs?: MLMLSpec;
9
11
  };
10
- export declare function createTestDocument<T extends RuleConfigValue = any, O extends PlainData = any>(
11
- sourceCode: string,
12
- options?: CreateTestOptions,
13
- ): Document<T, O>;
14
- export declare function createTestNodeList(
15
- sourceCode: string,
16
- options?: CreateTestOptions,
17
- ): readonly import('../ml-dom/node/node').MLNode<any, any, import('@markuplint/ml-ast').MLASTAbstractNode>[];
18
- export declare function createTestTokenList(
19
- sourceCode: string,
20
- options?: CreateTestOptions,
21
- ): readonly import('../ml-dom/token/token').MLToken<import('@markuplint/ml-ast').MLToken>[];
22
- export declare function createTestElement(
23
- sourceCode: string,
24
- options?: CreateTestOptions,
25
- ): import('../ml-dom').Element<any, any>;
12
+ export declare function createTestDocument<T extends RuleConfigValue = any, O extends PlainData = any>(sourceCode: string, options?: CreateTestOptions): Document<T, O>;
13
+ export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/node/node.js").MLNode<any, any, import("@markuplint/ml-ast").MLASTNode>[];
14
+ export declare function createTestTokenList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/token/token.js").MLToken<import("@markuplint/ml-ast").MLASTToken>[];
15
+ export declare function createTestElement(sourceCode: string, options?: CreateTestOptions): import("../ml-dom/index.js").Element<any, any>;
26
16
  /**
27
17
  * for test suite
28
18
  */
package/lib/test/index.js CHANGED
@@ -1,42 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dummySchemas = exports.createTestElement = exports.createTestTokenList = exports.createTestNodeList = exports.createTestDocument = void 0;
4
- const tslib_1 = require("tslib");
5
- const html_parser_1 = require("@markuplint/html-parser");
6
- const html_spec_1 = tslib_1.__importDefault(require("@markuplint/html-spec"));
7
- const convert_ruleset_1 = require("../convert-ruleset");
8
- const ml_dom_1 = require("../ml-dom");
9
- function createTestDocument(sourceCode, options) {
10
- var _a;
11
- const ast = (options === null || options === void 0 ? void 0 : options.parser) ? options.parser.parse(sourceCode) : (0, html_parser_1.parse)(sourceCode);
12
- const ruleset = (0, convert_ruleset_1.convertRuleset)(options === null || options === void 0 ? void 0 : options.config);
13
- const document = new ml_dom_1.Document(ast, ruleset, [(_a = options === null || options === void 0 ? void 0 : options.specs) !== null && _a !== void 0 ? _a : {}, {}]);
1
+ import { parser } from '@markuplint/html-parser';
2
+ import spec from '@markuplint/html-spec';
3
+ import { convertRuleset } from '../convert-ruleset.js';
4
+ import { Document } from '../ml-dom/index.js';
5
+ export function createTestDocument(sourceCode, options) {
6
+ const ast = options?.parser
7
+ ? 'parser' in options.parser
8
+ ? options.parser.parser.parse(sourceCode, options.config?.parserOptions)
9
+ : options.parser.parse(sourceCode, options.config?.parserOptions)
10
+ : parser.parse(sourceCode, options?.config?.parserOptions);
11
+ const ruleset = convertRuleset(options?.config);
12
+ const document = new Document(ast, ruleset, [options?.specs ?? {}, {}]);
14
13
  return document;
15
14
  }
16
- exports.createTestDocument = createTestDocument;
17
- function createTestNodeList(sourceCode, options) {
15
+ export function createTestNodeList(sourceCode, options) {
18
16
  const document = createTestDocument(sourceCode, options);
19
17
  return document.nodeList;
20
18
  }
21
- exports.createTestNodeList = createTestNodeList;
22
- function createTestTokenList(sourceCode, options) {
19
+ export function createTestTokenList(sourceCode, options) {
23
20
  const document = createTestDocument(sourceCode, options);
24
21
  return document.getTokenList();
25
22
  }
26
- exports.createTestTokenList = createTestTokenList;
27
- function createTestElement(sourceCode, options) {
23
+ export function createTestElement(sourceCode, options) {
28
24
  const document = createTestDocument(sourceCode, options);
29
25
  const el = document.nodeList[0];
30
26
  if (el && el.is(el.ELEMENT_NODE)) {
31
27
  return el;
32
28
  }
33
- throw TypeError(`Could not parse it to be an element from: ${sourceCode}`);
29
+ throw new TypeError(`Could not parse it to be an element from: ${sourceCode}`);
34
30
  }
35
- exports.createTestElement = createTestElement;
36
31
  /**
37
32
  * for test suite
38
33
  */
39
- function dummySchemas() {
40
- return [html_spec_1.default];
34
+ export function dummySchemas() {
35
+ return [spec];
41
36
  }
42
- exports.dummySchemas = dummySchemas;
package/lib/types.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- import type { AnyMLRule } from './ml-rule';
2
- import type Ruleset from './ruleset';
1
+ import type { AnyMLRule } from './ml-rule/index.js';
2
+ import type { Ruleset } from './ruleset/index.js';
3
3
  import type { LocaleSet } from '@markuplint/i18n';
4
- import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
4
+ import type { MLParser, ParserOptions } from '@markuplint/ml-ast';
5
5
  import type { Pretender } from '@markuplint/ml-config';
6
6
  import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
7
7
  export type MLSchema = readonly [MLMLSpec, ...ExtendedSpec[]];
8
8
  export type MLFabric = {
9
- readonly parser: Readonly<MLMarkupLanguageParser>;
10
- readonly ruleset: Partial<Readonly<Ruleset>>;
11
- readonly rules: readonly Readonly<AnyMLRule>[];
12
- readonly locale: LocaleSet;
13
- readonly schemas: MLSchema;
14
- readonly parserOptions: ParserOptions;
15
- readonly pretenders: readonly Pretender[];
16
- readonly configErrors?: readonly Readonly<Error>[];
9
+ readonly parser: Readonly<MLParser>;
10
+ readonly ruleset: Partial<Readonly<Ruleset>>;
11
+ readonly rules: readonly Readonly<AnyMLRule>[];
12
+ readonly locale: LocaleSet;
13
+ readonly schemas: MLSchema;
14
+ readonly parserOptions: ParserOptions;
15
+ readonly pretenders: readonly Pretender[];
16
+ readonly configErrors?: readonly Readonly<Error>[];
17
17
  };
package/lib/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,12 +1,7 @@
1
1
  interface Location {
2
- line: number;
3
- col: number;
4
- raw: string;
2
+ line: number;
3
+ col: number;
4
+ raw: string;
5
5
  }
6
- export declare function getLocationFromChars(
7
- searches: readonly string[],
8
- text: string,
9
- currentLine: number,
10
- currentCol: number,
11
- ): Location[];
6
+ export declare function getLocationFromChars(searches: readonly string[], text: string, currentLine: number, currentCol: number): Location[];
12
7
  export {};
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLocationFromChars = void 0;
4
- function getLocationFromChars(searches, text, currentLine, currentCol) {
5
- const lines = text.split(/\r?\n/g);
1
+ export function getLocationFromChars(searches, text, currentLine, currentCol) {
2
+ const lines = text.split(/\r?\n/);
6
3
  const foundLocations = [];
7
- lines.forEach((lineText, i) => {
4
+ for (const [i, lineText] of lines.entries()) {
8
5
  let offset = 0;
9
6
  for (const char of lineText) {
10
7
  if (searches.includes(char)) {
@@ -22,7 +19,6 @@ function getLocationFromChars(searches, text, currentLine, currentCol) {
22
19
  }
23
20
  offset++;
24
21
  }
25
- });
22
+ }
26
23
  return foundLocations;
27
24
  }
28
- exports.getLocationFromChars = getLocationFromChars;
@@ -1 +1 @@
1
- export { getLocationFromChars } from './get-location-from-chars';
1
+ export { getLocationFromChars } from './get-location-from-chars.js';
@@ -1,5 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLocationFromChars = void 0;
4
- var get_location_from_chars_1 = require("./get-location-from-chars");
5
- Object.defineProperty(exports, "getLocationFromChars", { enumerable: true, get: function () { return get_location_from_chars_1.getLocationFromChars; } });
1
+ export { getLocationFromChars } from './get-location-from-chars.js';
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringSplice = void 0;
4
- function stringSplice(str, start, count, add = '') {
1
+ export function stringSplice(str, start, count, add = '') {
5
2
  if (start < 0) {
6
3
  start = str.length + start;
7
4
  if (start < 0) {
@@ -10,4 +7,3 @@ function stringSplice(str, start, count, add = '') {
10
7
  }
11
8
  return str.slice(0, start) + add + str.slice(start + count);
12
9
  }
13
- exports.stringSplice = stringSplice;
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@markuplint/ml-core",
3
- "version": "3.15.0",
3
+ "version": "4.0.0-alpha.10",
4
4
  "description": "The core module of markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
7
7
  "license": "MIT",
8
8
  "private": false,
9
- "main": "lib/index.js",
10
- "types": "lib/index.d.ts",
9
+ "type": "module",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./lib/index.js"
13
+ }
14
+ },
15
+ "types": "./lib/index.d.ts",
11
16
  "publishConfig": {
12
17
  "access": "public"
13
18
  },
@@ -23,20 +28,19 @@
23
28
  "./lib/configs.js": "./lib/configs.browser.js"
24
29
  },
25
30
  "dependencies": {
26
- "@markuplint/config-presets": "3.9.0",
27
- "@markuplint/html-parser": "3.13.0",
28
- "@markuplint/html-spec": "3.14.0",
29
- "@markuplint/i18n": "3.12.0",
30
- "@markuplint/ml-ast": "3.2.0",
31
- "@markuplint/ml-config": "3.14.0",
32
- "@markuplint/ml-spec": "3.14.0",
33
- "@markuplint/parser-utils": "3.13.0",
34
- "@markuplint/selector": "3.14.0",
31
+ "@markuplint/config-presets": "4.0.0-alpha.10",
32
+ "@markuplint/html-parser": "4.0.0-alpha.10",
33
+ "@markuplint/html-spec": "4.0.0-alpha.10",
34
+ "@markuplint/i18n": "4.0.0-alpha.10",
35
+ "@markuplint/ml-ast": "4.0.0-alpha.10",
36
+ "@markuplint/ml-config": "4.0.0-alpha.10",
37
+ "@markuplint/ml-spec": "4.0.0-alpha.10",
38
+ "@markuplint/parser-utils": "4.0.0-alpha.10",
39
+ "@markuplint/selector": "4.0.0-alpha.10",
35
40
  "@types/debug": "^4.1.12",
36
41
  "debug": "^4.3.4",
37
42
  "is-plain-object": "^5.0.0",
38
- "tslib": "^2.6.2",
39
- "type-fest": "^4.8.2"
43
+ "type-fest": "^4.10.1"
40
44
  },
41
- "gitHead": "b37b749d7ac0f9e6cbd022ee7031bc020c6677d3"
45
+ "gitHead": "b41153ea665aa8f091daf6114a06047f4ccb8350"
42
46
  }
package/lib/configs.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { Config } from '@markuplint/ml-config';
2
- export declare function getPreset(name: string): Promise<Config>;
package/lib/configs.js DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getPreset = void 0;
27
- async function getPreset(name) {
28
- const json = await Promise.resolve(`${`@markuplint/config-presets/preset.${name}.json`}`).then(s => __importStar(require(s))).catch(() => new Error());
29
- if (json instanceof Error) {
30
- throw new ReferenceError(`Preset markuplint:${name} is not found`);
31
- }
32
- return json.default;
33
- }
34
- exports.getPreset = getPreset;
@@ -1,18 +0,0 @@
1
- import type { MLNode } from '../node/node';
2
- import type { MLText } from '../node/text';
3
- /**
4
- *
5
- * @deprecated
6
- * @param node
7
- */
8
- export declare function getIndent(node: MLNode<any, any>): MLDOMIndentation | null;
9
- declare class MLDOMIndentation {
10
- #private;
11
- readonly line: number;
12
- constructor(originTextNode: MLText<any, any>, raw: string, line: number, parentNode: MLNode<any, any>);
13
- get raw(): string;
14
- get type(): 'tab' | 'space' | 'mixed' | 'none';
15
- get width(): number;
16
- fix(raw: string): void;
17
- }
18
- export {};
@@ -1,106 +0,0 @@
1
- "use strict";
2
- var _MLDOMIndentation_fixed, _MLDOMIndentation_node, _MLDOMIndentation_parent;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getIndent = void 0;
5
- const tslib_1 = require("tslib");
6
- /**
7
- *
8
- * @deprecated
9
- * @param node
10
- */
11
- function getIndent(
12
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
13
- node) {
14
- const prevToken = node.prevToken;
15
- if (!prevToken) {
16
- return null;
17
- }
18
- if (node.is(node.TEXT_NODE)) {
19
- if (node.isRawTextElementContent()) {
20
- return null;
21
- }
22
- const matched = node.raw.match(/^(\s*(?:\r?\n)+\s*)(?:[^\s]+)/);
23
- if (matched) {
24
- const spaces = matched[1];
25
- if (spaces) {
26
- const spaceLines = spaces.split(/\r?\n/);
27
- const line = spaceLines.length + node.startLine - 1;
28
- const lastSpace = spaceLines.pop();
29
- if (lastSpace != null) {
30
- return new MLDOMIndentation(node, lastSpace, line, node);
31
- }
32
- }
33
- }
34
- return null;
35
- }
36
- if (!prevToken.is(node.TEXT_NODE)) {
37
- return null;
38
- }
39
- // One or more newlines and zero or more spaces or tabs.
40
- // Or, If textNode is first token and that is filled spaces, tabs and newlines only.
41
- const matched = isFirstToken(prevToken)
42
- ? prevToken.raw.match(/^(?:[ \t]*\r?\n)*([ \t]*)$/)
43
- : prevToken.raw.match(/\r?\n([ \t]*)$/);
44
- // console.log({ [`${this}`]: matched, _: prevToken.raw, f: prevToken._isFirstToken() });
45
- if (matched) {
46
- // Spaces will include empty string.
47
- const spaces = matched[1];
48
- if (spaces != null) {
49
- return new MLDOMIndentation(prevToken, spaces, node.startLine, node);
50
- }
51
- }
52
- return null;
53
- }
54
- exports.getIndent = getIndent;
55
- class MLDOMIndentation {
56
- constructor(
57
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
58
- originTextNode, raw, line,
59
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
60
- parentNode) {
61
- _MLDOMIndentation_fixed.set(this, void 0);
62
- _MLDOMIndentation_node.set(this, void 0);
63
- _MLDOMIndentation_parent.set(this, void 0);
64
- this.line = line;
65
- tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_node, originTextNode, "f");
66
- tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_parent, parentNode, "f");
67
- tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_fixed, raw, "f");
68
- }
69
- get raw() {
70
- if (!tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").is(tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").TEXT_NODE) && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
71
- return '';
72
- }
73
- return tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f");
74
- }
75
- get type() {
76
- if (!tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").is(tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").TEXT_NODE) && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
77
- return 'none';
78
- }
79
- const raw = tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f");
80
- return raw === '' ? 'none' : /^\t+$/.test(raw) ? 'tab' : /^[^\t]+$/.test(raw) ? 'space' : 'mixed';
81
- }
82
- get width() {
83
- if (!tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").is(tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").TEXT_NODE) && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
84
- return 0;
85
- }
86
- return tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f").length;
87
- }
88
- fix(raw) {
89
- const current = tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f");
90
- tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_fixed, raw, "f");
91
- const node = tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f");
92
- const line = node.startLine;
93
- const lines = node.raw.split(/\r?\n/);
94
- const index = this.line - line;
95
- if (lines[index] != null) {
96
- lines[index] = lines[index].replace(current, tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f"));
97
- }
98
- node.fix(lines.join('\n'));
99
- }
100
- }
101
- _MLDOMIndentation_fixed = new WeakMap(), _MLDOMIndentation_node = new WeakMap(), _MLDOMIndentation_parent = new WeakMap();
102
- function isFirstToken(
103
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
104
- node) {
105
- return !node.prevToken;
106
- }