Skip to content

Commit

Permalink
Update parsel-js
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Sep 11, 2023
1 parent 2e75e27 commit 244be0a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 104 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-suns-exist.md
@@ -0,0 +1,5 @@
---
"ultrahtml": patch
---

Update `parsel-js` to latest
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -71,7 +71,7 @@
"markdown-it": "^13.0.1",
"media-query-fns": "^2.0.0",
"npm-run-all": "^4.1.5",
"parsel-js": "^1.0.2",
"parsel-js": "^1.1.2",
"prettier": "^2.5.1",
"pretty-bytes": "^6.0.0",
"stylis": "^4.1.2",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 0 additions & 88 deletions src/env.d.ts

This file was deleted.

15 changes: 9 additions & 6 deletions src/selector.ts
@@ -1,10 +1,10 @@
import type { Node } from './index.js';
import { ELEMENT_NODE, TEXT_NODE, walkSync } from './index.js';
import type { AST, Tokens } from 'parsel-js';
import type { AST, AttributeToken } from 'parsel-js';
import { parse, specificity as getSpecificity, specificityToNumber } from 'parsel-js';

export function specificity(selector: string) {
return specificityToNumber(getSpecificity(selector));
return specificityToNumber(getSpecificity(selector), 10);
}

export function matches(node: Node, selector: string): boolean {
Expand Down Expand Up @@ -55,7 +55,7 @@ function select(node: Node, match: Matcher, opts: { single?: boolean } = { singl
return nodes;
}

const getAttributeMatch = (selector: Tokens) => {
const getAttributeMatch = (selector: AttributeToken) => {
const { operator = '=' } = selector;
switch (operator) {
case '=': return (a: string, b: string) => a === b;
Expand Down Expand Up @@ -90,7 +90,7 @@ const createMatch = (selector: AST): Matcher => {
case 'id': return (node: Node) => node.attributes?.id === selector.name;
case 'pseudo-class': {
switch (selector.name) {
case 'global': return (...args) => selectorToMatch(parse(selector.argument!))(...args);
case 'global': return (...args) => selectorToMatch(parse(selector.argument!)!)(...args);
case 'not': return (...args) => !createMatch(selector.subtree!)(...args);
case 'is': return (...args) => selectorToMatch(selector.subtree!)(...args);
case 'where': return (...args) => selectorToMatch(selector.subtree!)(...args);
Expand Down Expand Up @@ -146,6 +146,9 @@ const createMatch = (selector: AST): Matcher => {
}
return false
}
case 'universal': return (_: Node) => {
return true;
}
default: {
throw new Error(`Unhandled selector: ${selector.type}`)
}
Expand All @@ -154,7 +157,7 @@ const createMatch = (selector: AST): Matcher => {

const selectorToMatch = (sel: string | AST): Matcher => {
let selector = typeof sel === 'string' ? parse(sel) : sel;
switch (selector.type) {
switch (selector?.type) {
case 'list': {
const matchers = selector.list.map((s: any) => createMatch(s));
return (node: Node, parent?: Node, index?: number) => {
Expand Down Expand Up @@ -207,6 +210,6 @@ const selectorToMatch = (sel: string | AST): Matcher => {
}
}
}
default: return createMatch(selector) as Matcher;
default: return createMatch(selector!) as Matcher;
}
}
5 changes: 1 addition & 4 deletions src/transformers/inline.ts
@@ -1,4 +1,4 @@
import { walkSync, ELEMENT_NODE, TEXT_NODE, Node, ElementNode } from "../index.js";
import { walkSync, ELEMENT_NODE, TEXT_NODE, Node } from "../index.js";
import { querySelectorAll, specificity } from "../selector.js";
import { type Element as CSSEntry, compile } from "stylis";
import { compileQuery, matches, type Environment } from 'media-query-fns';
Expand Down Expand Up @@ -101,9 +101,6 @@ export default function inline(opts?: Partial<InlineOptions>) {
return doc;
};
}
function isHttpURL(href: string): boolean {
return href.startsWith('http://') || href.startsWith('https://');
}

type AlwaysDefinedValues = "widthPx" | "heightPx" | "deviceWidthPx" | "deviceHeightPx" | "dppx";
type ResolvedEnvironment = Omit<Partial<Environment>, AlwaysDefinedValues> & Record<AlwaysDefinedValues, number>;
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Expand Up @@ -4,7 +4,6 @@
"declaration": true,
"emitDeclarationOnly": true,
"strict": true,
"noImplicitAny": false,
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand Down

0 comments on commit 244be0a

Please sign in to comment.