@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,48 @@
|
|
|
1
|
+
export type Position = {
|
|
2
|
+
line: number;
|
|
3
|
+
column: number;
|
|
4
|
+
offset: number;
|
|
5
|
+
};
|
|
6
|
+
export type SourceRange = {
|
|
7
|
+
start: Position;
|
|
8
|
+
end: Position;
|
|
9
|
+
};
|
|
10
|
+
export type AstNode = Stylesheet | Rule | AtRule | Declaration | Comment | Raw;
|
|
11
|
+
export interface Stylesheet {
|
|
12
|
+
type: 'Stylesheet';
|
|
13
|
+
children: AstNode[];
|
|
14
|
+
loc: SourceRange;
|
|
15
|
+
source?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface Rule {
|
|
18
|
+
type: 'Rule';
|
|
19
|
+
selectors: string[];
|
|
20
|
+
prelude: string;
|
|
21
|
+
children: (Declaration | AtRule | Rule | Comment | Raw)[];
|
|
22
|
+
loc: SourceRange;
|
|
23
|
+
}
|
|
24
|
+
export interface AtRule {
|
|
25
|
+
type: 'AtRule';
|
|
26
|
+
name: string;
|
|
27
|
+
prelude: string;
|
|
28
|
+
children?: (Rule | Declaration | AtRule | Comment | Raw)[];
|
|
29
|
+
loc: SourceRange;
|
|
30
|
+
}
|
|
31
|
+
export interface Declaration {
|
|
32
|
+
type: 'Declaration';
|
|
33
|
+
property: string;
|
|
34
|
+
value: string;
|
|
35
|
+
important: boolean;
|
|
36
|
+
loc: SourceRange;
|
|
37
|
+
}
|
|
38
|
+
export interface Comment {
|
|
39
|
+
type: 'Comment';
|
|
40
|
+
value: string;
|
|
41
|
+
block: boolean;
|
|
42
|
+
loc: SourceRange;
|
|
43
|
+
}
|
|
44
|
+
export interface Raw {
|
|
45
|
+
type: 'Raw';
|
|
46
|
+
value: string;
|
|
47
|
+
loc: SourceRange;
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-ast.js","sourceRoot":"","sources":["../../src/css-ast.ts"],"names":[],"mappings":"","sourcesContent":["// packages/css-core/src/css-ast.ts\nexport type Position = { line: number; column: number; offset: number };\nexport type SourceRange = { start: Position; end: Position };\n\nexport type AstNode =\n | Stylesheet\n | Rule\n | AtRule\n | Declaration\n | Comment\n | Raw;\n\nexport interface Stylesheet {\n type: 'Stylesheet';\n children: AstNode[];\n loc: SourceRange;\n source?: string;\n}\n\nexport interface Rule {\n type: 'Rule';\n selectors: string[];\n prelude: string;\n children: (Declaration | AtRule | Rule | Comment | Raw)[]; // include Rule\n loc: SourceRange;\n}\n \nexport interface AtRule {\n type: 'AtRule';\n name: string;\n prelude: string;\n children?: (Rule | Declaration | AtRule | Comment | Raw)[]; // include Rule\n loc: SourceRange;\n}\n\nexport interface Declaration {\n type: 'Declaration';\n property: string;\n value: string; // raw value string (preserves functions, spaces)\n important: boolean;\n loc: SourceRange;\n}\n\nexport interface Comment {\n type: 'Comment';\n value: string;\n block: boolean; // /* ... */ vs // (kept false for CSS, true for block)\n loc: SourceRange;\n}\n\nexport interface Raw {\n type: 'Raw';\n value: string; // unparsed, used for graceful recovery\n loc: SourceRange;\n}"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS Generator — converts a CSS AST back to a CSS string.
|
|
3
|
+
*
|
|
4
|
+
* Supports:
|
|
5
|
+
* - Pretty-printing with configurable indent / newline
|
|
6
|
+
* - Minification (all whitespace removed except mandatory single spaces)
|
|
7
|
+
* - Optional comment suppression
|
|
8
|
+
* - Per-node middleware (onRule, onAtRule, onDeclaration, onComment, onKeyframe)
|
|
9
|
+
* called *after* serialization so you can post-process individual nodes
|
|
10
|
+
*/
|
|
11
|
+
import type { CssAstNode, GenerateOptions } from './types/css-parser';
|
|
12
|
+
export declare class CssGenerator {
|
|
13
|
+
private nl;
|
|
14
|
+
private sp;
|
|
15
|
+
private ind;
|
|
16
|
+
private showComments;
|
|
17
|
+
private opts;
|
|
18
|
+
constructor(opts?: GenerateOptions);
|
|
19
|
+
generate(node: CssAstNode, depth?: number): string;
|
|
20
|
+
private pad;
|
|
21
|
+
private genSheet;
|
|
22
|
+
private genRule;
|
|
23
|
+
private genAtRule;
|
|
24
|
+
private genDecl;
|
|
25
|
+
private genComment;
|
|
26
|
+
private genKeyframe;
|
|
27
|
+
}
|
|
28
|
+
/** Serialize a CSS AST node back to a CSS string. */
|
|
29
|
+
export declare function stringify(node: CssAstNode, options?: GenerateOptions): string;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS Generator — converts a CSS AST back to a CSS string.
|
|
3
|
+
*
|
|
4
|
+
* Supports:
|
|
5
|
+
* - Pretty-printing with configurable indent / newline
|
|
6
|
+
* - Minification (all whitespace removed except mandatory single spaces)
|
|
7
|
+
* - Optional comment suppression
|
|
8
|
+
* - Per-node middleware (onRule, onAtRule, onDeclaration, onComment, onKeyframe)
|
|
9
|
+
* called *after* serialization so you can post-process individual nodes
|
|
10
|
+
*/
|
|
11
|
+
export class CssGenerator {
|
|
12
|
+
constructor(opts = {}) {
|
|
13
|
+
var _a, _b, _c, _d;
|
|
14
|
+
this.opts = opts;
|
|
15
|
+
const min = (_a = opts.minify) !== null && _a !== void 0 ? _a : false;
|
|
16
|
+
this.nl = min ? '' : ((_b = opts.newline) !== null && _b !== void 0 ? _b : '\n');
|
|
17
|
+
this.sp = min ? '' : ' ';
|
|
18
|
+
this.ind = min ? '' : ((_c = opts.indent) !== null && _c !== void 0 ? _c : ' ');
|
|
19
|
+
this.showComments = (_d = opts.comments) !== null && _d !== void 0 ? _d : true;
|
|
20
|
+
}
|
|
21
|
+
generate(node, depth = 0) {
|
|
22
|
+
switch (node.type) {
|
|
23
|
+
case 'stylesheet': return this.genSheet(node, depth);
|
|
24
|
+
case 'rule': return this.genRule(node, depth);
|
|
25
|
+
case 'atrule': return this.genAtRule(node, depth);
|
|
26
|
+
case 'declaration': return this.genDecl(node, depth);
|
|
27
|
+
case 'comment':
|
|
28
|
+
return this.showComments ? this.genComment(node, depth) : '';
|
|
29
|
+
case 'keyframe': return this.genKeyframe(node, depth);
|
|
30
|
+
default: return '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
pad(depth) {
|
|
34
|
+
return this.opts.minify ? '' : this.ind.repeat(depth);
|
|
35
|
+
}
|
|
36
|
+
genSheet(ss, depth) {
|
|
37
|
+
return ss.children
|
|
38
|
+
.map(c => this.generate(c, depth))
|
|
39
|
+
.filter(s => s.length > 0)
|
|
40
|
+
.join(this.opts.minify ? '' : this.nl + this.nl);
|
|
41
|
+
}
|
|
42
|
+
genRule(rule, depth) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const pad = this.pad(depth);
|
|
45
|
+
const ipad = this.pad(depth + 1);
|
|
46
|
+
const sel = (_a = rule.rawSelector) !== null && _a !== void 0 ? _a : rule.selectors.map(s => s.value).join(`,${this.sp}`);
|
|
47
|
+
let body = '';
|
|
48
|
+
for (const d of rule.declarations) {
|
|
49
|
+
body += ipad + this.genDecl(d, 0) + this.nl;
|
|
50
|
+
}
|
|
51
|
+
if ((_b = rule.children) === null || _b === void 0 ? void 0 : _b.length) {
|
|
52
|
+
for (const child of rule.children) {
|
|
53
|
+
const str = this.generate(child, depth + 1);
|
|
54
|
+
if (str)
|
|
55
|
+
body += str + this.nl;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const css = `${pad}${sel}${this.sp}{${this.nl}${body}${pad}}`;
|
|
59
|
+
return this.opts.onRule ? this.opts.onRule(rule, css) : css;
|
|
60
|
+
}
|
|
61
|
+
genAtRule(ar, depth) {
|
|
62
|
+
var _a, _b, _c;
|
|
63
|
+
const pad = this.pad(depth);
|
|
64
|
+
const prelude = (_c = (_a = ar.preludeText) !== null && _a !== void 0 ? _a : (_b = ar.prelude) === null || _b === void 0 ? void 0 : _b.map(v => String(v.value)).join(' ')) !== null && _c !== void 0 ? _c : '';
|
|
65
|
+
const head = `@${ar.name}${prelude ? ' ' + prelude : ''}`;
|
|
66
|
+
if (!ar.block) {
|
|
67
|
+
const css = `${pad}${head};`;
|
|
68
|
+
return this.opts.onAtRule ? this.opts.onAtRule(ar, css) : css;
|
|
69
|
+
}
|
|
70
|
+
let body = '';
|
|
71
|
+
for (const child of ar.block.children) {
|
|
72
|
+
const str = this.generate(child, depth + 1);
|
|
73
|
+
if (str)
|
|
74
|
+
body += str + this.nl;
|
|
75
|
+
}
|
|
76
|
+
const css = `${pad}${head}${this.sp}{${this.nl}${body}${pad}}`;
|
|
77
|
+
return this.opts.onAtRule ? this.opts.onAtRule(ar, css) : css;
|
|
78
|
+
}
|
|
79
|
+
genDecl(d, depth) {
|
|
80
|
+
var _a;
|
|
81
|
+
const pad = this.pad(depth);
|
|
82
|
+
const value = (_a = d.rawValue) !== null && _a !== void 0 ? _a : d.value.map(v => String(v.value)).join(' ');
|
|
83
|
+
const imp = d.important ? ' !important' : '';
|
|
84
|
+
const css = `${pad}${d.property}:${this.sp}${value}${imp};`;
|
|
85
|
+
return this.opts.onDeclaration ? this.opts.onDeclaration(d, css) : css;
|
|
86
|
+
}
|
|
87
|
+
genComment(c, depth) {
|
|
88
|
+
const css = `${this.pad(depth)}/*${c.value}*/`;
|
|
89
|
+
return this.opts.onComment ? this.opts.onComment(c, css) : css;
|
|
90
|
+
}
|
|
91
|
+
genKeyframe(kf, depth) {
|
|
92
|
+
const pad = this.pad(depth);
|
|
93
|
+
const ipad = this.pad(depth + 1);
|
|
94
|
+
const body = kf.declarations.map(d => ipad + this.genDecl(d, 0) + this.nl).join('');
|
|
95
|
+
const css = `${pad}${kf.selector}${this.sp}{${this.nl}${body}${pad}}`;
|
|
96
|
+
return this.opts.onKeyframe ? this.opts.onKeyframe(kf, css) : css;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// ─── Convenience function ─────────────────────────────────────────────────────
|
|
100
|
+
/** Serialize a CSS AST node back to a CSS string. */
|
|
101
|
+
export function stringify(node, options) {
|
|
102
|
+
return new CssGenerator(options).generate(node);
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=css-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-generator.js","sourceRoot":"","sources":["../../src/css-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,MAAM,OAAO,YAAY;IAOrB,YAAY,OAAwB,EAAE;;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,MAAM,GAAG,GAAK,MAAA,IAAI,CAAC,MAAM,mCAAI,KAAK,CAAC;QACnC,IAAI,CAAC,EAAE,GAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAA,IAAI,CAAC,OAAO,mCAAI,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,EAAE,GAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAA,IAAI,CAAC,MAAM,mCAAK,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,MAAA,IAAI,CAAC,QAAQ,mCAAI,IAAI,CAAC;IAC9C,CAAC;IAED,QAAQ,CAAC,IAAgB,EAAE,KAAK,GAAG,CAAC;QAChC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAChB,KAAK,YAAY,CAAC,CAAE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAqB,EAAE,KAAK,CAAC,CAAC;YACvE,KAAK,MAAM,CAAC,CAAQ,OAAO,IAAI,CAAC,OAAO,CAAC,IAAe,EAAE,KAAK,CAAC,CAAC;YAChE,KAAK,QAAQ,CAAC,CAAM,OAAO,IAA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pF,MAAM,GAAG,GAAI,GAAG,GAAG,GAAG,EAAE,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,GAAG,IAAI,GAAG,GAAG,GAAG,CAAC;QACvE,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACtE,CAAC;CACJ;AAED,iFAAiF;AAEjF,qDAAqD;AACrD,MAAM,UAAU,SAAS,CAAC,IAAgB,EAAE,OAAyB;IACjE,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/**\n * CSS Generator — converts a CSS AST back to a CSS string.\n *\n * Supports:\n * - Pretty-printing with configurable indent / newline\n * - Minification (all whitespace removed except mandatory single spaces)\n * - Optional comment suppression\n * - Per-node middleware (onRule, onAtRule, onDeclaration, onComment, onKeyframe)\n * called *after* serialization so you can post-process individual nodes\n */\n\nimport type {\n CssAstNode, CssStylesheet, CssRule, CssAtRule, CssDeclaration,\n CssComment, CssKeyframe, GenerateOptions,\n} from './types/css-parser';\n\nexport class CssGenerator {\n private nl: string;\n private sp: string;\n private ind: string;\n private showComments: boolean;\n private opts: GenerateOptions;\n\n constructor(opts: GenerateOptions = {}) {\n this.opts = opts;\n const min = opts.minify ?? false;\n this.nl = min ? '' : (opts.newline ?? '\\n');\n this.sp = min ? '' : ' ';\n this.ind = min ? '' : (opts.indent ?? ' ');\n this.showComments = opts.comments ?? true;\n }\n\n generate(node: CssAstNode, depth = 0): string {\n switch (node.type) {\n case 'stylesheet': return this.genSheet(node as CssStylesheet, depth);\n case 'rule': return this.genRule(node as CssRule, depth);\n case 'atrule': return this.genAtRule(node as CssAtRule, depth);\n case 'declaration': return this.genDecl(node as CssDeclaration, depth);\n case 'comment':\n return this.showComments ? this.genComment(node as CssComment, depth) : '';\n case 'keyframe': return this.genKeyframe(node as CssKeyframe, depth);\n default: return '';\n }\n }\n\n private pad(depth: number): string {\n return this.opts.minify ? '' : this.ind.repeat(depth);\n }\n\n private genSheet(ss: CssStylesheet, depth: number): string {\n return ss.children\n .map(c => this.generate(c, depth))\n .filter(s => s.length > 0)\n .join(this.opts.minify ? '' : this.nl + this.nl);\n }\n\n private genRule(rule: CssRule, depth: number): string {\n const pad = this.pad(depth);\n const ipad = this.pad(depth + 1);\n const sel = rule.rawSelector ?? rule.selectors.map(s => s.value).join(`,${this.sp}`);\n\n let body = '';\n for (const d of rule.declarations) {\n body += ipad + this.genDecl(d, 0) + this.nl;\n }\n if (rule.children?.length) {\n for (const child of rule.children) {\n const str = this.generate(child as CssAstNode, depth + 1);\n if (str) body += str + this.nl;\n }\n }\n\n const css = `${pad}${sel}${this.sp}{${this.nl}${body}${pad}}`;\n return this.opts.onRule ? this.opts.onRule(rule, css) : css;\n }\n\n private genAtRule(ar: CssAtRule, depth: number): string {\n const pad = this.pad(depth);\n const prelude = ar.preludeText ?? ar.prelude?.map(v => String(v.value)).join(' ') ?? '';\n const head = `@${ar.name}${prelude ? ' ' + prelude : ''}`;\n\n if (!ar.block) {\n const css = `${pad}${head};`;\n return this.opts.onAtRule ? this.opts.onAtRule(ar, css) : css;\n }\n\n let body = '';\n for (const child of ar.block.children) {\n const str = this.generate(child as CssAstNode, depth + 1);\n if (str) body += str + this.nl;\n }\n\n const css = `${pad}${head}${this.sp}{${this.nl}${body}${pad}}`;\n return this.opts.onAtRule ? this.opts.onAtRule(ar, css) : css;\n }\n\n private genDecl(d: CssDeclaration, depth: number): string {\n const pad = this.pad(depth);\n const value = d.rawValue ?? d.value.map(v => String(v.value)).join(' ');\n const imp = d.important ? ' !important' : '';\n const css = `${pad}${d.property}:${this.sp}${value}${imp};`;\n return this.opts.onDeclaration ? this.opts.onDeclaration(d, css) : css;\n }\n\n private genComment(c: CssComment, depth: number): string {\n const css = `${this.pad(depth)}/*${c.value}*/`;\n return this.opts.onComment ? this.opts.onComment(c, css) : css;\n }\n\n private genKeyframe(kf: CssKeyframe, depth: number): string {\n const pad = this.pad(depth);\n const ipad = this.pad(depth + 1);\n const body = kf.declarations.map(d => ipad + this.genDecl(d, 0) + this.nl).join('');\n const css = `${pad}${kf.selector}${this.sp}{${this.nl}${body}${pad}}`;\n return this.opts.onKeyframe ? this.opts.onKeyframe(kf, css) : css;\n }\n}\n\n// ─── Convenience function ─────────────────────────────────────────────────────\n\n/** Serialize a CSS AST node back to a CSS string. */\nexport function stringify(node: CssAstNode, options?: GenerateOptions): string {\n return new CssGenerator(options).generate(node);\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS AST helper / factory functions.
|
|
3
|
+
*
|
|
4
|
+
* Thin wrappers that construct typed AST nodes so callers don't have to
|
|
5
|
+
* spell out `type: 'rule'` etc. everywhere.
|
|
6
|
+
*
|
|
7
|
+
* All parameters that could be omitted are optional and default to sensible
|
|
8
|
+
* empty values so that helpers compose naturally:
|
|
9
|
+
*
|
|
10
|
+
* import { rule, decl, atRule } from './css-helpers';
|
|
11
|
+
*
|
|
12
|
+
* const node = rule('.btn', [
|
|
13
|
+
* decl('color', 'red'),
|
|
14
|
+
* decl('font-size', '1rem'),
|
|
15
|
+
* ]);
|
|
16
|
+
*/
|
|
17
|
+
import type { Location, LocationPosition, CssAstNode, CssStylesheet, CssRule, CssAtRule, CssDeclaration, CssComment, CssSelector, CssValue, CssKeyframe, WalkVisitor } from './types/css-parser';
|
|
18
|
+
export declare function locationPos(line: number, column: number, offset: number): LocationPosition;
|
|
19
|
+
export declare function location(start: LocationPosition, end: LocationPosition, source?: string): Location;
|
|
20
|
+
export declare function selector(value: string, loc?: Location): CssSelector;
|
|
21
|
+
/**
|
|
22
|
+
* Build a `CssDeclaration` node.
|
|
23
|
+
*
|
|
24
|
+
* @param property CSS property name (e.g. `'color'`, `'--my-var'`)
|
|
25
|
+
* @param rawValue Raw value string (e.g. `'red'`, `'1px solid #000'`)
|
|
26
|
+
* @param important Whether the declaration carries `!important`
|
|
27
|
+
* @param value Parsed `CssValue[]` tokens — defaults to empty (lazy parse)
|
|
28
|
+
* @param loc Optional source location
|
|
29
|
+
*/
|
|
30
|
+
export declare function decl(property: string, rawValue: string, important?: boolean, value?: CssValue[], loc?: Location): CssDeclaration;
|
|
31
|
+
/** Alias for {@link decl} with a name that mirrors the AST interface. */
|
|
32
|
+
export declare function declaration(property: string, value: CssValue[], important: boolean, rawValue?: string, loc?: Location): CssDeclaration;
|
|
33
|
+
/**
|
|
34
|
+
* Build a `CssRule` node.
|
|
35
|
+
*
|
|
36
|
+
* @param rawSelector Raw selector string (e.g. `'.btn:hover'`)
|
|
37
|
+
* @param declarations Array of declarations
|
|
38
|
+
* @param children Optional nested rules / at-rules (CSS nesting)
|
|
39
|
+
* @param loc Optional source location
|
|
40
|
+
*/
|
|
41
|
+
export declare function rule(rawSelector: string, declarations?: CssDeclaration[], children?: (CssRule | CssAtRule)[], loc?: Location): CssRule;
|
|
42
|
+
/**
|
|
43
|
+
* Build a `CssAtRule` node.
|
|
44
|
+
*
|
|
45
|
+
* @param name At-rule name without `@` (e.g. `'media'`, `'keyframes'`)
|
|
46
|
+
* @param preludeText Raw prelude text (e.g. `'screen and (max-width: 600px)'`)
|
|
47
|
+
* @param children Block children (rules, declarations, keyframes…)
|
|
48
|
+
* @param loc Optional source location
|
|
49
|
+
*/
|
|
50
|
+
export declare function atRule(name: string, preludeText?: string, children?: CssAstNode[], loc?: Location): CssAtRule;
|
|
51
|
+
export declare function comment(value: string, loc?: Location): CssComment;
|
|
52
|
+
export declare function keyframe(selectorText: string, declarations?: CssDeclaration[], loc?: Location): CssKeyframe;
|
|
53
|
+
export declare function stylesheet(children?: CssAstNode[]): CssStylesheet;
|
|
54
|
+
/** Shallow-clone any CSS AST node (one level deep). */
|
|
55
|
+
export declare function cloneNode<T extends CssAstNode>(node: T): T;
|
|
56
|
+
/** Deep-clone a CSS AST node tree. */
|
|
57
|
+
export declare function cloneNodeDeep<T extends CssAstNode>(node: T): T;
|
|
58
|
+
/**
|
|
59
|
+
* Depth-first traversal of a CSS AST.
|
|
60
|
+
*
|
|
61
|
+
* The visitor may mutate, replace, or remove nodes via the `WalkContext`:
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* walk(ast, {
|
|
65
|
+
* rule(node, ctx) {
|
|
66
|
+
* if (node.rawSelector === '.old') ctx.replace(rule('.new', node.declarations));
|
|
67
|
+
* },
|
|
68
|
+
* declaration(node, ctx) {
|
|
69
|
+
* if (node.property === 'color') ctx.remove();
|
|
70
|
+
* },
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* To stop the entire traversal early call `ctx.stop()`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function walk(node: CssAstNode, visitor: WalkVisitor): void;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS AST helper / factory functions.
|
|
3
|
+
*
|
|
4
|
+
* Thin wrappers that construct typed AST nodes so callers don't have to
|
|
5
|
+
* spell out `type: 'rule'` etc. everywhere.
|
|
6
|
+
*
|
|
7
|
+
* All parameters that could be omitted are optional and default to sensible
|
|
8
|
+
* empty values so that helpers compose naturally:
|
|
9
|
+
*
|
|
10
|
+
* import { rule, decl, atRule } from './css-helpers';
|
|
11
|
+
*
|
|
12
|
+
* const node = rule('.btn', [
|
|
13
|
+
* decl('color', 'red'),
|
|
14
|
+
* decl('font-size', '1rem'),
|
|
15
|
+
* ]);
|
|
16
|
+
*/
|
|
17
|
+
// ─── Location ─────────────────────────────────────────────────────────────────
|
|
18
|
+
export function locationPos(line, column, offset) {
|
|
19
|
+
return { line, column, offset };
|
|
20
|
+
}
|
|
21
|
+
export function location(start, end, source) {
|
|
22
|
+
return { start, end, source };
|
|
23
|
+
}
|
|
24
|
+
// ─── Selector ─────────────────────────────────────────────────────────────────
|
|
25
|
+
export function selector(value, loc) {
|
|
26
|
+
return { type: 'selector', value, loc };
|
|
27
|
+
}
|
|
28
|
+
// ─── Declaration ──────────────────────────────────────────────────────────────
|
|
29
|
+
/**
|
|
30
|
+
* Build a `CssDeclaration` node.
|
|
31
|
+
*
|
|
32
|
+
* @param property CSS property name (e.g. `'color'`, `'--my-var'`)
|
|
33
|
+
* @param rawValue Raw value string (e.g. `'red'`, `'1px solid #000'`)
|
|
34
|
+
* @param important Whether the declaration carries `!important`
|
|
35
|
+
* @param value Parsed `CssValue[]` tokens — defaults to empty (lazy parse)
|
|
36
|
+
* @param loc Optional source location
|
|
37
|
+
*/
|
|
38
|
+
export function decl(property, rawValue, important = false, value = [], loc) {
|
|
39
|
+
return { type: 'declaration', property, rawValue, value, important, loc };
|
|
40
|
+
}
|
|
41
|
+
/** Alias for {@link decl} with a name that mirrors the AST interface. */
|
|
42
|
+
export function declaration(property, value, important, rawValue, loc) {
|
|
43
|
+
return { type: 'declaration', property, value, rawValue, important, loc };
|
|
44
|
+
}
|
|
45
|
+
// ─── Rule ─────────────────────────────────────────────────────────────────────
|
|
46
|
+
/**
|
|
47
|
+
* Build a `CssRule` node.
|
|
48
|
+
*
|
|
49
|
+
* @param rawSelector Raw selector string (e.g. `'.btn:hover'`)
|
|
50
|
+
* @param declarations Array of declarations
|
|
51
|
+
* @param children Optional nested rules / at-rules (CSS nesting)
|
|
52
|
+
* @param loc Optional source location
|
|
53
|
+
*/
|
|
54
|
+
export function rule(rawSelector, declarations = [], children, loc) {
|
|
55
|
+
const selectors = rawSelector
|
|
56
|
+
.split(',')
|
|
57
|
+
.map(s => selector(s.trim()));
|
|
58
|
+
const node = { type: 'rule', rawSelector, selectors, declarations, loc };
|
|
59
|
+
if (children === null || children === void 0 ? void 0 : children.length)
|
|
60
|
+
node.children = children;
|
|
61
|
+
return node;
|
|
62
|
+
}
|
|
63
|
+
// ─── At-rule ──────────────────────────────────────────────────────────────────
|
|
64
|
+
/**
|
|
65
|
+
* Build a `CssAtRule` node.
|
|
66
|
+
*
|
|
67
|
+
* @param name At-rule name without `@` (e.g. `'media'`, `'keyframes'`)
|
|
68
|
+
* @param preludeText Raw prelude text (e.g. `'screen and (max-width: 600px)'`)
|
|
69
|
+
* @param children Block children (rules, declarations, keyframes…)
|
|
70
|
+
* @param loc Optional source location
|
|
71
|
+
*/
|
|
72
|
+
export function atRule(name, preludeText = '', children = [], loc) {
|
|
73
|
+
const node = {
|
|
74
|
+
type: 'atrule',
|
|
75
|
+
name,
|
|
76
|
+
preludeText,
|
|
77
|
+
prelude: [],
|
|
78
|
+
loc,
|
|
79
|
+
};
|
|
80
|
+
if (children.length) {
|
|
81
|
+
node.block = { type: 'block', children: children };
|
|
82
|
+
}
|
|
83
|
+
return node;
|
|
84
|
+
}
|
|
85
|
+
// ─── Comment ──────────────────────────────────────────────────────────────────
|
|
86
|
+
export function comment(value, loc) {
|
|
87
|
+
return {
|
|
88
|
+
type: 'comment',
|
|
89
|
+
value,
|
|
90
|
+
style: value.includes('\n') ? 'multi-line' : 'single-line',
|
|
91
|
+
loc,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// ─── Keyframe ─────────────────────────────────────────────────────────────────
|
|
95
|
+
export function keyframe(selectorText, declarations = [], loc) {
|
|
96
|
+
return { type: 'keyframe', selector: selectorText, declarations, loc };
|
|
97
|
+
}
|
|
98
|
+
// ─── Stylesheet ───────────────────────────────────────────────────────────────
|
|
99
|
+
export function stylesheet(children = []) {
|
|
100
|
+
return {
|
|
101
|
+
type: 'stylesheet',
|
|
102
|
+
children,
|
|
103
|
+
imports: [], namespaces: [], mediaQueries: [], keyframes: [],
|
|
104
|
+
fontFaces: [], layers: [], containers: [], supports: [],
|
|
105
|
+
documents: [], pages: [], counterStyles: [], fontFeatureValues: [],
|
|
106
|
+
viewports: [], charsets: [],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// ─── Clone ────────────────────────────────────────────────────────────────────
|
|
110
|
+
/** Shallow-clone any CSS AST node (one level deep). */
|
|
111
|
+
export function cloneNode(node) {
|
|
112
|
+
return Object.assign({}, node);
|
|
113
|
+
}
|
|
114
|
+
/** Deep-clone a CSS AST node tree. */
|
|
115
|
+
export function cloneNodeDeep(node) {
|
|
116
|
+
const shallow = Object.assign({}, node);
|
|
117
|
+
if (shallow.declarations) {
|
|
118
|
+
shallow.declarations = shallow.declarations.map((d) => (Object.assign({}, d)));
|
|
119
|
+
}
|
|
120
|
+
if (shallow.children) {
|
|
121
|
+
shallow.children = shallow.children.map((c) => cloneNodeDeep(c));
|
|
122
|
+
}
|
|
123
|
+
if (shallow.block) {
|
|
124
|
+
shallow.block = Object.assign(Object.assign({}, shallow.block), { children: shallow.block.children.map((c) => cloneNodeDeep(c)) });
|
|
125
|
+
}
|
|
126
|
+
if (shallow.selectors) {
|
|
127
|
+
shallow.selectors = shallow.selectors.map((s) => (Object.assign({}, s)));
|
|
128
|
+
}
|
|
129
|
+
if (shallow.keyframes) {
|
|
130
|
+
shallow.keyframes = shallow.keyframes.map((kf) => (Object.assign(Object.assign({}, kf), { declarations: kf.declarations.map((d) => (Object.assign({}, d))) })));
|
|
131
|
+
}
|
|
132
|
+
return shallow;
|
|
133
|
+
}
|
|
134
|
+
// ─── Walk ─────────────────────────────────────────────────────────────────────
|
|
135
|
+
/**
|
|
136
|
+
* Depth-first traversal of a CSS AST.
|
|
137
|
+
*
|
|
138
|
+
* The visitor may mutate, replace, or remove nodes via the `WalkContext`:
|
|
139
|
+
*
|
|
140
|
+
* ```ts
|
|
141
|
+
* walk(ast, {
|
|
142
|
+
* rule(node, ctx) {
|
|
143
|
+
* if (node.rawSelector === '.old') ctx.replace(rule('.new', node.declarations));
|
|
144
|
+
* },
|
|
145
|
+
* declaration(node, ctx) {
|
|
146
|
+
* if (node.property === 'color') ctx.remove();
|
|
147
|
+
* },
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* To stop the entire traversal early call `ctx.stop()`.
|
|
152
|
+
*/
|
|
153
|
+
export function walk(node, visitor) {
|
|
154
|
+
const state = { stopped: false };
|
|
155
|
+
_walk(node, visitor, null, 0, 0, state);
|
|
156
|
+
}
|
|
157
|
+
function _walk(node, visitor, parent, index, depth, state) {
|
|
158
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
159
|
+
if (state.stopped)
|
|
160
|
+
return;
|
|
161
|
+
// ── Build mutation context ────────────────────────────────────────────────
|
|
162
|
+
let pendingAction = null;
|
|
163
|
+
const ctx = {
|
|
164
|
+
parent,
|
|
165
|
+
index,
|
|
166
|
+
depth,
|
|
167
|
+
stop: () => { state.stopped = true; },
|
|
168
|
+
remove: () => { pendingAction = 'remove'; },
|
|
169
|
+
replace: (n) => { pendingAction = { type: 'replace', node: n }; },
|
|
170
|
+
};
|
|
171
|
+
// ── Dispatch typed visitor ────────────────────────────────────────────────
|
|
172
|
+
switch (node.type) {
|
|
173
|
+
case 'stylesheet':
|
|
174
|
+
(_a = visitor.stylesheet) === null || _a === void 0 ? void 0 : _a.call(visitor, node, ctx);
|
|
175
|
+
break;
|
|
176
|
+
case 'rule':
|
|
177
|
+
(_b = visitor.rule) === null || _b === void 0 ? void 0 : _b.call(visitor, node, ctx);
|
|
178
|
+
break;
|
|
179
|
+
case 'atrule':
|
|
180
|
+
(_c = visitor.atrule) === null || _c === void 0 ? void 0 : _c.call(visitor, node, ctx);
|
|
181
|
+
break;
|
|
182
|
+
case 'declaration':
|
|
183
|
+
(_d = visitor.declaration) === null || _d === void 0 ? void 0 : _d.call(visitor, node, ctx);
|
|
184
|
+
break;
|
|
185
|
+
case 'comment':
|
|
186
|
+
(_e = visitor.comment) === null || _e === void 0 ? void 0 : _e.call(visitor, node, ctx);
|
|
187
|
+
break;
|
|
188
|
+
case 'keyframe':
|
|
189
|
+
(_f = visitor.keyframe) === null || _f === void 0 ? void 0 : _f.call(visitor, node, ctx);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
if (!state.stopped)
|
|
193
|
+
(_g = visitor.enter) === null || _g === void 0 ? void 0 : _g.call(visitor, node, ctx);
|
|
194
|
+
// ── Apply replace / remove before descending ──────────────────────────────
|
|
195
|
+
if (pendingAction !== null) {
|
|
196
|
+
applyMutation(pendingAction, parent, index);
|
|
197
|
+
// After removal/replacement, don't descend into the original node
|
|
198
|
+
if (!state.stopped)
|
|
199
|
+
(_h = visitor.leave) === null || _h === void 0 ? void 0 : _h.call(visitor, node, ctx);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (state.stopped)
|
|
203
|
+
return;
|
|
204
|
+
// ── Descend ───────────────────────────────────────────────────────────────
|
|
205
|
+
const children = getChildren(node);
|
|
206
|
+
for (let i = 0; i < children.length; i++) {
|
|
207
|
+
if (state.stopped)
|
|
208
|
+
break;
|
|
209
|
+
_walk(children[i], visitor, node, i, depth + 1, state);
|
|
210
|
+
// After a walk the array may have mutated (remove/replace); adjust index
|
|
211
|
+
// by checking length (children is a live reference to the original array)
|
|
212
|
+
}
|
|
213
|
+
if (!state.stopped)
|
|
214
|
+
(_j = visitor.leave) === null || _j === void 0 ? void 0 : _j.call(visitor, node, ctx);
|
|
215
|
+
}
|
|
216
|
+
function getChildren(node) {
|
|
217
|
+
switch (node.type) {
|
|
218
|
+
case 'stylesheet': {
|
|
219
|
+
const ss = node;
|
|
220
|
+
return ss.children;
|
|
221
|
+
}
|
|
222
|
+
case 'rule': {
|
|
223
|
+
const r = node;
|
|
224
|
+
const out = [...r.declarations];
|
|
225
|
+
if (r.children)
|
|
226
|
+
out.push(...r.children);
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
229
|
+
case 'atrule': {
|
|
230
|
+
const ar = node;
|
|
231
|
+
return ar.block ? ar.block.children : [];
|
|
232
|
+
}
|
|
233
|
+
default:
|
|
234
|
+
return [];
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function applyMutation(action, parent, index) {
|
|
238
|
+
if (!parent)
|
|
239
|
+
return;
|
|
240
|
+
const arr = getMutableChildArray(parent, index);
|
|
241
|
+
if (!arr)
|
|
242
|
+
return;
|
|
243
|
+
if (action === 'remove') {
|
|
244
|
+
arr.splice(index, 1);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const n = Array.isArray(action.node) ? action.node : [action.node];
|
|
248
|
+
arr.splice(index, 1, ...n);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function getMutableChildArray(parent, index) {
|
|
252
|
+
switch (parent.type) {
|
|
253
|
+
case 'stylesheet':
|
|
254
|
+
return parent.children;
|
|
255
|
+
case 'rule': {
|
|
256
|
+
const r = parent;
|
|
257
|
+
// index < declarations.length → declaration, else → nested child
|
|
258
|
+
if (index < r.declarations.length)
|
|
259
|
+
return r.declarations;
|
|
260
|
+
if (r.children)
|
|
261
|
+
return r.children;
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
case 'atrule': {
|
|
265
|
+
const ar = parent;
|
|
266
|
+
return ar.block ? ar.block.children : null;
|
|
267
|
+
}
|
|
268
|
+
default:
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=css-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-helpers.js","sourceRoot":"","sources":["../../src/css-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAYH,iFAAiF;AAEjF,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,MAAc,EAAE,MAAc;IACpE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,QAAQ,CACpB,KAAuB,EACvB,GAAqB,EACrB,MAAe;IAEf,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AAClC,CAAC;AAED,iFAAiF;AAEjF,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,GAAc;IAClD,OAAO,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EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/B,CAAC;AACL,CAAC;AAED,SAAS,oBAAoB,CAAC,MAAkB,EAAE,KAAa;IAC3D,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,YAAY;YACb,OAAQ,MAAwB,CAAC,QAAwB,CAAC;QAC9D,KAAK,MAAM,CAAC,CAAC,CAAC;YACV,MAAM,CAAC,GAAG,MAAiB,CAAC;YAC5B,iEAAiE;YACjE,IAAI,KAAK,GAAG,CAAC,CAAC,YAAY,CAAC,MAAM;gBAAE,OAAO,CAAC,CAAC,YAAuC,CAAC;YACpF,IAAI,CAAC,CAAC,QAAQ;gBAAE,OAAO,CAAC,CAAC,QAAwB,CAAC;YAClD,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACZ,MAAM,EAAE,GAAG,MAAmB,CAAC;YAC/B,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,CAAC,KAAK,CAAC,QAAyB,CAAC,CAAC,CAAC,IAAI,CAAC;QACjE,CAAC;QACD;YACI,OAAO,IAAI,CAAC;IACpB,CAAC;AACL,CAAC","sourcesContent":["/**\n * CSS AST helper / factory functions.\n *\n * Thin wrappers that construct typed AST nodes so callers don't have to\n * spell out `type: 'rule'` etc. everywhere.\n *\n * All parameters that could be omitted are optional and default to sensible\n * empty values so that helpers compose naturally:\n *\n * import { rule, decl, atRule } from './css-helpers';\n *\n * const node = rule('.btn', [\n * decl('color', 'red'),\n * decl('font-size', '1rem'),\n * ]);\n */\n\nimport type {\n Location, LocationPosition,\n CssAstNode, CssStylesheet,\n CssRule, CssAtRule, CssDeclaration, CssComment, CssSelector,\n CssValue, CssKeyframe,\n CssParserOptions, CssParseError, CssParseWarning,\n WalkVisitor, WalkContext,\n CssImportRule,\n} from './types/css-parser';\n\n// ─── Location ─────────────────────────────────────────────────────────────────\n\nexport function locationPos(line: number, column: number, offset: number): LocationPosition {\n return { line, column, offset };\n}\n\nexport function location(\n start: LocationPosition,\n end: LocationPosition,\n source?: string,\n): Location {\n return { start, end, source };\n}\n\n// ─── Selector ─────────────────────────────────────────────────────────────────\n\nexport function selector(value: string, loc?: Location): CssSelector {\n return { type: 'selector', value, loc };\n}\n\n// ─── Declaration ──────────────────────────────────────────────────────────────\n\n/**\n * Build a `CssDeclaration` node.\n *\n * @param property CSS property name (e.g. `'color'`, `'--my-var'`)\n * @param rawValue Raw value string (e.g. `'red'`, `'1px solid #000'`)\n * @param important Whether the declaration carries `!important`\n * @param value Parsed `CssValue[]` tokens — defaults to empty (lazy parse)\n * @param loc Optional source location\n */\nexport function decl(\n property: string,\n rawValue: string,\n important = false,\n value: CssValue[] = [],\n loc?: Location,\n): CssDeclaration {\n return { type: 'declaration', property, rawValue, value, important, loc };\n}\n\n/** Alias for {@link decl} with a name that mirrors the AST interface. */\nexport function declaration(\n property: string,\n value: CssValue[],\n important: boolean,\n rawValue?: string,\n loc?: Location,\n): CssDeclaration {\n return { type: 'declaration', property, value, rawValue, important, loc };\n}\n\n// ─── Rule ─────────────────────────────────────────────────────────────────────\n\n/**\n * Build a `CssRule` node.\n *\n * @param rawSelector Raw selector string (e.g. `'.btn:hover'`)\n * @param declarations Array of declarations\n * @param children Optional nested rules / at-rules (CSS nesting)\n * @param loc Optional source location\n */\nexport function rule(\n rawSelector: string,\n declarations: CssDeclaration[] = [],\n children?: (CssRule | CssAtRule)[],\n loc?: Location,\n): CssRule {\n const selectors: CssSelector[] = rawSelector\n .split(',')\n .map(s => selector(s.trim()));\n\n const node: CssRule = { type: 'rule', rawSelector, selectors, declarations, loc };\n if (children?.length) node.children = children;\n return node;\n}\n\n// ─── At-rule ──────────────────────────────────────────────────────────────────\n\n/**\n * Build a `CssAtRule` node.\n *\n * @param name At-rule name without `@` (e.g. `'media'`, `'keyframes'`)\n * @param preludeText Raw prelude text (e.g. `'screen and (max-width: 600px)'`)\n * @param children Block children (rules, declarations, keyframes…)\n * @param loc Optional source location\n */\nexport function atRule(\n name: string,\n preludeText = '',\n children: CssAstNode[] = [],\n loc?: Location,\n): CssAtRule {\n const node: CssAtRule = {\n type: 'atrule',\n name,\n preludeText,\n prelude: [],\n loc,\n };\n if (children.length) {\n node.block = { type: 'block', children: children as any };\n }\n return node;\n}\n\n// ─── Comment ──────────────────────────────────────────────────────────────────\n\nexport function comment(value: string, loc?: Location): CssComment {\n return {\n type: 'comment',\n value,\n style: value.includes('\\n') ? 'multi-line' : 'single-line',\n loc,\n };\n}\n\n// ─── Keyframe ─────────────────────────────────────────────────────────────────\n\nexport function keyframe(\n selectorText: string,\n declarations: CssDeclaration[] = [],\n loc?: Location,\n): CssKeyframe {\n return { type: 'keyframe', selector: selectorText, declarations, loc };\n}\n\n// ─── Stylesheet ───────────────────────────────────────────────────────────────\n\nexport function stylesheet(children: CssAstNode[] = []): CssStylesheet {\n return {\n type: 'stylesheet',\n children,\n imports: [], namespaces: [], mediaQueries: [], keyframes: [],\n fontFaces: [], layers: [], containers: [], supports: [],\n documents: [], pages: [], counterStyles: [], fontFeatureValues: [],\n viewports: [], charsets: [],\n };\n}\n\n// ─── Clone ────────────────────────────────────────────────────────────────────\n\n/** Shallow-clone any CSS AST node (one level deep). */\nexport function cloneNode<T extends CssAstNode>(node: T): T {\n return { ...node } as T;\n}\n\n/** Deep-clone a CSS AST node tree. */\nexport function cloneNodeDeep<T extends CssAstNode>(node: T): T {\n const shallow = { ...node } as any;\n\n if (shallow.declarations) {\n shallow.declarations = shallow.declarations.map((d: CssDeclaration) => ({ ...d }));\n }\n if (shallow.children) {\n shallow.children = shallow.children.map((c: CssAstNode) => cloneNodeDeep(c));\n }\n if (shallow.block) {\n shallow.block = {\n ...shallow.block,\n children: shallow.block.children.map((c: CssAstNode) => cloneNodeDeep(c)),\n };\n }\n if (shallow.selectors) {\n shallow.selectors = shallow.selectors.map((s: CssSelector) => ({ ...s }));\n }\n if (shallow.keyframes) {\n shallow.keyframes = shallow.keyframes.map((kf: CssKeyframe) => ({\n ...kf,\n declarations: kf.declarations.map((d: CssDeclaration) => ({ ...d })),\n }));\n }\n return shallow as T;\n}\n\n// ─── Walk ─────────────────────────────────────────────────────────────────────\n\n/**\n * Depth-first traversal of a CSS AST.\n *\n * The visitor may mutate, replace, or remove nodes via the `WalkContext`:\n *\n * ```ts\n * walk(ast, {\n * rule(node, ctx) {\n * if (node.rawSelector === '.old') ctx.replace(rule('.new', node.declarations));\n * },\n * declaration(node, ctx) {\n * if (node.property === 'color') ctx.remove();\n * },\n * });\n * ```\n *\n * To stop the entire traversal early call `ctx.stop()`.\n */\nexport function walk(node: CssAstNode, visitor: WalkVisitor): void {\n const state = { stopped: false };\n _walk(node, visitor, null, 0, 0, state);\n}\n\nfunction _walk(\n node: CssAstNode,\n visitor: WalkVisitor,\n parent: CssAstNode | null,\n index: number,\n depth: number,\n state: { stopped: boolean },\n): void {\n if (state.stopped) return;\n\n // ── Build mutation context ────────────────────────────────────────────────\n let pendingAction: null | 'remove' | { type: 'replace'; node: CssAstNode } = null;\n\n const ctx: WalkContext = {\n parent,\n index,\n depth,\n stop: () => { state.stopped = true; },\n remove: () => { pendingAction = 'remove'; },\n replace: (n) => { pendingAction = { type: 'replace', node: n }; },\n };\n\n // ── Dispatch typed visitor ────────────────────────────────────────────────\n switch (node.type) {\n case 'stylesheet': visitor.stylesheet?.(node as CssStylesheet, ctx); break;\n case 'rule': visitor.rule?.(node as CssRule, ctx); break;\n case 'atrule': visitor.atrule?.(node as CssAtRule, ctx); break;\n case 'declaration': visitor.declaration?.(node as CssDeclaration, ctx); break;\n case 'comment': visitor.comment?.(node as CssComment, ctx); break;\n case 'keyframe': visitor.keyframe?.(node as CssKeyframe, ctx); break;\n }\n if (!state.stopped) visitor.enter?.(node, ctx);\n\n // ── Apply replace / remove before descending ──────────────────────────────\n if (pendingAction !== null) {\n applyMutation(pendingAction, parent, index);\n // After removal/replacement, don't descend into the original node\n if (!state.stopped) visitor.leave?.(node, ctx);\n return;\n }\n\n if (state.stopped) return;\n\n // ── Descend ───────────────────────────────────────────────────────────────\n const children = getChildren(node);\n for (let i = 0; i < children.length; i++) {\n if (state.stopped) break;\n _walk(children[i], visitor, node, i, depth + 1, state);\n // After a walk the array may have mutated (remove/replace); adjust index\n // by checking length (children is a live reference to the original array)\n }\n\n if (!state.stopped) visitor.leave?.(node, ctx);\n}\n\nfunction getChildren(node: CssAstNode): CssAstNode[] {\n switch (node.type) {\n case 'stylesheet': {\n const ss = node as CssStylesheet;\n return ss.children as CssAstNode[];\n }\n case 'rule': {\n const r = node as CssRule;\n const out: CssAstNode[] = [...(r.declarations as CssAstNode[])];\n if (r.children) out.push(...(r.children as CssAstNode[]));\n return out;\n }\n case 'atrule': {\n const ar = node as CssAtRule;\n return ar.block ? (ar.block.children as CssAstNode[]) : [];\n }\n default:\n return [];\n }\n}\n\nfunction applyMutation(\n action: 'remove' | { type: 'replace'; node: CssAstNode | CssAstNode[] },\n parent: CssAstNode | null,\n index: number,\n): void {\n if (!parent) return;\n\n const arr = getMutableChildArray(parent, index);\n if (!arr) return;\n\n if (action === 'remove') {\n arr.splice(index, 1);\n } else {\n const n = Array.isArray(action.node) ? action.node : [action.node]\n arr.splice(index, 1, ...n);\n }\n}\n\nfunction getMutableChildArray(parent: CssAstNode, index: number): CssAstNode[] | null {\n switch (parent.type) {\n case 'stylesheet':\n return (parent as CssStylesheet).children as CssAstNode[];\n case 'rule': {\n const r = parent as CssRule;\n // index < declarations.length → declaration, else → nested child\n if (index < r.declarations.length) return r.declarations as unknown as CssAstNode[];\n if (r.children) return r.children as CssAstNode[];\n return null;\n }\n case 'atrule': {\n const ar = parent as CssAtRule;\n return ar.block ? (ar.block.children as CssAstNode[]) : null;\n }\n default:\n return null;\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare enum TokenType {
|
|
2
|
+
Whitespace = 0,
|
|
3
|
+
Comment = 1,
|
|
4
|
+
Ident = 2,
|
|
5
|
+
AtKeyword = 3,
|
|
6
|
+
String = 4,
|
|
7
|
+
Number = 5,
|
|
8
|
+
Hash = 6,
|
|
9
|
+
Delim = 7,
|
|
10
|
+
Colon = 8,
|
|
11
|
+
Semicolon = 9,
|
|
12
|
+
Comma = 10,
|
|
13
|
+
LBrace = 11,
|
|
14
|
+
RBrace = 12,
|
|
15
|
+
LParen = 13,
|
|
16
|
+
RParen = 14,
|
|
17
|
+
LBracket = 15,
|
|
18
|
+
RBracket = 16,
|
|
19
|
+
Function = 17,
|
|
20
|
+
Url = 18,
|
|
21
|
+
EOF = 19
|
|
22
|
+
}
|
|
23
|
+
export interface Token {
|
|
24
|
+
type: TokenType;
|
|
25
|
+
value?: string;
|
|
26
|
+
loc: {
|
|
27
|
+
start: Position;
|
|
28
|
+
end: Position;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export type Position = {
|
|
32
|
+
line: number;
|
|
33
|
+
column: number;
|
|
34
|
+
offset: number;
|
|
35
|
+
};
|
|
36
|
+
export declare class CssLexer {
|
|
37
|
+
private i;
|
|
38
|
+
private line;
|
|
39
|
+
private col;
|
|
40
|
+
private len;
|
|
41
|
+
private s;
|
|
42
|
+
constructor(input: string);
|
|
43
|
+
private cur;
|
|
44
|
+
private next;
|
|
45
|
+
private pos;
|
|
46
|
+
private adv;
|
|
47
|
+
tokenize(): Token[];
|
|
48
|
+
}
|