@fluixi-css/core 0.1.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/base.css +4 -0
- package/components.css +1 -0
- package/dist/base.css +4 -0
- package/dist/components.css +1 -0
- package/dist/index.css +2 -0
- package/dist/package.json +139 -0
- package/dist/reset.css +168 -0
- package/dist/src/ast.d.ts +298 -0
- package/dist/src/ast.js +2240 -0
- package/dist/src/ast.js.map +1 -0
- package/dist/src/commons/constants.d.ts +1193 -0
- package/dist/src/commons/constants.js +1323 -0
- package/dist/src/commons/constants.js.map +1 -0
- package/dist/src/commons/helper.d.ts +1298 -0
- package/dist/src/commons/helper.js +1310 -0
- package/dist/src/commons/helper.js.map +1 -0
- package/dist/src/commons/index.d.ts +3 -0
- package/dist/src/commons/index.js +4 -0
- package/dist/src/commons/index.js.map +1 -0
- package/dist/src/commons/properties.d.ts +1431 -0
- package/dist/src/commons/properties.js +2855 -0
- package/dist/src/commons/properties.js.map +1 -0
- package/dist/src/commons/types.d.ts +359 -0
- package/dist/src/commons/types.js +4 -0
- package/dist/src/commons/types.js.map +1 -0
- package/dist/src/components/avatar/index.d.ts +19 -0
- package/dist/src/components/avatar/index.js +22 -0
- package/dist/src/components/avatar/index.js.map +1 -0
- package/dist/src/components/button/index.d.ts +48 -0
- package/dist/src/components/button/index.js +51 -0
- package/dist/src/components/button/index.js.map +1 -0
- package/dist/src/components/card/index.d.ts +44 -0
- package/dist/src/components/card/index.js +47 -0
- package/dist/src/components/card/index.js.map +1 -0
- package/dist/src/components/checkbox/index.d.ts +69 -0
- package/dist/src/components/checkbox/index.js +80 -0
- package/dist/src/components/checkbox/index.js.map +1 -0
- package/dist/src/components/daterangepicker/index.d.ts +147 -0
- package/dist/src/components/daterangepicker/index.js +150 -0
- package/dist/src/components/daterangepicker/index.js.map +1 -0
- package/dist/src/components/dialog/index.d.ts +71 -0
- package/dist/src/components/dialog/index.js +74 -0
- package/dist/src/components/dialog/index.js.map +1 -0
- package/dist/src/components/drawer/index.d.ts +26 -0
- package/dist/src/components/drawer/index.js +29 -0
- package/dist/src/components/drawer/index.js.map +1 -0
- package/dist/src/components/dropdown/index.d.ts +101 -0
- package/dist/src/components/dropdown/index.js +104 -0
- package/dist/src/components/dropdown/index.js.map +1 -0
- package/dist/src/components/forms/index.d.ts +58 -0
- package/dist/src/components/forms/index.js +62 -0
- package/dist/src/components/forms/index.js.map +1 -0
- package/dist/src/components/index.d.ts +1228 -0
- package/dist/src/components/index.js +64 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/layout/index.d.ts +28 -0
- package/dist/src/components/layout/index.js +33 -0
- package/dist/src/components/layout/index.js.map +1 -0
- package/dist/src/components/list/index.d.ts +65 -0
- package/dist/src/components/list/index.js +68 -0
- package/dist/src/components/list/index.js.map +1 -0
- package/dist/src/components/popover/index.d.ts +79 -0
- package/dist/src/components/popover/index.js +82 -0
- package/dist/src/components/popover/index.js.map +1 -0
- package/dist/src/components/radio/index.d.ts +77 -0
- package/dist/src/components/radio/index.js +80 -0
- package/dist/src/components/radio/index.js.map +1 -0
- package/dist/src/components/select/index.d.ts +102 -0
- package/dist/src/components/select/index.js +105 -0
- package/dist/src/components/select/index.js.map +1 -0
- package/dist/src/components/sidenav/index.d.ts +98 -0
- package/dist/src/components/sidenav/index.js +101 -0
- package/dist/src/components/sidenav/index.js.map +1 -0
- package/dist/src/components/table/index.d.ts +95 -0
- package/dist/src/components/table/index.js +98 -0
- package/dist/src/components/table/index.js.map +1 -0
- package/dist/src/constants.d.ts +3 -0
- package/dist/src/constants.js +29 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/css-ast.d.ts +48 -0
- package/dist/src/css-ast.js +2 -0
- package/dist/src/css-ast.js.map +1 -0
- package/dist/src/css-generator.d.ts +29 -0
- package/dist/src/css-generator.js +104 -0
- package/dist/src/css-generator.js.map +1 -0
- package/dist/src/css-helpers.d.ts +76 -0
- package/dist/src/css-helpers.js +272 -0
- package/dist/src/css-helpers.js.map +1 -0
- package/dist/src/css-lexer.d.ts +48 -0
- package/dist/src/css-lexer.js +255 -0
- package/dist/src/css-lexer.js.map +1 -0
- package/dist/src/css-parser.cjs +2047 -0
- package/dist/src/css-parser.cjs.map +1 -0
- package/dist/src/css-parser.d.ts +100 -0
- package/dist/src/css-parser.js +1098 -0
- package/dist/src/css-parser.js.map +1 -0
- package/dist/src/css-parser.mjs +2028 -0
- package/dist/src/css-parser.mjs.map +1 -0
- package/dist/src/design-system.d.ts +210 -0
- package/dist/src/design-system.js +1034 -0
- package/dist/src/design-system.js.map +1 -0
- package/dist/src/engine/ast.d.ts +44 -0
- package/dist/src/engine/ast.js +92 -0
- package/dist/src/engine/ast.js.map +1 -0
- package/dist/src/engine/atom.d.ts +74 -0
- package/dist/src/engine/atom.js +227 -0
- package/dist/src/engine/atom.js.map +1 -0
- package/dist/src/engine/compile.d.ts +5 -0
- package/dist/src/engine/compile.js +79 -0
- package/dist/src/engine/compile.js.map +1 -0
- package/dist/src/engine/defaults.d.ts +2 -0
- package/dist/src/engine/defaults.js +14 -0
- package/dist/src/engine/defaults.js.map +1 -0
- package/dist/src/engine/directives.d.ts +2 -0
- package/dist/src/engine/directives.js +191 -0
- package/dist/src/engine/directives.js.map +1 -0
- package/dist/src/engine/index.d.ts +41 -0
- package/dist/src/engine/index.js +88 -0
- package/dist/src/engine/index.js.map +1 -0
- package/dist/src/engine/registry.d.ts +46 -0
- package/dist/src/engine/registry.js +49 -0
- package/dist/src/engine/registry.js.map +1 -0
- package/dist/src/engine/scanner.d.ts +1 -0
- package/dist/src/engine/scanner.js +45 -0
- package/dist/src/engine/scanner.js.map +1 -0
- package/dist/src/engine/source.d.ts +12 -0
- package/dist/src/engine/source.js +81 -0
- package/dist/src/engine/source.js.map +1 -0
- package/dist/src/engine/theme-defaults.d.ts +2 -0
- package/dist/src/engine/theme-defaults.js +54 -0
- package/dist/src/engine/theme-defaults.js.map +1 -0
- package/dist/src/engine/theme-source.d.ts +5 -0
- package/dist/src/engine/theme-source.js +71 -0
- package/dist/src/engine/theme-source.js.map +1 -0
- package/dist/src/engine/theme.d.ts +10 -0
- package/dist/src/engine/theme.js +42 -0
- package/dist/src/engine/theme.js.map +1 -0
- package/dist/src/engine/transform.d.ts +25 -0
- package/dist/src/engine/transform.js +91 -0
- package/dist/src/engine/transform.js.map +1 -0
- package/dist/src/engine/ui-preset.d.ts +4 -0
- package/dist/src/engine/ui-preset.js +56 -0
- package/dist/src/engine/ui-preset.js.map +1 -0
- package/dist/src/engine/utilities/backgrounds.d.ts +2 -0
- package/dist/src/engine/utilities/backgrounds.js +32 -0
- package/dist/src/engine/utilities/backgrounds.js.map +1 -0
- package/dist/src/engine/utilities/borders.d.ts +2 -0
- package/dist/src/engine/utilities/borders.js +95 -0
- package/dist/src/engine/utilities/borders.js.map +1 -0
- package/dist/src/engine/utilities/effects.d.ts +2 -0
- package/dist/src/engine/utilities/effects.js +61 -0
- package/dist/src/engine/utilities/effects.js.map +1 -0
- package/dist/src/engine/utilities/flexgrid.d.ts +2 -0
- package/dist/src/engine/utilities/flexgrid.js +125 -0
- package/dist/src/engine/utilities/flexgrid.js.map +1 -0
- package/dist/src/engine/utilities/index.d.ts +3 -0
- package/dist/src/engine/utilities/index.js +20 -0
- package/dist/src/engine/utilities/index.js.map +1 -0
- package/dist/src/engine/utilities/layout.d.ts +2 -0
- package/dist/src/engine/utilities/layout.js +84 -0
- package/dist/src/engine/utilities/layout.js.map +1 -0
- package/dist/src/engine/utilities/sizing.d.ts +2 -0
- package/dist/src/engine/utilities/sizing.js +21 -0
- package/dist/src/engine/utilities/sizing.js.map +1 -0
- package/dist/src/engine/utilities/spacing.d.ts +2 -0
- package/dist/src/engine/utilities/spacing.js +39 -0
- package/dist/src/engine/utilities/spacing.js.map +1 -0
- package/dist/src/engine/utilities/typography.d.ts +2 -0
- package/dist/src/engine/utilities/typography.js +120 -0
- package/dist/src/engine/utilities/typography.js.map +1 -0
- package/dist/src/engine/utilities/values.d.ts +16 -0
- package/dist/src/engine/utilities/values.js +91 -0
- package/dist/src/engine/utilities/values.js.map +1 -0
- package/dist/src/engine/variants.d.ts +2 -0
- package/dist/src/engine/variants.js +99 -0
- package/dist/src/engine/variants.js.map +1 -0
- package/dist/src/extractor.d.ts +146 -0
- package/dist/src/extractor.js +3862 -0
- package/dist/src/extractor.js.map +1 -0
- package/dist/src/index.cjs +4518 -0
- package/dist/src/index.cjs.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/index.mjs +4480 -0
- package/dist/src/index.mjs.map +1 -0
- package/dist/src/keyframes.cjs +367 -0
- package/dist/src/keyframes.cjs.map +1 -0
- package/dist/src/keyframes.d.ts +27 -0
- package/dist/src/keyframes.js +188 -0
- package/dist/src/keyframes.js.map +1 -0
- package/dist/src/keyframes.mjs +362 -0
- package/dist/src/keyframes.mjs.map +1 -0
- package/dist/src/logger.d.ts +2 -0
- package/dist/src/logger.js +31 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/plugin.cjs +43 -0
- package/dist/src/plugin.cjs.map +1 -0
- package/dist/src/plugin.d.ts +12 -0
- package/dist/src/plugin.js +39 -0
- package/dist/src/plugin.js.map +1 -0
- package/dist/src/plugin.mjs +41 -0
- package/dist/src/plugin.mjs.map +1 -0
- package/dist/src/presets-plugins.cjs +99 -0
- package/dist/src/presets-plugins.cjs.map +1 -0
- package/dist/src/presets-plugins.d.ts +1 -0
- package/dist/src/presets-plugins.js +56 -0
- package/dist/src/presets-plugins.js.map +1 -0
- package/dist/src/presets-plugins.mjs +97 -0
- package/dist/src/presets-plugins.mjs.map +1 -0
- package/dist/src/state.d.ts +76 -0
- package/dist/src/state.js +314 -0
- package/dist/src/state.js.map +1 -0
- package/dist/src/theme/constants.d.ts +22 -0
- package/dist/src/theme/constants.js +17 -0
- package/dist/src/theme/constants.js.map +1 -0
- package/dist/src/theme/index.d.ts +2 -0
- package/dist/src/theme/index.js +48 -0
- package/dist/src/theme/index.js.map +1 -0
- package/dist/src/theme/types.d.ts +13 -0
- package/dist/src/theme/types.js +2 -0
- package/dist/src/theme/types.js.map +1 -0
- package/dist/src/types/ast.d.ts +23 -0
- package/dist/src/types/ast.js +2 -0
- package/dist/src/types/ast.js.map +1 -0
- package/dist/src/types/base-types.d.ts +53 -0
- package/dist/src/types/base-types.js +2 -0
- package/dist/src/types/base-types.js.map +1 -0
- package/dist/src/types/components-types.d.ts +28 -0
- package/dist/src/types/components-types.js +2 -0
- package/dist/src/types/components-types.js.map +1 -0
- package/dist/src/types/config.d.ts +90 -0
- package/dist/src/types/config.js +3 -0
- package/dist/src/types/config.js.map +1 -0
- package/dist/src/types/css-parser.d.ts +361 -0
- package/dist/src/types/css-parser.js +2 -0
- package/dist/src/types/css-parser.js.map +1 -0
- package/dist/src/types/keyframes-type.d.ts +47 -0
- package/dist/src/types/keyframes-type.js +2 -0
- package/dist/src/types/keyframes-type.js.map +1 -0
- package/dist/src/types/plugin.d.ts +10 -0
- package/dist/src/types/plugin.js +2 -0
- package/dist/src/types/plugin.js.map +1 -0
- package/dist/src/types/screens-types.d.ts +47 -0
- package/dist/src/types/screens-types.js +2 -0
- package/dist/src/types/screens-types.js.map +1 -0
- package/dist/src/types/utilities-types.d.ts +147 -0
- package/dist/src/types/utilities-types.js +2 -0
- package/dist/src/types/utilities-types.js.map +1 -0
- package/dist/src/types.d.ts +77 -0
- package/dist/src/types.js +12 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/units/constants.d.ts +35 -0
- package/dist/src/units/constants.js +9 -0
- package/dist/src/units/constants.js.map +1 -0
- package/dist/src/units/index.d.ts +15 -0
- package/dist/src/units/index.js +7 -0
- package/dist/src/units/index.js.map +1 -0
- package/dist/src/units/types.d.ts +9 -0
- package/dist/src/units/types.js +2 -0
- package/dist/src/units/types.js.map +1 -0
- package/dist/src/utilities/backgrounds/constants.d.ts +2810 -0
- package/dist/src/utilities/backgrounds/constants.js +119 -0
- package/dist/src/utilities/backgrounds/constants.js.map +1 -0
- package/dist/src/utilities/backgrounds/index.d.ts +1 -0
- package/dist/src/utilities/backgrounds/index.js +2 -0
- package/dist/src/utilities/backgrounds/index.js.map +1 -0
- package/dist/src/utilities/borders/constants.d.ts +10586 -0
- package/dist/src/utilities/borders/constants.js +309 -0
- package/dist/src/utilities/borders/constants.js.map +1 -0
- package/dist/src/utilities/borders/index.d.ts +1 -0
- package/dist/src/utilities/borders/index.js +2 -0
- package/dist/src/utilities/borders/index.js.map +1 -0
- package/dist/src/utilities/breakpoints/constants.d.ts +330 -0
- package/dist/src/utilities/breakpoints/constants.js +269 -0
- package/dist/src/utilities/breakpoints/constants.js.map +1 -0
- package/dist/src/utilities/breakpoints/index.d.ts +2 -0
- package/dist/src/utilities/breakpoints/index.js +3 -0
- package/dist/src/utilities/breakpoints/index.js.map +1 -0
- package/dist/src/utilities/breakpoints/types.d.ts +8 -0
- package/dist/src/utilities/breakpoints/types.js +2 -0
- package/dist/src/utilities/breakpoints/types.js.map +1 -0
- package/dist/src/utilities/colors/base.d.ts +778 -0
- package/dist/src/utilities/colors/base.js +872 -0
- package/dist/src/utilities/colors/base.js.map +1 -0
- package/dist/src/utilities/colors/color.d.ts +1122 -0
- package/dist/src/utilities/colors/color.js +957 -0
- package/dist/src/utilities/colors/color.js.map +1 -0
- package/dist/src/utilities/colors/constants.d.ts +1 -0
- package/dist/src/utilities/colors/constants.js +2 -0
- package/dist/src/utilities/colors/constants.js.map +1 -0
- package/dist/src/utilities/colors/index.d.ts +4 -0
- package/dist/src/utilities/colors/index.js +29 -0
- package/dist/src/utilities/colors/index.js.map +1 -0
- package/dist/src/utilities/colors/types.d.ts +3 -0
- package/dist/src/utilities/colors/types.js +2 -0
- package/dist/src/utilities/colors/types.js.map +1 -0
- package/dist/src/utilities/effects/constants.d.ts +641 -0
- package/dist/src/utilities/effects/constants.js +83 -0
- package/dist/src/utilities/effects/constants.js.map +1 -0
- package/dist/src/utilities/effects/index.d.ts +1 -0
- package/dist/src/utilities/effects/index.js +2 -0
- package/dist/src/utilities/effects/index.js.map +1 -0
- package/dist/src/utilities/filters/constants.d.ts +406 -0
- package/dist/src/utilities/filters/constants.js +206 -0
- package/dist/src/utilities/filters/constants.js.map +1 -0
- package/dist/src/utilities/filters/index.d.ts +1 -0
- package/dist/src/utilities/filters/index.js +2 -0
- package/dist/src/utilities/filters/index.js.map +1 -0
- package/dist/src/utilities/flex/constants.d.ts +934 -0
- package/dist/src/utilities/flex/constants.js +221 -0
- package/dist/src/utilities/flex/constants.js.map +1 -0
- package/dist/src/utilities/flex/index.d.ts +1 -0
- package/dist/src/utilities/flex/index.js +2 -0
- package/dist/src/utilities/flex/index.js.map +1 -0
- package/dist/src/utilities/flex/types.d.ts +0 -0
- package/dist/src/utilities/flex/types.js +4 -0
- package/dist/src/utilities/flex/types.js.map +1 -0
- package/dist/src/utilities/index.d.ts +31338 -0
- package/dist/src/utilities/index.js +333 -0
- package/dist/src/utilities/index.js.map +1 -0
- package/dist/src/utilities/interactivity/constants.d.ts +1244 -0
- package/dist/src/utilities/interactivity/constants.js +165 -0
- package/dist/src/utilities/interactivity/constants.js.map +1 -0
- package/dist/src/utilities/interactivity/index.d.ts +1 -0
- package/dist/src/utilities/interactivity/index.js +2 -0
- package/dist/src/utilities/interactivity/index.js.map +1 -0
- package/dist/src/utilities/layout/constants.d.ts +837 -0
- package/dist/src/utilities/layout/constants.js +159 -0
- package/dist/src/utilities/layout/constants.js.map +1 -0
- package/dist/src/utilities/layout/index.d.ts +1 -0
- package/dist/src/utilities/layout/index.js +2 -0
- package/dist/src/utilities/layout/index.js.map +1 -0
- package/dist/src/utilities/layout/types.d.ts +0 -0
- package/dist/src/utilities/layout/types.js +2 -0
- package/dist/src/utilities/layout/types.js.map +1 -0
- package/dist/src/utilities/sizing/constants.d.ts +989 -0
- package/dist/src/utilities/sizing/constants.js +53 -0
- package/dist/src/utilities/sizing/constants.js.map +1 -0
- package/dist/src/utilities/sizing/index.d.ts +2 -0
- package/dist/src/utilities/sizing/index.js +3 -0
- package/dist/src/utilities/sizing/index.js.map +1 -0
- package/dist/src/utilities/sizing/types.d.ts +10 -0
- package/dist/src/utilities/sizing/types.js +2 -0
- package/dist/src/utilities/sizing/types.js.map +1 -0
- package/dist/src/utilities/spacing/constants.d.ts +1779 -0
- package/dist/src/utilities/spacing/constants.js +142 -0
- package/dist/src/utilities/spacing/constants.js.map +1 -0
- package/dist/src/utilities/spacing/index.d.ts +2 -0
- package/dist/src/utilities/spacing/index.js +3 -0
- package/dist/src/utilities/spacing/index.js.map +1 -0
- package/dist/src/utilities/spacing/types.d.ts +15 -0
- package/dist/src/utilities/spacing/types.js +8 -0
- package/dist/src/utilities/spacing/types.js.map +1 -0
- package/dist/src/utilities/svg/constants.d.ts +1062 -0
- package/dist/src/utilities/svg/constants.js +34 -0
- package/dist/src/utilities/svg/constants.js.map +1 -0
- package/dist/src/utilities/transforms/constants.d.ts +247 -0
- package/dist/src/utilities/transforms/constants.js +74 -0
- package/dist/src/utilities/transforms/constants.js.map +1 -0
- package/dist/src/utilities/transforms/index.d.ts +1 -0
- package/dist/src/utilities/transforms/index.js +2 -0
- package/dist/src/utilities/transforms/index.js.map +1 -0
- package/dist/src/utilities/transitions/constants.d.ts +116 -0
- package/dist/src/utilities/transitions/constants.js +91 -0
- package/dist/src/utilities/transitions/constants.js.map +1 -0
- package/dist/src/utilities/transitions/index.d.ts +1 -0
- package/dist/src/utilities/transitions/index.js +2 -0
- package/dist/src/utilities/transitions/index.js.map +1 -0
- package/dist/src/utilities/typography/constants.d.ts +2401 -0
- package/dist/src/utilities/typography/constants.js +401 -0
- package/dist/src/utilities/typography/constants.js.map +1 -0
- package/dist/src/utilities/typography/index.d.ts +1 -0
- package/dist/src/utilities/typography/index.js +2 -0
- package/dist/src/utilities/typography/index.js.map +1 -0
- package/dist/src/utils.d.ts +18 -0
- package/dist/src/utils.js +282 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/watcher.d.ts +15 -0
- package/dist/src/watcher.js +62 -0
- package/dist/src/watcher.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utilities.css +1 -0
- package/index.css +2 -0
- package/package.json +139 -0
- package/reset.css +168 -0
- package/utilities.css +1 -0
|
@@ -0,0 +1,3862 @@
|
|
|
1
|
+
import { arrayToObject, assignKeys, camelToKebab, checkType, kebabObjectKeys, objectKeys, omit, pick, pickSub, toCamelCase, asInt, isInt, formatRgba, updateValueDeep, getValueDeep, mergeNestedObjects, StylePatternsFlattened, uniq, splitString, mapObjects, kebabArrayString, COLON_REGEX, TIRET_REGEX, SLASH_REGEX, TAG_DYNAMIC_REGEX, startsWithSpace, ACCOLADE_SPLIT_REGEX, replaceString, escapeString, getCorrectKey, KeyCorrection, isImportantFn,
|
|
2
|
+
// memoizeFn,
|
|
3
|
+
PARENTHESES_DYNAMIC_REGEX, isUndefinedOrNull } from "./commons/helper.js";
|
|
4
|
+
import { DEFAULT_THEME_CONFIG } from "./constants.js";
|
|
5
|
+
import { UtilitiesData, UtilitiesShorthands, UtilitiesPropertiesConfig, TransformPropertiesFn, TransformPropertiesPrefix, OpacityProperties, ColorsPropertiesKeys, SizingPropertiesKeys, SpacingPropertiesKeys, BorderRadiusPropertiesKeys, BorderPropertiesKeys } from "./utilities/index.js";
|
|
6
|
+
import { ThemesSelectors } from "./theme/constants.js";
|
|
7
|
+
import { Color } from "./utilities/colors/color.js";
|
|
8
|
+
import { CssBorderColorProperties, DEFAULT_HINTS, GradientKeyMap, HINTS } from "./commons/constants.js";
|
|
9
|
+
import { FilterPropertiesFn, FiltersPropertiesPrefix } from "./utilities/filters/constants.js";
|
|
10
|
+
import { CssPropertiesKeys } from "./commons/properties.js";
|
|
11
|
+
import { getComponentsInfos } from "./components/index.js";
|
|
12
|
+
import { GlobalStateManager } from "./state.js";
|
|
13
|
+
import { processKeyframes } from "./keyframes.js";
|
|
14
|
+
import { DEFAULT_BRAEKPOINTS } from "./utilities/breakpoints/constants.js";
|
|
15
|
+
import { logger } from "./logger.js";
|
|
16
|
+
const CMP_PREFIX = 'flx';
|
|
17
|
+
export const EXACT_MATCH_PROPERTIES = ['display', 'position', 'flexDirection', 'flexWrap'];
|
|
18
|
+
export const STANDARD_MATCHING_OBJECT = ["clamp", "text", "fs", "font-smoothing", "fontSmoothing"];
|
|
19
|
+
export const state = new GlobalStateManager();
|
|
20
|
+
const memoizeFn = (fn) => {
|
|
21
|
+
const cache = state.cache;
|
|
22
|
+
return (...args) => {
|
|
23
|
+
const key = fn.name + JSON.stringify(args);
|
|
24
|
+
// const n = args[0];
|
|
25
|
+
if (cache.has(key)) {
|
|
26
|
+
const result = cache.get(key);
|
|
27
|
+
if (result !== undefined && result !== null) {
|
|
28
|
+
if (typeof result === "object") {
|
|
29
|
+
if (Array.isArray(result)) {
|
|
30
|
+
return result.slice();
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return Object.assign({}, result);
|
|
34
|
+
;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
let result = fn(...args);
|
|
42
|
+
if (result !== undefined && result !== null && typeof result === "object") {
|
|
43
|
+
if (Array.isArray(result)) {
|
|
44
|
+
cache.set(key, result.slice());
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
cache.set(key, Object.assign({}, result));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
cache.set(key, result);
|
|
52
|
+
}
|
|
53
|
+
// cache[key as any] = result;
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export const generateShorthandScheme = (key, shorthand, parent) => {
|
|
59
|
+
const result = [];
|
|
60
|
+
const v = {
|
|
61
|
+
start: '',
|
|
62
|
+
end: '',
|
|
63
|
+
global: ''
|
|
64
|
+
};
|
|
65
|
+
if (checkType(shorthand).is_object) {
|
|
66
|
+
const shorthandData = Object.assign({}, shorthand);
|
|
67
|
+
for (const k in shorthandData) {
|
|
68
|
+
if (shorthandData.hasOwnProperty(k)) {
|
|
69
|
+
result.push({ custom_style_name: k, attr: shorthandData[k], filtered: Object.assign({}, v), filteredComposed: Object.assign({}, v), searched: [], parent });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
result.push({ custom_style_name: key, attr: shorthand, filtered: Object.assign({}, v), filteredComposed: Object.assign({}, v), searched: [], parent });
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
78
|
+
export const _generateStyleMap = (_shorthands = Object.assign({}, UtilitiesShorthands)) => {
|
|
79
|
+
const shorthandsData = Object.assign({}, _shorthands);
|
|
80
|
+
const result = [];
|
|
81
|
+
for (let s in shorthandsData) {
|
|
82
|
+
if (shorthandsData.hasOwnProperty(s)) {
|
|
83
|
+
const v = {
|
|
84
|
+
start: '',
|
|
85
|
+
end: '',
|
|
86
|
+
global: '',
|
|
87
|
+
};
|
|
88
|
+
if (checkType(shorthandsData[s]).is_object) {
|
|
89
|
+
for (let k in shorthandsData[s]) {
|
|
90
|
+
if (shorthandsData[s].hasOwnProperty(k)) {
|
|
91
|
+
result.push({ custom_style_name: k, attr: Object.assign({}, shorthandsData)[s][k], filtered: Object.assign({}, v), filteredComposed: Object.assign({}, v), searched: [] });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
result.push({ custom_style_name: s, attr: Object.assign({}, shorthandsData)[s], filtered: Object.assign({}, v), filteredComposed: Object.assign({}, v) });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
};
|
|
102
|
+
export const flattenCssObjects = (object, main_shorthand, value, isSuffix = false, camel = true, separator = "-", wrappKeys = [], _shorthands_array = [], _objectKeys = objectKeys(object), _correction = KeyCorrection) => {
|
|
103
|
+
if (!checkType(object).is_object) {
|
|
104
|
+
return object;
|
|
105
|
+
}
|
|
106
|
+
let result = {};
|
|
107
|
+
const obj = Object.assign({}, object);
|
|
108
|
+
const shorthands = _shorthands_array;
|
|
109
|
+
for (const o in obj) {
|
|
110
|
+
if (obj.hasOwnProperty(o)) {
|
|
111
|
+
if (_objectKeys.some(ok => ok === o)) {
|
|
112
|
+
let key1 = `${o}`;
|
|
113
|
+
let key2 = `${o}`;
|
|
114
|
+
let key = key1;
|
|
115
|
+
if ('DEFAULT' === o.toString() || value.length === 0) {
|
|
116
|
+
key = value;
|
|
117
|
+
if (camel && value.length > 0) {
|
|
118
|
+
key = toCamelCase(key);
|
|
119
|
+
}
|
|
120
|
+
// shorthands.push(key)
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// if(o!==value){
|
|
124
|
+
// if(o!=='px' && value!=='px'){
|
|
125
|
+
// }
|
|
126
|
+
key1 = getCorrectKey(`${o}${separator}${value}`, _correction);
|
|
127
|
+
key2 = getCorrectKey(`${value}${separator}${o}`, _correction);
|
|
128
|
+
if (isSuffix) {
|
|
129
|
+
if (camel) {
|
|
130
|
+
key = toCamelCase(key1);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
key = key1;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!isSuffix) {
|
|
137
|
+
if (camel) {
|
|
138
|
+
key = toCamelCase(key2);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
key = key2;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
let preresult = {};
|
|
146
|
+
if (checkType(obj[o]).is_object) {
|
|
147
|
+
const cssPropsArr = [];
|
|
148
|
+
const cssProps = {};
|
|
149
|
+
const notCssProps = {};
|
|
150
|
+
const notCssPropsArr = [];
|
|
151
|
+
const keysArr = [];
|
|
152
|
+
for (const ok in obj[o]) {
|
|
153
|
+
if (obj[o].hasOwnProperty(ok)) {
|
|
154
|
+
keysArr.push(ok);
|
|
155
|
+
if (isCssPropMemo(ok)) {
|
|
156
|
+
cssPropsArr.push(ok);
|
|
157
|
+
cssProps[ok] = obj[o][ok];
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
notCssProps[ok] = obj[o][ok];
|
|
161
|
+
notCssPropsArr.push(ok);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
let prefixed;
|
|
166
|
+
if (cssPropsArr.length !== keysArr.length) {
|
|
167
|
+
prefixed = flattenCssObjects(notCssProps, main_shorthand, key, isSuffix, camel, separator, wrappKeys, shorthands, notCssPropsArr, _correction);
|
|
168
|
+
}
|
|
169
|
+
const normal_css = (cssPropsArr.length > 0 ? { [key]: cssProps } : {});
|
|
170
|
+
preresult = Object.assign(Object.assign({}, normal_css), (prefixed ? Object.assign({}, prefixed) : {}));
|
|
171
|
+
result = Object.assign(Object.assign({}, result), preresult);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
let value = obj[o];
|
|
175
|
+
if (typeof obj[o] === "string" && Color.isValidColor(obj[o])) {
|
|
176
|
+
const new_key = varify(key.replace(`${main_shorthand}-`, ''), true);
|
|
177
|
+
value = new_key;
|
|
178
|
+
}
|
|
179
|
+
preresult = { [key]: Object.assign({}, assignKeys(wrappKeys, value)) };
|
|
180
|
+
result = Object.assign(Object.assign({}, result), preresult);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
};
|
|
187
|
+
const stylesMap = () => {
|
|
188
|
+
return state.getThemeUtilities('styleMap');
|
|
189
|
+
};
|
|
190
|
+
export const flattenClassMap = memoizeFn(pickSub);
|
|
191
|
+
const getThemeMergedStyles = () => state.getThemeUtilities('merged');
|
|
192
|
+
const getThemeScreens = () => state.getThemeUtilities('screens') || Object.assign({}, DEFAULT_BRAEKPOINTS);
|
|
193
|
+
const getThemeBase = () => state.getThemeUtilities('base');
|
|
194
|
+
const getThemeKeyframes = () => state.getThemeUtilities('keyframes');
|
|
195
|
+
const getThemeKeyframesOptions = () => state.getThemeUtilities('keyframesOptions');
|
|
196
|
+
export const getStyleMapObject = () => state.getThemeUtilities('classMapFlattened');
|
|
197
|
+
export const getShorthandsArray = () => state.getThemeUtilities('shorthands_array');
|
|
198
|
+
const getSpaceString = () => state.getThemeUtilities('space') || ' ';
|
|
199
|
+
const getMode = () => state.getMode();
|
|
200
|
+
export const formatScreensSelectors = (screens_data) => {
|
|
201
|
+
const screens = screens_data ? Object.assign({}, screens_data) : getThemeScreens();
|
|
202
|
+
if (!getThemeScreens() && screens !== undefined) {
|
|
203
|
+
state.setThemeUtilities({ screens });
|
|
204
|
+
}
|
|
205
|
+
if (!screens) {
|
|
206
|
+
logger(`[Fluixi Css ❌]`, `No screens found in theme.`);
|
|
207
|
+
}
|
|
208
|
+
if (screens) {
|
|
209
|
+
return Object.keys(screens).flatMap(k => ({ name: k, selector: `:${k}`, tag: k }));
|
|
210
|
+
}
|
|
211
|
+
return [];
|
|
212
|
+
};
|
|
213
|
+
export const JIT_PSEUSO_PROPS = [
|
|
214
|
+
{
|
|
215
|
+
name: 'light',
|
|
216
|
+
selector: ':light',
|
|
217
|
+
tag: 'light',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: 'dark',
|
|
221
|
+
selector: ':dark',
|
|
222
|
+
tag: 'dark',
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: 'min',
|
|
226
|
+
selector: ':min',
|
|
227
|
+
tag: '(?<!group-|peer-)min-\\[.*\\]',
|
|
228
|
+
match_tag: 'min-\\[.*\\]'
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: 'max',
|
|
232
|
+
selector: ':max',
|
|
233
|
+
tag: '(?<!group-|peer-)max-\\[.*\\]',
|
|
234
|
+
match_tag: 'max-\\[.*\\]'
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: 'has',
|
|
238
|
+
selector: '&:has',
|
|
239
|
+
tag: '(?<!group-|peer-)has-\\[.*\\]',
|
|
240
|
+
match_tag: 'has-\\[.*\\]'
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: 'is',
|
|
244
|
+
selector: '&:is',
|
|
245
|
+
tag: '(?<!group-|peer-)is-\\[.*\\]',
|
|
246
|
+
match_tag: 'is-\\[.*\\]'
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: 'not',
|
|
250
|
+
selector: '&:not',
|
|
251
|
+
tag: '(?<!group-|peer-)not-\\[.*\\]',
|
|
252
|
+
match_tag: 'not-\\[.*\\]'
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
name: 'host',
|
|
256
|
+
selector: '&:host',
|
|
257
|
+
tag: '(?<!group-|peer-)host-\\[.*\\]',
|
|
258
|
+
match_tag: 'host-\\[.*\\]'
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: 'lang',
|
|
262
|
+
selector: '&:lang',
|
|
263
|
+
tag: '(?<!group-|peer-)lang-\\[.*\\]',
|
|
264
|
+
match_tag: 'lang-\\[.*\\]'
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
name: '\\[.*\\]',
|
|
268
|
+
selector: ':selector',
|
|
269
|
+
tag: '(?<!has-|min-|max-|content-|group-|peer-|is-|not-|host-|lang-|aria-|data-|&-)(\\[.*?[^\\[\\]]\\]:*?)',
|
|
270
|
+
skip_colon: true,
|
|
271
|
+
end_regex: ':',
|
|
272
|
+
match_tag: '(\\[.*\\]+)'
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: '&-\\[.*\\]',
|
|
276
|
+
selector: ':selector',
|
|
277
|
+
tag: '(?<!has-|min-|max-|content-|group-|peer-|is-|not-|host-|lang-|aria-|data-)&-\\[.*\\]',
|
|
278
|
+
match_tag: '(&-\\[.*\\]+)'
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
name: 'hover',
|
|
282
|
+
selector: '&:hover',
|
|
283
|
+
tag: '(?<!group-|peer-)hover',
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
name: 'active',
|
|
287
|
+
selector: '&:active',
|
|
288
|
+
tag: '(?<!group-|peer-)active'
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
name: 'visited',
|
|
292
|
+
selector: '&:visited',
|
|
293
|
+
tag: '(?<!group-|peer-)visited'
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
name: 'target',
|
|
297
|
+
selector: '&:target',
|
|
298
|
+
tag: '(?<!group-|peer-)target'
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: '*',
|
|
302
|
+
selector: '& > *',
|
|
303
|
+
tag: '(?<!group-|peer-)\\*',
|
|
304
|
+
match_tag: '\\*',
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
name: 'disabled',
|
|
308
|
+
selector: '&:disabled',
|
|
309
|
+
tag: '(?<!group-|peer-)disabled'
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
name: 'enabled',
|
|
313
|
+
selector: '&:enabled',
|
|
314
|
+
tag: '(?<!group-|peer-)enabled'
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
name: 'focus',
|
|
318
|
+
selector: '&:focus',
|
|
319
|
+
tag: '(?<!group-|peer-)focus'
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
name: 'focus-within',
|
|
323
|
+
selector: '&:focus-within',
|
|
324
|
+
tag: "(?<!group-|peer-)focus-within"
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
name: 'first',
|
|
328
|
+
selector: '&:first-child',
|
|
329
|
+
tag: '(?<!group-|peer-)first'
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
name: 'first-of-type',
|
|
333
|
+
selector: '&:first-of-type',
|
|
334
|
+
tag: '(?<!group-|peer-)first-of-type'
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
name: 'last',
|
|
338
|
+
selector: '&:last-child',
|
|
339
|
+
tag: '(?<!group-|peer-)last'
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
name: 'only',
|
|
343
|
+
selector: '&:only-child',
|
|
344
|
+
tag: '(?<!group-|peer-)only'
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: 'odd',
|
|
348
|
+
selector: '&:nth-child(odd)',
|
|
349
|
+
tag: '(?<!group-|peer-)odd'
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
name: 'even',
|
|
353
|
+
selector: '&:nth-child(even)',
|
|
354
|
+
tag: '(?<!group-|peer-)even'
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
name: 'first-of-type',
|
|
358
|
+
selector: '&:first-of-type',
|
|
359
|
+
tag: '(?<!group-|peer-)first-of-type'
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
name: 'last-of-type',
|
|
363
|
+
selector: '&:last-of-type',
|
|
364
|
+
tag: '(?<!group-|peer-)last-of-type'
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
name: 'only-of-type',
|
|
368
|
+
selector: '&:only-of-type',
|
|
369
|
+
tag: '(?<!group-|peer-)only-of-type'
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: 'checked',
|
|
373
|
+
selector: '&:checked',
|
|
374
|
+
tag: '(?<!group-|peer-)checked'
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
name: 'intermediate',
|
|
378
|
+
selector: '&:intermediate',
|
|
379
|
+
tag: '(?<!group-|peer-)intermediate'
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
name: 'default',
|
|
383
|
+
selector: '&:default',
|
|
384
|
+
tag: '(?<!group-|peer-)default'
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
name: 'required',
|
|
388
|
+
selector: '&:required',
|
|
389
|
+
tag: '(?<!group-|peer-)required'
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
name: 'empty',
|
|
393
|
+
selector: '&:empty',
|
|
394
|
+
tag: '(?<!group-|peer-)empty'
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
name: 'invalid',
|
|
398
|
+
selector: '&:invalid',
|
|
399
|
+
tag: '(?<!group-|peer-)invalid'
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
name: 'valid',
|
|
403
|
+
selector: '&:valid',
|
|
404
|
+
tag: '(?<!group-|peer-)valid'
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
name: 'in-range',
|
|
408
|
+
selector: '&:in-range',
|
|
409
|
+
tag: '(?<!group-|peer-)in-range'
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
name: 'out-of-range',
|
|
413
|
+
selector: '&:out-of-range',
|
|
414
|
+
tag: '(?<!group-|peer-)out-of-range'
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
name: 'placeholder-shown',
|
|
418
|
+
selector: '&:placeholder-shown',
|
|
419
|
+
tag: '(?<!group-|peer-)placeholder-shown'
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
name: 'autofill',
|
|
423
|
+
selector: '&:autofill',
|
|
424
|
+
tag: '(?<!group-|peer-)autofill'
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
name: 'read-only',
|
|
428
|
+
selector: '&:read-only',
|
|
429
|
+
tag: '(?<!group-|peer-)read-only'
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
name: 'before',
|
|
433
|
+
selector: '&::before',
|
|
434
|
+
tag: '(?<!group-|peer-)before'
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
name: 'after',
|
|
438
|
+
selector: '&::after',
|
|
439
|
+
tag: '(?<!group-|peer-)after'
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
name: 'first-letter',
|
|
443
|
+
selector: '&::first-letter',
|
|
444
|
+
tag: '(?<!group-|peer-)first-letter'
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
name: 'first-line',
|
|
448
|
+
selector: '&::first-line',
|
|
449
|
+
tag: '(?<!group-|peer-)first-line'
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: 'selection',
|
|
453
|
+
selector: '&::selection',
|
|
454
|
+
tag: '(?<!group-|peer-)selection'
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
name: 'marker',
|
|
458
|
+
selector: '&::marker',
|
|
459
|
+
tag: '(?<!group-|peer-)marker'
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
name: 'file',
|
|
463
|
+
selector: '&::file-selector-button',
|
|
464
|
+
tag: '(?<!group-|peer-)file'
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
name: 'backdrop',
|
|
468
|
+
selector: '&::backdrop',
|
|
469
|
+
tag: '(?<!group-|peer-)backdrop'
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
name: 'placeholder',
|
|
473
|
+
selector: '&::placeholder',
|
|
474
|
+
tag: '(?<!group-|peer-)placeholder'
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
name: 'rtl',
|
|
478
|
+
selector: '&:where([dir="rtl"], [dir="rtl"] *)',
|
|
479
|
+
tag: '(?<!group-|peer-)rtl'
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
name: 'ltr',
|
|
483
|
+
selector: '&:where([dir="ltr"], [dir="ltr"] *)',
|
|
484
|
+
tag: '(?<!group-|peer-)ltr'
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
name: 'open',
|
|
488
|
+
selector: '&[open]',
|
|
489
|
+
tag: '(?<!group-|peer-)open'
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
name: 'group',
|
|
493
|
+
selector: 'group',
|
|
494
|
+
tag: "(group|peer)([a-z/\\[\\].\\d#\\>\\<-]+|\\[.*\\])",
|
|
495
|
+
match_tag: 'group-(\\[.*?\\]|\\w+[-]?\\w+)'
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
name: 'aria',
|
|
499
|
+
selector: '&:aria',
|
|
500
|
+
tag: "(?<!group-|peer-)(aria-)+.*([^-\\&\\_\\.\\[\\]]+|\\[[^\\]]*\\]+)",
|
|
501
|
+
match_tag: 'aria-(\\[.*?\\]|\\w+[-]?\\w+)'
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
name: 'data',
|
|
505
|
+
selector: '&:data',
|
|
506
|
+
tag: "(?<!group-|peer-)(data-)+.*([^-\\&\\_\\.\\[\\]]+|\\[[^\\]]*\\]+)",
|
|
507
|
+
match_tag: 'data-(\\[.*?\\]|\\w+[-]?\\w+)'
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
name: 'peer',
|
|
511
|
+
selector: 'peer',
|
|
512
|
+
tag: "(group|peer)([a-z/\\[\\].\\d#\\>\\<-]+|\\[.*\\])",
|
|
513
|
+
match_tag: 'peer-(\\[.*?\\]|\\w+[-]?\\w+)'
|
|
514
|
+
}
|
|
515
|
+
];
|
|
516
|
+
const _getJitProps = (selectors, other) => {
|
|
517
|
+
if (!selectors) {
|
|
518
|
+
getThemeScreens();
|
|
519
|
+
}
|
|
520
|
+
const variants = state.variants ? state.variants : [];
|
|
521
|
+
return [...JIT_PSEUSO_PROPS, ...variants, ...(selectors ? selectors : formatScreensSelectors(other))];
|
|
522
|
+
};
|
|
523
|
+
const jitMemo = memoizeFn(_getJitProps);
|
|
524
|
+
export const getJitProps = (selectors, other) => {
|
|
525
|
+
return jitMemo(selectors, other);
|
|
526
|
+
};
|
|
527
|
+
export const getR = (el, property, global = false, bound = true) => {
|
|
528
|
+
const string = `${global ? "^" : ""}(${bound ? "\\b" : ""}(?:${el === null || el === void 0 ? void 0 : el.replace(/\-/g, "\\-")})${bound ? "" : ""}){1,}.*?(?=([${(property && property.end_regex) ? property.end_regex : '^:'}])+.*)`;
|
|
529
|
+
return new RegExp(string);
|
|
530
|
+
};
|
|
531
|
+
export const extractBracket = (el = "") => {
|
|
532
|
+
const string = `${el}\\[((?:[^\\[\\]]|\\[(?:[^\\[\\]]|\\[[^\\[\\]]*\\])*\\])*?)\\]`;
|
|
533
|
+
return new RegExp(string);
|
|
534
|
+
};
|
|
535
|
+
export const extractParentheses = (el = "") => {
|
|
536
|
+
const string = `${el}\\(((?:[^\\(\\)]|\\((?:[^\\(\\)]|\\([^\\(\\)]*\\))*\\))*?)\\)`;
|
|
537
|
+
return new RegExp(string);
|
|
538
|
+
};
|
|
539
|
+
const getStyleSchemeRegex = (style_map, value = '', propIsNotValue = true, debug = false) => {
|
|
540
|
+
const el = style_map.custom_style_name;
|
|
541
|
+
let reg = `(\\b${el.replace(/\-/g, "\\-")}\\b)(.*?)(?=${"-$".replace(/\-/g, "\\-")}|$.*)`;
|
|
542
|
+
return { match: new RegExp(reg, !propIsNotValue ? 'g' : '').exec(value) };
|
|
543
|
+
};
|
|
544
|
+
export const varify = (name, wrapp, prefix = CMP_PREFIX) => {
|
|
545
|
+
const varName = escapeString(`${(prefix && prefix.length > 0) ? prefix + "-" : ''}${name}`);
|
|
546
|
+
const varData = `--${varName}`;
|
|
547
|
+
if (wrapp) {
|
|
548
|
+
return `var(${varData})`;
|
|
549
|
+
}
|
|
550
|
+
return varData;
|
|
551
|
+
};
|
|
552
|
+
export const findOpacity = (str) => {
|
|
553
|
+
let opacity;
|
|
554
|
+
const reg = extractBracket().exec(str);
|
|
555
|
+
if (reg) {
|
|
556
|
+
opacity = reg[1];
|
|
557
|
+
if (opacity.includes('.')) {
|
|
558
|
+
opacity = Color.toOpacityPercent(opacity);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
const mr = getThemeMergedStyles();
|
|
563
|
+
if (mr && mr.effects && mr.effects.opacity) {
|
|
564
|
+
if (mr.effects.opacity.values[str]) {
|
|
565
|
+
const op = mr.effects.opacity.values[str];
|
|
566
|
+
if (op) {
|
|
567
|
+
opacity = op;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return opacity;
|
|
573
|
+
};
|
|
574
|
+
export const getDefaultValue = (values) => {
|
|
575
|
+
const DEFAULT_KEY = 'default';
|
|
576
|
+
const DEFAULT_COLOR_KEY = '500';
|
|
577
|
+
if (checkType(values).is_object) {
|
|
578
|
+
if (values[DEFAULT_KEY]) {
|
|
579
|
+
return values[DEFAULT_KEY];
|
|
580
|
+
}
|
|
581
|
+
if (values[DEFAULT_COLOR_KEY]) {
|
|
582
|
+
return values[DEFAULT_COLOR_KEY];
|
|
583
|
+
}
|
|
584
|
+
if (values[parseInt(DEFAULT_COLOR_KEY)]) {
|
|
585
|
+
return values[parseInt(DEFAULT_COLOR_KEY)];
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
return values;
|
|
589
|
+
};
|
|
590
|
+
const findProp = (styleData, _property, _val, _config, propName, extractDynamic = true) => {
|
|
591
|
+
const ss = pickSub(Object.assign({}, _config));
|
|
592
|
+
let normal = _val;
|
|
593
|
+
let r;
|
|
594
|
+
let sub;
|
|
595
|
+
let sb;
|
|
596
|
+
const filteredFind = findPropertyValue(_property, propName).filter(f => Object.keys(f.shorthands).some(sh => f.shorthands[sh].some(p => p === propName)));
|
|
597
|
+
if (filteredFind.length === 0) {
|
|
598
|
+
if (ss) {
|
|
599
|
+
sub = ss[toCamelCase(_property)];
|
|
600
|
+
}
|
|
601
|
+
sb = Object.assign({}, sub);
|
|
602
|
+
if (sub && sb.values) {
|
|
603
|
+
sb = Object.assign({}, sub).values;
|
|
604
|
+
}
|
|
605
|
+
if (checkType(sb).is_undefined || Object.keys(sb).length === 0) {
|
|
606
|
+
sb = Object.assign({}, ss);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
const findVal = (el) => {
|
|
610
|
+
let find = filteredFind.find(f => {
|
|
611
|
+
const split = splitString(el, TIRET_REGEX) || [];
|
|
612
|
+
const obj = getValueDeep(Object.assign({}, f.values), split);
|
|
613
|
+
if (obj) {
|
|
614
|
+
return obj;
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
return undefined;
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
if (find) {
|
|
621
|
+
const split = splitString(el, TIRET_REGEX) || [];
|
|
622
|
+
const obj = getValueDeep(Object.assign({}, find.values), split);
|
|
623
|
+
if (obj) {
|
|
624
|
+
find.values = getDefaultValue(obj);
|
|
625
|
+
}
|
|
626
|
+
return getDefaultValue(obj);
|
|
627
|
+
}
|
|
628
|
+
return undefined;
|
|
629
|
+
};
|
|
630
|
+
if (checkType(normal).is_string || checkType(normal).is_number) {
|
|
631
|
+
if (normal.toString().startsWith('var(')) {
|
|
632
|
+
r = normal;
|
|
633
|
+
return r;
|
|
634
|
+
}
|
|
635
|
+
if (extractOpacity(normal.toString()).matched || normal.toString().startsWith('[')) {
|
|
636
|
+
const processed = processStyleValue(normal, styleData.parent, propName);
|
|
637
|
+
if (!extractDynamic || !processed) {
|
|
638
|
+
return null;
|
|
639
|
+
}
|
|
640
|
+
if (processed.startsWith('[') && processed.endsWith(']')) {
|
|
641
|
+
if (!normal.toString().startsWith('[')) {
|
|
642
|
+
const op = extractOpacity(normal);
|
|
643
|
+
const vr = findVal(op.replaced);
|
|
644
|
+
if (op && op.matched && vr) {
|
|
645
|
+
return processed;
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
return null;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
return processed;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const splitted = processed.split('~~');
|
|
656
|
+
if (splitted.length !== 2) {
|
|
657
|
+
return processed;
|
|
658
|
+
}
|
|
659
|
+
normal = splitted[0];
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
let kebab = camelToKebab(normal);
|
|
663
|
+
if (typeof asInt(kebab) === 'number') {
|
|
664
|
+
if (asInt(kebab) === -1) {
|
|
665
|
+
kebab = '1';
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
const setValue = (values) => {
|
|
669
|
+
const opacityProp = kebabArrayString([...OpacityProperties]).find(p => p === _property || p === camelToKebab(_property));
|
|
670
|
+
if (opacityProp) {
|
|
671
|
+
return normal;
|
|
672
|
+
}
|
|
673
|
+
if (checkType(values).is_object) {
|
|
674
|
+
const k = (splitString(normal, TIRET_REGEX) || []).pop();
|
|
675
|
+
if (values[k]) {
|
|
676
|
+
return values[k];
|
|
677
|
+
}
|
|
678
|
+
if (values['500']) {
|
|
679
|
+
return values['500'];
|
|
680
|
+
}
|
|
681
|
+
if (values[500]) {
|
|
682
|
+
return values[500];
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return values;
|
|
686
|
+
};
|
|
687
|
+
const normalFind = findVal(normal);
|
|
688
|
+
if (!checkType(normalFind).is_undefined) {
|
|
689
|
+
r = setValue(normalFind);
|
|
690
|
+
}
|
|
691
|
+
else if (normal.startsWith('[')) {
|
|
692
|
+
r = normal;
|
|
693
|
+
}
|
|
694
|
+
return r;
|
|
695
|
+
};
|
|
696
|
+
export const matchDirectClass = (style_string, attr) => {
|
|
697
|
+
let findShort = findWithShorthands(style_string || '');
|
|
698
|
+
if (findShort) {
|
|
699
|
+
if (findShort['DEFAULT']) {
|
|
700
|
+
findShort = findShort['DEFAULT'];
|
|
701
|
+
}
|
|
702
|
+
else if (findShort['500']) {
|
|
703
|
+
findShort = findShort['500'];
|
|
704
|
+
}
|
|
705
|
+
else if (findShort[500]) {
|
|
706
|
+
findShort = findShort['500'];
|
|
707
|
+
}
|
|
708
|
+
else if (findShort['light'] || findShort['dark']) {
|
|
709
|
+
// findShort =
|
|
710
|
+
console.log('find short found'), { style_string, attr, findShort };
|
|
711
|
+
}
|
|
712
|
+
if (!checkType(findShort).is_object) {
|
|
713
|
+
return {
|
|
714
|
+
map: [findShort],
|
|
715
|
+
obj: attr ? { [attr]: findShort } : findShort,
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
return { map: [findShort], obj: Object.assign({}, findShort) };
|
|
719
|
+
}
|
|
720
|
+
return null;
|
|
721
|
+
};
|
|
722
|
+
const matchStyles = (s, m, match_) => {
|
|
723
|
+
try {
|
|
724
|
+
let { match } = memoGetStyleSchemeRegex(s, m, true);
|
|
725
|
+
if (!match) {
|
|
726
|
+
return null;
|
|
727
|
+
}
|
|
728
|
+
let attr = (s === null || s === void 0 ? void 0 : s.custom_style_name) || '';
|
|
729
|
+
let v = {};
|
|
730
|
+
let m2 = match[2];
|
|
731
|
+
if (m2 && m2.startsWith('-')) {
|
|
732
|
+
m2 = m2.replace('-', '');
|
|
733
|
+
}
|
|
734
|
+
let extracted = extractStyle(s, match[0] || '');
|
|
735
|
+
for (const i of extracted) {
|
|
736
|
+
if (i[1].startsWith('[')) {
|
|
737
|
+
v = Object.assign(Object.assign({}, v), { [i[0]]: i[1] });
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
const val = findProp(s, attr, m2, undefined, i[0]);
|
|
741
|
+
if (val) {
|
|
742
|
+
if (s.custom_style_name === 'space') {
|
|
743
|
+
if (checkType(val).is_object) {
|
|
744
|
+
v = Object.assign(Object.assign({}, v), { ['& >:not([hidden]) ~ :not([hidden])']: val });
|
|
745
|
+
}
|
|
746
|
+
else {
|
|
747
|
+
v = Object.assign(Object.assign({}, v), { ['& >:not([hidden]) ~ :not([hidden])']: { [i[0]]: val } });
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
else {
|
|
751
|
+
if (checkType(val).is_object) {
|
|
752
|
+
v = Object.assign(Object.assign({}, v), val);
|
|
753
|
+
}
|
|
754
|
+
else {
|
|
755
|
+
v = Object.assign(Object.assign({}, v), { [i[0]]: val });
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return { map: [], obj: v };
|
|
762
|
+
}
|
|
763
|
+
catch (err) {
|
|
764
|
+
console.error(`[Fluixi css ❌] Error matching styles`, s);
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
export const matchNormalReg = (text, jitProps) => {
|
|
769
|
+
try {
|
|
770
|
+
const string = `^([^:]*?)(?=${[...(jitProps ? jitProps : getJitProps())].flatMap(p => `-${p.tag}:`).join("|").replace(/\-/g, "\\-")})`;
|
|
771
|
+
const match = new RegExp(string).exec(text);
|
|
772
|
+
if (match) {
|
|
773
|
+
return match[0];
|
|
774
|
+
}
|
|
775
|
+
return null;
|
|
776
|
+
}
|
|
777
|
+
catch (err) {
|
|
778
|
+
return null;
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
export const matchGroup = (text) => {
|
|
782
|
+
const string = `\\bon-(.*?)(?:[:])\\b`;
|
|
783
|
+
const match = new RegExp(string).exec(text);
|
|
784
|
+
if (match) {
|
|
785
|
+
const group = match[0];
|
|
786
|
+
if (group) {
|
|
787
|
+
const parsed = parseOn(group);
|
|
788
|
+
return Object.assign(Object.assign({}, parsed), { styles: text.replace(group, ''), group });
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
return null;
|
|
792
|
+
};
|
|
793
|
+
const extractGroup = (text) => {
|
|
794
|
+
let selector = undefined;
|
|
795
|
+
const parsed = parseOn(text);
|
|
796
|
+
return Object.assign(Object.assign(Object.assign({}, parsed), (selector ? { selector } : {})), { styles: text.replace(text, ''), text });
|
|
797
|
+
};
|
|
798
|
+
const filterStyles = (style_string, prop, element, _config) => {
|
|
799
|
+
matchRegex = false;
|
|
800
|
+
if (style_string && style_string.length > 0) {
|
|
801
|
+
const sm = stylesMap();
|
|
802
|
+
// const cf = getStyleMapObject();
|
|
803
|
+
// const splitted = splitString(style_string, "([^\\-]+\\[|\\[.*?\\]|\\(.*?\\)|\\{.*?\\}|\".*?\"|\'.*?\'|\<.*?\>)+");
|
|
804
|
+
const splitted = splitString(style_string, TIRET_REGEX);
|
|
805
|
+
if (splitted.length === 0 || splitted.length === 1) {
|
|
806
|
+
return [];
|
|
807
|
+
}
|
|
808
|
+
// let prefix = '';
|
|
809
|
+
// for(const s of splitted){
|
|
810
|
+
// if(!s.startsWith('[')){
|
|
811
|
+
// prefix+=`${prefix.length > 0 ? '-':''}${s}`
|
|
812
|
+
// }else{
|
|
813
|
+
// break;
|
|
814
|
+
// }
|
|
815
|
+
// }
|
|
816
|
+
// const rp = replaceString(style_string, `${prefix}`, true, '');
|
|
817
|
+
// const sp = [prefix, rp]
|
|
818
|
+
// if(sp.length === 1){
|
|
819
|
+
// return [];
|
|
820
|
+
// }
|
|
821
|
+
// const maps = (sm as any[]).slice().filter(m=>m.custom_style_name===sp[0]);
|
|
822
|
+
const maps = sm.slice().filter(m => style_string.startsWith(m.custom_style_name));
|
|
823
|
+
if (maps.length === 0) {
|
|
824
|
+
return [];
|
|
825
|
+
}
|
|
826
|
+
return maps.slice().flatMap(sM => memoMatchStyles(sM, style_string)).filter(a => a !== null);
|
|
827
|
+
// Object.entries(cf).map(([key, value])=>{
|
|
828
|
+
// if(style_string.startsWith(key)){
|
|
829
|
+
// if(sp.length > 1){
|
|
830
|
+
// return {custom_style_name: sp[0], attr: Object.keys(value as any)}
|
|
831
|
+
// }
|
|
832
|
+
// }
|
|
833
|
+
// return
|
|
834
|
+
// })
|
|
835
|
+
// return sm.slice().flatMap(sM=>{
|
|
836
|
+
// if(!style_string.startsWith(sM.custom_style_name)){
|
|
837
|
+
// return null
|
|
838
|
+
// }else{
|
|
839
|
+
// return memoMatchStyles(sM, style_string, _config)
|
|
840
|
+
// }
|
|
841
|
+
// }).filter(a=>a!==null);
|
|
842
|
+
}
|
|
843
|
+
return [];
|
|
844
|
+
};
|
|
845
|
+
const extractExactBrackets = (_str, pref = '', symbol = '[') => {
|
|
846
|
+
let str = _str;
|
|
847
|
+
const startSymbol = symbol;
|
|
848
|
+
const endSymbol = symbol === '[' ? ']' : symbol === '(' ? ')' : symbol === '{' ? '}' : symbol === '<' ? '>' : null;
|
|
849
|
+
const rp = `${pref}${startSymbol}`;
|
|
850
|
+
if (startSymbol && endSymbol && str.startsWith(rp) && str.endsWith(`${endSymbol}`)) {
|
|
851
|
+
str = str.replace(rp, '');
|
|
852
|
+
str = str.slice(0, -1);
|
|
853
|
+
if (str.length > 0) {
|
|
854
|
+
return str;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
return null;
|
|
858
|
+
};
|
|
859
|
+
const splitByGroupOrPeer = (input) => {
|
|
860
|
+
const regex = /(?=(group-|peer-))/g;
|
|
861
|
+
const pseudoArr = SIBLINGS_PSEUDO.slice().flatMap(s => `${s}-`);
|
|
862
|
+
return input.split(regex).filter(g => !pseudoArr.some(arr => arr === g));
|
|
863
|
+
};
|
|
864
|
+
const SIBLING_SELECTORS = {
|
|
865
|
+
group: ' ',
|
|
866
|
+
peer: ' ~ ',
|
|
867
|
+
};
|
|
868
|
+
export const SIBLINGS_PSEUDO = [...objectKeys(Object.assign({}, SIBLING_SELECTORS))];
|
|
869
|
+
const parseOn = (input, modiferName = 'group') => {
|
|
870
|
+
let modifier = '';
|
|
871
|
+
let groupname = '';
|
|
872
|
+
let selector = '';
|
|
873
|
+
const replaceEnd = (txt, val, rp) => {
|
|
874
|
+
if (txt.endsWith(val)) {
|
|
875
|
+
return replaceString(txt, rp || val, false, '');
|
|
876
|
+
}
|
|
877
|
+
return txt;
|
|
878
|
+
};
|
|
879
|
+
const groups = [];
|
|
880
|
+
const modifiers = [];
|
|
881
|
+
const splittedSiblings = splitByGroupOrPeer(input);
|
|
882
|
+
splittedSiblings.forEach(gname => {
|
|
883
|
+
const text = gname.replace('on-', '');
|
|
884
|
+
const split = splitString(text, SLASH_REGEX) || [];
|
|
885
|
+
if (split.length > 0) {
|
|
886
|
+
const tiretSplit = splitString(split[0], TIRET_REGEX);
|
|
887
|
+
const grn = tiretSplit.flatMap((gn) => replaceEnd(gn, `:${modiferName}`)).flatMap(gn => replaceEnd(gn, ']:', ':'));
|
|
888
|
+
if (grn.length > 1) {
|
|
889
|
+
const n = grn.slice();
|
|
890
|
+
const first = n.shift();
|
|
891
|
+
modifiers.push(first);
|
|
892
|
+
const groupModifiers = [];
|
|
893
|
+
[n.join('-')].forEach(modif => {
|
|
894
|
+
modifier = modif;
|
|
895
|
+
const brModif = extractExactBrackets(modifier);
|
|
896
|
+
if (brModif) {
|
|
897
|
+
const dynamic = getDynamicSelector(modifier, false);
|
|
898
|
+
if (dynamic) {
|
|
899
|
+
modifier = dynamic.dynamicSelector;
|
|
900
|
+
if (selector.length === 0) {
|
|
901
|
+
if (dynamic.isAfter && dynamic.needSpace) {
|
|
902
|
+
// selector = `.${groupname}<&_${modifier.trim()}>`
|
|
903
|
+
groupModifiers.push(`<&_${modifier.trim()}>`);
|
|
904
|
+
}
|
|
905
|
+
else {
|
|
906
|
+
// selector = `.${groupname}{${modifier}}`
|
|
907
|
+
groupModifiers.push(`{${modifier}}`);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
else {
|
|
911
|
+
if (dynamic.isAfter && dynamic.needSpace) {
|
|
912
|
+
// selector += `<&_${modifier.trim()}>`
|
|
913
|
+
groupModifiers.push(`<&_${modifier.trim()}>`);
|
|
914
|
+
}
|
|
915
|
+
else {
|
|
916
|
+
// selector += `{${modifier}}`
|
|
917
|
+
groupModifiers.push(`{${modifier}}`);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
else {
|
|
922
|
+
modifier = brModif;
|
|
923
|
+
groupModifiers.push(`{${modifier}}`);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
else {
|
|
927
|
+
let { key, formatted } = memoFindKey(replaceString(modifier, ':', false, ''));
|
|
928
|
+
formatted = getStringBetweenTags(formatted, PARENTHESES_DYNAMIC_REGEX, true)[0] || replaceClassSelf(formatted);
|
|
929
|
+
if (formatted) {
|
|
930
|
+
modifier = `${formatted}`;
|
|
931
|
+
groupModifiers.push(`{${modifier}}`);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
groups.push({ key: first, value: `${split[1] ? `/${split[1]}` : ''}`, modifiers: groupModifiers });
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
const uniqModifiers = uniq(modifiers);
|
|
940
|
+
selector = uniqModifiers.flatMap(m => {
|
|
941
|
+
const gd = groups.slice().filter(g => g.key === m);
|
|
942
|
+
const values = uniq(gd.slice().flatMap(g => g.value));
|
|
943
|
+
let gname = values.flatMap(v => {
|
|
944
|
+
let val = m + replaceString(v, ':', false, '');
|
|
945
|
+
gd.forEach(g => {
|
|
946
|
+
if (g.value === v) {
|
|
947
|
+
// val += g.value + g.modifiers.join('')
|
|
948
|
+
val += g.modifiers.join('');
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
return val;
|
|
952
|
+
}).join(' ');
|
|
953
|
+
return `.${gname}${SIBLING_SELECTORS[m]}`;
|
|
954
|
+
}).join(':');
|
|
955
|
+
return { modifier, groupname, selector };
|
|
956
|
+
};
|
|
957
|
+
const getStringBetweenTags = (input, tag = TAG_DYNAMIC_REGEX, replaceSelf = false) => {
|
|
958
|
+
// Regular expression to match a string that starts with & and is between <>
|
|
959
|
+
let matches = [];
|
|
960
|
+
let match;
|
|
961
|
+
// Using a loop to find all matches
|
|
962
|
+
while ((match = tag.exec(input)) !== null) {
|
|
963
|
+
matches.push(replaceSelf ? replaceClassSelf(match[1]) : match[1]); // match[1] contains the group matched by (&[^>]+)
|
|
964
|
+
}
|
|
965
|
+
return matches;
|
|
966
|
+
};
|
|
967
|
+
export const getModifiersRegexString = (add_colon = false, colon_position = 'before') => {
|
|
968
|
+
const modifiersString = getJitProps().map(j => {
|
|
969
|
+
let value = j.match_tag ? j.match_tag : j.name;
|
|
970
|
+
if (add_colon) {
|
|
971
|
+
if (colon_position === 'after') {
|
|
972
|
+
value = `${value}:`;
|
|
973
|
+
}
|
|
974
|
+
else {
|
|
975
|
+
value = `:${value}`;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return value;
|
|
979
|
+
}).join('|');
|
|
980
|
+
return modifiersString;
|
|
981
|
+
};
|
|
982
|
+
export const getClassSchemeRegex = () => {
|
|
983
|
+
const shorthands = getShorthandsArray();
|
|
984
|
+
const modifiers = getModifiersRegexString(true, 'after');
|
|
985
|
+
return new RegExp(`^([!-]|)(${shorthands === null || shorthands === void 0 ? void 0 : shorthands.join('|')}|${modifiers})?.*`, 'g');
|
|
986
|
+
};
|
|
987
|
+
let hasGroup = false;
|
|
988
|
+
export const getNestedJitProps = (text) => {
|
|
989
|
+
const m = text;
|
|
990
|
+
let groupName;
|
|
991
|
+
let style_string = m;
|
|
992
|
+
const sp = splitString(m, COLON_REGEX).filter(s => !isUndefinedOrNull(s) && s.length > 0);
|
|
993
|
+
let r = {};
|
|
994
|
+
const parents = [];
|
|
995
|
+
if (sp.length === 1) {
|
|
996
|
+
return { style_string, parents };
|
|
997
|
+
}
|
|
998
|
+
style_string = sp.pop();
|
|
999
|
+
const gp = [];
|
|
1000
|
+
const not_modifiers = [];
|
|
1001
|
+
const normal_modifiers = [];
|
|
1002
|
+
const reg = new RegExp(`^(${getModifiersRegexString()})`, 'g');
|
|
1003
|
+
for (const s of sp) {
|
|
1004
|
+
if (s.startsWith('group') || s.startsWith('peer')) {
|
|
1005
|
+
gp.push(s);
|
|
1006
|
+
hasGroup = true;
|
|
1007
|
+
}
|
|
1008
|
+
else {
|
|
1009
|
+
if (s.match(reg)) {
|
|
1010
|
+
normal_modifiers.push(s);
|
|
1011
|
+
}
|
|
1012
|
+
else {
|
|
1013
|
+
not_modifiers.push(s);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
if (not_modifiers.length > 0) {
|
|
1018
|
+
style_string = `${not_modifiers.join(':')}:${style_string}`;
|
|
1019
|
+
}
|
|
1020
|
+
if (gp.length > 0) {
|
|
1021
|
+
const extract = extractGroup(`${gp.join(':')}`);
|
|
1022
|
+
groupName = extract.selector;
|
|
1023
|
+
parents.push(groupName);
|
|
1024
|
+
r = { [groupName]: {} };
|
|
1025
|
+
}
|
|
1026
|
+
const modifFirst = normal_modifiers.shift();
|
|
1027
|
+
if (modifFirst) {
|
|
1028
|
+
const gpkey = `${modifFirst.startsWith('[') ? '' : ':'}${modifFirst}`;
|
|
1029
|
+
if (groupName) {
|
|
1030
|
+
parents.push(gpkey);
|
|
1031
|
+
r[groupName] = { [gpkey]: {} };
|
|
1032
|
+
}
|
|
1033
|
+
else {
|
|
1034
|
+
r = { [gpkey]: {} };
|
|
1035
|
+
parents.push(gpkey);
|
|
1036
|
+
}
|
|
1037
|
+
normal_modifiers.forEach(m => {
|
|
1038
|
+
const key = `${m.startsWith('[') ? '' : ':'}${m}`;
|
|
1039
|
+
updateValueDeep(r, parents, { [`${key}`]: {} });
|
|
1040
|
+
parents.push(key);
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
return { object: r, parents, style_string };
|
|
1044
|
+
};
|
|
1045
|
+
export const _getDirectUtility = (s) => {
|
|
1046
|
+
if (!state.utilities || !state.utilities.utilitiesMap)
|
|
1047
|
+
return null;
|
|
1048
|
+
const utilities = state.utilities.utilitiesMap;
|
|
1049
|
+
const key = s.startsWith('.') ? s : `.${s}`;
|
|
1050
|
+
const find = utilities[key];
|
|
1051
|
+
if (find) {
|
|
1052
|
+
return find;
|
|
1053
|
+
}
|
|
1054
|
+
return null;
|
|
1055
|
+
};
|
|
1056
|
+
const _getDirectComponent = (s) => {
|
|
1057
|
+
if (!state.utilities || !state.utilities.components)
|
|
1058
|
+
return null;
|
|
1059
|
+
const components = state.utilities.components;
|
|
1060
|
+
const key = s.startsWith('.') ? s : `.${s}`;
|
|
1061
|
+
const find = components[key];
|
|
1062
|
+
if (find) {
|
|
1063
|
+
return find;
|
|
1064
|
+
}
|
|
1065
|
+
return null;
|
|
1066
|
+
};
|
|
1067
|
+
const directMemoize = memoizeFn(matchDirectClass);
|
|
1068
|
+
const memoFilter = memoizeFn(filterStyles);
|
|
1069
|
+
const nestedJitMemo = memoizeFn(getNestedJitProps);
|
|
1070
|
+
const getDirectUtility = memoizeFn(_getDirectUtility);
|
|
1071
|
+
const getDirectComponent = memoizeFn(_getDirectComponent);
|
|
1072
|
+
const getStylesMap = (s, k, element, _config) => {
|
|
1073
|
+
// cons
|
|
1074
|
+
let m = s;
|
|
1075
|
+
let isImportant = false;
|
|
1076
|
+
let isNegative = false;
|
|
1077
|
+
const component = getDirectComponent(m);
|
|
1078
|
+
if (component) {
|
|
1079
|
+
return { style: { value: component }, parents: [] };
|
|
1080
|
+
}
|
|
1081
|
+
let findShort = directMemoize(s);
|
|
1082
|
+
if (findShort !== null) {
|
|
1083
|
+
return { style: { ['main']: findShort.obj }, parents: [] };
|
|
1084
|
+
}
|
|
1085
|
+
const { style_string: _style_string, object, parents } = nestedJitMemo(m, getJitProps());
|
|
1086
|
+
let style_string = _style_string;
|
|
1087
|
+
if (style_string.startsWith('!')) {
|
|
1088
|
+
const imp = isImportantFn(style_string);
|
|
1089
|
+
if (imp) {
|
|
1090
|
+
isImportant = true;
|
|
1091
|
+
style_string = imp.str;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
if (style_string.startsWith('-')) {
|
|
1095
|
+
isNegative = true;
|
|
1096
|
+
style_string = style_string.slice(1);
|
|
1097
|
+
}
|
|
1098
|
+
findShort = directMemoize(style_string);
|
|
1099
|
+
let _data;
|
|
1100
|
+
if (findShort) {
|
|
1101
|
+
if (object && parents.length > 0) {
|
|
1102
|
+
_data = Object.assign({}, object);
|
|
1103
|
+
updateValueDeep(_data, parents, findShort.obj);
|
|
1104
|
+
}
|
|
1105
|
+
else {
|
|
1106
|
+
_data = { ['']: findShort.obj };
|
|
1107
|
+
}
|
|
1108
|
+
return { style: _data, parents, isNegative, isImportant };
|
|
1109
|
+
}
|
|
1110
|
+
let map = memoFilter(style_string, null, element, _config);
|
|
1111
|
+
ONLY_ONE_HINT = {};
|
|
1112
|
+
const mp = map.flatMap((m_) => m_ === null || m_ === void 0 ? void 0 : m_.obj).slice();
|
|
1113
|
+
if (map.length > 0) {
|
|
1114
|
+
const _value = arrayToObject(mp);
|
|
1115
|
+
if (_value && Object.keys(_value).length > 0) {
|
|
1116
|
+
if (object && parents.length > 0) {
|
|
1117
|
+
_data = Object.assign({}, object);
|
|
1118
|
+
updateValueDeep(_data, parents, _value);
|
|
1119
|
+
}
|
|
1120
|
+
else {
|
|
1121
|
+
_data = { ['']: _value };
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
return { style: _data, parents, isNegative, isImportant };
|
|
1126
|
+
};
|
|
1127
|
+
const _rgbaColors = [{ name: 'currentColor', hex: 'currentColor', rgba: 'currentColor' }];
|
|
1128
|
+
const getExtractedRgbaColors = () => _rgbaColors.slice();
|
|
1129
|
+
export const extractRgbaColor = (_r, _g, _b, _a = 1, propertyData, _colors = undefined) => {
|
|
1130
|
+
let r = _r;
|
|
1131
|
+
let g = _g;
|
|
1132
|
+
let b = _b;
|
|
1133
|
+
let a = _a;
|
|
1134
|
+
const name = _r;
|
|
1135
|
+
const findOnExtracted = getExtractedRgbaColors().find(c => c === r && !g);
|
|
1136
|
+
if (findOnExtracted) {
|
|
1137
|
+
return findOnExtracted;
|
|
1138
|
+
}
|
|
1139
|
+
if (r.toString().startsWith('var')) {
|
|
1140
|
+
return null;
|
|
1141
|
+
}
|
|
1142
|
+
const mr = getThemeMergedStyles();
|
|
1143
|
+
let val;
|
|
1144
|
+
let colors = _colors;
|
|
1145
|
+
const color_path = [];
|
|
1146
|
+
if (propertyData) {
|
|
1147
|
+
const propertyMapArray = [propertyData.parent, propertyData.property, "values", ...[...splitString(r, TIRET_REGEX) || []]];
|
|
1148
|
+
if (!colors) {
|
|
1149
|
+
const color = getValueDeep(mr, propertyMapArray);
|
|
1150
|
+
if (color !== undefined && color !== null) {
|
|
1151
|
+
color_path.push(...propertyMapArray);
|
|
1152
|
+
if (checkType(color).is_object && color['DEFAULT']) {
|
|
1153
|
+
r = color['DEFAULT'];
|
|
1154
|
+
color_path.push("DEFAULT");
|
|
1155
|
+
}
|
|
1156
|
+
else {
|
|
1157
|
+
r = color;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
if (colors) {
|
|
1163
|
+
if (typeof r === 'string') {
|
|
1164
|
+
const splited = splitString(r, TIRET_REGEX) || [];
|
|
1165
|
+
val = colors[r];
|
|
1166
|
+
if (!val) {
|
|
1167
|
+
if (colors[toCamelCase(splited.join('-'))]) {
|
|
1168
|
+
val = colors[toCamelCase(splited.join('-'))];
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
if (checkType(val).is_object) {
|
|
1172
|
+
if (val['500']) {
|
|
1173
|
+
val = val['500'];
|
|
1174
|
+
}
|
|
1175
|
+
else if (val[500]) {
|
|
1176
|
+
val = val[500];
|
|
1177
|
+
}
|
|
1178
|
+
else if (val['DEFAULT']) {
|
|
1179
|
+
val = val['DEFAULT'];
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
if (val) {
|
|
1183
|
+
r = val;
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
if (typeof r === 'string' && (r.startsWith('var(') || r.startsWith('rgb(var(') || r.startsWith('rgba(var(') || r.startsWith('hsl(') || r.startsWith('oklch('))) {
|
|
1188
|
+
return r;
|
|
1189
|
+
}
|
|
1190
|
+
const clr = Color.fromString(r);
|
|
1191
|
+
if (clr && clr.rgb) {
|
|
1192
|
+
r = clr.rgb[0];
|
|
1193
|
+
g = clr.rgb[1];
|
|
1194
|
+
b = clr.rgb[2];
|
|
1195
|
+
a = clr.rgb[3];
|
|
1196
|
+
}
|
|
1197
|
+
if (!g || !b) {
|
|
1198
|
+
return null;
|
|
1199
|
+
}
|
|
1200
|
+
const formatted = formatRgba(r, g, b, a);
|
|
1201
|
+
let hex;
|
|
1202
|
+
if (isInt(a)) {
|
|
1203
|
+
hex = Color.rgbToHex(parseInt(r.toString()), parseInt(g.toString()), parseInt(b.toString()), toAlphaNumber(a));
|
|
1204
|
+
}
|
|
1205
|
+
const result = { name, r: r.toString().trim(), g: g.toString().trim(), b: b.toString().trim(), a: a.toString().trim(), rgb: formatted, hex: hex };
|
|
1206
|
+
if (!getExtractedRgbaColors().find(n => n.r === r.toString() && n.g === g.toString() && n.b === b.toString() && n.a === a.toString() && name === n.name)) {
|
|
1207
|
+
_rgbaColors.push(result);
|
|
1208
|
+
}
|
|
1209
|
+
return result;
|
|
1210
|
+
};
|
|
1211
|
+
export const extractRgbaMemo = memoizeFn(extractRgbaColor);
|
|
1212
|
+
const opacify = (color, opacity) => {
|
|
1213
|
+
// if(color.startsWith('var(')
|
|
1214
|
+
// || color.startsWith('rgb(var(')
|
|
1215
|
+
// || color.startsWith('rgba(var(')
|
|
1216
|
+
// || color.startsWith('hsl(')
|
|
1217
|
+
// || color.startsWith('oklch(')){
|
|
1218
|
+
// const clr = Color.addOpacity(color, opacity)
|
|
1219
|
+
// return `[${clr}]`
|
|
1220
|
+
// }else{
|
|
1221
|
+
// const c = Color.mixInInOklab({color, opacity})
|
|
1222
|
+
// if(c){
|
|
1223
|
+
// return `[${c}]`
|
|
1224
|
+
// }
|
|
1225
|
+
// }
|
|
1226
|
+
const c = Color.mixInInOklab({ color, opacity });
|
|
1227
|
+
return `[${c}]`;
|
|
1228
|
+
// if(c){
|
|
1229
|
+
// }
|
|
1230
|
+
// return null;
|
|
1231
|
+
};
|
|
1232
|
+
const processStyleValue = (style_string, parent, property) => {
|
|
1233
|
+
let style = style_string;
|
|
1234
|
+
const op = extractOpacity(style_string);
|
|
1235
|
+
if (op.matched && op.replaced.length > 1) {
|
|
1236
|
+
style = op.replaced;
|
|
1237
|
+
const opacity = findOpacity(op.matched);
|
|
1238
|
+
const string_with_brackets = extractBracket().exec(style);
|
|
1239
|
+
if (string_with_brackets) {
|
|
1240
|
+
const color = Color.mixInInOklab({ color: string_with_brackets[1], opacity });
|
|
1241
|
+
return `[${color}]`;
|
|
1242
|
+
}
|
|
1243
|
+
else {
|
|
1244
|
+
try {
|
|
1245
|
+
// const clr = opacify(op.replaced, opacity)
|
|
1246
|
+
// if(clr){
|
|
1247
|
+
// return clr;
|
|
1248
|
+
// }
|
|
1249
|
+
const rgba = extractRgbaMemo(op.replaced, undefined, undefined, undefined, { parent, property });
|
|
1250
|
+
if (rgba) {
|
|
1251
|
+
const clr = opacify(typeof rgba === 'string' ? rgba : varify(rgba.name, true), opacity);
|
|
1252
|
+
return clr;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
catch (err) {
|
|
1256
|
+
console.error(`[Fluixi css ❌]`, err);
|
|
1257
|
+
return undefined;
|
|
1258
|
+
}
|
|
1259
|
+
// return `${unescapeString(op.replaced)}~~${op.matched}`;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
else if (extractBracket().exec(style)) {
|
|
1263
|
+
const string_with_brackets = extractBracket().exec(style);
|
|
1264
|
+
if (string_with_brackets) {
|
|
1265
|
+
return `[${string_with_brackets[1]}]`;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
return undefined;
|
|
1269
|
+
};
|
|
1270
|
+
let ONLY_ONE_HINT = {};
|
|
1271
|
+
let matchRegex = false;
|
|
1272
|
+
const getMix = (str = '') => {
|
|
1273
|
+
if (str.includes('mix')) {
|
|
1274
|
+
const ex = extractParentheses("(.*?)").exec(str);
|
|
1275
|
+
if (ex && ex.length === 3) {
|
|
1276
|
+
const value = ex[2].split(',').map(v => v.trim());
|
|
1277
|
+
if (value.length >= 2) {
|
|
1278
|
+
let op = {};
|
|
1279
|
+
op.color = value[0];
|
|
1280
|
+
op.with = value[1];
|
|
1281
|
+
op.withOpacity = value[2];
|
|
1282
|
+
return Object.assign({}, op);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
return null;
|
|
1287
|
+
};
|
|
1288
|
+
const checkDynamicStyleValue = (style_string, s) => {
|
|
1289
|
+
const value = [];
|
|
1290
|
+
let dataStyle = style_string;
|
|
1291
|
+
const op = extractOpacity(dataStyle);
|
|
1292
|
+
// let matchedOpacity: any;
|
|
1293
|
+
let mixed;
|
|
1294
|
+
if (op.matched) {
|
|
1295
|
+
dataStyle = op.replaced;
|
|
1296
|
+
const opacity = findOpacity(op.matched);
|
|
1297
|
+
if (opacity) {
|
|
1298
|
+
mixed = { opacity };
|
|
1299
|
+
}
|
|
1300
|
+
// matchedOpacity = op.matched
|
|
1301
|
+
}
|
|
1302
|
+
const b = extractBracket().exec(dataStyle);
|
|
1303
|
+
if (b !== null && dataStyle.replace(`-${b[0]}`, '') === s.custom_style_name) {
|
|
1304
|
+
let testValue = b[1];
|
|
1305
|
+
const splitted = testValue.split(':');
|
|
1306
|
+
let hintProperties = [];
|
|
1307
|
+
let hintText;
|
|
1308
|
+
if (splitted.length == 2) {
|
|
1309
|
+
hintText = splitted.shift();
|
|
1310
|
+
hintProperties = HINTS[hintText] || [];
|
|
1311
|
+
if (hintProperties.length > 0) {
|
|
1312
|
+
const checkMix = getMix(testValue);
|
|
1313
|
+
if (checkMix) {
|
|
1314
|
+
testValue = checkMix.color;
|
|
1315
|
+
if (!mixed) {
|
|
1316
|
+
mixed = {};
|
|
1317
|
+
}
|
|
1318
|
+
mixed = Object.assign(Object.assign({}, mixed), checkMix);
|
|
1319
|
+
}
|
|
1320
|
+
else {
|
|
1321
|
+
testValue = splitted.join(':');
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
else {
|
|
1326
|
+
const checkMix = getMix(testValue);
|
|
1327
|
+
if (checkMix) {
|
|
1328
|
+
testValue = checkMix.color;
|
|
1329
|
+
if (!mixed) {
|
|
1330
|
+
mixed = {};
|
|
1331
|
+
}
|
|
1332
|
+
mixed = Object.assign(Object.assign({}, mixed), checkMix);
|
|
1333
|
+
hintProperties = HINTS.color;
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
const value_intermediate = [];
|
|
1337
|
+
const data_hints = Object.assign({}, HINTS);
|
|
1338
|
+
let attr = s.attr.slice();
|
|
1339
|
+
const hints = [];
|
|
1340
|
+
Object.keys(data_hints).forEach(h => {
|
|
1341
|
+
const attributes = data_hints[h].filter(a => s.attr.some(at => at === a));
|
|
1342
|
+
if (attributes.length > 0) {
|
|
1343
|
+
const n = attr.filter(a => !attributes.includes(a));
|
|
1344
|
+
if (n.length > 0) {
|
|
1345
|
+
attr = n.slice();
|
|
1346
|
+
}
|
|
1347
|
+
hints.push(h);
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
if (hintProperties.length === 0) {
|
|
1351
|
+
s.attr.forEach(at => {
|
|
1352
|
+
const stylePatterns = StylePatternsFlattened;
|
|
1353
|
+
if (stylePatterns[at]) {
|
|
1354
|
+
const matched = stylePatterns[at].map(__at => {
|
|
1355
|
+
let _at = __at;
|
|
1356
|
+
if (_at.endsWith('i')) {
|
|
1357
|
+
_at = _at.slice(0, -1);
|
|
1358
|
+
return { match: new RegExp(_at, 'i').exec(testValue), property: at };
|
|
1359
|
+
}
|
|
1360
|
+
return { match: new RegExp(_at).exec(testValue), property: at };
|
|
1361
|
+
}).filter(match => match.match);
|
|
1362
|
+
if (matched.length > 0) {
|
|
1363
|
+
matchRegex = true;
|
|
1364
|
+
const newValue = `[${testValue.replace(/_/g, ' ')}]`;
|
|
1365
|
+
if (mixed) {
|
|
1366
|
+
const color = Color.mixInInOklab(Object.assign(Object.assign({}, mixed), { color: testValue.replace(/_/g, ' ') }));
|
|
1367
|
+
if (color) {
|
|
1368
|
+
value_intermediate.push({ s, value: `[${color}]`, attr: at });
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
else {
|
|
1372
|
+
value_intermediate.push({ s, value: newValue, attr: at });
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
if (!matchRegex) {
|
|
1379
|
+
if (hintProperties.length > 0) {
|
|
1380
|
+
if (value_intermediate.length === 0) {
|
|
1381
|
+
const newValue = `[${testValue.replace(/_/g, ' ')}]`;
|
|
1382
|
+
let default_hint = hints.find(h => h === 'color') || hints.find(h => h === 'weight') || hints.find(h => h === 'length');
|
|
1383
|
+
if (!default_hint) {
|
|
1384
|
+
if (DEFAULT_HINTS[s.custom_style_name]) {
|
|
1385
|
+
default_hint = DEFAULT_HINTS[s.custom_style_name];
|
|
1386
|
+
}
|
|
1387
|
+
else {
|
|
1388
|
+
default_hint = hints[0];
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
let attrs;
|
|
1392
|
+
let hv = [];
|
|
1393
|
+
if (default_hint) {
|
|
1394
|
+
hv = Object.assign({}, HINTS)[default_hint];
|
|
1395
|
+
}
|
|
1396
|
+
if (!hv || !default_hint) {
|
|
1397
|
+
hv = hintProperties;
|
|
1398
|
+
}
|
|
1399
|
+
const _attrs = hv.find(a => attr.some(at => at === a));
|
|
1400
|
+
if (_attrs) {
|
|
1401
|
+
attrs = _attrs;
|
|
1402
|
+
}
|
|
1403
|
+
else {
|
|
1404
|
+
attrs = hintProperties[0];
|
|
1405
|
+
}
|
|
1406
|
+
if (!ONLY_ONE_HINT[`${s.custom_style_name}-${style_string}`]) {
|
|
1407
|
+
ONLY_ONE_HINT[`${s.custom_style_name}-${style_string}`] = true;
|
|
1408
|
+
if (mixed) {
|
|
1409
|
+
const color = Color.mixInInOklab(Object.assign(Object.assign({}, mixed), { color: testValue.replace(/_/g, ' ') }));
|
|
1410
|
+
if (color) {
|
|
1411
|
+
value.push({ s, value: `[${color}]`, attr: attrs });
|
|
1412
|
+
}
|
|
1413
|
+
else {
|
|
1414
|
+
value.push({ s, value: newValue, attr: attrs });
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
else {
|
|
1418
|
+
value.push({ s, value: newValue, attr: attrs });
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
else {
|
|
1423
|
+
const filtered = value_intermediate.filter(v => {
|
|
1424
|
+
if (hintProperties.some(h => h === v.attr)) {
|
|
1425
|
+
return true;
|
|
1426
|
+
}
|
|
1427
|
+
return false;
|
|
1428
|
+
});
|
|
1429
|
+
value.push(...filtered);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
else {
|
|
1433
|
+
if (hints.length > 0) {
|
|
1434
|
+
let default_hint = hints.find(h => h === 'color') || hints.find(h => h === 'weight') || hints.find(h => h === 'length');
|
|
1435
|
+
if (!default_hint) {
|
|
1436
|
+
if (DEFAULT_HINTS[s.custom_style_name]) {
|
|
1437
|
+
default_hint = DEFAULT_HINTS[s.custom_style_name];
|
|
1438
|
+
}
|
|
1439
|
+
else {
|
|
1440
|
+
default_hint = hints[0];
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
const attrs = Object.assign({}, HINTS)[default_hint].filter(a => s.attr.some(at => at === a));
|
|
1444
|
+
if (attrs.length > 0) {
|
|
1445
|
+
const dataValue = value_intermediate.filter(v => attrs.some(a => a === v.attr));
|
|
1446
|
+
if (dataValue.length > 0) {
|
|
1447
|
+
if (!ONLY_ONE_HINT[`${s.custom_style_name}-${style_string}`]) {
|
|
1448
|
+
ONLY_ONE_HINT[`${s.custom_style_name}-${style_string}`] = true;
|
|
1449
|
+
value.push(dataValue[0]);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
else {
|
|
1454
|
+
if (value_intermediate.length > 0) {
|
|
1455
|
+
if (!ONLY_ONE_HINT[`${s.custom_style_name}-${style_string}`]) {
|
|
1456
|
+
ONLY_ONE_HINT[`${s.custom_style_name}-${style_string}`] = true;
|
|
1457
|
+
value.push(value_intermediate[0]);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
else {
|
|
1463
|
+
value.push(...value_intermediate);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
else {
|
|
1468
|
+
if (!ONLY_ONE_HINT[`${s.custom_style_name}-${style_string}`]) {
|
|
1469
|
+
ONLY_ONE_HINT[`${s.custom_style_name}-${style_string}`] = true;
|
|
1470
|
+
value.push(...value_intermediate);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
else {
|
|
1475
|
+
s.attr.forEach(at => {
|
|
1476
|
+
if (!op.matched && (findWithShorthands(`${dataStyle}`) || findWithShorthands(`${s.custom_style_name}-${dataStyle}`))) {
|
|
1477
|
+
value.push({ s, value: `${style_string}`, attr: at });
|
|
1478
|
+
}
|
|
1479
|
+
else if (op.matched && findWithShorthands(`${op.replaced}`)) {
|
|
1480
|
+
value.push({ s, value: `${style_string}`, attr: at });
|
|
1481
|
+
}
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
return value;
|
|
1485
|
+
};
|
|
1486
|
+
export const extractOpacity = (str) => {
|
|
1487
|
+
const regex = /\/([^/)]+)(?=\s|$)/g;
|
|
1488
|
+
if (typeof str === 'string') {
|
|
1489
|
+
const strMatch = str.match(regex);
|
|
1490
|
+
if (strMatch) {
|
|
1491
|
+
const matched = strMatch[0];
|
|
1492
|
+
let v = str.replace(regex, '');
|
|
1493
|
+
return { replaced: v, matched: matched.slice(1) };
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
return { replaced: str, matched: null };
|
|
1497
|
+
};
|
|
1498
|
+
const getColor = (str, opacity) => {
|
|
1499
|
+
const rgba = extractRgbaMemo(str);
|
|
1500
|
+
let result = str;
|
|
1501
|
+
if (rgba) {
|
|
1502
|
+
const clr = formatRgba(rgba.r, rgba.g, rgba.b, opacity || rgba.a);
|
|
1503
|
+
result = clr;
|
|
1504
|
+
}
|
|
1505
|
+
return result;
|
|
1506
|
+
};
|
|
1507
|
+
export const getNestedValue = (val) => {
|
|
1508
|
+
var _c;
|
|
1509
|
+
const utilities = state.utilities ? (_c = state.utilities) === null || _c === void 0 ? void 0 : _c.values : null;
|
|
1510
|
+
if (!utilities) {
|
|
1511
|
+
return val;
|
|
1512
|
+
}
|
|
1513
|
+
if (val.startsWith("'") || val.startsWith('"')) {
|
|
1514
|
+
const m = val.match(/(?<=['"])(?:[^'"\s]+(?:[^'"])*.)(?=['"])/g);
|
|
1515
|
+
if (m) {
|
|
1516
|
+
val = m[0];
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
let str = val;
|
|
1520
|
+
const op = extractOpacity(val);
|
|
1521
|
+
let opacity;
|
|
1522
|
+
if (op && op.matched) {
|
|
1523
|
+
str = op.replaced;
|
|
1524
|
+
opacity = findOpacity(op.matched);
|
|
1525
|
+
}
|
|
1526
|
+
let arr = str.split('.');
|
|
1527
|
+
const dataValue = getValueDeep(utilities, arr);
|
|
1528
|
+
if (dataValue) {
|
|
1529
|
+
let result;
|
|
1530
|
+
if (checkType(dataValue).is_object) {
|
|
1531
|
+
if (dataValue.DEFAULT) {
|
|
1532
|
+
if (!opacity) {
|
|
1533
|
+
return dataValue.DEFAULT;
|
|
1534
|
+
}
|
|
1535
|
+
else {
|
|
1536
|
+
return getColor(dataValue.DEFAULT, opacity);
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
else {
|
|
1540
|
+
for (const k in dataValue) {
|
|
1541
|
+
if (dataValue.hasOwnProperty(k)) {
|
|
1542
|
+
if (arr.some(_key => _key === k)) {
|
|
1543
|
+
if (!opacity) {
|
|
1544
|
+
return dataValue[k];
|
|
1545
|
+
}
|
|
1546
|
+
else {
|
|
1547
|
+
return getColor(dataValue[k], opacity);
|
|
1548
|
+
}
|
|
1549
|
+
// break;
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
if (!result) {
|
|
1554
|
+
console.log('cannot output dataValue because format is object', dataValue);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
else {
|
|
1559
|
+
if (!opacity) {
|
|
1560
|
+
return dataValue;
|
|
1561
|
+
}
|
|
1562
|
+
else {
|
|
1563
|
+
return getColor(dataValue, opacity);
|
|
1564
|
+
}
|
|
1565
|
+
// result = dataValue;
|
|
1566
|
+
}
|
|
1567
|
+
return '';
|
|
1568
|
+
}
|
|
1569
|
+
return '';
|
|
1570
|
+
};
|
|
1571
|
+
export const getThemeValue = (str, _utilities, debug = false) => {
|
|
1572
|
+
var _c;
|
|
1573
|
+
const utilities = _utilities || state.utilities ? (_c = state.utilities) === null || _c === void 0 ? void 0 : _c.values : null;
|
|
1574
|
+
if (!utilities) {
|
|
1575
|
+
return str;
|
|
1576
|
+
}
|
|
1577
|
+
// const opacity = extractOpacity(str).matched;
|
|
1578
|
+
const themeReg = /(theme)\(([^\(\)]*(?:\([^\(\)]*\))*)\)/;
|
|
1579
|
+
const value = str.replace(new RegExp(themeReg, 'g'), (_value) => {
|
|
1580
|
+
const theme_value = _value.match(themeReg);
|
|
1581
|
+
if (theme_value) {
|
|
1582
|
+
const val = theme_value[2] ? (theme_value[2].toString() || '') : '';
|
|
1583
|
+
const response = getNestedValue(val);
|
|
1584
|
+
return response;
|
|
1585
|
+
}
|
|
1586
|
+
return '';
|
|
1587
|
+
});
|
|
1588
|
+
return value;
|
|
1589
|
+
};
|
|
1590
|
+
export const parseTheme = (object, utilities, debug = false) => {
|
|
1591
|
+
let result = {};
|
|
1592
|
+
if (object && typeof object === 'object' && !Array.isArray(object)) {
|
|
1593
|
+
const obj = Object.assign({}, object);
|
|
1594
|
+
for (const key in obj) {
|
|
1595
|
+
if (obj.hasOwnProperty(key)) {
|
|
1596
|
+
if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
|
|
1597
|
+
result = Object.assign(Object.assign({}, result), { [key]: parseTheme(obj[key], utilities, debug) });
|
|
1598
|
+
}
|
|
1599
|
+
else {
|
|
1600
|
+
const value = getThemeValue(obj[key], utilities, debug);
|
|
1601
|
+
result = Object.assign(Object.assign({}, result), { [key]: value });
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
return result;
|
|
1607
|
+
};
|
|
1608
|
+
export const extractStyle = (s, style) => {
|
|
1609
|
+
const styles = checkDynamicStyleValue(style, s);
|
|
1610
|
+
return styles.slice().map(v => {
|
|
1611
|
+
if (v.s && v.value && v.attr) {
|
|
1612
|
+
return [v.attr, `${v.value}`];
|
|
1613
|
+
}
|
|
1614
|
+
return [];
|
|
1615
|
+
}).filter(a => a.length > 0);
|
|
1616
|
+
};
|
|
1617
|
+
export const escapeClasses = (_value) => {
|
|
1618
|
+
let value = _value;
|
|
1619
|
+
if (value.length === 0) {
|
|
1620
|
+
throw new TypeError('`CSS.escape` requires an argument.');
|
|
1621
|
+
}
|
|
1622
|
+
const base = getThemeBase();
|
|
1623
|
+
if (base && base[value]) {
|
|
1624
|
+
return value;
|
|
1625
|
+
}
|
|
1626
|
+
return escapeString(_value.toString());
|
|
1627
|
+
};
|
|
1628
|
+
const findWithShorthands = (input_value) => {
|
|
1629
|
+
const obj = getStyleMapObject();
|
|
1630
|
+
if (obj && obj[input_value]) {
|
|
1631
|
+
return obj[input_value];
|
|
1632
|
+
}
|
|
1633
|
+
return null;
|
|
1634
|
+
};
|
|
1635
|
+
const onSplitted = (value) => {
|
|
1636
|
+
if (typeof value === 'string') {
|
|
1637
|
+
let splitted = splitString(camelToKebab(value), TIRET_REGEX) || [];
|
|
1638
|
+
let last = splitted.pop();
|
|
1639
|
+
if (splitted.length > 1 && last) {
|
|
1640
|
+
return { last, joined: toCamelCase(splitted.join('-')) };
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
return { last: '', joined: '' };
|
|
1644
|
+
};
|
|
1645
|
+
export const findPropertyValue = (property_, propName, themeStyle) => {
|
|
1646
|
+
const stylesData = themeStyle ? themeStyle : getThemeMergedStyles(); //|| {...createMutable(UtilitiesData)}
|
|
1647
|
+
let property = toCamelCase(property_);
|
|
1648
|
+
return Object.keys(stylesData).flatMap(k => {
|
|
1649
|
+
const map = stylesData[k];
|
|
1650
|
+
const stylePropsName = Object.keys(map).flatMap(m => {
|
|
1651
|
+
let shorthandsObject = map[m].shorthands;
|
|
1652
|
+
let valuesObject = map[m].values;
|
|
1653
|
+
let st;
|
|
1654
|
+
const splitted = onSplitted(property_);
|
|
1655
|
+
if ((m === property_ || m === property) || (m === propName) || (m === splitted.joined && valuesObject[splitted.last])) {
|
|
1656
|
+
st = { values: valuesObject, shorthands: shorthandsObject };
|
|
1657
|
+
}
|
|
1658
|
+
else if (shorthandsObject) {
|
|
1659
|
+
if (Object.keys(shorthandsObject).find(s => s === property_ || s === property || s === propName || (s === splitted.joined && valuesObject[splitted.last])) || Object.values(shorthandsObject).flat().find(s => s === property)) {
|
|
1660
|
+
st = { values: valuesObject, shorthands: shorthandsObject };
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
return st;
|
|
1664
|
+
}).filter(a => !checkType(a).is_undefined);
|
|
1665
|
+
return stylePropsName.slice();
|
|
1666
|
+
});
|
|
1667
|
+
};
|
|
1668
|
+
export const createVar = (key, name, value, prefix = CMP_PREFIX) => {
|
|
1669
|
+
return { [key]: { name: `${varify(camelToKebab(name), false, prefix)}`, value } };
|
|
1670
|
+
};
|
|
1671
|
+
export const buildVar = (name, value, prefix = CMP_PREFIX) => {
|
|
1672
|
+
const var_name = `${varify(camelToKebab(name), false, prefix)}`;
|
|
1673
|
+
if (value.toString().startsWith('theme(')) {
|
|
1674
|
+
const _value = getThemeValue(value);
|
|
1675
|
+
return { name: var_name, value: `${var_name}: ${_value};` };
|
|
1676
|
+
}
|
|
1677
|
+
return { name: var_name, value: `${var_name}: ${value};` };
|
|
1678
|
+
};
|
|
1679
|
+
export const createVars = (values, omittedPrefix = [], prefix = CMP_PREFIX, prefixPath = [], options) => {
|
|
1680
|
+
const obj = Object.assign({}, values);
|
|
1681
|
+
let vars = '';
|
|
1682
|
+
let darkVars = '';
|
|
1683
|
+
let data_values = {};
|
|
1684
|
+
// const exepectedKeys = ['default', 'variants', 'values', 'light', 'dark'];
|
|
1685
|
+
for (const key in obj) {
|
|
1686
|
+
if (obj.hasOwnProperty(key)) {
|
|
1687
|
+
// const onexpectedKey = exepectedKeys.some(k=>k === key.toLowerCase());
|
|
1688
|
+
let value;
|
|
1689
|
+
if (options && options.matcher && options.matcher(obj[key], key) && options.transformer) {
|
|
1690
|
+
value = options.transformer(obj[key], key);
|
|
1691
|
+
}
|
|
1692
|
+
else {
|
|
1693
|
+
value = obj[key];
|
|
1694
|
+
}
|
|
1695
|
+
if (checkType(value).is_object) {
|
|
1696
|
+
const p = [...prefixPath];
|
|
1697
|
+
if (key !== 'variants' && key !== 'values' && key.toLowerCase() !== 'default' && !omittedPrefix.some(c => c === key)) {
|
|
1698
|
+
const k = (options === null || options === void 0 ? void 0 : options.transformKey) ? options.transformKey(obj[key], key) : key;
|
|
1699
|
+
if (k) {
|
|
1700
|
+
p.push(k);
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
const val = createVars(value, omittedPrefix, prefix, p, options);
|
|
1704
|
+
vars += val.vars;
|
|
1705
|
+
darkVars += val.darkVars;
|
|
1706
|
+
data_values = Object.assign(Object.assign({}, data_values), { [key]: val.data_values });
|
|
1707
|
+
}
|
|
1708
|
+
else {
|
|
1709
|
+
let pref = '';
|
|
1710
|
+
if (prefixPath.length > 0) {
|
|
1711
|
+
if (!omittedPrefix.some(c => c === key)) {
|
|
1712
|
+
pref = `${prefixPath.slice().filter(p => p !== 'light' && p !== 'dark').join('-')}-`;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
let _value = value;
|
|
1716
|
+
const isColor = Color.isValidColor(value);
|
|
1717
|
+
if (isColor) {
|
|
1718
|
+
const rgbaColor = extractRgbaMemo(value);
|
|
1719
|
+
let alpha = "1";
|
|
1720
|
+
if (rgbaColor) {
|
|
1721
|
+
alpha = rgbaColor.a;
|
|
1722
|
+
_value = formatRgba(rgbaColor.r, rgbaColor.g, rgbaColor.b, alpha);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
const isDark = (key === 'dark' || prefixPath.some(k => k === 'dark'));
|
|
1726
|
+
const k = (options === null || options === void 0 ? void 0 : options.transformKey) ? options.transformKey(obj[key], key) : key;
|
|
1727
|
+
const { name, value: val } = buildVar(`${pref}${(typeof k !== 'undefined' && k !== 'DEFAULT' && k !== 'light' && k !== 'dark') ? k : ''}`, _value, prefix);
|
|
1728
|
+
if (!isDark) {
|
|
1729
|
+
vars += val + '\n';
|
|
1730
|
+
}
|
|
1731
|
+
else {
|
|
1732
|
+
darkVars += val + '\n';
|
|
1733
|
+
}
|
|
1734
|
+
data_values = Object.assign(Object.assign({}, data_values), { [key]: `var(${name})` });
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
return { vars, darkVars, data_values };
|
|
1739
|
+
};
|
|
1740
|
+
export const _formatMediaQuery = (input) => {
|
|
1741
|
+
const screens = getThemeScreens();
|
|
1742
|
+
let query = {};
|
|
1743
|
+
if (screens) {
|
|
1744
|
+
if (checkType(input).is_string) {
|
|
1745
|
+
const brackets = extractBracket().exec(input);
|
|
1746
|
+
const keySplit = splitString(input, TIRET_REGEX) || [];
|
|
1747
|
+
if (!checkType(screens[input]).is_undefined) {
|
|
1748
|
+
if (checkType(screens[input]).is_object) {
|
|
1749
|
+
query = Object.assign(Object.assign({}, query), screens[input]);
|
|
1750
|
+
}
|
|
1751
|
+
else {
|
|
1752
|
+
query = Object.assign(Object.assign({}, query), { min: screens[input] });
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
else if (brackets && (replaceString(keySplit[0], ':', true) === 'min' || replaceString(keySplit[0], ':', true) === 'max') && brackets[1]) {
|
|
1756
|
+
query = { [keySplit[0]]: brackets[1] };
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
if (Object.keys(query).length > 0) {
|
|
1761
|
+
return createMediaQuery(query);
|
|
1762
|
+
}
|
|
1763
|
+
return null;
|
|
1764
|
+
};
|
|
1765
|
+
export const formatMediaQuery = memoizeFn(_formatMediaQuery);
|
|
1766
|
+
export const createMediaQuery = (queryObject, parent, direct = false) => {
|
|
1767
|
+
const mode = getMode();
|
|
1768
|
+
if (queryObject === 'light' || queryObject === 'dark') {
|
|
1769
|
+
if (mode[queryObject] === queryObject) {
|
|
1770
|
+
return `@media ${ThemesSelectors[queryObject].mediaQuery}`;
|
|
1771
|
+
}
|
|
1772
|
+
else {
|
|
1773
|
+
const selector = mode[queryObject];
|
|
1774
|
+
if (!direct) {
|
|
1775
|
+
if (selector.startsWith('.')) {
|
|
1776
|
+
if (!parent) {
|
|
1777
|
+
return `&media[${selector}_&]`;
|
|
1778
|
+
}
|
|
1779
|
+
else {
|
|
1780
|
+
return `${selector} ${parent}`;
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
else {
|
|
1784
|
+
if (parent === undefined || parent === null) {
|
|
1785
|
+
return `&media[&:where(${selector}, ${selector} *)]`;
|
|
1786
|
+
}
|
|
1787
|
+
else {
|
|
1788
|
+
return `${parent}:where(${selector}, ${selector} *)`;
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
else {
|
|
1793
|
+
return `${selector}`;
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
if (typeof queryObject === 'string') {
|
|
1798
|
+
return `@media min-width(${queryObject})`;
|
|
1799
|
+
}
|
|
1800
|
+
if (checkType(queryObject).is_object) {
|
|
1801
|
+
const raw = Object.assign({}, queryObject)['media'];
|
|
1802
|
+
const min = Object.assign({}, queryObject)['min'];
|
|
1803
|
+
const max = Object.assign({}, queryObject)['max'];
|
|
1804
|
+
if (checkType(raw).is_undefined || !checkType(raw).is_string || raw.length === 0) {
|
|
1805
|
+
let m = '@media';
|
|
1806
|
+
const hasMin = checkType(min).is_string && min.length > 0;
|
|
1807
|
+
const hasMax = checkType(max).is_string && max.length > 0;
|
|
1808
|
+
if (hasMin) {
|
|
1809
|
+
m += ` (min-width: ${min})`;
|
|
1810
|
+
}
|
|
1811
|
+
if (hasMax) {
|
|
1812
|
+
m += `${hasMin ? " and " : ''}(max-width: ${max})`;
|
|
1813
|
+
}
|
|
1814
|
+
if (m !== '@media') {
|
|
1815
|
+
return m;
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
return `@media ${raw}`;
|
|
1819
|
+
}
|
|
1820
|
+
return '';
|
|
1821
|
+
};
|
|
1822
|
+
const _replaceClassSelf = (str) => {
|
|
1823
|
+
if (Array.isArray(str)) {
|
|
1824
|
+
return str.map(s => _replaceClassSelf(s));
|
|
1825
|
+
}
|
|
1826
|
+
let r = '';
|
|
1827
|
+
let space = false;
|
|
1828
|
+
if (typeof str === 'string') {
|
|
1829
|
+
r = str.replace(/\\/g, '');
|
|
1830
|
+
space = startsWithSpace(r);
|
|
1831
|
+
if (space) {
|
|
1832
|
+
r = replaceString(r, ' ', true, '');
|
|
1833
|
+
}
|
|
1834
|
+
r = replaceString(r, '&', true, '');
|
|
1835
|
+
r = replaceString(r, '&', false, '');
|
|
1836
|
+
}
|
|
1837
|
+
return `${space ? ' ' : ''}${r}`;
|
|
1838
|
+
};
|
|
1839
|
+
const _replaceClassExtra = (str) => {
|
|
1840
|
+
let r = '';
|
|
1841
|
+
let space = false;
|
|
1842
|
+
if (typeof str === 'string') {
|
|
1843
|
+
r = replaceClassSelf(str.replace(/\\/g, ''));
|
|
1844
|
+
space = startsWithSpace(r);
|
|
1845
|
+
if (space) {
|
|
1846
|
+
r = replaceString(r, ' ', true, '');
|
|
1847
|
+
}
|
|
1848
|
+
r = replaceString(r, '.', true, '');
|
|
1849
|
+
r = replaceString(r, '::', true, '');
|
|
1850
|
+
r = replaceString(r, ':', true, '');
|
|
1851
|
+
}
|
|
1852
|
+
return `${space ? ' ' : ''}${r}`;
|
|
1853
|
+
};
|
|
1854
|
+
const replaceClassExtra = memoizeFn(_replaceClassExtra);
|
|
1855
|
+
const replaceClassSelf = memoizeFn(_replaceClassSelf);
|
|
1856
|
+
const _isPseudoSelector = (str, pseudo_selector) => {
|
|
1857
|
+
const _br = getBracketsValue(str);
|
|
1858
|
+
const isPseudo = (replaceClassExtra(str) === pseudo_selector.name) || (_br && _br.str === pseudo_selector.name)
|
|
1859
|
+
|| (!Array.isArray(pseudo_selector.selector) ?
|
|
1860
|
+
replaceClassSelf(pseudo_selector.selector) === replaceClassSelf(str)
|
|
1861
|
+
: replaceClassSelf(pseudo_selector.selector).some(c => c === replaceClassSelf(str)))
|
|
1862
|
+
|| (!Array.isArray(pseudo_selector.selector)
|
|
1863
|
+
? checkSelector(replaceClassSelf(pseudo_selector.selector)) === checkSelector(replaceClassSelf(str))
|
|
1864
|
+
: replaceClassSelf(pseudo_selector.selector).some(c => checkSelector(c) === replaceClassSelf(str)));
|
|
1865
|
+
return isPseudo;
|
|
1866
|
+
};
|
|
1867
|
+
const isPseudoSelector = memoizeFn(_isPseudoSelector);
|
|
1868
|
+
let foundedKeys = {};
|
|
1869
|
+
export const clearResources = () => {
|
|
1870
|
+
foundedKeys = {};
|
|
1871
|
+
};
|
|
1872
|
+
const _finKey = (_key) => {
|
|
1873
|
+
// Early return if result is cached
|
|
1874
|
+
const cached = foundedKeys[replaceClassSelf(_key)];
|
|
1875
|
+
if (cached)
|
|
1876
|
+
return Object.assign({}, cached);
|
|
1877
|
+
// Initialize result
|
|
1878
|
+
const result = {
|
|
1879
|
+
key: _key,
|
|
1880
|
+
formatted: '',
|
|
1881
|
+
isModifier: false
|
|
1882
|
+
};
|
|
1883
|
+
// Handle screens and themes first
|
|
1884
|
+
const screens = getThemeScreens();
|
|
1885
|
+
const themeKey = ['light', 'dark'].find(k => k === replaceClassExtra(_key));
|
|
1886
|
+
if (themeKey) {
|
|
1887
|
+
result.key = `${themeKey}:`;
|
|
1888
|
+
const media = createMediaQuery(themeKey);
|
|
1889
|
+
result.formatted = media;
|
|
1890
|
+
if (!media.startsWith('@media')) {
|
|
1891
|
+
result.key = result.formatted;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
// Handle screens
|
|
1895
|
+
else if (screens && (screens[_key] || screens[replaceClassExtra(_key)])) {
|
|
1896
|
+
const cleanKey = replaceClassExtra(_key);
|
|
1897
|
+
result.key = `${cleanKey.startsWith(':') ? '' : ':'}${cleanKey}`;
|
|
1898
|
+
result.formatted = checkType(screens[cleanKey]).is_object
|
|
1899
|
+
? createMediaQuery(screens[cleanKey])
|
|
1900
|
+
: screens[cleanKey];
|
|
1901
|
+
}
|
|
1902
|
+
// Handle brackets
|
|
1903
|
+
else if (_key.includes('[') && !isOperatorSelector(_key)) {
|
|
1904
|
+
if (_key.startsWith('aria-') || _key.startsWith('data-')) {
|
|
1905
|
+
result.formatted = handleDataAriaSelector(_key);
|
|
1906
|
+
}
|
|
1907
|
+
else {
|
|
1908
|
+
result.formatted = handleBracketSelector(_key);
|
|
1909
|
+
}
|
|
1910
|
+
result.key = `${_key.startsWith(':') ? '' : ':'}${_key}`;
|
|
1911
|
+
}
|
|
1912
|
+
// Handle pseudo and special selectors
|
|
1913
|
+
else {
|
|
1914
|
+
const { formatted, key, isModifier } = handleSpecialSelectors(_key);
|
|
1915
|
+
if (formatted) {
|
|
1916
|
+
result.formatted = formatted;
|
|
1917
|
+
result.key = key;
|
|
1918
|
+
result.isModifier = isModifier;
|
|
1919
|
+
}
|
|
1920
|
+
else {
|
|
1921
|
+
result.formatted = `{${_key}}`;
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
// Cache result
|
|
1925
|
+
foundedKeys[replaceClassSelf(_key)] = result;
|
|
1926
|
+
return result;
|
|
1927
|
+
};
|
|
1928
|
+
// Helper functions
|
|
1929
|
+
const isOperatorSelector = (key) => {
|
|
1930
|
+
const operators = ['has', 'not', 'is', 'where', 'nth\\-child'];
|
|
1931
|
+
return operators.some(op => key.startsWith(`${op}-[`) ||
|
|
1932
|
+
key.startsWith(`${op}(`) ||
|
|
1933
|
+
key.startsWith(`:${op}-[`) ||
|
|
1934
|
+
key.startsWith(`:${op}(`));
|
|
1935
|
+
};
|
|
1936
|
+
const handleBracketSelector = (key) => {
|
|
1937
|
+
const brackets = extractBracket().exec(key);
|
|
1938
|
+
if (!brackets)
|
|
1939
|
+
return `{${key}}`;
|
|
1940
|
+
const [prefix] = splitString(key, TIRET_REGEX) || [];
|
|
1941
|
+
const cleanPrefix = replaceString(prefix || '', ':', true);
|
|
1942
|
+
if (cleanPrefix === 'min' || cleanPrefix === 'max') {
|
|
1943
|
+
return createMediaQuery({ [cleanPrefix]: brackets[1] });
|
|
1944
|
+
}
|
|
1945
|
+
if (cleanPrefix === '&') {
|
|
1946
|
+
return brackets[1].startsWith('data-') ||
|
|
1947
|
+
brackets[1].startsWith('aria-') ||
|
|
1948
|
+
brackets[1].includes('=')
|
|
1949
|
+
? `{[${brackets[1]}]}`
|
|
1950
|
+
: `{${brackets[1]}}`;
|
|
1951
|
+
}
|
|
1952
|
+
const dynamicSelector = getDynamicSelector(key);
|
|
1953
|
+
return dynamicSelector
|
|
1954
|
+
? `{${dynamicSelector.dynamicSelector}}`
|
|
1955
|
+
: `{${key}}`;
|
|
1956
|
+
};
|
|
1957
|
+
const handleSpecialSelectors = (key) => {
|
|
1958
|
+
const NTH_CHILD_REGEX_STRING = "(([-+]?\\d*)?n([+-]\\d+)?|\\d+)";
|
|
1959
|
+
const NTH_REGEX = new RegExp(`^(nth\\-child|nth\\-of\\-type|nth\\-last\\-child|nth\\-last\\-of\\-type)\\(${NTH_CHILD_REGEX_STRING}\\)$`, 'g');
|
|
1960
|
+
const HNIWN_REGEX = new RegExp(`^(has|not|is|where)\\(.*\\)$`, 'g');
|
|
1961
|
+
if (key.startsWith('&:')) {
|
|
1962
|
+
return { formatted: `{${key}}`, key, isModifier: false };
|
|
1963
|
+
}
|
|
1964
|
+
if (!key.startsWith(':where(') && !key.startsWith(':has(') && !key.startsWith(':not(') && !key.startsWith(':is(') && !key.startsWith(':nth-child(') && !key.startsWith(':nth-of-type(') && !key.startsWith(':nth-last-child(') && !key.startsWith(':nth-last-of-type(')) {
|
|
1965
|
+
const pseudoProps = jitMemo().find(k => isPseudoSelector(key, k));
|
|
1966
|
+
if (pseudoProps) {
|
|
1967
|
+
return handlePseudoSelector(key, pseudoProps);
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
const nthMatch = NTH_REGEX.exec(replaceClassExtra(key));
|
|
1971
|
+
if (nthMatch) {
|
|
1972
|
+
return {
|
|
1973
|
+
formatted: `{:${nthMatch[0]}}`,
|
|
1974
|
+
key: nthMatch[0],
|
|
1975
|
+
isModifier: true
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
const hniwMatch = HNIWN_REGEX.exec(replaceClassExtra(key));
|
|
1979
|
+
if (hniwMatch) {
|
|
1980
|
+
return {
|
|
1981
|
+
formatted: `{:${hniwMatch[0]}}`,
|
|
1982
|
+
key: hniwMatch[0],
|
|
1983
|
+
isModifier: true
|
|
1984
|
+
};
|
|
1985
|
+
}
|
|
1986
|
+
return { formatted: '', key: '', isModifier: false };
|
|
1987
|
+
};
|
|
1988
|
+
const handleDataAriaSelector = (key) => {
|
|
1989
|
+
const attr = `${replaceClassExtra(key)}-`;
|
|
1990
|
+
const attrValue = replaceString(key, attr);
|
|
1991
|
+
const brackets = getBracketsValue(attrValue);
|
|
1992
|
+
if (brackets) {
|
|
1993
|
+
const prefixAria = brackets.content.startsWith('aria-') ? '' : 'aria-';
|
|
1994
|
+
const prefixData = brackets.content.startsWith('data-') ? '' : 'data-';
|
|
1995
|
+
const prefix = key.startsWith('aria-') ? prefixAria : prefixData;
|
|
1996
|
+
// Handle bracketed values
|
|
1997
|
+
if (brackets.content.includes('=')) {
|
|
1998
|
+
return `{[${prefix}${brackets.content}]}`;
|
|
1999
|
+
}
|
|
2000
|
+
const content = brackets.content.startsWith('!')
|
|
2001
|
+
? replaceString(brackets.content, '!', true)
|
|
2002
|
+
: `${prefix}${brackets.content}`;
|
|
2003
|
+
return `{[${content}]}`;
|
|
2004
|
+
}
|
|
2005
|
+
// Handle direct values
|
|
2006
|
+
return `{[${(attrValue.startsWith('data-') || attrValue.startsWith('aria-')) ? '' : attr}${attrValue}]}`;
|
|
2007
|
+
};
|
|
2008
|
+
const handleBracketPseudoSelector = (key, formatted) => {
|
|
2009
|
+
const brackets = getBracketsValue(key);
|
|
2010
|
+
if (!brackets)
|
|
2011
|
+
return formatted;
|
|
2012
|
+
if (key === '&:data' || key === '&:aria') {
|
|
2013
|
+
const attr = key === '&:data' ? 'data-' : 'aria-';
|
|
2014
|
+
const content = brackets.content.startsWith('!')
|
|
2015
|
+
? replaceString(brackets.content, '!', true)
|
|
2016
|
+
: `${brackets.content.startsWith(attr) ? '' : attr}${brackets.content}`;
|
|
2017
|
+
return `{[${content}]}`;
|
|
2018
|
+
}
|
|
2019
|
+
// Handle regular pseudo selectors with brackets
|
|
2020
|
+
const hasSeparator = brackets.content.includes('=');
|
|
2021
|
+
return hasSeparator
|
|
2022
|
+
? `${formatted}([${brackets.content}])`
|
|
2023
|
+
: `${formatted}(${brackets.content})`;
|
|
2024
|
+
};
|
|
2025
|
+
const handlePseudoSelector = (key, pseudoProps) => {
|
|
2026
|
+
let formatted = `${pseudoProps.selector}`;
|
|
2027
|
+
const isModifier = true;
|
|
2028
|
+
if (key === '&:data' || key === '&:aria') {
|
|
2029
|
+
formatted = handleDataAriaSelector(key);
|
|
2030
|
+
}
|
|
2031
|
+
if (key.includes('[') && key.includes(']')) {
|
|
2032
|
+
formatted = handleBracketPseudoSelector(key, formatted);
|
|
2033
|
+
}
|
|
2034
|
+
return {
|
|
2035
|
+
formatted: formatted.startsWith('{') ? formatted : `{${formatted}}`,
|
|
2036
|
+
key: pseudoProps.selector,
|
|
2037
|
+
isModifier
|
|
2038
|
+
};
|
|
2039
|
+
};
|
|
2040
|
+
const memoFindKey = memoizeFn(_finKey);
|
|
2041
|
+
const memoGetStyleSchemeRegex = memoizeFn(getStyleSchemeRegex);
|
|
2042
|
+
const memoMatchStyles = memoizeFn(matchStyles);
|
|
2043
|
+
const _getBracketsValue = (str) => {
|
|
2044
|
+
if (str.includes('[') && str.includes(']')) {
|
|
2045
|
+
const br = splitString(str, TIRET_REGEX) || [];
|
|
2046
|
+
if (br.length > 1 && (br[1].startsWith('[') && br[1].endsWith(']'))) {
|
|
2047
|
+
let rs = br[0];
|
|
2048
|
+
return { str: rs, bracket: br, content: (extractBracket().exec(br[1]) || [])[1] };
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
return null;
|
|
2052
|
+
};
|
|
2053
|
+
const getBracketsValue = memoizeFn(_getBracketsValue);
|
|
2054
|
+
const checkSelector = (str) => {
|
|
2055
|
+
if (Array.isArray(str)) {
|
|
2056
|
+
return str.slice().map(s => checkSelector(s));
|
|
2057
|
+
}
|
|
2058
|
+
const br = getBracketsValue(str);
|
|
2059
|
+
if (br) {
|
|
2060
|
+
return br.str;
|
|
2061
|
+
}
|
|
2062
|
+
return str;
|
|
2063
|
+
};
|
|
2064
|
+
function needsEscaping(className) {
|
|
2065
|
+
const regex = /^-?(?:[a-zA-Z_]|[^\x00-\x7F])[\w-]*$/;
|
|
2066
|
+
return !regex.test(className);
|
|
2067
|
+
}
|
|
2068
|
+
let whiteListPurge = [];
|
|
2069
|
+
export const formatClassName = (_classStrings, debug = false, from) => {
|
|
2070
|
+
if (!needsEscaping(replaceString(_classStrings, '.', true))) {
|
|
2071
|
+
return _classStrings;
|
|
2072
|
+
}
|
|
2073
|
+
let classStrings = _classStrings;
|
|
2074
|
+
const classesSpace = splitString(classStrings);
|
|
2075
|
+
const sibling_operators = ['*', '>', '~', '+', '.'];
|
|
2076
|
+
let result = '';
|
|
2077
|
+
// const classReg = /(([!*&]|\w)([.#\-\*\!\w\(\)\<\>\}\/\[\]:\+%]+)|((:|::)([\w\(\).\-*/].|\w)+(?=::|:|\{))|(([.~#])(?=[\w])+)|([\w-.&*~\(\):]+)|\[([^\[\]]*(?:\[[^\[\]]*\])*)\]|\{[^\}]+\})/g;
|
|
2078
|
+
// const classReg = /(([!*&\[\]]+|\w)([.#\-\*\!\w\(\)\<\>\}\/\[\]:\+%='"]+)|((:|::)([\w\(\).\-*/].|\w)+(?=::|:|\{))|(([.~#])(?=[\w])+)|([\w-.&*~\(\):='"]+)|\[([^\[\]]*(?:\[[^\[\]]*\])*)\]|\{[^\}]+\})/g;
|
|
2079
|
+
const classReg = /(([!*&\[\]]+|\w)([.#\-\*\!\w\(\)\<\>\}\/\[\]:\+%='"]+)|((:|::)([\w\(\).\-*/].|\w)+(?=::|:|\{))|(([.~#])(?=[\w\\])+)|([-.&*~\(\):='"]+)|\[([^\[\]]*(?:\[[^\[\]]*\])*)\]|\{[^\}]+\})/g;
|
|
2080
|
+
for (const _classString of classesSpace) {
|
|
2081
|
+
let r = '';
|
|
2082
|
+
let classStartsWithIdent = false;
|
|
2083
|
+
let stratsWithAll = false;
|
|
2084
|
+
let classString = _classString;
|
|
2085
|
+
let endsWithComma = false;
|
|
2086
|
+
classStartsWithIdent = startsWithSelectorIdentifier(classString);
|
|
2087
|
+
if (classStartsWithIdent) {
|
|
2088
|
+
classString = replaceString(classString, '.');
|
|
2089
|
+
}
|
|
2090
|
+
stratsWithAll = classString.startsWith('*:');
|
|
2091
|
+
if (stratsWithAll) {
|
|
2092
|
+
classString = replaceString(classString, '*:', true);
|
|
2093
|
+
}
|
|
2094
|
+
endsWithComma = classString.endsWith(',');
|
|
2095
|
+
if (endsWithComma) {
|
|
2096
|
+
classString = replaceString(classString, ',', false);
|
|
2097
|
+
}
|
|
2098
|
+
if (sibling_operators.some(so => so === classString)) {
|
|
2099
|
+
r = classString;
|
|
2100
|
+
}
|
|
2101
|
+
else {
|
|
2102
|
+
r = classString.replace(classReg, (p) => {
|
|
2103
|
+
let style = '';
|
|
2104
|
+
if ((p.startsWith('[') && p.endsWith(']')) || sibling_operators.some(so => so === p)) {
|
|
2105
|
+
const ct = extractBracket().exec(p) || [p, p];
|
|
2106
|
+
if (needsEscaping(ct[1])) {
|
|
2107
|
+
style += escapeClasses(p);
|
|
2108
|
+
}
|
|
2109
|
+
else {
|
|
2110
|
+
style += p;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
else if ((p.startsWith('{') && p.endsWith('}'))) {
|
|
2114
|
+
let v = p;
|
|
2115
|
+
v = replaceString(v, '{', true);
|
|
2116
|
+
v = replaceString(v, '}', false);
|
|
2117
|
+
style += replaceClassSelf(v);
|
|
2118
|
+
}
|
|
2119
|
+
else if (p.startsWith(':')) {
|
|
2120
|
+
let { key, formatted, isModifier } = memoFindKey(p);
|
|
2121
|
+
if (isModifier) {
|
|
2122
|
+
style += p;
|
|
2123
|
+
}
|
|
2124
|
+
else {
|
|
2125
|
+
style += escapeClasses(p);
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
else {
|
|
2129
|
+
style += escapeClasses(p);
|
|
2130
|
+
}
|
|
2131
|
+
return style;
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
result += `${result.length <= 1 ? '' : ' '}${classStartsWithIdent ? '.' : ''}${stratsWithAll ? '\\*\\:' : ''}${r}${endsWithComma ? ',' : ''}`;
|
|
2135
|
+
}
|
|
2136
|
+
// whiteListPurge.push(unescapeString(replaceString(result, '.', true)));
|
|
2137
|
+
return result;
|
|
2138
|
+
};
|
|
2139
|
+
const startsWithSelectorIdentifier = (str) => {
|
|
2140
|
+
return str.startsWith('.') || str.startsWith('#');
|
|
2141
|
+
};
|
|
2142
|
+
const replaceColor = (text, replaceValue) => {
|
|
2143
|
+
const reg = '(rgba|rgb|hsl)+\\(([^)]+)\\)';
|
|
2144
|
+
let hexPattern = '#([a-fA-F0-9]{8}|[a-fA-F0-9]{6}|[a-fA-F0-9]{3})\\b';
|
|
2145
|
+
return text.replace(new RegExp(`${reg}|${hexPattern}`, 'g'), () => {
|
|
2146
|
+
return replaceValue;
|
|
2147
|
+
});
|
|
2148
|
+
};
|
|
2149
|
+
const findPropertyFilter = (str) => {
|
|
2150
|
+
const filterFn = FilterPropertiesFn.find(fnName => str.endsWith(fnName));
|
|
2151
|
+
if (filterFn) {
|
|
2152
|
+
const filterProperty = FiltersPropertiesPrefix.find(filterProperty => filterProperty === str.replace(`-${filterFn}`, ''));
|
|
2153
|
+
if (filterProperty) {
|
|
2154
|
+
return { propertyName: filterProperty, propertyFn: filterFn };
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
return null;
|
|
2158
|
+
};
|
|
2159
|
+
const findPropertyTransform = (str) => {
|
|
2160
|
+
const filterFn = TransformPropertiesFn.find(fnName => str.endsWith(fnName));
|
|
2161
|
+
if (filterFn) {
|
|
2162
|
+
const filterProperty = TransformPropertiesPrefix.find(filterProperty => filterProperty === str.replace(`-${filterFn}`, '') || filterProperty === filterFn);
|
|
2163
|
+
if (filterProperty) {
|
|
2164
|
+
return { propertyName: filterProperty, propertyFn: filterFn };
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
return null;
|
|
2168
|
+
};
|
|
2169
|
+
const wrapFilterValue = (str, fnName) => {
|
|
2170
|
+
if (str.startsWith(fnName)) {
|
|
2171
|
+
return str;
|
|
2172
|
+
}
|
|
2173
|
+
if (str.startsWith('var')) {
|
|
2174
|
+
return str;
|
|
2175
|
+
}
|
|
2176
|
+
return `${fnName}(${str})`;
|
|
2177
|
+
};
|
|
2178
|
+
export const convertKeyframesToString = (value) => {
|
|
2179
|
+
const { keyframeRules, utilities } = value;
|
|
2180
|
+
// Output CSS
|
|
2181
|
+
const css = [
|
|
2182
|
+
'/* Keyframe Animations */',
|
|
2183
|
+
...keyframeRules,
|
|
2184
|
+
'',
|
|
2185
|
+
'/* Animation Utilities */',
|
|
2186
|
+
...Object.entries(utilities).map(([name, props]) => `\n${Object.entries(props).map(([p, v]) => ` ${p}: ${v};`).join('\n')}\n`
|
|
2187
|
+
// `.${name} {\n${Object.entries(props).map(([p, v]) => ` ${p}: ${v};`).join('\n')}\n}`
|
|
2188
|
+
)
|
|
2189
|
+
].join('\n');
|
|
2190
|
+
return css;
|
|
2191
|
+
};
|
|
2192
|
+
const convertToKeyframes = (name, keyFrames) => {
|
|
2193
|
+
let keyFramesString = `@keyframes ${name} {\n`;
|
|
2194
|
+
const processKey = (k) => {
|
|
2195
|
+
const commaSplit = k.split(',');
|
|
2196
|
+
const spaceSplit = k.split(' ');
|
|
2197
|
+
if (commaSplit.length > 1) {
|
|
2198
|
+
return commaSplit.flatMap(c => c.trim());
|
|
2199
|
+
}
|
|
2200
|
+
else if (spaceSplit.length > 1) {
|
|
2201
|
+
return spaceSplit.flatMap(c => c.trim());
|
|
2202
|
+
}
|
|
2203
|
+
return [k];
|
|
2204
|
+
};
|
|
2205
|
+
Object.keys(keyFrames).forEach(_key => {
|
|
2206
|
+
const keys = processKey(_key);
|
|
2207
|
+
keyFramesString += ` ${keys.join(', ')} {\n`;
|
|
2208
|
+
if (!checkType(keyFrames[_key]).is_object) {
|
|
2209
|
+
keyFramesString += ` ${keyFrames[_key]}`;
|
|
2210
|
+
}
|
|
2211
|
+
else {
|
|
2212
|
+
Object.keys(keyFrames[_key]).forEach(property => {
|
|
2213
|
+
keyFramesString += ` ${property}: ${keyFrames[_key][property]};\n`;
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
keyFramesString += ` }\n`;
|
|
2217
|
+
// keys.forEach(key=>{
|
|
2218
|
+
// })
|
|
2219
|
+
});
|
|
2220
|
+
keyFramesString += ` \n}\n`;
|
|
2221
|
+
return keyFramesString;
|
|
2222
|
+
};
|
|
2223
|
+
const toAlphaNumber = (value) => {
|
|
2224
|
+
if (typeof value === "number") {
|
|
2225
|
+
return value;
|
|
2226
|
+
}
|
|
2227
|
+
let v = value;
|
|
2228
|
+
if (v.includes('%')) {
|
|
2229
|
+
v = value.replace('%', '');
|
|
2230
|
+
}
|
|
2231
|
+
let r = parseFloat(v) / 100;
|
|
2232
|
+
return r;
|
|
2233
|
+
};
|
|
2234
|
+
let keyframeRules = [];
|
|
2235
|
+
const buildDirectStyle = (key, value, isNegative = false, isImportant = false) => {
|
|
2236
|
+
let brackets;
|
|
2237
|
+
if (typeof value === 'string') {
|
|
2238
|
+
brackets = extractBracket().exec(value);
|
|
2239
|
+
}
|
|
2240
|
+
const getDataValue = (_value, toHex = false, makeNegative = false, makeImportant = false) => {
|
|
2241
|
+
if (checkType(_value).is_string) {
|
|
2242
|
+
let rgba;
|
|
2243
|
+
if (GradientKeyMap[_value]) {
|
|
2244
|
+
return GradientKeyMap[_value];
|
|
2245
|
+
}
|
|
2246
|
+
const matchBracket = extractBracket().exec(_value);
|
|
2247
|
+
if (!matchBracket && (_value.startsWith('rgb') || _value.startsWith('#'))) {
|
|
2248
|
+
rgba = extractRgbaMemo(_value);
|
|
2249
|
+
}
|
|
2250
|
+
if (rgba && typeof rgba === 'object') {
|
|
2251
|
+
if (!toHex) {
|
|
2252
|
+
return formatRgba(rgba.r, rgba.g, rgba.b, rgba.a);
|
|
2253
|
+
}
|
|
2254
|
+
if (!rgba.a.toString().startsWith('var')) {
|
|
2255
|
+
const hex = Color.rgbToHex(parseInt(rgba.r), parseInt(rgba.g), parseInt(rgba.b), toAlphaNumber(rgba.a));
|
|
2256
|
+
return hex;
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
if (matchBracket) {
|
|
2260
|
+
let val = matchBracket[1];
|
|
2261
|
+
if (makeNegative && isNegative) {
|
|
2262
|
+
val = "-" + val;
|
|
2263
|
+
}
|
|
2264
|
+
if (makeImportant && isImportant) {
|
|
2265
|
+
val = val + " !important";
|
|
2266
|
+
}
|
|
2267
|
+
return val;
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
let val = _value;
|
|
2271
|
+
if (makeNegative && isNegative) {
|
|
2272
|
+
val = "-" + val;
|
|
2273
|
+
}
|
|
2274
|
+
if (makeImportant && isImportant) {
|
|
2275
|
+
val = val + " !important";
|
|
2276
|
+
}
|
|
2277
|
+
return val;
|
|
2278
|
+
};
|
|
2279
|
+
const propertyFilter = findPropertyFilter(key);
|
|
2280
|
+
const propertyTransform = findPropertyTransform(key);
|
|
2281
|
+
const opacityProp = kebabArrayString([...OpacityProperties]).find(p => p === key);
|
|
2282
|
+
if (opacityProp) {
|
|
2283
|
+
let replaced = key.replace('-opacity', '');
|
|
2284
|
+
let varName = 'bg';
|
|
2285
|
+
if (replaced !== 'background') {
|
|
2286
|
+
varName = replaced;
|
|
2287
|
+
}
|
|
2288
|
+
return `${varify(`${varName}-opacity`, false)}: ${getDataValue(value, false, false, true)};\n`;
|
|
2289
|
+
}
|
|
2290
|
+
else if (key === 'background-color' || key === 'color') {
|
|
2291
|
+
if (value.startsWith('[') && value.endsWith(']')) {
|
|
2292
|
+
return `${key}: ${getDataValue(value, false, false, false)}${isImportant ? ' !important' : ''};\n`;
|
|
2293
|
+
}
|
|
2294
|
+
const rgba = extractRgbaMemo(value);
|
|
2295
|
+
let propertyVarName = 'bg-opacity';
|
|
2296
|
+
if (key === 'color') {
|
|
2297
|
+
propertyVarName = 'color-opacity';
|
|
2298
|
+
}
|
|
2299
|
+
if (rgba && typeof rgba === 'object') {
|
|
2300
|
+
let opacityProperty = '';
|
|
2301
|
+
if (!rgba.a.toString().startsWith('var')) {
|
|
2302
|
+
opacityProperty = `${varify(propertyVarName, false)}: ${rgba.a};\n`;
|
|
2303
|
+
}
|
|
2304
|
+
const clr = formatRgba(rgba.r, rgba.g, rgba.b, varify(propertyVarName, true));
|
|
2305
|
+
const bgProperty = `${key}: ${clr}${isImportant ? ' !important' : ''};\n`;
|
|
2306
|
+
return `${opacityProperty}${bgProperty}`;
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
else if (key === 'gradient-stop-from') {
|
|
2310
|
+
if (value === '0' || value.endsWith('%')) {
|
|
2311
|
+
return `${varify('gradient-from-position', false)}: ${getDataValue(value, false, true, false)}${isImportant ? ' !important' : ''};\n`;
|
|
2312
|
+
}
|
|
2313
|
+
else {
|
|
2314
|
+
const gradientFrom = `${varify('gradient-from', false)}: ${getDataValue(value, false, false, false)} ${varify('gradient-from-position', true)};\n`;
|
|
2315
|
+
const gradientTo = `${varify('gradient-to', false)}: ${getDataValue(value, false, true, false)} ${varify('gradient-to-position', true)};\n`;
|
|
2316
|
+
const gradientStops = `${varify('gradient-stops', false)}: ${varify('gradient-from', true)}, ${varify('gradient-to', true)}${isImportant ? ' !important' : ''};\n`;
|
|
2317
|
+
return `${gradientFrom}${gradientTo}${gradientStops}`;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
else if (key === 'gradient-stop-via') {
|
|
2321
|
+
if (value === '0' || value.endsWith('%')) {
|
|
2322
|
+
return `${varify('gradient-via-position', false)}: ${getDataValue(value, false, true, false)}${isImportant ? ' !important' : ''};\n`;
|
|
2323
|
+
}
|
|
2324
|
+
else {
|
|
2325
|
+
const gradientTo = `${varify('gradient-to', false)}: ${getDataValue(value, false, true)} ${varify('gradient-to-position', true)};\n`;
|
|
2326
|
+
const gradientStops = `${varify('gradient-stops', false)}: ${varify('gradient-from', true)}, ${getDataValue(value, false)} ${varify('gradient-via-position', true)}, ${varify('gradient-to', true)}${isImportant ? ' !important' : ''};\n`;
|
|
2327
|
+
return `${gradientTo}${gradientStops}`;
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
else if (key === 'gradient-stop-to') {
|
|
2331
|
+
if (value === '0' || value.endsWith('%')) {
|
|
2332
|
+
return `${varify('gradient-to-position', false)}: ${getDataValue(value)}${isImportant ? ' !important' : ''};\n`;
|
|
2333
|
+
}
|
|
2334
|
+
else {
|
|
2335
|
+
return `${varify('gradient-to', false)}: ${getDataValue(value, false)} ${varify('gradient-to-position', true)}${isImportant ? ' !important' : ''};\n`;
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
else if (key === 'box-shadow') {
|
|
2339
|
+
if (brackets) {
|
|
2340
|
+
return `box-shadow: ${brackets.at(1)}${isImportant ? ' !important' : ''};\n`;
|
|
2341
|
+
}
|
|
2342
|
+
else {
|
|
2343
|
+
const normalShadow = `${varify('shadow', false)}: ${getDataValue(value, false)};\n`;
|
|
2344
|
+
const coloredShadow = `${varify('shadow-colored', false)}: ${replaceColor(getDataValue(value, false), varify('shadow-color', true))};\n`;
|
|
2345
|
+
const shadow = `${key}: var(${varify('ring-offset-shadow', false)}, 0 0 #0000), var(${varify('ring-shadow', false)}, 0 0 #0000), ${varify('shadow', true)}${isImportant ? ' !important' : ''};\n`;
|
|
2346
|
+
return `${normalShadow}${coloredShadow}${shadow}`;
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
else if (key === 'box-shadow-color') {
|
|
2350
|
+
const normalShadow = `${varify('shadow-color', false)}: ${getDataValue(value, false)};\n`;
|
|
2351
|
+
const shadow = `${varify('shadow', false)}: ${varify('shadow-colored', true)}${isImportant ? ' !important' : ''};\n`;
|
|
2352
|
+
return `${normalShadow}${shadow}`;
|
|
2353
|
+
}
|
|
2354
|
+
else if (key === 'ring-width') {
|
|
2355
|
+
if (value === 'inset') {
|
|
2356
|
+
return `${varify('ring-inset', false)}: ${value};`;
|
|
2357
|
+
}
|
|
2358
|
+
else {
|
|
2359
|
+
const ringValue = value.replace('ring-inset', varify('ring-inset', true)).replace('ring-offset-width', varify('ring-offset-width', true)).replace('ring-color', varify('ring-color', true));
|
|
2360
|
+
const ringOffsetShadowVar = `${varify('ring-offset-shadow', false)}: ${varify('ring-inset', true)} 0 0 0 ${varify('ring-offset-width', true)} ${varify('ring-offset-color', true)};\n`;
|
|
2361
|
+
const ringShadowVar = `${varify('ring-shadow', false)}: ${ringValue};\n`;
|
|
2362
|
+
const ringShadow = `box-shadow: ${varify('ring-offset-shadow', true)}, ${varify('ring-shadow', true)}, var(${varify('shadow', false)}, 0 0 #0000)${isImportant ? ' !important' : ''};\n`;
|
|
2363
|
+
return `${ringOffsetShadowVar}${ringShadowVar}${ringShadow}`;
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
else if (key === 'ring-color') {
|
|
2367
|
+
let rgba;
|
|
2368
|
+
let ringOpacity = '';
|
|
2369
|
+
let ringColor = '';
|
|
2370
|
+
if (brackets) {
|
|
2371
|
+
rgba = brackets.at(1);
|
|
2372
|
+
ringColor = `${varify('ring-color', false)}: ${brackets.at(1)};\n`;
|
|
2373
|
+
}
|
|
2374
|
+
else {
|
|
2375
|
+
rgba = extractRgbaMemo(value);
|
|
2376
|
+
if (rgba) {
|
|
2377
|
+
const clr = formatRgba(rgba.r, rgba.g, rgba.b, varify('ring-opacity', true));
|
|
2378
|
+
ringOpacity = `${varify('ring-opacity', false)}: ${rgba.a};\n`;
|
|
2379
|
+
ringColor = `${varify('ring-color', false)}: ${clr}${isImportant ? ' !important' : ''};\n`;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
return `${ringOpacity}${ringColor}`;
|
|
2383
|
+
}
|
|
2384
|
+
else if (key === 'ring-offset-color') {
|
|
2385
|
+
let rgba;
|
|
2386
|
+
let ringOffsetOpacity = '';
|
|
2387
|
+
let ringOffsetColor = '';
|
|
2388
|
+
if (brackets) {
|
|
2389
|
+
rgba = brackets.at(1);
|
|
2390
|
+
ringOffsetColor = `${varify('ring-offset-color', false)}: ${brackets.at(1)}${isImportant ? ' !important' : ''};\n`;
|
|
2391
|
+
}
|
|
2392
|
+
else {
|
|
2393
|
+
rgba = extractRgbaMemo(value);
|
|
2394
|
+
if (rgba) {
|
|
2395
|
+
const clr = formatRgba(rgba.r, rgba.g, rgba.b, varify('ring-offset-opacity', true));
|
|
2396
|
+
ringOffsetOpacity = `${varify('ring-offset-opacity', false)}: ${rgba.a};\n`;
|
|
2397
|
+
ringOffsetColor = `${varify('ring-offset-color', false)}: ${clr}${isImportant ? ' !important' : ''};\n`;
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
return `${ringOffsetOpacity}${ringOffsetColor}`;
|
|
2401
|
+
// return `${varify('ring-offset-color', false)}: ${getDataValue(value, false)};\n`;
|
|
2402
|
+
}
|
|
2403
|
+
else if (key === 'ring-offset-width') {
|
|
2404
|
+
return `${varify('ring-offset-width', false)}: ${getDataValue(value, false, true)}${isImportant ? ' !important' : ''};\n`;
|
|
2405
|
+
}
|
|
2406
|
+
else if (propertyFilter) {
|
|
2407
|
+
const filterName = propertyFilter.propertyName;
|
|
2408
|
+
const filterFn = propertyFilter.propertyFn;
|
|
2409
|
+
let varPrefix = '';
|
|
2410
|
+
if (filterName !== 'filter') {
|
|
2411
|
+
varPrefix = (splitString(filterName, TIRET_REGEX) || [])[0] + "-";
|
|
2412
|
+
}
|
|
2413
|
+
let filterPropertyVar = '';
|
|
2414
|
+
let filterCss = '';
|
|
2415
|
+
if (propertyFilter.propertyName === 'backdrop-filter') {
|
|
2416
|
+
filterPropertyVar = `${varify(`backdrop-${filterFn}`, false)}: ${wrapFilterValue(value, filterFn)};\n`;
|
|
2417
|
+
}
|
|
2418
|
+
else {
|
|
2419
|
+
filterPropertyVar = `${varify(filterFn, false)}: ${wrapFilterValue(value, filterFn)};\n`;
|
|
2420
|
+
}
|
|
2421
|
+
filterCss = `${filterName}: ${varify(`${varPrefix}blur`, true)} ${varify(`${varPrefix}brightness`, true)} ${varify(`${varPrefix}contrast`, true)} ${varify(`${varPrefix}grayscale`, true)} ${varify(`${varPrefix}hue-rotate`, true)} ${varify(`${varPrefix}invert`, true)} ${varify(`${varPrefix}sepia`, true)} ${isImportant ? ' !important' : ''};\n`;
|
|
2422
|
+
return `${filterPropertyVar}${filterCss}`;
|
|
2423
|
+
}
|
|
2424
|
+
else if (propertyTransform) {
|
|
2425
|
+
const transformName = propertyTransform.propertyName;
|
|
2426
|
+
const transformFn = propertyTransform.propertyFn;
|
|
2427
|
+
let transformPropertyVar = `${varify(transformFn, false)}: ${getDataValue(value, false, true, true)};\n`;
|
|
2428
|
+
if (transformFn === 'scale') {
|
|
2429
|
+
transformPropertyVar = `${varify(`${transformFn}-x`, false)}: ${getDataValue(value, false, true)};\n`;
|
|
2430
|
+
transformPropertyVar += `${varify(`${transformFn}-y`, false)}: ${getDataValue(value, false, true)};\n`;
|
|
2431
|
+
}
|
|
2432
|
+
let fnName = 'translate';
|
|
2433
|
+
if (transformFn === 'transform') {
|
|
2434
|
+
if (value === 'translate' || value === 'translate3d') {
|
|
2435
|
+
fnName = value;
|
|
2436
|
+
transformPropertyVar = '';
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
const transformCss = `${transformName}: ${fnName}(${varify(`translate-x`, true)}, ${varify(`translate-y`, true)}) rotate(${varify(`rotate`, true)}) skewX(${varify(`skew-x`, true)}) skewY(${varify(`skew-y`, true)}) scaleX(${varify(`scale-x`, true)}) scaleY(${varify(`scale-y`, true)})${isImportant ? ' !important' : ''};\n`;
|
|
2440
|
+
return `${transformPropertyVar}${transformCss}`;
|
|
2441
|
+
}
|
|
2442
|
+
else if (key === 'animation') {
|
|
2443
|
+
const keyFrameName = value.split(' ')[0];
|
|
2444
|
+
const keyframes = getThemeKeyframes();
|
|
2445
|
+
if (keyframes && keyframes[keyFrameName]) {
|
|
2446
|
+
// const keyFrame = convertToKeyframes(keyFrameName, keyframes[keyFrameName]);
|
|
2447
|
+
const keyFrameObject = processKeyframes({ [keyFrameName]: keyframes[keyFrameName] }, getThemeKeyframesOptions());
|
|
2448
|
+
const keyFrame = convertKeyframesToString(keyFrameObject);
|
|
2449
|
+
const cssValue = `${key}: ${value}${isImportant ? ' !important' : ''};\n`;
|
|
2450
|
+
keyframeRules.push(...keyFrameObject.keyframeRules);
|
|
2451
|
+
return `${cssValue}${keyFrame}`;
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
else if (key.startsWith('space-between')) {
|
|
2455
|
+
const spaceName = key.replace('space-between-', '');
|
|
2456
|
+
if (spaceName === 'x' || spaceName === 'y') {
|
|
2457
|
+
const spaceBetweenVar = `${varify(`space-${spaceName}-reverse`, false)}: ${value === 'reverse' ? 1 : 0};\n`;
|
|
2458
|
+
let spaceBetween = '';
|
|
2459
|
+
if (value !== 'reverse') {
|
|
2460
|
+
if (spaceName === 'x') {
|
|
2461
|
+
spaceBetween += `margin-right: calc(${getDataValue(value, false, true)} * ${varify(`space-${spaceName}-reverse`, true)})${isImportant ? ' !important' : ''};\n`;
|
|
2462
|
+
spaceBetween += `margin-left: calc(${getDataValue(value, false, true)} * calc(1 - ${varify(`space-${spaceName}-reverse`, true)}))${isImportant ? ' !important' : ''};\n`;
|
|
2463
|
+
}
|
|
2464
|
+
else {
|
|
2465
|
+
spaceBetween += `margin-top: calc(${getDataValue(value, false, true)} * calc(1 - ${varify(`space-${spaceName}-reverse`, true)}))${isImportant ? ' !important' : ''};\n`;
|
|
2466
|
+
spaceBetween += `margin-bottom: calc(${getDataValue(value, false, true)} * ${varify(`space-${spaceName}-reverse`, true)})${isImportant ? ' !important' : ''};\n`;
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
return `${spaceBetweenVar}${spaceBetween}`;
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
else if (key === 'divide-x' || key === 'divide-y' || key === 'divide-style') {
|
|
2473
|
+
const divideName = key.replace('divide-', '');
|
|
2474
|
+
if (divideName === 'x' || divideName === 'y') {
|
|
2475
|
+
const divideVar = `${varify(`divide-${divideName}-reverse`, false)}: ${value === 'reverse' ? 1 : 0};\n`;
|
|
2476
|
+
let divideBetween = '';
|
|
2477
|
+
if (value !== 'reverse') {
|
|
2478
|
+
if (divideName === 'x') {
|
|
2479
|
+
divideBetween += `border-right-width: calc(${getDataValue(value, false, true)} * ${varify(`divide-${divideName}-reverse`, true)})${isImportant ? ' !important' : ''};\n`;
|
|
2480
|
+
divideBetween += `border-left-width: calc(${getDataValue(value, false, true)} * calc(1 - ${varify(`divide-${divideName}-reverse`, true)}))${isImportant ? ' !important' : ''};\n`;
|
|
2481
|
+
}
|
|
2482
|
+
else {
|
|
2483
|
+
divideBetween += `border-top-width: calc(${getDataValue(value, false, true)} * calc(1 - ${varify(`divide-${divideName}-reverse`, true)}))${isImportant ? ' !important' : ''};\n`;
|
|
2484
|
+
divideBetween += `border-bottom-width: calc(${getDataValue(value, false, true)} * ${varify(`divide-${divideName}-reverse`, true)})${isImportant ? ' !important' : ''};\n`;
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
return `${divideVar}${divideBetween}`;
|
|
2488
|
+
}
|
|
2489
|
+
else if (divideName === 'style') {
|
|
2490
|
+
return `border-style: ${getDataValue(value, false, false, true)}`;
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
else if (key === 'divide-color' || CssBorderColorProperties.includes(key)) {
|
|
2494
|
+
let rgba;
|
|
2495
|
+
if (value === 'currentColor') {
|
|
2496
|
+
rgba = value;
|
|
2497
|
+
}
|
|
2498
|
+
else if (brackets) {
|
|
2499
|
+
rgba = brackets.at(1);
|
|
2500
|
+
}
|
|
2501
|
+
else {
|
|
2502
|
+
rgba = extractRgbaMemo(value);
|
|
2503
|
+
}
|
|
2504
|
+
let propertyVarName = `border-opacity`;
|
|
2505
|
+
if (key.startsWith('divide')) {
|
|
2506
|
+
propertyVarName = `divide-opacity`;
|
|
2507
|
+
}
|
|
2508
|
+
if (rgba) {
|
|
2509
|
+
let opacityProperty = '';
|
|
2510
|
+
let clr = '';
|
|
2511
|
+
if (typeof rgba === 'object' && rgba.r) {
|
|
2512
|
+
if (!rgba.a.toString().startsWith('var')) {
|
|
2513
|
+
opacityProperty = `${varify(propertyVarName, false)}: ${rgba.a};\n`;
|
|
2514
|
+
}
|
|
2515
|
+
clr = formatRgba(rgba.r, rgba.g, rgba.b, varify(propertyVarName, true));
|
|
2516
|
+
}
|
|
2517
|
+
else {
|
|
2518
|
+
clr = rgba;
|
|
2519
|
+
}
|
|
2520
|
+
let propKey = CssBorderColorProperties.find(pp => pp === key);
|
|
2521
|
+
if (!propKey) {
|
|
2522
|
+
propKey = 'border-color';
|
|
2523
|
+
}
|
|
2524
|
+
const divideProperty = `${propKey}: ${clr}${isImportant ? ' !important' : ''};\n`;
|
|
2525
|
+
return `${opacityProperty}${divideProperty}`;
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
else if (key === 'placeholder-color') {
|
|
2529
|
+
let rgba;
|
|
2530
|
+
if (value === 'currentColor') {
|
|
2531
|
+
rgba = value;
|
|
2532
|
+
}
|
|
2533
|
+
else if (brackets) {
|
|
2534
|
+
rgba = brackets.at(1);
|
|
2535
|
+
}
|
|
2536
|
+
else {
|
|
2537
|
+
rgba = extractRgbaMemo(value);
|
|
2538
|
+
}
|
|
2539
|
+
// const rgba = extractRgbaMemo(value);
|
|
2540
|
+
const propertyVarName = 'placeholder-opacity';
|
|
2541
|
+
if (rgba) {
|
|
2542
|
+
let opacityProperty = '';
|
|
2543
|
+
let clr = '';
|
|
2544
|
+
if (rgba.r) {
|
|
2545
|
+
if (!rgba.a.toString().startsWith('var')) {
|
|
2546
|
+
opacityProperty = `${varify(propertyVarName, false)}: ${rgba.a};\n`;
|
|
2547
|
+
}
|
|
2548
|
+
clr = formatRgba(rgba.r, rgba.g, rgba.b, varify(propertyVarName, true));
|
|
2549
|
+
}
|
|
2550
|
+
else {
|
|
2551
|
+
clr = rgba;
|
|
2552
|
+
}
|
|
2553
|
+
const placeholderProperty = `color: ${clr}${isImportant ? ' !important' : ''};\n`;
|
|
2554
|
+
return `${placeholderProperty}${opacityProperty}`;
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
return `${key}: ${getDataValue(value, false, true, true)};`;
|
|
2558
|
+
};
|
|
2559
|
+
// export const objectToCss = (obj: any, class_name: string = '', mainClass?: string, isNegative = false, isImportant = false, depth=0, debug = false)=> {
|
|
2560
|
+
// if(!checkType(obj).is_object){
|
|
2561
|
+
// return ''
|
|
2562
|
+
// }
|
|
2563
|
+
// const className = class_name ? class_name : '';
|
|
2564
|
+
// let _className = className.length > 0 ? className : mainClass ? mainClass : className;
|
|
2565
|
+
// let pseudoStyle = '';
|
|
2566
|
+
// let directStyle = '';
|
|
2567
|
+
// let directProps = [] as any[];
|
|
2568
|
+
// for(const k in obj){
|
|
2569
|
+
// if(obj.hasOwnProperty(k)){
|
|
2570
|
+
// if(typeof obj[k] === 'string' || typeof obj[k] === 'number' || Array.isArray(obj[k])){
|
|
2571
|
+
// const sp = buildDirectStyle(camelToKebab(k), (obj[k] as any).toString(), isNegative, isImportant);
|
|
2572
|
+
// if(sp && sp.length>0){
|
|
2573
|
+
// directProps.push(sp);
|
|
2574
|
+
// }
|
|
2575
|
+
// }else if(typeof obj[k] === 'object'){
|
|
2576
|
+
// const value = obj[k];
|
|
2577
|
+
// const _key = k;
|
|
2578
|
+
// let {key, formatted} = memoFindKey(_key);
|
|
2579
|
+
// formatted = formatted.startsWith('{') ? getStringBetweenTags(formatted, PARENTHESES_DYNAMIC_REGEX, true)[0] : formatted
|
|
2580
|
+
// let cls = mainClass;
|
|
2581
|
+
// if(!cls || (_className.startsWith(cls) && _className.replace(cls, '').trim().length>0)){
|
|
2582
|
+
// cls = _className;
|
|
2583
|
+
// }
|
|
2584
|
+
// if(formatted.startsWith('@')){
|
|
2585
|
+
// if(formatted.startsWith('@(')){
|
|
2586
|
+
// const selector = formatted.replace('@(', '').replace(')', '').trim();
|
|
2587
|
+
// const _className_ = mainClass ? `${mainClass.length > 0 ? mainClass + " ": ""}${selector}` : `${_className.length > 0 ? _className + " ": ""}${selector}`
|
|
2588
|
+
// pseudoStyle += `${_className_}{\n${objectToCss(obj[k] as any, _className_, mainClass, isNegative, isImportant, mainClass ? 1 : 0, debug)}\n}\n`;
|
|
2589
|
+
// }else{
|
|
2590
|
+
// const _className_ = mainClass ? mainClass : _className+`${key}`
|
|
2591
|
+
// pseudoStyle += `${formatted}{\n${objectToCss(obj[k] as any, _className_, mainClass, isNegative, isImportant, mainClass ? 1 : 0, debug)}\n}\n`;
|
|
2592
|
+
// }
|
|
2593
|
+
// }else if(key.startsWith('&') || key.startsWith(':')){
|
|
2594
|
+
// let _className_ = '';
|
|
2595
|
+
// const dynamicRequest = getDynamicSelector((_key === ':dark' || _key === ':light') ? formatted : k, true, (_key === ':dark' || _key === ':light') ? 'media' : '');
|
|
2596
|
+
// if(dynamicRequest){
|
|
2597
|
+
// let {dynamicSelector} = dynamicRequest;
|
|
2598
|
+
// if(dynamicSelector.startsWith('\\s') || dynamicSelector.endsWith('\\s')){
|
|
2599
|
+
// dynamicSelector = dynamicSelector.replace('\\s', '_space_')
|
|
2600
|
+
// }
|
|
2601
|
+
// const cp = splitString(cls);
|
|
2602
|
+
// if(dynamicRequest.isAfter){
|
|
2603
|
+
// const _cls = cp.shift() as string;
|
|
2604
|
+
// _className_ = _cls+`{${dynamicSelector}}`+`${cp.length>0 ? ' '+ cp.join(' '):''}`;
|
|
2605
|
+
// }else{
|
|
2606
|
+
// const _cls = cp.shift();
|
|
2607
|
+
// _className_ = `{${dynamicSelector}}`+_cls+`${cp.length>0 ? ' '+ cp.join(' '):''}`;
|
|
2608
|
+
// }
|
|
2609
|
+
// }else{
|
|
2610
|
+
// _className_ = cls+`{${formatted}}`;
|
|
2611
|
+
// }
|
|
2612
|
+
// pseudoStyle +=objectToCss(obj[k] as any, _className_, mainClass, isNegative, isImportant, mainClass ? 1 : 0, debug);
|
|
2613
|
+
// }else{
|
|
2614
|
+
// const _className_ = mainClass ? `${mainClass.length > 0 ? mainClass + " ": ""}${key}` : `${_className.length > 0 ? _className + " ": ""}${key}`
|
|
2615
|
+
// pseudoStyle +=objectToCss(obj[k] as any, _className_, mainClass, isNegative, isImportant, mainClass ? 1 : 0, debug);
|
|
2616
|
+
// }
|
|
2617
|
+
// }
|
|
2618
|
+
// }
|
|
2619
|
+
// }
|
|
2620
|
+
// if(directProps.length>0){
|
|
2621
|
+
// directStyle = `${_className.length > 0 ? formatClassName(_className) + "{\n": ''}${directProps.join(' ')}\n${_className.length > 0 ? '}\n': ''}`;
|
|
2622
|
+
// }
|
|
2623
|
+
// const result = [directStyle.replace(/_space_/g,'\xa0').trim(), pseudoStyle.replace(/_space_/g,'\xa0')].filter(a=>a.length>0).join('\n');
|
|
2624
|
+
// if(keyframeRules.length>0){
|
|
2625
|
+
// return `${keyframeRules.join('\n')}\n${result}`
|
|
2626
|
+
// }
|
|
2627
|
+
// return result;
|
|
2628
|
+
// }
|
|
2629
|
+
export const objectToCss = (obj, class_name = '', mainClass, isNegative = false, isImportant = false, depth = 0, debug = false) => {
|
|
2630
|
+
if (!checkType(obj).is_object) {
|
|
2631
|
+
return '';
|
|
2632
|
+
}
|
|
2633
|
+
const className = class_name ? class_name : '';
|
|
2634
|
+
let _className = className.length > 0 ? className : mainClass ? mainClass : className;
|
|
2635
|
+
let pseudoStyle = '';
|
|
2636
|
+
let directStyle = '';
|
|
2637
|
+
const directProps = [];
|
|
2638
|
+
for (let k in obj) {
|
|
2639
|
+
if (obj.hasOwnProperty(k)) {
|
|
2640
|
+
if (typeof obj[k] === 'string' || typeof obj[k] === 'number' || Array.isArray(obj[k])) {
|
|
2641
|
+
const sp = buildDirectStyle(camelToKebab(k), obj[k].toString(), isNegative, isImportant);
|
|
2642
|
+
if (sp && sp.length > 0) {
|
|
2643
|
+
if (directProps.length === 0) {
|
|
2644
|
+
directStyle += `${_className.length > 0 ? (formatClassName(_className)) + "{\n" : ''}`;
|
|
2645
|
+
}
|
|
2646
|
+
directStyle += sp + ' ';
|
|
2647
|
+
// if(keyframeRules.length>0){
|
|
2648
|
+
// directStyle+=`${keyframeRules.join('')}`
|
|
2649
|
+
// keyframeRules = []
|
|
2650
|
+
// }
|
|
2651
|
+
directProps.push(directProps.length);
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
else if (typeof obj[k] === 'object') {
|
|
2655
|
+
const value = obj[k];
|
|
2656
|
+
const _key = k;
|
|
2657
|
+
let key = '';
|
|
2658
|
+
let formatted = '';
|
|
2659
|
+
if (_key.startsWith('{') && _key.endsWith('}')) {
|
|
2660
|
+
formatted = getStringBetweenTags(_key, PARENTHESES_DYNAMIC_REGEX, true)[0];
|
|
2661
|
+
key = '&';
|
|
2662
|
+
}
|
|
2663
|
+
else {
|
|
2664
|
+
let f = memoFindKey(_key);
|
|
2665
|
+
key = f.key.toString();
|
|
2666
|
+
formatted = f.formatted;
|
|
2667
|
+
}
|
|
2668
|
+
formatted = formatted.startsWith('{') ? getStringBetweenTags(formatted, PARENTHESES_DYNAMIC_REGEX, true)[0] : formatted;
|
|
2669
|
+
let cls = mainClass;
|
|
2670
|
+
if (!cls || (_className.startsWith(cls) && _className.replace(cls, '').trim().length > 0) || (_className.startsWith('{') && _className.includes(cls))) {
|
|
2671
|
+
cls = _className;
|
|
2672
|
+
}
|
|
2673
|
+
//formatted.startsWith('&media[')
|
|
2674
|
+
if (formatted.startsWith('@')) {
|
|
2675
|
+
const _className_ = mainClass ? mainClass : _className + `${key}`;
|
|
2676
|
+
// const _className_ = mainClass ? formatClassName(mainClass, debug,1) : formatClassName(_className+`${key}`)
|
|
2677
|
+
if (formatted.startsWith('@(')) {
|
|
2678
|
+
const selector = formatted.replace('@(', '').replace(')', '').trim();
|
|
2679
|
+
const _className_ = mainClass ? `${mainClass.length > 0 ? mainClass + " " : ""}${selector}` : `${_className.length > 0 ? _className + " " : ""}${selector}`;
|
|
2680
|
+
pseudoStyle += `${_className_}{\n${objectToCss(value, _className_, mainClass, isNegative, isImportant, mainClass ? 1 : 0, debug)}\n}\n`;
|
|
2681
|
+
}
|
|
2682
|
+
// else if(formatted.startsWith('&media[')){
|
|
2683
|
+
// let _className_ = `{${formatted.replace('&media[', '').slice(0,-1)}}` + `space_`+cls;
|
|
2684
|
+
// pseudoStyle += objectToCss(value as any, _className_, mainClass, isNegative, isImportant, mainClass ? 1 : 0, true)
|
|
2685
|
+
// }
|
|
2686
|
+
else {
|
|
2687
|
+
pseudoStyle += `${formatted}{\n${objectToCss(value, _className_, mainClass, isNegative, isImportant, mainClass ? 1 : 0, debug)}\n}\n`;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
else if (key.startsWith('&') || key.startsWith(':')) {
|
|
2691
|
+
let has_objects = false;
|
|
2692
|
+
if (key.startsWith('&')) {
|
|
2693
|
+
key = replaceClassSelf(key);
|
|
2694
|
+
formatted = replaceClassSelf(formatted);
|
|
2695
|
+
}
|
|
2696
|
+
let _className_ = '';
|
|
2697
|
+
const dynamicRequest = getDynamicSelector((_key === ':dark' || _key === ':light') ? formatted : _key, true, (_key === ':dark' || _key === ':light') ? 'media' : '');
|
|
2698
|
+
if (dynamicRequest) {
|
|
2699
|
+
let { dynamicSelector } = dynamicRequest;
|
|
2700
|
+
if (dynamicSelector.startsWith('\\s') || dynamicSelector.endsWith('\\s')) {
|
|
2701
|
+
dynamicSelector = dynamicSelector.replace('\\s', '_space_');
|
|
2702
|
+
}
|
|
2703
|
+
const cp = splitString(cls);
|
|
2704
|
+
if (dynamicRequest.isAfter) {
|
|
2705
|
+
const _cls = cp.shift();
|
|
2706
|
+
// let buildValues = {} as any;
|
|
2707
|
+
// for(const _k in value){
|
|
2708
|
+
// if(value.hasOwnProperty(_k)){
|
|
2709
|
+
// if(_k!=='& > *'){
|
|
2710
|
+
// buildValues[_k] = value[_k]
|
|
2711
|
+
// has_objects = true
|
|
2712
|
+
// }else{
|
|
2713
|
+
// _className_ = cls+' > *'+dynamicSelector;
|
|
2714
|
+
// buildValues = {...buildValues, ...value[_k]}
|
|
2715
|
+
// }
|
|
2716
|
+
// }
|
|
2717
|
+
// }
|
|
2718
|
+
// _className_ = formatClassName(_cls)+`${dynamicSelector}`+`${cp.length>0 ? ' '+ cp.join(' '):''}`
|
|
2719
|
+
_className_ = _cls + `{${dynamicSelector}}` + `${cp.length > 0 ? ' ' + cp.join(' ') : ''}`;
|
|
2720
|
+
// _className_ = mainClass ? formatClassName(mainClass, debug,2)+dynamicRequest.dynamicSelector : _className+dynamicRequest.dynamicSelector;
|
|
2721
|
+
// _className_ =cls+`<&${dynamicSelector}>`;
|
|
2722
|
+
}
|
|
2723
|
+
else {
|
|
2724
|
+
const _cls = cp.shift();
|
|
2725
|
+
_className_ = `{${dynamicSelector}}` + _cls + `${cp.length > 0 ? ' ' + cp.join(' ') : ''}`;
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
else {
|
|
2729
|
+
has_objects = true;
|
|
2730
|
+
_className_ = cls + `{${formatted}}`;
|
|
2731
|
+
}
|
|
2732
|
+
pseudoStyle += objectToCss(value, _className_, mainClass, isNegative, isImportant, mainClass ? 1 : 0, true);
|
|
2733
|
+
}
|
|
2734
|
+
else {
|
|
2735
|
+
const _className_ = mainClass ? `${mainClass.length > 0 ? mainClass + " " : ""}${key}` : `${_className.length > 0 ? _className + " " : ""}${key}`;
|
|
2736
|
+
pseudoStyle += objectToCss(value, _className_, mainClass, isNegative, isImportant, mainClass ? 1 : 0, debug);
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
if (directProps.length > 0) {
|
|
2742
|
+
directStyle += ` ${_className.length > 0 ? `\n}\n` : ''}`;
|
|
2743
|
+
}
|
|
2744
|
+
const result = [directProps.length > 0 ? directStyle.replace(/_space_/g, '\xa0').trim() : '', pseudoStyle.replace(/_space_/g, '\xa0')].filter(a => a.length > 0).join('\n');
|
|
2745
|
+
if (keyframeRules.length > 0) {
|
|
2746
|
+
const rules = keyframeRules.slice().join('\n');
|
|
2747
|
+
keyframeRules = [];
|
|
2748
|
+
return `${rules}\n${result}`;
|
|
2749
|
+
}
|
|
2750
|
+
return result;
|
|
2751
|
+
};
|
|
2752
|
+
const _checkSelectorScheme = (content) => {
|
|
2753
|
+
let needSpace = false;
|
|
2754
|
+
let content_valid = false;
|
|
2755
|
+
let isAfter = false;
|
|
2756
|
+
let replace_value = undefined;
|
|
2757
|
+
if (content.startsWith('&')) {
|
|
2758
|
+
needSpace = content.startsWith('&_');
|
|
2759
|
+
replace_value = needSpace ? '&_' : '&';
|
|
2760
|
+
isAfter = true;
|
|
2761
|
+
content_valid = true;
|
|
2762
|
+
}
|
|
2763
|
+
else if (content.endsWith('&')) {
|
|
2764
|
+
needSpace = content.endsWith('_&');
|
|
2765
|
+
replace_value = needSpace ? '_&' : '&';
|
|
2766
|
+
content_valid = true;
|
|
2767
|
+
}
|
|
2768
|
+
if (replace_value) {
|
|
2769
|
+
return { needSpace, content_valid, isAfter, replace_value };
|
|
2770
|
+
}
|
|
2771
|
+
return null;
|
|
2772
|
+
};
|
|
2773
|
+
const checkSelectorSchemeMemo = memoizeFn(_checkSelectorScheme);
|
|
2774
|
+
const checkSelectorScheme = (content) => {
|
|
2775
|
+
return checkSelectorSchemeMemo(content);
|
|
2776
|
+
};
|
|
2777
|
+
const getDynamicSelector = (str, followSelf = true, prefix = '') => {
|
|
2778
|
+
let br = extractBracket(prefix).exec(str);
|
|
2779
|
+
if (prefix === 'media') {
|
|
2780
|
+
let st = replaceString(str, 'media[', true, '');
|
|
2781
|
+
st = replaceString(st, ']', false, '');
|
|
2782
|
+
br = [str, st];
|
|
2783
|
+
}
|
|
2784
|
+
let needSpace = false;
|
|
2785
|
+
let isAfter = false;
|
|
2786
|
+
let replace_value = undefined;
|
|
2787
|
+
let dynamicSelector = '';
|
|
2788
|
+
let content = undefined;
|
|
2789
|
+
let content_valid = false;
|
|
2790
|
+
if (br && br[1] && (`[${br[1]}]` === str || prefix === 'media')) {
|
|
2791
|
+
content = br[1];
|
|
2792
|
+
const check = checkSelectorScheme(content);
|
|
2793
|
+
if (check) {
|
|
2794
|
+
needSpace = check.needSpace;
|
|
2795
|
+
replace_value = check.replace_value;
|
|
2796
|
+
content_valid = check.content_valid;
|
|
2797
|
+
isAfter = check.isAfter;
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
if (content && replace_value && content_valid) {
|
|
2801
|
+
dynamicSelector = content.replace(replace_value, '').trim();
|
|
2802
|
+
const dyn = memoFindKey(dynamicSelector);
|
|
2803
|
+
// const scheme = checkSelectorScheme(dynamicSelector);
|
|
2804
|
+
if (dyn.key && dyn.formatted && dyn.isModifier) {
|
|
2805
|
+
const f = getStringBetweenTags(dyn.formatted, PARENTHESES_DYNAMIC_REGEX, true)[0] || dyn.formatted.replace('&', '');
|
|
2806
|
+
dynamicSelector = f;
|
|
2807
|
+
}
|
|
2808
|
+
if (dynamicSelector.split('=').length === 2
|
|
2809
|
+
|| dynamicSelector.startsWith('data-')
|
|
2810
|
+
|| dynamicSelector.startsWith('aria-')) {
|
|
2811
|
+
dynamicSelector = `[${dynamicSelector}]`;
|
|
2812
|
+
}
|
|
2813
|
+
if (needSpace) {
|
|
2814
|
+
if (followSelf) {
|
|
2815
|
+
dynamicSelector = isAfter ? `${getSpaceString()}` + dynamicSelector : dynamicSelector + `${getSpaceString()}`;
|
|
2816
|
+
}
|
|
2817
|
+
else {
|
|
2818
|
+
dynamicSelector = isAfter ? dynamicSelector + `${getSpaceString()}` : `${getSpaceString()}` + dynamicSelector;
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
return { dynamicSelector, needSpace, isAfter };
|
|
2822
|
+
}
|
|
2823
|
+
return null;
|
|
2824
|
+
};
|
|
2825
|
+
const _getCssProperties = () => {
|
|
2826
|
+
const chs = UtilitiesShorthands;
|
|
2827
|
+
const shorthandsArray = [];
|
|
2828
|
+
for (const ch in chs) {
|
|
2829
|
+
if (chs.hasOwnProperty(ch)) {
|
|
2830
|
+
for (const s in chs[ch]) {
|
|
2831
|
+
if (chs[ch].hasOwnProperty(s)) {
|
|
2832
|
+
const props = chs[ch][s];
|
|
2833
|
+
const notExist = props.filter(p => !shorthandsArray.some(short => short === p));
|
|
2834
|
+
shorthandsArray.push(...notExist);
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
const propsKeys = uniq(kebabArrayString(shorthandsArray).concat([...CssPropertiesKeys]));
|
|
2840
|
+
return propsKeys;
|
|
2841
|
+
};
|
|
2842
|
+
export const getCssProperties = memoizeFn(_getCssProperties);
|
|
2843
|
+
const _isCssProperty = (key) => {
|
|
2844
|
+
const cssProps = getCssProperties();
|
|
2845
|
+
if (typeof key === 'string' || typeof key === 'number') {
|
|
2846
|
+
let cssKey = key.toString();
|
|
2847
|
+
if (cssProps.find(c => c === cssKey) || cssKey.startsWith('-')) {
|
|
2848
|
+
return true;
|
|
2849
|
+
}
|
|
2850
|
+
else if (cssProps.find(c => c === camelToKebab(cssKey))) {
|
|
2851
|
+
return true;
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
return false;
|
|
2855
|
+
};
|
|
2856
|
+
const isCssPropMemo = memoizeFn(_isCssProperty);
|
|
2857
|
+
export const isCssProperty = (key) => {
|
|
2858
|
+
return isCssPropMemo(key);
|
|
2859
|
+
};
|
|
2860
|
+
export const wrapValues = (values, keys) => {
|
|
2861
|
+
let result = {};
|
|
2862
|
+
if (!checkType(values).is_object) {
|
|
2863
|
+
return values;
|
|
2864
|
+
}
|
|
2865
|
+
const obj = Object.assign({}, values);
|
|
2866
|
+
for (const k in obj) {
|
|
2867
|
+
if (obj.hasOwnProperty(k)) {
|
|
2868
|
+
if (checkType(Object.assign({}, obj)[k]).is_object) {
|
|
2869
|
+
const okeys = keys.slice();
|
|
2870
|
+
const objk = Object.keys(obj[k]).filter(kk => !isCssProperty(kk));
|
|
2871
|
+
if (objk.length > 0) {
|
|
2872
|
+
const picked = pick(obj[k], objk);
|
|
2873
|
+
const omitted = omit(obj[k], objk);
|
|
2874
|
+
const wrapped = wrapValues(picked, okeys);
|
|
2875
|
+
result = Object.assign(Object.assign({}, result), { [k]: Object.assign(Object.assign({}, (omitted ? omitted : {})), wrapped) });
|
|
2876
|
+
}
|
|
2877
|
+
else {
|
|
2878
|
+
result = Object.assign(Object.assign({}, result), { [k]: obj[k] });
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
else {
|
|
2882
|
+
const assigned = assignKeys([...keys], Object.assign({}, obj)[k], false);
|
|
2883
|
+
result = Object.assign(Object.assign({}, result), { [k]: assigned });
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
return result;
|
|
2888
|
+
};
|
|
2889
|
+
export const buildClassMap = (_utilities = UtilitiesData, variants = {}, screens = {}) => {
|
|
2890
|
+
const utilities = Object.assign({}, _utilities);
|
|
2891
|
+
let result = {};
|
|
2892
|
+
let flattenedClassMap = {};
|
|
2893
|
+
const wrappedClassMap = {};
|
|
2894
|
+
const normal_result = {};
|
|
2895
|
+
const result_variants = {};
|
|
2896
|
+
const cssMap = {};
|
|
2897
|
+
const cssString = '';
|
|
2898
|
+
const shorthands_array = [];
|
|
2899
|
+
const styles_schemes = [];
|
|
2900
|
+
for (const parent in utilities) {
|
|
2901
|
+
if (utilities.hasOwnProperty(parent)) {
|
|
2902
|
+
const prop = utilities[parent];
|
|
2903
|
+
const propKeys = Object.keys(prop);
|
|
2904
|
+
for (const k of propKeys) {
|
|
2905
|
+
const { shorthands, values } = prop[k];
|
|
2906
|
+
let short_result = {};
|
|
2907
|
+
let normal_short_result = {};
|
|
2908
|
+
if (Array.isArray(values)) {
|
|
2909
|
+
short_result = values.reduce((acc, v) => {
|
|
2910
|
+
if (v.includes(':')) {
|
|
2911
|
+
const [_k, _v] = v.split(':');
|
|
2912
|
+
return Object.assign(Object.assign({}, acc), { [_k]: { [k]: _v } });
|
|
2913
|
+
}
|
|
2914
|
+
return Object.assign(Object.assign({}, acc), { [v]: { [k]: v } });
|
|
2915
|
+
}, {});
|
|
2916
|
+
normal_short_result = values.reduce((acc, v) => {
|
|
2917
|
+
if (v.includes(':')) {
|
|
2918
|
+
const [_k, _v] = v.split(':');
|
|
2919
|
+
return Object.assign(Object.assign({}, acc), { [_k]: { [k]: _v } });
|
|
2920
|
+
}
|
|
2921
|
+
return Object.assign(Object.assign({}, acc), v);
|
|
2922
|
+
}, {});
|
|
2923
|
+
}
|
|
2924
|
+
else {
|
|
2925
|
+
const valuesKeys = Object.keys(values);
|
|
2926
|
+
const shorthandsKeys = Object.keys(shorthands);
|
|
2927
|
+
for (const shorthand_key in shorthands) {
|
|
2928
|
+
if (shorthands.hasOwnProperty(shorthand_key)) {
|
|
2929
|
+
const shorthand_value = shorthands[shorthand_key];
|
|
2930
|
+
const scheme = generateShorthandScheme(shorthand_key, shorthand_value, parent);
|
|
2931
|
+
styles_schemes.push(...scheme);
|
|
2932
|
+
const typeOfValue = values[valuesKeys[0]];
|
|
2933
|
+
let arrayProps = Array.isArray(shorthand_value) ? shorthand_value : checkType(shorthand_value).is_object ? Object.keys(shorthand_value) : shorthand_value;
|
|
2934
|
+
let properties = arrayProps;
|
|
2935
|
+
if (checkType(typeOfValue).is_object) {
|
|
2936
|
+
const filter = Object.keys(typeOfValue).filter(k => arrayProps.some(s => s === k));
|
|
2937
|
+
if (filter.length > 0 && Object.keys(typeOfValue).length >= arrayProps.length) {
|
|
2938
|
+
properties = Object.keys(typeOfValue);
|
|
2939
|
+
}
|
|
2940
|
+
if (filter.length === 0) {
|
|
2941
|
+
properties = arrayProps.slice();
|
|
2942
|
+
arrayProps = [];
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
if (valuesKeys.length === shorthandsKeys.length && valuesKeys.length > 1) {
|
|
2946
|
+
let _val = values[shorthand_key];
|
|
2947
|
+
let _key = shorthand_key;
|
|
2948
|
+
let prefs = [];
|
|
2949
|
+
if (!_val) {
|
|
2950
|
+
const split = splitString(shorthand_key, TIRET_REGEX) || [];
|
|
2951
|
+
const splitted = split.slice();
|
|
2952
|
+
if (splitted.length > 1) {
|
|
2953
|
+
// prefs.push(splitted.shift() as any)
|
|
2954
|
+
// eslint-disable-next-line no-loops/no-loops
|
|
2955
|
+
while (splitted.length > 0 && (!_val)) {
|
|
2956
|
+
if (values[splitted.join('-')]) {
|
|
2957
|
+
_key = splitted.join('-');
|
|
2958
|
+
_val = values[_key];
|
|
2959
|
+
if (_val) {
|
|
2960
|
+
break;
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
else {
|
|
2964
|
+
const pref = splitted.shift();
|
|
2965
|
+
prefs.push(pref);
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
if (_val && _key) {
|
|
2971
|
+
const dataKey = `${prefs.length > 0 ? prefs.join('-') + "-" : ''}${camelToKebab(_key)}`;
|
|
2972
|
+
if (shorthand_key.length > 0) {
|
|
2973
|
+
shorthands_array.push(dataKey);
|
|
2974
|
+
}
|
|
2975
|
+
let dict = { [dataKey]: _val };
|
|
2976
|
+
let cc = wrapValues(dict, kebabArrayString(properties));
|
|
2977
|
+
short_result = Object.assign(Object.assign({}, short_result), cc);
|
|
2978
|
+
normal_short_result = Object.assign(Object.assign({}, normal_short_result), cc);
|
|
2979
|
+
continue;
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
if (shorthand_key.length > 0) {
|
|
2983
|
+
shorthands_array.push(`${shorthand_key}-`);
|
|
2984
|
+
}
|
|
2985
|
+
const prefixed = flattenCssObjects(values, `${shorthand_key}`, `${shorthand_key}`, false, false, '-', kebabArrayString(properties), shorthands_array);
|
|
2986
|
+
short_result = Object.assign(Object.assign({}, short_result), prefixed);
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
result = Object.assign(Object.assign({}, result), { [k]: short_result });
|
|
2991
|
+
flattenedClassMap = Object.assign(Object.assign({}, flattenedClassMap), short_result);
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
return { result, normal_result, result_variants, cssMap, flattenedClassMap, styles_schemes, wrappedClassMap, cssString, shorthands_array };
|
|
2996
|
+
};
|
|
2997
|
+
function convertSelectors(cssString) {
|
|
2998
|
+
// Pattern 1: Simple attributes like :aria-hidden or :data-open
|
|
2999
|
+
let converted = cssString;
|
|
3000
|
+
converted = converted.replace(/(?::|^)((?:aria|data)-)\[([^=]+)=?([^\]]+)?\]/g, (match, type, attr, value) => {
|
|
3001
|
+
// Remove any quotes from the value and attribute
|
|
3002
|
+
attr = attr.replace(/['"]/g, '');
|
|
3003
|
+
if (value) {
|
|
3004
|
+
value = value.replace(/['"]/g, '');
|
|
3005
|
+
return `[${type}${attr}="${value}"]`;
|
|
3006
|
+
}
|
|
3007
|
+
else {
|
|
3008
|
+
return `[${type}${attr}="true"]`;
|
|
3009
|
+
}
|
|
3010
|
+
});
|
|
3011
|
+
// Pattern 2: Simple attributes
|
|
3012
|
+
converted = converted.replace(/(?::|^)((?:aria|data)-[a-zA-Z]+)\b/g, (match, type) => {
|
|
3013
|
+
return `[${type}="true"]`;
|
|
3014
|
+
});
|
|
3015
|
+
return `&${converted}`;
|
|
3016
|
+
}
|
|
3017
|
+
const replaceAllMain = (object, parents = []) => {
|
|
3018
|
+
const obj = Object.assign({}, object);
|
|
3019
|
+
let result = {};
|
|
3020
|
+
const emptyKey = '';
|
|
3021
|
+
for (const key in obj) {
|
|
3022
|
+
if (obj.hasOwnProperty(key)) {
|
|
3023
|
+
if (key === "" || key === 'main') {
|
|
3024
|
+
if (checkType(obj[key]).is_object) {
|
|
3025
|
+
const _p = parents.slice();
|
|
3026
|
+
_p.push(key);
|
|
3027
|
+
result = Object.assign(Object.assign({}, result), replaceAllMain(obj[key], _p));
|
|
3028
|
+
}
|
|
3029
|
+
else {
|
|
3030
|
+
result = Object.assign(Object.assign({}, result), { [emptyKey]: obj[key] });
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
else {
|
|
3034
|
+
const jitP = getJitProps().find(p => p.name === key || `:${p.name}` === key || replaceClassSelf(p.selector) === replaceClassSelf(key));
|
|
3035
|
+
let _key = key;
|
|
3036
|
+
if (jitP) {
|
|
3037
|
+
_key = jitP.selector;
|
|
3038
|
+
}
|
|
3039
|
+
else if (key.startsWith(':aria-') || key.startsWith(':data-')) {
|
|
3040
|
+
_key = convertSelectors(key);
|
|
3041
|
+
}
|
|
3042
|
+
if (checkType(obj[key]).is_object && Object.keys(obj[key]).length > 0) {
|
|
3043
|
+
const _p = parents.slice();
|
|
3044
|
+
_p.push(key);
|
|
3045
|
+
if (Array.isArray(_key)) {
|
|
3046
|
+
updateValueDeep(result, _key, replaceAllMain(obj[key]));
|
|
3047
|
+
// _key.forEach(k=>{
|
|
3048
|
+
// result = {...result, [`${k}`]: replaceAllMain(obj[key])}
|
|
3049
|
+
// })
|
|
3050
|
+
}
|
|
3051
|
+
else {
|
|
3052
|
+
result = Object.assign(Object.assign({}, result), { [`${_key}`]: replaceAllMain(obj[key]) });
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
else {
|
|
3056
|
+
if (key === 'placeholderColor' || key === 'placeholder-color') {
|
|
3057
|
+
result = Object.assign(Object.assign({}, result), { [':placeholder']: { [`${_key}`]: obj[key] } });
|
|
3058
|
+
}
|
|
3059
|
+
else if (key.startsWith("space-")) {
|
|
3060
|
+
result = Object.assign(Object.assign({}, result), { ['{& >:not([hidden]) ~ :not([hidden])}']: { [`${_key}`]: obj[key] } });
|
|
3061
|
+
}
|
|
3062
|
+
else {
|
|
3063
|
+
if (Array.isArray(_key)) {
|
|
3064
|
+
updateValueDeep(result, _key, replaceAllMain(obj[key]));
|
|
3065
|
+
// _key.forEach(k=>{
|
|
3066
|
+
// result = {...result, [`${k}`]: obj[key]}
|
|
3067
|
+
// })
|
|
3068
|
+
}
|
|
3069
|
+
else {
|
|
3070
|
+
result = Object.assign(Object.assign({}, result), { [`${_key}`]: obj[key] });
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
return result;
|
|
3078
|
+
};
|
|
3079
|
+
const hasSelfSelector = (text) => {
|
|
3080
|
+
const content = checkSelectorScheme(text);
|
|
3081
|
+
if (content && content.content_valid) {
|
|
3082
|
+
return content;
|
|
3083
|
+
}
|
|
3084
|
+
return null;
|
|
3085
|
+
};
|
|
3086
|
+
const replaceSelfSelector = (text, replaceValue) => {
|
|
3087
|
+
let key = text;
|
|
3088
|
+
const selectorMatch = hasSelfSelector(key);
|
|
3089
|
+
if (selectorMatch) {
|
|
3090
|
+
key = key.replace(selectorMatch.replace_value, replaceValue);
|
|
3091
|
+
}
|
|
3092
|
+
return key;
|
|
3093
|
+
};
|
|
3094
|
+
const replaceCodeSelector = (text, replaceValue = '') => {
|
|
3095
|
+
let key = text;
|
|
3096
|
+
if (key.startsWith('<')) {
|
|
3097
|
+
key = replaceString(key, '\\<', true, replaceValue);
|
|
3098
|
+
}
|
|
3099
|
+
if (key.endsWith('>')) {
|
|
3100
|
+
key = replaceString(key, '\\>', false, replaceValue);
|
|
3101
|
+
}
|
|
3102
|
+
return key;
|
|
3103
|
+
};
|
|
3104
|
+
const findSiblingName = (str) => {
|
|
3105
|
+
const start = SIBLINGS_PSEUDO.slice().find(sibling => str.startsWith(sibling));
|
|
3106
|
+
return start;
|
|
3107
|
+
};
|
|
3108
|
+
const getStringBetweenTagsMemo = memoizeFn(getStringBetweenTags);
|
|
3109
|
+
const getPreselector = (object) => {
|
|
3110
|
+
const r = Object.assign({}, object);
|
|
3111
|
+
let prefixedKey = '';
|
|
3112
|
+
let suffixKey = '';
|
|
3113
|
+
if (Object.keys(r).length > 0) {
|
|
3114
|
+
const style_keys = [];
|
|
3115
|
+
for (const spk in r) {
|
|
3116
|
+
let _objKey = spk;
|
|
3117
|
+
if (_objKey.startsWith('.')) {
|
|
3118
|
+
_objKey = replaceString(_objKey, '.', true, '');
|
|
3119
|
+
}
|
|
3120
|
+
if (checkType(r[spk]).is_object && SIBLINGS_PSEUDO.slice().some(sibling => _objKey.startsWith(sibling))) {
|
|
3121
|
+
style_keys.push(spk);
|
|
3122
|
+
const sp = splitString(_objKey, COLON_REGEX);
|
|
3123
|
+
for (const _ss of sp) {
|
|
3124
|
+
const ss = replaceString(_ss, '.', true, '');
|
|
3125
|
+
const siblingModiferName = findSiblingName(ss);
|
|
3126
|
+
if (siblingModiferName) {
|
|
3127
|
+
const noModifierName = ss.replace(`${siblingModiferName}`, '');
|
|
3128
|
+
const standardModifComposition = noModifierName.split(ACCOLADE_SPLIT_REGEX).filter(a => a !== undefined && a.length > 0);
|
|
3129
|
+
const standardModifiers = standardModifComposition.flatMap(mod => {
|
|
3130
|
+
// const br = extractExactBrackets(mod.trim(), '', '{');
|
|
3131
|
+
// if(br){
|
|
3132
|
+
// if(br.startsWith(':'))
|
|
3133
|
+
// }else{
|
|
3134
|
+
// return mod;
|
|
3135
|
+
// }
|
|
3136
|
+
return `{${replaceSelfSelector(extractExactBrackets(mod.trim(), '', '{') || mod, '')}}`;
|
|
3137
|
+
}); // style in format like {styleName}
|
|
3138
|
+
let newKey = `.${siblingModiferName}` + `${standardModifiers.join('')}`;
|
|
3139
|
+
let modifOrder = getStringBetweenTagsMemo(newKey); // style in format like <&_styleName>
|
|
3140
|
+
let fromBrackets = false;
|
|
3141
|
+
if (modifOrder.length === 0) {
|
|
3142
|
+
const modifbrackets = extractExactBrackets(newKey, `.${siblingModiferName}`);
|
|
3143
|
+
if (modifbrackets) {
|
|
3144
|
+
modifOrder = [modifbrackets];
|
|
3145
|
+
fromBrackets = true;
|
|
3146
|
+
}
|
|
3147
|
+
}
|
|
3148
|
+
if (modifOrder.length > 0) {
|
|
3149
|
+
const suff = modifOrder.slice().flatMap(f => (replaceSelfSelector(replaceCodeSelector(fromBrackets ? `[${f}]` : f), '')));
|
|
3150
|
+
newKey = newKey.replace(TAG_DYNAMIC_REGEX, '');
|
|
3151
|
+
suffixKey += ' ' + `${suff.join(' ')}`;
|
|
3152
|
+
}
|
|
3153
|
+
prefixedKey += `${prefixedKey.length > 0 ? ' ' : ''}${newKey}`;
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
// const spk = style_keys.slice()[0];
|
|
3159
|
+
// Object.keys(r).forEach(spk=>{
|
|
3160
|
+
// })
|
|
3161
|
+
if (style_keys.length > 0) {
|
|
3162
|
+
prefixedKey += ' ';
|
|
3163
|
+
let newValue = {};
|
|
3164
|
+
for (const __key of style_keys) {
|
|
3165
|
+
newValue = Object.assign(Object.assign({}, newValue), Object.assign({}, r)[__key]);
|
|
3166
|
+
}
|
|
3167
|
+
// style_keys.forEach(gp=>{
|
|
3168
|
+
// })
|
|
3169
|
+
return { style_keys, newValue, prefixedKey, suffixKey };
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
return null;
|
|
3173
|
+
};
|
|
3174
|
+
const styleMapMemo = memoizeFn(getStylesMap);
|
|
3175
|
+
const makeImportantFn = (styleString) => {
|
|
3176
|
+
// Split into individual style declarations
|
|
3177
|
+
return styleString.replace(/;(?!\s*$)/g, ' !important;')
|
|
3178
|
+
.replace(/;$/, ' !important;');
|
|
3179
|
+
};
|
|
3180
|
+
// eslint-disable-next-line no-unused-vars
|
|
3181
|
+
export const getJustInTimeStyles = (main_selector, _style_string, _isImportant = false, global_config, config, element, parents = []) => {
|
|
3182
|
+
const cache_key = main_selector + _style_string;
|
|
3183
|
+
if (state.cachedJit.get(cache_key) !== undefined) {
|
|
3184
|
+
return state.cachedJit.get(cache_key);
|
|
3185
|
+
}
|
|
3186
|
+
whiteListPurge = [];
|
|
3187
|
+
if (_style_string.length === 0) {
|
|
3188
|
+
return null;
|
|
3189
|
+
}
|
|
3190
|
+
try {
|
|
3191
|
+
let isNegative = false;
|
|
3192
|
+
let isImportant = _isImportant;
|
|
3193
|
+
let style_string = _style_string;
|
|
3194
|
+
// const reg = getClassSchemeRegex();
|
|
3195
|
+
// if(!reg.exec(_style_string)){
|
|
3196
|
+
// return null
|
|
3197
|
+
// }
|
|
3198
|
+
const important = isImportantFn(style_string);
|
|
3199
|
+
if (important) {
|
|
3200
|
+
style_string = important.str;
|
|
3201
|
+
isImportant = true;
|
|
3202
|
+
}
|
|
3203
|
+
if (important === null) {
|
|
3204
|
+
isImportant = false;
|
|
3205
|
+
}
|
|
3206
|
+
if (style_string.startsWith('-')) {
|
|
3207
|
+
isNegative = true;
|
|
3208
|
+
style_string = replaceString(style_string, '-', true, '');
|
|
3209
|
+
}
|
|
3210
|
+
const st = styleMapMemo(style_string, style_string, element, config);
|
|
3211
|
+
if (st.isNegative) {
|
|
3212
|
+
isNegative = st.isNegative;
|
|
3213
|
+
}
|
|
3214
|
+
if (st.isImportant) {
|
|
3215
|
+
isImportant = st.isImportant;
|
|
3216
|
+
}
|
|
3217
|
+
let prefixedKey = '';
|
|
3218
|
+
let suffixKey = '';
|
|
3219
|
+
if (!st.style) {
|
|
3220
|
+
return null;
|
|
3221
|
+
}
|
|
3222
|
+
if (st.style.value) {
|
|
3223
|
+
let value = st.style.value;
|
|
3224
|
+
let selector = formatClassName(main_selector, true);
|
|
3225
|
+
if (important) {
|
|
3226
|
+
value = makeImportantFn(value);
|
|
3227
|
+
}
|
|
3228
|
+
return { styles: value.replace(/&/g, selector), classes: [...whiteListPurge.slice()] };
|
|
3229
|
+
}
|
|
3230
|
+
if (st.isNegative) {
|
|
3231
|
+
isNegative = st.isNegative;
|
|
3232
|
+
}
|
|
3233
|
+
const rr = Object.assign({}, st.style);
|
|
3234
|
+
if (rr) {
|
|
3235
|
+
let r = replaceAllMain(rr);
|
|
3236
|
+
const k = Object.keys(r)[0];
|
|
3237
|
+
if (k && k.length > 0 && (k.startsWith('.group') || k.startsWith('.peer'))) {
|
|
3238
|
+
const presetSelector = getPreselector(r);
|
|
3239
|
+
if (presetSelector) {
|
|
3240
|
+
prefixedKey = presetSelector.prefixedKey;
|
|
3241
|
+
suffixKey = presetSelector.suffixKey;
|
|
3242
|
+
r = Object.assign({}, presetSelector.newValue);
|
|
3243
|
+
}
|
|
3244
|
+
hasGroup = false;
|
|
3245
|
+
}
|
|
3246
|
+
r = kebabObjectKeys(Object.assign({}, r), getCssProperties());
|
|
3247
|
+
const selectorName = `${prefixedKey}${main_selector}${suffixKey}`;
|
|
3248
|
+
const key = Object.keys(r)[0];
|
|
3249
|
+
if (key &&
|
|
3250
|
+
((typeof r[key] === 'string' && r[key].length > 0) ||
|
|
3251
|
+
(typeof r[key] === 'number') ||
|
|
3252
|
+
(checkType(r[key]).is_object && Object.keys(r[key]).length > 0))) {
|
|
3253
|
+
let selector = formatClassName(selectorName, true);
|
|
3254
|
+
const css_styles = objectToCss(r, '', 'xxx', isNegative, isImportant, 0, _style_string === 'bg-accent-300' || _style_string === 'dark:bg-white').replace(/xxx/g, selector);
|
|
3255
|
+
const result = {
|
|
3256
|
+
style_object: r,
|
|
3257
|
+
styles: css_styles,
|
|
3258
|
+
classes: [...whiteListPurge.slice()],
|
|
3259
|
+
};
|
|
3260
|
+
whiteListPurge = [];
|
|
3261
|
+
state.cachedJit.set(cache_key, result);
|
|
3262
|
+
return result;
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
catch (e) {
|
|
3267
|
+
console.error('exception catched while building', { e });
|
|
3268
|
+
logger(`[Fluixi Css ⚠️]`, `cannot build styles ${_style_string} ${main_selector}`);
|
|
3269
|
+
}
|
|
3270
|
+
state.cachedJit.set(cache_key, null);
|
|
3271
|
+
return null;
|
|
3272
|
+
};
|
|
3273
|
+
export const standardizeConfig = (values, property, _parent) => {
|
|
3274
|
+
var _c;
|
|
3275
|
+
// Early return for non-objects
|
|
3276
|
+
if (!checkType(values).is_object) {
|
|
3277
|
+
return { values };
|
|
3278
|
+
}
|
|
3279
|
+
// Find parent if not provided
|
|
3280
|
+
const parent = _parent || findParentConfigMemo(property);
|
|
3281
|
+
if (!parent) {
|
|
3282
|
+
return { values: {} };
|
|
3283
|
+
}
|
|
3284
|
+
// Get default config for this property
|
|
3285
|
+
const defaultConfig = (_c = UtilitiesPropertiesConfig[parent]) === null || _c === void 0 ? void 0 : _c[property];
|
|
3286
|
+
if (!defaultConfig) {
|
|
3287
|
+
return { values: {} };
|
|
3288
|
+
}
|
|
3289
|
+
// Extract config parts
|
|
3290
|
+
const { values: configValues, shorthands: configShorthands, variants: configVariants } = extractConfigPartsMemo(values);
|
|
3291
|
+
return {
|
|
3292
|
+
values: configValues || {},
|
|
3293
|
+
shorthands: configShorthands || defaultConfig.shorthands,
|
|
3294
|
+
variants: configVariants || defaultConfig.variants
|
|
3295
|
+
};
|
|
3296
|
+
};
|
|
3297
|
+
// Helper functions
|
|
3298
|
+
const findParentConfig = (property) => {
|
|
3299
|
+
return Object.keys(UtilitiesPropertiesConfig).find(uk => Object.keys(UtilitiesPropertiesConfig[uk]).some(uuk => uuk === property));
|
|
3300
|
+
};
|
|
3301
|
+
const extractConfigParts = (obj) => {
|
|
3302
|
+
const result = {
|
|
3303
|
+
values: {},
|
|
3304
|
+
shorthands: undefined,
|
|
3305
|
+
variants: undefined
|
|
3306
|
+
};
|
|
3307
|
+
// Handle direct values object
|
|
3308
|
+
if (obj.values) {
|
|
3309
|
+
result.values = obj.values;
|
|
3310
|
+
}
|
|
3311
|
+
else if (!obj.shorthands && !obj.variants) {
|
|
3312
|
+
// If no special keys, treat entire object as values
|
|
3313
|
+
result.values = omit(obj, ['shorthands', 'variants']);
|
|
3314
|
+
}
|
|
3315
|
+
// Handle shorthands
|
|
3316
|
+
if (obj.shorthands && checkType(obj.shorthands).is_object) {
|
|
3317
|
+
result.shorthands = obj.shorthands;
|
|
3318
|
+
}
|
|
3319
|
+
// Handle variants
|
|
3320
|
+
if (obj.variants && Array.isArray(obj.variants)) {
|
|
3321
|
+
result.variants = obj.variants;
|
|
3322
|
+
}
|
|
3323
|
+
return result;
|
|
3324
|
+
};
|
|
3325
|
+
// Memoize common operations
|
|
3326
|
+
const findParentConfigMemo = memoizeFn(findParentConfig);
|
|
3327
|
+
const extractConfigPartsMemo = memoizeFn(extractConfigParts);
|
|
3328
|
+
// Main function with memoization
|
|
3329
|
+
export const standardizeConfigMemo = memoizeFn(standardizeConfig);
|
|
3330
|
+
// export const standardizeConfig = (values: any, property: string, _parent?: string)=>{
|
|
3331
|
+
// const object = {...values as any}
|
|
3332
|
+
// const obj = {...object as any};
|
|
3333
|
+
// let parent = _parent;
|
|
3334
|
+
// if(!UtilitiesPropertiesConfig[parent || '']){
|
|
3335
|
+
// parent = Object.keys(UtilitiesPropertiesConfig).find(uk=>Object.keys(UtilitiesPropertiesConfig[uk]).some(uuk=>uuk===property));
|
|
3336
|
+
// }
|
|
3337
|
+
// if(!parent){
|
|
3338
|
+
// return {}
|
|
3339
|
+
// }
|
|
3340
|
+
// if(checkType(obj).is_object){
|
|
3341
|
+
// let res = {};
|
|
3342
|
+
// let hasValues = false;
|
|
3343
|
+
// let hasShorthands = false
|
|
3344
|
+
// let hasVariants = false
|
|
3345
|
+
// let val: any;
|
|
3346
|
+
// let sh: any;
|
|
3347
|
+
// let vr: any;
|
|
3348
|
+
// for(const k in obj){
|
|
3349
|
+
// if(obj.hasOwnProperty(k)){
|
|
3350
|
+
// if(k==='values' && (checkType(obj[k]).is_object || checkType(obj[k]).is_array)){
|
|
3351
|
+
// hasValues = true
|
|
3352
|
+
// val = {[k]: {...obj}[k]}
|
|
3353
|
+
// }else if(k==='shorthands' && checkType(obj[k]).is_object){
|
|
3354
|
+
// hasShorthands = true;
|
|
3355
|
+
// sh = {[k]: {...obj}[k]}
|
|
3356
|
+
// }else if(k==='variants' && checkType(obj[k]).is_array){
|
|
3357
|
+
// hasVariants = true
|
|
3358
|
+
// vr = {[k]:{...obj}[k]}
|
|
3359
|
+
// }
|
|
3360
|
+
// }
|
|
3361
|
+
// }
|
|
3362
|
+
// if(!hasValues){
|
|
3363
|
+
// val = omit({...obj}, ['shorthands', 'variants']);
|
|
3364
|
+
// }
|
|
3365
|
+
// if(!hasShorthands){
|
|
3366
|
+
// const _sh = UtilitiesPropertiesConfig[parent][property].shorthands;
|
|
3367
|
+
// sh = {shorthands: _sh}
|
|
3368
|
+
// }
|
|
3369
|
+
// if(!hasVariants){
|
|
3370
|
+
// const _vr = UtilitiesPropertiesConfig[parent][property].variants;
|
|
3371
|
+
// vr = {variants: _vr}
|
|
3372
|
+
// }
|
|
3373
|
+
// if(val){
|
|
3374
|
+
// if(!val.values){
|
|
3375
|
+
// val = {values: val}
|
|
3376
|
+
// }
|
|
3377
|
+
// res = {...res, ...val, ...sh, ...vr};
|
|
3378
|
+
// return res;
|
|
3379
|
+
// }
|
|
3380
|
+
// for(const k in obj){
|
|
3381
|
+
// if(obj.hasOwnProperty(k)){
|
|
3382
|
+
// if(k==='variants' || k==='shorthands'){
|
|
3383
|
+
// res = {...res, [k]: obj[k]}
|
|
3384
|
+
// }else if(checkType(obj[k]).is_object){
|
|
3385
|
+
// if(k==='values'){
|
|
3386
|
+
// res = {...res, [k]: standardizeConfig(obj[k], property, parent)}
|
|
3387
|
+
// }else{
|
|
3388
|
+
// res = {...res, [k]: obj[k]}
|
|
3389
|
+
// }
|
|
3390
|
+
// }else{
|
|
3391
|
+
// res = {...res, [k]: obj[k]}
|
|
3392
|
+
// }
|
|
3393
|
+
// }
|
|
3394
|
+
// }
|
|
3395
|
+
// return res
|
|
3396
|
+
// }
|
|
3397
|
+
// return obj;
|
|
3398
|
+
// }
|
|
3399
|
+
// export const filterStandard = (values: any)=>{
|
|
3400
|
+
// const obj = {...values as any};
|
|
3401
|
+
// let result = {} as any;
|
|
3402
|
+
// let flattened_result = {} as any;
|
|
3403
|
+
// let no_values = {} as any;
|
|
3404
|
+
// for(const k in {...obj as any}){
|
|
3405
|
+
// if(obj.hasOwnProperty(k)){
|
|
3406
|
+
// let res = {} as any
|
|
3407
|
+
// for(const o in obj[k]){
|
|
3408
|
+
// if(obj[k].hasOwnProperty(o)){
|
|
3409
|
+
// const data = standardizeConfigMemo(obj[k][o], o, k);
|
|
3410
|
+
// res = {...res, [o]: data}
|
|
3411
|
+
// no_values = {...no_values, [o]:data.values}
|
|
3412
|
+
// }
|
|
3413
|
+
// }
|
|
3414
|
+
// result = {...result, [k]: res}
|
|
3415
|
+
// flattened_result = {...flattened_result, ...res}
|
|
3416
|
+
// }
|
|
3417
|
+
// }
|
|
3418
|
+
// return {result, flattened_result, no_values};
|
|
3419
|
+
// }
|
|
3420
|
+
export const filterStandard = (values) => {
|
|
3421
|
+
// Early return for invalid input
|
|
3422
|
+
if (!values || typeof values !== 'object') {
|
|
3423
|
+
return { result: {}, flattened_result: {}, no_values: {} };
|
|
3424
|
+
}
|
|
3425
|
+
const result = {};
|
|
3426
|
+
const flattened_result = {};
|
|
3427
|
+
const no_values = {};
|
|
3428
|
+
// Single loop through top-level keys
|
|
3429
|
+
Object.entries(values).forEach(([k, kValue]) => {
|
|
3430
|
+
if (!kValue || typeof kValue !== 'object')
|
|
3431
|
+
return;
|
|
3432
|
+
// Process inner object entries
|
|
3433
|
+
const innerResult = {};
|
|
3434
|
+
Object.entries(kValue).forEach(([o, oValue]) => {
|
|
3435
|
+
const data = standardizeConfigMemo(oValue, o, k);
|
|
3436
|
+
innerResult[o] = data;
|
|
3437
|
+
no_values[o] = data.values;
|
|
3438
|
+
flattened_result[o] = data;
|
|
3439
|
+
});
|
|
3440
|
+
result[k] = innerResult;
|
|
3441
|
+
});
|
|
3442
|
+
return { result, flattened_result, no_values };
|
|
3443
|
+
};
|
|
3444
|
+
export const wrappClassMap = (themeValues, classMap) => {
|
|
3445
|
+
if ((!themeValues || !checkType(themeValues).is_object) || (!classMap || !checkType(classMap).is_object)) {
|
|
3446
|
+
return {};
|
|
3447
|
+
}
|
|
3448
|
+
let _classMapWrapped = {};
|
|
3449
|
+
const values = Object.assign({}, themeValues);
|
|
3450
|
+
for (const k in Object.assign({}, values)) {
|
|
3451
|
+
if (values.hasOwnProperty(k)) {
|
|
3452
|
+
const val = pick(classMap, Object.keys(values[k]));
|
|
3453
|
+
if (val && Object.keys(val).length > 0) {
|
|
3454
|
+
_classMapWrapped = Object.assign(Object.assign({}, _classMapWrapped), { [k]: val });
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3458
|
+
return _classMapWrapped;
|
|
3459
|
+
};
|
|
3460
|
+
const mergeNestedMemo = memoizeFn(mergeNestedObjects);
|
|
3461
|
+
/**
|
|
3462
|
+
* This function is used to merge the theme's extend with the main
|
|
3463
|
+
* style values. It will override the main style values with the
|
|
3464
|
+
* values from the extend object.
|
|
3465
|
+
* @param {Object} data - The theme's object
|
|
3466
|
+
* @param {string} key - The key to get the extended value from
|
|
3467
|
+
* @return {Object} The merged object
|
|
3468
|
+
*/
|
|
3469
|
+
const getExtendedValueWithOverrided = (data, key) => {
|
|
3470
|
+
// Get the extend object from the data
|
|
3471
|
+
const extendedData = (pick(data, ['extend']) || { extend: {} }).extend || {};
|
|
3472
|
+
// Get the overrided data from the data
|
|
3473
|
+
const overridedData = omit(data, ['extend']) || {};
|
|
3474
|
+
// if(Object.keys(overridedData).length>0){
|
|
3475
|
+
// return {...overridedData};
|
|
3476
|
+
// }
|
|
3477
|
+
// Get the main data from the key
|
|
3478
|
+
const mainData = omit(Object.assign({}, DEFAULT_THEME_CONFIG.theme)[key], ['extend']);
|
|
3479
|
+
// Merge the main data with the extended data
|
|
3480
|
+
const used = omit(mergeNestedMemo(mainData, extendedData), Object.keys(overridedData));
|
|
3481
|
+
// Override the main data with the overrided data
|
|
3482
|
+
const result = mapObjects(used, overridedData);
|
|
3483
|
+
return result;
|
|
3484
|
+
};
|
|
3485
|
+
const parseMode = (mode, key) => {
|
|
3486
|
+
let result = key;
|
|
3487
|
+
if (typeof mode === 'object') {
|
|
3488
|
+
if (typeof mode[key] === 'string') {
|
|
3489
|
+
result = mode[key];
|
|
3490
|
+
}
|
|
3491
|
+
else if (typeof mode[key] === 'object') {
|
|
3492
|
+
if (Array.isArray(mode[key])) {
|
|
3493
|
+
if (mode[key][0] === 'selector' && mode[key][1] !== undefined) {
|
|
3494
|
+
result = mode[key][1];
|
|
3495
|
+
}
|
|
3496
|
+
else {
|
|
3497
|
+
result = mode[key][0];
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
else {
|
|
3501
|
+
if (mode[key] !== undefined && mode[key].selector !== undefined) {
|
|
3502
|
+
result = mode[key].selector;
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3506
|
+
}
|
|
3507
|
+
return result;
|
|
3508
|
+
};
|
|
3509
|
+
// export const objectToCssString = (obj: Record<string, any>, parent = '', replacementWord = '&'): string => {
|
|
3510
|
+
// let css = '';
|
|
3511
|
+
// for (const [key, value] of Object.entries(obj)) {
|
|
3512
|
+
// // Handle nested selectors and media queries
|
|
3513
|
+
// if (typeof value === 'object' && value !== null) {
|
|
3514
|
+
// // Handle @media, @supports, etc
|
|
3515
|
+
// if (key.startsWith('@')) {
|
|
3516
|
+
// css += `${key} {\n${objectToCss(value, '', replacementWord)}\n}\n`;
|
|
3517
|
+
// } else {
|
|
3518
|
+
// // Handle nested selectors
|
|
3519
|
+
// const selector = parent
|
|
3520
|
+
// ? key.split(',')
|
|
3521
|
+
// .map(k =>
|
|
3522
|
+
// k.trim().startsWith(replacementWord)
|
|
3523
|
+
// ? k.replace(new RegExp(replacementWord, 'g'), parent)
|
|
3524
|
+
// : `${parent} ${k}`
|
|
3525
|
+
// )
|
|
3526
|
+
// .join(',')
|
|
3527
|
+
// : key;
|
|
3528
|
+
// css += objectToCss(value, selector, replacementWord);
|
|
3529
|
+
// }
|
|
3530
|
+
// } else {
|
|
3531
|
+
// // Handle property-value pairs
|
|
3532
|
+
// if (parent) {
|
|
3533
|
+
// if (!css.includes(parent + ' {')) {
|
|
3534
|
+
// css += `${parent} {\n`;
|
|
3535
|
+
// }
|
|
3536
|
+
// css += ` ${camelToKebab(key)}: ${value};\n`;
|
|
3537
|
+
// if (!css.endsWith('}\n')) {
|
|
3538
|
+
// css += '}\n';
|
|
3539
|
+
// }
|
|
3540
|
+
// } else {
|
|
3541
|
+
// css += `${camelToKebab(key)}: ${value};\n`;
|
|
3542
|
+
// }
|
|
3543
|
+
// }
|
|
3544
|
+
// }
|
|
3545
|
+
// return css;
|
|
3546
|
+
// };
|
|
3547
|
+
export const objectToCssString = (obj, parent = '', replacementWord = '&') => {
|
|
3548
|
+
let css = '';
|
|
3549
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
3550
|
+
// Handle nested selectors and media queries
|
|
3551
|
+
if (typeof value === 'object' && value !== null) {
|
|
3552
|
+
// Handle @media, @supports, etc
|
|
3553
|
+
if (key.startsWith('@')) {
|
|
3554
|
+
css += `${key} {\n${objectToCssString(value, '', replacementWord)}\n}\n`;
|
|
3555
|
+
}
|
|
3556
|
+
else {
|
|
3557
|
+
// Handle nested selectors
|
|
3558
|
+
const selector = parent
|
|
3559
|
+
? key.split(',')
|
|
3560
|
+
.map(k => k.trim().startsWith(replacementWord)
|
|
3561
|
+
? k.replace(new RegExp(replacementWord, 'g'), parent)
|
|
3562
|
+
: `${parent} ${k}`)
|
|
3563
|
+
.join(',')
|
|
3564
|
+
: key;
|
|
3565
|
+
css += objectToCssString(value, selector, replacementWord);
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
else {
|
|
3569
|
+
// Handle property-value pairs
|
|
3570
|
+
if (parent) {
|
|
3571
|
+
if (!css.includes(parent + ' {')) {
|
|
3572
|
+
css += `${parent} {\n`;
|
|
3573
|
+
}
|
|
3574
|
+
css += ` ${camelToKebab(key)}: ${value};\n`;
|
|
3575
|
+
if (!css.endsWith('}\n')) {
|
|
3576
|
+
css += '}\n';
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
else {
|
|
3580
|
+
css += `${camelToKebab(key)}: ${value};\n`;
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
return css;
|
|
3585
|
+
};
|
|
3586
|
+
export const ConfigurePlugins = (utilities, plugins) => {
|
|
3587
|
+
try {
|
|
3588
|
+
let { base, utilitiesMap: utilitiesMap = {}, classMapFlattened, components = {}, variants: variants = [] } = utilities;
|
|
3589
|
+
for (const plugin of plugins) {
|
|
3590
|
+
plugin({
|
|
3591
|
+
theme: (path) => getNestedValue(`${path}`),
|
|
3592
|
+
addBase: (styles) => {
|
|
3593
|
+
Object.keys(styles).forEach(k => {
|
|
3594
|
+
if (styles.hasOwnProperty(k)) {
|
|
3595
|
+
if (base.hasOwnProperty(k)) {
|
|
3596
|
+
base[k] = Object.assign(Object.assign({}, base[k]), styles[k]);
|
|
3597
|
+
}
|
|
3598
|
+
else {
|
|
3599
|
+
base[k] = styles[k];
|
|
3600
|
+
}
|
|
3601
|
+
}
|
|
3602
|
+
});
|
|
3603
|
+
if (Object.keys(styles).length > 0) {
|
|
3604
|
+
// state.setThemeUtilities({base: {...base}})
|
|
3605
|
+
}
|
|
3606
|
+
},
|
|
3607
|
+
addUtilities: (styles) => {
|
|
3608
|
+
Object.keys(styles).forEach(k => {
|
|
3609
|
+
if (styles.hasOwnProperty(k)) {
|
|
3610
|
+
// const classKey = k.startsWith('.') ? k : `.${k}`;
|
|
3611
|
+
const key = k.startsWith('.') ? k.slice(1) : k;
|
|
3612
|
+
utilitiesMap[`${key}`] = objectToCssString({ [k]: styles[k] });
|
|
3613
|
+
classMapFlattened[`${key}`] = styles[k];
|
|
3614
|
+
}
|
|
3615
|
+
});
|
|
3616
|
+
if (Object.keys(styles).length > 0) {
|
|
3617
|
+
state.setThemeUtilities({ utilitiesMap: Object.assign({}, utilitiesMap) });
|
|
3618
|
+
state.setThemeUtilities({ classMapFlattened: Object.assign({}, classMapFlattened) });
|
|
3619
|
+
}
|
|
3620
|
+
},
|
|
3621
|
+
addComponents: (styles) => {
|
|
3622
|
+
Object.keys(styles).forEach(k => {
|
|
3623
|
+
if (styles.hasOwnProperty(k)) {
|
|
3624
|
+
const key = k.startsWith('.') ? k.slice(1) : k;
|
|
3625
|
+
// const classKey = k.startsWith('.') ? k : `.${k}`;
|
|
3626
|
+
components[`${key}`] = objectToCssString({ [k]: styles[k] });
|
|
3627
|
+
classMapFlattened[`${key}`] = styles[k];
|
|
3628
|
+
}
|
|
3629
|
+
});
|
|
3630
|
+
if (Object.keys(styles).length > 0) {
|
|
3631
|
+
state.setThemeUtilities({ classMapFlattened: Object.assign({}, classMapFlattened), components: Object.assign({}, components) });
|
|
3632
|
+
}
|
|
3633
|
+
},
|
|
3634
|
+
addVariant: (name, value) => {
|
|
3635
|
+
const props = [];
|
|
3636
|
+
props.push({
|
|
3637
|
+
name: name,
|
|
3638
|
+
selector: value,
|
|
3639
|
+
tag: name
|
|
3640
|
+
});
|
|
3641
|
+
variants.push(props);
|
|
3642
|
+
// state.setVariants([...variants])
|
|
3643
|
+
}
|
|
3644
|
+
});
|
|
3645
|
+
}
|
|
3646
|
+
return { base, utilitiesMap, classMapFlattened, components, variants };
|
|
3647
|
+
}
|
|
3648
|
+
catch (e) {
|
|
3649
|
+
console.error('Error while configuring plugins', e);
|
|
3650
|
+
return null;
|
|
3651
|
+
}
|
|
3652
|
+
};
|
|
3653
|
+
const getExtendedMerged = (data, key) => {
|
|
3654
|
+
// const inInitialData = {...DEFAULT_THEME_CONFIG.theme}[key];
|
|
3655
|
+
// const inFinalData = {...data.options.theme}[key];
|
|
3656
|
+
// Get the extend object from the data
|
|
3657
|
+
const extendedData = (Object.assign({}, data).extend || {})[key] || {};
|
|
3658
|
+
// Get the overrided data from the data
|
|
3659
|
+
const overridedData = Object.assign({}, data)[key] || {};
|
|
3660
|
+
// omit(inFinalData, ['extend']) || {};
|
|
3661
|
+
// Get the main data from the key
|
|
3662
|
+
const mainData = Object.assign({}, DEFAULT_THEME_CONFIG.theme)[key];
|
|
3663
|
+
// omit({...inInitialData}, ['extend']);
|
|
3664
|
+
// Merge the main data with the extended data
|
|
3665
|
+
const used = omit(mergeNestedMemo(mainData, extendedData), Object.keys(overridedData));
|
|
3666
|
+
// Override the main data with the overrided data
|
|
3667
|
+
const result = mapObjects(used, overridedData);
|
|
3668
|
+
if (typeof result === 'object' && result && typeof result.values === 'object' && result.values && typeof result.shorthands === 'object' && result.shorthands) {
|
|
3669
|
+
return result.values;
|
|
3670
|
+
}
|
|
3671
|
+
return result;
|
|
3672
|
+
};
|
|
3673
|
+
const convertColorsToOklch = (obj) => {
|
|
3674
|
+
let result = {};
|
|
3675
|
+
Object.keys(obj).map(k => {
|
|
3676
|
+
if (checkType(obj[k]).is_object) {
|
|
3677
|
+
result[k] = convertColorsToOklch(obj[k]);
|
|
3678
|
+
}
|
|
3679
|
+
else {
|
|
3680
|
+
if (Color.isValidColor(obj[k])) {
|
|
3681
|
+
const color = Color.toOKLCH(obj[k], 'string');
|
|
3682
|
+
if (color !== null) {
|
|
3683
|
+
result[k] = color;
|
|
3684
|
+
}
|
|
3685
|
+
else {
|
|
3686
|
+
result[k] = obj[k];
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
else {
|
|
3690
|
+
result[k] = obj[k];
|
|
3691
|
+
}
|
|
3692
|
+
}
|
|
3693
|
+
});
|
|
3694
|
+
};
|
|
3695
|
+
export const generateThemeConfig = (config = {}) => {
|
|
3696
|
+
var _c;
|
|
3697
|
+
if (config && config.debug) {
|
|
3698
|
+
console.time('generate theme config');
|
|
3699
|
+
}
|
|
3700
|
+
const variables_keys = ["colors", "spacing", "sizing"];
|
|
3701
|
+
const variable_properties = [...ColorsPropertiesKeys, ...SizingPropertiesKeys, ...SpacingPropertiesKeys];
|
|
3702
|
+
let input;
|
|
3703
|
+
const options = Object.assign({}, config);
|
|
3704
|
+
// const themeColors = getExtendedValueWithOverrided(options.theme.colors, 'colors');
|
|
3705
|
+
const themeColors = getExtendedMerged(Object.assign({}, options.theme), 'colors');
|
|
3706
|
+
const themeSpacing = getExtendedMerged(Object.assign({}, options.theme), 'spacing');
|
|
3707
|
+
const themeSizing = getExtendedMerged(Object.assign({}, options.theme), 'sizing');
|
|
3708
|
+
const fontSize = getExtendedMerged(Object.assign({}, options.theme), 'fontSize');
|
|
3709
|
+
const fontFamily = getExtendedMerged(Object.assign({}, options.theme), 'fontFamily');
|
|
3710
|
+
const radius = getExtendedMerged(Object.assign({}, options.theme), 'radius');
|
|
3711
|
+
const border = getExtendedMerged(Object.assign({}, options.theme), 'border');
|
|
3712
|
+
const lightMode = parseMode(options.mode, 'light');
|
|
3713
|
+
const darkMode = parseMode(options.mode, 'dark');
|
|
3714
|
+
const mode = { light: lightMode, dark: darkMode };
|
|
3715
|
+
state.setMode(mode);
|
|
3716
|
+
const themeUtilities = options.theme;
|
|
3717
|
+
const fontSizeMatcher = (value, key) => {
|
|
3718
|
+
if (typeof value === 'object' && value && !Array.isArray(value)) {
|
|
3719
|
+
if (value.fontSize && value.lineHeight) {
|
|
3720
|
+
return true;
|
|
3721
|
+
}
|
|
3722
|
+
}
|
|
3723
|
+
return false;
|
|
3724
|
+
};
|
|
3725
|
+
let data_vars = createVars({
|
|
3726
|
+
"_colors": themeColors,
|
|
3727
|
+
"spacing": themeSizing,
|
|
3728
|
+
"sizing": themeSpacing,
|
|
3729
|
+
"text": fontSize,
|
|
3730
|
+
"font": fontFamily,
|
|
3731
|
+
radius,
|
|
3732
|
+
border
|
|
3733
|
+
}, ['_colors'], undefined, [], {
|
|
3734
|
+
matcher(value, key) {
|
|
3735
|
+
return fontSizeMatcher(value, key);
|
|
3736
|
+
},
|
|
3737
|
+
transformKey(value, key) {
|
|
3738
|
+
if (key === 'fontSize') {
|
|
3739
|
+
return;
|
|
3740
|
+
}
|
|
3741
|
+
if (key === 'lineHeight') {
|
|
3742
|
+
return '--line-height';
|
|
3743
|
+
}
|
|
3744
|
+
return key;
|
|
3745
|
+
},
|
|
3746
|
+
// transformer(value, key) {
|
|
3747
|
+
// if(fontSizeMatcher(value, key)){
|
|
3748
|
+
// return {DEFAULT: value.fontSize, 'line-height': value.lineHeight}
|
|
3749
|
+
// }
|
|
3750
|
+
// }
|
|
3751
|
+
});
|
|
3752
|
+
if (checkType(themeUtilities).is_object) {
|
|
3753
|
+
let utilities = {};
|
|
3754
|
+
for (const utility_key in themeUtilities) {
|
|
3755
|
+
const extended_utilities = Object.assign({}, themeUtilities)[utility_key];
|
|
3756
|
+
if (utility_key === 'extend') {
|
|
3757
|
+
for (const ek in extended_utilities) {
|
|
3758
|
+
if (extended_utilities.hasOwnProperty(ek) && !variables_keys.some(k => k === ek) && ek !== 'screens' && ek !== 'keyframes' && ek !== 'components') {
|
|
3759
|
+
if (utilities[ek]) {
|
|
3760
|
+
const e = Object.assign({}, extended_utilities)[ek];
|
|
3761
|
+
const f = Object.assign({}, utilities)[ek];
|
|
3762
|
+
utilities = Object.assign(Object.assign({}, utilities), { [ek]: Object.assign({}, mergeNestedObjects(Object.assign({}, f), { values: Object.assign({}, e) })) });
|
|
3763
|
+
}
|
|
3764
|
+
else {
|
|
3765
|
+
utilities = Object.assign(Object.assign({}, utilities), { [ek]: extended_utilities[ek] });
|
|
3766
|
+
}
|
|
3767
|
+
}
|
|
3768
|
+
}
|
|
3769
|
+
}
|
|
3770
|
+
else {
|
|
3771
|
+
if (!variables_keys.some(k => k === utility_key) && utility_key !== 'screens' && utility_key !== 'keyframes' && utility_key !== 'components') {
|
|
3772
|
+
if (ColorsPropertiesKeys.some(ccp => ccp === utility_key)) {
|
|
3773
|
+
extended_utilities.values = mergeNestedObjects(Object.assign({}, Object.assign({}, extended_utilities).values), Object.assign({}, data_vars.data_values._colors));
|
|
3774
|
+
}
|
|
3775
|
+
else if (SizingPropertiesKeys.some(ccp => ccp === utility_key)) {
|
|
3776
|
+
extended_utilities.values = mergeNestedObjects(Object.assign({}, Object.assign({}, extended_utilities).values), Object.assign({}, data_vars.data_values.sizing));
|
|
3777
|
+
}
|
|
3778
|
+
else if (SpacingPropertiesKeys.some(ccp => ccp === utility_key)) {
|
|
3779
|
+
extended_utilities.values = mergeNestedObjects(Object.assign({}, Object.assign({}, extended_utilities).values), Object.assign({}, data_vars.data_values.spacing));
|
|
3780
|
+
}
|
|
3781
|
+
else if (utility_key === 'fontSize') {
|
|
3782
|
+
extended_utilities.values = mergeNestedObjects(Object.assign({}, Object.assign({}, extended_utilities).values), Object.assign({}, data_vars.data_values.text));
|
|
3783
|
+
}
|
|
3784
|
+
else if (utility_key === 'fontFamily') {
|
|
3785
|
+
extended_utilities.values = mergeNestedObjects(Object.assign({}, Object.assign({}, extended_utilities).values), Object.assign({}, data_vars.data_values.font));
|
|
3786
|
+
}
|
|
3787
|
+
else if (BorderRadiusPropertiesKeys.some(ccp => ccp === utility_key)) {
|
|
3788
|
+
extended_utilities.values = mergeNestedObjects(Object.assign({}, Object.assign({}, extended_utilities).values), Object.assign({}, data_vars.data_values.radius));
|
|
3789
|
+
}
|
|
3790
|
+
else if (BorderPropertiesKeys.some(ccp => ccp === utility_key)) {
|
|
3791
|
+
extended_utilities.values = mergeNestedObjects(Object.assign({}, Object.assign({}, extended_utilities).values), Object.assign({}, data_vars.data_values.border));
|
|
3792
|
+
}
|
|
3793
|
+
if (utilities[utility_key]) {
|
|
3794
|
+
utilities = mergeNestedObjects({ [utility_key]: Object.assign({}, extended_utilities) }, Object.assign({}, utilities));
|
|
3795
|
+
}
|
|
3796
|
+
else {
|
|
3797
|
+
utilities = Object.assign(Object.assign({}, utilities), { [utility_key]: Object.assign({}, extended_utilities) });
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
}
|
|
3802
|
+
const themeInput = wrappClassMap(UtilitiesPropertiesConfig, utilities);
|
|
3803
|
+
input = Object.assign({}, filterStandard(themeInput));
|
|
3804
|
+
}
|
|
3805
|
+
let merged = input.result;
|
|
3806
|
+
let values = input.no_values;
|
|
3807
|
+
const screens = getExtendedValueWithOverrided(options.theme.screens, 'screens');
|
|
3808
|
+
const keyframes = getExtendedValueWithOverrided(options.theme.screens, 'keyframes');
|
|
3809
|
+
const KeyframesOptions = !isUndefinedOrNull(options.theme.keyframes) ? (_c = options.theme.keyframes) === null || _c === void 0 ? void 0 : _c.options : null;
|
|
3810
|
+
const base = getExtendedValueWithOverrided(options.theme.base, 'base');
|
|
3811
|
+
state.setThemeUtilities({ screens: Object.assign({}, screens), base: Object.assign({}, base) });
|
|
3812
|
+
state.updateObject('keyframesOptions', KeyframesOptions);
|
|
3813
|
+
let vars = `${varify('color-opacity', false)}: 1;\n${data_vars.vars}`;
|
|
3814
|
+
let darkVars = '';
|
|
3815
|
+
let componentsVars = {};
|
|
3816
|
+
if (data_vars.darkVars.length > 0) {
|
|
3817
|
+
darkVars = `${varify('color-opacity', false)}: 1;${data_vars.darkVars}`;
|
|
3818
|
+
}
|
|
3819
|
+
if (config && config.debug) {
|
|
3820
|
+
console.timeEnd('generate theme config');
|
|
3821
|
+
console.time('classmapBuild');
|
|
3822
|
+
}
|
|
3823
|
+
const classMapBuild = buildClassMap(Object.assign({}, input.result));
|
|
3824
|
+
if (config && config.debug) {
|
|
3825
|
+
console.timeEnd('classmapBuild');
|
|
3826
|
+
}
|
|
3827
|
+
let utilitiesCss = {};
|
|
3828
|
+
// const classValues = {...classMapBuild.flattenedClassMap}
|
|
3829
|
+
if (config && config.debug) {
|
|
3830
|
+
console.time('generate css utilities');
|
|
3831
|
+
console.timeEnd('generate css utilities');
|
|
3832
|
+
}
|
|
3833
|
+
// for(let s in classValues){
|
|
3834
|
+
// if(classValues.hasOwnProperty(s)){
|
|
3835
|
+
// if(s.startsWith('space')){
|
|
3836
|
+
// utilitiesCss[`.${s}`] = objectToCss({["{& >:not([hidden]) ~ :not([hidden])}"]: classValues[s]}, undefined, `.${s}`, false, false, 0, false);
|
|
3837
|
+
// }else{
|
|
3838
|
+
// utilitiesCss[`.${s}`]=objectToCss(classValues[s], undefined, `.${s}`, false, false, 0, false);
|
|
3839
|
+
// }
|
|
3840
|
+
// }
|
|
3841
|
+
// }
|
|
3842
|
+
state.setThemeUtilities({ values: Object.assign({}, values) });
|
|
3843
|
+
let components_string_vars = '';
|
|
3844
|
+
if ((typeof options.theme.components !== "undefined" && ((typeof options.theme.components === 'boolean' && options.theme.components)) || (typeof options.theme.components === 'object' && !Array.isArray(options.theme.components)))) {
|
|
3845
|
+
const components = getExtendedValueWithOverrided(options.theme.components, 'components');
|
|
3846
|
+
componentsVars = parseTheme(components, input.no_values, true);
|
|
3847
|
+
const components_names = getComponentsInfos();
|
|
3848
|
+
for (const component in componentsVars) {
|
|
3849
|
+
if (componentsVars.hasOwnProperty(component)) {
|
|
3850
|
+
const l = createVars({ [component]: componentsVars[component] }, ["reset"]);
|
|
3851
|
+
vars += l.vars;
|
|
3852
|
+
darkVars += l.darkVars;
|
|
3853
|
+
}
|
|
3854
|
+
}
|
|
3855
|
+
}
|
|
3856
|
+
const plugins = options.plugins || [];
|
|
3857
|
+
const classMapFlattened = Object.assign({}, classMapBuild.flattenedClassMap);
|
|
3858
|
+
const utilities = { screens, keyframes, merged, values, classMap: Object.assign({}, classMapBuild.result), styleMap: [...classMapBuild.styles_schemes], classMapFlattened: Object.assign({}, classMapFlattened), base, utilitiesMap: utilitiesCss, shorthands_array: [...new Set([...classMapBuild.shorthands_array])], rootVars: vars, darkRootVars: darkVars, componentsVars, components_string_vars, mode, plugins };
|
|
3859
|
+
// writeFileSync(path.join(cwd(), 'data.json'), JSON.stringify({screens, keyframes, merged, values, styleMap: [...classMapBuild.styles_schemes], shorthands_array: [...new Set([...classMapBuild.shorthands_array])]}))
|
|
3860
|
+
return utilities;
|
|
3861
|
+
};
|
|
3862
|
+
//# sourceMappingURL=extractor.js.map
|