@markuplint/selector
Advanced tools
Comparing version 3.11.0 to 4.0.0-alpha.1
@@ -1,2 +0,2 @@ | ||
import type { Specificity } from './types'; | ||
import type { Specificity } from './types.js'; | ||
export declare function compareSpecificity(a: Specificity, b: Specificity): 0 | 1 | -1; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.compareSpecificity = void 0; | ||
function compareSpecificity(a, b) { | ||
export function compareSpecificity(a, b) { | ||
if (a[0] < b[0]) { | ||
@@ -25,2 +22,1 @@ return -1; | ||
} | ||
exports.compareSpecificity = compareSpecificity; |
import type { MLMLSpec } from '@markuplint/ml-spec'; | ||
import { Selector } from './selector'; | ||
import { Selector } from './selector.js'; | ||
export declare function createSelector(selector: string, specs?: MLMLSpec): Selector; |
@@ -1,10 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSelector = void 0; | ||
const aria_pseudo_class_1 = require("./extended-selector/aria-pseudo-class"); | ||
const aria_role_pseudo_class_1 = require("./extended-selector/aria-role-pseudo-class"); | ||
const content_model_pseudo_class_1 = require("./extended-selector/content-model-pseudo-class"); | ||
const selector_1 = require("./selector"); | ||
import { ariaPseudoClass } from './extended-selector/aria-pseudo-class.js'; | ||
import { ariaRolePseudoClass } from './extended-selector/aria-role-pseudo-class.js'; | ||
import { contentModelPseudoClass } from './extended-selector/content-model-pseudo-class.js'; | ||
import { Selector } from './selector.js'; | ||
const caches = new Map(); | ||
function createSelector(selector, specs) { | ||
export function createSelector(selector, specs) { | ||
let instance = caches.get(selector); | ||
@@ -14,7 +11,7 @@ if (instance) { | ||
} | ||
instance = new selector_1.Selector(selector, specs | ||
instance = new Selector(selector, specs | ||
? { | ||
model: (0, content_model_pseudo_class_1.contentModelPseudoClass)(specs), | ||
aria: (0, aria_pseudo_class_1.ariaPseudoClass)(), | ||
role: (0, aria_role_pseudo_class_1.ariaRolePseudoClass)(specs), | ||
model: contentModelPseudoClass(specs), | ||
aria: ariaPseudoClass(), | ||
role: ariaRolePseudoClass(specs), | ||
} | ||
@@ -25,2 +22,1 @@ : undefined); | ||
} | ||
exports.createSelector = createSelector; |
@@ -1,18 +0,13 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.enableDebug = exports.log = void 0; | ||
const tslib_1 = require("tslib"); | ||
const debug_1 = tslib_1.__importDefault(require("debug")); | ||
import debug from 'debug'; | ||
const CLI_NS = 'markuplint-cli'; | ||
exports.log = (0, debug_1.default)('selector'); | ||
function enableDebug() { | ||
if (!exports.log.enabled) { | ||
debug_1.default.enable(`${exports.log.namespace}*`); | ||
(0, exports.log)(`Debug enable: ${exports.log.namespace}`); | ||
if (!debug_1.default.enabled(CLI_NS)) { | ||
debug_1.default.enable(`${exports.log.namespace}*,${CLI_NS}*`); | ||
(0, exports.log)(`Debug enable: ${exports.log.namespace}, ${CLI_NS}`); | ||
export const log = debug('selector'); | ||
export function enableDebug() { | ||
if (!log.enabled) { | ||
debug.enable(`${log.namespace}*`); | ||
log(`Debug enable: ${log.namespace}`); | ||
if (!debug.enabled(CLI_NS)) { | ||
debug.enable(`${log.namespace}*,${CLI_NS}*`); | ||
log(`Debug enable: ${log.namespace}, ${CLI_NS}`); | ||
} | ||
} | ||
} | ||
exports.enableDebug = enableDebug; |
@@ -1,2 +0,2 @@ | ||
import type { SelectorResult } from '../types'; | ||
import type { SelectorResult } from '../types.js'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Version Syntax is not support yet. |
@@ -1,9 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ariaPseudoClass = void 0; | ||
const ml_spec_1 = require("@markuplint/ml-spec"); | ||
import { validateAriaVersion, ARIA_RECOMMENDED_VERSION, getAccname } from '@markuplint/ml-spec'; | ||
/** | ||
* Version Syntax is not support yet. | ||
*/ | ||
function ariaPseudoClass() { | ||
export function ariaPseudoClass() { | ||
return (content) => ( | ||
@@ -13,3 +10,3 @@ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
const aria = ariaPseudoClassParser(content); | ||
const name = (0, ml_spec_1.getAccname)(el); | ||
const name = getAccname(el); | ||
switch (aria.type) { | ||
@@ -47,8 +44,7 @@ case 'hasName': { | ||
} | ||
exports.ariaPseudoClass = ariaPseudoClass; | ||
function ariaPseudoClassParser(syntax) { | ||
const [_query, _version] = syntax.split('|'); | ||
const query = _query === null || _query === void 0 ? void 0 : _query.replace(/\s+/g, '').toLowerCase(); | ||
const version = _version !== null && _version !== void 0 ? _version : ml_spec_1.ARIA_RECOMMENDED_VERSION; | ||
if (!(0, ml_spec_1.validateAriaVersion)(version)) { | ||
const query = _query?.replace(/\s+/g, '').toLowerCase(); | ||
const version = _version ?? ARIA_RECOMMENDED_VERSION; | ||
if (!validateAriaVersion(version)) { | ||
throw new SyntaxError(`Unsupported ARIA version: ${version}`); | ||
@@ -55,0 +51,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import type { SelectorResult } from '../types'; | ||
import type { SelectorResult } from '../types.js'; | ||
import type { MLMLSpec } from '@markuplint/ml-spec'; | ||
export declare function ariaRolePseudoClass(specs: MLMLSpec): (content: string) => (el: Element) => SelectorResult; |
@@ -1,13 +0,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ariaRolePseudoClass = void 0; | ||
const ml_spec_1 = require("@markuplint/ml-spec"); | ||
function ariaRolePseudoClass(specs) { | ||
import { validateAriaVersion, ARIA_RECOMMENDED_VERSION, getComputedRole } from '@markuplint/ml-spec'; | ||
export function ariaRolePseudoClass(specs) { | ||
return (content) => ( | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
el) => { | ||
var _a, _b; | ||
const aria = ariaPseudoClassParser(content); | ||
const computed = (0, ml_spec_1.getComputedRole)(specs, el, (_a = aria.version) !== null && _a !== void 0 ? _a : ml_spec_1.ARIA_RECOMMENDED_VERSION); | ||
if (((_b = computed.role) === null || _b === void 0 ? void 0 : _b.name) === aria.role) { | ||
const computed = getComputedRole(specs, el, aria.version ?? ARIA_RECOMMENDED_VERSION); | ||
if (computed.role?.name === aria.role) { | ||
return { | ||
@@ -26,14 +22,12 @@ specificity: [0, 1, 0], | ||
} | ||
exports.ariaRolePseudoClass = ariaRolePseudoClass; | ||
function ariaPseudoClassParser(syntax) { | ||
var _a; | ||
const [roleName, _version] = syntax.split('|'); | ||
const version = _version !== null && _version !== void 0 ? _version : ml_spec_1.ARIA_RECOMMENDED_VERSION; | ||
if (!(0, ml_spec_1.validateAriaVersion)(version)) { | ||
const version = _version ?? ARIA_RECOMMENDED_VERSION; | ||
if (!validateAriaVersion(version)) { | ||
throw new SyntaxError(`Unsupported ARIA version: ${version}`); | ||
} | ||
return { | ||
role: (_a = roleName === null || roleName === void 0 ? void 0 : roleName.trim().toLowerCase()) !== null && _a !== void 0 ? _a : syntax.trim().toLowerCase(), | ||
role: roleName?.trim().toLowerCase() ?? syntax.trim().toLowerCase(), | ||
version, | ||
}; | ||
} |
@@ -1,3 +0,3 @@ | ||
import type { SelectorResult } from '../types'; | ||
import type { SelectorResult } from '../types.js'; | ||
import type { MLMLSpec } from '@markuplint/ml-spec'; | ||
export declare function contentModelPseudoClass(specs: MLMLSpec): (category: string) => (el: Element) => SelectorResult; |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.contentModelPseudoClass = void 0; | ||
const ml_spec_1 = require("@markuplint/ml-spec"); | ||
const create_selector_1 = require("../create-selector"); | ||
function contentModelPseudoClass(specs) { | ||
import { contentModelCategoryToTagNames } from '@markuplint/ml-spec'; | ||
import { createSelector } from '../create-selector.js'; | ||
export function contentModelPseudoClass(specs) { | ||
return (category) => ( | ||
@@ -11,3 +8,3 @@ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
category = category.trim().toLowerCase(); | ||
const selectors = (0, ml_spec_1.contentModelCategoryToTagNames)(`#${category}`, specs.def); | ||
const selectors = contentModelCategoryToTagNames(`#${category}`, specs.def); | ||
const matched = selectors | ||
@@ -42,3 +39,3 @@ .map(selector => { | ||
} | ||
return (0, create_selector_1.createSelector)(selector, specs).search(el); | ||
return createSelector(selector, specs).search(el); | ||
}) | ||
@@ -61,2 +58,1 @@ .flat() | ||
} | ||
exports.contentModelPseudoClass = contentModelPseudoClass; |
@@ -1,5 +0,5 @@ | ||
export { compareSpecificity } from './compare-specificity'; | ||
export { matchSelector } from './match-selector'; | ||
export { createSelector } from './create-selector'; | ||
export { InvalidSelectorError } from './invalid-selector-error'; | ||
export * from './types'; | ||
export { compareSpecificity } from './compare-specificity.js'; | ||
export { matchSelector } from './match-selector.js'; | ||
export { createSelector } from './create-selector.js'; | ||
export { InvalidSelectorError } from './invalid-selector-error.js'; | ||
export * from './types.js'; |
@@ -1,13 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InvalidSelectorError = exports.createSelector = exports.matchSelector = exports.compareSpecificity = void 0; | ||
const tslib_1 = require("tslib"); | ||
var compare_specificity_1 = require("./compare-specificity"); | ||
Object.defineProperty(exports, "compareSpecificity", { enumerable: true, get: function () { return compare_specificity_1.compareSpecificity; } }); | ||
var match_selector_1 = require("./match-selector"); | ||
Object.defineProperty(exports, "matchSelector", { enumerable: true, get: function () { return match_selector_1.matchSelector; } }); | ||
var create_selector_1 = require("./create-selector"); | ||
Object.defineProperty(exports, "createSelector", { enumerable: true, get: function () { return create_selector_1.createSelector; } }); | ||
var invalid_selector_error_1 = require("./invalid-selector-error"); | ||
Object.defineProperty(exports, "InvalidSelectorError", { enumerable: true, get: function () { return invalid_selector_error_1.InvalidSelectorError; } }); | ||
tslib_1.__exportStar(require("./types"), exports); | ||
export { compareSpecificity } from './compare-specificity.js'; | ||
export { matchSelector } from './match-selector.js'; | ||
export { createSelector } from './create-selector.js'; | ||
export { InvalidSelectorError } from './invalid-selector-error.js'; | ||
export * from './types.js'; |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InvalidSelectorError = void 0; | ||
class InvalidSelectorError extends Error { | ||
export class InvalidSelectorError extends Error { | ||
constructor(selector, message) { | ||
super(message !== null && message !== void 0 ? message : `Invalid selector: "${selector}"`); | ||
super(message ?? `Invalid selector: "${selector}"`); | ||
this.name = 'InvalidSelectorError'; | ||
@@ -11,2 +8,1 @@ this.selector = selector; | ||
} | ||
exports.InvalidSelectorError = InvalidSelectorError; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isPureHTMLElement = exports.isNonDocumentTypeChildNode = exports.isElement = void 0; | ||
function isElement( | ||
export function isElement( | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
@@ -9,4 +6,3 @@ node) { | ||
} | ||
exports.isElement = isElement; | ||
function isNonDocumentTypeChildNode( | ||
export function isNonDocumentTypeChildNode( | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
@@ -16,4 +12,3 @@ node) { | ||
} | ||
exports.isNonDocumentTypeChildNode = isNonDocumentTypeChildNode; | ||
function isPureHTMLElement( | ||
export function isPureHTMLElement( | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
@@ -23,2 +18,1 @@ el) { | ||
} | ||
exports.isPureHTMLElement = isPureHTMLElement; |
@@ -1,2 +0,2 @@ | ||
import type { Specificity, RegexSelector } from './types'; | ||
import type { Specificity, RegexSelector } from './types.js'; | ||
export type SelectorMatches = SelectorMatched | SelectorUnmatched; | ||
@@ -3,0 +3,0 @@ type SelectorMatched = { |
@@ -1,10 +0,7 @@ | ||
"use strict"; | ||
var _SelectorTarget_combinedFrom, _SelectorTarget_selector; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.matchSelector = void 0; | ||
const tslib_1 = require("tslib"); | ||
const is_1 = require("./is"); | ||
const regex_selector_matches_1 = require("./regex-selector-matches"); | ||
const selector_1 = require("./selector"); | ||
function matchSelector( | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { isElement, isNonDocumentTypeChildNode, isPureHTMLElement } from './is.js'; | ||
import { regexSelectorMatches } from './regex-selector-matches.js'; | ||
import { Selector } from './selector.js'; | ||
export function matchSelector( | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
@@ -18,3 +15,3 @@ el, selector) { | ||
if (typeof selector === 'string') { | ||
const sel = new selector_1.Selector(selector); | ||
const sel = new Selector(selector); | ||
const specificity = sel.match(el); | ||
@@ -34,3 +31,2 @@ if (specificity !== false) { | ||
} | ||
exports.matchSelector = matchSelector; | ||
function regexSelect( | ||
@@ -53,6 +49,6 @@ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
_SelectorTarget_selector.set(this, void 0); | ||
tslib_1.__classPrivateFieldSet(this, _SelectorTarget_selector, selector, "f"); | ||
__classPrivateFieldSet(this, _SelectorTarget_selector, selector, "f"); | ||
} | ||
from(target, combinator) { | ||
tslib_1.__classPrivateFieldSet(this, _SelectorTarget_combinedFrom, { target, combinator }, "f"); | ||
__classPrivateFieldSet(this, _SelectorTarget_combinedFrom, { target, combinator }, "f"); | ||
} | ||
@@ -66,9 +62,9 @@ match( | ||
} | ||
if (!tslib_1.__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f")) { | ||
if (!__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f")) { | ||
return unitCheck; | ||
} | ||
if (!(0, is_1.isNonDocumentTypeChildNode)(el)) { | ||
if (!isNonDocumentTypeChildNode(el)) { | ||
return unitCheck; | ||
} | ||
const { target, combinator } = tslib_1.__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f"); | ||
const { target, combinator } = __classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f"); | ||
switch (combinator) { | ||
@@ -148,3 +144,3 @@ // Descendant combinator | ||
default: { | ||
throw new Error(`Unsupported ${tslib_1.__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f").combinator} combinator in selector`); | ||
throw new Error(`Unsupported ${__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f").combinator} combinator in selector`); | ||
} | ||
@@ -156,3 +152,3 @@ } | ||
el) { | ||
return uncombinedRegexSelect(el, tslib_1.__classPrivateFieldGet(this, _SelectorTarget_selector, "f")); | ||
return uncombinedRegexSelect(el, __classPrivateFieldGet(this, _SelectorTarget_selector, "f")); | ||
} | ||
@@ -164,3 +160,3 @@ } | ||
el, selector) { | ||
if (!(0, is_1.isElement)(el)) { | ||
if (!isElement(el)) { | ||
return { | ||
@@ -176,3 +172,3 @@ matched: false, | ||
if (selector.nodeName) { | ||
const matchedNodeName = (0, regex_selector_matches_1.regexSelectorMatches)(selector.nodeName, el.localName, (0, is_1.isPureHTMLElement)(el)); | ||
const matchedNodeName = regexSelectorMatches(selector.nodeName, el.localName, isPureHTMLElement(el)); | ||
if (matchedNodeName) { | ||
@@ -195,3 +191,3 @@ delete matchedNodeName.$0; | ||
const attrName = attr.name; | ||
const matchedAttrName = (0, regex_selector_matches_1.regexSelectorMatches)(selectorAttrName, attrName, (0, is_1.isPureHTMLElement)(el)); | ||
const matchedAttrName = regexSelectorMatches(selectorAttrName, attrName, isPureHTMLElement(el)); | ||
if (matchedAttrName) { | ||
@@ -216,3 +212,3 @@ delete matchedAttrName.$0; | ||
const attrValue = attr.value; | ||
const matchedAttrValue = (0, regex_selector_matches_1.regexSelectorMatches)(selectorAttrValue, attrValue, (0, is_1.isPureHTMLElement)(el)); | ||
const matchedAttrValue = regexSelectorMatches(selectorAttrValue, attrValue, isPureHTMLElement(el)); | ||
if (matchedAttrValue) { | ||
@@ -219,0 +215,0 @@ delete matchedAttrValue.$0; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.regexSelectorMatches = void 0; | ||
function regexSelectorMatches(reg, raw, ignoreCase) { | ||
export function regexSelectorMatches(reg, raw, ignoreCase) { | ||
const res = {}; | ||
@@ -18,3 +15,2 @@ const pattern = toRegexp(reg); | ||
} | ||
exports.regexSelectorMatches = regexSelectorMatches; | ||
function toRegexp(pattern) { | ||
@@ -21,0 +17,0 @@ const matched = pattern.match(/^\/(.+)\/([ig]*)$/i); |
@@ -1,2 +0,2 @@ | ||
import type { SelectorResult, Specificity } from './types'; | ||
import type { SelectorResult, Specificity } from './types.js'; | ||
type ExtendedPseudoClass = Readonly<Record<string, (content: string) => (el: Element) => SelectorResult>>; | ||
@@ -3,0 +3,0 @@ export declare class Selector { |
@@ -1,18 +0,15 @@ | ||
"use strict"; | ||
var _Selector_ruleset, _Ruleset_selectorGroup, _StructuredSelector_edge, _StructuredSelector_selector, _SelectorTarget_combinedFrom, _SelectorTarget_extended, _SelectorTarget_isAdded; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Selector = void 0; | ||
const tslib_1 = require("tslib"); | ||
const ml_spec_1 = require("@markuplint/ml-spec"); | ||
const postcss_selector_parser_1 = tslib_1.__importStar(require("postcss-selector-parser")); | ||
const compare_specificity_1 = require("./compare-specificity"); | ||
const debug_1 = require("./debug"); | ||
const invalid_selector_error_1 = require("./invalid-selector-error"); | ||
const is_1 = require("./is"); | ||
const selLog = debug_1.log.extend('selector'); | ||
const resLog = debug_1.log.extend('result'); | ||
class Selector { | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { resolveNamespace } from '@markuplint/ml-spec'; | ||
import parser from 'postcss-selector-parser'; | ||
import { compareSpecificity } from './compare-specificity.js'; | ||
import { log as coreLog } from './debug.js'; | ||
import { InvalidSelectorError } from './invalid-selector-error.js'; | ||
import { isElement, isNonDocumentTypeChildNode, isPureHTMLElement } from './is.js'; | ||
const selLog = coreLog.extend('selector'); | ||
const resLog = coreLog.extend('result'); | ||
export class Selector { | ||
constructor(selector, extended = {}) { | ||
_Selector_ruleset.set(this, void 0); | ||
tslib_1.__classPrivateFieldSet(this, _Selector_ruleset, Ruleset.parse(selector, extended), "f"); | ||
__classPrivateFieldSet(this, _Selector_ruleset, Ruleset.parse(selector, extended), "f"); | ||
} | ||
@@ -24,3 +21,3 @@ match( | ||
scope) { | ||
scope = (0, is_1.isElement)(el) ? el : null; | ||
scope = isElement(el) ? el : null; | ||
const results = this.search(el, scope); | ||
@@ -39,7 +36,6 @@ for (const result of results) { | ||
scope) { | ||
scope = (0, is_1.isElement)(el) ? el : null; | ||
return tslib_1.__classPrivateFieldGet(this, _Selector_ruleset, "f").match(el, scope); | ||
scope = isElement(el) ? el : null; | ||
return __classPrivateFieldGet(this, _Selector_ruleset, "f").match(el, scope); | ||
} | ||
} | ||
exports.Selector = Selector; | ||
_Selector_ruleset = new WeakMap(); | ||
@@ -50,3 +46,3 @@ class Ruleset { | ||
try { | ||
(0, postcss_selector_parser_1.default)(root => { | ||
parser(root => { | ||
selectors.push(...root.nodes); | ||
@@ -57,3 +53,3 @@ }).processSync(selector); | ||
if (e instanceof Error) { | ||
throw new invalid_selector_error_1.InvalidSelectorError(selector); | ||
throw new InvalidSelectorError(selector); | ||
} | ||
@@ -65,11 +61,10 @@ throw e; | ||
constructor(selectors, extended, depth) { | ||
var _a, _b, _c; | ||
_Ruleset_selectorGroup.set(this, []); | ||
tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f").push(...selectors.map(selector => new StructuredSelector(selector, depth, extended))); | ||
const head = tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]; | ||
this.headCombinator = (_a = head === null || head === void 0 ? void 0 : head.headCombinator) !== null && _a !== void 0 ? _a : null; | ||
__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f").push(...selectors.map(selector => new StructuredSelector(selector, depth, extended))); | ||
const head = __classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]; | ||
this.headCombinator = head?.headCombinator ?? null; | ||
if (this.headCombinator) { | ||
if (depth <= 0) { | ||
if ((_b = tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]) === null || _b === void 0 ? void 0 : _b.selector) { | ||
throw new invalid_selector_error_1.InvalidSelectorError((_c = tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]) === null || _c === void 0 ? void 0 : _c.selector); | ||
if (__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]?.selector) { | ||
throw new InvalidSelectorError(__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f")[0]?.selector); | ||
} | ||
@@ -85,7 +80,7 @@ throw new Error('Combinated selector depth is not expected'); | ||
scope) { | ||
(0, debug_1.log)('<%s> (%s)', (0, is_1.isElement)(el) ? el.localName : el.nodeName, scope ? ((0, is_1.isElement)(scope) ? scope.localName : scope.nodeName) : null); | ||
return tslib_1.__classPrivateFieldGet(this, _Ruleset_selectorGroup, "f").map(selector => { | ||
coreLog('<%s> (%s)', isElement(el) ? el.localName : el.nodeName, scope ? (isElement(scope) ? scope.localName : scope.nodeName) : null); | ||
return __classPrivateFieldGet(this, _Ruleset_selectorGroup, "f").map(selector => { | ||
selLog('"%s"', selector.selector); | ||
const res = selector.match(el, scope); | ||
resLog('%s "%s" => %o', (0, is_1.isElement)(el) ? el.localName : el.nodeName, selector.selector, res); | ||
resLog('%s "%s" => %o', isElement(el) ? el.localName : el.nodeName, selector.selector, res); | ||
return res; | ||
@@ -98,12 +93,12 @@ }); | ||
constructor(selector, depth, extended) { | ||
var _a, _b; | ||
_StructuredSelector_edge.set(this, void 0); | ||
_StructuredSelector_selector.set(this, void 0); | ||
tslib_1.__classPrivateFieldSet(this, _StructuredSelector_selector, selector, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _StructuredSelector_edge, new SelectorTarget(extended, depth), "f"); | ||
__classPrivateFieldSet(this, _StructuredSelector_selector, selector, "f"); | ||
__classPrivateFieldSet(this, _StructuredSelector_edge, new SelectorTarget(extended, depth), "f"); | ||
this.headCombinator = | ||
((_a = tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0]) === null || _a === void 0 ? void 0 : _a.type) === 'combinator' ? (_b = tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0].value) !== null && _b !== void 0 ? _b : null : null; | ||
const nodes = tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes.slice(); | ||
__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0]?.type === 'combinator' ? __classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes[0].value ?? null : null; | ||
const nodes = __classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes.slice(); | ||
if (0 < depth && this.headCombinator) { | ||
nodes.unshift((0, postcss_selector_parser_1.pseudo)({ value: ':scope' })); | ||
// eslint-disable-next-line import/no-named-as-default-member | ||
nodes.unshift(parser.pseudo({ value: ':scope' })); | ||
} | ||
@@ -114,4 +109,4 @@ nodes.forEach(node => { | ||
const combinedTarget = new SelectorTarget(extended, depth); | ||
combinedTarget.from(tslib_1.__classPrivateFieldGet(this, _StructuredSelector_edge, "f"), node); | ||
tslib_1.__classPrivateFieldSet(this, _StructuredSelector_edge, combinedTarget, "f"); | ||
combinedTarget.from(__classPrivateFieldGet(this, _StructuredSelector_edge, "f"), node); | ||
__classPrivateFieldSet(this, _StructuredSelector_edge, combinedTarget, "f"); | ||
break; | ||
@@ -130,3 +125,3 @@ } | ||
default: { | ||
tslib_1.__classPrivateFieldGet(this, _StructuredSelector_edge, "f").add(node); | ||
__classPrivateFieldGet(this, _StructuredSelector_edge, "f").add(node); | ||
} | ||
@@ -137,3 +132,3 @@ } | ||
get selector() { | ||
return tslib_1.__classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes.join(''); | ||
return __classPrivateFieldGet(this, _StructuredSelector_selector, "f").nodes.join(''); | ||
} | ||
@@ -145,3 +140,3 @@ match( | ||
scope) { | ||
return tslib_1.__classPrivateFieldGet(this, _StructuredSelector_edge, "f").match(el, scope, 0); | ||
return __classPrivateFieldGet(this, _StructuredSelector_edge, "f").match(el, scope, 0); | ||
} | ||
@@ -160,7 +155,7 @@ } | ||
this.tag = null; | ||
tslib_1.__classPrivateFieldSet(this, _SelectorTarget_extended, extended, "f"); | ||
__classPrivateFieldSet(this, _SelectorTarget_extended, extended, "f"); | ||
this.depth = depth; | ||
} | ||
add(selector) { | ||
tslib_1.__classPrivateFieldSet(this, _SelectorTarget_isAdded, true, "f"); | ||
__classPrivateFieldSet(this, _SelectorTarget_isAdded, true, "f"); | ||
switch (selector.type) { | ||
@@ -191,3 +186,3 @@ case 'tag': | ||
from(target, combinator) { | ||
tslib_1.__classPrivateFieldSet(this, _SelectorTarget_combinedFrom, { target, combinator }, "f"); | ||
__classPrivateFieldSet(this, _SelectorTarget_combinedFrom, { target, combinator }, "f"); | ||
} | ||
@@ -199,11 +194,10 @@ match( | ||
scope, count) { | ||
var _a, _b, _c; | ||
const result = this._match(el, scope, count); | ||
if (selLog.enabled) { | ||
const nodeName = el.nodeName; | ||
const selector = (_b = (_a = tslib_1.__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f")) === null || _a === void 0 ? void 0 : _a.target.toString()) !== null && _b !== void 0 ? _b : this.toString(); | ||
const selector = __classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f")?.target.toString() ?? this.toString(); | ||
const combinator = result.combinator ? ` ${result.combinator}` : ''; | ||
selLog('The %s element by "%s" => %s (%d)', nodeName, `${selector}${combinator}`, result.matched, count); | ||
if (selector === ':scope') { | ||
selLog(`† Scope is the ${(_c = scope === null || scope === void 0 ? void 0 : scope.nodeName) !== null && _c !== void 0 ? _c : null}`); | ||
selLog(`† Scope is the ${scope?.nodeName ?? null}`); | ||
} | ||
@@ -215,5 +209,4 @@ } | ||
toString() { | ||
var _a, _b; | ||
return [ | ||
(_b = (_a = this.tag) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '', | ||
this.tag?.toString() ?? '', | ||
this.id.map(id => `#${id.value}`).join(''), | ||
@@ -234,9 +227,9 @@ this.class.map(c => `.${c.value}`).join(''), | ||
} | ||
if (!tslib_1.__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f")) { | ||
if (!__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f")) { | ||
return unitCheck; | ||
} | ||
if (!(0, is_1.isNonDocumentTypeChildNode)(el)) { | ||
if (!isNonDocumentTypeChildNode(el)) { | ||
return unitCheck; | ||
} | ||
const { target, combinator } = tslib_1.__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f"); | ||
const { target, combinator } = __classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f"); | ||
switch (combinator.value) { | ||
@@ -437,3 +430,3 @@ // Descendant combinator | ||
default: { | ||
throw new Error(`Unsupported ${tslib_1.__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f").combinator.value} combinator in selector`); | ||
throw new Error(`Unsupported ${__classPrivateFieldGet(this, _SelectorTarget_combinedFrom, "f").combinator.value} combinator in selector`); | ||
} | ||
@@ -447,5 +440,4 @@ } | ||
scope) { | ||
var _a; | ||
const specificity = [0, 0, 0]; | ||
if (!(0, is_1.isElement)(el)) { | ||
if (!isElement(el)) { | ||
return { | ||
@@ -477,3 +469,3 @@ specificity, | ||
default: { | ||
throw new invalid_selector_error_1.InvalidSelectorError(`The ${namespace} namespace is not supported`); | ||
throw new InvalidSelectorError(`The ${namespace} namespace is not supported`); | ||
} | ||
@@ -483,3 +475,3 @@ } | ||
let matched = true; | ||
if (!tslib_1.__classPrivateFieldGet(this, _SelectorTarget_isAdded, "f") && !isScope(el, scope)) { | ||
if (!__classPrivateFieldGet(this, _SelectorTarget_isAdded, "f") && !isScope(el, scope)) { | ||
matched = false; | ||
@@ -500,3 +492,3 @@ } | ||
for (const pseudo of this.pseudo) { | ||
const pseudoRes = pseudoMatch(pseudo, el, scope, tslib_1.__classPrivateFieldGet(this, _SelectorTarget_extended, "f"), this.depth); | ||
const pseudoRes = pseudoMatch(pseudo, el, scope, __classPrivateFieldGet(this, _SelectorTarget_extended, "f"), this.depth); | ||
specificity[0] += pseudoRes.specificity[0]; | ||
@@ -509,3 +501,3 @@ specificity[1] += pseudoRes.specificity[1]; | ||
else { | ||
not.push(...((_a = pseudoRes.not) !== null && _a !== void 0 ? _a : [])); | ||
not.push(...(pseudoRes.not ?? [])); | ||
matched = false; | ||
@@ -518,3 +510,3 @@ } | ||
let b = el.localName; | ||
if ((0, is_1.isPureHTMLElement)(el)) { | ||
if (isPureHTMLElement(el)) { | ||
a = a.toLowerCase(); | ||
@@ -551,3 +543,3 @@ b = b.toLowerCase(); | ||
if (attr.namespace != null && attr.namespace !== true && attr.namespace !== '*') { | ||
const ns = (0, ml_spec_1.resolveNamespace)(attrOfEl.localName, attrOfEl.namespaceURI); | ||
const ns = resolveNamespace(attrOfEl.localName, attrOfEl.namespaceURI); | ||
if (attr.namespace !== ns.namespace) { | ||
@@ -822,4 +814,3 @@ return false; | ||
scope) { | ||
var _a; | ||
return (_a = el === scope) !== null && _a !== void 0 ? _a : el.parentNode === null; | ||
return el === scope ?? el.parentNode === null; | ||
} | ||
@@ -839,4 +830,3 @@ function getDescendants( | ||
el) { | ||
var _a, _b; | ||
return Array.from((_b = (_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : []); | ||
return Array.from(el.parentElement?.children ?? []); | ||
} | ||
@@ -849,3 +839,3 @@ function getSpecificity( | ||
if (specificity) { | ||
const order = (0, compare_specificity_1.compareSpecificity)(specificity, result.specificity); | ||
const order = compareSpecificity(specificity, result.specificity); | ||
if (order === -1) { | ||
@@ -852,0 +842,0 @@ specificity = result.specificity; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; |
{ | ||
"name": "@markuplint/selector", | ||
"version": "3.11.0", | ||
"version": "4.0.0-alpha.1", | ||
"description": "Extended W3C Selectors matcher", | ||
@@ -9,3 +9,8 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
"private": false, | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./lib/index.js" | ||
} | ||
}, | ||
"types": "lib/index.d.ts", | ||
@@ -24,8 +29,8 @@ "publishConfig": { | ||
"dependencies": { | ||
"@markuplint/ml-spec": "3.11.0", | ||
"@markuplint/ml-spec": "4.0.0-alpha.1", | ||
"@types/debug": "^4.1.8", | ||
"debug": "^4.3.4", | ||
"postcss-selector-parser": "^6.0.13", | ||
"tslib": "^2.6.0", | ||
"type-fest": "^3.12.0" | ||
"tslib": "^2.6.1", | ||
"type-fest": "^4.1.0" | ||
}, | ||
@@ -36,3 +41,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "4ab20276db48a6acb29a923ea8666890ca853442" | ||
"gitHead": "22502ee22a378ae766033d687dbc0443e5ed35dc" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
63528
29
1410
2
+ Added@markuplint/ml-ast@4.0.0-alpha.1(transitive)
+ Added@markuplint/ml-spec@4.0.0-alpha.1(transitive)
+ Added@markuplint/types@4.0.0-alpha.1(transitive)
+ Added@types/bcp-47@2.0.4(transitive)
+ Addedbcp-47@2.1.0(transitive)
+ Addedis-alphabetical@2.0.1(transitive)
+ Addedis-alphanumerical@2.0.1(transitive)
+ Addedis-decimal@2.0.1(transitive)
+ Addedleven@4.0.0(transitive)
+ Addedtype-fest@4.30.2(transitive)
- Removed@markuplint/ml-ast@3.2.0(transitive)
- Removed@markuplint/ml-spec@3.11.0(transitive)
- Removed@markuplint/types@3.9.0(transitive)
- Removed@types/bcp-47@1.0.0(transitive)
- Removedbcp-47@1.0.8(transitive)
- Removedis-alphabetical@1.0.4(transitive)
- Removedis-alphanumerical@1.0.4(transitive)
- Removedis-decimal@1.0.4(transitive)
- Removedleven@3.1.0(transitive)
- Removedtype-fest@3.13.1(transitive)
Updatedtslib@^2.6.1
Updatedtype-fest@^4.1.0