Skip to content

Commit

Permalink
fixed pages router font bug
Browse files Browse the repository at this point in the history
  • Loading branch information
artemis-prime committed Jan 28, 2024
1 parent 9b2533f commit 29f221a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 48 deletions.
2 changes: 1 addition & 1 deletion pkgs/luxdefi-ui/next/pages-router-font-vars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type NextFontDesc from './next-font-desc'
const PagesRouterFontVars: React.FC = () => {

const fontVars = nextFonts.map((fd: NextFontDesc) => (
`${fd.cssVar}: ${fd.nextFont.style.fontFamily}`
`${fd.cssVar}: ${fd.nextFont.style.fontFamily};`
)).join('\n')

return <style jsx global>{`
Expand Down
2 changes: 1 addition & 1 deletion pkgs/luxdefi-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luxdefi/ui",
"version": "0.2.3",
"version": "0.2.4",
"description": "Library that contains shared UI primitives, styles, and core types",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
Expand Down
90 changes: 44 additions & 46 deletions pkgs/luxdefi-ui/tailwind/typo-plugin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,58 @@ import parser from 'postcss-selector-parser'

const parseSelector = parser()

export default {
isUsableColor(color, values) {
return isPlainObject(values) && color !== 'gray' && values[600]
},

/**
* @param {string} selector
*/
commonTrailingPseudos(selector) {
let ast = parseSelector.astSync(selector)

/** @type {import('postcss-selector-parser').Pseudo[][]} */
let matrix = []

// Put the pseudo elements in reverse order in a sparse, column-major 2D array
for (let [i, sel] of ast.nodes.entries()) {
for (const [j, child] of [...sel.nodes].reverse().entries()) {
// We only care about pseudo elements
if (child.type !== 'pseudo' || !child.value.startsWith('::')) {
break
}

matrix[j] = matrix[j] || []
matrix[j][i] = child
}
}

let trailingPseudos = parser.selector()
export function isUsableColor(color, values) {
return isPlainObject(values) && color !== 'gray' && values[600]
}

// At this point the pseudo elements are in a column-major 2D array
// This means each row contains one "column" of pseudo elements from each selector
// We can compare all the pseudo elements in a row to see if they are the same
for (const pseudos of matrix) {
// It's a sparse 2D array so there are going to be holes in the rows
// We skip those
if (!pseudos) {
continue
}
/**
* @param {string} selector
*/
export function commonTrailingPseudos(selector) {
let ast = parseSelector.astSync(selector)

let values = new Set([...pseudos.map((p) => p.value)])
/** @type {import('postcss-selector-parser').Pseudo[][]} */
let matrix = []

// The pseudo elements are not the same
if (values.size > 1) {
// Put the pseudo elements in reverse order in a sparse, column-major 2D array
for (let [i, sel] of ast.nodes.entries()) {
for (const [j, child] of [...sel.nodes].reverse().entries()) {
// We only care about pseudo elements
if (child.type !== 'pseudo' || !child.value.startsWith('::')) {
break
}

pseudos.forEach((pseudo) => pseudo.remove())
trailingPseudos.prepend(pseudos[0])
matrix[j] = matrix[j] || []
matrix[j][i] = child
}
}

let trailingPseudos = parser.selector()

// At this point the pseudo elements are in a column-major 2D array
// This means each row contains one "column" of pseudo elements from each selector
// We can compare all the pseudo elements in a row to see if they are the same
for (const pseudos of matrix) {
// It's a sparse 2D array so there are going to be holes in the rows
// We skip those
if (!pseudos) {
continue
}

let values = new Set([...pseudos.map((p) => p.value)])

if (trailingPseudos.nodes.length) {
return [trailingPseudos.toString(), ast.toString()]
// The pseudo elements are not the same
if (values.size > 1) {
break
}

return [null, selector]
},
pseudos.forEach((pseudo) => pseudo.remove())
trailingPseudos.prepend(pseudos[0])
}

if (trailingPseudos.nodes.length) {
return [trailingPseudos.toString(), ast.toString()]
}

return [null, selector]
}

0 comments on commit 29f221a

Please sign in to comment.