@hypen-space/web 0.2.7 → 0.2.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypen-space/web",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "Hypen web renderers - DOM and Canvas rendering for browsers",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",
@@ -48,7 +48,7 @@
48
48
  "clean": "rm -rf dist"
49
49
  },
50
50
  "dependencies": {
51
- "@hypen-space/core": "^0.2.7"
51
+ "@hypen-space/core": "^0.2.9"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/bun": "latest",
@@ -47,6 +47,25 @@ export const advancedLayoutHandlers: Record<string, ApplicatorHandler> = {
47
47
  el.style.gridTemplateRows = String(value);
48
48
  },
49
49
 
50
+ // Unified API aliases (simpler names)
51
+ gridColumns: (el, value) => {
52
+ // Support number (repeat) or string (CSS value)
53
+ if (typeof value === "number") {
54
+ el.style.gridTemplateColumns = `repeat(${value}, 1fr)`;
55
+ } else {
56
+ el.style.gridTemplateColumns = String(value);
57
+ }
58
+ },
59
+
60
+ gridRows: (el, value) => {
61
+ // Support number (repeat) or string (CSS value)
62
+ if (typeof value === "number") {
63
+ el.style.gridTemplateRows = `repeat(${value}, 1fr)`;
64
+ } else {
65
+ el.style.gridTemplateRows = String(value);
66
+ }
67
+ },
68
+
50
69
  gridTemplateAreas: (el, value) => {
51
70
  el.style.gridTemplateAreas = String(value);
52
71
  },
@@ -5,6 +5,43 @@
5
5
  import type { ApplicatorHandler } from "./index.js";
6
6
 
7
7
  export const borderHandlers: Record<string, ApplicatorHandler> = {
8
+ // Compound border applicator - can take width, color, style, radius
9
+ border: (el, value) => {
10
+ if (typeof value === "number") {
11
+ // Just width
12
+ el.style.borderWidth = `${value}px`;
13
+ el.style.borderStyle = "solid";
14
+ } else if (typeof value === "object" && value !== null) {
15
+ const obj = value as Record<string, any>;
16
+
17
+ // Width
18
+ if (obj.width !== undefined) {
19
+ el.style.borderWidth = typeof obj.width === "number" ? `${obj.width}px` : String(obj.width);
20
+ }
21
+
22
+ // Color
23
+ if (obj.color !== undefined) {
24
+ el.style.borderColor = String(obj.color);
25
+ }
26
+
27
+ // Style (solid, dashed, dotted, etc.)
28
+ if (obj.style !== undefined) {
29
+ el.style.borderStyle = String(obj.style);
30
+ } else {
31
+ // Default to solid if not specified
32
+ el.style.borderStyle = "solid";
33
+ }
34
+
35
+ // Radius
36
+ if (obj.radius !== undefined) {
37
+ el.style.borderRadius = typeof obj.radius === "number" ? `${obj.radius}px` : String(obj.radius);
38
+ }
39
+ } else if (typeof value === "string") {
40
+ // CSS shorthand like "1px solid black"
41
+ el.style.border = value;
42
+ }
43
+ },
44
+
8
45
  borderWidth: (el, value) => {
9
46
  el.style.borderWidth = typeof value === "number" ? `${value}px` : String(value);
10
47
  },
@@ -14,6 +51,38 @@ export const borderHandlers: Record<string, ApplicatorHandler> = {
14
51
  },
15
52
 
16
53
  borderRadius: (el, value) => {
17
- el.style.borderRadius = typeof value === "number" ? `${value}px` : String(value);
54
+ if (typeof value === "number") {
55
+ el.style.borderRadius = `${value}px`;
56
+ } else if (typeof value === "object" && value !== null) {
57
+ // Support for individual corners
58
+ const obj = value as Record<string, any>;
59
+ const topLeft = obj.topLeft ?? obj.topStart ?? 0;
60
+ const topRight = obj.topRight ?? obj.topEnd ?? 0;
61
+ const bottomRight = obj.bottomRight ?? obj.bottomEnd ?? 0;
62
+ const bottomLeft = obj.bottomLeft ?? obj.bottomStart ?? 0;
63
+
64
+ const formatValue = (v: any) => typeof v === "number" ? `${v}px` : String(v);
65
+ el.style.borderRadius = `${formatValue(topLeft)} ${formatValue(topRight)} ${formatValue(bottomRight)} ${formatValue(bottomLeft)}`;
66
+ } else {
67
+ el.style.borderRadius = String(value);
68
+ }
69
+ },
70
+
71
+ // Alias for borderRadius (Compose naming)
72
+ cornerRadius: (el, value) => {
73
+ if (typeof value === "number") {
74
+ el.style.borderRadius = `${value}px`;
75
+ } else if (typeof value === "object" && value !== null) {
76
+ const obj = value as Record<string, any>;
77
+ const topLeft = obj.topLeft ?? obj.topStart ?? 0;
78
+ const topRight = obj.topRight ?? obj.topEnd ?? 0;
79
+ const bottomRight = obj.bottomRight ?? obj.bottomEnd ?? 0;
80
+ const bottomLeft = obj.bottomLeft ?? obj.bottomStart ?? 0;
81
+
82
+ const formatValue = (v: any) => typeof v === "number" ? `${v}px` : String(v);
83
+ el.style.borderRadius = `${formatValue(topLeft)} ${formatValue(topRight)} ${formatValue(bottomRight)} ${formatValue(bottomLeft)}`;
84
+ } else {
85
+ el.style.borderRadius = String(value);
86
+ }
18
87
  },
19
88
  };
@@ -28,4 +28,50 @@ export const sizeHandlers: Record<string, ApplicatorHandler> = {
28
28
  maxHeight: (el, value) => {
29
29
  el.style.maxHeight = typeof value === "number" ? `${value}px` : String(value);
30
30
  },
31
+
32
+ // Combined size applicator - sets both width and height
33
+ size: (el, value) => {
34
+ if (typeof value === "number") {
35
+ el.style.width = `${value}px`;
36
+ el.style.height = `${value}px`;
37
+ } else if (typeof value === "object" && value !== null) {
38
+ const obj = value as Record<string, any>;
39
+ if (obj.width !== undefined) {
40
+ el.style.width = typeof obj.width === "number" ? `${obj.width}px` : String(obj.width);
41
+ }
42
+ if (obj.height !== undefined) {
43
+ el.style.height = typeof obj.height === "number" ? `${obj.height}px` : String(obj.height);
44
+ }
45
+ } else {
46
+ // Single value for both
47
+ const size = String(value);
48
+ el.style.width = size;
49
+ el.style.height = size;
50
+ }
51
+ },
52
+
53
+ // Fill max width - shorthand for width: 100%
54
+ fillMaxWidth: (el, value) => {
55
+ if (value === false) return;
56
+ // Value can be a fraction (0-1) or boolean
57
+ const fraction = typeof value === "number" ? value : 1;
58
+ el.style.width = `${fraction * 100}%`;
59
+ },
60
+
61
+ // Fill max height - shorthand for height: 100%
62
+ fillMaxHeight: (el, value) => {
63
+ if (value === false) return;
64
+ // Value can be a fraction (0-1) or boolean
65
+ const fraction = typeof value === "number" ? value : 1;
66
+ el.style.height = `${fraction * 100}%`;
67
+ },
68
+
69
+ // Fill max size - shorthand for width: 100% and height: 100%
70
+ fillMaxSize: (el, value) => {
71
+ if (value === false) return;
72
+ // Value can be a fraction (0-1) or boolean
73
+ const fraction = typeof value === "number" ? value : 1;
74
+ el.style.width = `${fraction * 100}%`;
75
+ el.style.height = `${fraction * 100}%`;
76
+ },
31
77
  };