Skip to content

Commit

Permalink
fix: assign higher precedence to custom selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Jul 22, 2020
1 parent f9f666e commit 002c790
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
7 changes: 5 additions & 2 deletions packages/otion/src/createInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
PROPERTY_ACCEPTS_UNITLESS_VALUES,
PROPERTY_PRECEDENCE_CORRECTION_GROUPS,
} from "./propertyMatchers";
import { PRECEDENCES_BY_PSEUDO_CLASS } from "./pseudos";
import {
PRECEDENCES_BY_PSEUDO_CLASS,
PSEUDO_CLASS_PRECEDENCE_GROUP_COUNT,
} from "./pseudos";

const MAX_CLASS_NAME_LENGTH = 9;
export const PRECEDENCE_GROUP_COUNT = 36;
Expand Down Expand Up @@ -210,7 +213,7 @@ export function createInstance(): OtionInstance {
classSelectorStartIndex + 8,
),
)) ||
1;
PSEUDO_CLASS_PRECEDENCE_GROUP_COUNT + 1;

const scopeSelector = `.${className}`;
injector.insert(
Expand Down
20 changes: 11 additions & 9 deletions packages/otion/src/pseudos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
*/

export const PRECEDENCES_BY_PSEUDO_CLASS = new Map([
[/* li */ "nk", 2],
[/* vi */ "sited", 3],
[/* em */ "pty", 4],
[/* fo */ "cus-w" /* ithin */, 5],
[/* ho */ "ver", 6],
[/* fo */ "cus", 7],
[/* fo */ "cus-v" /* isible */, 8],
[/* ac */ "tive", 9],
[/* di */ "sable" /* d */, 10],
[/* li */ "nk", 1],
[/* vi */ "sited", 2],
[/* em */ "pty", 3],
[/* fo */ "cus-w" /* ithin */, 4],
[/* ho */ "ver", 5],
[/* fo */ "cus", 6],
[/* fo */ "cus-v" /* isible */, 7],
[/* ac */ "tive", 8],
[/* di */ "sable" /* d */, 9],
]);

export const PSEUDO_CLASS_PRECEDENCE_GROUP_COUNT = 9;

0 comments on commit 002c790

Please sign in to comment.