@stacksjs/ts-css 0.3.26 → 0.3.27
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.
- package/dist/bin/cli.js +4 -4
- package/dist/bin/cssx.js +31 -31
- package/dist/chunk-0bs815x2.js +3 -0
- package/dist/chunk-bxhasn1f.js +2 -0
- package/dist/engine/generator.d.ts +1 -0
- package/dist/engine/index.d.ts +1 -0
- package/dist/engine/index.js +34 -34
- package/dist/engine/resolve.d.ts +87 -0
- package/dist/index.js +1 -1
- package/dist/optimize/index.js +1 -1
- package/dist/select/index.js +1 -1
- package/dist/select/pseudo-selectors/selectors.d.ts +25 -1
- package/package.json +1 -1
- package/dist/chunk-k6ta54hd.js +0 -3
- package/dist/chunk-zn8gy7w7.js +0 -2
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { CSSGenerator } from './generator';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve one class into the rules it generates.
|
|
4
|
+
*
|
|
5
|
+
* An empty result means the engine does not know the class -- a typo, or a
|
|
6
|
+
* utility it rejects. A renderer should report that rather than guess, which
|
|
7
|
+
* is the same answer the browser gets: no rule.
|
|
8
|
+
*
|
|
9
|
+
* A class the engine knows but that sets nothing -- `group`, `peer/draft` --
|
|
10
|
+
* resolves to a single entry with no properties instead, so it is not mistaken
|
|
11
|
+
* for an unknown one and reported as a typo.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveUtility(className: string, generator: CSSGenerator): ResolvedUtility[];
|
|
14
|
+
/**
|
|
15
|
+
* A CSS length in points, or undefined when it is not a plain length.
|
|
16
|
+
*
|
|
17
|
+
* `em` resolves against the element's own font size, which is what
|
|
18
|
+
* `tracking-wide` (`0.025em`) means. Native had been resolving it against a
|
|
19
|
+
* fixed 16, so any text that was not 16 points got the wrong spacing.
|
|
20
|
+
*
|
|
21
|
+
* Anything this cannot reduce to a number -- `calc()`, a percentage, a
|
|
22
|
+
* variable -- is undefined, for the renderer to report.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveLength(value: string, context?: LengthContext): number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* A `line-height` in points.
|
|
27
|
+
*
|
|
28
|
+
* Unlike other properties, a unitless line-height is a multiplier of the font
|
|
29
|
+
* size: `leading-tight` is `1.25`, so `text-sm leading-tight` is 17.5 points.
|
|
30
|
+
* Native had been multiplying by a fixed 16 and getting 20.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveLineHeight(value: string, fontSize: number, rootFontSize?: number): number | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* A colour as channels a native renderer can hand to its colour type.
|
|
35
|
+
*
|
|
36
|
+
* Hex stays sRGB; an oklch colour -- every palette colour in Tailwind v4 --
|
|
37
|
+
* goes into `options.space`. `var()` resolves against `options.variables` and
|
|
38
|
+
* then its own fallback, and the `color-mix(..., transparent)` form the engine
|
|
39
|
+
* uses for opacity on a variable colour comes back with its alpha scaled.
|
|
40
|
+
*
|
|
41
|
+
* Undefined for anything else (`currentColor`, a named colour, an unset
|
|
42
|
+
* variable with no fallback), which the renderer resolves or reports.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveColor(value: string, options?: ColorOptions): ResolvedColor | undefined;
|
|
45
|
+
/** `#rrggbb`, or `#rrggbbaa` when not opaque. Meaningful for an sRGB colour. */
|
|
46
|
+
export declare function colorToHex(color: ResolvedColor): string;
|
|
47
|
+
/**
|
|
48
|
+
* Resolving utilities for a renderer that is not a browser.
|
|
49
|
+
*
|
|
50
|
+
* A native renderer cannot read a stylesheet, so it has historically carried
|
|
51
|
+
* its own copy of the utility table -- stx's native compiler re-parses class
|
|
52
|
+
* names against a hardcoded palette. Two implementations of the same semantics
|
|
53
|
+
* drift: measured against each other, native dropped the line-height a
|
|
54
|
+
* `text-*` utility sets, resolved `leading-*` and `tracking-*` against a fixed
|
|
55
|
+
* 16px instead of the font size, carried Tailwind v3 colours where the web has
|
|
56
|
+
* v4, and silently dropped `hover:`, `active:` and `focus:`.
|
|
57
|
+
*
|
|
58
|
+
* This lets such a renderer ask the engine instead, so there is one source of
|
|
59
|
+
* semantics. It answers in CSS terms -- declarations, and the variants that
|
|
60
|
+
* condition them -- and leaves mapping a CSS property onto a native one to the
|
|
61
|
+
* renderer, which is the only part that is genuinely platform-specific. It
|
|
62
|
+
* also resolves the two kinds of value a native renderer cannot interpret on
|
|
63
|
+
* its own: lengths relative to a font size, and oklch colours.
|
|
64
|
+
*/
|
|
65
|
+
export declare interface ResolvedUtility {
|
|
66
|
+
variants: string[]
|
|
67
|
+
properties: Record<string, string>
|
|
68
|
+
mediaQuery?: string
|
|
69
|
+
childSelector?: string
|
|
70
|
+
important: boolean
|
|
71
|
+
}
|
|
72
|
+
export declare interface LengthContext {
|
|
73
|
+
fontSize?: number
|
|
74
|
+
rootFontSize?: number
|
|
75
|
+
}
|
|
76
|
+
export declare interface ResolvedColor {
|
|
77
|
+
space: 'srgb' | 'display-p3'
|
|
78
|
+
r: number
|
|
79
|
+
g: number
|
|
80
|
+
b: number
|
|
81
|
+
alpha: number
|
|
82
|
+
}
|
|
83
|
+
export declare interface ColorOptions {
|
|
84
|
+
space?: 'srgb' | 'display-p3'
|
|
85
|
+
variables?: Record<string, string>
|
|
86
|
+
}
|
|
87
|
+
declare type Vector = [number, number, number];
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{t,m,e,o,n,T}from"./chunk-8h5zg4ad.js";import{r,f,x,O}from"./chunk-dbj97h19.js";import{v,R,k,C}from"./chunk-
|
|
2
|
+
import{t,m,e,o,n,T}from"./chunk-8h5zg4ad.js";import{r,f,x,O}from"./chunk-dbj97h19.js";import{v,R,k,C}from"./chunk-bxhasn1f.js";import{h,a,l,w,A}from"./chunk-0bs815x2.js";var s={floatPrecision:3,verbose:!1},i=null;async function c(){if(!i){let{loadConfig:p}=await import("bunfig");i=await p({name:"ts-css",defaultConfig:s})}return i}var S=s;export{t as List,m as clone,S as config,C as cssSelect,O as cssWhat,A as csso,T as csstree,s as defaultConfig,e as generate,c as getConfig,k as is,x as isTraversal,h as minify,a as minifyBlock,o as parse,r as parseSelector,v as selectAll,R as selectOne,l as specificity,f as stringifySelector,w as syntax,n as walk};
|
package/dist/optimize/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{s,u,p,h,a,l,S,w}from"../chunk-
|
|
2
|
+
import{s,u,p,h,a,l,S,w}from"../chunk-0bs815x2.js";import"../chunk-8h5zg4ad.js";import"../chunk-dbj97h19.js";export{p as compressTree,u as dedupeDeclarations,h as minify,a as minifyBlock,s as removeComments,l as specificity,S as specificityToString,w as syntax};
|
package/dist/select/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{i,g,P,v,R,k}from"../chunk-
|
|
2
|
+
import{i,g,P,v,R,k}from"../chunk-bxhasn1f.js";import"../chunk-dbj97h19.js";export{P as clearSelectorCache,g as compile,k as is,i as parseAndCompile,v as selectAll,R as selectOne};
|
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import type { CompiledQuery, Options } from '../types';
|
|
2
2
|
import type { Selector } from '../../what/index';
|
|
3
3
|
export declare function compileGeneric<Node, ElementNode extends Node>(segments: Selector[][], options: Options<Node, ElementNode>): CompiledQuery<ElementNode>;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function isCombinator(token: Selector): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Compile one complex selector.
|
|
7
|
+
*
|
|
8
|
+
* With an `anchor`, `tokens` is a RELATIVE selector (Selectors 4), as in the
|
|
9
|
+
* argument to `:has()`: its leftmost compound is the anchor itself, and an
|
|
10
|
+
* argument with no leading combinator takes the implied descendant one. So
|
|
11
|
+
* `> span` is "a span whose parent is the anchor" and `section span` is "a
|
|
12
|
+
* span under a section under the anchor". Without the anchor, the empty
|
|
13
|
+
* leading compound was ALWAYS_TRUE, which made `> span` "a span whose parent
|
|
14
|
+
* is anything" and let `section span` match through a section OUTSIDE the
|
|
15
|
+
* subject.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseAndCompile<Node, ElementNode extends Node>(tokens: Selector[], options: Options<Node, ElementNode>, anchor?: SelectorAnchor<ElementNode>): CompiledQuery<ElementNode>;
|
|
18
|
+
/**
|
|
19
|
+
* The element a relative selector is measured from.
|
|
20
|
+
*
|
|
21
|
+
* Mutable on purpose: `:has()` compiles its argument once and then evaluates
|
|
22
|
+
* it from a different subject for every candidate, so the anchor is read at
|
|
23
|
+
* match time rather than captured at compile time the way `:scope` captures
|
|
24
|
+
* `options.context`.
|
|
25
|
+
*/
|
|
26
|
+
export declare interface SelectorAnchor<ElementNode> {
|
|
27
|
+
current: ElementNode | null
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/ts-css",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.27",
|
|
5
5
|
"description": "Pure-TypeScript CSS toolkit and utility-first CSS engine for Bun/Node — parser, walker, generator, selector engine, minifier, and a Tailwind-compatible utility engine. Zero runtime deps.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
package/dist/chunk-k6ta54hd.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{e,o,n}from"./chunk-8h5zg4ad.js";import{r}from"./chunk-dbj97h19.js";import{c}from"./chunk-vbjv9wf0.js";var A={};c(A,{compressTree:()=>p,dedupeDeclarations:()=>u,minify:()=>h,minifyBlock:()=>a,removeComments:()=>s,specificity:()=>l,specificityToString:()=>S,syntax:()=>w});function s(i,t={}){let f=t.exclamation??!1,y=!1;n(i,(m,b,g)=>{if(m.type!=="Comment")return;let d=m.value.startsWith("!");if(f===!0&&d)return;if(f==="first-exclamation"&&d&&!y){y=!0;return}if(b&&g)g.remove(b)})}function u(i){n(i,(t)=>{if(t.type!=="Block"&&t.type!=="DeclarationList")return;if(!("children"in t)||!t.children)return;let f=t.children,y=f.head;if(y==null||y.next==null)return;let m=0;for(let d=y;d!=null;d=d.next)if(d.data.type==="Declaration"){if(m++,m>=2)break}if(m<2)return;let b=new Map,g=[];for(let d=y;d!=null;d=d.next){let x=d.data;if(x.type!=="Declaration")continue;let v=x.property,N=b.get(v);if(N){let z=!!N.decl.important,W=!!x.important;if(W||z===W)g.push(N.item),b.set(v,{item:d,decl:x});else g.push(d)}else b.set(v,{item:d,decl:x})}for(let d of g)f.remove(d)})}var G={black:"#000",fuchsia:"#f0f",white:"#fff",red:"#f00",cyan:"#0ff",blue:"#00f",yellow:"#ff0",magenta:"#f0f",lime:"#0f0",silver:"#c0c0c0",gray:"#808080",maroon:"#800000",olive:"#808000",green:"#008000",purple:"#800080",teal:"#008080",navy:"#000080"},U={"#f00":"red","#ff0000":"red","#000080":"navy","#008080":"teal"};function O(i){if(!i.startsWith("#"))return i;let t=i.slice(1);if(t.length===6){if(t[0]===t[1]&&t[2]===t[3]&&t[4]===t[5])return`#${t[0]}${t[2]}${t[4]}`}if(t.length===8){if(t[0]===t[1]&&t[2]===t[3]&&t[4]===t[5]&&t[6]===t[7])return`#${t[0]}${t[2]}${t[4]}${t[6]}`}return i}function R(i){let t=i.toLowerCase();return G[t]??null}function P(i){let t=i.toLowerCase();return U[t]??null}function X(i,t,f){let y=(i<<16|t<<8|f).toString(16).padStart(6,"0");return O(`#${y}`)}var j=/^rgba?\(\s*([+-]?\d*\.?\d+%?)\s*[,\s]\s*([+-]?\d*\.?\d+%?)\s*[,\s]\s*([+-]?\d*\.?\d+%?)\s*(?:[,/]\s*([+-]?\d*\.?\d+%?)\s*)?\)$/;function T(i){let t=j.exec(i.trim());if(!t)return i;let f=k(t[1]),y=k(t[2]),m=k(t[3]);if(t[4]!==void 0&&!V(t[4]))return i;return X(f,y,m)}function V(i){if(i.endsWith("%"))return Number.parseFloat(i)>=100;return Number.parseFloat(i)>=1}function k(i){if(i.endsWith("%"))return Math.max(0,Math.min(255,Math.round(Number.parseFloat(i)*2.55)));return Math.max(0,Math.min(255,Math.round(Number.parseFloat(i))))}var Z=new Set(["px","pt","pc","in","cm","mm","q","em","rem","ex","ch","cap","ic","lh","rlh","vw","vh","vi","vb","vmin","vmax","svw","svh","svi","svb","svmin","svmax","lvw","lvh","lvi","lvb","lvmin","lvmax","dvw","dvh","dvi","dvb","dvmin","dvmax","cqw","cqh","cqi","cqb","cqmin","cqmax"]);function C(i){if(i.charCodeAt(0)===43)i=i.slice(1);if(i.includes(".")){let t=i.replace(/(\.\d*?)0+($|[eE])/,"$1$2");t=t.replace(/\.($|[eE])/,"$1"),i=t}if(i.startsWith("0.")&&i.length>2)i=i.slice(1);else if(i.startsWith("-0.")&&i.length>3)i=`-${i.slice(2)}`;if(i==="-0"||i==="-.0"||i==="-0.0")i="0";return i}function I(i,t){let f=C(i);if((f==="0"||f==="-0")&&Z.has(t.toLowerCase()))return{value:"0",unit:""};return{value:f,unit:t}}function H(i){return C(i)}function _(i,t){let f=Number.parseFloat(i);if(!Number.isFinite(f))return i;let y=t<0?0:t;return f.toFixed(y)}var D=new Set(["color","background","background-color","border","border-color","border-top","border-top-color","border-right","border-right-color","border-bottom","border-bottom-color","border-left","border-left-color","border-block","border-block-color","border-block-start-color","border-block-end-color","border-inline","border-inline-color","border-inline-start-color","border-inline-end-color","outline","outline-color","caret-color","fill","stroke","flood-color","lighting-color","stop-color","column-rule","column-rule-color","text-decoration","text-decoration-color","text-emphasis","text-emphasis-color","text-shadow","box-shadow","accent-color","scrollbar-color"]);function L(i){if(!i||i.type!=="Operator")return!1;let t=i.value;return t===":"||t===","||t==="/"}function J(i){let t=i.children;if(!t)return;while(t.head&&t.head.data.type==="WhiteSpace")t.remove(t.head);while(t.tail&&t.tail.data.type==="WhiteSpace")t.remove(t.tail);let f=t.head;while(f){let y=f.next;if(f.data.type==="WhiteSpace"){let m=f.prev&&L(f.prev.data),b=y&&L(y.data);if(m||b)t.remove(f)}f=y}}function p(i,t={}){let f=t.floatPrecision??null,y=f===null?null:(m)=>_(m,f);n(i,{enter(m,b,g){switch(m.type){case"Number":{let d=y?y(m.value):m.value;m.value=C(d);return}case"Percentage":{let d=y?y(m.value):m.value;m.value=H(d);return}case"Dimension":{let d=y?y(m.value):m.value,x=I(d,m.unit);m.value=x.value,m.unit=x.unit;return}case"Hash":{let d=O(`#${m.name}`).slice(1);if(m.name=d,b&&g&&this.declaration&&D.has(this.declaration.property.toLowerCase())){let x=P(`#${d}`);if(x&&x.length<d.length+1){let v={type:"Identifier",name:x,loc:m.loc};g.replace(b,g.createItem(v))}}return}case"Identifier":{if(!b||!g||!this.declaration)return;if(!D.has(this.declaration.property.toLowerCase()))return;let d=R(m.name);if(d&&d.length<m.name.length){let x={type:"Hash",name:d.slice(1),loc:m.loc};g.replace(b,g.createItem(x))}return}case"Url":return;case"Function":{let d=m.name.toLowerCase();if((d==="rgb"||d==="rgba")&&b&&g)m.__rgbReplaceCandidate=!0}}},leave(m,b,g){if(m.type==="Parentheses"||m.type==="Function"||m.type==="Value")J(m);if(m.type==="Function"&&m.__rgbReplaceCandidate&&b&&g){let d=e(m),x=T(d);if(x!==d&&x.startsWith("#")){let v={type:"Hash",name:x.slice(1),loc:m.loc};g.replace(b,g.createItem(v))}}}})}function h(i,t={}){let f=o(i,{context:"stylesheet"});return E(f,t)}function a(i,t={}){let f=o(i,{context:"declarationList"});return E(f,t)}function E(i,t){if(t.comments===!1)s(i,{exclamation:!1});else if(t.comments==="first-exclamation")s(i,{exclamation:"first-exclamation"});else s(i,{exclamation:!0});return p(i,{floatPrecision:t.floatPrecision??null}),u(i),{css:e(i),ast:i}}function l(i){let t=[0,0,0];if(typeof i==="string"){let f=r(i);return F(f,t),t}if(Array.isArray(i)){if(i.length===0)return t;if(Array.isArray(i[0]))F(i,t);else M(i,t);return t}return q(i,t),t}function q(i,t){switch(i.type){case"IdSelector":t[0]++;return;case"ClassSelector":case"AttributeSelector":t[1]++;return;case"TypeSelector":if(i.name!=="*")t[2]++;return;case"PseudoClassSelector":{let f=i.name.toLowerCase();if(f==="is"||f==="matches"||f==="-moz-any"||f==="-webkit-any"||f==="not"||f==="has"){if(i.children){let y=[];for(let b of i.children)if(b.type==="SelectorList"&&"children"in b&&b.children)for(let g of b.children)y.push(g);else if(b.type==="Selector")y.push(b);let m=[0,0,0];for(let b of y){let g=l(b);if(B(g,m)>0)m=g}t[0]+=m[0],t[1]+=m[1],t[2]+=m[2]}return}if(f==="where")return;t[1]++;return}case"PseudoElementSelector":t[2]++;return;case"Selector":case"SelectorList":case"AtrulePrelude":if("children"in i&&i.children)for(let f of i.children)q(f,t);return;case"NestingSelector":return}}function F(i,t){for(let f of i)M(f,t)}function M(i,t){for(let f of i)switch(f.type){case"tag":if(f.name!=="*")t[2]++;break;case"attribute":if(f.name==="id"&&f.action==="equals")t[0]++;else t[1]++;break;case"pseudo":{let y=f.name.toLowerCase();if(y==="is"||y==="matches"||y==="not"||y==="has"||y==="-moz-any"||y==="-webkit-any"){if(Array.isArray(f.data)){let m=[0,0,0];for(let b of f.data){let g=[0,0,0];if(M(b,g),B(g,m)>0)m=g}t[0]+=m[0],t[1]+=m[1],t[2]+=m[2]}break}if(y==="where")break;t[1]++;break}case"pseudo-element":t[2]++;break}}function B(i,t){for(let f=0;f<3;f++)if(i[f]!==t[f])return i[f]-t[f];return 0}function S(i){return i.join(",")}var w={specificity:l};
|
|
3
|
-
export{s,u,p,h,a,l,S,w,A};
|
package/dist/chunk-zn8gy7w7.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{r}from"./chunk-dbj97h19.js";import{c}from"./chunk-vbjv9wf0.js";var C={};c(C,{clearSelectorCache:()=>P,compile:()=>g,is:()=>k,parseAndCompile:()=>i,selectAll:()=>v,selectOne:()=>R});function O(u,o,t,l){let a=[],d=[o],n=[0];for(;;){if(n[0]>=d[0].length){if(d.length===1)return a;d.shift(),n.shift();continue}let e=d[0][n[0]++];if(!t.isTag(e))continue;if(u(e))a.push(e);if(l||t.getName(e)!=="template"){let s=t.getChildren(e);if(s.length>0)d.unshift(s),n.unshift(0)}}}function Q(u,o,t,l){let a=[o],d=[0];for(;;){if(d[0]>=a[0].length){if(a.length===1)return null;a.shift(),d.shift();continue}let n=a[0][d[0]++];if(!t.isTag(n))continue;if(u(n))return n;if(l||t.getName(n)!=="template"){let e=t.getChildren(n);if(e.length>0)a.unshift(e),d.unshift(0)}}}function T(u,o){if(Array.isArray(u))return o.removeSubsets(u);return o.getChildren(u)}var y=(u)=>!0;function x(u){return u===32||u===9||u===10||u===12||u===13}function h(u,o){let t=o.length,l=u.length;if(t===0||t>l)return!1;let a=u.indexOf(o);while(a>=0){let d=a===0||x(u.charCodeAt(a-1)),n=a+t,e=n===l||x(u.charCodeAt(n));if(d&&e)return!0;a=u.indexOf(o,a+1)}return!1}function j(u,o,t){if(o.ignoreCase===!0)return!0;if(o.ignoreCase===!1)return!1;if(o.ignoreCase==="quirks")return!t.xmlMode;return!1}function L(u,o,t){let l=o.adapter,{action:a,name:d,value:n}=u,e=j(n,u,o);if(e)n=n.toLowerCase();return q(a,d,n,e,l,t)}function q(u,o,t,l,a,d){let n=d===y;switch(u){case"exists":if(n)return(e)=>a.hasAttrib(e,o);return(e)=>a.hasAttrib(e,o)&&d(e);case"equals":if(!l){if(n)return(e)=>a.getAttributeValue(e,o)===t;return(e)=>a.getAttributeValue(e,o)===t&&d(e)}if(n)return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return s.toLowerCase()===t};return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return s.toLowerCase()===t&&d(e)};case"not":return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return d(e);return(l?s.toLowerCase():s)!==t&&d(e)};case"start":if(t==="")return()=>!1;if(n)return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return(l?s.toLowerCase():s).startsWith(t)};return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return(l?s.toLowerCase():s).startsWith(t)&&d(e)};case"end":if(t==="")return()=>!1;if(n)return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return(l?s.toLowerCase():s).endsWith(t)};return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return(l?s.toLowerCase():s).endsWith(t)&&d(e)};case"any":{if(t==="")return()=>!1;if(l){if(n)return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return s.toLowerCase().indexOf(t)>=0};return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return s.toLowerCase().indexOf(t)>=0&&d(e)}}if(n)return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return s.indexOf(t)>=0};return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return s.indexOf(t)>=0&&d(e)}}case"element":{if(t===""||/\s/.test(t))return()=>!1;if(l){if(n)return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return h(s.toLowerCase(),t)};return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return h(s.toLowerCase(),t)&&d(e)}}if(n)return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return h(s,t)};return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;return h(s,t)&&d(e)}}case"hyphen":if(n)return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;let f=l?s.toLowerCase():s;if(f===t)return!0;if(f.startsWith(t)&&f.charAt(t.length)==="-")return!0;return!1};return(e)=>{let s=a.getAttributeValue(e,o);if(s==null)return!1;let f=l?s.toLowerCase():s;if(f===t)return d(e);if(f.startsWith(t)&&f.charAt(t.length)==="-")return d(e);return!1}}return(e)=>!1}var D=new Set(["link","any-link","visited","hover","active","focus","focus-visible","focus-within","target","target-within","enabled","disabled","checked","required","optional","valid","invalid","selected","placeholder-shown","read-only","read-write","in-range","out-of-range","default","indeterminate"]),G=new Set(["is","where","matches","-moz-any","-webkit-any"]),I=new Set(["nth-child","nth-last-child","nth-of-type","nth-last-of-type"]);function V(u,o,t){let l=o.adapter,{name:a,data:d}=u;if(u.type==="pseudo"&&G.has(a)){if(!Array.isArray(d))return t;let n=d.map((e)=>i(e,o));if(n.length===1){let e=n[0];return(s)=>e(s)&&t(s)}return(e)=>{for(let s of n)if(s(e))return t(e);return!1}}if(u.type==="pseudo"&&a==="not"){if(!Array.isArray(d))return t;let n=d.map((e)=>i(e,o));if(n.length===1){let e=n[0];return(s)=>!e(s)&&t(s)}return(e)=>{for(let s of n)if(s(e))return!1;return t(e)}}if(u.type==="pseudo"&&a==="has"){if(!Array.isArray(d))return t;let n=d.map((s)=>i(s,o)),e=n.length===1?n[0]:(s)=>{for(let f of n)if(f(s))return!0;return!1};return(s)=>{let f=l.getChildren(s).slice();while(f.length>0){let m=f.pop();if(!l.isTag(m))continue;if(e(m))return t(s);let p=l.getChildren(m);for(let N=0;N<p.length;N++)f.push(p[N])}return!1}}if(u.type==="pseudo"&&I.has(a)){let n=F(typeof d==="string"?d:"",a,o);return(e)=>n(e)&&t(e)}if(u.type==="pseudo"&&a==="first-child")return(n)=>{let e=l.getSiblings(n);for(let s of e){if(!l.isTag(s))continue;return s===n&&t(n)}return!1};if(u.type==="pseudo"&&a==="last-child")return(n)=>{let e=l.getSiblings(n);for(let s=e.length-1;s>=0;s--){let f=e[s];if(!l.isTag(f))continue;return f===n&&t(n)}return!1};if(u.type==="pseudo"&&a==="first-of-type")return(n)=>{let e=l.getName(n),s=l.getSiblings(n);for(let f of s){if(!l.isTag(f)||l.getName(f)!==e)continue;return f===n&&t(n)}return!1};if(u.type==="pseudo"&&a==="last-of-type")return(n)=>{let e=l.getName(n),s=l.getSiblings(n);for(let f=s.length-1;f>=0;f--){let m=s[f];if(!l.isTag(m)||l.getName(m)!==e)continue;return m===n&&t(n)}return!1};if(u.type==="pseudo"&&a==="only-child")return(n)=>{let e=l.getSiblings(n),s=0,f=!1;for(let m of e){if(!l.isTag(m))continue;if(s++,s>1)return!1;if(m===n)f=!0}return s===1&&f&&t(n)};if(u.type==="pseudo"&&a==="only-of-type")return(n)=>{let e=l.getName(n),s=l.getSiblings(n),f=0,m=!1;for(let p of s){if(!l.isTag(p)||l.getName(p)!==e)continue;if(f++,f>1)return!1;if(p===n)m=!0}return f===1&&m&&t(n)};if(u.type==="pseudo"&&a==="empty")return(n)=>l.getChildren(n).length===0&&t(n);if(u.type==="pseudo"&&a==="root")return(n)=>{let e=l.getParent(n);return(e==null||!l.isTag(e))&&t(n)};if(u.type==="pseudo"&&a==="scope"){if(o.context&&Array.isArray(o.context)){let n=new Set(o.context);return(e)=>n.has(e)&&t(e)}if(o.context){let n=o.context;return(e)=>e===n&&t(e)}return(n)=>{let e=l.getParent(n);return(e==null||!l.isTag(e))&&t(n)}}if(u.type==="pseudo"&&D.has(a)){if(o.pseudos&&o.pseudos[a]){let n=o.pseudos[a];if(typeof n==="function")return(e)=>n(e,void 0)&&t(e)}return(n)=>!1}if(u.type==="pseudo-element")return t;if(o.pseudos&&o.pseudos[a]){let n=o.pseudos[a];if(typeof n==="function")return(e)=>n(e,typeof d==="string"?d:void 0)&&t(e);if(typeof n==="string"){let e=r(n),s=b(e,o);return(f)=>s(f)&&t(f)}}return(n)=>!1}function Y(u){let o=u.trim();if(o==="odd")return{a:2,b:1};if(o==="even")return{a:2,b:0};let t=/^([+-]?\d*)n([+-]\d+)?$/.exec(o.replace(/\s+/g,""));if(t){let a=t[1]===""||t[1]==="+"?1:t[1]==="-"?-1:Number(t[1]),d=t[2]?Number(t[2]):0;return{a,b:d}}let l=Number(o);if(!Number.isNaN(l))return{a:0,b:l};return null}function F(u,o,t){let l=Y(u);if(!l)return()=>!1;let{a,b:d}=l,n=t.adapter,e=o==="nth-of-type"||o==="nth-last-of-type",s=o==="nth-last-child"||o==="nth-last-of-type";return(f)=>{let m=n.getSiblings(f),p=e?n.getName(f):"",N=0,A=0;for(let w of m){if(!n.isTag(w))continue;if(e&&n.getName(w)!==p)continue;if(A++,w===f)N=A}if(N===0)return!1;let S=s?A-N+1:N;if(a===0)return S===d;return(S-d)/a>=0&&(S-d)%a===0}}function W(u,o,t){let l=o.adapter,a=t===y;switch(u.type){case"tag":{let d=o.lowerCaseTags!==!1&&!o.xmlMode?u.name.toLowerCase():u.name;if(a)return(n)=>l.getName(n)===d;return(n)=>l.getName(n)===d&&t(n)}case"universal":return t;case"attribute":return L(u,o,t);case"pseudo":case"pseudo-element":return V(u,o,t);case"descendant":case"child":case"parent":case"sibling":case"adjacent":case"column-combinator":return t}return(d)=>!1}var B={universal:50,tag:30,attribute:1,pseudo:0,"pseudo-element":0},z={exists:10,equals:8,not:7,start:6,end:6,hyphen:5,any:4,element:3};function M(u){let o=B[u.type]??0;if(u.type==="attribute")return o+(z[u.action]??0);return o}function b(u,o){if(u.length===1)return i(u[0],o);let t=u.map((l)=>i(l,o));return(l)=>t.some((a)=>a(l))}function i(u,o){let t=o.adapter,l=[[]],a=[];for(let n of u)if(n.type==="descendant"||n.type==="child"||n.type==="sibling"||n.type==="adjacent"||n.type==="parent"||n.type==="column-combinator")a.push(n),l.push([]);else l[l.length-1].push(n);let d=y;for(let n=0;n<l.length;n++){let e=l[n].slice().sort((s,f)=>M(s)-M(f));for(let s of e)d=W(s,o,d);if(n<a.length)d=H(a[n],d,t)}return d}function H(u,o,t){switch(u.type){case"descendant":case"column-combinator":return(l)=>{let a=t.getParent(l);while(a){if(t.isTag(a)&&o(a))return!0;a=t.getParent(a)}return!1};case"child":return(l)=>{let a=t.getParent(l);return a!=null&&t.isTag(a)&&o(a)};case"sibling":return(l)=>{let a=t.getSiblings(l);for(let d of a){if(d===l)return!1;if(t.isTag(d)&&o(d))return!0}return!1};case"adjacent":return(l)=>{let a=t.getSiblings(l),d=null;for(let n of a){if(n===l)return d!=null&&t.isTag(d)&&o(d);d=n}return!1};case"parent":return(l)=>t.existsOne(o,t.getChildren(l))}return(l)=>!1}function _(u){if(!u||!u.adapter)throw Error("css-select: adapter is required");return u.adapter}var E=new WeakMap;function J(u){return(u.xmlMode?1:0)<<0|(u.lowerCaseAttributeNames===!1?1:0)<<1|(u.lowerCaseTags===!1?1:0)<<2}function K(u,o){let t=E.get(u);if(!t)t=[],E.set(u,t);let l=t[o];if(!l)l=new Map,t[o]=l;return l}function U(u,o){let t=r(u,{xmlMode:o.xmlMode,lowerCaseAttributeNames:o.lowerCaseAttributeNames,lowerCaseTags:o.lowerCaseTags});return b(t,o)}function g(u,o){if(typeof u!=="string")return b(u,o);if(o.cacheResults===!1||!o.adapter)return U(u,o);let t=K(o.adapter,J(o)),l=t.get(u);if(l!==void 0)return l;return l=U(u,o),t.set(u,l),l}function P(u,o){if(o===void 0){E.delete(u);return}let t=E.get(u);if(!t)return;for(let l of t)if(l)l.delete(o)}function v(u,o,t){let l=_(t),a=typeof u==="function"?u:g(u,t),d=T(o,l);return O(a,d,l,t.xmlMode===!0)}function R(u,o,t){let l=_(t),a=typeof u==="function"?u:g(u,t),d=T(o,l);return Q(a,d,l,t.xmlMode===!0)}function k(u,o,t){return(typeof o==="function"?o:g(o,t))(u)}export{i,g,P,v,R,k,C};
|