@asamuzakjp/dom-selector
Advanced tools
Comparing version 0.19.6 to 0.20.0
@@ -23,4 +23,3 @@ { | ||
"css-tree": "^2.3.1", | ||
"is-potential-custom-element-name": "^1.0.1", | ||
"xpath": "^0.0.33" | ||
"is-potential-custom-element-name": "^1.0.1" | ||
}, | ||
@@ -31,5 +30,4 @@ "devDependencies": { | ||
"c8": "^8.0.1", | ||
"chai": "^4.3.8", | ||
"css2xpath": "^0.0.3", | ||
"eslint": "^8.50.0", | ||
"chai": "^4.3.10", | ||
"eslint": "^8.51.0", | ||
"eslint-config-standard": "^17.1.0", | ||
@@ -41,10 +39,8 @@ "eslint-plugin-import": "^2.28.1", | ||
"jsdom": "^22.1.0", | ||
"linkedom": "^0.15.3", | ||
"mocha": "^10.2.0", | ||
"nwsapi": "^2.2.7", | ||
"sinon": "^16.0.0", | ||
"sinon": "^16.1.0", | ||
"typescript": "^5.2.2" | ||
}, | ||
"scripts": { | ||
"bench": "node benchmark/benchmark.js", | ||
"bench": "node benchmark/bench.js", | ||
"build": "npm run tsc && npm run lint && npm test", | ||
@@ -55,3 +51,3 @@ "lint": "eslint --fix .", | ||
}, | ||
"version": "0.19.6" | ||
"version": "0.20.0" | ||
} |
@@ -5,2 +5,3 @@ /** | ||
/* string */ | ||
export const AN_PLUS_B = 'AnPlusB'; | ||
@@ -22,1 +23,23 @@ export const ATTRIBUTE_SELECTOR = 'AttributeSelector'; | ||
export const TYPE_SELECTOR = 'TypeSelector'; | ||
/* numeric */ | ||
export const BIT_1 = 1; | ||
export const BIT_10 = 2; | ||
export const BIT_100 = 4; | ||
export const BIT_1000 = 8; | ||
export const BIT_10000 = 16; | ||
export const BIT_100000 = 32; | ||
export const TYPE_FROM = 8; | ||
export const TYPE_TO = -1; | ||
/* Node */ | ||
export const ELEMENT_NODE = 1; | ||
export const TEXT_NODE = 3; | ||
export const DOCUMENT_NODE = 9; | ||
export const DOCUMENT_FRAGMENT_NODE = 11; | ||
export const DOCUMENT_POSITION_PRECEDING = 0x02; | ||
export const DOCUMENT_POSITION_CONTAINS = 0x08; | ||
export const DOCUMENT_POSITION_CONTAINED_BY = 0x10; | ||
/* NodeFilter */ | ||
export const SHOW_ELEMENT = 0x00000001; |
@@ -9,13 +9,61 @@ /** | ||
/* constants */ | ||
import { PSEUDO_CLASS_SELECTOR, SELECTOR, SYNTAX_ERR } from './constant.js'; | ||
import { | ||
PSEUDO_CLASS_SELECTOR, SELECTOR, SYNTAX_ERR, TYPE_FROM, TYPE_TO | ||
} from './constant.js'; | ||
const CODE_POINT_UNIT = parseInt('10000', 16); | ||
const HEX = 16; | ||
const PAIR = 2; | ||
const TYPE_FROM = 8; | ||
const TYPE_TO = -1; | ||
/* regexp */ | ||
const HEX_CAPTURE = /^([\da-f]{1,6}\s?)/i; | ||
const PSEUDO_FUNC = /^(?:(?:ha|i)s|not|where)$/; | ||
const WHITESPACE = /^[\n\r\f]/; | ||
/** | ||
* unescape selector | ||
* @param {string} selector - CSS selector | ||
* @returns {?string} - unescaped selector | ||
*/ | ||
export const unescapeSelector = (selector = '') => { | ||
if (typeof selector === 'string' && selector.indexOf('\\', 0) >= 0) { | ||
const arr = selector.split('\\'); | ||
const l = arr.length; | ||
for (let i = 1; i < l; i++) { | ||
let item = arr[i]; | ||
if (i === l - 1 && item === '') { | ||
item = '\uFFFD'; | ||
} else { | ||
const hexExists = HEX_CAPTURE.exec(item); | ||
if (hexExists) { | ||
const [, hex] = hexExists; | ||
let str; | ||
try { | ||
const low = parseInt('D800', 16); | ||
const high = parseInt('DFFF', 16); | ||
const deci = parseInt(hex, 16); | ||
if (deci === 0 || (deci >= low && deci <= high)) { | ||
str = '\uFFFD'; | ||
} else { | ||
str = String.fromCodePoint(deci); | ||
} | ||
} catch (e) { | ||
str = '\uFFFD'; | ||
} | ||
let postStr = ''; | ||
if (item.length > hex.length) { | ||
postStr = item.substring(hex.length); | ||
} | ||
item = `${str}${postStr}`; | ||
} else if (WHITESPACE.test(item)) { | ||
item = '\\' + item; | ||
} | ||
} | ||
arr[i] = item; | ||
} | ||
selector = arr.join(''); | ||
} | ||
return selector; | ||
}; | ||
/** | ||
* preprocess | ||
@@ -71,3 +119,3 @@ * @see https://drafts.csswg.org/css-syntax-3/#input-preprocessing | ||
// invalid selectors | ||
if (selector === '' || /^\s*>/.test(selector) || /,\s*$/.test(selector)) { | ||
if (/^$|^\s*>|,\s*$/.test(selector)) { | ||
throw new DOMException(`invalid selector ${selector}`, SYNTAX_ERR); | ||
@@ -74,0 +122,0 @@ } |
@@ -7,2 +7,3 @@ export const AN_PLUS_B: "AnPlusB"; | ||
export const IDENTIFIER: "Identifier"; | ||
export const NOT_SUPPORTED_ERR: "NotSupportedError"; | ||
export const NTH: "Nth"; | ||
@@ -15,2 +16,19 @@ export const PSEUDO_CLASS_SELECTOR: "PseudoClassSelector"; | ||
export const STRING: "String"; | ||
export const SYNTAX_ERR: "SyntaxError"; | ||
export const TYPE_SELECTOR: "TypeSelector"; | ||
export const BIT_1: 1; | ||
export const BIT_10: 2; | ||
export const BIT_100: 4; | ||
export const BIT_1000: 8; | ||
export const BIT_10000: 16; | ||
export const BIT_100000: 32; | ||
export const TYPE_FROM: 8; | ||
export const TYPE_TO: -1; | ||
export const ELEMENT_NODE: 1; | ||
export const TEXT_NODE: 3; | ||
export const DOCUMENT_NODE: 9; | ||
export const DOCUMENT_FRAGMENT_NODE: 11; | ||
export const DOCUMENT_POSITION_PRECEDING: 2; | ||
export const DOCUMENT_POSITION_CONTAINS: 8; | ||
export const DOCUMENT_POSITION_CONTAINED_BY: 16; | ||
export const SHOW_ELEMENT: 1; |
@@ -1,6 +0,1 @@ | ||
export function isContentEditable(node?: object): boolean; | ||
export function isNamespaceDeclared(ns?: string, node?: object): boolean; | ||
export function isDescendant(node?: object, root?: object): boolean; | ||
export function unescapeSelector(selector?: string): string | null; | ||
export function parseASTName(name: string, node?: object): object; | ||
export class Matcher { | ||
@@ -29,2 +24,3 @@ constructor(selector: string, node: object, opt?: { | ||
_matchLanguagePseudoClass(ast: object, node: object): object | null; | ||
_matchHasPseudoFunc(leaves: any[], node: object): boolean; | ||
_matchLogicalPseudoFunc(ast: object, node: object): object | null; | ||
@@ -39,11 +35,10 @@ _matchPseudoClassSelector(ast: object, node: object): object; | ||
_matchLeaves(leaves: any[], node: object): boolean; | ||
_matchTwig(twig: object, node: object, opt?: { | ||
_matchCombinator(twig: object, node: object, opt?: { | ||
find?: string; | ||
}): object; | ||
_matchCombo(combo: object, prevNodes: object, nextNodes: object): object; | ||
_findNodes(twig: object, range: string): object; | ||
_collectNodes(range: string): any[]; | ||
_matchNodes(range: string): object; | ||
_find(range: string): object; | ||
_findNodes(twig: object, targetType: string): object; | ||
_collectNodes(targetType: string): any[]; | ||
_sortNodes(nodes: object): any[]; | ||
_matchNodes(targetType: string): object; | ||
_find(targetType: string): object; | ||
matches(): boolean; | ||
@@ -50,0 +45,0 @@ closest(): object | null; |
@@ -0,1 +1,2 @@ | ||
export function unescapeSelector(selector?: string): string | null; | ||
export function preprocess(...args: any[]): string; | ||
@@ -2,0 +3,0 @@ export function parseSelector(selector: string): object; |
Sorry, the diff of this file is too big to display
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
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
88908
2
14
13
2747
- Removedxpath@^0.0.33
- Removedxpath@0.0.33(transitive)