From ae9f9b463906456b2b71758580f86e83c6f48103 Mon Sep 17 00:00:00 2001 From: Jeffrey Posnick Date: Fri, 29 Sep 2023 17:11:49 -0400 Subject: [PATCH 1/2] WIP uno preset --- package.json | 2 ++ src/presets/unocss/index.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/presets/unocss/index.js diff --git a/package.json b/package.json index 8e084174..5da7d341 100644 --- a/package.json +++ b/package.json @@ -175,6 +175,7 @@ "./postcss/theme-dark": "./src/extra/theme-dark.css", "./postcss/theme-light": "./src/extra/theme-light.css", "./utilities": "./src/extra/utilities.css", + "./preset-unocss": "./src/presets/unocss/index.js", "./*": "./*" }, "browserslist": [ @@ -189,6 +190,7 @@ "gen:shadowdom": "cd build && node props \"\" false \":host\" \"shadow\"", "gen:prefixed": "cd build && node props.js \"op\" true", "gen:types": "tsc -p tsconfig.json", + "gen:unocss": "tsc -p src/presets/unocss/tsconfig.json", "lib:all": "postcss src/index.css -o open-props.min.css", "lib:normalize": "postcss src/extra/normalize.css -o normalize.min.css && node ./build/extras.js", "lib:normalize:light": "postcss src/extra/normalize.light.css -o normalize.light.min.css", diff --git a/src/presets/unocss/index.js b/src/presets/unocss/index.js new file mode 100644 index 00000000..5b02c04c --- /dev/null +++ b/src/presets/unocss/index.js @@ -0,0 +1,30 @@ +import Colors from "../../../src/props.colors.js"; +import Fonts from "../../../src/props.fonts.js"; + +export const openPropsPreset = { + name: "unocss-preset-open-props", + rules: [ + [ + /^op-color-(.*)$/, + ([, c], { theme }) => { + const normalizedVariable = `--${c}`; + if (theme["colors"][normalizedVariable]) { + return { color: theme["colors"][normalizedVariable] }; + } + }, + ], + [ + /^op-font-(.*)$/, + ([, c], { theme }) => { + const normalizedVariable = `--font-${c}`; + if (theme["fontFamily"][normalizedVariable]) { + return { "font-family": theme["fontFamily"][normalizedVariable] }; + } + }, + ], + ], + theme: { + colors: Colors, + fontFamily: Fonts, + }, +}; From 86d01642cd752b313af6cd53bda35eb3acbf9f6f Mon Sep 17 00:00:00 2001 From: Jeffrey Posnick Date: Fri, 29 Sep 2023 17:16:56 -0400 Subject: [PATCH 2/2] Tweaks --- package.json | 1 - src/presets/unocss/index.js | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 5da7d341..347f6d9d 100644 --- a/package.json +++ b/package.json @@ -190,7 +190,6 @@ "gen:shadowdom": "cd build && node props \"\" false \":host\" \"shadow\"", "gen:prefixed": "cd build && node props.js \"op\" true", "gen:types": "tsc -p tsconfig.json", - "gen:unocss": "tsc -p src/presets/unocss/tsconfig.json", "lib:all": "postcss src/index.css -o open-props.min.css", "lib:normalize": "postcss src/extra/normalize.css -o normalize.min.css && node ./build/extras.js", "lib:normalize:light": "postcss src/extra/normalize.light.css -o normalize.light.min.css", diff --git a/src/presets/unocss/index.js b/src/presets/unocss/index.js index 5b02c04c..ead4e005 100644 --- a/src/presets/unocss/index.js +++ b/src/presets/unocss/index.js @@ -6,8 +6,8 @@ export const openPropsPreset = { rules: [ [ /^op-color-(.*)$/, - ([, c], { theme }) => { - const normalizedVariable = `--${c}`; + ([, token], { theme }) => { + const normalizedVariable = `--${token}`; if (theme["colors"][normalizedVariable]) { return { color: theme["colors"][normalizedVariable] }; } @@ -15,8 +15,8 @@ export const openPropsPreset = { ], [ /^op-font-(.*)$/, - ([, c], { theme }) => { - const normalizedVariable = `--font-${c}`; + ([, token], { theme }) => { + const normalizedVariable = `--font-${token}`; if (theme["fontFamily"][normalizedVariable]) { return { "font-family": theme["fontFamily"][normalizedVariable] }; }