Skip to content

Commit

Permalink
fix: change dependency version or import source for capability of low…
Browse files Browse the repository at this point in the history
… deno version
  • Loading branch information
TomokiMiyauci committed Mar 6, 2022
1 parent 06a1ef8 commit 2650b0e
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 27 deletions.
10 changes: 6 additions & 4 deletions core/postcss/minify.ts
@@ -1,14 +1,16 @@
import valueParser from "https://esm.sh/postcss-value-parser";
import { parseSelector, type PostcssPlugin } from "../../deps.ts";
import { parseSelector, PostcssPlugin, SyncProcessor } from "../../deps.ts";

const selectorProcessor = parseSelector((selectors) => {
const processor: SyncProcessor = (selectors) => {
selectors.walk((selector) => {
selector.spaces = { before: "", after: "" };
});
});
};

export function minifySelector(value: string): string {
return selectorProcessor.processSync(value);
const selectorProcessor = parseSelector(processor);

return selectorProcessor.processSync(value, {});
}

function minifyValue(value: string): string {
Expand Down
4 changes: 2 additions & 2 deletions core/utils/monad.ts
@@ -1,5 +1,5 @@
import { None, type Option, Some } from "../../deps.ts";
import { hex2RGBA, type RGBA } from "./parse.ts";
import { None, Option, Some } from "../../deps.ts";
import { hex2RGBA, RGBA } from "./parse.ts";

export function parseNumeric(value: string): Option<number> {
const number = Number(value);
Expand Down
11 changes: 9 additions & 2 deletions deps.ts
Expand Up @@ -52,10 +52,17 @@ export {
toAST,
toObject,
} from "https://deno.land/x/postcss_js@v1.0.0-beta.3/mod.ts";
export { default as parseSelector } from "https://deno.land/x/postcss_selector_parser@v6.0.2/mod.js";
export {
default as parseSelector,
className as classNameNode,
combinator as combinatorNode,
pseudo as pseudoNode,
selector as selectorNode,
} from "https://deno.land/x/postcss_selector_parser@v6.0.2/src/selectors/index.js";
export type {
Node as SelectorNode,
SyncProcessor,
} from "https://esm.sh/postcss-selector-parser@6.0.9?pin=v66";
export type { Node as SelectorNode } from "https://esm.sh/postcss-selector-parser@6.0.9?pin=v66";
export function isStringOrNumber(value: unknown): value is string | number {
return isString(value) || isNumber(value);
}
Expand Down
2 changes: 1 addition & 1 deletion preset_svg/convert.ts
@@ -1,4 +1,4 @@
import { IconifyJSON } from "https://esm.sh/@iconify/types/types.ts";
import type { IconifyJSON } from "https://cdn.esm.sh/v66/@iconify/types@1.0.12/types.ts~.d.ts";

import { parseIconSet } from "https://esm.sh/@iconify/utils/lib/icon-set/parse?dts&pin=v66";
import { defaults } from "https://esm.sh/@iconify/utils/lib/customisations";
Expand Down
5 changes: 5 additions & 0 deletions preset_tw/deps.ts
@@ -0,0 +1,5 @@
import mediaQueryOrder from "https://esm.sh/sort-css-media-queries@2.0.4/lib/create-sort.js?pin=v66&no-check";

const mobileOrder: <T = string>(a: T, b: T) => number = mediaQueryOrder({});

export { mobileOrder };
7 changes: 1 addition & 6 deletions preset_tw/identifier/_utils.ts
@@ -1,9 +1,4 @@
import {
type Arrayable,
associateWith,
isNumber,
type Option,
} from "../../deps.ts";
import { Arrayable, associateWith, isNumber, Option } from "../../deps.ts";
import {
customProperty,
multiple,
Expand Down
2 changes: 1 addition & 1 deletion preset_tw/postcss.ts
@@ -1,5 +1,5 @@
import type { AtRule, PostcssPlugin } from "../deps.ts";
import mobileOrder from "https://esm.sh/sort-css-media-queries@2.0.4?pin=v66";
import { mobileOrder } from "./deps.ts";

function sortMediaQueries(): PostcssPlugin {
return {
Expand Down
30 changes: 19 additions & 11 deletions preset_typography/identifier/prose.ts
@@ -1,6 +1,8 @@
import { customProperty, varFn } from "../../core/utils/format.ts";
import {
chain,
classNameNode,
combinatorNode,
deepMerge,
isEmptyObject,
isLength0,
Expand All @@ -10,9 +12,12 @@ import {
mapEntries,
parseSelector,
prop,
pseudoNode,
Root,
Rule,
SelectorNode,
selectorNode,
SyncProcessor,
toAST,
} from "../../deps.ts";
import { $resolveTheme } from "../../core/resolve.ts";
Expand Down Expand Up @@ -373,38 +378,41 @@ function isWhereableNode(node: SelectorNode): boolean {
}

export function transformSelector(selector: string, className: string): string {
const result = parseSelector((root) => {
const processor: SyncProcessor = (root) => {
root.nodes.forEach((selector) => {
const pseudos = selector.filter((v) => !isWhereableNode(v));

const where = parseSelector.pseudo({
const where = pseudoNode({
"value": ":where",
nodes: [
parseSelector.selector({
selectorNode({
value: "",
nodes: selector.filter(isWhereableNode),
}),
],
});

const classNameNode = parseSelector.className({ value: className });
const combinator = parseSelector.combinator({ value: " " });
const _classNameNode = classNameNode({ value: className });
const _combinatorNode = combinatorNode({ value: " " });
const NOT = "not";
const notClassName = parseSelector.className({
const notClassName = classNameNode({
value: `${NOT}-${className}`,
});
const not = parseSelector.pseudo({
const not = pseudoNode({
value: ":not",
nodes: [notClassName],
});
const newSelector = parseSelector.selector({
const newSelector = selectorNode({
value: "",
nodes: [classNameNode, combinator, where, not, ...pseudos],
nodes: [_classNameNode, _combinatorNode, where, not, ...pseudos],
});

selector.replaceWith(newSelector);
selector.replaceWith(newSelector as never);
});
}).processSync(selector, { lossless: false });
};
const result = parseSelector(processor).processSync(selector, {
lossless: false,
});
return result;
}

Expand Down

0 comments on commit 2650b0e

Please sign in to comment.