@k9kbdev/roblox-css 0.1.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.
Files changed (55) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +245 -0
  3. package/default.project.json +6 -0
  4. package/out/index.d.ts +35 -0
  5. package/out/init.luau +57 -0
  6. package/out/logger.d.ts +23 -0
  7. package/out/logger.luau +73 -0
  8. package/out/primitives/Box.d.ts +23 -0
  9. package/out/primitives/Box.luau +103 -0
  10. package/out/primitives/Button.d.ts +62 -0
  11. package/out/primitives/Button.luau +170 -0
  12. package/out/primitives/Image.d.ts +37 -0
  13. package/out/primitives/Image.luau +79 -0
  14. package/out/primitives/InlineText.d.ts +25 -0
  15. package/out/primitives/InlineText.luau +273 -0
  16. package/out/primitives/Input.d.ts +59 -0
  17. package/out/primitives/Input.luau +126 -0
  18. package/out/primitives/MotionBox.d.ts +15 -0
  19. package/out/primitives/MotionBox.luau +69 -0
  20. package/out/primitives/MotionButton.d.ts +15 -0
  21. package/out/primitives/MotionButton.luau +146 -0
  22. package/out/primitives/MotionImage.d.ts +13 -0
  23. package/out/primitives/MotionImage.luau +70 -0
  24. package/out/primitives/MotionText.d.ts +12 -0
  25. package/out/primitives/MotionText.luau +116 -0
  26. package/out/primitives/MotionUIScale.d.ts +9 -0
  27. package/out/primitives/MotionUIScale.luau +48 -0
  28. package/out/primitives/ScrollBox.d.ts +25 -0
  29. package/out/primitives/ScrollBox.luau +69 -0
  30. package/out/primitives/Text.d.ts +50 -0
  31. package/out/primitives/Text.luau +139 -0
  32. package/out/primitives/usePercentageConstraints.d.ts +3 -0
  33. package/out/primitives/usePercentageConstraints.luau +112 -0
  34. package/out/primitives/useVariantResolver.d.ts +13 -0
  35. package/out/primitives/useVariantResolver.luau +260 -0
  36. package/out/styles/CSSTypes.d.ts +96 -0
  37. package/out/styles/ParentSizeContext.d.ts +6 -0
  38. package/out/styles/ParentSizeContext.luau +13 -0
  39. package/out/styles/colorParser.d.ts +28 -0
  40. package/out/styles/colorParser.luau +229 -0
  41. package/out/styles/dimensionParser.d.ts +49 -0
  42. package/out/styles/dimensionParser.luau +205 -0
  43. package/out/styles/gradientParser.d.ts +9 -0
  44. package/out/styles/gradientParser.luau +434 -0
  45. package/out/styles/namedColors.d.ts +7 -0
  46. package/out/styles/namedColors.luau +162 -0
  47. package/out/styles/transitions.d.ts +18 -0
  48. package/out/styles/transitions.luau +19 -0
  49. package/out/styles/webStyle.d.ts +74 -0
  50. package/out/styles/webStyle.luau +973 -0
  51. package/out/types.d.ts +4 -0
  52. package/out/types.luau +3 -0
  53. package/out/utils/parseInlineImages.d.ts +20 -0
  54. package/out/utils/parseInlineImages.luau +93 -0
  55. package/package.json +56 -0
@@ -0,0 +1,74 @@
1
+ /**
2
+ * webStyle.ts — Core CSS → Roblox translation engine.
3
+ *
4
+ * Takes a CSSProperties object and produces:
5
+ * 1. Roblox instance properties (Size, BackgroundColor3, etc.)
6
+ * 2. Child instances to inject (UICorner, UIPadding, UIListLayout, UIStroke)
7
+ *
8
+ * This is the heart of the middleware — the function that makes
9
+ * <Box style={{ borderRadius: 10 }}> automatically inject a <uicorner>.
10
+ *
11
+ * Translation mapping:
12
+ * CSS Property → Roblox Output
13
+ * ─────────────────────────────────────────────────────────
14
+ * width / height → Size (UDim2)
15
+ * backgroundColor → BackgroundColor3 + BackgroundTransparency
16
+ * opacity → BackgroundTransparency (inverted: 1 - opacity)
17
+ * borderRadius → <uicorner> child (CornerRadius)
18
+ * padding / padding* → <uipadding> child (PaddingTop/Right/Bottom/Left)
19
+ * display: "flex" → <uilistlayout> child (FillDirection, alignment, gap)
20
+ * border → <uistroke> child (Thickness, Color)
21
+ * position: "absolute"→ Position (UDim2) + AnchorPoint (Vector2)
22
+ */
23
+ import type { CSSProperties } from "./CSSTypes";
24
+ import { DeepReadonly } from "../types";
25
+ import React from "@rbxts/react";
26
+ export type { CSSProperties };
27
+ /**
28
+ * Branded WebStyleResult — the `_parsed` brand ensures only values produced by
29
+ * webStyle() are assignable. A plain `{ props, children }` object will NOT
30
+ * satisfy this type, catching accidental bypasses at compile time.
31
+ *
32
+ * - `props`: Roblox instance properties to spread onto the host element
33
+ * - `children`: UI constraint elements to inject (<uicorner>, <uipadding>, etc.)
34
+ */
35
+ export type WebStyleResult = {
36
+ readonly props: Record<string, unknown>;
37
+ readonly children: React.Element[];
38
+ } & {
39
+ readonly _parsed: unique symbol;
40
+ };
41
+ /**
42
+ * Default shadow asset for boxShadow emulation.
43
+ *
44
+ * This is a 9-slice shadow sprite from the Roblox Creator Marketplace:
45
+ * https://create.roblox.com/store/asset/6015897843
46
+ *
47
+ * SliceCenter is hardcoded to Rect(47, 47, 450, 450) to match this specific
48
+ * asset's padding region. If you change the asset, update SHADOW_SLICE_CENTER
49
+ * accordingly.
50
+ *
51
+ * To use a custom shadow asset project-wide, set `SHADOW_ASSET_ID` and
52
+ * `SHADOW_SLICE_CENTER` before any UI renders.
53
+ */
54
+ export declare const SHADOW_ASSET_ID = "rbxassetid://6015897843";
55
+ export declare const SHADOW_SLICE_CENTER: Rect;
56
+ /**
57
+ * Translates a CSSProperties object into Roblox-compatible props and child elements.
58
+ *
59
+ * This is the primary entry point for the CSS → Roblox translation layer.
60
+ * Wrapper components (Box, Text, etc.) call this function with their `style` prop
61
+ * and spread the resulting `props` onto the host instance while injecting `children`
62
+ * as UI constraint siblings.
63
+ *
64
+ * @param style - A CSSProperties object from the component's style prop.
65
+ * @returns A branded WebStyleResult containing:
66
+ * - `props`: Record of Roblox instance properties (Size, BackgroundColor3, Position, etc.)
67
+ * - `children`: Array of React elements for UI constraints (<uicorner>, <uipadding>, etc.)
68
+ *
69
+ * @example
70
+ * const result = webStyle({ width: "50%", backgroundColor: "#333", borderRadius: 8 });
71
+ * // result.props → { Size: UDim2(...), BackgroundColor3: Color3(...) }
72
+ * // result.children → [ <uicorner CornerRadius={UDim(0, 8)} /> ]
73
+ */
74
+ export declare function webStyle(style: CSSProperties): DeepReadonly<WebStyleResult>;