@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,2047 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _arrayLikeToArray(r, a) {
|
|
4
|
+
(null == a || a > r.length) && (a = r.length);
|
|
5
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
6
|
+
return n;
|
|
7
|
+
}
|
|
8
|
+
function _arrayWithoutHoles(r) {
|
|
9
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
10
|
+
}
|
|
11
|
+
function _classCallCheck(a, n) {
|
|
12
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
13
|
+
}
|
|
14
|
+
function _defineProperties(e, r) {
|
|
15
|
+
for (var t = 0; t < r.length; t++) {
|
|
16
|
+
var o = r[t];
|
|
17
|
+
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function _createClass(e, r, t) {
|
|
21
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
22
|
+
writable: false
|
|
23
|
+
}), e;
|
|
24
|
+
}
|
|
25
|
+
function _createForOfIteratorHelper(r, e) {
|
|
26
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
27
|
+
if (!t) {
|
|
28
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
|
|
29
|
+
t && (r = t);
|
|
30
|
+
var n = 0,
|
|
31
|
+
F = function () {};
|
|
32
|
+
return {
|
|
33
|
+
s: F,
|
|
34
|
+
n: function () {
|
|
35
|
+
return n >= r.length ? {
|
|
36
|
+
done: true
|
|
37
|
+
} : {
|
|
38
|
+
done: false,
|
|
39
|
+
value: r[n++]
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
e: function (r) {
|
|
43
|
+
throw r;
|
|
44
|
+
},
|
|
45
|
+
f: F
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
49
|
+
}
|
|
50
|
+
var o,
|
|
51
|
+
a = true,
|
|
52
|
+
u = false;
|
|
53
|
+
return {
|
|
54
|
+
s: function () {
|
|
55
|
+
t = t.call(r);
|
|
56
|
+
},
|
|
57
|
+
n: function () {
|
|
58
|
+
var r = t.next();
|
|
59
|
+
return a = r.done, r;
|
|
60
|
+
},
|
|
61
|
+
e: function (r) {
|
|
62
|
+
u = true, o = r;
|
|
63
|
+
},
|
|
64
|
+
f: function () {
|
|
65
|
+
try {
|
|
66
|
+
a || null == t.return || t.return();
|
|
67
|
+
} finally {
|
|
68
|
+
if (u) throw o;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function _defineProperty(e, r, t) {
|
|
74
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
75
|
+
value: t,
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true
|
|
79
|
+
}) : e[r] = t, e;
|
|
80
|
+
}
|
|
81
|
+
function _iterableToArray(r) {
|
|
82
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
83
|
+
}
|
|
84
|
+
function _nonIterableSpread() {
|
|
85
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
86
|
+
}
|
|
87
|
+
function ownKeys(e, r) {
|
|
88
|
+
var t = Object.keys(e);
|
|
89
|
+
if (Object.getOwnPropertySymbols) {
|
|
90
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
91
|
+
r && (o = o.filter(function (r) {
|
|
92
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
93
|
+
})), t.push.apply(t, o);
|
|
94
|
+
}
|
|
95
|
+
return t;
|
|
96
|
+
}
|
|
97
|
+
function _objectSpread2(e) {
|
|
98
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
99
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
100
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
101
|
+
_defineProperty(e, r, t[r]);
|
|
102
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
103
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return e;
|
|
107
|
+
}
|
|
108
|
+
function _toConsumableArray(r) {
|
|
109
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
110
|
+
}
|
|
111
|
+
function _toPrimitive(t, r) {
|
|
112
|
+
if ("object" != typeof t || !t) return t;
|
|
113
|
+
var e = t[Symbol.toPrimitive];
|
|
114
|
+
if (void 0 !== e) {
|
|
115
|
+
var i = e.call(t, r);
|
|
116
|
+
if ("object" != typeof i) return i;
|
|
117
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
118
|
+
}
|
|
119
|
+
return ("string" === r ? String : Number)(t);
|
|
120
|
+
}
|
|
121
|
+
function _toPropertyKey(t) {
|
|
122
|
+
var i = _toPrimitive(t, "string");
|
|
123
|
+
return "symbol" == typeof i ? i : i + "";
|
|
124
|
+
}
|
|
125
|
+
function _unsupportedIterableToArray(r, a) {
|
|
126
|
+
if (r) {
|
|
127
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
128
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
129
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* CSS Generator — converts a CSS AST back to a CSS string.
|
|
135
|
+
*
|
|
136
|
+
* Supports:
|
|
137
|
+
* - Pretty-printing with configurable indent / newline
|
|
138
|
+
* - Minification (all whitespace removed except mandatory single spaces)
|
|
139
|
+
* - Optional comment suppression
|
|
140
|
+
* - Per-node middleware (onRule, onAtRule, onDeclaration, onComment, onKeyframe)
|
|
141
|
+
* called *after* serialization so you can post-process individual nodes
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
var CssGenerator = /*#__PURE__*/function () {
|
|
145
|
+
function CssGenerator() {
|
|
146
|
+
var _opts$minify, _opts$newline, _opts$indent, _opts$comments;
|
|
147
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
148
|
+
_classCallCheck(this, CssGenerator);
|
|
149
|
+
this.opts = opts;
|
|
150
|
+
var min = (_opts$minify = opts.minify) !== null && _opts$minify !== void 0 ? _opts$minify : false;
|
|
151
|
+
this.nl = min ? '' : (_opts$newline = opts.newline) !== null && _opts$newline !== void 0 ? _opts$newline : '\n';
|
|
152
|
+
this.sp = min ? '' : ' ';
|
|
153
|
+
this.ind = min ? '' : (_opts$indent = opts.indent) !== null && _opts$indent !== void 0 ? _opts$indent : ' ';
|
|
154
|
+
this.showComments = (_opts$comments = opts.comments) !== null && _opts$comments !== void 0 ? _opts$comments : true;
|
|
155
|
+
}
|
|
156
|
+
return _createClass(CssGenerator, [{
|
|
157
|
+
key: "generate",
|
|
158
|
+
value: function generate(node) {
|
|
159
|
+
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
160
|
+
switch (node.type) {
|
|
161
|
+
case 'stylesheet':
|
|
162
|
+
return this.genSheet(node, depth);
|
|
163
|
+
case 'rule':
|
|
164
|
+
return this.genRule(node, depth);
|
|
165
|
+
case 'atrule':
|
|
166
|
+
return this.genAtRule(node, depth);
|
|
167
|
+
case 'declaration':
|
|
168
|
+
return this.genDecl(node, depth);
|
|
169
|
+
case 'comment':
|
|
170
|
+
return this.showComments ? this.genComment(node, depth) : '';
|
|
171
|
+
case 'keyframe':
|
|
172
|
+
return this.genKeyframe(node, depth);
|
|
173
|
+
default:
|
|
174
|
+
return '';
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
key: "pad",
|
|
179
|
+
value: function pad(depth) {
|
|
180
|
+
return this.opts.minify ? '' : this.ind.repeat(depth);
|
|
181
|
+
}
|
|
182
|
+
}, {
|
|
183
|
+
key: "genSheet",
|
|
184
|
+
value: function genSheet(ss, depth) {
|
|
185
|
+
var _this = this;
|
|
186
|
+
return ss.children.map(function (c) {
|
|
187
|
+
return _this.generate(c, depth);
|
|
188
|
+
}).filter(function (s) {
|
|
189
|
+
return s.length > 0;
|
|
190
|
+
}).join(this.opts.minify ? '' : this.nl + this.nl);
|
|
191
|
+
}
|
|
192
|
+
}, {
|
|
193
|
+
key: "genRule",
|
|
194
|
+
value: function genRule(rule, depth) {
|
|
195
|
+
var _rule$rawSelector, _rule$children;
|
|
196
|
+
var pad = this.pad(depth);
|
|
197
|
+
var ipad = this.pad(depth + 1);
|
|
198
|
+
var sel = (_rule$rawSelector = rule.rawSelector) !== null && _rule$rawSelector !== void 0 ? _rule$rawSelector : rule.selectors.map(function (s) {
|
|
199
|
+
return s.value;
|
|
200
|
+
}).join(",".concat(this.sp));
|
|
201
|
+
var body = '';
|
|
202
|
+
var _iterator = _createForOfIteratorHelper(rule.declarations),
|
|
203
|
+
_step;
|
|
204
|
+
try {
|
|
205
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
206
|
+
var d = _step.value;
|
|
207
|
+
body += ipad + this.genDecl(d, 0) + this.nl;
|
|
208
|
+
}
|
|
209
|
+
} catch (err) {
|
|
210
|
+
_iterator.e(err);
|
|
211
|
+
} finally {
|
|
212
|
+
_iterator.f();
|
|
213
|
+
}
|
|
214
|
+
if ((_rule$children = rule.children) !== null && _rule$children !== void 0 && _rule$children.length) {
|
|
215
|
+
var _iterator2 = _createForOfIteratorHelper(rule.children),
|
|
216
|
+
_step2;
|
|
217
|
+
try {
|
|
218
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
219
|
+
var child = _step2.value;
|
|
220
|
+
var str = this.generate(child, depth + 1);
|
|
221
|
+
if (str) body += str + this.nl;
|
|
222
|
+
}
|
|
223
|
+
} catch (err) {
|
|
224
|
+
_iterator2.e(err);
|
|
225
|
+
} finally {
|
|
226
|
+
_iterator2.f();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
var css = "".concat(pad).concat(sel).concat(this.sp, "{").concat(this.nl).concat(body).concat(pad, "}");
|
|
230
|
+
return this.opts.onRule ? this.opts.onRule(rule, css) : css;
|
|
231
|
+
}
|
|
232
|
+
}, {
|
|
233
|
+
key: "genAtRule",
|
|
234
|
+
value: function genAtRule(ar, depth) {
|
|
235
|
+
var _ref, _ar$preludeText, _ar$prelude;
|
|
236
|
+
var pad = this.pad(depth);
|
|
237
|
+
var prelude = (_ref = (_ar$preludeText = ar.preludeText) !== null && _ar$preludeText !== void 0 ? _ar$preludeText : (_ar$prelude = ar.prelude) === null || _ar$prelude === void 0 ? void 0 : _ar$prelude.map(function (v) {
|
|
238
|
+
return String(v.value);
|
|
239
|
+
}).join(' ')) !== null && _ref !== void 0 ? _ref : '';
|
|
240
|
+
var head = "@".concat(ar.name).concat(prelude ? ' ' + prelude : '');
|
|
241
|
+
if (!ar.block) {
|
|
242
|
+
var _css = "".concat(pad).concat(head, ";");
|
|
243
|
+
return this.opts.onAtRule ? this.opts.onAtRule(ar, _css) : _css;
|
|
244
|
+
}
|
|
245
|
+
var body = '';
|
|
246
|
+
var _iterator3 = _createForOfIteratorHelper(ar.block.children),
|
|
247
|
+
_step3;
|
|
248
|
+
try {
|
|
249
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
250
|
+
var child = _step3.value;
|
|
251
|
+
var str = this.generate(child, depth + 1);
|
|
252
|
+
if (str) body += str + this.nl;
|
|
253
|
+
}
|
|
254
|
+
} catch (err) {
|
|
255
|
+
_iterator3.e(err);
|
|
256
|
+
} finally {
|
|
257
|
+
_iterator3.f();
|
|
258
|
+
}
|
|
259
|
+
var css = "".concat(pad).concat(head).concat(this.sp, "{").concat(this.nl).concat(body).concat(pad, "}");
|
|
260
|
+
return this.opts.onAtRule ? this.opts.onAtRule(ar, css) : css;
|
|
261
|
+
}
|
|
262
|
+
}, {
|
|
263
|
+
key: "genDecl",
|
|
264
|
+
value: function genDecl(d, depth) {
|
|
265
|
+
var _d$rawValue;
|
|
266
|
+
var pad = this.pad(depth);
|
|
267
|
+
var value = (_d$rawValue = d.rawValue) !== null && _d$rawValue !== void 0 ? _d$rawValue : d.value.map(function (v) {
|
|
268
|
+
return String(v.value);
|
|
269
|
+
}).join(' ');
|
|
270
|
+
var imp = d.important ? ' !important' : '';
|
|
271
|
+
var css = "".concat(pad).concat(d.property, ":").concat(this.sp).concat(value).concat(imp, ";");
|
|
272
|
+
return this.opts.onDeclaration ? this.opts.onDeclaration(d, css) : css;
|
|
273
|
+
}
|
|
274
|
+
}, {
|
|
275
|
+
key: "genComment",
|
|
276
|
+
value: function genComment(c, depth) {
|
|
277
|
+
var css = "".concat(this.pad(depth), "/*").concat(c.value, "*/");
|
|
278
|
+
return this.opts.onComment ? this.opts.onComment(c, css) : css;
|
|
279
|
+
}
|
|
280
|
+
}, {
|
|
281
|
+
key: "genKeyframe",
|
|
282
|
+
value: function genKeyframe(kf, depth) {
|
|
283
|
+
var _this2 = this;
|
|
284
|
+
var pad = this.pad(depth);
|
|
285
|
+
var ipad = this.pad(depth + 1);
|
|
286
|
+
var body = kf.declarations.map(function (d) {
|
|
287
|
+
return ipad + _this2.genDecl(d, 0) + _this2.nl;
|
|
288
|
+
}).join('');
|
|
289
|
+
var css = "".concat(pad).concat(kf.selector).concat(this.sp, "{").concat(this.nl).concat(body).concat(pad, "}");
|
|
290
|
+
return this.opts.onKeyframe ? this.opts.onKeyframe(kf, css) : css;
|
|
291
|
+
}
|
|
292
|
+
}]);
|
|
293
|
+
}();
|
|
294
|
+
|
|
295
|
+
// ─── Convenience function ─────────────────────────────────────────────────────
|
|
296
|
+
|
|
297
|
+
/** Serialize a CSS AST node back to a CSS string. */
|
|
298
|
+
function stringify(node, options) {
|
|
299
|
+
return new CssGenerator(options).generate(node);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* CSS AST helper / factory functions.
|
|
304
|
+
*
|
|
305
|
+
* Thin wrappers that construct typed AST nodes so callers don't have to
|
|
306
|
+
* spell out `type: 'rule'` etc. everywhere.
|
|
307
|
+
*
|
|
308
|
+
* All parameters that could be omitted are optional and default to sensible
|
|
309
|
+
* empty values so that helpers compose naturally:
|
|
310
|
+
*
|
|
311
|
+
* import { rule, decl, atRule } from './css-helpers';
|
|
312
|
+
*
|
|
313
|
+
* const node = rule('.btn', [
|
|
314
|
+
* decl('color', 'red'),
|
|
315
|
+
* decl('font-size', '1rem'),
|
|
316
|
+
* ]);
|
|
317
|
+
*/
|
|
318
|
+
|
|
319
|
+
// ─── Location ─────────────────────────────────────────────────────────────────
|
|
320
|
+
|
|
321
|
+
function locationPos(line, column, offset) {
|
|
322
|
+
return {
|
|
323
|
+
line: line,
|
|
324
|
+
column: column,
|
|
325
|
+
offset: offset
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function location(start, end, source) {
|
|
329
|
+
return {
|
|
330
|
+
start: start,
|
|
331
|
+
end: end,
|
|
332
|
+
source: source
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// ─── Selector ─────────────────────────────────────────────────────────────────
|
|
337
|
+
|
|
338
|
+
function selector(value, loc) {
|
|
339
|
+
return {
|
|
340
|
+
type: 'selector',
|
|
341
|
+
value: value,
|
|
342
|
+
loc: loc
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// ─── Declaration ──────────────────────────────────────────────────────────────
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Build a `CssDeclaration` node.
|
|
350
|
+
*
|
|
351
|
+
* @param property CSS property name (e.g. `'color'`, `'--my-var'`)
|
|
352
|
+
* @param rawValue Raw value string (e.g. `'red'`, `'1px solid #000'`)
|
|
353
|
+
* @param important Whether the declaration carries `!important`
|
|
354
|
+
* @param value Parsed `CssValue[]` tokens — defaults to empty (lazy parse)
|
|
355
|
+
* @param loc Optional source location
|
|
356
|
+
*/
|
|
357
|
+
function decl(property, rawValue) {
|
|
358
|
+
var important = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
359
|
+
var value = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
360
|
+
var loc = arguments.length > 4 ? arguments[4] : undefined;
|
|
361
|
+
return {
|
|
362
|
+
type: 'declaration',
|
|
363
|
+
property: property,
|
|
364
|
+
rawValue: rawValue,
|
|
365
|
+
value: value,
|
|
366
|
+
important: important,
|
|
367
|
+
loc: loc
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Alias for {@link decl} with a name that mirrors the AST interface. */
|
|
372
|
+
function declaration(property, value, important, rawValue, loc) {
|
|
373
|
+
return {
|
|
374
|
+
type: 'declaration',
|
|
375
|
+
property: property,
|
|
376
|
+
value: value,
|
|
377
|
+
rawValue: rawValue,
|
|
378
|
+
important: important,
|
|
379
|
+
loc: loc
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// ─── Rule ─────────────────────────────────────────────────────────────────────
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Build a `CssRule` node.
|
|
387
|
+
*
|
|
388
|
+
* @param rawSelector Raw selector string (e.g. `'.btn:hover'`)
|
|
389
|
+
* @param declarations Array of declarations
|
|
390
|
+
* @param children Optional nested rules / at-rules (CSS nesting)
|
|
391
|
+
* @param loc Optional source location
|
|
392
|
+
*/
|
|
393
|
+
function rule(rawSelector) {
|
|
394
|
+
var declarations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
395
|
+
var children = arguments.length > 2 ? arguments[2] : undefined;
|
|
396
|
+
var loc = arguments.length > 3 ? arguments[3] : undefined;
|
|
397
|
+
var selectors = rawSelector.split(',').map(function (s) {
|
|
398
|
+
return selector(s.trim());
|
|
399
|
+
});
|
|
400
|
+
var node = {
|
|
401
|
+
type: 'rule',
|
|
402
|
+
rawSelector: rawSelector,
|
|
403
|
+
selectors: selectors,
|
|
404
|
+
declarations: declarations,
|
|
405
|
+
loc: loc
|
|
406
|
+
};
|
|
407
|
+
if (children !== null && children !== void 0 && children.length) node.children = children;
|
|
408
|
+
return node;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// ─── At-rule ──────────────────────────────────────────────────────────────────
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Build a `CssAtRule` node.
|
|
415
|
+
*
|
|
416
|
+
* @param name At-rule name without `@` (e.g. `'media'`, `'keyframes'`)
|
|
417
|
+
* @param preludeText Raw prelude text (e.g. `'screen and (max-width: 600px)'`)
|
|
418
|
+
* @param children Block children (rules, declarations, keyframes…)
|
|
419
|
+
* @param loc Optional source location
|
|
420
|
+
*/
|
|
421
|
+
function atRule(name) {
|
|
422
|
+
var preludeText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
423
|
+
var children = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
424
|
+
var loc = arguments.length > 3 ? arguments[3] : undefined;
|
|
425
|
+
var node = {
|
|
426
|
+
type: 'atrule',
|
|
427
|
+
name: name,
|
|
428
|
+
preludeText: preludeText,
|
|
429
|
+
prelude: [],
|
|
430
|
+
loc: loc
|
|
431
|
+
};
|
|
432
|
+
if (children.length) {
|
|
433
|
+
node.block = {
|
|
434
|
+
type: 'block',
|
|
435
|
+
children: children
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
return node;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// ─── Comment ──────────────────────────────────────────────────────────────────
|
|
442
|
+
|
|
443
|
+
function comment(value, loc) {
|
|
444
|
+
return {
|
|
445
|
+
type: 'comment',
|
|
446
|
+
value: value,
|
|
447
|
+
style: value.includes('\n') ? 'multi-line' : 'single-line',
|
|
448
|
+
loc: loc
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// ─── Keyframe ─────────────────────────────────────────────────────────────────
|
|
453
|
+
|
|
454
|
+
function keyframe(selectorText) {
|
|
455
|
+
var declarations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
456
|
+
var loc = arguments.length > 2 ? arguments[2] : undefined;
|
|
457
|
+
return {
|
|
458
|
+
type: 'keyframe',
|
|
459
|
+
selector: selectorText,
|
|
460
|
+
declarations: declarations,
|
|
461
|
+
loc: loc
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// ─── Stylesheet ───────────────────────────────────────────────────────────────
|
|
466
|
+
|
|
467
|
+
function stylesheet() {
|
|
468
|
+
var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
469
|
+
return {
|
|
470
|
+
type: 'stylesheet',
|
|
471
|
+
children: children,
|
|
472
|
+
imports: [],
|
|
473
|
+
namespaces: [],
|
|
474
|
+
mediaQueries: [],
|
|
475
|
+
keyframes: [],
|
|
476
|
+
fontFaces: [],
|
|
477
|
+
layers: [],
|
|
478
|
+
containers: [],
|
|
479
|
+
supports: [],
|
|
480
|
+
documents: [],
|
|
481
|
+
pages: [],
|
|
482
|
+
counterStyles: [],
|
|
483
|
+
fontFeatureValues: [],
|
|
484
|
+
viewports: [],
|
|
485
|
+
charsets: []
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// ─── Clone ────────────────────────────────────────────────────────────────────
|
|
490
|
+
|
|
491
|
+
/** Shallow-clone any CSS AST node (one level deep). */
|
|
492
|
+
function cloneNode(node) {
|
|
493
|
+
return _objectSpread2({}, node);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** Deep-clone a CSS AST node tree. */
|
|
497
|
+
function cloneNodeDeep(node) {
|
|
498
|
+
var shallow = _objectSpread2({}, node);
|
|
499
|
+
if (shallow.declarations) {
|
|
500
|
+
shallow.declarations = shallow.declarations.map(function (d) {
|
|
501
|
+
return _objectSpread2({}, d);
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
if (shallow.children) {
|
|
505
|
+
shallow.children = shallow.children.map(function (c) {
|
|
506
|
+
return cloneNodeDeep(c);
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
if (shallow.block) {
|
|
510
|
+
shallow.block = _objectSpread2(_objectSpread2({}, shallow.block), {}, {
|
|
511
|
+
children: shallow.block.children.map(function (c) {
|
|
512
|
+
return cloneNodeDeep(c);
|
|
513
|
+
})
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
if (shallow.selectors) {
|
|
517
|
+
shallow.selectors = shallow.selectors.map(function (s) {
|
|
518
|
+
return _objectSpread2({}, s);
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
if (shallow.keyframes) {
|
|
522
|
+
shallow.keyframes = shallow.keyframes.map(function (kf) {
|
|
523
|
+
return _objectSpread2(_objectSpread2({}, kf), {}, {
|
|
524
|
+
declarations: kf.declarations.map(function (d) {
|
|
525
|
+
return _objectSpread2({}, d);
|
|
526
|
+
})
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
return shallow;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// ─── Walk ─────────────────────────────────────────────────────────────────────
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Depth-first traversal of a CSS AST.
|
|
537
|
+
*
|
|
538
|
+
* The visitor may mutate, replace, or remove nodes via the `WalkContext`:
|
|
539
|
+
*
|
|
540
|
+
* ```ts
|
|
541
|
+
* walk(ast, {
|
|
542
|
+
* rule(node, ctx) {
|
|
543
|
+
* if (node.rawSelector === '.old') ctx.replace(rule('.new', node.declarations));
|
|
544
|
+
* },
|
|
545
|
+
* declaration(node, ctx) {
|
|
546
|
+
* if (node.property === 'color') ctx.remove();
|
|
547
|
+
* },
|
|
548
|
+
* });
|
|
549
|
+
* ```
|
|
550
|
+
*
|
|
551
|
+
* To stop the entire traversal early call `ctx.stop()`.
|
|
552
|
+
*/
|
|
553
|
+
function walk(node, visitor) {
|
|
554
|
+
var state = {
|
|
555
|
+
stopped: false
|
|
556
|
+
};
|
|
557
|
+
_walk(node, visitor, null, 0, 0, state);
|
|
558
|
+
}
|
|
559
|
+
function _walk(node, visitor, parent, index, depth, state) {
|
|
560
|
+
var _visitor$stylesheet, _visitor$rule, _visitor$atrule, _visitor$declaration, _visitor$comment, _visitor$keyframe, _visitor$enter, _visitor$leave2;
|
|
561
|
+
if (state.stopped) return;
|
|
562
|
+
|
|
563
|
+
// ── Build mutation context ────────────────────────────────────────────────
|
|
564
|
+
var pendingAction = null;
|
|
565
|
+
var ctx = {
|
|
566
|
+
parent: parent,
|
|
567
|
+
index: index,
|
|
568
|
+
depth: depth,
|
|
569
|
+
stop: function stop() {
|
|
570
|
+
state.stopped = true;
|
|
571
|
+
},
|
|
572
|
+
remove: function remove() {
|
|
573
|
+
pendingAction = 'remove';
|
|
574
|
+
},
|
|
575
|
+
replace: function replace(n) {
|
|
576
|
+
pendingAction = {
|
|
577
|
+
type: 'replace',
|
|
578
|
+
node: n
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
// ── Dispatch typed visitor ────────────────────────────────────────────────
|
|
584
|
+
switch (node.type) {
|
|
585
|
+
case 'stylesheet':
|
|
586
|
+
(_visitor$stylesheet = visitor.stylesheet) === null || _visitor$stylesheet === void 0 || _visitor$stylesheet.call(visitor, node, ctx);
|
|
587
|
+
break;
|
|
588
|
+
case 'rule':
|
|
589
|
+
(_visitor$rule = visitor.rule) === null || _visitor$rule === void 0 || _visitor$rule.call(visitor, node, ctx);
|
|
590
|
+
break;
|
|
591
|
+
case 'atrule':
|
|
592
|
+
(_visitor$atrule = visitor.atrule) === null || _visitor$atrule === void 0 || _visitor$atrule.call(visitor, node, ctx);
|
|
593
|
+
break;
|
|
594
|
+
case 'declaration':
|
|
595
|
+
(_visitor$declaration = visitor.declaration) === null || _visitor$declaration === void 0 || _visitor$declaration.call(visitor, node, ctx);
|
|
596
|
+
break;
|
|
597
|
+
case 'comment':
|
|
598
|
+
(_visitor$comment = visitor.comment) === null || _visitor$comment === void 0 || _visitor$comment.call(visitor, node, ctx);
|
|
599
|
+
break;
|
|
600
|
+
case 'keyframe':
|
|
601
|
+
(_visitor$keyframe = visitor.keyframe) === null || _visitor$keyframe === void 0 || _visitor$keyframe.call(visitor, node, ctx);
|
|
602
|
+
break;
|
|
603
|
+
}
|
|
604
|
+
if (!state.stopped) (_visitor$enter = visitor.enter) === null || _visitor$enter === void 0 || _visitor$enter.call(visitor, node, ctx);
|
|
605
|
+
|
|
606
|
+
// ── Apply replace / remove before descending ──────────────────────────────
|
|
607
|
+
if (pendingAction !== null) {
|
|
608
|
+
var _visitor$leave;
|
|
609
|
+
applyMutation(pendingAction, parent, index);
|
|
610
|
+
// After removal/replacement, don't descend into the original node
|
|
611
|
+
if (!state.stopped) (_visitor$leave = visitor.leave) === null || _visitor$leave === void 0 || _visitor$leave.call(visitor, node, ctx);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
if (state.stopped) return;
|
|
615
|
+
|
|
616
|
+
// ── Descend ───────────────────────────────────────────────────────────────
|
|
617
|
+
var children = getChildren(node);
|
|
618
|
+
for (var i = 0; i < children.length; i++) {
|
|
619
|
+
if (state.stopped) break;
|
|
620
|
+
_walk(children[i], visitor, node, i, depth + 1, state);
|
|
621
|
+
// After a walk the array may have mutated (remove/replace); adjust index
|
|
622
|
+
// by checking length (children is a live reference to the original array)
|
|
623
|
+
}
|
|
624
|
+
if (!state.stopped) (_visitor$leave2 = visitor.leave) === null || _visitor$leave2 === void 0 || _visitor$leave2.call(visitor, node, ctx);
|
|
625
|
+
}
|
|
626
|
+
function getChildren(node) {
|
|
627
|
+
switch (node.type) {
|
|
628
|
+
case 'stylesheet':
|
|
629
|
+
{
|
|
630
|
+
var ss = node;
|
|
631
|
+
return ss.children;
|
|
632
|
+
}
|
|
633
|
+
case 'rule':
|
|
634
|
+
{
|
|
635
|
+
var r = node;
|
|
636
|
+
var out = _toConsumableArray(r.declarations);
|
|
637
|
+
if (r.children) out.push.apply(out, _toConsumableArray(r.children));
|
|
638
|
+
return out;
|
|
639
|
+
}
|
|
640
|
+
case 'atrule':
|
|
641
|
+
{
|
|
642
|
+
var ar = node;
|
|
643
|
+
return ar.block ? ar.block.children : [];
|
|
644
|
+
}
|
|
645
|
+
default:
|
|
646
|
+
return [];
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
function applyMutation(action, parent, index) {
|
|
650
|
+
if (!parent) return;
|
|
651
|
+
var arr = getMutableChildArray(parent, index);
|
|
652
|
+
if (!arr) return;
|
|
653
|
+
if (action === 'remove') {
|
|
654
|
+
arr.splice(index, 1);
|
|
655
|
+
} else {
|
|
656
|
+
var n = Array.isArray(action.node) ? action.node : [action.node];
|
|
657
|
+
arr.splice.apply(arr, [index, 1].concat(_toConsumableArray(n)));
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
function getMutableChildArray(parent, index) {
|
|
661
|
+
switch (parent.type) {
|
|
662
|
+
case 'stylesheet':
|
|
663
|
+
return parent.children;
|
|
664
|
+
case 'rule':
|
|
665
|
+
{
|
|
666
|
+
var r = parent;
|
|
667
|
+
// index < declarations.length → declaration, else → nested child
|
|
668
|
+
if (index < r.declarations.length) return r.declarations;
|
|
669
|
+
if (r.children) return r.children;
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
case 'atrule':
|
|
673
|
+
{
|
|
674
|
+
var ar = parent;
|
|
675
|
+
return ar.block ? ar.block.children : null;
|
|
676
|
+
}
|
|
677
|
+
default:
|
|
678
|
+
return null;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// ─── Charcode constants (avoids string allocation on hot paths) ───────────────
|
|
683
|
+
var CC_TAB = 9,
|
|
684
|
+
CC_LF = 10,
|
|
685
|
+
CC_CR = 13,
|
|
686
|
+
CC_FF = 12,
|
|
687
|
+
CC_SPACE = 32;
|
|
688
|
+
var CC_DQUOTE = 34,
|
|
689
|
+
CC_HASH = 35,
|
|
690
|
+
CC_AMP = 38,
|
|
691
|
+
CC_SQUOTE = 39;
|
|
692
|
+
var CC_LPAREN = 40,
|
|
693
|
+
CC_RPAREN = 41,
|
|
694
|
+
CC_STAR = 42,
|
|
695
|
+
CC_PLUS = 43;
|
|
696
|
+
var CC_COMMA = 44,
|
|
697
|
+
CC_MINUS = 45,
|
|
698
|
+
CC_DOT = 46,
|
|
699
|
+
CC_SLASH = 47;
|
|
700
|
+
var CC_COLON = 58,
|
|
701
|
+
CC_SEMI = 59,
|
|
702
|
+
CC_GT = 62;
|
|
703
|
+
var CC_AT = 64,
|
|
704
|
+
CC_LBRACK = 91,
|
|
705
|
+
CC_BSLASH = 92,
|
|
706
|
+
CC_RBRACK = 93;
|
|
707
|
+
var CC_UNDER = 95,
|
|
708
|
+
CC_LBRACE = 123,
|
|
709
|
+
CC_RBRACE = 125,
|
|
710
|
+
CC_TILDE = 126;
|
|
711
|
+
|
|
712
|
+
// ─── Character predicates (charcode-based, no regex) ─────────────────────────
|
|
713
|
+
|
|
714
|
+
function isWS(c) {
|
|
715
|
+
return c === CC_SPACE || c === CC_TAB || c === CC_LF || c === CC_CR || c === CC_FF;
|
|
716
|
+
}
|
|
717
|
+
function isDigit(c) {
|
|
718
|
+
return c >= 48 && c <= 57;
|
|
719
|
+
}
|
|
720
|
+
function isAlpha(c) {
|
|
721
|
+
return c >= 65 && c <= 90 || c >= 97 && c <= 122;
|
|
722
|
+
}
|
|
723
|
+
function isHex(c) {
|
|
724
|
+
return isDigit(c) || c >= 65 && c <= 70 || c >= 97 && c <= 102;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* CSS ident-start: letter | underscore | non-ASCII | hyphen.
|
|
728
|
+
* A leading hyphen is valid (vendor prefixes, custom properties).
|
|
729
|
+
*/
|
|
730
|
+
function isNameStart(c) {
|
|
731
|
+
return isAlpha(c) || c === CC_UNDER || c === CC_MINUS || c > 127;
|
|
732
|
+
}
|
|
733
|
+
/** CSS ident-char: ident-start | digit */
|
|
734
|
+
function isNameChar(c) {
|
|
735
|
+
return isAlpha(c) || isDigit(c) || c === CC_UNDER || c === CC_MINUS || c > 127;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// ─── Block context ────────────────────────────────────────────────────────────
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Determines what may legally appear inside a block:
|
|
742
|
+
* stylesheet – top-level: rules + at-rules
|
|
743
|
+
* mixed – @media/@supports/@container/@layer: rules + at-rules
|
|
744
|
+
* rule – inside a style rule: declarations + optional CSS nesting
|
|
745
|
+
* keyframes – inside @keyframes: keyframe stops (from/to/%)
|
|
746
|
+
* declarations– @font-face/@page/etc.: declarations only
|
|
747
|
+
*/
|
|
748
|
+
|
|
749
|
+
// ─── CssParser ────────────────────────────────────────────────────────────────
|
|
750
|
+
|
|
751
|
+
var CssParser = /*#__PURE__*/function () {
|
|
752
|
+
function CssParser() {
|
|
753
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
754
|
+
_classCallCheck(this, CssParser);
|
|
755
|
+
_defineProperty(this, "input", '');
|
|
756
|
+
_defineProperty(this, "pos", 0);
|
|
757
|
+
_defineProperty(this, "length", 0);
|
|
758
|
+
_defineProperty(this, "line", 1);
|
|
759
|
+
_defineProperty(this, "col", 1);
|
|
760
|
+
_defineProperty(this, "errors", []);
|
|
761
|
+
_defineProperty(this, "warnings", []);
|
|
762
|
+
_defineProperty(this, "stats", CssParser.emptyStats());
|
|
763
|
+
this.options = _objectSpread2({
|
|
764
|
+
parseAtrulePrelude: true,
|
|
765
|
+
parseValue: true,
|
|
766
|
+
parseCustomProperty: true,
|
|
767
|
+
parseRulePrelude: true,
|
|
768
|
+
parseSelector: true,
|
|
769
|
+
includeComments: true,
|
|
770
|
+
includeSourceMaps: true,
|
|
771
|
+
includeSpecificity: true,
|
|
772
|
+
includeVendorPrefixes: true,
|
|
773
|
+
onError: function onError() {/* noop */},
|
|
774
|
+
onWarning: function onWarning() {/* noop */},
|
|
775
|
+
maxDepth: 100,
|
|
776
|
+
maxNodes: 100000,
|
|
777
|
+
enableNesting: true,
|
|
778
|
+
enableCustomProperties: true,
|
|
779
|
+
enableLogicalProperties: true,
|
|
780
|
+
enableContainerQueries: true,
|
|
781
|
+
enableLayerQueries: true,
|
|
782
|
+
enableSupportsQueries: true,
|
|
783
|
+
// middleware — undefined by default (fast path skips them)
|
|
784
|
+
onRule: undefined,
|
|
785
|
+
onAtRule: undefined,
|
|
786
|
+
onDeclaration: undefined,
|
|
787
|
+
onComment: undefined,
|
|
788
|
+
onKeyframe: undefined
|
|
789
|
+
}, options);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// ── Public API ────────────────────────────────────────────────────────────
|
|
793
|
+
return _createClass(CssParser, [{
|
|
794
|
+
key: "parse",
|
|
795
|
+
value: function parse(css) {
|
|
796
|
+
var t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
797
|
+
this.reset(css);
|
|
798
|
+
var sheet = this.parseStylesheet();
|
|
799
|
+
this.stats.parseTime = (typeof performance !== 'undefined' ? performance.now() : Date.now()) - t0;
|
|
800
|
+
return sheet;
|
|
801
|
+
}
|
|
802
|
+
}, {
|
|
803
|
+
key: "getErrors",
|
|
804
|
+
value: function getErrors() {
|
|
805
|
+
return _toConsumableArray(this.errors);
|
|
806
|
+
}
|
|
807
|
+
}, {
|
|
808
|
+
key: "getWarnings",
|
|
809
|
+
value: function getWarnings() {
|
|
810
|
+
return _toConsumableArray(this.warnings);
|
|
811
|
+
}
|
|
812
|
+
}, {
|
|
813
|
+
key: "getStats",
|
|
814
|
+
value: function getStats() {
|
|
815
|
+
return _objectSpread2({}, this.stats);
|
|
816
|
+
}
|
|
817
|
+
}, {
|
|
818
|
+
key: "toLegacyFormat",
|
|
819
|
+
value: function toLegacyFormat(stylesheet) {
|
|
820
|
+
var _this = this;
|
|
821
|
+
return stylesheet.children.map(function (c) {
|
|
822
|
+
return _this.toLegacyNode(c);
|
|
823
|
+
}).filter(Boolean);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
// ── Reset ─────────────────────────────────────────────────────────────────
|
|
827
|
+
}, {
|
|
828
|
+
key: "reset",
|
|
829
|
+
value: function reset(css) {
|
|
830
|
+
this.input = css;
|
|
831
|
+
this.pos = 0;
|
|
832
|
+
this.length = css.length;
|
|
833
|
+
this.line = 1;
|
|
834
|
+
this.col = 1;
|
|
835
|
+
this.errors = [];
|
|
836
|
+
this.warnings = [];
|
|
837
|
+
this.stats = CssParser.emptyStats();
|
|
838
|
+
}
|
|
839
|
+
}, {
|
|
840
|
+
key: "parseStylesheet",
|
|
841
|
+
value:
|
|
842
|
+
// ── Stylesheet ────────────────────────────────────────────────────────────
|
|
843
|
+
|
|
844
|
+
function parseStylesheet() {
|
|
845
|
+
var locStart = this.locPos();
|
|
846
|
+
var ss = {
|
|
847
|
+
type: 'stylesheet',
|
|
848
|
+
source: this.input,
|
|
849
|
+
children: [],
|
|
850
|
+
charset: undefined,
|
|
851
|
+
imports: [],
|
|
852
|
+
namespaces: [],
|
|
853
|
+
mediaQueries: [],
|
|
854
|
+
keyframes: [],
|
|
855
|
+
fontFaces: [],
|
|
856
|
+
layers: [],
|
|
857
|
+
containers: [],
|
|
858
|
+
supports: [],
|
|
859
|
+
documents: [],
|
|
860
|
+
pages: [],
|
|
861
|
+
counterStyles: [],
|
|
862
|
+
fontFeatureValues: [],
|
|
863
|
+
viewports: [],
|
|
864
|
+
charsets: []
|
|
865
|
+
};
|
|
866
|
+
while (this.pos < this.length) {
|
|
867
|
+
this.skipWS();
|
|
868
|
+
if (this.pos >= this.length) break;
|
|
869
|
+
var node = this.parseTopNode();
|
|
870
|
+
if (node) {
|
|
871
|
+
ss.children.push(node);
|
|
872
|
+
this.categorize(ss, node);
|
|
873
|
+
this.stats.totalNodes++;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
if (this.options.includeSourceMaps) {
|
|
877
|
+
ss.loc = {
|
|
878
|
+
start: locStart,
|
|
879
|
+
end: this.locPos(),
|
|
880
|
+
source: this.input
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
return ss;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// ── Top-level node dispatch ───────────────────────────────────────────────
|
|
887
|
+
}, {
|
|
888
|
+
key: "parseTopNode",
|
|
889
|
+
value: function parseTopNode() {
|
|
890
|
+
var c = this.peek();
|
|
891
|
+
if (c === CC_SLASH && this.peek(1) === CC_STAR) {
|
|
892
|
+
var comment = this.parseComment();
|
|
893
|
+
return this.options.includeComments ? comment : null;
|
|
894
|
+
}
|
|
895
|
+
if (c === CC_AT) return this.parseAtRule();
|
|
896
|
+
// Skip stray closing braces that can appear in malformed CSS
|
|
897
|
+
if (c === CC_RBRACE) {
|
|
898
|
+
this.advance();
|
|
899
|
+
return null;
|
|
900
|
+
}
|
|
901
|
+
return this.parseRule();
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// ── Block-level node dispatch ─────────────────────────────────────────────
|
|
905
|
+
}, {
|
|
906
|
+
key: "parseBlockNode",
|
|
907
|
+
value: function parseBlockNode(mode) {
|
|
908
|
+
this.skipWS();
|
|
909
|
+
if (this.pos >= this.length || this.peek() === CC_RBRACE) return null;
|
|
910
|
+
var c = this.peek();
|
|
911
|
+
if (c === CC_SLASH && this.peek(1) === CC_STAR) {
|
|
912
|
+
var comment = this.parseComment();
|
|
913
|
+
return this.options.includeComments ? comment : null;
|
|
914
|
+
}
|
|
915
|
+
if (c === CC_AT) return this.parseAtRule();
|
|
916
|
+
switch (mode) {
|
|
917
|
+
case 'keyframes':
|
|
918
|
+
return this.parseKeyframeStop();
|
|
919
|
+
case 'declarations':
|
|
920
|
+
return this.parseDeclaration();
|
|
921
|
+
case 'mixed':
|
|
922
|
+
case 'stylesheet':
|
|
923
|
+
if (c === CC_RBRACE) return null;
|
|
924
|
+
return this.parseRule();
|
|
925
|
+
case 'rule':
|
|
926
|
+
default:
|
|
927
|
+
// Unambiguous nesting-selector starters
|
|
928
|
+
if (this.isNestingStart(c)) return this.parseRule();
|
|
929
|
+
// Lookahead: first unescaped { at depth 0 → rule, ; or } → declaration
|
|
930
|
+
if (this.lookaheadIsRule()) return this.parseRule();
|
|
931
|
+
// console.log('parse block', c, mode);
|
|
932
|
+
return this.parseDeclaration();
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// ── At-rule ───────────────────────────────────────────────────────────────
|
|
937
|
+
}, {
|
|
938
|
+
key: "parseAtRule",
|
|
939
|
+
value: function parseAtRule() {
|
|
940
|
+
if (this.peek() !== CC_AT) return null;
|
|
941
|
+
var locStart = this.locPos();
|
|
942
|
+
this.advance(); // '@'
|
|
943
|
+
|
|
944
|
+
var name = this.readIdent();
|
|
945
|
+
if (!name) {
|
|
946
|
+
this.recoverPast(CC_SEMI, CC_RBRACE);
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
949
|
+
this.skipWS();
|
|
950
|
+
var preludeText = this.readPrelude();
|
|
951
|
+
this.skipWS();
|
|
952
|
+
var baseName = name.replace(/^-(webkit|moz|ms|o)-/, '');
|
|
953
|
+
var ar = {
|
|
954
|
+
type: 'atrule',
|
|
955
|
+
name: name,
|
|
956
|
+
preludeText: preludeText,
|
|
957
|
+
prelude: this.options.parseAtrulePrelude ? this.tokenizeValue(preludeText) : []
|
|
958
|
+
};
|
|
959
|
+
if (this.options.includeVendorPrefixes) {
|
|
960
|
+
var vp = name.match(/^-(webkit|moz|ms|o)-/);
|
|
961
|
+
if (vp) ar.vendorPrefix = vp[0];
|
|
962
|
+
}
|
|
963
|
+
if (this.peek() === CC_LBRACE) {
|
|
964
|
+
var mode = this.modeForAtRule(baseName);
|
|
965
|
+
var blockStart = this.locPos();
|
|
966
|
+
var children = this.parseBlockChildren(mode);
|
|
967
|
+
var blockEnd = this.locPos();
|
|
968
|
+
ar.block = _objectSpread2({
|
|
969
|
+
type: 'block',
|
|
970
|
+
children: children
|
|
971
|
+
}, this.options.includeSourceMaps ? {
|
|
972
|
+
loc: {
|
|
973
|
+
start: blockStart,
|
|
974
|
+
end: blockEnd
|
|
975
|
+
}
|
|
976
|
+
} : {});
|
|
977
|
+
|
|
978
|
+
// Populate keyframes shortcut
|
|
979
|
+
if (baseName === 'keyframes') {
|
|
980
|
+
ar.keyframes = children.filter(function (n) {
|
|
981
|
+
return n.type === 'keyframe';
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
} else if (this.peek() === CC_SEMI) {
|
|
985
|
+
this.advance();
|
|
986
|
+
}
|
|
987
|
+
this.stats.totalAtRules++;
|
|
988
|
+
if (this.options.includeSourceMaps) {
|
|
989
|
+
ar.loc = {
|
|
990
|
+
start: locStart,
|
|
991
|
+
end: this.locPos(),
|
|
992
|
+
source: this.input
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
if (this.options.onAtRule) {
|
|
996
|
+
var result = this.options.onAtRule(ar);
|
|
997
|
+
if (result === null) return null;
|
|
998
|
+
if (result) return result;
|
|
999
|
+
}
|
|
1000
|
+
return ar;
|
|
1001
|
+
}
|
|
1002
|
+
}, {
|
|
1003
|
+
key: "modeForAtRule",
|
|
1004
|
+
value: function modeForAtRule(baseName) {
|
|
1005
|
+
// AWC encodes comments as @comment-XXXXXXXX { --rule-...: "..."; }
|
|
1006
|
+
// which contain only declarations — must NOT use mixed/rule mode or
|
|
1007
|
+
// readUntilLBrace() will consume past the closing } and corrupt state.
|
|
1008
|
+
if (baseName.startsWith('comment')) return 'declarations';
|
|
1009
|
+
switch (baseName) {
|
|
1010
|
+
case 'keyframes':
|
|
1011
|
+
return 'keyframes';
|
|
1012
|
+
case 'font-face':
|
|
1013
|
+
case 'page':
|
|
1014
|
+
case 'counter-style':
|
|
1015
|
+
case 'viewport':
|
|
1016
|
+
case 'theme':
|
|
1017
|
+
case 'utility':
|
|
1018
|
+
return 'declarations';
|
|
1019
|
+
case 'media':
|
|
1020
|
+
case 'supports':
|
|
1021
|
+
case 'container':
|
|
1022
|
+
case 'layer':
|
|
1023
|
+
case 'document':
|
|
1024
|
+
default:
|
|
1025
|
+
return 'mixed';
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
// ── Regular rule ──────────────────────────────────────────────────────────
|
|
1030
|
+
}, {
|
|
1031
|
+
key: "parseRule",
|
|
1032
|
+
value: function parseRule() {
|
|
1033
|
+
var locStart = this.locPos();
|
|
1034
|
+
var rawSelector = this.readUntilLBrace().trim();
|
|
1035
|
+
if (!rawSelector || this.peek() !== CC_LBRACE) {
|
|
1036
|
+
// Malformed — skip to closing brace
|
|
1037
|
+
if (this.peek() === CC_LBRACE) {
|
|
1038
|
+
this.skipBalancedBraces();
|
|
1039
|
+
}
|
|
1040
|
+
return null;
|
|
1041
|
+
}
|
|
1042
|
+
var mode = this.options.enableNesting ? 'rule' : 'declarations';
|
|
1043
|
+
var children = this.parseBlockChildren(mode);
|
|
1044
|
+
var declarations = [];
|
|
1045
|
+
var nested = [];
|
|
1046
|
+
var _iterator = _createForOfIteratorHelper(children),
|
|
1047
|
+
_step;
|
|
1048
|
+
try {
|
|
1049
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1050
|
+
var child = _step.value;
|
|
1051
|
+
var t = child.type;
|
|
1052
|
+
if (t === 'declaration') declarations.push(child);else if (t === 'rule') nested.push(child);else if (t === 'atrule') nested.push(child);
|
|
1053
|
+
}
|
|
1054
|
+
} catch (err) {
|
|
1055
|
+
_iterator.e(err);
|
|
1056
|
+
} finally {
|
|
1057
|
+
_iterator.f();
|
|
1058
|
+
}
|
|
1059
|
+
var selectors = this.parseSelectorList(rawSelector);
|
|
1060
|
+
this.stats.totalRules++;
|
|
1061
|
+
this.stats.totalSelectors += selectors.length;
|
|
1062
|
+
var rule = {
|
|
1063
|
+
type: 'rule',
|
|
1064
|
+
rawSelector: rawSelector,
|
|
1065
|
+
selectors: selectors,
|
|
1066
|
+
declarations: declarations
|
|
1067
|
+
};
|
|
1068
|
+
if (nested.length > 0) rule.children = nested;
|
|
1069
|
+
if (this.options.includeSpecificity) {
|
|
1070
|
+
rule.specificity = this.calcSpecificity(rawSelector);
|
|
1071
|
+
}
|
|
1072
|
+
if (this.options.includeSourceMaps) {
|
|
1073
|
+
rule.loc = {
|
|
1074
|
+
start: locStart,
|
|
1075
|
+
end: this.locPos(),
|
|
1076
|
+
source: this.input
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
if (this.options.onRule) {
|
|
1080
|
+
var result = this.options.onRule(rule);
|
|
1081
|
+
if (result === null) return null;
|
|
1082
|
+
if (result) return result;
|
|
1083
|
+
}
|
|
1084
|
+
return rule;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
// ── Keyframe stop (from / to / <percentage>) ──────────────────────────────
|
|
1088
|
+
}, {
|
|
1089
|
+
key: "parseKeyframeStop",
|
|
1090
|
+
value: function parseKeyframeStop() {
|
|
1091
|
+
var locStart = this.locPos();
|
|
1092
|
+
var selector = this.readUntilLBrace().trim();
|
|
1093
|
+
if (!selector || this.peek() !== CC_LBRACE) return null;
|
|
1094
|
+
var children = this.parseBlockChildren('declarations');
|
|
1095
|
+
var declarations = children.filter(function (n) {
|
|
1096
|
+
return n.type === 'declaration';
|
|
1097
|
+
});
|
|
1098
|
+
var kf = _objectSpread2({
|
|
1099
|
+
type: 'keyframe',
|
|
1100
|
+
selector: selector,
|
|
1101
|
+
declarations: declarations
|
|
1102
|
+
}, this.options.includeSourceMaps ? {
|
|
1103
|
+
loc: {
|
|
1104
|
+
start: locStart,
|
|
1105
|
+
end: this.locPos()
|
|
1106
|
+
}
|
|
1107
|
+
} : {});
|
|
1108
|
+
if (this.options.onKeyframe) {
|
|
1109
|
+
var result = this.options.onKeyframe(kf);
|
|
1110
|
+
if (result === null) return null;
|
|
1111
|
+
if (result) return result;
|
|
1112
|
+
}
|
|
1113
|
+
return kf;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// ── Block (consumes { … }) ────────────────────────────────────────────────
|
|
1117
|
+
}, {
|
|
1118
|
+
key: "parseBlockChildren",
|
|
1119
|
+
value: function parseBlockChildren(mode) {
|
|
1120
|
+
if (this.peek() !== CC_LBRACE) return [];
|
|
1121
|
+
this.advance(); // '{'
|
|
1122
|
+
|
|
1123
|
+
var children = [];
|
|
1124
|
+
while (this.pos < this.length) {
|
|
1125
|
+
this.skipWS();
|
|
1126
|
+
if (this.pos >= this.length || this.peek() === CC_RBRACE) break;
|
|
1127
|
+
var prevPos = this.pos;
|
|
1128
|
+
var node = this.parseBlockNode(mode);
|
|
1129
|
+
// Guard against infinite loop: if nothing was consumed, force-advance
|
|
1130
|
+
if (this.pos === prevPos) {
|
|
1131
|
+
this.advance();
|
|
1132
|
+
continue;
|
|
1133
|
+
}
|
|
1134
|
+
if (node) {
|
|
1135
|
+
children.push(node);
|
|
1136
|
+
this.stats.totalNodes++;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
if (this.pos < this.length && this.peek() === CC_RBRACE) this.advance(); // '}'
|
|
1140
|
+
return children;
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
// ── Declaration ───────────────────────────────────────────────────────────
|
|
1144
|
+
}, {
|
|
1145
|
+
key: "parseDeclaration",
|
|
1146
|
+
value: function parseDeclaration() {
|
|
1147
|
+
var locStart = this.locPos();
|
|
1148
|
+
|
|
1149
|
+
// Property name (supports --custom-props and -vendor-prefixed)
|
|
1150
|
+
var property = this.readIdent();
|
|
1151
|
+
if (!property) {
|
|
1152
|
+
this.recoverTo(CC_SEMI, CC_RBRACE);
|
|
1153
|
+
return null;
|
|
1154
|
+
}
|
|
1155
|
+
this.skipWS();
|
|
1156
|
+
if (this.peek() !== CC_COLON) {
|
|
1157
|
+
this.recoverTo(CC_SEMI, CC_RBRACE);
|
|
1158
|
+
return null;
|
|
1159
|
+
}
|
|
1160
|
+
this.advance(); // ':'
|
|
1161
|
+
this.skipWS();
|
|
1162
|
+
var rawFull = this.readRawValue();
|
|
1163
|
+
|
|
1164
|
+
// Strip !important
|
|
1165
|
+
var rawValue = rawFull;
|
|
1166
|
+
var important = false;
|
|
1167
|
+
var impMatch = rawFull.match(/\s*!important\s*$/i);
|
|
1168
|
+
if (impMatch) {
|
|
1169
|
+
important = true;
|
|
1170
|
+
rawValue = rawFull.slice(0, rawFull.length - impMatch[0].length).trimEnd();
|
|
1171
|
+
}
|
|
1172
|
+
this.skipWS();
|
|
1173
|
+
if (this.pos < this.length && this.peek() === CC_SEMI) this.advance();
|
|
1174
|
+
this.stats.totalDeclarations++;
|
|
1175
|
+
var decl = {
|
|
1176
|
+
type: 'declaration',
|
|
1177
|
+
property: property,
|
|
1178
|
+
rawValue: rawValue,
|
|
1179
|
+
value: this.options.parseValue ? this.tokenizeValue(rawValue) : [],
|
|
1180
|
+
important: important
|
|
1181
|
+
};
|
|
1182
|
+
if (this.options.enableCustomProperties && property.startsWith('--')) {
|
|
1183
|
+
decl.customProperty = true;
|
|
1184
|
+
}
|
|
1185
|
+
if (this.options.includeVendorPrefixes) {
|
|
1186
|
+
var vp = property.match(/^-(webkit|moz|ms|o)-/);
|
|
1187
|
+
if (vp) decl.vendorPrefix = vp[0];
|
|
1188
|
+
}
|
|
1189
|
+
if (this.options.includeSourceMaps) {
|
|
1190
|
+
decl.loc = {
|
|
1191
|
+
start: locStart,
|
|
1192
|
+
end: this.locPos(),
|
|
1193
|
+
source: this.input
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
if (this.options.onDeclaration) {
|
|
1197
|
+
var result = this.options.onDeclaration(decl);
|
|
1198
|
+
if (result === null) return null;
|
|
1199
|
+
if (result) return result;
|
|
1200
|
+
}
|
|
1201
|
+
return decl;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
// ── Comment ───────────────────────────────────────────────────────────────
|
|
1205
|
+
}, {
|
|
1206
|
+
key: "parseComment",
|
|
1207
|
+
value: function parseComment() {
|
|
1208
|
+
var locStart = this.locPos();
|
|
1209
|
+
this.advance(); // '/'
|
|
1210
|
+
this.advance(); // '*'
|
|
1211
|
+
var start = this.pos;
|
|
1212
|
+
while (this.pos < this.length - 1) {
|
|
1213
|
+
if (this.peek() === CC_STAR && this.peek(1) === CC_SLASH) {
|
|
1214
|
+
var _value = this.input.slice(start, this.pos);
|
|
1215
|
+
this.advance();
|
|
1216
|
+
this.advance(); // '*/'
|
|
1217
|
+
this.stats.totalComments++;
|
|
1218
|
+
var _c = _objectSpread2({
|
|
1219
|
+
type: 'comment',
|
|
1220
|
+
value: _value,
|
|
1221
|
+
style: _value.includes('\n') ? 'multi-line' : 'single-line'
|
|
1222
|
+
}, this.options.includeSourceMaps ? {
|
|
1223
|
+
loc: {
|
|
1224
|
+
start: locStart,
|
|
1225
|
+
end: this.locPos()
|
|
1226
|
+
}
|
|
1227
|
+
} : {});
|
|
1228
|
+
if (this.options.onComment) {
|
|
1229
|
+
var result = this.options.onComment(_c);
|
|
1230
|
+
if (result === null) return null;
|
|
1231
|
+
if (result) return result;
|
|
1232
|
+
}
|
|
1233
|
+
return _c;
|
|
1234
|
+
}
|
|
1235
|
+
this.advance();
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
// Unterminated comment
|
|
1239
|
+
var value = this.input.slice(start);
|
|
1240
|
+
this.pos = this.length;
|
|
1241
|
+
this.stats.totalComments++;
|
|
1242
|
+
var c = {
|
|
1243
|
+
type: 'comment',
|
|
1244
|
+
value: value,
|
|
1245
|
+
style: 'multi-line'
|
|
1246
|
+
};
|
|
1247
|
+
if (this.options.onComment) {
|
|
1248
|
+
var _result = this.options.onComment(c);
|
|
1249
|
+
if (_result === null) return null;
|
|
1250
|
+
if (_result) return _result;
|
|
1251
|
+
}
|
|
1252
|
+
return c;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
// ── Selectors ─────────────────────────────────────────────────────────────
|
|
1256
|
+
|
|
1257
|
+
/**
|
|
1258
|
+
* Splits a raw selector string on commas (respecting parentheses depth)
|
|
1259
|
+
* and returns one CssSelector per part.
|
|
1260
|
+
*/
|
|
1261
|
+
}, {
|
|
1262
|
+
key: "parseSelectorList",
|
|
1263
|
+
value: function parseSelectorList(raw) {
|
|
1264
|
+
var parts = [];
|
|
1265
|
+
var depth = 0,
|
|
1266
|
+
start = 0;
|
|
1267
|
+
for (var i = 0; i < raw.length; i++) {
|
|
1268
|
+
var c = raw.charCodeAt(i);
|
|
1269
|
+
if (c === CC_LPAREN || c === CC_LBRACK) depth++;else if (c === CC_RPAREN || c === CC_RBRACK) depth--;else if (c === CC_COMMA && depth === 0) {
|
|
1270
|
+
parts.push(raw.slice(start, i).trim());
|
|
1271
|
+
start = i + 1;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
parts.push(raw.slice(start).trim());
|
|
1275
|
+
return parts.filter(function (p) {
|
|
1276
|
+
return p.length > 0;
|
|
1277
|
+
}).map(function (p) {
|
|
1278
|
+
return {
|
|
1279
|
+
type: 'selector',
|
|
1280
|
+
value: p
|
|
1281
|
+
};
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
/**
|
|
1286
|
+
* Simple specificity scorer — counts IDs, classes/attributes/pseudos, elements.
|
|
1287
|
+
*/
|
|
1288
|
+
}, {
|
|
1289
|
+
key: "calcSpecificity",
|
|
1290
|
+
value: function calcSpecificity(sel) {
|
|
1291
|
+
var ids = 0,
|
|
1292
|
+
classes = 0,
|
|
1293
|
+
elements = 0;
|
|
1294
|
+
var i = 0;
|
|
1295
|
+
while (i < sel.length) {
|
|
1296
|
+
var c = sel.charCodeAt(i);
|
|
1297
|
+
if (c === CC_HASH) {
|
|
1298
|
+
ids++;
|
|
1299
|
+
i++;
|
|
1300
|
+
while (i < sel.length && isNameChar(sel.charCodeAt(i))) i++;
|
|
1301
|
+
} else if (c === CC_DOT) {
|
|
1302
|
+
classes++;
|
|
1303
|
+
i++;
|
|
1304
|
+
while (i < sel.length && isNameChar(sel.charCodeAt(i))) i++;
|
|
1305
|
+
} else if (c === CC_LBRACK) {
|
|
1306
|
+
classes++;
|
|
1307
|
+
while (i < sel.length && sel.charCodeAt(i) !== CC_RBRACK) i++;
|
|
1308
|
+
i++;
|
|
1309
|
+
} else if (c === CC_COLON) {
|
|
1310
|
+
if (sel.charCodeAt(i + 1) === CC_COLON) {
|
|
1311
|
+
elements++;
|
|
1312
|
+
i += 2;
|
|
1313
|
+
} else {
|
|
1314
|
+
// :not(), :is(), :has() — don't double-count the wrapper
|
|
1315
|
+
classes++;
|
|
1316
|
+
i++;
|
|
1317
|
+
}
|
|
1318
|
+
while (i < sel.length && isNameChar(sel.charCodeAt(i))) i++;
|
|
1319
|
+
// skip argument parens
|
|
1320
|
+
if (i < sel.length && sel.charCodeAt(i) === CC_LPAREN) {
|
|
1321
|
+
var d = 1;
|
|
1322
|
+
i++;
|
|
1323
|
+
while (i < sel.length && d > 0) {
|
|
1324
|
+
if (sel.charCodeAt(i) === CC_LPAREN) d++;else if (sel.charCodeAt(i) === CC_RPAREN) d--;
|
|
1325
|
+
i++;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
} else if (isAlpha(c) || c === CC_UNDER) {
|
|
1329
|
+
elements++;
|
|
1330
|
+
while (i < sel.length && isNameChar(sel.charCodeAt(i))) i++;
|
|
1331
|
+
} else {
|
|
1332
|
+
i++;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
return {
|
|
1336
|
+
ids: ids,
|
|
1337
|
+
classes: classes,
|
|
1338
|
+
elements: elements,
|
|
1339
|
+
total: ids * 100 + classes * 10 + elements
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// ── Value tokenizer ───────────────────────────────────────────────────────
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* Tokenises a raw CSS value string into a flat array of CssValue tokens.
|
|
1347
|
+
* Handles: strings, colors (#hex), numbers/dimensions/percentages,
|
|
1348
|
+
* functions (recursive), identifiers, operators, commas.
|
|
1349
|
+
*/
|
|
1350
|
+
}, {
|
|
1351
|
+
key: "tokenizeValue",
|
|
1352
|
+
value: function tokenizeValue(raw) {
|
|
1353
|
+
var tokens = [];
|
|
1354
|
+
var i = 0;
|
|
1355
|
+
var len = raw.length;
|
|
1356
|
+
while (i < len) {
|
|
1357
|
+
var c = raw.charCodeAt(i);
|
|
1358
|
+
|
|
1359
|
+
// Whitespace — skip (no whitespace tokens)
|
|
1360
|
+
if (isWS(c)) {
|
|
1361
|
+
i++;
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
// Quoted string
|
|
1366
|
+
if (c === CC_DQUOTE || c === CC_SQUOTE) {
|
|
1367
|
+
var q = c;
|
|
1368
|
+
i++;
|
|
1369
|
+
var s = i;
|
|
1370
|
+
while (i < len && raw.charCodeAt(i) !== q) {
|
|
1371
|
+
if (raw.charCodeAt(i) === CC_BSLASH) i++;
|
|
1372
|
+
i++;
|
|
1373
|
+
}
|
|
1374
|
+
tokens.push({
|
|
1375
|
+
type: 'string',
|
|
1376
|
+
value: raw.slice(s, i)
|
|
1377
|
+
});
|
|
1378
|
+
i++; // closing quote
|
|
1379
|
+
continue;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
// Hex color (#rrggbb / #rgb / #rrggbbaa / #rgba)
|
|
1383
|
+
if (c === CC_HASH) {
|
|
1384
|
+
var _s = i++;
|
|
1385
|
+
while (i < len && isHex(raw.charCodeAt(i))) i++;
|
|
1386
|
+
tokens.push({
|
|
1387
|
+
type: 'color',
|
|
1388
|
+
value: raw.slice(_s, i)
|
|
1389
|
+
});
|
|
1390
|
+
continue;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
// Number / dimension / percentage
|
|
1394
|
+
// Handles: 10, 1.5, .5, 1e3, +10px, -2em, 50%
|
|
1395
|
+
var isNumStart = isDigit(c) || c === CC_DOT && isDigit(raw.charCodeAt(i + 1)) || (c === CC_PLUS || c === CC_MINUS) && (isDigit(raw.charCodeAt(i + 1)) || raw.charCodeAt(i + 1) === CC_DOT && isDigit(raw.charCodeAt(i + 2)));
|
|
1396
|
+
if (isNumStart) {
|
|
1397
|
+
var _s2 = i;
|
|
1398
|
+
if (c === CC_PLUS || c === CC_MINUS) i++;
|
|
1399
|
+
while (i < len && isDigit(raw.charCodeAt(i))) i++;
|
|
1400
|
+
if (i < len && raw.charCodeAt(i) === CC_DOT) {
|
|
1401
|
+
i++;
|
|
1402
|
+
while (i < len && isDigit(raw.charCodeAt(i))) i++;
|
|
1403
|
+
}
|
|
1404
|
+
// Exponent
|
|
1405
|
+
if (i < len && (raw.charCodeAt(i) === 101 || raw.charCodeAt(i) === 69)) {
|
|
1406
|
+
i++;
|
|
1407
|
+
if (i < len && (raw.charCodeAt(i) === CC_PLUS || raw.charCodeAt(i) === CC_MINUS)) i++;
|
|
1408
|
+
while (i < len && isDigit(raw.charCodeAt(i))) i++;
|
|
1409
|
+
}
|
|
1410
|
+
var num = parseFloat(raw.slice(_s2, i));
|
|
1411
|
+
// Unit / percentage
|
|
1412
|
+
var us = i;
|
|
1413
|
+
while (i < len && (isAlpha(raw.charCodeAt(i)) || raw.charCodeAt(i) === CC_UNDER)) i++;
|
|
1414
|
+
if (i < len && raw[i] === '%') i++;
|
|
1415
|
+
var unit = raw.slice(us, i);
|
|
1416
|
+
if (unit === '%') tokens.push({
|
|
1417
|
+
type: 'percentage',
|
|
1418
|
+
value: num
|
|
1419
|
+
});else if (unit) tokens.push({
|
|
1420
|
+
type: 'dimension',
|
|
1421
|
+
value: num,
|
|
1422
|
+
unit: unit
|
|
1423
|
+
});else tokens.push({
|
|
1424
|
+
type: 'number',
|
|
1425
|
+
value: num
|
|
1426
|
+
});
|
|
1427
|
+
continue;
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
// Identifier or function call
|
|
1431
|
+
if (isNameStart(c)) {
|
|
1432
|
+
var _s3 = i;
|
|
1433
|
+
while (i < len && isNameChar(raw.charCodeAt(i))) i++;
|
|
1434
|
+
var name = raw.slice(_s3, i);
|
|
1435
|
+
if (i < len && raw.charCodeAt(i) === CC_LPAREN) {
|
|
1436
|
+
i++; // '('
|
|
1437
|
+
var as_ = i;
|
|
1438
|
+
var depth = 1;
|
|
1439
|
+
while (i < len && depth > 0) {
|
|
1440
|
+
var ch = raw.charCodeAt(i);
|
|
1441
|
+
if (ch === CC_LPAREN) depth++;else if (ch === CC_RPAREN) depth--;
|
|
1442
|
+
i++;
|
|
1443
|
+
}
|
|
1444
|
+
var argStr = raw.slice(as_, i - 1);
|
|
1445
|
+
var args = name.toLowerCase() === 'url' ? [{
|
|
1446
|
+
type: 'string',
|
|
1447
|
+
value: argStr.replace(/^['"]|['"]$/g, '')
|
|
1448
|
+
}] : this.tokenizeValue(argStr);
|
|
1449
|
+
tokens.push({
|
|
1450
|
+
type: 'function',
|
|
1451
|
+
name: name,
|
|
1452
|
+
value: "".concat(name, "(").concat(argStr, ")"),
|
|
1453
|
+
args: args
|
|
1454
|
+
});
|
|
1455
|
+
} else {
|
|
1456
|
+
tokens.push({
|
|
1457
|
+
type: 'identifier',
|
|
1458
|
+
value: name
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
continue;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// Comma
|
|
1465
|
+
if (c === CC_COMMA) {
|
|
1466
|
+
tokens.push({
|
|
1467
|
+
type: 'comma',
|
|
1468
|
+
value: ','
|
|
1469
|
+
});
|
|
1470
|
+
i++;
|
|
1471
|
+
continue;
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
// Operator or any other character
|
|
1475
|
+
tokens.push({
|
|
1476
|
+
type: 'operator',
|
|
1477
|
+
value: raw[i]
|
|
1478
|
+
});
|
|
1479
|
+
i++;
|
|
1480
|
+
}
|
|
1481
|
+
this.stats.totalValues += tokens.length;
|
|
1482
|
+
return tokens;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// ── Scanner primitives ────────────────────────────────────────────────────
|
|
1486
|
+
}, {
|
|
1487
|
+
key: "peek",
|
|
1488
|
+
value: function peek() {
|
|
1489
|
+
var offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
1490
|
+
return this.input.charCodeAt(this.pos + offset);
|
|
1491
|
+
}
|
|
1492
|
+
}, {
|
|
1493
|
+
key: "advance",
|
|
1494
|
+
value: function advance() {
|
|
1495
|
+
if (this.pos < this.length) {
|
|
1496
|
+
if (this.input.charCodeAt(this.pos) === CC_LF) {
|
|
1497
|
+
this.line++;
|
|
1498
|
+
this.col = 1;
|
|
1499
|
+
} else this.col++;
|
|
1500
|
+
this.pos++;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
}, {
|
|
1504
|
+
key: "skipWS",
|
|
1505
|
+
value: function skipWS() {
|
|
1506
|
+
while (this.pos < this.length && isWS(this.peek())) this.advance();
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
/**
|
|
1510
|
+
* Read a CSS identifier (supports `--custom-props` and `-vendor-prefix`).
|
|
1511
|
+
* Returns empty string if the current position isn't the start of an ident.
|
|
1512
|
+
*/
|
|
1513
|
+
}, {
|
|
1514
|
+
key: "readIdent",
|
|
1515
|
+
value: function readIdent() {
|
|
1516
|
+
if (this.pos >= this.length) return '';
|
|
1517
|
+
var c = this.peek();
|
|
1518
|
+
// Allow backslash-escape as a valid ident start (e.g. \/ in custom props)
|
|
1519
|
+
if (!isNameStart(c) && c !== CC_BSLASH) return '';
|
|
1520
|
+
var start = this.pos;
|
|
1521
|
+
while (this.pos < this.length) {
|
|
1522
|
+
var ch = this.peek();
|
|
1523
|
+
if (ch === CC_BSLASH) {
|
|
1524
|
+
// CSS escape sequence: consume backslash + following char/codepoint
|
|
1525
|
+
// Preserve raw text (including the backslash) so the generator
|
|
1526
|
+
// can emit valid CSS unchanged.
|
|
1527
|
+
this.advance(); // consume '\'
|
|
1528
|
+
if (this.pos >= this.length) break;
|
|
1529
|
+
var next = this.peek();
|
|
1530
|
+
if (isHex(next)) {
|
|
1531
|
+
// 1–6 hex digits
|
|
1532
|
+
var hexLen = 0;
|
|
1533
|
+
while (this.pos < this.length && isHex(this.peek()) && hexLen < 6) {
|
|
1534
|
+
this.advance();
|
|
1535
|
+
hexLen++;
|
|
1536
|
+
}
|
|
1537
|
+
// optional single whitespace after hex escape
|
|
1538
|
+
if (this.pos < this.length && isWS(this.peek())) this.advance();
|
|
1539
|
+
} else if (next === CC_LF || next === CC_CR || next === CC_FF) {
|
|
1540
|
+
// newline inside escape — skip
|
|
1541
|
+
this.advance();
|
|
1542
|
+
} else {
|
|
1543
|
+
// e.g. \/ — consume the escaped character
|
|
1544
|
+
this.advance();
|
|
1545
|
+
}
|
|
1546
|
+
} else if (isNameChar(ch)) {
|
|
1547
|
+
this.advance();
|
|
1548
|
+
} else {
|
|
1549
|
+
break;
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
return this.input.slice(start, this.pos);
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* Read at-rule prelude: raw text from current position up to (but not
|
|
1557
|
+
* including) the next `{` or `;` at depth 0.
|
|
1558
|
+
* Parentheses, brackets, strings and comments are respected.
|
|
1559
|
+
*/
|
|
1560
|
+
}, {
|
|
1561
|
+
key: "readPrelude",
|
|
1562
|
+
value: function readPrelude() {
|
|
1563
|
+
var start = this.pos;
|
|
1564
|
+
var depth = 0;
|
|
1565
|
+
while (this.pos < this.length) {
|
|
1566
|
+
var c = this.peek();
|
|
1567
|
+
if (c === CC_DQUOTE || c === CC_SQUOTE) {
|
|
1568
|
+
this.skipString(c);
|
|
1569
|
+
continue;
|
|
1570
|
+
}
|
|
1571
|
+
if (c === CC_SLASH && this.peek(1) === CC_STAR) {
|
|
1572
|
+
this.skipMLComment();
|
|
1573
|
+
continue;
|
|
1574
|
+
}
|
|
1575
|
+
if (c === CC_LPAREN || c === CC_LBRACK) {
|
|
1576
|
+
depth++;
|
|
1577
|
+
this.advance();
|
|
1578
|
+
continue;
|
|
1579
|
+
}
|
|
1580
|
+
if (c === CC_RPAREN || c === CC_RBRACK) {
|
|
1581
|
+
depth--;
|
|
1582
|
+
this.advance();
|
|
1583
|
+
continue;
|
|
1584
|
+
}
|
|
1585
|
+
if (depth === 0 && (c === CC_LBRACE || c === CC_SEMI)) break;
|
|
1586
|
+
this.advance();
|
|
1587
|
+
}
|
|
1588
|
+
return this.input.slice(start, this.pos).trim();
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
/**
|
|
1592
|
+
* Read a declaration value: raw text up to `;` or `}` at depth 0.
|
|
1593
|
+
*/
|
|
1594
|
+
}, {
|
|
1595
|
+
key: "readRawValue",
|
|
1596
|
+
value: function readRawValue() {
|
|
1597
|
+
var start = this.pos;
|
|
1598
|
+
var depth = 0;
|
|
1599
|
+
while (this.pos < this.length) {
|
|
1600
|
+
var c = this.peek();
|
|
1601
|
+
// Backslash escape: consume '\' + next char as a unit.
|
|
1602
|
+
// This prevents '\"' from being misread as a string delimiter,
|
|
1603
|
+
// '\;' from prematurely terminating the value, and '\(' from
|
|
1604
|
+
// incorrectly incrementing paren depth.
|
|
1605
|
+
if (c === CC_BSLASH) {
|
|
1606
|
+
this.advance(); // consume '\'
|
|
1607
|
+
if (this.pos < this.length) this.advance(); // consume escaped char
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1610
|
+
if (c === CC_DQUOTE || c === CC_SQUOTE) {
|
|
1611
|
+
this.skipString(c);
|
|
1612
|
+
continue;
|
|
1613
|
+
}
|
|
1614
|
+
if (c === CC_SLASH && this.peek(1) === CC_STAR) {
|
|
1615
|
+
this.skipMLComment();
|
|
1616
|
+
continue;
|
|
1617
|
+
}
|
|
1618
|
+
if (c === CC_LPAREN || c === CC_LBRACK) {
|
|
1619
|
+
depth++;
|
|
1620
|
+
this.advance();
|
|
1621
|
+
continue;
|
|
1622
|
+
}
|
|
1623
|
+
if (c === CC_RPAREN || c === CC_RBRACK) {
|
|
1624
|
+
depth--;
|
|
1625
|
+
this.advance();
|
|
1626
|
+
continue;
|
|
1627
|
+
}
|
|
1628
|
+
if (depth === 0 && (c === CC_SEMI || c === CC_RBRACE)) break;
|
|
1629
|
+
this.advance();
|
|
1630
|
+
}
|
|
1631
|
+
return this.input.slice(start, this.pos).trim();
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
/**
|
|
1635
|
+
* Read a selector (rule prelude): raw text up to the first `{` at depth 0.
|
|
1636
|
+
* Parentheses, brackets, strings and comments are respected.
|
|
1637
|
+
*/
|
|
1638
|
+
}, {
|
|
1639
|
+
key: "readUntilLBrace",
|
|
1640
|
+
value: function readUntilLBrace() {
|
|
1641
|
+
var start = this.pos;
|
|
1642
|
+
var depth = 0;
|
|
1643
|
+
while (this.pos < this.length) {
|
|
1644
|
+
var c = this.peek();
|
|
1645
|
+
// Backslash escape: consume '\' + next char as a unit.
|
|
1646
|
+
// Prevents '\{' from falsely terminating the selector,
|
|
1647
|
+
// and '\"' from being misread as a string delimiter.
|
|
1648
|
+
if (c === CC_BSLASH) {
|
|
1649
|
+
this.advance(); // consume '\'
|
|
1650
|
+
if (this.pos < this.length) this.advance(); // consume escaped char
|
|
1651
|
+
continue;
|
|
1652
|
+
}
|
|
1653
|
+
if (c === CC_DQUOTE || c === CC_SQUOTE) {
|
|
1654
|
+
this.skipString(c);
|
|
1655
|
+
continue;
|
|
1656
|
+
}
|
|
1657
|
+
if (c === CC_SLASH && this.peek(1) === CC_STAR) {
|
|
1658
|
+
this.skipMLComment();
|
|
1659
|
+
continue;
|
|
1660
|
+
}
|
|
1661
|
+
if (c === CC_LPAREN || c === CC_LBRACK) {
|
|
1662
|
+
depth++;
|
|
1663
|
+
this.advance();
|
|
1664
|
+
continue;
|
|
1665
|
+
}
|
|
1666
|
+
if (c === CC_RPAREN || c === CC_RBRACK) {
|
|
1667
|
+
depth--;
|
|
1668
|
+
this.advance();
|
|
1669
|
+
continue;
|
|
1670
|
+
}
|
|
1671
|
+
if (depth === 0 && c === CC_LBRACE) break;
|
|
1672
|
+
this.advance();
|
|
1673
|
+
}
|
|
1674
|
+
return this.input.slice(start, this.pos);
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
/** Skip a quoted string starting at the current position (quote char given). */
|
|
1678
|
+
}, {
|
|
1679
|
+
key: "skipString",
|
|
1680
|
+
value: function skipString(quote) {
|
|
1681
|
+
this.advance(); // opening quote
|
|
1682
|
+
while (this.pos < this.length) {
|
|
1683
|
+
var c = this.peek();
|
|
1684
|
+
if (c === CC_BSLASH) {
|
|
1685
|
+
this.advance();
|
|
1686
|
+
this.advance();
|
|
1687
|
+
continue;
|
|
1688
|
+
}
|
|
1689
|
+
if (c === quote) {
|
|
1690
|
+
this.advance();
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
if (c === CC_LF) return; // unterminated → stop
|
|
1694
|
+
this.advance();
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
/** Skip a block comment (slash-star ... star-slash) starting at current position. */
|
|
1699
|
+
}, {
|
|
1700
|
+
key: "skipMLComment",
|
|
1701
|
+
value: function skipMLComment() {
|
|
1702
|
+
this.advance();
|
|
1703
|
+
this.advance(); // '/' '*'
|
|
1704
|
+
while (this.pos < this.length - 1) {
|
|
1705
|
+
if (this.peek() === CC_STAR && this.peek(1) === CC_SLASH) {
|
|
1706
|
+
this.advance();
|
|
1707
|
+
this.advance();
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
this.advance();
|
|
1711
|
+
}
|
|
1712
|
+
this.pos = this.length;
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
/** Skip a balanced `{ … }` block (including the opening brace). */
|
|
1716
|
+
}, {
|
|
1717
|
+
key: "skipBalancedBraces",
|
|
1718
|
+
value: function skipBalancedBraces() {
|
|
1719
|
+
if (this.peek() !== CC_LBRACE) return;
|
|
1720
|
+
var depth = 0;
|
|
1721
|
+
while (this.pos < this.length) {
|
|
1722
|
+
var c = this.peek();
|
|
1723
|
+
if (c === CC_LBRACE) depth++;else if (c === CC_RBRACE) {
|
|
1724
|
+
depth--;
|
|
1725
|
+
if (depth === 0) {
|
|
1726
|
+
this.advance();
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
this.advance();
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
/**
|
|
1735
|
+
* Lookahead: scan forward from current position and return true if
|
|
1736
|
+
* an unescaped `{` at depth 0 is found before any `;` or `}`.
|
|
1737
|
+
* Used in `rule` block mode to distinguish declarations from nested rules.
|
|
1738
|
+
*/
|
|
1739
|
+
}, {
|
|
1740
|
+
key: "lookaheadIsRule",
|
|
1741
|
+
value: function lookaheadIsRule() {
|
|
1742
|
+
var i = this.pos,
|
|
1743
|
+
depth = 0;
|
|
1744
|
+
while (i < this.length) {
|
|
1745
|
+
var c = this.input.charCodeAt(i);
|
|
1746
|
+
if (c === CC_DQUOTE || c === CC_SQUOTE) {
|
|
1747
|
+
var q = c;
|
|
1748
|
+
i++;
|
|
1749
|
+
while (i < this.length && this.input.charCodeAt(i) !== q) {
|
|
1750
|
+
if (this.input.charCodeAt(i) === CC_BSLASH) i++;
|
|
1751
|
+
i++;
|
|
1752
|
+
}
|
|
1753
|
+
i++;
|
|
1754
|
+
continue;
|
|
1755
|
+
}
|
|
1756
|
+
if (c === CC_LPAREN || c === CC_LBRACK) {
|
|
1757
|
+
depth++;
|
|
1758
|
+
i++;
|
|
1759
|
+
continue;
|
|
1760
|
+
}
|
|
1761
|
+
if (c === CC_RPAREN || c === CC_RBRACK) {
|
|
1762
|
+
depth--;
|
|
1763
|
+
i++;
|
|
1764
|
+
continue;
|
|
1765
|
+
}
|
|
1766
|
+
if (depth === 0) {
|
|
1767
|
+
if (c === CC_LBRACE) return true;
|
|
1768
|
+
if (c === CC_SEMI || c === CC_RBRACE) return false;
|
|
1769
|
+
}
|
|
1770
|
+
i++;
|
|
1771
|
+
}
|
|
1772
|
+
return false;
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
/**
|
|
1776
|
+
* Characters that unambiguously start a CSS nesting selector
|
|
1777
|
+
* (can never be the start of a property name).
|
|
1778
|
+
*/
|
|
1779
|
+
}, {
|
|
1780
|
+
key: "isNestingStart",
|
|
1781
|
+
value: function isNestingStart(c) {
|
|
1782
|
+
return c === CC_AMP // & nesting selector
|
|
1783
|
+
|| c === CC_DOT // . class
|
|
1784
|
+
|| c === CC_HASH // # id
|
|
1785
|
+
|| c === CC_LBRACK // [ attribute
|
|
1786
|
+
|| c === 42 // * universal
|
|
1787
|
+
|| c === CC_GT // > child combinator
|
|
1788
|
+
|| c === CC_PLUS // + adjacent sibling
|
|
1789
|
+
|| c === CC_TILDE // ~ general sibling
|
|
1790
|
+
|| c === CC_COLON; // : pseudo-class / ::pseudo-element
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
/** Advance past chars until one of the given charcodes (exclusive). */
|
|
1794
|
+
}, {
|
|
1795
|
+
key: "recoverTo",
|
|
1796
|
+
value: function recoverTo() {
|
|
1797
|
+
for (var _len = arguments.length, stops = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1798
|
+
stops[_key] = arguments[_key];
|
|
1799
|
+
}
|
|
1800
|
+
while (this.pos < this.length && !stops.includes(this.peek())) this.advance();
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
/** Advance past chars until one of the given charcodes, then advance one more. */
|
|
1804
|
+
}, {
|
|
1805
|
+
key: "recoverPast",
|
|
1806
|
+
value: function recoverPast() {
|
|
1807
|
+
this.recoverTo.apply(this, arguments);
|
|
1808
|
+
if (this.pos < this.length) this.advance();
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
// ── Location helpers ──────────────────────────────────────────────────────
|
|
1812
|
+
}, {
|
|
1813
|
+
key: "locPos",
|
|
1814
|
+
value: function locPos() {
|
|
1815
|
+
return {
|
|
1816
|
+
line: this.line,
|
|
1817
|
+
column: this.col,
|
|
1818
|
+
offset: this.pos
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
// ── Stylesheet categorizer ────────────────────────────────────────────────
|
|
1823
|
+
}, {
|
|
1824
|
+
key: "categorize",
|
|
1825
|
+
value: function categorize(ss, node) {
|
|
1826
|
+
var _ar$preludeText, _ar$preludeText2;
|
|
1827
|
+
if (node.type !== 'atrule') return;
|
|
1828
|
+
var ar = node;
|
|
1829
|
+
var base = ar.name.replace(/^-(webkit|moz|ms|o)-/, '');
|
|
1830
|
+
switch (base) {
|
|
1831
|
+
case 'import':
|
|
1832
|
+
ss.imports.push(ar);
|
|
1833
|
+
break;
|
|
1834
|
+
case 'media':
|
|
1835
|
+
ss.mediaQueries.push({
|
|
1836
|
+
type: 'media-query',
|
|
1837
|
+
media: (_ar$preludeText = ar.preludeText) !== null && _ar$preludeText !== void 0 ? _ar$preludeText : '',
|
|
1838
|
+
features: [],
|
|
1839
|
+
loc: ar.loc
|
|
1840
|
+
});
|
|
1841
|
+
break;
|
|
1842
|
+
case 'namespace':
|
|
1843
|
+
ss.namespaces.push(ar);
|
|
1844
|
+
break;
|
|
1845
|
+
case 'keyframes':
|
|
1846
|
+
ss.keyframes.push(ar);
|
|
1847
|
+
break;
|
|
1848
|
+
case 'font-face':
|
|
1849
|
+
ss.fontFaces.push(ar);
|
|
1850
|
+
break;
|
|
1851
|
+
case 'layer':
|
|
1852
|
+
{
|
|
1853
|
+
var layerRule = ar;
|
|
1854
|
+
// preludeText holds the layer name (e.g. "atomic" for "@layer atomic { … }")
|
|
1855
|
+
if (ar.preludeText) layerRule.layerName = ar.preludeText.trim();
|
|
1856
|
+
ss.layers.push(layerRule);
|
|
1857
|
+
break;
|
|
1858
|
+
}
|
|
1859
|
+
case 'container':
|
|
1860
|
+
{
|
|
1861
|
+
var containerRule = ar;
|
|
1862
|
+
if (ar.preludeText) {
|
|
1863
|
+
// "@container main (width > 600px)" → name is the first token
|
|
1864
|
+
var parts = ar.preludeText.trim().match(/^([\w-]+)?\s*(.*)/);
|
|
1865
|
+
if (parts !== null && parts !== void 0 && parts[1]) containerRule.containerName = parts[1];
|
|
1866
|
+
if (parts !== null && parts !== void 0 && parts[2]) containerRule.containerQuery = parts[2].trim();
|
|
1867
|
+
}
|
|
1868
|
+
ss.containers.push(containerRule);
|
|
1869
|
+
break;
|
|
1870
|
+
}
|
|
1871
|
+
case 'supports':
|
|
1872
|
+
ss.supports.push(ar);
|
|
1873
|
+
break;
|
|
1874
|
+
case 'document':
|
|
1875
|
+
ss.documents.push(ar);
|
|
1876
|
+
break;
|
|
1877
|
+
case 'page':
|
|
1878
|
+
ss.pages.push(ar);
|
|
1879
|
+
break;
|
|
1880
|
+
case 'counter-style':
|
|
1881
|
+
ss.counterStyles.push(ar);
|
|
1882
|
+
break;
|
|
1883
|
+
case 'font-feature-values':
|
|
1884
|
+
ss.fontFeatureValues.push(ar);
|
|
1885
|
+
break;
|
|
1886
|
+
case 'viewport':
|
|
1887
|
+
ss.viewports.push(ar);
|
|
1888
|
+
break;
|
|
1889
|
+
case 'charset':
|
|
1890
|
+
ss.charsets.push(ar);
|
|
1891
|
+
ss.charset = (_ar$preludeText2 = ar.preludeText) === null || _ar$preludeText2 === void 0 ? void 0 : _ar$preludeText2.replace(/^['"]|['"]$/g, '');
|
|
1892
|
+
break;
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
// ── Legacy format ─────────────────────────────────────────────────────────
|
|
1897
|
+
}, {
|
|
1898
|
+
key: "toLegacyNode",
|
|
1899
|
+
value: function toLegacyNode(node) {
|
|
1900
|
+
var _this2 = this;
|
|
1901
|
+
switch (node.type) {
|
|
1902
|
+
case 'rule':
|
|
1903
|
+
{
|
|
1904
|
+
var _r$rawSelector;
|
|
1905
|
+
var r = node;
|
|
1906
|
+
var name = (_r$rawSelector = r.rawSelector) !== null && _r$rawSelector !== void 0 ? _r$rawSelector : r.selectors.map(function (s) {
|
|
1907
|
+
return s.value;
|
|
1908
|
+
}).join(', ');
|
|
1909
|
+
return {
|
|
1910
|
+
kind: 'rule',
|
|
1911
|
+
name: name,
|
|
1912
|
+
value: r.declarations.map(function (d) {
|
|
1913
|
+
var _d$rawValue;
|
|
1914
|
+
return "".concat(d.property, ": ").concat((_d$rawValue = d.rawValue) !== null && _d$rawValue !== void 0 ? _d$rawValue : d.value.map(function (v) {
|
|
1915
|
+
return String(v.value);
|
|
1916
|
+
}).join(' ')).concat(d.important ? ' !important' : '');
|
|
1917
|
+
}).join('; '),
|
|
1918
|
+
important: false,
|
|
1919
|
+
children: r.declarations.map(function (d) {
|
|
1920
|
+
return _this2.toLegacyNode(d);
|
|
1921
|
+
}).filter(Boolean),
|
|
1922
|
+
loc: r.loc,
|
|
1923
|
+
node: 'rule',
|
|
1924
|
+
cssNode: {},
|
|
1925
|
+
parents: [],
|
|
1926
|
+
selectors: r.selectors.map(function (s) {
|
|
1927
|
+
return {
|
|
1928
|
+
kind: 'rule',
|
|
1929
|
+
name: s.value,
|
|
1930
|
+
value: s.value,
|
|
1931
|
+
loc: s.loc,
|
|
1932
|
+
node: 'selector',
|
|
1933
|
+
cssNode: {},
|
|
1934
|
+
parents: []
|
|
1935
|
+
};
|
|
1936
|
+
})
|
|
1937
|
+
};
|
|
1938
|
+
}
|
|
1939
|
+
case 'atrule':
|
|
1940
|
+
{
|
|
1941
|
+
var _ref, _ar$preludeText3, _ar$prelude, _ar$block$children, _ar$block;
|
|
1942
|
+
var ar = node;
|
|
1943
|
+
return {
|
|
1944
|
+
kind: 'atrule',
|
|
1945
|
+
name: ar.name,
|
|
1946
|
+
value: (_ref = (_ar$preludeText3 = ar.preludeText) !== null && _ar$preludeText3 !== void 0 ? _ar$preludeText3 : (_ar$prelude = ar.prelude) === null || _ar$prelude === void 0 ? void 0 : _ar$prelude.map(function (v) {
|
|
1947
|
+
return String(v.value);
|
|
1948
|
+
}).join(' ')) !== null && _ref !== void 0 ? _ref : '',
|
|
1949
|
+
important: false,
|
|
1950
|
+
children: ((_ar$block$children = (_ar$block = ar.block) === null || _ar$block === void 0 ? void 0 : _ar$block.children) !== null && _ar$block$children !== void 0 ? _ar$block$children : []).map(function (c) {
|
|
1951
|
+
return _this2.toLegacyNode(c);
|
|
1952
|
+
}).filter(Boolean),
|
|
1953
|
+
loc: ar.loc,
|
|
1954
|
+
node: 'atrule',
|
|
1955
|
+
cssNode: {},
|
|
1956
|
+
parents: []
|
|
1957
|
+
};
|
|
1958
|
+
}
|
|
1959
|
+
case 'declaration':
|
|
1960
|
+
{
|
|
1961
|
+
var _d$rawValue2;
|
|
1962
|
+
var d = node;
|
|
1963
|
+
return {
|
|
1964
|
+
kind: 'decl',
|
|
1965
|
+
name: d.property,
|
|
1966
|
+
value: (_d$rawValue2 = d.rawValue) !== null && _d$rawValue2 !== void 0 ? _d$rawValue2 : d.value.map(function (v) {
|
|
1967
|
+
return String(v.value);
|
|
1968
|
+
}).join(' '),
|
|
1969
|
+
important: d.important,
|
|
1970
|
+
children: [],
|
|
1971
|
+
loc: d.loc,
|
|
1972
|
+
node: 'declaration',
|
|
1973
|
+
cssNode: {},
|
|
1974
|
+
parents: []
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1977
|
+
case 'comment':
|
|
1978
|
+
{
|
|
1979
|
+
var c = node;
|
|
1980
|
+
return {
|
|
1981
|
+
kind: 'comment',
|
|
1982
|
+
name: undefined,
|
|
1983
|
+
value: c.value,
|
|
1984
|
+
important: false,
|
|
1985
|
+
children: [],
|
|
1986
|
+
loc: c.loc,
|
|
1987
|
+
node: 'comment',
|
|
1988
|
+
cssNode: {},
|
|
1989
|
+
parents: []
|
|
1990
|
+
};
|
|
1991
|
+
}
|
|
1992
|
+
default:
|
|
1993
|
+
return null;
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
}], [{
|
|
1997
|
+
key: "emptyStats",
|
|
1998
|
+
value: function emptyStats() {
|
|
1999
|
+
return {
|
|
2000
|
+
totalNodes: 0,
|
|
2001
|
+
totalRules: 0,
|
|
2002
|
+
totalDeclarations: 0,
|
|
2003
|
+
totalAtRules: 0,
|
|
2004
|
+
totalComments: 0,
|
|
2005
|
+
totalSelectors: 0,
|
|
2006
|
+
totalValues: 0,
|
|
2007
|
+
parseTime: 0,
|
|
2008
|
+
memoryUsage: 0,
|
|
2009
|
+
errors: 0,
|
|
2010
|
+
warnings: 0
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
}]);
|
|
2014
|
+
}();
|
|
2015
|
+
|
|
2016
|
+
// ─── Public parse helpers ─────────────────────────────────────────────────────
|
|
2017
|
+
|
|
2018
|
+
/** Parse a CSS string into a stylesheet AST. */
|
|
2019
|
+
function parseCss(css, options) {
|
|
2020
|
+
return new CssParser(options).parse(css);
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
/** Parse CSS and convert to the legacy AstNode[] format. */
|
|
2024
|
+
function parseCssToLegacy(css, options) {
|
|
2025
|
+
var parser = new CssParser(options);
|
|
2026
|
+
return parser.toLegacyFormat(parser.parse(css));
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
exports.CssGenerator = CssGenerator;
|
|
2030
|
+
exports.CssParser = CssParser;
|
|
2031
|
+
exports.atRule = atRule;
|
|
2032
|
+
exports.cloneNode = cloneNode;
|
|
2033
|
+
exports.cloneNodeDeep = cloneNodeDeep;
|
|
2034
|
+
exports.comment = comment;
|
|
2035
|
+
exports.decl = decl;
|
|
2036
|
+
exports.declaration = declaration;
|
|
2037
|
+
exports.keyframe = keyframe;
|
|
2038
|
+
exports.location = location;
|
|
2039
|
+
exports.locationPos = locationPos;
|
|
2040
|
+
exports.parseCss = parseCss;
|
|
2041
|
+
exports.parseCssToLegacy = parseCssToLegacy;
|
|
2042
|
+
exports.rule = rule;
|
|
2043
|
+
exports.selector = selector;
|
|
2044
|
+
exports.stringify = stringify;
|
|
2045
|
+
exports.stylesheet = stylesheet;
|
|
2046
|
+
exports.walk = walk;
|
|
2047
|
+
//# sourceMappingURL=css-parser.cjs.map
|