-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hiccup-css): add attrib fn, at-rules, quoted fns, decl value arrays
- quoted functions map keywords in root-level rules to fns (useful for pure JSON definitions, where fns are not possible) - add @import, @Keyframes, @media, @namespace, @supports fns - refactor @media & @supports to use generic `conditional()` - add attrib selector fns - add support for declaration value arrays (converted to string, first level joined w/ `,` and inner arrays joined w/ ` ` - add/update re-exports
- Loading branch information
1 parent
e687230
commit ebbc491
Showing
12 changed files
with
96 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const $ = (op) => (id: string, x: string | number, caseSensitve = false) => `[${id}${op}="${x}"${caseSensitve ? " i" : ""}]`; | ||
export const withAttrib = (id: string) => `[${id}]`; | ||
export const attribEq = $(""); | ||
export const attribIncl = $("~"); | ||
export const attribPrefix = $("^"); | ||
export const attribSuffix = $("$"); | ||
export const attribContains = $("*"); |
6 changes: 3 additions & 3 deletions
6
packages/hiccup-css/src/media-query.ts → packages/hiccup-css/src/conditional.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function at_import(url: string, ...queries: string[]) { | ||
return (acc, _) => { | ||
if (queries.length === 0) { | ||
acc.push(`@import url(${url});`); | ||
} else { | ||
acc.push(`@import url(${url}) ${queries.join(" ")};`); | ||
} | ||
return acc; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
export * from "./api"; | ||
export * from "./attribs"; | ||
export * from "./conditional"; | ||
export * from "./css"; | ||
export * from "./import"; | ||
export * from "./keyframes"; | ||
export * from "./media-query"; | ||
export * from "./media"; | ||
export * from "./namespace"; | ||
export * from "./quoted-functions"; | ||
export * from "./supports"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { RuleFn } from "./api"; | ||
import { conditional } from "./conditional"; | ||
|
||
export function at_media(cond, rules: any[]): RuleFn { | ||
return conditional("@media", cond, rules); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function at_namespace(url: string); | ||
export function at_namespace(prefix: string, url: string); | ||
export function at_namespace(...args: string[]) { | ||
return (acc, _) => { | ||
if (args.length === 1) { | ||
acc.push(`@namespace url(${args[0]});`); | ||
} else { | ||
acc.push(`@namespace ${args[0]} url(${args[1]});`); | ||
} | ||
return acc; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { at_import } from "./import"; | ||
import { at_keyframes } from "./keyframes"; | ||
import { at_media } from "./media"; | ||
import { at_namespace } from "./namespace"; | ||
import { at_supports } from "./supports"; | ||
|
||
export const QUOTED_FNS = { | ||
"@import": at_import, | ||
"@keyframes": at_keyframes, | ||
"@media": at_media, | ||
"@namespace": at_namespace, | ||
"@supports": at_supports, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { RuleFn } from "./api"; | ||
import { conditional } from "./conditional"; | ||
|
||
export function at_supports(cond, rules: any[]): RuleFn { | ||
return conditional("@supports", cond, rules); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters