-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from dburles/refactor
Refactor
- Loading branch information
Showing
25 changed files
with
455 additions
and
387 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
{ | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:jsdoc/recommended", | ||
"plugin:node/recommended", | ||
"plugin:import/recommended", | ||
"plugin:compat/recommended", | ||
"plugin:react/recommended", | ||
"plugin:prettier/recommended" | ||
"plugin:react-hooks/recommended" | ||
], | ||
"plugins": ["jsdoc", "react-hooks"], | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
"ecmaVersion": "latest", | ||
"sourceType": "script" | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "detect" | ||
} | ||
}, | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"es2022": true | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": ["**/*.mjs"], | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
} | ||
} | ||
], | ||
"rules": { | ||
"arrow-body-style": ["error", "always"], | ||
"curly": ["error", "all"], | ||
"jsdoc/require-jsdoc": "off", | ||
"func-style": ["error", "declaration"] | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
package.json | ||
/snapshots |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
"use strict"; | ||
|
||
const darkColorMode = "@media (prefers-color-scheme: dark)"; | ||
const darkColorMode = "__MYSTICAL_INTERNAL_DARK_MODE__"; | ||
|
||
module.exports = darkColorMode; |
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,82 @@ | ||
"use strict"; | ||
|
||
const darkColorMode = require("../darkColorMode.js"); | ||
const facepaint = require("./facepaint.js"); | ||
const forceDarkModeAttribute = require("./forceDarkModeAttribute.js"); | ||
const isObject = require("./isObject.js"); | ||
const merge = require("./merge.js"); | ||
const negativeTransform = require("./negativeTransform.js"); | ||
const shorthandProperties = require("./shorthandProperties.js"); | ||
const themeTokens = require("./themeTokens.js"); | ||
const transformColors = require("./transformColors.js"); | ||
|
||
function transformStyle(property, value, theme = {}) { | ||
const themeKey = themeTokens[property]; | ||
|
||
if (shorthandProperties[property]) { | ||
return shorthandProperties[property](theme, String(value)); | ||
} else if (themeKey) { | ||
let currentThemeProperties = theme[themeKey]; | ||
if (themeKey === "colors") { | ||
return transformColors(theme.colors, property, value); | ||
} | ||
const transformNegatives = negativeTransform(property); | ||
return { | ||
[property]: transformNegatives(currentThemeProperties, value, value), | ||
}; | ||
} | ||
return { [property]: value }; | ||
} | ||
|
||
function css(rootStyles) { | ||
let mergedStyles = Array.isArray(rootStyles) | ||
? merge(...rootStyles) | ||
: rootStyles; | ||
|
||
return (context) => { | ||
let transformedStyles = {}; | ||
|
||
function transformStyles(styles) { | ||
for (const property in styles) { | ||
const value = styles[property]; | ||
if (isObject(value)) { | ||
if (property === darkColorMode) { | ||
const transformed = css(value)(context); | ||
if (!context.options?.darkModeOff) { | ||
transformedStyles["@media (prefers-color-scheme: dark)"] = | ||
transformed; | ||
} | ||
if (context.options?.darkModeForcedBoundary) { | ||
transformedStyles[`[${forceDarkModeAttribute}] &`] = transformed; | ||
} | ||
} else { | ||
transformedStyles[property] = css(value)(context); | ||
} | ||
} else { | ||
transformedStyles = { | ||
...transformedStyles, | ||
...transformStyle(property, value, context.theme), | ||
}; | ||
} | ||
} | ||
} | ||
|
||
if (Array.isArray(context.theme?.breakpoints)) { | ||
const mq = facepaint( | ||
context.theme.breakpoints.map((bp) => { | ||
return `@media (min-width: ${bp})`; | ||
}) | ||
); | ||
|
||
for (const styles of mq(mergedStyles)) { | ||
transformStyles(styles); | ||
} | ||
} else { | ||
transformStyles(mergedStyles); | ||
} | ||
|
||
return transformedStyles; | ||
}; | ||
} | ||
|
||
module.exports = css; |
Oops, something went wrong.