@fluixi-css/core 0.1.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/base.css +4 -0
- package/components.css +1 -0
- package/dist/base.css +4 -0
- package/dist/components.css +1 -0
- package/dist/index.css +2 -0
- package/dist/package.json +139 -0
- package/dist/reset.css +168 -0
- package/dist/src/ast.d.ts +298 -0
- package/dist/src/ast.js +2240 -0
- package/dist/src/ast.js.map +1 -0
- package/dist/src/commons/constants.d.ts +1193 -0
- package/dist/src/commons/constants.js +1323 -0
- package/dist/src/commons/constants.js.map +1 -0
- package/dist/src/commons/helper.d.ts +1298 -0
- package/dist/src/commons/helper.js +1310 -0
- package/dist/src/commons/helper.js.map +1 -0
- package/dist/src/commons/index.d.ts +3 -0
- package/dist/src/commons/index.js +4 -0
- package/dist/src/commons/index.js.map +1 -0
- package/dist/src/commons/properties.d.ts +1431 -0
- package/dist/src/commons/properties.js +2855 -0
- package/dist/src/commons/properties.js.map +1 -0
- package/dist/src/commons/types.d.ts +359 -0
- package/dist/src/commons/types.js +4 -0
- package/dist/src/commons/types.js.map +1 -0
- package/dist/src/components/avatar/index.d.ts +19 -0
- package/dist/src/components/avatar/index.js +22 -0
- package/dist/src/components/avatar/index.js.map +1 -0
- package/dist/src/components/button/index.d.ts +48 -0
- package/dist/src/components/button/index.js +51 -0
- package/dist/src/components/button/index.js.map +1 -0
- package/dist/src/components/card/index.d.ts +44 -0
- package/dist/src/components/card/index.js +47 -0
- package/dist/src/components/card/index.js.map +1 -0
- package/dist/src/components/checkbox/index.d.ts +69 -0
- package/dist/src/components/checkbox/index.js +80 -0
- package/dist/src/components/checkbox/index.js.map +1 -0
- package/dist/src/components/daterangepicker/index.d.ts +147 -0
- package/dist/src/components/daterangepicker/index.js +150 -0
- package/dist/src/components/daterangepicker/index.js.map +1 -0
- package/dist/src/components/dialog/index.d.ts +71 -0
- package/dist/src/components/dialog/index.js +74 -0
- package/dist/src/components/dialog/index.js.map +1 -0
- package/dist/src/components/drawer/index.d.ts +26 -0
- package/dist/src/components/drawer/index.js +29 -0
- package/dist/src/components/drawer/index.js.map +1 -0
- package/dist/src/components/dropdown/index.d.ts +101 -0
- package/dist/src/components/dropdown/index.js +104 -0
- package/dist/src/components/dropdown/index.js.map +1 -0
- package/dist/src/components/forms/index.d.ts +58 -0
- package/dist/src/components/forms/index.js +62 -0
- package/dist/src/components/forms/index.js.map +1 -0
- package/dist/src/components/index.d.ts +1228 -0
- package/dist/src/components/index.js +64 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/layout/index.d.ts +28 -0
- package/dist/src/components/layout/index.js +33 -0
- package/dist/src/components/layout/index.js.map +1 -0
- package/dist/src/components/list/index.d.ts +65 -0
- package/dist/src/components/list/index.js +68 -0
- package/dist/src/components/list/index.js.map +1 -0
- package/dist/src/components/popover/index.d.ts +79 -0
- package/dist/src/components/popover/index.js +82 -0
- package/dist/src/components/popover/index.js.map +1 -0
- package/dist/src/components/radio/index.d.ts +77 -0
- package/dist/src/components/radio/index.js +80 -0
- package/dist/src/components/radio/index.js.map +1 -0
- package/dist/src/components/select/index.d.ts +102 -0
- package/dist/src/components/select/index.js +105 -0
- package/dist/src/components/select/index.js.map +1 -0
- package/dist/src/components/sidenav/index.d.ts +98 -0
- package/dist/src/components/sidenav/index.js +101 -0
- package/dist/src/components/sidenav/index.js.map +1 -0
- package/dist/src/components/table/index.d.ts +95 -0
- package/dist/src/components/table/index.js +98 -0
- package/dist/src/components/table/index.js.map +1 -0
- package/dist/src/constants.d.ts +3 -0
- package/dist/src/constants.js +29 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/css-ast.d.ts +48 -0
- package/dist/src/css-ast.js +2 -0
- package/dist/src/css-ast.js.map +1 -0
- package/dist/src/css-generator.d.ts +29 -0
- package/dist/src/css-generator.js +104 -0
- package/dist/src/css-generator.js.map +1 -0
- package/dist/src/css-helpers.d.ts +76 -0
- package/dist/src/css-helpers.js +272 -0
- package/dist/src/css-helpers.js.map +1 -0
- package/dist/src/css-lexer.d.ts +48 -0
- package/dist/src/css-lexer.js +255 -0
- package/dist/src/css-lexer.js.map +1 -0
- package/dist/src/css-parser.cjs +2047 -0
- package/dist/src/css-parser.cjs.map +1 -0
- package/dist/src/css-parser.d.ts +100 -0
- package/dist/src/css-parser.js +1098 -0
- package/dist/src/css-parser.js.map +1 -0
- package/dist/src/css-parser.mjs +2028 -0
- package/dist/src/css-parser.mjs.map +1 -0
- package/dist/src/design-system.d.ts +210 -0
- package/dist/src/design-system.js +1034 -0
- package/dist/src/design-system.js.map +1 -0
- package/dist/src/engine/ast.d.ts +44 -0
- package/dist/src/engine/ast.js +92 -0
- package/dist/src/engine/ast.js.map +1 -0
- package/dist/src/engine/atom.d.ts +74 -0
- package/dist/src/engine/atom.js +227 -0
- package/dist/src/engine/atom.js.map +1 -0
- package/dist/src/engine/compile.d.ts +5 -0
- package/dist/src/engine/compile.js +79 -0
- package/dist/src/engine/compile.js.map +1 -0
- package/dist/src/engine/defaults.d.ts +2 -0
- package/dist/src/engine/defaults.js +14 -0
- package/dist/src/engine/defaults.js.map +1 -0
- package/dist/src/engine/directives.d.ts +2 -0
- package/dist/src/engine/directives.js +191 -0
- package/dist/src/engine/directives.js.map +1 -0
- package/dist/src/engine/index.d.ts +41 -0
- package/dist/src/engine/index.js +88 -0
- package/dist/src/engine/index.js.map +1 -0
- package/dist/src/engine/registry.d.ts +46 -0
- package/dist/src/engine/registry.js +49 -0
- package/dist/src/engine/registry.js.map +1 -0
- package/dist/src/engine/scanner.d.ts +1 -0
- package/dist/src/engine/scanner.js +45 -0
- package/dist/src/engine/scanner.js.map +1 -0
- package/dist/src/engine/source.d.ts +12 -0
- package/dist/src/engine/source.js +81 -0
- package/dist/src/engine/source.js.map +1 -0
- package/dist/src/engine/theme-defaults.d.ts +2 -0
- package/dist/src/engine/theme-defaults.js +54 -0
- package/dist/src/engine/theme-defaults.js.map +1 -0
- package/dist/src/engine/theme-source.d.ts +5 -0
- package/dist/src/engine/theme-source.js +71 -0
- package/dist/src/engine/theme-source.js.map +1 -0
- package/dist/src/engine/theme.d.ts +10 -0
- package/dist/src/engine/theme.js +42 -0
- package/dist/src/engine/theme.js.map +1 -0
- package/dist/src/engine/transform.d.ts +25 -0
- package/dist/src/engine/transform.js +91 -0
- package/dist/src/engine/transform.js.map +1 -0
- package/dist/src/engine/ui-preset.d.ts +4 -0
- package/dist/src/engine/ui-preset.js +56 -0
- package/dist/src/engine/ui-preset.js.map +1 -0
- package/dist/src/engine/utilities/backgrounds.d.ts +2 -0
- package/dist/src/engine/utilities/backgrounds.js +32 -0
- package/dist/src/engine/utilities/backgrounds.js.map +1 -0
- package/dist/src/engine/utilities/borders.d.ts +2 -0
- package/dist/src/engine/utilities/borders.js +95 -0
- package/dist/src/engine/utilities/borders.js.map +1 -0
- package/dist/src/engine/utilities/effects.d.ts +2 -0
- package/dist/src/engine/utilities/effects.js +61 -0
- package/dist/src/engine/utilities/effects.js.map +1 -0
- package/dist/src/engine/utilities/flexgrid.d.ts +2 -0
- package/dist/src/engine/utilities/flexgrid.js +125 -0
- package/dist/src/engine/utilities/flexgrid.js.map +1 -0
- package/dist/src/engine/utilities/index.d.ts +3 -0
- package/dist/src/engine/utilities/index.js +20 -0
- package/dist/src/engine/utilities/index.js.map +1 -0
- package/dist/src/engine/utilities/layout.d.ts +2 -0
- package/dist/src/engine/utilities/layout.js +84 -0
- package/dist/src/engine/utilities/layout.js.map +1 -0
- package/dist/src/engine/utilities/sizing.d.ts +2 -0
- package/dist/src/engine/utilities/sizing.js +21 -0
- package/dist/src/engine/utilities/sizing.js.map +1 -0
- package/dist/src/engine/utilities/spacing.d.ts +2 -0
- package/dist/src/engine/utilities/spacing.js +39 -0
- package/dist/src/engine/utilities/spacing.js.map +1 -0
- package/dist/src/engine/utilities/typography.d.ts +2 -0
- package/dist/src/engine/utilities/typography.js +120 -0
- package/dist/src/engine/utilities/typography.js.map +1 -0
- package/dist/src/engine/utilities/values.d.ts +16 -0
- package/dist/src/engine/utilities/values.js +91 -0
- package/dist/src/engine/utilities/values.js.map +1 -0
- package/dist/src/engine/variants.d.ts +2 -0
- package/dist/src/engine/variants.js +99 -0
- package/dist/src/engine/variants.js.map +1 -0
- package/dist/src/extractor.d.ts +146 -0
- package/dist/src/extractor.js +3862 -0
- package/dist/src/extractor.js.map +1 -0
- package/dist/src/index.cjs +4518 -0
- package/dist/src/index.cjs.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/index.mjs +4480 -0
- package/dist/src/index.mjs.map +1 -0
- package/dist/src/keyframes.cjs +367 -0
- package/dist/src/keyframes.cjs.map +1 -0
- package/dist/src/keyframes.d.ts +27 -0
- package/dist/src/keyframes.js +188 -0
- package/dist/src/keyframes.js.map +1 -0
- package/dist/src/keyframes.mjs +362 -0
- package/dist/src/keyframes.mjs.map +1 -0
- package/dist/src/logger.d.ts +2 -0
- package/dist/src/logger.js +31 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/plugin.cjs +43 -0
- package/dist/src/plugin.cjs.map +1 -0
- package/dist/src/plugin.d.ts +12 -0
- package/dist/src/plugin.js +39 -0
- package/dist/src/plugin.js.map +1 -0
- package/dist/src/plugin.mjs +41 -0
- package/dist/src/plugin.mjs.map +1 -0
- package/dist/src/presets-plugins.cjs +99 -0
- package/dist/src/presets-plugins.cjs.map +1 -0
- package/dist/src/presets-plugins.d.ts +1 -0
- package/dist/src/presets-plugins.js +56 -0
- package/dist/src/presets-plugins.js.map +1 -0
- package/dist/src/presets-plugins.mjs +97 -0
- package/dist/src/presets-plugins.mjs.map +1 -0
- package/dist/src/state.d.ts +76 -0
- package/dist/src/state.js +314 -0
- package/dist/src/state.js.map +1 -0
- package/dist/src/theme/constants.d.ts +22 -0
- package/dist/src/theme/constants.js +17 -0
- package/dist/src/theme/constants.js.map +1 -0
- package/dist/src/theme/index.d.ts +2 -0
- package/dist/src/theme/index.js +48 -0
- package/dist/src/theme/index.js.map +1 -0
- package/dist/src/theme/types.d.ts +13 -0
- package/dist/src/theme/types.js +2 -0
- package/dist/src/theme/types.js.map +1 -0
- package/dist/src/types/ast.d.ts +23 -0
- package/dist/src/types/ast.js +2 -0
- package/dist/src/types/ast.js.map +1 -0
- package/dist/src/types/base-types.d.ts +53 -0
- package/dist/src/types/base-types.js +2 -0
- package/dist/src/types/base-types.js.map +1 -0
- package/dist/src/types/components-types.d.ts +28 -0
- package/dist/src/types/components-types.js +2 -0
- package/dist/src/types/components-types.js.map +1 -0
- package/dist/src/types/config.d.ts +90 -0
- package/dist/src/types/config.js +3 -0
- package/dist/src/types/config.js.map +1 -0
- package/dist/src/types/css-parser.d.ts +361 -0
- package/dist/src/types/css-parser.js +2 -0
- package/dist/src/types/css-parser.js.map +1 -0
- package/dist/src/types/keyframes-type.d.ts +47 -0
- package/dist/src/types/keyframes-type.js +2 -0
- package/dist/src/types/keyframes-type.js.map +1 -0
- package/dist/src/types/plugin.d.ts +10 -0
- package/dist/src/types/plugin.js +2 -0
- package/dist/src/types/plugin.js.map +1 -0
- package/dist/src/types/screens-types.d.ts +47 -0
- package/dist/src/types/screens-types.js +2 -0
- package/dist/src/types/screens-types.js.map +1 -0
- package/dist/src/types/utilities-types.d.ts +147 -0
- package/dist/src/types/utilities-types.js +2 -0
- package/dist/src/types/utilities-types.js.map +1 -0
- package/dist/src/types.d.ts +77 -0
- package/dist/src/types.js +12 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/units/constants.d.ts +35 -0
- package/dist/src/units/constants.js +9 -0
- package/dist/src/units/constants.js.map +1 -0
- package/dist/src/units/index.d.ts +15 -0
- package/dist/src/units/index.js +7 -0
- package/dist/src/units/index.js.map +1 -0
- package/dist/src/units/types.d.ts +9 -0
- package/dist/src/units/types.js +2 -0
- package/dist/src/units/types.js.map +1 -0
- package/dist/src/utilities/backgrounds/constants.d.ts +2810 -0
- package/dist/src/utilities/backgrounds/constants.js +119 -0
- package/dist/src/utilities/backgrounds/constants.js.map +1 -0
- package/dist/src/utilities/backgrounds/index.d.ts +1 -0
- package/dist/src/utilities/backgrounds/index.js +2 -0
- package/dist/src/utilities/backgrounds/index.js.map +1 -0
- package/dist/src/utilities/borders/constants.d.ts +10586 -0
- package/dist/src/utilities/borders/constants.js +309 -0
- package/dist/src/utilities/borders/constants.js.map +1 -0
- package/dist/src/utilities/borders/index.d.ts +1 -0
- package/dist/src/utilities/borders/index.js +2 -0
- package/dist/src/utilities/borders/index.js.map +1 -0
- package/dist/src/utilities/breakpoints/constants.d.ts +330 -0
- package/dist/src/utilities/breakpoints/constants.js +269 -0
- package/dist/src/utilities/breakpoints/constants.js.map +1 -0
- package/dist/src/utilities/breakpoints/index.d.ts +2 -0
- package/dist/src/utilities/breakpoints/index.js +3 -0
- package/dist/src/utilities/breakpoints/index.js.map +1 -0
- package/dist/src/utilities/breakpoints/types.d.ts +8 -0
- package/dist/src/utilities/breakpoints/types.js +2 -0
- package/dist/src/utilities/breakpoints/types.js.map +1 -0
- package/dist/src/utilities/colors/base.d.ts +778 -0
- package/dist/src/utilities/colors/base.js +872 -0
- package/dist/src/utilities/colors/base.js.map +1 -0
- package/dist/src/utilities/colors/color.d.ts +1122 -0
- package/dist/src/utilities/colors/color.js +957 -0
- package/dist/src/utilities/colors/color.js.map +1 -0
- package/dist/src/utilities/colors/constants.d.ts +1 -0
- package/dist/src/utilities/colors/constants.js +2 -0
- package/dist/src/utilities/colors/constants.js.map +1 -0
- package/dist/src/utilities/colors/index.d.ts +4 -0
- package/dist/src/utilities/colors/index.js +29 -0
- package/dist/src/utilities/colors/index.js.map +1 -0
- package/dist/src/utilities/colors/types.d.ts +3 -0
- package/dist/src/utilities/colors/types.js +2 -0
- package/dist/src/utilities/colors/types.js.map +1 -0
- package/dist/src/utilities/effects/constants.d.ts +641 -0
- package/dist/src/utilities/effects/constants.js +83 -0
- package/dist/src/utilities/effects/constants.js.map +1 -0
- package/dist/src/utilities/effects/index.d.ts +1 -0
- package/dist/src/utilities/effects/index.js +2 -0
- package/dist/src/utilities/effects/index.js.map +1 -0
- package/dist/src/utilities/filters/constants.d.ts +406 -0
- package/dist/src/utilities/filters/constants.js +206 -0
- package/dist/src/utilities/filters/constants.js.map +1 -0
- package/dist/src/utilities/filters/index.d.ts +1 -0
- package/dist/src/utilities/filters/index.js +2 -0
- package/dist/src/utilities/filters/index.js.map +1 -0
- package/dist/src/utilities/flex/constants.d.ts +934 -0
- package/dist/src/utilities/flex/constants.js +221 -0
- package/dist/src/utilities/flex/constants.js.map +1 -0
- package/dist/src/utilities/flex/index.d.ts +1 -0
- package/dist/src/utilities/flex/index.js +2 -0
- package/dist/src/utilities/flex/index.js.map +1 -0
- package/dist/src/utilities/flex/types.d.ts +0 -0
- package/dist/src/utilities/flex/types.js +4 -0
- package/dist/src/utilities/flex/types.js.map +1 -0
- package/dist/src/utilities/index.d.ts +31338 -0
- package/dist/src/utilities/index.js +333 -0
- package/dist/src/utilities/index.js.map +1 -0
- package/dist/src/utilities/interactivity/constants.d.ts +1244 -0
- package/dist/src/utilities/interactivity/constants.js +165 -0
- package/dist/src/utilities/interactivity/constants.js.map +1 -0
- package/dist/src/utilities/interactivity/index.d.ts +1 -0
- package/dist/src/utilities/interactivity/index.js +2 -0
- package/dist/src/utilities/interactivity/index.js.map +1 -0
- package/dist/src/utilities/layout/constants.d.ts +837 -0
- package/dist/src/utilities/layout/constants.js +159 -0
- package/dist/src/utilities/layout/constants.js.map +1 -0
- package/dist/src/utilities/layout/index.d.ts +1 -0
- package/dist/src/utilities/layout/index.js +2 -0
- package/dist/src/utilities/layout/index.js.map +1 -0
- package/dist/src/utilities/layout/types.d.ts +0 -0
- package/dist/src/utilities/layout/types.js +2 -0
- package/dist/src/utilities/layout/types.js.map +1 -0
- package/dist/src/utilities/sizing/constants.d.ts +989 -0
- package/dist/src/utilities/sizing/constants.js +53 -0
- package/dist/src/utilities/sizing/constants.js.map +1 -0
- package/dist/src/utilities/sizing/index.d.ts +2 -0
- package/dist/src/utilities/sizing/index.js +3 -0
- package/dist/src/utilities/sizing/index.js.map +1 -0
- package/dist/src/utilities/sizing/types.d.ts +10 -0
- package/dist/src/utilities/sizing/types.js +2 -0
- package/dist/src/utilities/sizing/types.js.map +1 -0
- package/dist/src/utilities/spacing/constants.d.ts +1779 -0
- package/dist/src/utilities/spacing/constants.js +142 -0
- package/dist/src/utilities/spacing/constants.js.map +1 -0
- package/dist/src/utilities/spacing/index.d.ts +2 -0
- package/dist/src/utilities/spacing/index.js +3 -0
- package/dist/src/utilities/spacing/index.js.map +1 -0
- package/dist/src/utilities/spacing/types.d.ts +15 -0
- package/dist/src/utilities/spacing/types.js +8 -0
- package/dist/src/utilities/spacing/types.js.map +1 -0
- package/dist/src/utilities/svg/constants.d.ts +1062 -0
- package/dist/src/utilities/svg/constants.js +34 -0
- package/dist/src/utilities/svg/constants.js.map +1 -0
- package/dist/src/utilities/transforms/constants.d.ts +247 -0
- package/dist/src/utilities/transforms/constants.js +74 -0
- package/dist/src/utilities/transforms/constants.js.map +1 -0
- package/dist/src/utilities/transforms/index.d.ts +1 -0
- package/dist/src/utilities/transforms/index.js +2 -0
- package/dist/src/utilities/transforms/index.js.map +1 -0
- package/dist/src/utilities/transitions/constants.d.ts +116 -0
- package/dist/src/utilities/transitions/constants.js +91 -0
- package/dist/src/utilities/transitions/constants.js.map +1 -0
- package/dist/src/utilities/transitions/index.d.ts +1 -0
- package/dist/src/utilities/transitions/index.js +2 -0
- package/dist/src/utilities/transitions/index.js.map +1 -0
- package/dist/src/utilities/typography/constants.d.ts +2401 -0
- package/dist/src/utilities/typography/constants.js +401 -0
- package/dist/src/utilities/typography/constants.js.map +1 -0
- package/dist/src/utilities/typography/index.d.ts +1 -0
- package/dist/src/utilities/typography/index.js +2 -0
- package/dist/src/utilities/typography/index.js.map +1 -0
- package/dist/src/utils.d.ts +18 -0
- package/dist/src/utils.js +282 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/watcher.d.ts +15 -0
- package/dist/src/watcher.js +62 -0
- package/dist/src/watcher.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utilities.css +1 -0
- package/index.css +2 -0
- package/package.json +139 -0
- package/reset.css +168 -0
- package/utilities.css +1 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export * from './ast';
|
|
2
|
+
export * from './atom';
|
|
3
|
+
export * from './theme';
|
|
4
|
+
export * from './theme-source';
|
|
5
|
+
export * from './directives';
|
|
6
|
+
export * from './registry';
|
|
7
|
+
export * from './compile';
|
|
8
|
+
export * from './defaults';
|
|
9
|
+
export * from './theme-defaults';
|
|
10
|
+
export * from './variants';
|
|
11
|
+
export * from './utilities';
|
|
12
|
+
export * from './scanner';
|
|
13
|
+
export * from './source';
|
|
14
|
+
export * from './ui-preset';
|
|
15
|
+
export * from './transform';
|
|
16
|
+
import { type StringifyOptions } from './ast';
|
|
17
|
+
import { Registry } from './registry';
|
|
18
|
+
export declare function compileClasses(classes: string[], reg: Registry, options?: StringifyOptions): string;
|
|
19
|
+
export interface CompileOptions {
|
|
20
|
+
/** An existing registry; defaults to {@link createRegistry}. */
|
|
21
|
+
registry?: Registry;
|
|
22
|
+
/** Classes to compile directly. */
|
|
23
|
+
classes?: string[];
|
|
24
|
+
/** Raw source texts to scan for classes. */
|
|
25
|
+
sources?: string[];
|
|
26
|
+
/** Base directory for resolving `@source` globs. Default `process.cwd()`. */
|
|
27
|
+
base?: string;
|
|
28
|
+
/** Prepend `:root { …tokens }`. Default true. */
|
|
29
|
+
emitTokens?: boolean;
|
|
30
|
+
/** Also emit the `--flx-ui-*` bridge that drives Fluixi UI from the theme. */
|
|
31
|
+
emitUiTokens?: boolean;
|
|
32
|
+
minify?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface CompileResult {
|
|
35
|
+
css: string;
|
|
36
|
+
classes: string[];
|
|
37
|
+
/** Absolute paths of the files scanned via `@source` — watch deps for a plugin. */
|
|
38
|
+
sources: string[];
|
|
39
|
+
registry: Registry;
|
|
40
|
+
}
|
|
41
|
+
export declare function compile(input: string, options?: CompileOptions): CompileResult;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export * from './ast';
|
|
2
|
+
export * from './atom';
|
|
3
|
+
export * from './theme';
|
|
4
|
+
export * from './theme-source';
|
|
5
|
+
export * from './directives';
|
|
6
|
+
export * from './registry';
|
|
7
|
+
export * from './compile';
|
|
8
|
+
export * from './defaults';
|
|
9
|
+
export * from './theme-defaults';
|
|
10
|
+
export * from './variants';
|
|
11
|
+
export * from './utilities';
|
|
12
|
+
export * from './scanner';
|
|
13
|
+
export * from './source';
|
|
14
|
+
export * from './ui-preset';
|
|
15
|
+
export * from './transform';
|
|
16
|
+
import { stringify } from './ast';
|
|
17
|
+
import { parseAtom } from './atom';
|
|
18
|
+
import { compileAtom } from './compile';
|
|
19
|
+
import { createRegistry } from './defaults';
|
|
20
|
+
import { scanAtoms } from './scanner';
|
|
21
|
+
import { loadDirectives } from './directives';
|
|
22
|
+
import { parseSources, resolveSourceFiles, scanSourceFiles } from './source';
|
|
23
|
+
import { collectVarRefs, emitTheme, loadTheme } from './theme-source';
|
|
24
|
+
import { emitUiTheme } from './ui-preset';
|
|
25
|
+
// Parse, compile and stringify a set of utility classes. Unknown or malformed
|
|
26
|
+
// classes are skipped.
|
|
27
|
+
export function compileClasses(classes, reg, options) {
|
|
28
|
+
const nodes = [];
|
|
29
|
+
for (const cls of classes) {
|
|
30
|
+
const atom = parseAtom(cls, reg);
|
|
31
|
+
if (!atom)
|
|
32
|
+
continue;
|
|
33
|
+
const compiled = compileAtom(atom, reg);
|
|
34
|
+
if (compiled)
|
|
35
|
+
nodes.push(...compiled);
|
|
36
|
+
}
|
|
37
|
+
return stringify(nodes, options);
|
|
38
|
+
}
|
|
39
|
+
// The one-call entry: merge `@theme` tokens from `input`, gather classes (given
|
|
40
|
+
// and/or scanned), and emit the token `:root` plus the rules they need.
|
|
41
|
+
export function compile(input, options = {}) {
|
|
42
|
+
var _a, _b, _c, _d;
|
|
43
|
+
const reg = (_a = options.registry) !== null && _a !== void 0 ? _a : createRegistry();
|
|
44
|
+
loadTheme(input, reg.theme);
|
|
45
|
+
loadDirectives(input, reg);
|
|
46
|
+
const classes = new Set((_b = options.classes) !== null && _b !== void 0 ? _b : []);
|
|
47
|
+
for (const source of (_c = options.sources) !== null && _c !== void 0 ? _c : []) {
|
|
48
|
+
for (const c of scanAtoms(source))
|
|
49
|
+
classes.add(c);
|
|
50
|
+
}
|
|
51
|
+
// `@source` directives pull classes from files on disk.
|
|
52
|
+
const parsedSources = parseSources(input);
|
|
53
|
+
for (const c of parsedSources.inline)
|
|
54
|
+
classes.add(c);
|
|
55
|
+
let sources = [];
|
|
56
|
+
if (parsedSources.patterns.length) {
|
|
57
|
+
sources = resolveSourceFiles(parsedSources, (_d = options.base) !== null && _d !== void 0 ? _d : process.cwd());
|
|
58
|
+
for (const c of scanSourceFiles(sources))
|
|
59
|
+
classes.add(c);
|
|
60
|
+
}
|
|
61
|
+
const rules = [];
|
|
62
|
+
for (const cls of classes) {
|
|
63
|
+
const atom = parseAtom(cls, reg);
|
|
64
|
+
if (!atom)
|
|
65
|
+
continue;
|
|
66
|
+
const compiled = compileAtom(atom, reg);
|
|
67
|
+
if (compiled)
|
|
68
|
+
rules.push(...compiled);
|
|
69
|
+
}
|
|
70
|
+
// The `--flx-ui-*` bridge, if requested — its `var()` refs must survive the
|
|
71
|
+
// token tree-shake, so fold them into the used set.
|
|
72
|
+
const uiBlock = options.emitUiTokens ? emitUiTheme(reg.theme) : null;
|
|
73
|
+
// Emit only the tokens the compiled rules (and any UI bridge) actually reference.
|
|
74
|
+
const nodes = [];
|
|
75
|
+
if (options.emitTokens !== false) {
|
|
76
|
+
const used = collectVarRefs(rules);
|
|
77
|
+
if (uiBlock)
|
|
78
|
+
collectVarRefs([uiBlock], used);
|
|
79
|
+
const tokens = emitTheme(reg.theme, ':root', used);
|
|
80
|
+
if (tokens.nodes.length)
|
|
81
|
+
nodes.push(tokens);
|
|
82
|
+
}
|
|
83
|
+
if (uiBlock && uiBlock.nodes.length)
|
|
84
|
+
nodes.push(uiBlock);
|
|
85
|
+
nodes.push(...rules);
|
|
86
|
+
return { css: stringify(nodes, { minify: options.minify }), classes: [...classes], sources, registry: reg };
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/engine/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAE5B,OAAO,EAAgB,SAAS,EAAyB,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CA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C;IAC9C,CAAC;IACD,IAAI,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzD,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;IAErB,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;AAC9G,CAAC","sourcesContent":["export * from './ast';\nexport * from './atom';\nexport * from './theme';\nexport * from './theme-source';\nexport * from './directives';\nexport * from './registry';\nexport * from './compile';\nexport * from './defaults';\nexport * from './theme-defaults';\nexport * from './variants';\nexport * from './utilities';\nexport * from './scanner';\nexport * from './source';\nexport * from './ui-preset';\nexport * from './transform';\n\nimport { type AstNode, stringify, type StringifyOptions } from './ast';\nimport { parseAtom } from './atom';\nimport { compileAtom } from './compile';\nimport { createRegistry } from './defaults';\nimport { Registry } from './registry';\nimport { scanAtoms } from './scanner';\nimport { loadDirectives } from './directives';\nimport { parseSources, resolveSourceFiles, scanSourceFiles } from './source';\nimport { collectVarRefs, emitTheme, loadTheme } from './theme-source';\nimport { emitUiTheme } from './ui-preset';\n\n// Parse, compile and stringify a set of utility classes. Unknown or malformed\n// classes are skipped.\nexport function compileClasses(classes: string[], reg: Registry, options?: StringifyOptions): string {\n const nodes: AstNode[] = [];\n for (const cls of classes) {\n const atom = parseAtom(cls, reg);\n if (!atom) continue;\n const compiled = compileAtom(atom, reg);\n if (compiled) nodes.push(...compiled);\n }\n return stringify(nodes, options);\n}\n\nexport interface CompileOptions {\n /** An existing registry; defaults to {@link createRegistry}. */\n registry?: Registry;\n /** Classes to compile directly. */\n classes?: string[];\n /** Raw source texts to scan for classes. */\n sources?: string[];\n /** Base directory for resolving `@source` globs. Default `process.cwd()`. */\n base?: string;\n /** Prepend `:root { …tokens }`. Default true. */\n emitTokens?: boolean;\n /** Also emit the `--flx-ui-*` bridge that drives Fluixi UI from the theme. */\n emitUiTokens?: boolean;\n minify?: boolean;\n}\n\nexport interface CompileResult {\n css: string;\n classes: string[];\n /** Absolute paths of the files scanned via `@source` — watch deps for a plugin. */\n sources: string[];\n registry: Registry;\n}\n\n// The one-call entry: merge `@theme` tokens from `input`, gather classes (given\n// and/or scanned), and emit the token `:root` plus the rules they need.\nexport function compile(input: string, options: CompileOptions = {}): CompileResult {\n const reg = options.registry ?? createRegistry();\n loadTheme(input, reg.theme);\n loadDirectives(input, reg);\n\n const classes = new Set<string>(options.classes ?? []);\n for (const source of options.sources ?? []) {\n for (const c of scanAtoms(source)) classes.add(c);\n }\n\n // `@source` directives pull classes from files on disk.\n const parsedSources = parseSources(input);\n for (const c of parsedSources.inline) classes.add(c);\n let sources: string[] = [];\n if (parsedSources.patterns.length) {\n sources = resolveSourceFiles(parsedSources, options.base ?? process.cwd());\n for (const c of scanSourceFiles(sources)) classes.add(c);\n }\n\n const rules: AstNode[] = [];\n for (const cls of classes) {\n const atom = parseAtom(cls, reg);\n if (!atom) continue;\n const compiled = compileAtom(atom, reg);\n if (compiled) rules.push(...compiled);\n }\n\n // The `--flx-ui-*` bridge, if requested — its `var()` refs must survive the\n // token tree-shake, so fold them into the used set.\n const uiBlock = options.emitUiTokens ? emitUiTheme(reg.theme) : null;\n\n // Emit only the tokens the compiled rules (and any UI bridge) actually reference.\n const nodes: AstNode[] = [];\n if (options.emitTokens !== false) {\n const used = collectVarRefs(rules);\n if (uiBlock) collectVarRefs([uiBlock], used);\n const tokens = emitTheme(reg.theme, ':root', used);\n if (tokens.nodes.length) nodes.push(tokens);\n }\n if (uiBlock && uiBlock.nodes.length) nodes.push(uiBlock);\n nodes.push(...rules);\n\n return { css: stringify(nodes, { minify: options.minify }), classes: [...classes], sources, registry: reg };\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Declaration } from './ast';
|
|
2
|
+
import type { AtomContext, AtomModifier, AtomValue } from './atom';
|
|
3
|
+
import { Theme } from './theme';
|
|
4
|
+
export interface RuleContext {
|
|
5
|
+
value: AtomValue | null;
|
|
6
|
+
modifier: AtomModifier | null;
|
|
7
|
+
negative: boolean;
|
|
8
|
+
theme: Theme;
|
|
9
|
+
}
|
|
10
|
+
export type DynamicRuleFn = (ctx: RuleContext) => Declaration[] | null;
|
|
11
|
+
export interface VariantWrap {
|
|
12
|
+
selector?: string;
|
|
13
|
+
atRule?: {
|
|
14
|
+
name: string;
|
|
15
|
+
params: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export type VariantValue = {
|
|
19
|
+
kind: 'named';
|
|
20
|
+
value: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'arbitrary';
|
|
23
|
+
value: string;
|
|
24
|
+
dataType: string | null;
|
|
25
|
+
} | null;
|
|
26
|
+
export type DynamicVariantFn = (value: VariantValue, modifier: AtomModifier | null) => VariantWrap | null;
|
|
27
|
+
export declare class Registry implements AtomContext {
|
|
28
|
+
readonly theme: Theme;
|
|
29
|
+
private rules;
|
|
30
|
+
private dynamicRules;
|
|
31
|
+
private variants;
|
|
32
|
+
private dynamicVariants;
|
|
33
|
+
constructor(theme?: Theme);
|
|
34
|
+
rule(name: string, declarations: Declaration[]): this;
|
|
35
|
+
dynamicRule(name: string, handler: DynamicRuleFn): this;
|
|
36
|
+
variant(name: string, wrap: VariantWrap): this;
|
|
37
|
+
dynamicVariant(name: string, handler: DynamicVariantFn): this;
|
|
38
|
+
isRule: (root: string) => boolean;
|
|
39
|
+
isDynamicRule: (root: string) => boolean;
|
|
40
|
+
isVariant: (root: string) => boolean;
|
|
41
|
+
isDynamicVariant: (root: string) => boolean;
|
|
42
|
+
getRule(root: string): Declaration[] | null;
|
|
43
|
+
getDynamicRule(root: string): DynamicRuleFn | null;
|
|
44
|
+
getVariant(name: string): VariantWrap | null;
|
|
45
|
+
getDynamicVariant(root: string): DynamicVariantFn | null;
|
|
46
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Theme } from './theme';
|
|
2
|
+
// Holds the theme plus the rule and variant tables, and answers the keyword vs
|
|
3
|
+
// value-taking questions the atom parser asks.
|
|
4
|
+
export class Registry {
|
|
5
|
+
constructor(theme = new Theme()) {
|
|
6
|
+
this.rules = new Map();
|
|
7
|
+
this.dynamicRules = new Map();
|
|
8
|
+
this.variants = new Map();
|
|
9
|
+
this.dynamicVariants = new Map();
|
|
10
|
+
this.isRule = (root) => this.rules.has(root);
|
|
11
|
+
this.isDynamicRule = (root) => this.dynamicRules.has(root);
|
|
12
|
+
this.isVariant = (root) => this.variants.has(root);
|
|
13
|
+
this.isDynamicVariant = (root) => this.dynamicVariants.has(root);
|
|
14
|
+
this.theme = theme;
|
|
15
|
+
}
|
|
16
|
+
rule(name, declarations) {
|
|
17
|
+
this.rules.set(name, declarations);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
dynamicRule(name, handler) {
|
|
21
|
+
this.dynamicRules.set(name, handler);
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
variant(name, wrap) {
|
|
25
|
+
this.variants.set(name, wrap);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
dynamicVariant(name, handler) {
|
|
29
|
+
this.dynamicVariants.set(name, handler);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
getRule(root) {
|
|
33
|
+
var _a;
|
|
34
|
+
return (_a = this.rules.get(root)) !== null && _a !== void 0 ? _a : null;
|
|
35
|
+
}
|
|
36
|
+
getDynamicRule(root) {
|
|
37
|
+
var _a;
|
|
38
|
+
return (_a = this.dynamicRules.get(root)) !== null && _a !== void 0 ? _a : null;
|
|
39
|
+
}
|
|
40
|
+
getVariant(name) {
|
|
41
|
+
var _a;
|
|
42
|
+
return (_a = this.variants.get(name)) !== null && _a !== void 0 ? _a : null;
|
|
43
|
+
}
|
|
44
|
+
getDynamicVariant(root) {
|
|
45
|
+
var _a;
|
|
46
|
+
return (_a = this.dynamicVariants.get(root)) !== null && _a !== void 0 ? _a : null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/engine/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAyBhC,+EAA+E;AAC/E,+CAA+C;AAC/C,MAAM,OAAO,QAAQ;IAQnB,YAAY,QAAe,IAAI,KAAK,EAAE;QAL9B,UAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;QACzC,iBAAY,GAAG,IAAI,GAAG,EAAyB,CAAC;QAChD,aAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;QAC1C,oBAAe,GAAG,IAAI,GAAG,EAA4B,CAAC;QA0B9D,WAAM,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzD,kBAAa,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvE,cAAS,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/D,qBAAgB,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QA1B3E,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,IAAI,CAAC,IAAY,EAAE,YAA2B;QAC5C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,OAAsB;QAC9C,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAAC,IAAY,EAAE,IAAiB;QACrC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,cAAc,CAAC,IAAY,EAAE,OAAyB;QACpD,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAOD,OAAO,CAAC,IAAY;;QAClB,OAAO,MAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAI,IAAI,CAAC;IACtC,CAAC;IACD,cAAc,CAAC,IAAY;;QACzB,OAAO,MAAA,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAI,IAAI,CAAC;IAC7C,CAAC;IACD,UAAU,CAAC,IAAY;;QACrB,OAAO,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAI,IAAI,CAAC;IACzC,CAAC;IACD,iBAAiB,CAAC,IAAY;;QAC5B,OAAO,MAAA,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAI,IAAI,CAAC;IAChD,CAAC;CACF","sourcesContent":["import type { Declaration } from './ast';\nimport type { AtomContext, AtomModifier, AtomValue } from './atom';\nimport { Theme } from './theme';\n\nexport interface RuleContext {\n value: AtomValue | null;\n modifier: AtomModifier | null;\n negative: boolean;\n theme: Theme;\n}\n\nexport type DynamicRuleFn = (ctx: RuleContext) => Declaration[] | null;\n\n// A variant either narrows the selector (`&:hover`, `.group:hover &`) or wraps\n// the rule in an at-rule (`@media`, `@supports`). It may do both.\nexport interface VariantWrap {\n selector?: string;\n atRule?: { name: string; params: string };\n}\n\nexport type VariantValue =\n | { kind: 'named'; value: string }\n | { kind: 'arbitrary'; value: string; dataType: string | null }\n | null;\n\nexport type DynamicVariantFn = (value: VariantValue, modifier: AtomModifier | null) => VariantWrap | null;\n\n// Holds the theme plus the rule and variant tables, and answers the keyword vs\n// value-taking questions the atom parser asks.\nexport class Registry implements AtomContext {\n readonly theme: Theme;\n\n private rules = new Map<string, Declaration[]>();\n private dynamicRules = new Map<string, DynamicRuleFn>();\n private variants = new Map<string, VariantWrap>();\n private dynamicVariants = new Map<string, DynamicVariantFn>();\n\n constructor(theme: Theme = new Theme()) {\n this.theme = theme;\n }\n\n rule(name: string, declarations: Declaration[]): this {\n this.rules.set(name, declarations);\n return this;\n }\n\n dynamicRule(name: string, handler: DynamicRuleFn): this {\n this.dynamicRules.set(name, handler);\n return this;\n }\n\n variant(name: string, wrap: VariantWrap): this {\n this.variants.set(name, wrap);\n return this;\n }\n\n dynamicVariant(name: string, handler: DynamicVariantFn): this {\n this.dynamicVariants.set(name, handler);\n return this;\n }\n\n isRule = (root: string): boolean => this.rules.has(root);\n isDynamicRule = (root: string): boolean => this.dynamicRules.has(root);\n isVariant = (root: string): boolean => this.variants.has(root);\n isDynamicVariant = (root: string): boolean => this.dynamicVariants.has(root);\n\n getRule(root: string): Declaration[] | null {\n return this.rules.get(root) ?? null;\n }\n getDynamicRule(root: string): DynamicRuleFn | null {\n return this.dynamicRules.get(root) ?? null;\n }\n getVariant(name: string): VariantWrap | null {\n return this.variants.get(name) ?? null;\n }\n getDynamicVariant(root: string): DynamicVariantFn | null {\n return this.dynamicVariants.get(root) ?? null;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function scanAtoms(source: string): string[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Pulls atom class strings out of arbitrary source (HTML, JSX, template
|
|
2
|
+
// literals, …). It's deliberately permissive — anything class-shaped is emitted
|
|
3
|
+
// and the compiler drops what it doesn't recognise. Runs inside `[...]` are kept
|
|
4
|
+
// whole so arbitrary values and selectors survive; `(` `)` and quotes end a run
|
|
5
|
+
// so classes inside `clsx('a', 'b')` are found individually.
|
|
6
|
+
const BOUNDARY = new Set([
|
|
7
|
+
' ', '\t', '\n', '\r', '\f',
|
|
8
|
+
'"', "'", '`', '<', '>', '=', '{', '}', ';', ',', '(', ')', '|', '\\',
|
|
9
|
+
]);
|
|
10
|
+
export function scanAtoms(source) {
|
|
11
|
+
const found = new Set();
|
|
12
|
+
const n = source.length;
|
|
13
|
+
let i = 0;
|
|
14
|
+
while (i < n) {
|
|
15
|
+
if (BOUNDARY.has(source[i])) {
|
|
16
|
+
i++;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
let j = i;
|
|
20
|
+
let depth = 0;
|
|
21
|
+
while (j < n) {
|
|
22
|
+
const c = source[j];
|
|
23
|
+
if (c === '[')
|
|
24
|
+
depth++;
|
|
25
|
+
else if (c === ']') {
|
|
26
|
+
if (depth === 0)
|
|
27
|
+
break;
|
|
28
|
+
depth--;
|
|
29
|
+
}
|
|
30
|
+
else if (depth === 0 && BOUNDARY.has(c))
|
|
31
|
+
break;
|
|
32
|
+
j++;
|
|
33
|
+
}
|
|
34
|
+
add(found, source.slice(i, j));
|
|
35
|
+
i = j;
|
|
36
|
+
}
|
|
37
|
+
return [...found];
|
|
38
|
+
}
|
|
39
|
+
function add(found, token) {
|
|
40
|
+
// Trailing sentence/markup punctuation is never part of a class.
|
|
41
|
+
const cleaned = token.replace(/[.,;:]+$/, '');
|
|
42
|
+
if (cleaned && /[a-zA-Z]/.test(cleaned))
|
|
43
|
+
found.add(cleaned);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../../src/engine/scanner.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,gFAAgF;AAChF,iFAAiF;AACjF,gFAAgF;AAChF,6DAA6D;A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AO,CAAC,GAAG,KAAK,CAAC,CAAC;AACpB,CAAC;AAED,SAAS,GAAG,CAAC,KAAkB,EAAE,KAAa;IAC5C,iEAAiE;IACjE,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC9C,IAAI,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["// Pulls atom class strings out of arbitrary source (HTML, JSX, template\n// literals, …). It's deliberately permissive — anything class-shaped is emitted\n// and the compiler drops what it doesn't recognise. Runs inside `[...]` are kept\n// whole so arbitrary values and selectors survive; `(` `)` and quotes end a run\n// so classes inside `clsx('a', 'b')` are found individually.\n\nconst BOUNDARY = new Set([\n ' ', '\\t', '\\n', '\\r', '\\f',\n '\"', \"'\", '`', '<', '>', '=', '{', '}', ';', ',', '(', ')', '|', '\\\\',\n]);\n\nexport function scanAtoms(source: string): string[] {\n const found = new Set<string>();\n const n = source.length;\n let i = 0;\n\n while (i < n) {\n if (BOUNDARY.has(source[i])) {\n i++;\n continue;\n }\n let j = i;\n let depth = 0;\n while (j < n) {\n const c = source[j];\n if (c === '[') depth++;\n else if (c === ']') {\n if (depth === 0) break;\n depth--;\n } else if (depth === 0 && BOUNDARY.has(c)) break;\n j++;\n }\n add(found, source.slice(i, j));\n i = j;\n }\n\n return [...found];\n}\n\nfunction add(found: Set<string>, token: string): void {\n // Trailing sentence/markup punctuation is never part of a class.\n const cleaned = token.replace(/[.,;:]+$/, '');\n if (cleaned && /[a-zA-Z]/.test(cleaned)) found.add(cleaned);\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ParsedSources {
|
|
2
|
+
/** Glob/dir patterns to scan, with their negate flag. */
|
|
3
|
+
patterns: {
|
|
4
|
+
pattern: string;
|
|
5
|
+
negate: boolean;
|
|
6
|
+
}[];
|
|
7
|
+
/** Classes named directly via `inline(...)`; scanned like source text. */
|
|
8
|
+
inline: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function parseSources(css: string): ParsedSources;
|
|
11
|
+
export declare function resolveSourceFiles(parsed: ParsedSources, base: string): string[];
|
|
12
|
+
export declare function scanSourceFiles(files: string[]): string[];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fg from 'fast-glob';
|
|
4
|
+
import { parseCss } from '../css-parser';
|
|
5
|
+
import { scanAtoms } from './scanner';
|
|
6
|
+
export function parseSources(css) {
|
|
7
|
+
var _a;
|
|
8
|
+
const patterns = [];
|
|
9
|
+
const inline = [];
|
|
10
|
+
for (const node of parseCss(css).children) {
|
|
11
|
+
if (node.type !== 'atrule' || node.name !== 'source')
|
|
12
|
+
continue;
|
|
13
|
+
let raw = ((_a = node.preludeText) !== null && _a !== void 0 ? _a : '').trim();
|
|
14
|
+
if (!raw)
|
|
15
|
+
continue;
|
|
16
|
+
let negate = false;
|
|
17
|
+
if (raw === 'not' || raw.startsWith('not ') || raw.startsWith('not"') || raw.startsWith("not'")) {
|
|
18
|
+
negate = true;
|
|
19
|
+
raw = raw.slice(3).trim();
|
|
20
|
+
}
|
|
21
|
+
if (raw.startsWith('inline(') && raw.endsWith(')')) {
|
|
22
|
+
for (const c of scanAtoms(unquote(raw.slice(7, -1))))
|
|
23
|
+
inline.push(c);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const pattern = unquote(raw);
|
|
27
|
+
if (pattern)
|
|
28
|
+
patterns.push({ pattern, negate });
|
|
29
|
+
}
|
|
30
|
+
return { patterns, inline };
|
|
31
|
+
}
|
|
32
|
+
function unquote(s) {
|
|
33
|
+
const t = s.trim();
|
|
34
|
+
return t.length >= 2 && (t[0] === '"' || t[0] === "'") && t[t.length - 1] === t[0] ? t.slice(1, -1) : t;
|
|
35
|
+
}
|
|
36
|
+
const GLOB_CHARS = /[*?{}[\]()!]/;
|
|
37
|
+
const SOURCE_EXTS = 'html,js,jsx,ts,tsx,mjs,cjs,vue,svelte,astro,md,mdx,php,erb';
|
|
38
|
+
const DEFAULT_IGNORE = ['**/node_modules/**', '**/.git/**', '**/dist/**'];
|
|
39
|
+
// Expands the parsed patterns to a de-duplicated list of absolute file paths,
|
|
40
|
+
// relative to `base`. A bare directory path scans its source files recursively;
|
|
41
|
+
// a plain file path or an explicit glob is honoured as written.
|
|
42
|
+
export function resolveSourceFiles(parsed, base) {
|
|
43
|
+
const include = [];
|
|
44
|
+
const ignore = [...DEFAULT_IGNORE];
|
|
45
|
+
for (const { pattern, negate } of parsed.patterns) {
|
|
46
|
+
(negate ? ignore : include).push(expandBareDir(pattern, base));
|
|
47
|
+
}
|
|
48
|
+
if (include.length === 0)
|
|
49
|
+
return [];
|
|
50
|
+
return fg.sync(include, { cwd: base, ignore, absolute: true, dot: false, onlyFiles: true });
|
|
51
|
+
}
|
|
52
|
+
// A pattern with no glob magic that points at a directory becomes `dir/**/*.{exts}`.
|
|
53
|
+
function expandBareDir(pattern, base) {
|
|
54
|
+
if (GLOB_CHARS.test(pattern))
|
|
55
|
+
return pattern;
|
|
56
|
+
const abs = path.resolve(base, pattern);
|
|
57
|
+
try {
|
|
58
|
+
if (fs.statSync(abs).isDirectory())
|
|
59
|
+
return path.join(pattern, `**/*.{${SOURCE_EXTS}}`);
|
|
60
|
+
}
|
|
61
|
+
catch (_a) {
|
|
62
|
+
// Missing path: leave as-is so fast-glob simply matches nothing.
|
|
63
|
+
}
|
|
64
|
+
return pattern;
|
|
65
|
+
}
|
|
66
|
+
export function scanSourceFiles(files) {
|
|
67
|
+
const found = new Set();
|
|
68
|
+
for (const file of files) {
|
|
69
|
+
let text;
|
|
70
|
+
try {
|
|
71
|
+
text = fs.readFileSync(file, 'utf8');
|
|
72
|
+
}
|
|
73
|
+
catch (_a) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
for (const c of scanAtoms(text))
|
|
77
|
+
found.add(c);
|
|
78
|
+
}
|
|
79
|
+
return [...found];
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../../src/engine/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,WAAW,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AActC,MAAM,UAAU,YAAY,CAAC,GAAW;;IACtC,MAAM,QAAQ,GAA8B,EAAE,CAAC;IAC/C,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC1C,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ;YAAE,SAAS;QAC/D,IAAI,GAAG,GAAG,CAAC,MAAA,IAAI,CAAC,WAAW,mCAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1C,IAAI,CAAC,GAAG;YAAE,SAAS;QAEnB,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAChG,MAAM,GAAG,IAAI,CAAC;YACd,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5B,CAAC;QAED,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,QAAQ,C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CAAC,IAAI,SAAS,CAAC,IAAI,CAAC;YAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;AACpB,CAAC","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport fg from 'fast-glob';\nimport { parseCss } from '../css-parser';\nimport { scanAtoms } from './scanner';\n\n// Reads `@source` directives from the input CSS: which files to scan for classes.\n// @source \"../src/**/*.html\"; — a glob or directory, relative to the CSS file\n// @source not \"../legacy/**\"; — exclude\n// @source inline(\"flex hidden\"); — safelist literal classes, no file involved\n\nexport interface ParsedSources {\n /** Glob/dir patterns to scan, with their negate flag. */\n patterns: { pattern: string; negate: boolean }[];\n /** Classes named directly via `inline(...)`; scanned like source text. */\n inline: string[];\n}\n\nexport function parseSources(css: string): ParsedSources {\n const patterns: ParsedSources['patterns'] = [];\n const inline: string[] = [];\n\n for (const node of parseCss(css).children) {\n if (node.type !== 'atrule' || node.name !== 'source') continue;\n let raw = (node.preludeText ?? '').trim();\n if (!raw) continue;\n\n let negate = false;\n if (raw === 'not' || raw.startsWith('not ') || raw.startsWith('not\"') || raw.startsWith(\"not'\")) {\n negate = true;\n raw = raw.slice(3).trim();\n }\n\n if (raw.startsWith('inline(') && raw.endsWith(')')) {\n for (const c of scanAtoms(unquote(raw.slice(7, -1)))) inline.push(c);\n continue;\n }\n\n const pattern = unquote(raw);\n if (pattern) patterns.push({ pattern, negate });\n }\n\n return { patterns, inline };\n}\n\nfunction unquote(s: string): string {\n const t = s.trim();\n return t.length >= 2 && (t[0] === '\"' || t[0] === \"'\") && t[t.length - 1] === t[0] ? t.slice(1, -1) : t;\n}\n\nconst GLOB_CHARS = /[*?{}[\\]()!]/;\nconst SOURCE_EXTS = 'html,js,jsx,ts,tsx,mjs,cjs,vue,svelte,astro,md,mdx,php,erb';\nconst DEFAULT_IGNORE = ['**/node_modules/**', '**/.git/**', '**/dist/**'];\n\n// Expands the parsed patterns to a de-duplicated list of absolute file paths,\n// relative to `base`. A bare directory path scans its source files recursively;\n// a plain file path or an explicit glob is honoured as written.\nexport function resolveSourceFiles(parsed: ParsedSources, base: string): string[] {\n const include: string[] = [];\n const ignore = [...DEFAULT_IGNORE];\n\n for (const { pattern, negate } of parsed.patterns) {\n (negate ? ignore : include).push(expandBareDir(pattern, base));\n }\n if (include.length === 0) return [];\n\n return fg.sync(include, { cwd: base, ignore, absolute: true, dot: false, onlyFiles: true });\n}\n\n// A pattern with no glob magic that points at a directory becomes `dir/**/*.{exts}`.\nfunction expandBareDir(pattern: string, base: string): string {\n if (GLOB_CHARS.test(pattern)) return pattern;\n const abs = path.resolve(base, pattern);\n try {\n if (fs.statSync(abs).isDirectory()) return path.join(pattern, `**/*.{${SOURCE_EXTS}}`);\n } catch {\n // Missing path: leave as-is so fast-glob simply matches nothing.\n }\n return pattern;\n}\n\nexport function scanSourceFiles(files: string[]): string[] {\n const found = new Set<string>();\n for (const file of files) {\n let text: string;\n try {\n text = fs.readFileSync(file, 'utf8');\n } catch {\n continue;\n }\n for (const c of scanAtoms(text)) found.add(c);\n }\n return [...found];\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Palettes } from '../utilities/colors/base';
|
|
2
|
+
import { Theme } from './theme';
|
|
3
|
+
// The default token set for `createRegistry`. Colours reuse the repo's shared
|
|
4
|
+
// `Palettes` data; the rest are the usual scales. Projects override any of this
|
|
5
|
+
// through `@theme`.
|
|
6
|
+
export function defaultTheme() {
|
|
7
|
+
const theme = new Theme();
|
|
8
|
+
for (const name in Palettes) {
|
|
9
|
+
const shades = Palettes[name];
|
|
10
|
+
for (const shade in shades) {
|
|
11
|
+
// Scaled colours only (50–950); the palette's black/white carry custom
|
|
12
|
+
// values, so we set the plain ones below.
|
|
13
|
+
if (shade !== 'DEFAULT')
|
|
14
|
+
theme.add(`--color-${name}-${shade}`, shades[shade]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
theme.add('--color-black', '#000');
|
|
18
|
+
theme.add('--color-white', '#fff');
|
|
19
|
+
theme.addAll({
|
|
20
|
+
'--spacing': '0.25rem',
|
|
21
|
+
'--breakpoint-sm': '40rem',
|
|
22
|
+
'--breakpoint-md': '48rem',
|
|
23
|
+
'--breakpoint-lg': '64rem',
|
|
24
|
+
'--breakpoint-xl': '80rem',
|
|
25
|
+
'--breakpoint-2xl': '96rem',
|
|
26
|
+
'--radius-DEFAULT': '0.25rem',
|
|
27
|
+
'--radius-xs': '0.125rem',
|
|
28
|
+
'--radius-sm': '0.25rem',
|
|
29
|
+
'--radius-md': '0.375rem',
|
|
30
|
+
'--radius-lg': '0.5rem',
|
|
31
|
+
'--radius-xl': '0.75rem',
|
|
32
|
+
'--radius-2xl': '1rem',
|
|
33
|
+
'--radius-3xl': '1.5rem',
|
|
34
|
+
'--text-xs': '0.75rem',
|
|
35
|
+
'--text-sm': '0.875rem',
|
|
36
|
+
'--text-base': '1rem',
|
|
37
|
+
'--text-lg': '1.125rem',
|
|
38
|
+
'--text-xl': '1.25rem',
|
|
39
|
+
'--text-2xl': '1.5rem',
|
|
40
|
+
'--text-3xl': '1.875rem',
|
|
41
|
+
'--text-4xl': '2.25rem',
|
|
42
|
+
'--text-5xl': '3rem',
|
|
43
|
+
'--text-6xl': '3.75rem',
|
|
44
|
+
'--text-7xl': '4.5rem',
|
|
45
|
+
'--shadow-sm': '0 1px 2px 0 rgb(0 0 0 / 0.05)',
|
|
46
|
+
'--shadow-DEFAULT': '0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)',
|
|
47
|
+
'--shadow-md': '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
|
|
48
|
+
'--shadow-lg': '0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)',
|
|
49
|
+
'--shadow-xl': '0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)',
|
|
50
|
+
'--shadow-2xl': '0 25px 50px -12px rgb(0 0 0 / 0.25)',
|
|
51
|
+
});
|
|
52
|
+
return theme;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=theme-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-defaults.js","sourceRoot":"","sources":["../../../src/engine/theme-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,8EAA8E;AAC9E,gFAAgF;AAChF,oBAAoB;AACpB,MAAM,UAAU,YAAY;IAC1B,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;IAE1B,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,QAAQ,CAAC,IAA6B,CAA2B,CAAC;QACjF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,uEAAuE;YACvE,0CAA0C;YAC1C,IAAI,KAAK,KAAK,SAAS;gBAAE,KAAK,CAAC,GAAG,CAAC,WAAW,IAAI,IAAI,KAAK,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IACnC,KAAK,CAAC,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAEnC,KAAK,CAAC,MAAM,CAAC;QACX,WAAW,EAAE,SAAS;QAEtB,iBAAiB,EAAE,OAAO;QAC1B,iBAAiB,EAAE,OAAO;QAC1B,iBAAiB,EAAE,OAAO;QAC1B,iBAAiB,EAAE,OAAO;QAC1B,kBAAkB,EAAE,OAAO;QAE3B,kBAAkB,EAAE,SAAS;QAC7B,aAAa,EAAE,UAAU;QACzB,aAAa,EAAE,SAAS;QACxB,aAAa,EAAE,UAAU;QACzB,aAAa,EAAE,QAAQ;QACvB,aAAa,EAAE,SAAS;QACxB,cAAc,EAAE,MAAM;QACtB,cAAc,EAAE,QAAQ;QAExB,WAAW,EAAE,SAAS;QACtB,WAAW,EAAE,UAAU;QACvB,aAAa,EAAE,MAAM;QACrB,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,SAAS;QACtB,YAAY,EAAE,QAAQ;QACtB,YAAY,EAAE,UAAU;QACxB,YAAY,EAAE,SAAS;QACvB,YAAY,EAAE,MAAM;QACpB,YAAY,EAAE,SAAS;QACvB,YAAY,EAAE,QAAQ;QAEtB,aAAa,EAAE,+BAA+B;QAC9C,kBAAkB,EAAE,+DAA+D;QACnF,aAAa,EAAE,kEAAkE;QACjF,aAAa,EAAE,oEAAoE;QACnF,aAAa,EAAE,qEAAqE;QACpF,cAAc,EAAE,qCAAqC;KACtD,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { Palettes } from '../utilities/colors/base';\nimport { Theme } from './theme';\n\n// The default token set for `createRegistry`. Colours reuse the repo's shared\n// `Palettes` data; the rest are the usual scales. Projects override any of this\n// through `@theme`.\nexport function defaultTheme(): Theme {\n const theme = new Theme();\n\n for (const name in Palettes) {\n const shades = Palettes[name as keyof typeof Palettes] as Record<string, string>;\n for (const shade in shades) {\n // Scaled colours only (50–950); the palette's black/white carry custom\n // values, so we set the plain ones below.\n if (shade !== 'DEFAULT') theme.add(`--color-${name}-${shade}`, shades[shade]);\n }\n }\n theme.add('--color-black', '#000');\n theme.add('--color-white', '#fff');\n\n theme.addAll({\n '--spacing': '0.25rem',\n\n '--breakpoint-sm': '40rem',\n '--breakpoint-md': '48rem',\n '--breakpoint-lg': '64rem',\n '--breakpoint-xl': '80rem',\n '--breakpoint-2xl': '96rem',\n\n '--radius-DEFAULT': '0.25rem',\n '--radius-xs': '0.125rem',\n '--radius-sm': '0.25rem',\n '--radius-md': '0.375rem',\n '--radius-lg': '0.5rem',\n '--radius-xl': '0.75rem',\n '--radius-2xl': '1rem',\n '--radius-3xl': '1.5rem',\n\n '--text-xs': '0.75rem',\n '--text-sm': '0.875rem',\n '--text-base': '1rem',\n '--text-lg': '1.125rem',\n '--text-xl': '1.25rem',\n '--text-2xl': '1.5rem',\n '--text-3xl': '1.875rem',\n '--text-4xl': '2.25rem',\n '--text-5xl': '3rem',\n '--text-6xl': '3.75rem',\n '--text-7xl': '4.5rem',\n\n '--shadow-sm': '0 1px 2px 0 rgb(0 0 0 / 0.05)',\n '--shadow-DEFAULT': '0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)',\n '--shadow-md': '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',\n '--shadow-lg': '0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)',\n '--shadow-xl': '0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)',\n '--shadow-2xl': '0 25px 50px -12px rgb(0 0 0 / 0.25)',\n });\n\n return theme;\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AstNode, type StyleRule } from './ast';
|
|
2
|
+
import { Theme } from './theme';
|
|
3
|
+
export declare function loadTheme(css: string, theme?: Theme): Theme;
|
|
4
|
+
export declare function emitTheme(theme: Theme, selector?: string, used?: Set<string>): StyleRule;
|
|
5
|
+
export declare function collectVarRefs(nodes: AstNode[], into?: Set<string>): Set<string>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { parseCss } from '../css-parser';
|
|
2
|
+
import { decl, rule } from './ast';
|
|
3
|
+
import { Theme } from './theme';
|
|
4
|
+
// Read `@theme { --color-red-500: …; --spacing: …; }` blocks from CSS into a
|
|
5
|
+
// Theme. This is the CSS-first way to define tokens; the registry is then
|
|
6
|
+
// built from the resulting theme.
|
|
7
|
+
export function loadTheme(css, theme = new Theme()) {
|
|
8
|
+
const sheet = parseCss(css);
|
|
9
|
+
for (const node of sheet.children) {
|
|
10
|
+
if (node.type === 'atrule' && node.name === 'theme' && node.block) {
|
|
11
|
+
collect(node, theme);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return theme;
|
|
15
|
+
}
|
|
16
|
+
function collect(atRule, theme) {
|
|
17
|
+
var _a;
|
|
18
|
+
for (const child of atRule.block.children) {
|
|
19
|
+
if (child.type === 'declaration' && isCustomProperty(child)) {
|
|
20
|
+
theme.add(child.property, ((_a = child.rawValue) !== null && _a !== void 0 ? _a : '').trim());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function isCustomProperty(d) {
|
|
25
|
+
return d.customProperty === true || d.property.startsWith('--');
|
|
26
|
+
}
|
|
27
|
+
// Emit the theme as `:root { --token: value; … }` so the tokens ship as live
|
|
28
|
+
// custom properties. Pass `used` to emit only the tokens actually referenced
|
|
29
|
+
// (plus any they transitively reference) — see {@link collectVarRefs}.
|
|
30
|
+
export function emitTheme(theme, selector = ':root', used) {
|
|
31
|
+
const entries = used ? usedEntries(theme, used) : theme.entries();
|
|
32
|
+
return rule(selector, entries.map(([name, value]) => decl(name, value)));
|
|
33
|
+
}
|
|
34
|
+
const VAR_REF = /var\(\s*(--[\w-]+)/g;
|
|
35
|
+
// Every `--token` referenced through `var(--token)` across a compiled tree.
|
|
36
|
+
export function collectVarRefs(nodes, into = new Set()) {
|
|
37
|
+
for (const node of nodes) {
|
|
38
|
+
if (node.kind === 'declaration') {
|
|
39
|
+
for (const m of node.value.matchAll(VAR_REF))
|
|
40
|
+
into.add(m[1]);
|
|
41
|
+
}
|
|
42
|
+
else if (node.kind === 'raw') {
|
|
43
|
+
for (const m of node.text.matchAll(VAR_REF))
|
|
44
|
+
into.add(m[1]);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
collectVarRefs(node.nodes, into);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return into;
|
|
51
|
+
}
|
|
52
|
+
// The theme entries to keep for `used`: the referenced tokens plus the transitive
|
|
53
|
+
// closure of any tokens their own values reference (e.g. `--color-primary:
|
|
54
|
+
// var(--color-blue-500)`). Insertion order is preserved.
|
|
55
|
+
function usedEntries(theme, used) {
|
|
56
|
+
const keep = new Set();
|
|
57
|
+
const stack = [...used];
|
|
58
|
+
while (stack.length) {
|
|
59
|
+
const name = stack.pop();
|
|
60
|
+
if (keep.has(name))
|
|
61
|
+
continue;
|
|
62
|
+
const value = theme.get(name);
|
|
63
|
+
if (value === undefined)
|
|
64
|
+
continue; // referenced but not a theme token
|
|
65
|
+
keep.add(name);
|
|
66
|
+
for (const m of value.matchAll(VAR_REF))
|
|
67
|
+
stack.push(m[1]);
|
|
68
|
+
}
|
|
69
|
+
return theme.entries().filter(([name]) => keep.has(name));
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=theme-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-source.js","sourceRoot":"","sources":["../../../src/engine/theme-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAgB,IAAI,EAAE,IAAI,EAAkB,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,6EAA6E;AAC7E,0EAA0E;AAC1E,kCAAkC;AAClC,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,QAAe,IAAI,KAAK,EAAE;IAC/D,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QAClC,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAClE,O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,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import { parseCss } from '../css-parser';\nimport type { CssAtRule, CssDeclaration } from '../types/css-parser';\nimport { type AstNode, decl, rule, type StyleRule } from './ast';\nimport { Theme } from './theme';\n\n// Read `@theme { --color-red-500: …; --spacing: …; }` blocks from CSS into a\n// Theme. This is the CSS-first way to define tokens; the registry is then\n// built from the resulting theme.\nexport function loadTheme(css: string, theme: Theme = new Theme()): Theme {\n const sheet = parseCss(css);\n for (const node of sheet.children) {\n if (node.type === 'atrule' && node.name === 'theme' && node.block) {\n collect(node, theme);\n }\n }\n return theme;\n}\n\nfunction collect(atRule: CssAtRule, theme: Theme): void {\n for (const child of atRule.block!.children) {\n if (child.type === 'declaration' && isCustomProperty(child)) {\n theme.add(child.property, (child.rawValue ?? '').trim());\n }\n }\n}\n\nfunction isCustomProperty(d: CssDeclaration): boolean {\n return d.customProperty === true || d.property.startsWith('--');\n}\n\n// Emit the theme as `:root { --token: value; … }` so the tokens ship as live\n// custom properties. Pass `used` to emit only the tokens actually referenced\n// (plus any they transitively reference) — see {@link collectVarRefs}.\nexport function emitTheme(theme: Theme, selector = ':root', used?: Set<string>): StyleRule {\n const entries = used ? usedEntries(theme, used) : theme.entries();\n return rule(\n selector,\n entries.map(([name, value]) => decl(name, value)),\n );\n}\n\nconst VAR_REF = /var\\(\\s*(--[\\w-]+)/g;\n\n// Every `--token` referenced through `var(--token)` across a compiled tree.\nexport function collectVarRefs(nodes: AstNode[], into = new Set<string>()): Set<string> {\n for (const node of nodes) {\n if (node.kind === 'declaration') {\n for (const m of node.value.matchAll(VAR_REF)) into.add(m[1]);\n } else if (node.kind === 'raw') {\n for (const m of node.text.matchAll(VAR_REF)) into.add(m[1]);\n } else {\n collectVarRefs(node.nodes, into);\n }\n }\n return into;\n}\n\n// The theme entries to keep for `used`: the referenced tokens plus the transitive\n// closure of any tokens their own values reference (e.g. `--color-primary:\n// var(--color-blue-500)`). Insertion order is preserved.\nfunction usedEntries(theme: Theme, used: Set<string>): [string, string][] {\n const keep = new Set<string>();\n const stack = [...used];\n while (stack.length) {\n const name = stack.pop()!;\n if (keep.has(name)) continue;\n const value = theme.get(name);\n if (value === undefined) continue; // referenced but not a theme token\n keep.add(name);\n for (const m of value.matchAll(VAR_REF)) stack.push(m[1]);\n }\n return theme.entries().filter(([name]) => keep.has(name));\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class Theme {
|
|
2
|
+
private values;
|
|
3
|
+
add(name: string, value: string): this;
|
|
4
|
+
addAll(entries: Record<string, string>): this;
|
|
5
|
+
get(name: string): string | undefined;
|
|
6
|
+
has(name: string): boolean;
|
|
7
|
+
resolve(namespace: string, key: string): string | null;
|
|
8
|
+
keysIn(namespace: string): string[];
|
|
9
|
+
entries(): [string, string][];
|
|
10
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// The resolved token table. Every entry is a CSS custom property (`--color-red-500`,
|
|
2
|
+
// `--spacing`, `--breakpoint-md`, …); utilities read them by namespace and emit
|
|
3
|
+
// `var()` references, so the tokens stay live and themeable at runtime.
|
|
4
|
+
export class Theme {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.values = new Map();
|
|
7
|
+
}
|
|
8
|
+
add(name, value) {
|
|
9
|
+
this.values.set(name, value);
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
addAll(entries) {
|
|
13
|
+
for (const name in entries)
|
|
14
|
+
this.add(name, entries[name]);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
get(name) {
|
|
18
|
+
return this.values.get(name);
|
|
19
|
+
}
|
|
20
|
+
has(name) {
|
|
21
|
+
return this.values.has(name);
|
|
22
|
+
}
|
|
23
|
+
// A `var()` reference to `--<namespace>-<key>` when that token exists.
|
|
24
|
+
resolve(namespace, key) {
|
|
25
|
+
const name = `--${namespace}-${key}`;
|
|
26
|
+
return this.values.has(name) ? `var(${name})` : null;
|
|
27
|
+
}
|
|
28
|
+
// Bare keys registered under a namespace, e.g. every color name.
|
|
29
|
+
keysIn(namespace) {
|
|
30
|
+
const prefix = `--${namespace}-`;
|
|
31
|
+
const out = [];
|
|
32
|
+
for (const name of this.values.keys()) {
|
|
33
|
+
if (name.startsWith(prefix))
|
|
34
|
+
out.push(name.slice(prefix.length));
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
entries() {
|
|
39
|
+
return [...this.values.entries()];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=theme.js.map
|