@bookklik/senangstart-css 0.1.8 → 0.2.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/README.md +38 -0
- package/dist/senangstart-css.js +2269 -1955
- package/dist/senangstart-css.min.js +141 -1479
- package/docs/.vitepress/config.js +2 -0
- package/docs/guide/responsive.md +25 -0
- package/docs/index.md +1 -1
- package/docs/ms/guide/responsive.md +25 -0
- package/docs/ms/index.md +1 -1
- package/docs/ms/reference/breakpoints.md +23 -0
- package/docs/ms/reference/layout/align-content.md +57 -4
- package/docs/ms/reference/layout/align-items.md +81 -4
- package/docs/ms/reference/layout/align-self.md +25 -4
- package/docs/ms/reference/layout/aspect-ratio.md +27 -8
- package/docs/ms/reference/layout/border-collapse.md +81 -4
- package/docs/ms/reference/layout/border-spacing.md +43 -8
- package/docs/ms/reference/layout/box-sizing.md +21 -4
- package/docs/ms/reference/layout/caption-side.md +69 -4
- package/docs/ms/reference/layout/columns.md +21 -4
- package/docs/ms/reference/layout/container.md +21 -4
- package/docs/ms/reference/layout/display.md +39 -7
- package/docs/ms/reference/layout/flex-basis.md +29 -8
- package/docs/ms/reference/layout/flex-direction.md +81 -4
- package/docs/ms/reference/layout/flex-items.md +51 -4
- package/docs/ms/reference/layout/flex-wrap.md +55 -4
- package/docs/ms/reference/layout/flex.md +54 -7
- package/docs/ms/reference/layout/float-clear.md +23 -4
- package/docs/ms/reference/layout/grid-auto-flow.md +57 -4
- package/docs/ms/reference/layout/grid-auto-sizing.md +25 -4
- package/docs/ms/reference/layout/grid-column-span.md +59 -4
- package/docs/ms/reference/layout/grid-columns.md +61 -4
- package/docs/ms/reference/layout/grid-row-span.md +29 -4
- package/docs/ms/reference/layout/grid-rows.md +31 -4
- package/docs/ms/reference/layout/inset.md +56 -7
- package/docs/ms/reference/layout/isolation.md +21 -4
- package/docs/ms/reference/layout/justify-content.md +81 -4
- package/docs/ms/reference/layout/justify-items.md +25 -4
- package/docs/ms/reference/layout/justify-self.md +25 -4
- package/docs/ms/reference/layout/object-fit.md +57 -4
- package/docs/ms/reference/layout/object-position.md +29 -8
- package/docs/ms/reference/layout/order.md +53 -4
- package/docs/ms/reference/layout/overflow.md +45 -4
- package/docs/ms/reference/layout/overscroll.md +21 -4
- package/docs/ms/reference/layout/place-content.md +23 -4
- package/docs/ms/reference/layout/place-items.md +25 -4
- package/docs/ms/reference/layout/place-self.md +25 -4
- package/docs/ms/reference/layout/position.md +47 -4
- package/docs/ms/reference/layout/shorthand-alignment.md +47 -4
- package/docs/ms/reference/layout/table-layout.md +69 -4
- package/docs/ms/reference/layout/visibility.md +25 -4
- package/docs/ms/reference/layout/z-index.md +27 -4
- package/docs/ms/reference/space/gap.md +71 -7
- package/docs/ms/reference/space/height.md +61 -7
- package/docs/ms/reference/space/margin.md +61 -7
- package/docs/ms/reference/space/padding.md +65 -7
- package/docs/ms/reference/space/width.md +61 -7
- package/docs/ms/reference/visual/accent-color.md +29 -8
- package/docs/ms/reference/visual/animation-builtin.md +29 -8
- package/docs/ms/reference/visual/animation-delay.md +25 -8
- package/docs/ms/reference/visual/animation-direction.md +25 -4
- package/docs/ms/reference/visual/animation-duration.md +27 -8
- package/docs/ms/reference/visual/animation-fill.md +25 -4
- package/docs/ms/reference/visual/animation-iteration.md +23 -4
- package/docs/ms/reference/visual/animation-play.md +23 -4
- package/docs/ms/reference/visual/appearance.md +23 -4
- package/docs/ms/reference/visual/backdrop-blur.md +29 -8
- package/docs/ms/reference/visual/backdrop-brightness.md +29 -8
- package/docs/ms/reference/visual/backdrop-contrast.md +29 -8
- package/docs/ms/reference/visual/backdrop-grayscale.md +27 -8
- package/docs/ms/reference/visual/backdrop-hue-rotate.md +29 -8
- package/docs/ms/reference/visual/backdrop-invert.md +27 -8
- package/docs/ms/reference/visual/backdrop-opacity.md +29 -8
- package/docs/ms/reference/visual/backdrop-saturate.md +29 -8
- package/docs/ms/reference/visual/backdrop-sepia.md +27 -8
- package/docs/ms/reference/visual/background-attachment.md +23 -4
- package/docs/ms/reference/visual/background-blend-mode.md +25 -4
- package/docs/ms/reference/visual/background-clip.md +21 -4
- package/docs/ms/reference/visual/background-color.md +33 -8
- package/docs/ms/reference/visual/background-image.md +27 -8
- package/docs/ms/reference/visual/background-origin.md +25 -4
- package/docs/ms/reference/visual/background-position.md +29 -8
- package/docs/ms/reference/visual/background-repeat.md +25 -4
- package/docs/ms/reference/visual/background-size.md +29 -8
- package/docs/ms/reference/visual/blend-modes.md +23 -4
- package/docs/ms/reference/visual/border-radius.md +36 -4
- package/docs/ms/reference/visual/border-style.md +25 -4
- package/docs/ms/reference/visual/border-width.md +29 -8
- package/docs/ms/reference/visual/border.md +56 -7
- package/docs/ms/reference/visual/box-shadow.md +34 -4
- package/docs/ms/reference/visual/caret-color.md +25 -8
- package/docs/ms/reference/visual/color-scheme.md +23 -4
- package/docs/ms/reference/visual/cursor.md +25 -4
- package/docs/ms/reference/visual/field-sizing.md +23 -4
- package/docs/ms/reference/visual/fill.md +29 -8
- package/docs/ms/reference/visual/filter-blur.md +29 -8
- package/docs/ms/reference/visual/filter-brightness.md +29 -8
- package/docs/ms/reference/visual/filter-contrast.md +29 -8
- package/docs/ms/reference/visual/filter-drop-shadow.md +29 -8
- package/docs/ms/reference/visual/filter-grayscale.md +29 -8
- package/docs/ms/reference/visual/filter-hue-rotate.md +29 -8
- package/docs/ms/reference/visual/filter-invert.md +27 -8
- package/docs/ms/reference/visual/filter-saturate.md +29 -8
- package/docs/ms/reference/visual/filter-sepia.md +29 -8
- package/docs/ms/reference/visual/font-family.md +25 -4
- package/docs/ms/reference/visual/font-smoothing.md +23 -4
- package/docs/ms/reference/visual/font-style.md +23 -4
- package/docs/ms/reference/visual/font-variant-numeric.md +23 -4
- package/docs/ms/reference/visual/font-weight.md +35 -4
- package/docs/ms/reference/visual/forced-color-adjust.md +23 -4
- package/docs/ms/reference/visual/hyphens.md +25 -4
- package/docs/ms/reference/visual/letter-spacing.md +29 -8
- package/docs/ms/reference/visual/line-clamp.md +29 -8
- package/docs/ms/reference/visual/line-height.md +29 -8
- package/docs/ms/reference/visual/list-style.md +25 -4
- package/docs/ms/reference/visual/mask.md +25 -8
- package/docs/ms/reference/visual/opacity.md +27 -4
- package/docs/ms/reference/visual/outline.md +25 -8
- package/docs/ms/reference/visual/pointer-events.md +23 -4
- package/docs/ms/reference/visual/resize.md +27 -4
- package/docs/ms/reference/visual/scroll-behavior.md +23 -4
- package/docs/ms/reference/visual/scroll-margin.md +25 -8
- package/docs/ms/reference/visual/scroll-padding.md +25 -8
- package/docs/ms/reference/visual/scroll-snap-align.md +25 -4
- package/docs/ms/reference/visual/scroll-snap-stop.md +23 -4
- package/docs/ms/reference/visual/scroll-snap-type.md +25 -4
- package/docs/ms/reference/visual/state-prefixes.md +21 -4
- package/docs/ms/reference/visual/stroke-width.md +29 -8
- package/docs/ms/reference/visual/stroke.md +27 -8
- package/docs/ms/reference/visual/text-alignment.md +25 -4
- package/docs/ms/reference/visual/text-color.md +31 -8
- package/docs/ms/reference/visual/text-decoration.md +23 -4
- package/docs/ms/reference/visual/text-indent.md +25 -8
- package/docs/ms/reference/visual/text-overflow.md +21 -4
- package/docs/ms/reference/visual/text-shadow.md +25 -8
- package/docs/ms/reference/visual/text-size.md +41 -7
- package/docs/ms/reference/visual/text-transform.md +25 -4
- package/docs/ms/reference/visual/text-wrap.md +25 -4
- package/docs/ms/reference/visual/touch-action.md +25 -4
- package/docs/ms/reference/visual/transform-backface.md +23 -4
- package/docs/ms/reference/visual/transform-origin.md +27 -8
- package/docs/ms/reference/visual/transform-perspective-origin.md +25 -8
- package/docs/ms/reference/visual/transform-perspective.md +25 -8
- package/docs/ms/reference/visual/transform-rotate.md +29 -8
- package/docs/ms/reference/visual/transform-scale.md +29 -8
- package/docs/ms/reference/visual/transform-skew.md +29 -8
- package/docs/ms/reference/visual/transform-style.md +23 -4
- package/docs/ms/reference/visual/transform-translate.md +29 -8
- package/docs/ms/reference/visual/transition-delay.md +25 -8
- package/docs/ms/reference/visual/transition-duration.md +27 -8
- package/docs/ms/reference/visual/transition-property.md +21 -4
- package/docs/ms/reference/visual/transition-timing.md +29 -8
- package/docs/ms/reference/visual/typography-keywords.md +27 -4
- package/docs/ms/reference/visual/user-select.md +23 -4
- package/docs/ms/reference/visual/vertical-align.md +25 -4
- package/docs/ms/reference/visual/whitespace.md +25 -4
- package/docs/ms/reference/visual/will-change.md +23 -4
- package/docs/ms/reference/visual/word-break.md +25 -4
- package/docs/public/assets/senangstart-css-logo.svg +1 -0
- package/docs/reference/breakpoints.md +23 -0
- package/docs/reference/layout/align-content.md +57 -4
- package/docs/reference/layout/align-items.md +81 -4
- package/docs/reference/layout/align-self.md +25 -4
- package/docs/reference/layout/aspect-ratio.md +27 -8
- package/docs/reference/layout/border-collapse.md +81 -4
- package/docs/reference/layout/border-spacing.md +43 -8
- package/docs/reference/layout/box-sizing.md +21 -4
- package/docs/reference/layout/caption-side.md +69 -4
- package/docs/reference/layout/columns.md +21 -4
- package/docs/reference/layout/container.md +21 -4
- package/docs/reference/layout/display.md +39 -7
- package/docs/reference/layout/flex-basis.md +29 -8
- package/docs/reference/layout/flex-direction.md +81 -4
- package/docs/reference/layout/flex-items.md +51 -4
- package/docs/reference/layout/flex-wrap.md +55 -4
- package/docs/reference/layout/flex.md +54 -7
- package/docs/reference/layout/float-clear.md +23 -4
- package/docs/reference/layout/grid-auto-flow.md +57 -4
- package/docs/reference/layout/grid-auto-sizing.md +25 -4
- package/docs/reference/layout/grid-column-span.md +59 -4
- package/docs/reference/layout/grid-columns.md +61 -4
- package/docs/reference/layout/grid-row-span.md +29 -4
- package/docs/reference/layout/grid-rows.md +31 -4
- package/docs/reference/layout/inset.md +56 -7
- package/docs/reference/layout/isolation.md +21 -4
- package/docs/reference/layout/justify-content.md +81 -4
- package/docs/reference/layout/justify-items.md +25 -4
- package/docs/reference/layout/justify-self.md +25 -4
- package/docs/reference/layout/object-fit.md +57 -4
- package/docs/reference/layout/object-position.md +29 -8
- package/docs/reference/layout/order.md +53 -4
- package/docs/reference/layout/overflow.md +45 -4
- package/docs/reference/layout/overscroll.md +21 -4
- package/docs/reference/layout/place-content.md +23 -4
- package/docs/reference/layout/place-items.md +25 -4
- package/docs/reference/layout/place-self.md +25 -4
- package/docs/reference/layout/position.md +47 -4
- package/docs/reference/layout/shorthand-alignment.md +47 -4
- package/docs/reference/layout/table-layout.md +69 -4
- package/docs/reference/layout/visibility.md +25 -4
- package/docs/reference/layout/z-index.md +27 -4
- package/docs/reference/space/gap.md +71 -7
- package/docs/reference/space/height.md +61 -7
- package/docs/reference/space/margin.md +61 -7
- package/docs/reference/space/padding.md +65 -7
- package/docs/reference/space/width.md +61 -7
- package/docs/reference/visual/accent-color.md +29 -8
- package/docs/reference/visual/animation-builtin.md +29 -8
- package/docs/reference/visual/animation-delay.md +25 -8
- package/docs/reference/visual/animation-direction.md +25 -4
- package/docs/reference/visual/animation-duration.md +27 -8
- package/docs/reference/visual/animation-fill.md +25 -4
- package/docs/reference/visual/animation-iteration.md +23 -4
- package/docs/reference/visual/animation-play.md +23 -4
- package/docs/reference/visual/appearance.md +23 -4
- package/docs/reference/visual/backdrop-blur.md +29 -8
- package/docs/reference/visual/backdrop-brightness.md +29 -8
- package/docs/reference/visual/backdrop-contrast.md +29 -8
- package/docs/reference/visual/backdrop-grayscale.md +27 -8
- package/docs/reference/visual/backdrop-hue-rotate.md +29 -8
- package/docs/reference/visual/backdrop-invert.md +27 -8
- package/docs/reference/visual/backdrop-opacity.md +29 -8
- package/docs/reference/visual/backdrop-saturate.md +29 -8
- package/docs/reference/visual/backdrop-sepia.md +27 -8
- package/docs/reference/visual/background-attachment.md +23 -4
- package/docs/reference/visual/background-blend-mode.md +25 -4
- package/docs/reference/visual/background-clip.md +21 -4
- package/docs/reference/visual/background-color.md +33 -8
- package/docs/reference/visual/background-image.md +27 -8
- package/docs/reference/visual/background-origin.md +25 -4
- package/docs/reference/visual/background-position.md +29 -8
- package/docs/reference/visual/background-repeat.md +25 -4
- package/docs/reference/visual/background-size.md +29 -8
- package/docs/reference/visual/blend-modes.md +23 -4
- package/docs/reference/visual/border-radius.md +36 -4
- package/docs/reference/visual/border-style.md +25 -4
- package/docs/reference/visual/border-width.md +29 -8
- package/docs/reference/visual/border.md +56 -7
- package/docs/reference/visual/box-shadow.md +34 -4
- package/docs/reference/visual/caret-color.md +25 -8
- package/docs/reference/visual/color-scheme.md +23 -4
- package/docs/reference/visual/cursor.md +25 -4
- package/docs/reference/visual/field-sizing.md +23 -4
- package/docs/reference/visual/fill.md +29 -8
- package/docs/reference/visual/filter-blur.md +29 -8
- package/docs/reference/visual/filter-brightness.md +29 -8
- package/docs/reference/visual/filter-contrast.md +29 -8
- package/docs/reference/visual/filter-drop-shadow.md +29 -8
- package/docs/reference/visual/filter-grayscale.md +29 -8
- package/docs/reference/visual/filter-hue-rotate.md +29 -8
- package/docs/reference/visual/filter-invert.md +27 -8
- package/docs/reference/visual/filter-saturate.md +29 -8
- package/docs/reference/visual/filter-sepia.md +29 -8
- package/docs/reference/visual/font-family.md +25 -4
- package/docs/reference/visual/font-smoothing.md +23 -4
- package/docs/reference/visual/font-style.md +23 -4
- package/docs/reference/visual/font-variant-numeric.md +23 -4
- package/docs/reference/visual/font-weight.md +35 -4
- package/docs/reference/visual/forced-color-adjust.md +23 -4
- package/docs/reference/visual/hyphens.md +25 -4
- package/docs/reference/visual/letter-spacing.md +29 -8
- package/docs/reference/visual/line-clamp.md +29 -8
- package/docs/reference/visual/line-height.md +29 -8
- package/docs/reference/visual/list-style.md +25 -4
- package/docs/reference/visual/mask.md +25 -8
- package/docs/reference/visual/opacity.md +27 -4
- package/docs/reference/visual/outline.md +25 -8
- package/docs/reference/visual/pointer-events.md +23 -4
- package/docs/reference/visual/resize.md +27 -4
- package/docs/reference/visual/scroll-behavior.md +23 -4
- package/docs/reference/visual/scroll-margin.md +25 -8
- package/docs/reference/visual/scroll-padding.md +25 -8
- package/docs/reference/visual/scroll-snap-align.md +25 -4
- package/docs/reference/visual/scroll-snap-stop.md +23 -4
- package/docs/reference/visual/scroll-snap-type.md +25 -4
- package/docs/reference/visual/state-prefixes.md +21 -4
- package/docs/reference/visual/stroke-width.md +29 -8
- package/docs/reference/visual/stroke.md +27 -8
- package/docs/reference/visual/text-alignment.md +25 -4
- package/docs/reference/visual/text-color.md +31 -8
- package/docs/reference/visual/text-decoration.md +23 -4
- package/docs/reference/visual/text-indent.md +25 -8
- package/docs/reference/visual/text-overflow.md +21 -4
- package/docs/reference/visual/text-shadow.md +25 -8
- package/docs/reference/visual/text-size.md +41 -7
- package/docs/reference/visual/text-transform.md +25 -4
- package/docs/reference/visual/text-wrap.md +25 -4
- package/docs/reference/visual/touch-action.md +25 -4
- package/docs/reference/visual/transform-backface.md +23 -4
- package/docs/reference/visual/transform-origin.md +27 -8
- package/docs/reference/visual/transform-perspective-origin.md +25 -8
- package/docs/reference/visual/transform-perspective.md +25 -8
- package/docs/reference/visual/transform-rotate.md +29 -8
- package/docs/reference/visual/transform-scale.md +29 -8
- package/docs/reference/visual/transform-skew.md +29 -8
- package/docs/reference/visual/transform-style.md +23 -4
- package/docs/reference/visual/transform-translate.md +29 -8
- package/docs/reference/visual/transition-delay.md +25 -8
- package/docs/reference/visual/transition-duration.md +27 -8
- package/docs/reference/visual/transition-property.md +21 -4
- package/docs/reference/visual/transition-timing.md +29 -8
- package/docs/reference/visual/typography-keywords.md +27 -4
- package/docs/reference/visual/user-select.md +23 -4
- package/docs/reference/visual/vertical-align.md +25 -4
- package/docs/reference/visual/whitespace.md +25 -4
- package/docs/reference/visual/will-change.md +23 -4
- package/docs/reference/visual/word-break.md +25 -4
- package/package.json +2 -1
- package/playground/jit-tw-mix-test.html +238 -0
- package/playground/tw-convertor.html +696 -0
- package/scripts/build-dist.js +34 -29
- package/scripts/bundle-jit.js +45 -0
- package/scripts/convert-tailwind.js +759 -0
- package/scripts/generate-docs.js +65 -16
- package/src/cdn/jit.js +313 -102
- package/src/cli/commands/build.js +14 -6
- package/src/cli/commands/dev.js +28 -10
- package/src/compiler/generators/css.js +187 -28
- package/src/compiler/parser.js +23 -10
- package/src/compiler/tokenizer.js +19 -137
- package/src/config/defaults.js +45 -18
- package/src/core/constants.js +427 -0
- package/src/core/tokenizer-core.js +233 -0
- package/src/definitions/layout-alignment.js +210 -0
- package/src/definitions/layout-flex.js +155 -0
- package/src/definitions/layout-grid.js +134 -0
- package/src/definitions/layout-positioning.js +64 -0
- package/src/definitions/layout-table.js +129 -0
- package/src/definitions/layout-utilities.js +164 -0
- package/src/definitions/space.js +172 -0
- package/src/definitions/visual-backgrounds.js +231 -0
- package/src/definitions/visual-borders.js +66 -0
- package/src/definitions/visual-filters.js +111 -0
- package/src/definitions/visual-interactivity.js +159 -0
- package/src/definitions/visual-svg.js +41 -0
- package/src/definitions/visual-transform3d.js +74 -0
- package/src/definitions/visual-transforms.js +69 -0
- package/src/definitions/visual-transitions.js +144 -0
- package/src/definitions/visual-typography.js +214 -0
- package/src/definitions/visual.js +306 -1
- package/tests/integration/compiler.test.js +63 -2
- package/tests/unit/convert-tailwind.test.js +324 -0
- package/tests/unit/security.test.js +206 -0
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Tailwind CSS to SenangStart CSS Converter
|
|
4
|
+
* Converts Tailwind class syntax to SenangStart attribute syntax
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* node scripts/convert-tailwind.js input.html -o output.html
|
|
8
|
+
* node scripts/convert-tailwind.js --string "<div class='flex'>"
|
|
9
|
+
* node scripts/convert-tailwind.js --clipboard
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
13
|
+
import { argv } from 'process';
|
|
14
|
+
import { resolve, join, sep } from 'path';
|
|
15
|
+
|
|
16
|
+
// ======================
|
|
17
|
+
// SPACING SCALE MAPPING
|
|
18
|
+
// ======================
|
|
19
|
+
// Maps Tailwind spacing numbers to SenangStart semantic scale
|
|
20
|
+
const spacingScale = {
|
|
21
|
+
'0': 'none',
|
|
22
|
+
'px': '[1px]',
|
|
23
|
+
'0.5': 'tiny',
|
|
24
|
+
'1': 'tiny',
|
|
25
|
+
'1.5': 'tiny',
|
|
26
|
+
'2': 'tiny',
|
|
27
|
+
'2.5': 'small',
|
|
28
|
+
'3': 'small',
|
|
29
|
+
'3.5': 'small',
|
|
30
|
+
'4': 'small',
|
|
31
|
+
'5': 'medium',
|
|
32
|
+
'6': 'medium',
|
|
33
|
+
'7': 'medium',
|
|
34
|
+
'8': 'big',
|
|
35
|
+
'9': 'big',
|
|
36
|
+
'10': 'big',
|
|
37
|
+
'11': 'big',
|
|
38
|
+
'12': 'giant',
|
|
39
|
+
'14': 'giant',
|
|
40
|
+
'16': 'giant',
|
|
41
|
+
'20': 'vast',
|
|
42
|
+
'24': 'vast',
|
|
43
|
+
'28': 'vast',
|
|
44
|
+
'32': 'vast',
|
|
45
|
+
'36': 'vast',
|
|
46
|
+
'40': 'vast',
|
|
47
|
+
'44': 'vast',
|
|
48
|
+
'48': 'vast',
|
|
49
|
+
'52': 'vast',
|
|
50
|
+
'56': 'vast',
|
|
51
|
+
'60': 'vast',
|
|
52
|
+
'64': 'vast',
|
|
53
|
+
'72': 'vast',
|
|
54
|
+
'80': 'vast',
|
|
55
|
+
'96': 'vast',
|
|
56
|
+
'full': '[100%]',
|
|
57
|
+
'screen': '[100vw]',
|
|
58
|
+
'min': '[min-content]',
|
|
59
|
+
'max': '[max-content]',
|
|
60
|
+
'fit': '[fit-content]',
|
|
61
|
+
'auto': 'auto'
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// ======================
|
|
65
|
+
// BORDER RADIUS MAPPING
|
|
66
|
+
// ======================
|
|
67
|
+
const radiusScale = {
|
|
68
|
+
'none': 'none',
|
|
69
|
+
'sm': 'small',
|
|
70
|
+
'': 'small', // rounded without suffix
|
|
71
|
+
'md': 'medium',
|
|
72
|
+
'lg': 'medium',
|
|
73
|
+
'xl': 'big',
|
|
74
|
+
'2xl': 'big',
|
|
75
|
+
'3xl': 'big',
|
|
76
|
+
'full': 'round'
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// ======================
|
|
80
|
+
// SHADOW MAPPING
|
|
81
|
+
// ======================
|
|
82
|
+
const shadowScale = {
|
|
83
|
+
'sm': 'small',
|
|
84
|
+
'': 'small', // shadow without suffix
|
|
85
|
+
'md': 'medium',
|
|
86
|
+
'lg': 'big',
|
|
87
|
+
'xl': 'giant',
|
|
88
|
+
'2xl': 'giant',
|
|
89
|
+
'none': 'none'
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// ======================
|
|
93
|
+
// FONT SIZE MAPPING
|
|
94
|
+
// ======================
|
|
95
|
+
const fontSizeScale = {
|
|
96
|
+
'xs': 'tiny',
|
|
97
|
+
'sm': 'small',
|
|
98
|
+
'base': 'medium',
|
|
99
|
+
'lg': 'big',
|
|
100
|
+
'xl': 'big',
|
|
101
|
+
'2xl': 'giant',
|
|
102
|
+
'3xl': 'giant',
|
|
103
|
+
'4xl': 'vast',
|
|
104
|
+
'5xl': 'vast',
|
|
105
|
+
'6xl': 'vast',
|
|
106
|
+
'7xl': 'vast',
|
|
107
|
+
'8xl': 'vast',
|
|
108
|
+
'9xl': 'vast'
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// ======================
|
|
112
|
+
// LAYOUT CLASS MAPPINGS
|
|
113
|
+
// ======================
|
|
114
|
+
const layoutMappings = {
|
|
115
|
+
// Display
|
|
116
|
+
'container': 'container',
|
|
117
|
+
'flex': 'flex',
|
|
118
|
+
'inline-flex': 'inline-flex',
|
|
119
|
+
'grid': 'grid',
|
|
120
|
+
'inline-grid': 'inline-grid',
|
|
121
|
+
'block': 'block',
|
|
122
|
+
'inline-block': 'inline',
|
|
123
|
+
'inline': 'inline',
|
|
124
|
+
'hidden': 'hidden',
|
|
125
|
+
|
|
126
|
+
// Flex direction
|
|
127
|
+
'flex-row': 'row',
|
|
128
|
+
'flex-col': 'col',
|
|
129
|
+
'flex-row-reverse': 'row-reverse',
|
|
130
|
+
'flex-col-reverse': 'col-reverse',
|
|
131
|
+
|
|
132
|
+
// Flex wrap
|
|
133
|
+
'flex-wrap': 'wrap',
|
|
134
|
+
'flex-nowrap': 'nowrap',
|
|
135
|
+
'flex-wrap-reverse': 'wrap-reverse',
|
|
136
|
+
|
|
137
|
+
// Flex grow/shrink
|
|
138
|
+
'flex-grow': 'grow',
|
|
139
|
+
'flex-grow-0': 'grow-0',
|
|
140
|
+
'grow': 'grow',
|
|
141
|
+
'grow-0': 'grow-0',
|
|
142
|
+
'flex-shrink': 'shrink',
|
|
143
|
+
'flex-shrink-0': 'shrink-0',
|
|
144
|
+
'shrink': 'shrink',
|
|
145
|
+
'shrink-0': 'shrink-0',
|
|
146
|
+
|
|
147
|
+
// Flex shorthand
|
|
148
|
+
'flex-1': 'flex:1',
|
|
149
|
+
'flex-auto': 'flex:auto',
|
|
150
|
+
'flex-initial': 'flex:initial',
|
|
151
|
+
'flex-none': 'flex:none',
|
|
152
|
+
|
|
153
|
+
// Justify content
|
|
154
|
+
'justify-start': 'justify:start',
|
|
155
|
+
'justify-end': 'justify:end',
|
|
156
|
+
'justify-center': 'justify:center',
|
|
157
|
+
'justify-between': 'justify:between',
|
|
158
|
+
'justify-around': 'justify:around',
|
|
159
|
+
'justify-evenly': 'justify:evenly',
|
|
160
|
+
'justify-stretch': 'justify:stretch',
|
|
161
|
+
|
|
162
|
+
// Align items
|
|
163
|
+
'items-start': 'items:start',
|
|
164
|
+
'items-end': 'items:end',
|
|
165
|
+
'items-center': 'items:center',
|
|
166
|
+
'items-baseline': 'items:baseline',
|
|
167
|
+
'items-stretch': 'items:stretch',
|
|
168
|
+
|
|
169
|
+
// Align self
|
|
170
|
+
'self-auto': 'self:auto',
|
|
171
|
+
'self-start': 'self:start',
|
|
172
|
+
'self-end': 'self:end',
|
|
173
|
+
'self-center': 'self:center',
|
|
174
|
+
'self-stretch': 'self:stretch',
|
|
175
|
+
'self-baseline': 'self:baseline',
|
|
176
|
+
|
|
177
|
+
// Align content
|
|
178
|
+
'content-start': 'content:start',
|
|
179
|
+
'content-end': 'content:end',
|
|
180
|
+
'content-center': 'content:center',
|
|
181
|
+
'content-between': 'content:between',
|
|
182
|
+
'content-around': 'content:around',
|
|
183
|
+
'content-evenly': 'content:evenly',
|
|
184
|
+
'content-stretch': 'content:stretch',
|
|
185
|
+
|
|
186
|
+
// Shorthand alignment
|
|
187
|
+
'center': 'center',
|
|
188
|
+
|
|
189
|
+
// Position
|
|
190
|
+
'static': 'static',
|
|
191
|
+
'relative': 'relative',
|
|
192
|
+
'absolute': 'absolute',
|
|
193
|
+
'fixed': 'fixed',
|
|
194
|
+
'sticky': 'sticky',
|
|
195
|
+
|
|
196
|
+
// Visibility
|
|
197
|
+
'visible': 'visible',
|
|
198
|
+
'invisible': 'invisible',
|
|
199
|
+
'collapse': 'collapse',
|
|
200
|
+
|
|
201
|
+
// Overflow
|
|
202
|
+
'overflow-auto': 'overflow:auto',
|
|
203
|
+
'overflow-hidden': 'overflow:hidden',
|
|
204
|
+
'overflow-visible': 'overflow:visible',
|
|
205
|
+
'overflow-scroll': 'overflow:scroll',
|
|
206
|
+
'overflow-x-auto': 'overflow-x:auto',
|
|
207
|
+
'overflow-x-hidden': 'overflow-x:hidden',
|
|
208
|
+
'overflow-y-auto': 'overflow-y:auto',
|
|
209
|
+
'overflow-y-hidden': 'overflow-y:hidden',
|
|
210
|
+
|
|
211
|
+
// Object fit
|
|
212
|
+
'object-contain': 'object:contain',
|
|
213
|
+
'object-cover': 'object:cover',
|
|
214
|
+
'object-fill': 'object:fill',
|
|
215
|
+
'object-none': 'object:none',
|
|
216
|
+
'object-scale-down': 'object:scale-down',
|
|
217
|
+
|
|
218
|
+
// Box sizing
|
|
219
|
+
'box-border': 'box:border',
|
|
220
|
+
'box-content': 'box:content',
|
|
221
|
+
|
|
222
|
+
// Table
|
|
223
|
+
'table': 'table',
|
|
224
|
+
'table-auto': 'table:auto',
|
|
225
|
+
'table-fixed': 'table:fixed',
|
|
226
|
+
'border-collapse': 'border-collapse',
|
|
227
|
+
'border-separate': 'border-separate'
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// ======================
|
|
231
|
+
// VISUAL KEYWORD MAPPINGS
|
|
232
|
+
// ======================
|
|
233
|
+
const visualKeywordMappings = {
|
|
234
|
+
// Font style
|
|
235
|
+
'italic': 'italic',
|
|
236
|
+
'not-italic': 'not-italic',
|
|
237
|
+
|
|
238
|
+
// Font smoothing
|
|
239
|
+
'antialiased': 'antialiased',
|
|
240
|
+
'subpixel-antialiased': 'subpixel-antialiased',
|
|
241
|
+
|
|
242
|
+
// Text transform
|
|
243
|
+
'uppercase': 'uppercase',
|
|
244
|
+
'lowercase': 'lowercase',
|
|
245
|
+
'capitalize': 'capitalize',
|
|
246
|
+
'normal-case': 'normal-case',
|
|
247
|
+
|
|
248
|
+
// Text decoration
|
|
249
|
+
'underline': 'underline',
|
|
250
|
+
'overline': 'overline',
|
|
251
|
+
'line-through': 'line-through',
|
|
252
|
+
'no-underline': 'no-underline',
|
|
253
|
+
|
|
254
|
+
// Text decoration style
|
|
255
|
+
'decoration-solid': 'decoration-solid',
|
|
256
|
+
'decoration-double': 'decoration-double',
|
|
257
|
+
'decoration-dotted': 'decoration-dotted',
|
|
258
|
+
'decoration-dashed': 'decoration-dashed',
|
|
259
|
+
'decoration-wavy': 'decoration-wavy',
|
|
260
|
+
|
|
261
|
+
// Text overflow
|
|
262
|
+
'truncate': 'truncate',
|
|
263
|
+
'text-ellipsis': 'text-ellipsis',
|
|
264
|
+
'text-clip': 'text-clip',
|
|
265
|
+
|
|
266
|
+
// Text wrap
|
|
267
|
+
'text-wrap': 'text-wrap',
|
|
268
|
+
'text-nowrap': 'text-nowrap',
|
|
269
|
+
'text-balance': 'text-balance',
|
|
270
|
+
'text-pretty': 'text-pretty',
|
|
271
|
+
|
|
272
|
+
// Whitespace
|
|
273
|
+
'whitespace-normal': 'whitespace-normal',
|
|
274
|
+
'whitespace-nowrap': 'whitespace-nowrap',
|
|
275
|
+
'whitespace-pre': 'whitespace-pre',
|
|
276
|
+
'whitespace-pre-line': 'whitespace-pre-line',
|
|
277
|
+
'whitespace-pre-wrap': 'whitespace-pre-wrap',
|
|
278
|
+
'whitespace-break-spaces': 'whitespace-break-spaces',
|
|
279
|
+
|
|
280
|
+
// Word break
|
|
281
|
+
'break-normal': 'break-normal',
|
|
282
|
+
'break-words': 'break-words',
|
|
283
|
+
'break-all': 'break-all',
|
|
284
|
+
'break-keep': 'break-keep',
|
|
285
|
+
|
|
286
|
+
// Hyphens
|
|
287
|
+
'hyphens-none': 'hyphens-none',
|
|
288
|
+
'hyphens-manual': 'hyphens-manual',
|
|
289
|
+
'hyphens-auto': 'hyphens-auto',
|
|
290
|
+
|
|
291
|
+
// List style
|
|
292
|
+
'list-none': 'list-none',
|
|
293
|
+
'list-disc': 'list-disc',
|
|
294
|
+
'list-decimal': 'list-decimal',
|
|
295
|
+
'list-inside': 'list-inside',
|
|
296
|
+
'list-outside': 'list-outside',
|
|
297
|
+
|
|
298
|
+
// Cursor
|
|
299
|
+
'cursor-auto': 'cursor:auto',
|
|
300
|
+
'cursor-default': 'cursor:default',
|
|
301
|
+
'cursor-pointer': 'cursor:pointer',
|
|
302
|
+
'cursor-wait': 'cursor:wait',
|
|
303
|
+
'cursor-text': 'cursor:text',
|
|
304
|
+
'cursor-move': 'cursor:move',
|
|
305
|
+
'cursor-not-allowed': 'cursor:not-allowed',
|
|
306
|
+
'cursor-grab': 'cursor:grab',
|
|
307
|
+
'cursor-grabbing': 'cursor:grabbing',
|
|
308
|
+
|
|
309
|
+
// User select
|
|
310
|
+
'select-none': 'select:none',
|
|
311
|
+
'select-text': 'select:text',
|
|
312
|
+
'select-all': 'select:all',
|
|
313
|
+
'select-auto': 'select:auto',
|
|
314
|
+
|
|
315
|
+
// Pointer events
|
|
316
|
+
'pointer-events-none': 'pointer-events:none',
|
|
317
|
+
'pointer-events-auto': 'pointer-events:auto',
|
|
318
|
+
|
|
319
|
+
// Appearance
|
|
320
|
+
'appearance-none': 'appearance:none',
|
|
321
|
+
'appearance-auto': 'appearance:auto'
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// ======================
|
|
325
|
+
// CONVERTER FUNCTIONS
|
|
326
|
+
// ======================
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Get spacing scale value from Tailwind number
|
|
330
|
+
* @param {string} value - The Tailwind spacing value
|
|
331
|
+
* @param {Object} options - Conversion options
|
|
332
|
+
* @param {boolean} options.exact - If true, output tw-{value} prefix instead of semantic scale
|
|
333
|
+
*/
|
|
334
|
+
function getSpacingScale(value, options = {}) {
|
|
335
|
+
// Exact mode: output tw-{value} for Tailwind scale
|
|
336
|
+
if (options.exact) {
|
|
337
|
+
// Handle arbitrary values like [20px]
|
|
338
|
+
if (value.startsWith('[') && value.endsWith(']')) {
|
|
339
|
+
return value;
|
|
340
|
+
}
|
|
341
|
+
// Special keywords that don't map to tw- scale
|
|
342
|
+
const specialKeywords = ['full', 'screen', 'min', 'max', 'fit', 'auto'];
|
|
343
|
+
if (specialKeywords.includes(value)) {
|
|
344
|
+
const specialMap = {
|
|
345
|
+
'full': '[100%]',
|
|
346
|
+
'screen': '[100vw]',
|
|
347
|
+
'min': '[min-content]',
|
|
348
|
+
'max': '[max-content]',
|
|
349
|
+
'fit': '[fit-content]',
|
|
350
|
+
'auto': 'auto'
|
|
351
|
+
};
|
|
352
|
+
return specialMap[value];
|
|
353
|
+
}
|
|
354
|
+
// Output tw- prefix for numeric scale
|
|
355
|
+
return `tw-${value}`;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Semantic mode (default)
|
|
359
|
+
if (spacingScale[value]) {
|
|
360
|
+
return spacingScale[value];
|
|
361
|
+
}
|
|
362
|
+
// Handle arbitrary values like [20px]
|
|
363
|
+
if (value.startsWith('[') && value.endsWith(']')) {
|
|
364
|
+
return value;
|
|
365
|
+
}
|
|
366
|
+
// Unknown spacing, passthrough as arbitrary
|
|
367
|
+
return `[${value}]`;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Convert a single Tailwind class to SenangStart
|
|
372
|
+
* Returns { category: 'layout'|'space'|'visual'|null, value: string }
|
|
373
|
+
* @param {string} twClass - The Tailwind class to convert
|
|
374
|
+
* @param {Object} options - Conversion options
|
|
375
|
+
* @param {boolean} options.exact - If true, output tw-{value} prefix instead of semantic scale
|
|
376
|
+
*/
|
|
377
|
+
function convertClass(twClass, options = {}) {
|
|
378
|
+
// Handle prefixes (hover:, sm:, md:, etc.)
|
|
379
|
+
const prefixMatch = twClass.match(
|
|
380
|
+
/^(sm:|md:|lg:|xl:|2xl:|hover:|focus:|active:|disabled:|dark:)(.+)$/
|
|
381
|
+
);
|
|
382
|
+
let prefix = "",
|
|
383
|
+
baseClass = twClass;
|
|
384
|
+
if (prefixMatch) {
|
|
385
|
+
const rawPrefix = prefixMatch[1].slice(0, -1); // remove colon
|
|
386
|
+
if (['sm', 'md', 'lg', 'xl', '2xl'].includes(rawPrefix)) {
|
|
387
|
+
prefix = `tw-${rawPrefix}:`;
|
|
388
|
+
} else {
|
|
389
|
+
prefix = prefixMatch[1];
|
|
390
|
+
}
|
|
391
|
+
baseClass = prefixMatch[2];
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Layout mappings
|
|
395
|
+
if (layoutMappings[baseClass]) {
|
|
396
|
+
return { category: 'layout', value: prefix + layoutMappings[baseClass] };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Visual keywords
|
|
400
|
+
if (visualKeywordMappings[baseClass]) {
|
|
401
|
+
return { category: 'visual', value: prefix + visualKeywordMappings[baseClass] };
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Text color
|
|
405
|
+
const textColorMatch = baseClass.match(
|
|
406
|
+
/^text-((?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose|white|black|transparent|current|inherit)(?:-\d+)?)$/
|
|
407
|
+
);
|
|
408
|
+
if (textColorMatch)
|
|
409
|
+
return { category: 'visual', value: prefix + "text:" + textColorMatch[1] };
|
|
410
|
+
|
|
411
|
+
// Text alignment
|
|
412
|
+
if (
|
|
413
|
+
["text-left", "text-center", "text-right", "text-justify"].includes(
|
|
414
|
+
baseClass
|
|
415
|
+
)
|
|
416
|
+
)
|
|
417
|
+
return {
|
|
418
|
+
category: 'visual',
|
|
419
|
+
value: prefix + "text:" + baseClass.replace("text-", ""),
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// Text size
|
|
423
|
+
const textSizeMatch = baseClass.match(
|
|
424
|
+
/^text-(xs|sm|base|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl|8xl|9xl)$/
|
|
425
|
+
);
|
|
426
|
+
if (textSizeMatch) {
|
|
427
|
+
const size = options.exact
|
|
428
|
+
? `tw-${textSizeMatch[1]}`
|
|
429
|
+
: fontSizeScale[textSizeMatch[1]] || textSizeMatch[1];
|
|
430
|
+
return { category: 'visual', value: prefix + "text-size:" + size };
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Background color
|
|
434
|
+
const bgMatch = baseClass.match(
|
|
435
|
+
/^bg-((?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose|white|black|transparent|current|inherit)(?:-\d+)?)$/
|
|
436
|
+
);
|
|
437
|
+
if (bgMatch) return { category: 'visual', value: prefix + "bg:" + bgMatch[1] };
|
|
438
|
+
|
|
439
|
+
// Border color
|
|
440
|
+
const borderColorMatch = baseClass.match(
|
|
441
|
+
/^border-((?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose|white|black|transparent|current|inherit)(?:-\d+)?)$/
|
|
442
|
+
);
|
|
443
|
+
if (borderColorMatch)
|
|
444
|
+
return {
|
|
445
|
+
category: 'visual',
|
|
446
|
+
value: prefix + "border:" + borderColorMatch[1],
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
// Padding
|
|
450
|
+
const paddingMatch = baseClass.match(/^p([trblxy])?-(.+)$/);
|
|
451
|
+
if (paddingMatch) {
|
|
452
|
+
const side = paddingMatch[1] ? "-" + paddingMatch[1] : "";
|
|
453
|
+
return {
|
|
454
|
+
category: 'space',
|
|
455
|
+
value: prefix + "p" + side + ":" + getSpacingScale(paddingMatch[2], options),
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// Margin
|
|
460
|
+
const marginMatch = baseClass.match(
|
|
461
|
+
/^-?m([trblxy])?-(\d+\.?\d*|px|auto|full|screen)$/
|
|
462
|
+
);
|
|
463
|
+
if (marginMatch) {
|
|
464
|
+
const isNeg = baseClass.startsWith("-");
|
|
465
|
+
const side = marginMatch[1] ? "-" + marginMatch[1] : "";
|
|
466
|
+
let val = getSpacingScale(marginMatch[2], options);
|
|
467
|
+
if (isNeg) val = "[-" + val + "]";
|
|
468
|
+
return { category: 'space', value: prefix + "m" + side + ":" + val };
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// Gap
|
|
472
|
+
const gapMatch = baseClass.match(/^gap-([xy])?-?(.+)$/);
|
|
473
|
+
if (gapMatch) {
|
|
474
|
+
const axis = gapMatch[1] ? "-" + gapMatch[1] : "";
|
|
475
|
+
return {
|
|
476
|
+
category: 'space',
|
|
477
|
+
value: prefix + "g" + axis + ":" + getSpacingScale(gapMatch[2], options),
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// Width/Height with special values
|
|
482
|
+
const widthMatch = baseClass.match(/^(min-w|max-w|w)-(.+)$/);
|
|
483
|
+
if (widthMatch) {
|
|
484
|
+
const prop = widthMatch[1];
|
|
485
|
+
const rawVal = widthMatch[2];
|
|
486
|
+
// Special width values
|
|
487
|
+
const specialWidthVals = { 'max': '[max-content]', 'min': '[min-content]', 'fit': '[fit-content]', 'prose': '[65ch]' };
|
|
488
|
+
const val = specialWidthVals[rawVal] || getSpacingScale(rawVal, options);
|
|
489
|
+
return { category: 'space', value: prefix + prop + ":" + val };
|
|
490
|
+
}
|
|
491
|
+
const heightMatch = baseClass.match(/^(min-h|max-h|h)-(.+)$/);
|
|
492
|
+
if (heightMatch) {
|
|
493
|
+
const prop = heightMatch[1];
|
|
494
|
+
const rawVal = heightMatch[2];
|
|
495
|
+
const specialHeightVals = { 'screen': '[100vh]', 'svh': '[100svh]', 'lvh': '[100lvh]', 'dvh': '[100dvh]', 'max': '[max-content]', 'min': '[min-content]', 'fit': '[fit-content]' };
|
|
496
|
+
const val = specialHeightVals[rawVal] || getSpacingScale(rawVal, options);
|
|
497
|
+
return { category: 'space', value: prefix + prop + ":" + val };
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Border radius
|
|
501
|
+
const roundedMatch = baseClass.match(/^rounded(?:-(.+))?$/);
|
|
502
|
+
if (roundedMatch) {
|
|
503
|
+
const size = roundedMatch[1] || "";
|
|
504
|
+
const scale = options.exact
|
|
505
|
+
? size === ""
|
|
506
|
+
? "tw-DEFAULT"
|
|
507
|
+
: `tw-${size}`
|
|
508
|
+
: radiusScale[size] || "medium";
|
|
509
|
+
return { category: 'visual', value: prefix + "rounded:" + scale };
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// Shadow
|
|
513
|
+
const shadowMatch = baseClass.match(/^shadow(?:-(.+))?$/);
|
|
514
|
+
if (shadowMatch) {
|
|
515
|
+
const size = shadowMatch[1] || "";
|
|
516
|
+
const scale = options.exact
|
|
517
|
+
? size === ""
|
|
518
|
+
? "tw-DEFAULT"
|
|
519
|
+
: `tw-${size}`
|
|
520
|
+
: shadowScale[size] || "medium";
|
|
521
|
+
return { category: 'visual', value: prefix + "shadow:" + scale };
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Font weight
|
|
525
|
+
const fontWeightMatch = baseClass.match(
|
|
526
|
+
/^font-(thin|extralight|light|normal|medium|semibold|bold|extrabold|black)$/
|
|
527
|
+
);
|
|
528
|
+
if (fontWeightMatch)
|
|
529
|
+
return { category: 'visual', value: prefix + "font:tw-" + fontWeightMatch[1] };
|
|
530
|
+
|
|
531
|
+
// Border width
|
|
532
|
+
const borderWidthMatch = baseClass.match(
|
|
533
|
+
/^border(?:-([trblxy]))?(?:-(\d+))?$/
|
|
534
|
+
);
|
|
535
|
+
if (
|
|
536
|
+
borderWidthMatch &&
|
|
537
|
+
(borderWidthMatch[2] ||
|
|
538
|
+
(!borderWidthMatch[1] && baseClass === "border"))
|
|
539
|
+
) {
|
|
540
|
+
const side = borderWidthMatch[1]
|
|
541
|
+
? "-" + borderWidthMatch[1] + "-w"
|
|
542
|
+
: "-w";
|
|
543
|
+
const width = borderWidthMatch[2] || "1";
|
|
544
|
+
return {
|
|
545
|
+
category: 'visual',
|
|
546
|
+
value: prefix + "border" + side + ":[" + width + "px]",
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// Order
|
|
551
|
+
const orderMatch = baseClass.match(/^order-(\d+|first|last|none)$/);
|
|
552
|
+
if (orderMatch) {
|
|
553
|
+
return { category: 'layout', value: prefix + "order:" + orderMatch[1] };
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Grid columns
|
|
557
|
+
const gridColsMatch = baseClass.match(/^grid-cols-(\d+|none)$/);
|
|
558
|
+
if (gridColsMatch) {
|
|
559
|
+
return { category: 'layout', value: prefix + "grid-cols:" + gridColsMatch[1] };
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// Column span
|
|
563
|
+
const colSpanMatch = baseClass.match(/^col-span-(\d+|full)$/);
|
|
564
|
+
if (colSpanMatch) {
|
|
565
|
+
return { category: 'layout', value: prefix + "col-span:" + colSpanMatch[1] };
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// Grid rows
|
|
569
|
+
const gridRowsMatch = baseClass.match(/^grid-rows-(\d+|none)$/);
|
|
570
|
+
if (gridRowsMatch) {
|
|
571
|
+
return { category: 'layout', value: prefix + "grid-rows:" + gridRowsMatch[1] };
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// Row span
|
|
575
|
+
const rowSpanMatch = baseClass.match(/^row-span-(\d+|full)$/);
|
|
576
|
+
if (rowSpanMatch) {
|
|
577
|
+
return { category: 'layout', value: prefix + "row-span:" + rowSpanMatch[1] };
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// Opacity
|
|
581
|
+
const opacityMatch = baseClass.match(/^opacity-(\d+)$/);
|
|
582
|
+
if (opacityMatch) {
|
|
583
|
+
return { category: 'visual', value: prefix + "opacity:" + opacityMatch[1] };
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return null;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Convert HTML string with Tailwind classes to SenangStart syntax
|
|
591
|
+
*/
|
|
592
|
+
export function convertHTML(html, options = {}) {
|
|
593
|
+
// Match elements with class attribute
|
|
594
|
+
const classRegex = /class\s*=\s*["']([^"']+)["']/gi;
|
|
595
|
+
|
|
596
|
+
let result = html;
|
|
597
|
+
let match;
|
|
598
|
+
|
|
599
|
+
// Find all class attributes
|
|
600
|
+
const matches = [];
|
|
601
|
+
while ((match = classRegex.exec(html)) !== null) {
|
|
602
|
+
matches.push({
|
|
603
|
+
full: match[0],
|
|
604
|
+
classes: match[1],
|
|
605
|
+
index: match.index
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Process in reverse to maintain indices
|
|
610
|
+
for (let i = matches.length - 1; i >= 0; i--) {
|
|
611
|
+
const m = matches[i];
|
|
612
|
+
const converted = convertClasses(m.classes, options);
|
|
613
|
+
|
|
614
|
+
// Build replacement attributes
|
|
615
|
+
const attrs = [];
|
|
616
|
+
if (converted.layout.length > 0) {
|
|
617
|
+
attrs.push(`layout="${converted.layout.join(' ')}"`);
|
|
618
|
+
}
|
|
619
|
+
if (converted.space.length > 0) {
|
|
620
|
+
attrs.push(`space="${converted.space.join(' ')}"`);
|
|
621
|
+
}
|
|
622
|
+
if (converted.visual.length > 0) {
|
|
623
|
+
attrs.push(`visual="${converted.visual.join(' ')}"`);
|
|
624
|
+
}
|
|
625
|
+
if (converted.unrecognized.length > 0) {
|
|
626
|
+
attrs.push(`class="${converted.unrecognized.join(' ')}"`);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const replacement = attrs.join(' ');
|
|
630
|
+
result = result.slice(0, m.index) + replacement + result.slice(m.index + m.full.length);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
return result;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Convert a class string to categorized SenangStart values
|
|
638
|
+
* @param {string} classString - Space-separated Tailwind classes
|
|
639
|
+
* @param {Object} options - Conversion options
|
|
640
|
+
* @param {boolean} options.exact - If true, output tw-{value} prefix instead of semantic scale
|
|
641
|
+
*/
|
|
642
|
+
export function convertClasses(classString, options = {}) {
|
|
643
|
+
const classes = classString.trim().split(/\s+/);
|
|
644
|
+
|
|
645
|
+
const result = {
|
|
646
|
+
layout: [],
|
|
647
|
+
space: [],
|
|
648
|
+
visual: [],
|
|
649
|
+
unrecognized: []
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
for (const cls of classes) {
|
|
653
|
+
if (!cls) continue;
|
|
654
|
+
|
|
655
|
+
const converted = convertClass(cls, options);
|
|
656
|
+
|
|
657
|
+
if (converted) {
|
|
658
|
+
result[converted.category].push(converted.value);
|
|
659
|
+
} else {
|
|
660
|
+
result.unrecognized.push(cls);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
return result;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* CLI entry point
|
|
669
|
+
*/
|
|
670
|
+
function main() {
|
|
671
|
+
const args = argv.slice(2);
|
|
672
|
+
|
|
673
|
+
// Parse --exact flag
|
|
674
|
+
const exactMode = args.includes('--exact') || args.includes('-e');
|
|
675
|
+
const options = { exact: exactMode };
|
|
676
|
+
|
|
677
|
+
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
|
|
678
|
+
console.log(`
|
|
679
|
+
Tailwind CSS to SenangStart CSS Converter
|
|
680
|
+
|
|
681
|
+
Usage:
|
|
682
|
+
node scripts/convert-tailwind.js <input.html> [-o <output.html>]
|
|
683
|
+
node scripts/convert-tailwind.js --string "<div class='flex'>"
|
|
684
|
+
|
|
685
|
+
Options:
|
|
686
|
+
-o, --output Output file path (default: stdout)
|
|
687
|
+
--string Convert a single HTML string
|
|
688
|
+
-e, --exact Use Tailwind numeric scale with tw- prefix (e.g., p:tw-4)
|
|
689
|
+
-h, --help Show this help message
|
|
690
|
+
|
|
691
|
+
Examples:
|
|
692
|
+
node scripts/convert-tailwind.js template.html -o converted.html
|
|
693
|
+
node scripts/convert-tailwind.js --string "<div class='flex items-center p-4'>"
|
|
694
|
+
node scripts/convert-tailwind.js --exact --string "<div class='p-4 rounded-lg'>"
|
|
695
|
+
`);
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// String mode
|
|
700
|
+
if (args.includes('--string')) {
|
|
701
|
+
const stringIndex = args.indexOf('--string');
|
|
702
|
+
const htmlString = args[stringIndex + 1];
|
|
703
|
+
|
|
704
|
+
if (!htmlString) {
|
|
705
|
+
console.error('Error: --string requires an HTML string argument');
|
|
706
|
+
process.exit(1);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
const result = convertHTML(htmlString, options);
|
|
710
|
+
console.log(result);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// File mode
|
|
715
|
+
const inputFile = args.find(arg => !arg.startsWith('-') && args.indexOf(arg) !== args.indexOf('-o') + 1 && args.indexOf(arg) !== args.indexOf('--output') + 1);
|
|
716
|
+
|
|
717
|
+
if (!inputFile) {
|
|
718
|
+
console.error('Error: Input file required');
|
|
719
|
+
process.exit(1);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
let outputFile = null;
|
|
723
|
+
const outputIndex = args.indexOf('-o') !== -1 ? args.indexOf('-o') : args.indexOf('--output');
|
|
724
|
+
if (outputIndex !== -1 && args[outputIndex + 1]) {
|
|
725
|
+
outputFile = args[outputIndex + 1];
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
try {
|
|
729
|
+
if (!isValidFilePath(inputFile)) {
|
|
730
|
+
console.error(`Error: File path outside allowed directory: ${inputFile}`);
|
|
731
|
+
process.exit(1);
|
|
732
|
+
}
|
|
733
|
+
const input = readFileSync(inputFile, 'utf-8');
|
|
734
|
+
const result = convertHTML(input, options);
|
|
735
|
+
|
|
736
|
+
if (outputFile) {
|
|
737
|
+
if (!isValidFilePath(outputFile)) {
|
|
738
|
+
console.error(`Error: Output file path outside allowed directory: ${outputFile}`);
|
|
739
|
+
process.exit(1);
|
|
740
|
+
}
|
|
741
|
+
writeFileSync(outputFile, result);
|
|
742
|
+
console.log(`Converted: ${inputFile} -> ${outputFile}`);
|
|
743
|
+
} else {
|
|
744
|
+
console.log(result);
|
|
745
|
+
}
|
|
746
|
+
} catch (error) {
|
|
747
|
+
console.error(`Error: ${error.message}`);
|
|
748
|
+
process.exit(1);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// Run CLI if executed directly
|
|
753
|
+
if (import.meta.url === `file://${process.argv[1].replace(/\\/g, '/')}` ||
|
|
754
|
+
process.argv[1]?.endsWith('convert-tailwind.js')) {
|
|
755
|
+
main();
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// Export for testing
|
|
759
|
+
export { convertClass, spacingScale, layoutMappings, visualKeywordMappings };
|