Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parsel-js

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parsel-js - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

index.d.ts

7

dist/cjs/parsel.js

@@ -6,3 +6,3 @@ 'use strict';

const TOKENS = {
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(?<caseSensitive>[iIsS])?\s*)?\]/gu,
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(\s(?<caseSensitive>[iIsS]))?\s*)?\]/gu,
id: /#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

@@ -134,4 +134,3 @@ class: /\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

let strings = [];
// FIXME Does not account for escaped backslashes before a quote
selector = selector.replace(/(['"])(\\\1|.)+?\1/g, (str, quote, content, start) => {
selector = selector.replace(/(['"])((?:\\\1|.)+?)\1/g, (str, quote, content, start) => {
strings.push({str, start});

@@ -245,3 +244,3 @@ return quote + "§".repeat(content.length) + quote;

}
else if (node.type === "compound") {
else if (node.type === "compound" || node.type === "list") {
for (let n of node.list) {

@@ -248,0 +247,0 @@ walk(n, callback, o, node);

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={attribute:/\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(?<caseSensitive>[iIsS])?\s*)?\]/gu,id:/#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,class:/\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,comma:/\s*,\s*/g,combinator:/\s*[\s>+~]\s*/g,"pseudo-element":/::(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,"pseudo-class":/:(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,type:/(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)|\*/gu},t=new Set(["pseudo-class","pseudo-element"]),n=new Set([...t,"attribute"]),r=new Set(["combinator","comma"]),s=new Set(["not","is","where","has","matches","-moz-any","-webkit-any","nth-child","nth-last-child"]),o={"nth-child":/(?<index>[\dn+-]+)\s+of\s+(?<subtree>.+)/};s["nth-last-child"]=o["nth-child"];const l=Object.assign({},e);function i(e,t){let n="",r=[];for(;t<e.length;t++){let s=e[t];if("("===s)r.push(s);else if(")"===s){if(!(r.length>0))throw new Error("Closing paren without opening paren at "+t);r.pop()}if(n+=s,0===r.length)return n}throw new Error("Opening paren without closing paren")}function u(e,t){if(!e)return[];var n=[e];for(var s in t){let e=t[s];for(var o=0;o<n.length;o++){var l=n[o];if("string"==typeof l){e.lastIndex=0;var i=e.exec(l);if(i){let e=i.index-1,t=[],r=i[0],u=l.slice(0,e+1);u&&t.push(u),t.push({type:s,content:r,...i.groups});let a=l.slice(e+r.length+1);a&&t.push(a),n.splice(o,1,...t)}}}}let u=0;for(let e=0;e<n.length;e++){let t=n[e],s=t.length||t.content.length;"object"==typeof t&&(t.pos=[u,u+s],r.has(t.type)&&(t.content=t.content.trim()||" ")),u+=s}return n}function a(r){if(!r)return null;r=r.trim();let s=[];r=r.replace(/(['"])(\\\1|.)+?\1/g,((e,t,n,r)=>(s.push({str:e,start:r}),t+"§".repeat(n.length)+t)));let o,a=[],p=0;for(;(o=r.indexOf("(",p))>-1;){let e=i(r,o);a.push({str:e,start:o}),r=r.substring(0,o)+"("+"¶".repeat(e.length-2)+")"+r.substring(o+e.length),p=o+e.length}let c=u(r,e);function f(e,t,n){for(let r of e)for(let e of c)if(n.has(e.type)&&e.pos[0]<r.start&&r.start<e.pos[1]){let n=e.content;if(e.content=e.content.replace(t,r.str),e.content!==n){l[e.type].lastIndex=0;let t=l[e.type].exec(e.content).groups;Object.assign(e,t)}}}return f(a,/\(¶+\)/,t),f(s,/(['"])§+?\1/,n),c}function p(e,{list:t=!0}={}){if(t&&e.find((e=>"comma"===e.type))){let t=[],n=[];for(let r=0;r<e.length;r++)if("comma"===e[r].type){if(0===n.length)throw new Error("Incorrect comma at "+r);t.push(p(n,{list:!1})),n.length=0}else n.push(e[r]);if(0===n.length)throw new Error("Trailing comma");return t.push(p(n,{list:!1})),{type:"list",list:t}}for(let t=e.length-1;t>=0;t--){let n=e[t];if("combinator"===n.type){let r=e.slice(0,t),s=e.slice(t+1);return{type:"complex",combinator:n.content,left:p(r),right:p(s)}}}return 0===e.length?null:1===e.length?e[0]:{type:"compound",list:[...e]}}function c(e,t,n,r){if(e){if("complex"===e.type)c(e.left,t,n,e),c(e.right,t,n,e);else if("compound"===e.type)for(let r of e.list)c(r,t,n,e);else e.subtree&&n&&n.subtree&&c(e.subtree,t,n,e);t(e,r)}}function f(e,{recursive:t=!0,list:n=!0}={}){let r=a(e);if(!r)return null;let l=p(r,{list:n});return t&&c(l,(e=>{if("pseudo-class"===e.type&&e.argument&&s.has(e.name)){let t=e.argument;const n=o[e.name];if(n){const r=n.exec(t);if(!r)return;Object.assign(e,r.groups),t=r.groups.subtree}t&&(e.subtree=f(t,{recursive:!0,list:!0}))}})),l}function g(e,t){return t=t||Math.max(...e)+1,e[0]*t**2+e[1]*t+e[2]}l["pseudo-element"]=RegExp(e["pseudo-element"].source.replace("(?<argument>¶+)","(?<argument>.+?)"),"gu"),l["pseudo-class"]=RegExp(e["pseudo-class"].source.replace("(?<argument>¶+)","(?<argument>.+)"),"gu"),exports.RECURSIVE_PSEUDO_CLASSES=s,exports.RECURSIVE_PSEUDO_CLASSES_ARGS=o,exports.TOKENS=e,exports.TRIM_TOKENS=r,exports.gobbleParens=i,exports.nestTokens=p,exports.parse=f,exports.specificity=function e(t,{format:n="array"}={}){let r="object"==typeof t?t:f(t,{recursive:!0});if(!r)return null;if("list"===r.type){let t=10,n=r.list.map((n=>{let r=e(n);return t=Math.max(t,...r),r})),s=n.map((e=>g(e,t)));return n[function(e){let t=e[0],n=0;for(let r=0;r<e.length;r++)e[r]>t&&(n=r,t=e[r]);return 0===e.length?-1:n}(s)]}let o=[0,0,0];return c(r,(t=>{if("id"===t.type)o[0]++;else if("class"===t.type||"attribute"===t.type)o[1]++;else if("type"===t.type&&"*"!==t.content||"pseudo-element"===t.type)o[2]++;else if("pseudo-class"===t.type&&"where"!==t.name)if(s.has(t.name)&&t.subtree){e(t.subtree).forEach(((e,t)=>o[t]+=e))}else o[1]++})),o},exports.specificityToNumber=g,exports.tokenize=a,exports.tokenizeBy=u,exports.walk=c;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={attribute:/\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(\s(?<caseSensitive>[iIsS]))?\s*)?\]/gu,id:/#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,class:/\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,comma:/\s*,\s*/g,combinator:/\s*[\s>+~]\s*/g,"pseudo-element":/::(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,"pseudo-class":/:(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,type:/(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)|\*/gu},t=new Set(["pseudo-class","pseudo-element"]),n=new Set([...t,"attribute"]),s=new Set(["combinator","comma"]),r=new Set(["not","is","where","has","matches","-moz-any","-webkit-any","nth-child","nth-last-child"]),o={"nth-child":/(?<index>[\dn+-]+)\s+of\s+(?<subtree>.+)/};r["nth-last-child"]=o["nth-child"];const l=Object.assign({},e);function i(e,t){let n="",s=[];for(;t<e.length;t++){let r=e[t];if("("===r)s.push(r);else if(")"===r){if(!(s.length>0))throw new Error("Closing paren without opening paren at "+t);s.pop()}if(n+=r,0===s.length)return n}throw new Error("Opening paren without closing paren")}function u(e,t){if(!e)return[];var n=[e];for(var r in t){let e=t[r];for(var o=0;o<n.length;o++){var l=n[o];if("string"==typeof l){e.lastIndex=0;var i=e.exec(l);if(i){let e=i.index-1,t=[],s=i[0],u=l.slice(0,e+1);u&&t.push(u),t.push({type:r,content:s,...i.groups});let a=l.slice(e+s.length+1);a&&t.push(a),n.splice(o,1,...t)}}}}let u=0;for(let e=0;e<n.length;e++){let t=n[e],r=t.length||t.content.length;"object"==typeof t&&(t.pos=[u,u+r],s.has(t.type)&&(t.content=t.content.trim()||" ")),u+=r}return n}function a(s){if(!s)return null;s=s.trim();let r=[];s=s.replace(/(['"])((?:\\\1|.)+?)\1/g,((e,t,n,s)=>(r.push({str:e,start:s}),t+"§".repeat(n.length)+t)));let o,a=[],p=0;for(;(o=s.indexOf("(",p))>-1;){let e=i(s,o);a.push({str:e,start:o}),s=s.substring(0,o)+"("+"¶".repeat(e.length-2)+")"+s.substring(o+e.length),p=o+e.length}let c=u(s,e);function f(e,t,n){for(let s of e)for(let e of c)if(n.has(e.type)&&e.pos[0]<s.start&&s.start<e.pos[1]){let n=e.content;if(e.content=e.content.replace(t,s.str),e.content!==n){l[e.type].lastIndex=0;let t=l[e.type].exec(e.content).groups;Object.assign(e,t)}}}return f(a,/\(¶+\)/,t),f(r,/(['"])§+?\1/,n),c}function p(e,{list:t=!0}={}){if(t&&e.find((e=>"comma"===e.type))){let t=[],n=[];for(let s=0;s<e.length;s++)if("comma"===e[s].type){if(0===n.length)throw new Error("Incorrect comma at "+s);t.push(p(n,{list:!1})),n.length=0}else n.push(e[s]);if(0===n.length)throw new Error("Trailing comma");return t.push(p(n,{list:!1})),{type:"list",list:t}}for(let t=e.length-1;t>=0;t--){let n=e[t];if("combinator"===n.type){let s=e.slice(0,t),r=e.slice(t+1);return{type:"complex",combinator:n.content,left:p(s),right:p(r)}}}return 0===e.length?null:1===e.length?e[0]:{type:"compound",list:[...e]}}function c(e,t,n,s){if(e){if("complex"===e.type)c(e.left,t,n,e),c(e.right,t,n,e);else if("compound"===e.type||"list"===e.type)for(let s of e.list)c(s,t,n,e);else e.subtree&&n&&n.subtree&&c(e.subtree,t,n,e);t(e,s)}}function f(e,{recursive:t=!0,list:n=!0}={}){let s=a(e);if(!s)return null;let l=p(s,{list:n});return t&&c(l,(e=>{if("pseudo-class"===e.type&&e.argument&&r.has(e.name)){let t=e.argument;const n=o[e.name];if(n){const s=n.exec(t);if(!s)return;Object.assign(e,s.groups),t=s.groups.subtree}t&&(e.subtree=f(t,{recursive:!0,list:!0}))}})),l}function g(e,t){return t=t||Math.max(...e)+1,e[0]*t**2+e[1]*t+e[2]}l["pseudo-element"]=RegExp(e["pseudo-element"].source.replace("(?<argument>¶+)","(?<argument>.+?)"),"gu"),l["pseudo-class"]=RegExp(e["pseudo-class"].source.replace("(?<argument>¶+)","(?<argument>.+)"),"gu"),exports.RECURSIVE_PSEUDO_CLASSES=r,exports.RECURSIVE_PSEUDO_CLASSES_ARGS=o,exports.TOKENS=e,exports.TRIM_TOKENS=s,exports.gobbleParens=i,exports.nestTokens=p,exports.parse=f,exports.specificity=function e(t,{format:n="array"}={}){let s="object"==typeof t?t:f(t,{recursive:!0});if(!s)return null;if("list"===s.type){let t=10,n=s.list.map((n=>{let s=e(n);return t=Math.max(t,...s),s})),r=n.map((e=>g(e,t)));return n[function(e){let t=e[0],n=0;for(let s=0;s<e.length;s++)e[s]>t&&(n=s,t=e[s]);return 0===e.length?-1:n}(r)]}let o=[0,0,0];return c(s,(t=>{if("id"===t.type)o[0]++;else if("class"===t.type||"attribute"===t.type)o[1]++;else if("type"===t.type&&"*"!==t.content||"pseudo-element"===t.type)o[2]++;else if("pseudo-class"===t.type&&"where"!==t.name)if(r.has(t.name)&&t.subtree){e(t.subtree).forEach(((e,t)=>o[t]+=e))}else o[1]++})),o},exports.specificityToNumber=g,exports.tokenize=a,exports.tokenizeBy=u,exports.walk=c;

@@ -5,3 +5,3 @@ var parsel = (function (exports) {

const TOKENS = {
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(?<caseSensitive>[iIsS])?\s*)?\]/gu,
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(\s(?<caseSensitive>[iIsS]))?\s*)?\]/gu,
id: /#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

@@ -133,4 +133,3 @@ class: /\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

let strings = [];
// FIXME Does not account for escaped backslashes before a quote
selector = selector.replace(/(['"])(\\\1|.)+?\1/g, (str, quote, content, start) => {
selector = selector.replace(/(['"])((?:\\\1|.)+?)\1/g, (str, quote, content, start) => {
strings.push({str, start});

@@ -244,3 +243,3 @@ return quote + "§".repeat(content.length) + quote;

}
else if (node.type === "compound") {
else if (node.type === "compound" || node.type === "list") {
for (let n of node.list) {

@@ -247,0 +246,0 @@ walk(n, callback, o, node);

@@ -1,1 +0,1 @@

var parsel=function(e){"use strict";const t={attribute:/\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(?<caseSensitive>[iIsS])?\s*)?\]/gu,id:/#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,class:/\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,comma:/\s*,\s*/g,combinator:/\s*[\s>+~]\s*/g,"pseudo-element":/::(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,"pseudo-class":/:(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,type:/(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)|\*/gu},n=new Set(["pseudo-class","pseudo-element"]),r=new Set([...n,"attribute"]),s=new Set(["combinator","comma"]),l=new Set(["not","is","where","has","matches","-moz-any","-webkit-any","nth-child","nth-last-child"]),o={"nth-child":/(?<index>[\dn+-]+)\s+of\s+(?<subtree>.+)/};l["nth-last-child"]=o["nth-child"];const i=Object.assign({},t);function u(e,t){let n="",r=[];for(;t<e.length;t++){let s=e[t];if("("===s)r.push(s);else if(")"===s){if(!(r.length>0))throw new Error("Closing paren without opening paren at "+t);r.pop()}if(n+=s,0===r.length)return n}throw new Error("Opening paren without closing paren")}function a(e,t){if(!e)return[];var n=[e];for(var r in t){let e=t[r];for(var l=0;l<n.length;l++){var o=n[l];if("string"==typeof o){e.lastIndex=0;var i=e.exec(o);if(i){let e=i.index-1,t=[],s=i[0],u=o.slice(0,e+1);u&&t.push(u),t.push({type:r,content:s,...i.groups});let a=o.slice(e+s.length+1);a&&t.push(a),n.splice(l,1,...t)}}}}let u=0;for(let e=0;e<n.length;e++){let t=n[e],r=t.length||t.content.length;"object"==typeof t&&(t.pos=[u,u+r],s.has(t.type)&&(t.content=t.content.trim()||" ")),u+=r}return n}function c(e){if(!e)return null;e=e.trim();let s=[];e=e.replace(/(['"])(\\\1|.)+?\1/g,((e,t,n,r)=>(s.push({str:e,start:r}),t+"§".repeat(n.length)+t)));let l,o=[],c=0;for(;(l=e.indexOf("(",c))>-1;){let t=u(e,l);o.push({str:t,start:l}),e=e.substring(0,l)+"("+"¶".repeat(t.length-2)+")"+e.substring(l+t.length),c=l+t.length}let p=a(e,t);function f(e,t,n){for(let r of e)for(let e of p)if(n.has(e.type)&&e.pos[0]<r.start&&r.start<e.pos[1]){let n=e.content;if(e.content=e.content.replace(t,r.str),e.content!==n){i[e.type].lastIndex=0;let t=i[e.type].exec(e.content).groups;Object.assign(e,t)}}}return f(o,/\(¶+\)/,n),f(s,/(['"])§+?\1/,r),p}function p(e,{list:t=!0}={}){if(t&&e.find((e=>"comma"===e.type))){let t=[],n=[];for(let r=0;r<e.length;r++)if("comma"===e[r].type){if(0===n.length)throw new Error("Incorrect comma at "+r);t.push(p(n,{list:!1})),n.length=0}else n.push(e[r]);if(0===n.length)throw new Error("Trailing comma");return t.push(p(n,{list:!1})),{type:"list",list:t}}for(let t=e.length-1;t>=0;t--){let n=e[t];if("combinator"===n.type){let r=e.slice(0,t),s=e.slice(t+1);return{type:"complex",combinator:n.content,left:p(r),right:p(s)}}}return 0===e.length?null:1===e.length?e[0]:{type:"compound",list:[...e]}}function f(e,t,n,r){if(e){if("complex"===e.type)f(e.left,t,n,e),f(e.right,t,n,e);else if("compound"===e.type)for(let r of e.list)f(r,t,n,e);else e.subtree&&n&&n.subtree&&f(e.subtree,t,n,e);t(e,r)}}function g(e,{recursive:t=!0,list:n=!0}={}){let r=c(e);if(!r)return null;let s=p(r,{list:n});return t&&f(s,(e=>{if("pseudo-class"===e.type&&e.argument&&l.has(e.name)){let t=e.argument;const n=o[e.name];if(n){const r=n.exec(t);if(!r)return;Object.assign(e,r.groups),t=r.groups.subtree}t&&(e.subtree=g(t,{recursive:!0,list:!0}))}})),s}function h(e,t){return t=t||Math.max(...e)+1,e[0]*t**2+e[1]*t+e[2]}return i["pseudo-element"]=RegExp(t["pseudo-element"].source.replace("(?<argument>¶+)","(?<argument>.+?)"),"gu"),i["pseudo-class"]=RegExp(t["pseudo-class"].source.replace("(?<argument>¶+)","(?<argument>.+)"),"gu"),e.RECURSIVE_PSEUDO_CLASSES=l,e.RECURSIVE_PSEUDO_CLASSES_ARGS=o,e.TOKENS=t,e.TRIM_TOKENS=s,e.gobbleParens=u,e.nestTokens=p,e.parse=g,e.specificity=function e(t,{format:n="array"}={}){let r="object"==typeof t?t:g(t,{recursive:!0});if(!r)return null;if("list"===r.type){let t=10,n=r.list.map((n=>{let r=e(n);return t=Math.max(t,...r),r})),s=n.map((e=>h(e,t)));return n[function(e){let t=e[0],n=0;for(let r=0;r<e.length;r++)e[r]>t&&(n=r,t=e[r]);return 0===e.length?-1:n}(s)]}let s=[0,0,0];return f(r,(t=>{if("id"===t.type)s[0]++;else if("class"===t.type||"attribute"===t.type)s[1]++;else if("type"===t.type&&"*"!==t.content||"pseudo-element"===t.type)s[2]++;else if("pseudo-class"===t.type&&"where"!==t.name)if(l.has(t.name)&&t.subtree){e(t.subtree).forEach(((e,t)=>s[t]+=e))}else s[1]++})),s},e.specificityToNumber=h,e.tokenize=c,e.tokenizeBy=a,e.walk=f,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
var parsel=function(e){"use strict";const t={attribute:/\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(\s(?<caseSensitive>[iIsS]))?\s*)?\]/gu,id:/#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,class:/\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,comma:/\s*,\s*/g,combinator:/\s*[\s>+~]\s*/g,"pseudo-element":/::(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,"pseudo-class":/:(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,type:/(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)|\*/gu},n=new Set(["pseudo-class","pseudo-element"]),r=new Set([...n,"attribute"]),s=new Set(["combinator","comma"]),l=new Set(["not","is","where","has","matches","-moz-any","-webkit-any","nth-child","nth-last-child"]),o={"nth-child":/(?<index>[\dn+-]+)\s+of\s+(?<subtree>.+)/};l["nth-last-child"]=o["nth-child"];const i=Object.assign({},t);function u(e,t){let n="",r=[];for(;t<e.length;t++){let s=e[t];if("("===s)r.push(s);else if(")"===s){if(!(r.length>0))throw new Error("Closing paren without opening paren at "+t);r.pop()}if(n+=s,0===r.length)return n}throw new Error("Opening paren without closing paren")}function a(e,t){if(!e)return[];var n=[e];for(var r in t){let e=t[r];for(var l=0;l<n.length;l++){var o=n[l];if("string"==typeof o){e.lastIndex=0;var i=e.exec(o);if(i){let e=i.index-1,t=[],s=i[0],u=o.slice(0,e+1);u&&t.push(u),t.push({type:r,content:s,...i.groups});let a=o.slice(e+s.length+1);a&&t.push(a),n.splice(l,1,...t)}}}}let u=0;for(let e=0;e<n.length;e++){let t=n[e],r=t.length||t.content.length;"object"==typeof t&&(t.pos=[u,u+r],s.has(t.type)&&(t.content=t.content.trim()||" ")),u+=r}return n}function c(e){if(!e)return null;e=e.trim();let s=[];e=e.replace(/(['"])((?:\\\1|.)+?)\1/g,((e,t,n,r)=>(s.push({str:e,start:r}),t+"§".repeat(n.length)+t)));let l,o=[],c=0;for(;(l=e.indexOf("(",c))>-1;){let t=u(e,l);o.push({str:t,start:l}),e=e.substring(0,l)+"("+"¶".repeat(t.length-2)+")"+e.substring(l+t.length),c=l+t.length}let p=a(e,t);function f(e,t,n){for(let r of e)for(let e of p)if(n.has(e.type)&&e.pos[0]<r.start&&r.start<e.pos[1]){let n=e.content;if(e.content=e.content.replace(t,r.str),e.content!==n){i[e.type].lastIndex=0;let t=i[e.type].exec(e.content).groups;Object.assign(e,t)}}}return f(o,/\(¶+\)/,n),f(s,/(['"])§+?\1/,r),p}function p(e,{list:t=!0}={}){if(t&&e.find((e=>"comma"===e.type))){let t=[],n=[];for(let r=0;r<e.length;r++)if("comma"===e[r].type){if(0===n.length)throw new Error("Incorrect comma at "+r);t.push(p(n,{list:!1})),n.length=0}else n.push(e[r]);if(0===n.length)throw new Error("Trailing comma");return t.push(p(n,{list:!1})),{type:"list",list:t}}for(let t=e.length-1;t>=0;t--){let n=e[t];if("combinator"===n.type){let r=e.slice(0,t),s=e.slice(t+1);return{type:"complex",combinator:n.content,left:p(r),right:p(s)}}}return 0===e.length?null:1===e.length?e[0]:{type:"compound",list:[...e]}}function f(e,t,n,r){if(e){if("complex"===e.type)f(e.left,t,n,e),f(e.right,t,n,e);else if("compound"===e.type||"list"===e.type)for(let r of e.list)f(r,t,n,e);else e.subtree&&n&&n.subtree&&f(e.subtree,t,n,e);t(e,r)}}function g(e,{recursive:t=!0,list:n=!0}={}){let r=c(e);if(!r)return null;let s=p(r,{list:n});return t&&f(s,(e=>{if("pseudo-class"===e.type&&e.argument&&l.has(e.name)){let t=e.argument;const n=o[e.name];if(n){const r=n.exec(t);if(!r)return;Object.assign(e,r.groups),t=r.groups.subtree}t&&(e.subtree=g(t,{recursive:!0,list:!0}))}})),s}function h(e,t){return t=t||Math.max(...e)+1,e[0]*t**2+e[1]*t+e[2]}return i["pseudo-element"]=RegExp(t["pseudo-element"].source.replace("(?<argument>¶+)","(?<argument>.+?)"),"gu"),i["pseudo-class"]=RegExp(t["pseudo-class"].source.replace("(?<argument>¶+)","(?<argument>.+)"),"gu"),e.RECURSIVE_PSEUDO_CLASSES=l,e.RECURSIVE_PSEUDO_CLASSES_ARGS=o,e.TOKENS=t,e.TRIM_TOKENS=s,e.gobbleParens=u,e.nestTokens=p,e.parse=g,e.specificity=function e(t,{format:n="array"}={}){let r="object"==typeof t?t:g(t,{recursive:!0});if(!r)return null;if("list"===r.type){let t=10,n=r.list.map((n=>{let r=e(n);return t=Math.max(t,...r),r})),s=n.map((e=>h(e,t)));return n[function(e){let t=e[0],n=0;for(let r=0;r<e.length;r++)e[r]>t&&(n=r,t=e[r]);return 0===e.length?-1:n}(s)]}let s=[0,0,0];return f(r,(t=>{if("id"===t.type)s[0]++;else if("class"===t.type||"attribute"===t.type)s[1]++;else if("type"===t.type&&"*"!==t.content||"pseudo-element"===t.type)s[2]++;else if("pseudo-class"===t.type&&"where"!==t.name)if(l.has(t.name)&&t.subtree){e(t.subtree).forEach(((e,t)=>s[t]+=e))}else s[1]++})),s},e.specificityToNumber=h,e.tokenize=c,e.tokenizeBy=a,e.walk=f,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
const TOKENS = {
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(?<caseSensitive>[iIsS])?\s*)?\]/gu,
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(\s(?<caseSensitive>[iIsS]))?\s*)?\]/gu,
id: /#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

@@ -129,4 +129,3 @@ class: /\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

let strings = [];
// FIXME Does not account for escaped backslashes before a quote
selector = selector.replace(/(['"])(\\\1|.)+?\1/g, (str, quote, content, start) => {
selector = selector.replace(/(['"])((?:\\\1|.)+?)\1/g, (str, quote, content, start) => {
strings.push({str, start});

@@ -240,3 +239,3 @@ return quote + "§".repeat(content.length) + quote;

}
else if (node.type === "compound") {
else if (node.type === "compound" || node.type === "list") {
for (let n of node.list) {

@@ -243,0 +242,0 @@ walk(n, callback, o, node);

@@ -1,1 +0,1 @@

const e={attribute:/\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(?<caseSensitive>[iIsS])?\s*)?\]/gu,id:/#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,class:/\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,comma:/\s*,\s*/g,combinator:/\s*[\s>+~]\s*/g,"pseudo-element":/::(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,"pseudo-class":/:(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,type:/(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)|\*/gu},t=new Set(["pseudo-class","pseudo-element"]),n=new Set([...t,"attribute"]),r=new Set(["combinator","comma"]),s=new Set(["not","is","where","has","matches","-moz-any","-webkit-any","nth-child","nth-last-child"]),l={"nth-child":/(?<index>[\dn+-]+)\s+of\s+(?<subtree>.+)/};s["nth-last-child"]=l["nth-child"];const o=Object.assign({},e);function u(e,t){let n="",r=[];for(;t<e.length;t++){let s=e[t];if("("===s)r.push(s);else if(")"===s){if(!(r.length>0))throw new Error("Closing paren without opening paren at "+t);r.pop()}if(n+=s,0===r.length)return n}throw new Error("Opening paren without closing paren")}function i(e,t){if(!e)return[];var n=[e];for(var s in t){let e=t[s];for(var l=0;l<n.length;l++){var o=n[l];if("string"==typeof o){e.lastIndex=0;var u=e.exec(o);if(u){let e=u.index-1,t=[],r=u[0],i=o.slice(0,e+1);i&&t.push(i),t.push({type:s,content:r,...u.groups});let a=o.slice(e+r.length+1);a&&t.push(a),n.splice(l,1,...t)}}}}let i=0;for(let e=0;e<n.length;e++){let t=n[e],s=t.length||t.content.length;"object"==typeof t&&(t.pos=[i,i+s],r.has(t.type)&&(t.content=t.content.trim()||" ")),i+=s}return n}function a(r){if(!r)return null;r=r.trim();let s=[];r=r.replace(/(['"])(\\\1|.)+?\1/g,((e,t,n,r)=>(s.push({str:e,start:r}),t+"§".repeat(n.length)+t)));let l,a=[],c=0;for(;(l=r.indexOf("(",c))>-1;){let e=u(r,l);a.push({str:e,start:l}),r=r.substring(0,l)+"("+"¶".repeat(e.length-2)+")"+r.substring(l+e.length),c=l+e.length}let p=i(r,e);function f(e,t,n){for(let r of e)for(let e of p)if(n.has(e.type)&&e.pos[0]<r.start&&r.start<e.pos[1]){let n=e.content;if(e.content=e.content.replace(t,r.str),e.content!==n){o[e.type].lastIndex=0;let t=o[e.type].exec(e.content).groups;Object.assign(e,t)}}}return f(a,/\(¶+\)/,t),f(s,/(['"])§+?\1/,n),p}function c(e,{list:t=!0}={}){if(t&&e.find((e=>"comma"===e.type))){let t=[],n=[];for(let r=0;r<e.length;r++)if("comma"===e[r].type){if(0===n.length)throw new Error("Incorrect comma at "+r);t.push(c(n,{list:!1})),n.length=0}else n.push(e[r]);if(0===n.length)throw new Error("Trailing comma");return t.push(c(n,{list:!1})),{type:"list",list:t}}for(let t=e.length-1;t>=0;t--){let n=e[t];if("combinator"===n.type){let r=e.slice(0,t),s=e.slice(t+1);return{type:"complex",combinator:n.content,left:c(r),right:c(s)}}}return 0===e.length?null:1===e.length?e[0]:{type:"compound",list:[...e]}}function p(e,t,n,r){if(e){if("complex"===e.type)p(e.left,t,n,e),p(e.right,t,n,e);else if("compound"===e.type)for(let r of e.list)p(r,t,n,e);else e.subtree&&n&&n.subtree&&p(e.subtree,t,n,e);t(e,r)}}function f(e,{recursive:t=!0,list:n=!0}={}){let r=a(e);if(!r)return null;let o=c(r,{list:n});return t&&p(o,(e=>{if("pseudo-class"===e.type&&e.argument&&s.has(e.name)){let t=e.argument;const n=l[e.name];if(n){const r=n.exec(t);if(!r)return;Object.assign(e,r.groups),t=r.groups.subtree}t&&(e.subtree=f(t,{recursive:!0,list:!0}))}})),o}function g(e,t){return t=t||Math.max(...e)+1,e[0]*t**2+e[1]*t+e[2]}function h(e,{format:t="array"}={}){let n="object"==typeof e?e:f(e,{recursive:!0});if(!n)return null;if("list"===n.type){let e=10,t=n.list.map((t=>{let n=h(t);return e=Math.max(e,...n),n})),r=t.map((t=>g(t,e)));return t[function(e){let t=e[0],n=0;for(let r=0;r<e.length;r++)e[r]>t&&(n=r,t=e[r]);return 0===e.length?-1:n}(r)]}let r=[0,0,0];return p(n,(e=>{if("id"===e.type)r[0]++;else if("class"===e.type||"attribute"===e.type)r[1]++;else if("type"===e.type&&"*"!==e.content||"pseudo-element"===e.type)r[2]++;else if("pseudo-class"===e.type&&"where"!==e.name)if(s.has(e.name)&&e.subtree){h(e.subtree).forEach(((e,t)=>r[t]+=e))}else r[1]++})),r}o["pseudo-element"]=RegExp(e["pseudo-element"].source.replace("(?<argument>¶+)","(?<argument>.+?)"),"gu"),o["pseudo-class"]=RegExp(e["pseudo-class"].source.replace("(?<argument>¶+)","(?<argument>.+)"),"gu");export{s as RECURSIVE_PSEUDO_CLASSES,l as RECURSIVE_PSEUDO_CLASSES_ARGS,e as TOKENS,r as TRIM_TOKENS,u as gobbleParens,c as nestTokens,f as parse,h as specificity,g as specificityToNumber,a as tokenize,i as tokenizeBy,p as walk};
const e={attribute:/\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(\s(?<caseSensitive>[iIsS]))?\s*)?\]/gu,id:/#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,class:/\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,comma:/\s*,\s*/g,combinator:/\s*[\s>+~]\s*/g,"pseudo-element":/::(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,"pseudo-class":/:(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,type:/(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)|\*/gu},t=new Set(["pseudo-class","pseudo-element"]),n=new Set([...t,"attribute"]),r=new Set(["combinator","comma"]),s=new Set(["not","is","where","has","matches","-moz-any","-webkit-any","nth-child","nth-last-child"]),l={"nth-child":/(?<index>[\dn+-]+)\s+of\s+(?<subtree>.+)/};s["nth-last-child"]=l["nth-child"];const o=Object.assign({},e);function u(e,t){let n="",r=[];for(;t<e.length;t++){let s=e[t];if("("===s)r.push(s);else if(")"===s){if(!(r.length>0))throw new Error("Closing paren without opening paren at "+t);r.pop()}if(n+=s,0===r.length)return n}throw new Error("Opening paren without closing paren")}function i(e,t){if(!e)return[];var n=[e];for(var s in t){let e=t[s];for(var l=0;l<n.length;l++){var o=n[l];if("string"==typeof o){e.lastIndex=0;var u=e.exec(o);if(u){let e=u.index-1,t=[],r=u[0],i=o.slice(0,e+1);i&&t.push(i),t.push({type:s,content:r,...u.groups});let a=o.slice(e+r.length+1);a&&t.push(a),n.splice(l,1,...t)}}}}let i=0;for(let e=0;e<n.length;e++){let t=n[e],s=t.length||t.content.length;"object"==typeof t&&(t.pos=[i,i+s],r.has(t.type)&&(t.content=t.content.trim()||" ")),i+=s}return n}function a(r){if(!r)return null;r=r.trim();let s=[];r=r.replace(/(['"])((?:\\\1|.)+?)\1/g,((e,t,n,r)=>(s.push({str:e,start:r}),t+"§".repeat(n.length)+t)));let l,a=[],c=0;for(;(l=r.indexOf("(",c))>-1;){let e=u(r,l);a.push({str:e,start:l}),r=r.substring(0,l)+"("+"¶".repeat(e.length-2)+")"+r.substring(l+e.length),c=l+e.length}let p=i(r,e);function f(e,t,n){for(let r of e)for(let e of p)if(n.has(e.type)&&e.pos[0]<r.start&&r.start<e.pos[1]){let n=e.content;if(e.content=e.content.replace(t,r.str),e.content!==n){o[e.type].lastIndex=0;let t=o[e.type].exec(e.content).groups;Object.assign(e,t)}}}return f(a,/\(¶+\)/,t),f(s,/(['"])§+?\1/,n),p}function c(e,{list:t=!0}={}){if(t&&e.find((e=>"comma"===e.type))){let t=[],n=[];for(let r=0;r<e.length;r++)if("comma"===e[r].type){if(0===n.length)throw new Error("Incorrect comma at "+r);t.push(c(n,{list:!1})),n.length=0}else n.push(e[r]);if(0===n.length)throw new Error("Trailing comma");return t.push(c(n,{list:!1})),{type:"list",list:t}}for(let t=e.length-1;t>=0;t--){let n=e[t];if("combinator"===n.type){let r=e.slice(0,t),s=e.slice(t+1);return{type:"complex",combinator:n.content,left:c(r),right:c(s)}}}return 0===e.length?null:1===e.length?e[0]:{type:"compound",list:[...e]}}function p(e,t,n,r){if(e){if("complex"===e.type)p(e.left,t,n,e),p(e.right,t,n,e);else if("compound"===e.type||"list"===e.type)for(let r of e.list)p(r,t,n,e);else e.subtree&&n&&n.subtree&&p(e.subtree,t,n,e);t(e,r)}}function f(e,{recursive:t=!0,list:n=!0}={}){let r=a(e);if(!r)return null;let o=c(r,{list:n});return t&&p(o,(e=>{if("pseudo-class"===e.type&&e.argument&&s.has(e.name)){let t=e.argument;const n=l[e.name];if(n){const r=n.exec(t);if(!r)return;Object.assign(e,r.groups),t=r.groups.subtree}t&&(e.subtree=f(t,{recursive:!0,list:!0}))}})),o}function g(e,t){return t=t||Math.max(...e)+1,e[0]*t**2+e[1]*t+e[2]}function h(e,{format:t="array"}={}){let n="object"==typeof e?e:f(e,{recursive:!0});if(!n)return null;if("list"===n.type){let e=10,t=n.list.map((t=>{let n=h(t);return e=Math.max(e,...n),n})),r=t.map((t=>g(t,e)));return t[function(e){let t=e[0],n=0;for(let r=0;r<e.length;r++)e[r]>t&&(n=r,t=e[r]);return 0===e.length?-1:n}(r)]}let r=[0,0,0];return p(n,(e=>{if("id"===e.type)r[0]++;else if("class"===e.type||"attribute"===e.type)r[1]++;else if("type"===e.type&&"*"!==e.content||"pseudo-element"===e.type)r[2]++;else if("pseudo-class"===e.type&&"where"!==e.name)if(s.has(e.name)&&e.subtree){h(e.subtree).forEach(((e,t)=>r[t]+=e))}else r[1]++})),r}o["pseudo-element"]=RegExp(e["pseudo-element"].source.replace("(?<argument>¶+)","(?<argument>.+?)"),"gu"),o["pseudo-class"]=RegExp(e["pseudo-class"].source.replace("(?<argument>¶+)","(?<argument>.+)"),"gu");export{s as RECURSIVE_PSEUDO_CLASSES,l as RECURSIVE_PSEUDO_CLASSES_ARGS,e as TOKENS,r as TRIM_TOKENS,u as gobbleParens,c as nestTokens,f as parse,h as specificity,g as specificityToNumber,a as tokenize,i as tokenizeBy,p as walk};

@@ -8,3 +8,3 @@ (function (global, factory) {

const TOKENS = {
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(?<caseSensitive>[iIsS])?\s*)?\]/gu,
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(\s(?<caseSensitive>[iIsS]))?\s*)?\]/gu,
id: /#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

@@ -136,4 +136,3 @@ class: /\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

let strings = [];
// FIXME Does not account for escaped backslashes before a quote
selector = selector.replace(/(['"])(\\\1|.)+?\1/g, (str, quote, content, start) => {
selector = selector.replace(/(['"])((?:\\\1|.)+?)\1/g, (str, quote, content, start) => {
strings.push({str, start});

@@ -247,3 +246,3 @@ return quote + "§".repeat(content.length) + quote;

}
else if (node.type === "compound") {
else if (node.type === "compound" || node.type === "list") {
for (let n of node.list) {

@@ -250,0 +249,0 @@ walk(n, callback, o, node);

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).parsel={})}(this,(function(e){"use strict";const t={attribute:/\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(?<caseSensitive>[iIsS])?\s*)?\]/gu,id:/#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,class:/\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,comma:/\s*,\s*/g,combinator:/\s*[\s>+~]\s*/g,"pseudo-element":/::(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,"pseudo-class":/:(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,type:/(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)|\*/gu},n=new Set(["pseudo-class","pseudo-element"]),s=new Set([...n,"attribute"]),r=new Set(["combinator","comma"]),l=new Set(["not","is","where","has","matches","-moz-any","-webkit-any","nth-child","nth-last-child"]),o={"nth-child":/(?<index>[\dn+-]+)\s+of\s+(?<subtree>.+)/};l["nth-last-child"]=o["nth-child"];const i=Object.assign({},t);function u(e,t){let n="",s=[];for(;t<e.length;t++){let r=e[t];if("("===r)s.push(r);else if(")"===r){if(!(s.length>0))throw new Error("Closing paren without opening paren at "+t);s.pop()}if(n+=r,0===s.length)return n}throw new Error("Opening paren without closing paren")}function a(e,t){if(!e)return[];var n=[e];for(var s in t){let e=t[s];for(var l=0;l<n.length;l++){var o=n[l];if("string"==typeof o){e.lastIndex=0;var i=e.exec(o);if(i){let e=i.index-1,t=[],r=i[0],u=o.slice(0,e+1);u&&t.push(u),t.push({type:s,content:r,...i.groups});let a=o.slice(e+r.length+1);a&&t.push(a),n.splice(l,1,...t)}}}}let u=0;for(let e=0;e<n.length;e++){let t=n[e],s=t.length||t.content.length;"object"==typeof t&&(t.pos=[u,u+s],r.has(t.type)&&(t.content=t.content.trim()||" ")),u+=s}return n}function c(e){if(!e)return null;e=e.trim();let r=[];e=e.replace(/(['"])(\\\1|.)+?\1/g,((e,t,n,s)=>(r.push({str:e,start:s}),t+"§".repeat(n.length)+t)));let l,o=[],c=0;for(;(l=e.indexOf("(",c))>-1;){let t=u(e,l);o.push({str:t,start:l}),e=e.substring(0,l)+"("+"¶".repeat(t.length-2)+")"+e.substring(l+t.length),c=l+t.length}let p=a(e,t);function f(e,t,n){for(let s of e)for(let e of p)if(n.has(e.type)&&e.pos[0]<s.start&&s.start<e.pos[1]){let n=e.content;if(e.content=e.content.replace(t,s.str),e.content!==n){i[e.type].lastIndex=0;let t=i[e.type].exec(e.content).groups;Object.assign(e,t)}}}return f(o,/\(¶+\)/,n),f(r,/(['"])§+?\1/,s),p}function p(e,{list:t=!0}={}){if(t&&e.find((e=>"comma"===e.type))){let t=[],n=[];for(let s=0;s<e.length;s++)if("comma"===e[s].type){if(0===n.length)throw new Error("Incorrect comma at "+s);t.push(p(n,{list:!1})),n.length=0}else n.push(e[s]);if(0===n.length)throw new Error("Trailing comma");return t.push(p(n,{list:!1})),{type:"list",list:t}}for(let t=e.length-1;t>=0;t--){let n=e[t];if("combinator"===n.type){let s=e.slice(0,t),r=e.slice(t+1);return{type:"complex",combinator:n.content,left:p(s),right:p(r)}}}return 0===e.length?null:1===e.length?e[0]:{type:"compound",list:[...e]}}function f(e,t,n,s){if(e){if("complex"===e.type)f(e.left,t,n,e),f(e.right,t,n,e);else if("compound"===e.type)for(let s of e.list)f(s,t,n,e);else e.subtree&&n&&n.subtree&&f(e.subtree,t,n,e);t(e,s)}}function g(e,{recursive:t=!0,list:n=!0}={}){let s=c(e);if(!s)return null;let r=p(s,{list:n});return t&&f(r,(e=>{if("pseudo-class"===e.type&&e.argument&&l.has(e.name)){let t=e.argument;const n=o[e.name];if(n){const s=n.exec(t);if(!s)return;Object.assign(e,s.groups),t=s.groups.subtree}t&&(e.subtree=g(t,{recursive:!0,list:!0}))}})),r}function h(e,t){return t=t||Math.max(...e)+1,e[0]*t**2+e[1]*t+e[2]}i["pseudo-element"]=RegExp(t["pseudo-element"].source.replace("(?<argument>¶+)","(?<argument>.+?)"),"gu"),i["pseudo-class"]=RegExp(t["pseudo-class"].source.replace("(?<argument>¶+)","(?<argument>.+)"),"gu"),e.RECURSIVE_PSEUDO_CLASSES=l,e.RECURSIVE_PSEUDO_CLASSES_ARGS=o,e.TOKENS=t,e.TRIM_TOKENS=r,e.gobbleParens=u,e.nestTokens=p,e.parse=g,e.specificity=function e(t,{format:n="array"}={}){let s="object"==typeof t?t:g(t,{recursive:!0});if(!s)return null;if("list"===s.type){let t=10,n=s.list.map((n=>{let s=e(n);return t=Math.max(t,...s),s})),r=n.map((e=>h(e,t)));return n[function(e){let t=e[0],n=0;for(let s=0;s<e.length;s++)e[s]>t&&(n=s,t=e[s]);return 0===e.length?-1:n}(r)]}let r=[0,0,0];return f(s,(t=>{if("id"===t.type)r[0]++;else if("class"===t.type||"attribute"===t.type)r[1]++;else if("type"===t.type&&"*"!==t.content||"pseudo-element"===t.type)r[2]++;else if("pseudo-class"===t.type&&"where"!==t.name)if(l.has(t.name)&&t.subtree){e(t.subtree).forEach(((e,t)=>r[t]+=e))}else r[1]++})),r},e.specificityToNumber=h,e.tokenize=c,e.tokenizeBy=a,e.walk=f,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).parsel={})}(this,(function(e){"use strict";const t={attribute:/\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(\s(?<caseSensitive>[iIsS]))?\s*)?\]/gu,id:/#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,class:/\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,comma:/\s*,\s*/g,combinator:/\s*[\s>+~]\s*/g,"pseudo-element":/::(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,"pseudo-class":/:(?<name>[-\w\u{0080}-\u{FFFF}]+)(?:\((?<argument>¶+)\))?/gu,type:/(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)|\*/gu},n=new Set(["pseudo-class","pseudo-element"]),s=new Set([...n,"attribute"]),r=new Set(["combinator","comma"]),l=new Set(["not","is","where","has","matches","-moz-any","-webkit-any","nth-child","nth-last-child"]),o={"nth-child":/(?<index>[\dn+-]+)\s+of\s+(?<subtree>.+)/};l["nth-last-child"]=o["nth-child"];const i=Object.assign({},t);function u(e,t){let n="",s=[];for(;t<e.length;t++){let r=e[t];if("("===r)s.push(r);else if(")"===r){if(!(s.length>0))throw new Error("Closing paren without opening paren at "+t);s.pop()}if(n+=r,0===s.length)return n}throw new Error("Opening paren without closing paren")}function a(e,t){if(!e)return[];var n=[e];for(var s in t){let e=t[s];for(var l=0;l<n.length;l++){var o=n[l];if("string"==typeof o){e.lastIndex=0;var i=e.exec(o);if(i){let e=i.index-1,t=[],r=i[0],u=o.slice(0,e+1);u&&t.push(u),t.push({type:s,content:r,...i.groups});let a=o.slice(e+r.length+1);a&&t.push(a),n.splice(l,1,...t)}}}}let u=0;for(let e=0;e<n.length;e++){let t=n[e],s=t.length||t.content.length;"object"==typeof t&&(t.pos=[u,u+s],r.has(t.type)&&(t.content=t.content.trim()||" ")),u+=s}return n}function c(e){if(!e)return null;e=e.trim();let r=[];e=e.replace(/(['"])((?:\\\1|.)+?)\1/g,((e,t,n,s)=>(r.push({str:e,start:s}),t+"§".repeat(n.length)+t)));let l,o=[],c=0;for(;(l=e.indexOf("(",c))>-1;){let t=u(e,l);o.push({str:t,start:l}),e=e.substring(0,l)+"("+"¶".repeat(t.length-2)+")"+e.substring(l+t.length),c=l+t.length}let p=a(e,t);function f(e,t,n){for(let s of e)for(let e of p)if(n.has(e.type)&&e.pos[0]<s.start&&s.start<e.pos[1]){let n=e.content;if(e.content=e.content.replace(t,s.str),e.content!==n){i[e.type].lastIndex=0;let t=i[e.type].exec(e.content).groups;Object.assign(e,t)}}}return f(o,/\(¶+\)/,n),f(r,/(['"])§+?\1/,s),p}function p(e,{list:t=!0}={}){if(t&&e.find((e=>"comma"===e.type))){let t=[],n=[];for(let s=0;s<e.length;s++)if("comma"===e[s].type){if(0===n.length)throw new Error("Incorrect comma at "+s);t.push(p(n,{list:!1})),n.length=0}else n.push(e[s]);if(0===n.length)throw new Error("Trailing comma");return t.push(p(n,{list:!1})),{type:"list",list:t}}for(let t=e.length-1;t>=0;t--){let n=e[t];if("combinator"===n.type){let s=e.slice(0,t),r=e.slice(t+1);return{type:"complex",combinator:n.content,left:p(s),right:p(r)}}}return 0===e.length?null:1===e.length?e[0]:{type:"compound",list:[...e]}}function f(e,t,n,s){if(e){if("complex"===e.type)f(e.left,t,n,e),f(e.right,t,n,e);else if("compound"===e.type||"list"===e.type)for(let s of e.list)f(s,t,n,e);else e.subtree&&n&&n.subtree&&f(e.subtree,t,n,e);t(e,s)}}function g(e,{recursive:t=!0,list:n=!0}={}){let s=c(e);if(!s)return null;let r=p(s,{list:n});return t&&f(r,(e=>{if("pseudo-class"===e.type&&e.argument&&l.has(e.name)){let t=e.argument;const n=o[e.name];if(n){const s=n.exec(t);if(!s)return;Object.assign(e,s.groups),t=s.groups.subtree}t&&(e.subtree=g(t,{recursive:!0,list:!0}))}})),r}function h(e,t){return t=t||Math.max(...e)+1,e[0]*t**2+e[1]*t+e[2]}i["pseudo-element"]=RegExp(t["pseudo-element"].source.replace("(?<argument>¶+)","(?<argument>.+?)"),"gu"),i["pseudo-class"]=RegExp(t["pseudo-class"].source.replace("(?<argument>¶+)","(?<argument>.+)"),"gu"),e.RECURSIVE_PSEUDO_CLASSES=l,e.RECURSIVE_PSEUDO_CLASSES_ARGS=o,e.TOKENS=t,e.TRIM_TOKENS=r,e.gobbleParens=u,e.nestTokens=p,e.parse=g,e.specificity=function e(t,{format:n="array"}={}){let s="object"==typeof t?t:g(t,{recursive:!0});if(!s)return null;if("list"===s.type){let t=10,n=s.list.map((n=>{let s=e(n);return t=Math.max(t,...s),s})),r=n.map((e=>h(e,t)));return n[function(e){let t=e[0],n=0;for(let s=0;s<e.length;s++)e[s]>t&&(n=s,t=e[s]);return 0===e.length?-1:n}(r)]}let r=[0,0,0];return f(s,(t=>{if("id"===t.type)r[0]++;else if("class"===t.type||"attribute"===t.type)r[1]++;else if("type"===t.type&&"*"!==t.content||"pseudo-element"===t.type)r[2]++;else if("pseudo-class"===t.type&&"where"!==t.name)if(l.has(t.name)&&t.subtree){e(t.subtree).forEach(((e,t)=>r[t]+=e))}else r[1]++})),r},e.specificityToNumber=h,e.tokenize=c,e.tokenizeBy=a,e.walk=f,Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "parsel-js",
"version": "1.0.2",
"version": "1.0.3",
"description": "A tiny, permissive CSS selector parser",

@@ -15,5 +15,6 @@ "main": "dist/cjs/parsel.min.js",

},
"type": "module",
"scripts": {
"test": "open test.html",
"build": "rollup -c"
"build": "npx rollup -c"
},

@@ -20,0 +21,0 @@ "repository": {

export const TOKENS = {
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(?<caseSensitive>[iIsS])?\s*)?\]/gu,
attribute: /\[\s*(?:(?<namespace>\*|[-\w]*)\|)?(?<name>[-\w\u{0080}-\u{FFFF}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(\s(?<caseSensitive>[iIsS]))?\s*)?\]/gu,
id: /#(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

@@ -129,4 +129,3 @@ class: /\.(?<name>(?:[-\w\u{0080}-\u{FFFF}]|\\.)+)/gu,

let strings = [];
// FIXME Does not account for escaped backslashes before a quote
selector = selector.replace(/(['"])(\\\1|.)+?\1/g, (str, quote, content, start) => {
selector = selector.replace(/(['"])((?:\\\1|.)+?)\1/g, (str, quote, content, start) => {
strings.push({str, start});

@@ -240,3 +239,3 @@ return quote + "§".repeat(content.length) + quote;

}
else if (node.type === "compound") {
else if (node.type === "compound" || node.type === "list") {
for (let n of node.list) {

@@ -243,0 +242,0 @@ walk(n, callback, o, node);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc