@viewscript/browser-defaults 0.1.0-202605140639

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.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Browser Default Constraint Modules
3
+ *
4
+ * Provides the default CSS/HTML layout constraints for each browser engine
5
+ * as ViewScript IR modules.
6
+ */
7
+ export type BrowserEngine = 'chromium' | 'firefox' | 'webkit';
8
+ export interface BrowserDefaultModule {
9
+ engine: BrowserEngine;
10
+ version: string;
11
+ constraints: unknown[];
12
+ }
13
+ export declare function loadBrowserDefaults(engine: BrowserEngine): Promise<BrowserDefaultModule>;
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Browser Default Constraint Modules
3
+ *
4
+ * Provides the default CSS/HTML layout constraints for each browser engine
5
+ * as ViewScript IR modules.
6
+ */
7
+ export async function loadBrowserDefaults(engine) {
8
+ // TODO: Load browser-specific default constraints
9
+ return {
10
+ engine,
11
+ version: '1.0.0',
12
+ constraints: [],
13
+ };
14
+ }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@viewscript/browser-defaults",
3
+ "version": "0.1.0-202605140639",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "test": "vitest run"
10
+ },
11
+ "devDependencies": {
12
+ "typescript": "^5.4.0",
13
+ "vitest": "^1.6.0"
14
+ }
15
+ }
@@ -0,0 +1,118 @@
1
+ // =============================================================================
2
+ // ViewScript Standard Library: RoundedRect Component
3
+ // =============================================================================
4
+ //
5
+ // A rounded rectangle composed of 8 tangent points (where arcs meet edges),
6
+ // 4 corner arcs, and connecting line segments.
7
+ //
8
+ // ## Geometry
9
+ //
10
+ // tl_top tr_top
11
+ // ●━━━━━━━━━━━━━━━━━━━━━●
12
+ // ╱ ╲
13
+ // tl_left ● (arc_tl) (arc_tr)● tr_right
14
+ // │ │
15
+ // │ │
16
+ // │ │
17
+ // bl_left ● (arc_bl) (arc_br)● br_right
18
+ // ╲ ╱
19
+ // ●━━━━━━━━━━━━━━━━━━━━━●
20
+ // bl_bottom br_bottom
21
+ //
22
+ // ## Parameters
23
+ // - x: X position of top-left corner (default: 0)
24
+ // - y: Y position of top-left corner (default: 0)
25
+ // - width: Width of rectangle (default: 100)
26
+ // - height: Height of rectangle (default: 50)
27
+ // - corner_radius: Default corner radius for all corners (default: 10)
28
+ // - radius_tl: Top-left corner radius (overrides corner_radius)
29
+ // - radius_tr: Top-right corner radius (overrides corner_radius)
30
+ // - radius_br: Bottom-right corner radius (overrides corner_radius)
31
+ // - radius_bl: Bottom-left corner radius (overrides corner_radius)
32
+ //
33
+ // ## Constraints
34
+ // - Corner radius constraints are Soft (can be overridden)
35
+ // - Edge alignment constraints are Hard (structural)
36
+ //
37
+ // ## Usage
38
+ // import RoundedRect from "@viewscript/components/RoundedRect.vs"
39
+ //
40
+ // const button = RoundedRect({ x: 10, y: 10, width: 120, height: 40 })
41
+ // // Override top-right corner to be sharp (no rounding)
42
+ // constraint button.radius_tr = 0
43
+ //
44
+
45
+ export component RoundedRect {
46
+ // Position and size parameters
47
+ param x: Rational = 0
48
+ param y: Rational = 0
49
+ param width: Rational = 100
50
+ param height: Rational = 50
51
+
52
+ // Corner radius parameters (Soft: can be overridden individually)
53
+ param corner_radius: Rational = 10
54
+ param radius_tl: Rational = corner_radius
55
+ param radius_tr: Rational = corner_radius
56
+ param radius_br: Rational = corner_radius
57
+ param radius_bl: Rational = corner_radius
58
+
59
+ // 8 tangent points where arcs meet straight edges
60
+ controlpoint tl_top { role: anchor }
61
+ controlpoint tl_left { role: anchor }
62
+ controlpoint tr_top { role: anchor }
63
+ controlpoint tr_right { role: anchor }
64
+ controlpoint br_right { role: anchor }
65
+ controlpoint br_bottom { role: anchor }
66
+ controlpoint bl_bottom { role: anchor }
67
+ controlpoint bl_left { role: anchor }
68
+
69
+ // Top-left corner constraints
70
+ constraint tl_top.x = x + radius_tl { priority: soft }
71
+ constraint tl_top.y = y { priority: hard }
72
+ constraint tl_left.x = x { priority: hard }
73
+ constraint tl_left.y = y + radius_tl { priority: soft }
74
+
75
+ // Top-right corner constraints
76
+ constraint tr_top.x = x + width - radius_tr { priority: soft }
77
+ constraint tr_top.y = y { priority: hard }
78
+ constraint tr_right.x = x + width { priority: hard }
79
+ constraint tr_right.y = y + radius_tr { priority: soft }
80
+
81
+ // Bottom-right corner constraints
82
+ constraint br_right.x = x + width { priority: hard }
83
+ constraint br_right.y = y + height - radius_br { priority: soft }
84
+ constraint br_bottom.x = x + width - radius_br { priority: soft }
85
+ constraint br_bottom.y = y + height { priority: hard }
86
+
87
+ // Bottom-left corner constraints
88
+ constraint bl_bottom.x = x + radius_bl { priority: soft }
89
+ constraint bl_bottom.y = y + height { priority: hard }
90
+ constraint bl_left.x = x { priority: hard }
91
+ constraint bl_left.y = y + height - radius_bl { priority: soft }
92
+
93
+ // Edge alignment constraints (Hard: structural integrity)
94
+ // Top edge is horizontal
95
+ constraint tl_top.y = tr_top.y { priority: hard }
96
+ // Bottom edge is horizontal
97
+ constraint bl_bottom.y = br_bottom.y { priority: hard }
98
+ // Left edge is vertical
99
+ constraint tl_left.x = bl_left.x { priority: hard }
100
+ // Right edge is vertical
101
+ constraint tr_right.x = br_right.x { priority: hard }
102
+
103
+ // Exported ports
104
+ export tl_top
105
+ export tl_left
106
+ export tr_top
107
+ export tr_right
108
+ export br_right
109
+ export br_bottom
110
+ export bl_bottom
111
+ export bl_left
112
+
113
+ // Radius scalar exports (for overriding from parent)
114
+ export radius_tl
115
+ export radius_tr
116
+ export radius_br
117
+ export radius_bl
118
+ }
@@ -0,0 +1,71 @@
1
+ // =============================================================================
2
+ // ViewScript Standard Library: Text Component
3
+ // =============================================================================
4
+ //
5
+ // A text entity with 4 bounding box control points (TL, TR, BL, BR).
6
+ // This component is a macro that expands to 4 ControlPoints with structural
7
+ // constraints ensuring the bounding box remains rectangular.
8
+ //
9
+ // ## Parameters
10
+ // - x: Initial X position of top-left corner (default: 0)
11
+ // - y: Initial Y position of top-left corner (default: 0)
12
+ // - content: Text content (string, default: "")
13
+ // - font_family: Font family name (string, default: "sans-serif")
14
+ // - font_size: Font size in P-dimension units (default: 16)
15
+ //
16
+ // ## Exports (Control Points)
17
+ // - TL: Top-left corner
18
+ // - TR: Top-right corner
19
+ // - BL: Bottom-left corner
20
+ // - BR: Bottom-right corner
21
+ //
22
+ // ## Constraints
23
+ // - Width/height are set via `update-metrics` from Renderer measurement
24
+ // - Structural alignment constraints are Hard (cannot be shadowed)
25
+ // - Position constraints are Soft (can be overridden by parent scope)
26
+ //
27
+ // ## Usage
28
+ // import Text from "@viewscript/components/Text.vs"
29
+ //
30
+ // const label = Text({ x: 100, y: 50, content: "Hello, World!" })
31
+ // // Access corners: label.TL, label.TR, label.BL, label.BR
32
+ //
33
+
34
+ export component Text {
35
+ // Parameters with defaults
36
+ param x: Rational = 0
37
+ param y: Rational = 0
38
+ param content: String = ""
39
+ param font_family: String = "sans-serif"
40
+ param font_size: Rational = 16
41
+
42
+ // Control points (4 corners of bounding box)
43
+ controlpoint TL { role: anchor }
44
+ controlpoint TR { role: anchor }
45
+ controlpoint BL { role: anchor }
46
+ controlpoint BR { role: anchor }
47
+
48
+ // Position constraints (Soft: can be overridden)
49
+ constraint TL.x = x { priority: soft }
50
+ constraint TL.y = y { priority: soft }
51
+
52
+ // Structural constraints (Hard: cannot be shadowed)
53
+ // Top edge horizontal
54
+ constraint TR.y = TL.y { priority: hard }
55
+ // Bottom edge horizontal
56
+ constraint BR.y = BL.y { priority: hard }
57
+ // Left edge vertical
58
+ constraint BL.x = TL.x { priority: hard }
59
+ // Right edge vertical
60
+ constraint BR.x = TR.x { priority: hard }
61
+
62
+ // Width/height constraints are added dynamically via update-metrics
63
+ // These are Soft because the actual measured dimensions may differ
64
+ // from any initial estimates.
65
+
66
+ // Exported ports for external reference
67
+ export TL
68
+ export TR
69
+ export BL
70
+ export BR
71
+ }
@@ -0,0 +1,12 @@
1
+ // =============================================================================
2
+ // ViewScript Standard Library: Component Index
3
+ // =============================================================================
4
+ //
5
+ // This file re-exports all standard library components for convenient import.
6
+ //
7
+ // ## Usage
8
+ // import { Text, RoundedRect } from "@viewscript/components"
9
+ //
10
+
11
+ export { Text } from "./Text.vs"
12
+ export { RoundedRect } from "./RoundedRect.vs"
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Browser Default Constraint Modules
3
+ *
4
+ * Provides the default CSS/HTML layout constraints for each browser engine
5
+ * as ViewScript IR modules.
6
+ */
7
+
8
+ export type BrowserEngine = 'chromium' | 'firefox' | 'webkit';
9
+
10
+ export interface BrowserDefaultModule {
11
+ engine: BrowserEngine;
12
+ version: string;
13
+ constraints: unknown[]; // VS IR constraints
14
+ }
15
+
16
+ export async function loadBrowserDefaults(engine: BrowserEngine): Promise<BrowserDefaultModule> {
17
+ // TODO: Load browser-specific default constraints
18
+ return {
19
+ engine,
20
+ version: '1.0.0',
21
+ constraints: [],
22
+ };
23
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "declaration": true,
7
+ "strict": true,
8
+ "outDir": "dist",
9
+ "rootDir": "src"
10
+ },
11
+ "include": ["src"]
12
+ }