@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
package/dist/src/ast.js
ADDED
|
@@ -0,0 +1,2240 @@
|
|
|
1
|
+
var _a, _AstParser_ast, _AstParser_file, _AstParser_requireImports, _AstParser_hasImports, _AstParser_hasImportMatch, _AstParser_hasImportsDone, _AstParser_replaceSource, _AstParser_cachedJit, _AstParser_encoded_tokens, _AstParser_dependencies, _AstParser_atImportMaps, _AstParser_source, _AstParser_sourceLocations, _AstParser_initial, _AstParser_imports, _AstParser_sourceMap, _AstParser_options, _AstParser_astArray, _AstParser_mappings;
|
|
2
|
+
import { __awaiter, __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import path, { dirname, isAbsolute, join } from "node:path";
|
|
5
|
+
import { cwd } from "node:process";
|
|
6
|
+
import { parseCss, stringify as stringifyCss, walk as walkCss, cloneNodeDeep, stylesheet as makeStylesheet, rule as makeRule, atRule as makeAtRule, decl as makeDecl, } from "./css-parser";
|
|
7
|
+
import { Features, transform } from "lightningcss";
|
|
8
|
+
import { createMediaQuery, formatClassName, formatMediaQuery, getJustInTimeStyles, objectToCss, objectToCssString, state } from "./extractor";
|
|
9
|
+
import { COMMA_REGEX, isImportantFn, replaceString, splitString } from "./commons";
|
|
10
|
+
import { logger } from "./logger";
|
|
11
|
+
import DesignSystem from "./design-system";
|
|
12
|
+
import { SourceMapGenerator } from 'source-map';
|
|
13
|
+
// Fixed key and initialization vector (IV)
|
|
14
|
+
const ENCRYPTION_KEY = '1234567890123456'; // Must be 16 bytes for AES-128
|
|
15
|
+
const IV_LENGTH = 16; // For AES, this is always 16
|
|
16
|
+
// ─── CSS ident encode / decode (replaces csstree's ident.encode / ident.decode)
|
|
17
|
+
function cssIdentEncode(value) {
|
|
18
|
+
return value.replace(/([^\w-])/g, (ch) => {
|
|
19
|
+
const code = ch.charCodeAt(0);
|
|
20
|
+
return `\\${code.toString(16)} `;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function cssIdentDecode(value) {
|
|
24
|
+
return value
|
|
25
|
+
// Hex escapes first: \2c → ','
|
|
26
|
+
.replace(/\\([0-9a-fA-F]{1,6}) ?/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
|
|
27
|
+
// Short-form char escapes (lightningcss emits these): \. → '.' \, → ',' \% → '%' etc.
|
|
28
|
+
.replace(/\\([^0-9a-fA-F\r\n])/g, (_, ch) => ch);
|
|
29
|
+
}
|
|
30
|
+
/** Walk an AST and collect all nodes matching a predicate. */
|
|
31
|
+
function findAll(ast, pred) {
|
|
32
|
+
const found = [];
|
|
33
|
+
walkCss(ast, {
|
|
34
|
+
enter(node) {
|
|
35
|
+
if (pred(node))
|
|
36
|
+
found.push(node);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return found;
|
|
40
|
+
}
|
|
41
|
+
class AstParser {
|
|
42
|
+
static resolveLocalModulesPath(options) {
|
|
43
|
+
var _b;
|
|
44
|
+
const { resolveLocalPresets = false, rootHost = state ? (_b = state.config) === null || _b === void 0 ? void 0 : _b.rootHost : null } = options || {};
|
|
45
|
+
const core_base = resolveLocalPresets ? path.resolve(cwd(), 'base.css') : rootHost && rootHost.length > 0
|
|
46
|
+
? path.resolve(path.relative(cwd(), rootHost), 'node_modules', '@fluixi/css-core', 'base.css')
|
|
47
|
+
: path.resolve(cwd(), 'node_modules', '@fluixi/css-core/base.css');
|
|
48
|
+
const core_utilities = resolveLocalPresets ? path.resolve(cwd(), 'utilities.css') : rootHost && rootHost.length > 0
|
|
49
|
+
? path.resolve(path.relative(cwd(), rootHost), 'node_modules', '@fluixi/css-core', 'utilities.css')
|
|
50
|
+
: path.resolve(cwd(), 'node_modules', '@fluixi/css-core/utilities.css');
|
|
51
|
+
const core_components = resolveLocalPresets
|
|
52
|
+
? path.resolve(cwd(), 'components.css')
|
|
53
|
+
: rootHost && rootHost.length > 0
|
|
54
|
+
? path.resolve(path.relative(cwd(), rootHost), 'node_modules', '@fluixi/css-core', 'components.css')
|
|
55
|
+
: path.resolve(cwd(), 'node_modules', '@fluixi/css-core/components.css');
|
|
56
|
+
const core_reset = resolveLocalPresets
|
|
57
|
+
? path.resolve(cwd(), 'reset.css')
|
|
58
|
+
: rootHost && rootHost.length > 0
|
|
59
|
+
? path.resolve(path.relative(cwd(), rootHost), 'node_modules', '@fluixi/css-core', 'reset.css')
|
|
60
|
+
: path.resolve(cwd(), 'node_modules', '@fluixi/css-core/reset.css');
|
|
61
|
+
return { core_base, core_utilities, core_components, core_reset };
|
|
62
|
+
}
|
|
63
|
+
static resolveLocalImportsPath(path, resolveLocalPresets = false) {
|
|
64
|
+
const { core_base, core_utilities, core_components, core_reset } = this.resolveLocalModulesPath({ resolveLocalPresets });
|
|
65
|
+
const match = this.ImportsMatch[path];
|
|
66
|
+
if (match === "base") {
|
|
67
|
+
return { path: core_base, match };
|
|
68
|
+
}
|
|
69
|
+
if (match === "utilities") {
|
|
70
|
+
return { path: core_utilities, match };
|
|
71
|
+
}
|
|
72
|
+
if (match === "components") {
|
|
73
|
+
return { path: core_components, match };
|
|
74
|
+
}
|
|
75
|
+
if (match === "reset") {
|
|
76
|
+
return { path: core_reset, match };
|
|
77
|
+
}
|
|
78
|
+
return { path: path };
|
|
79
|
+
}
|
|
80
|
+
static isPluginDeclarativeName(val, prefix = true) {
|
|
81
|
+
return [..._a.PLUGIN_LAYERS, "sheet"].some(l => l === val || `${prefix ? '@' : ''}${l}` === val);
|
|
82
|
+
}
|
|
83
|
+
static decode(value, map) {
|
|
84
|
+
if (!value || value.trim().length === 0)
|
|
85
|
+
return '';
|
|
86
|
+
let result = map.get(value.trim());
|
|
87
|
+
if (!result) {
|
|
88
|
+
const starts_with = value.startsWith('"') && value.endsWith('"');
|
|
89
|
+
const inner = starts_with ? value.toString().slice(1, -1) : value;
|
|
90
|
+
const key = cssIdentEncode(cssIdentDecode(inner));
|
|
91
|
+
result = map.get(key);
|
|
92
|
+
if (result)
|
|
93
|
+
return result.from;
|
|
94
|
+
return cssIdentDecode(value);
|
|
95
|
+
}
|
|
96
|
+
return result.from;
|
|
97
|
+
}
|
|
98
|
+
static encode(value, map) {
|
|
99
|
+
let result = map.get(value);
|
|
100
|
+
if (result)
|
|
101
|
+
return result.encoded;
|
|
102
|
+
result = cssIdentEncode(value);
|
|
103
|
+
map.set(value.trim(), { encoded: result, from: value });
|
|
104
|
+
map.set(result.trim(), { encoded: result, from: value });
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
static findImports(ast) {
|
|
108
|
+
if (!ast)
|
|
109
|
+
return [];
|
|
110
|
+
const nodes = findAll(ast, n => n.type === 'atrule' && n.name === 'import');
|
|
111
|
+
return nodes.map(n => {
|
|
112
|
+
var _b, _c;
|
|
113
|
+
const val = (_c = (_b = n.preludeText) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
|
|
114
|
+
const isUrl = val.toLowerCase().startsWith('url(');
|
|
115
|
+
return {
|
|
116
|
+
name: n.name,
|
|
117
|
+
loc: n.loc,
|
|
118
|
+
type: isUrl ? 'Url' : 'String',
|
|
119
|
+
value: val,
|
|
120
|
+
node: stringifyCss(n),
|
|
121
|
+
};
|
|
122
|
+
}).filter(a => a !== null);
|
|
123
|
+
}
|
|
124
|
+
static findPluginDirectives(ast) {
|
|
125
|
+
if (!ast)
|
|
126
|
+
return [];
|
|
127
|
+
const nodes = findAll(ast, n => n.type === 'atrule' && n.name === 'fluixi');
|
|
128
|
+
return nodes.map(n => {
|
|
129
|
+
var _b, _c;
|
|
130
|
+
const val = (_c = (_b = n.preludeText) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
|
|
131
|
+
if (_a.isPluginDeclarativeName(val)) {
|
|
132
|
+
return { name: n.name, loc: n.loc, type: 'String', value: val, node: stringifyCss(n) };
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}).filter(a => a !== null);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Encrypts a string using AES-128-CBC.
|
|
139
|
+
* @param {string} text - The text to encrypt.
|
|
140
|
+
* @returns {string} - The encrypted text in base64 format.
|
|
141
|
+
*/
|
|
142
|
+
static encrypt(text) {
|
|
143
|
+
// Convert to Base64 and escape special characters
|
|
144
|
+
return Buffer.from(text, 'utf8')
|
|
145
|
+
.toString('base64')
|
|
146
|
+
.replace(/[+/=]/g, char => ({
|
|
147
|
+
'+': '-',
|
|
148
|
+
'/': '_',
|
|
149
|
+
'=': '.'
|
|
150
|
+
}[char] || char));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Decrypts a string using AES-128-CBC.
|
|
154
|
+
* @param {string} text - The text to decrypt (IV:encryptedText).
|
|
155
|
+
* @returns {string} - The decrypted text.
|
|
156
|
+
*/
|
|
157
|
+
static decrypt(text) {
|
|
158
|
+
// Restore special characters and decode Base64
|
|
159
|
+
const restored = text
|
|
160
|
+
.replace('"encrypted-', '').replace('"', '').replace(/[-_.]/g, char => ({
|
|
161
|
+
'-': '+',
|
|
162
|
+
'_': '/',
|
|
163
|
+
'.': '='
|
|
164
|
+
}[char] || char));
|
|
165
|
+
return Buffer.from(restored, 'base64').toString('utf8');
|
|
166
|
+
}
|
|
167
|
+
static parse(content, options = {
|
|
168
|
+
parseAtrulePrelude: false,
|
|
169
|
+
parseValue: false,
|
|
170
|
+
parseCustomProperty: false,
|
|
171
|
+
parseRulePrelude: false,
|
|
172
|
+
}, minify = false) {
|
|
173
|
+
return parseCss(content, Object.assign(Object.assign({}, options), { includeComments: !minify }));
|
|
174
|
+
}
|
|
175
|
+
static isSelf(str) {
|
|
176
|
+
if (str.trim().startsWith('&') || str.trim().endsWith('&')) {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
;
|
|
180
|
+
let isS = false;
|
|
181
|
+
if (!str.includes('&'))
|
|
182
|
+
return isS;
|
|
183
|
+
if (str.includes(' ')) {
|
|
184
|
+
const strings = splitString(str);
|
|
185
|
+
const a = [str];
|
|
186
|
+
if (a === strings) {
|
|
187
|
+
return isS;
|
|
188
|
+
}
|
|
189
|
+
for (const s of strings) {
|
|
190
|
+
if (this.isSelf(s)) {
|
|
191
|
+
isS = true;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return isS;
|
|
197
|
+
}
|
|
198
|
+
static findMainRule(node) {
|
|
199
|
+
if (node.kind === "rule" && !this.isSelf(node.name || ''))
|
|
200
|
+
return node;
|
|
201
|
+
let result;
|
|
202
|
+
for (const child of node.children) {
|
|
203
|
+
if (child.kind === "rule" && !this.isSelf(node.name || '')) {
|
|
204
|
+
result = child;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
else if (child.kind === "atrule" && _a.hasChildren(child)) {
|
|
208
|
+
result = _a.findMainRule(child);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
static merge(astNodes, rules = []) {
|
|
214
|
+
return astNodes.map(n => {
|
|
215
|
+
var _b, _c, _d, _e;
|
|
216
|
+
if (n.kind === 'atrule' && n.name === 'layer') {
|
|
217
|
+
const r = rules.find(rule => rule.name === n.name && rule.value === n.value);
|
|
218
|
+
if (!r) {
|
|
219
|
+
rules.push(Object.assign({}, n));
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
(_b = r.children) === null || _b === void 0 ? void 0 : _b.push(...Object.assign({}, n).children.slice());
|
|
223
|
+
n.children = [];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else if (n.kind === 'atrule' && n.name === 'import' && n.children) {
|
|
227
|
+
const layers = (_c = Object.assign({}, n).children) === null || _c === void 0 ? void 0 : _c.filter(c => c.kind === 'atrule' && c.name === 'layer');
|
|
228
|
+
const other = (_d = Object.assign({}, n).children) === null || _d === void 0 ? void 0 : _d.filter(c => !(c.kind === 'atrule' && c.name === 'layer'));
|
|
229
|
+
if (layers.length > 0) {
|
|
230
|
+
layers.forEach(l => {
|
|
231
|
+
var _b;
|
|
232
|
+
const r = rules.find(rule => rule.name === l.name && rule.value === l.value);
|
|
233
|
+
if (!r) {
|
|
234
|
+
rules.push(Object.assign({}, l));
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
(_b = r.children) === null || _b === void 0 ? void 0 : _b.push(...Object.assign({}, l).children.slice());
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
if (other.length > 0) {
|
|
242
|
+
const newRule = Object.assign({}, n);
|
|
243
|
+
newRule.children = other;
|
|
244
|
+
rules.push(newRule);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else if (n.kind === "rule") {
|
|
248
|
+
const r = rules.find(rule => rule.name === n.name);
|
|
249
|
+
if (!r) {
|
|
250
|
+
rules.push(Object.assign({}, n));
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
(_e = r.children) === null || _e === void 0 ? void 0 : _e.push(...Object.assign({}, n).children.slice());
|
|
254
|
+
n.children = [];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
rules.push(Object.assign({}, n));
|
|
259
|
+
}
|
|
260
|
+
return rules.slice();
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
static generate(ast) {
|
|
264
|
+
if (!ast)
|
|
265
|
+
return '';
|
|
266
|
+
return stringifyCss(ast);
|
|
267
|
+
}
|
|
268
|
+
static generateSourceKey(length) {
|
|
269
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
270
|
+
let result = '';
|
|
271
|
+
const charactersLength = characters.length;
|
|
272
|
+
for (let i = 0; i < length; i++) {
|
|
273
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
static addDeclarationSource(node, source, s) {
|
|
278
|
+
if (source) {
|
|
279
|
+
const key = this.generateSourceKey(7);
|
|
280
|
+
const sourceDecl = {
|
|
281
|
+
type: 'Declaration',
|
|
282
|
+
loc: s ? s : node.loc,
|
|
283
|
+
property: '--source',
|
|
284
|
+
value: _a.parse(key, { context: 'value' }),
|
|
285
|
+
important: false
|
|
286
|
+
};
|
|
287
|
+
source.set(key, node.loc);
|
|
288
|
+
return [sourceDecl];
|
|
289
|
+
}
|
|
290
|
+
return [];
|
|
291
|
+
}
|
|
292
|
+
static addAstDeclarationSource(node, source, s) {
|
|
293
|
+
var _b;
|
|
294
|
+
if (source && node.kind === 'rule') {
|
|
295
|
+
const key = this.generateSourceKey(7);
|
|
296
|
+
const source_string = `--source: ${key};`;
|
|
297
|
+
const sourceParsed = _a.parse(source_string);
|
|
298
|
+
const loc = s ? Object.assign({}, s) : node.loc;
|
|
299
|
+
(_b = node.children) === null || _b === void 0 ? void 0 : _b.push({
|
|
300
|
+
kind: 'decl',
|
|
301
|
+
name: '--source',
|
|
302
|
+
cssNode: sourceParsed,
|
|
303
|
+
node: source_string,
|
|
304
|
+
parents: node.parents,
|
|
305
|
+
value: key,
|
|
306
|
+
loc
|
|
307
|
+
});
|
|
308
|
+
source.set(key, loc);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
static generateRule(node, declarations = [], loc) {
|
|
312
|
+
return makeRule(node.name || '', declarations, undefined, loc);
|
|
313
|
+
}
|
|
314
|
+
static convertNode(node, sourceMap, sourceLocations, removeDirectives, options, encoded_tokens) {
|
|
315
|
+
var _b, _c;
|
|
316
|
+
let loc = node.loc ? Object.assign({}, node.loc) : undefined;
|
|
317
|
+
const convertChildren = (nodes) => nodes.flatMap(c => {
|
|
318
|
+
const r = _a.convertNode(c, sourceMap, sourceLocations, removeDirectives, options, encoded_tokens);
|
|
319
|
+
if (!r)
|
|
320
|
+
return [];
|
|
321
|
+
return Array.isArray(r) ? r : [r];
|
|
322
|
+
});
|
|
323
|
+
switch (node.kind) {
|
|
324
|
+
case 'rule': {
|
|
325
|
+
const sourceDecl = [];
|
|
326
|
+
const source = (_b = node.children) === null || _b === void 0 ? void 0 : _b.find(c => c.kind === 'decl' && c.name === '--source');
|
|
327
|
+
if (!source) {
|
|
328
|
+
if (!options.removeSource) {
|
|
329
|
+
// source tracking handled via AstNode children
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
else if (source.value) {
|
|
333
|
+
const s = sourceMap.get(source.value.trim());
|
|
334
|
+
if (s)
|
|
335
|
+
loc = Object.assign({}, s);
|
|
336
|
+
}
|
|
337
|
+
const declChildren = convertChildren(node.children || []);
|
|
338
|
+
const declarations = declChildren.filter(c => c.type === 'declaration');
|
|
339
|
+
const nestedChildren = declChildren.filter(c => c.type !== 'declaration');
|
|
340
|
+
return makeRule(node.name || '', declarations, nestedChildren.length ? nestedChildren : undefined, loc);
|
|
341
|
+
}
|
|
342
|
+
case 'atrule': {
|
|
343
|
+
if (!_a.at_rules_design_fns.some(n => n === node.name) && node.name !== 'import') {
|
|
344
|
+
if (node.name === 'layer' && [..._a.PLUGIN_LAYERS, 'atomic'].some(l => { var _b; return l === ((_b = node.value) === null || _b === void 0 ? void 0 : _b.trim()); }) && options.unwrap) {
|
|
345
|
+
return convertChildren(node.children || []);
|
|
346
|
+
}
|
|
347
|
+
else if (node.name === 'fluixi' && removeDirectives) {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
const blockChildren = node.children ? convertChildren(node.children) : undefined;
|
|
352
|
+
return makeAtRule(node.name || '', node.value || '', blockChildren, loc);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
if (node.children) {
|
|
357
|
+
return convertChildren(node.children);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
if (node.name !== 'import')
|
|
361
|
+
return null;
|
|
362
|
+
return makeAtRule(node.name, node.value || '', undefined, loc);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
case 'decl': {
|
|
367
|
+
if (options.removeSource && ((_c = node.name) === null || _c === void 0 ? void 0 : _c.trim()) === '--source')
|
|
368
|
+
return null;
|
|
369
|
+
const encoded = this.encode((node.value || '').trim(), encoded_tokens);
|
|
370
|
+
const rawVal = node.value === ' ' ? '\\xa0' : encoded;
|
|
371
|
+
return makeDecl(node.name || '', rawVal, !!node.important, [], loc);
|
|
372
|
+
}
|
|
373
|
+
case 'comment': {
|
|
374
|
+
const commentAr = _a.createComment({
|
|
375
|
+
loc: node.loc,
|
|
376
|
+
type: 'Comment',
|
|
377
|
+
value: node.value
|
|
378
|
+
});
|
|
379
|
+
commentAr.loc = node.loc || loc;
|
|
380
|
+
return commentAr;
|
|
381
|
+
}
|
|
382
|
+
default:
|
|
383
|
+
return node.cssNode;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
static overrideLoc(node, newLoc) {
|
|
387
|
+
if (node && typeof node === 'object') {
|
|
388
|
+
if (node.loc) {
|
|
389
|
+
node.loc = Object.assign({}, newLoc);
|
|
390
|
+
}
|
|
391
|
+
for (const key in node) {
|
|
392
|
+
if (Array.isArray(node[key])) {
|
|
393
|
+
node[key].forEach(child => this.overrideLoc(child, newLoc));
|
|
394
|
+
}
|
|
395
|
+
else if (typeof node[key] === 'object') {
|
|
396
|
+
this.overrideLoc(node[key], newLoc);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
collectUtilities(nodes) {
|
|
402
|
+
var _b;
|
|
403
|
+
const utilities = new Map();
|
|
404
|
+
for (const rule of nodes) {
|
|
405
|
+
if (rule.kind === "atrule" && rule.name === "layer" && rule.value === "utilities") {
|
|
406
|
+
if (rule.children) {
|
|
407
|
+
for (const child of rule.children) {
|
|
408
|
+
if (child.kind === "rule" && child.children) {
|
|
409
|
+
const name = (_b = child.name) === null || _b === void 0 ? void 0 : _b.trim();
|
|
410
|
+
if (name) {
|
|
411
|
+
utilities.set(name, child.node);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
state.updateCssUtilities(Object.fromEntries(utilities));
|
|
419
|
+
return utilities;
|
|
420
|
+
}
|
|
421
|
+
clear() {
|
|
422
|
+
__classPrivateFieldSet(this, _AstParser_ast, undefined, "f");
|
|
423
|
+
__classPrivateFieldSet(this, _AstParser_file, undefined, "f");
|
|
424
|
+
__classPrivateFieldSet(this, _AstParser_requireImports, false, "f");
|
|
425
|
+
__classPrivateFieldSet(this, _AstParser_hasImports, false, "f");
|
|
426
|
+
__classPrivateFieldSet(this, _AstParser_hasImportMatch, false, "f");
|
|
427
|
+
__classPrivateFieldSet(this, _AstParser_hasImportsDone, false, "f");
|
|
428
|
+
__classPrivateFieldSet(this, _AstParser_replaceSource, false, "f");
|
|
429
|
+
__classPrivateFieldGet(this, _AstParser_cachedJit, "f").clear();
|
|
430
|
+
__classPrivateFieldGet(this, _AstParser_encoded_tokens, "f").clear();
|
|
431
|
+
__classPrivateFieldSet(this, _AstParser_dependencies, [], "f");
|
|
432
|
+
__classPrivateFieldSet(this, _AstParser_atImportMaps, [], "f");
|
|
433
|
+
__classPrivateFieldSet(this, _AstParser_source, undefined, "f");
|
|
434
|
+
__classPrivateFieldGet(this, _AstParser_sourceLocations, "f").clear();
|
|
435
|
+
__classPrivateFieldSet(this, _AstParser_initial, undefined, "f");
|
|
436
|
+
__classPrivateFieldSet(this, _AstParser_imports, [], "f");
|
|
437
|
+
}
|
|
438
|
+
get ast() {
|
|
439
|
+
return __classPrivateFieldGet(this, _AstParser_ast, "f") ? cloneNodeDeep(__classPrivateFieldGet(this, _AstParser_ast, "f")) : null;
|
|
440
|
+
}
|
|
441
|
+
get requireImports() {
|
|
442
|
+
return __classPrivateFieldGet(this, _AstParser_requireImports, "f");
|
|
443
|
+
}
|
|
444
|
+
get hasImports() {
|
|
445
|
+
return __classPrivateFieldGet(this, _AstParser_hasImports, "f");
|
|
446
|
+
}
|
|
447
|
+
get imports() {
|
|
448
|
+
return __classPrivateFieldGet(this, _AstParser_imports, "f").slice();
|
|
449
|
+
}
|
|
450
|
+
get hasImportMatch() {
|
|
451
|
+
return __classPrivateFieldGet(this, _AstParser_hasImportMatch, "f");
|
|
452
|
+
}
|
|
453
|
+
get hasImportsDone() {
|
|
454
|
+
return __classPrivateFieldGet(this, _AstParser_hasImportsDone, "f");
|
|
455
|
+
}
|
|
456
|
+
get replaceSource() {
|
|
457
|
+
return __classPrivateFieldGet(this, _AstParser_replaceSource, "f");
|
|
458
|
+
}
|
|
459
|
+
get dependencies() {
|
|
460
|
+
return __classPrivateFieldGet(this, _AstParser_dependencies, "f").slice();
|
|
461
|
+
}
|
|
462
|
+
get atImportMaps() {
|
|
463
|
+
return __classPrivateFieldGet(this, _AstParser_atImportMaps, "f").slice();
|
|
464
|
+
}
|
|
465
|
+
get source() {
|
|
466
|
+
return __classPrivateFieldGet(this, _AstParser_source, "f");
|
|
467
|
+
}
|
|
468
|
+
get file() {
|
|
469
|
+
return __classPrivateFieldGet(this, _AstParser_file, "f");
|
|
470
|
+
}
|
|
471
|
+
get designSystem() {
|
|
472
|
+
return __classPrivateFieldGet(this, _AstParser_options, "f").designSystem;
|
|
473
|
+
}
|
|
474
|
+
get logger() {
|
|
475
|
+
if (this.designSystem) {
|
|
476
|
+
return this.designSystem.logger;
|
|
477
|
+
}
|
|
478
|
+
return __classPrivateFieldGet(this, _AstParser_options, "f").logger;
|
|
479
|
+
}
|
|
480
|
+
constructor(file, options = {}) {
|
|
481
|
+
_AstParser_ast.set(this, void 0);
|
|
482
|
+
_AstParser_file.set(this, void 0);
|
|
483
|
+
_AstParser_requireImports.set(this, false);
|
|
484
|
+
_AstParser_hasImports.set(this, false);
|
|
485
|
+
_AstParser_hasImportMatch.set(this, false);
|
|
486
|
+
_AstParser_hasImportsDone.set(this, false);
|
|
487
|
+
_AstParser_replaceSource.set(this, false);
|
|
488
|
+
_AstParser_cachedJit.set(this, new Map());
|
|
489
|
+
_AstParser_encoded_tokens.set(this, new Map());
|
|
490
|
+
_AstParser_dependencies.set(this, []);
|
|
491
|
+
_AstParser_atImportMaps.set(this, []);
|
|
492
|
+
_AstParser_source.set(this, void 0);
|
|
493
|
+
_AstParser_sourceLocations.set(this, new Map());
|
|
494
|
+
_AstParser_initial.set(this, void 0);
|
|
495
|
+
_AstParser_imports.set(this, []);
|
|
496
|
+
_AstParser_sourceMap.set(this, new Map());
|
|
497
|
+
_AstParser_options.set(this, void 0);
|
|
498
|
+
this.convertAst = (node, { postcss, sources, unwrap, encoded_tokens = new Map() } = { postcss: null, sources: null, unwrap: false }) => {
|
|
499
|
+
var _b, _c, _d;
|
|
500
|
+
if (!postcss)
|
|
501
|
+
return null;
|
|
502
|
+
const source = {
|
|
503
|
+
start: node.loc.start,
|
|
504
|
+
end: node.loc.end,
|
|
505
|
+
input: new postcss.Input('', { from: node.loc.source })
|
|
506
|
+
};
|
|
507
|
+
if (sources) {
|
|
508
|
+
const s = sources.get(node.loc.source);
|
|
509
|
+
if (s) {
|
|
510
|
+
source.input = s;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (node.kind === 'rule') {
|
|
514
|
+
if (!node.children)
|
|
515
|
+
return null;
|
|
516
|
+
const rule = new postcss.Rule({ selector: node.name });
|
|
517
|
+
rule.source = source;
|
|
518
|
+
const children = [];
|
|
519
|
+
for (const child of node.children) {
|
|
520
|
+
const c = this.convertAst(child, { postcss, sources, encoded_tokens });
|
|
521
|
+
if (c) {
|
|
522
|
+
if (Array.isArray(c)) {
|
|
523
|
+
children.push(...c);
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
children.push(c);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (children.length > 0) {
|
|
531
|
+
rule.append(children);
|
|
532
|
+
if (__classPrivateFieldGet(this, _AstParser_options, "f").minify) {
|
|
533
|
+
rule.selector = rule.selector.replace(/\s+/g, '');
|
|
534
|
+
}
|
|
535
|
+
return rule;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
else if (node.kind === 'atrule') {
|
|
539
|
+
if (node.name === "fluixi") {
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
else if (((_b = node.name) === null || _b === void 0 ? void 0 : _b.startsWith("comment")) && !__classPrivateFieldGet(this, _AstParser_options, "f").minify) {
|
|
543
|
+
const childValue = (_d = (_c = node.children) === null || _c === void 0 ? void 0 : _c.find(c => c.kind === "decl")) === null || _d === void 0 ? void 0 : _d.value;
|
|
544
|
+
const comment = new postcss.Comment({ text: _a.decrypt(childValue) });
|
|
545
|
+
comment.source = source;
|
|
546
|
+
return comment;
|
|
547
|
+
}
|
|
548
|
+
if (node.name === "layer" && [..._a.PLUGIN_LAYERS, "atomic"].some(l => { var _b; return l === ((_b = node.value) === null || _b === void 0 ? void 0 : _b.trim()); }) && unwrap === true) {
|
|
549
|
+
if (!node.children) {
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
const children = [];
|
|
553
|
+
for (const child of node.children) {
|
|
554
|
+
const c = this.convertAst(child, { postcss, sources, unwrap });
|
|
555
|
+
if (c) {
|
|
556
|
+
if (Array.isArray(c)) {
|
|
557
|
+
children.push(...c);
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
children.push(c);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return children;
|
|
565
|
+
}
|
|
566
|
+
const atrule = new postcss.AtRule({ name: node.name, params: node.value });
|
|
567
|
+
const children = [];
|
|
568
|
+
if (!node.children) {
|
|
569
|
+
atrule.source = source;
|
|
570
|
+
if (__classPrivateFieldGet(this, _AstParser_options, "f").minify) {
|
|
571
|
+
atrule.params = atrule.params.replace(/\s+/g, '');
|
|
572
|
+
}
|
|
573
|
+
return atrule;
|
|
574
|
+
}
|
|
575
|
+
for (const child of node.children) {
|
|
576
|
+
const c = this.convertAst(child, { postcss, sources, encoded_tokens });
|
|
577
|
+
if (c) {
|
|
578
|
+
if (Array.isArray(c)) {
|
|
579
|
+
children.push(...c);
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
children.push(c);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (children.length > 0) {
|
|
587
|
+
atrule.append(children);
|
|
588
|
+
atrule.source = source;
|
|
589
|
+
if (__classPrivateFieldGet(this, _AstParser_options, "f").minify) {
|
|
590
|
+
atrule.params = atrule.params.replace(/\s+/g, '');
|
|
591
|
+
}
|
|
592
|
+
return atrule;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
else if (node.kind === 'comment' && !__classPrivateFieldGet(this, _AstParser_options, "f").minify) {
|
|
596
|
+
const comment = new postcss.Comment({ text: node.value });
|
|
597
|
+
comment.source = source;
|
|
598
|
+
return comment;
|
|
599
|
+
}
|
|
600
|
+
else if (node.kind === 'decl' && (node.name || '').trim() !== '--source') {
|
|
601
|
+
const decl = new postcss.Declaration({ prop: node.name, value: _a.decode(node.value.replace(/xa0/g, ' '), __classPrivateFieldGet(this, _AstParser_encoded_tokens, "f")), important: !!node.important });
|
|
602
|
+
// const decl = new postcss.Declaration({prop: node.name!, value: node.value!.replace(/var(--space)/g, ' '), important: !!node.important});
|
|
603
|
+
decl.source = source;
|
|
604
|
+
if (__classPrivateFieldGet(this, _AstParser_options, "f").minify) {
|
|
605
|
+
decl.prop = decl.prop.replace(/\s+/g, ''); // Remove whitespace from properties
|
|
606
|
+
decl.value = decl.value.replace(/\s+/g, ''); // Remove whitespace from values
|
|
607
|
+
}
|
|
608
|
+
return decl;
|
|
609
|
+
}
|
|
610
|
+
return null;
|
|
611
|
+
};
|
|
612
|
+
this.astToPostcss = (nodes, root, { postcss, sources, unwrap, encoded_tokens } = { postcss: null, sources: null, unwrap: false, encoded_tokens: new Map() }) => {
|
|
613
|
+
if (!postcss)
|
|
614
|
+
return null;
|
|
615
|
+
for (const node of nodes) {
|
|
616
|
+
const value = this.convertAst(node, { postcss, sources, unwrap, encoded_tokens: encoded_tokens ? encoded_tokens : __classPrivateFieldGet(this, _AstParser_encoded_tokens, "f") });
|
|
617
|
+
if (value) {
|
|
618
|
+
if (Array.isArray(value)) {
|
|
619
|
+
root.append(...value);
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
root.append(value);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (root.raws.before) {
|
|
627
|
+
root.raws.before = '';
|
|
628
|
+
}
|
|
629
|
+
if (root.raws.after) {
|
|
630
|
+
root.raws.after = '';
|
|
631
|
+
}
|
|
632
|
+
return root;
|
|
633
|
+
};
|
|
634
|
+
this.HandleScreens = (astNode) => {
|
|
635
|
+
var _b;
|
|
636
|
+
const name = ((_b = astNode.value) === null || _b === void 0 ? void 0 : _b.startsWith('(')) ? astNode.value.slice(1, -1) : astNode.value;
|
|
637
|
+
if (name) {
|
|
638
|
+
const mediaQuery = formatMediaQuery(name);
|
|
639
|
+
if (mediaQuery) {
|
|
640
|
+
const parsed = _a.parse(mediaQuery);
|
|
641
|
+
const p = parsed.children.find(f => f.type === 'atrule');
|
|
642
|
+
if (p) {
|
|
643
|
+
return { name: p.name, prelude: { value: p.preludeText || '' }, loc: p.loc };
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return null;
|
|
648
|
+
};
|
|
649
|
+
this.createStyles = (_applyStyles) => {
|
|
650
|
+
var _b;
|
|
651
|
+
let dataStyles = '';
|
|
652
|
+
let isImportant = false;
|
|
653
|
+
let applyStyles = _applyStyles.slice();
|
|
654
|
+
const important = isImportantFn(applyStyles);
|
|
655
|
+
if (important) {
|
|
656
|
+
applyStyles = important.str.slice();
|
|
657
|
+
isImportant = true;
|
|
658
|
+
}
|
|
659
|
+
const um = Object.assign({}, (((_b = state.utilities) === null || _b === void 0 ? void 0 : _b.utilitiesMap) || {}));
|
|
660
|
+
for (const applyStyle of applyStyles) {
|
|
661
|
+
let style;
|
|
662
|
+
let hasPoint = false;
|
|
663
|
+
let stylesCached = __classPrivateFieldGet(this, _AstParser_cachedJit, "f").get(applyStyle);
|
|
664
|
+
if (stylesCached) {
|
|
665
|
+
dataStyles += stylesCached + "\n";
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
// const selectors = splitString(_selector, COMMA_REGEX)
|
|
669
|
+
if (um) {
|
|
670
|
+
style = um[applyStyle];
|
|
671
|
+
if (!style) {
|
|
672
|
+
style = um[`.${applyStyle}`];
|
|
673
|
+
hasPoint = true;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
if (style) {
|
|
677
|
+
let st = '';
|
|
678
|
+
if (hasPoint) {
|
|
679
|
+
if (typeof style === 'string') {
|
|
680
|
+
st += style.replace(`.${_a.isSpecial(applyStyle) ? formatClassName(applyStyle) : applyStyle}`, 'xxx').replace(!isImportant ? /\!important/g : '', '') + "\n";
|
|
681
|
+
dataStyles += st;
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
console.warn('[Fluixi Css] type of style is not string', style);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
// console.log('style no point', {style, applyStyle})
|
|
689
|
+
// selectors.forEach(selector=>{
|
|
690
|
+
// const rule = postcss.rule({
|
|
691
|
+
// selector: selector,
|
|
692
|
+
// nodes: [...style],
|
|
693
|
+
// });
|
|
694
|
+
// // rule.after(postcss.comment({text: sourceComment}))
|
|
695
|
+
// // Add source comment
|
|
696
|
+
// // rule.append(postcss.comment({ text: ` @apply ${applyStyle} from ${originalSource}:${sourceLine} ` }));
|
|
697
|
+
// st += rule.toString().replace(!isImportant ? /\!important/g: '', '')
|
|
698
|
+
// })
|
|
699
|
+
}
|
|
700
|
+
__classPrivateFieldGet(this, _AstParser_cachedJit, "f").set(applyStyle, st);
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
let styles = __classPrivateFieldGet(this, _AstParser_cachedJit, "f").get(applyStyle);
|
|
704
|
+
let save = false;
|
|
705
|
+
if (!styles) {
|
|
706
|
+
styles = getJustInTimeStyles('xxx_selector', applyStyle, isImportant);
|
|
707
|
+
save = true;
|
|
708
|
+
}
|
|
709
|
+
if (styles && styles.styles && styles.styles.length > 0) {
|
|
710
|
+
// const parsed = parse(styles.css.trim().replace(/xxx_selector/g, selector), {from: undefined});
|
|
711
|
+
let style = styles.styles.trim().replace(/xxx_selector/g, 'xxx').toString();
|
|
712
|
+
dataStyles += style;
|
|
713
|
+
if (save) {
|
|
714
|
+
__classPrivateFieldGet(this, _AstParser_cachedJit, "f").set(applyStyle, style);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
// state.clearState();
|
|
719
|
+
// clearResources();
|
|
720
|
+
// const r = (atRule as postcss.AtRule)
|
|
721
|
+
// const err = r.error(`cutom directive ${applyStyle} is not a valid utility`, {plugin: '@fluixi/jit', word: `${atRule.name}`, index: r.parent?.index(atRule)}).toString();
|
|
722
|
+
logger(`[Fluixi Css ⚠️ ]`, `cutom directive ${applyStyle} is not a valid utility`);
|
|
723
|
+
// logger(`@fluixi/css-postcss ⚠️`, `cutom directive ${applyStyle} is not a valid utility ${atRule.toString()}`)
|
|
724
|
+
// throw postcss.atRule().error(`cutom directive ${applyStyle} is not a valid utility`, {plugin: '@fluixi/jit', word: `${atRule.name}`});
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return dataStyles;
|
|
729
|
+
};
|
|
730
|
+
_AstParser_astArray.set(this, []);
|
|
731
|
+
_AstParser_mappings.set(this, []);
|
|
732
|
+
__classPrivateFieldSet(this, _AstParser_file, file, "f");
|
|
733
|
+
__classPrivateFieldSet(this, _AstParser_options, options, "f");
|
|
734
|
+
const { ast } = this.init();
|
|
735
|
+
if (!options || !options.css) {
|
|
736
|
+
__classPrivateFieldSet(this, _AstParser_ast, cloneNodeDeep(ast), "f");
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
__classPrivateFieldSet(this, _AstParser_ast, _a.parse(options.css, { filename: file, positions: true }, __classPrivateFieldGet(this, _AstParser_options, "f").minify), "f");
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
init() {
|
|
743
|
+
var _b;
|
|
744
|
+
const _file = (_b = state.files) === null || _b === void 0 ? void 0 : _b.find(f => f.file === this.file && f.isStyleSheet);
|
|
745
|
+
const content = (_file && _file.content) ? _file.content : readFileSync(this.file, 'utf-8');
|
|
746
|
+
const ast = _a.parse(content, { positions: true, filename: this.file }, __classPrivateFieldGet(this, _AstParser_options, "f").minify);
|
|
747
|
+
__classPrivateFieldSet(this, _AstParser_source, ast.loc, "f");
|
|
748
|
+
const value = { content, ast };
|
|
749
|
+
__classPrivateFieldSet(this, _AstParser_initial, Object.assign({}, value), "f");
|
|
750
|
+
__classPrivateFieldSet(this, _AstParser_replaceSource, (__classPrivateFieldGet(this, _AstParser_options, "f").css !== undefined && __classPrivateFieldGet(this, _AstParser_initial, "f").content !== __classPrivateFieldGet(this, _AstParser_options, "f").css), "f");
|
|
751
|
+
// Load per-file config and CSS directives (fire-and-forget; sync after first pass is fine)
|
|
752
|
+
if (__classPrivateFieldGet(this, _AstParser_options, "f").designSystem && this.file) {
|
|
753
|
+
const ds = __classPrivateFieldGet(this, _AstParser_options, "f").designSystem;
|
|
754
|
+
// Per-file fluixi.config.* (async – schedule after sync init completes)
|
|
755
|
+
Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () {
|
|
756
|
+
const filePatch = yield ds.loadFileConfig(this.file);
|
|
757
|
+
if (filePatch)
|
|
758
|
+
ds.applyConfigPatch(filePatch);
|
|
759
|
+
// CSS-directive-based config (@theme, @plugin, @config, @source)
|
|
760
|
+
const cssPatch = yield ds.parseCssDirectives(content, this.file);
|
|
761
|
+
if (cssPatch && Object.keys(cssPatch).length > 0)
|
|
762
|
+
ds.applyConfigPatch(cssPatch);
|
|
763
|
+
})).catch(() => { });
|
|
764
|
+
}
|
|
765
|
+
return value;
|
|
766
|
+
}
|
|
767
|
+
handleBase() {
|
|
768
|
+
if (!__classPrivateFieldGet(this, _AstParser_initial, "f") || !__classPrivateFieldGet(this, _AstParser_ast, "f")) {
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
const import_nodes = _a.findImports(__classPrivateFieldGet(this, _AstParser_initial, "f").ast);
|
|
772
|
+
const current_import_nodes = _a.findImports(__classPrivateFieldGet(this, _AstParser_ast, "f"));
|
|
773
|
+
const modules = _a.resolveLocalModulesPath();
|
|
774
|
+
if (import_nodes.length > 0) {
|
|
775
|
+
__classPrivateFieldSet(this, _AstParser_hasImports, true, "f");
|
|
776
|
+
if (import_nodes.length === current_import_nodes.length && import_nodes.length > 0) {
|
|
777
|
+
__classPrivateFieldSet(this, _AstParser_requireImports, true, "f");
|
|
778
|
+
}
|
|
779
|
+
__classPrivateFieldSet(this, _AstParser_imports, import_nodes.slice().flatMap(e => {
|
|
780
|
+
if (e.type === "String") {
|
|
781
|
+
const value = _a.ImportsMatch[_a.unquote(e.value)];
|
|
782
|
+
if (value) {
|
|
783
|
+
const loc = e.loc;
|
|
784
|
+
if (loc) {
|
|
785
|
+
loc.source = modules[`core_${value}`];
|
|
786
|
+
loc.start.line = 1;
|
|
787
|
+
loc.end.line = 1;
|
|
788
|
+
}
|
|
789
|
+
return { node: e.node, param: e.value, match: value, loc };
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return null;
|
|
793
|
+
}).filter(a => a !== null), "f");
|
|
794
|
+
}
|
|
795
|
+
__classPrivateFieldSet(this, _AstParser_hasImportMatch, __classPrivateFieldGet(this, _AstParser_imports, "f").some(i => i.match), "f");
|
|
796
|
+
// this.#replaceSource = this.#hasImports && !this.#requireImports;
|
|
797
|
+
return "ok";
|
|
798
|
+
}
|
|
799
|
+
importAtRule(filePath) {
|
|
800
|
+
var _b;
|
|
801
|
+
let { path, match } = _a.resolveLocalImportsPath(filePath, __classPrivateFieldGet(this, _AstParser_options, "f").resolveLocalPresets);
|
|
802
|
+
if (!match) {
|
|
803
|
+
if (path.startsWith(".")) {
|
|
804
|
+
path = join(dirname(this.file), path);
|
|
805
|
+
}
|
|
806
|
+
else {
|
|
807
|
+
if (!isAbsolute(path) && this.file) {
|
|
808
|
+
path = join(dirname(this.file), filePath);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
if (!existsSync(path))
|
|
813
|
+
return null;
|
|
814
|
+
const f = (_b = state.files) === null || _b === void 0 ? void 0 : _b.find(f => f.file === path && f.isStyleSheet);
|
|
815
|
+
if (f && f.content) {
|
|
816
|
+
const content = f.content;
|
|
817
|
+
const parsed = _a.parse(content, { filename: path, positions: true }, __classPrivateFieldGet(this, _AstParser_options, "f").minify);
|
|
818
|
+
return { atImport: parsed, file: path, match: null, content };
|
|
819
|
+
}
|
|
820
|
+
const content = readFileSync(path, { encoding: "utf-8" });
|
|
821
|
+
const parsed = _a.parse(content, { filename: path, positions: true }, __classPrivateFieldGet(this, _AstParser_options, "f").minify);
|
|
822
|
+
return { atImport: parsed, file: path, match, content };
|
|
823
|
+
}
|
|
824
|
+
loadBaseSources() {
|
|
825
|
+
var _b, _c;
|
|
826
|
+
const init = this.handleBase();
|
|
827
|
+
if (!init)
|
|
828
|
+
return null;
|
|
829
|
+
__classPrivateFieldGet(this, _AstParser_dependencies, "f").push({
|
|
830
|
+
type: 'dependency',
|
|
831
|
+
file: this.file,
|
|
832
|
+
content: (_b = __classPrivateFieldGet(this, _AstParser_initial, "f")) === null || _b === void 0 ? void 0 : _b.content,
|
|
833
|
+
parent: this.file
|
|
834
|
+
});
|
|
835
|
+
if (!(this.hasImportMatch && !this.requireImports)) {
|
|
836
|
+
const imports = _a.findImports(__classPrivateFieldGet(this, _AstParser_ast, "f"));
|
|
837
|
+
const directives = _a.findPluginDirectives(__classPrivateFieldGet(this, _AstParser_ast, "f"));
|
|
838
|
+
imports.forEach(imported => {
|
|
839
|
+
if (!__classPrivateFieldGet(this, _AstParser_sourceLocations, "f").get(imported.value) && imported.loc) {
|
|
840
|
+
__classPrivateFieldGet(this, _AstParser_sourceLocations, "f").set(imported.value, {
|
|
841
|
+
source: imported.loc.source,
|
|
842
|
+
start: imported.loc.start,
|
|
843
|
+
end: imported.loc.end,
|
|
844
|
+
});
|
|
845
|
+
__classPrivateFieldGet(this, _AstParser_sourceMap, "f").set(imported.value, {
|
|
846
|
+
source: imported.loc.source,
|
|
847
|
+
start: imported.loc.start,
|
|
848
|
+
end: imported.loc.end,
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
directives.forEach(directive => {
|
|
853
|
+
if (!__classPrivateFieldGet(this, _AstParser_sourceLocations, "f").get(directive.value) && directive.loc) {
|
|
854
|
+
__classPrivateFieldGet(this, _AstParser_sourceLocations, "f").set(directive.value, {
|
|
855
|
+
source: directive.loc.source,
|
|
856
|
+
start: directive.loc.start,
|
|
857
|
+
end: directive.loc.end,
|
|
858
|
+
});
|
|
859
|
+
__classPrivateFieldGet(this, _AstParser_sourceMap, "f").set(directive.value, {
|
|
860
|
+
source: directive.loc.source,
|
|
861
|
+
start: directive.loc.start,
|
|
862
|
+
end: directive.loc.end,
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
const entry_imports = _a.findImports((_c = __classPrivateFieldGet(this, _AstParser_initial, "f")) === null || _c === void 0 ? void 0 : _c.ast);
|
|
868
|
+
entry_imports.forEach(element => {
|
|
869
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
870
|
+
const source = {
|
|
871
|
+
start: (_b = element.loc) === null || _b === void 0 ? void 0 : _b.start,
|
|
872
|
+
end: (_c = element.loc) === null || _c === void 0 ? void 0 : _c.end,
|
|
873
|
+
source: (_d = element.loc) === null || _d === void 0 ? void 0 : _d.source
|
|
874
|
+
};
|
|
875
|
+
const isUrl = element.value.includes('Url(');
|
|
876
|
+
if (!isUrl) {
|
|
877
|
+
const at = this.importAtRule(_a.unquote(element.value));
|
|
878
|
+
if (at) {
|
|
879
|
+
const { atImport, file, match, content } = at;
|
|
880
|
+
__classPrivateFieldGet(this, _AstParser_dependencies, "f").push({
|
|
881
|
+
type: 'dependency',
|
|
882
|
+
file,
|
|
883
|
+
content,
|
|
884
|
+
parent: this.file
|
|
885
|
+
});
|
|
886
|
+
if (match) {
|
|
887
|
+
__classPrivateFieldSet(this, _AstParser_hasImportsDone, true, "f");
|
|
888
|
+
// this.#replaceSource = true;
|
|
889
|
+
if (!__classPrivateFieldGet(this, _AstParser_sourceLocations, "f").get(match)) {
|
|
890
|
+
const _source = _a.resolveLocalModulesPath()[`core_${match}`];
|
|
891
|
+
if (_source) {
|
|
892
|
+
source.source = _source;
|
|
893
|
+
}
|
|
894
|
+
__classPrivateFieldGet(this, _AstParser_sourceLocations, "f").set(match, {
|
|
895
|
+
// file,
|
|
896
|
+
source: _source ? _source : atImport.loc ? atImport.loc.source : source.source,
|
|
897
|
+
start: (_e = element.loc) === null || _e === void 0 ? void 0 : _e.start,
|
|
898
|
+
end: (_f = element.loc) === null || _f === void 0 ? void 0 : _f.end,
|
|
899
|
+
});
|
|
900
|
+
__classPrivateFieldGet(this, _AstParser_sourceMap, "f").set(match, {
|
|
901
|
+
// file,
|
|
902
|
+
source: _source ? _source : atImport.loc ? atImport.loc.source : source.source,
|
|
903
|
+
start: (_g = element.loc) === null || _g === void 0 ? void 0 : _g.start,
|
|
904
|
+
end: (_h = element.loc) === null || _h === void 0 ? void 0 : _h.end,
|
|
905
|
+
});
|
|
906
|
+
if (match === "utilities") {
|
|
907
|
+
__classPrivateFieldGet(this, _AstParser_sourceLocations, "f").set("atomic", {
|
|
908
|
+
// file,
|
|
909
|
+
source: _source ? _source : atImport.loc ? atImport.loc.source : source.source,
|
|
910
|
+
start: (_j = element.loc) === null || _j === void 0 ? void 0 : _j.start,
|
|
911
|
+
end: (_k = element.loc) === null || _k === void 0 ? void 0 : _k.end,
|
|
912
|
+
});
|
|
913
|
+
__classPrivateFieldGet(this, _AstParser_sourceMap, "f").set("atomic", {
|
|
914
|
+
// file,
|
|
915
|
+
source: _source ? _source : atImport.loc ? atImport.loc.source : source.source,
|
|
916
|
+
start: (_l = element.loc) === null || _l === void 0 ? void 0 : _l.start,
|
|
917
|
+
end: (_m = element.loc) === null || _m === void 0 ? void 0 : _m.end,
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
__classPrivateFieldGet(this, _AstParser_atImportMaps, "f").push({
|
|
922
|
+
file,
|
|
923
|
+
node: element.node,
|
|
924
|
+
source,
|
|
925
|
+
parent: this.file,
|
|
926
|
+
atImport: atImport,
|
|
927
|
+
match
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
else {
|
|
931
|
+
__classPrivateFieldGet(this, _AstParser_atImportMaps, "f").push({
|
|
932
|
+
file: this.file,
|
|
933
|
+
node: element.node,
|
|
934
|
+
source,
|
|
935
|
+
atImport,
|
|
936
|
+
parent: this.file
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
else {
|
|
942
|
+
__classPrivateFieldGet(this, _AstParser_atImportMaps, "f").push({
|
|
943
|
+
file: this.file,
|
|
944
|
+
node: element.node,
|
|
945
|
+
source
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
static mergeRules(ast) {
|
|
951
|
+
var _b, _c;
|
|
952
|
+
const rulesMap = new Map();
|
|
953
|
+
const result = [];
|
|
954
|
+
for (const node of ast.children) {
|
|
955
|
+
if (node.type === 'rule') {
|
|
956
|
+
const rule = node;
|
|
957
|
+
const selector = (_b = rule.rawSelector) !== null && _b !== void 0 ? _b : '';
|
|
958
|
+
if (rulesMap.has(selector)) {
|
|
959
|
+
const existing = rulesMap.get(selector);
|
|
960
|
+
for (const d of rule.declarations) {
|
|
961
|
+
if (!existing.declarations.some(e => e.property === d.property)) {
|
|
962
|
+
existing.declarations.push(Object.assign({}, d));
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
else {
|
|
967
|
+
rulesMap.set(selector, rule);
|
|
968
|
+
result.push(rule);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
else if (node.type === 'atrule') {
|
|
972
|
+
const ar = node;
|
|
973
|
+
if (ar.block) {
|
|
974
|
+
const mergedChildren = [];
|
|
975
|
+
const innerMap = new Map();
|
|
976
|
+
for (const child of ar.block.children) {
|
|
977
|
+
if (child.type === 'rule') {
|
|
978
|
+
const r = child;
|
|
979
|
+
const key = (_c = r.rawSelector) !== null && _c !== void 0 ? _c : '';
|
|
980
|
+
if (innerMap.has(key)) {
|
|
981
|
+
const ex = innerMap.get(key);
|
|
982
|
+
for (const d of r.declarations) {
|
|
983
|
+
if (!ex.declarations.some(e => e.property === d.property)) {
|
|
984
|
+
ex.declarations.push(Object.assign({}, d));
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
else {
|
|
989
|
+
innerMap.set(key, r);
|
|
990
|
+
mergedChildren.push(r);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
mergedChildren.push(child);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
ar.block.children = mergedChildren;
|
|
998
|
+
}
|
|
999
|
+
result.push(ar);
|
|
1000
|
+
}
|
|
1001
|
+
else {
|
|
1002
|
+
result.push(node);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return makeStylesheet(result);
|
|
1006
|
+
}
|
|
1007
|
+
directiveToCss(rule, sourceKey, parents = [], parent) {
|
|
1008
|
+
const l = rule.value ? rule.value : replaceString(rule.node.replace(`@${rule.name} `, ''), ';', false, '');
|
|
1009
|
+
const str = l.split(' ');
|
|
1010
|
+
const styles = this.createStyles(str);
|
|
1011
|
+
const optimized = _a.optimize(styles, undefined, { minify: true });
|
|
1012
|
+
const parsed = _a.parse(optimized.code.replace(/xxx/g, '&'));
|
|
1013
|
+
if (sourceKey && !__classPrivateFieldGet(this, _AstParser_sourceMap, "f").has(sourceKey.trim())) {
|
|
1014
|
+
__classPrivateFieldGet(this, _AstParser_sourceMap, "f").set(sourceKey.trim(), rule.loc);
|
|
1015
|
+
}
|
|
1016
|
+
return parsed;
|
|
1017
|
+
}
|
|
1018
|
+
findSourceLocation(ast) {
|
|
1019
|
+
if (ast.type === 'rule') {
|
|
1020
|
+
const rule = ast;
|
|
1021
|
+
const sourceDecl = rule.declarations.find(d => d.property === '--source');
|
|
1022
|
+
if (sourceDecl && sourceDecl.rawValue) {
|
|
1023
|
+
return sourceDecl.rawValue.trim();
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
return undefined;
|
|
1027
|
+
}
|
|
1028
|
+
extractSourceKey(name) {
|
|
1029
|
+
const match = name.match(/--source-(.*)/);
|
|
1030
|
+
return match ? match[1] : null;
|
|
1031
|
+
}
|
|
1032
|
+
createSourcesMap() {
|
|
1033
|
+
const map = new SourceMapGenerator();
|
|
1034
|
+
__classPrivateFieldGet(this, _AstParser_mappings, "f").forEach(m => {
|
|
1035
|
+
map.addMapping(m);
|
|
1036
|
+
});
|
|
1037
|
+
this.dependencies.forEach(d => {
|
|
1038
|
+
map.setSourceContent(d.file, d.content);
|
|
1039
|
+
});
|
|
1040
|
+
return map;
|
|
1041
|
+
}
|
|
1042
|
+
findRuleParent(parents, child_selector) {
|
|
1043
|
+
const ruleParents = parents.filter(p => p.kind === 'rule');
|
|
1044
|
+
if (ruleParents.length > 0) {
|
|
1045
|
+
const childSelectors = splitString((child_selector || ''), COMMA_REGEX).map(s => s.trim());
|
|
1046
|
+
const closestRuleParent = ruleParents[ruleParents.length - 1];
|
|
1047
|
+
const parentSelectors = splitString((closestRuleParent.name || ''), COMMA_REGEX).map(s => s.trim());
|
|
1048
|
+
const combinedSelectors = _a.combineSelectors(parentSelectors, childSelectors).join(', ');
|
|
1049
|
+
return { closestRuleParent, parentSelectors, combinedSelectors };
|
|
1050
|
+
}
|
|
1051
|
+
return null;
|
|
1052
|
+
}
|
|
1053
|
+
// Helper method to combine parent and child selectors
|
|
1054
|
+
static combineSelectors(parentSelectors, childSelectors) {
|
|
1055
|
+
const result = [];
|
|
1056
|
+
for (const parent_ of parentSelectors) {
|
|
1057
|
+
const sp = splitString(parent_, COMMA_REGEX);
|
|
1058
|
+
const results = [];
|
|
1059
|
+
for (const parent of sp) {
|
|
1060
|
+
for (const child_ of childSelectors) {
|
|
1061
|
+
const sc = splitString(child_, COMMA_REGEX);
|
|
1062
|
+
for (const child of sc) {
|
|
1063
|
+
// Replace & with parent selector
|
|
1064
|
+
if (child.includes('&')) {
|
|
1065
|
+
results.push(child.replace(/&/g, parent));
|
|
1066
|
+
}
|
|
1067
|
+
else {
|
|
1068
|
+
// If no & is present, assume descendant selector
|
|
1069
|
+
results.push(`${parent} ${child}`);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
result.push(results.join(', '));
|
|
1075
|
+
}
|
|
1076
|
+
return result;
|
|
1077
|
+
}
|
|
1078
|
+
getRulesParentRuleSelectors(values) {
|
|
1079
|
+
return values.slice().filter(v => !v.startsWith('@') && v !== "sheet");
|
|
1080
|
+
}
|
|
1081
|
+
static getSelector(value, parents) {
|
|
1082
|
+
const parentSelectors = parents.filter(p => !p.startsWith('@'));
|
|
1083
|
+
if (parentSelectors.length > 0) {
|
|
1084
|
+
const selector = _a.buildSelector(parentSelectors);
|
|
1085
|
+
if (value === '&')
|
|
1086
|
+
return selector;
|
|
1087
|
+
const sp = splitString(value, COMMA_REGEX);
|
|
1088
|
+
const comb = parentSelectors.length > 0 ? _a.combineSelectors(selector, sp) : [...sp];
|
|
1089
|
+
if (comb.length > sp.length) {
|
|
1090
|
+
comb.shift();
|
|
1091
|
+
}
|
|
1092
|
+
return comb;
|
|
1093
|
+
}
|
|
1094
|
+
return [value];
|
|
1095
|
+
}
|
|
1096
|
+
static replaceRulesChild(r, first = false) {
|
|
1097
|
+
var _b, _c;
|
|
1098
|
+
if (!r.children)
|
|
1099
|
+
return r;
|
|
1100
|
+
if (r.kind === "rule") {
|
|
1101
|
+
if (((_b = r.parents) === null || _b === void 0 ? void 0 : _b.filter(p => !_a.isPluginDeclarativeName(p)).length) > 0) {
|
|
1102
|
+
if ((_c = r.name) === null || _c === void 0 ? void 0 : _c.includes('&')) {
|
|
1103
|
+
const comb = _a.getSelector(r.name, r.parents);
|
|
1104
|
+
r.name = comb.join(', ');
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
const children = [];
|
|
1109
|
+
for (const c of r.children) {
|
|
1110
|
+
if (c.children && c.children.length > 0) {
|
|
1111
|
+
children.push(this.replaceRulesChild(c));
|
|
1112
|
+
}
|
|
1113
|
+
else {
|
|
1114
|
+
children.push(c);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
r.children = children.slice();
|
|
1118
|
+
return r;
|
|
1119
|
+
}
|
|
1120
|
+
astToArray(params) {
|
|
1121
|
+
var _b, _c, _d, _e, _f, _g, _h;
|
|
1122
|
+
const { ast, collect = undefined, collectSources = false, parent = null, parents = [], source = undefined, debug = false, _sourceKey = undefined } = params;
|
|
1123
|
+
const result = [];
|
|
1124
|
+
let _parents = parents.slice();
|
|
1125
|
+
let loc = (source !== undefined && source !== null) ? Object.assign({}, source) : ast.loc ? Object.assign({}, ast.loc) : undefined;
|
|
1126
|
+
let sourceDecl;
|
|
1127
|
+
if (!collectSources) {
|
|
1128
|
+
if (collect !== false && ast.type === 'rule') {
|
|
1129
|
+
const ss = this.findSourceLocation(ast);
|
|
1130
|
+
sourceDecl = _sourceKey ? __classPrivateFieldGet(this, _AstParser_sourceMap, "f").get(_sourceKey) : __classPrivateFieldGet(this, _AstParser_sourceMap, "f").get(ss || '');
|
|
1131
|
+
if (sourceDecl) {
|
|
1132
|
+
loc = Object.assign({}, sourceDecl);
|
|
1133
|
+
}
|
|
1134
|
+
const parent_ = parents.find(p => _a.PLUGIN_LAYERS.some(a => p === a || `@${p}` === a));
|
|
1135
|
+
if (!sourceDecl) {
|
|
1136
|
+
if (parent_ && !loc) {
|
|
1137
|
+
const base = __classPrivateFieldGet(this, _AstParser_sourceMap, "f").get(parent_);
|
|
1138
|
+
if (base) {
|
|
1139
|
+
loc = { source: base === null || base === void 0 ? void 0 : base.source, start: base === null || base === void 0 ? void 0 : base.start, end: base === null || base === void 0 ? void 0 : base.end };
|
|
1140
|
+
}
|
|
1141
|
+
if (!loc && parent_ === '@components') {
|
|
1142
|
+
loc = Object.assign({}, _a.componentsSources);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (ast.type === 'stylesheet') {
|
|
1149
|
+
const ss = ast;
|
|
1150
|
+
const hasSheet = parents.some(p => p === '@sheet') || parents.length > 0;
|
|
1151
|
+
for (const child of ss.children) {
|
|
1152
|
+
result.push(...this.astToArray({ ast: child, collectSources, parent, parents: hasSheet ? [...parents] : ['@sheet'], source, debug, _sourceKey }).slice());
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
else if (ast.type === 'atrule') {
|
|
1156
|
+
const ar = ast;
|
|
1157
|
+
if (ar.name.startsWith('comment')) {
|
|
1158
|
+
const child = (_b = ar.block) === null || _b === void 0 ? void 0 : _b.children[0];
|
|
1159
|
+
const rawVal = (_c = child === null || child === void 0 ? void 0 : child.rawValue) !== null && _c !== void 0 ? _c : '';
|
|
1160
|
+
const el = {
|
|
1161
|
+
kind: 'comment',
|
|
1162
|
+
name: '',
|
|
1163
|
+
loc,
|
|
1164
|
+
value: _a.decrypt(rawVal),
|
|
1165
|
+
node: child ? stringifyCss(child) : '',
|
|
1166
|
+
cssNode: ar,
|
|
1167
|
+
parents: parents.slice(),
|
|
1168
|
+
important: (_d = child === null || child === void 0 ? void 0 : child.important) !== null && _d !== void 0 ? _d : false,
|
|
1169
|
+
};
|
|
1170
|
+
result.push(el);
|
|
1171
|
+
}
|
|
1172
|
+
else {
|
|
1173
|
+
const children = [];
|
|
1174
|
+
const value = (_e = ar.preludeText) !== null && _e !== void 0 ? _e : '';
|
|
1175
|
+
_parents.push(`@${value}`);
|
|
1176
|
+
for (const child of ((_f = ar.block) === null || _f === void 0 ? void 0 : _f.children) || []) {
|
|
1177
|
+
children.push(...this.astToArray({ ast: child, collectSources, parent, parents: [..._parents], source, debug, _sourceKey }).slice());
|
|
1178
|
+
}
|
|
1179
|
+
const el = Object.assign({ kind: 'atrule', name: ar.name, loc,
|
|
1180
|
+
value, node: stringifyCss(ar), cssNode: ar, parents: parents.slice() }, (children.length > 0 ? { children } : {}));
|
|
1181
|
+
result.push(el);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
else if (ast.type === 'rule') {
|
|
1185
|
+
const rule = ast;
|
|
1186
|
+
const value = (_g = rule.rawSelector) !== null && _g !== void 0 ? _g : '';
|
|
1187
|
+
const children = [];
|
|
1188
|
+
const flattened_nodes = [];
|
|
1189
|
+
// Declarations first, then nested children
|
|
1190
|
+
const ruleChildren = [
|
|
1191
|
+
...rule.declarations,
|
|
1192
|
+
...(rule.children || []),
|
|
1193
|
+
];
|
|
1194
|
+
for (const child of ruleChildren) {
|
|
1195
|
+
if (child.type !== 'declaration' && child.type !== 'comment' && value !== '&' && !_parents.some(p => p === value)) {
|
|
1196
|
+
_parents.push(value);
|
|
1197
|
+
}
|
|
1198
|
+
const rule_value = this.astToArray({ ast: child, collectSources, parent: rule, parents: [..._parents], source: loc, debug, _sourceKey }).slice();
|
|
1199
|
+
if (rule_value.length > 0) {
|
|
1200
|
+
if (child.type !== 'declaration' && child.type !== 'comment') {
|
|
1201
|
+
// nested atrule comment → keep inline
|
|
1202
|
+
if (child.type === 'atrule' && child.name.startsWith('comment')) {
|
|
1203
|
+
children.push(...rule_value);
|
|
1204
|
+
}
|
|
1205
|
+
else {
|
|
1206
|
+
flattened_nodes.push(...rule_value);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
else {
|
|
1210
|
+
children.push(...rule_value);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
let collected = false;
|
|
1215
|
+
if (collect !== false && children.length > 0 && !children.find(c => c.kind === 'decl' && c.name === '--source')) {
|
|
1216
|
+
const sourceKey = _sourceKey ? _sourceKey : _a.generateSourceKey(10);
|
|
1217
|
+
const source_string = `--source: ${sourceKey};`;
|
|
1218
|
+
const sourceParsed = _a.parse(source_string);
|
|
1219
|
+
const currentIdx = children.findIndex(i => i.kind === 'decl' && i.name === '--source');
|
|
1220
|
+
if (currentIdx !== -1) {
|
|
1221
|
+
children[currentIdx].value = `${sourceKey}`;
|
|
1222
|
+
}
|
|
1223
|
+
else if (children.length > 0 && children.every(c => c.kind === 'decl' || c.kind === 'comment')) {
|
|
1224
|
+
children.push({
|
|
1225
|
+
kind: 'decl',
|
|
1226
|
+
name: '--source',
|
|
1227
|
+
cssNode: sourceParsed,
|
|
1228
|
+
node: source_string,
|
|
1229
|
+
parents: parents.slice(),
|
|
1230
|
+
value: sourceKey,
|
|
1231
|
+
loc,
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
if (!__classPrivateFieldGet(this, _AstParser_sourceMap, "f").has(sourceKey)) {
|
|
1235
|
+
__classPrivateFieldGet(this, _AstParser_sourceMap, "f").set(sourceKey, loc);
|
|
1236
|
+
}
|
|
1237
|
+
collected = true;
|
|
1238
|
+
}
|
|
1239
|
+
if (!collected) {
|
|
1240
|
+
const dclSource = _sourceKey ? { value: _sourceKey } : children.find(c => c.kind === 'decl' && c.name === '--source');
|
|
1241
|
+
if (dclSource && dclSource.value) {
|
|
1242
|
+
const s = __classPrivateFieldGet(this, _AstParser_sourceMap, "f").get(dclSource.value.trim());
|
|
1243
|
+
if (s)
|
|
1244
|
+
loc = s;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
const name = value;
|
|
1248
|
+
const rules = [];
|
|
1249
|
+
if (flattened_nodes.length > 0) {
|
|
1250
|
+
for (const r of flattened_nodes) {
|
|
1251
|
+
if (r.kind === 'rule') {
|
|
1252
|
+
rules.push(Object.assign({}, _a.replaceRulesChild(r, true)));
|
|
1253
|
+
}
|
|
1254
|
+
else if (r.kind === 'atrule' && r.children && !_a.isPluginDeclarativeName(r.name || '')) {
|
|
1255
|
+
rules.push(Object.assign({}, _a.replaceRulesChild(r)));
|
|
1256
|
+
}
|
|
1257
|
+
else {
|
|
1258
|
+
children.push(Object.assign({}, r));
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
if (children.length > 0) {
|
|
1263
|
+
if (name.includes('&')) {
|
|
1264
|
+
if (name === '&') {
|
|
1265
|
+
result.push(...children);
|
|
1266
|
+
}
|
|
1267
|
+
else {
|
|
1268
|
+
const el = Object.assign({ kind: 'rule', name,
|
|
1269
|
+
loc,
|
|
1270
|
+
value, node: stringifyCss(rule), cssNode: rule, parents: parents.slice() }, (children.length > 0 ? { children } : {}));
|
|
1271
|
+
result.push(el);
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
else {
|
|
1275
|
+
const el = Object.assign({ kind: 'rule', name,
|
|
1276
|
+
loc,
|
|
1277
|
+
value, node: stringifyCss(rule), cssNode: rule, parents: parents.slice() }, (children.length > 0 ? { children } : {}));
|
|
1278
|
+
result.push(el);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
if (rules.length > 0)
|
|
1282
|
+
result.push(...rules);
|
|
1283
|
+
}
|
|
1284
|
+
else if (ast.type === 'declaration') {
|
|
1285
|
+
const d = ast;
|
|
1286
|
+
const rawVal = (_h = d.rawValue) !== null && _h !== void 0 ? _h : d.value.map(v => String(v.value)).join(' ');
|
|
1287
|
+
const el = {
|
|
1288
|
+
kind: 'decl',
|
|
1289
|
+
name: d.property,
|
|
1290
|
+
loc,
|
|
1291
|
+
value: rawVal,
|
|
1292
|
+
node: stringifyCss(d),
|
|
1293
|
+
cssNode: d,
|
|
1294
|
+
parents: parents.slice(),
|
|
1295
|
+
important: d.important,
|
|
1296
|
+
};
|
|
1297
|
+
result.push(el);
|
|
1298
|
+
}
|
|
1299
|
+
else if (ast.type === 'comment') {
|
|
1300
|
+
const c = ast;
|
|
1301
|
+
const el = {
|
|
1302
|
+
kind: 'comment',
|
|
1303
|
+
name: '',
|
|
1304
|
+
loc,
|
|
1305
|
+
value: c.value,
|
|
1306
|
+
parents: parents.slice(),
|
|
1307
|
+
node: stringifyCss(c),
|
|
1308
|
+
cssNode: c,
|
|
1309
|
+
};
|
|
1310
|
+
result.push(el);
|
|
1311
|
+
}
|
|
1312
|
+
else {
|
|
1313
|
+
const el = {
|
|
1314
|
+
kind: 'other',
|
|
1315
|
+
name: stringifyCss(ast),
|
|
1316
|
+
loc,
|
|
1317
|
+
node: stringifyCss(ast),
|
|
1318
|
+
parents: parents.slice(),
|
|
1319
|
+
cssNode: ast,
|
|
1320
|
+
value: stringifyCss(ast),
|
|
1321
|
+
};
|
|
1322
|
+
result.push(el);
|
|
1323
|
+
}
|
|
1324
|
+
return result;
|
|
1325
|
+
}
|
|
1326
|
+
findDecl(node) {
|
|
1327
|
+
var _b;
|
|
1328
|
+
if (node.type === 'rule') {
|
|
1329
|
+
const rule = node;
|
|
1330
|
+
const sourceDecl = rule.declarations.find(d => d.property === '--source');
|
|
1331
|
+
if (sourceDecl && sourceDecl.rawValue) {
|
|
1332
|
+
return (_b = __classPrivateFieldGet(this, _AstParser_sourceMap, "f").get(sourceDecl.rawValue.trim())) !== null && _b !== void 0 ? _b : null;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
return null;
|
|
1336
|
+
}
|
|
1337
|
+
/** @deprecated Use collectSourcesAst instead */
|
|
1338
|
+
collectSources(_cssNode) {
|
|
1339
|
+
return '';
|
|
1340
|
+
}
|
|
1341
|
+
collectSourcesAst(cssNodes) {
|
|
1342
|
+
__classPrivateFieldSet(this, _AstParser_mappings, [], "f");
|
|
1343
|
+
let generatedCode = '';
|
|
1344
|
+
let currentLine = 1;
|
|
1345
|
+
let currentColumn = 0;
|
|
1346
|
+
// Helper to update position based on generated content
|
|
1347
|
+
const updatePosition = (str) => {
|
|
1348
|
+
let final_str = "";
|
|
1349
|
+
for (const char of str) {
|
|
1350
|
+
if (char === '\n') {
|
|
1351
|
+
currentLine++;
|
|
1352
|
+
currentColumn = 0;
|
|
1353
|
+
// if(!this.#options.minify){
|
|
1354
|
+
// }
|
|
1355
|
+
}
|
|
1356
|
+
else {
|
|
1357
|
+
currentColumn++;
|
|
1358
|
+
}
|
|
1359
|
+
generatedCode += char;
|
|
1360
|
+
}
|
|
1361
|
+
// generatedCode += final_str;
|
|
1362
|
+
};
|
|
1363
|
+
// Helper to find source location from --source declaration
|
|
1364
|
+
const findSourceLocation = (node) => {
|
|
1365
|
+
if (node.kind === 'rule') {
|
|
1366
|
+
const sourceDecl = (node.children || []).find(child => child.kind === 'decl' && child.name === '--source');
|
|
1367
|
+
if (sourceDecl === null || sourceDecl === void 0 ? void 0 : sourceDecl.value) {
|
|
1368
|
+
return __classPrivateFieldGet(this, _AstParser_sourceMap, "f").get(sourceDecl.value.trim());
|
|
1369
|
+
}
|
|
1370
|
+
else {
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
return node.loc;
|
|
1374
|
+
};
|
|
1375
|
+
// Helper to add mapping
|
|
1376
|
+
const addMapping = (node, str) => {
|
|
1377
|
+
const loc = findSourceLocation(node);
|
|
1378
|
+
// Always emit the CSS text; source map entry is optional
|
|
1379
|
+
if (loc === null || loc === void 0 ? void 0 : loc.source) {
|
|
1380
|
+
__classPrivateFieldGet(this, _AstParser_mappings, "f").push({
|
|
1381
|
+
source: path.resolve(loc.source),
|
|
1382
|
+
original: { line: loc.start.line, column: loc.start.column },
|
|
1383
|
+
generated: { line: currentLine, column: currentColumn },
|
|
1384
|
+
name: null
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
updatePosition(str);
|
|
1388
|
+
};
|
|
1389
|
+
// Process nodes recursively
|
|
1390
|
+
const processNode = (node, indent = '') => {
|
|
1391
|
+
switch (node.kind) {
|
|
1392
|
+
case 'rule':
|
|
1393
|
+
addMapping(node, indent + node.name + ' {\n');
|
|
1394
|
+
for (const child of node.children) {
|
|
1395
|
+
processNode(child, indent + ' ');
|
|
1396
|
+
}
|
|
1397
|
+
updatePosition(indent + '}\n');
|
|
1398
|
+
break;
|
|
1399
|
+
case 'decl':
|
|
1400
|
+
if (node.name === '--source')
|
|
1401
|
+
break;
|
|
1402
|
+
let value = node.value;
|
|
1403
|
+
value = value === '\\xa0' ? ' ' : _a.decode(value.replace(/xa0/g, ' '), __classPrivateFieldGet(this, _AstParser_encoded_tokens, "f"));
|
|
1404
|
+
updatePosition(indent + node.name + ': ' + value + ';\n');
|
|
1405
|
+
// updatePosition(indent + generate(node, { mode: "spec", }) + ';\n');
|
|
1406
|
+
break;
|
|
1407
|
+
case 'atrule':
|
|
1408
|
+
const prelude = node.value ? ' ' + node.value : '';
|
|
1409
|
+
if (node.name === 'fluixi') {
|
|
1410
|
+
break;
|
|
1411
|
+
}
|
|
1412
|
+
updatePosition(indent + '@' + node.name + prelude);
|
|
1413
|
+
if (node.children) {
|
|
1414
|
+
updatePosition(' {\n');
|
|
1415
|
+
for (const child of node.children) {
|
|
1416
|
+
processNode(child, indent + ' ');
|
|
1417
|
+
}
|
|
1418
|
+
updatePosition(indent + '}\n');
|
|
1419
|
+
}
|
|
1420
|
+
else {
|
|
1421
|
+
updatePosition(';\n');
|
|
1422
|
+
}
|
|
1423
|
+
break;
|
|
1424
|
+
case 'comment':
|
|
1425
|
+
updatePosition(indent + '/*' + node.value + '*/\n');
|
|
1426
|
+
break;
|
|
1427
|
+
case 'other':
|
|
1428
|
+
updatePosition(indent + node.value);
|
|
1429
|
+
default:
|
|
1430
|
+
break;
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
for (const cssNode of cssNodes) {
|
|
1434
|
+
processNode(cssNode);
|
|
1435
|
+
}
|
|
1436
|
+
return generatedCode;
|
|
1437
|
+
}
|
|
1438
|
+
arrayToAst(astNodes, options = { removeSource: false, unwrap: false, removeDirectives: false, debug: false, mappings: [], renderComments: false }) {
|
|
1439
|
+
if (!__classPrivateFieldGet(this, _AstParser_sourceMap, "f").get('default')) {
|
|
1440
|
+
__classPrivateFieldGet(this, _AstParser_sourceMap, "f").set('default', __classPrivateFieldGet(this, _AstParser_source, "f"));
|
|
1441
|
+
}
|
|
1442
|
+
const children = astNodes.flatMap(node => {
|
|
1443
|
+
const converted = _a.convertNode(node, __classPrivateFieldGet(this, _AstParser_sourceMap, "f"), __classPrivateFieldGet(this, _AstParser_sourceLocations, "f"), options.removeDirectives || false, options, __classPrivateFieldGet(this, _AstParser_encoded_tokens, "f"));
|
|
1444
|
+
if (!converted)
|
|
1445
|
+
return [];
|
|
1446
|
+
return Array.isArray(converted) ? converted : [converted];
|
|
1447
|
+
});
|
|
1448
|
+
return makeStylesheet(children);
|
|
1449
|
+
}
|
|
1450
|
+
findImportSource(node, nodes) {
|
|
1451
|
+
let source;
|
|
1452
|
+
if (nodes) {
|
|
1453
|
+
for (const i of nodes) {
|
|
1454
|
+
if (i.node === node.node) {
|
|
1455
|
+
source = i;
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
else {
|
|
1461
|
+
for (const i of __classPrivateFieldGet(this, _AstParser_atImportMaps, "f")) {
|
|
1462
|
+
if (!i.atImport)
|
|
1463
|
+
continue;
|
|
1464
|
+
const astNodes = this.astToArray({ ast: i.atImport });
|
|
1465
|
+
const v = astNodes.find(n => n.node === node.node || node.node === _a.generate(i.atImport));
|
|
1466
|
+
if (v) {
|
|
1467
|
+
source = v;
|
|
1468
|
+
break;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
if (!source) {
|
|
1472
|
+
const v = __classPrivateFieldGet(this, _AstParser_astArray, "f").find(n => n.node === node.node);
|
|
1473
|
+
if (v) {
|
|
1474
|
+
source = v;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
return source;
|
|
1479
|
+
}
|
|
1480
|
+
replaceSources(nodes, sources) {
|
|
1481
|
+
const result = [];
|
|
1482
|
+
for (const node of nodes) {
|
|
1483
|
+
const source = this.findImportSource(node, sources);
|
|
1484
|
+
if (!source) {
|
|
1485
|
+
result.push(node);
|
|
1486
|
+
continue;
|
|
1487
|
+
}
|
|
1488
|
+
node.loc = Object.assign({}, source.loc);
|
|
1489
|
+
if (node.children) {
|
|
1490
|
+
node.children = this.replaceSources(node.children, source.children);
|
|
1491
|
+
const idx = node.children.findIndex(c => c.name === '--source');
|
|
1492
|
+
if (idx === -1) {
|
|
1493
|
+
// Remove and map to found source location
|
|
1494
|
+
// node.children.splice(idx, 1);
|
|
1495
|
+
_a.addAstDeclarationSource(node, __classPrivateFieldGet(this, _AstParser_sourceMap, "f"), Object.assign({}, source.loc));
|
|
1496
|
+
}
|
|
1497
|
+
// const decl = node.children.find(c=>c.name === '--source');
|
|
1498
|
+
}
|
|
1499
|
+
result.push(node);
|
|
1500
|
+
}
|
|
1501
|
+
return result;
|
|
1502
|
+
}
|
|
1503
|
+
walkAstAndTransform(astNodes, parent, parents = []) {
|
|
1504
|
+
var _b, _c, _d;
|
|
1505
|
+
const transformedNodes = []; // Preallocate the result array
|
|
1506
|
+
for (const node of astNodes) {
|
|
1507
|
+
if (node.kind === 'atrule') {
|
|
1508
|
+
if (node.name === 'import') {
|
|
1509
|
+
const _at = __classPrivateFieldGet(this, _AstParser_atImportMaps, "f").find(i => i.node === node.node);
|
|
1510
|
+
if (_at) {
|
|
1511
|
+
const { atImport } = _at;
|
|
1512
|
+
if (atImport) {
|
|
1513
|
+
const nodes = this.astToArray({ ast: atImport });
|
|
1514
|
+
if (state.config && state.config.debug) {
|
|
1515
|
+
console.time(`walk transform ${node.node}`);
|
|
1516
|
+
}
|
|
1517
|
+
const transformed = this.walkAstAndTransform(nodes, parent, [...parents]);
|
|
1518
|
+
this.collectUtilities(transformed);
|
|
1519
|
+
node.children = transformed;
|
|
1520
|
+
transformedNodes.push(node);
|
|
1521
|
+
if (state.config && state.config.debug) {
|
|
1522
|
+
console.timeEnd(`walk transform ${node.node}`);
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
else if (node.name === 'screen') {
|
|
1528
|
+
const media = this.HandleScreens(node);
|
|
1529
|
+
if (media) {
|
|
1530
|
+
node.name = media.name;
|
|
1531
|
+
node.value = media.prelude.value;
|
|
1532
|
+
// generate(media.prelude!, { mode: "spec" });
|
|
1533
|
+
}
|
|
1534
|
+
else if (node.children && node.children.length > 0) {
|
|
1535
|
+
const transformed = this.walkAstAndTransform(node.children, undefined, [...parents]);
|
|
1536
|
+
node.children = transformed;
|
|
1537
|
+
transformedNodes.push(node);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
else if (_a.at_rules_design_fns.some(n => n === node.name)) {
|
|
1541
|
+
let sourceDecl = (_b = parent === null || parent === void 0 ? void 0 : parent.children) === null || _b === void 0 ? void 0 : _b.find(c => c.kind === 'decl' && c.name === '--source');
|
|
1542
|
+
let source;
|
|
1543
|
+
let sourceKey;
|
|
1544
|
+
if (sourceDecl) {
|
|
1545
|
+
source = __classPrivateFieldGet(this, _AstParser_sourceMap, "f").get(((_c = sourceDecl.value) === null || _c === void 0 ? void 0 : _c.trim()) || '');
|
|
1546
|
+
sourceKey = ((_d = sourceDecl.value) === null || _d === void 0 ? void 0 : _d.trim()) || '';
|
|
1547
|
+
}
|
|
1548
|
+
else {
|
|
1549
|
+
source = parent === null || parent === void 0 ? void 0 : parent.loc;
|
|
1550
|
+
}
|
|
1551
|
+
const value = this.astToArray({ ast: this.directiveToCss(node, sourceKey, parents, parent), collectSources: false, parent: null, parents: [], source, debug: false, _sourceKey: sourceKey });
|
|
1552
|
+
node.children = value;
|
|
1553
|
+
transformedNodes.push(node);
|
|
1554
|
+
}
|
|
1555
|
+
else if (node.children && node.children.length > 0) {
|
|
1556
|
+
const transformed = this.walkAstAndTransform(node.children, undefined, [...parents, node]);
|
|
1557
|
+
node.children = transformed;
|
|
1558
|
+
transformedNodes.push(node);
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
else if (node.kind === 'rule') {
|
|
1562
|
+
const transformed = this.walkAstAndTransform(node.children, node, [...parents, node]);
|
|
1563
|
+
node.children = transformed;
|
|
1564
|
+
transformedNodes.push(node);
|
|
1565
|
+
}
|
|
1566
|
+
else {
|
|
1567
|
+
transformedNodes.push(node);
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
return transformedNodes; // Return the preallocated result array
|
|
1571
|
+
}
|
|
1572
|
+
// #sources: any;
|
|
1573
|
+
createSourceMap(sources, generator) {
|
|
1574
|
+
const map = new generator();
|
|
1575
|
+
sources.forEach(item => {
|
|
1576
|
+
map.addMapping({
|
|
1577
|
+
source: item.source,
|
|
1578
|
+
original: {
|
|
1579
|
+
line: item.start.line,
|
|
1580
|
+
column: item.start.column
|
|
1581
|
+
},
|
|
1582
|
+
generated: {
|
|
1583
|
+
line: item.start.line,
|
|
1584
|
+
column: item.start.column
|
|
1585
|
+
}
|
|
1586
|
+
});
|
|
1587
|
+
// Add end position mapping if needed
|
|
1588
|
+
map.addMapping({
|
|
1589
|
+
source: item.source,
|
|
1590
|
+
original: {
|
|
1591
|
+
line: item.end.line,
|
|
1592
|
+
column: item.end.column
|
|
1593
|
+
},
|
|
1594
|
+
generated: {
|
|
1595
|
+
line: item.end.line,
|
|
1596
|
+
column: item.end.column
|
|
1597
|
+
}
|
|
1598
|
+
});
|
|
1599
|
+
});
|
|
1600
|
+
// Add source content for each unique source
|
|
1601
|
+
const uniqueSources = [...new Set(sources.map(item => item.source))];
|
|
1602
|
+
uniqueSources.forEach(source => {
|
|
1603
|
+
const content = readFileSync(source, 'utf-8');
|
|
1604
|
+
map.setSourceContent(source, content);
|
|
1605
|
+
});
|
|
1606
|
+
return map.toJSON();
|
|
1607
|
+
}
|
|
1608
|
+
walkSource(cssNode) {
|
|
1609
|
+
const map = new SourceMapGenerator({
|
|
1610
|
+
file: this.file,
|
|
1611
|
+
sourceRoot: ''
|
|
1612
|
+
});
|
|
1613
|
+
walkCss(cssNode, {
|
|
1614
|
+
enter: (node) => {
|
|
1615
|
+
if (!node.loc) {
|
|
1616
|
+
node.loc = __classPrivateFieldGet(this, _AstParser_source, "f");
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
if (node.loc.source) {
|
|
1620
|
+
try {
|
|
1621
|
+
const content = readFileSync(node.loc.source, 'utf8');
|
|
1622
|
+
map.setSourceContent(node.loc.source, content);
|
|
1623
|
+
__classPrivateFieldGet(this, _AstParser_mappings, "f").forEach(m => { map.addMapping(m); });
|
|
1624
|
+
}
|
|
1625
|
+
catch (err) {
|
|
1626
|
+
logger('@fluixi/css', `Error generating source map for ${node.loc.source}: ${err}`);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
});
|
|
1631
|
+
return map;
|
|
1632
|
+
}
|
|
1633
|
+
static asClassName(name) {
|
|
1634
|
+
return _a.isSpecial(name) ? `.${formatClassName(name)}` : `${name}`;
|
|
1635
|
+
}
|
|
1636
|
+
removeUtilities(nodes, removedClasses) {
|
|
1637
|
+
var _b;
|
|
1638
|
+
const result = [];
|
|
1639
|
+
for (const node of nodes.slice()) {
|
|
1640
|
+
const match = removedClasses.some(c => c === _a.asClassName(node.name));
|
|
1641
|
+
if (node.kind === 'rule' && match) {
|
|
1642
|
+
// return [];
|
|
1643
|
+
}
|
|
1644
|
+
else if (node.kind === "atrule" && node.name === "layer" && ((_b = node.value) === null || _b === void 0 ? void 0 : _b.trim()) === "utilities" && node.children && node.children.length > 0) {
|
|
1645
|
+
const children = this.removeUtilities(node.children, removedClasses);
|
|
1646
|
+
if (children.length > 0) {
|
|
1647
|
+
node.children = children;
|
|
1648
|
+
}
|
|
1649
|
+
result.push(node);
|
|
1650
|
+
}
|
|
1651
|
+
else {
|
|
1652
|
+
result.push(node);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return result;
|
|
1656
|
+
}
|
|
1657
|
+
addUtilities(nodes, utilities) {
|
|
1658
|
+
var _b, _c, _d;
|
|
1659
|
+
if (utilities.length === 0) {
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1662
|
+
const utilitiesLayer = nodes.find(n => n.name === "layer" && n.value === "utilities");
|
|
1663
|
+
if (utilitiesLayer) {
|
|
1664
|
+
const atomic = DesignSystem.generateAtomicCSS(utilities, state, (_b = this.designSystem) === null || _b === void 0 ? void 0 : _b.config, (_c = this.designSystem) === null || _c === void 0 ? void 0 : _c.config);
|
|
1665
|
+
const parsed = this.astToArray({ ast: _a.parse(`${atomic}`, { context: "stylesheet" }, __classPrivateFieldGet(this, _AstParser_options, "f").minify) });
|
|
1666
|
+
logger(`${utilities.length} utilities added`, '');
|
|
1667
|
+
(_d = utilitiesLayer.children) === null || _d === void 0 ? void 0 : _d.push(...parsed);
|
|
1668
|
+
// utilitiesLayer.children = [...this.astToArray(AstParser.parse(`@layer atomic{${atomic}}`), null, [], source), ...utilitiesLayer.children]
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
transform(options = { sourceMap: false, unwrap: false, sources: [] }) {
|
|
1672
|
+
// if(this.designSystem){
|
|
1673
|
+
// const buildType = this.designSystem.buildType;
|
|
1674
|
+
// console.log('build type', buildType)
|
|
1675
|
+
// if(buildType === 'no-changes' || buildType === 'partial'){
|
|
1676
|
+
// const cachedAst = this.designSystem.cacheData?.ast;
|
|
1677
|
+
// if(cachedAst){
|
|
1678
|
+
// let ast = cachedAst as AstNode[];
|
|
1679
|
+
// // console.log('cached ast', ast)
|
|
1680
|
+
// if(buildType !== 'no-changes'){
|
|
1681
|
+
// // console.log('no changes on build')
|
|
1682
|
+
// const utilitiesClasses = this.designSystem.updateContextData?.addedUtilitiesClasses;
|
|
1683
|
+
// const classes = this.designSystem.updateContextData?.addedClasses;
|
|
1684
|
+
// const removedUtilitiesClasses = this.designSystem.updateContextData?.removedUtilitiesClasses;
|
|
1685
|
+
// const removedClasses = this.designSystem.updateContextData?.removedClasses;
|
|
1686
|
+
// const added = [...(utilitiesClasses || []), ...(classes || [])];
|
|
1687
|
+
// const removed = [...(removedUtilitiesClasses || []), ...(removedClasses || [])];
|
|
1688
|
+
// console.log('added', added);
|
|
1689
|
+
// console.log('removed', removed);
|
|
1690
|
+
// if(removed.length>0){
|
|
1691
|
+
// const removedNodes = this.removeUtilities(ast.slice(), removed);
|
|
1692
|
+
// if(removedNodes.length>0){
|
|
1693
|
+
// logger(`${removed.length} utilities removed`, '')
|
|
1694
|
+
// ast = removedNodes;
|
|
1695
|
+
// }
|
|
1696
|
+
// }
|
|
1697
|
+
// if(added.length>0){
|
|
1698
|
+
// this.addUtilities(ast, added);
|
|
1699
|
+
// }
|
|
1700
|
+
// }
|
|
1701
|
+
// this.designSystem?.buildVisualizerOutput();
|
|
1702
|
+
// const styles = this.generateStyles(ast, {
|
|
1703
|
+
// removeSource: true,
|
|
1704
|
+
// // unwrap: options.unwrap,
|
|
1705
|
+
// unwrap: false,
|
|
1706
|
+
// removeDirectives: true,
|
|
1707
|
+
// sourceMap: options.sourceMap
|
|
1708
|
+
// })
|
|
1709
|
+
// if(buildType === 'partial'){
|
|
1710
|
+
// this.designSystem?.saveCache(ast);
|
|
1711
|
+
// }
|
|
1712
|
+
// return styles;
|
|
1713
|
+
// // return {cssNode: this.arrayToAst(ast), css: AstParser.generate(ast), ast};
|
|
1714
|
+
// }
|
|
1715
|
+
// }
|
|
1716
|
+
// }
|
|
1717
|
+
var _b, _c, _d;
|
|
1718
|
+
// console.time('load base')
|
|
1719
|
+
this.loadBaseSources();
|
|
1720
|
+
__classPrivateFieldSet(this, _AstParser_astArray, this.astToArray({ ast: (_b = __classPrivateFieldGet(this, _AstParser_initial, "f")) === null || _b === void 0 ? void 0 : _b.ast, collectSources: false, collect: false }), "f");
|
|
1721
|
+
let astArray = [];
|
|
1722
|
+
if (this.replaceSource) {
|
|
1723
|
+
// console.time('replace sources')
|
|
1724
|
+
astArray = this.replaceSources(this.astToArray({ ast: __classPrivateFieldGet(this, _AstParser_ast, "f"), collectSources: false, collect: false }));
|
|
1725
|
+
// console.timeEnd('replace sources')
|
|
1726
|
+
}
|
|
1727
|
+
else {
|
|
1728
|
+
astArray = this.astToArray({ ast: __classPrivateFieldGet(this, _AstParser_ast, "f"), collectSources: true });
|
|
1729
|
+
}
|
|
1730
|
+
const array = astArray.slice();
|
|
1731
|
+
this.collectUtilities(array);
|
|
1732
|
+
const walked = this.walkAstAndTransform(array);
|
|
1733
|
+
const t = _a.generate(this.unwrap(this.arrayToAst(walked, { removeDirectives: true, removeSource: true })));
|
|
1734
|
+
const transformer = _a.getBaseTransformer(state.config, this.file, __classPrivateFieldGet(this, _AstParser_options, "f").resolveLocalPresets);
|
|
1735
|
+
const ast = this.addPresets(walked, transformer);
|
|
1736
|
+
const styles = this.generateStyles(ast.ast, {
|
|
1737
|
+
cssNode: ast.cssNode,
|
|
1738
|
+
removeSource: true,
|
|
1739
|
+
unwrap: options.unwrap,
|
|
1740
|
+
removeDirectives: true,
|
|
1741
|
+
sourceMap: options.sourceMap
|
|
1742
|
+
});
|
|
1743
|
+
// console.log('generate styles from ast transform')
|
|
1744
|
+
styles.cssNode.loc = __classPrivateFieldGet(this, _AstParser_source, "f");
|
|
1745
|
+
(_c = this.designSystem) === null || _c === void 0 ? void 0 : _c.buildVisualizerOutput();
|
|
1746
|
+
// this.designSystem?.saveCache(ast.ast);
|
|
1747
|
+
return Object.assign(Object.assign({}, styles), { files: (_d = this.designSystem) === null || _d === void 0 ? void 0 : _d.files });
|
|
1748
|
+
}
|
|
1749
|
+
get mappings() {
|
|
1750
|
+
return __classPrivateFieldGet(this, _AstParser_mappings, "f");
|
|
1751
|
+
}
|
|
1752
|
+
getPreludeString(cssNode) {
|
|
1753
|
+
var _b, _c;
|
|
1754
|
+
if (!cssNode)
|
|
1755
|
+
return '';
|
|
1756
|
+
if (cssNode.type === 'rule')
|
|
1757
|
+
return (_b = cssNode.rawSelector) !== null && _b !== void 0 ? _b : '';
|
|
1758
|
+
if (cssNode.type === 'atrule')
|
|
1759
|
+
return (_c = cssNode.preludeText) !== null && _c !== void 0 ? _c : '';
|
|
1760
|
+
return '';
|
|
1761
|
+
}
|
|
1762
|
+
getDecltring(cssNode) {
|
|
1763
|
+
var _b;
|
|
1764
|
+
if (!cssNode)
|
|
1765
|
+
return '';
|
|
1766
|
+
return _a.decrypt((_b = cssNode.rawValue) !== null && _b !== void 0 ? _b : '');
|
|
1767
|
+
}
|
|
1768
|
+
getAtRuleCommentValue(el) {
|
|
1769
|
+
var _b, _c;
|
|
1770
|
+
const decl = (_b = el.block) === null || _b === void 0 ? void 0 : _b.children[0];
|
|
1771
|
+
if (!decl)
|
|
1772
|
+
return '';
|
|
1773
|
+
return _a.decrypt((_c = decl.rawValue) !== null && _c !== void 0 ? _c : '');
|
|
1774
|
+
}
|
|
1775
|
+
reinsertComments(css) {
|
|
1776
|
+
const ast = cloneNodeDeep(css);
|
|
1777
|
+
walkCss(ast, {
|
|
1778
|
+
atrule(node, ctx) {
|
|
1779
|
+
var _b, _c;
|
|
1780
|
+
if (node.name.startsWith('comment')) {
|
|
1781
|
+
const decl = (_b = node.block) === null || _b === void 0 ? void 0 : _b.children[0];
|
|
1782
|
+
const v = _a.decrypt((_c = decl === null || decl === void 0 ? void 0 : decl.rawValue) !== null && _c !== void 0 ? _c : '');
|
|
1783
|
+
const commentNode = {
|
|
1784
|
+
type: 'comment',
|
|
1785
|
+
value: v,
|
|
1786
|
+
style: v.includes('\n') ? 'multi-line' : 'single-line',
|
|
1787
|
+
loc: node.loc,
|
|
1788
|
+
};
|
|
1789
|
+
// Insert comment before this atrule, then keep the atrule
|
|
1790
|
+
// We do this by replacing the node with an array via parent manipulation.
|
|
1791
|
+
// Simplest: replace the comment-atrule with the comment node itself.
|
|
1792
|
+
ctx.replace(commentNode);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
});
|
|
1796
|
+
return ast;
|
|
1797
|
+
}
|
|
1798
|
+
unwrap(css) {
|
|
1799
|
+
walkCss(css, {
|
|
1800
|
+
atrule(node, ctx) {
|
|
1801
|
+
var _b;
|
|
1802
|
+
if (node.name === 'layer' && [..._a.PLUGIN_LAYERS, 'atomic'].some(l => { var _b; return l === ((_b = node.preludeText) === null || _b === void 0 ? void 0 : _b.trim()); })) {
|
|
1803
|
+
const children = (_b = node.block) === null || _b === void 0 ? void 0 : _b.children;
|
|
1804
|
+
if (children && children.length > 0) {
|
|
1805
|
+
// Replace with first child; the rest are pushed by repeated replacement.
|
|
1806
|
+
// For full replacement of one node with N children, we need to handle via parent.
|
|
1807
|
+
// Since our walker supports replace() for single node, we serialize and re-parse.
|
|
1808
|
+
// Alternatively, mark for removal and add children to parent — done after walk.
|
|
1809
|
+
// ctx.remove();
|
|
1810
|
+
ctx.replace(node.block.children);
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
});
|
|
1815
|
+
return css;
|
|
1816
|
+
}
|
|
1817
|
+
generateStyles(ast, options = { sourceMap: false, unwrap: false, removeSource: false, removeDirectives: false }) {
|
|
1818
|
+
const initialCssNode = options.cssNode ? Object.assign({}, options.cssNode) : this.arrayToAst(ast, {
|
|
1819
|
+
removeSource: false,
|
|
1820
|
+
unwrap: options.unwrap,
|
|
1821
|
+
removeDirectives: options.removeDirectives,
|
|
1822
|
+
debug: true,
|
|
1823
|
+
mappings: __classPrivateFieldGet(this, _AstParser_mappings, "f")
|
|
1824
|
+
});
|
|
1825
|
+
// Apply comment reinsertion
|
|
1826
|
+
// const cssNode = this.#options.minify ? initialCssNode : this.reinsertComments(initialCssNode);
|
|
1827
|
+
const cssNode = initialCssNode;
|
|
1828
|
+
// const cssNode = this.#options.minify ? initialCssNode : this.reinsertComments(initialCssNode);
|
|
1829
|
+
let css = _a.generate(options.unwrap ? this.unwrap(cssNode) : cssNode);
|
|
1830
|
+
// writeFileSync(path.join(cwd(), 'walked_presets.css'), css);
|
|
1831
|
+
let map;
|
|
1832
|
+
css = this.collectSourcesAst(ast);
|
|
1833
|
+
if (options.sourceMap && !__classPrivateFieldGet(this, _AstParser_options, "f").minify) {
|
|
1834
|
+
map = this.createSourcesMap();
|
|
1835
|
+
}
|
|
1836
|
+
else {
|
|
1837
|
+
if (__classPrivateFieldGet(this, _AstParser_options, "f").minify) {
|
|
1838
|
+
css = _a.optimize(css, __classPrivateFieldGet(this, _AstParser_file, "f"), { minify: __classPrivateFieldGet(this, _AstParser_options, "f").minify }).code;
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
css = css.replace(/xa0/g, ' ');
|
|
1842
|
+
return { cssNode, css, ast, map };
|
|
1843
|
+
}
|
|
1844
|
+
attachLayer(nodes, content, name) {
|
|
1845
|
+
if (!content || content.length === 0 || !name) {
|
|
1846
|
+
return undefined;
|
|
1847
|
+
}
|
|
1848
|
+
const source = __classPrivateFieldGet(this, _AstParser_sourceLocations, "f").get(name === 'atomic' ? "utilities" : name);
|
|
1849
|
+
const layer = nodes.find(n => n.name === "layer" && (n.value === name));
|
|
1850
|
+
if (layer) {
|
|
1851
|
+
if (!layer.children) {
|
|
1852
|
+
layer.children = [];
|
|
1853
|
+
}
|
|
1854
|
+
layer.children = [...this.astToArray({ ast: _a.parse(content, {}, __classPrivateFieldGet(this, _AstParser_options, "f").minify), collectSources: false, parent: null, parents: [], source, debug: false, _sourceKey: name === 'atomic' ? "utilities" : name }), ...layer.children];
|
|
1855
|
+
return undefined;
|
|
1856
|
+
}
|
|
1857
|
+
else {
|
|
1858
|
+
const str = `@layer ${name} {${content}}`;
|
|
1859
|
+
// writeFileSync(join(cwd(), `${name}-layer.css`), str)
|
|
1860
|
+
const atomic = this.astToArray({ ast: _a.parse(str, {}, __classPrivateFieldGet(this, _AstParser_options, "f").minify), collectSources: false, parent: null, parents: [], source, debug: false, _sourceKey: name === 'atomic' ? "utilities" : name });
|
|
1861
|
+
return atomic;
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
static getLayerWeight(kind, name) {
|
|
1865
|
+
if (kind === 'import') {
|
|
1866
|
+
return _a.LAYERS_WEIGHT.imports;
|
|
1867
|
+
}
|
|
1868
|
+
if (!name) {
|
|
1869
|
+
return _a.LAYERS_WEIGHT.other;
|
|
1870
|
+
}
|
|
1871
|
+
return this.LAYERS_WEIGHT[name.replace('@', '')] || _a.LAYERS_WEIGHT.other;
|
|
1872
|
+
}
|
|
1873
|
+
orderNodes(nodes) {
|
|
1874
|
+
return nodes.sort((a, b) => {
|
|
1875
|
+
return _a.getLayerWeight(a.name, a.value) - _a.getLayerWeight(b.name, b.value);
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
addPresets(astNodes, transformer) {
|
|
1879
|
+
const merge = _a.merge(astNodes.slice()).pop();
|
|
1880
|
+
const layers = [..._a.PLUGIN_LAYERS, "atomic"];
|
|
1881
|
+
for (const layer of layers) {
|
|
1882
|
+
if (layer === "atomic") {
|
|
1883
|
+
if (transformer.atomic_css.length > 0) {
|
|
1884
|
+
const l = this.attachLayer(merge, transformer.atomic_css, "atomic");
|
|
1885
|
+
if (l) {
|
|
1886
|
+
merge.push(...l);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
else {
|
|
1891
|
+
const l = this.attachLayer(merge, transformer[layer], layer);
|
|
1892
|
+
if (l) {
|
|
1893
|
+
merge.push(...l);
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
// const ordered = merge.slice();
|
|
1898
|
+
// const ordered = AstParser.processNesting(this.orderNodes(merge.slice()));
|
|
1899
|
+
const ordered = this.orderNodes(merge.slice());
|
|
1900
|
+
const generated = _a.generate(this.arrayToAst(ordered, { renderComments: true, removeSource: false }));
|
|
1901
|
+
const optimized = _a.optimize(generated, this.file, { minify: false });
|
|
1902
|
+
// writeFileSync(join(cwd(), 'generated_presets.css'), optimized.code)
|
|
1903
|
+
const parsed = _a.parse(optimized.code, { positions: true, filename: this.file, }, true);
|
|
1904
|
+
walkCss(parsed, {
|
|
1905
|
+
rule: (node, ctx) => {
|
|
1906
|
+
const dcl = this.findDecl(node);
|
|
1907
|
+
if (dcl && node.declarations.length === 1) {
|
|
1908
|
+
ctx.remove();
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
});
|
|
1912
|
+
const cssNode = parsed;
|
|
1913
|
+
const ast = this.astToArray({ ast: cssNode, collectSources: false, parent: null, parents: [], source: undefined, debug: false, _sourceKey: undefined });
|
|
1914
|
+
return { cssNode, ast };
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
_a = AstParser, _AstParser_ast = new WeakMap(), _AstParser_file = new WeakMap(), _AstParser_requireImports = new WeakMap(), _AstParser_hasImports = new WeakMap(), _AstParser_hasImportMatch = new WeakMap(), _AstParser_hasImportsDone = new WeakMap(), _AstParser_replaceSource = new WeakMap(), _AstParser_cachedJit = new WeakMap(), _AstParser_encoded_tokens = new WeakMap(), _AstParser_dependencies = new WeakMap(), _AstParser_atImportMaps = new WeakMap(), _AstParser_source = new WeakMap(), _AstParser_sourceLocations = new WeakMap(), _AstParser_initial = new WeakMap(), _AstParser_imports = new WeakMap(), _AstParser_sourceMap = new WeakMap(), _AstParser_options = new WeakMap(), _AstParser_astArray = new WeakMap(), _AstParser_mappings = new WeakMap();
|
|
1918
|
+
AstParser.at_rules_design_fns = ["defal", "apply"];
|
|
1919
|
+
AstParser.ImportsMatch = {
|
|
1920
|
+
"@fluixi/css-core/base": "base",
|
|
1921
|
+
"@fluixi/css-core/utilities": "utilities",
|
|
1922
|
+
"@fluixi/css-core/components": "components",
|
|
1923
|
+
"@fluixi/css-core/reset": "reset",
|
|
1924
|
+
};
|
|
1925
|
+
AstParser.PLUGIN_LAYERS = ["base", "utilities", "components"];
|
|
1926
|
+
AstParser.unquote = (params) => {
|
|
1927
|
+
const param = /(?:[^'"`\s]+(?:[^'"`])*.)(?=['"`])/.exec(params.toString());
|
|
1928
|
+
return param ? param[0] : params;
|
|
1929
|
+
};
|
|
1930
|
+
AstParser.createComment = (currentComment) => {
|
|
1931
|
+
var _b, _c;
|
|
1932
|
+
const key = _a.generateSourceKey(8);
|
|
1933
|
+
const selector = `rule-comment-${key}`;
|
|
1934
|
+
const rawVal = ((_b = currentComment.value) === null || _b === void 0 ? void 0 : _b.startsWith('encrypted-'))
|
|
1935
|
+
? currentComment.value
|
|
1936
|
+
: `"encrypted-${_a.encrypt((_c = currentComment.value) !== null && _c !== void 0 ? _c : '')}"`;
|
|
1937
|
+
const ar = {
|
|
1938
|
+
type: 'atrule',
|
|
1939
|
+
name: `comment-${key}`,
|
|
1940
|
+
preludeText: _a.generateSourceKey(8),
|
|
1941
|
+
prelude: [],
|
|
1942
|
+
block: {
|
|
1943
|
+
type: 'block',
|
|
1944
|
+
children: [{
|
|
1945
|
+
type: 'declaration',
|
|
1946
|
+
property: `--${selector}-content`,
|
|
1947
|
+
rawValue: rawVal,
|
|
1948
|
+
value: [],
|
|
1949
|
+
important: false,
|
|
1950
|
+
}],
|
|
1951
|
+
},
|
|
1952
|
+
loc: currentComment.loc,
|
|
1953
|
+
};
|
|
1954
|
+
return ar;
|
|
1955
|
+
};
|
|
1956
|
+
AstParser.DefineBaseImports = (options) => {
|
|
1957
|
+
const utilities = state.utilities;
|
|
1958
|
+
const { base } = utilities;
|
|
1959
|
+
let css = '';
|
|
1960
|
+
let values = base;
|
|
1961
|
+
const maybe_jit = [];
|
|
1962
|
+
if (values) {
|
|
1963
|
+
for (const key in values) {
|
|
1964
|
+
css += objectToCssString({ [key]: values[key] });
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
let cssUtilities = '';
|
|
1968
|
+
if (options.purge) {
|
|
1969
|
+
const classes = (state.utilities_classes || []);
|
|
1970
|
+
for (const key of classes) {
|
|
1971
|
+
if (utilities && utilities.classMapFlattened.hasOwnProperty(key)) {
|
|
1972
|
+
let css;
|
|
1973
|
+
let className;
|
|
1974
|
+
if (key.startsWith('space')) {
|
|
1975
|
+
css = objectToCss({ ["{& >:not([hidden]) ~ :not([hidden])}"]: utilities.classMapFlattened[key] }, undefined, `.${key}`, false, false, 0, false);
|
|
1976
|
+
className = `.${key}`;
|
|
1977
|
+
}
|
|
1978
|
+
else {
|
|
1979
|
+
css = objectToCss(utilities.classMapFlattened[key], undefined, `.${key}`, false, false, 0, false);
|
|
1980
|
+
className = `.${key}`;
|
|
1981
|
+
}
|
|
1982
|
+
if (className && css) {
|
|
1983
|
+
cssUtilities += css;
|
|
1984
|
+
state.updateCssUtilities({ [className]: css });
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
else {
|
|
1988
|
+
maybe_jit.push(key);
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
else {
|
|
1993
|
+
for (const key in utilities === null || utilities === void 0 ? void 0 : utilities.classMapFlattened) {
|
|
1994
|
+
if (utilities.classMapFlattened.hasOwnProperty(key)) {
|
|
1995
|
+
const css = objectToCss(utilities.classMapFlattened[key], undefined, `.${key}`, false, false, 0, false);
|
|
1996
|
+
const className = `.${key}`;
|
|
1997
|
+
if (css.length > 0 && className.length > 0) {
|
|
1998
|
+
cssUtilities += css;
|
|
1999
|
+
state.updateCssUtilities({ [className]: css });
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
return { base: css, utilities: cssUtilities, maybe_jit };
|
|
2005
|
+
};
|
|
2006
|
+
AstParser.getBaseTransformer = (_options, file, resolveLocalPresets = false) => {
|
|
2007
|
+
const { base: layer_base_import, utilities: layer_utilities_import, maybe_jit } = _a.DefineBaseImports(_options);
|
|
2008
|
+
const ut = state.utilities;
|
|
2009
|
+
const vars = ut.rootVars;
|
|
2010
|
+
const darkVars = ut.darkRootVars;
|
|
2011
|
+
const components_string_vars = ut.components_string_vars;
|
|
2012
|
+
let components = '';
|
|
2013
|
+
const media = createMediaQuery('dark', '*', true);
|
|
2014
|
+
let base_string = '';
|
|
2015
|
+
let utilities_string = '';
|
|
2016
|
+
if (layer_base_import) {
|
|
2017
|
+
base_string += layer_base_import;
|
|
2018
|
+
}
|
|
2019
|
+
if (layer_utilities_import) {
|
|
2020
|
+
utilities_string += layer_utilities_import;
|
|
2021
|
+
}
|
|
2022
|
+
let atomic_css = '';
|
|
2023
|
+
const classes = state.extracted_classes || [];
|
|
2024
|
+
classes.push(...maybe_jit);
|
|
2025
|
+
if (classes.length > 0) {
|
|
2026
|
+
const has_tonal = classes.slice().filter(c => c.includes("tonal"));
|
|
2027
|
+
const atomic = DesignSystem.generateAtomicCSS(classes, state, _options, state.config);
|
|
2028
|
+
if (atomic) {
|
|
2029
|
+
atomic_css += atomic.atomic_css;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
try {
|
|
2033
|
+
const { core_reset } = _a.resolveLocalModulesPath({ resolveLocalPresets });
|
|
2034
|
+
base_string = readFileSync(core_reset, { encoding: 'utf-8' }) + "\n" + base_string;
|
|
2035
|
+
}
|
|
2036
|
+
catch (e) {
|
|
2037
|
+
console.error('exception during importing reset', e);
|
|
2038
|
+
}
|
|
2039
|
+
if (vars && vars.length > 0) {
|
|
2040
|
+
if (media.startsWith('@media')) {
|
|
2041
|
+
base_string += `*,:before,:after,::backdrop{\n${vars}\n}\n`;
|
|
2042
|
+
}
|
|
2043
|
+
else {
|
|
2044
|
+
base_string += `\n:not(${media} *){\n${vars}\n}\n`;
|
|
2045
|
+
// base_string += `\n:root{\n${vars}\n}\n`
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
if (darkVars && darkVars.length > 0) {
|
|
2049
|
+
if (media.startsWith('@media')) {
|
|
2050
|
+
base_string += `\n${media}{\n*,::before,::after,::backdrop{\n${darkVars}\n}\n}`;
|
|
2051
|
+
}
|
|
2052
|
+
else {
|
|
2053
|
+
base_string += `\n${media}{\n${darkVars}\n}\n`;
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
if (components_string_vars !== undefined && components_string_vars.length > 0) {
|
|
2057
|
+
components = `${components_string_vars}`;
|
|
2058
|
+
}
|
|
2059
|
+
const layer = `@layer base, components, utilities;\n@layer base {\n${base_string}\n}\n@layer components {\n${components}\n}\n@layer utilities {\n${utilities_string}\n}`;
|
|
2060
|
+
const parsed = _a.parse(layer, { filename: file });
|
|
2061
|
+
return { layer: parsed, base: base_string, components, utilities: utilities_string, atomic_css };
|
|
2062
|
+
};
|
|
2063
|
+
AstParser.isRule = (astNode) => {
|
|
2064
|
+
return astNode.kind === "rule";
|
|
2065
|
+
};
|
|
2066
|
+
AstParser.isAtRule = (astNode, enforce = false) => {
|
|
2067
|
+
if (astNode.kind !== "atrule")
|
|
2068
|
+
return false;
|
|
2069
|
+
if (!enforce)
|
|
2070
|
+
return true;
|
|
2071
|
+
return (enforce && astNode.children && astNode.children.length > 0);
|
|
2072
|
+
};
|
|
2073
|
+
AstParser.isRuleOrAtRule = (astNode, enforce = false) => {
|
|
2074
|
+
return astNode.kind === "rule" || _a.isAtRule(astNode, enforce);
|
|
2075
|
+
};
|
|
2076
|
+
AstParser.hasChildren = (astNode) => {
|
|
2077
|
+
return astNode.children && astNode.children.length > 0;
|
|
2078
|
+
};
|
|
2079
|
+
AstParser.hasNestedChilds = (node) => {
|
|
2080
|
+
if (node.children && node.children.length > 0) {
|
|
2081
|
+
if (node.children.some(c => { var _b; return _a.isRuleOrAtRule(c) && _a.hasChildren(c) && ((_b = c.children) === null || _b === void 0 ? void 0 : _b.some(cc => cc.kind === 'rule' || cc.kind === 'atrule')); })) {
|
|
2082
|
+
return true;
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
return false;
|
|
2086
|
+
};
|
|
2087
|
+
AstParser.updateLastRule = (astNode, children) => {
|
|
2088
|
+
if (astNode.children && astNode.children.length > 0) {
|
|
2089
|
+
if (_a.hasNestedChilds(astNode)) {
|
|
2090
|
+
for (const c of astNode.children) {
|
|
2091
|
+
if (_a.hasNestedChilds(c)) {
|
|
2092
|
+
_a.updateLastRule(c, children);
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
else {
|
|
2097
|
+
if (_a.isRule(astNode)) {
|
|
2098
|
+
if (!astNode.children)
|
|
2099
|
+
astNode.children = [];
|
|
2100
|
+
astNode.children.push(...children);
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
};
|
|
2105
|
+
AstParser.buildSelector = (selectors) => {
|
|
2106
|
+
const result = [];
|
|
2107
|
+
if (selectors.length <= 1) {
|
|
2108
|
+
return selectors;
|
|
2109
|
+
}
|
|
2110
|
+
selectors.forEach(selector_ => {
|
|
2111
|
+
// If the selector contains '&', treat it as a nested selector
|
|
2112
|
+
const sp = selector_.includes(',') ? splitString(selector_, COMMA_REGEX) : [selector_];
|
|
2113
|
+
const results = [];
|
|
2114
|
+
for (const selector of sp) {
|
|
2115
|
+
if (selector.includes('&')) {
|
|
2116
|
+
const parentSelector = result[result.length - 1] || '';
|
|
2117
|
+
const nestedSelectors = [];
|
|
2118
|
+
if (parentSelector.includes(',')) {
|
|
2119
|
+
const parents = splitString(parentSelector, COMMA_REGEX);
|
|
2120
|
+
nestedSelectors.push(...splitString(selector, COMMA_REGEX).map(nested => parents.map(p => nested.trim().replace(/&/g, p)).join(', ')));
|
|
2121
|
+
}
|
|
2122
|
+
else {
|
|
2123
|
+
nestedSelectors.push(selector.trim().replace(/&/g, parentSelector));
|
|
2124
|
+
// nestedSelectors.push(...splitString(selector, COMMA_REGEX).map(nested => nested.trim().replace(/&/g, parentSelector)));
|
|
2125
|
+
}
|
|
2126
|
+
results.push(...nestedSelectors);
|
|
2127
|
+
}
|
|
2128
|
+
else {
|
|
2129
|
+
// Add the base selector to the result
|
|
2130
|
+
results.push(selector.trim());
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
result.push(results.slice().join(', '));
|
|
2134
|
+
});
|
|
2135
|
+
// Join the result with commas to form the final CSS rule selector
|
|
2136
|
+
return result;
|
|
2137
|
+
};
|
|
2138
|
+
AstParser.optimize = (css, filename = "index.css", options = { map: null, minify: false }) => {
|
|
2139
|
+
const comments = [];
|
|
2140
|
+
const commentPlaceholderPrefix = '/*!__COMMENT_PLACEHOLDER_';
|
|
2141
|
+
const commentPlaceholderSuffix = '__*/';
|
|
2142
|
+
// Replace comments with placeholders and store the original comments
|
|
2143
|
+
let cssWithPlaceholders = css.replace(/\/\*[\s\S]*?\*\//g, (match) => {
|
|
2144
|
+
const index = comments.length;
|
|
2145
|
+
comments.push(match);
|
|
2146
|
+
return `${commentPlaceholderPrefix}${index}${commentPlaceholderSuffix}`;
|
|
2147
|
+
});
|
|
2148
|
+
let { code, map: lightningMap, warnings, } = transform({
|
|
2149
|
+
filename,
|
|
2150
|
+
code: Buffer.from(css),
|
|
2151
|
+
sourceMap: false,
|
|
2152
|
+
inputSourceMap: options.map ? options.map : undefined,
|
|
2153
|
+
drafts: {
|
|
2154
|
+
customMedia: true,
|
|
2155
|
+
},
|
|
2156
|
+
nonStandard: {
|
|
2157
|
+
deepSelectorCombinator: true,
|
|
2158
|
+
},
|
|
2159
|
+
include: Features.Nesting,
|
|
2160
|
+
exclude: Features.LogicalProperties |
|
|
2161
|
+
Features.DirSelector |
|
|
2162
|
+
Features.LightDark,
|
|
2163
|
+
targets: {
|
|
2164
|
+
safari: (16 << 16) | (4 << 8),
|
|
2165
|
+
chrome: 95,
|
|
2166
|
+
firefox: 95,
|
|
2167
|
+
},
|
|
2168
|
+
minify: options.minify || false,
|
|
2169
|
+
errorRecovery: true,
|
|
2170
|
+
});
|
|
2171
|
+
// Replace placeholders with original comments
|
|
2172
|
+
let processedCss = code.toString();
|
|
2173
|
+
// for (let i = 0; i < comments.length; i++) {
|
|
2174
|
+
// const placeholder = `${commentPlaceholderPrefix}${i}${commentPlaceholderSuffix}`;
|
|
2175
|
+
// processedCss = processedCss.replace(placeholder, comments[i]);
|
|
2176
|
+
// }
|
|
2177
|
+
return { code: processedCss, map: lightningMap };
|
|
2178
|
+
// return {code: code.toString(), map: lightningMap};
|
|
2179
|
+
};
|
|
2180
|
+
AstParser.isSpecial = (style) => {
|
|
2181
|
+
return style.includes('.') || style.includes('/');
|
|
2182
|
+
};
|
|
2183
|
+
AstParser.componentsSources = {
|
|
2184
|
+
source: _a.resolveLocalModulesPath().core_components,
|
|
2185
|
+
start: { offset: 0, line: 1, column: 1 },
|
|
2186
|
+
end: { offset: 19, line: 1, column: 20 }
|
|
2187
|
+
};
|
|
2188
|
+
AstParser.formatAstNested = (nodes, child) => {
|
|
2189
|
+
const order = ['atrule', 'rule'];
|
|
2190
|
+
const sorted = nodes.sort((a, b) => {
|
|
2191
|
+
const aIndex = order.indexOf(a.kind);
|
|
2192
|
+
const bIndex = order.indexOf(b.kind);
|
|
2193
|
+
return aIndex - bIndex;
|
|
2194
|
+
});
|
|
2195
|
+
const combined = sorted.reduce((acc, node, index) => {
|
|
2196
|
+
var _b;
|
|
2197
|
+
if (_a.isRule(node)) {
|
|
2198
|
+
let main = _a.findMainRule(acc);
|
|
2199
|
+
if (!main) {
|
|
2200
|
+
// console.log('no main', omit(acc, ['children']))
|
|
2201
|
+
main = node;
|
|
2202
|
+
}
|
|
2203
|
+
else {
|
|
2204
|
+
// if(this.isSelf(node.name || '')){
|
|
2205
|
+
// console.log('main found', main)
|
|
2206
|
+
// }
|
|
2207
|
+
}
|
|
2208
|
+
if (!main.selectors) {
|
|
2209
|
+
main.selectors = [Object.assign(Object.assign({}, node), { kind: "rule" })];
|
|
2210
|
+
}
|
|
2211
|
+
else {
|
|
2212
|
+
if ((_b = node.name) === null || _b === void 0 ? void 0 : _b.startsWith('&')) {
|
|
2213
|
+
main.selectors.forEach(s => {
|
|
2214
|
+
if (!s.selectors)
|
|
2215
|
+
s.selectors = [];
|
|
2216
|
+
s.selectors.push(Object.assign(Object.assign({}, node), { kind: "rule" }));
|
|
2217
|
+
});
|
|
2218
|
+
}
|
|
2219
|
+
else {
|
|
2220
|
+
main.selectors.push(Object.assign(Object.assign({}, node), { kind: "rule" }));
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
else {
|
|
2225
|
+
_a.updateLastRule(acc, child.children || []);
|
|
2226
|
+
}
|
|
2227
|
+
return acc;
|
|
2228
|
+
});
|
|
2229
|
+
return combined;
|
|
2230
|
+
};
|
|
2231
|
+
AstParser.LAYERS_WEIGHT = {
|
|
2232
|
+
"imports": 0,
|
|
2233
|
+
"base": 1,
|
|
2234
|
+
"other": 2,
|
|
2235
|
+
"components": 3,
|
|
2236
|
+
"utilities": 4,
|
|
2237
|
+
"atomic": 5,
|
|
2238
|
+
};
|
|
2239
|
+
export default AstParser;
|
|
2240
|
+
//# sourceMappingURL=ast.js.map
|